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 CheckBitrateControllersDecision(BitrateController* controller, | |
22 const Controller::NetworkMetrics& metrics, | |
23 int frame_length_ms, | |
24 int expected_bitrate_bps) { | |
25 AudioNetworkAdaptor::EncoderRuntimeConfig config; | |
26 config.frame_length_ms = rtc::Optional<int>(frame_length_ms); | |
27 controller->MakeDecision(metrics, &config); | |
28 EXPECT_EQ(config.bitrate_bps, rtc::Optional<int>(expected_bitrate_bps)); | |
hlundin-webrtc
2016/09/15 11:01:09
Swap parameters. Expected value should go before t
minyue-webrtc
2016/09/15 12:12:15
Ok. There can be a bit more polishing to be made i
| |
29 } | |
30 | |
31 } // namespace | |
32 | |
33 // These tests are named AnaBitrateControllerTest to distinguish from | |
34 // BitrateControllerTest in | |
35 // modules/bitrate_controller/bitrate_controller_unittest.cc. | |
36 | |
37 TEST(AnaBitrateControllerTest, OutputInitValueWhenTargetBitrateUnknown) { | |
38 constexpr int kInitialBitrateBps = 32000; | |
39 constexpr int kInitialFrameLengthMs = 20; | |
40 BitrateController controller( | |
41 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); | |
42 Controller::NetworkMetrics metrics; | |
43 CheckBitrateControllersDecision( | |
44 &controller, metrics, kInitialFrameLengthMs * 2, kInitialBitrateBps); | |
45 } | |
46 | |
47 TEST(AnaBitrateControllerTest, ChangeBitrateOnTargetBitrateChanged) { | |
48 constexpr int kInitialBitrateBps = 32000; | |
49 constexpr int kInitialFrameLengthMs = 20; | |
50 BitrateController controller( | |
51 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); | |
52 | |
53 Controller::NetworkMetrics metrics; | |
54 constexpr int kTargetBitrateBps = 48000; | |
55 metrics.target_audio_bitrate_bps = rtc::Optional<int>(kTargetBitrateBps); | |
56 | |
57 // Frame length unchanged, bitrate changes in accordance with | |
58 // |metrics.target_audio_bitrate_bps| | |
59 CheckBitrateControllersDecision(&controller, metrics, kInitialFrameLengthMs, | |
60 kTargetBitrateBps); | |
61 } | |
62 | |
63 TEST(AnaBitrateControllerTest, IncreaseBitrateOnFrameLengthIncreased) { | |
64 constexpr int kInitialBitrateBps = 32000; | |
65 constexpr int kInitialFrameLengthMs = 20; | |
66 BitrateController controller( | |
67 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); | |
68 | |
69 Controller::NetworkMetrics metrics; | |
70 metrics.target_audio_bitrate_bps = rtc::Optional<int>(kInitialBitrateBps); | |
71 | |
72 constexpr int kFrameLengthMs = 60; | |
73 constexpr int kPacketOverheadRateDiff = | |
74 kPacketOverheadBits * 1000 / kInitialFrameLengthMs - | |
75 kPacketOverheadBits * 1000 / kFrameLengthMs; | |
76 CheckBitrateControllersDecision(&controller, metrics, kFrameLengthMs, | |
77 kInitialBitrateBps + kPacketOverheadRateDiff); | |
78 } | |
79 | |
80 TEST(AnaBitrateControllerTest, DecreaseBitrateOnFrameLengthDecreased) { | |
81 constexpr int kInitialBitrateBps = 32000; | |
82 constexpr int kInitialFrameLengthMs = 60; | |
83 BitrateController controller( | |
84 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); | |
85 | |
86 Controller::NetworkMetrics metrics; | |
87 metrics.target_audio_bitrate_bps = rtc::Optional<int>(kInitialBitrateBps); | |
88 | |
89 constexpr int kFrameLengthMs = 20; | |
90 constexpr int kPacketOverheadRateDiff = | |
91 kPacketOverheadBits * 1000 / kInitialFrameLengthMs - | |
92 kPacketOverheadBits * 1000 / kFrameLengthMs; | |
93 CheckBitrateControllersDecision(&controller, metrics, kFrameLengthMs, | |
94 kInitialBitrateBps + kPacketOverheadRateDiff); | |
95 } | |
96 | |
97 } // namespace webrtc | |
OLD | NEW |