Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(826)

Side by Side Diff: modules/audio_coding/audio_network_adaptor/bitrate_controller_unittest.cc

Issue 3013613002: Added configurable offsets to the per-packet overhead in ANA. (Closed)
Patch Set: Added conversion to size_t in DCHECK. Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } // namespace 48 } // namespace
49 49
50 // These tests are named AnaBitrateControllerTest to distinguish from 50 // These tests are named AnaBitrateControllerTest to distinguish from
51 // BitrateControllerTest in 51 // BitrateControllerTest in
52 // modules/bitrate_controller/bitrate_controller_unittest.cc. 52 // modules/bitrate_controller/bitrate_controller_unittest.cc.
53 53
54 TEST(AnaBitrateControllerTest, OutputInitValueWhenTargetBitrateUnknown) { 54 TEST(AnaBitrateControllerTest, OutputInitValueWhenTargetBitrateUnknown) {
55 constexpr int kInitialBitrateBps = 32000; 55 constexpr int kInitialBitrateBps = 32000;
56 constexpr int kInitialFrameLengthMs = 20; 56 constexpr int kInitialFrameLengthMs = 20;
57 constexpr size_t kOverheadBytesPerPacket = 64; 57 constexpr size_t kOverheadBytesPerPacket = 64;
58 BitrateController controller( 58 BitrateController controller(BitrateController::Config(
59 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); 59 kInitialBitrateBps, kInitialFrameLengthMs, 0, 0));
60 UpdateNetworkMetrics(&controller, rtc::Optional<int>(), 60 UpdateNetworkMetrics(&controller, rtc::Optional<int>(),
61 rtc::Optional<size_t>(kOverheadBytesPerPacket)); 61 rtc::Optional<size_t>(kOverheadBytesPerPacket));
62 CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs * 2), 62 CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs * 2),
63 kInitialBitrateBps); 63 kInitialBitrateBps);
64 } 64 }
65 65
66 TEST(AnaBitrateControllerTest, OutputInitValueWhenOverheadUnknown) { 66 TEST(AnaBitrateControllerTest, OutputInitValueWhenOverheadUnknown) {
67 constexpr int kInitialBitrateBps = 32000; 67 constexpr int kInitialBitrateBps = 32000;
68 constexpr int kInitialFrameLengthMs = 20; 68 constexpr int kInitialFrameLengthMs = 20;
69 constexpr int kTargetBitrateBps = 48000; 69 constexpr int kTargetBitrateBps = 48000;
70 BitrateController controller( 70 BitrateController controller(BitrateController::Config(
71 BitrateController::Config(kInitialBitrateBps, kInitialFrameLengthMs)); 71 kInitialBitrateBps, kInitialFrameLengthMs, 0, 0));
72 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps), 72 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
73 rtc::Optional<size_t>()); 73 rtc::Optional<size_t>());
74 CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs * 2), 74 CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs * 2),
75 kInitialBitrateBps); 75 kInitialBitrateBps);
76 } 76 }
77 77
78 TEST(AnaBitrateControllerTest, ChangeBitrateOnTargetBitrateChanged) { 78 TEST(AnaBitrateControllerTest, ChangeBitrateOnTargetBitrateChanged) {
79 test::ScopedFieldTrials override_field_trials( 79 test::ScopedFieldTrials override_field_trials(
80 "WebRTC-SendSideBwe-WithOverhead/Enabled/"); 80 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
81 constexpr int kInitialFrameLengthMs = 20; 81 constexpr int kInitialFrameLengthMs = 20;
82 BitrateController controller( 82 BitrateController controller(
83 BitrateController::Config(32000, kInitialFrameLengthMs)); 83 BitrateController::Config(32000, kInitialFrameLengthMs, 0, 0));
84 constexpr int kTargetBitrateBps = 48000; 84 constexpr int kTargetBitrateBps = 48000;
85 constexpr size_t kOverheadBytesPerPacket = 64; 85 constexpr size_t kOverheadBytesPerPacket = 64;
86 constexpr int kBitrateBps = 86 constexpr int kBitrateBps =
87 kTargetBitrateBps - 87 kTargetBitrateBps -
88 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs; 88 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
89 // Frame length unchanged, bitrate changes in accordance with 89 // Frame length unchanged, bitrate changes in accordance with
90 // |metrics.target_audio_bitrate_bps| and |metrics.overhead_bytes_per_packet|. 90 // |metrics.target_audio_bitrate_bps| and |metrics.overhead_bytes_per_packet|.
91 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps), 91 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
92 rtc::Optional<size_t>(kOverheadBytesPerPacket)); 92 rtc::Optional<size_t>(kOverheadBytesPerPacket));
93 CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs), 93 CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs),
94 kBitrateBps); 94 kBitrateBps);
95 } 95 }
96 96
97 TEST(AnaBitrateControllerTest, UpdateMultipleNetworkMetricsAtOnce) { 97 TEST(AnaBitrateControllerTest, UpdateMultipleNetworkMetricsAtOnce) {
98 // This test is similar to ChangeBitrateOnTargetBitrateChanged. But instead of 98 // This test is similar to ChangeBitrateOnTargetBitrateChanged. But instead of
99 // using ::UpdateNetworkMetrics(...), which calls 99 // using ::UpdateNetworkMetrics(...), which calls
100 // BitrateController::UpdateNetworkMetrics(...) multiple times, we 100 // BitrateController::UpdateNetworkMetrics(...) multiple times, we
101 // we call it only once. This is to verify that 101 // we call it only once. This is to verify that
102 // BitrateController::UpdateNetworkMetrics(...) can handle multiple 102 // BitrateController::UpdateNetworkMetrics(...) can handle multiple
103 // network updates at once. This is, however, not a common use case in current 103 // network updates at once. This is, however, not a common use case in current
104 // audio_network_adaptor_impl.cc. 104 // audio_network_adaptor_impl.cc.
105 test::ScopedFieldTrials override_field_trials( 105 test::ScopedFieldTrials override_field_trials(
106 "WebRTC-SendSideBwe-WithOverhead/Enabled/"); 106 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
107 constexpr int kInitialFrameLengthMs = 20; 107 constexpr int kInitialFrameLengthMs = 20;
108 BitrateController controller( 108 BitrateController controller(
109 BitrateController::Config(32000, kInitialFrameLengthMs)); 109 BitrateController::Config(32000, kInitialFrameLengthMs, 0, 0));
110 constexpr int kTargetBitrateBps = 48000; 110 constexpr int kTargetBitrateBps = 48000;
111 constexpr size_t kOverheadBytesPerPacket = 64; 111 constexpr size_t kOverheadBytesPerPacket = 64;
112 constexpr int kBitrateBps = 112 constexpr int kBitrateBps =
113 kTargetBitrateBps - 113 kTargetBitrateBps -
114 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs; 114 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
115 Controller::NetworkMetrics network_metrics; 115 Controller::NetworkMetrics network_metrics;
116 network_metrics.target_audio_bitrate_bps = 116 network_metrics.target_audio_bitrate_bps =
117 rtc::Optional<int>(kTargetBitrateBps); 117 rtc::Optional<int>(kTargetBitrateBps);
118 network_metrics.overhead_bytes_per_packet = 118 network_metrics.overhead_bytes_per_packet =
119 rtc::Optional<size_t>(kOverheadBytesPerPacket); 119 rtc::Optional<size_t>(kOverheadBytesPerPacket);
120 controller.UpdateNetworkMetrics(network_metrics); 120 controller.UpdateNetworkMetrics(network_metrics);
121 CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs), 121 CheckDecision(&controller, rtc::Optional<int>(kInitialFrameLengthMs),
122 kBitrateBps); 122 kBitrateBps);
123 } 123 }
124 124
125 TEST(AnaBitrateControllerTest, TreatUnknownFrameLengthAsFrameLengthUnchanged) { 125 TEST(AnaBitrateControllerTest, TreatUnknownFrameLengthAsFrameLengthUnchanged) {
126 test::ScopedFieldTrials override_field_trials( 126 test::ScopedFieldTrials override_field_trials(
127 "WebRTC-SendSideBwe-WithOverhead/Enabled/"); 127 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
128 constexpr int kInitialFrameLengthMs = 20; 128 constexpr int kInitialFrameLengthMs = 20;
129 BitrateController controller( 129 BitrateController controller(
130 BitrateController::Config(32000, kInitialFrameLengthMs)); 130 BitrateController::Config(32000, kInitialFrameLengthMs, 0, 0));
131 constexpr int kTargetBitrateBps = 48000; 131 constexpr int kTargetBitrateBps = 48000;
132 constexpr size_t kOverheadBytesPerPacket = 64; 132 constexpr size_t kOverheadBytesPerPacket = 64;
133 constexpr int kBitrateBps = 133 constexpr int kBitrateBps =
134 kTargetBitrateBps - 134 kTargetBitrateBps -
135 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs; 135 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
136 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps), 136 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
137 rtc::Optional<size_t>(kOverheadBytesPerPacket)); 137 rtc::Optional<size_t>(kOverheadBytesPerPacket));
138 CheckDecision(&controller, rtc::Optional<int>(), kBitrateBps); 138 CheckDecision(&controller, rtc::Optional<int>(), kBitrateBps);
139 } 139 }
140 140
141 TEST(AnaBitrateControllerTest, IncreaseBitrateOnFrameLengthIncreased) { 141 TEST(AnaBitrateControllerTest, IncreaseBitrateOnFrameLengthIncreased) {
142 test::ScopedFieldTrials override_field_trials( 142 test::ScopedFieldTrials override_field_trials(
143 "WebRTC-SendSideBwe-WithOverhead/Enabled/"); 143 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
144 constexpr int kInitialFrameLengthMs = 20; 144 constexpr int kInitialFrameLengthMs = 20;
145 BitrateController controller( 145 BitrateController controller(
146 BitrateController::Config(32000, kInitialFrameLengthMs)); 146 BitrateController::Config(32000, kInitialFrameLengthMs, 0, 0));
147 147
148 constexpr int kTargetBitrateBps = 48000; 148 constexpr int kTargetBitrateBps = 48000;
149 constexpr size_t kOverheadBytesPerPacket = 64; 149 constexpr size_t kOverheadBytesPerPacket = 64;
150 constexpr int kBitrateBps = 150 constexpr int kBitrateBps =
151 kTargetBitrateBps - 151 kTargetBitrateBps -
152 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs; 152 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
153 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps), 153 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
154 rtc::Optional<size_t>(kOverheadBytesPerPacket)); 154 rtc::Optional<size_t>(kOverheadBytesPerPacket));
155 CheckDecision(&controller, rtc::Optional<int>(), kBitrateBps); 155 CheckDecision(&controller, rtc::Optional<int>(), kBitrateBps);
156 156
157 constexpr int kFrameLengthMs = 60; 157 constexpr int kFrameLengthMs = 60;
158 constexpr size_t kPacketOverheadRateDiff = 158 constexpr size_t kPacketOverheadRateDiff =
159 kOverheadBytesPerPacket * 8 * 1000 / 20 - 159 kOverheadBytesPerPacket * 8 * 1000 / 20 -
160 kOverheadBytesPerPacket * 8 * 1000 / 60; 160 kOverheadBytesPerPacket * 8 * 1000 / 60;
161 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps), 161 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
162 rtc::Optional<size_t>(kOverheadBytesPerPacket)); 162 rtc::Optional<size_t>(kOverheadBytesPerPacket));
163 CheckDecision(&controller, rtc::Optional<int>(kFrameLengthMs), 163 CheckDecision(&controller, rtc::Optional<int>(kFrameLengthMs),
164 kBitrateBps + kPacketOverheadRateDiff); 164 kBitrateBps + kPacketOverheadRateDiff);
165 } 165 }
166 166
167 TEST(AnaBitrateControllerTest, DecreaseBitrateOnFrameLengthDecreased) { 167 TEST(AnaBitrateControllerTest, DecreaseBitrateOnFrameLengthDecreased) {
168 test::ScopedFieldTrials override_field_trials( 168 test::ScopedFieldTrials override_field_trials(
169 "WebRTC-SendSideBwe-WithOverhead/Enabled/"); 169 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
170 constexpr int kInitialFrameLengthMs = 60; 170 constexpr int kInitialFrameLengthMs = 60;
171 BitrateController controller( 171 BitrateController controller(
172 BitrateController::Config(32000, kInitialFrameLengthMs)); 172 BitrateController::Config(32000, kInitialFrameLengthMs, 0, 0));
173 173
174 constexpr int kTargetBitrateBps = 48000; 174 constexpr int kTargetBitrateBps = 48000;
175 constexpr size_t kOverheadBytesPerPacket = 64; 175 constexpr size_t kOverheadBytesPerPacket = 64;
176 constexpr int kBitrateBps = 176 constexpr int kBitrateBps =
177 kTargetBitrateBps - 177 kTargetBitrateBps -
178 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs; 178 kOverheadBytesPerPacket * 8 * 1000 / kInitialFrameLengthMs;
179 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps), 179 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
180 rtc::Optional<size_t>(kOverheadBytesPerPacket)); 180 rtc::Optional<size_t>(kOverheadBytesPerPacket));
181 CheckDecision(&controller, rtc::Optional<int>(), kBitrateBps); 181 CheckDecision(&controller, rtc::Optional<int>(), kBitrateBps);
182 182
183 constexpr int kFrameLengthMs = 20; 183 constexpr int kFrameLengthMs = 20;
184 constexpr size_t kPacketOverheadRateDiff = 184 constexpr size_t kPacketOverheadRateDiff =
185 kOverheadBytesPerPacket * 8 * 1000 / 20 - 185 kOverheadBytesPerPacket * 8 * 1000 / 20 -
186 kOverheadBytesPerPacket * 8 * 1000 / 60; 186 kOverheadBytesPerPacket * 8 * 1000 / 60;
187 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps), 187 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
188 rtc::Optional<size_t>(kOverheadBytesPerPacket)); 188 rtc::Optional<size_t>(kOverheadBytesPerPacket));
189 CheckDecision(&controller, rtc::Optional<int>(kFrameLengthMs), 189 CheckDecision(&controller, rtc::Optional<int>(kFrameLengthMs),
190 kBitrateBps - kPacketOverheadRateDiff); 190 kBitrateBps - kPacketOverheadRateDiff);
191 } 191 }
192 192
193 TEST(AnaBitrateControllerTest, BitrateNeverBecomesNegative) { 193 TEST(AnaBitrateControllerTest, BitrateNeverBecomesNegative) {
194 test::ScopedFieldTrials override_field_trials( 194 test::ScopedFieldTrials override_field_trials(
195 "WebRTC-SendSideBwe-WithOverhead/Enabled/"); 195 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
196 BitrateController controller(BitrateController::Config(32000, 20)); 196 BitrateController controller(BitrateController::Config(32000, 20, 0, 0));
197 constexpr size_t kOverheadBytesPerPacket = 64; 197 constexpr size_t kOverheadBytesPerPacket = 64;
198 constexpr int kFrameLengthMs = 60; 198 constexpr int kFrameLengthMs = 60;
199 // Set a target rate smaller than overhead rate, the bitrate is bounded by 0. 199 // Set a target rate smaller than overhead rate, the bitrate is bounded by 0.
200 constexpr int kTargetBitrateBps = 200 constexpr int kTargetBitrateBps =
201 kOverheadBytesPerPacket * 8 * 1000 / kFrameLengthMs - 1; 201 kOverheadBytesPerPacket * 8 * 1000 / kFrameLengthMs - 1;
202 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps), 202 UpdateNetworkMetrics(&controller, rtc::Optional<int>(kTargetBitrateBps),
203 rtc::Optional<size_t>(kOverheadBytesPerPacket)); 203 rtc::Optional<size_t>(kOverheadBytesPerPacket));
204 CheckDecision(&controller, rtc::Optional<int>(kFrameLengthMs), 0); 204 CheckDecision(&controller, rtc::Optional<int>(kFrameLengthMs), 0);
205 } 205 }
206 206
207 TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) { 207 TEST(AnaBitrateControllerTest, CheckBehaviorOnChangingCondition) {
208 test::ScopedFieldTrials override_field_trials( 208 test::ScopedFieldTrials override_field_trials(
209 "WebRTC-SendSideBwe-WithOverhead/Enabled/"); 209 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
210 BitrateController controller(BitrateController::Config(32000, 20)); 210 BitrateController controller(BitrateController::Config(32000, 20, 0, 0));
211 211
212 // Start from an arbitrary overall bitrate. 212 // Start from an arbitrary overall bitrate.
213 int overall_bitrate = 34567; 213 int overall_bitrate = 34567;
214 size_t overhead_bytes_per_packet = 64; 214 size_t overhead_bytes_per_packet = 64;
215 int frame_length_ms = 20; 215 int frame_length_ms = 20;
216 int current_bitrate = 216 int current_bitrate =
217 overall_bitrate - overhead_bytes_per_packet * 8 * 1000 / frame_length_ms; 217 overall_bitrate - overhead_bytes_per_packet * 8 * 1000 / frame_length_ms;
218 218
219 UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate), 219 UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
220 rtc::Optional<size_t>(overhead_bytes_per_packet)); 220 rtc::Optional<size_t>(overhead_bytes_per_packet));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 overhead_bytes_per_packet * 8 * 1000 / 60; 263 overhead_bytes_per_packet * 8 * 1000 / 60;
264 264
265 UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate), 265 UpdateNetworkMetrics(&controller, rtc::Optional<int>(overall_bitrate),
266 rtc::Optional<size_t>(overhead_bytes_per_packet)); 266 rtc::Optional<size_t>(overhead_bytes_per_packet));
267 CheckDecision(&controller, rtc::Optional<int>(frame_length_ms), 267 CheckDecision(&controller, rtc::Optional<int>(frame_length_ms),
268 current_bitrate); 268 current_bitrate);
269 } 269 }
270 270
271 } // namespace audio_network_adaptor 271 } // namespace audio_network_adaptor
272 } // namespace webrtc 272 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698