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" |
| 17 #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/dtx_controller.h" |
| 20 #include "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller.h" |
| 21 #include "webrtc/modules/audio_coding/audio_network_adaptor/frame_length_control
ler.h" |
16 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
17 | 23 |
| 24 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 25 RTC_PUSH_IGNORING_WUNDEF() |
| 26 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| 27 #include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/conf
ig.pb.h" |
| 28 #else |
| 29 #include "webrtc/modules/audio_coding/audio_network_adaptor/config.pb.h" |
| 30 #endif |
| 31 RTC_POP_IGNORING_WUNDEF() |
| 32 #endif |
| 33 |
18 namespace webrtc { | 34 namespace webrtc { |
19 | 35 |
| 36 namespace { |
| 37 |
| 38 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 39 |
| 40 std::unique_ptr<FecController> CreateFecController( |
| 41 const audio_network_adaptor::config::FecController& config, |
| 42 bool initial_fec_enabled, |
| 43 const Clock* clock) { |
| 44 RTC_CHECK(config.has_fec_enabling_threshold()); |
| 45 RTC_CHECK(config.has_fec_disabling_threshold()); |
| 46 RTC_CHECK(config.has_time_constant_ms()); |
| 47 |
| 48 auto& fec_enabling_threshold = config.fec_enabling_threshold(); |
| 49 RTC_CHECK(fec_enabling_threshold.has_low_bandwidth_bps()); |
| 50 RTC_CHECK(fec_enabling_threshold.has_low_bandwidth_packet_loss()); |
| 51 RTC_CHECK(fec_enabling_threshold.has_high_bandwidth_bps()); |
| 52 RTC_CHECK(fec_enabling_threshold.has_high_bandwidth_packet_loss()); |
| 53 |
| 54 auto& fec_disabling_threshold = config.fec_disabling_threshold(); |
| 55 RTC_CHECK(fec_disabling_threshold.has_low_bandwidth_bps()); |
| 56 RTC_CHECK(fec_disabling_threshold.has_low_bandwidth_packet_loss()); |
| 57 RTC_CHECK(fec_disabling_threshold.has_high_bandwidth_bps()); |
| 58 RTC_CHECK(fec_disabling_threshold.has_high_bandwidth_packet_loss()); |
| 59 |
| 60 return std::unique_ptr<FecController>(new FecController(FecController::Config( |
| 61 initial_fec_enabled, |
| 62 FecController::Config::Threshold( |
| 63 fec_enabling_threshold.low_bandwidth_bps(), |
| 64 fec_enabling_threshold.low_bandwidth_packet_loss(), |
| 65 fec_enabling_threshold.high_bandwidth_bps(), |
| 66 fec_enabling_threshold.high_bandwidth_packet_loss()), |
| 67 FecController::Config::Threshold( |
| 68 fec_disabling_threshold.low_bandwidth_bps(), |
| 69 fec_disabling_threshold.low_bandwidth_packet_loss(), |
| 70 fec_disabling_threshold.high_bandwidth_bps(), |
| 71 fec_disabling_threshold.high_bandwidth_packet_loss()), |
| 72 config.has_time_constant_ms(), clock))); |
| 73 } |
| 74 |
| 75 std::unique_ptr<FrameLengthController> CreateFrameLengthController( |
| 76 const audio_network_adaptor::config::FrameLengthController& config, |
| 77 rtc::ArrayView<const int> encoder_frame_lengths_ms, |
| 78 int initial_frame_length_ms) { |
| 79 RTC_CHECK(config.has_fl_increasing_packet_loss_fraction()); |
| 80 RTC_CHECK(config.has_fl_decreasing_packet_loss_fraction()); |
| 81 RTC_CHECK(config.has_fl_20ms_to_60ms_bandwidth_bps()); |
| 82 RTC_CHECK(config.has_fl_60ms_to_20ms_bandwidth_bps()); |
| 83 |
| 84 FrameLengthController::Config ctor_config( |
| 85 std::vector<int>(), initial_frame_length_ms, |
| 86 config.fl_increasing_packet_loss_fraction(), |
| 87 config.fl_decreasing_packet_loss_fraction(), |
| 88 config.fl_20ms_to_60ms_bandwidth_bps(), |
| 89 config.fl_60ms_to_20ms_bandwidth_bps()); |
| 90 |
| 91 for (auto frame_length : encoder_frame_lengths_ms) |
| 92 ctor_config.encoder_frame_lengths_ms.push_back(frame_length); |
| 93 |
| 94 return std::unique_ptr<FrameLengthController>( |
| 95 new FrameLengthController(ctor_config)); |
| 96 } |
| 97 |
| 98 std::unique_ptr<ChannelController> CreateChannelController( |
| 99 const audio_network_adaptor::config::ChannelController& config, |
| 100 size_t num_encoder_channels, |
| 101 size_t intial_channels_to_encode) { |
| 102 RTC_CHECK(config.has_channel_1_to_2_bandwidth_bps()); |
| 103 RTC_CHECK(config.has_channel_2_to_1_bandwidth_bps()); |
| 104 |
| 105 return std::unique_ptr<ChannelController>(new ChannelController( |
| 106 ChannelController::Config(num_encoder_channels, intial_channels_to_encode, |
| 107 config.channel_1_to_2_bandwidth_bps(), |
| 108 config.channel_2_to_1_bandwidth_bps()))); |
| 109 } |
| 110 |
| 111 std::unique_ptr<DtxController> CreateDtxController( |
| 112 const audio_network_adaptor::config::DtxController& dtx_config, |
| 113 bool initial_dtx_enabled) { |
| 114 RTC_CHECK(dtx_config.has_dtx_enabling_bandwidth_bps()); |
| 115 RTC_CHECK(dtx_config.has_dtx_disabling_bandwidth_bps()); |
| 116 |
| 117 return std::unique_ptr<DtxController>(new DtxController(DtxController::Config( |
| 118 initial_dtx_enabled, dtx_config.dtx_enabling_bandwidth_bps(), |
| 119 dtx_config.dtx_disabling_bandwidth_bps()))); |
| 120 } |
| 121 |
| 122 using audio_network_adaptor::BitrateController; |
| 123 std::unique_ptr<BitrateController> CreateBitrateController( |
| 124 int initial_bitrate_bps, |
| 125 int initial_frame_length_ms) { |
| 126 return std::unique_ptr<BitrateController>(new BitrateController( |
| 127 BitrateController::Config(initial_bitrate_bps, initial_frame_length_ms))); |
| 128 } |
| 129 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 130 |
| 131 } // namespace |
| 132 |
20 ControllerManagerImpl::Config::Config(int min_reordering_time_ms, | 133 ControllerManagerImpl::Config::Config(int min_reordering_time_ms, |
21 float min_reordering_squared_distance, | 134 float min_reordering_squared_distance, |
22 const Clock* clock) | 135 const Clock* clock) |
23 : min_reordering_time_ms(min_reordering_time_ms), | 136 : min_reordering_time_ms(min_reordering_time_ms), |
24 min_reordering_squared_distance(min_reordering_squared_distance), | 137 min_reordering_squared_distance(min_reordering_squared_distance), |
25 clock(clock) {} | 138 clock(clock) {} |
26 | 139 |
27 ControllerManagerImpl::Config::~Config() = default; | 140 ControllerManagerImpl::Config::~Config() = default; |
28 | 141 |
| 142 std::unique_ptr<ControllerManager> ControllerManagerImpl::Create( |
| 143 const std::string& config_string, |
| 144 size_t num_encoder_channels, |
| 145 rtc::ArrayView<const int> encoder_frame_lengths_ms, |
| 146 size_t intial_channels_to_encode, |
| 147 int initial_frame_length_ms, |
| 148 int initial_bitrate_bps, |
| 149 bool initial_fec_enabled, |
| 150 bool initial_dtx_enabled, |
| 151 const Clock* clock) { |
| 152 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 153 audio_network_adaptor::config::ControllerManager controller_manager_config; |
| 154 controller_manager_config.ParseFromString(config_string); |
| 155 |
| 156 std::vector<std::unique_ptr<Controller>> controllers; |
| 157 std::map<const Controller*, std::pair<int, float>> chracteristic_points; |
| 158 |
| 159 for (int i = 0; i < controller_manager_config.controllers_size(); ++i) { |
| 160 auto& controller_config = controller_manager_config.controllers(i); |
| 161 std::unique_ptr<Controller> controller; |
| 162 switch (controller_config.controller_case()) { |
| 163 case audio_network_adaptor::config::Controller::kFecController: |
| 164 controller = CreateFecController(controller_config.fec_controller(), |
| 165 initial_fec_enabled, clock); |
| 166 break; |
| 167 case audio_network_adaptor::config::Controller::kFrameLengthController: |
| 168 controller = CreateFrameLengthController( |
| 169 controller_config.frame_length_controller(), |
| 170 encoder_frame_lengths_ms, initial_frame_length_ms); |
| 171 break; |
| 172 case audio_network_adaptor::config::Controller::kChannelController: |
| 173 controller = CreateChannelController( |
| 174 controller_config.channel_controller(), num_encoder_channels, |
| 175 intial_channels_to_encode); |
| 176 break; |
| 177 case audio_network_adaptor::config::Controller::kDtxController: |
| 178 controller = CreateDtxController(controller_config.dtx_controller(), |
| 179 initial_dtx_enabled); |
| 180 break; |
| 181 case audio_network_adaptor::config::Controller::kBitrateController: |
| 182 controller = CreateBitrateController(initial_bitrate_bps, |
| 183 initial_frame_length_ms); |
| 184 break; |
| 185 default: |
| 186 RTC_NOTREACHED(); |
| 187 } |
| 188 if (controller_config.has_scoring_point()) { |
| 189 auto& characteristic_point = controller_config.scoring_point(); |
| 190 RTC_CHECK(characteristic_point.has_uplink_bandwidth_bps()); |
| 191 RTC_CHECK(characteristic_point.has_uplink_packet_loss_fraction()); |
| 192 chracteristic_points[controller.get()] = std::make_pair<int, float>( |
| 193 characteristic_point.uplink_bandwidth_bps(), |
| 194 characteristic_point.uplink_packet_loss_fraction()); |
| 195 } |
| 196 controllers.push_back(std::move(controller)); |
| 197 } |
| 198 |
| 199 RTC_CHECK(controller_manager_config.has_min_reordering_time_ms()); |
| 200 RTC_CHECK(controller_manager_config.has_min_reordering_squared_distance()); |
| 201 return std::unique_ptr<ControllerManagerImpl>(new ControllerManagerImpl( |
| 202 ControllerManagerImpl::Config( |
| 203 controller_manager_config.min_reordering_time_ms(), |
| 204 controller_manager_config.min_reordering_squared_distance(), clock), |
| 205 std::move(controllers), chracteristic_points)); |
| 206 #else |
| 207 RTC_NOTREACHED(); |
| 208 return nullptr; |
| 209 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP |
| 210 } |
| 211 |
29 ControllerManagerImpl::ControllerManagerImpl(const Config& config) | 212 ControllerManagerImpl::ControllerManagerImpl(const Config& config) |
30 : ControllerManagerImpl( | 213 : ControllerManagerImpl( |
31 config, | 214 config, |
32 std::vector<std::unique_ptr<Controller>>(), | 215 std::vector<std::unique_ptr<Controller>>(), |
33 std::map<const Controller*, std::pair<int, float>>()) {} | 216 std::map<const Controller*, std::pair<int, float>>()) {} |
34 | 217 |
35 ControllerManagerImpl::ControllerManagerImpl( | 218 ControllerManagerImpl::ControllerManagerImpl( |
36 const Config& config, | 219 const Config& config, |
37 std::vector<std::unique_ptr<Controller>>&& controllers, | 220 std::vector<std::unique_ptr<Controller>>&& controllers, |
38 const std::map<const Controller*, std::pair<int, float>>& | 221 const std::map<const Controller*, std::pair<int, float>>& |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 NormalizeUplinkBandwidth(scoring_point.uplink_bandwidth_bps) - | 325 NormalizeUplinkBandwidth(scoring_point.uplink_bandwidth_bps) - |
143 NormalizeUplinkBandwidth(uplink_bandwidth_bps); | 326 NormalizeUplinkBandwidth(uplink_bandwidth_bps); |
144 float diff_normalized_packet_loss = | 327 float diff_normalized_packet_loss = |
145 NormalizePacketLossFraction(scoring_point.uplink_packet_loss_fraction) - | 328 NormalizePacketLossFraction(scoring_point.uplink_packet_loss_fraction) - |
146 NormalizePacketLossFraction(uplink_packet_loss_fraction); | 329 NormalizePacketLossFraction(uplink_packet_loss_fraction); |
147 return std::pow(diff_normalized_bitrate_bps, 2) + | 330 return std::pow(diff_normalized_bitrate_bps, 2) + |
148 std::pow(diff_normalized_packet_loss, 2); | 331 std::pow(diff_normalized_packet_loss, 2); |
149 } | 332 } |
150 | 333 |
151 } // namespace webrtc | 334 } // namespace webrtc |
OLD | NEW |