| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | 11 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" |
| 12 | 12 |
| 13 #include <limits> | 13 #include <limits> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <utility> | 15 #include <utility> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "webrtc/test/gmock.h" |
| 18 #include "webrtc/test/gtest.h" | 19 #include "webrtc/test/gtest.h" |
| 19 | 20 |
| 20 namespace webrtc { | 21 namespace webrtc { |
| 21 namespace { | 22 namespace { |
| 23 using ::testing::_; |
| 24 |
| 22 constexpr uint32_t kMinBitrateKbps = 50; | 25 constexpr uint32_t kMinBitrateKbps = 50; |
| 23 constexpr uint32_t kTargetBitrateKbps = 100; | 26 constexpr uint32_t kTargetBitrateKbps = 100; |
| 24 constexpr uint32_t kMaxBitrateKbps = 1000; | 27 constexpr uint32_t kMaxBitrateKbps = 1000; |
| 25 constexpr uint32_t kFramerateFps = 5; | 28 constexpr uint32_t kFramerateFps = 5; |
| 29 |
| 30 class MockTemporalLayers : public TemporalLayers { |
| 31 public: |
| 32 MOCK_METHOD1(EncodeFlags, int(uint32_t)); |
| 33 MOCK_METHOD3(OnRatesUpdated, std::vector<uint32_t>(int, int, int)); |
| 34 MOCK_METHOD1(UpdateConfiguration, bool(vpx_codec_enc_cfg_t*)); |
| 35 MOCK_METHOD3(PopulateCodecSpecific, |
| 36 void(bool, CodecSpecificInfoVP8*, uint32_t)); |
| 37 MOCK_METHOD3(FrameEncoded, void(unsigned int, uint32_t, int)); |
| 38 MOCK_CONST_METHOD0(CurrentLayerId, int()); |
| 39 }; |
| 26 } // namespace | 40 } // namespace |
| 27 | 41 |
| 28 class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> { | 42 class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> { |
| 29 public: | 43 public: |
| 30 SimulcastRateAllocatorTest() { | 44 SimulcastRateAllocatorTest() { |
| 31 memset(&codec_, 0, sizeof(VideoCodec)); | 45 memset(&codec_, 0, sizeof(VideoCodec)); |
| 32 codec_.minBitrate = kMinBitrateKbps; | 46 codec_.minBitrate = kMinBitrateKbps; |
| 33 codec_.targetBitrate = kTargetBitrateKbps; | 47 codec_.targetBitrate = kTargetBitrateKbps; |
| 34 codec_.maxBitrate = kMaxBitrateKbps; | 48 codec_.maxBitrate = kMaxBitrateKbps; |
| 35 CreateAllocator(); | 49 CreateAllocator(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 codec_.simulcastStream[1].targetBitrate + | 258 codec_.simulcastStream[1].targetBitrate + |
| 245 codec_.simulcastStream[2].maxBitrate; | 259 codec_.simulcastStream[2].maxBitrate; |
| 246 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, | 260 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, |
| 247 codec_.simulcastStream[1].targetBitrate, | 261 codec_.simulcastStream[1].targetBitrate, |
| 248 codec_.simulcastStream[2].maxBitrate}; | 262 codec_.simulcastStream[2].maxBitrate}; |
| 249 ExpectEqual(expected, GetAllocation(bitrate)); | 263 ExpectEqual(expected, GetAllocation(bitrate)); |
| 250 } | 264 } |
| 251 } | 265 } |
| 252 | 266 |
| 253 TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrateBps) { | 267 TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrateBps) { |
| 268 MockTemporalLayers mock_layers; |
| 269 allocator_.reset(new SimulcastRateAllocator(codec_, nullptr)); |
| 270 allocator_->OnTemporalLayersCreated(0, &mock_layers); |
| 271 EXPECT_CALL(mock_layers, OnRatesUpdated(_, _, _)).Times(0); |
| 254 EXPECT_EQ(codec_.maxBitrate * 1000, | 272 EXPECT_EQ(codec_.maxBitrate * 1000, |
| 255 allocator_->GetPreferredBitrateBps(codec_.maxFramerate)); | 273 allocator_->GetPreferredBitrateBps(codec_.maxFramerate)); |
| 256 } | 274 } |
| 257 | 275 |
| 258 TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrateSimulcast) { | 276 TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrateSimulcast) { |
| 259 codec_.numberOfSimulcastStreams = 3; | 277 codec_.numberOfSimulcastStreams = 3; |
| 260 codec_.maxBitrate = 999999; | 278 codec_.maxBitrate = 999999; |
| 261 codec_.simulcastStream[0].minBitrate = 10; | 279 codec_.simulcastStream[0].minBitrate = 10; |
| 262 codec_.simulcastStream[0].targetBitrate = 100; | 280 codec_.simulcastStream[0].targetBitrate = 100; |
| 263 | 281 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 allocator_->GetAllocation(kMaxBitrateKbps * 2000, kFramerateFps); | 362 allocator_->GetAllocation(kMaxBitrateKbps * 2000, kFramerateFps); |
| 345 | 363 |
| 346 // Fill both TL0 and TL1, but no more. | 364 // Fill both TL0 and TL1, but no more. |
| 347 EXPECT_EQ(kMaxBitrateKbps, allocation.get_sum_kbps()); | 365 EXPECT_EQ(kMaxBitrateKbps, allocation.get_sum_kbps()); |
| 348 EXPECT_EQ(kTargetBitrateKbps, allocation.GetBitrate(0, 0) / 1000); | 366 EXPECT_EQ(kTargetBitrateKbps, allocation.GetBitrate(0, 0) / 1000); |
| 349 EXPECT_EQ(kMaxBitrateKbps - kTargetBitrateKbps, | 367 EXPECT_EQ(kMaxBitrateKbps - kTargetBitrateKbps, |
| 350 allocation.GetBitrate(0, 1) / 1000); | 368 allocation.GetBitrate(0, 1) / 1000); |
| 351 } | 369 } |
| 352 | 370 |
| 353 } // namespace webrtc | 371 } // namespace webrtc |
| OLD | NEW |