OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ |
6 #define MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ | 6 #define MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "media/base/pipeline_status.h" | 15 #include "media/base/pipeline_status.h" |
16 #include "media/base/demuxer_stream.h" | |
17 #include "media/base/video_decoder.h" | 16 #include "media/base/video_decoder.h" |
18 #include "media/video/video_decode_accelerator.h" | 17 #include "media/video/video_decode_accelerator.h" |
19 | 18 |
20 template <class T> class scoped_refptr; | 19 template <class T> class scoped_refptr; |
21 | 20 |
22 namespace base { | 21 namespace base { |
23 class MessageLoopProxy; | 22 class MessageLoopProxy; |
24 class SharedMemory; | 23 class SharedMemory; |
25 } | 24 } |
26 | 25 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 74 |
76 protected: | 75 protected: |
77 friend class base::RefCountedThreadSafe<Factories>; | 76 friend class base::RefCountedThreadSafe<Factories>; |
78 virtual ~Factories(); | 77 virtual ~Factories(); |
79 }; | 78 }; |
80 | 79 |
81 GpuVideoDecoder(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 80 GpuVideoDecoder(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
82 const scoped_refptr<Factories>& factories); | 81 const scoped_refptr<Factories>& factories); |
83 | 82 |
84 // VideoDecoder implementation. | 83 // VideoDecoder implementation. |
85 virtual void Initialize(DemuxerStream* stream, | 84 virtual void Initialize(const VideoDecoderConfig& config, |
86 const PipelineStatusCB& status_cb, | 85 const PipelineStatusCB& status_cb, |
87 const StatisticsCB& statistics_cb) OVERRIDE; | 86 const StatisticsCB& statistics_cb) OVERRIDE; |
88 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 87 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 88 const ReadCB& read_cb) OVERRIDE; |
89 virtual void Reset(const base::Closure& closure) OVERRIDE; | 89 virtual void Reset(const base::Closure& closure) OVERRIDE; |
90 virtual void Stop(const base::Closure& closure) OVERRIDE; | 90 virtual void Stop(const base::Closure& closure) OVERRIDE; |
91 virtual bool HasAlpha() const OVERRIDE; | 91 virtual bool HasAlpha() const OVERRIDE; |
92 virtual bool NeedsBitstreamConversion() const OVERRIDE; | 92 virtual bool NeedsBitstreamConversion() const OVERRIDE; |
93 virtual bool CanReadWithoutStalling() const OVERRIDE; | 93 virtual bool CanReadWithoutStalling() const OVERRIDE; |
94 | 94 |
95 // VideoDecodeAccelerator::Client implementation. | 95 // VideoDecodeAccelerator::Client implementation. |
96 virtual void NotifyInitializeDone() OVERRIDE; | 96 virtual void NotifyInitializeDone() OVERRIDE; |
97 virtual void ProvidePictureBuffers(uint32 count, | 97 virtual void ProvidePictureBuffers(uint32 count, |
98 const gfx::Size& size, | 98 const gfx::Size& size, |
99 uint32 texture_target) OVERRIDE; | 99 uint32 texture_target) OVERRIDE; |
100 virtual void DismissPictureBuffer(int32 id) OVERRIDE; | 100 virtual void DismissPictureBuffer(int32 id) OVERRIDE; |
101 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | 101 virtual void PictureReady(const media::Picture& picture) OVERRIDE; |
102 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; | 102 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; |
103 virtual void NotifyFlushDone() OVERRIDE; | 103 virtual void NotifyFlushDone() OVERRIDE; |
104 virtual void NotifyResetDone() OVERRIDE; | 104 virtual void NotifyResetDone() OVERRIDE; |
105 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; | 105 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; |
106 | 106 |
107 protected: | 107 protected: |
108 virtual ~GpuVideoDecoder(); | 108 virtual ~GpuVideoDecoder(); |
109 | 109 |
110 private: | 110 private: |
111 enum State { | 111 enum State { |
112 kNormal, | 112 kNormal, |
113 kDrainingDecoder, | 113 kDrainingDecoder, |
114 kDecoderDrained, | 114 kDecoderDrained, |
115 kError | 115 kError |
116 }; | 116 }; |
117 | 117 |
118 // If no demuxer read is in flight and no bitstream buffers are in the | |
119 // decoder, kick some off demuxing/decoding. | |
120 void EnsureDemuxOrDecode(); | |
121 | |
122 // Return true if more decode work can be piled on to the VDA. | 118 // Return true if more decode work can be piled on to the VDA. |
123 bool CanMoreDecodeWorkBeDone(); | 119 bool CanMoreDecodeWorkBeDone(); |
124 | 120 |
125 // Callback to pass to demuxer_stream_->Read() for receiving encoded bits. | |
126 void RequestBufferDecode(DemuxerStream::Status status, | |
127 const scoped_refptr<DecoderBuffer>& buffer); | |
128 | |
129 // Enqueue a frame for later delivery (or drop it on the floor if a | 121 // Enqueue a frame for later delivery (or drop it on the floor if a |
130 // vda->Reset() is in progress) and trigger out-of-line delivery of the oldest | 122 // vda->Reset() is in progress) and trigger out-of-line delivery of the oldest |
131 // ready frame to the client if there is a pending read. A NULL |frame| | 123 // ready frame to the client if there is a pending read. A NULL |frame| |
132 // merely triggers delivery, and requires the ready_video_frames_ queue not be | 124 // merely triggers delivery, and requires the ready_video_frames_ queue not be |
133 // empty. | 125 // empty. |
134 void EnqueueFrameAndTriggerFrameDelivery( | 126 void EnqueueFrameAndTriggerFrameDelivery( |
135 const scoped_refptr<VideoFrame>& frame); | 127 const scoped_refptr<VideoFrame>& frame); |
136 | 128 |
137 // Indicate the picture buffer can be reused by the decoder. | 129 // Indicate the picture buffer can be reused by the decoder. |
138 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); | 130 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); |
(...skipping 24 matching lines...) Expand all Loading... |
163 // allocate as necessary. Caller does not own returned pointer. | 155 // allocate as necessary. Caller does not own returned pointer. |
164 SHMBuffer* GetSHM(size_t min_size); | 156 SHMBuffer* GetSHM(size_t min_size); |
165 | 157 |
166 // Return a shared-memory segment to the available pool. | 158 // Return a shared-memory segment to the available pool. |
167 void PutSHM(SHMBuffer* shm_buffer); | 159 void PutSHM(SHMBuffer* shm_buffer); |
168 | 160 |
169 void DestroyTextures(); | 161 void DestroyTextures(); |
170 | 162 |
171 StatisticsCB statistics_cb_; | 163 StatisticsCB statistics_cb_; |
172 | 164 |
173 // Pointer to the demuxer stream that will feed us compressed buffers. | |
174 DemuxerStream* demuxer_stream_; | |
175 | 165 |
176 bool needs_bitstream_conversion_; | 166 bool needs_bitstream_conversion_; |
177 | 167 |
178 // Message loop on which to fire callbacks and trampoline calls to this class | 168 // Message loop on which to fire callbacks and trampoline calls to this class |
179 // if they arrive on other loops. | 169 // if they arrive on other loops. |
180 scoped_refptr<base::MessageLoopProxy> gvd_loop_proxy_; | 170 scoped_refptr<base::MessageLoopProxy> gvd_loop_proxy_; |
181 base::WeakPtrFactory<GpuVideoDecoder> weak_factory_; | 171 base::WeakPtrFactory<GpuVideoDecoder> weak_factory_; |
182 base::WeakPtr<GpuVideoDecoder> weak_this_; | 172 base::WeakPtr<GpuVideoDecoder> weak_this_; |
183 | 173 |
184 // Message loop on which to makes all calls to vda_. (beware this loop may be | 174 // Message loop on which to makes all calls to vda_. (beware this loop may be |
(...skipping 13 matching lines...) Expand all Loading... |
198 // Used to post tasks from the GVD thread to the VDA thread safely. | 188 // Used to post tasks from the GVD thread to the VDA thread safely. |
199 base::WeakPtr<VideoDecodeAccelerator> weak_vda_; | 189 base::WeakPtr<VideoDecodeAccelerator> weak_vda_; |
200 | 190 |
201 // Callbacks that are !is_null() only during their respective operation being | 191 // Callbacks that are !is_null() only during their respective operation being |
202 // asynchronously executed. | 192 // asynchronously executed. |
203 ReadCB pending_read_cb_; | 193 ReadCB pending_read_cb_; |
204 base::Closure pending_reset_cb_; | 194 base::Closure pending_reset_cb_; |
205 | 195 |
206 State state_; | 196 State state_; |
207 | 197 |
| 198 VideoDecoderConfig config_; |
| 199 |
208 // Is a demuxer read in flight? | 200 // Is a demuxer read in flight? |
209 bool demuxer_read_in_progress_; | 201 bool demuxer_read_in_progress_; |
210 | 202 |
211 // Shared-memory buffer pool. Since allocating SHM segments requires a | 203 // Shared-memory buffer pool. Since allocating SHM segments requires a |
212 // round-trip to the browser process, we keep allocation out of the | 204 // round-trip to the browser process, we keep allocation out of the |
213 // steady-state of the decoder. | 205 // steady-state of the decoder. |
214 std::vector<SHMBuffer*> available_shm_segments_; | 206 std::vector<SHMBuffer*> available_shm_segments_; |
215 | 207 |
216 // Book-keeping variables. | 208 // Book-keeping variables. |
217 struct BufferPair { | 209 struct BufferPair { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // Set during ProvidePictureBuffers(), used for checking and implementing | 243 // Set during ProvidePictureBuffers(), used for checking and implementing |
252 // HasAvailableOutputFrames(). | 244 // HasAvailableOutputFrames(). |
253 int available_pictures_; | 245 int available_pictures_; |
254 | 246 |
255 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder); | 247 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder); |
256 }; | 248 }; |
257 | 249 |
258 } // namespace media | 250 } // namespace media |
259 | 251 |
260 #endif // MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ | 252 #endif // MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ |
OLD | NEW |