Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: content/common/gpu/media/dxva_video_decode_accelerator_win.h

Issue 1815063002: Detect configuration changes in H.264 video streams in the DXVA decoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Report config changed only after we see an IDR frame Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <d3d11.h>
9 #include <d3d9.h> 9 #include <d3d9.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 26 matching lines...) Expand all
37 namespace gfx { 37 namespace gfx {
38 class GLContext; 38 class GLContext;
39 } 39 }
40 40
41 typedef HRESULT (WINAPI* CreateDXGIDeviceManager)( 41 typedef HRESULT (WINAPI* CreateDXGIDeviceManager)(
42 UINT* reset_token, 42 UINT* reset_token,
43 IMFDXGIDeviceManager** device_manager); 43 IMFDXGIDeviceManager** device_manager);
44 44
45 namespace content { 45 namespace content {
46 46
47 // Provides functionality to detect H.264 stream configuration changes.
48 // TODO(ananta)
49 // Move this to a common place so that all VDA's can use this.
50 class H264ConfigChangeDetector {
51 public:
52 H264ConfigChangeDetector();
53 ~H264ConfigChangeDetector();
54
55 // Detects stream configuration changes.
56 // Returns false on failure.
57 bool DetectConfig(const uint8_t* stream, unsigned int size);
58
59 bool config_changed() const {
60 return config_changed_;
61 }
62
63 private:
64 // These fields are used to track the SPS/PPS in the H.264 bitstream and
65 // are eventually compared against the SPS/PPS in the bitstream to detect
66 // a change.
67 int last_sps_id_;
68 std::vector<uint8_t> last_sps_;
69 int last_pps_id_;
70 std::vector<uint8_t> last_pps_;
71 bool config_changed_;
72
73 DISALLOW_COPY_AND_ASSIGN(H264ConfigChangeDetector);
74 };
75
76
47 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media 77 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media
48 // foundation APIs via the VideoDecodeAccelerator interface. 78 // foundation APIs via the VideoDecodeAccelerator interface.
49 // This class lives on a single thread and DCHECKs that it is never accessed 79 // This class lives on a single thread and DCHECKs that it is never accessed
50 // from any other. 80 // from any other.
51 class CONTENT_EXPORT DXVAVideoDecodeAccelerator 81 class CONTENT_EXPORT DXVAVideoDecodeAccelerator
52 : public media::VideoDecodeAccelerator { 82 : public media::VideoDecodeAccelerator {
53 public: 83 public:
54 enum State { 84 enum State {
55 kUninitialized, // un-initialized. 85 kUninitialized, // un-initialized.
56 kNormal, // normal playing state. 86 kNormal, // normal playing state.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Helper for handling the Decode operation. 202 // Helper for handling the Decode operation.
173 void DecodeInternal(const base::win::ScopedComPtr<IMFSample>& input_sample); 203 void DecodeInternal(const base::win::ScopedComPtr<IMFSample>& input_sample);
174 204
175 // Handles mid stream resolution changes. 205 // Handles mid stream resolution changes.
176 void HandleResolutionChanged(int width, int height); 206 void HandleResolutionChanged(int width, int height);
177 207
178 struct DXVAPictureBuffer; 208 struct DXVAPictureBuffer;
179 typedef std::map<int32_t, linked_ptr<DXVAPictureBuffer>> OutputBuffers; 209 typedef std::map<int32_t, linked_ptr<DXVAPictureBuffer>> OutputBuffers;
180 210
181 // Tells the client to dismiss the stale picture buffers passed in. 211 // Tells the client to dismiss the stale picture buffers passed in.
182 void DismissStaleBuffers(); 212 void DismissStaleBuffers(bool force);
183 213
184 // Called after the client indicates we can recycle a stale picture buffer. 214 // Called after the client indicates we can recycle a stale picture buffer.
185 void DeferredDismissStaleBuffer(int32_t picture_buffer_id); 215 void DeferredDismissStaleBuffer(int32_t picture_buffer_id);
186 216
187 // Sets the state of the decoder. Called from the main thread and the decoder 217 // Sets the state of the decoder. Called from the main thread and the decoder
188 // thread. The state is changed on the main thread. 218 // thread. The state is changed on the main thread.
189 void SetState(State state); 219 void SetState(State state);
190 220
191 // Gets the state of the decoder. Can be called from the main thread and 221 // Gets the state of the decoder. Can be called from the main thread and
192 // the decoder thread. Thread safe. 222 // the decoder thread. Thread safe.
193 State GetState(); 223 State GetState();
194 224
195 // Worker function for the Decoder Reset functionality. Executes on the
196 // decoder thread and queues tasks on the main thread as needed.
197 void ResetHelper();
198
199 // Starts the thread used for decoding. 225 // Starts the thread used for decoding.
200 void StartDecoderThread(); 226 void StartDecoderThread();
201 227
202 // Returns if we have output samples waiting to be processed. We only 228 // Returns if we have output samples waiting to be processed. We only
203 // allow one output sample to be present in the output queue at any given 229 // allow one output sample to be present in the output queue at any given
204 // time. 230 // time.
205 bool OutputSamplesPresent(); 231 bool OutputSamplesPresent();
206 232
207 // Copies the source surface |src_surface| to the destination |dest_surface|. 233 // Copies the source surface |src_surface| to the destination |dest_surface|.
208 // The copying is done on the decoder thread. 234 // The copying is done on the decoder thread.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // the |output_type| parameter. The GUID can be MFVideoFormat_RGB32, 283 // the |output_type| parameter. The GUID can be MFVideoFormat_RGB32,
258 // MFVideoFormat_ARGB32, MFVideoFormat_NV12, etc. 284 // MFVideoFormat_ARGB32, MFVideoFormat_NV12, etc.
259 // Additionally if the |width| and |height| parameters are non zero, then 285 // Additionally if the |width| and |height| parameters are non zero, then
260 // this function also sets the MF_MT_FRAME_SIZE attribute on the type. 286 // this function also sets the MF_MT_FRAME_SIZE attribute on the type.
261 // Returns true on success. 287 // Returns true on success.
262 bool SetTransformOutputType(IMFTransform* transform, 288 bool SetTransformOutputType(IMFTransform* transform,
263 const GUID& output_type, 289 const GUID& output_type,
264 int width, 290 int width,
265 int height); 291 int height);
266 292
293 // Checks if the resolution, bitrate etc of the stream changed. We do this
294 // by keeping track of the SPS/PPS frames and if they change we assume
295 // that the configuration changed.
296 // Returns S_OK or S_FALSE on succcess.
297 // The |config_changed| parameter is set to true if we detect a change in the
298 // stream.
299 HRESULT CheckConfigChanged(IMFSample* sample, bool* config_changed);
300
301 // Called when we detect a stream configuration change. We reinitialize the
302 // decoder here.
303 void ConfigChanged(const Config& config,
304 const base::win::ScopedComPtr<IMFSample>& input_sample);
305
267 // To expose client callbacks from VideoDecodeAccelerator. 306 // To expose client callbacks from VideoDecodeAccelerator.
268 media::VideoDecodeAccelerator::Client* client_; 307 media::VideoDecodeAccelerator::Client* client_;
269 308
270 base::win::ScopedComPtr<IMFTransform> decoder_; 309 base::win::ScopedComPtr<IMFTransform> decoder_;
271 base::win::ScopedComPtr<IMFTransform> video_format_converter_mft_; 310 base::win::ScopedComPtr<IMFTransform> video_format_converter_mft_;
272 311
273 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; 312 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_;
274 base::win::ScopedComPtr<IDirect3DDevice9Ex> d3d9_device_ex_; 313 base::win::ScopedComPtr<IDirect3DDevice9Ex> d3d9_device_ex_;
275 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; 314 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_;
276 base::win::ScopedComPtr<IDirect3DQuery9> query_; 315 base::win::ScopedComPtr<IDirect3DQuery9> query_;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 435
397 // Enables experimental hardware acceleration for VP8/VP9 video decoding. 436 // Enables experimental hardware acceleration for VP8/VP9 video decoding.
398 const bool enable_accelerated_vpx_decode_; 437 const bool enable_accelerated_vpx_decode_;
399 438
400 // WeakPtrFactory for posting tasks back to |this|. 439 // WeakPtrFactory for posting tasks back to |this|.
401 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_; 440 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_;
402 441
403 // Function pointer for the MFCreateDXGIDeviceManager API. 442 // Function pointer for the MFCreateDXGIDeviceManager API.
404 static CreateDXGIDeviceManager create_dxgi_device_manager_; 443 static CreateDXGIDeviceManager create_dxgi_device_manager_;
405 444
445 // The media foundation H.264 decoder has problems handling changes like
446 // resolution change, bitrate change etc. If we reinitialize the decoder
447 // when these changes occur then, the decoder works fine. The
448 // H264ConfigChangeDetector class provides functionality to check if the
449 // stream configuration changed.
450 H264ConfigChangeDetector config_change_detector_;
451
452 // Contains the initialization parameters for the video.
453 Config config_;
454
406 DISALLOW_COPY_AND_ASSIGN(DXVAVideoDecodeAccelerator); 455 DISALLOW_COPY_AND_ASSIGN(DXVAVideoDecodeAccelerator);
407 }; 456 };
408 457
409 } // namespace content 458 } // namespace content
410 459
411 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ 460 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698