Commit 4159b371 authored by henrika's avatar henrika Committed by Commit bot

Reduce power logging and UMA stats when AGC is disabled.

Sets a const bool member when AIC is constructed and uses that member to access the stream AGC setting on the correct thread. Same member also enables or disables power logging.

In short: should reduce logging for all non-WebRTC clients.

BUG=408967
TEST=WebRTC clients checking DVLOGs.

Review URL: https://codereview.chromium.org/663123002

Cr-Commit-Position: refs/heads/master@{#300664}
parent 6b4bf550
...@@ -389,16 +389,17 @@ void AudioInputRendererHost::DoCreateStream( ...@@ -389,16 +389,17 @@ void AudioInputRendererHost::DoCreateStream(
entry->writer.get(), entry->writer.get(),
user_input_monitor_); user_input_monitor_);
} else { } else {
// TODO(henrika): replace CreateLowLatency() with Create() as soon DCHECK_EQ(config.params.format(),
// as satish has ensured that Speech Input also uses the default low- media::AudioParameters::AUDIO_PCM_LOW_LATENCY);
// latency path. See crbug.com/112472 for details. entry->controller = media::AudioInputController::CreateLowLatency(
entry->controller = audio_manager_,
media::AudioInputController::CreateLowLatency(audio_manager_, this,
this, audio_params,
audio_params, device_id,
device_id, entry->writer.get(),
entry->writer.get(), user_input_monitor_,
user_input_monitor_); config.automatic_gain_control);
oss << ", AGC=" << config.automatic_gain_control;
} }
if (!entry->controller.get()) { if (!entry->controller.get()) {
...@@ -407,13 +408,6 @@ void AudioInputRendererHost::DoCreateStream( ...@@ -407,13 +408,6 @@ void AudioInputRendererHost::DoCreateStream(
return; return;
} }
// Set the initial AGC state for the audio input stream. Note that, the AGC
// is only supported in AUDIO_PCM_LOW_LATENCY mode.
if (config.params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY) {
entry->controller->SetAutomaticGainControl(config.automatic_gain_control);
oss << ", AGC=" << config.automatic_gain_control;
}
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
if (config.params.channel_layout() == if (config.params.channel_layout() ==
media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC) { media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC) {
......
...@@ -117,7 +117,8 @@ AudioInputController::Factory* AudioInputController::factory_ = NULL; ...@@ -117,7 +117,8 @@ AudioInputController::Factory* AudioInputController::factory_ = NULL;
AudioInputController::AudioInputController(EventHandler* handler, AudioInputController::AudioInputController(EventHandler* handler,
SyncWriter* sync_writer, SyncWriter* sync_writer,
UserInputMonitor* user_input_monitor) UserInputMonitor* user_input_monitor,
const bool agc_is_enabled)
: creator_task_runner_(base::MessageLoopProxy::current()), : creator_task_runner_(base::MessageLoopProxy::current()),
handler_(handler), handler_(handler),
stream_(NULL), stream_(NULL),
...@@ -126,6 +127,7 @@ AudioInputController::AudioInputController(EventHandler* handler, ...@@ -126,6 +127,7 @@ AudioInputController::AudioInputController(EventHandler* handler,
sync_writer_(sync_writer), sync_writer_(sync_writer),
max_volume_(0.0), max_volume_(0.0),
user_input_monitor_(user_input_monitor), user_input_monitor_(user_input_monitor),
agc_is_enabled_(agc_is_enabled),
#if defined(AUDIO_POWER_MONITORING) #if defined(AUDIO_POWER_MONITORING)
power_measurement_is_enabled_(false), power_measurement_is_enabled_(false),
log_silence_state_(false), log_silence_state_(false),
...@@ -156,7 +158,7 @@ scoped_refptr<AudioInputController> AudioInputController::Create( ...@@ -156,7 +158,7 @@ scoped_refptr<AudioInputController> AudioInputController::Create(
audio_manager, event_handler, params, user_input_monitor); audio_manager, event_handler, params, user_input_monitor);
} }
scoped_refptr<AudioInputController> controller( scoped_refptr<AudioInputController> controller(
new AudioInputController(event_handler, NULL, user_input_monitor)); new AudioInputController(event_handler, NULL, user_input_monitor, false));
controller->task_runner_ = audio_manager->GetTaskRunner(); controller->task_runner_ = audio_manager->GetTaskRunner();
...@@ -182,7 +184,8 @@ scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency( ...@@ -182,7 +184,8 @@ scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency(
const AudioParameters& params, const AudioParameters& params,
const std::string& device_id, const std::string& device_id,
SyncWriter* sync_writer, SyncWriter* sync_writer,
UserInputMonitor* user_input_monitor) { UserInputMonitor* user_input_monitor,
const bool agc_is_enabled) {
DCHECK(audio_manager); DCHECK(audio_manager);
DCHECK(sync_writer); DCHECK(sync_writer);
...@@ -191,8 +194,8 @@ scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency( ...@@ -191,8 +194,8 @@ scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency(
// Create the AudioInputController object and ensure that it runs on // Create the AudioInputController object and ensure that it runs on
// the audio-manager thread. // the audio-manager thread.
scoped_refptr<AudioInputController> controller( scoped_refptr<AudioInputController> controller(new AudioInputController(
new AudioInputController(event_handler, sync_writer, user_input_monitor)); event_handler, sync_writer, user_input_monitor, agc_is_enabled));
controller->task_runner_ = audio_manager->GetTaskRunner(); controller->task_runner_ = audio_manager->GetTaskRunner();
// Create and open a new audio input stream from the existing // Create and open a new audio input stream from the existing
...@@ -222,8 +225,8 @@ scoped_refptr<AudioInputController> AudioInputController::CreateForStream( ...@@ -222,8 +225,8 @@ scoped_refptr<AudioInputController> AudioInputController::CreateForStream(
// Create the AudioInputController object and ensure that it runs on // Create the AudioInputController object and ensure that it runs on
// the audio-manager thread. // the audio-manager thread.
scoped_refptr<AudioInputController> controller( scoped_refptr<AudioInputController> controller(new AudioInputController(
new AudioInputController(event_handler, sync_writer, user_input_monitor)); event_handler, sync_writer, user_input_monitor, false));
controller->task_runner_ = task_runner; controller->task_runner_ = task_runner;
// TODO(miu): See TODO at top of file. Until that's resolved, we need to // TODO(miu): See TODO at top of file. Until that's resolved, we need to
...@@ -260,11 +263,6 @@ void AudioInputController::SetVolume(double volume) { ...@@ -260,11 +263,6 @@ void AudioInputController::SetVolume(double volume) {
&AudioInputController::DoSetVolume, this, volume)); &AudioInputController::DoSetVolume, this, volume));
} }
void AudioInputController::SetAutomaticGainControl(bool enabled) {
task_runner_->PostTask(FROM_HERE, base::Bind(
&AudioInputController::DoSetAutomaticGainControl, this, enabled));
}
void AudioInputController::DoCreate(AudioManager* audio_manager, void AudioInputController::DoCreate(AudioManager* audio_manager,
const AudioParameters& params, const AudioParameters& params,
const std::string& device_id) { const std::string& device_id) {
...@@ -274,7 +272,9 @@ void AudioInputController::DoCreate(AudioManager* audio_manager, ...@@ -274,7 +272,9 @@ void AudioInputController::DoCreate(AudioManager* audio_manager,
handler_->OnLog(this, "AIC::DoCreate"); handler_->OnLog(this, "AIC::DoCreate");
#if defined(AUDIO_POWER_MONITORING) #if defined(AUDIO_POWER_MONITORING)
power_measurement_is_enabled_ = true; // Disable power monitoring for streams that run without AGC enabled to
// avoid adding logs and UMA for non-WebRTC clients.
power_measurement_is_enabled_ = agc_is_enabled_;
last_audio_level_log_time_ = base::TimeTicks::Now(); last_audio_level_log_time_ = base::TimeTicks::Now();
silence_state_ = SILENCE_STATE_NO_MEASUREMENT; silence_state_ = SILENCE_STATE_NO_MEASUREMENT;
#endif #endif
...@@ -327,6 +327,10 @@ void AudioInputController::DoCreateForStream( ...@@ -327,6 +327,10 @@ void AudioInputController::DoCreateForStream(
DCHECK(!no_data_timer_.get()); DCHECK(!no_data_timer_.get());
// Set AGC state using mode in |agc_is_enabled_| which can only be enabled in
// CreateLowLatency().
stream_->SetAutomaticGainControl(agc_is_enabled_);
// Create the data timer which will call FirstCheckForNoData(). The timer // Create the data timer which will call FirstCheckForNoData(). The timer
// is started in DoRecord() and restarted in each DoCheckForNoData() // is started in DoRecord() and restarted in each DoCheckForNoData()
// callback. // callback.
...@@ -449,17 +453,6 @@ void AudioInputController::DoSetVolume(double volume) { ...@@ -449,17 +453,6 @@ void AudioInputController::DoSetVolume(double volume) {
stream_->SetVolume(max_volume_ * volume); stream_->SetVolume(max_volume_ * volume);
} }
void AudioInputController::DoSetAutomaticGainControl(bool enabled) {
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK_NE(state_, RECORDING);
// Ensure that the AGC state only can be modified before streaming starts.
if (state_ != CREATED)
return;
stream_->SetAutomaticGainControl(enabled);
}
void AudioInputController::FirstCheckForNoData() { void AudioInputController::FirstCheckForNoData() {
DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(task_runner_->BelongsToCurrentThread());
LogCaptureStartupResult(GetDataIsActive() ? LogCaptureStartupResult(GetDataIsActive() ?
......
...@@ -188,7 +188,8 @@ class MEDIA_EXPORT AudioInputController ...@@ -188,7 +188,8 @@ class MEDIA_EXPORT AudioInputController
const std::string& device_id, const std::string& device_id,
// External synchronous writer for audio controller. // External synchronous writer for audio controller.
SyncWriter* sync_writer, SyncWriter* sync_writer,
UserInputMonitor* user_input_monitor); UserInputMonitor* user_input_monitor,
const bool agc_is_enabled);
// Factory method for creating an AudioInputController with an existing // Factory method for creating an AudioInputController with an existing
// |stream| for low-latency mode, taking ownership of |stream|. The stream // |stream| for low-latency mode, taking ownership of |stream|. The stream
...@@ -221,10 +222,6 @@ class MEDIA_EXPORT AudioInputController ...@@ -221,10 +222,6 @@ class MEDIA_EXPORT AudioInputController
// to muted and 1.0 to maximum volume. // to muted and 1.0 to maximum volume.
virtual void SetVolume(double volume); virtual void SetVolume(double volume);
// Sets the Automatic Gain Control (AGC) state of the input stream.
// Changing the AGC state is not supported while recording is active.
virtual void SetAutomaticGainControl(bool enabled);
// AudioInputCallback implementation. Threading details depends on the // AudioInputCallback implementation. Threading details depends on the
// device-specific implementation. // device-specific implementation.
void OnData(AudioInputStream* stream, void OnData(AudioInputStream* stream,
...@@ -267,8 +264,9 @@ class MEDIA_EXPORT AudioInputController ...@@ -267,8 +264,9 @@ class MEDIA_EXPORT AudioInputController
AudioInputController(EventHandler* handler, AudioInputController(EventHandler* handler,
SyncWriter* sync_writer, SyncWriter* sync_writer,
UserInputMonitor* user_input_monitor); UserInputMonitor* user_input_monitor,
~AudioInputController() override; const bool agc_is_enabled);
virtual ~AudioInputController();
// Methods called on the audio thread (owned by the AudioManager). // Methods called on the audio thread (owned by the AudioManager).
void DoCreate(AudioManager* audio_manager, void DoCreate(AudioManager* audio_manager,
...@@ -282,7 +280,6 @@ class MEDIA_EXPORT AudioInputController ...@@ -282,7 +280,6 @@ class MEDIA_EXPORT AudioInputController
void DoClose(); void DoClose();
void DoReportError(); void DoReportError();
void DoSetVolume(double volume); void DoSetVolume(double volume);
void DoSetAutomaticGainControl(bool enabled);
void DoOnData(scoped_ptr<AudioBus> data); void DoOnData(scoped_ptr<AudioBus> data);
void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent); void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent);
...@@ -351,6 +348,8 @@ class MEDIA_EXPORT AudioInputController ...@@ -351,6 +348,8 @@ class MEDIA_EXPORT AudioInputController
UserInputMonitor* user_input_monitor_; UserInputMonitor* user_input_monitor_;
const bool agc_is_enabled_;
#if defined(AUDIO_POWER_MONITORING) #if defined(AUDIO_POWER_MONITORING)
// Enabled in DoCrete() but not in DoCreateForStream(). // Enabled in DoCrete() but not in DoCreateForStream().
bool power_measurement_is_enabled_; bool power_measurement_is_enabled_;
......
...@@ -14,7 +14,10 @@ TestAudioInputController::TestAudioInputController( ...@@ -14,7 +14,10 @@ TestAudioInputController::TestAudioInputController(
EventHandler* event_handler, EventHandler* event_handler,
SyncWriter* sync_writer, SyncWriter* sync_writer,
UserInputMonitor* user_input_monitor) UserInputMonitor* user_input_monitor)
: AudioInputController(event_handler, sync_writer, user_input_monitor), : AudioInputController(event_handler,
sync_writer,
user_input_monitor,
false),
audio_parameters_(audio_parameters), audio_parameters_(audio_parameters),
factory_(factory), factory_(factory),
event_handler_(event_handler) { event_handler_(event_handler) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment