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/audio_network_adapto r_impl.h" | 11 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto r_impl.h" |
12 | 12 |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "webrtc/rtc_base/logging.h" | 15 #include "webrtc/rtc_base/logging.h" |
16 #include "webrtc/rtc_base/timeutils.h" | 16 #include "webrtc/rtc_base/timeutils.h" |
17 #include "webrtc/system_wrappers/include/field_trial.h" | |
17 | 18 |
18 namespace webrtc { | 19 namespace webrtc { |
19 | 20 |
20 namespace { | 21 namespace { |
21 constexpr int kEventLogMinBitrateChangeBps = 5000; | 22 constexpr int kEventLogMinBitrateChangeBps = 5000; |
22 constexpr float kEventLogMinBitrateChangeFraction = 0.25; | 23 constexpr float kEventLogMinBitrateChangeFraction = 0.25; |
23 constexpr float kEventLogMinPacketLossChangeFraction = 0.5; | 24 constexpr float kEventLogMinPacketLossChangeFraction = 0.5; |
24 } // namespace | 25 } // namespace |
25 | 26 |
26 AudioNetworkAdaptorImpl::Config::Config() : event_log(nullptr){}; | 27 AudioNetworkAdaptorImpl::Config::Config() : event_log(nullptr){}; |
27 | 28 |
28 AudioNetworkAdaptorImpl::Config::~Config() = default; | 29 AudioNetworkAdaptorImpl::Config::~Config() = default; |
29 | 30 |
30 AudioNetworkAdaptorImpl::AudioNetworkAdaptorImpl( | 31 AudioNetworkAdaptorImpl::AudioNetworkAdaptorImpl( |
31 const Config& config, | 32 const Config& config, |
32 std::unique_ptr<ControllerManager> controller_manager, | 33 std::unique_ptr<ControllerManager> controller_manager, |
33 std::unique_ptr<DebugDumpWriter> debug_dump_writer) | 34 std::unique_ptr<DebugDumpWriter> debug_dump_writer) |
34 : config_(config), | 35 : config_(config), |
35 controller_manager_(std::move(controller_manager)), | 36 controller_manager_(std::move(controller_manager)), |
36 debug_dump_writer_(std::move(debug_dump_writer)), | 37 debug_dump_writer_(std::move(debug_dump_writer)), |
37 event_log_writer_( | 38 event_log_writer_( |
38 config.event_log | 39 config.event_log |
39 ? new EventLogWriter(config.event_log, | 40 ? new EventLogWriter(config.event_log, |
40 kEventLogMinBitrateChangeBps, | 41 kEventLogMinBitrateChangeBps, |
41 kEventLogMinBitrateChangeFraction, | 42 kEventLogMinBitrateChangeFraction, |
42 kEventLogMinPacketLossChangeFraction) | 43 kEventLogMinPacketLossChangeFraction) |
43 : nullptr) { | 44 : nullptr), |
45 enable_bitrate_adaptation_( | |
46 webrtc::field_trial::IsEnabled("WebRTC-Audio-BitrateAdaptation")), | |
47 enable_dtx_adaptation_( | |
48 webrtc::field_trial::IsEnabled("WebRTC-Audio-DtxAdaptation")), | |
49 enable_fec_adaptation_( | |
50 webrtc::field_trial::IsEnabled("WebRTC-Audio-FecAdaptation")), | |
51 enable_channel_adaptation_( | |
52 webrtc::field_trial::IsEnabled("WebRTC-Audio-ChannelAdaptation")), | |
53 enable_frame_length_adaptation_(webrtc::field_trial::IsEnabled( | |
54 "WebRTC-Audio-FrameLengthAdaptation")) { | |
44 RTC_DCHECK(controller_manager_); | 55 RTC_DCHECK(controller_manager_); |
45 } | 56 } |
46 | 57 |
47 AudioNetworkAdaptorImpl::~AudioNetworkAdaptorImpl() = default; | 58 AudioNetworkAdaptorImpl::~AudioNetworkAdaptorImpl() = default; |
48 | 59 |
49 void AudioNetworkAdaptorImpl::SetUplinkBandwidth(int uplink_bandwidth_bps) { | 60 void AudioNetworkAdaptorImpl::SetUplinkBandwidth(int uplink_bandwidth_bps) { |
50 last_metrics_.uplink_bandwidth_bps = rtc::Optional<int>(uplink_bandwidth_bps); | 61 last_metrics_.uplink_bandwidth_bps = rtc::Optional<int>(uplink_bandwidth_bps); |
51 DumpNetworkMetrics(); | 62 DumpNetworkMetrics(); |
52 | 63 |
53 Controller::NetworkMetrics network_metrics; | 64 Controller::NetworkMetrics network_metrics; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 rtc::Optional<size_t>(overhead_bytes_per_packet); | 122 rtc::Optional<size_t>(overhead_bytes_per_packet); |
112 UpdateNetworkMetrics(network_metrics); | 123 UpdateNetworkMetrics(network_metrics); |
113 } | 124 } |
114 | 125 |
115 AudioEncoderRuntimeConfig AudioNetworkAdaptorImpl::GetEncoderRuntimeConfig() { | 126 AudioEncoderRuntimeConfig AudioNetworkAdaptorImpl::GetEncoderRuntimeConfig() { |
116 AudioEncoderRuntimeConfig config; | 127 AudioEncoderRuntimeConfig config; |
117 for (auto& controller : | 128 for (auto& controller : |
118 controller_manager_->GetSortedControllers(last_metrics_)) | 129 controller_manager_->GetSortedControllers(last_metrics_)) |
119 controller->MakeDecision(&config); | 130 controller->MakeDecision(&config); |
120 | 131 |
132 // Update ANA stats. | |
133 auto increment_opt = [](rtc::Optional<uint32_t>& a) { | |
134 if (a) | |
135 (*a)++; | |
136 else | |
137 a = rtc::Optional<uint32_t>(1); | |
ossu
2017/09/08 10:56:01
I think you could just do a = a.value_or(0) + 1 as
ivoc
2017/09/08 11:43:47
Nice! Done, although I needed to wrap the result i
ossu
2017/09/08 12:05:21
Ah, that's right. I'll try to look at getting a ne
| |
138 }; | |
139 if (prev_config_) { | |
140 if (config.bitrate_bps != prev_config_->bitrate_bps) { | |
141 increment_opt(stats_.bitrate_action_counter); | |
142 } | |
143 if (config.enable_dtx != prev_config_->enable_dtx) { | |
144 increment_opt(stats_.dtx_action_counter); | |
145 } | |
146 if (config.enable_fec != prev_config_->enable_fec) { | |
147 increment_opt(stats_.fec_action_counter); | |
148 } | |
149 if (config.frame_length_ms && prev_config_->frame_length_ms) { | |
150 if (*config.frame_length_ms > *prev_config_->frame_length_ms) { | |
151 increment_opt(stats_.frame_length_increase_counter); | |
152 } else if (*config.frame_length_ms < *prev_config_->frame_length_ms) { | |
153 increment_opt(stats_.frame_length_decrease_counter); | |
154 } | |
155 } | |
156 if (config.num_channels != prev_config_->num_channels) { | |
157 increment_opt(stats_.channel_action_counter); | |
158 } | |
159 if (config.uplink_packet_loss_fraction) { | |
160 stats_.uplink_packet_loss_fraction = rtc::Optional<double>( | |
161 static_cast<double>(*config.uplink_packet_loss_fraction)); | |
ossu
2017/09/08 10:56:01
Why does this need a static_cast? Why isn't uplink
ivoc
2017/09/08 11:43:47
That's a good point, I changed the stat into a flo
| |
162 } | |
163 } | |
164 prev_config_ = rtc::Optional<AudioEncoderRuntimeConfig>(config); | |
165 | |
166 // Prevent certain controllers from taking action (determined by field trials) | |
167 if (!enable_bitrate_adaptation_ && config.bitrate_bps) { | |
168 config.bitrate_bps = rtc::Optional<int>(); | |
ossu
2017/09/08 10:56:01
You can use .reset() to empty Optionals and save o
ivoc
2017/09/08 11:43:47
Done!
| |
169 } | |
170 if (!enable_dtx_adaptation_ && config.enable_dtx) { | |
171 config.enable_dtx = rtc::Optional<bool>(); | |
172 } | |
173 if (!enable_fec_adaptation_ && config.enable_fec) { | |
174 config.enable_fec = rtc::Optional<bool>(); | |
175 config.uplink_packet_loss_fraction = rtc::Optional<float>(); | |
176 } | |
177 if (!enable_frame_length_adaptation_ && config.frame_length_ms) { | |
178 config.frame_length_ms = rtc::Optional<int>(); | |
179 } | |
180 if (!enable_channel_adaptation_ && config.num_channels) { | |
181 config.num_channels = rtc::Optional<size_t>(); | |
182 } | |
183 | |
121 if (debug_dump_writer_) | 184 if (debug_dump_writer_) |
122 debug_dump_writer_->DumpEncoderRuntimeConfig(config, rtc::TimeMillis()); | 185 debug_dump_writer_->DumpEncoderRuntimeConfig(config, rtc::TimeMillis()); |
123 | 186 |
124 if (event_log_writer_) | 187 if (event_log_writer_) |
125 event_log_writer_->MaybeLogEncoderConfig(config); | 188 event_log_writer_->MaybeLogEncoderConfig(config); |
126 | 189 |
127 return config; | 190 return config; |
128 } | 191 } |
129 | 192 |
130 void AudioNetworkAdaptorImpl::StartDebugDump(FILE* file_handle) { | 193 void AudioNetworkAdaptorImpl::StartDebugDump(FILE* file_handle) { |
131 debug_dump_writer_ = DebugDumpWriter::Create(file_handle); | 194 debug_dump_writer_ = DebugDumpWriter::Create(file_handle); |
132 } | 195 } |
133 | 196 |
134 void AudioNetworkAdaptorImpl::StopDebugDump() { | 197 void AudioNetworkAdaptorImpl::StopDebugDump() { |
135 debug_dump_writer_.reset(nullptr); | 198 debug_dump_writer_.reset(nullptr); |
136 } | 199 } |
137 | 200 |
138 ANAStats AudioNetworkAdaptorImpl::GetStats() const { | 201 ANAStats AudioNetworkAdaptorImpl::GetStats() const { |
139 // TODO(ivoc): Actually implement the stat. | 202 return stats_; |
140 // Tracking bug: https://bugs.chromium.org/p/webrtc/issues/detail?id=8127 | |
141 return ANAStats(); | |
142 } | 203 } |
143 | 204 |
144 void AudioNetworkAdaptorImpl::DumpNetworkMetrics() { | 205 void AudioNetworkAdaptorImpl::DumpNetworkMetrics() { |
145 if (debug_dump_writer_) | 206 if (debug_dump_writer_) |
146 debug_dump_writer_->DumpNetworkMetrics(last_metrics_, rtc::TimeMillis()); | 207 debug_dump_writer_->DumpNetworkMetrics(last_metrics_, rtc::TimeMillis()); |
147 } | 208 } |
148 | 209 |
149 void AudioNetworkAdaptorImpl::UpdateNetworkMetrics( | 210 void AudioNetworkAdaptorImpl::UpdateNetworkMetrics( |
150 const Controller::NetworkMetrics& network_metrics) { | 211 const Controller::NetworkMetrics& network_metrics) { |
151 for (auto& controller : controller_manager_->GetControllers()) | 212 for (auto& controller : controller_manager_->GetControllers()) |
152 controller->UpdateNetworkMetrics(network_metrics); | 213 controller->UpdateNetworkMetrics(network_metrics); |
153 } | 214 } |
154 | 215 |
155 } // namespace webrtc | 216 } // namespace webrtc |
OLD | NEW |