Bug 1302350 - part2 : provide a method to check whether the agent was started.
Since the agent is created in beginning in patch1, we need another way to know
whether we have already called notifyStartedPlaying().
MozReview-Commit-ID: 5YNhwEl5Xfp
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -349,8 +349,15 @@ AudioChannelAgent::WindowAudioCaptureCha
}
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
("AudioChannelAgent, WindowAudioCaptureChanged, this = %p, "
"capture = %d\n", this, aCapture));
callback->WindowAudioCaptureChanged(aCapture);
}
+
+bool
+AudioChannelAgent::IsPlayingStarted() const
+{
+ return mIsRegToService;
+}
+
--- a/dom/audiochannel/AudioChannelAgent.h
+++ b/dom/audiochannel/AudioChannelAgent.h
@@ -43,16 +43,18 @@ public:
nsPIDOMWindowOuter* Window() const
{
return mWindow;
}
uint64_t WindowID() const;
uint64_t InnerWindowID() const;
+ bool IsPlayingStarted() const;
+
private:
virtual ~AudioChannelAgent();
AudioPlaybackConfig GetMediaConfig();
bool IsDisposableSuspend(nsSuspendedTypes aSuspend) const;
// Returns mCallback if that's non-null, or otherwise tries to get an
// nsIAudioChannelAgentCallback out of mWeakCallback.
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -6391,17 +6391,19 @@ HTMLMediaElement::SetAudibleState(bool a
NotifyAudioPlaybackChanged(
AudioChannelService::AudibleChangedReasons::eDataAudibleChanged);
}
}
void
HTMLMediaElement::NotifyAudioPlaybackChanged(AudibleChangedReasons aReason)
{
- if (!mAudioChannelAgent) {
+ MOZ_ASSERT(mAudioChannelAgent);
+
+ if (!mAudioChannelAgent->IsPlayingStarted()) {
return;
}
if (mAudible == IsAudible()) {
return;
}
mAudible = IsAudible();
@@ -6515,26 +6517,27 @@ HTMLMediaElement::SetMediaInfo(const Med
{
mMediaInfo = aInfo;
AudioCaptureStreamChangeIfNeeded();
}
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<nsPIDOMWindowInner> window = OwnerDoc()->GetInnerWindow();
if (!OwnerDoc()->GetInnerWindow()) {
return;
}
uint64_t id = window->WindowID();
MediaStreamGraph* msg =