Replace DataSize and DataRate factories with newer versions

This is search and replace change:
find . -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/DataSize::Bytes<\(.*\)>()/DataSize::Bytes(\1)/g"
find . -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/DataSize::bytes/DataSize::Bytes/g"
find . -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/DataRate::BitsPerSec<\(.*\)>()/DataRate::BitsPerSec(\1)/g"
find . -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/DataRate::BytesPerSec<\(.*\)>()/DataRate::BytesPerSec(\1)/g"
find . -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/DataRate::KilobitsPerSec<\(.*\)>()/DataRate::KilobitsPerSec(\1)/g"
find . -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/DataRate::bps/DataRate::BitsPerSec/g"
find . -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/DataRate::kbps/DataRate::KilobitsPerSec/g"
git cl format

Bug: webrtc:9709
Change-Id: I65aaca69474ba038c1fe2dd8dc30d3f8e7b94c29
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168647
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30545}
This commit is contained in:
Danil Chapovalov
2020-02-17 18:46:07 +01:00
committed by Commit Bot
parent 701bd172d8
commit cad3e0e2fa
102 changed files with 947 additions and 798 deletions

View File

@ -295,7 +295,7 @@ int32_t H264EncoderImpl::InitEncode(const VideoCodec* inst,
SimulcastRateAllocator init_allocator(codec_);
VideoBitrateAllocation allocation =
init_allocator.Allocate(VideoBitrateAllocationParameters(
DataRate::kbps(codec_.startBitrate), codec_.maxFramerate));
DataRate::KilobitsPerSec(codec_.startBitrate), codec_.maxFramerate));
SetRates(RateControlParameters(allocation, codec_.maxFramerate));
return WEBRTC_VIDEO_CODEC_OK;
}

View File

@ -242,7 +242,7 @@ void MultiplexEncoderAdapter::SetRates(
bitrate_allocation,
static_cast<uint32_t>(encoders_.size() * parameters.framerate_fps),
parameters.bandwidth_allocation -
DataRate::bps(augmenting_data_size_)));
DataRate::BitsPerSec(augmenting_data_size_)));
}
}

View File

@ -206,7 +206,7 @@ TEST_F(TestVp8Impl, DynamicSetRates) {
static_cast<double>(codec_settings_.maxFramerate);
// Set rates with no headroom.
rate_settings.bandwidth_allocation = DataRate::bps(kBitrateBps);
rate_settings.bandwidth_allocation = DataRate::BitsPerSec(kBitrateBps);
EXPECT_CALL(
*vpx,
codec_enc_config_set(
@ -221,7 +221,7 @@ TEST_F(TestVp8Impl, DynamicSetRates) {
encoder.SetRates(rate_settings);
// Set rates with max headroom.
rate_settings.bandwidth_allocation = DataRate::bps(kBitrateBps * 2);
rate_settings.bandwidth_allocation = DataRate::BitsPerSec(kBitrateBps * 2);
EXPECT_CALL(
*vpx, codec_enc_config_set(
_, AllOf(Field(&vpx_codec_enc_cfg_t::rc_target_bitrate,
@ -235,7 +235,8 @@ TEST_F(TestVp8Impl, DynamicSetRates) {
encoder.SetRates(rate_settings);
// Set rates with headroom half way.
rate_settings.bandwidth_allocation = DataRate::bps((3 * kBitrateBps) / 2);
rate_settings.bandwidth_allocation =
DataRate::BitsPerSec((3 * kBitrateBps) / 2);
EXPECT_CALL(
*vpx,
codec_enc_config_set(

View File

@ -62,9 +62,9 @@ std::vector<DataRate> AdjustAndVerify(
// max bitrate constraint, try to pass it forward to the next one.
DataRate excess_rate = DataRate::Zero();
for (size_t sl_idx = 0; sl_idx < spatial_layer_rates.size(); ++sl_idx) {
DataRate min_rate = DataRate::kbps(
DataRate min_rate = DataRate::KilobitsPerSec(
codec.spatialLayers[first_active_layer + sl_idx].minBitrate);
DataRate max_rate = DataRate::kbps(
DataRate max_rate = DataRate::KilobitsPerSec(
codec.spatialLayers[first_active_layer + sl_idx].maxBitrate);
DataRate layer_rate = spatial_layer_rates[sl_idx] + excess_rate;
@ -125,7 +125,7 @@ DataRate FindLayerTogglingThreshold(const VideoCodec& codec,
size_t first_active_layer,
size_t num_active_layers) {
if (num_active_layers == 1) {
return DataRate::kbps(codec.spatialLayers[0].minBitrate);
return DataRate::KilobitsPerSec(codec.spatialLayers[0].minBitrate);
}
if (codec.mode == VideoCodecMode::kRealtimeVideo) {
@ -133,19 +133,19 @@ DataRate FindLayerTogglingThreshold(const VideoCodec& codec,
DataRate upper_bound = DataRate::Zero();
if (num_active_layers > 1) {
for (size_t i = 0; i < num_active_layers - 1; ++i) {
lower_bound += DataRate::kbps(
lower_bound += DataRate::KilobitsPerSec(
codec.spatialLayers[first_active_layer + i].minBitrate);
upper_bound += DataRate::kbps(
upper_bound += DataRate::KilobitsPerSec(
codec.spatialLayers[first_active_layer + i].maxBitrate);
}
}
upper_bound +=
DataRate::kbps(codec.spatialLayers[num_active_layers - 1].minBitrate);
upper_bound += DataRate::KilobitsPerSec(
codec.spatialLayers[num_active_layers - 1].minBitrate);
// Do a binary search until upper and lower bound is the highest bitrate for
// |num_active_layers| - 1 layers and lowest bitrate for |num_active_layers|
// layers respectively.
while (upper_bound - lower_bound > DataRate::bps(1)) {
while (upper_bound - lower_bound > DataRate::BitsPerSec(1)) {
DataRate try_rate = (lower_bound + upper_bound) / 2;
if (AdjustAndVerify(codec, first_active_layer,
SplitBitrate(num_active_layers, try_rate,
@ -160,10 +160,10 @@ DataRate FindLayerTogglingThreshold(const VideoCodec& codec,
} else {
DataRate toggling_rate = DataRate::Zero();
for (size_t i = 0; i < num_active_layers - 1; ++i) {
toggling_rate += DataRate::kbps(
toggling_rate += DataRate::KilobitsPerSec(
codec.spatialLayers[first_active_layer + i].targetBitrate);
}
toggling_rate += DataRate::kbps(
toggling_rate += DataRate::KilobitsPerSec(
codec.spatialLayers[first_active_layer + num_active_layers - 1]
.minBitrate);
return toggling_rate;
@ -199,7 +199,8 @@ VideoBitrateAllocation SvcRateAllocator::Allocate(
VideoBitrateAllocationParameters parameters) {
DataRate total_bitrate = parameters.total_bitrate;
if (codec_.maxBitrate != 0) {
total_bitrate = std::min(total_bitrate, DataRate::kbps(codec_.maxBitrate));
total_bitrate =
std::min(total_bitrate, DataRate::KilobitsPerSec(codec_.maxBitrate));
}
if (codec_.spatialLayers[0].targetBitrate == 0) {
@ -324,7 +325,8 @@ VideoBitrateAllocation SvcRateAllocator::GetAllocationScreenSharing(
if (num_spatial_layers == 0 ||
total_bitrate <
DataRate::kbps(codec_.spatialLayers[first_active_layer].minBitrate)) {
DataRate::KilobitsPerSec(
codec_.spatialLayers[first_active_layer].minBitrate)) {
// Always enable at least one layer.
bitrate_allocation.SetBitrate(first_active_layer, 0, total_bitrate.bps());
return bitrate_allocation;
@ -336,9 +338,9 @@ VideoBitrateAllocation SvcRateAllocator::GetAllocationScreenSharing(
for (sl_idx = first_active_layer;
sl_idx < first_active_layer + num_spatial_layers; ++sl_idx) {
const DataRate min_rate =
DataRate::kbps(codec_.spatialLayers[sl_idx].minBitrate);
DataRate::KilobitsPerSec(codec_.spatialLayers[sl_idx].minBitrate);
const DataRate target_rate =
DataRate::kbps(codec_.spatialLayers[sl_idx].targetBitrate);
DataRate::KilobitsPerSec(codec_.spatialLayers[sl_idx].targetBitrate);
if (allocated_rate + min_rate > total_bitrate) {
// Use stable rate to determine if layer should be enabled.
@ -352,9 +354,9 @@ VideoBitrateAllocation SvcRateAllocator::GetAllocationScreenSharing(
if (sl_idx > 0 && total_bitrate - allocated_rate > DataRate::Zero()) {
// Add leftover to the last allocated layer.
top_layer_rate =
std::min(top_layer_rate + (total_bitrate - allocated_rate),
DataRate::kbps(codec_.spatialLayers[sl_idx - 1].maxBitrate));
top_layer_rate = std::min(
top_layer_rate + (total_bitrate - allocated_rate),
DataRate::KilobitsPerSec(codec_.spatialLayers[sl_idx - 1].maxBitrate));
bitrate_allocation.SetBitrate(sl_idx - 1, 0, top_layer_rate.bps());
}
@ -385,12 +387,13 @@ DataRate SvcRateAllocator::GetMaxBitrate(const VideoCodec& codec) {
DataRate max_bitrate = DataRate::Zero();
for (size_t sl_idx = 0; sl_idx < num_spatial_layers; ++sl_idx) {
max_bitrate += DataRate::kbps(
max_bitrate += DataRate::KilobitsPerSec(
codec.spatialLayers[first_active_layer + sl_idx].maxBitrate);
}
if (codec.maxBitrate != 0) {
max_bitrate = std::min(max_bitrate, DataRate::kbps(codec.maxBitrate));
max_bitrate =
std::min(max_bitrate, DataRate::KilobitsPerSec(codec.maxBitrate));
}
return max_bitrate;

View File

@ -259,8 +259,8 @@ TEST(SvcRateAllocatorTest, FindLayerTogglingThreshold) {
// Predetermined constants indicating the min bitrate needed for two and three
// layers to be enabled respectively, using the config from Configure() with
// 1280x720 resolution and three spatial layers.
const DataRate kTwoLayerMinRate = DataRate::bps(299150);
const DataRate kThreeLayerMinRate = DataRate::bps(891052);
const DataRate kTwoLayerMinRate = DataRate::BitsPerSec(299150);
const DataRate kThreeLayerMinRate = DataRate::BitsPerSec(891052);
VideoCodec codec = Configure(1280, 720, 3, 1, false);
absl::InlinedVector<DataRate, kMaxSpatialLayers> layer_start_bitrates =
@ -283,14 +283,14 @@ class SvcRateAllocatorTestParametrizedContentType
TEST_P(SvcRateAllocatorTestParametrizedContentType, MaxBitrate) {
VideoCodec codec = Configure(1280, 720, 3, 1, is_screen_sharing_);
EXPECT_EQ(SvcRateAllocator::GetMaxBitrate(codec),
DataRate::kbps(codec.spatialLayers[0].maxBitrate +
codec.spatialLayers[1].maxBitrate +
codec.spatialLayers[2].maxBitrate));
DataRate::KilobitsPerSec(codec.spatialLayers[0].maxBitrate +
codec.spatialLayers[1].maxBitrate +
codec.spatialLayers[2].maxBitrate));
// Deactivate middle layer. This causes deactivation of top layer as well.
codec.spatialLayers[1].active = false;
EXPECT_EQ(SvcRateAllocator::GetMaxBitrate(codec),
DataRate::kbps(codec.spatialLayers[0].maxBitrate));
DataRate::KilobitsPerSec(codec.spatialLayers[0].maxBitrate));
}
TEST_P(SvcRateAllocatorTestParametrizedContentType, PaddingBitrate) {
@ -349,12 +349,13 @@ TEST_P(SvcRateAllocatorTestParametrizedContentType, StableBitrate) {
const DataRate min_rate_three_layers = start_rates[2];
const DataRate max_rate_one_layer =
DataRate::kbps(codec.spatialLayers[0].maxBitrate);
DataRate::KilobitsPerSec(codec.spatialLayers[0].maxBitrate);
const DataRate max_rate_two_layers =
is_screen_sharing_ ? DataRate::kbps(codec.spatialLayers[0].targetBitrate +
codec.spatialLayers[1].maxBitrate)
: DataRate::kbps(codec.spatialLayers[0].maxBitrate +
codec.spatialLayers[1].maxBitrate);
is_screen_sharing_
? DataRate::KilobitsPerSec(codec.spatialLayers[0].targetBitrate +
codec.spatialLayers[1].maxBitrate)
: DataRate::KilobitsPerSec(codec.spatialLayers[0].maxBitrate +
codec.spatialLayers[1].maxBitrate);
SvcRateAllocator allocator = SvcRateAllocator(codec);
@ -368,12 +369,12 @@ TEST_P(SvcRateAllocatorTestParametrizedContentType, StableBitrate) {
// Two layers, stable bitrate too low for two layers.
allocation = allocator.Allocate(VideoBitrateAllocationParameters(
/*total_bitrate=*/min_rate_two_layers,
/*stable_bitrate=*/min_rate_two_layers - DataRate::bps(1),
/*stable_bitrate=*/min_rate_two_layers - DataRate::BitsPerSec(1),
/*fps=*/30.0));
EXPECT_FALSE(allocation.IsSpatialLayerUsed(1));
EXPECT_EQ(
DataRate::bps(allocation.get_sum_bps()),
std::min(min_rate_two_layers - DataRate::bps(1), max_rate_one_layer));
EXPECT_EQ(DataRate::BitsPerSec(allocation.get_sum_bps()),
std::min(min_rate_two_layers - DataRate::BitsPerSec(1),
max_rate_one_layer));
// Three layers, stable and target equal.
allocation = allocator.Allocate(VideoBitrateAllocationParameters(
@ -385,12 +386,12 @@ TEST_P(SvcRateAllocatorTestParametrizedContentType, StableBitrate) {
// Three layers, stable bitrate too low for three layers.
allocation = allocator.Allocate(VideoBitrateAllocationParameters(
/*total_bitrate=*/min_rate_three_layers,
/*stable_bitrate=*/min_rate_three_layers - DataRate::bps(1),
/*stable_bitrate=*/min_rate_three_layers - DataRate::BitsPerSec(1),
/*fps=*/30.0));
EXPECT_FALSE(allocation.IsSpatialLayerUsed(2));
EXPECT_EQ(
DataRate::bps(allocation.get_sum_bps()),
std::min(min_rate_three_layers - DataRate::bps(1), max_rate_two_layers));
EXPECT_EQ(DataRate::BitsPerSec(allocation.get_sum_bps()),
std::min(min_rate_three_layers - DataRate::BitsPerSec(1),
max_rate_two_layers));
}
TEST_P(SvcRateAllocatorTestParametrizedContentType,
@ -444,7 +445,8 @@ TEST_P(SvcRateAllocatorTestParametrizedContentType,
// Going below min for two layers, second layer should turn off again.
allocation = allocator.Allocate(VideoBitrateAllocationParameters(
/*total_bitrate=*/max_bitrate,
/*stable_bitrate=*/min_rate_two_layers - DataRate::bps(1), /*fps=*/30.0));
/*stable_bitrate=*/min_rate_two_layers - DataRate::BitsPerSec(1),
/*fps=*/30.0));
EXPECT_TRUE(allocation.IsSpatialLayerUsed(0));
EXPECT_FALSE(allocation.IsSpatialLayerUsed(1));
EXPECT_FALSE(allocation.IsSpatialLayerUsed(2));
@ -476,7 +478,7 @@ TEST_P(SvcRateAllocatorTestParametrizedContentType,
// Going below min for three layers, third layer should turn off again.
allocation = allocator.Allocate(VideoBitrateAllocationParameters(
/*total_bitrate=*/max_bitrate,
/*stable_bitrate=*/min_rate_three_layers - DataRate::bps(1),
/*stable_bitrate=*/min_rate_three_layers - DataRate::BitsPerSec(1),
/*fps=*/30.0));
EXPECT_TRUE(allocation.IsSpatialLayerUsed(0));
EXPECT_TRUE(allocation.IsSpatialLayerUsed(1));

View File

@ -1667,7 +1667,7 @@ TEST_F(TestVp9Impl, EncodeWithDynamicRate) {
// Set 300kbps target with 100% headroom.
VideoEncoder::RateControlParameters params;
params.bandwidth_allocation = DataRate::bps(300000);
params.bandwidth_allocation = DataRate::BitsPerSec(300000);
params.bitrate.SetBitrate(0, 0, params.bandwidth_allocation.bps());
params.framerate_fps = 30.0;