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

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

Issue 144303004: Revert of Revert of Revert of Remove threading from RendererGpuVideoAcceleratorFactories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dthread
Patch Set: Created 6 years, 10 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 <list>
10 #include <map> 9 #include <map>
11 #include <set> 10 #include <set>
12 #include <utility> 11 #include <utility>
13 12
14 #include "base/basictypes.h" 13 #include "base/basictypes.h"
15 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
16 #include "base/memory/weak_ptr.h" 15 #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"
18 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
19 #include "content/common/content_export.h" 20 #include "content/common/content_export.h"
20 #include "media/base/bitstream_buffer.h" 21 #include "media/base/bitstream_buffer.h"
21 #include "media/base/video_decoder.h" 22 #include "media/base/video_decoder.h"
22 #include "media/video/picture.h" 23 #include "media/video/picture.h"
23 #include "media/video/video_decode_accelerator.h" 24 #include "media/video/video_decode_accelerator.h"
24 #include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_i nterface.h" 25 #include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_i nterface.h"
25 26
26 namespace base { 27 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 {
47 public: 48 public:
48 virtual ~RTCVideoDecoder(); 49 virtual ~RTCVideoDecoder();
49 50
50 // Creates a RTCVideoDecoder. Returns NULL if failed. The video decoder will 51 // Creates a RTCVideoDecoder. Returns NULL if failed. The video decoder will
51 // run on the message loop of |factories|. 52 // run on the message loop of |factories|.
52 static scoped_ptr<RTCVideoDecoder> Create( 53 static scoped_ptr<RTCVideoDecoder> Create(
53 webrtc::VideoCodecType type, 54 webrtc::VideoCodecType type,
54 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); 55 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories);
55 56
56 // webrtc::VideoDecoder implementation. 57 // webrtc::VideoDecoder implementation.
(...skipping 22 matching lines...) Expand all
79 virtual void ProvidePictureBuffers(uint32 count, 80 virtual void ProvidePictureBuffers(uint32 count,
80 const gfx::Size& size, 81 const gfx::Size& size,
81 uint32 texture_target) OVERRIDE; 82 uint32 texture_target) OVERRIDE;
82 virtual void DismissPictureBuffer(int32 id) OVERRIDE; 83 virtual void DismissPictureBuffer(int32 id) OVERRIDE;
83 virtual void PictureReady(const media::Picture& picture) OVERRIDE; 84 virtual void PictureReady(const media::Picture& picture) OVERRIDE;
84 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; 85 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE;
85 virtual void NotifyFlushDone() OVERRIDE; 86 virtual void NotifyFlushDone() OVERRIDE;
86 virtual void NotifyResetDone() OVERRIDE; 87 virtual void NotifyResetDone() OVERRIDE;
87 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; 88 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE;
88 89
90 // base::DestructionObserver implementation. Called when |vda_message_loop_|
91 // is stopped.
92 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
93
89 private: 94 private:
90 class SHMBuffer; 95 class SHMBuffer;
91 // Metadata of a bitstream buffer. 96 // Metadata of a bitstream buffer.
92 struct BufferData { 97 struct BufferData {
93 BufferData(int32 bitstream_buffer_id, 98 BufferData(int32 bitstream_buffer_id,
94 uint32_t timestamp, 99 uint32_t timestamp,
95 int width, 100 int width,
96 int height, 101 int height,
97 size_t size); 102 size_t size);
98 BufferData(); 103 BufferData();
99 ~BufferData(); 104 ~BufferData();
100 int32 bitstream_buffer_id; 105 int32 bitstream_buffer_id;
101 uint32_t timestamp; // in 90KHz 106 uint32_t timestamp; // in 90KHz
102 uint32_t width; 107 uint32_t width;
103 uint32_t height; 108 uint32_t height;
104 size_t size; // buffer size 109 size_t size; // buffer size
105 }; 110 };
106 111
107 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset); 112 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsBufferAfterReset);
108 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset); 113 FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, IsFirstBufferAfterReset);
109 114
110 // The meessage loop of |factories| will be saved to |vda_task_runner_|. 115 // The meessage loop of |factories| will be saved to |vda_task_runner_|.
111 RTCVideoDecoder( 116 RTCVideoDecoder(
112 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories); 117 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories);
113 118
119 void Initialize(base::WaitableEvent* waiter);
120
114 // Requests a buffer to be decoded by VDA. 121 // Requests a buffer to be decoded by VDA.
115 void RequestBufferDecode(); 122 void RequestBufferDecode();
116 123
117 bool CanMoreDecodeWorkBeDone(); 124 bool CanMoreDecodeWorkBeDone();
118 125
119 // 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|.
120 // This handles the wraparound. 127 // This handles the wraparound.
121 bool IsBufferAfterReset(int32 id_buffer, int32 id_reset); 128 bool IsBufferAfterReset(int32 id_buffer, int32 id_reset);
122 129
123 // Returns true if bitstream buffer |id_buffer| is the first buffer after 130 // Returns true if bitstream buffer |id_buffer| is the first buffer after
(...skipping 20 matching lines...) Expand all
144 uint32_t width, 151 uint32_t width,
145 uint32_t height, 152 uint32_t height,
146 size_t size); 153 size_t size);
147 154
148 // Resets VDA. 155 // Resets VDA.
149 void ResetInternal(); 156 void ResetInternal();
150 157
151 // Tells VDA that a picture buffer can be recycled. 158 // Tells VDA that a picture buffer can be recycled.
152 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); 159 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point);
153 160
154 // Create |vda_| on |vda_loop_proxy_|.
155 void CreateVDA(media::VideoCodecProfile profile, base::WaitableEvent* waiter);
156
157 void DestroyTextures(); 161 void DestroyTextures();
158 void DestroyVDA(); 162 void DestroyVDA();
159 163
160 // Gets a shared-memory segment of at least |min_size| bytes from 164 // Gets a shared-memory segment of at least |min_size| bytes from
161 // |available_shm_segments_|. Returns NULL if there is no buffer or the 165 // |available_shm_segments_|. Returns NULL if there is no buffer or the
162 // buffer is not big enough. 166 // buffer is not big enough.
163 scoped_ptr<SHMBuffer> GetSHM_Locked(size_t min_size); 167 scoped_ptr<SHMBuffer> GetSHM_Locked(size_t min_size);
164 168
165 // Returns a shared-memory segment to the available pool. 169 // Returns a shared-memory segment to the available pool.
166 void PutSHM_Locked(scoped_ptr<SHMBuffer> shm_buffer); 170 void PutSHM_Locked(scoped_ptr<SHMBuffer> shm_buffer);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // Factory used to populate |weak_this_|. Must be destroyed, or invalidated, 271 // Factory used to populate |weak_this_|. Must be destroyed, or invalidated,
268 // on |vda_loop_proxy_|. 272 // on |vda_loop_proxy_|.
269 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; 273 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_;
270 274
271 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); 275 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder);
272 }; 276 };
273 277
274 } // namespace content 278 } // namespace content
275 279
276 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ 280 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/renderer_gpu_video_accelerator_factories.cc ('k') | content/renderer/media/rtc_video_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698