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

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

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

Powered by Google App Engine
This is Rietveld 408576698