| Index: webrtc/modules/video_coding/utility/simulcast_rate_allocator_unittest.cc
|
| diff --git a/webrtc/modules/video_coding/utility/simulcast_rate_allocator_unittest.cc b/webrtc/modules/video_coding/utility/simulcast_rate_allocator_unittest.cc
|
| index 57fd5d22bdfb235b0524228cb6e1a9e03c42a815..a6ea0c0526f2d6fd3826ea308123d020e88a4958 100644
|
| --- a/webrtc/modules/video_coding/utility/simulcast_rate_allocator_unittest.cc
|
| +++ b/webrtc/modules/video_coding/utility/simulcast_rate_allocator_unittest.cc
|
| @@ -12,6 +12,7 @@
|
|
|
| #include <limits>
|
| #include <memory>
|
| +#include <vector>
|
|
|
| #include "webrtc/test/gtest.h"
|
|
|
| @@ -41,43 +42,59 @@ class SimulcastRateAllocatorTest : public ::testing::Test {
|
| EXPECT_EQ(expected[i], actual[i]) << "Mismatch at index " << i;
|
| }
|
|
|
| + template <size_t S>
|
| + void ExpectEqual(uint32_t (&expected)[S], const BitrateAllocation& actual) {
|
| + // EXPECT_EQ(S, actual.size());
|
| + uint32_t sum = 0;
|
| + for (size_t i = 0; i < S; ++i) {
|
| + uint32_t layer_bitrate = actual.get_spatial_layer_sum(i);
|
| + EXPECT_EQ(expected[i] * 1000, layer_bitrate) << "Mismatch at index " << i;
|
| + sum += layer_bitrate;
|
| + }
|
| + EXPECT_EQ(sum, actual.get_sum_bps());
|
| + }
|
| +
|
| void CreateAllocator() {
|
| allocator_.reset(new SimulcastRateAllocator(codec_));
|
| }
|
|
|
| + BitrateAllocation GetAllocation(uint32_t target_bitrate) {
|
| + return allocator_->GetAllocation(target_bitrate * 1000, kDefaultFrameRate);
|
| + }
|
| +
|
| protected:
|
| + static const int kDefaultFrameRate = 30;
|
| VideoCodec codec_;
|
| std::unique_ptr<SimulcastRateAllocator> allocator_;
|
| };
|
|
|
| TEST_F(SimulcastRateAllocatorTest, NoSimulcastBelowMin) {
|
| uint32_t expected[] = {codec_.minBitrate};
|
| - ExpectEqual(expected, allocator_->GetAllocation(codec_.minBitrate - 1));
|
| - ExpectEqual(expected, allocator_->GetAllocation(1));
|
| - ExpectEqual(expected, allocator_->GetAllocation(0));
|
| + ExpectEqual(expected, GetAllocation(codec_.minBitrate - 1));
|
| + ExpectEqual(expected, GetAllocation(1));
|
| + ExpectEqual(expected, GetAllocation(0));
|
| }
|
|
|
| TEST_F(SimulcastRateAllocatorTest, NoSimulcastAboveMax) {
|
| uint32_t expected[] = {codec_.maxBitrate};
|
| - ExpectEqual(expected, allocator_->GetAllocation(codec_.maxBitrate + 1));
|
| - ExpectEqual(expected,
|
| - allocator_->GetAllocation(std::numeric_limits<uint32_t>::max()));
|
| + ExpectEqual(expected, GetAllocation(codec_.maxBitrate + 1));
|
| + ExpectEqual(expected, GetAllocation(std::numeric_limits<uint32_t>::max()));
|
| }
|
|
|
| TEST_F(SimulcastRateAllocatorTest, NoSimulcastNoMax) {
|
| - constexpr uint32_t kMax = std::numeric_limits<uint32_t>::max();
|
| + constexpr uint32_t kMax = BitrateAllocation::kMaxBitrateBps / 1000;
|
| codec_.maxBitrate = 0;
|
| CreateAllocator();
|
|
|
| uint32_t expected[] = {kMax};
|
| - ExpectEqual(expected, allocator_->GetAllocation(kMax));
|
| + ExpectEqual(expected, GetAllocation(kMax));
|
| }
|
|
|
| TEST_F(SimulcastRateAllocatorTest, NoSimulcastWithinLimits) {
|
| for (uint32_t bitrate = codec_.minBitrate; bitrate <= codec_.maxBitrate;
|
| ++bitrate) {
|
| uint32_t expected[] = {bitrate};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
| }
|
|
|
| @@ -90,9 +107,9 @@ TEST_F(SimulcastRateAllocatorTest, SingleSimulcastBelowMin) {
|
| CreateAllocator();
|
|
|
| uint32_t expected[] = {kMin};
|
| - ExpectEqual(expected, allocator_->GetAllocation(kMin - 1));
|
| - ExpectEqual(expected, allocator_->GetAllocation(1));
|
| - ExpectEqual(expected, allocator_->GetAllocation(0));
|
| + ExpectEqual(expected, GetAllocation(kMin - 1));
|
| + ExpectEqual(expected, GetAllocation(1));
|
| + ExpectEqual(expected, GetAllocation(0));
|
| }
|
|
|
| TEST_F(SimulcastRateAllocatorTest, SingleSimulcastAboveMax) {
|
| @@ -103,9 +120,9 @@ TEST_F(SimulcastRateAllocatorTest, SingleSimulcastAboveMax) {
|
| CreateAllocator();
|
|
|
| uint32_t expected[] = {kMax};
|
| - ExpectEqual(expected, allocator_->GetAllocation(kMax + 1));
|
| - ExpectEqual(expected,
|
| - allocator_->GetAllocation(std::numeric_limits<uint32_t>::max()));
|
| + ExpectEqual(expected, GetAllocation(kMax));
|
| + ExpectEqual(expected, GetAllocation(kMax + 1));
|
| + ExpectEqual(expected, GetAllocation(std::numeric_limits<uint32_t>::max()));
|
| }
|
|
|
| TEST_F(SimulcastRateAllocatorTest, SingleSimulcastWithinLimits) {
|
| @@ -117,7 +134,7 @@ TEST_F(SimulcastRateAllocatorTest, SingleSimulcastWithinLimits) {
|
|
|
| for (uint32_t bitrate = kMinBitrate; bitrate <= kMaxBitrate; ++bitrate) {
|
| uint32_t expected[] = {bitrate};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
| }
|
|
|
| @@ -139,14 +156,14 @@ TEST_F(SimulcastRateAllocatorTest, OneToThreeStreams) {
|
| // Single stream, min bitrate.
|
| const uint32_t bitrate = codec_.simulcastStream[0].minBitrate;
|
| uint32_t expected[] = {bitrate, 0, 0};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
|
|
| {
|
| // Single stream at target bitrate.
|
| const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate;
|
| uint32_t expected[] = {bitrate, 0, 0};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
|
|
| {
|
| @@ -154,7 +171,7 @@ TEST_F(SimulcastRateAllocatorTest, OneToThreeStreams) {
|
| const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate +
|
| codec_.simulcastStream[1].minBitrate - 1;
|
| uint32_t expected[] = {bitrate, 0, 0};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
|
|
| {
|
| @@ -163,7 +180,7 @@ TEST_F(SimulcastRateAllocatorTest, OneToThreeStreams) {
|
| codec_.simulcastStream[1].minBitrate;
|
| uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate,
|
| codec_.simulcastStream[1].minBitrate, 0};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
|
|
| {
|
| @@ -172,7 +189,7 @@ TEST_F(SimulcastRateAllocatorTest, OneToThreeStreams) {
|
| codec_.simulcastStream[1].maxBitrate;
|
| uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate,
|
| codec_.simulcastStream[1].maxBitrate, 0};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
|
|
| {
|
| @@ -182,7 +199,7 @@ TEST_F(SimulcastRateAllocatorTest, OneToThreeStreams) {
|
| codec_.simulcastStream[1].maxBitrate + 499;
|
| uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate,
|
| codec_.simulcastStream[1].maxBitrate, 0};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
|
|
| {
|
| @@ -193,7 +210,7 @@ TEST_F(SimulcastRateAllocatorTest, OneToThreeStreams) {
|
| uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate,
|
| codec_.simulcastStream[1].targetBitrate,
|
| codec_.simulcastStream[2].minBitrate};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
|
|
| {
|
| @@ -204,12 +221,13 @@ TEST_F(SimulcastRateAllocatorTest, OneToThreeStreams) {
|
| uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate,
|
| codec_.simulcastStream[1].targetBitrate,
|
| codec_.simulcastStream[2].maxBitrate};
|
| - ExpectEqual(expected, allocator_->GetAllocation(bitrate));
|
| + ExpectEqual(expected, GetAllocation(bitrate));
|
| }
|
| }
|
|
|
| TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrate) {
|
| - EXPECT_EQ(codec_.maxBitrate, allocator_->GetPreferedBitrate());
|
| + EXPECT_EQ(codec_.maxBitrate,
|
| + allocator_->GetPreferedBitrate(codec_.maxFramerate));
|
| }
|
|
|
| TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrateSimulcast) {
|
| @@ -233,7 +251,8 @@ TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrateSimulcast) {
|
| preferred_bitrate += codec_.simulcastStream[1].targetBitrate;
|
| preferred_bitrate += codec_.simulcastStream[2].maxBitrate;
|
|
|
| - EXPECT_EQ(preferred_bitrate, allocator_->GetPreferedBitrate());
|
| + EXPECT_EQ(preferred_bitrate,
|
| + allocator_->GetPreferedBitrate(codec_.maxFramerate));
|
| }
|
|
|
| } // namespace webrtc
|
|
|