media_foundation_renderer_integration_test.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "media/renderers/win/media_foundation_renderer.h"
  5. #include <memory>
  6. #include <mfapi.h>
  7. #include "base/win/windows_version.h"
  8. #include "media/base/media_util.h"
  9. #include "media/test/pipeline_integration_test_base.h"
  10. #include "media/test/test_media_source.h"
  11. namespace media {
  12. namespace {
  13. // TODO(xhwang): Generalize this to support more codecs, or use CanPlay() or
  14. // IsTypeSupported() which can take mime types directly.
  15. bool CanDecodeVp9() {
  16. if (!MediaFoundationRenderer::IsSupported()) {
  17. LOG(WARNING) << "MediaFoundationRenderer not supported";
  18. return false;
  19. }
  20. MFT_REGISTER_TYPE_INFO input_type = {MFMediaType_Video, MFVideoFormat_VP90};
  21. IMFActivate** activates = nullptr;
  22. UINT32 count = 0;
  23. if (FAILED(MFTEnumEx(MFT_CATEGORY_VIDEO_DECODER,
  24. MFT_ENUM_FLAG_SYNCMFT | MFT_ENUM_FLAG_ASYNCMFT |
  25. MFT_ENUM_FLAG_HARDWARE,
  26. &input_type, /*output_type=*/nullptr, &activates,
  27. &count))) {
  28. return false;
  29. }
  30. for (UINT32 i = 0; i < count; ++i)
  31. activates[i]->Release();
  32. CoTaskMemFree(activates);
  33. if (count == 0) {
  34. LOG(WARNING) << "No decoder for VP9";
  35. return false;
  36. }
  37. return true;
  38. }
  39. } // namespace
  40. class MediaFoundationRendererIntegrationTest
  41. : public testing::Test,
  42. public PipelineIntegrationTestBase {
  43. public:
  44. MediaFoundationRendererIntegrationTest() {
  45. SetCreateRendererCB(base::BindRepeating(
  46. &MediaFoundationRendererIntegrationTest::CreateMediaFoundationRenderer,
  47. base::Unretained(this)));
  48. }
  49. MediaFoundationRendererIntegrationTest(
  50. const MediaFoundationRendererIntegrationTest&) = delete;
  51. MediaFoundationRendererIntegrationTest& operator=(
  52. const MediaFoundationRendererIntegrationTest&) = delete;
  53. private:
  54. std::unique_ptr<Renderer> CreateMediaFoundationRenderer(
  55. absl::optional<RendererType> /*renderer_type*/) {
  56. LUID empty_luid{0, 0};
  57. auto renderer = std::make_unique<MediaFoundationRenderer>(
  58. task_environment_.GetMainThreadTaskRunner(),
  59. std::make_unique<NullMediaLog>(), empty_luid,
  60. /*force_dcomp_mode_for_testing=*/true);
  61. return renderer;
  62. }
  63. };
  64. TEST_F(MediaFoundationRendererIntegrationTest, BasicPlayback) {
  65. // TODO(crbug.com/1240681): This test is very flaky on win10-20h2.
  66. if (base::win::OSInfo::GetInstance()->version() >=
  67. base::win::Version::WIN10_20H2) {
  68. GTEST_SKIP() << "Skipping test for WIN10_20H2 and greater";
  69. }
  70. if (!CanDecodeVp9())
  71. return;
  72. ASSERT_EQ(PIPELINE_OK, Start("bear-vp9.webm"));
  73. Play();
  74. ASSERT_TRUE(WaitUntilOnEnded());
  75. }
  76. TEST_F(MediaFoundationRendererIntegrationTest, BasicPlayback_MediaSource) {
  77. // TODO(crbug.com/1240681): This test is very flaky on win10-20h2.
  78. if (base::win::OSInfo::GetInstance()->version() >=
  79. base::win::Version::WIN10_20H2) {
  80. GTEST_SKIP() << "Skipping test for WIN10_20H2 and greater";
  81. }
  82. if (!CanDecodeVp9())
  83. return;
  84. TestMediaSource source("bear-vp9.webm", 67504);
  85. EXPECT_EQ(PIPELINE_OK, StartPipelineWithMediaSource(&source));
  86. source.EndOfStream();
  87. Play();
  88. ASSERT_TRUE(WaitUntilOnEnded());
  89. source.Shutdown();
  90. Stop();
  91. }
  92. } // namespace media