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 CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ |
7 | 7 |
8 #include <d3d9.h> | 8 #include <d3d9.h> |
9 // Work around bug in this header by disabling the relevant warning for it. | 9 // Work around bug in this header by disabling the relevant warning for it. |
10 // https://connect.microsoft.com/VisualStudio/feedback/details/911260/dxva2api-h -in-win8-sdk-triggers-c4201-with-w4 | 10 // https://connect.microsoft.com/VisualStudio/feedback/details/911260/dxva2api-h -in-win8-sdk-triggers-c4201-with-w4 |
11 #pragma warning(push) | 11 #pragma warning(push) |
12 #pragma warning(disable:4201) | 12 #pragma warning(disable:4201) |
13 #include <dxva2api.h> | 13 #include <dxva2api.h> |
14 #pragma warning(pop) | 14 #pragma warning(pop) |
15 #include <list> | 15 #include <list> |
16 #include <map> | 16 #include <map> |
17 #include <mfidl.h> | 17 #include <mfidl.h> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
21 #include "base/memory/linked_ptr.h" | 21 #include "base/memory/linked_ptr.h" |
22 #include "base/memory/weak_ptr.h" | 22 #include "base/memory/weak_ptr.h" |
23 #include "base/threading/non_thread_safe.h" | 23 #include "base/threading/non_thread_safe.h" |
24 #include "base/threading/thread.h" | |
24 #include "base/win/scoped_comptr.h" | 25 #include "base/win/scoped_comptr.h" |
25 #include "content/common/content_export.h" | 26 #include "content/common/content_export.h" |
26 #include "media/video/video_decode_accelerator.h" | 27 #include "media/video/video_decode_accelerator.h" |
27 | 28 |
28 interface IMFSample; | 29 interface IMFSample; |
29 interface IDirect3DSurface9; | 30 interface IDirect3DSurface9; |
30 | 31 |
31 namespace content { | 32 namespace content { |
32 | 33 |
33 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media | 34 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media |
(...skipping 27 matching lines...) Expand all Loading... | |
61 const std::vector<media::PictureBuffer>& buffers) override; | 62 const std::vector<media::PictureBuffer>& buffers) override; |
62 virtual void ReusePictureBuffer(int32 picture_buffer_id) override; | 63 virtual void ReusePictureBuffer(int32 picture_buffer_id) override; |
63 virtual void Flush() override; | 64 virtual void Flush() override; |
64 virtual void Reset() override; | 65 virtual void Reset() override; |
65 virtual void Destroy() override; | 66 virtual void Destroy() override; |
66 virtual bool CanDecodeOnIOThread() override; | 67 virtual bool CanDecodeOnIOThread() override; |
67 | 68 |
68 private: | 69 private: |
69 typedef void* EGLConfig; | 70 typedef void* EGLConfig; |
70 typedef void* EGLSurface; | 71 typedef void* EGLSurface; |
72 // List of input samples waiting to be processed. | |
73 typedef std::list<base::win::ScopedComPtr<IMFSample>> PendingInputs; | |
74 PendingInputs pending_input_buffers_; | |
DaleCurtis
2014/12/03 01:04:33
This should be declared below and the typedef with
| |
75 | |
71 // Creates and initializes an instance of the D3D device and the | 76 // Creates and initializes an instance of the D3D device and the |
72 // corresponding device manager. The device manager instance is eventually | 77 // corresponding device manager. The device manager instance is eventually |
73 // passed to the IMFTransform interface implemented by the decoder. | 78 // passed to the IMFTransform interface implemented by the decoder. |
74 bool CreateD3DDevManager(); | 79 bool CreateD3DDevManager(); |
75 | 80 |
76 // Creates, initializes and sets the media codec types for the decoder. | 81 // Creates, initializes and sets the media codec types for the decoder. |
77 bool InitDecoder(media::VideoCodecProfile profile); | 82 bool InitDecoder(media::VideoCodecProfile profile); |
78 | 83 |
79 // Validates whether the decoder supports hardware video acceleration. | 84 // Validates whether the decoder supports hardware video acceleration. |
80 bool CheckDecoderDxvaSupport(); | 85 bool CheckDecoderDxvaSupport(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 void NotifyResetDone(); | 133 void NotifyResetDone(); |
129 | 134 |
130 // Requests picture buffers from the client. | 135 // Requests picture buffers from the client. |
131 void RequestPictureBuffers(int width, int height); | 136 void RequestPictureBuffers(int width, int height); |
132 | 137 |
133 // Notifies the client about the availability of a picture. | 138 // Notifies the client about the availability of a picture. |
134 void NotifyPictureReady(const media::Picture& picture); | 139 void NotifyPictureReady(const media::Picture& picture); |
135 | 140 |
136 // Sends pending input buffer processed acks to the client if we don't have | 141 // Sends pending input buffer processed acks to the client if we don't have |
137 // output samples waiting to be processed. | 142 // output samples waiting to be processed. |
138 void NotifyInputBuffersDropped(); | 143 void NotifyInputBuffersDropped(const PendingInputs& input_buffers); |
139 | 144 |
140 // Decodes pending input buffers. | 145 // Decodes pending input buffers. |
141 void DecodePendingInputBuffers(); | 146 void DecodePendingInputBuffers(); |
142 | 147 |
143 // Helper for handling the Flush operation. | 148 // Helper for handling the Flush operation. |
144 void FlushInternal(); | 149 void FlushInternal(); |
145 | 150 |
146 // Helper for handling the Decode operation. | 151 // Helper for handling the Decode operation. |
147 void DecodeInternal(const base::win::ScopedComPtr<IMFSample>& input_sample); | 152 void DecodeInternal(const base::win::ScopedComPtr<IMFSample>& input_sample); |
148 | 153 |
149 // Handles mid stream resolution changes. | 154 // Handles mid stream resolution changes. |
150 void HandleResolutionChanged(int width, int height); | 155 void HandleResolutionChanged(int width, int height); |
151 | 156 |
152 struct DXVAPictureBuffer; | 157 struct DXVAPictureBuffer; |
153 typedef std::map<int32, linked_ptr<DXVAPictureBuffer> > OutputBuffers; | 158 typedef std::map<int32, linked_ptr<DXVAPictureBuffer> > OutputBuffers; |
154 | 159 |
155 // Tells the client to dismiss the stale picture buffers passed in. | 160 // Tells the client to dismiss the stale picture buffers passed in. |
156 void DismissStaleBuffers(); | 161 void DismissStaleBuffers(); |
157 | 162 |
158 // Called after the client indicates we can recycle a stale picture buffer. | 163 // Called after the client indicates we can recycle a stale picture buffer. |
159 void DeferredDismissStaleBuffer(int32 picture_buffer_id); | 164 void DeferredDismissStaleBuffer(int32 picture_buffer_id); |
160 | 165 |
166 // Sets the state of the decoder. Can be called from the main thread and | |
167 // the decoder thread. Threadsafe. | |
DaleCurtis
2014/12/03 01:04:33
"thread-safe" or "thread safe" -- up to you.
ananta
2014/12/03 04:08:02
Reworded
| |
168 void SetState(State state); | |
169 | |
170 // Gets the state of the decoder. Can be called from the main thread and | |
171 // the decoder thread. Threadsafe. | |
172 State GetState() const; | |
173 | |
174 // Worker function for the Decoder Reset functionality. Executes on the | |
175 // decoder thread and queues tasks on the main thread as needed. | |
176 void ResetHelper(); | |
177 | |
161 // To expose client callbacks from VideoDecodeAccelerator. | 178 // To expose client callbacks from VideoDecodeAccelerator. |
162 media::VideoDecodeAccelerator::Client* client_; | 179 media::VideoDecodeAccelerator::Client* client_; |
163 | 180 |
164 base::win::ScopedComPtr<IMFTransform> decoder_; | 181 base::win::ScopedComPtr<IMFTransform> decoder_; |
165 | 182 |
166 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; | 183 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; |
167 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_; | 184 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_; |
168 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; | 185 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; |
169 base::win::ScopedComPtr<IDirect3DQuery9> query_; | 186 base::win::ScopedComPtr<IDirect3DQuery9> query_; |
170 // Ideally the reset token would be a stack variable which is used while | 187 // Ideally the reset token would be a stack variable which is used while |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 // become available. | 224 // become available. |
208 OutputBuffers stale_output_picture_buffers_; | 225 OutputBuffers stale_output_picture_buffers_; |
209 | 226 |
210 // Set to true if we requested picture slots from the client. | 227 // Set to true if we requested picture slots from the client. |
211 bool pictures_requested_; | 228 bool pictures_requested_; |
212 | 229 |
213 // Counter which holds the number of input packets before a successful | 230 // Counter which holds the number of input packets before a successful |
214 // decode. | 231 // decode. |
215 int inputs_before_decode_; | 232 int inputs_before_decode_; |
216 | 233 |
217 // List of input samples waiting to be processed. | |
218 typedef std::list<base::win::ScopedComPtr<IMFSample>> PendingInputs; | |
219 PendingInputs pending_input_buffers_; | |
220 | |
221 // Callback to set the correct gl context. | 234 // Callback to set the correct gl context. |
222 base::Callback<bool(void)> make_context_current_; | 235 base::Callback<bool(void)> make_context_current_; |
223 | 236 |
224 // WeakPtrFactory for posting tasks back to |this|. | 237 // WeakPtrFactory for posting tasks back to |this|. |
225 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_; | 238 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_; |
226 | 239 |
227 // Which codec we are decoding with hardware acceleration. | 240 // Which codec we are decoding with hardware acceleration. |
228 media::VideoCodec codec_; | 241 media::VideoCodec codec_; |
242 // Thread on which the decoder operations like passing input frames, | |
243 // getting output frames are performed. One instance of this thread | |
244 // is created per decoder instance. | |
245 base::Thread decoder_thread_; | |
246 | |
247 // Task runner to be used for posting tasks to the decoder thread. | |
248 scoped_refptr<base::TaskRunner> decoder_thread_task_runner_; | |
249 | |
250 // Task runner to be used for posting tasks to the main thread. | |
251 scoped_refptr<base::TaskRunner> main_thread_task_runner_; | |
229 }; | 252 }; |
230 | 253 |
231 } // namespace content | 254 } // namespace content |
232 | 255 |
233 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ | 256 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |