| 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 media { | 31 namespace media { |
| 32 class DecoderBuffer; | 32 class DecoderBuffer; |
| 33 class GpuVideoAcceleratorFactories; | 33 class GpuVideoAcceleratorFactories; |
| 34 } | 34 } |
| 35 | 35 |
| 36 namespace content { | 36 namespace content { |
| 37 | 37 |
| 38 // This class uses hardware accelerated video decoder to decode video for | 38 // This class uses hardware accelerated video decoder to decode video for |
| 39 // WebRTC. |vda_message_loop_| is the message loop proxy of the media thread, | 39 // WebRTC. |vda_message_loop_| is the message loop proxy of the media thread, |
| 40 // which VDA::Client methods run on. webrtc::VideoDecoder methods run on WebRTC | 40 // which VDA::Client methods run on. webrtc::VideoDecoder methods run on WebRTC |
| 41 // DecodingThread or Chrome_libJingle_WorkerThread, which are trampolined to | 41 // DecodingThread or Chrome_libJingle_WorkerThread, which are trampolined to |
| 42 // |vda_message_loop_|. Decode() is non-blocking and queues the buffers. Decoded | 42 // |vda_message_loop_|. Decode() is non-blocking and queues the buffers. Decoded |
| 43 // frames are delivered to WebRTC on |vda_message_loop_|. | 43 // frames are delivered to WebRTC on |vda_message_loop_|. |
| 44 class CONTENT_EXPORT RTCVideoDecoder | 44 class CONTENT_EXPORT RTCVideoDecoder |
| 45 : NON_EXPORTED_BASE(public webrtc::VideoDecoder), | 45 : NON_EXPORTED_BASE(public webrtc::VideoDecoder), |
| 46 public media::VideoDecodeAccelerator::Client, | 46 public media::VideoDecodeAccelerator::Client { |
| 47 public base::MessageLoop::DestructionObserver { | |
| 48 public: | 47 public: |
| 49 virtual ~RTCVideoDecoder(); | 48 virtual ~RTCVideoDecoder(); |
| 50 | 49 |
| 51 // Creates a RTCVideoDecoder. Returns NULL if failed. The video decoder will | 50 // Creates a RTCVideoDecoder. Returns NULL if failed. The video decoder will |
| 52 // run on the message loop of |factories|. | 51 // run on the message loop of |factories|. |
| 53 static scoped_ptr<RTCVideoDecoder> Create( | 52 static scoped_ptr<RTCVideoDecoder> Create( |
| 54 webrtc::VideoCodecType type, | 53 webrtc::VideoCodecType type, |
| 55 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); | 54 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); |
| 56 | 55 |
| 57 // webrtc::VideoDecoder implementation. | 56 // webrtc::VideoDecoder implementation. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 80 virtual void ProvidePictureBuffers(uint32 count, | 79 virtual void ProvidePictureBuffers(uint32 count, |
| 81 const gfx::Size& size, | 80 const gfx::Size& size, |
| 82 uint32 texture_target) OVERRIDE; | 81 uint32 texture_target) OVERRIDE; |
| 83 virtual void DismissPictureBuffer(int32 id) OVERRIDE; | 82 virtual void DismissPictureBuffer(int32 id) OVERRIDE; |
| 84 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | 83 virtual void PictureReady(const media::Picture& picture) OVERRIDE; |
| 85 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; | 84 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; |
| 86 virtual void NotifyFlushDone() OVERRIDE; | 85 virtual void NotifyFlushDone() OVERRIDE; |
| 87 virtual void NotifyResetDone() OVERRIDE; | 86 virtual void NotifyResetDone() OVERRIDE; |
| 88 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; | 87 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; |
| 89 | 88 |
| 90 // base::DestructionObserver implementation. Called when |vda_message_loop_| | |
| 91 // is stopped. | |
| 92 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | |
| 93 | |
| 94 private: | 89 private: |
| 95 class SHMBuffer; | 90 class SHMBuffer; |
| 96 // Metadata of a bitstream buffer. | 91 // Metadata of a bitstream buffer. |
| 97 struct BufferData { | 92 struct BufferData { |
| 98 BufferData(int32 bitstream_buffer_id, | 93 BufferData(int32 bitstream_buffer_id, |
| 99 uint32_t timestamp, | 94 uint32_t timestamp, |
| 100 int width, | 95 int width, |
| 101 int height, | 96 int height, |
| 102 size_t size); | 97 size_t size); |
| 103 BufferData(); | 98 BufferData(); |
| 104 ~BufferData(); | 99 ~BufferData(); |
| 105 int32 bitstream_buffer_id; | 100 int32 bitstream_buffer_id; |
| 106 uint32_t timestamp; // in 90KHz | 101 uint32_t timestamp; // in 90KHz |
| 107 uint32_t width; | 102 uint32_t width; |
| 108 uint32_t height; | 103 uint32_t height; |
| 109 size_t size; // buffer size | 104 size_t size; // buffer size |
| 110 }; | 105 }; |
| 111 | 106 |
| 112 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); | 107 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); |
| 113 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset); | 108 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset); |
| 114 | 109 |
| 115 // The meessage loop of |factories| will be saved to |vda_task_runner_|. | 110 // The meessage loop of |factories| will be saved to |vda_task_runner_|. |
| 116 RTCVideoDecoder( | 111 RTCVideoDecoder( |
| 117 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); | 112 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); |
| 118 | 113 |
| 119 void Initialize(base::WaitableEvent* waiter); | |
| 120 | |
| 121 // Requests a buffer to be decoded by VDA. | 114 // Requests a buffer to be decoded by VDA. |
| 122 void RequestBufferDecode(); | 115 void RequestBufferDecode(); |
| 123 | 116 |
| 124 bool CanMoreDecodeWorkBeDone(); | 117 bool CanMoreDecodeWorkBeDone(); |
| 125 | 118 |
| 126 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|. | 119 // Returns true if bitstream buffer id |id_buffer| comes after |id_reset|. |
| 127 // This handles the wraparound. | 120 // This handles the wraparound. |
| 128 bool IsBufferAfterReset(int32 id_buffer, int32 id_reset); | 121 bool IsBufferAfterReset(int32 id_buffer, int32 id_reset); |
| 129 | 122 |
| 130 // Returns true if bitstream buffer |id_buffer| is the first buffer after | 123 // Returns true if bitstream buffer |id_buffer| is the first buffer after |
| (...skipping 20 matching lines...) Expand all Loading... |
| 151 uint32_t width, | 144 uint32_t width, |
| 152 uint32_t height, | 145 uint32_t height, |
| 153 size_t size); | 146 size_t size); |
| 154 | 147 |
| 155 // Resets VDA. | 148 // Resets VDA. |
| 156 void ResetInternal(); | 149 void ResetInternal(); |
| 157 | 150 |
| 158 // Tells VDA that a picture buffer can be recycled. | 151 // Tells VDA that a picture buffer can be recycled. |
| 159 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); | 152 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); |
| 160 | 153 |
| 154 // Create |vda_| on |vda_loop_proxy_|. |
| 155 void CreateVDA(media::VideoCodecProfile profile, base::WaitableEvent* waiter); |
| 156 |
| 161 void DestroyTextures(); | 157 void DestroyTextures(); |
| 162 void DestroyVDA(); | 158 void DestroyVDA(); |
| 163 | 159 |
| 164 // Gets a shared-memory segment of at least |min_size| bytes from | 160 // Gets a shared-memory segment of at least |min_size| bytes from |
| 165 // |available_shm_segments_|. Returns NULL if there is no buffer or the | 161 // |available_shm_segments_|. Returns NULL if there is no buffer or the |
| 166 // buffer is not big enough. | 162 // buffer is not big enough. |
| 167 scoped_ptr<SHMBuffer> GetSHM_Locked(size_t min_size); | 163 scoped_ptr<SHMBuffer> GetSHM_Locked(size_t min_size); |
| 168 | 164 |
| 169 // Returns a shared-memory segment to the available pool. | 165 // Returns a shared-memory segment to the available pool. |
| 170 void PutSHM_Locked(scoped_ptr<SHMBuffer> shm_buffer); | 166 void PutSHM_Locked(scoped_ptr<SHMBuffer> shm_buffer); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 // Factory used to populate |weak_this_|. Must be destroyed, or invalidated, | 267 // Factory used to populate |weak_this_|. Must be destroyed, or invalidated, |
| 272 // on |vda_loop_proxy_|. | 268 // on |vda_loop_proxy_|. |
| 273 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; | 269 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; |
| 274 | 270 |
| 275 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); | 271 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); |
| 276 }; | 272 }; |
| 277 | 273 |
| 278 } // namespace content | 274 } // namespace content |
| 279 | 275 |
| 280 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ | 276 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ |
| OLD | NEW |