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 "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h
" | 11 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h
" |
12 | 12 |
13 #include <cmath> | 13 #include <cmath> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/ignore_wundef.h" | 16 #include "webrtc/base/ignore_wundef.h" |
| 17 #include "webrtc/base/timeutils.h" |
17 #include "webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.h
" | 18 #include "webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.h
" |
18 #include "webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.h
" | 19 #include "webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.h
" |
19 #include "webrtc/modules/audio_coding/audio_network_adaptor/dtx_controller.h" | 20 #include "webrtc/modules/audio_coding/audio_network_adaptor/dtx_controller.h" |
20 #include "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_b
ased.h" | 21 #include "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_b
ased.h" |
21 #include "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_rplr_
based.h" | 22 #include "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_rplr_
based.h" |
22 #include "webrtc/modules/audio_coding/audio_network_adaptor/frame_length_control
ler.h" | 23 #include "webrtc/modules/audio_coding/audio_network_adaptor/frame_length_control
ler.h" |
23 #include "webrtc/modules/audio_coding/audio_network_adaptor/util/threshold_curve
.h" | 24 #include "webrtc/modules/audio_coding/audio_network_adaptor/util/threshold_curve
.h" |
24 #include "webrtc/system_wrappers/include/clock.h" | |
25 | 25 |
26 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP | 26 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
27 RTC_PUSH_IGNORING_WUNDEF() | 27 RTC_PUSH_IGNORING_WUNDEF() |
28 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 28 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
29 #include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/conf
ig.pb.h" | 29 #include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/conf
ig.pb.h" |
30 #else | 30 #else |
31 #include "webrtc/modules/audio_coding/audio_network_adaptor/config.pb.h" | 31 #include "webrtc/modules/audio_coding/audio_network_adaptor/config.pb.h" |
32 #endif | 32 #endif |
33 RTC_POP_IGNORING_WUNDEF() | 33 RTC_POP_IGNORING_WUNDEF() |
34 #endif | 34 #endif |
35 | 35 |
36 namespace webrtc { | 36 namespace webrtc { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP | 40 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
41 | 41 |
42 std::unique_ptr<FecControllerPlrBased> CreateFecControllerPlrBased( | 42 std::unique_ptr<FecControllerPlrBased> CreateFecControllerPlrBased( |
43 const audio_network_adaptor::config::FecController& config, | 43 const audio_network_adaptor::config::FecController& config, |
44 bool initial_fec_enabled, | 44 bool initial_fec_enabled) { |
45 const Clock* clock) { | |
46 RTC_CHECK(config.has_fec_enabling_threshold()); | 45 RTC_CHECK(config.has_fec_enabling_threshold()); |
47 RTC_CHECK(config.has_fec_disabling_threshold()); | 46 RTC_CHECK(config.has_fec_disabling_threshold()); |
48 RTC_CHECK(config.has_time_constant_ms()); | 47 RTC_CHECK(config.has_time_constant_ms()); |
49 | 48 |
50 auto& fec_enabling_threshold = config.fec_enabling_threshold(); | 49 auto& fec_enabling_threshold = config.fec_enabling_threshold(); |
51 RTC_CHECK(fec_enabling_threshold.has_low_bandwidth_bps()); | 50 RTC_CHECK(fec_enabling_threshold.has_low_bandwidth_bps()); |
52 RTC_CHECK(fec_enabling_threshold.has_low_bandwidth_packet_loss()); | 51 RTC_CHECK(fec_enabling_threshold.has_low_bandwidth_packet_loss()); |
53 RTC_CHECK(fec_enabling_threshold.has_high_bandwidth_bps()); | 52 RTC_CHECK(fec_enabling_threshold.has_high_bandwidth_bps()); |
54 RTC_CHECK(fec_enabling_threshold.has_high_bandwidth_packet_loss()); | 53 RTC_CHECK(fec_enabling_threshold.has_high_bandwidth_packet_loss()); |
55 | 54 |
56 auto& fec_disabling_threshold = config.fec_disabling_threshold(); | 55 auto& fec_disabling_threshold = config.fec_disabling_threshold(); |
57 RTC_CHECK(fec_disabling_threshold.has_low_bandwidth_bps()); | 56 RTC_CHECK(fec_disabling_threshold.has_low_bandwidth_bps()); |
58 RTC_CHECK(fec_disabling_threshold.has_low_bandwidth_packet_loss()); | 57 RTC_CHECK(fec_disabling_threshold.has_low_bandwidth_packet_loss()); |
59 RTC_CHECK(fec_disabling_threshold.has_high_bandwidth_bps()); | 58 RTC_CHECK(fec_disabling_threshold.has_high_bandwidth_bps()); |
60 RTC_CHECK(fec_disabling_threshold.has_high_bandwidth_packet_loss()); | 59 RTC_CHECK(fec_disabling_threshold.has_high_bandwidth_packet_loss()); |
61 | 60 |
62 return std::unique_ptr<FecControllerPlrBased>( | 61 return std::unique_ptr<FecControllerPlrBased>( |
63 new FecControllerPlrBased(FecControllerPlrBased::Config( | 62 new FecControllerPlrBased(FecControllerPlrBased::Config( |
64 initial_fec_enabled, | 63 initial_fec_enabled, |
65 ThresholdCurve(fec_enabling_threshold.low_bandwidth_bps(), | 64 ThresholdCurve(fec_enabling_threshold.low_bandwidth_bps(), |
66 fec_enabling_threshold.low_bandwidth_packet_loss(), | 65 fec_enabling_threshold.low_bandwidth_packet_loss(), |
67 fec_enabling_threshold.high_bandwidth_bps(), | 66 fec_enabling_threshold.high_bandwidth_bps(), |
68 fec_enabling_threshold.high_bandwidth_packet_loss()), | 67 fec_enabling_threshold.high_bandwidth_packet_loss()), |
69 ThresholdCurve(fec_disabling_threshold.low_bandwidth_bps(), | 68 ThresholdCurve(fec_disabling_threshold.low_bandwidth_bps(), |
70 fec_disabling_threshold.low_bandwidth_packet_loss(), | 69 fec_disabling_threshold.low_bandwidth_packet_loss(), |
71 fec_disabling_threshold.high_bandwidth_bps(), | 70 fec_disabling_threshold.high_bandwidth_bps(), |
72 fec_disabling_threshold.high_bandwidth_packet_loss()), | 71 fec_disabling_threshold.high_bandwidth_packet_loss()), |
73 config.time_constant_ms(), clock))); | 72 config.time_constant_ms()))); |
74 } | 73 } |
75 | 74 |
76 std::unique_ptr<FecControllerRplrBased> CreateFecControllerRplrBased( | 75 std::unique_ptr<FecControllerRplrBased> CreateFecControllerRplrBased( |
77 const audio_network_adaptor::config::FecControllerRplrBased& config, | 76 const audio_network_adaptor::config::FecControllerRplrBased& config, |
78 bool initial_fec_enabled) { | 77 bool initial_fec_enabled) { |
79 RTC_CHECK(config.has_fec_enabling_threshold()); | 78 RTC_CHECK(config.has_fec_enabling_threshold()); |
80 RTC_CHECK(config.has_fec_disabling_threshold()); | 79 RTC_CHECK(config.has_fec_disabling_threshold()); |
81 | 80 |
82 auto& fec_enabling_threshold = config.fec_enabling_threshold(); | 81 auto& fec_enabling_threshold = config.fec_enabling_threshold(); |
83 RTC_CHECK(fec_enabling_threshold.has_low_bandwidth_bps()); | 82 RTC_CHECK(fec_enabling_threshold.has_low_bandwidth_bps()); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 int initial_bitrate_bps, | 178 int initial_bitrate_bps, |
180 int initial_frame_length_ms) { | 179 int initial_frame_length_ms) { |
181 return std::unique_ptr<BitrateController>(new BitrateController( | 180 return std::unique_ptr<BitrateController>(new BitrateController( |
182 BitrateController::Config(initial_bitrate_bps, initial_frame_length_ms))); | 181 BitrateController::Config(initial_bitrate_bps, initial_frame_length_ms))); |
183 } | 182 } |
184 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP | 183 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
185 | 184 |
186 } // namespace | 185 } // namespace |
187 | 186 |
188 ControllerManagerImpl::Config::Config(int min_reordering_time_ms, | 187 ControllerManagerImpl::Config::Config(int min_reordering_time_ms, |
189 float min_reordering_squared_distance, | 188 float min_reordering_squared_distance) |
190 const Clock* clock) | |
191 : min_reordering_time_ms(min_reordering_time_ms), | 189 : min_reordering_time_ms(min_reordering_time_ms), |
192 min_reordering_squared_distance(min_reordering_squared_distance), | 190 min_reordering_squared_distance(min_reordering_squared_distance) {} |
193 clock(clock) {} | |
194 | 191 |
195 ControllerManagerImpl::Config::~Config() = default; | 192 ControllerManagerImpl::Config::~Config() = default; |
196 | 193 |
197 std::unique_ptr<ControllerManager> ControllerManagerImpl::Create( | 194 std::unique_ptr<ControllerManager> ControllerManagerImpl::Create( |
198 const ProtoString& config_string, | 195 const ProtoString& config_string, |
199 size_t num_encoder_channels, | 196 size_t num_encoder_channels, |
200 rtc::ArrayView<const int> encoder_frame_lengths_ms, | 197 rtc::ArrayView<const int> encoder_frame_lengths_ms, |
201 int min_encoder_bitrate_bps, | 198 int min_encoder_bitrate_bps, |
202 size_t intial_channels_to_encode, | 199 size_t intial_channels_to_encode, |
203 int initial_frame_length_ms, | 200 int initial_frame_length_ms, |
204 int initial_bitrate_bps, | 201 int initial_bitrate_bps, |
205 bool initial_fec_enabled, | 202 bool initial_fec_enabled, |
206 bool initial_dtx_enabled, | 203 bool initial_dtx_enabled) { |
207 const Clock* clock) { | |
208 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP | 204 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
209 audio_network_adaptor::config::ControllerManager controller_manager_config; | 205 audio_network_adaptor::config::ControllerManager controller_manager_config; |
210 controller_manager_config.ParseFromString(config_string); | 206 controller_manager_config.ParseFromString(config_string); |
211 | 207 |
212 std::vector<std::unique_ptr<Controller>> controllers; | 208 std::vector<std::unique_ptr<Controller>> controllers; |
213 std::map<const Controller*, std::pair<int, float>> chracteristic_points; | 209 std::map<const Controller*, std::pair<int, float>> chracteristic_points; |
214 | 210 |
215 for (int i = 0; i < controller_manager_config.controllers_size(); ++i) { | 211 for (int i = 0; i < controller_manager_config.controllers_size(); ++i) { |
216 auto& controller_config = controller_manager_config.controllers(i); | 212 auto& controller_config = controller_manager_config.controllers(i); |
217 std::unique_ptr<Controller> controller; | 213 std::unique_ptr<Controller> controller; |
218 switch (controller_config.controller_case()) { | 214 switch (controller_config.controller_case()) { |
219 case audio_network_adaptor::config::Controller::kFecController: | 215 case audio_network_adaptor::config::Controller::kFecController: |
220 controller = CreateFecControllerPlrBased( | 216 controller = CreateFecControllerPlrBased( |
221 controller_config.fec_controller(), initial_fec_enabled, clock); | 217 controller_config.fec_controller(), initial_fec_enabled); |
222 break; | 218 break; |
223 case audio_network_adaptor::config::Controller::kFecControllerRplrBased: | 219 case audio_network_adaptor::config::Controller::kFecControllerRplrBased: |
224 controller = CreateFecControllerRplrBased( | 220 controller = CreateFecControllerRplrBased( |
225 controller_config.fec_controller_rplr_based(), initial_fec_enabled); | 221 controller_config.fec_controller_rplr_based(), initial_fec_enabled); |
226 break; | 222 break; |
227 case audio_network_adaptor::config::Controller::kFrameLengthController: | 223 case audio_network_adaptor::config::Controller::kFrameLengthController: |
228 controller = CreateFrameLengthController( | 224 controller = CreateFrameLengthController( |
229 controller_config.frame_length_controller(), | 225 controller_config.frame_length_controller(), |
230 encoder_frame_lengths_ms, initial_frame_length_ms, | 226 encoder_frame_lengths_ms, initial_frame_length_ms, |
231 min_encoder_bitrate_bps); | 227 min_encoder_bitrate_bps); |
(...skipping 23 matching lines...) Expand all Loading... |
255 characteristic_point.uplink_packet_loss_fraction()); | 251 characteristic_point.uplink_packet_loss_fraction()); |
256 } | 252 } |
257 controllers.push_back(std::move(controller)); | 253 controllers.push_back(std::move(controller)); |
258 } | 254 } |
259 | 255 |
260 RTC_CHECK(controller_manager_config.has_min_reordering_time_ms()); | 256 RTC_CHECK(controller_manager_config.has_min_reordering_time_ms()); |
261 RTC_CHECK(controller_manager_config.has_min_reordering_squared_distance()); | 257 RTC_CHECK(controller_manager_config.has_min_reordering_squared_distance()); |
262 return std::unique_ptr<ControllerManagerImpl>(new ControllerManagerImpl( | 258 return std::unique_ptr<ControllerManagerImpl>(new ControllerManagerImpl( |
263 ControllerManagerImpl::Config( | 259 ControllerManagerImpl::Config( |
264 controller_manager_config.min_reordering_time_ms(), | 260 controller_manager_config.min_reordering_time_ms(), |
265 controller_manager_config.min_reordering_squared_distance(), clock), | 261 controller_manager_config.min_reordering_squared_distance()), |
266 std::move(controllers), chracteristic_points)); | 262 std::move(controllers), chracteristic_points)); |
267 #else | 263 #else |
268 RTC_NOTREACHED(); | 264 RTC_NOTREACHED(); |
269 return nullptr; | 265 return nullptr; |
270 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP | 266 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
271 } | 267 } |
272 | 268 |
273 ControllerManagerImpl::ControllerManagerImpl(const Config& config) | 269 ControllerManagerImpl::ControllerManagerImpl(const Config& config) |
274 : ControllerManagerImpl( | 270 : ControllerManagerImpl( |
275 config, | 271 config, |
(...skipping 16 matching lines...) Expand all Loading... |
292 controller_scoring_points_.insert(std::make_pair( | 288 controller_scoring_points_.insert(std::make_pair( |
293 controller_point.first, ScoringPoint(controller_point.second.first, | 289 controller_point.first, ScoringPoint(controller_point.second.first, |
294 controller_point.second.second))); | 290 controller_point.second.second))); |
295 } | 291 } |
296 } | 292 } |
297 | 293 |
298 ControllerManagerImpl::~ControllerManagerImpl() = default; | 294 ControllerManagerImpl::~ControllerManagerImpl() = default; |
299 | 295 |
300 std::vector<Controller*> ControllerManagerImpl::GetSortedControllers( | 296 std::vector<Controller*> ControllerManagerImpl::GetSortedControllers( |
301 const Controller::NetworkMetrics& metrics) { | 297 const Controller::NetworkMetrics& metrics) { |
302 int64_t now_ms = config_.clock->TimeInMilliseconds(); | 298 int64_t now_ms = rtc::TimeMillis(); |
303 | 299 |
304 if (!metrics.uplink_bandwidth_bps || !metrics.uplink_packet_loss_fraction) | 300 if (!metrics.uplink_bandwidth_bps || !metrics.uplink_packet_loss_fraction) |
305 return sorted_controllers_; | 301 return sorted_controllers_; |
306 | 302 |
307 if (last_reordering_time_ms_ && | 303 if (last_reordering_time_ms_ && |
308 now_ms - *last_reordering_time_ms_ < config_.min_reordering_time_ms) | 304 now_ms - *last_reordering_time_ms_ < config_.min_reordering_time_ms) |
309 return sorted_controllers_; | 305 return sorted_controllers_; |
310 | 306 |
311 ScoringPoint scoring_point(*metrics.uplink_bandwidth_bps, | 307 ScoringPoint scoring_point(*metrics.uplink_bandwidth_bps, |
312 *metrics.uplink_packet_loss_fraction); | 308 *metrics.uplink_packet_loss_fraction); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 NormalizeUplinkBandwidth(scoring_point.uplink_bandwidth_bps) - | 382 NormalizeUplinkBandwidth(scoring_point.uplink_bandwidth_bps) - |
387 NormalizeUplinkBandwidth(uplink_bandwidth_bps); | 383 NormalizeUplinkBandwidth(uplink_bandwidth_bps); |
388 float diff_normalized_packet_loss = | 384 float diff_normalized_packet_loss = |
389 NormalizePacketLossFraction(scoring_point.uplink_packet_loss_fraction) - | 385 NormalizePacketLossFraction(scoring_point.uplink_packet_loss_fraction) - |
390 NormalizePacketLossFraction(uplink_packet_loss_fraction); | 386 NormalizePacketLossFraction(uplink_packet_loss_fraction); |
391 return std::pow(diff_normalized_bitrate_bps, 2) + | 387 return std::pow(diff_normalized_bitrate_bps, 2) + |
392 std::pow(diff_normalized_packet_loss, 2); | 388 std::pow(diff_normalized_packet_loss, 2); |
393 } | 389 } |
394 | 390 |
395 } // namespace webrtc | 391 } // namespace webrtc |
OLD | NEW |