chromium/third_party/blink/renderer/platform/peerconnection/rtc_video_decoder_factory_test.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/peerconnection/rtc_video_decoder_factory.h"

#include <stdint.h>

#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "media/base/platform_features.h"
#include "media/base/video_codecs.h"
#include "media/video/mock_gpu_video_accelerator_factories.h"
#include "media/video/video_decode_accelerator.h"
#include "media/webrtc/webrtc_features.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/webrtc/api/video_codecs/sdp_video_format.h"
#include "third_party/webrtc/api/video_codecs/video_decoder_factory.h"

Return;
UnorderedElementsAre;

namespace blink {

namespace {

const webrtc::SdpVideoFormat kVp9Profile0Sdp("VP9", {});
const webrtc::SdpVideoFormat kVp9Profile1Sdp("VP9", {});
const webrtc::SdpVideoFormat kVp9Profile2Sdp("VP9", {});
const webrtc::SdpVideoFormat kAv1Sdp("AV1", {});
const webrtc::SdpVideoFormat kH264CbPacketizatonMode0Sdp(
    "H264",
    {});
const webrtc::SdpVideoFormat kH264CbPacketizatonMode1Sdp(
    "H264",
    {});
const webrtc::SdpVideoFormat kH264BaselinePacketizatonMode0Sdp(
    "H264",
    {});
const webrtc::SdpVideoFormat kH264BaselinePacketizatonMode1Sdp(
    "H264",
    {});
const webrtc::SdpVideoFormat kH264MainPacketizatonMode0Sdp(
    "H264",
    {});
const webrtc::SdpVideoFormat kH264MainPacketizatonMode1Sdp(
    "H264",
    {});
#if BUILDFLAG(RTC_USE_H265)
const webrtc::SdpVideoFormat kH265MainProfileSdp("H265",
                                                 {{"profile-id", "1"},
                                                  {"tier-flag", "0"},
                                                  {"level-id", "93"},
                                                  {"tx-mode", "SRST"}});
const webrtc::SdpVideoFormat kH265Main10ProfileSdp("H265",
                                                   {{"profile-id", "2"},
                                                    {"tier-flag", "0"},
                                                    {"level-id", "93"},
                                                    {"tx-mode", "SRST"}});
#endif  // BUILDFLAG(RTC_USE_H265)

bool Equals(webrtc::VideoDecoderFactory::CodecSupport a,
            webrtc::VideoDecoderFactory::CodecSupport b) {}

constexpr webrtc::VideoDecoderFactory::CodecSupport kSupportedPowerEfficient =;
constexpr webrtc::VideoDecoderFactory::CodecSupport kUnsupported =;
class MockGpuVideoDecodeAcceleratorFactories
    : public media::MockGpuVideoAcceleratorFactories {};

}  // anonymous namespace

class RTCVideoDecoderFactoryTest : public ::testing::Test {};

TEST_F(RTCVideoDecoderFactoryTest, QueryCodecSupportReturnsExpectedResults) {}

TEST_F(RTCVideoDecoderFactoryTest, GetSupportedFormatsReturnsAllExpectedModes) {}

#if BUILDFLAG(RTC_USE_H265)
TEST_F(RTCVideoDecoderFactoryTest,
       QueryCodecSupportH265WithWebRtcAllowH265ReceiveEnabled) {
  base::test::ScopedFeatureList scoped_feature_list;
  scoped_feature_list.InitWithFeatures({::features::kWebRtcAllowH265Receive},
                                       {});
  EXPECT_CALL(mock_gpu_factories_, IsDecoderSupportKnown())
      .WillRepeatedly(Return(true));

  // H265 decode should be supported without reference scaling.
  EXPECT_TRUE(
      Equals(decoder_factory_.QueryCodecSupport(webrtc::SdpVideoFormat("H265"),
                                                false /*reference_scaling*/),
             kSupportedPowerEfficient));

  // H265 decode should not be supported with reference scaling.
  EXPECT_TRUE(
      Equals(decoder_factory_.QueryCodecSupport(webrtc::SdpVideoFormat("H265"),
                                                true /*reference_scaling*/),
             kUnsupported));

  // H265 decode should be supported with main profile explicitly configured.
  EXPECT_TRUE(Equals(decoder_factory_.QueryCodecSupport(
                         webrtc::SdpVideoFormat("H265", {{"profile-id", "1"}}),
                         false /*reference_scaling*/),
                     kSupportedPowerEfficient));

  // H265 main10 profile is not supported.
  EXPECT_TRUE(Equals(decoder_factory_.QueryCodecSupport(
                         webrtc::SdpVideoFormat("H265", {{"profile-id", "2"}}),
                         false /*reference_scaling*/),
                     kUnsupported));

  EXPECT_THAT(
      decoder_factory_.GetSupportedFormats(),
      UnorderedElementsAre(
          kH264CbPacketizatonMode0Sdp, kH264CbPacketizatonMode1Sdp,
          kH264BaselinePacketizatonMode0Sdp, kH264BaselinePacketizatonMode1Sdp,
          kH264MainPacketizatonMode0Sdp, kH264MainPacketizatonMode1Sdp,
          kVp9Profile0Sdp, kVp9Profile1Sdp, kVp9Profile2Sdp, kAv1Sdp,
          kH265MainProfileSdp));
}
#endif  // BUILDFLAG(RTC_USE_H265)
}  // namespace blink