OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.h
" |
| 13 |
| 14 namespace webrtc { |
| 15 |
| 16 namespace { |
| 17 |
| 18 // L2(14B) + IPv4(20B) + UDP(8B) + RTP(12B) + SRTP_AUTH(10B) = 64B = 512 bits |
| 19 constexpr int kPacketOverheadBits = 512; |
| 20 |
| 21 void CheckDecision(BitrateController* controller, |
| 22 const rtc::Optional<int>& target_audio_bitrate_bps, |
| 23 const rtc::Optional<int>& frame_length_ms, |
| 24 int expected_bitrate_bps) { |
| 25 Controller::NetworkMetrics metrics; |
| 26 metrics.target_audio_bitrate_bps = target_audio_bitrate_bps; |
| 27 AudioNetworkAdaptor::EncoderRuntimeConfig config; |
| 28 config.frame_length_ms = frame_length_ms; |
| 29 controller->MakeDecision(metrics, &config); |
| 30 EXPECT_EQ(rtc::Optional<int>(expected_bitrate_bps), config.bitrate_bps); |
| 31 } |
| 32 |
| 33 } // namespace |
| 34 |
| 35 // These tests are named AnaBitrateControllerTest to distinguish from |
| 36 // BitrateControllerTest in |
| 37 // modules/bitrate_controller/bitrate_controller_unittest.cc. |
| 38 |
| 39 TEST(AnaBitrateControllerTest, OutputInitValueWhenTargetBitrateUnknown) { |
| 40 constexpr int kInitialBitrateBps = 32000; |
| 41 constexpr int kInitialFrameLengthMs = 20; |
| 42 BitrateController controller( |
| 43 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); |
| 44 CheckDecision(&controller, rtc::Optional<int>(), |
| 45 rtc::Optional<int>(kInitialFrameLengthMs * 2), |
| 46 kInitialBitrateBps); |
| 47 } |
| 48 |
| 49 TEST(AnaBitrateControllerTest, ChangeBitrateOnTargetBitrateChanged) { |
| 50 constexpr int kInitialBitrateBps = 32000; |
| 51 constexpr int kInitialFrameLengthMs = 20; |
| 52 BitrateController controller( |
| 53 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); |
| 54 constexpr int kTargetBitrateBps = 48000; |
| 55 // Frame length unchanged, bitrate changes in accordance with |
| 56 // |metrics.target_audio_bitrate_bps| |
| 57 CheckDecision(&controller, rtc::Optional<int>(kTargetBitrateBps), |
| 58 rtc::Optional<int>(kInitialFrameLengthMs), kTargetBitrateBps); |
| 59 } |
| 60 |
| 61 TEST(AnaBitrateControllerTest, TreatUnknownFrameLengthAsFrameLengthUnchanged) { |
| 62 constexpr int kInitialBitrateBps = 32000; |
| 63 constexpr int kInitialFrameLengthMs = 20; |
| 64 BitrateController controller( |
| 65 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); |
| 66 constexpr int kTargetBitrateBps = 48000; |
| 67 CheckDecision(&controller, rtc::Optional<int>(kTargetBitrateBps), |
| 68 rtc::Optional<int>(), kTargetBitrateBps); |
| 69 } |
| 70 |
| 71 TEST(AnaBitrateControllerTest, IncreaseBitrateOnFrameLengthIncreased) { |
| 72 constexpr int kInitialBitrateBps = 32000; |
| 73 constexpr int kInitialFrameLengthMs = 20; |
| 74 BitrateController controller( |
| 75 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); |
| 76 constexpr int kFrameLengthMs = 60; |
| 77 constexpr int kPacketOverheadRateDiff = |
| 78 kPacketOverheadBits * 1000 / kInitialFrameLengthMs - |
| 79 kPacketOverheadBits * 1000 / kFrameLengthMs; |
| 80 CheckDecision(&controller, rtc::Optional<int>(kInitialBitrateBps), |
| 81 rtc::Optional<int>(kFrameLengthMs), |
| 82 kInitialBitrateBps + kPacketOverheadRateDiff); |
| 83 } |
| 84 |
| 85 TEST(AnaBitrateControllerTest, DecreaseBitrateOnFrameLengthDecreased) { |
| 86 constexpr int kInitialBitrateBps = 32000; |
| 87 constexpr int kInitialFrameLengthMs = 60; |
| 88 BitrateController controller( |
| 89 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); |
| 90 constexpr int kFrameLengthMs = 20; |
| 91 constexpr int kPacketOverheadRateDiff = |
| 92 kPacketOverheadBits * 1000 / kInitialFrameLengthMs - |
| 93 kPacketOverheadBits * 1000 / kFrameLengthMs; |
| 94 CheckDecision(&controller, rtc::Optional<int>(kInitialBitrateBps), |
| 95 rtc::Optional<int>(kFrameLengthMs), |
| 96 kInitialBitrateBps + kPacketOverheadRateDiff); |
| 97 } |
| 98 |
| 99 TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) { |
| 100 constexpr int kInitialBitrateBps = 32000; |
| 101 constexpr int kInitialFrameLengthMs = 20; |
| 102 BitrateController controller( |
| 103 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); |
| 104 |
| 105 int last_overhead_bitrate = |
| 106 kPacketOverheadBits * 1000 / kInitialFrameLengthMs; |
| 107 int current_overhead_bitrate = kPacketOverheadBits * 1000 / 20; |
| 108 // Start from an arbitrary overall bitrate. |
| 109 int overall_bitrate = 34567; |
| 110 CheckDecision( |
| 111 &controller, rtc::Optional<int>(overall_bitrate - last_overhead_bitrate), |
| 112 rtc::Optional<int>(20), overall_bitrate - current_overhead_bitrate); |
| 113 |
| 114 // Next: increase overall bitrate. |
| 115 overall_bitrate += 100; |
| 116 CheckDecision( |
| 117 &controller, rtc::Optional<int>(overall_bitrate - last_overhead_bitrate), |
| 118 rtc::Optional<int>(20), overall_bitrate - current_overhead_bitrate); |
| 119 |
| 120 // Next: change frame length. |
| 121 current_overhead_bitrate = kPacketOverheadBits * 1000 / 60; |
| 122 CheckDecision( |
| 123 &controller, rtc::Optional<int>(overall_bitrate - last_overhead_bitrate), |
| 124 rtc::Optional<int>(60), overall_bitrate - current_overhead_bitrate); |
| 125 last_overhead_bitrate = current_overhead_bitrate; |
| 126 |
| 127 // Next: change frame length. |
| 128 current_overhead_bitrate = kPacketOverheadBits * 1000 / 20; |
| 129 CheckDecision( |
| 130 &controller, rtc::Optional<int>(overall_bitrate - last_overhead_bitrate), |
| 131 rtc::Optional<int>(20), overall_bitrate - current_overhead_bitrate); |
| 132 last_overhead_bitrate = current_overhead_bitrate; |
| 133 |
| 134 // Next: decrease overall bitrate and frame length. |
| 135 overall_bitrate -= 100; |
| 136 current_overhead_bitrate = kPacketOverheadBits * 1000 / 60; |
| 137 CheckDecision( |
| 138 &controller, rtc::Optional<int>(overall_bitrate - last_overhead_bitrate), |
| 139 rtc::Optional<int>(60), overall_bitrate - current_overhead_bitrate); |
| 140 } |
| 141 |
| 142 } // namespace webrtc |
OLD | NEW |