OLD | NEW |
---|---|
(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 <utility> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/message_loop.h" | |
13 #include "base/synchronization/lock.h" | |
14 #include "base/synchronization/waitable_event.h" | |
15 #include "content/common/content_export.h" | |
16 #include "media/base/bitstream_buffer.h" | |
17 #include "media/base/video_decoder.h" | |
18 #include "media/filters/gpu_video_decoder.h" | |
19 #include "media/video/picture.h" | |
20 #include "media/video/video_decode_accelerator.h" | |
21 #include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_i nterface.h" | |
22 | |
23 namespace base { | |
24 class MessageLoopProxy; | |
25 }; | |
26 | |
27 namespace media { | |
28 class DecoderBuffer; | |
29 } | |
30 | |
31 namespace content { | |
32 | |
33 // This class uses hardware accelerated video decoder to decode video for | |
34 // WebRTC. The message loop of RendererGpuVideoDecoderFactories is stored | |
35 // as |vda_message_loop_|, which is a new thread. VDA::Client methods run on | |
36 // |vda_message_loop_|. webrtc::VideoDecoder methods run on WebRTC | |
37 // DecodingThread or Chrome_libJingle_WorkerThread, which are trampolined to | |
38 // |vda_message_loop_|. Decode() is non-blocking and queues the buffers. | |
39 // Decoded frames are delivered on |vda_message_loop_|. | |
40 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'
| |
41 : 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
| |
42 public media::VideoDecodeAccelerator::Client, | |
43 public base::MessageLoop::DestructionObserver { | |
44 public: | |
45 RTCVideoDecoder( | |
46 const scoped_refptr<media::GpuVideoDecoder::Factories>& factories); | |
47 virtual ~RTCVideoDecoder(); | |
48 | |
49 // Initializes VDA and a weak pointer. True if successful. | |
50 virtual bool Initialize(webrtc::VideoCodecType); | |
51 | |
52 // webrtc::VideoDecoder implementation. | |
53 // Called on WebRTC DecodingThread. | |
54 virtual int32_t InitDecode( | |
55 const webrtc::VideoCodec* codecSettings, | |
56 int32_t numberOfCores) OVERRIDE; | |
57 // Called on WebRTC DecodingThread. | |
58 virtual int32_t Decode( | |
59 const webrtc::EncodedImage& inputImage, | |
60 bool missingFrames, | |
61 const webrtc::RTPFragmentationHeader* fragmentation, | |
62 const webrtc::CodecSpecificInfo* codecSpecificInfo = NULL, | |
63 int64_t renderTimeMs = -1) OVERRIDE; | |
64 // Called on WebRTC DecodingThread. | |
65 virtual int32_t RegisterDecodeCompleteCallback( | |
66 webrtc::DecodedImageCallback* callback) OVERRIDE; | |
67 // Called on Chrome_libJingle_WorkerThread. | |
68 virtual int32_t Release() OVERRIDE; | |
69 // Called on Chrome_libJingle_WorkerThread. | |
70 virtual int32_t Reset() OVERRIDE; | |
71 | |
72 // VideoDecodeAccelerator::Client implementation. | |
73 virtual void NotifyInitializeDone() OVERRIDE; | |
74 virtual void ProvidePictureBuffers(uint32 count, | |
75 const gfx::Size& size, | |
76 uint32 texture_target) OVERRIDE; | |
77 virtual void DismissPictureBuffer(int32 id) OVERRIDE; | |
78 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | |
79 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; | |
80 virtual void NotifyFlushDone() OVERRIDE; | |
81 virtual void NotifyResetDone() OVERRIDE; | |
82 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; | |
83 | |
84 // base::DestructionObserver implementation. Called when |vda_message_loop_| | |
85 // is stopped. | |
86 virtual void WillDestroyCurrentMessageLoop(); | |
87 | |
88 private: | |
89 // A shared memory segment and its allocated size. | |
90 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.
| |
91 SHMBuffer(base::SharedMemory* m, size_t s); | |
92 ~SHMBuffer(); | |
93 base::SharedMemory* shm; | |
94 size_t size; | |
95 }; | |
96 | |
97 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.
| |
98 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.
| |
99 ~BufferData(); | |
100 int32 bitstream_buffer_id; | |
101 uint32_t timestamp; // in 90KHz | |
102 uint32_t width; | |
103 uint32_t height; | |
104 size_t size; // buffer size | |
105 }; | |
106 | |
107 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
| |
108 | |
109 // Requests a buffer to be decoded. | |
110 void RequestBufferDecode(); | |
111 | |
112 bool CanMoreDecodeWorkBeDone(); | |
113 | |
114 // Resets VDA. | |
115 void ResetInternal(); | |
116 | |
117 // Destroys VDA and the textures. | |
118 void ReleaseInternal(); | |
119 | |
120 // Tells VDA that a picture buffer can be recycled. | |
121 void ReusePictureBuffer(int64 picture_buffer_id); | |
122 | |
123 // Waits for |decoder_waiter_| or |aborted_waiter_| to be signaled. | |
124 void Wait(); | |
125 | |
126 void DestroyTextures(); | |
127 void DestroyVDA(); | |
128 | |
129 // Requests a shared-memory segment of at least |min_size| bytes. Will | |
130 // allocate as necessary. Caller does not own returned pointer. | |
131 SHMBuffer* GetSHM(size_t min_size); | |
132 | |
133 // Returns a shared-memory segment to the available pool. | |
134 void PutSHM(SHMBuffer* shm_buffer); | |
135 | |
136 // Stores the buffer data to |input_buffer_data_|. | |
137 void RecordBufferData(const BufferData& buffer_data); | |
138 // Gets the buffer data from |input_buffer_data_|. | |
139 void GetBufferData(int32 bitstream_buffer_id, uint32_t* timestamp, | |
140 uint32_t* width, uint32_t* height, size_t *size); | |
141 | |
142 enum State { | |
143 kUninitialized, // The decoder has not initialized. | |
144 kInitialized, // The decoder has initialized. | |
145 kDecodeError, // Decoding error happened. | |
146 }; | |
147 | |
148 // The hardware video decoder. | |
149 scoped_ptr<media::VideoDecodeAccelerator> vda_; | |
150 | |
151 // Used to wait for VDA calls to complete in InitDecode(), Release() and | |
152 // Reset(). | |
153 base::WaitableEvent decoder_waiter_; | |
154 | |
155 // An event signaled when the thread running |vda_loop_proxy_| is stopped. | |
156 base::WaitableEvent aborted_waiter_; | |
157 | |
158 // The size of the incoming video frames. | |
159 int32_t frame_width_; | |
160 int32_t frame_height_; | |
161 | |
162 // Protects |state_|, |decode_complete_callback_| , |available_shm_segments_|, | |
163 // 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.
| |
164 base::Lock lock_; | |
165 | |
166 // The state of RTCVideoDecoder. Guarded by |lock_|. | |
167 State state_; | |
168 | |
169 // Guarded by |lock_|. | |
170 webrtc::DecodedImageCallback* decode_complete_callback_; | |
171 | |
172 // Shared-memory buffer pool. Since allocating SHM segments requires a | |
173 // round-trip to the browser process, we keep allocation out of the | |
174 // steady-state of the decoder. Guarded by |lock_|. | |
175 std::vector<SHMBuffer*> available_shm_segments_; | |
176 | |
177 // 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.
| |
178 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; | |
179 base::WeakPtr<RTCVideoDecoder> weak_this_; | |
180 | |
181 scoped_refptr<media::GpuVideoDecoder::Factories> factories_; | |
182 | |
183 // 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.
| |
184 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; | |
185 | |
186 // The texture target used for decoded pictures. | |
187 uint32 decoder_texture_target_; | |
188 | |
189 // The data of the buffers that are in VDA. | |
190 std::list<BufferData> input_buffer_data_; | |
191 | |
192 // A queue storing buffers (and their data) that will be sent to VDA for | |
193 // 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.
| |
194 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.
| |
195 | |
196 // A map from bitstream buffer IDs to bitstream buffers that are being | |
197 // processed by VDA. | |
198 std::map<int32, SHMBuffer*> bitstream_buffers_in_decoder_; | |
199 | |
200 // A map from picture buffer IDs to texture-backed picture buffers. | |
201 std::map<int32, media::PictureBuffer> picture_buffers_in_decoder_; | |
202 | |
203 int32 next_picture_buffer_id_; | |
204 int32 next_bitstream_buffer_id_; | |
205 | |
206 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); | |
207 }; | |
208 | |
209 } // namespace content | |
210 | |
211 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ | |
OLD | NEW |