gpu_mojo_media_client_win.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright 2021 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. #include "media/mojo/services/gpu_mojo_media_client.h"
  5. #include "base/task/thread_pool.h"
  6. #include "base/win/windows_version.h"
  7. #include "media/base/audio_decoder.h"
  8. #include "media/base/media_switches.h"
  9. #include "media/base/offloading_audio_encoder.h"
  10. #if BUILDFLAG(USE_PROPRIETARY_CODECS) && BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
  11. #include "media/filters/win/media_foundation_audio_decoder.h"
  12. #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) &&
  13. // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
  14. #include "media/gpu/ipc/service/vda_video_decoder.h"
  15. #include "media/gpu/windows/d3d11_video_decoder.h"
  16. #include "media/gpu/windows/mf_audio_encoder.h"
  17. #include "ui/gl/direct_composition_support.h"
  18. #include "ui/gl/gl_angle_util_win.h"
  19. namespace media {
  20. namespace {
  21. D3D11VideoDecoder::GetD3D11DeviceCB GetD3D11DeviceCallback() {
  22. return base::BindRepeating(
  23. []() { return gl::QueryD3D11DeviceObjectFromANGLE(); });
  24. }
  25. bool ShouldUseD3D11VideoDecoder(
  26. const gpu::GpuDriverBugWorkarounds& gpu_workarounds) {
  27. return !gpu_workarounds.disable_d3d11_video_decoder &&
  28. base::win::GetVersion() > base::win::Version::WIN7;
  29. }
  30. } // namespace
  31. std::unique_ptr<VideoDecoder> CreatePlatformVideoDecoder(
  32. VideoDecoderTraits& traits) {
  33. if (!ShouldUseD3D11VideoDecoder(*traits.gpu_workarounds)) {
  34. if (traits.gpu_workarounds->disable_dxva_video_decoder)
  35. return nullptr;
  36. return VdaVideoDecoder::Create(
  37. traits.task_runner, traits.gpu_task_runner, traits.media_log->Clone(),
  38. *traits.target_color_space, traits.gpu_preferences,
  39. *traits.gpu_workarounds, traits.get_command_buffer_stub_cb);
  40. }
  41. // Report that HDR is enabled if any display has HDR enabled.
  42. bool hdr_enabled = false;
  43. auto dxgi_info = gl::GetDirectCompositionHDRMonitorDXGIInfo();
  44. for (const auto& output_desc : dxgi_info->output_descs)
  45. hdr_enabled |= output_desc->hdr_enabled;
  46. return D3D11VideoDecoder::Create(
  47. traits.gpu_task_runner, traits.media_log->Clone(), traits.gpu_preferences,
  48. *traits.gpu_workarounds, traits.get_command_buffer_stub_cb,
  49. GetD3D11DeviceCallback(), traits.get_cached_configs_cb.Run(),
  50. hdr_enabled);
  51. }
  52. std::unique_ptr<AudioEncoder> CreatePlatformAudioEncoder(
  53. scoped_refptr<base::SequencedTaskRunner> task_runner) {
  54. auto encoding_runner = base::ThreadPool::CreateCOMSTATaskRunner({});
  55. auto mf_encoder = std::make_unique<MFAudioEncoder>(encoding_runner);
  56. return std::make_unique<OffloadingAudioEncoder>(std::move(mf_encoder),
  57. std::move(encoding_runner),
  58. std::move(task_runner));
  59. }
  60. absl::optional<SupportedVideoDecoderConfigs>
  61. GetPlatformSupportedVideoDecoderConfigs(
  62. gpu::GpuDriverBugWorkarounds gpu_workarounds,
  63. gpu::GpuPreferences gpu_preferences,
  64. const gpu::GPUInfo& gpu_info,
  65. base::OnceCallback<SupportedVideoDecoderConfigs()> get_vda_configs) {
  66. SupportedVideoDecoderConfigs supported_configs;
  67. if (ShouldUseD3D11VideoDecoder(gpu_workarounds)) {
  68. supported_configs = D3D11VideoDecoder::GetSupportedVideoDecoderConfigs(
  69. gpu_preferences, gpu_workarounds, GetD3D11DeviceCallback());
  70. } else if (!gpu_workarounds.disable_dxva_video_decoder) {
  71. supported_configs = std::move(get_vda_configs).Run();
  72. }
  73. return supported_configs;
  74. }
  75. std::unique_ptr<AudioDecoder> CreatePlatformAudioDecoder(
  76. scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
  77. #if BUILDFLAG(USE_PROPRIETARY_CODECS) && BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
  78. return MediaFoundationAudioDecoder::Create(std::move(task_runner));
  79. #else
  80. return nullptr;
  81. #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) &&
  82. // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
  83. }
  84. VideoDecoderType GetPlatformDecoderImplementationType(
  85. gpu::GpuDriverBugWorkarounds gpu_workarounds,
  86. gpu::GpuPreferences gpu_preferences,
  87. const gpu::GPUInfo& gpu_info) {
  88. return ShouldUseD3D11VideoDecoder(gpu_workarounds) ? VideoDecoderType::kD3D11
  89. : VideoDecoderType::kVda;
  90. }
  91. // There is no CdmFactory on windows, so just stub it out.
  92. class CdmFactory {};
  93. std::unique_ptr<CdmFactory> CreatePlatformCdmFactory(
  94. mojom::FrameInterfaceFactory* frame_interfaces) {
  95. return nullptr;
  96. }
  97. } // namespace media