Chromium Code Reviews| Index: content/renderer/media/rtc_video_decoder.h |
| diff --git a/content/renderer/media/rtc_video_decoder.h b/content/renderer/media/rtc_video_decoder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b345c2143d16a8411b470dd7d204591f640b09ee |
| --- /dev/null |
| +++ b/content/renderer/media/rtc_video_decoder.h |
| @@ -0,0 +1,211 @@ |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ |
| +#define CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ |
| + |
| +#include <deque> |
| +#include <utility> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/message_loop.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "content/common/content_export.h" |
| +#include "media/base/bitstream_buffer.h" |
| +#include "media/base/video_decoder.h" |
| +#include "media/filters/gpu_video_decoder.h" |
| +#include "media/video/picture.h" |
| +#include "media/video/video_decode_accelerator.h" |
| +#include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_interface.h" |
| + |
| +namespace base { |
| +class MessageLoopProxy; |
| +}; |
| + |
| +namespace media { |
| +class DecoderBuffer; |
| +} |
| + |
| +namespace content { |
| + |
| +// This class uses hardware accelerated video decoder to decode video for |
| +// WebRTC. The message loop of RendererGpuVideoDecoderFactories is stored |
| +// as |vda_message_loop_|, which is a new thread. VDA::Client methods run on |
| +// |vda_message_loop_|. webrtc::VideoDecoder methods run on WebRTC |
| +// DecodingThread or Chrome_libJingle_WorkerThread, which are trampolined to |
| +// |vda_message_loop_|. Decode() is non-blocking and queues the buffers. |
| +// Decoded frames are delivered on |vda_message_loop_|. |
| +class CONTENT_EXPORT RTCVideoDecoder |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
Add a TODO to merge with RTCVideoDecoderBridgeTv ?
wuchengli
2013/06/13 10:28:07
I just looked their CL. It's diverted more. I don'
|
| + : NON_EXPORTED_BASE(public webrtc::VideoDecoder), |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
colon goes on previous line
(you might enjoy git c
wuchengli
2013/06/13 10:28:07
git cl format did not say this should go on previo
|
| + public media::VideoDecodeAccelerator::Client, |
| + public base::MessageLoop::DestructionObserver { |
| + public: |
| + RTCVideoDecoder( |
| + const scoped_refptr<media::GpuVideoDecoder::Factories>& factories); |
| + virtual ~RTCVideoDecoder(); |
| + |
| + // Initializes VDA and a weak pointer. True if successful. |
| + virtual bool Initialize(webrtc::VideoCodecType); |
| + |
| + // webrtc::VideoDecoder implementation. |
| + // Called on WebRTC DecodingThread. |
| + virtual int32_t InitDecode( |
| + const webrtc::VideoCodec* codecSettings, |
| + int32_t numberOfCores) OVERRIDE; |
| + // Called on WebRTC DecodingThread. |
| + virtual int32_t Decode( |
| + const webrtc::EncodedImage& inputImage, |
| + bool missingFrames, |
| + const webrtc::RTPFragmentationHeader* fragmentation, |
| + const webrtc::CodecSpecificInfo* codecSpecificInfo = NULL, |
| + int64_t renderTimeMs = -1) OVERRIDE; |
| + // Called on WebRTC DecodingThread. |
| + virtual int32_t RegisterDecodeCompleteCallback( |
| + webrtc::DecodedImageCallback* callback) OVERRIDE; |
| + // Called on Chrome_libJingle_WorkerThread. |
| + virtual int32_t Release() OVERRIDE; |
| + // Called on Chrome_libJingle_WorkerThread. |
| + virtual int32_t Reset() OVERRIDE; |
| + |
| + // VideoDecodeAccelerator::Client implementation. |
| + virtual void NotifyInitializeDone() OVERRIDE; |
| + virtual void ProvidePictureBuffers(uint32 count, |
| + const gfx::Size& size, |
| + uint32 texture_target) OVERRIDE; |
| + virtual void DismissPictureBuffer(int32 id) OVERRIDE; |
| + virtual void PictureReady(const media::Picture& picture) OVERRIDE; |
| + virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; |
| + virtual void NotifyFlushDone() OVERRIDE; |
| + virtual void NotifyResetDone() OVERRIDE; |
| + virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; |
| + |
| + // base::DestructionObserver implementation. Called when |vda_message_loop_| |
| + // is stopped. |
| + virtual void WillDestroyCurrentMessageLoop(); |
| + |
| + private: |
| + // A shared memory segment and its allocated size. |
| + struct SHMBuffer { |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
can move to .cc file w/ fwd-decl left here
wuchengli
2013/06/13 10:28:07
Done.
|
| + SHMBuffer(base::SharedMemory* m, size_t s); |
| + ~SHMBuffer(); |
| + base::SharedMemory* shm; |
| + size_t size; |
| + }; |
| + |
| + struct BufferData { |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
ditto
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
doco what this is
wuchengli
2013/06/13 10:28:07
Done.
wuchengli
2013/06/13 10:28:07
Done.
|
| + BufferData(int32 bbid, uint32_t ts, int w, int h, size_t s); |
|
Pawel Osciak
2013/06/12 23:38:22
I'd suggest more verbose argument names.
wuchengli
2013/06/13 10:28:07
Done.
|
| + ~BufferData(); |
| + int32 bitstream_buffer_id; |
| + uint32_t timestamp; // in 90KHz |
| + uint32_t width; |
| + uint32_t height; |
| + size_t size; // buffer size |
| + }; |
| + |
| + void CreateVideoDecodeAccelerator(media::VideoCodecProfile profile); |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
See comment in .cc file; I think this and the rest
wuchengli
2013/06/13 10:28:07
I removed trampolining for this. The method is ren
|
| + |
| + // Requests a buffer to be decoded. |
| + void RequestBufferDecode(); |
| + |
| + bool CanMoreDecodeWorkBeDone(); |
| + |
| + // Resets VDA. |
| + void ResetInternal(); |
| + |
| + // Destroys VDA and the textures. |
| + void ReleaseInternal(); |
| + |
| + // Tells VDA that a picture buffer can be recycled. |
| + void ReusePictureBuffer(int64 picture_buffer_id); |
| + |
| + // Waits for |decoder_waiter_| or |aborted_waiter_| to be signaled. |
| + void Wait(); |
| + |
| + void DestroyTextures(); |
| + void DestroyVDA(); |
| + |
| + // Requests a shared-memory segment of at least |min_size| bytes. Will |
| + // allocate as necessary. Caller does not own returned pointer. |
| + SHMBuffer* GetSHM(size_t min_size); |
| + |
| + // Returns a shared-memory segment to the available pool. |
| + void PutSHM(SHMBuffer* shm_buffer); |
| + |
| + // Stores the buffer data to |input_buffer_data_|. |
| + void RecordBufferData(const BufferData& buffer_data); |
| + // Gets the buffer data from |input_buffer_data_|. |
| + void GetBufferData(int32 bitstream_buffer_id, uint32_t* timestamp, |
| + uint32_t* width, uint32_t* height, size_t *size); |
| + |
| + enum State { |
| + kUninitialized, // The decoder has not initialized. |
| + kInitialized, // The decoder has initialized. |
| + kDecodeError, // Decoding error happened. |
| + }; |
| + |
| + // The hardware video decoder. |
| + scoped_ptr<media::VideoDecodeAccelerator> vda_; |
| + |
| + // Used to wait for VDA calls to complete in InitDecode(), Release() and |
| + // Reset(). |
| + base::WaitableEvent decoder_waiter_; |
| + |
| + // An event signaled when the thread running |vda_loop_proxy_| is stopped. |
| + base::WaitableEvent aborted_waiter_; |
| + |
| + // The size of the incoming video frames. |
| + int32_t frame_width_; |
| + int32_t frame_height_; |
| + |
| + // Protects |state_|, |decode_complete_callback_| , |available_shm_segments_|, |
| + // and |buffers_to_be_decoded|; |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
s/d|/d_|/
wuchengli
2013/06/13 10:28:07
Done.
|
| + base::Lock lock_; |
| + |
| + // The state of RTCVideoDecoder. Guarded by |lock_|. |
| + State state_; |
| + |
| + // Guarded by |lock_|. |
| + webrtc::DecodedImageCallback* decode_complete_callback_; |
| + |
| + // 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<SHMBuffer*> available_shm_segments_; |
| + |
| + // The weak pointer should live and die on the |decoder_message_loop_|; |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
|decoder_message_loop_| is not a thing that exists
wuchengli
2013/06/13 10:28:07
Done.
|
| + base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; |
| + base::WeakPtr<RTCVideoDecoder> weak_this_; |
| + |
| + scoped_refptr<media::GpuVideoDecoder::Factories> factories_; |
| + |
| + // The message loop to run callbacks on. This is from |factories|. |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
s/s|/s_|/
wuchengli
2013/06/13 10:28:07
Done.
|
| + scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; |
| + |
| + // The texture target used for decoded pictures. |
| + uint32 decoder_texture_target_; |
| + |
| + // The data of the buffers that are in VDA. |
| + std::list<BufferData> input_buffer_data_; |
| + |
| + // A queue storing buffers (and their data) that will be sent to VDA for |
| + // decode. Gguarded by |lock|. |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
typo: Gg
Pawel Osciak
2013/06/12 23:38:22
s/|lock|/|lock_|/
wuchengli
2013/06/13 10:28:07
Done.
wuchengli
2013/06/13 10:28:07
Done.
|
| + std::deque<std::pair<SHMBuffer*, BufferData> > buffers_to_be_decoded; |
|
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
s/d;/d_;/
wuchengli
2013/06/13 10:28:07
Done.
|
| + |
| + // A map from bitstream buffer IDs to bitstream buffers that are being |
| + // processed by VDA. |
| + std::map<int32, SHMBuffer*> bitstream_buffers_in_decoder_; |
| + |
| + // A map from picture buffer IDs to texture-backed picture buffers. |
| + std::map<int32, media::PictureBuffer> picture_buffers_in_decoder_; |
| + |
| + int32 next_picture_buffer_id_; |
| + int32 next_bitstream_buffer_id_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ |