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/synchronization/lock.h" |
23 #include "base/threading/non_thread_safe.h" | 24 #include "base/threading/non_thread_safe.h" |
| 25 #include "base/threading/thread.h" |
24 #include "base/win/scoped_comptr.h" | 26 #include "base/win/scoped_comptr.h" |
25 #include "content/common/content_export.h" | 27 #include "content/common/content_export.h" |
26 #include "media/video/video_decode_accelerator.h" | 28 #include "media/video/video_decode_accelerator.h" |
27 | 29 |
28 interface IMFSample; | 30 interface IMFSample; |
29 interface IDirect3DSurface9; | 31 interface IDirect3DSurface9; |
30 | 32 |
31 namespace content { | 33 namespace content { |
32 | 34 |
33 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media | 35 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media |
34 // foundation APIs via the VideoDecodeAccelerator interface. | 36 // foundation APIs via the VideoDecodeAccelerator interface. |
35 // This class lives on a single thread and DCHECKs that it is never accessed | 37 // This class lives on a single thread and DCHECKs that it is never accessed |
36 // from any other. | 38 // from any other. |
37 class CONTENT_EXPORT DXVAVideoDecodeAccelerator | 39 class CONTENT_EXPORT DXVAVideoDecodeAccelerator |
38 : public media::VideoDecodeAccelerator, | 40 : public media::VideoDecodeAccelerator { |
39 NON_EXPORTED_BASE(public base::NonThreadSafe) { | |
40 public: | 41 public: |
41 enum State { | 42 enum State { |
42 kUninitialized, // un-initialized. | 43 kUninitialized, // un-initialized. |
43 kNormal, // normal playing state. | 44 kNormal, // normal playing state. |
44 kResetting, // upon received Reset(), before ResetDone() | 45 kResetting, // upon received Reset(), before ResetDone() |
45 kStopped, // upon output EOS received. | 46 kStopped, // upon output EOS received. |
46 kFlushing, // upon flush request received. | 47 kFlushing, // upon flush request received. |
47 kFlushingPendingInputBuffers, // pending flush request for unprocessed | 48 kFlushingPendingInputBuffers, // pending flush request for unprocessed |
48 // input buffers. | 49 // input buffers. |
49 }; | 50 }; |
(...skipping 11 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 |
71 // Creates and initializes an instance of the D3D device and the | 73 // Creates and initializes an instance of the D3D device and the |
72 // corresponding device manager. The device manager instance is eventually | 74 // corresponding device manager. The device manager instance is eventually |
73 // passed to the IMFTransform interface implemented by the decoder. | 75 // passed to the IMFTransform interface implemented by the decoder. |
74 bool CreateD3DDevManager(); | 76 bool CreateD3DDevManager(); |
75 | 77 |
76 // Creates, initializes and sets the media codec types for the decoder. | 78 // Creates, initializes and sets the media codec types for the decoder. |
77 bool InitDecoder(media::VideoCodecProfile profile); | 79 bool InitDecoder(media::VideoCodecProfile profile); |
78 | 80 |
79 // Validates whether the decoder supports hardware video acceleration. | 81 // Validates whether the decoder supports hardware video acceleration. |
80 bool CheckDecoderDxvaSupport(); | 82 bool CheckDecoderDxvaSupport(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 153 |
152 struct DXVAPictureBuffer; | 154 struct DXVAPictureBuffer; |
153 typedef std::map<int32, linked_ptr<DXVAPictureBuffer> > OutputBuffers; | 155 typedef std::map<int32, linked_ptr<DXVAPictureBuffer> > OutputBuffers; |
154 | 156 |
155 // Tells the client to dismiss the stale picture buffers passed in. | 157 // Tells the client to dismiss the stale picture buffers passed in. |
156 void DismissStaleBuffers(); | 158 void DismissStaleBuffers(); |
157 | 159 |
158 // Called after the client indicates we can recycle a stale picture buffer. | 160 // Called after the client indicates we can recycle a stale picture buffer. |
159 void DeferredDismissStaleBuffer(int32 picture_buffer_id); | 161 void DeferredDismissStaleBuffer(int32 picture_buffer_id); |
160 | 162 |
| 163 // Sets the state of the decoder. Called from the main thread and the decoder |
| 164 // thread. The state is changed on the main thread. |
| 165 void SetState(State state); |
| 166 |
| 167 // Gets the state of the decoder. Can be called from the main thread and |
| 168 // the decoder thread. Thread safe. |
| 169 State GetState() const; |
| 170 |
| 171 // Worker function for the Decoder Reset functionality. Executes on the |
| 172 // decoder thread and queues tasks on the main thread as needed. |
| 173 void ResetHelper(); |
| 174 |
| 175 // Starts the thread used for decoding. |
| 176 void StartDecoderThread(); |
| 177 |
| 178 // Returns if we have output samples waiting to be processed. We only |
| 179 // allow one output sample to be present in the output queue at any given |
| 180 // time. |
| 181 bool OutputSamplesPresent(); |
| 182 |
161 // To expose client callbacks from VideoDecodeAccelerator. | 183 // To expose client callbacks from VideoDecodeAccelerator. |
162 media::VideoDecodeAccelerator::Client* client_; | 184 media::VideoDecodeAccelerator::Client* client_; |
163 | 185 |
164 base::win::ScopedComPtr<IMFTransform> decoder_; | 186 base::win::ScopedComPtr<IMFTransform> decoder_; |
165 | 187 |
166 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; | 188 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; |
167 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_; | 189 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_; |
168 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; | 190 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; |
169 base::win::ScopedComPtr<IDirect3DQuery9> query_; | 191 base::win::ScopedComPtr<IDirect3DQuery9> query_; |
170 // Ideally the reset token would be a stack variable which is used while | 192 // Ideally the reset token would be a stack variable which is used while |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 PendingInputs pending_input_buffers_; | 241 PendingInputs pending_input_buffers_; |
220 | 242 |
221 // Callback to set the correct gl context. | 243 // Callback to set the correct gl context. |
222 base::Callback<bool(void)> make_context_current_; | 244 base::Callback<bool(void)> make_context_current_; |
223 | 245 |
224 // WeakPtrFactory for posting tasks back to |this|. | 246 // WeakPtrFactory for posting tasks back to |this|. |
225 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_; | 247 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_; |
226 | 248 |
227 // Which codec we are decoding with hardware acceleration. | 249 // Which codec we are decoding with hardware acceleration. |
228 media::VideoCodec codec_; | 250 media::VideoCodec codec_; |
| 251 // Thread on which the decoder operations like passing input frames, |
| 252 // getting output frames are performed. One instance of this thread |
| 253 // is created per decoder instance. |
| 254 base::Thread decoder_thread_; |
| 255 |
| 256 // Task runner to be used for posting tasks to the decoder thread. |
| 257 scoped_refptr<base::SingleThreadTaskRunner> decoder_thread_task_runner_; |
| 258 |
| 259 // Task runner to be used for posting tasks to the main thread. |
| 260 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 261 |
| 262 // Used to synchronize access between the decoder thread and the main thread. |
| 263 // Currently only used to synchronize access to the pending output samples |
| 264 // queue. |
| 265 base::Lock decoder_lock_; |
229 }; | 266 }; |
230 | 267 |
231 } // namespace content | 268 } // namespace content |
232 | 269 |
233 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ | 270 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |