#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
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 { … };
}
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));
EXPECT_TRUE(
Equals(decoder_factory_.QueryCodecSupport(webrtc::SdpVideoFormat("H265"),
false ),
kSupportedPowerEfficient));
EXPECT_TRUE(
Equals(decoder_factory_.QueryCodecSupport(webrtc::SdpVideoFormat("H265"),
true ),
kUnsupported));
EXPECT_TRUE(Equals(decoder_factory_.QueryCodecSupport(
webrtc::SdpVideoFormat("H265", {{"profile-id", "1"}}),
false ),
kSupportedPowerEfficient));
EXPECT_TRUE(Equals(decoder_factory_.QueryCodecSupport(
webrtc::SdpVideoFormat("H265", {{"profile-id", "2"}}),
false ),
kUnsupported));
EXPECT_THAT(
decoder_factory_.GetSupportedFormats(),
UnorderedElementsAre(
kH264CbPacketizatonMode0Sdp, kH264CbPacketizatonMode1Sdp,
kH264BaselinePacketizatonMode0Sdp, kH264BaselinePacketizatonMode1Sdp,
kH264MainPacketizatonMode0Sdp, kH264MainPacketizatonMode1Sdp,
kVp9Profile0Sdp, kVp9Profile1Sdp, kVp9Profile2Sdp, kAv1Sdp,
kH265MainProfileSdp));
}
#endif
}