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 <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 kFl20msTo60msBandwidthBps = 22000; | 23 constexpr int kFl20msTo60msBandwidthBps = 40000; |
24 constexpr int kFl60msTo20msBandwidthBps = 88000; | 24 constexpr int kFl60msTo20msBandwidthBps = 50000; |
| 25 constexpr int kFl60msTo120msBandwidthBps = 30000; |
| 26 constexpr int kFl120msTo60msBandwidthBps = 40000; |
25 constexpr int kMediumBandwidthBps = | 27 constexpr int kMediumBandwidthBps = |
26 (kFl60msTo20msBandwidthBps + kFl20msTo60msBandwidthBps) / 2; | 28 (kFl60msTo20msBandwidthBps + kFl20msTo60msBandwidthBps) / 2; |
27 constexpr float kMediumPacketLossFraction = | 29 constexpr float kMediumPacketLossFraction = |
28 (kFlDecreasingPacketLossFraction + kFlIncreasingPacketLossFraction) / 2; | 30 (kFlDecreasingPacketLossFraction + kFlIncreasingPacketLossFraction) / 2; |
29 | 31 |
30 std::unique_ptr<FrameLengthController> CreateController( | 32 std::unique_ptr<FrameLengthController> CreateController( |
| 33 const std::map<FrameLengthController::Config::FrameLengthChange, int>& |
| 34 frame_length_change_criteria, |
31 const std::vector<int>& encoder_frame_lengths_ms, | 35 const std::vector<int>& encoder_frame_lengths_ms, |
32 int initial_frame_length_ms) { | 36 int initial_frame_length_ms) { |
33 std::unique_ptr<FrameLengthController> controller( | 37 std::unique_ptr<FrameLengthController> controller( |
34 new FrameLengthController(FrameLengthController::Config( | 38 new FrameLengthController(FrameLengthController::Config( |
35 encoder_frame_lengths_ms, initial_frame_length_ms, | 39 encoder_frame_lengths_ms, initial_frame_length_ms, |
36 kFlIncreasingPacketLossFraction, kFlDecreasingPacketLossFraction, | 40 kFlIncreasingPacketLossFraction, kFlDecreasingPacketLossFraction, |
37 kFl20msTo60msBandwidthBps, kFl60msTo20msBandwidthBps))); | 41 frame_length_change_criteria))); |
| 42 |
38 return controller; | 43 return controller; |
39 } | 44 } |
40 | 45 |
| 46 std::map<FrameLengthController::Config::FrameLengthChange, int> |
| 47 CreateChangeCriteriaFor20msAnd60ms() { |
| 48 return std::map<FrameLengthController::Config::FrameLengthChange, int>{ |
| 49 {FrameLengthController::Config::FrameLengthChange(20, 60), |
| 50 kFl20msTo60msBandwidthBps}, |
| 51 {FrameLengthController::Config::FrameLengthChange(60, 20), |
| 52 kFl60msTo20msBandwidthBps}}; |
| 53 } |
| 54 |
| 55 std::map<FrameLengthController::Config::FrameLengthChange, int> |
| 56 CreateChangeCriteriaFor20ms60msAnd120ms() { |
| 57 return std::map<FrameLengthController::Config::FrameLengthChange, int>{ |
| 58 {FrameLengthController::Config::FrameLengthChange(20, 60), |
| 59 kFl20msTo60msBandwidthBps}, |
| 60 {FrameLengthController::Config::FrameLengthChange(60, 20), |
| 61 kFl60msTo20msBandwidthBps}, |
| 62 {FrameLengthController::Config::FrameLengthChange(60, 120), |
| 63 kFl60msTo120msBandwidthBps}, |
| 64 {FrameLengthController::Config::FrameLengthChange(120, 60), |
| 65 kFl120msTo60msBandwidthBps}}; |
| 66 } |
| 67 |
41 void UpdateNetworkMetrics( | 68 void UpdateNetworkMetrics( |
42 FrameLengthController* controller, | 69 FrameLengthController* controller, |
43 const rtc::Optional<int>& uplink_bandwidth_bps, | 70 const rtc::Optional<int>& uplink_bandwidth_bps, |
44 const rtc::Optional<float>& uplink_packet_loss_fraction) { | 71 const rtc::Optional<float>& uplink_packet_loss_fraction) { |
45 // UpdateNetworkMetrics can accept multiple network metric updates at once. | 72 // UpdateNetworkMetrics can accept multiple network metric updates at once. |
46 // However, currently, the most used case is to update one metric at a time. | 73 // However, currently, the most used case is to update one metric at a time. |
47 // To reflect this fact, we separate the calls. | 74 // To reflect this fact, we separate the calls. |
48 if (uplink_bandwidth_bps) { | 75 if (uplink_bandwidth_bps) { |
49 Controller::NetworkMetrics network_metrics; | 76 Controller::NetworkMetrics network_metrics; |
50 network_metrics.uplink_bandwidth_bps = uplink_bandwidth_bps; | 77 network_metrics.uplink_bandwidth_bps = uplink_bandwidth_bps; |
(...skipping 12 matching lines...) Expand all Loading... |
63 AudioNetworkAdaptor::EncoderRuntimeConfig config; | 90 AudioNetworkAdaptor::EncoderRuntimeConfig config; |
64 config.enable_fec = enable_fec; | 91 config.enable_fec = enable_fec; |
65 controller->MakeDecision(&config); | 92 controller->MakeDecision(&config); |
66 EXPECT_EQ(rtc::Optional<int>(expected_frame_length_ms), | 93 EXPECT_EQ(rtc::Optional<int>(expected_frame_length_ms), |
67 config.frame_length_ms); | 94 config.frame_length_ms); |
68 } | 95 } |
69 | 96 |
70 } // namespace | 97 } // namespace |
71 | 98 |
72 TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkBandwidth) { | 99 TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkBandwidth) { |
73 auto controller = CreateController({20, 60}, 60); | 100 auto controller = |
| 101 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60); |
74 UpdateNetworkMetrics(controller.get(), | 102 UpdateNetworkMetrics(controller.get(), |
75 rtc::Optional<int>(kFl60msTo20msBandwidthBps), | 103 rtc::Optional<int>(kFl60msTo20msBandwidthBps), |
76 rtc::Optional<float>()); | 104 rtc::Optional<float>()); |
77 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); | 105 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); |
78 } | 106 } |
79 | 107 |
80 TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkPacketLossFraction) { | 108 TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkPacketLossFraction) { |
81 auto controller = CreateController({20, 60}, 60); | 109 auto controller = |
| 110 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60); |
82 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(), | 111 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(), |
83 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); | 112 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); |
84 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); | 113 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); |
85 } | 114 } |
86 | 115 |
87 TEST(FrameLengthControllerTest, DecreaseTo20MsWhenFecIsOn) { | 116 TEST(FrameLengthControllerTest, DecreaseTo20MsWhenFecIsOn) { |
88 auto controller = CreateController({20, 60}, 60); | 117 auto controller = |
| 118 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60); |
89 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20); | 119 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20); |
90 } | 120 } |
91 | 121 |
92 TEST(FrameLengthControllerTest, | 122 TEST(FrameLengthControllerTest, |
93 Maintain60MsIf20MsNotInReceiverFrameLengthRange) { | 123 Maintain60MsIf20MsNotInReceiverFrameLengthRange) { |
94 auto controller = CreateController({60}, 60); | 124 auto controller = |
| 125 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {60}, 60); |
95 // Set FEC on that would cause frame length to decrease if receiver frame | 126 // Set FEC on that would cause frame length to decrease if receiver frame |
96 // length range included 20ms. | 127 // length range included 20ms. |
97 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60); | 128 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60); |
98 } | 129 } |
99 | 130 |
100 TEST(FrameLengthControllerTest, Maintain60MsOnMultipleConditions) { | 131 TEST(FrameLengthControllerTest, Maintain60MsOnMultipleConditions) { |
101 // Maintain 60ms frame length if | 132 // Maintain 60ms frame length if |
102 // 1. |uplink_bandwidth_bps| is at medium level, | 133 // 1. |uplink_bandwidth_bps| is at medium level, |
103 // 2. |uplink_packet_loss_fraction| is at medium, | 134 // 2. |uplink_packet_loss_fraction| is at medium, |
104 // 3. FEC is not decided ON. | 135 // 3. FEC is not decided ON. |
105 auto controller = CreateController({20, 60}, 60); | 136 auto controller = |
| 137 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 60); |
106 UpdateNetworkMetrics(controller.get(), | 138 UpdateNetworkMetrics(controller.get(), |
107 rtc::Optional<int>(kMediumBandwidthBps), | 139 rtc::Optional<int>(kMediumBandwidthBps), |
108 rtc::Optional<float>(kMediumPacketLossFraction)); | 140 rtc::Optional<float>(kMediumPacketLossFraction)); |
109 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 141 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
110 } | 142 } |
111 | 143 |
112 TEST(FrameLengthControllerTest, IncreaseTo60MsOnMultipleConditions) { | 144 TEST(FrameLengthControllerTest, IncreaseTo60MsOnMultipleConditions) { |
113 // Increase to 60ms frame length if | 145 // Increase to 60ms frame length if |
114 // 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND | 146 // 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND |
115 // 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold | 147 // 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold |
116 // AND | 148 // AND |
117 // 3. FEC is not decided or OFF. | 149 // 3. FEC is not decided or OFF. |
118 auto controller = CreateController({20, 60}, 20); | 150 auto controller = |
| 151 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); |
119 UpdateNetworkMetrics(controller.get(), | 152 UpdateNetworkMetrics(controller.get(), |
120 rtc::Optional<int>(kFl20msTo60msBandwidthBps), | 153 rtc::Optional<int>(kFl20msTo60msBandwidthBps), |
121 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 154 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
122 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 155 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
123 } | 156 } |
124 | 157 |
125 TEST(FrameLengthControllerTest, UpdateMultipleNetworkMetricsAtOnce) { | 158 TEST(FrameLengthControllerTest, UpdateMultipleNetworkMetricsAtOnce) { |
126 // This test is similar to IncreaseTo60MsOnMultipleConditions. But instead of | 159 // This test is similar to IncreaseTo60MsOnMultipleConditions. But instead of |
127 // using ::UpdateNetworkMetrics(...), which calls | 160 // using ::UpdateNetworkMetrics(...), which calls |
128 // FrameLengthController::UpdateNetworkMetrics(...) multiple times, we | 161 // FrameLengthController::UpdateNetworkMetrics(...) multiple times, we |
129 // we call it only once. This is to verify that | 162 // we call it only once. This is to verify that |
130 // FrameLengthController::UpdateNetworkMetrics(...) can handle multiple | 163 // FrameLengthController::UpdateNetworkMetrics(...) can handle multiple |
131 // network updates at once. This is, however, not a common use case in current | 164 // network updates at once. This is, however, not a common use case in current |
132 // audio_network_adaptor_impl.cc. | 165 // audio_network_adaptor_impl.cc. |
133 auto controller = CreateController({20, 60}, 20); | 166 auto controller = |
| 167 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); |
134 Controller::NetworkMetrics network_metrics; | 168 Controller::NetworkMetrics network_metrics; |
135 network_metrics.uplink_bandwidth_bps = | 169 network_metrics.uplink_bandwidth_bps = |
136 rtc::Optional<int>(kFl20msTo60msBandwidthBps); | 170 rtc::Optional<int>(kFl20msTo60msBandwidthBps); |
137 network_metrics.uplink_packet_loss_fraction = | 171 network_metrics.uplink_packet_loss_fraction = |
138 rtc::Optional<float>(kFlIncreasingPacketLossFraction); | 172 rtc::Optional<float>(kFlIncreasingPacketLossFraction); |
139 controller->UpdateNetworkMetrics(network_metrics); | 173 controller->UpdateNetworkMetrics(network_metrics); |
140 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 174 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
141 } | 175 } |
142 | 176 |
143 TEST(FrameLengthControllerTest, | 177 TEST(FrameLengthControllerTest, |
144 Maintain20MsIf60MsNotInReceiverFrameLengthRange) { | 178 Maintain20MsIf60MsNotInReceiverFrameLengthRange) { |
145 auto controller = CreateController({20}, 20); | 179 auto controller = |
| 180 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20}, 20); |
146 // Use a low uplink bandwidth and a low uplink packet loss fraction that would | 181 // Use a low uplink bandwidth and a low uplink packet loss fraction that would |
147 // cause frame length to increase if receiver frame length included 60ms. | 182 // cause frame length to increase if receiver frame length included 60ms. |
148 UpdateNetworkMetrics(controller.get(), | 183 UpdateNetworkMetrics(controller.get(), |
149 rtc::Optional<int>(kFl20msTo60msBandwidthBps), | 184 rtc::Optional<int>(kFl20msTo60msBandwidthBps), |
150 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 185 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
151 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); | 186 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); |
152 } | 187 } |
153 | 188 |
154 TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkBandwidth) { | 189 TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkBandwidth) { |
155 auto controller = CreateController({20, 60}, 20); | 190 auto controller = |
| 191 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); |
156 UpdateNetworkMetrics(controller.get(), | 192 UpdateNetworkMetrics(controller.get(), |
157 rtc::Optional<int>(kMediumBandwidthBps), | 193 rtc::Optional<int>(kMediumBandwidthBps), |
158 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 194 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
159 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); | 195 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); |
160 } | 196 } |
161 | 197 |
162 TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkPacketLossFraction) { | 198 TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkPacketLossFraction) { |
163 auto controller = CreateController({20, 60}, 20); | 199 auto controller = |
| 200 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); |
164 // Use a low uplink bandwidth that would cause frame length to increase if | 201 // Use a low uplink bandwidth that would cause frame length to increase if |
165 // uplink packet loss fraction was low. | 202 // uplink packet loss fraction was low. |
166 UpdateNetworkMetrics(controller.get(), | 203 UpdateNetworkMetrics(controller.get(), |
167 rtc::Optional<int>(kFl20msTo60msBandwidthBps), | 204 rtc::Optional<int>(kFl20msTo60msBandwidthBps), |
168 rtc::Optional<float>(kMediumPacketLossFraction)); | 205 rtc::Optional<float>(kMediumPacketLossFraction)); |
169 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); | 206 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); |
170 } | 207 } |
171 | 208 |
172 TEST(FrameLengthControllerTest, Maintain20MsWhenFecIsOn) { | 209 TEST(FrameLengthControllerTest, Maintain20MsWhenFecIsOn) { |
173 auto controller = CreateController({20, 60}, 20); | 210 auto controller = |
| 211 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60}, 20); |
174 // Use a low uplink bandwidth and a low uplink packet loss fraction that would | 212 // Use a low uplink bandwidth and a low uplink packet loss fraction that would |
175 // cause frame length to increase if FEC was not ON. | 213 // cause frame length to increase if FEC was not ON. |
176 UpdateNetworkMetrics(controller.get(), | 214 UpdateNetworkMetrics(controller.get(), |
177 rtc::Optional<int>(kFl20msTo60msBandwidthBps), | 215 rtc::Optional<int>(kFl20msTo60msBandwidthBps), |
178 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 216 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
179 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20); | 217 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20); |
180 } | 218 } |
181 | 219 |
182 namespace { | 220 TEST(FrameLengthControllerTest, Maintain60MsWhenNo120msCriteriaIsSet) { |
183 constexpr int kFl60msTo120msBandwidthBps = 18000; | 221 auto controller = |
184 constexpr int kFl120msTo60msBandwidthBps = 72000; | 222 CreateController(CreateChangeCriteriaFor20msAnd60ms(), {20, 60, 120}, 60); |
| 223 UpdateNetworkMetrics(controller.get(), |
| 224 rtc::Optional<int>(kFl60msTo120msBandwidthBps), |
| 225 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
| 226 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
185 } | 227 } |
186 | 228 |
187 class FrameLengthControllerForTest { | |
188 public: | |
189 // This class is to test multiple frame lengths. FrameLengthController is | |
190 // implemented to support this, but is not enabled for the default constructor | |
191 // for the time being. We use this class to test it. | |
192 FrameLengthControllerForTest(const std::vector<int>& encoder_frame_lengths_ms, | |
193 int initial_frame_length_ms) | |
194 : frame_length_controller_( | |
195 FrameLengthController::Config(encoder_frame_lengths_ms, | |
196 initial_frame_length_ms, | |
197 kFlIncreasingPacketLossFraction, | |
198 kFlDecreasingPacketLossFraction, | |
199 kFl20msTo60msBandwidthBps, | |
200 kFl60msTo20msBandwidthBps)) { | |
201 frame_length_controller_.frame_length_change_criteria_.insert( | |
202 std::make_pair(FrameLengthController::FrameLengthChange(60, 120), | |
203 kFl60msTo120msBandwidthBps)); | |
204 frame_length_controller_.frame_length_change_criteria_.insert( | |
205 std::make_pair(FrameLengthController::FrameLengthChange(120, 60), | |
206 kFl120msTo60msBandwidthBps)); | |
207 } | |
208 FrameLengthController* get() { return &frame_length_controller_; } | |
209 | |
210 private: | |
211 FrameLengthController frame_length_controller_; | |
212 }; | |
213 | |
214 TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkBandwidth) { | 229 TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkBandwidth) { |
215 FrameLengthControllerForTest controller({20, 60, 120}, 120); | 230 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), |
| 231 {20, 60, 120}, 120); |
216 // It takes two steps for frame length to go from 120ms to 20ms. | 232 // It takes two steps for frame length to go from 120ms to 20ms. |
217 UpdateNetworkMetrics(controller.get(), | 233 UpdateNetworkMetrics(controller.get(), |
218 rtc::Optional<int>(kFl60msTo20msBandwidthBps), | 234 rtc::Optional<int>(kFl60msTo20msBandwidthBps), |
219 rtc::Optional<float>()); | 235 rtc::Optional<float>()); |
220 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 236 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
221 | 237 |
222 UpdateNetworkMetrics(controller.get(), | 238 UpdateNetworkMetrics(controller.get(), |
223 rtc::Optional<int>(kFl60msTo20msBandwidthBps), | 239 rtc::Optional<int>(kFl60msTo20msBandwidthBps), |
224 rtc::Optional<float>()); | 240 rtc::Optional<float>()); |
225 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); | 241 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); |
226 } | 242 } |
227 | 243 |
228 TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkPacketLossFraction) { | 244 TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkPacketLossFraction) { |
229 FrameLengthControllerForTest controller({20, 60, 120}, 120); | 245 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), |
| 246 {20, 60, 120}, 120); |
230 // It takes two steps for frame length to go from 120ms to 20ms. | 247 // It takes two steps for frame length to go from 120ms to 20ms. |
231 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(), | 248 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(), |
232 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); | 249 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); |
233 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 250 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
234 | 251 |
235 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(), | 252 UpdateNetworkMetrics(controller.get(), rtc::Optional<int>(), |
236 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); | 253 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); |
237 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); | 254 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); |
238 } | 255 } |
239 | 256 |
240 TEST(FrameLengthControllerTest, From120MsTo20MsWhenFecIsOn) { | 257 TEST(FrameLengthControllerTest, From120MsTo20MsWhenFecIsOn) { |
241 FrameLengthControllerForTest controller({20, 60, 120}, 120); | 258 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), |
| 259 {20, 60, 120}, 120); |
242 // It takes two steps for frame length to go from 120ms to 20ms. | 260 // It takes two steps for frame length to go from 120ms to 20ms. |
243 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60); | 261 CheckDecision(controller.get(), rtc::Optional<bool>(true), 60); |
244 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20); | 262 CheckDecision(controller.get(), rtc::Optional<bool>(true), 20); |
245 } | 263 } |
246 | 264 |
247 TEST(FrameLengthControllerTest, From20MsTo120MsOnMultipleConditions) { | 265 TEST(FrameLengthControllerTest, From20MsTo120MsOnMultipleConditions) { |
248 // Increase to 120ms frame length if | 266 // Increase to 120ms frame length if |
249 // 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND | 267 // 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND |
250 // 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold | 268 // 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold |
251 // AND | 269 // AND |
252 // 3. FEC is not decided or OFF. | 270 // 3. FEC is not decided or OFF. |
253 FrameLengthControllerForTest controller({20, 60, 120}, 20); | 271 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), |
| 272 {20, 60, 120}, 20); |
254 // It takes two steps for frame length to go from 20ms to 120ms. | 273 // It takes two steps for frame length to go from 20ms to 120ms. |
255 UpdateNetworkMetrics(controller.get(), | 274 UpdateNetworkMetrics(controller.get(), |
256 rtc::Optional<int>(kFl60msTo120msBandwidthBps), | 275 rtc::Optional<int>(kFl60msTo120msBandwidthBps), |
257 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 276 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
258 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 277 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
259 UpdateNetworkMetrics(controller.get(), | 278 UpdateNetworkMetrics(controller.get(), |
260 rtc::Optional<int>(kFl60msTo120msBandwidthBps), | 279 rtc::Optional<int>(kFl60msTo120msBandwidthBps), |
261 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 280 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
262 CheckDecision(controller.get(), rtc::Optional<bool>(), 120); | 281 CheckDecision(controller.get(), rtc::Optional<bool>(), 120); |
263 } | 282 } |
264 | 283 |
265 TEST(FrameLengthControllerTest, Stall60MsIf120MsNotInReceiverFrameLengthRange) { | 284 TEST(FrameLengthControllerTest, Stall60MsIf120MsNotInReceiverFrameLengthRange) { |
266 FrameLengthControllerForTest controller({20, 60}, 20); | 285 auto controller = |
| 286 CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), {20, 60}, 20); |
267 UpdateNetworkMetrics(controller.get(), | 287 UpdateNetworkMetrics(controller.get(), |
268 rtc::Optional<int>(kFl60msTo120msBandwidthBps), | 288 rtc::Optional<int>(kFl60msTo120msBandwidthBps), |
269 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 289 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
270 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 290 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
271 UpdateNetworkMetrics(controller.get(), | 291 UpdateNetworkMetrics(controller.get(), |
272 rtc::Optional<int>(kFl60msTo120msBandwidthBps), | 292 rtc::Optional<int>(kFl60msTo120msBandwidthBps), |
273 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 293 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
274 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 294 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
275 } | 295 } |
276 | 296 |
277 TEST(FrameLengthControllerTest, CheckBehaviorOnChangingNetworkMetrics) { | 297 TEST(FrameLengthControllerTest, CheckBehaviorOnChangingNetworkMetrics) { |
278 FrameLengthControllerForTest controller({20, 60, 120}, 20); | 298 auto controller = CreateController(CreateChangeCriteriaFor20ms60msAnd120ms(), |
| 299 {20, 60, 120}, 20); |
279 UpdateNetworkMetrics(controller.get(), | 300 UpdateNetworkMetrics(controller.get(), |
280 rtc::Optional<int>(kMediumBandwidthBps), | 301 rtc::Optional<int>(kMediumBandwidthBps), |
281 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 302 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
282 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); | 303 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); |
283 | 304 |
284 UpdateNetworkMetrics(controller.get(), | 305 UpdateNetworkMetrics(controller.get(), |
285 rtc::Optional<int>(kFl20msTo60msBandwidthBps), | 306 rtc::Optional<int>(kFl20msTo60msBandwidthBps), |
286 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 307 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
287 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 308 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
288 | 309 |
(...skipping 12 matching lines...) Expand all Loading... |
301 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); | 322 rtc::Optional<float>(kFlIncreasingPacketLossFraction)); |
302 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); | 323 CheckDecision(controller.get(), rtc::Optional<bool>(), 60); |
303 | 324 |
304 UpdateNetworkMetrics(controller.get(), | 325 UpdateNetworkMetrics(controller.get(), |
305 rtc::Optional<int>(kMediumPacketLossFraction), | 326 rtc::Optional<int>(kMediumPacketLossFraction), |
306 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); | 327 rtc::Optional<float>(kFlDecreasingPacketLossFraction)); |
307 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); | 328 CheckDecision(controller.get(), rtc::Optional<bool>(), 20); |
308 } | 329 } |
309 | 330 |
310 } // namespace webrtc | 331 } // namespace webrtc |
OLD | NEW |