dxva_video_decode_accelerator_win.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_GPU_WINDOWS_DXVA_VIDEO_DECODE_ACCELERATOR_WIN_H_
  5. #define MEDIA_GPU_WINDOWS_DXVA_VIDEO_DECODE_ACCELERATOR_WIN_H_
  6. #include <d3d11_1.h>
  7. #include <d3d9.h>
  8. #include <dxva2api.h>
  9. #include <initguid.h>
  10. #include <mfidl.h>
  11. #include <stdint.h>
  12. #include <wrl/client.h>
  13. #include <list>
  14. #include <map>
  15. #include <memory>
  16. #include <vector>
  17. #include "base/compiler_specific.h"
  18. #include "base/memory/raw_ptr.h"
  19. #include "base/memory/weak_ptr.h"
  20. #include "base/synchronization/lock.h"
  21. #include "base/threading/thread.h"
  22. #include "gpu/config/gpu_preferences.h"
  23. #include "media/base/video_color_space.h"
  24. #include "media/gpu/gpu_video_decode_accelerator_helpers.h"
  25. #include "media/gpu/media_gpu_export.h"
  26. #include "media/gpu/windows/d3d11_com_defs.h"
  27. #include "media/video/video_decode_accelerator.h"
  28. #include "ui/gfx/color_space.h"
  29. #include "ui/gfx/geometry/rect.h"
  30. #include "ui/gl/hdr_metadata_helper_win.h"
  31. interface IMFSample;
  32. interface IDirect3DSurface9;
  33. namespace gl {
  34. class GLContext;
  35. class GLImageDXGI;
  36. }
  37. namespace gpu {
  38. class GpuDriverBugWorkarounds;
  39. struct GpuPreferences;
  40. } // namespace gpu
  41. typedef HRESULT(WINAPI* CreateDXGIDeviceManager)(
  42. UINT* reset_token,
  43. IMFDXGIDeviceManager** device_manager);
  44. namespace media {
  45. class DXVAPictureBuffer;
  46. class EGLStreamCopyPictureBuffer;
  47. class EGLStreamPictureBuffer;
  48. class MediaLog;
  49. class PbufferPictureBuffer;
  50. class ConfigChangeDetector {
  51. public:
  52. virtual ~ConfigChangeDetector();
  53. virtual bool DetectConfig(const uint8_t* stream, unsigned int size) = 0;
  54. virtual gfx::Rect current_visible_rect(
  55. const gfx::Rect& container_visible_rect) const = 0;
  56. virtual VideoColorSpace current_color_space(
  57. const VideoColorSpace& container_color_space) const = 0;
  58. virtual bool IsYUV420() const;
  59. virtual bool is_vp9_resilient_mode() const;
  60. bool config_changed() const { return config_changed_; }
  61. protected:
  62. // Set to true if we detect a stream configuration change.
  63. bool config_changed_ = false;
  64. };
  65. // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media
  66. // foundation APIs via the VideoDecodeAccelerator interface.
  67. // This class lives on a single thread and DCHECKs that it is never accessed
  68. // from any other.
  69. class MEDIA_GPU_EXPORT DXVAVideoDecodeAccelerator
  70. : public VideoDecodeAccelerator {
  71. public:
  72. enum State {
  73. kUninitialized, // un-initialized.
  74. kNormal, // normal playing state.
  75. kResetting, // upon received Reset(), before ResetDone()
  76. kStopped, // upon output EOS received.
  77. kFlushing, // upon flush request received.
  78. };
  79. // Does not take ownership of |client| which must outlive |*this|.
  80. DXVAVideoDecodeAccelerator(
  81. const GetGLContextCallback& get_gl_context_cb,
  82. const MakeGLContextCurrentCallback& make_context_current_cb,
  83. const BindGLImageCallback& bind_image_cb,
  84. const gpu::GpuDriverBugWorkarounds& workarounds,
  85. const gpu::GpuPreferences& gpu_preferences,
  86. MediaLog* media_log);
  87. DXVAVideoDecodeAccelerator(const DXVAVideoDecodeAccelerator&) = delete;
  88. DXVAVideoDecodeAccelerator& operator=(const DXVAVideoDecodeAccelerator&) =
  89. delete;
  90. ~DXVAVideoDecodeAccelerator() override;
  91. // VideoDecodeAccelerator implementation.
  92. bool Initialize(const Config& config, Client* client) override;
  93. void Decode(BitstreamBuffer bitstream) override;
  94. void Decode(scoped_refptr<DecoderBuffer> buffer,
  95. int32_t bitstream_id) override;
  96. void AssignPictureBuffers(const std::vector<PictureBuffer>& buffers) override;
  97. void ReusePictureBuffer(int32_t picture_buffer_id) override;
  98. void Flush() override;
  99. void Reset() override;
  100. void Destroy() override;
  101. bool TryToSetupDecodeOnSeparateThread(
  102. const base::WeakPtr<Client>& decode_client,
  103. const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner)
  104. override;
  105. GLenum GetSurfaceInternalFormat() const override;
  106. bool SupportsSharedImagePictureBuffers() const override;
  107. static VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(
  108. const gpu::GpuPreferences& gpu_preferences,
  109. const gpu::GpuDriverBugWorkarounds& workarounds);
  110. // Preload dlls required for decoding.
  111. static void PreSandboxInitialization();
  112. private:
  113. friend class DXVAPictureBuffer;
  114. friend class EGLStreamDelayedCopyPictureBuffer;
  115. friend class EGLStreamCopyPictureBuffer;
  116. friend class EGLStreamPictureBuffer;
  117. friend class PbufferPictureBuffer;
  118. typedef void* EGLConfig;
  119. typedef void* EGLSurface;
  120. typedef std::list<Microsoft::WRL::ComPtr<IMFSample>> PendingInputs;
  121. // These are used for histograms, so don't change their numeric value (except
  122. // for kMaxValue as described below).
  123. enum class PictureBufferMechanism {
  124. // Copy to either a BGRA8 or FP16 texture using the video processor.
  125. COPY_TO_RGB = 0,
  126. // Copy to another NV12 texture that can be used in ANGLE.
  127. COPY_TO_NV12 = 1,
  128. // Bind the resulting GLImage to the NV12 texture. If the texture's used
  129. // in a an overlay than use it directly, otherwise copy it to another NV12
  130. // texture when necessary.
  131. DELAYED_COPY_TO_NV12 = 2,
  132. // Bind the NV12 decoder texture directly to the texture used in ANGLE.
  133. BIND = 3,
  134. // For UMA. Must be the last entry. It should be initialized to the
  135. // numerically largest value above; if you add more entries, then please
  136. // update this to be the last one.
  137. kMaxValue = BIND
  138. };
  139. // Creates and initializes an instance of the D3D device and the
  140. // corresponding device manager. The device manager instance is eventually
  141. // passed to the IMFTransform interface implemented by the decoder.
  142. bool CreateD3DDevManager();
  143. // TODO(hubbe): COMMENT
  144. bool CreateVideoProcessor();
  145. // Creates and initializes an instance of the DX11 device and the
  146. // corresponding device manager. The device manager instance is eventually
  147. // passed to the IMFTransform interface implemented by the decoder.
  148. bool CreateDX11DevManager();
  149. // Creates, initializes and sets the media codec types for the decoder.
  150. bool InitDecoder(VideoCodecProfile profile);
  151. // Validates whether the decoder supports hardware video acceleration.
  152. bool CheckDecoderDxvaSupport();
  153. // Returns information about the input and output streams. This includes
  154. // alignment information, decoder support flags, minimum sample size, etc.
  155. bool GetStreamsInfoAndBufferReqs();
  156. // Registers the input and output media types on the decoder. This includes
  157. // the expected input and output formats.
  158. bool SetDecoderMediaTypes();
  159. // Registers the input media type for the decoder.
  160. bool SetDecoderInputMediaType();
  161. // Registers the output media type for the decoder.
  162. bool SetDecoderOutputMediaType(const GUID& subtype);
  163. // Passes a command message to the decoder. This includes commands like
  164. // start of stream, end of stream, flush, drain the decoder, etc.
  165. bool SendMFTMessage(MFT_MESSAGE_TYPE msg, int32_t param);
  166. // The bulk of the decoding happens here. This function handles errors,
  167. // format changes and processes decoded output.
  168. void DoDecode(const gfx::Rect& visible_rect,
  169. const gfx::ColorSpace& color_space);
  170. // Invoked when we have a valid decoded output sample. Retrieves the D3D
  171. // surface and maintains a copy of it which is passed eventually to the
  172. // client when we have a picture buffer to copy the surface contents to.
  173. bool ProcessOutputSample(Microsoft::WRL::ComPtr<IMFSample> sample,
  174. const gfx::Rect& visible_rect,
  175. const gfx::ColorSpace& color_space);
  176. // Processes pending output samples by copying them to available picture
  177. // slots.
  178. void ProcessPendingSamples();
  179. // Helper function to notify the accelerator client about the error.
  180. void StopOnError(VideoDecodeAccelerator::Error error);
  181. // Transitions the decoder to the uninitialized state. The decoder will stop
  182. // accepting requests in this state.
  183. void Invalidate(bool for_config_change = false);
  184. // Stop and join on the decoder thread.
  185. void StopDecoderThread();
  186. // Notifies the client that the input buffer identifed by input_buffer_id has
  187. // been processed.
  188. void NotifyInputBufferRead(int input_buffer_id);
  189. // Notifies the client that the decoder was flushed.
  190. void NotifyFlushDone();
  191. // Notifies the client that the decoder was reset.
  192. void NotifyResetDone();
  193. // Requests picture buffers from the client.
  194. void RequestPictureBuffers(int width, int height);
  195. // Notifies the client about the availability of a picture.
  196. void NotifyPictureReady(int picture_buffer_id,
  197. int input_buffer_id,
  198. const gfx::Rect& visible_rect,
  199. const gfx::ColorSpace& color_space,
  200. bool allow_overlay,
  201. std::vector<scoped_refptr<Picture::ScopedSharedImage>>
  202. shared_images = {});
  203. // Sends pending input buffer processed acks to the client if we don't have
  204. // output samples waiting to be processed.
  205. void NotifyInputBuffersDropped(const PendingInputs& input_buffers);
  206. // Decodes pending input buffers.
  207. void DecodePendingInputBuffers();
  208. // Helper for handling the Flush operation.
  209. void FlushInternal();
  210. // Helper for handling the Decode operation.
  211. void DecodeInternal(const Microsoft::WRL::ComPtr<IMFSample>& input_sample);
  212. // Handles mid stream resolution changes.
  213. void HandleResolutionChanged(int width, int height);
  214. using OutputBuffers = std::map<int32_t, std::unique_ptr<DXVAPictureBuffer>>;
  215. // Tells the client to dismiss the stale picture buffers passed in.
  216. void DismissStaleBuffers(bool force);
  217. // Called after the client indicates we can recycle a stale picture buffer.
  218. void DeferredDismissStaleBuffer(int32_t picture_buffer_id);
  219. // Sets the state of the decoder. Called from the main thread and the decoder
  220. // thread. The state is changed on the main thread.
  221. void SetState(State state);
  222. // Gets the state of the decoder. Can be called from the main thread and
  223. // the decoder thread. Thread safe.
  224. State GetState();
  225. // Starts the thread used for decoding. Returns true on success.
  226. bool StartDecoderThread();
  227. // Returns if we have output samples waiting to be processed. We only
  228. // allow one output sample to be present in the output queue at any given
  229. // time.
  230. bool OutputSamplesPresent();
  231. // Copies the source surface |src_surface| to the destination |dest_surface|.
  232. // The copying is done on the decoder thread.
  233. void CopySurface(IDirect3DSurface9* src_surface,
  234. IDirect3DSurface9* dest_surface,
  235. int picture_buffer_id,
  236. int input_buffer_id,
  237. const gfx::ColorSpace& color_space);
  238. // This is a notification that the source surface |src_surface| was copied to
  239. // the destination |dest_surface|. Received on the main thread.
  240. void CopySurfaceComplete(IDirect3DSurface9* src_surface,
  241. IDirect3DSurface9* dest_surface,
  242. int picture_buffer_id,
  243. int input_buffer_id);
  244. void BindPictureBufferToSample(Microsoft::WRL::ComPtr<IMFSample> sample,
  245. int picture_buffer_id,
  246. int input_buffer_id);
  247. // Copies the source texture |src_texture| to the destination |dest_texture|.
  248. // The copying is done on the decoder thread. Returns true on success.
  249. bool CopyTexture(ID3D11Texture2D* src_texture,
  250. ID3D11Texture2D* dest_texture,
  251. Microsoft::WRL::ComPtr<IDXGIKeyedMutex> dest_keyed_mutex,
  252. uint64_t keyed_mutex_value,
  253. int picture_buffer_id,
  254. int input_buffer_id,
  255. const gfx::ColorSpace& color_space);
  256. // Copies the |video_frame| to the destination |dest_texture|.
  257. void CopyTextureOnDecoderThread(
  258. ID3D11Texture2D* dest_texture,
  259. Microsoft::WRL::ComPtr<IDXGIKeyedMutex> dest_keyed_mutex,
  260. uint64_t keyed_mutex_value,
  261. Microsoft::WRL::ComPtr<IMFSample> input_sample,
  262. int picture_buffer_id,
  263. int input_buffer_id);
  264. // Flushes the decoder device to ensure that the decoded surface is copied
  265. // to the target surface. |iterations| helps to maintain an upper limit on
  266. // the number of times we try to complete the flush operation.
  267. void FlushDecoder(int iterations,
  268. IDirect3DSurface9* src_surface,
  269. IDirect3DSurface9* dest_surface,
  270. int picture_buffer_id,
  271. int input_buffer_id);
  272. // Polls to wait for GPU commands to be finished on the picture buffer
  273. // before reusing it.
  274. void WaitForOutputBuffer(int32_t picture_buffer_id, int count);
  275. // Initialize the DX11 video processor.
  276. // Returns true on success.
  277. bool InitializeID3D11VideoProcessor(int width,
  278. int height,
  279. const gfx::ColorSpace& color_space);
  280. // Some devices require HDR metadata. This will set it if needed, else
  281. // do nothing.
  282. void SetDX11ProcessorHDRMetadataIfNeeded();
  283. // Returns the output video frame dimensions (width, height).
  284. // |sample| :- This is the output sample containing the video frame.
  285. // |width| :- The width is returned here.
  286. // |height| :- The height is returned here.
  287. // Returns true on success.
  288. bool GetVideoFrameDimensions(IMFSample* sample, int* width, int* height);
  289. // Sets the output type on the |transform| to the GUID identified by the
  290. // the |output_type| parameter. The GUID can be MFVideoFormat_RGB32,
  291. // MFVideoFormat_ARGB32, MFVideoFormat_NV12, etc.
  292. // Additionally if the |width| and |height| parameters are non zero, then
  293. // this function also sets the MF_MT_FRAME_SIZE attribute on the type.
  294. // Returns true on success.
  295. bool SetTransformOutputType(IMFTransform* transform,
  296. const GUID& output_type,
  297. int width,
  298. int height);
  299. // Checks if the resolution, bitrate etc of the stream changed. We do this
  300. // by keeping track of the SPS/PPS frames and if they change we assume
  301. // that the configuration changed.
  302. // Returns S_OK or S_FALSE on success.
  303. // The |config_changed| parameter is set to true if we detect a change in the
  304. // stream.
  305. HRESULT CheckConfigChanged(IMFSample* sample, bool* config_changed);
  306. // Called when we detect a stream configuration change. We reinitialize the
  307. // decoder here.
  308. void ConfigChanged(const Config& config);
  309. // Sets |support_share_nv12_textures_| to false and updates
  310. // |num_picture_buffers_requested_|.
  311. void DisableSharedTextureSupport();
  312. // Creates ScopedSharedImages for the provided PictureBuffer. If the buffer
  313. // has a GLImageDXGI this function will create D3DImageBacking using the
  314. // DX11 texture. Otherwise it will create thin GLImageBacking
  315. // wrappers around the existing textures in |picture_buffer|.
  316. std::vector<scoped_refptr<Picture::ScopedSharedImage>>
  317. GetSharedImagesFromPictureBuffer(DXVAPictureBuffer* picture_buffer);
  318. uint32_t GetTextureTarget() const;
  319. PictureBufferMechanism GetPictureBufferMechanism() const;
  320. bool ShouldUseANGLEDevice() const;
  321. ID3D11Device* D3D11Device() const;
  322. // To expose client callbacks from VideoDecodeAccelerator.
  323. raw_ptr<VideoDecodeAccelerator::Client> client_;
  324. Microsoft::WRL::ComPtr<IMFTransform> decoder_;
  325. Microsoft::WRL::ComPtr<IDirect3D9Ex> d3d9_;
  326. Microsoft::WRL::ComPtr<IDirect3DDevice9Ex> d3d9_device_ex_;
  327. Microsoft::WRL::ComPtr<IDirect3DDeviceManager9> device_manager_;
  328. Microsoft::WRL::ComPtr<IDirect3DQuery9> query_;
  329. ComD3D11Device d3d11_device_;
  330. ComD3D11Device angle_device_;
  331. Microsoft::WRL::ComPtr<IMFDXGIDeviceManager> d3d11_device_manager_;
  332. Microsoft::WRL::ComPtr<ID3D10Multithread> multi_threaded_;
  333. ComD3D11DeviceContext d3d11_device_context_;
  334. ComD3D11Query d3d11_query_;
  335. ComD3D11VideoDevice video_device_;
  336. ComD3D11VideoContext video_context_;
  337. ComD3D11VideoProcessorEnumerator enumerator_;
  338. ComD3D11VideoProcessor d3d11_processor_;
  339. int processor_width_ = 0;
  340. int processor_height_ = 0;
  341. // Used for lifetime progression logging. Have we logged that initialization
  342. // was successful, and nothing since?
  343. bool already_initialized_ = false;
  344. Microsoft::WRL::ComPtr<IDirectXVideoProcessorService>
  345. video_processor_service_;
  346. Microsoft::WRL::ComPtr<IDirectXVideoProcessor> processor_;
  347. DXVA2_ProcAmpValues default_procamp_values_;
  348. // Ideally the reset token would be a stack variable which is used while
  349. // creating the device manager. However it seems that the device manager
  350. // holds onto the token and attempts to access it if the underlying device
  351. // changes.
  352. // TODO(ananta): This needs to be verified.
  353. uint32_t dev_manager_reset_token_;
  354. // Reset token for the DX11 device manager.
  355. uint32_t dx11_dev_manager_reset_token_;
  356. // The EGL config to use for decoded frames.
  357. EGLConfig egl_config_;
  358. // Current state of the decoder.
  359. volatile State state_;
  360. MFT_INPUT_STREAM_INFO input_stream_info_;
  361. MFT_OUTPUT_STREAM_INFO output_stream_info_;
  362. // Contains information about a decoded sample.
  363. struct PendingSampleInfo {
  364. PendingSampleInfo(int32_t buffer_id,
  365. Microsoft::WRL::ComPtr<IMFSample> sample,
  366. const gfx::Rect& visible_rect,
  367. const gfx::ColorSpace& color_space);
  368. PendingSampleInfo(const PendingSampleInfo& other);
  369. ~PendingSampleInfo();
  370. int32_t input_buffer_id;
  371. // The target picture buffer id where the frame would be copied to.
  372. // Defaults to -1.
  373. int picture_buffer_id;
  374. gfx::Rect visible_rect;
  375. // The color space of this picture.
  376. gfx::ColorSpace color_space;
  377. Microsoft::WRL::ComPtr<IMFSample> output_sample;
  378. };
  379. typedef std::list<PendingSampleInfo> PendingOutputSamples;
  380. // List of decoded output samples. Protected by |decoder_lock_|.
  381. PendingOutputSamples pending_output_samples_;
  382. // This map maintains the picture buffers passed the client for decoding.
  383. // The key is the picture buffer id.
  384. OutputBuffers output_picture_buffers_;
  385. // After a resolution change there may be a few output buffers which have yet
  386. // to be displayed so they cannot be dismissed immediately. We move them from
  387. // |output_picture_buffers_| to this map so they may be dismissed once they
  388. // become available.
  389. OutputBuffers stale_output_picture_buffers_;
  390. // Set to true if we requested picture slots from the client.
  391. bool pictures_requested_;
  392. // Counter which holds the number of input packets before a successful
  393. // decode.
  394. int inputs_before_decode_;
  395. // Set to true when the drain message is sent to the decoder during a flush
  396. // operation. Used to ensure the message is only sent once after
  397. // |pending_input_buffers_| is drained. Protected by |decoder_lock_|.
  398. bool sent_drain_message_;
  399. // This is the array size of the D3D11 texture that's output to by the
  400. // decoder. It's only used for debugging.
  401. uint32_t output_array_size_ = 0;
  402. // List of input samples waiting to be processed.
  403. PendingInputs pending_input_buffers_;
  404. // Callback to get current GLContext.
  405. GetGLContextCallback get_gl_context_cb_;
  406. // Callback to set the correct gl context.
  407. MakeGLContextCurrentCallback make_context_current_cb_;
  408. BindGLImageCallback bind_image_cb_;
  409. // This may be null, e.g. when not using MojoVideoDecoder.
  410. const raw_ptr<MediaLog> media_log_;
  411. // Which codec we are decoding with hardware acceleration.
  412. VideoCodec codec_;
  413. // Thread on which the decoder operations like passing input frames,
  414. // getting output frames are performed. One instance of this thread
  415. // is created per decoder instance.
  416. base::Thread decoder_thread_;
  417. // Task runner to be used for posting tasks to the decoder thread.
  418. scoped_refptr<base::SingleThreadTaskRunner> decoder_thread_task_runner_;
  419. // Task runner to be used for posting tasks to the main thread.
  420. scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
  421. // Used to synchronize access between the decoder thread and the main thread.
  422. base::Lock decoder_lock_;
  423. // Disallow rebinding WeakReference ownership to a different thread by
  424. // keeping a persistent reference. This avoids problems with the
  425. // thread safety of reaching into this class from multiple threads to
  426. // attain a WeakPtr.
  427. base::WeakPtr<DXVAVideoDecodeAccelerator> weak_ptr_;
  428. // Set to true if we are in the context of a Flush operation. Used to prevent
  429. // multiple flush done notifications being sent out.
  430. bool pending_flush_;
  431. // Use CODECAPI_AVLowLatencyMode.
  432. bool enable_low_latency_;
  433. // Supports sharing the decoded NV12 textures with ANGLE
  434. bool support_share_nv12_textures_;
  435. // Number of requested picture buffers from the client which are used to hold
  436. // the decoded samples.
  437. int num_picture_buffers_requested_;
  438. // Supports copying the NV12 texture to another NV12 texture to use in
  439. // ANGLE.
  440. bool support_copy_nv12_textures_;
  441. // Supports copying NV12 textures on the main thread to use in ANGLE.
  442. bool support_delayed_copy_nv12_textures_;
  443. // Copy video to FP16 scRGB textures.
  444. bool use_fp16_ = false;
  445. // True if decoder's output is P010/P016.
  446. bool decoder_output_p010_or_p016_ = false;
  447. // When converting YUV to RGB, make sure we tell the blitter about the input
  448. // color space so that it can convert it correctly.
  449. bool use_color_info_ = true;
  450. // Defaults to false. Indicates if we should use D3D or DX11 interfaces for
  451. // H/W decoding.
  452. bool use_dx11_;
  453. // True when using Microsoft's VPx HMFT for decoding.
  454. bool using_ms_vpx_mft_ = false;
  455. // True if we should use DXGI keyed mutexes to synchronize between the two
  456. // contexts.
  457. bool use_keyed_mutex_;
  458. // Outputs from the dx11 format converter will be in this color space.
  459. gfx::ColorSpace dx11_converter_output_color_space_;
  460. // Set to true if we are sharing ANGLE's device.
  461. bool using_angle_device_;
  462. bool using_debug_device_;
  463. // Enables hardware acceleration for AV1 video decoding.
  464. const bool enable_accelerated_av1_decode_;
  465. // Enables hardware acceleration for VP8/VP9 video decoding.
  466. const bool enable_accelerated_vp8_decode_;
  467. const bool enable_accelerated_vp9_decode_;
  468. const bool disallow_vp9_resilient_dxva_decoding_;
  469. // The media foundation H.264 decoder has problems handling changes like
  470. // resolution change, bitrate change etc. If we reinitialize the decoder
  471. // when these changes occur then, the decoder works fine. The
  472. // H264ConfigChangeDetector class provides functionality to check if the
  473. // stream configuration changed.
  474. std::unique_ptr<ConfigChangeDetector> config_change_detector_;
  475. // Contains the initialization parameters for the video.
  476. Config config_;
  477. // Set to true if we are processing a video configuration change.
  478. bool processing_config_changed_;
  479. // Contain the visible rect and color space of frames that are currently being
  480. // fed into the decoder. These may change at a config change.
  481. gfx::Rect current_visible_rect_;
  482. VideoColorSpace current_color_space_;
  483. absl::optional<gl::HDRMetadataHelperWin> hdr_metadata_helper_;
  484. bool use_empty_video_hdr_metadata_ = false;
  485. // Have we delivered any decoded frames since the last call to Initialize()?
  486. bool decoded_any_frames_ = false;
  487. // WeakPtrFactory for posting tasks back to |this|.
  488. base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_{this};
  489. // Function pointer for the MFCreateDXGIDeviceManager API.
  490. static CreateDXGIDeviceManager create_dxgi_device_manager_;
  491. };
  492. } // namespace media
  493. #endif // MEDIA_GPU_WINDOWS_DXVA_VIDEO_DECODE_ACCELERATOR_WIN_H_