diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp index 695116d05ce2..8746638ca48c 100644 --- a/dom/media/GraphDriver.cpp +++ b/dom/media/GraphDriver.cpp @@ -660,6 +660,13 @@ AudioCallbackDriver::Init() return; } } +#ifdef XP_MACOSX + // Currently, only mac cares about this + bool aec; + Unused << mGraphImpl->AudioTrackPresent(aec); + SetMicrophoneActive(aec); +#endif + cubeb_stream_register_device_changed_callback(mAudioStream, AudioCallbackDriver::DeviceChangedCallback_s); @@ -1063,6 +1070,7 @@ void AudioCallbackDriver::PanOutputIfNeeded(bool aMicrophoneActive) void AudioCallbackDriver::DeviceChangedCallback() { +#ifdef XP_MACOSX MonitorAutoLock mon(mGraphImpl->GetMonitor()); PanOutputIfNeeded(mMicrophoneActive); // On OSX, changing the output device causes the audio thread to no call the @@ -1071,7 +1079,7 @@ AudioCallbackDriver::DeviceChangedCallback() { // We switch to a system driver until audio callbacks are called again, so we // still pull from the input stream, so that everything works apart from the // audio output. -#ifdef XP_MACOSX + // Don't bother doing the device switching dance if the graph is not RUNNING // (starting up, shutting down), because we haven't started pulling from the // SourceMediaStream. @@ -1096,11 +1104,13 @@ AudioCallbackDriver::DeviceChangedCallback() { void AudioCallbackDriver::SetMicrophoneActive(bool aActive) { +#ifdef XP_MACOSX MonitorAutoLock mon(mGraphImpl->GetMonitor()); mMicrophoneActive = aActive; PanOutputIfNeeded(mMicrophoneActive); +#endif } uint32_t diff --git a/dom/media/MediaStreamGraph.cpp b/dom/media/MediaStreamGraph.cpp index 822c69cbac5d..9994336df25a 100644 --- a/dom/media/MediaStreamGraph.cpp +++ b/dom/media/MediaStreamGraph.cpp @@ -420,6 +420,8 @@ namespace { bool MediaStreamGraphImpl::AudioTrackPresent(bool& aNeedsAEC) { + AssertOnGraphThreadOrNotRunning(); + bool audioTrackPresent = false; for (uint32_t i = 0; i < mStreams.Length() && audioTrackPresent == false; ++i) { MediaStream* stream = mStreams[i]; @@ -501,13 +503,21 @@ MediaStreamGraphImpl::UpdateStreamOrder() } #ifdef MOZ_WEBRTC + // Whenever we change AEC state, notify the current driver, which also + // will sample the state when the driver inits if (shouldAEC && !mFarendObserverRef && gFarendObserver) { mFarendObserverRef = gFarendObserver; mMixer.AddCallback(mFarendObserverRef); + if (CurrentDriver()->AsAudioCallbackDriver()) { + CurrentDriver()->AsAudioCallbackDriver()->SetMicrophoneActive(true); + } } else if (!shouldAEC && mFarendObserverRef){ if (mMixer.FindCallback(mFarendObserverRef)) { mMixer.RemoveCallback(mFarendObserverRef); mFarendObserverRef = nullptr; + if (CurrentDriver()->AsAudioCallbackDriver()) { + CurrentDriver()->AsAudioCallbackDriver()->SetMicrophoneActive(false); + } } } #endif