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

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

Issue 3007983002: Implement ANA statistics. (Closed)
Patch Set: Fix for failing unittests. Created 3 years, 3 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/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
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 a = rtc::Optional<uint32_t>(a.value_or(0) + 1);
135 };
136 if (prev_config_) {
137 if (config.bitrate_bps != prev_config_->bitrate_bps) {
138 increment_opt(stats_.bitrate_action_counter);
139 }
140 if (config.enable_dtx != prev_config_->enable_dtx) {
141 increment_opt(stats_.dtx_action_counter);
142 }
143 if (config.enable_fec != prev_config_->enable_fec) {
144 increment_opt(stats_.fec_action_counter);
145 }
146 if (config.frame_length_ms && prev_config_->frame_length_ms) {
147 if (*config.frame_length_ms > *prev_config_->frame_length_ms) {
148 increment_opt(stats_.frame_length_increase_counter);
149 } else if (*config.frame_length_ms < *prev_config_->frame_length_ms) {
150 increment_opt(stats_.frame_length_decrease_counter);
151 }
152 }
153 if (config.num_channels != prev_config_->num_channels) {
154 increment_opt(stats_.channel_action_counter);
155 }
156 if (config.uplink_packet_loss_fraction) {
157 stats_.uplink_packet_loss_fraction =
158 rtc::Optional<float>(*config.uplink_packet_loss_fraction);
159 }
160 }
161 prev_config_ = rtc::Optional<AudioEncoderRuntimeConfig>(config);
162
163 // Prevent certain controllers from taking action (determined by field trials)
164 if (!enable_bitrate_adaptation_ && config.bitrate_bps) {
165 config.bitrate_bps.reset();
166 }
167 if (!enable_dtx_adaptation_ && config.enable_dtx) {
168 config.enable_dtx.reset();
169 }
170 if (!enable_fec_adaptation_ && config.enable_fec) {
171 config.enable_fec.reset();
172 config.uplink_packet_loss_fraction.reset();
173 }
174 if (!enable_frame_length_adaptation_ && config.frame_length_ms) {
175 config.frame_length_ms.reset();
176 }
177 if (!enable_channel_adaptation_ && config.num_channels) {
178 config.num_channels.reset();
179 }
180
121 if (debug_dump_writer_) 181 if (debug_dump_writer_)
122 debug_dump_writer_->DumpEncoderRuntimeConfig(config, rtc::TimeMillis()); 182 debug_dump_writer_->DumpEncoderRuntimeConfig(config, rtc::TimeMillis());
123 183
124 if (event_log_writer_) 184 if (event_log_writer_)
125 event_log_writer_->MaybeLogEncoderConfig(config); 185 event_log_writer_->MaybeLogEncoderConfig(config);
126 186
127 return config; 187 return config;
128 } 188 }
129 189
130 void AudioNetworkAdaptorImpl::StartDebugDump(FILE* file_handle) { 190 void AudioNetworkAdaptorImpl::StartDebugDump(FILE* file_handle) {
131 debug_dump_writer_ = DebugDumpWriter::Create(file_handle); 191 debug_dump_writer_ = DebugDumpWriter::Create(file_handle);
132 } 192 }
133 193
134 void AudioNetworkAdaptorImpl::StopDebugDump() { 194 void AudioNetworkAdaptorImpl::StopDebugDump() {
135 debug_dump_writer_.reset(nullptr); 195 debug_dump_writer_.reset(nullptr);
136 } 196 }
137 197
138 ANAStats AudioNetworkAdaptorImpl::GetStats() const { 198 ANAStats AudioNetworkAdaptorImpl::GetStats() const {
139 // TODO(ivoc): Actually implement the stat. 199 return stats_;
140 // Tracking bug: https://crbug.com/webrtc/8127
141 return ANAStats();
142 } 200 }
143 201
144 void AudioNetworkAdaptorImpl::DumpNetworkMetrics() { 202 void AudioNetworkAdaptorImpl::DumpNetworkMetrics() {
145 if (debug_dump_writer_) 203 if (debug_dump_writer_)
146 debug_dump_writer_->DumpNetworkMetrics(last_metrics_, rtc::TimeMillis()); 204 debug_dump_writer_->DumpNetworkMetrics(last_metrics_, rtc::TimeMillis());
147 } 205 }
148 206
149 void AudioNetworkAdaptorImpl::UpdateNetworkMetrics( 207 void AudioNetworkAdaptorImpl::UpdateNetworkMetrics(
150 const Controller::NetworkMetrics& network_metrics) { 208 const Controller::NetworkMetrics& network_metrics) {
151 for (auto& controller : controller_manager_->GetControllers()) 209 for (auto& controller : controller_manager_->GetControllers())
152 controller->UpdateNetworkMetrics(network_metrics); 210 controller->UpdateNetworkMetrics(network_metrics);
153 } 211 }
154 212
155 } // namespace webrtc 213 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698