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

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: 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_DCHECK(config.has_fec_enabling_threshold() &&
42 config.has_fec_disabling_threshold() &&
43 config.has_time_constant_ms());
kwiberg-webrtc 2016/09/28 08:59:22 Perfer to do CHECK(a); CHECK(b); instead of
minyue-webrtc 2016/09/28 12:47:26 Done.
44
45 auto fec_enabling_threshold = config.fec_enabling_threshold();
hlundin-webrtc 2016/09/27 20:21:15 Why create this copy?
minyue-webrtc 2016/09/27 20:50:20 right. should be auto&
46 RTC_DCHECK(fec_enabling_threshold.has_low_bandwidth_bps() &&
47 fec_enabling_threshold.has_low_bandwidth_packet_loss() &&
48 fec_enabling_threshold.has_high_bandwidth_bps() &&
49 fec_enabling_threshold.has_high_bandwidth_packet_loss());
kwiberg-webrtc 2016/09/28 08:59:22 What will happen if you read a protobuf variable t
minyue-webrtc 2016/09/29 11:56:26 Done.
50
51 auto fec_disabling_threshold = config.fec_disabling_threshold();
52 RTC_DCHECK(fec_disabling_threshold.has_low_bandwidth_bps() &&
53 fec_disabling_threshold.has_low_bandwidth_packet_loss() &&
54 fec_disabling_threshold.has_high_bandwidth_bps() &&
55 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(
hlundin-webrtc 2016/09/27 20:21:15 What is the type for fec_enabling_threshold? Isn't
minyue-webrtc 2016/09/27 20:50:20 because this functions are mainly converting from
kwiberg-webrtc 2016/09/28 08:59:22 Why do you convert?
minyue-webrtc 2016/09/28 12:47:26 Any better ideas?
kwiberg-webrtc 2016/09/28 13:10:24 Using protobuf directly, instead of converting it
minyue-webrtc 2016/09/28 16:32:34 We thought about using protobuf for all Controller
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 const std::vector<int>& encoder_frame_lengths_ms,
75 int initial_frame_length_ms) {
76 RTC_DCHECK(config.has_fl_increasing_packet_loss_fraction() &&
77 config.has_fl_decreasing_packet_loss_fraction() &&
78 config.has_fl_20ms_to_60ms_bandwidth_bps() &&
79 config.has_fl_60ms_to_20ms_bandwidth_bps());
80
81 return std::unique_ptr<FrameLengthController>(
82 new FrameLengthController(FrameLengthController::Config(
83 encoder_frame_lengths_ms, initial_frame_length_ms,
84 config.fl_increasing_packet_loss_fraction(),
85 config.fl_decreasing_packet_loss_fraction(),
86 config.fl_20ms_to_60ms_bandwidth_bps(),
87 config.fl_60ms_to_20ms_bandwidth_bps())));
88 }
89
90 std::unique_ptr<ChannelController> CreateChannelController(
91 const audio_network_adaptor::config::ChannelController& config,
92 size_t num_encoder_channels,
93 size_t intial_channels_to_encode) {
94 RTC_DCHECK(config.has_channel_1_to_2_bandwidth_bps() &&
95 config.has_channel_2_to_1_bandwidth_bps());
96
97 return std::unique_ptr<ChannelController>(new ChannelController(
98 ChannelController::Config(num_encoder_channels, intial_channels_to_encode,
99 config.channel_1_to_2_bandwidth_bps(),
100 config.channel_2_to_1_bandwidth_bps())));
101 }
102
103 std::unique_ptr<DtxController> CreateDtxController(
104 const audio_network_adaptor::config::DtxController& dtx_config,
105 bool initial_dtx_enabled) {
106 RTC_DCHECK(dtx_config.has_dtx_enabling_bandwidth_bps() &&
107 dtx_config.has_dtx_disabling_bandwidth_bps());
108
109 return std::unique_ptr<DtxController>(new DtxController(DtxController::Config(
110 initial_dtx_enabled, dtx_config.dtx_enabling_bandwidth_bps(),
111 dtx_config.dtx_disabling_bandwidth_bps())));
112 }
113
114 using audio_network_adaptor::BitrateController;
115 std::unique_ptr<BitrateController> CreateBitrateController(
116 int initial_bitrate_bps,
117 int initial_frame_length_ms) {
118 return std::unique_ptr<BitrateController>(new BitrateController(
119 BitrateController::Config(initial_bitrate_bps, initial_frame_length_ms)));
120 }
121 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
122
123 } // namespace
124
20 ControllerManagerImpl::Config::Config(int min_reordering_time_ms, 125 ControllerManagerImpl::Config::Config(int min_reordering_time_ms,
21 float min_reordering_squared_distance, 126 float min_reordering_squared_distance,
22 const Clock* clock) 127 const Clock* clock)
23 : min_reordering_time_ms(min_reordering_time_ms), 128 : min_reordering_time_ms(min_reordering_time_ms),
24 min_reordering_squared_distance(min_reordering_squared_distance), 129 min_reordering_squared_distance(min_reordering_squared_distance),
25 clock(clock) {} 130 clock(clock) {}
26 131
27 ControllerManagerImpl::Config::~Config() = default; 132 ControllerManagerImpl::Config::~Config() = default;
28 133
134 std::unique_ptr<ControllerManager> ControllerManagerImpl::Create(
135 const std::string& config_string,
136 size_t num_encoder_channels,
137 const std::vector<int>& encoder_frame_lengths_ms,
138 size_t intial_channels_to_encode,
139 int initial_frame_length_ms,
140 int initial_bitrate_bps,
141 bool initial_fec_enabled,
142 bool initial_dtx_enabled,
143 const Clock* clock) {
144 #ifdef WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
145 audio_network_adaptor::config::ControllerManager controller_manager_config;
146 controller_manager_config.ParseFromString(config_string);
147
148 std::vector<std::unique_ptr<Controller>> controllers;
149 std::map<const Controller*, std::pair<int, float>> chracteristic_points;
150
151 for (int i = 0; i < controller_manager_config.controllers_size(); ++i) {
152 auto controller_config = controller_manager_config.controllers(i);
153 std::unique_ptr<Controller> controller;
154 switch (controller_config.controller_case()) {
155 case audio_network_adaptor::config::Controller::kFecController:
156 controller = CreateFecController(controller_config.fec_controller(),
157 initial_fec_enabled, clock);
158 break;
159 case audio_network_adaptor::config::Controller::kFrameLengthController:
160 controller = CreateFrameLengthController(
161 controller_config.frame_length_controller(),
162 encoder_frame_lengths_ms, initial_frame_length_ms);
163 break;
164 case audio_network_adaptor::config::Controller::kChannelController:
165 controller = CreateChannelController(
166 controller_config.channel_controller(), num_encoder_channels,
167 intial_channels_to_encode);
168 break;
169 case audio_network_adaptor::config::Controller::kDtxController:
170 controller = CreateDtxController(controller_config.dtx_controller(),
171 initial_dtx_enabled);
172 break;
173 case audio_network_adaptor::config::Controller::kBitrateController:
174 controller = CreateBitrateController(initial_bitrate_bps,
175 initial_frame_length_ms);
176 break;
177 default:
hlundin-webrtc 2016/09/27 20:21:15 What is controller_config.controller_case()? Is it
minyue-webrtc 2016/09/27 20:50:20 yes, it is enum generated by protobuf. It has an a
hlundin-webrtc 2016/09/29 09:31:52 Then I think RTC_NOTREACHED() is the correct way.
minyue-webrtc 2016/09/29 11:56:26 Done.
178 RTC_DCHECK(false);
kwiberg-webrtc 2016/09/28 08:59:22 RTC_NOTREACHED?
minyue-webrtc 2016/09/29 11:56:26 Done.
179 }
180 if (controller_config.has_scoring_point()) {
181 auto characteristic_point = controller_config.scoring_point();
182 RTC_DCHECK(characteristic_point.has_uplink_bandwidth_bps());
183 RTC_DCHECK(characteristic_point.has_uplink_packet_loss_fraction());
184 chracteristic_points[controller.get()] = std::make_pair<int, float>(
185 characteristic_point.uplink_bandwidth_bps(),
186 characteristic_point.uplink_packet_loss_fraction());
187 }
188 controllers.push_back(std::move(controller));
189 }
190
191 RTC_DCHECK(controller_manager_config.has_min_reordering_time_ms());
192 RTC_DCHECK(controller_manager_config.has_min_reordering_squared_distance());
193 return std::unique_ptr<ControllerManagerImpl>(new ControllerManagerImpl(
194 ControllerManagerImpl::Config(
195 controller_manager_config.min_reordering_time_ms(),
196 controller_manager_config.min_reordering_squared_distance(), clock),
197 std::move(controllers), chracteristic_points));
198 #else
199 RTC_DCHECK(false);
hlundin-webrtc 2016/09/27 20:21:15 RTC_NOTREACHED?
minyue-webrtc 2016/09/27 20:50:20 ok, will do.
200 return nullptr;
201 #endif // WEBRTC_AUDIO_NETWORK_ADAPTOR_DEBUG_DUMP
202 }
203
29 ControllerManagerImpl::ControllerManagerImpl(const Config& config) 204 ControllerManagerImpl::ControllerManagerImpl(const Config& config)
30 : ControllerManagerImpl( 205 : ControllerManagerImpl(
31 config, 206 config,
32 std::vector<std::unique_ptr<Controller>>(), 207 std::vector<std::unique_ptr<Controller>>(),
33 std::map<const Controller*, std::pair<int, float>>()) {} 208 std::map<const Controller*, std::pair<int, float>>()) {}
34 209
35 ControllerManagerImpl::ControllerManagerImpl( 210 ControllerManagerImpl::ControllerManagerImpl(
36 const Config& config, 211 const Config& config,
37 std::vector<std::unique_ptr<Controller>>&& controllers, 212 std::vector<std::unique_ptr<Controller>>&& controllers,
38 const std::map<const Controller*, std::pair<int, float>>& 213 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) - 317 NormalizeUplinkBandwidth(scoring_point.uplink_bandwidth_bps) -
143 NormalizeUplinkBandwidth(uplink_bandwidth_bps); 318 NormalizeUplinkBandwidth(uplink_bandwidth_bps);
144 float diff_normalized_packet_loss = 319 float diff_normalized_packet_loss =
145 NormalizePacketLossFraction(scoring_point.uplink_packet_loss_fraction) - 320 NormalizePacketLossFraction(scoring_point.uplink_packet_loss_fraction) -
146 NormalizePacketLossFraction(uplink_packet_loss_fraction); 321 NormalizePacketLossFraction(uplink_packet_loss_fraction);
147 return std::pow(diff_normalized_bitrate_bps, 2) + 322 return std::pow(diff_normalized_bitrate_bps, 2) +
148 std::pow(diff_normalized_packet_loss, 2); 323 std::pow(diff_normalized_packet_loss, 2);
149 } 324 }
150 325
151 } // namespace webrtc 326 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698