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

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

Issue 2782563003: Replace Clock with timeutils in AudioEncoder. (Closed)
Patch Set: Fix for failing unittest. Created 3 years, 8 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/fakeclock.h"
13 #include "webrtc/base/ignore_wundef.h" 14 #include "webrtc/base/ignore_wundef.h"
14 #include "webrtc/base/protobuf_utils.h" 15 #include "webrtc/base/protobuf_utils.h"
15 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h " 16 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h "
16 #include "webrtc/modules/audio_coding/audio_network_adaptor/mock/mock_controller .h" 17 #include "webrtc/modules/audio_coding/audio_network_adaptor/mock/mock_controller .h"
17 #include "webrtc/system_wrappers/include/clock.h"
18 #include "webrtc/test/gtest.h" 18 #include "webrtc/test/gtest.h"
19 19
20 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP 20 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
21 RTC_PUSH_IGNORING_WUNDEF() 21 RTC_PUSH_IGNORING_WUNDEF()
22 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD 22 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
23 #include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/conf ig.pb.h" 23 #include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/conf ig.pb.h"
24 #else 24 #else
25 #include "webrtc/modules/audio_coding/audio_network_adaptor/config.pb.h" 25 #include "webrtc/modules/audio_coding/audio_network_adaptor/config.pb.h"
26 #endif 26 #endif
27 RTC_POP_IGNORING_WUNDEF() 27 RTC_POP_IGNORING_WUNDEF()
(...skipping 12 matching lines...) Expand all
40 constexpr int kFactor = 100; 40 constexpr int kFactor = 100;
41 constexpr float kMinReorderingSquareDistance = 1.0f / kFactor / kFactor; 41 constexpr float kMinReorderingSquareDistance = 1.0f / kFactor / kFactor;
42 42
43 // |kMinUplinkBandwidthBps| and |kMaxUplinkBandwidthBps| are copied from 43 // |kMinUplinkBandwidthBps| and |kMaxUplinkBandwidthBps| are copied from
44 // controller_manager.cc 44 // controller_manager.cc
45 constexpr int kMinUplinkBandwidthBps = 0; 45 constexpr int kMinUplinkBandwidthBps = 0;
46 constexpr int kMaxUplinkBandwidthBps = 120000; 46 constexpr int kMaxUplinkBandwidthBps = 120000;
47 constexpr int kMinBandwithChangeBps = 47 constexpr int kMinBandwithChangeBps =
48 (kMaxUplinkBandwidthBps - kMinUplinkBandwidthBps) / kFactor; 48 (kMaxUplinkBandwidthBps - kMinUplinkBandwidthBps) / kFactor;
49 49
50 constexpr int64_t kClockInitialTime = 123456789;
51
52 struct ControllerManagerStates { 50 struct ControllerManagerStates {
53 std::unique_ptr<ControllerManager> controller_manager; 51 std::unique_ptr<ControllerManager> controller_manager;
54 std::vector<MockController*> mock_controllers; 52 std::vector<MockController*> mock_controllers;
55 std::unique_ptr<SimulatedClock> simulated_clock;
56 }; 53 };
57 54
58 ControllerManagerStates CreateControllerManager() { 55 ControllerManagerStates CreateControllerManager() {
59 ControllerManagerStates states; 56 ControllerManagerStates states;
60 std::vector<std::unique_ptr<Controller>> controllers; 57 std::vector<std::unique_ptr<Controller>> controllers;
61 std::map<const Controller*, std::pair<int, float>> chracteristic_points; 58 std::map<const Controller*, std::pair<int, float>> chracteristic_points;
62 for (size_t i = 0; i < kNumControllers; ++i) { 59 for (size_t i = 0; i < kNumControllers; ++i) {
63 auto controller = 60 auto controller =
64 std::unique_ptr<MockController>(new NiceMock<MockController>()); 61 std::unique_ptr<MockController>(new NiceMock<MockController>());
65 EXPECT_CALL(*controller, Die()); 62 EXPECT_CALL(*controller, Die());
66 states.mock_controllers.push_back(controller.get()); 63 states.mock_controllers.push_back(controller.get());
67 controllers.push_back(std::move(controller)); 64 controllers.push_back(std::move(controller));
68 } 65 }
69 66
70 // Assign characteristic points to the last two controllers. 67 // Assign characteristic points to the last two controllers.
71 chracteristic_points[states.mock_controllers[kNumControllers - 2]] = 68 chracteristic_points[states.mock_controllers[kNumControllers - 2]] =
72 std::make_pair(kChracteristicBandwithBps[0], 69 std::make_pair(kChracteristicBandwithBps[0],
73 kChracteristicPacketLossFraction[0]); 70 kChracteristicPacketLossFraction[0]);
74 chracteristic_points[states.mock_controllers[kNumControllers - 1]] = 71 chracteristic_points[states.mock_controllers[kNumControllers - 1]] =
75 std::make_pair(kChracteristicBandwithBps[1], 72 std::make_pair(kChracteristicBandwithBps[1],
76 kChracteristicPacketLossFraction[1]); 73 kChracteristicPacketLossFraction[1]);
77 74
78 states.simulated_clock.reset(new SimulatedClock(kClockInitialTime));
79 states.controller_manager.reset(new ControllerManagerImpl( 75 states.controller_manager.reset(new ControllerManagerImpl(
80 ControllerManagerImpl::Config(kMinReorderingTimeMs, 76 ControllerManagerImpl::Config(kMinReorderingTimeMs,
81 kMinReorderingSquareDistance, 77 kMinReorderingSquareDistance),
82 states.simulated_clock.get()),
83 std::move(controllers), chracteristic_points)); 78 std::move(controllers), chracteristic_points));
84 return states; 79 return states;
85 } 80 }
86 81
87 // |expected_order| contains the expected indices of all controllers in the 82 // |expected_order| contains the expected indices of all controllers in the
88 // vector of controllers returned by GetSortedControllers(). A negative index 83 // vector of controllers returned by GetSortedControllers(). A negative index
89 // means that we do not care about its exact place, but we do check that it 84 // means that we do not care about its exact place, but we do check that it
90 // exists in the vector. 85 // exists in the vector.
91 void CheckControllersOrder( 86 void CheckControllersOrder(
92 ControllerManagerStates* states, 87 ControllerManagerStates* states,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 135
141 TEST(ControllerManagerTest, ControllersWithCharPointDependOnNetworkMetrics) { 136 TEST(ControllerManagerTest, ControllersWithCharPointDependOnNetworkMetrics) {
142 auto states = CreateControllerManager(); 137 auto states = CreateControllerManager();
143 CheckControllersOrder( 138 CheckControllersOrder(
144 &states, rtc::Optional<int>(kChracteristicBandwithBps[1]), 139 &states, rtc::Optional<int>(kChracteristicBandwithBps[1]),
145 rtc::Optional<float>(kChracteristicPacketLossFraction[1]), 140 rtc::Optional<float>(kChracteristicPacketLossFraction[1]),
146 {kNumControllers - 2, kNumControllers - 1, 1, 0}); 141 {kNumControllers - 2, kNumControllers - 1, 1, 0});
147 } 142 }
148 143
149 TEST(ControllerManagerTest, DoNotReorderBeforeMinReordingTime) { 144 TEST(ControllerManagerTest, DoNotReorderBeforeMinReordingTime) {
145 rtc::ScopedFakeClock fake_clock;
150 auto states = CreateControllerManager(); 146 auto states = CreateControllerManager();
151 CheckControllersOrder( 147 CheckControllersOrder(
152 &states, rtc::Optional<int>(kChracteristicBandwithBps[0]), 148 &states, rtc::Optional<int>(kChracteristicBandwithBps[0]),
153 rtc::Optional<float>(kChracteristicPacketLossFraction[0]), 149 rtc::Optional<float>(kChracteristicPacketLossFraction[0]),
154 {kNumControllers - 2, kNumControllers - 1, 0, 1}); 150 {kNumControllers - 2, kNumControllers - 1, 0, 1});
155 states.simulated_clock->AdvanceTimeMilliseconds(kMinReorderingTimeMs - 1); 151 fake_clock.AdvanceTime(
152 rtc::TimeDelta::FromMilliseconds(kMinReorderingTimeMs - 1));
156 // Move uplink bandwidth and packet loss fraction to the other controller's 153 // Move uplink bandwidth and packet loss fraction to the other controller's
157 // characteristic point, which would cause controller manager to reorder the 154 // characteristic point, which would cause controller manager to reorder the
158 // controllers if time had reached min reordering time. 155 // controllers if time had reached min reordering time.
159 CheckControllersOrder( 156 CheckControllersOrder(
160 &states, rtc::Optional<int>(kChracteristicBandwithBps[1]), 157 &states, rtc::Optional<int>(kChracteristicBandwithBps[1]),
161 rtc::Optional<float>(kChracteristicPacketLossFraction[1]), 158 rtc::Optional<float>(kChracteristicPacketLossFraction[1]),
162 {kNumControllers - 2, kNumControllers - 1, 0, 1}); 159 {kNumControllers - 2, kNumControllers - 1, 0, 1});
163 } 160 }
164 161
165 TEST(ControllerManagerTest, ReorderBeyondMinReordingTimeAndMinDistance) { 162 TEST(ControllerManagerTest, ReorderBeyondMinReordingTimeAndMinDistance) {
163 rtc::ScopedFakeClock fake_clock;
166 auto states = CreateControllerManager(); 164 auto states = CreateControllerManager();
167 constexpr int kBandwidthBps = 165 constexpr int kBandwidthBps =
168 (kChracteristicBandwithBps[0] + kChracteristicBandwithBps[1]) / 2; 166 (kChracteristicBandwithBps[0] + kChracteristicBandwithBps[1]) / 2;
169 constexpr float kPacketLossFraction = (kChracteristicPacketLossFraction[0] + 167 constexpr float kPacketLossFraction = (kChracteristicPacketLossFraction[0] +
170 kChracteristicPacketLossFraction[1]) / 168 kChracteristicPacketLossFraction[1]) /
171 2.0f; 169 2.0f;
172 // Set network metrics to be in the middle between the characteristic points 170 // Set network metrics to be in the middle between the characteristic points
173 // of two controllers. 171 // of two controllers.
174 CheckControllersOrder(&states, rtc::Optional<int>(kBandwidthBps), 172 CheckControllersOrder(&states, rtc::Optional<int>(kBandwidthBps),
175 rtc::Optional<float>(kPacketLossFraction), 173 rtc::Optional<float>(kPacketLossFraction),
176 {kNumControllers - 2, kNumControllers - 1, 0, 1}); 174 {kNumControllers - 2, kNumControllers - 1, 0, 1});
177 states.simulated_clock->AdvanceTimeMilliseconds(kMinReorderingTimeMs); 175 fake_clock.AdvanceTime(
176 rtc::TimeDelta::FromMilliseconds(kMinReorderingTimeMs));
178 // Then let network metrics move a little towards the other controller. 177 // Then let network metrics move a little towards the other controller.
179 CheckControllersOrder( 178 CheckControllersOrder(
180 &states, rtc::Optional<int>(kBandwidthBps - kMinBandwithChangeBps - 1), 179 &states, rtc::Optional<int>(kBandwidthBps - kMinBandwithChangeBps - 1),
181 rtc::Optional<float>(kPacketLossFraction), 180 rtc::Optional<float>(kPacketLossFraction),
182 {kNumControllers - 2, kNumControllers - 1, 1, 0}); 181 {kNumControllers - 2, kNumControllers - 1, 1, 0});
183 } 182 }
184 183
185 TEST(ControllerManagerTest, DoNotReorderIfNetworkMetricsChangeTooSmall) { 184 TEST(ControllerManagerTest, DoNotReorderIfNetworkMetricsChangeTooSmall) {
185 rtc::ScopedFakeClock fake_clock;
186 auto states = CreateControllerManager(); 186 auto states = CreateControllerManager();
187 constexpr int kBandwidthBps = 187 constexpr int kBandwidthBps =
188 (kChracteristicBandwithBps[0] + kChracteristicBandwithBps[1]) / 2; 188 (kChracteristicBandwithBps[0] + kChracteristicBandwithBps[1]) / 2;
189 constexpr float kPacketLossFraction = (kChracteristicPacketLossFraction[0] + 189 constexpr float kPacketLossFraction = (kChracteristicPacketLossFraction[0] +
190 kChracteristicPacketLossFraction[1]) / 190 kChracteristicPacketLossFraction[1]) /
191 2.0f; 191 2.0f;
192 // Set network metrics to be in the middle between the characteristic points 192 // Set network metrics to be in the middle between the characteristic points
193 // of two controllers. 193 // of two controllers.
194 CheckControllersOrder(&states, rtc::Optional<int>(kBandwidthBps), 194 CheckControllersOrder(&states, rtc::Optional<int>(kBandwidthBps),
195 rtc::Optional<float>(kPacketLossFraction), 195 rtc::Optional<float>(kPacketLossFraction),
196 {kNumControllers - 2, kNumControllers - 1, 0, 1}); 196 {kNumControllers - 2, kNumControllers - 1, 0, 1});
197 states.simulated_clock->AdvanceTimeMilliseconds(kMinReorderingTimeMs); 197 fake_clock.AdvanceTime(
198 rtc::TimeDelta::FromMilliseconds(kMinReorderingTimeMs));
198 // Then let network metrics move a little towards the other controller. 199 // Then let network metrics move a little towards the other controller.
199 CheckControllersOrder( 200 CheckControllersOrder(
200 &states, rtc::Optional<int>(kBandwidthBps - kMinBandwithChangeBps + 1), 201 &states, rtc::Optional<int>(kBandwidthBps - kMinBandwithChangeBps + 1),
201 rtc::Optional<float>(kPacketLossFraction), 202 rtc::Optional<float>(kPacketLossFraction),
202 {kNumControllers - 2, kNumControllers - 1, 0, 1}); 203 {kNumControllers - 2, kNumControllers - 1, 0, 1});
203 } 204 }
204 205
205 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP 206 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
206 207
207 namespace { 208 namespace {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 constexpr int kInitialBitrateBps = 24000; 270 constexpr int kInitialBitrateBps = 24000;
270 constexpr size_t kIntialChannelsToEncode = 1; 271 constexpr size_t kIntialChannelsToEncode = 1;
271 constexpr bool kInitialDtxEnabled = true; 272 constexpr bool kInitialDtxEnabled = true;
272 constexpr bool kInitialFecEnabled = true; 273 constexpr bool kInitialFecEnabled = true;
273 constexpr int kInitialFrameLengthMs = 60; 274 constexpr int kInitialFrameLengthMs = 60;
274 constexpr int kMinBitrateBps = 6000; 275 constexpr int kMinBitrateBps = 6000;
275 276
276 ControllerManagerStates CreateControllerManager( 277 ControllerManagerStates CreateControllerManager(
277 const ProtoString& config_string) { 278 const ProtoString& config_string) {
278 ControllerManagerStates states; 279 ControllerManagerStates states;
279 states.simulated_clock.reset(new SimulatedClock(kClockInitialTime));
280 constexpr size_t kNumEncoderChannels = 2; 280 constexpr size_t kNumEncoderChannels = 2;
281 const std::vector<int> encoder_frame_lengths_ms = {20, 60}; 281 const std::vector<int> encoder_frame_lengths_ms = {20, 60};
282 states.controller_manager = ControllerManagerImpl::Create( 282 states.controller_manager = ControllerManagerImpl::Create(
283 config_string, kNumEncoderChannels, encoder_frame_lengths_ms, 283 config_string, kNumEncoderChannels, encoder_frame_lengths_ms,
284 kMinBitrateBps, kIntialChannelsToEncode, kInitialFrameLengthMs, 284 kMinBitrateBps, kIntialChannelsToEncode, kInitialFrameLengthMs,
285 kInitialBitrateBps, kInitialFecEnabled, kInitialDtxEnabled, 285 kInitialBitrateBps, kInitialFecEnabled, kInitialDtxEnabled);
286 states.simulated_clock.get());
287 return states; 286 return states;
288 } 287 }
289 288
290 enum class ControllerType : int8_t { 289 enum class ControllerType : int8_t {
291 FEC, 290 FEC,
292 CHANNEL, 291 CHANNEL,
293 DTX, 292 DTX,
294 FRAME_LENGTH, 293 FRAME_LENGTH,
295 BIT_RATE 294 BIT_RATE
296 }; 295 };
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 353
355 auto controllers = states.controller_manager->GetSortedControllers(metrics); 354 auto controllers = states.controller_manager->GetSortedControllers(metrics);
356 CheckControllersOrder( 355 CheckControllersOrder(
357 controllers, 356 controllers,
358 std::vector<ControllerType>{ 357 std::vector<ControllerType>{
359 ControllerType::FEC, ControllerType::CHANNEL, ControllerType::DTX, 358 ControllerType::FEC, ControllerType::CHANNEL, ControllerType::DTX,
360 ControllerType::FRAME_LENGTH, ControllerType::BIT_RATE}); 359 ControllerType::FRAME_LENGTH, ControllerType::BIT_RATE});
361 } 360 }
362 361
363 TEST(ControllerManagerTest, CreateFromConfigStringAndCheckReordering) { 362 TEST(ControllerManagerTest, CreateFromConfigStringAndCheckReordering) {
363 rtc::ScopedFakeClock fake_clock;
364 audio_network_adaptor::config::ControllerManager config; 364 audio_network_adaptor::config::ControllerManager config;
365 config.set_min_reordering_time_ms(kMinReorderingTimeMs); 365 config.set_min_reordering_time_ms(kMinReorderingTimeMs);
366 config.set_min_reordering_squared_distance(kMinReorderingSquareDistance); 366 config.set_min_reordering_squared_distance(kMinReorderingSquareDistance);
367 367
368 AddChannelControllerConfig(&config); 368 AddChannelControllerConfig(&config);
369 369
370 // Internally associated with characteristic point 0. 370 // Internally associated with characteristic point 0.
371 AddFecControllerConfig(&config); 371 AddFecControllerConfig(&config);
372 372
373 AddDtxControllerConfig(&config); 373 AddDtxControllerConfig(&config);
(...skipping 18 matching lines...) Expand all
392 CheckControllersOrder(controllers, 392 CheckControllersOrder(controllers,
393 std::vector<ControllerType>{ 393 std::vector<ControllerType>{
394 ControllerType::FEC, ControllerType::FRAME_LENGTH, 394 ControllerType::FEC, ControllerType::FRAME_LENGTH,
395 ControllerType::CHANNEL, ControllerType::DTX, 395 ControllerType::CHANNEL, ControllerType::DTX,
396 ControllerType::BIT_RATE}); 396 ControllerType::BIT_RATE});
397 397
398 metrics.uplink_bandwidth_bps = 398 metrics.uplink_bandwidth_bps =
399 rtc::Optional<int>(kChracteristicBandwithBps[1]); 399 rtc::Optional<int>(kChracteristicBandwithBps[1]);
400 metrics.uplink_packet_loss_fraction = 400 metrics.uplink_packet_loss_fraction =
401 rtc::Optional<float>(kChracteristicPacketLossFraction[1]); 401 rtc::Optional<float>(kChracteristicPacketLossFraction[1]);
402 states.simulated_clock->AdvanceTimeMilliseconds(kMinReorderingTimeMs - 1); 402 fake_clock.AdvanceTime(
403 rtc::TimeDelta::FromMilliseconds(kMinReorderingTimeMs - 1));
403 controllers = states.controller_manager->GetSortedControllers(metrics); 404 controllers = states.controller_manager->GetSortedControllers(metrics);
404 // Should not reorder since min reordering time is not met. 405 // Should not reorder since min reordering time is not met.
405 CheckControllersOrder(controllers, 406 CheckControllersOrder(controllers,
406 std::vector<ControllerType>{ 407 std::vector<ControllerType>{
407 ControllerType::FEC, ControllerType::FRAME_LENGTH, 408 ControllerType::FEC, ControllerType::FRAME_LENGTH,
408 ControllerType::CHANNEL, ControllerType::DTX, 409 ControllerType::CHANNEL, ControllerType::DTX,
409 ControllerType::BIT_RATE}); 410 ControllerType::BIT_RATE});
410 411
411 states.simulated_clock->AdvanceTimeMilliseconds(1); 412 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1));
412 controllers = states.controller_manager->GetSortedControllers(metrics); 413 controllers = states.controller_manager->GetSortedControllers(metrics);
413 // Reorder now. 414 // Reorder now.
414 CheckControllersOrder(controllers, 415 CheckControllersOrder(controllers,
415 std::vector<ControllerType>{ 416 std::vector<ControllerType>{
416 ControllerType::FRAME_LENGTH, ControllerType::FEC, 417 ControllerType::FRAME_LENGTH, ControllerType::FEC,
417 ControllerType::CHANNEL, ControllerType::DTX, 418 ControllerType::CHANNEL, ControllerType::DTX,
418 ControllerType::BIT_RATE}); 419 ControllerType::BIT_RATE});
419 } 420 }
420 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP 421 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
421 422
422 } // namespace webrtc 423 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698