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/video_decoder.h" | 16 #include "media/base/video_decoder.h" |
17 #include "media/video/video_decode_accelerator.h" | 17 #include "media/video/video_decode_accelerator.h" |
18 | 18 |
19 template <class T> class scoped_refptr; | 19 template <class T> class scoped_refptr; |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 class MessageLoopProxy; | 22 class MessageLoopProxy; |
23 class SharedMemory; | 23 class SharedMemory; |
24 } | 24 } |
25 | 25 |
26 namespace media { | 26 namespace media { |
27 | 27 |
28 class DecoderBuffer; | 28 class DecoderBuffer; |
29 class GpuVideoDecoderFactories; | 29 class GpuVideoDecoderFactories; |
30 class VDAClientProxy; | |
31 | 30 |
32 // GPU-accelerated video decoder implementation. Relies on | 31 // GPU-accelerated video decoder implementation. Relies on |
33 // AcceleratedVideoDecoderMsg_Decode and friends. | 32 // AcceleratedVideoDecoderMsg_Decode and friends. |
34 // All methods internally trampoline to the |message_loop| passed to the ctor. | |
35 class MEDIA_EXPORT GpuVideoDecoder | 33 class MEDIA_EXPORT GpuVideoDecoder |
36 : public VideoDecoder, | 34 : public VideoDecoder, |
37 public VideoDecodeAccelerator::Client { | 35 public VideoDecodeAccelerator::Client { |
38 public: | 36 public: |
39 GpuVideoDecoder(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 37 // The message loop of |factories| will be saved to |gvd_loop_proxy_|. |
40 const scoped_refptr<GpuVideoDecoderFactories>& factories); | 38 explicit GpuVideoDecoder( |
| 39 const scoped_refptr<GpuVideoDecoderFactories>& factories); |
41 | 40 |
42 // VideoDecoder implementation. | 41 // VideoDecoder implementation. |
43 virtual void Initialize(const VideoDecoderConfig& config, | 42 virtual void Initialize(const VideoDecoderConfig& config, |
44 const PipelineStatusCB& status_cb) OVERRIDE; | 43 const PipelineStatusCB& status_cb) OVERRIDE; |
45 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 44 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
46 const ReadCB& read_cb) OVERRIDE; | 45 const ReadCB& read_cb) OVERRIDE; |
47 virtual void Reset(const base::Closure& closure) OVERRIDE; | 46 virtual void Reset(const base::Closure& closure) OVERRIDE; |
48 virtual void Stop(const base::Closure& closure) OVERRIDE; | 47 virtual void Stop(const base::Closure& closure) OVERRIDE; |
49 virtual bool HasAlpha() const OVERRIDE; | 48 virtual bool HasAlpha() const OVERRIDE; |
50 virtual bool NeedsBitstreamConversion() const OVERRIDE; | 49 virtual bool NeedsBitstreamConversion() const OVERRIDE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 const scoped_refptr<VideoFrame>& frame); | 84 const scoped_refptr<VideoFrame>& frame); |
86 | 85 |
87 // Indicate the picture buffer can be reused by the decoder. | 86 // Indicate the picture buffer can be reused by the decoder. |
88 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); | 87 void ReusePictureBuffer(int64 picture_buffer_id, uint32 sync_point); |
89 | 88 |
90 void RecordBufferData( | 89 void RecordBufferData( |
91 const BitstreamBuffer& bitstream_buffer, const DecoderBuffer& buffer); | 90 const BitstreamBuffer& bitstream_buffer, const DecoderBuffer& buffer); |
92 void GetBufferData(int32 id, base::TimeDelta* timetamp, | 91 void GetBufferData(int32 id, base::TimeDelta* timetamp, |
93 gfx::Rect* visible_rect, gfx::Size* natural_size); | 92 gfx::Rect* visible_rect, gfx::Size* natural_size); |
94 | 93 |
95 // Sets |vda_| and |weak_vda_| on the GVD thread and runs |status_cb|. | |
96 void SetVDA(const PipelineStatusCB& status_cb, | |
97 VideoDecodeAccelerator* vda, | |
98 base::WeakPtr<VideoDecodeAccelerator> weak_vda); | |
99 | |
100 // Call VDA::Destroy() on |vda_loop_proxy_| ensuring that |this| outlives the | |
101 // Destroy() call. | |
102 void DestroyVDA(); | 94 void DestroyVDA(); |
103 | 95 |
104 // A shared memory segment and its allocated size. | 96 // A shared memory segment and its allocated size. |
105 struct SHMBuffer { | 97 struct SHMBuffer { |
106 SHMBuffer(base::SharedMemory* m, size_t s); | 98 SHMBuffer(base::SharedMemory* m, size_t s); |
107 ~SHMBuffer(); | 99 ~SHMBuffer(); |
108 base::SharedMemory* shm; | 100 base::SharedMemory* shm; |
109 size_t size; | 101 size_t size; |
110 }; | 102 }; |
111 | 103 |
112 // Request a shared-memory segment of at least |min_size| bytes. Will | 104 // Request a shared-memory segment of at least |min_size| bytes. Will |
113 // allocate as necessary. Caller does not own returned pointer. | 105 // allocate as necessary. Caller does not own returned pointer. |
114 SHMBuffer* GetSHM(size_t min_size); | 106 SHMBuffer* GetSHM(size_t min_size); |
115 | 107 |
116 // Return a shared-memory segment to the available pool. | 108 // Return a shared-memory segment to the available pool. |
117 void PutSHM(SHMBuffer* shm_buffer); | 109 void PutSHM(SHMBuffer* shm_buffer); |
118 | 110 |
119 void DestroyTextures(); | 111 void DestroyTextures(); |
120 | 112 |
121 bool needs_bitstream_conversion_; | 113 bool needs_bitstream_conversion_; |
122 | 114 |
123 // Message loop on which to fire callbacks and trampoline calls to this class | 115 // Message loop which this class and |factories_| run on. |
124 // if they arrive on other loops. | |
125 scoped_refptr<base::MessageLoopProxy> gvd_loop_proxy_; | 116 scoped_refptr<base::MessageLoopProxy> gvd_loop_proxy_; |
126 base::WeakPtrFactory<GpuVideoDecoder> weak_factory_; | 117 base::WeakPtrFactory<GpuVideoDecoder> weak_factory_; |
127 base::WeakPtr<GpuVideoDecoder> weak_this_; | 118 base::WeakPtr<GpuVideoDecoder> weak_this_; |
128 | 119 |
129 // Message loop on which to makes all calls to vda_. (beware this loop may be | |
130 // paused during the Pause/Flush/Stop dance PipelineImpl::Stop() goes | |
131 // through). | |
132 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; | |
133 | |
134 scoped_refptr<GpuVideoDecoderFactories> factories_; | 120 scoped_refptr<GpuVideoDecoderFactories> factories_; |
135 | 121 |
136 // Proxies calls from |vda_| to |gvd_loop_proxy_| and used to safely detach | 122 // Populated during Initialize() (on success) and unchanged until an error |
137 // during shutdown. | 123 // occurs. |
138 scoped_refptr<VDAClientProxy> client_proxy_; | |
139 | |
140 // Populated during Initialize() via SetVDA() (on success) and unchanged | |
141 // until an error occurs. | |
142 scoped_ptr<VideoDecodeAccelerator> vda_; | 124 scoped_ptr<VideoDecodeAccelerator> vda_; |
143 // Used to post tasks from the GVD thread to the VDA thread safely. | |
144 base::WeakPtr<VideoDecodeAccelerator> weak_vda_; | |
145 | 125 |
146 // Callbacks that are !is_null() only during their respective operation being | 126 // Callbacks that are !is_null() only during their respective operation being |
147 // asynchronously executed. | 127 // asynchronously executed. |
148 ReadCB pending_read_cb_; | 128 ReadCB pending_read_cb_; |
149 base::Closure pending_reset_cb_; | 129 base::Closure pending_reset_cb_; |
150 | 130 |
151 State state_; | 131 State state_; |
152 | 132 |
153 VideoDecoderConfig config_; | 133 VideoDecoderConfig config_; |
154 | 134 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // Set during ProvidePictureBuffers(), used for checking and implementing | 178 // Set during ProvidePictureBuffers(), used for checking and implementing |
199 // HasAvailableOutputFrames(). | 179 // HasAvailableOutputFrames(). |
200 int available_pictures_; | 180 int available_pictures_; |
201 | 181 |
202 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder); | 182 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder); |
203 }; | 183 }; |
204 | 184 |
205 } // namespace media | 185 } // namespace media |
206 | 186 |
207 #endif // MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ | 187 #endif // MEDIA_FILTERS_GPU_VIDEO_DECODER_H_ |
OLD | NEW |