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_GPU_DXVA_VIDEO_DECODE_ACCELERATOR_WIN_H_ | 5 #ifndef MEDIA_GPU_DXVA_VIDEO_DECODE_ACCELERATOR_WIN_H_ |
6 #define MEDIA_GPU_DXVA_VIDEO_DECODE_ACCELERATOR_WIN_H_ | 6 #define MEDIA_GPU_DXVA_VIDEO_DECODE_ACCELERATOR_WIN_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> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 std::vector<uint8_t> last_sps_; | 78 std::vector<uint8_t> last_sps_; |
79 int last_pps_id_; | 79 int last_pps_id_; |
80 std::vector<uint8_t> last_pps_; | 80 std::vector<uint8_t> last_pps_; |
81 // Set to true if we detect a stream configuration change. | 81 // Set to true if we detect a stream configuration change. |
82 bool config_changed_; | 82 bool config_changed_; |
83 // We want to indicate configuration changes only after we see IDR slices. | 83 // We want to indicate configuration changes only after we see IDR slices. |
84 // This flag tracks that we potentially have a configuration change which | 84 // This flag tracks that we potentially have a configuration change which |
85 // we want to honor after we see an IDR slice. | 85 // we want to honor after we see an IDR slice. |
86 bool pending_config_changed_; | 86 bool pending_config_changed_; |
87 | 87 |
88 std::unique_ptr<media::H264Parser> parser_; | 88 std::unique_ptr<H264Parser> parser_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(H264ConfigChangeDetector); | 90 DISALLOW_COPY_AND_ASSIGN(H264ConfigChangeDetector); |
91 }; | 91 }; |
92 | 92 |
93 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media | 93 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media |
94 // foundation APIs via the VideoDecodeAccelerator interface. | 94 // foundation APIs via the VideoDecodeAccelerator interface. |
95 // This class lives on a single thread and DCHECKs that it is never accessed | 95 // This class lives on a single thread and DCHECKs that it is never accessed |
96 // from any other. | 96 // from any other. |
97 class MEDIA_GPU_EXPORT DXVAVideoDecodeAccelerator | 97 class MEDIA_GPU_EXPORT DXVAVideoDecodeAccelerator |
98 : public media::VideoDecodeAccelerator { | 98 : public VideoDecodeAccelerator { |
99 public: | 99 public: |
100 enum State { | 100 enum State { |
101 kUninitialized, // un-initialized. | 101 kUninitialized, // un-initialized. |
102 kNormal, // normal playing state. | 102 kNormal, // normal playing state. |
103 kResetting, // upon received Reset(), before ResetDone() | 103 kResetting, // upon received Reset(), before ResetDone() |
104 kStopped, // upon output EOS received. | 104 kStopped, // upon output EOS received. |
105 kFlushing, // upon flush request received. | 105 kFlushing, // upon flush request received. |
106 kConfigChange, // stream configuration change detected. | 106 kConfigChange, // stream configuration change detected. |
107 }; | 107 }; |
108 | 108 |
109 // Does not take ownership of |client| which must outlive |*this|. | 109 // Does not take ownership of |client| which must outlive |*this|. |
110 DXVAVideoDecodeAccelerator( | 110 DXVAVideoDecodeAccelerator( |
111 const GetGLContextCallback& get_gl_context_cb, | 111 const GetGLContextCallback& get_gl_context_cb, |
112 const MakeGLContextCurrentCallback& make_context_current_cb, | 112 const MakeGLContextCurrentCallback& make_context_current_cb, |
113 const gpu::GpuPreferences& gpu_preferences); | 113 const gpu::GpuPreferences& gpu_preferences); |
114 ~DXVAVideoDecodeAccelerator() override; | 114 ~DXVAVideoDecodeAccelerator() override; |
115 | 115 |
116 // media::VideoDecodeAccelerator implementation. | 116 // VideoDecodeAccelerator implementation. |
117 bool Initialize(const Config& config, Client* client) override; | 117 bool Initialize(const Config& config, Client* client) override; |
118 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 118 void Decode(const BitstreamBuffer& bitstream_buffer) override; |
119 void AssignPictureBuffers( | 119 void AssignPictureBuffers(const std::vector<PictureBuffer>& buffers) override; |
120 const std::vector<media::PictureBuffer>& buffers) override; | |
121 void ReusePictureBuffer(int32_t picture_buffer_id) override; | 120 void ReusePictureBuffer(int32_t picture_buffer_id) override; |
122 void Flush() override; | 121 void Flush() override; |
123 void Reset() override; | 122 void Reset() override; |
124 void Destroy() override; | 123 void Destroy() override; |
125 bool TryToSetupDecodeOnSeparateThread( | 124 bool TryToSetupDecodeOnSeparateThread( |
126 const base::WeakPtr<Client>& decode_client, | 125 const base::WeakPtr<Client>& decode_client, |
127 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) | 126 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) |
128 override; | 127 override; |
129 GLenum GetSurfaceInternalFormat() const override; | 128 GLenum GetSurfaceInternalFormat() const override; |
130 | 129 |
131 static media::VideoDecodeAccelerator::SupportedProfiles | 130 static VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(); |
132 GetSupportedProfiles(); | |
133 | 131 |
134 // Preload dlls required for decoding. | 132 // Preload dlls required for decoding. |
135 static void PreSandboxInitialization(); | 133 static void PreSandboxInitialization(); |
136 | 134 |
137 private: | 135 private: |
138 friend class DXVAPictureBuffer; | 136 friend class DXVAPictureBuffer; |
139 friend class EGLStreamPictureBuffer; | 137 friend class EGLStreamPictureBuffer; |
140 friend class PbufferPictureBuffer; | 138 friend class PbufferPictureBuffer; |
141 typedef void* EGLConfig; | 139 typedef void* EGLConfig; |
142 typedef void* EGLSurface; | 140 typedef void* EGLSurface; |
143 | 141 |
144 // Returns the minimum resolution for the |profile| passed in. | 142 // Returns the minimum resolution for the |profile| passed in. |
145 static std::pair<int, int> GetMinResolution( | 143 static std::pair<int, int> GetMinResolution(const VideoCodecProfile profile); |
146 const media::VideoCodecProfile profile); | |
147 | 144 |
148 // Returns the maximum resolution for the |profile| passed in. | 145 // Returns the maximum resolution for the |profile| passed in. |
149 static std::pair<int, int> GetMaxResolution( | 146 static std::pair<int, int> GetMaxResolution(const VideoCodecProfile profile); |
150 const media::VideoCodecProfile profile); | |
151 | 147 |
152 // Returns the maximum resolution for H264 video. | 148 // Returns the maximum resolution for H264 video. |
153 static std::pair<int, int> GetMaxH264Resolution(); | 149 static std::pair<int, int> GetMaxH264Resolution(); |
154 | 150 |
155 // Certain AMD GPU drivers like R600, R700, Evergreen and Cayman and | 151 // Certain AMD GPU drivers like R600, R700, Evergreen and Cayman and |
156 // some second generation Intel GPU drivers crash if we create a video | 152 // some second generation Intel GPU drivers crash if we create a video |
157 // device with a resolution higher then 1920 x 1088. This function | 153 // device with a resolution higher then 1920 x 1088. This function |
158 // checks if the GPU is in this list and if yes returns true. | 154 // checks if the GPU is in this list and if yes returns true. |
159 static bool IsLegacyGPU(ID3D11Device* device); | 155 static bool IsLegacyGPU(ID3D11Device* device); |
160 | 156 |
161 // Creates and initializes an instance of the D3D device and the | 157 // Creates and initializes an instance of the D3D device and the |
162 // corresponding device manager. The device manager instance is eventually | 158 // corresponding device manager. The device manager instance is eventually |
163 // passed to the IMFTransform interface implemented by the decoder. | 159 // passed to the IMFTransform interface implemented by the decoder. |
164 bool CreateD3DDevManager(); | 160 bool CreateD3DDevManager(); |
165 | 161 |
166 // Creates and initializes an instance of the DX11 device and the | 162 // Creates and initializes an instance of the DX11 device and the |
167 // corresponding device manager. The device manager instance is eventually | 163 // corresponding device manager. The device manager instance is eventually |
168 // passed to the IMFTransform interface implemented by the decoder. | 164 // passed to the IMFTransform interface implemented by the decoder. |
169 bool CreateDX11DevManager(); | 165 bool CreateDX11DevManager(); |
170 | 166 |
171 // Creates, initializes and sets the media codec types for the decoder. | 167 // Creates, initializes and sets the media codec types for the decoder. |
172 bool InitDecoder(media::VideoCodecProfile profile); | 168 bool InitDecoder(VideoCodecProfile profile); |
173 | 169 |
174 // Validates whether the decoder supports hardware video acceleration. | 170 // Validates whether the decoder supports hardware video acceleration. |
175 bool CheckDecoderDxvaSupport(); | 171 bool CheckDecoderDxvaSupport(); |
176 | 172 |
177 // Returns information about the input and output streams. This includes | 173 // Returns information about the input and output streams. This includes |
178 // alignment information, decoder support flags, minimum sample size, etc. | 174 // alignment information, decoder support flags, minimum sample size, etc. |
179 bool GetStreamsInfoAndBufferReqs(); | 175 bool GetStreamsInfoAndBufferReqs(); |
180 | 176 |
181 // Registers the input and output media types on the decoder. This includes | 177 // Registers the input and output media types on the decoder. This includes |
182 // the expected input and output formats. | 178 // the expected input and output formats. |
(...skipping 16 matching lines...) Expand all Loading... |
199 // Invoked when we have a valid decoded output sample. Retrieves the D3D | 195 // Invoked when we have a valid decoded output sample. Retrieves the D3D |
200 // surface and maintains a copy of it which is passed eventually to the | 196 // surface and maintains a copy of it which is passed eventually to the |
201 // client when we have a picture buffer to copy the surface contents to. | 197 // client when we have a picture buffer to copy the surface contents to. |
202 bool ProcessOutputSample(IMFSample* sample); | 198 bool ProcessOutputSample(IMFSample* sample); |
203 | 199 |
204 // Processes pending output samples by copying them to available picture | 200 // Processes pending output samples by copying them to available picture |
205 // slots. | 201 // slots. |
206 void ProcessPendingSamples(); | 202 void ProcessPendingSamples(); |
207 | 203 |
208 // Helper function to notify the accelerator client about the error. | 204 // Helper function to notify the accelerator client about the error. |
209 void StopOnError(media::VideoDecodeAccelerator::Error error); | 205 void StopOnError(VideoDecodeAccelerator::Error error); |
210 | 206 |
211 // Transitions the decoder to the uninitialized state. The decoder will stop | 207 // Transitions the decoder to the uninitialized state. The decoder will stop |
212 // accepting requests in this state. | 208 // accepting requests in this state. |
213 void Invalidate(); | 209 void Invalidate(); |
214 | 210 |
215 // Notifies the client that the input buffer identifed by input_buffer_id has | 211 // Notifies the client that the input buffer identifed by input_buffer_id has |
216 // been processed. | 212 // been processed. |
217 void NotifyInputBufferRead(int input_buffer_id); | 213 void NotifyInputBufferRead(int input_buffer_id); |
218 | 214 |
219 // Notifies the client that the decoder was flushed. | 215 // Notifies the client that the decoder was flushed. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 // Returns S_OK or S_FALSE on succcess. | 334 // Returns S_OK or S_FALSE on succcess. |
339 // The |config_changed| parameter is set to true if we detect a change in the | 335 // The |config_changed| parameter is set to true if we detect a change in the |
340 // stream. | 336 // stream. |
341 HRESULT CheckConfigChanged(IMFSample* sample, bool* config_changed); | 337 HRESULT CheckConfigChanged(IMFSample* sample, bool* config_changed); |
342 | 338 |
343 // Called when we detect a stream configuration change. We reinitialize the | 339 // Called when we detect a stream configuration change. We reinitialize the |
344 // decoder here. | 340 // decoder here. |
345 void ConfigChanged(const Config& config); | 341 void ConfigChanged(const Config& config); |
346 | 342 |
347 // To expose client callbacks from VideoDecodeAccelerator. | 343 // To expose client callbacks from VideoDecodeAccelerator. |
348 media::VideoDecodeAccelerator::Client* client_; | 344 VideoDecodeAccelerator::Client* client_; |
349 | 345 |
350 base::win::ScopedComPtr<IMFTransform> decoder_; | 346 base::win::ScopedComPtr<IMFTransform> decoder_; |
351 base::win::ScopedComPtr<IMFTransform> video_format_converter_mft_; | 347 base::win::ScopedComPtr<IMFTransform> video_format_converter_mft_; |
352 | 348 |
353 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; | 349 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; |
354 base::win::ScopedComPtr<IDirect3DDevice9Ex> d3d9_device_ex_; | 350 base::win::ScopedComPtr<IDirect3DDevice9Ex> d3d9_device_ex_; |
355 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; | 351 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; |
356 base::win::ScopedComPtr<IDirect3DQuery9> query_; | 352 base::win::ScopedComPtr<IDirect3DQuery9> query_; |
357 | 353 |
358 base::win::ScopedComPtr<ID3D11Device> d3d11_device_; | 354 base::win::ScopedComPtr<ID3D11Device> d3d11_device_; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 // List of input samples waiting to be processed. | 423 // List of input samples waiting to be processed. |
428 typedef std::list<base::win::ScopedComPtr<IMFSample>> PendingInputs; | 424 typedef std::list<base::win::ScopedComPtr<IMFSample>> PendingInputs; |
429 PendingInputs pending_input_buffers_; | 425 PendingInputs pending_input_buffers_; |
430 | 426 |
431 // Callback to get current GLContext. | 427 // Callback to get current GLContext. |
432 GetGLContextCallback get_gl_context_cb_; | 428 GetGLContextCallback get_gl_context_cb_; |
433 // Callback to set the correct gl context. | 429 // Callback to set the correct gl context. |
434 MakeGLContextCurrentCallback make_context_current_cb_; | 430 MakeGLContextCurrentCallback make_context_current_cb_; |
435 | 431 |
436 // Which codec we are decoding with hardware acceleration. | 432 // Which codec we are decoding with hardware acceleration. |
437 media::VideoCodec codec_; | 433 VideoCodec codec_; |
438 // Thread on which the decoder operations like passing input frames, | 434 // Thread on which the decoder operations like passing input frames, |
439 // getting output frames are performed. One instance of this thread | 435 // getting output frames are performed. One instance of this thread |
440 // is created per decoder instance. | 436 // is created per decoder instance. |
441 base::Thread decoder_thread_; | 437 base::Thread decoder_thread_; |
442 | 438 |
443 // Task runner to be used for posting tasks to the decoder thread. | 439 // Task runner to be used for posting tasks to the decoder thread. |
444 scoped_refptr<base::SingleThreadTaskRunner> decoder_thread_task_runner_; | 440 scoped_refptr<base::SingleThreadTaskRunner> decoder_thread_task_runner_; |
445 | 441 |
446 // Task runner to be used for posting tasks to the main thread. | 442 // Task runner to be used for posting tasks to the main thread. |
447 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 443 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 490 |
495 // Function pointer for the MFCreateDXGIDeviceManager API. | 491 // Function pointer for the MFCreateDXGIDeviceManager API. |
496 static CreateDXGIDeviceManager create_dxgi_device_manager_; | 492 static CreateDXGIDeviceManager create_dxgi_device_manager_; |
497 | 493 |
498 DISALLOW_COPY_AND_ASSIGN(DXVAVideoDecodeAccelerator); | 494 DISALLOW_COPY_AND_ASSIGN(DXVAVideoDecodeAccelerator); |
499 }; | 495 }; |
500 | 496 |
501 } // namespace media | 497 } // namespace media |
502 | 498 |
503 #endif // MEDIA_GPU_DXVA_VIDEO_DECODE_ACCELERATOR_WIN_H_ | 499 #endif // MEDIA_GPU_DXVA_VIDEO_DECODE_ACCELERATOR_WIN_H_ |
OLD | NEW |