From f33fc35277ab95e35c56dca3f0a9bf1b555f4a48 Mon Sep 17 00:00:00 2001 From: Jerome Jiang Date: Tue, 19 Oct 2021 11:03:19 -0700 Subject: [PATCH] Set rates for av1 svc tests Bug: webrtc:11404 Change-Id: I79c4cee99d1bee1cdd3a8e0f901fadc6178a07a6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235602 Reviewed-by: Philip Eliasson Reviewed-by: Danil Chapovalov Commit-Queue: Jerome Jiang Cr-Commit-Position: refs/heads/main@{#35250} --- .../codecs/av1/libaom_av1_encoder_unittest.cc | 24 ++++++++++++++++- .../codecs/av1/libaom_av1_unittest.cc | 27 ++++++++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder_unittest.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder_unittest.cc index 96057a0ce2..6e92e50821 100644 --- a/modules/video_coding/codecs/av1/libaom_av1_encoder_unittest.cc +++ b/modules/video_coding/codecs/av1/libaom_av1_encoder_unittest.cc @@ -86,13 +86,22 @@ TEST(LibaomAv1EncoderTest, NoBitrateOnTopLayerRefecltedInActiveDecodeTargets) { } TEST(LibaomAv1EncoderTest, SetsEndOfPictureForLastFrameInTemporalUnit) { + VideoBitrateAllocation allocation; + allocation.SetBitrate(0, 0, 30000); + allocation.SetBitrate(1, 0, 40000); + allocation.SetBitrate(2, 0, 30000); + std::unique_ptr encoder = CreateLibaomAv1Encoder(); VideoCodec codec_settings = DefaultCodecSettings(); // Configure encoder with 3 spatial layers. codec_settings.SetScalabilityMode("L3T1"); + codec_settings.maxBitrate = allocation.get_sum_kbps(); ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()), WEBRTC_VIDEO_CODEC_OK); + encoder->SetRates(VideoEncoder::RateControlParameters( + allocation, codec_settings.maxFramerate)); + std::vector encoded_frames = EncodedVideoFrameProducer(*encoder).SetNumInputFrames(2).Encode(); ASSERT_THAT(encoded_frames, SizeIs(6)); @@ -105,6 +114,10 @@ TEST(LibaomAv1EncoderTest, SetsEndOfPictureForLastFrameInTemporalUnit) { } TEST(LibaomAv1EncoderTest, CheckOddDimensionsWithSpatialLayers) { + VideoBitrateAllocation allocation; + allocation.SetBitrate(0, 0, 30000); + allocation.SetBitrate(1, 0, 40000); + allocation.SetBitrate(2, 0, 30000); std::unique_ptr encoder = CreateLibaomAv1Encoder(); VideoCodec codec_settings = DefaultCodecSettings(); // Configure encoder with 3 spatial layers. @@ -112,8 +125,11 @@ TEST(LibaomAv1EncoderTest, CheckOddDimensionsWithSpatialLayers) { // Odd width and height values should not make encoder crash. codec_settings.width = 623; codec_settings.height = 405; + codec_settings.maxBitrate = allocation.get_sum_kbps(); ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()), WEBRTC_VIDEO_CODEC_OK); + encoder->SetRates(VideoEncoder::RateControlParameters( + allocation, codec_settings.maxFramerate)); EncodedVideoFrameProducer evfp(*encoder); evfp.SetResolution(RenderResolution{623, 405}); std::vector encoded_frames = @@ -137,14 +153,20 @@ TEST(LibaomAv1EncoderTest, EncoderInfoProvidesFpsAllocation) { } TEST(LibaomAv1EncoderTest, PopulatesEncodedFrameSize) { + VideoBitrateAllocation allocation; + allocation.SetBitrate(0, 0, 30000); + allocation.SetBitrate(1, 0, 40000); + allocation.SetBitrate(2, 0, 30000); std::unique_ptr encoder = CreateLibaomAv1Encoder(); VideoCodec codec_settings = DefaultCodecSettings(); + codec_settings.maxBitrate = allocation.get_sum_kbps(); ASSERT_GT(codec_settings.width, 4); // Configure encoder with 3 spatial layers. codec_settings.SetScalabilityMode("L3T1"); ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()), WEBRTC_VIDEO_CODEC_OK); - + encoder->SetRates(VideoEncoder::RateControlParameters( + allocation, codec_settings.maxFramerate)); using Frame = EncodedVideoFrameProducer::EncodedFrame; std::vector encoded_frames = EncodedVideoFrameProducer(*encoder).SetNumInputFrames(1).Encode(); diff --git a/modules/video_coding/codecs/av1/libaom_av1_unittest.cc b/modules/video_coding/codecs/av1/libaom_av1_unittest.cc index 5823266952..e893bfd74d 100644 --- a/modules/video_coding/codecs/av1/libaom_av1_unittest.cc +++ b/modules/video_coding/codecs/av1/libaom_av1_unittest.cc @@ -178,15 +178,36 @@ struct SvcTestParam { class LibaomAv1SvcTest : public ::testing::TestWithParam {}; TEST_P(LibaomAv1SvcTest, EncodeAndDecodeAllDecodeTargets) { - size_t num_decode_targets = CreateScalabilityStructure(GetParam().name) - ->DependencyStructure() - .num_decode_targets; + const SvcTestParam param = GetParam(); + std::unique_ptr svc_controller = + CreateScalabilityStructure(param.name); + ASSERT_TRUE(svc_controller); + VideoBitrateAllocation allocation; + if (param.configured_bitrates.empty()) { + ScalableVideoController::StreamLayersConfig config = + svc_controller->StreamConfig(); + for (int sid = 0; sid < config.num_spatial_layers; ++sid) { + for (int tid = 0; tid < config.num_temporal_layers; ++tid) { + allocation.SetBitrate(sid, tid, 100'000); + } + } + } else { + for (const auto& kv : param.configured_bitrates) { + allocation.SetBitrate(kv.first.spatial_id, kv.first.temporal_id, + kv.second.bps()); + } + } + + size_t num_decode_targets = + svc_controller->DependencyStructure().num_decode_targets; std::unique_ptr encoder = CreateLibaomAv1Encoder(); VideoCodec codec_settings = DefaultCodecSettings(); codec_settings.SetScalabilityMode(GetParam().name); ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()), WEBRTC_VIDEO_CODEC_OK); + encoder->SetRates(VideoEncoder::RateControlParameters( + allocation, codec_settings.maxFramerate)); std::vector encoded_frames = EncodedVideoFrameProducer(*encoder) .SetNumInputFrames(GetParam().num_frames_to_generate)