Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: content/renderer/media/rtc_video_decoder.h

Issue 13890012: Integrate VDA with WebRTC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix a deadlock by calling RGVDF::CreateSharedMemory asynchronously Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Use of this source code is governed by a BSD-style license that can be
2 // found in the LICENSE file.
3
4 #ifndef CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
5 #define CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
6
7 #include <deque>
8 #include <set>
9 #include <utility>
10
11 #include "base/basictypes.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop.h"
14 #include "base/synchronization/lock.h"
15 #include "base/synchronization/waitable_event.h"
16 #include "base/threading/thread.h"
17 #include "content/common/content_export.h"
18 #include "media/base/bitstream_buffer.h"
19 #include "media/base/video_decoder.h"
20 #include "media/filters/gpu_video_decoder.h"
21 #include "media/video/picture.h"
22 #include "media/video/video_decode_accelerator.h"
23 #include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_i nterface.h"
24
25 namespace base {
26 class MessageLoopProxy;
27 };
28
29 namespace media {
30 class DecoderBuffer;
31 }
32
33 namespace content {
34
35 // This class uses hardware accelerated video decoder to decode video for
36 // WebRTC. The message loop of RendererGpuVideoDecoderFactories is stored as
37 // |vda_message_loop_|. It is the compositor thread, or the renderer thread if
38 // threaded compositing is disabled. VDA::Client methods run on
39 // |vda_message_loop_|. webrtc::VideoDecoder methods run on WebRTC
40 // DecodingThread or Chrome_libJingle_WorkerThread, which are trampolined to
41 // |vda_message_loop_|. Decode() is non-blocking and queues the buffers. Decoded
42 // frames are delivered on |vda_message_loop_|.
43 class CONTENT_EXPORT RTCVideoDecoder
44 : NON_EXPORTED_BASE(public webrtc::VideoDecoder),
45 public media::VideoDecodeAccelerator::Client,
46 public base::MessageLoop::DestructionObserver {
47 public:
48 virtual ~RTCVideoDecoder();
49
50 // Creates a RTCVideoDecoder. Returns NULL if failed.
51 static scoped_ptr<RTCVideoDecoder> Create(
52 const scoped_refptr<media::GpuVideoDecoder::Factories>& factories);
53
54 // webrtc::VideoDecoder implementation.
55 // Called on WebRTC DecodingThread.
56 virtual int32_t InitDecode(const webrtc::VideoCodec* codecSettings,
57 int32_t numberOfCores) OVERRIDE;
58 // Called on WebRTC DecodingThread.
59 virtual int32_t Decode(
60 const webrtc::EncodedImage& inputImage,
61 bool missingFrames,
62 const webrtc::RTPFragmentationHeader* fragmentation,
63 const webrtc::CodecSpecificInfo* codecSpecificInfo = NULL,
64 int64_t renderTimeMs = -1) OVERRIDE;
65 // Called on WebRTC DecodingThread.
66 virtual int32_t RegisterDecodeCompleteCallback(
67 webrtc::DecodedImageCallback* callback) OVERRIDE;
68 // Called on Chrome_libJingle_WorkerThread. The child thread is blocked while
69 // this runs.
70 virtual int32_t Release() OVERRIDE;
71 // Called on Chrome_libJingle_WorkerThread. The child thread is blocked while
72 // this runs.
73 virtual int32_t Reset() OVERRIDE;
74
75 // VideoDecodeAccelerator::Client implementation.
76 virtual void NotifyInitializeDone() OVERRIDE;
77 virtual void ProvidePictureBuffers(uint32 count,
78 const gfx::Size& size,
79 uint32 texture_target) OVERRIDE;
80 virtual void DismissPictureBuffer(int32 id) OVERRIDE;
81 virtual void PictureReady(const media::Picture& picture) OVERRIDE;
82 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE;
83 virtual void NotifyFlushDone() OVERRIDE;
84 virtual void NotifyResetDone() OVERRIDE;
85 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE;
86
87 // base::DestructionObserver implementation. Called when |vda_message_loop_|
88 // is stopped.
89 virtual void WillDestroyCurrentMessageLoop();
90
91 private:
92 struct SHMBuffer;
93 struct BufferData;
94
95 RTCVideoDecoder(
96 const scoped_refptr<media::GpuVideoDecoder::Factories>& factories);
97
98 void Initialize(base::WaitableEvent* waiter);
99
100 // Requests a buffer to be decoded by VDA.
101 void RequestBufferDecode();
102
103 bool CanMoreDecodeWorkBeDone();
104
105 // Sends the WebRTC buffer for decode on |vda_loop_proxy_|.
106 void SendBufferForDecode(const webrtc::EncodedImage& inputImage,
Ami GONE FROM CHROMIUM 2013/06/26 00:11:58 s/inputImage/input_image/ since this isn't an over
wuchengli 2013/06/28 15:08:44 Done.
107 SHMBuffer* shm_buffer,
Ami GONE FROM CHROMIUM 2013/06/26 00:11:58 indent is off here and elsewhere
Ami GONE FROM CHROMIUM 2013/06/26 00:11:58 style: output params follow input params But this
wuchengli 2013/06/28 15:08:44 Indent looks correct. I've run git cl format. Wher
wuchengli 2013/06/28 15:08:44 They are all output params. It's a pointer because
108 const BufferData& buffer_data);
109
110 // Sends all WebRTC buffers for decode on |vda_loop_proxy_|.
111 void SendPendingBuffersForDecode();
112
113 // Saves a WebRTC buffer for decode later.
114 void SaveToPendingBuffers(const webrtc::EncodedImage& inputImage,
115 const BufferData& buffer_data);
116
117 scoped_refptr<media::VideoFrame> CreateVideoFrame(
118 const media::Picture& picture,
119 const media::PictureBuffer& pb,
120 uint32_t timestamp,
121 uint32_t width,
122 uint32_t height,
123 size_t size);
124
125 // Resets VDA.
126 void ResetInternal();
127
128 // Tells VDA that a picture buffer can be recycled.
129 void ReusePictureBuffer(int64 picture_buffer_id);
130
131 void DestroyTextures();
132 void DestroyVDA();
133
134 // Requests a shared-memory segment of at least |min_size| bytes. Caller does
135 // not own returned pointer.
Ami GONE FROM CHROMIUM 2013/06/26 00:11:58 Doco meaning of NULL return
wuchengli 2013/06/28 15:08:44 Done.
136 SHMBuffer* GetSHM(size_t min_size);
137
138 // Allocates shared memory of at least |min_size| bytes.
139 void CreateSHM(size_t min_size);
140
141 // Returns a shared-memory segment to the available pool.
142 void PutSHM(SHMBuffer* shm_buffer);
143
144 // Stores the buffer metadata to |input_buffer_data_|.
145 void RecordBufferData(const BufferData& buffer_data);
146 // Gets the buffer metadata from |input_buffer_data_|.
147 void GetBufferData(int32 bitstream_buffer_id,
148 uint32_t* timestamp,
149 uint32_t* width,
150 uint32_t* height,
151 size_t* size);
152
153 enum State {
154 UNINITIALIZED, // The decoder has not initialized.
155 INITIALIZED, // The decoder has initialized.
156 RESETTING, // The decoder is being reset.
157 DECODE_ERROR, // Decoding error happened.
158 };
159
160 // The hardware video decoder.
161 scoped_ptr<media::VideoDecodeAccelerator> vda_;
162
163 // The size of the incoming video frames.
164 gfx::Size frame_size_;
165
166 // Protects |state_|, |decode_complete_callback_| , |available_shm_segments_|,
167 // |buffers_to_be_decoded_|, |next_bitstream_buffer_id_| and
168 // |reset_bitstream_buffer_id_|.
169 base::Lock lock_;
170
171 // The state of RTCVideoDecoder. Guarded by |lock_|.
172 State state_;
173
174 // Guarded by |lock_|.
175 webrtc::DecodedImageCallback* decode_complete_callback_;
176
177 // Shared-memory buffer pool. Since allocating SHM segments requires a
178 // round-trip to the browser process, we keep allocation out of the
179 // steady-state of the decoder. Guarded by |lock_|.
180 std::vector<SHMBuffer*> available_shm_segments_;
181
182 // The weak pointer should live and die on the |vda_loop_proxy_|;
183 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_;
184 base::WeakPtr<RTCVideoDecoder> weak_this_;
185
186 scoped_refptr<media::GpuVideoDecoder::Factories> factories_;
187
188 // The message loop to run callbacks on. This is should be the same as the one
189 // of |factories_|.
190 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_;
191
192 // The texture target used for decoded pictures.
193 uint32 decoder_texture_target_;
194
195 // A queue storing WebRTC encoding images (and their metadata) that are
196 // waiting for the allocation of shared memory. Only accessed by WebRTC
197 // DecodingThread.
Ami GONE FROM CHROMIUM 2013/06/26 00:11:58 Generally vars not protected by locks go above the
wuchengli 2013/06/28 15:08:44 Done.
198 std::deque<std::pair<webrtc::EncodedImage, BufferData> > webrtc_buffers_;
199
200 // Metadata of the buffers that have been sent for decode.
201 std::list<BufferData> input_buffer_data_;
202
203 // A queue storing buffers (and their metadata) that will be sent to VDA for
204 // decode. Guarded by |lock_|.
205 std::deque<std::pair<SHMBuffer*, BufferData> > buffers_to_be_decoded_;
206
207 // A map from bitstream buffer IDs to bitstream buffers that are being
208 // processed by VDA.
209 std::map<int32, SHMBuffer*> bitstream_buffers_in_decoder_;
210
211 // A map from picture buffer IDs to texture-backed picture buffers.
212 std::map<int32, media::PictureBuffer> assigned_picture_buffers_;
213
214 // Picture buffers that are dismissed but not deleted yet.
215 std::map<int32, media::PictureBuffer> dismissed_picture_buffers_;
216
217 // PictureBuffers given to us by VDA via PictureReady, which we sent forward
218 // as VideoFrames to be rendered via read_cb_, and which will be returned
219 // to us via ReusePictureBuffer.
220 std::set<int32> picture_buffers_at_display_;
221
222 // The id that will be given to the next picture buffer.
223 int32 next_picture_buffer_id_;
224
225 // The id that will be given to the next bitstream buffer. Guarded by |lock_|.
226 int32 next_bitstream_buffer_id_;
227
228 // A buffer that has an id less than this should be dropped because Reset or
229 // Release has been called. Guarded by |lock_|.
230 int32 reset_bitstream_buffer_id_;
231
232 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder);
233 };
234
235 } // namespace content
236
237 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698