OLD | NEW |
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 <list> |
9 #include <map> | 10 #include <map> |
10 #include <set> | 11 #include <set> |
11 #include <utility> | 12 #include <utility> |
12 | 13 |
13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
14 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/synchronization/waitable_event.h" | |
19 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
20 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
21 #include "media/base/bitstream_buffer.h" | 20 #include "media/base/bitstream_buffer.h" |
22 #include "media/base/video_decoder.h" | 21 #include "media/base/video_decoder.h" |
23 #include "media/video/picture.h" | 22 #include "media/video/picture.h" |
24 #include "media/video/video_decode_accelerator.h" | 23 #include "media/video/video_decode_accelerator.h" |
25 #include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_i
nterface.h" | 24 #include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_i
nterface.h" |
26 | 25 |
27 namespace base { | 26 namespace base { |
| 27 class WaitableEvent; |
28 class MessageLoopProxy; | 28 class MessageLoopProxy; |
29 }; | 29 }; |
30 | 30 |
31 namespace gpu { | 31 namespace gpu { |
32 struct MailboxHolder; | 32 struct MailboxHolder; |
33 } | 33 } |
34 | 34 |
35 namespace media { | 35 namespace media { |
36 class DecoderBuffer; | 36 class DecoderBuffer; |
37 class GpuVideoAcceleratorFactories; | 37 class GpuVideoAcceleratorFactories; |
38 } | 38 } |
39 | 39 |
40 namespace content { | 40 namespace content { |
41 | 41 |
42 // This class uses hardware accelerated video decoder to decode video for | 42 // This class uses hardware accelerated video decoder to decode video for |
43 // WebRTC. |vda_message_loop_| is the message loop proxy of the media thread, | 43 // WebRTC. |vda_message_loop_| is the message loop proxy of the media thread, |
44 // which VDA::Client methods run on. webrtc::VideoDecoder methods run on WebRTC | 44 // which VDA::Client methods run on. webrtc::VideoDecoder methods run on WebRTC |
45 // DecodingThread or Chrome_libJingle_WorkerThread, which are trampolined to | 45 // DecodingThread or Chrome_libJingle_WorkerThread, which are trampolined to |
46 // |vda_message_loop_|. Decode() is non-blocking and queues the buffers. Decoded | 46 // |vda_message_loop_|. Decode() is non-blocking and queues the buffers. Decoded |
47 // frames are delivered to WebRTC on |vda_message_loop_|. | 47 // frames are delivered to WebRTC on |vda_message_loop_|. |
48 class CONTENT_EXPORT RTCVideoDecoder | 48 class CONTENT_EXPORT RTCVideoDecoder |
49 : NON_EXPORTED_BASE(public webrtc::VideoDecoder), | 49 : NON_EXPORTED_BASE(public webrtc::VideoDecoder), |
50 public media::VideoDecodeAccelerator::Client, | 50 public media::VideoDecodeAccelerator::Client { |
51 public base::MessageLoop::DestructionObserver { | |
52 public: | 51 public: |
53 virtual ~RTCVideoDecoder(); | 52 virtual ~RTCVideoDecoder(); |
54 | 53 |
55 // Creates a RTCVideoDecoder. Returns NULL if failed. The video decoder will | 54 // Creates a RTCVideoDecoder. Returns NULL if failed. The video decoder will |
56 // run on the message loop of |factories|. | 55 // run on the message loop of |factories|. |
57 static scoped_ptr<RTCVideoDecoder> Create( | 56 static scoped_ptr<RTCVideoDecoder> Create( |
58 webrtc::VideoCodecType type, | 57 webrtc::VideoCodecType type, |
59 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); | 58 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); |
60 | 59 |
61 // webrtc::VideoDecoder implementation. | 60 // webrtc::VideoDecoder implementation. |
(...skipping 22 matching lines...) Expand all Loading... |
84 virtual void ProvidePictureBuffers(uint32 count, | 83 virtual void ProvidePictureBuffers(uint32 count, |
85 const gfx::Size& size, | 84 const gfx::Size& size, |
86 uint32 texture_target) OVERRIDE; | 85 uint32 texture_target) OVERRIDE; |
87 virtual void DismissPictureBuffer(int32 id) OVERRIDE; | 86 virtual void DismissPictureBuffer(int32 id) OVERRIDE; |
88 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | 87 virtual void PictureReady(const media::Picture& picture) OVERRIDE; |
89 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; | 88 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; |
90 virtual void NotifyFlushDone() OVERRIDE; | 89 virtual void NotifyFlushDone() OVERRIDE; |
91 virtual void NotifyResetDone() OVERRIDE; | 90 virtual void NotifyResetDone() OVERRIDE; |
92 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; | 91 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; |
93 | 92 |
94 // base::DestructionObserver implementation. Called when |vda_message_loop_| | |
95 // is stopped. | |
96 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | |
97 | |
98 private: | 93 private: |
99 class SHMBuffer; | 94 class SHMBuffer; |
100 // Metadata of a bitstream buffer. | 95 // Metadata of a bitstream buffer. |
101 struct BufferData { | 96 struct BufferData { |
102 BufferData(int32 bitstream_buffer_id, | 97 BufferData(int32 bitstream_buffer_id, |
103 uint32_t timestamp, | 98 uint32_t timestamp, |
104 int width, | 99 int width, |
105 int height, | 100 int height, |
106 size_t size); | 101 size_t size); |
107 BufferData(); | 102 BufferData(); |
108 ~BufferData(); | 103 ~BufferData(); |
109 int32 bitstream_buffer_id; | 104 int32 bitstream_buffer_id; |
110 uint32_t timestamp; // in 90KHz | 105 uint32_t timestamp; // in 90KHz |
111 uint32_t width; | 106 uint32_t width; |
112 uint32_t height; | 107 uint32_t height; |
113 size_t size; // buffer size | 108 size_t size; // buffer size |
114 }; | 109 }; |
115 | 110 |
116 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); | 111 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); |
117 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset); | 112 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset); |
118 | 113 |
119 // The meessage loop of |factories| will be saved to |vda_task_runner_|. | 114 // The meessage loop of |factories| will be saved to |vda_task_runner_|. |
120 RTCVideoDecoder( | 115 RTCVideoDecoder( |
121 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); | 116 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); |
122 | 117 |
123 void Initialize(base::WaitableEvent* waiter); | |
124 | |
125 // Requests a buffer to be decoded by VDA. | 118 // Requests a buffer to be decoded by VDA. |
126 void RequestBufferDecode(); | 119 void RequestBufferDecode(); |
127 | 120 |
128 bool CanMoreDecodeWorkBeDone(); | 121 bool CanMoreDecodeWorkBeDone(); |
129 | 122 |
130 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|. | 123 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|. |
131 // This handles the wraparound. | 124 // This handles the wraparound. |
132 bool IsBufferAfterReset(int32 id_buffer, int32 id_reset); | 125 bool IsBufferAfterReset(int32 id_buffer, int32 id_reset); |
133 | 126 |
134 // Returns true if bitstream buffer |id_buffer| is the first buffer after | 127 // Returns true if bitstream buffer |id_buffer| is the first buffer after |
(...skipping 21 matching lines...) Expand all Loading... |
156 uint32_t height, | 149 uint32_t height, |
157 size_t size); | 150 size_t size); |
158 | 151 |
159 // Resets VDA. | 152 // Resets VDA. |
160 void ResetInternal(); | 153 void ResetInternal(); |
161 | 154 |
162 // Tells VDA that a picture buffer can be recycled. | 155 // Tells VDA that a picture buffer can be recycled. |
163 void ReusePictureBuffer(int64 picture_buffer_id, | 156 void ReusePictureBuffer(int64 picture_buffer_id, |
164 scoped_ptr<gpu::MailboxHolder> mailbox_holder); | 157 scoped_ptr<gpu::MailboxHolder> mailbox_holder); |
165 | 158 |
| 159 // Create |vda_| on |vda_loop_proxy_|. |
| 160 void CreateVDA(media::VideoCodecProfile profile, base::WaitableEvent* waiter); |
| 161 |
166 void DestroyTextures(); | 162 void DestroyTextures(); |
167 void DestroyVDA(); | 163 void DestroyVDA(); |
168 | 164 |
169 // Gets a shared-memory segment of at least |min_size| bytes from | 165 // Gets a shared-memory segment of at least |min_size| bytes from |
170 // |available_shm_segments_|. Returns NULL if there is no buffer or the | 166 // |available_shm_segments_|. Returns NULL if there is no buffer or the |
171 // buffer is not big enough. | 167 // buffer is not big enough. |
172 scoped_ptr<SHMBuffer> GetSHM_Locked(size_t min_size); | 168 scoped_ptr<SHMBuffer> GetSHM_Locked(size_t min_size); |
173 | 169 |
174 // Returns a shared-memory segment to the available pool. | 170 // Returns a shared-memory segment to the available pool. |
175 void PutSHM_Locked(scoped_ptr<SHMBuffer> shm_buffer); | 171 void PutSHM_Locked(scoped_ptr<SHMBuffer> shm_buffer); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // Factory used to populate |weak_this_|. Must be destroyed, or invalidated, | 272 // Factory used to populate |weak_this_|. Must be destroyed, or invalidated, |
277 // on |vda_loop_proxy_|. | 273 // on |vda_loop_proxy_|. |
278 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; | 274 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; |
279 | 275 |
280 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); | 276 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); |
281 }; | 277 }; |
282 | 278 |
283 } // namespace content | 279 } // namespace content |
284 | 280 |
285 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ | 281 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ |
OLD | NEW |