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 <d3d11.h> |
8 #include <d3d9.h> | 9 #include <d3d9.h> |
9 // Work around bug in this header by disabling the relevant warning for it. | 10 // 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 | 11 // https://connect.microsoft.com/VisualStudio/feedback/details/911260/dxva2api-h
-in-win8-sdk-triggers-c4201-with-w4 |
11 #pragma warning(push) | 12 #pragma warning(push) |
12 #pragma warning(disable:4201) | 13 #pragma warning(disable:4201) |
13 #include <dxva2api.h> | 14 #include <dxva2api.h> |
14 #pragma warning(pop) | 15 #pragma warning(pop) |
15 #include <list> | 16 #include <list> |
16 #include <map> | 17 #include <map> |
17 #include <mfidl.h> | 18 #include <mfidl.h> |
18 #include <vector> | 19 #include <vector> |
19 | 20 |
20 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
21 #include "base/memory/linked_ptr.h" | 22 #include "base/memory/linked_ptr.h" |
22 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
23 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
24 #include "base/threading/non_thread_safe.h" | 25 #include "base/threading/non_thread_safe.h" |
25 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
26 #include "base/win/scoped_comptr.h" | 27 #include "base/win/scoped_comptr.h" |
27 #include "content/common/content_export.h" | 28 #include "content/common/content_export.h" |
28 #include "media/video/video_decode_accelerator.h" | 29 #include "media/video/video_decode_accelerator.h" |
29 | 30 |
30 interface IMFSample; | 31 interface IMFSample; |
31 interface IDirect3DSurface9; | 32 interface IDirect3DSurface9; |
32 | 33 |
| 34 namespace gfx { |
| 35 class GLContext; |
| 36 } |
| 37 |
| 38 typedef HRESULT (WINAPI* CreateDXGIDeviceManager)( |
| 39 UINT* reset_token, |
| 40 IMFDXGIDeviceManager** device_manager); |
| 41 |
33 namespace content { | 42 namespace content { |
34 | 43 |
35 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media | 44 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media |
36 // foundation APIs via the VideoDecodeAccelerator interface. | 45 // foundation APIs via the VideoDecodeAccelerator interface. |
37 // This class lives on a single thread and DCHECKs that it is never accessed | 46 // This class lives on a single thread and DCHECKs that it is never accessed |
38 // from any other. | 47 // from any other. |
39 class CONTENT_EXPORT DXVAVideoDecodeAccelerator | 48 class CONTENT_EXPORT DXVAVideoDecodeAccelerator |
40 : public media::VideoDecodeAccelerator { | 49 : public media::VideoDecodeAccelerator { |
41 public: | 50 public: |
42 enum State { | 51 enum State { |
43 kUninitialized, // un-initialized. | 52 kUninitialized, // un-initialized. |
44 kNormal, // normal playing state. | 53 kNormal, // normal playing state. |
45 kResetting, // upon received Reset(), before ResetDone() | 54 kResetting, // upon received Reset(), before ResetDone() |
46 kStopped, // upon output EOS received. | 55 kStopped, // upon output EOS received. |
47 kFlushing, // upon flush request received. | 56 kFlushing, // upon flush request received. |
48 }; | 57 }; |
49 | 58 |
50 // Does not take ownership of |client| which must outlive |*this|. | 59 // Does not take ownership of |client| which must outlive |*this|. |
51 explicit DXVAVideoDecodeAccelerator( | 60 explicit DXVAVideoDecodeAccelerator( |
52 const base::Callback<bool(void)>& make_context_current); | 61 const base::Callback<bool(void)>& make_context_current, |
| 62 gfx::GLContext* gl_context); |
53 ~DXVAVideoDecodeAccelerator() override; | 63 ~DXVAVideoDecodeAccelerator() override; |
54 | 64 |
55 // media::VideoDecodeAccelerator implementation. | 65 // media::VideoDecodeAccelerator implementation. |
56 bool Initialize(media::VideoCodecProfile profile, | 66 bool Initialize(media::VideoCodecProfile profile, |
57 Client* client) override; | 67 Client* client) override; |
58 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 68 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
59 void AssignPictureBuffers( | 69 void AssignPictureBuffers( |
60 const std::vector<media::PictureBuffer>& buffers) override; | 70 const std::vector<media::PictureBuffer>& buffers) override; |
61 void ReusePictureBuffer(int32 picture_buffer_id) override; | 71 void ReusePictureBuffer(int32 picture_buffer_id) override; |
62 void Flush() override; | 72 void Flush() override; |
63 void Reset() override; | 73 void Reset() override; |
64 void Destroy() override; | 74 void Destroy() override; |
65 bool CanDecodeOnIOThread() override; | 75 bool CanDecodeOnIOThread() override; |
66 GLenum GetSurfaceInternalFormat() const override; | 76 GLenum GetSurfaceInternalFormat() const override; |
67 | 77 |
68 private: | 78 private: |
69 typedef void* EGLConfig; | 79 typedef void* EGLConfig; |
70 typedef void* EGLSurface; | 80 typedef void* EGLSurface; |
71 | 81 |
72 // Creates and initializes an instance of the D3D device and the | 82 // Creates and initializes an instance of the D3D device and the |
73 // corresponding device manager. The device manager instance is eventually | 83 // corresponding device manager. The device manager instance is eventually |
74 // passed to the IMFTransform interface implemented by the decoder. | 84 // passed to the IMFTransform interface implemented by the decoder. |
75 bool CreateD3DDevManager(); | 85 bool CreateD3DDevManager(); |
76 | 86 |
| 87 // Creates and initializes an instance of the DX11 device and the |
| 88 // corresponding device manager. The device manager instance is eventually |
| 89 // passed to the IMFTransform interface implemented by the decoder. |
| 90 bool CreateDX11DevManager(); |
| 91 |
77 // Creates, initializes and sets the media codec types for the decoder. | 92 // Creates, initializes and sets the media codec types for the decoder. |
78 bool InitDecoder(media::VideoCodecProfile profile); | 93 bool InitDecoder(media::VideoCodecProfile profile); |
79 | 94 |
80 // Validates whether the decoder supports hardware video acceleration. | 95 // Validates whether the decoder supports hardware video acceleration. |
81 bool CheckDecoderDxvaSupport(); | 96 bool CheckDecoderDxvaSupport(); |
82 | 97 |
83 // Returns information about the input and output streams. This includes | 98 // Returns information about the input and output streams. This includes |
84 // alignment information, decoder support flags, minimum sample size, etc. | 99 // alignment information, decoder support flags, minimum sample size, etc. |
85 bool GetStreamsInfoAndBufferReqs(); | 100 bool GetStreamsInfoAndBufferReqs(); |
86 | 101 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 int picture_buffer_id, | 203 int picture_buffer_id, |
189 int input_buffer_id); | 204 int input_buffer_id); |
190 | 205 |
191 // This is a notification that the source surface |src_surface| was copied to | 206 // This is a notification that the source surface |src_surface| was copied to |
192 // the destination |dest_surface|. Received on the main thread. | 207 // the destination |dest_surface|. Received on the main thread. |
193 void CopySurfaceComplete(IDirect3DSurface9* src_surface, | 208 void CopySurfaceComplete(IDirect3DSurface9* src_surface, |
194 IDirect3DSurface9* dest_surface, | 209 IDirect3DSurface9* dest_surface, |
195 int picture_buffer_id, | 210 int picture_buffer_id, |
196 int input_buffer_id); | 211 int input_buffer_id); |
197 | 212 |
| 213 // Copies the source texture |src_texture| to the destination |dest_texture|. |
| 214 // The copying is done on the decoder thread. The |video_frame| parameter |
| 215 // is the sample containing the frame to be copied. |
| 216 void CopyTexture(ID3D11Texture2D* src_texture, |
| 217 ID3D11Texture2D* dest_texture, |
| 218 IMFSample* video_frame, |
| 219 int picture_buffer_id, |
| 220 int input_buffer_id); |
| 221 |
198 // Flushes the decoder device to ensure that the decoded surface is copied | 222 // Flushes the decoder device to ensure that the decoded surface is copied |
199 // to the target surface. |iterations| helps to maintain an upper limit on | 223 // to the target surface. |iterations| helps to maintain an upper limit on |
200 // the number of times we try to complete the flush operation. | 224 // the number of times we try to complete the flush operation. |
201 void FlushDecoder(int iterations, | 225 void FlushDecoder(int iterations, |
202 IDirect3DSurface9* src_surface, | 226 IDirect3DSurface9* src_surface, |
203 IDirect3DSurface9* dest_surface, | 227 IDirect3DSurface9* dest_surface, |
204 int picture_buffer_id, | 228 int picture_buffer_id, |
205 int input_buffer_id); | 229 int input_buffer_id); |
206 | 230 |
| 231 // Initializes the DX11 Video format converter media types. |
| 232 // Returns true on success. |
| 233 bool InitializeDX11VideoFormatConverterMediaType(int width, int height); |
| 234 |
| 235 // Returns the output video frame dimensions (width, height). |
| 236 // |sample| :- This is the output sample containing the video frame. |
| 237 // |width| :- The width is returned here. |
| 238 // |height| :- The height is returned here. |
| 239 // Returns true on success. |
| 240 bool GetVideoFrameDimensions(IMFSample* sample, int* width, int* height); |
| 241 |
207 // To expose client callbacks from VideoDecodeAccelerator. | 242 // To expose client callbacks from VideoDecodeAccelerator. |
208 media::VideoDecodeAccelerator::Client* client_; | 243 media::VideoDecodeAccelerator::Client* client_; |
209 | 244 |
210 base::win::ScopedComPtr<IMFTransform> decoder_; | 245 base::win::ScopedComPtr<IMFTransform> decoder_; |
| 246 base::win::ScopedComPtr<IMFTransform> video_format_converter_mft_; |
211 | 247 |
212 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; | 248 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; |
213 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_; | 249 base::win::ScopedComPtr<IDirect3DDevice9Ex> d3d9_device_ex_; |
214 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; | 250 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; |
215 base::win::ScopedComPtr<IDirect3DQuery9> query_; | 251 base::win::ScopedComPtr<IDirect3DQuery9> query_; |
| 252 |
| 253 base::win::ScopedComPtr<ID3D11DeviceContext> d3d11_device_context_; |
| 254 base::win::ScopedComPtr<ID3D11Device > d3d11_device_; |
| 255 base::win::ScopedComPtr<IMFDXGIDeviceManager> d3d11_device_manager_; |
| 256 base::win::ScopedComPtr<ID3D11Query> d3d11_query_; |
| 257 |
216 // Ideally the reset token would be a stack variable which is used while | 258 // Ideally the reset token would be a stack variable which is used while |
217 // creating the device manager. However it seems that the device manager | 259 // creating the device manager. However it seems that the device manager |
218 // holds onto the token and attempts to access it if the underlying device | 260 // holds onto the token and attempts to access it if the underlying device |
219 // changes. | 261 // changes. |
220 // TODO(ananta): This needs to be verified. | 262 // TODO(ananta): This needs to be verified. |
221 uint32 dev_manager_reset_token_; | 263 uint32 dev_manager_reset_token_; |
222 | 264 |
| 265 // Reset token for the DX11 device manager. |
| 266 uint32 dx11_dev_manager_reset_token_; |
| 267 |
| 268 uint32 dx11_dev_manager_reset_token_format_conversion_; |
| 269 |
223 // The EGL config to use for decoded frames. | 270 // The EGL config to use for decoded frames. |
224 EGLConfig egl_config_; | 271 EGLConfig egl_config_; |
225 | 272 |
226 // Current state of the decoder. | 273 // Current state of the decoder. |
227 volatile State state_; | 274 volatile State state_; |
228 | 275 |
229 MFT_INPUT_STREAM_INFO input_stream_info_; | 276 MFT_INPUT_STREAM_INFO input_stream_info_; |
230 MFT_OUTPUT_STREAM_INFO output_stream_info_; | 277 MFT_OUTPUT_STREAM_INFO output_stream_info_; |
231 | 278 |
232 // Contains information about a decoded sample. | 279 // Contains information about a decoded sample. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 345 |
299 // Disallow rebinding WeakReference ownership to a different thread by | 346 // Disallow rebinding WeakReference ownership to a different thread by |
300 // keeping a persistent reference. This avoids problems with the | 347 // keeping a persistent reference. This avoids problems with the |
301 // thread safety of reaching into this class from multiple threads to | 348 // thread safety of reaching into this class from multiple threads to |
302 // attain a WeakPtr. | 349 // attain a WeakPtr. |
303 const base::WeakPtr<DXVAVideoDecodeAccelerator> weak_ptr_; | 350 const base::WeakPtr<DXVAVideoDecodeAccelerator> weak_ptr_; |
304 | 351 |
305 // Set to true if we are in the context of a Flush operation. Used to prevent | 352 // Set to true if we are in the context of a Flush operation. Used to prevent |
306 // multiple flush done notifications being sent out. | 353 // multiple flush done notifications being sent out. |
307 bool pending_flush_; | 354 bool pending_flush_; |
| 355 |
| 356 // Defaults to false. Indicates if we should use D3D or DX11 interfaces for |
| 357 // H/W decoding. |
| 358 bool use_dx11_; |
| 359 |
| 360 // Set to true if the DX11 video format converter input media types need to |
| 361 // be initialized. Defaults to true. |
| 362 bool dx11_video_format_converter_media_type_needs_init_; |
| 363 |
| 364 // The GLContext to be used by the decoder. |
| 365 scoped_refptr<gfx::GLContext> gl_context_; |
| 366 |
| 367 // Function pointer for the MFCreateDXGIDeviceManager API. |
| 368 static CreateDXGIDeviceManager create_dxgi_device_manager_; |
308 }; | 369 }; |
309 | 370 |
310 } // namespace content | 371 } // namespace content |
311 | 372 |
312 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ | 373 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |