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

Unified Diff: media/audio/audio_input_controller.cc

Issue 2919793002: Detect AudioInputStream muting and propagate to MediaStreamAudioSource. (Closed)
Patch Set: Implemented tests, addressed comments. Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
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..413bb3a30f9307aea843fdd56ad96afe861a54b6 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.
@@ -197,6 +198,7 @@ AudioInputController::AudioInputController(
}
AudioInputController::~AudioInputController() {
+ DCHECK(!check_muted_state_timer_);
DCHECK(!audio_callback_);
DCHECK(!stream_);
}
@@ -353,6 +355,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 create a new repeating timer to keep that
+ // updated.
+ CheckMutedState();
DaleCurtis 2017/06/15 18:44:00 Instead of using a repeating timer like this why n
ossu-chromium 2017/06/20 12:25:15 From looking at the implementations of IsMuted, th
DaleCurtis 2017/06/20 17:08:09 Which implementation are you worried about? I brie
ossu-chromium 2017/06/21 12:51:47 I'm mostly concerned about the PulseAudio implemen
+ check_muted_state_timer_.emplace();
+ 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 +393,9 @@ void AudioInputController::DoClose() {
if (!stream_)
return;
+ // Stop and destroy the muted check timer.
+ 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 +666,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;
+ // We don't log OnMuted here, but leave that for AudioInputRendererHost.
+ handler_->OnMuted(this, is_muted_);
+ }
+}
+
// static
AudioInputController::StreamType AudioInputController::ParamsToStreamType(
const AudioParameters& params) {

Powered by Google App Engine
This is Rietveld 408576698