diff --git a/test/encoder_settings.cc b/test/encoder_settings.cc index acad68706d..ff3b096ef6 100644 --- a/test/encoder_settings.cc +++ b/test/encoder_settings.cc @@ -87,6 +87,10 @@ std::vector CreateVideoStreams( RTC_DCHECK_GE(*stream.num_temporal_layers, 1); stream_settings[i].num_temporal_layers = stream.num_temporal_layers; } + if (stream.scale_resolution_down_by >= 1.0) { + stream_settings[i].width = width / stream.scale_resolution_down_by; + stream_settings[i].height = height / stream.scale_resolution_down_by; + } } else { max_bitrate_bps = std::min( bitrate_left_bps, DefaultVideoStreamFactory::kMaxBitratePerStream[i]); diff --git a/video/picture_id_tests.cc b/video/picture_id_tests.cc index ef1da0c042..c007877627 100644 --- a/video/picture_id_tests.cc +++ b/video/picture_id_tests.cc @@ -230,6 +230,7 @@ class PictureIdTest : public test::CallTest, void SetupEncoder(VideoEncoderFactory* encoder_factory, const std::string& payload_name); + void SetVideoEncoderConfig(int num_streams); void TestPictureIdContinuousAfterReconfigure( const std::vector& ssrc_counts); void TestPictureIdIncreaseAfterRecreateStreams( @@ -244,52 +245,6 @@ INSTANTIATE_TEST_SUITE_P(TemporalLayers, PictureIdTest, ::testing::ValuesIn(kNumTemporalLayers)); -// Use a special stream factory to ensure that all simulcast streams are being -// sent. -class VideoStreamFactory - : public VideoEncoderConfig::VideoStreamFactoryInterface { - public: - explicit VideoStreamFactory(size_t num_temporal_layers) - : num_of_temporal_layers_(num_temporal_layers) {} - - private: - std::vector CreateEncoderStreams( - int width, - int height, - const VideoEncoderConfig& encoder_config) override { - std::vector streams = - test::CreateVideoStreams(width, height, encoder_config); - - // Always divide the same total bitrate across all streams so that sending a - // single stream avoids lowering the bitrate estimate and requiring a - // subsequent rampup. - const int encoder_stream_bps = - kEncoderBitrateBps / - rtc::checked_cast(encoder_config.number_of_streams); - - for (size_t i = 0; i < encoder_config.number_of_streams; ++i) { - // Reduce the min bitrate by 10% to account for overhead that might - // otherwise cause streams to not be enabled. - streams[i].min_bitrate_bps = static_cast(encoder_stream_bps * 0.9); - streams[i].target_bitrate_bps = encoder_stream_bps; - streams[i].max_bitrate_bps = encoder_stream_bps; - streams[i].num_temporal_layers = num_of_temporal_layers_; - // test::CreateVideoStreams does not return frame sizes for the lower - // streams that are accepted by VP8Impl::InitEncode. - // TODO(brandtr): Fix the problem in test::CreateVideoStreams, rather - // than overriding the values here. - streams[i].width = - width / (1 << (encoder_config.number_of_streams - 1 - i)); - streams[i].height = - height / (1 << (encoder_config.number_of_streams - 1 - i)); - } - - return streams; - } - - const size_t num_of_temporal_layers_; -}; - void PictureIdTest::SetupEncoder(VideoEncoderFactory* encoder_factory, const std::string& payload_name) { observer_.reset( @@ -310,12 +265,32 @@ void PictureIdTest::SetupEncoder(VideoEncoderFactory* encoder_factory, GetVideoSendConfig()->rtp.payload_name = payload_name; GetVideoEncoderConfig()->codec_type = PayloadStringToCodecType(payload_name); - GetVideoEncoderConfig()->video_stream_factory = - new rtc::RefCountedObject(num_temporal_layers_); - GetVideoEncoderConfig()->number_of_streams = 1; + SetVideoEncoderConfig(/* number_of_streams */ 1); }); } +void PictureIdTest::SetVideoEncoderConfig(int num_streams) { + GetVideoEncoderConfig()->number_of_streams = num_streams; + GetVideoEncoderConfig()->max_bitrate_bps = kEncoderBitrateBps; + + // Always divide the same total bitrate across all streams so that sending a + // single stream avoids lowering the bitrate estimate and requiring a + // subsequent rampup. + const int encoder_stream_bps = kEncoderBitrateBps / num_streams; + double scale_factor = 1.0; + for (int i = num_streams - 1; i >= 0; --i) { + VideoStream& stream = GetVideoEncoderConfig()->simulcast_layers[i]; + // Reduce the min bitrate by 10% to account for overhead that might + // otherwise cause streams to not be enabled. + stream.min_bitrate_bps = static_cast(encoder_stream_bps * 0.9); + stream.target_bitrate_bps = encoder_stream_bps; + stream.max_bitrate_bps = encoder_stream_bps; + stream.num_temporal_layers = num_temporal_layers_; + stream.scale_resolution_down_by = scale_factor; + scale_factor *= 2.0; + } +} + void PictureIdTest::TestPictureIdContinuousAfterReconfigure( const std::vector& ssrc_counts) { task_queue_.SendTask([this]() { @@ -332,7 +307,7 @@ void PictureIdTest::TestPictureIdContinuousAfterReconfigure( // Expect continuously increasing picture id, equivalent to no gaps. observer_->SetMaxExpectedPictureIdGap(0); for (int ssrc_count : ssrc_counts) { - GetVideoEncoderConfig()->number_of_streams = ssrc_count; + SetVideoEncoderConfig(ssrc_count); observer_->SetExpectedSsrcs(ssrc_count); observer_->ResetObservedSsrcs(); // Make sure the picture_id sequence is continuous on reinit and recreate. @@ -369,7 +344,7 @@ void PictureIdTest::TestPictureIdIncreaseAfterRecreateStreams( task_queue_.SendTask([this, &ssrc_count]() { DestroyVideoSendStreams(); - GetVideoEncoderConfig()->number_of_streams = ssrc_count; + SetVideoEncoderConfig(ssrc_count); observer_->SetExpectedSsrcs(ssrc_count); observer_->ResetObservedSsrcs();