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

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

Issue 2364403004: Creating controller manager from config string in audio network adaptor. (Closed)
Patch Set: rebasing Created 4 years, 2 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 <utility> 11 #include <utility>
12 12
13 #include "webrtc/base/ignore_wundef.h"
13 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h " 14 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h "
14 #include "webrtc/modules/audio_coding/audio_network_adaptor/mock/mock_controller .h" 15 #include "webrtc/modules/audio_coding/audio_network_adaptor/mock/mock_controller .h"
15 #include "webrtc/system_wrappers/include/clock.h" 16 #include "webrtc/system_wrappers/include/clock.h"
16 #include "webrtc/test/gtest.h" 17 #include "webrtc/test/gtest.h"
17 18
19 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
20 RTC_PUSH_IGNORING_WUNDEF()
21 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
22 #include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/conf ig.pb.h"
23 #else
24 #include "webrtc/modules/audio_coding/audio_network_adaptor/config.pb.h"
25 #endif
26 RTC_POP_IGNORING_WUNDEF()
27 #endif
28
18 namespace webrtc { 29 namespace webrtc {
19 30
20 using ::testing::NiceMock; 31 using ::testing::NiceMock;
21 32
22 namespace { 33 namespace {
23 34
24 constexpr size_t kNumControllers = 4; 35 constexpr size_t kNumControllers = 4;
25 constexpr int kChracteristicBandwithBps[2] = {15000, 0}; 36 constexpr int kChracteristicBandwithBps[2] = {15000, 0};
26 constexpr float kChracteristicPacketLossFraction[2] = {0.2f, 0.0f}; 37 constexpr float kChracteristicPacketLossFraction[2] = {0.2f, 0.0f};
27 constexpr int kMinReorderingTimeMs = 200; 38 constexpr int kMinReorderingTimeMs = 200;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 rtc::Optional<float>(kPacketLossFraction), 194 rtc::Optional<float>(kPacketLossFraction),
184 {kNumControllers - 2, kNumControllers - 1, 0, 1}); 195 {kNumControllers - 2, kNumControllers - 1, 0, 1});
185 states.simulated_clock->AdvanceTimeMilliseconds(kMinReorderingTimeMs); 196 states.simulated_clock->AdvanceTimeMilliseconds(kMinReorderingTimeMs);
186 // Then let network metrics move a little towards the other controller. 197 // Then let network metrics move a little towards the other controller.
187 CheckControllersOrder( 198 CheckControllersOrder(
188 &states, rtc::Optional<int>(kBandwidthBps - kMinBandwithChangeBps + 1), 199 &states, rtc::Optional<int>(kBandwidthBps - kMinBandwithChangeBps + 1),
189 rtc::Optional<float>(kPacketLossFraction), 200 rtc::Optional<float>(kPacketLossFraction),
190 {kNumControllers - 2, kNumControllers - 1, 0, 1}); 201 {kNumControllers - 2, kNumControllers - 1, 0, 1});
191 } 202 }
192 203
204 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
205
206 namespace {
207
208 void AddBitrateControllerConfig(
209 audio_network_adaptor::config::ControllerManager* config) {
210 config->add_controllers()->mutable_bitrate_controller();
211 }
212
213 void AddChannelControllerConfig(
214 audio_network_adaptor::config::ControllerManager* config) {
215 auto controller_config =
216 config->add_controllers()->mutable_channel_controller();
217 controller_config->set_channel_1_to_2_bandwidth_bps(31000);
218 controller_config->set_channel_2_to_1_bandwidth_bps(29000);
219 }
220
221 void AddDtxControllerConfig(
222 audio_network_adaptor::config::ControllerManager* config) {
223 auto controller_config = config->add_controllers()->mutable_dtx_controller();
224 controller_config->set_dtx_enabling_bandwidth_bps(55000);
225 controller_config->set_dtx_disabling_bandwidth_bps(65000);
226 }
227
228 void AddFecControllerConfig(
229 audio_network_adaptor::config::ControllerManager* config) {
230 auto controller_config_ext = config->add_controllers();
231 auto controller_config = controller_config_ext->mutable_fec_controller();
232 auto fec_enabling_threshold =
233 controller_config->mutable_fec_enabling_threshold();
234 fec_enabling_threshold->set_low_bandwidth_bps(17000);
235 fec_enabling_threshold->set_low_bandwidth_packet_loss(0.1f);
236 fec_enabling_threshold->set_high_bandwidth_bps(64000);
237 fec_enabling_threshold->set_high_bandwidth_packet_loss(0.05f);
238 auto fec_disabling_threshold =
239 controller_config->mutable_fec_disabling_threshold();
240 fec_disabling_threshold->set_low_bandwidth_bps(15000);
241 fec_disabling_threshold->set_low_bandwidth_packet_loss(0.08f);
242 fec_disabling_threshold->set_high_bandwidth_bps(64000);
243 fec_disabling_threshold->set_high_bandwidth_packet_loss(0.01f);
244 controller_config->set_time_constant_ms(500);
245
246 auto scoring_point = controller_config_ext->mutable_scoring_point();
247 scoring_point->set_uplink_bandwidth_bps(kChracteristicBandwithBps[0]);
248 scoring_point->set_uplink_packet_loss_fraction(
249 kChracteristicPacketLossFraction[0]);
250 }
251
252 void AddFrameLengthControllerConfig(
253 audio_network_adaptor::config::ControllerManager* config) {
254 auto controller_config_ext = config->add_controllers();
255 auto controller_config =
256 controller_config_ext->mutable_frame_length_controller();
257 controller_config->set_fl_decreasing_packet_loss_fraction(0.05f);
258 controller_config->set_fl_increasing_packet_loss_fraction(0.04f);
259 controller_config->set_fl_20ms_to_60ms_bandwidth_bps(72000);
260 controller_config->set_fl_60ms_to_20ms_bandwidth_bps(88000);
261
262 auto scoring_point = controller_config_ext->mutable_scoring_point();
263 scoring_point->set_uplink_bandwidth_bps(kChracteristicBandwithBps[1]);
264 scoring_point->set_uplink_packet_loss_fraction(
265 kChracteristicPacketLossFraction[1]);
266 }
267
268 constexpr int kInitialBitrateBps = 24000;
269 constexpr size_t kIntialChannelsToEncode = 1;
270 constexpr bool kInitialDtxEnabled = true;
271 constexpr bool kInitialFecEnabled = true;
272 constexpr int kInitialFrameLengthMs = 60;
273
274 ControllerManagerStates CreateControllerManager(
275 const std::string& config_string) {
276 ControllerManagerStates states;
277 states.simulated_clock.reset(new SimulatedClock(kClockInitialTime));
278 constexpr size_t kNumEncoderChannels = 2;
279 const std::vector<int> encoder_frame_lengths_ms = {20, 60};
280 states.controller_manager = ControllerManagerImpl::Create(
281 config_string, kNumEncoderChannels, encoder_frame_lengths_ms,
282 kIntialChannelsToEncode, kInitialFrameLengthMs, kInitialBitrateBps,
283 kInitialFecEnabled, kInitialDtxEnabled, states.simulated_clock.get());
284 return states;
285 }
286
287 enum class ControllerType : int8_t {
288 FEC,
289 CHANNEL,
290 DTX,
291 FRAME_LENGTH,
292 BIT_RATE
293 };
294
295 void CheckControllersOrder(const std::vector<Controller*>& controllers,
296 const std::vector<ControllerType>& expected_types) {
297 ASSERT_EQ(expected_types.size(), controllers.size());
298
299 // We also check that the controllers follow the initial settings.
300 AudioNetworkAdaptor::EncoderRuntimeConfig encoder_config;
301
302 // We do not check the internal logic of controllers. We only check that
303 // when no network metrics are known, controllers provide the initial values.
304 Controller::NetworkMetrics metrics;
305
306 for (size_t i = 0; i < controllers.size(); ++i) {
307 AudioNetworkAdaptor::EncoderRuntimeConfig encoder_config;
308 // We check the order of |controllers| by judging their decisions.
309 controllers[i]->MakeDecision(metrics, &encoder_config);
310 switch (expected_types[i]) {
311 case ControllerType::FEC:
312 EXPECT_EQ(rtc::Optional<bool>(kInitialFecEnabled),
313 encoder_config.enable_fec);
314 break;
315 case ControllerType::CHANNEL:
316 EXPECT_EQ(rtc::Optional<size_t>(kIntialChannelsToEncode),
317 encoder_config.num_channels);
318 break;
319 case ControllerType::DTX:
320 EXPECT_EQ(rtc::Optional<bool>(kInitialDtxEnabled),
321 encoder_config.enable_dtx);
322 break;
323 case ControllerType::FRAME_LENGTH:
324 EXPECT_EQ(rtc::Optional<int>(kInitialFrameLengthMs),
325 encoder_config.frame_length_ms);
326 break;
327 case ControllerType::BIT_RATE:
328 EXPECT_EQ(rtc::Optional<int>(kInitialBitrateBps),
329 encoder_config.bitrate_bps);
330 }
331 }
332 }
333
334 } // namespace
335
336 TEST(ControllerManagerTest, CreateFromConfigStringAndCheckDefaultOrder) {
337 audio_network_adaptor::config::ControllerManager config;
338 config.set_min_reordering_time_ms(kMinReorderingTimeMs);
339 config.set_min_reordering_squared_distance(kMinReorderingSquareDistance);
340
341 AddFecControllerConfig(&config);
342 AddChannelControllerConfig(&config);
343 AddDtxControllerConfig(&config);
344 AddFrameLengthControllerConfig(&config);
345 AddBitrateControllerConfig(&config);
346
347 std::string config_string;
348 config.SerializeToString(&config_string);
349
350 auto states = CreateControllerManager(config_string);
351 Controller::NetworkMetrics metrics;
352
353 auto controllers = states.controller_manager->GetSortedControllers(metrics);
354 CheckControllersOrder(
355 controllers,
356 std::vector<ControllerType>{
357 ControllerType::FEC, ControllerType::CHANNEL, ControllerType::DTX,
358 ControllerType::FRAME_LENGTH, ControllerType::BIT_RATE});
359 }
360
361 TEST(ControllerManagerTest, CreateFromConfigStringAndCheckReordering) {
362 audio_network_adaptor::config::ControllerManager config;
363 config.set_min_reordering_time_ms(kMinReorderingTimeMs);
364 config.set_min_reordering_squared_distance(kMinReorderingSquareDistance);
365
366 AddChannelControllerConfig(&config);
367
368 // Internally associated with characteristic point 0.
369 AddFecControllerConfig(&config);
370
371 AddDtxControllerConfig(&config);
372
373 // Internally associated with characteristic point 1.
374 AddFrameLengthControllerConfig(&config);
375
376 AddBitrateControllerConfig(&config);
377
378 std::string config_string;
379 config.SerializeToString(&config_string);
380
381 auto states = CreateControllerManager(config_string);
382
383 Controller::NetworkMetrics metrics;
384 metrics.uplink_bandwidth_bps =
385 rtc::Optional<int>(kChracteristicBandwithBps[0]);
386 metrics.uplink_packet_loss_fraction =
387 rtc::Optional<float>(kChracteristicPacketLossFraction[0]);
388
389 auto controllers = states.controller_manager->GetSortedControllers(metrics);
390 CheckControllersOrder(controllers,
391 std::vector<ControllerType>{
392 ControllerType::FEC, ControllerType::FRAME_LENGTH,
393 ControllerType::CHANNEL, ControllerType::DTX,
394 ControllerType::BIT_RATE});
395
396 metrics.uplink_bandwidth_bps =
397 rtc::Optional<int>(kChracteristicBandwithBps[1]);
398 metrics.uplink_packet_loss_fraction =
399 rtc::Optional<float>(kChracteristicPacketLossFraction[1]);
400 states.simulated_clock->AdvanceTimeMilliseconds(kMinReorderingTimeMs - 1);
401 controllers = states.controller_manager->GetSortedControllers(metrics);
402 // Should not reorder since min reordering time is not met.
403 CheckControllersOrder(controllers,
404 std::vector<ControllerType>{
405 ControllerType::FEC, ControllerType::FRAME_LENGTH,
406 ControllerType::CHANNEL, ControllerType::DTX,
407 ControllerType::BIT_RATE});
408
409 states.simulated_clock->AdvanceTimeMilliseconds(1);
410 controllers = states.controller_manager->GetSortedControllers(metrics);
411 // Reorder now.
412 CheckControllersOrder(controllers,
413 std::vector<ControllerType>{
414 ControllerType::FRAME_LENGTH, ControllerType::FEC,
415 ControllerType::CHANNEL, ControllerType::DTX,
416 ControllerType::BIT_RATE});
417 }
418 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
419
193 } // namespace webrtc 420 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698