| 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 MEDIA_GPU_DXVA_VIDEO_DECODE_ACCELERATOR_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define MEDIA_GPU_DXVA_VIDEO_DECODE_ACCELERATOR_H_ |
| 7 | 7 |
| 8 #include <d3d11.h> | 8 #include <d3d11.h> |
| 9 #include <d3d9.h> | 9 #include <d3d9.h> |
| 10 #include <initguid.h> | 10 #include <initguid.h> |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 // Work around bug in this header by disabling the relevant warning for it. | 12 // Work around bug in this header by disabling the relevant warning for it. |
| 13 // https://connect.microsoft.com/VisualStudio/feedback/details/911260/dxva2api-h
-in-win8-sdk-triggers-c4201-with-w4 | 13 // https://connect.microsoft.com/VisualStudio/feedback/details/911260/dxva2api-h
-in-win8-sdk-triggers-c4201-with-w4 |
| 14 #pragma warning(push) | 14 #pragma warning(push) |
| 15 #pragma warning(disable:4201) | 15 #pragma warning(disable : 4201) |
| 16 #include <dxva2api.h> | 16 #include <dxva2api.h> |
| 17 #pragma warning(pop) | 17 #pragma warning(pop) |
| 18 #include <mfidl.h> | 18 #include <mfidl.h> |
| 19 | 19 |
| 20 #include <list> | 20 #include <list> |
| 21 #include <map> | 21 #include <map> |
| 22 #include <vector> | 22 #include <vector> |
| 23 | 23 |
| 24 #include "base/compiler_specific.h" | 24 #include "base/compiler_specific.h" |
| 25 #include "base/macros.h" | 25 #include "base/macros.h" |
| 26 #include "base/memory/linked_ptr.h" | 26 #include "base/memory/linked_ptr.h" |
| 27 #include "base/memory/weak_ptr.h" | 27 #include "base/memory/weak_ptr.h" |
| 28 #include "base/synchronization/lock.h" | 28 #include "base/synchronization/lock.h" |
| 29 #include "base/threading/non_thread_safe.h" | 29 #include "base/threading/non_thread_safe.h" |
| 30 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
| 31 #include "base/win/scoped_comptr.h" | 31 #include "base/win/scoped_comptr.h" |
| 32 #include "content/common/content_export.h" | |
| 33 #include "content/common/gpu/media/gpu_video_decode_accelerator_helpers.h" | |
| 34 #include "media/filters/h264_parser.h" | 32 #include "media/filters/h264_parser.h" |
| 33 #include "media/gpu/gpu_video_decode_accelerator_helpers.h" |
| 34 #include "media/gpu/media_gpu_export.h" |
| 35 #include "media/video/video_decode_accelerator.h" | 35 #include "media/video/video_decode_accelerator.h" |
| 36 | 36 |
| 37 interface IMFSample; | 37 interface IMFSample; |
| 38 interface IDirect3DSurface9; | 38 interface IDirect3DSurface9; |
| 39 | 39 |
| 40 namespace gfx { | 40 namespace gfx { |
| 41 class GLContext; | 41 class GLContext; |
| 42 } | 42 } |
| 43 | 43 |
| 44 typedef HRESULT (WINAPI* CreateDXGIDeviceManager)( | 44 typedef HRESULT(WINAPI* CreateDXGIDeviceManager)( |
| 45 UINT* reset_token, | 45 UINT* reset_token, |
| 46 IMFDXGIDeviceManager** device_manager); | 46 IMFDXGIDeviceManager** device_manager); |
| 47 | 47 |
| 48 namespace content { | 48 namespace media { |
| 49 | 49 |
| 50 // Provides functionality to detect H.264 stream configuration changes. | 50 // Provides functionality to detect H.264 stream configuration changes. |
| 51 // TODO(ananta) | 51 // TODO(ananta) |
| 52 // Move this to a common place so that all VDA's can use this. | 52 // Move this to a common place so that all VDA's can use this. |
| 53 class H264ConfigChangeDetector { | 53 class H264ConfigChangeDetector { |
| 54 public: | 54 public: |
| 55 H264ConfigChangeDetector(); | 55 H264ConfigChangeDetector(); |
| 56 ~H264ConfigChangeDetector(); | 56 ~H264ConfigChangeDetector(); |
| 57 | 57 |
| 58 // Detects stream configuration changes. | 58 // Detects stream configuration changes. |
| 59 // Returns false on failure. | 59 // Returns false on failure. |
| 60 bool DetectConfig(const uint8_t* stream, unsigned int size); | 60 bool DetectConfig(const uint8_t* stream, unsigned int size); |
| 61 | 61 |
| 62 bool config_changed() const { | 62 bool config_changed() const { return config_changed_; } |
| 63 return config_changed_; | |
| 64 } | |
| 65 | 63 |
| 66 private: | 64 private: |
| 67 // These fields are used to track the SPS/PPS in the H.264 bitstream and | 65 // These fields are used to track the SPS/PPS in the H.264 bitstream and |
| 68 // are eventually compared against the SPS/PPS in the bitstream to detect | 66 // are eventually compared against the SPS/PPS in the bitstream to detect |
| 69 // a change. | 67 // a change. |
| 70 int last_sps_id_; | 68 int last_sps_id_; |
| 71 std::vector<uint8_t> last_sps_; | 69 std::vector<uint8_t> last_sps_; |
| 72 int last_pps_id_; | 70 int last_pps_id_; |
| 73 std::vector<uint8_t> last_pps_; | 71 std::vector<uint8_t> last_pps_; |
| 74 // Set to true if we detect a stream configuration change. | 72 // Set to true if we detect a stream configuration change. |
| 75 bool config_changed_; | 73 bool config_changed_; |
| 76 // We want to indicate configuration changes only after we see IDR slices. | 74 // We want to indicate configuration changes only after we see IDR slices. |
| 77 // This flag tracks that we potentially have a configuration change which | 75 // This flag tracks that we potentially have a configuration change which |
| 78 // we want to honor after we see an IDR slice. | 76 // we want to honor after we see an IDR slice. |
| 79 bool pending_config_changed_; | 77 bool pending_config_changed_; |
| 80 | 78 |
| 81 std::unique_ptr<media::H264Parser> parser_; | 79 std::unique_ptr<media::H264Parser> parser_; |
| 82 | 80 |
| 83 DISALLOW_COPY_AND_ASSIGN(H264ConfigChangeDetector); | 81 DISALLOW_COPY_AND_ASSIGN(H264ConfigChangeDetector); |
| 84 }; | 82 }; |
| 85 | 83 |
| 86 | |
| 87 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media | 84 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media |
| 88 // foundation APIs via the VideoDecodeAccelerator interface. | 85 // foundation APIs via the VideoDecodeAccelerator interface. |
| 89 // This class lives on a single thread and DCHECKs that it is never accessed | 86 // This class lives on a single thread and DCHECKs that it is never accessed |
| 90 // from any other. | 87 // from any other. |
| 91 class CONTENT_EXPORT DXVAVideoDecodeAccelerator | 88 class MEDIA_GPU_EXPORT DXVAVideoDecodeAccelerator |
| 92 : public media::VideoDecodeAccelerator { | 89 : public media::VideoDecodeAccelerator { |
| 93 public: | 90 public: |
| 94 enum State { | 91 enum State { |
| 95 kUninitialized, // un-initialized. | 92 kUninitialized, // un-initialized. |
| 96 kNormal, // normal playing state. | 93 kNormal, // normal playing state. |
| 97 kResetting, // upon received Reset(), before ResetDone() | 94 kResetting, // upon received Reset(), before ResetDone() |
| 98 kStopped, // upon output EOS received. | 95 kStopped, // upon output EOS received. |
| 99 kFlushing, // upon flush request received. | 96 kFlushing, // upon flush request received. |
| 100 kConfigChange, // stream configuration change detected. | 97 kConfigChange, // stream configuration change detected. |
| 101 }; | 98 }; |
| 102 | 99 |
| 103 // Does not take ownership of |client| which must outlive |*this|. | 100 // Does not take ownership of |client| which must outlive |*this|. |
| 104 DXVAVideoDecodeAccelerator( | 101 DXVAVideoDecodeAccelerator( |
| 105 const GetGLContextCallback& get_gl_context_cb, | 102 const GetGLContextCallback& get_gl_context_cb, |
| 106 const MakeGLContextCurrentCallback& make_context_current_cb, | 103 const MakeGLContextCurrentCallback& make_context_current_cb, |
| 107 bool enable_accelerated_vpx_decode); | 104 bool enable_accelerated_vpx_decode); |
| 108 ~DXVAVideoDecodeAccelerator() override; | 105 ~DXVAVideoDecodeAccelerator() override; |
| 109 | 106 |
| 110 // media::VideoDecodeAccelerator implementation. | 107 // media::VideoDecodeAccelerator implementation. |
| 111 bool Initialize(const Config& config, Client* client) override; | 108 bool Initialize(const Config& config, Client* client) override; |
| 112 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 109 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
| 113 void AssignPictureBuffers( | 110 void AssignPictureBuffers( |
| 114 const std::vector<media::PictureBuffer>& buffers) override; | 111 const std::vector<media::PictureBuffer>& buffers) override; |
| 115 void ReusePictureBuffer(int32_t picture_buffer_id) override; | 112 void ReusePictureBuffer(int32_t picture_buffer_id) override; |
| 116 void Flush() override; | 113 void Flush() override; |
| 117 void Reset() override; | 114 void Reset() override; |
| 118 void Destroy() override; | 115 void Destroy() override; |
| 119 bool TryToSetupDecodeOnSeparateThread( | 116 bool TryToSetupDecodeOnSeparateThread( |
| 120 const base::WeakPtr<Client>& decode_client, | 117 const base::WeakPtr<Client>& decode_client, |
| 121 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) | 118 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) |
| 122 override; | 119 override; |
| 123 GLenum GetSurfaceInternalFormat() const override; | 120 GLenum GetSurfaceInternalFormat() const override; |
| 124 | 121 |
| 125 static media::VideoDecodeAccelerator::SupportedProfiles | 122 static media::VideoDecodeAccelerator::SupportedProfiles |
| 126 GetSupportedProfiles(); | 123 GetSupportedProfiles(); |
| 127 | 124 |
| 128 // Preload dlls required for decoding. | 125 // Preload dlls required for decoding. |
| 129 static void PreSandboxInitialization(); | 126 static void PreSandboxInitialization(); |
| 130 | 127 |
| 131 private: | 128 private: |
| 132 typedef void* EGLConfig; | 129 typedef void* EGLConfig; |
| 133 typedef void* EGLSurface; | 130 typedef void* EGLSurface; |
| 134 | 131 |
| 135 // Returns the minimum resolution for the |profile| passed in. | 132 // Returns the minimum resolution for the |profile| passed in. |
| 136 static std::pair<int, int> GetMinResolution( | 133 static std::pair<int, int> GetMinResolution( |
| 137 const media::VideoCodecProfile profile); | 134 const media::VideoCodecProfile profile); |
| 138 | 135 |
| 139 // Returns the maximum resolution for the |profile| passed in. | 136 // Returns the maximum resolution for the |profile| passed in. |
| 140 static std::pair<int, int> GetMaxResolution( | 137 static std::pair<int, int> GetMaxResolution( |
| 141 const media::VideoCodecProfile profile); | 138 const media::VideoCodecProfile profile); |
| 142 | 139 |
| 143 // Returns the maximum resolution for H264 video. | 140 // Returns the maximum resolution for H264 video. |
| 144 static std::pair<int, int> GetMaxH264Resolution(); | 141 static std::pair<int, int> GetMaxH264Resolution(); |
| 145 | 142 |
| 146 // Certain AMD GPU drivers like R600, R700, Evergreen and Cayman and | 143 // Certain AMD GPU drivers like R600, R700, Evergreen and Cayman and |
| 147 // some second generation Intel GPU drivers crash if we create a video | 144 // some second generation Intel GPU drivers crash if we create a video |
| 148 // device with a resolution higher then 1920 x 1088. This function | 145 // device with a resolution higher then 1920 x 1088. This function |
| 149 // checks if the GPU is in this list and if yes returns true. | 146 // checks if the GPU is in this list and if yes returns true. |
| 150 static bool IsLegacyGPU(ID3D11Device* device); | 147 static bool IsLegacyGPU(ID3D11Device* device); |
| 151 | 148 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // Notifies the client that the decoder was flushed. | 207 // Notifies the client that the decoder was flushed. |
| 211 void NotifyFlushDone(); | 208 void NotifyFlushDone(); |
| 212 | 209 |
| 213 // Notifies the client that the decoder was reset. | 210 // Notifies the client that the decoder was reset. |
| 214 void NotifyResetDone(); | 211 void NotifyResetDone(); |
| 215 | 212 |
| 216 // Requests picture buffers from the client. | 213 // Requests picture buffers from the client. |
| 217 void RequestPictureBuffers(int width, int height); | 214 void RequestPictureBuffers(int width, int height); |
| 218 | 215 |
| 219 // Notifies the client about the availability of a picture. | 216 // Notifies the client about the availability of a picture. |
| 220 void NotifyPictureReady(int picture_buffer_id, | 217 void NotifyPictureReady(int picture_buffer_id, int input_buffer_id); |
| 221 int input_buffer_id); | |
| 222 | 218 |
| 223 // Sends pending input buffer processed acks to the client if we don't have | 219 // Sends pending input buffer processed acks to the client if we don't have |
| 224 // output samples waiting to be processed. | 220 // output samples waiting to be processed. |
| 225 void NotifyInputBuffersDropped(); | 221 void NotifyInputBuffersDropped(); |
| 226 | 222 |
| 227 // Decodes pending input buffers. | 223 // Decodes pending input buffers. |
| 228 void DecodePendingInputBuffers(); | 224 void DecodePendingInputBuffers(); |
| 229 | 225 |
| 230 // Helper for handling the Flush operation. | 226 // Helper for handling the Flush operation. |
| 231 void FlushInternal(); | 227 void FlushInternal(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 media::VideoDecodeAccelerator::Client* client_; | 333 media::VideoDecodeAccelerator::Client* client_; |
| 338 | 334 |
| 339 base::win::ScopedComPtr<IMFTransform> decoder_; | 335 base::win::ScopedComPtr<IMFTransform> decoder_; |
| 340 base::win::ScopedComPtr<IMFTransform> video_format_converter_mft_; | 336 base::win::ScopedComPtr<IMFTransform> video_format_converter_mft_; |
| 341 | 337 |
| 342 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; | 338 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; |
| 343 base::win::ScopedComPtr<IDirect3DDevice9Ex> d3d9_device_ex_; | 339 base::win::ScopedComPtr<IDirect3DDevice9Ex> d3d9_device_ex_; |
| 344 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; | 340 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; |
| 345 base::win::ScopedComPtr<IDirect3DQuery9> query_; | 341 base::win::ScopedComPtr<IDirect3DQuery9> query_; |
| 346 | 342 |
| 347 base::win::ScopedComPtr<ID3D11Device > d3d11_device_; | 343 base::win::ScopedComPtr<ID3D11Device> d3d11_device_; |
| 348 base::win::ScopedComPtr<IMFDXGIDeviceManager> d3d11_device_manager_; | 344 base::win::ScopedComPtr<IMFDXGIDeviceManager> d3d11_device_manager_; |
| 349 base::win::ScopedComPtr<ID3D10Multithread> multi_threaded_; | 345 base::win::ScopedComPtr<ID3D10Multithread> multi_threaded_; |
| 350 base::win::ScopedComPtr<ID3D11DeviceContext> d3d11_device_context_; | 346 base::win::ScopedComPtr<ID3D11DeviceContext> d3d11_device_context_; |
| 351 base::win::ScopedComPtr<ID3D11Query> d3d11_query_; | 347 base::win::ScopedComPtr<ID3D11Query> d3d11_query_; |
| 352 | 348 |
| 353 // Ideally the reset token would be a stack variable which is used while | 349 // Ideally the reset token would be a stack variable which is used while |
| 354 // creating the device manager. However it seems that the device manager | 350 // creating the device manager. However it seems that the device manager |
| 355 // holds onto the token and attempts to access it if the underlying device | 351 // holds onto the token and attempts to access it if the underlying device |
| 356 // changes. | 352 // changes. |
| 357 // TODO(ananta): This needs to be verified. | 353 // TODO(ananta): This needs to be verified. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 474 |
| 479 // WeakPtrFactory for posting tasks back to |this|. | 475 // WeakPtrFactory for posting tasks back to |this|. |
| 480 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_; | 476 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_; |
| 481 | 477 |
| 482 // Function pointer for the MFCreateDXGIDeviceManager API. | 478 // Function pointer for the MFCreateDXGIDeviceManager API. |
| 483 static CreateDXGIDeviceManager create_dxgi_device_manager_; | 479 static CreateDXGIDeviceManager create_dxgi_device_manager_; |
| 484 | 480 |
| 485 DISALLOW_COPY_AND_ASSIGN(DXVAVideoDecodeAccelerator); | 481 DISALLOW_COPY_AND_ASSIGN(DXVAVideoDecodeAccelerator); |
| 486 }; | 482 }; |
| 487 | 483 |
| 488 } // namespace content | 484 } // namespace media |
| 489 | 485 |
| 490 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ | 486 #endif // MEDIA_GPU_DXVA_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |