accelerated_video_decoder.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_GPU_ACCELERATED_VIDEO_DECODER_H_
  5. #define MEDIA_GPU_ACCELERATED_VIDEO_DECODER_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include "media/base/decoder_buffer.h"
  9. #include "media/base/video_codecs.h"
  10. #include "media/base/video_types.h"
  11. #include "media/gpu/media_gpu_export.h"
  12. #include "ui/gfx/geometry/rect.h"
  13. #include "ui/gfx/geometry/size.h"
  14. namespace media {
  15. // An AcceleratedVideoDecoder is a video decoder that requires support from an
  16. // external accelerator (typically a hardware accelerator) to partially offload
  17. // the decode process after parsing stream headers, and performing reference
  18. // frame and state management.
  19. class MEDIA_GPU_EXPORT AcceleratedVideoDecoder {
  20. public:
  21. AcceleratedVideoDecoder() {}
  22. AcceleratedVideoDecoder(const AcceleratedVideoDecoder&) = delete;
  23. AcceleratedVideoDecoder& operator=(const AcceleratedVideoDecoder&) = delete;
  24. virtual ~AcceleratedVideoDecoder() {}
  25. // Set the buffer owned by |decoder_buffer| as the current source of encoded
  26. // stream data. AcceleratedVideoDecoder doesn't have an ownership of the
  27. // buffer. |decoder_buffer| must be kept alive until Decode() returns
  28. // kRanOutOfStreamData. Pictures produced as a result of this call should be
  29. // assigned the passed stream |id|.
  30. virtual void SetStream(int32_t id, const DecoderBuffer& decoder_buffer) = 0;
  31. // Have the decoder flush its state and trigger output of all previously
  32. // decoded surfaces. Return false on failure.
  33. [[nodiscard]] virtual bool Flush() = 0;
  34. // Stop (pause) decoding, discarding all remaining inputs and outputs,
  35. // but do not flush decoder state, so that playback can be resumed later,
  36. // possibly from a different location.
  37. // To be called during decoding.
  38. virtual void Reset() = 0;
  39. enum DecodeResult {
  40. kDecodeError, // Error while decoding.
  41. // TODO(posciak): unsupported streams are currently treated as error
  42. // in decoding; in future it could perhaps be possible to fall back
  43. // to software decoding instead.
  44. // kStreamError, // Error in stream.
  45. kConfigChange, // This is returned when some configuration (e.g.
  46. // profile or picture size) is changed. A client may
  47. // need to apply the client side the configuration
  48. // properly (e.g. allocate buffers with the new
  49. // resolution).
  50. kRanOutOfStreamData, // Need more stream data to proceed.
  51. kRanOutOfSurfaces, // Waiting for the client to free up output surfaces.
  52. kNeedContextUpdate, // Waiting for the client to update decoding context
  53. // with data acquired from the accelerator.
  54. kTryAgain, // The accelerator needs additional data (independently
  55. // provided) in order to proceed. This may be a new key in order to decrypt
  56. // encrypted data, or existing hardware resources freed so that they can be
  57. // reused. Decoding can resume once the data has been provided.
  58. };
  59. // Try to decode more of the stream, returning decoded frames asynchronously.
  60. // Return when more stream is needed, when we run out of free surfaces, when
  61. // we need a new set of them, or when an error occurs.
  62. [[nodiscard]] virtual DecodeResult Decode() = 0;
  63. // Return dimensions/visible rectangle/profile/bit depth/chroma sampling
  64. // format/required number of pictures that client should be ready to provide
  65. // for the decoder to function properly (of which up to
  66. // GetNumReferenceFrames() might be needed for internal decoding). To be used
  67. // after Decode() returns kConfigChange.
  68. virtual gfx::Size GetPicSize() const = 0;
  69. virtual gfx::Rect GetVisibleRect() const = 0;
  70. virtual VideoCodecProfile GetProfile() const = 0;
  71. virtual uint8_t GetBitDepth() const = 0;
  72. virtual VideoChromaSampling GetChromaSampling() const = 0;
  73. virtual size_t GetRequiredNumOfPictures() const = 0;
  74. virtual size_t GetNumReferenceFrames() const = 0;
  75. // About 3 secs for 30 fps video. When the new sized keyframe is missed, the
  76. // decoder cannot decode the frame. The number of frames are skipped until
  77. // getting new keyframe. If dropping more than the number of frames, the
  78. // decoder reports decode error, which may take longer time to recover it.
  79. // The number is the sweet spot which the decoder can tolerate to handle the
  80. // missing keyframe by itself. In addition, this situation is exceptional.
  81. static constexpr size_t kVPxMaxNumOfSizeChangeFailures = 75;
  82. };
  83. } // namespace media
  84. #endif // MEDIA_GPU_ACCELERATED_VIDEO_DECODER_H_