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

Side by Side Diff: webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller_unittest.cc

Issue 2703353002: Change frame length on very low bandwidth. (Closed)
Patch Set: Responsd to comments. Created 3 years, 10 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
11 #include <memory> 11 #include <memory>
12 #include <utility> 12 #include <utility>
13 13
14 #include "webrtc/modules/audio_coding/audio_network_adaptor/frame_length_control ler.h" 14 #include "webrtc/modules/audio_coding/audio_network_adaptor/frame_length_control ler.h"
15 #include "webrtc/test/gtest.h" 15 #include "webrtc/test/gtest.h"
16 16
17 namespace webrtc { 17 namespace webrtc {
18 18
19 namespace { 19 namespace {
20 20
21 constexpr float kFlIncreasingPacketLossFraction = 0.04f; 21 constexpr float kFlIncreasingPacketLossFraction = 0.04f;
22 constexpr float kFlDecreasingPacketLossFraction = 0.05f; 22 constexpr float kFlDecreasingPacketLossFraction = 0.05f;
23 constexpr int kMinEncoderBitrateBps = 6000;
24 constexpr int kPreventOveruseMarginBps = 5000;
25 constexpr size_t kOverheadBytesPerPacket = 20;
23 constexpr int kFl20msTo60msBandwidthBps = 40000; 26 constexpr int kFl20msTo60msBandwidthBps = 40000;
24 constexpr int kFl60msTo20msBandwidthBps = 50000; 27 constexpr int kFl60msTo20msBandwidthBps = 50000;
25 constexpr int kFl60msTo120msBandwidthBps = 30000; 28 constexpr int kFl60msTo120msBandwidthBps = 30000;
26 constexpr int kFl120msTo60msBandwidthBps = 40000; 29 constexpr int kFl120msTo60msBandwidthBps = 40000;
27 constexpr int kMediumBandwidthBps = 30 constexpr int kMediumBandwidthBps =
28 (kFl60msTo20msBandwidthBps + kFl20msTo60msBandwidthBps) / 2; 31 (kFl60msTo20msBandwidthBps + kFl20msTo60msBandwidthBps) / 2;
29 constexpr float kMediumPacketLossFraction = 32 constexpr float kMediumPacketLossFraction =
30 (kFlDecreasingPacketLossFraction + kFlIncreasingPacketLossFraction) / 2; 33 (kFlDecreasingPacketLossFraction + kFlIncreasingPacketLossFraction) / 2;
31 34
35 int VeryLowBitrate(int frame_length_ms) {
36 return kMinEncoderBitrateBps + kPreventOveruseMarginBps +
37 (kOverheadBytesPerPacket * 8 * 1000 / frame_length_ms);
38 }
39
32 std::unique_ptr<FrameLengthController> CreateController( 40 std::unique_ptr<FrameLengthController> CreateController(
33 const std::map<FrameLengthController::Config::FrameLengthChange, int>& 41 const std::map<FrameLengthController::Config::FrameLengthChange, int>&
34 frame_length_change_criteria, 42 frame_length_change_criteria,
35 const std::vector<int>& encoder_frame_lengths_ms, 43 const std::vector<int>& encoder_frame_lengths_ms,
36 int initial_frame_length_ms) { 44 int initial_frame_length_ms) {
37 std::unique_ptr<FrameLengthController> controller( 45 std::unique_ptr<FrameLengthController> controller(
38 new FrameLengthController(FrameLengthController::Config( 46 new FrameLengthController(FrameLengthController::Config(
39 encoder_frame_lengths_ms, initial_frame_length_ms, 47 encoder_frame_lengths_ms, initial_frame_length_ms,
40 kFlIncreasingPacketLossFraction, kFlDecreasingPacketLossFraction, 48 kMinEncoderBitrateBps, kFlIncreasingPacketLossFraction,
41 frame_length_change_criteria))); 49 kFlDecreasingPacketLossFraction, frame_length_change_criteria)));
42 50
43 return controller; 51 return controller;
44 } 52 }
45 53
46 std::map<FrameLengthController::Config::FrameLengthChange, int> 54 std::map<FrameLengthController::Config::FrameLengthChange, int>
47 CreateChangeCriteriaFor20msAnd60ms() { 55 CreateChangeCriteriaFor20msAnd60ms() {
48 return std::map<FrameLengthController::Config::FrameLengthChange, int>{ 56 return std::map<FrameLengthController::Config::FrameLengthChange, int>{
49 {FrameLengthController::Config::FrameLengthChange(20, 60), 57 {FrameLengthController::Config::FrameLengthChange(20, 60),
50 kFl20msTo60msBandwidthBps}, 58 kFl20msTo60msBandwidthBps},
51 {FrameLengthController::Config::FrameLengthChange(60, 20), 59 {FrameLengthController::Config::FrameLengthChange(60, 20),
52 kFl60msTo20msBandwidthBps}}; 60 kFl60msTo20msBandwidthBps}};
53 } 61 }
54 62
55 std::map<FrameLengthController::Config::FrameLengthChange, int> 63 std::map<FrameLengthController::Config::FrameLengthChange, int>
56 CreateChangeCriteriaFor20ms60msAnd120ms() { 64 CreateChangeCriteriaFor20ms60msAnd120ms() {
57 return std::map<FrameLengthController::Config::FrameLengthChange, int>{ 65 return std::map<FrameLengthController::Config::FrameLengthChange, int>{
58 {FrameLengthController::Config::FrameLengthChange(20, 60), 66 {FrameLengthController::Config::FrameLengthChange(20, 60),
59 kFl20msTo60msBandwidthBps}, 67 kFl20msTo60msBandwidthBps},
60 {FrameLengthController::Config::FrameLengthChange(60, 20), 68 {FrameLengthController::Config::FrameLengthChange(60, 20),
61 kFl60msTo20msBandwidthBps}, 69 kFl60msTo20msBandwidthBps},
62 {FrameLengthController::Config::FrameLengthChange(60, 120), 70 {FrameLengthController::Config::FrameLengthChange(60, 120),
63 kFl60msTo120msBandwidthBps}, 71 kFl60msTo120msBandwidthBps},
64 {FrameLengthController::Config::FrameLengthChange(120, 60), 72 {FrameLengthController::Config::FrameLengthChange(120, 60),
65 kFl120msTo60msBandwidthBps}}; 73 kFl120msTo60msBandwidthBps}};
66 } 74 }
67 75
68 void UpdateNetworkMetrics( 76 void UpdateNetworkMetrics(
69 FrameLengthController* controller, 77 FrameLengthController* controller,
70 const rtc::Optional<int>& uplink_bandwidth_bps, 78 const rtc::Optional<int>& uplink_bandwidth_bps,
71 const rtc::Optional<float>& uplink_packet_loss_fraction) { 79 const rtc::Optional<float>& uplink_packet_loss_fraction,
80 const rtc::Optional<size_t>& overhead_bytes_per_packet) {
72 // UpdateNetworkMetrics can accept multiple network metric updates at once. 81 // UpdateNetworkMetrics can accept multiple network metric updates at once.
73 // However, currently, the most used case is to update one metric at a time. 82 // However, currently, the most used case is to update one metric at a time.
74 // To reflect this fact, we separate the calls. 83 // To reflect this fact, we separate the calls.
75 if (uplink_bandwidth_bps) { 84 if (uplink_bandwidth_bps) {
76 Controller::NetworkMetrics network_metrics; 85 Controller::NetworkMetrics network_metrics;
77 network_metrics.uplink_bandwidth_bps = uplink_bandwidth_bps; 86 network_metrics.uplink_bandwidth_bps = uplink_bandwidth_bps;
78 controller->UpdateNetworkMetrics(network_metrics); 87 controller->UpdateNetworkMetrics(network_metrics);
79 } 88 }
80 if (uplink_packet_loss_fraction) { 89 if (uplink_packet_loss_fraction) {
81 Controller::NetworkMetrics network_metrics; 90 Controller::NetworkMetrics network_metrics;
82 network_metrics.uplink_packet_loss_fraction = uplink_packet_loss_fraction; 91 network_metrics.uplink_packet_loss_fraction = uplink_packet_loss_fraction;
83 controller->UpdateNetworkMetrics(network_metrics); 92 controller->UpdateNetworkMetrics(network_metrics);
84 } 93 }
94 if (overhead_bytes_per_packet) {
95 Controller::NetworkMetrics network_metrics;
96 network_metrics.overhead_bytes_per_packet = overhead_bytes_per_packet;
97 controller->UpdateNetworkMetrics(network_metrics);
98 }
85 } 99 }
86 100
87 void CheckDecision(FrameLengthController* controller, 101 void CheckDecision(FrameLengthController* controller,
88 const rtc::Optional<bool>& enable_fec, 102 const rtc::Optional<bool>& enable_fec,
89 int expected_frame_length_ms) { 103 int expected_frame_length_ms) {
90 AudioNetworkAdaptor::EncoderRuntimeConfig config; 104 AudioNetworkAdaptor::EncoderRuntimeConfig config;
91 config.enable_fec = enable_fec; 105 config.enable_fec = enable_fec;
92 controller->MakeDecision(&config); 106 controller->MakeDecision(&config);
93 EXPECT_EQ(rtc::Optional<int>(expected_frame_length_ms), 107 EXPECT_EQ(rtc::Optional<int>(expected_frame_length_ms),
94 config.frame_length_ms); 108 config.frame_length_ms);
95 } 109 }
96 110
97 } // namespace 111 } // namespace
98 112
99 TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkBandwidth) { 113 TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkBandwidth) {
100 auto controller = 114 auto controller =
101 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60); 115 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60);
102 UpdateNetworkMetrics(controller.get(), 116 UpdateNetworkMetrics(
103 rtc::Optional<int>(kFl60msTo20msBandwidthBps), 117 controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
104 rtc::Optional<float>()); 118 rtc::Optional<float>(), rtc::Optional<size_t>(kOverheadBytesPerPacket));
105 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); 119 CheckDecision(controller.get(), rtc::Optional<bool>(), 20);
106 } 120 }
107 121
108 TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkPacketLossFraction) { 122 TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkPacketLossFraction) {
109 auto controller = 123 auto controller =
110 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60); 124 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60);
111 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(), 125 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(),
112 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); 126 rtc::Optional<float>(kFlDecreasingPacketLossFraction),
127 rtc::Optional<size_t>(kOverheadBytesPerPacket));
113 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); 128 CheckDecision(controller.get(), rtc::Optional<bool>(), 20);
114 } 129 }
115 130
116 TEST(FrameLengthControllerTest, DecreaseTo20MsWhenFecIsOn) { 131 TEST(FrameLengthControllerTest, DecreaseTo20MsWhenFecIsOn) {
117 auto controller = 132 auto controller =
118 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60); 133 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60);
119 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20); 134 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20);
120 } 135 }
121 136
122 TEST(FrameLengthControllerTest, 137 TEST(FrameLengthControllerTest,
123 Maintain60MsIf20MsNotInReceiverFrameLengthRange) { 138 Maintain60MsIf20MsNotInReceiverFrameLengthRange) {
124 auto controller = 139 auto controller =
125 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {60}, 60); 140 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {60}, 60);
126 // Set FEC on that would cause frame length to decrease if receiver frame 141 // Set FEC on that would cause frame length to decrease if receiver frame
127 // length range included 20ms. 142 // length range included 20ms.
128 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60); 143 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60);
129 } 144 }
130 145
131 TEST(FrameLengthControllerTest, Maintain60MsOnMultipleConditions) { 146 TEST(FrameLengthControllerTest, Maintain60MsOnMultipleConditions) {
132 // Maintain 60ms frame length if 147 // Maintain 60ms frame length if
133 // 1. |uplink_bandwidth_bps| is at medium level, 148 // 1. |uplink_bandwidth_bps| is at medium level,
134 // 2. |uplink_packet_loss_fraction| is at medium, 149 // 2. |uplink_packet_loss_fraction| is at medium,
135 // 3. FEC is not decided ON. 150 // 3. FEC is not decided ON.
136 auto controller = 151 auto controller =
137 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60); 152 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60);
138 UpdateNetworkMetrics(controller.get(), 153 UpdateNetworkMetrics(controller.get(),
139 rtc::Optional<int>(kMediumBandwidthBps), 154 rtc::Optional<int>(kMediumBandwidthBps),
140 rtc::Optional<float>(kMediumPacketLossFraction)); 155 rtc::Optional<float>(kMediumPacketLossFraction),
156 rtc::Optional<size_t>(kOverheadBytesPerPacket));
141 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 157 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
142 } 158 }
143 159
144 TEST(FrameLengthControllerTest, IncreaseTo60MsOnMultipleConditions) { 160 TEST(FrameLengthControllerTest, IncreaseTo60MsOnMultipleConditions) {
145 // Increase to 60ms frame length if 161 // Increase to 60ms frame length if
146 // 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND 162 // 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND
147 // 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold 163 // 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold
148 // AND 164 // AND
149 // 3. FEC is not decided or OFF. 165 // 3. FEC is not decided or OFF.
150 auto controller = 166 auto controller =
151 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); 167 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20);
152 UpdateNetworkMetrics(controller.get(), 168 UpdateNetworkMetrics(controller.get(),
153 rtc::Optional<int>(kFl20msTo60msBandwidthBps), 169 rtc::Optional<int>(kFl20msTo60msBandwidthBps),
154 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 170 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
171 rtc::Optional<size_t>(kOverheadBytesPerPacket));
155 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 172 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
156 } 173 }
157 174
175 TEST(FrameLengthControllerTest, IncreaseTo60MsOnVeryLowUplinkBandwidth) {
176 auto controller =
177 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20);
178 // We set packet loss fraction to kFlDecreasingPacketLossFraction, and FEC on,
179 // both of which should have prevented frame length to increase, if the uplink
180 // bandwidth was not this low.
181 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(VeryLowBitrate(20)),
182 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
183 rtc::Optional<size_t>(kOverheadBytesPerPacket));
184 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60);
185 }
186
187 TEST(FrameLengthControllerTest, Maintain60MsOnVeryLowUplinkBandwidth) {
188 auto controller =
189 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60);
190 // We set packet loss fraction to FlDecreasingPacketLossFraction, and FEC on,
191 // both of which should have caused the frame length to decrease, if the
192 // uplink bandwidth was not this low.
193 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(VeryLowBitrate(20)),
194 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
195 rtc::Optional<size_t>(kOverheadBytesPerPacket));
196 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60);
197 }
198
158 TEST(FrameLengthControllerTest, UpdateMultipleNetworkMetricsAtOnce) { 199 TEST(FrameLengthControllerTest, UpdateMultipleNetworkMetricsAtOnce) {
159 // This test is similar to IncreaseTo60MsOnMultipleConditions. But instead of 200 // This test is similar to IncreaseTo60MsOnMultipleConditions. But instead of
160 // using ::UpdateNetworkMetrics(...), which calls 201 // using ::UpdateNetworkMetrics(...), which calls
161 // FrameLengthController::UpdateNetworkMetrics(...) multiple times, we 202 // FrameLengthController::UpdateNetworkMetrics(...) multiple times, we
162 // we call it only once. This is to verify that 203 // we call it only once. This is to verify that
163 // FrameLengthController::UpdateNetworkMetrics(...) can handle multiple 204 // FrameLengthController::UpdateNetworkMetrics(...) can handle multiple
164 // network updates at once. This is, however, not a common use case in current 205 // network updates at once. This is, however, not a common use case in current
165 // audio_network_adaptor_impl.cc. 206 // audio_network_adaptor_impl.cc.
166 auto controller = 207 auto controller =
167 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); 208 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20);
168 Controller::NetworkMetrics network_metrics; 209 Controller::NetworkMetrics network_metrics;
169 network_metrics.uplink_bandwidth_bps = 210 network_metrics.uplink_bandwidth_bps =
170 rtc::Optional<int>(kFl20msTo60msBandwidthBps); 211 rtc::Optional<int>(kFl20msTo60msBandwidthBps);
171 network_metrics.uplink_packet_loss_fraction = 212 network_metrics.uplink_packet_loss_fraction =
172 rtc::Optional<float>(kFlIncreasingPacketLossFraction); 213 rtc::Optional<float>(kFlIncreasingPacketLossFraction);
173 controller->UpdateNetworkMetrics(network_metrics); 214 controller->UpdateNetworkMetrics(network_metrics);
174 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 215 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
175 } 216 }
176 217
177 TEST(FrameLengthControllerTest, 218 TEST(FrameLengthControllerTest,
178 Maintain20MsIf60MsNotInReceiverFrameLengthRange) { 219 Maintain20MsIf60MsNotInReceiverFrameLengthRange) {
179 auto controller = 220 auto controller =
180 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20}, 20); 221 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20}, 20);
181 // Use a low uplink bandwidth and a low uplink packet loss fraction that would 222 // Use a low uplink bandwidth and a low uplink packet loss fraction that would
182 // cause frame length to increase if receiver frame length included 60ms. 223 // cause frame length to increase if receiver frame length included 60ms.
183 UpdateNetworkMetrics(controller.get(), 224 UpdateNetworkMetrics(controller.get(),
184 rtc::Optional<int>(kFl20msTo60msBandwidthBps), 225 rtc::Optional<int>(kFl20msTo60msBandwidthBps),
185 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 226 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
227 rtc::Optional<size_t>(kOverheadBytesPerPacket));
186 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); 228 CheckDecision(controller.get(), rtc::Optional<bool>(), 20);
187 } 229 }
188 230
189 TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkBandwidth) { 231 TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkBandwidth) {
190 auto controller = 232 auto controller =
191 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); 233 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20);
192 UpdateNetworkMetrics(controller.get(), 234 UpdateNetworkMetrics(controller.get(),
193 rtc::Optional<int>(kMediumBandwidthBps), 235 rtc::Optional<int>(kMediumBandwidthBps),
194 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 236 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
237 rtc::Optional<size_t>(kOverheadBytesPerPacket));
195 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); 238 CheckDecision(controller.get(), rtc::Optional<bool>(), 20);
196 } 239 }
197 240
198 TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkPacketLossFraction) { 241 TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkPacketLossFraction) {
199 auto controller = 242 auto controller =
200 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); 243 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20);
201 // Use a low uplink bandwidth that would cause frame length to increase if 244 // Use a low uplink bandwidth that would cause frame length to increase if
202 // uplink packet loss fraction was low. 245 // uplink packet loss fraction was low.
203 UpdateNetworkMetrics(controller.get(), 246 UpdateNetworkMetrics(controller.get(),
204 rtc::Optional<int>(kFl20msTo60msBandwidthBps), 247 rtc::Optional<int>(kFl20msTo60msBandwidthBps),
205 rtc::Optional<float>(kMediumPacketLossFraction)); 248 rtc::Optional<float>(kMediumPacketLossFraction),
249 rtc::Optional<size_t>(kOverheadBytesPerPacket));
206 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); 250 CheckDecision(controller.get(), rtc::Optional<bool>(), 20);
207 } 251 }
208 252
209 TEST(FrameLengthControllerTest, Maintain20MsWhenFecIsOn) { 253 TEST(FrameLengthControllerTest, Maintain20MsWhenFecIsOn) {
210 auto controller = 254 auto controller =
211 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); 255 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20);
212 // Use a low uplink bandwidth and a low uplink packet loss fraction that would 256 // Use a low uplink bandwidth and a low uplink packet loss fraction that would
213 // cause frame length to increase if FEC was not ON. 257 // cause frame length to increase if FEC was not ON.
214 UpdateNetworkMetrics(controller.get(), 258 UpdateNetworkMetrics(controller.get(),
215 rtc::Optional<int>(kFl20msTo60msBandwidthBps), 259 rtc::Optional<int>(kFl20msTo60msBandwidthBps),
216 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 260 rtc::Optional<float>(kMediumPacketLossFraction),
261 rtc::Optional<size_t>(kOverheadBytesPerPacket));
217 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20); 262 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20);
218 } 263 }
219 264
220 TEST(FrameLengthControllerTest, Maintain60MsWhenNo120msCriteriaIsSet) { 265 TEST(FrameLengthControllerTest, Maintain60MsWhenNo120msCriteriaIsSet) {
221 auto controller = 266 auto controller =
222 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60, 120}, 60); 267 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60, 120}, 60);
223 UpdateNetworkMetrics(controller.get(), 268 UpdateNetworkMetrics(controller.get(),
224 rtc::Optional<int>(kFl60msTo120msBandwidthBps), 269 rtc::Optional<int>(kFl60msTo120msBandwidthBps),
225 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 270 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
271 rtc::Optional<size_t>(kOverheadBytesPerPacket));
226 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 272 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
227 } 273 }
228 274
229 TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkBandwidth) { 275 TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkBandwidth) {
230 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), 276 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
231 {20, 60, 120}, 120); 277 {20, 60, 120}, 120);
232 // It takes two steps for frame length to go from 120ms to 20ms. 278 // It takes two steps for frame length to go from 120ms to 20ms.
233 UpdateNetworkMetrics(controller.get(), 279 UpdateNetworkMetrics(
234 rtc::Optional<int>(kFl60msTo20msBandwidthBps), 280 controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
235 rtc::Optional<float>()); 281 rtc::Optional<float>(), rtc::Optional<size_t>(kOverheadBytesPerPacket));
236 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 282 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
237 283
238 UpdateNetworkMetrics(controller.get(), 284 UpdateNetworkMetrics(
239 rtc::Optional<int>(kFl60msTo20msBandwidthBps), 285 controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
240 rtc::Optional<float>()); 286 rtc::Optional<float>(), rtc::Optional<size_t>(kOverheadBytesPerPacket));
241 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); 287 CheckDecision(controller.get(), rtc::Optional<bool>(), 20);
242 } 288 }
243 289
244 TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkPacketLossFraction) { 290 TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkPacketLossFraction) {
245 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), 291 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
246 {20, 60, 120}, 120); 292 {20, 60, 120}, 120);
247 // It takes two steps for frame length to go from 120ms to 20ms. 293 // It takes two steps for frame length to go from 120ms to 20ms.
248 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(), 294 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(),
249 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); 295 rtc::Optional<float>(kFlDecreasingPacketLossFraction),
296 rtc::Optional<size_t>(kOverheadBytesPerPacket));
250 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 297 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
251 298
252 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(), 299 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(),
253 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); 300 rtc::Optional<float>(kFlDecreasingPacketLossFraction),
301 rtc::Optional<size_t>(kOverheadBytesPerPacket));
254 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); 302 CheckDecision(controller.get(), rtc::Optional<bool>(), 20);
255 } 303 }
256 304
257 TEST(FrameLengthControllerTest, From120MsTo20MsWhenFecIsOn) { 305 TEST(FrameLengthControllerTest, From120MsTo20MsWhenFecIsOn) {
258 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), 306 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
259 {20, 60, 120}, 120); 307 {20, 60, 120}, 120);
260 // It takes two steps for frame length to go from 120ms to 20ms. 308 // It takes two steps for frame length to go from 120ms to 20ms.
261 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60); 309 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60);
262 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20); 310 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20);
263 } 311 }
264 312
313 TEST(FrameLengthControllerTest, Maintain120MsOnVeryLowUplinkBandwidth) {
314 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
315 {20, 60, 120}, 120);
316 // We set packet loss fraction to FlDecreasingPacketLossFraction, and FEC on,
317 // both of which should have caused the frame length to decrease, if the
318 // uplink bandwidth was not this low.
319 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(VeryLowBitrate(60)),
320 rtc::Optional<float>(kFlDecreasingPacketLossFraction),
321 rtc::Optional<size_t>(kOverheadBytesPerPacket));
322 CheckDecision(controller.get(), rtc::Optional<bool>(true), 120);
323 }
324
325 TEST(FrameLengthControllerTest, From60MsTo120MsOnVeryLowUplinkBandwidth) {
326 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
327 {20, 60, 120}, 60);
328 // We set packet loss fraction to FlDecreasingPacketLossFraction, and FEC on,
329 // both of which should have prevented frame length to increase, if the uplink
330 // bandwidth was not this low.
331 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(VeryLowBitrate(60)),
332 rtc::Optional<float>(kFlDecreasingPacketLossFraction),
333 rtc::Optional<size_t>(kOverheadBytesPerPacket));
334 CheckDecision(controller.get(), rtc::Optional<bool>(true), 120);
335 }
336
265 TEST(FrameLengthControllerTest, From20MsTo120MsOnMultipleConditions) { 337 TEST(FrameLengthControllerTest, From20MsTo120MsOnMultipleConditions) {
266 // Increase to 120ms frame length if 338 // Increase to 120ms frame length if
267 // 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND 339 // 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND
268 // 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold 340 // 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold
269 // AND 341 // AND
270 // 3. FEC is not decided or OFF. 342 // 3. FEC is not decided or OFF.
271 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), 343 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
272 {20, 60, 120}, 20); 344 {20, 60, 120}, 20);
273 // It takes two steps for frame length to go from 20ms to 120ms. 345 // It takes two steps for frame length to go from 20ms to 120ms.
274 UpdateNetworkMetrics(controller.get(), 346 UpdateNetworkMetrics(controller.get(),
275 rtc::Optional<int>(kFl60msTo120msBandwidthBps), 347 rtc::Optional<int>(kFl60msTo120msBandwidthBps),
276 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 348 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
349 rtc::Optional<size_t>(kOverheadBytesPerPacket));
277 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 350 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
278 UpdateNetworkMetrics(controller.get(), 351 UpdateNetworkMetrics(controller.get(),
279 rtc::Optional<int>(kFl60msTo120msBandwidthBps), 352 rtc::Optional<int>(kFl60msTo120msBandwidthBps),
280 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 353 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
354 rtc::Optional<size_t>(kOverheadBytesPerPacket));
281 CheckDecision(controller.get(), rtc::Optional<bool>(), 120); 355 CheckDecision(controller.get(), rtc::Optional<bool>(), 120);
282 } 356 }
283 357
284 TEST(FrameLengthControllerTest, Stall60MsIf120MsNotInReceiverFrameLengthRange) { 358 TEST(FrameLengthControllerTest, Stall60MsIf120MsNotInReceiverFrameLengthRange) {
285 auto controller = 359 auto controller =
286 CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), {20, 60}, 20); 360 CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), {20, 60}, 20);
287 UpdateNetworkMetrics(controller.get(), 361 UpdateNetworkMetrics(controller.get(),
288 rtc::Optional<int>(kFl60msTo120msBandwidthBps), 362 rtc::Optional<int>(kFl60msTo120msBandwidthBps),
289 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 363 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
364 rtc::Optional<size_t>(kOverheadBytesPerPacket));
290 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 365 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
291 UpdateNetworkMetrics(controller.get(), 366 UpdateNetworkMetrics(controller.get(),
292 rtc::Optional<int>(kFl60msTo120msBandwidthBps), 367 rtc::Optional<int>(kFl60msTo120msBandwidthBps),
293 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 368 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
369 rtc::Optional<size_t>(kOverheadBytesPerPacket));
294 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 370 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
295 } 371 }
296 372
297 TEST(FrameLengthControllerTest, CheckBehaviorOnChangingNetworkMetrics) { 373 TEST(FrameLengthControllerTest, CheckBehaviorOnChangingNetworkMetrics) {
298 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), 374 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(),
299 {20, 60, 120}, 20); 375 {20, 60, 120}, 20);
300 UpdateNetworkMetrics(controller.get(), 376 UpdateNetworkMetrics(controller.get(),
301 rtc::Optional<int>(kMediumBandwidthBps), 377 rtc::Optional<int>(kMediumBandwidthBps),
302 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 378 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
379 rtc::Optional<size_t>(kOverheadBytesPerPacket));
303 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); 380 CheckDecision(controller.get(), rtc::Optional<bool>(), 20);
304 381
305 UpdateNetworkMetrics(controller.get(), 382 UpdateNetworkMetrics(controller.get(),
306 rtc::Optional<int>(kFl20msTo60msBandwidthBps), 383 rtc::Optional<int>(kFl20msTo60msBandwidthBps),
307 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 384 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
385 rtc::Optional<size_t>(kOverheadBytesPerPacket));
308 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 386 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
309 387
310 UpdateNetworkMetrics(controller.get(), 388 UpdateNetworkMetrics(controller.get(),
311 rtc::Optional<int>(kFl60msTo120msBandwidthBps), 389 rtc::Optional<int>(kFl60msTo120msBandwidthBps),
312 rtc::Optional<float>(kMediumPacketLossFraction)); 390 rtc::Optional<float>(kMediumPacketLossFraction),
391 rtc::Optional<size_t>(kOverheadBytesPerPacket));
313 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 392 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
314 393
315 UpdateNetworkMetrics(controller.get(), 394 UpdateNetworkMetrics(controller.get(),
316 rtc::Optional<int>(kFl60msTo120msBandwidthBps), 395 rtc::Optional<int>(kFl60msTo120msBandwidthBps),
317 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 396 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
397 rtc::Optional<size_t>(kOverheadBytesPerPacket));
318 CheckDecision(controller.get(), rtc::Optional<bool>(), 120); 398 CheckDecision(controller.get(), rtc::Optional<bool>(), 120);
319 399
320 UpdateNetworkMetrics(controller.get(), 400 UpdateNetworkMetrics(controller.get(),
321 rtc::Optional<int>(kFl120msTo60msBandwidthBps), 401 rtc::Optional<int>(kFl120msTo60msBandwidthBps),
322 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); 402 rtc::Optional<float>(kFlIncreasingPacketLossFraction),
403 rtc::Optional<size_t>(kOverheadBytesPerPacket));
323 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); 404 CheckDecision(controller.get(), rtc::Optional<bool>(), 60);
324 405
325 UpdateNetworkMetrics(controller.get(), 406 UpdateNetworkMetrics(controller.get(),
326 rtc::Optional<int>(kMediumBandwidthBps), 407 rtc::Optional<int>(kMediumBandwidthBps),
327 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); 408 rtc::Optional<float>(kFlDecreasingPacketLossFraction),
409 rtc::Optional<size_t>(kOverheadBytesPerPacket));
328 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); 410 CheckDecision(controller.get(), rtc::Optional<bool>(), 20);
329 } 411 }
330 412
331 } // namespace webrtc 413 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698