Index: content/renderer/media/gpu/rtc_video_decoder.h |
diff --git a/content/renderer/media/gpu/rtc_video_decoder.h b/content/renderer/media/gpu/rtc_video_decoder.h |
index e6eefade04b4073981784e09c6078d0d5ec2bae2..4beb6ec1d08f00807eca2301474938480a168648 100644 |
--- a/content/renderer/media/gpu/rtc_video_decoder.h |
+++ b/content/renderer/media/gpu/rtc_video_decoder.h |
@@ -35,6 +35,7 @@ class WaitableEvent; |
namespace media { |
class DecoderBuffer; |
class GpuVideoAcceleratorFactories; |
+class VideoDecoder; |
} |
namespace gpu { |
@@ -50,19 +51,22 @@ namespace content { |
// Decode() is non-blocking and queues the buffers. Decoded frames are |
// delivered to WebRTC on the media task runner. |
class CONTENT_EXPORT RTCVideoDecoder |
- : NON_EXPORTED_BASE(public webrtc::VideoDecoder), |
- public media::VideoDecodeAccelerator::Client { |
+ : NON_EXPORTED_BASE(public webrtc::VideoDecoder) { |
public: |
~RTCVideoDecoder() override; |
- // Creates a RTCVideoDecoder on the message loop of |factories|. Returns NULL |
- // if failed. The video decoder will run on the message loop of |factories|. |
+ using CreateVideoDecoderCB = |
+ base::Callback<std::unique_ptr<media::VideoDecoder>()>; |
+ |
+ // TODO(slan): Document! |
static std::unique_ptr<RTCVideoDecoder> Create( |
webrtc::VideoCodecType type, |
- media::GpuVideoAcceleratorFactories* factories); |
- // Destroys |decoder| on the loop of |factories| |
- static void Destroy(webrtc::VideoDecoder* decoder, |
- media::GpuVideoAcceleratorFactories* factories); |
+ const CreateVideoDecoderCB& create_video_decoder_cb, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner); |
+ // Destroys |decoder| on |decoder_task_runner|. |
+ static void Destroy( |
+ webrtc::VideoDecoder* decoder, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner); |
// webrtc::VideoDecoder implementation. |
// Called on WebRTC DecodingThread. |
@@ -81,40 +85,15 @@ class CONTENT_EXPORT RTCVideoDecoder |
// this runs. |
int32_t Release() override; |
- // VideoDecodeAccelerator::Client implementation. |
- void ProvidePictureBuffers(uint32_t count, |
- media::VideoPixelFormat format, |
- uint32_t textures_per_buffer, |
- const gfx::Size& size, |
- uint32_t texture_target) override; |
- void DismissPictureBuffer(int32_t id) override; |
- void PictureReady(const media::Picture& picture) override; |
- void NotifyEndOfBitstreamBuffer(int32_t id) override; |
- void NotifyFlushDone() override; |
- void NotifyResetDone() override; |
- void NotifyError(media::VideoDecodeAccelerator::Error error) override; |
- |
private: |
- // Metadata of a bitstream buffer. |
- struct BufferData { |
- BufferData(int32_t bitstream_buffer_id, |
- uint32_t timestamp, |
- size_t size, |
- const gfx::Rect& visible_rect); |
- BufferData(); |
- ~BufferData(); |
- int32_t bitstream_buffer_id; |
- uint32_t timestamp; // in 90KHz |
- size_t size; // buffer size |
- gfx::Rect visible_rect; |
- }; |
- |
FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); |
FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset); |
FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, GetVDAErrorCounterForTesting); |
- RTCVideoDecoder(webrtc::VideoCodecType type, |
- media::GpuVideoAcceleratorFactories* factories); |
+ RTCVideoDecoder( |
+ webrtc::VideoCodecType type, |
+ const CreateVideoDecoderCB& create_video_decoder_cb, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner); |
// Requests a buffer to be decoded by VDA. |
void RequestBufferDecode(); |
@@ -129,78 +108,35 @@ class CONTENT_EXPORT RTCVideoDecoder |
// |id_reset|. |
bool IsFirstBufferAfterReset(int32_t id_buffer, int32_t id_reset); |
- int GetVDAErrorCounterForTesting() { return vda_error_counter_; } |
- |
- // Saves a WebRTC buffer in |decode_buffers_| for decode. |
- void SaveToDecodeBuffers_Locked( |
- const webrtc::EncodedImage& input_image, |
- std::unique_ptr<base::SharedMemory> shm_buffer, |
- const BufferData& buffer_data); |
- |
- // Saves a WebRTC buffer in |pending_buffers_| waiting for SHM available. |
- // Returns true on success. |
- bool SaveToPendingBuffers_Locked(const webrtc::EncodedImage& input_image, |
- const BufferData& buffer_data); |
- |
- // Gets SHM and moves pending buffers to decode buffers. |
- void MovePendingBuffersToDecodeBuffers(); |
- |
- scoped_refptr<media::VideoFrame> CreateVideoFrame( |
- const media::Picture& picture, |
- const media::PictureBuffer& pb, |
- uint32_t timestamp, |
- const gfx::Rect& visible_rect, |
- media::VideoPixelFormat pixel_format); |
- |
- // Resets VDA. |
- void ResetInternal(); |
- |
- // Static method is to allow it to run even after RVD is deleted. |
- static void ReleaseMailbox(base::WeakPtr<RTCVideoDecoder> decoder, |
- media::GpuVideoAcceleratorFactories* factories, |
- int64_t picture_buffer_id, |
- uint32_t texture_id, |
- const gpu::SyncToken& release_sync_token); |
- // Tells VDA that a picture buffer can be recycled. |
- void ReusePictureBuffer(int64_t picture_buffer_id); |
- |
- // Creates |vda_| on the media thread. |
- void CreateVDA(media::VideoCodecProfile profile, base::WaitableEvent* waiter); |
- |
- void DestroyTextures(); |
- void DestroyVDA(); |
- |
- // Gets a shared-memory segment of at least |min_size| bytes from |
- // |available_shm_segments_|. Returns NULL if there is no buffer or the |
- // buffer is not big enough. |
- std::unique_ptr<base::SharedMemory> GetSHM_Locked(size_t min_size); |
- |
- // Returns a shared-memory segment to the available pool. |
- void PutSHM_Locked(std::unique_ptr<base::SharedMemory> shm_buffer); |
- |
- // Allocates |count| shared memory buffers of |size| bytes. |
- void CreateSHM(size_t count, size_t size); |
- |
- // Stores the buffer metadata to |input_buffer_data_|. |
- void RecordBufferData(const BufferData& buffer_data); |
- // Gets the buffer metadata from |input_buffer_data_|. |
- void GetBufferData(int32_t bitstream_buffer_id, |
- uint32_t* timestamp, |
- gfx::Rect* visible_rect); |
+ int GetVDAErrorCounterForTesting() { return decoder_error_counter_; } |
+ |
+ // Saves a DecoderBuffer buffer in |pending_buffers_| waiting to be sent to |
+ // the decoder. Returns true on success. |
+ bool SaveToPendingBuffers_Locked( |
+ int32_t decoder_buffer_id, |
+ const scoped_refptr<media::DecoderBuffer>& decoder_buffer); |
+ |
+ // Calls Reset() on |decoder_|. Must be executed on the decoder thread. |
+ void ResetOnDecoderThread(); |
+ void OnResetDone(); |
+ |
+ void OnBufferDecoded(int32_t buffer_decode_id, |
+ bool is_eos, |
+ media::DecodeStatus status); |
// Records the result of InitDecode to UMA and returns |status|. |
int32_t RecordInitDecodeUMA(int32_t status); |
// Asserts the contract that this class is operated on the right thread. |
- void DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() const; |
+ void DCheckDecoderTaskRunnerIsCurrent() const; |
// Queries factories_ whether |profile| is supported and return true is so, |
// false otherwise. If true, also set resolution limits for |profile| |
// in min/max_resolution_. |
bool IsProfileSupported(media::VideoCodecProfile profile); |
- // Clears the pending_buffers_ queue, freeing memory. |
- void ClearPendingBuffers(); |
+ // Clears the pending_buffers_ queue, freeing memory. Guarded by |lock_|. |
+ void ClearPendingBuffers_Locked(); |
enum State { |
UNINITIALIZED, // The decoder has not initialized. |
@@ -214,12 +150,17 @@ class CONTENT_EXPORT RTCVideoDecoder |
static const int32_t ID_INVALID; // indicates Reset or Release never occurred |
// The hardware video decoder. |
- std::unique_ptr<media::VideoDecodeAccelerator> vda_; |
+ std::unique_ptr<::media::VideoDecoder> decoder_; |
+ void InitializeDecoder(media::VideoCodecProfile profile, |
+ media::VideoCodec codec, |
+ base::WaitableEvent* waiter); |
+ void OnDecoderInitialized(base::WaitableEvent* waiter, bool success); |
+ void OnFrameReady(const scoped_refptr<media::VideoFrame>& frame); |
media::VideoCodecProfile vda_codec_profile_; |
// Number of times that |vda_| notified of an error. |
- uint32_t vda_error_counter_; |
+ uint32_t decoder_error_counter_; |
// The video codec type, as reported by WebRTC. |
const webrtc::VideoCodecType video_codec_type_; |
@@ -227,39 +168,16 @@ class CONTENT_EXPORT RTCVideoDecoder |
// The size of the incoming video frames. |
gfx::Size frame_size_; |
- media::GpuVideoAcceleratorFactories* const factories_; |
- |
- // The texture target used for decoded pictures. |
- uint32_t decoder_texture_target_; |
+ const CreateVideoDecoderCB create_video_decoder_cb_; |
+ scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_; |
// The format of the decoded pictures. |
media::VideoPixelFormat pixel_format_; |
- // Metadata of the buffers that have been sent for decode. |
- std::list<BufferData> input_buffer_data_; |
- |
- // A map from bitstream buffer IDs to bitstream buffers that are being |
- // processed by VDA. |
- std::map<int32_t, std::unique_ptr<base::SharedMemory>> |
- bitstream_buffers_in_decoder_; |
- |
- // A map from picture buffer IDs to texture-backed picture buffers. |
- std::map<int32_t, media::PictureBuffer> assigned_picture_buffers_; |
- |
- // PictureBuffers given to us by VDA via PictureReady, which we sent forward |
- // as VideoFrames to be rendered via read_cb_, and which will be returned |
- // to us via ReusePictureBuffer. |
- typedef std::map<int32_t /* picture_buffer_id */, uint32_t /* texture_id */> |
- PictureBufferTextureMap; |
- PictureBufferTextureMap picture_buffers_at_display_; |
- |
- // The id that will be given to the next picture buffer. |
- int32_t next_picture_buffer_id_; |
- |
// Protects |state_|, |decode_complete_callback_| , |num_shm_buffers_|, |
// |available_shm_segments_|, |pending_buffers_|, |decode_buffers_|, |
- // |next_bitstream_buffer_id_|, |reset_bitstream_buffer_id_| and |
- // |vda_error_counter_|. |
+ // |next_decoder_buffer_id_|, |reset_bitstream_buffer_id_| and |
+ // |decoder_error_counter_|. |
base::Lock lock_; |
// The state of RTCVideoDecoder. Guarded by |lock_|. |
@@ -268,29 +186,21 @@ class CONTENT_EXPORT RTCVideoDecoder |
// Guarded by |lock_|. |
webrtc::DecodedImageCallback* decode_complete_callback_; |
- // Total number of allocated SHM buffers. Guarded by |lock_|. |
- size_t num_shm_buffers_; |
- |
- // Shared-memory buffer pool. Since allocating SHM segments requires a |
- // round-trip to the browser process, we keep allocation out of the |
- // steady-state of the decoder. Guarded by |lock_|. |
- std::vector<std::unique_ptr<base::SharedMemory>> available_shm_segments_; |
- |
// A queue storing WebRTC encoding images (and their metadata) that are |
// waiting for the shared memory. Guarded by |lock_|. |
- std::deque<std::pair<webrtc::EncodedImage, BufferData>> pending_buffers_; |
+ std::deque<std::pair<int32_t, scoped_refptr<media::DecoderBuffer>>> |
+ pending_buffers_; |
- // A queue storing buffers (and their metadata) that will be sent to VDA for |
- // decode. Guarded by |lock_|. |
- std::deque<std::pair<std::unique_ptr<base::SharedMemory>, BufferData>> |
- decode_buffers_; |
+ std::unordered_map<int32_t /* decoder_buffer_id */, |
+ scoped_refptr<media::DecoderBuffer>> |
+ buffers_in_decoder_; |
// The id that will be given to the next bitstream buffer. Guarded by |lock_|. |
- int32_t next_bitstream_buffer_id_; |
+ int32_t next_decoder_buffer_id_; |
// A buffer that has an id less than this should be dropped because Reset or |
// Release has been called. Guarded by |lock_|. |
- int32_t reset_bitstream_buffer_id_; |
+ int32_t reset_decoder_buffer_id_; |
// Minimum and maximum supported resolutions for the current profile/VDA. |
gfx::Size min_resolution_; |