Chromium Code Reviews| 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> |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 : public VideoDecoder, | 37 : public VideoDecoder, |
| 38 public VideoDecodeAccelerator::Client { | 38 public VideoDecodeAccelerator::Client { |
| 39 public: | 39 public: |
| 40 explicit GpuVideoDecoder( | 40 explicit GpuVideoDecoder( |
| 41 const scoped_refptr<GpuVideoAcceleratorFactories>& factories, | 41 const scoped_refptr<GpuVideoAcceleratorFactories>& factories, |
| 42 const scoped_refptr<MediaLog>& media_log); | 42 const scoped_refptr<MediaLog>& media_log); |
| 43 | 43 |
| 44 // VideoDecoder implementation. | 44 // VideoDecoder implementation. |
| 45 virtual void Initialize(const VideoDecoderConfig& config, | 45 virtual void Initialize(const VideoDecoderConfig& config, |
| 46 bool live_mode, | 46 bool live_mode, |
| 47 const PipelineStatusCB& status_cb) OVERRIDE; | 47 const PipelineStatusCB& status_cb, |
| 48 const OutputCB& output_cb) OVERRIDE; | |
| 48 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 49 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 49 const DecodeCB& decode_cb) OVERRIDE; | 50 const DecodeCB& decode_cb) OVERRIDE; |
| 50 virtual void Reset(const base::Closure& closure) OVERRIDE; | 51 virtual void Reset(const base::Closure& closure) OVERRIDE; |
| 51 virtual void Stop() OVERRIDE; | 52 virtual void Stop() OVERRIDE; |
| 52 virtual bool NeedsBitstreamConversion() const OVERRIDE; | 53 virtual bool NeedsBitstreamConversion() const OVERRIDE; |
| 53 virtual bool CanReadWithoutStalling() const OVERRIDE; | 54 virtual bool CanReadWithoutStalling() const OVERRIDE; |
| 55 virtual int GetMaxDecodeRequests() const OVERRIDE; | |
| 54 | 56 |
| 55 // VideoDecodeAccelerator::Client implementation. | 57 // VideoDecodeAccelerator::Client implementation. |
| 56 virtual void ProvidePictureBuffers(uint32 count, | 58 virtual void ProvidePictureBuffers(uint32 count, |
| 57 const gfx::Size& size, | 59 const gfx::Size& size, |
| 58 uint32 texture_target) OVERRIDE; | 60 uint32 texture_target) OVERRIDE; |
| 59 virtual void DismissPictureBuffer(int32 id) OVERRIDE; | 61 virtual void DismissPictureBuffer(int32 id) OVERRIDE; |
| 60 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | 62 virtual void PictureReady(const media::Picture& picture) OVERRIDE; |
| 61 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; | 63 virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; |
| 62 virtual void NotifyFlushDone() OVERRIDE; | 64 virtual void NotifyFlushDone() OVERRIDE; |
| 63 virtual void NotifyResetDone() OVERRIDE; | 65 virtual void NotifyResetDone() OVERRIDE; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 76 | 78 |
| 77 // A shared memory segment and its allocated size. | 79 // A shared memory segment and its allocated size. |
| 78 struct SHMBuffer { | 80 struct SHMBuffer { |
| 79 SHMBuffer(base::SharedMemory* m, size_t s); | 81 SHMBuffer(base::SharedMemory* m, size_t s); |
| 80 ~SHMBuffer(); | 82 ~SHMBuffer(); |
| 81 base::SharedMemory* shm; | 83 base::SharedMemory* shm; |
| 82 size_t size; | 84 size_t size; |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 // A SHMBuffer and the DecoderBuffer its data came from. | 87 // A SHMBuffer and the DecoderBuffer its data came from. |
| 86 struct BufferPair { | 88 struct PendingDecodeBuffer { |
|
xhwang
2014/05/29 22:15:14
Shall this be PendingDecode-r-Buffer?
Sergey Ulanov
2014/06/03 00:08:11
Yes
| |
| 87 BufferPair(SHMBuffer* s, const scoped_refptr<DecoderBuffer>& b); | 89 PendingDecodeBuffer(SHMBuffer* s, |
| 88 ~BufferPair(); | 90 const scoped_refptr<DecoderBuffer>& b, |
| 91 const DecodeCB& done_cb); | |
| 92 ~PendingDecodeBuffer(); | |
| 89 SHMBuffer* shm_buffer; | 93 SHMBuffer* shm_buffer; |
| 90 scoped_refptr<DecoderBuffer> buffer; | 94 scoped_refptr<DecoderBuffer> buffer; |
| 95 DecodeCB done_cb; | |
| 91 }; | 96 }; |
| 92 | 97 |
| 93 typedef std::map<int32, PictureBuffer> PictureBufferMap; | 98 typedef std::map<int32, PictureBuffer> PictureBufferMap; |
| 94 | 99 |
| 95 // Return true if more decode work can be piled on to the VDA. | 100 void DeliverFrame( const scoped_refptr<VideoFrame>& frame); |
|
xhwang
2014/05/29 22:15:14
nit: drop extra space before "const"
Sergey Ulanov
2014/06/03 00:08:11
Done.
| |
| 96 bool CanMoreDecodeWorkBeDone(); | |
| 97 | |
| 98 // Enqueue a frame for later delivery (or drop it on the floor if a | |
| 99 // vda->Reset() is in progress) and trigger out-of-line delivery of the oldest | |
| 100 // ready frame to the client if there is a pending read. A NULL |frame| | |
| 101 // merely triggers delivery, and requires the ready_video_frames_ queue not be | |
| 102 // empty. | |
| 103 void EnqueueFrameAndTriggerFrameDelivery( | |
| 104 const scoped_refptr<VideoFrame>& frame); | |
| 105 | 101 |
| 106 // Static method is to allow it to run even after GVD is deleted. | 102 // Static method is to allow it to run even after GVD is deleted. |
| 107 static void ReleaseMailbox( | 103 static void ReleaseMailbox( |
| 108 base::WeakPtr<GpuVideoDecoder> decoder, | 104 base::WeakPtr<GpuVideoDecoder> decoder, |
| 109 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, | 105 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, |
| 110 int64 picture_buffer_id, | 106 int64 picture_buffer_id, |
| 111 uint32 texture_id, | 107 uint32 texture_id, |
| 112 const std::vector<uint32>& release_sync_points); | 108 const std::vector<uint32>& release_sync_points); |
| 113 // Indicate the picture buffer can be reused by the decoder. | 109 // Indicate the picture buffer can be reused by the decoder. |
| 114 void ReusePictureBuffer(int64 picture_buffer_id); | 110 void ReusePictureBuffer(int64 picture_buffer_id); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 134 void DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() const; | 130 void DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() const; |
| 135 | 131 |
| 136 bool needs_bitstream_conversion_; | 132 bool needs_bitstream_conversion_; |
| 137 | 133 |
| 138 scoped_refptr<GpuVideoAcceleratorFactories> factories_; | 134 scoped_refptr<GpuVideoAcceleratorFactories> factories_; |
| 139 | 135 |
| 140 // Populated during Initialize() (on success) and unchanged until an error | 136 // Populated during Initialize() (on success) and unchanged until an error |
| 141 // occurs. | 137 // occurs. |
| 142 scoped_ptr<VideoDecodeAccelerator> vda_; | 138 scoped_ptr<VideoDecodeAccelerator> vda_; |
| 143 | 139 |
| 144 // Callbacks that are !is_null() only during their respective operation being | 140 OutputCB output_cb_; |
| 145 // asynchronously executed. | 141 |
| 146 DecodeCB pending_decode_cb_; | 142 DecodeCB flush_cb_; |
|
xhwang
2014/05/29 22:15:14
Usually people associate "flush" with "Reset". So
Sergey Ulanov
2014/06/03 00:08:11
I think Flush and Reset are distinct operations. V
| |
| 143 | |
| 144 // Not null only during reset. | |
| 147 base::Closure pending_reset_cb_; | 145 base::Closure pending_reset_cb_; |
| 148 | 146 |
| 149 State state_; | 147 State state_; |
| 150 | 148 |
| 151 VideoDecoderConfig config_; | 149 VideoDecoderConfig config_; |
| 152 | 150 |
| 153 // Shared-memory buffer pool. Since allocating SHM segments requires a | 151 // Shared-memory buffer pool. Since allocating SHM segments requires a |
| 154 // round-trip to the browser process, we keep allocation out of the | 152 // round-trip to the browser process, we keep allocation out of the |
| 155 // steady-state of the decoder. | 153 // steady-state of the decoder. |
| 156 std::vector<SHMBuffer*> available_shm_segments_; | 154 std::vector<SHMBuffer*> available_shm_segments_; |
| 157 | 155 |
| 158 scoped_refptr<MediaLog> media_log_; | 156 scoped_refptr<MediaLog> media_log_; |
| 159 | 157 |
| 160 std::map<int32, BufferPair> bitstream_buffers_in_decoder_; | 158 std::map<int32, PendingDecodeBuffer> bitstream_buffers_in_decoder_; |
| 161 PictureBufferMap assigned_picture_buffers_; | 159 PictureBufferMap assigned_picture_buffers_; |
| 162 // PictureBuffers given to us by VDA via PictureReady, which we sent forward | 160 // PictureBuffers given to us by VDA via PictureReady, which we sent forward |
| 163 // as VideoFrames to be rendered via decode_cb_, and which will be returned | 161 // as VideoFrames to be rendered via decode_cb_, and which will be returned |
| 164 // to us via ReusePictureBuffer. | 162 // to us via ReusePictureBuffer. |
| 165 typedef std::map<int32 /* picture_buffer_id */, uint32 /* texture_id */> | 163 typedef std::map<int32 /* picture_buffer_id */, uint32 /* texture_id */> |
| 166 PictureBufferTextureMap; | 164 PictureBufferTextureMap; |
| 167 PictureBufferTextureMap picture_buffers_at_display_; | 165 PictureBufferTextureMap picture_buffers_at_display_; |
| 168 | 166 |
| 169 // The texture target used for decoded pictures. | 167 // The texture target used for decoded pictures. |
| 170 uint32 decoder_texture_target_; | 168 uint32 decoder_texture_target_; |
| 171 | 169 |
| 172 struct BufferData { | 170 struct BufferData { |
| 173 BufferData(int32 bbid, base::TimeDelta ts, const gfx::Rect& visible_rect, | 171 BufferData(int32 bbid, base::TimeDelta ts, const gfx::Rect& visible_rect, |
| 174 const gfx::Size& natural_size); | 172 const gfx::Size& natural_size); |
| 175 ~BufferData(); | 173 ~BufferData(); |
| 176 int32 bitstream_buffer_id; | 174 int32 bitstream_buffer_id; |
| 177 base::TimeDelta timestamp; | 175 base::TimeDelta timestamp; |
| 178 gfx::Rect visible_rect; | 176 gfx::Rect visible_rect; |
| 179 gfx::Size natural_size; | 177 gfx::Size natural_size; |
| 180 }; | 178 }; |
| 181 std::list<BufferData> input_buffer_data_; | 179 std::list<BufferData> input_buffer_data_; |
| 182 | 180 |
| 183 // picture_buffer_id and the frame wrapping the corresponding Picture, for | 181 // picture_buffer_id and the frame wrapping the corresponding Picture, for |
| 184 // frames that have been decoded but haven't been requested by a Decode() yet. | 182 // frames that have been decoded but haven't been requested by a Decode() yet. |
| 185 std::list<scoped_refptr<VideoFrame> > ready_video_frames_; | |
| 186 int32 next_picture_buffer_id_; | 183 int32 next_picture_buffer_id_; |
| 187 int32 next_bitstream_buffer_id_; | 184 int32 next_bitstream_buffer_id_; |
| 188 | 185 |
| 189 // Set during ProvidePictureBuffers(), used for checking and implementing | 186 // Set during ProvidePictureBuffers(), used for checking and implementing |
| 190 // HasAvailableOutputFrames(). | 187 // HasAvailableOutputFrames(). |
| 191 int available_pictures_; | 188 int available_pictures_; |
| 192 | 189 |
| 193 // Bound to factories_->GetMessageLoop(). | 190 // Bound to factories_->GetMessageLoop(). |
| 194 // NOTE: Weak pointers must be invalidated before all other member variables. | 191 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 195 base::WeakPtrFactory<GpuVideoDecoder> weak_factory_; | 192 base::WeakPtrFactory<GpuVideoDecoder> weak_factory_; |
| 196 | 193 |
| 197 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder); | 194 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder); |
| 198 }; | 195 }; |
| 199 | 196 |
| 200 } // namespace media | 197 } // namespace media |
| 201 | 198 |
| 202 #endif // MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ | 199 #endif // MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ |
| OLD | NEW |