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

Side by Side Diff: webrtc/modules/audio_processing/gain_control_impl.cc

Issue 2457783003: Added offline data logpoints and logging functionality to the gain controller (Closed)
Patch Set: Created 4 years, 1 month 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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_processing/gain_control_impl.h" 11 #include "webrtc/modules/audio_processing/gain_control_impl.h"
12 12
13 #include "webrtc/base/constructormagic.h" 13 #include "webrtc/base/constructormagic.h"
14 #include "webrtc/base/optional.h" 14 #include "webrtc/base/optional.h"
15 #include "webrtc/modules/audio_processing/audio_buffer.h" 15 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #include "webrtc/modules/audio_processing/agc/legacy/gain_control.h" 16 #include "webrtc/modules/audio_processing/agc/legacy/gain_control.h"
17 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
17 18
18 namespace webrtc { 19 namespace webrtc {
19 20
20 typedef void Handle; 21 typedef void Handle;
21 22
22 namespace { 23 namespace {
23 int16_t MapSetting(GainControl::Mode mode) { 24 int16_t MapSetting(GainControl::Mode mode) {
24 switch (mode) { 25 switch (mode) {
25 case GainControl::kAdaptiveAnalog: 26 case GainControl::kAdaptiveAnalog:
26 return kAgcModeAdaptiveAnalog; 27 return kAgcModeAdaptiveAnalog;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 78
78 private: 79 private:
79 Handle* state_; 80 Handle* state_;
80 // TODO(peah): Remove the optional once the initialization is moved into the 81 // TODO(peah): Remove the optional once the initialization is moved into the
81 // ctor. 82 // ctor.
82 rtc::Optional<int> capture_level_; 83 rtc::Optional<int> capture_level_;
83 84
84 RTC_DISALLOW_COPY_AND_ASSIGN(GainController); 85 RTC_DISALLOW_COPY_AND_ASSIGN(GainController);
85 }; 86 };
86 87
88 int GainControlImpl::instance_counter_ = 0;
89
87 GainControlImpl::GainControlImpl(rtc::CriticalSection* crit_render, 90 GainControlImpl::GainControlImpl(rtc::CriticalSection* crit_render,
88 rtc::CriticalSection* crit_capture) 91 rtc::CriticalSection* crit_capture)
89 : crit_render_(crit_render), 92 : crit_render_(crit_render),
90 crit_capture_(crit_capture), 93 crit_capture_(crit_capture),
94 data_dumper_(new ApmDataDumper(instance_counter_)),
ivoc 2016/10/28 09:20:10 The experimental AGC and the regular AGC could end
peah-webrtc 2016/10/28 09:43:41 They are not in practice active at the same time.
91 mode_(kAdaptiveAnalog), 95 mode_(kAdaptiveAnalog),
92 minimum_capture_level_(0), 96 minimum_capture_level_(0),
93 maximum_capture_level_(255), 97 maximum_capture_level_(255),
94 limiter_enabled_(true), 98 limiter_enabled_(true),
95 target_level_dbfs_(3), 99 target_level_dbfs_(3),
96 compression_gain_db_(9), 100 compression_gain_db_(9),
97 analog_capture_level_(0), 101 analog_capture_level_(0),
98 was_analog_level_set_(false), 102 was_analog_level_set_(false),
99 stream_is_saturated_(false) { 103 stream_is_saturated_(false) {
100 RTC_DCHECK(crit_render); 104 RTC_DCHECK(crit_render);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 236 }
233 237
234 int GainControlImpl::compression_gain_db() const { 238 int GainControlImpl::compression_gain_db() const {
235 rtc::CritScope cs(crit_capture_); 239 rtc::CritScope cs(crit_capture_);
236 return compression_gain_db_; 240 return compression_gain_db_;
237 } 241 }
238 242
239 // TODO(ajm): ensure this is called under kAdaptiveAnalog. 243 // TODO(ajm): ensure this is called under kAdaptiveAnalog.
240 int GainControlImpl::set_stream_analog_level(int level) { 244 int GainControlImpl::set_stream_analog_level(int level) {
241 rtc::CritScope cs(crit_capture_); 245 rtc::CritScope cs(crit_capture_);
246 data_dumper_->DumpRaw("gain_control_set_stream_analog_level", 1, &level);
ivoc 2016/10/28 09:20:10 Shouldn't there be a way to enable/disable this lo
peah-webrtc 2016/10/28 09:43:41 There is. What happens is that this method call ex
242 247
243 was_analog_level_set_ = true; 248 was_analog_level_set_ = true;
244 if (level < minimum_capture_level_ || level > maximum_capture_level_) { 249 if (level < minimum_capture_level_ || level > maximum_capture_level_) {
245 return AudioProcessing::kBadParameterError; 250 return AudioProcessing::kBadParameterError;
246 } 251 }
247 analog_capture_level_ = level; 252 analog_capture_level_ = level;
248 253
249 return AudioProcessing::kNoError; 254 return AudioProcessing::kNoError;
250 } 255 }
251 256
252 int GainControlImpl::stream_analog_level() { 257 int GainControlImpl::stream_analog_level() {
253 rtc::CritScope cs(crit_capture_); 258 rtc::CritScope cs(crit_capture_);
259 data_dumper_->DumpRaw("gain_control_stream_analog_level", 1,
260 &analog_capture_level_);
254 // TODO(ajm): enable this assertion? 261 // TODO(ajm): enable this assertion?
255 //RTC_DCHECK_EQ(kAdaptiveAnalog, mode_); 262 //RTC_DCHECK_EQ(kAdaptiveAnalog, mode_);
256 263
257 return analog_capture_level_; 264 return analog_capture_level_;
258 } 265 }
259 266
260 int GainControlImpl::Enable(bool enable) { 267 int GainControlImpl::Enable(bool enable) {
261 rtc::CritScope cs_render(crit_render_); 268 rtc::CritScope cs_render(crit_render_);
262 rtc::CritScope cs_capture(crit_capture_); 269 rtc::CritScope cs_capture(crit_capture_);
263 if (enable && !enabled_) { 270 if (enable && !enabled_) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 385 }
379 386
380 bool GainControlImpl::is_limiter_enabled() const { 387 bool GainControlImpl::is_limiter_enabled() const {
381 rtc::CritScope cs(crit_capture_); 388 rtc::CritScope cs(crit_capture_);
382 return limiter_enabled_; 389 return limiter_enabled_;
383 } 390 }
384 391
385 void GainControlImpl::Initialize(size_t num_proc_channels, int sample_rate_hz) { 392 void GainControlImpl::Initialize(size_t num_proc_channels, int sample_rate_hz) {
386 rtc::CritScope cs_render(crit_render_); 393 rtc::CritScope cs_render(crit_render_);
387 rtc::CritScope cs_capture(crit_capture_); 394 rtc::CritScope cs_capture(crit_capture_);
395 data_dumper_->InitiateNewSetOfRecordings();
388 396
389 num_proc_channels_ = rtc::Optional<size_t>(num_proc_channels); 397 num_proc_channels_ = rtc::Optional<size_t>(num_proc_channels);
390 sample_rate_hz_ = rtc::Optional<int>(sample_rate_hz); 398 sample_rate_hz_ = rtc::Optional<int>(sample_rate_hz);
391 399
392 if (!enabled_) { 400 if (!enabled_) {
393 return; 401 return;
394 } 402 }
395 403
396 gain_controllers_.resize(*num_proc_channels_); 404 gain_controllers_.resize(*num_proc_channels_);
397 for (auto& gain_controller : gain_controllers_) { 405 for (auto& gain_controller : gain_controllers_) {
(...skipping 24 matching lines...) Expand all
422 for (auto& gain_controller : gain_controllers_) { 430 for (auto& gain_controller : gain_controllers_) {
423 const int handle_error = 431 const int handle_error =
424 WebRtcAgc_set_config(gain_controller->state(), config); 432 WebRtcAgc_set_config(gain_controller->state(), config);
425 if (handle_error != AudioProcessing::kNoError) { 433 if (handle_error != AudioProcessing::kNoError) {
426 error = handle_error; 434 error = handle_error;
427 } 435 }
428 } 436 }
429 return error; 437 return error;
430 } 438 }
431 } // namespace webrtc 439 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698