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

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

Issue 19534002: Make RendererGpuVideoDecoderFactories live on arbitrary threads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 7 years, 5 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
6 #define CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ 6 #define CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 17 matching lines...) Expand all
28 class MessageLoopProxy; 28 class MessageLoopProxy;
29 }; 29 };
30 30
31 namespace media { 31 namespace media {
32 class DecoderBuffer; 32 class DecoderBuffer;
33 } 33 }
34 34
35 namespace content { 35 namespace content {
36 36
37 // This class uses hardware accelerated video decoder to decode video for 37 // This class uses hardware accelerated video decoder to decode video for
38 // WebRTC. The message loop of RendererGpuVideoDecoderFactories is stored as 38 // WebRTC. |vda_message_loop_| is the message loop proxy of the media thread,
39 // |vda_message_loop_|. It is the compositor thread, or the renderer thread if 39 // which VDA::Client methods run on. webrtc::VideoDecoder methods run on WebRTC
40 // threaded compositing is disabled. VDA::Client methods run on
41 // |vda_message_loop_|. webrtc::VideoDecoder methods run on WebRTC
42 // DecodingThread or Chrome_libJingle_WorkerThread, which are trampolined to 40 // DecodingThread or Chrome_libJingle_WorkerThread, which are trampolined to
43 // |vda_message_loop_|. Decode() is non-blocking and queues the buffers. Decoded 41 // |vda_message_loop_|. Decode() is non-blocking and queues the buffers. Decoded
44 // frames are delivered on |vda_message_loop_|. 42 // frames are delivered to WebRTC on |vda_message_loop_|.
45 class CONTENT_EXPORT RTCVideoDecoder 43 class CONTENT_EXPORT RTCVideoDecoder
46 : NON_EXPORTED_BASE(public webrtc::VideoDecoder), 44 : NON_EXPORTED_BASE(public webrtc::VideoDecoder),
47 public media::VideoDecodeAccelerator::Client, 45 public media::VideoDecodeAccelerator::Client,
48 public base::MessageLoop::DestructionObserver { 46 public base::MessageLoop::DestructionObserver {
49 public: 47 public:
50 virtual ~RTCVideoDecoder(); 48 virtual ~RTCVideoDecoder();
51 49
52 // Creates a RTCVideoDecoder. Returns NULL if failed. 50 // Creates a RTCVideoDecoder. Returns NULL if failed. |vda_loop_proxy| should
51 // be the same as the one running |factories|.
53 static scoped_ptr<RTCVideoDecoder> Create( 52 static scoped_ptr<RTCVideoDecoder> Create(
53 webrtc::VideoCodecType type,
54 const scoped_refptr<base::MessageLoopProxy> vda_loop_proxy,
54 const scoped_refptr<media::GpuVideoDecoder::Factories>& factories); 55 const scoped_refptr<media::GpuVideoDecoder::Factories>& factories);
55 56
56 // webrtc::VideoDecoder implementation. 57 // webrtc::VideoDecoder implementation.
57 // Called on WebRTC DecodingThread. 58 // Called on WebRTC DecodingThread.
58 virtual int32_t InitDecode(const webrtc::VideoCodec* codecSettings, 59 virtual int32_t InitDecode(const webrtc::VideoCodec* codecSettings,
59 int32_t numberOfCores) OVERRIDE; 60 int32_t numberOfCores) OVERRIDE;
60 // Called on WebRTC DecodingThread. 61 // Called on WebRTC DecodingThread.
61 virtual int32_t Decode( 62 virtual int32_t Decode(
62 const webrtc::EncodedImage& inputImage, 63 const webrtc::EncodedImage& inputImage,
63 bool missingFrames, 64 bool missingFrames,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 ~BufferData(); 104 ~BufferData();
104 int32 bitstream_buffer_id; 105 int32 bitstream_buffer_id;
105 uint32_t timestamp; // in 90KHz 106 uint32_t timestamp; // in 90KHz
106 uint32_t width; 107 uint32_t width;
107 uint32_t height; 108 uint32_t height;
108 size_t size; // buffer size 109 size_t size; // buffer size
109 }; 110 };
110 111
111 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); 112 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset);
112 113
114 // |vda_loop_proxy| should be the same as the one running |factories|.
113 RTCVideoDecoder( 115 RTCVideoDecoder(
116 const scoped_refptr<base::MessageLoopProxy>& vda_loop_proxy,
114 const scoped_refptr<media::GpuVideoDecoder::Factories>& factories); 117 const scoped_refptr<media::GpuVideoDecoder::Factories>& factories);
115 118
116 void Initialize(base::WaitableEvent* waiter); 119 void Initialize(base::WaitableEvent* waiter);
117 120
118 // Requests a buffer to be decoded by VDA. 121 // Requests a buffer to be decoded by VDA.
119 void RequestBufferDecode(); 122 void RequestBufferDecode();
120 123
121 bool CanMoreDecodeWorkBeDone(); 124 bool CanMoreDecodeWorkBeDone();
122 125
123 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|. 126 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|.
(...skipping 16 matching lines...) Expand all
140 scoped_refptr<media::VideoFrame> CreateVideoFrame( 143 scoped_refptr<media::VideoFrame> CreateVideoFrame(
141 const media::Picture& picture, 144 const media::Picture& picture,
142 const media::PictureBuffer& pb, 145 const media::PictureBuffer& pb,
143 uint32_t timestamp, 146 uint32_t timestamp,
144 uint32_t width, 147 uint32_t width,
145 uint32_t height, 148 uint32_t height,
146 size_t size); 149 size_t size);
147 150
148 // Resets VDA. 151 // Resets VDA.
149 void ResetInternal(); 152 void ResetInternal();
153 void ReleaseInternal();
150 154
151 // Tells VDA that a picture buffer can be recycled. 155 // Tells VDA that a picture buffer can be recycled.
152 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); 156 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point);
153 157
154 void DestroyTextures(); 158 void DestroyTextures();
155 void DestroyVDA(); 159 void DestroyVDA();
156 160
157 // Gets a shared-memory segment of at least |min_size| bytes from 161 // Gets a shared-memory segment of at least |min_size| bytes from
158 // |available_shm_segments_|. Returns NULL if there is no buffer or the 162 // |available_shm_segments_|. Returns NULL if there is no buffer or the
159 // buffer is not big enough. 163 // buffer is not big enough.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // The weak pointer should live and die on the |vda_loop_proxy_|; 198 // The weak pointer should live and die on the |vda_loop_proxy_|;
195 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; 199 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_;
196 base::WeakPtr<RTCVideoDecoder> weak_this_; 200 base::WeakPtr<RTCVideoDecoder> weak_this_;
197 201
198 scoped_refptr<media::GpuVideoDecoder::Factories> factories_; 202 scoped_refptr<media::GpuVideoDecoder::Factories> factories_;
199 203
200 // The message loop to run callbacks on. This is should be the same as the one 204 // The message loop to run callbacks on. This is should be the same as the one
201 // of |factories_|. 205 // of |factories_|.
202 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; 206 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_;
203 207
204 // The thread to create shared memory. Factories::CreateSharedMemory is
205 // trampolined to the child thread. When |vda_loop_proxy_| is the compositor
206 // thread, blocking on the child thread will deadlock. During WebRTC hang up,
207 // the child thread waits for Chrome_libJingle_WorkerThread. libJingle thread
208 // cannot finish when DecodingThread holds a WebRTC lock and blocks on the
209 // child thread. So we need to call CreateSharedMemory asynchronously from a
210 // different thread.
211 base::Thread create_shm_thread_;
212
213 // The texture target used for decoded pictures. 208 // The texture target used for decoded pictures.
214 uint32 decoder_texture_target_; 209 uint32 decoder_texture_target_;
215 210
216 // Metadata of the buffers that have been sent for decode. 211 // Metadata of the buffers that have been sent for decode.
217 std::list<BufferData> input_buffer_data_; 212 std::list<BufferData> input_buffer_data_;
218 213
219 // A map from bitstream buffer IDs to bitstream buffers that are being 214 // A map from bitstream buffer IDs to bitstream buffers that are being
220 // processed by VDA. The map owns SHM buffers. 215 // processed by VDA. The map owns SHM buffers.
221 std::map<int32, SHMBuffer*> bitstream_buffers_in_decoder_; 216 std::map<int32, SHMBuffer*> bitstream_buffers_in_decoder_;
222 217
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // A buffer that has an id less than this should be dropped because Reset or 263 // A buffer that has an id less than this should be dropped because Reset or
269 // Release has been called. Guarded by |lock_|. 264 // Release has been called. Guarded by |lock_|.
270 int32 reset_bitstream_buffer_id_; 265 int32 reset_bitstream_buffer_id_;
271 266
272 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); 267 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder);
273 }; 268 };
274 269
275 } // namespace content 270 } // namespace content
276 271
277 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ 272 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698