d3d11_decoder_configurator_unittest.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2020 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 <utility>
  5. #include "media/base/media_util.h"
  6. #include "media/base/win/d3d11_mocks.h"
  7. #include "media/gpu/windows/av1_guids.h"
  8. #include "media/gpu/windows/d3d11_decoder_configurator.h"
  9. #include "testing/gmock/include/gmock/gmock.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. using ::testing::_;
  12. using ::testing::Combine;
  13. using ::testing::DoAll;
  14. using ::testing::Return;
  15. using ::testing::SetArgPointee;
  16. using ::testing::Values;
  17. namespace media {
  18. class D3D11DecoderConfiguratorUnittest : public ::testing::Test {
  19. public:
  20. VideoDecoderConfig CreateDecoderConfig(VideoCodecProfile profile,
  21. gfx::Size size,
  22. bool encrypted) {
  23. VideoDecoderConfig result;
  24. result.Initialize(
  25. VideoCodec::kUnknown, // It doesn't matter because it won't
  26. // be used.
  27. profile, VideoDecoderConfig::AlphaMode::kIsOpaque, VideoColorSpace(),
  28. kNoTransformation, size, {}, {}, {},
  29. encrypted ? EncryptionScheme::kCenc : EncryptionScheme::kUnencrypted);
  30. return result;
  31. }
  32. std::unique_ptr<D3D11DecoderConfigurator> CreateWithDefaultGPUInfo(
  33. const VideoDecoderConfig& config,
  34. bool zero_copy_enabled = true,
  35. uint8_t bit_depth = 8) {
  36. gpu::GpuPreferences prefs;
  37. prefs.enable_zero_copy_dxgi_video = zero_copy_enabled;
  38. gpu::GpuDriverBugWorkarounds workarounds;
  39. workarounds.disable_dxgi_zero_copy_video = false;
  40. VideoChromaSampling chroma_sampling = VideoChromaSampling::k420;
  41. auto media_log = std::make_unique<NullMediaLog>();
  42. return D3D11DecoderConfigurator::Create(
  43. prefs, workarounds, config, bit_depth, chroma_sampling, media_log.get(),
  44. false /*use_shared_handle*/);
  45. }
  46. };
  47. TEST_F(D3D11DecoderConfiguratorUnittest, VP9Profile0RightFormats) {
  48. auto configurator = CreateWithDefaultGPUInfo(
  49. CreateDecoderConfig(VP9PROFILE_PROFILE0, {0, 0}, false));
  50. EXPECT_EQ(configurator->DecoderGuid(),
  51. D3D11_DECODER_PROFILE_VP9_VLD_PROFILE0);
  52. EXPECT_EQ(configurator->DecoderDescriptor()->OutputFormat, DXGI_FORMAT_NV12);
  53. }
  54. TEST_F(D3D11DecoderConfiguratorUnittest, VP9Profile2RightFormats) {
  55. auto configurator = CreateWithDefaultGPUInfo(
  56. CreateDecoderConfig(VP9PROFILE_PROFILE2, {0, 0}, false), false, 10);
  57. EXPECT_EQ(configurator->DecoderGuid(),
  58. D3D11_DECODER_PROFILE_VP9_VLD_10BIT_PROFILE2);
  59. EXPECT_EQ(configurator->DecoderDescriptor()->OutputFormat, DXGI_FORMAT_P010);
  60. }
  61. TEST_F(D3D11DecoderConfiguratorUnittest, AV1ProfileRightFormats) {
  62. auto configurator = CreateWithDefaultGPUInfo(
  63. CreateDecoderConfig(AV1PROFILE_PROFILE_MAIN, {0, 0}, false), false, 8);
  64. EXPECT_EQ(configurator->DecoderGuid(), DXVA_ModeAV1_VLD_Profile0);
  65. EXPECT_EQ(configurator->DecoderDescriptor()->OutputFormat, DXGI_FORMAT_NV12);
  66. configurator = CreateWithDefaultGPUInfo(
  67. CreateDecoderConfig(AV1PROFILE_PROFILE_MAIN, {0, 0}, false), false, 10);
  68. EXPECT_EQ(configurator->DecoderGuid(), DXVA_ModeAV1_VLD_Profile0);
  69. EXPECT_EQ(configurator->DecoderDescriptor()->OutputFormat, DXGI_FORMAT_P010);
  70. }
  71. TEST_F(D3D11DecoderConfiguratorUnittest, SupportsDeviceNoProfiles) {
  72. auto configurator = CreateWithDefaultGPUInfo(
  73. CreateDecoderConfig(VP9PROFILE_PROFILE0, {0, 0}, false));
  74. auto vd_mock = MakeComPtr<D3D11VideoDeviceMock>();
  75. EXPECT_CALL(*vd_mock.Get(), GetVideoDecoderProfileCount())
  76. .Times(1)
  77. .WillOnce(Return(0));
  78. EXPECT_FALSE(configurator->SupportsDevice(vd_mock));
  79. }
  80. TEST_F(D3D11DecoderConfiguratorUnittest, SupportsDeviceWrongProfiles) {
  81. auto configurator = CreateWithDefaultGPUInfo(
  82. CreateDecoderConfig(VP9PROFILE_PROFILE0, {0, 0}, false));
  83. auto vd_mock = MakeComPtr<D3D11VideoDeviceMock>();
  84. EXPECT_CALL(*vd_mock.Get(), GetVideoDecoderProfileCount())
  85. .Times(1)
  86. .WillOnce(Return(2));
  87. EXPECT_CALL(*vd_mock.Get(), GetVideoDecoderProfile(0, _))
  88. .Times(1)
  89. .WillOnce(DoAll(SetArgPointee<1>(D3D11_DECODER_PROFILE_HEVC_VLD_MAIN),
  90. Return(S_OK)));
  91. EXPECT_CALL(*vd_mock.Get(), GetVideoDecoderProfile(1, _))
  92. .Times(1)
  93. .WillOnce(
  94. DoAll(SetArgPointee<1>(D3D11_DECODER_PROFILE_VC1_VLD), Return(S_OK)));
  95. EXPECT_FALSE(configurator->SupportsDevice(vd_mock));
  96. }
  97. TEST_F(D3D11DecoderConfiguratorUnittest, SupportsDeviceCorrectProfile) {
  98. auto configurator = CreateWithDefaultGPUInfo(
  99. CreateDecoderConfig(VP9PROFILE_PROFILE0, {0, 0}, false));
  100. auto vd_mock = MakeComPtr<D3D11VideoDeviceMock>();
  101. EXPECT_CALL(*vd_mock.Get(), GetVideoDecoderProfileCount())
  102. .Times(1)
  103. .WillOnce(Return(5));
  104. EXPECT_CALL(*vd_mock.Get(), GetVideoDecoderProfile(4, _))
  105. .Times(1)
  106. .WillOnce(DoAll(SetArgPointee<1>(D3D11_DECODER_PROFILE_VP9_VLD_PROFILE0),
  107. Return(S_OK)));
  108. EXPECT_TRUE(configurator->SupportsDevice(vd_mock));
  109. }
  110. } // namespace media