Fix potential divide by zero in SimulcastEncoderAdapter
Bug: webrtc:11453 Change-Id: I4119955d7a3cdc4099b8f0ab013e5e33ec38715f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/171511 Reviewed-by: Sebastian Jansson <srte@webrtc.org> Commit-Queue: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30866}
This commit is contained in:
@ -513,7 +513,8 @@ void SimulcastEncoderAdapter::SetRates(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Assign link allocation proportionally to spatial layer allocation.
|
// Assign link allocation proportionally to spatial layer allocation.
|
||||||
if (parameters.bandwidth_allocation != DataRate::Zero()) {
|
if (!parameters.bandwidth_allocation.IsZero() &&
|
||||||
|
parameters.bitrate.get_sum_bps() > 0) {
|
||||||
stream_parameters.bandwidth_allocation =
|
stream_parameters.bandwidth_allocation =
|
||||||
DataRate::BitsPerSec((parameters.bandwidth_allocation.bps() *
|
DataRate::BitsPerSec((parameters.bandwidth_allocation.bps() *
|
||||||
stream_parameters.bitrate.get_sum_bps()) /
|
stream_parameters.bitrate.get_sum_bps()) /
|
||||||
|
|||||||
@ -1364,6 +1364,31 @@ TEST_F(TestSimulcastEncoderAdapterFake, SetRateDistributesBandwithAllocation) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TestSimulcastEncoderAdapterFake, CanSetZeroBitrateWithHeadroom) {
|
||||||
|
SimulcastTestFixtureImpl::DefaultSettings(
|
||||||
|
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
|
||||||
|
kVideoCodecVP8);
|
||||||
|
codec_.numberOfSimulcastStreams = 3;
|
||||||
|
|
||||||
|
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||||
|
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||||
|
adapter_->RegisterEncodeCompleteCallback(this);
|
||||||
|
|
||||||
|
// Set allocated bitrate to 0, but keep (network) bandwidth allocation.
|
||||||
|
VideoEncoder::RateControlParameters rate_params;
|
||||||
|
rate_params.framerate_fps = 30;
|
||||||
|
rate_params.bandwidth_allocation = DataRate::KilobitsPerSec(600);
|
||||||
|
|
||||||
|
adapter_->SetRates(rate_params);
|
||||||
|
|
||||||
|
std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
|
||||||
|
|
||||||
|
ASSERT_EQ(3u, encoders.size());
|
||||||
|
for (size_t i = 0; i < 3; ++i) {
|
||||||
|
EXPECT_EQ(0u, encoders[i]->last_set_rates().bitrate.get_sum_bps());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TestSimulcastEncoderAdapterFake, SupportsSimulcast) {
|
TEST_F(TestSimulcastEncoderAdapterFake, SupportsSimulcast) {
|
||||||
SimulcastTestFixtureImpl::DefaultSettings(
|
SimulcastTestFixtureImpl::DefaultSettings(
|
||||||
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
|
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
|
||||||
|
|||||||
Reference in New Issue
Block a user