#include "third_party/blink/renderer/platform/peerconnection/rtc_video_encoder_factory.h"
#include <stdint.h>
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "media/base/media_switches.h"
#include "media/base/svc_scalability_mode.h"
#include "media/base/video_codecs.h"
#include "media/mojo/clients/mojo_video_encoder_metrics_provider.h"
#include "media/video/mock_gpu_video_accelerator_factories.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/blink/renderer/platform/peerconnection/rtc_video_encoder.h"
#include "third_party/webrtc/api/video_codecs/sdp_video_format.h"
#include "third_party/webrtc/api/video_codecs/video_encoder_factory.h"
Return;
namespace blink {
namespace {
constexpr webrtc::VideoEncoderFactory::CodecSupport kSupportedPowerEfficient = …;
constexpr webrtc::VideoEncoderFactory::CodecSupport kUnsupported = …;
constexpr gfx::Size kMaxResolution = …;
constexpr uint32_t kMaxFramerateNumerator = …;
#if BUILDFLAG(RTC_USE_H265)
constexpr gfx::Size kHEVCMaxResolution = {4096, 2304};
constexpr uint32_t kHEVCMaxFramerateNumerator = 120;
#endif
constexpr uint32_t kMaxFramerateDenominator = …;
const std::vector<media::SVCScalabilityMode> kScalabilityModes = …;
bool Equals(webrtc::VideoEncoderFactory::CodecSupport a,
webrtc::VideoEncoderFactory::CodecSupport b) { … }
class MockGpuVideoEncodeAcceleratorFactories
: public media::MockGpuVideoAcceleratorFactories { … };
}
class RTCVideoEncoderFactoryTest : public ::testing::Test { … };
TEST_F(RTCVideoEncoderFactoryTest, QueryCodecSupportNoSvc) { … }
TEST_F(RTCVideoEncoderFactoryTest, QueryCodecSupportSvc) { … }
#if BUILDFLAG(RTC_USE_H265)
TEST_F(RTCVideoEncoderFactoryTest,
QueryCodecSupportForH265WithoutNeccessaryFeatures) {
base::test::ScopedFeatureList scoped_feature_list;
EXPECT_CALL(mock_gpu_factories_, IsEncoderSupportKnown())
.WillRepeatedly(Return(true));
EXPECT_TRUE(Equals(encoder_factory_.QueryCodecSupport(
webrtc::SdpVideoFormat("H265", {{"profile-id", "1"}}),
std::nullopt),
kUnsupported));
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_ANDROID)
scoped_feature_list.InitWithFeatures({::features::kWebRtcAllowH265Send},
{media::kPlatformHEVCEncoderSupport});
EXPECT_TRUE(Equals(encoder_factory_.QueryCodecSupport(
webrtc::SdpVideoFormat("H265", {{"profile-id", "1"}}),
std::nullopt),
kUnsupported));
#endif
}
TEST_F(RTCVideoEncoderFactoryTest,
QueryCodecSupportForH265WithNeccessaryFeatures) {
ClearDisabledProfilesForTesting();
base::test::ScopedFeatureList scoped_feature_list;
std::vector<base::test::FeatureRef> enabled_features;
enabled_features.emplace_back(::features::kWebRtcAllowH265Send);
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_ANDROID)
enabled_features.emplace_back(media::kPlatformHEVCEncoderSupport);
#endif
scoped_feature_list.InitWithFeatures(enabled_features, {});
EXPECT_CALL(mock_gpu_factories_, IsEncoderSupportKnown())
.WillRepeatedly(Return(true));
EXPECT_TRUE(Equals(encoder_factory_.QueryCodecSupport(
webrtc::SdpVideoFormat("H265", {{"profile-id", "1"}}),
std::nullopt),
kSupportedPowerEfficient));
EXPECT_TRUE(Equals(encoder_factory_.QueryCodecSupport(
webrtc::SdpVideoFormat(
"H265", {{"profile-id", "1"}, {"level-id", "93"}}),
std::nullopt),
kSupportedPowerEfficient));
EXPECT_TRUE(Equals(encoder_factory_.QueryCodecSupport(
webrtc::SdpVideoFormat("H265", {{"profile-id", "1"},
{"level-id", "156"}}),
std::nullopt),
kSupportedPowerEfficient));
EXPECT_TRUE(Equals(encoder_factory_.QueryCodecSupport(
webrtc::SdpVideoFormat("H265", {{"profile-id", "2"}}),
std::nullopt),
kUnsupported));
}
#endif
}