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

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

Issue 3007983002: Implement ANA statistics. (Closed)
Patch Set: 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) {
44 RTC_DCHECK(controller_manager_); 45 RTC_DCHECK(controller_manager_);
46 // Set the field trial flags to determine if adaptation is enabled.
47 enable_bitrate_adaptation_ =
48 webrtc::field_trial::IsEnabled("WebRTC-Audio-BitrateAdaptation");
49 enable_channel_adaptation_ =
50 webrtc::field_trial::IsEnabled("WebRTC-Audio-ChannelAdaptation");
51 enable_dtx_adaptation_ =
52 webrtc::field_trial::IsEnabled("WebRTC-Audio-DtxAdaptation");
53 enable_fec_adaptation_ =
54 webrtc::field_trial::IsEnabled("WebRTC-Audio-FecAdaptation");
55 enable_frame_length_adaptation_ =
56 webrtc::field_trial::IsEnabled("WebRTC-Audio-FrameLengthAdaptation");
45 } 57 }
46 58
47 AudioNetworkAdaptorImpl::~AudioNetworkAdaptorImpl() = default; 59 AudioNetworkAdaptorImpl::~AudioNetworkAdaptorImpl() = default;
48 60
49 void AudioNetworkAdaptorImpl::SetUplinkBandwidth(int uplink_bandwidth_bps) { 61 void AudioNetworkAdaptorImpl::SetUplinkBandwidth(int uplink_bandwidth_bps) {
50 last_metrics_.uplink_bandwidth_bps = rtc::Optional<int>(uplink_bandwidth_bps); 62 last_metrics_.uplink_bandwidth_bps = rtc::Optional<int>(uplink_bandwidth_bps);
51 DumpNetworkMetrics(); 63 DumpNetworkMetrics();
52 64
53 Controller::NetworkMetrics network_metrics; 65 Controller::NetworkMetrics network_metrics;
54 network_metrics.uplink_bandwidth_bps = 66 network_metrics.uplink_bandwidth_bps =
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 rtc::Optional<size_t>(overhead_bytes_per_packet); 123 rtc::Optional<size_t>(overhead_bytes_per_packet);
112 UpdateNetworkMetrics(network_metrics); 124 UpdateNetworkMetrics(network_metrics);
113 } 125 }
114 126
115 AudioEncoderRuntimeConfig AudioNetworkAdaptorImpl::GetEncoderRuntimeConfig() { 127 AudioEncoderRuntimeConfig AudioNetworkAdaptorImpl::GetEncoderRuntimeConfig() {
116 AudioEncoderRuntimeConfig config; 128 AudioEncoderRuntimeConfig config;
117 for (auto& controller : 129 for (auto& controller :
118 controller_manager_->GetSortedControllers(last_metrics_)) 130 controller_manager_->GetSortedControllers(last_metrics_))
119 controller->MakeDecision(&config); 131 controller->MakeDecision(&config);
120 132
133 // Update ANA stats.
134 auto increment_opt = [](rtc::Optional<int>& a) {
135 if (a)
136 (*a)++;
137 else
138 a = rtc::Optional<int>(1);
139 };
140 if (prev_config_) {
141 if (config.bitrate_bps != prev_config_->bitrate_bps) {
142 increment_opt(stats_.ana_bitrate_action_counter);
143 }
144 if (config.enable_dtx != prev_config_->enable_dtx) {
145 increment_opt(stats_.ana_dtx_action_counter);
146 }
147 if (config.enable_fec != prev_config_->enable_fec) {
alexnarest 2017/09/04 11:24:02 In addition I think we want to record the fact FEC
ivoc 2017/09/05 09:01:40 Another option is to add another stat for uplink p
alexnarest 2017/09/05 10:43:27 Yes, I think it is a good idea
148 increment_opt(stats_.ana_fec_action_counter);
149 }
150 if (config.frame_length_ms != prev_config_->frame_length_ms) {
alexnarest 2017/09/05 10:43:27 It would be helpful to report inc/dec counters rat
151 increment_opt(stats_.ana_frame_length_action_counter);
152 }
153 if (config.num_channels != prev_config_->num_channels) {
154 increment_opt(stats_.ana_channel_action_counter);
155 }
156 }
157 prev_config_ = rtc::Optional<AudioEncoderRuntimeConfig>(config);
158
159 // Prevent certain controllers from taking action (determined by field trials)
160 if (!enable_bitrate_adaptation_ && config.bitrate_bps) {
161 config.bitrate_bps = rtc::Optional<int>();
162 }
163 if (!enable_dtx_adaptation_ && config.enable_dtx) {
164 config.enable_dtx = rtc::Optional<bool>();
165 }
166 if (!enable_fec_adaptation_ && config.enable_fec) {
alexnarest 2017/09/04 11:24:01 In addition to enable_fec we want to prevent PL sm
ivoc 2017/09/05 09:01:40 Good point, done.
167 config.enable_fec = rtc::Optional<bool>();
168 }
169 if (!enable_frame_length_adaptation_ && config.frame_length_ms) {
170 config.frame_length_ms = rtc::Optional<int>();
171 }
172 if (!enable_channel_adaptation_ && config.num_channels) {
173 config.num_channels = rtc::Optional<size_t>();
174 }
175
121 if (debug_dump_writer_) 176 if (debug_dump_writer_)
122 debug_dump_writer_->DumpEncoderRuntimeConfig(config, rtc::TimeMillis()); 177 debug_dump_writer_->DumpEncoderRuntimeConfig(config, rtc::TimeMillis());
123 178
124 if (event_log_writer_) 179 if (event_log_writer_)
125 event_log_writer_->MaybeLogEncoderConfig(config); 180 event_log_writer_->MaybeLogEncoderConfig(config);
126 181
127 return config; 182 return config;
128 } 183 }
129 184
130 void AudioNetworkAdaptorImpl::StartDebugDump(FILE* file_handle) { 185 void AudioNetworkAdaptorImpl::StartDebugDump(FILE* file_handle) {
131 debug_dump_writer_ = DebugDumpWriter::Create(file_handle); 186 debug_dump_writer_ = DebugDumpWriter::Create(file_handle);
132 } 187 }
133 188
134 void AudioNetworkAdaptorImpl::StopDebugDump() { 189 void AudioNetworkAdaptorImpl::StopDebugDump() {
135 debug_dump_writer_.reset(nullptr); 190 debug_dump_writer_.reset(nullptr);
136 } 191 }
137 192
138 AudioNetworkAdaptorImpl::AudioNetworkAdaptorStats 193 AudioNetworkAdaptorImpl::AudioNetworkAdaptorStats
139 AudioNetworkAdaptorImpl::GetStats() const { 194 AudioNetworkAdaptorImpl::GetStats() const {
140 // TODO(ivoc): Actually implement the stat. 195 return stats_;
141 return AudioNetworkAdaptorStats();
142 } 196 }
143 197
144 void AudioNetworkAdaptorImpl::DumpNetworkMetrics() { 198 void AudioNetworkAdaptorImpl::DumpNetworkMetrics() {
145 if (debug_dump_writer_) 199 if (debug_dump_writer_)
146 debug_dump_writer_->DumpNetworkMetrics(last_metrics_, rtc::TimeMillis()); 200 debug_dump_writer_->DumpNetworkMetrics(last_metrics_, rtc::TimeMillis());
147 } 201 }
148 202
149 void AudioNetworkAdaptorImpl::UpdateNetworkMetrics( 203 void AudioNetworkAdaptorImpl::UpdateNetworkMetrics(
150 const Controller::NetworkMetrics& network_metrics) { 204 const Controller::NetworkMetrics& network_metrics) {
151 for (auto& controller : controller_manager_->GetControllers()) 205 for (auto& controller : controller_manager_->GetControllers())
152 controller->UpdateNetworkMetrics(network_metrics); 206 controller->UpdateNetworkMetrics(network_metrics);
153 } 207 }
154 208
155 } // namespace webrtc 209 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698