Replace usage of old SetRates/SetRateAllocation methods
This rather large CL replaces all relevant usage of the old VideoEncoder::SetRates()/SetRateAllocation() methods in WebRTC. API is unchanged to allow downstream projects to update without breakage. Bug: webrtc:10481 Change-Id: Iab8f292ce6be6c3f5056a239d26361962b14bb38 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131949 Commit-Queue: Erik Språng <sprang@webrtc.org> Reviewed-by: Per Kjellander <perkj@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27554}
This commit is contained in:
@ -207,10 +207,8 @@ class MockVideoEncoder : public VideoEncoder {
|
||||
|
||||
MOCK_METHOD0(Release, int32_t());
|
||||
|
||||
int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation,
|
||||
uint32_t framerate) {
|
||||
last_set_bitrate_ = bitrate_allocation;
|
||||
return 0;
|
||||
void SetRates(const RateControlParameters& parameters) {
|
||||
last_set_rates_ = parameters;
|
||||
}
|
||||
|
||||
EncoderInfo GetEncoderInfo() const override {
|
||||
@ -271,7 +269,7 @@ class MockVideoEncoder : public VideoEncoder {
|
||||
fps_allocation_ = fps_allocation;
|
||||
}
|
||||
|
||||
VideoBitrateAllocation last_set_bitrate() const { return last_set_bitrate_; }
|
||||
RateControlParameters last_set_rates() const { return last_set_rates_; }
|
||||
|
||||
private:
|
||||
MockVideoEncoderFactory* const factory_;
|
||||
@ -282,7 +280,7 @@ class MockVideoEncoder : public VideoEncoder {
|
||||
bool is_hardware_accelerated_ = false;
|
||||
bool has_internal_source_ = false;
|
||||
int32_t init_encode_return_value_ = 0;
|
||||
VideoBitrateAllocation last_set_bitrate_;
|
||||
VideoEncoder::RateControlParameters last_set_rates_;
|
||||
FramerateFractions fps_allocation_;
|
||||
|
||||
VideoCodec codec_;
|
||||
@ -500,7 +498,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) {
|
||||
SetupCodec();
|
||||
|
||||
// Set bitrates so that we send all layers.
|
||||
adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30);
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(1200, 30), 30.0));
|
||||
|
||||
// At this point, the simulcast encoder adapter should have 3 streams: HD,
|
||||
// quarter HD, and quarter quarter HD. We're going to mostly ignore the exact
|
||||
@ -560,8 +559,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
|
||||
// Encode with three streams.
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
|
||||
VerifyCodecSettings();
|
||||
adapter_->SetRateAllocation(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30);
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
|
||||
|
||||
std::vector<MockVideoEncoder*> original_encoders =
|
||||
helper_->factory()->encoders();
|
||||
@ -587,8 +586,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
|
||||
codec_.height /= 2;
|
||||
codec_.numberOfSimulcastStreams = 2;
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
|
||||
adapter_->SetRateAllocation(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30);
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
|
||||
std::vector<MockVideoEncoder*> new_encoders = helper_->factory()->encoders();
|
||||
ASSERT_EQ(2u, new_encoders.size());
|
||||
ASSERT_EQ(original_encoders[0], new_encoders[0]);
|
||||
@ -610,8 +609,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
|
||||
codec_.height /= 2;
|
||||
codec_.numberOfSimulcastStreams = 1;
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
|
||||
adapter_->SetRateAllocation(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30);
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
|
||||
new_encoders = helper_->factory()->encoders();
|
||||
ASSERT_EQ(1u, new_encoders.size());
|
||||
ASSERT_EQ(original_encoders[0], new_encoders[0]);
|
||||
@ -628,8 +627,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
|
||||
codec_.height *= 4;
|
||||
codec_.numberOfSimulcastStreams = 3;
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
|
||||
adapter_->SetRateAllocation(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30);
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
|
||||
new_encoders = helper_->factory()->encoders();
|
||||
ASSERT_EQ(3u, new_encoders.size());
|
||||
// The first encoder is reused.
|
||||
@ -712,7 +711,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderEncoderSettings) {
|
||||
// discontinuities.
|
||||
TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderFrameSimulcastIdx) {
|
||||
SetupCodec();
|
||||
adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30);
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(1200, 30), 30.0));
|
||||
VerifyCodecSettings();
|
||||
|
||||
// Send frames on all streams.
|
||||
@ -736,7 +736,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderFrameSimulcastIdx) {
|
||||
// Reinitialize.
|
||||
EXPECT_EQ(0, adapter_->Release());
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
|
||||
adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30);
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(1200, 30), 30.0));
|
||||
|
||||
// Verify that the same encoder sends out frames on the same simulcast index.
|
||||
encoders[0]->SendEncodedImage(1152, 704);
|
||||
@ -780,21 +781,23 @@ TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) {
|
||||
// Above min should be respected.
|
||||
VideoBitrateAllocation target_bitrate =
|
||||
rate_allocator_->GetAllocation(codec_.minBitrate * 1000, 30);
|
||||
adapter_->SetRateAllocation(target_bitrate, 30);
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(target_bitrate, 30.0));
|
||||
EXPECT_EQ(target_bitrate,
|
||||
helper_->factory()->encoders()[0]->last_set_bitrate());
|
||||
helper_->factory()->encoders()[0]->last_set_rates().bitrate);
|
||||
|
||||
// Below min but non-zero should be replaced with the min bitrate.
|
||||
VideoBitrateAllocation too_low_bitrate =
|
||||
rate_allocator_->GetAllocation((codec_.minBitrate - 1) * 1000, 30);
|
||||
adapter_->SetRateAllocation(too_low_bitrate, 30);
|
||||
adapter_->SetRates(
|
||||
VideoEncoder::RateControlParameters(too_low_bitrate, 30.0));
|
||||
EXPECT_EQ(target_bitrate,
|
||||
helper_->factory()->encoders()[0]->last_set_bitrate());
|
||||
helper_->factory()->encoders()[0]->last_set_rates().bitrate);
|
||||
|
||||
// Zero should be passed on as is, since it means "pause".
|
||||
adapter_->SetRateAllocation(VideoBitrateAllocation(), 30);
|
||||
adapter_->SetRates(
|
||||
VideoEncoder::RateControlParameters(VideoBitrateAllocation(), 30.0));
|
||||
EXPECT_EQ(VideoBitrateAllocation(),
|
||||
helper_->factory()->encoders()[0]->last_set_bitrate());
|
||||
helper_->factory()->encoders()[0]->last_set_rates().bitrate);
|
||||
}
|
||||
|
||||
TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) {
|
||||
@ -1157,5 +1160,45 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReportsFpsAllocation) {
|
||||
::testing::ElementsAreArray(expected_fps_allocation));
|
||||
}
|
||||
|
||||
TEST_F(TestSimulcastEncoderAdapterFake, SetRateDistributesBandwithAllocation) {
|
||||
SimulcastTestFixtureImpl::DefaultSettings(
|
||||
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
|
||||
kVideoCodecVP8);
|
||||
codec_.numberOfSimulcastStreams = 3;
|
||||
const DataRate target_bitrate =
|
||||
DataRate::kbps(codec_.simulcastStream[0].targetBitrate +
|
||||
codec_.simulcastStream[1].targetBitrate +
|
||||
codec_.simulcastStream[2].minBitrate);
|
||||
const DataRate bandwidth_allocation = target_bitrate + DataRate::kbps(600);
|
||||
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
|
||||
adapter_->RegisterEncodeCompleteCallback(this);
|
||||
|
||||
// Set bitrates so that we send all layers.
|
||||
adapter_->SetRates(VideoEncoder::RateControlParameters(
|
||||
rate_allocator_->GetAllocation(target_bitrate.bps(), 30), 30.0,
|
||||
bandwidth_allocation));
|
||||
|
||||
std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
|
||||
|
||||
ASSERT_EQ(3u, encoders.size());
|
||||
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
const uint32_t layer_bitrate_bps =
|
||||
(i < static_cast<size_t>(codec_.numberOfSimulcastStreams) - 1
|
||||
? codec_.simulcastStream[i].targetBitrate
|
||||
: codec_.simulcastStream[i].minBitrate) *
|
||||
1000;
|
||||
EXPECT_EQ(layer_bitrate_bps,
|
||||
encoders[i]->last_set_rates().bitrate.get_sum_bps())
|
||||
<< i;
|
||||
EXPECT_EQ(
|
||||
(layer_bitrate_bps * bandwidth_allocation.bps()) / target_bitrate.bps(),
|
||||
encoders[i]->last_set_rates().bandwidth_allocation.bps())
|
||||
<< i;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user