diff --git a/dom/audiochannel/AudioChannelAgent.cpp b/dom/audiochannel/AudioChannelAgent.cpp index 5d218996ed06..4ca36656ff68 100644 --- a/dom/audiochannel/AudioChannelAgent.cpp +++ b/dom/audiochannel/AudioChannelAgent.cpp @@ -354,3 +354,10 @@ AudioChannelAgent::WindowAudioCaptureChanged(uint64_t aInnerWindowID, callback->WindowAudioCaptureChanged(aCapture); } + +bool +AudioChannelAgent::IsPlayingStarted() const +{ + return mIsRegToService; +} + diff --git a/dom/audiochannel/AudioChannelAgent.h b/dom/audiochannel/AudioChannelAgent.h index 10cbec1ac080..8e844a16007e 100644 --- a/dom/audiochannel/AudioChannelAgent.h +++ b/dom/audiochannel/AudioChannelAgent.h @@ -48,6 +48,8 @@ public: uint64_t WindowID() const; uint64_t InnerWindowID() const; + bool IsPlayingStarted() const; + private: virtual ~AudioChannelAgent(); diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 4de1ea2a1a0b..24ac87bab8a7 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -6430,7 +6430,9 @@ HTMLMediaElement::SetAudibleState(bool aAudible) void HTMLMediaElement::NotifyAudioPlaybackChanged(AudibleChangedReasons aReason) { - if (!mAudioChannelAgent) { + MOZ_ASSERT(mAudioChannelAgent); + + if (!mAudioChannelAgent->IsPlayingStarted()) { return; } @@ -6554,16 +6556,17 @@ HTMLMediaElement::SetMediaInfo(const MediaInfo& aInfo) void HTMLMediaElement::AudioCaptureStreamChangeIfNeeded() { - // Window audio capturing only happens after creating audio channel agent. - if (!mAudioChannelAgent) { - return; - } + MOZ_ASSERT(mAudioChannelAgent); // No need to capture a silence media element. if (!HasAudio()) { return; } + if (!mAudioChannelAgent->IsPlayingStarted()) { + return; + } + if (mAudioCapturedByWindow && !mCaptureStreamPort) { nsCOMPtr window = OwnerDoc()->GetInnerWindow(); if (!OwnerDoc()->GetInnerWindow()) {