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

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: Flag a pending configuration change if we detect a change in SPS/PPS and return config changed the … 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
« no previous file with comments | « no previous file | content/common/gpu/media/dxva_video_decode_accelerator_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Set to true if we detect a stream configuration change.
72 bool config_changed_;
73 // We want to indicate configuration changes only after we see IDR slices.
74 // This flag tracks that we potentially have a configuration change which
75 // we want to honor after we see an IDR slice.
76 bool pending_config_changed_;
77
78 DISALLOW_COPY_AND_ASSIGN(H264ConfigChangeDetector);
79 };
80
81
47 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media 82 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media
48 // foundation APIs via the VideoDecodeAccelerator interface. 83 // foundation APIs via the VideoDecodeAccelerator interface.
49 // This class lives on a single thread and DCHECKs that it is never accessed 84 // This class lives on a single thread and DCHECKs that it is never accessed
50 // from any other. 85 // from any other.
51 class CONTENT_EXPORT DXVAVideoDecodeAccelerator 86 class CONTENT_EXPORT DXVAVideoDecodeAccelerator
52 : public media::VideoDecodeAccelerator { 87 : public media::VideoDecodeAccelerator {
53 public: 88 public:
54 enum State { 89 enum State {
55 kUninitialized, // un-initialized. 90 kUninitialized, // un-initialized.
56 kNormal, // normal playing state. 91 kNormal, // normal playing state.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Helper for handling the Decode operation. 207 // Helper for handling the Decode operation.
173 void DecodeInternal(const base::win::ScopedComPtr<IMFSample>& input_sample); 208 void DecodeInternal(const base::win::ScopedComPtr<IMFSample>& input_sample);
174 209
175 // Handles mid stream resolution changes. 210 // Handles mid stream resolution changes.
176 void HandleResolutionChanged(int width, int height); 211 void HandleResolutionChanged(int width, int height);
177 212
178 struct DXVAPictureBuffer; 213 struct DXVAPictureBuffer;
179 typedef std::map<int32_t, linked_ptr<DXVAPictureBuffer>> OutputBuffers; 214 typedef std::map<int32_t, linked_ptr<DXVAPictureBuffer>> OutputBuffers;
180 215
181 // Tells the client to dismiss the stale picture buffers passed in. 216 // Tells the client to dismiss the stale picture buffers passed in.
182 void DismissStaleBuffers(); 217 void DismissStaleBuffers(bool force);
183 218
184 // Called after the client indicates we can recycle a stale picture buffer. 219 // Called after the client indicates we can recycle a stale picture buffer.
185 void DeferredDismissStaleBuffer(int32_t picture_buffer_id); 220 void DeferredDismissStaleBuffer(int32_t picture_buffer_id);
186 221
187 // Sets the state of the decoder. Called from the main thread and the decoder 222 // Sets the state of the decoder. Called from the main thread and the decoder
188 // thread. The state is changed on the main thread. 223 // thread. The state is changed on the main thread.
189 void SetState(State state); 224 void SetState(State state);
190 225
191 // Gets the state of the decoder. Can be called from the main thread and 226 // Gets the state of the decoder. Can be called from the main thread and
192 // the decoder thread. Thread safe. 227 // the decoder thread. Thread safe.
193 State GetState(); 228 State GetState();
194 229
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. 230 // Starts the thread used for decoding.
200 void StartDecoderThread(); 231 void StartDecoderThread();
201 232
202 // Returns if we have output samples waiting to be processed. We only 233 // 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 234 // allow one output sample to be present in the output queue at any given
204 // time. 235 // time.
205 bool OutputSamplesPresent(); 236 bool OutputSamplesPresent();
206 237
207 // Copies the source surface |src_surface| to the destination |dest_surface|. 238 // Copies the source surface |src_surface| to the destination |dest_surface|.
208 // The copying is done on the decoder thread. 239 // 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, 288 // the |output_type| parameter. The GUID can be MFVideoFormat_RGB32,
258 // MFVideoFormat_ARGB32, MFVideoFormat_NV12, etc. 289 // MFVideoFormat_ARGB32, MFVideoFormat_NV12, etc.
259 // Additionally if the |width| and |height| parameters are non zero, then 290 // 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. 291 // this function also sets the MF_MT_FRAME_SIZE attribute on the type.
261 // Returns true on success. 292 // Returns true on success.
262 bool SetTransformOutputType(IMFTransform* transform, 293 bool SetTransformOutputType(IMFTransform* transform,
263 const GUID& output_type, 294 const GUID& output_type,
264 int width, 295 int width,
265 int height); 296 int height);
266 297
298 // Checks if the resolution, bitrate etc of the stream changed. We do this
299 // by keeping track of the SPS/PPS frames and if they change we assume
300 // that the configuration changed.
301 // Returns S_OK or S_FALSE on succcess.
302 // The |config_changed| parameter is set to true if we detect a change in the
303 // stream.
304 HRESULT CheckConfigChanged(IMFSample* sample, bool* config_changed);
305
306 // Called when we detect a stream configuration change. We reinitialize the
307 // decoder here.
308 void ConfigChanged(const Config& config,
309 const base::win::ScopedComPtr<IMFSample>& input_sample);
310
267 // To expose client callbacks from VideoDecodeAccelerator. 311 // To expose client callbacks from VideoDecodeAccelerator.
268 media::VideoDecodeAccelerator::Client* client_; 312 media::VideoDecodeAccelerator::Client* client_;
269 313
270 base::win::ScopedComPtr<IMFTransform> decoder_; 314 base::win::ScopedComPtr<IMFTransform> decoder_;
271 base::win::ScopedComPtr<IMFTransform> video_format_converter_mft_; 315 base::win::ScopedComPtr<IMFTransform> video_format_converter_mft_;
272 316
273 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; 317 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_;
274 base::win::ScopedComPtr<IDirect3DDevice9Ex> d3d9_device_ex_; 318 base::win::ScopedComPtr<IDirect3DDevice9Ex> d3d9_device_ex_;
275 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; 319 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_;
276 base::win::ScopedComPtr<IDirect3DQuery9> query_; 320 base::win::ScopedComPtr<IDirect3DQuery9> query_;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 440
397 // Enables experimental hardware acceleration for VP8/VP9 video decoding. 441 // Enables experimental hardware acceleration for VP8/VP9 video decoding.
398 const bool enable_accelerated_vpx_decode_; 442 const bool enable_accelerated_vpx_decode_;
399 443
400 // WeakPtrFactory for posting tasks back to |this|. 444 // WeakPtrFactory for posting tasks back to |this|.
401 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_; 445 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_;
402 446
403 // Function pointer for the MFCreateDXGIDeviceManager API. 447 // Function pointer for the MFCreateDXGIDeviceManager API.
404 static CreateDXGIDeviceManager create_dxgi_device_manager_; 448 static CreateDXGIDeviceManager create_dxgi_device_manager_;
405 449
450 // The media foundation H.264 decoder has problems handling changes like
451 // resolution change, bitrate change etc. If we reinitialize the decoder
452 // when these changes occur then, the decoder works fine. The
453 // H264ConfigChangeDetector class provides functionality to check if the
454 // stream configuration changed.
455 H264ConfigChangeDetector config_change_detector_;
456
457 // Contains the initialization parameters for the video.
458 Config config_;
459
406 DISALLOW_COPY_AND_ASSIGN(DXVAVideoDecodeAccelerator); 460 DISALLOW_COPY_AND_ASSIGN(DXVAVideoDecodeAccelerator);
407 }; 461 };
408 462
409 } // namespace content 463 } // namespace content
410 464
411 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ 465 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW
« no previous file with comments | « no previous file | content/common/gpu/media/dxva_video_decode_accelerator_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698