Chromium Code Reviews| Index: media/audio/audio_input_controller.cc |
| diff --git a/media/audio/audio_input_controller.cc b/media/audio/audio_input_controller.cc |
| index 5c8997e0875b0853d02152b2c2d1ab6531f487ef..017ba18198f42acec130681ba3c0ffba607fd3c8 100644 |
| --- a/media/audio/audio_input_controller.cc |
| +++ b/media/audio/audio_input_controller.cc |
| @@ -26,6 +26,7 @@ namespace media { |
| namespace { |
| const int kMaxInputChannels = 3; |
| +constexpr int kCheckMutedStateIntervalSeconds = 1; |
| #if defined(AUDIO_POWER_MONITORING) |
| // Time in seconds between two successive measurements of audio power levels. |
| @@ -353,6 +354,15 @@ void AudioInputController::DoCreateForStream( |
| // Finally, keep the stream pointer around, update the state and notify. |
| stream_ = stream_to_control; |
| handler_->OnCreated(this); |
| + |
| + // Check the current muted state and start a repeating timer to keep that |
| + // updated. |
| + CheckMutedState(); |
| + check_muted_state_timer_.reset(new base::RepeatingTimer()); |
|
Max Morin
2017/06/02 09:56:04
If you use unique_ptr, most Chromium people prefer
Guido Urdaneta
2017/06/02 13:33:45
MakeUnique is strongly preferred over raw new, but
|
| + check_muted_state_timer_->Start( |
| + FROM_HERE, base::TimeDelta::FromSeconds(kCheckMutedStateIntervalSeconds), |
| + this, &AudioInputController::CheckMutedState); |
| + DCHECK(check_muted_state_timer_->IsRunning()); |
| } |
| void AudioInputController::DoRecord() { |
| @@ -382,6 +392,13 @@ void AudioInputController::DoClose() { |
| if (!stream_) |
| return; |
| + // Stop the muted check timer. |
| + // TODO(ossu): Can't we just reset() it here? Should stop automatically, IIUC. |
|
Max Morin
2017/06/02 09:56:04
Looking at the implementation, yes. Would be nice
ossu-chromium
2017/06/02 10:48:00
The top of timer.h says:
"OneShotTimer and Repeati
Guido Urdaneta
2017/06/02 13:33:45
There are also many uses in the codebase that just
|
| + if (check_muted_state_timer_ != nullptr) { |
| + check_muted_state_timer_->Stop(); |
| + check_muted_state_timer_.reset(); |
| + } |
| + |
| // Allow calling unconditionally and bail if we don't have a stream to close. |
| if (audio_callback_) { |
| stream_->Stop(); |
| @@ -652,6 +669,17 @@ bool AudioInputController::CheckAudioPower(const AudioBus* source, |
| #endif |
| } |
| +void AudioInputController::CheckMutedState() { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + DCHECK(stream_); |
| + const bool new_state = stream_->IsMuted(); |
| + if (new_state != is_muted_) { |
| + is_muted_ = new_state; |
| + // Don't log this here, AudioInputRendererHost will log instead. |
|
Max Morin
2017/06/02 09:56:04
Does AIRH actually log this?
ossu-chromium
2017/06/02 10:48:00
Aww, shucks. It did until I removed that. I think
|
| + handler_->OnMuted(this, is_muted_); |
| + } |
| +} |
| + |
| // static |
| AudioInputController::StreamType AudioInputController::ParamsToStreamType( |
| const AudioParameters& params) { |