Move BitrateAllocation to api/ and rename it VideoBitrateAllocation

Since the webrtc_common build target does not have visibility set, we
cannot easily use BitrateAllocation in other parts of Chromium.
This is currently blocking parts of chromium:794608, and I know of other
usage outside webrtc already, so moving it to api/ should be warranted.

Also, since there's some naming confusion and this class is video
specific rename it VideoBitrateAllocation. This also fits with the
standard interface for producing these: VideoBitrateAllocator.

Bug: chromium:794608
Change-Id: I4c0fae40f9365e860c605a76a4f67ecc9b9cf9fe
Reviewed-on: https://webrtc-review.googlesource.com/70783
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22986}
This commit is contained in:
Erik Språng
2018-04-23 12:32:22 +02:00
committed by Commit Bot
parent 5c14725d53
commit 566124a6df
75 changed files with 452 additions and 348 deletions

View File

@ -20,10 +20,10 @@ DefaultVideoBitrateAllocator::DefaultVideoBitrateAllocator(
DefaultVideoBitrateAllocator::~DefaultVideoBitrateAllocator() {}
BitrateAllocation DefaultVideoBitrateAllocator::GetAllocation(
VideoBitrateAllocation DefaultVideoBitrateAllocator::GetAllocation(
uint32_t total_bitrate_bps,
uint32_t framerate) {
BitrateAllocation allocation;
VideoBitrateAllocation allocation;
if (total_bitrate_bps == 0 || !codec_.active)
return allocation;

View File

@ -20,8 +20,8 @@ class DefaultVideoBitrateAllocator : public VideoBitrateAllocator {
explicit DefaultVideoBitrateAllocator(const VideoCodec& codec);
~DefaultVideoBitrateAllocator() override;
BitrateAllocation GetAllocation(uint32_t total_bitrate,
uint32_t framerate) override;
VideoBitrateAllocation GetAllocation(uint32_t total_bitrate,
uint32_t framerate) override;
uint32_t GetPreferredBitrateBps(uint32_t framerate) override;
private:

View File

@ -41,19 +41,22 @@ class DefaultVideoBitrateAllocatorTest : public ::testing::Test {
};
TEST_F(DefaultVideoBitrateAllocatorTest, ZeroIsOff) {
BitrateAllocation allocation = allocator_->GetAllocation(0, kMaxFramerate);
VideoBitrateAllocation allocation =
allocator_->GetAllocation(0, kMaxFramerate);
EXPECT_EQ(0u, allocation.get_sum_bps());
}
TEST_F(DefaultVideoBitrateAllocatorTest, Inactive) {
codec_.active = false;
allocator_.reset(new DefaultVideoBitrateAllocator(codec_));
BitrateAllocation allocation = allocator_->GetAllocation(1, kMaxFramerate);
VideoBitrateAllocation allocation =
allocator_->GetAllocation(1, kMaxFramerate);
EXPECT_EQ(0u, allocation.get_sum_bps());
}
TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMin) {
BitrateAllocation allocation = allocator_->GetAllocation(1, kMaxFramerate);
VideoBitrateAllocation allocation =
allocator_->GetAllocation(1, kMaxFramerate);
EXPECT_EQ(kMinBitrateBps, allocation.get_sum_bps());
allocation = allocator_->GetAllocation(kMinBitrateBps - 1, kMaxFramerate);
@ -64,7 +67,7 @@ TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMin) {
}
TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMax) {
BitrateAllocation allocation =
VideoBitrateAllocation allocation =
allocator_->GetAllocation(kMaxBitrateBps, kMaxFramerate);
EXPECT_EQ(kMaxBitrateBps, allocation.get_sum_bps());
@ -77,7 +80,7 @@ TEST_F(DefaultVideoBitrateAllocatorTest, CapsToMax) {
}
TEST_F(DefaultVideoBitrateAllocatorTest, GoodInBetween) {
BitrateAllocation allocation =
VideoBitrateAllocation allocation =
allocator_->GetAllocation(kMinBitrateBps + 1, kMaxFramerate);
EXPECT_EQ(kMinBitrateBps + 1, allocation.get_sum_bps());

View File

@ -65,7 +65,8 @@ class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> {
}
template <size_t S>
void ExpectEqual(uint32_t (&expected)[S], const BitrateAllocation& actual) {
void ExpectEqual(uint32_t (&expected)[S],
const VideoBitrateAllocation& actual) {
// EXPECT_EQ(S, actual.size());
uint32_t sum = 0;
for (size_t i = 0; i < S; ++i) {
@ -112,7 +113,7 @@ class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> {
}
}
BitrateAllocation GetAllocation(uint32_t target_bitrate) {
VideoBitrateAllocation GetAllocation(uint32_t target_bitrate) {
return allocator_->GetAllocation(target_bitrate * 1000U, kDefaultFrameRate);
}
@ -138,7 +139,7 @@ TEST_F(SimulcastRateAllocatorTest, NoSimulcastAboveMax) {
}
TEST_F(SimulcastRateAllocatorTest, NoSimulcastNoMax) {
const uint32_t kMax = BitrateAllocation::kMaxBitrateBps / 1000;
const uint32_t kMax = VideoBitrateAllocation::kMaxBitrateBps / 1000;
codec_.active = true;
codec_.maxBitrate = 0;
CreateAllocator();
@ -528,7 +529,7 @@ TEST_P(ScreenshareRateAllocationTest, BitrateBelowTl0) {
SetupConferenceScreenshare(GetParam());
CreateAllocator();
BitrateAllocation allocation =
VideoBitrateAllocation allocation =
allocator_->GetAllocation(kTargetBitrateKbps * 1000, kFramerateFps);
// All allocation should go in TL0.
@ -541,7 +542,7 @@ TEST_P(ScreenshareRateAllocationTest, BitrateAboveTl0) {
CreateAllocator();
uint32_t target_bitrate_kbps = (kTargetBitrateKbps + kMaxBitrateKbps) / 2;
BitrateAllocation allocation =
VideoBitrateAllocation allocation =
allocator_->GetAllocation(target_bitrate_kbps * 1000, kFramerateFps);
// Fill TL0, then put the rest in TL1.
@ -555,7 +556,7 @@ TEST_P(ScreenshareRateAllocationTest, BitrateAboveTl1) {
SetupConferenceScreenshare(GetParam());
CreateAllocator();
BitrateAllocation allocation =
VideoBitrateAllocation allocation =
allocator_->GetAllocation(kMaxBitrateKbps * 2000, kFramerateFps);
// Fill both TL0 and TL1, but no more.
@ -573,7 +574,7 @@ TEST_P(ScreenshareRateAllocationTest, InactiveScreenshare) {
// Enough bitrate for TL0 and TL1.
uint32_t target_bitrate_kbps = (kTargetBitrateKbps + kMaxBitrateKbps) / 2;
BitrateAllocation allocation =
VideoBitrateAllocation allocation =
allocator_->GetAllocation(target_bitrate_kbps * 1000, kFramerateFps);
EXPECT_EQ(0U, allocation.get_sum_kbps());