Bug 1580659 - part5 : stop audio capturing explicitly. r=chunmin,karlt

As we start audio capturing explicitly, we should also take responsibility to stop audio capturing when we don't need it.

We were hiding too many details on `AudioChannelAgent` before, which allow us hard to know who and where we handle audio capturing.

Differential Revision: https://phabricator.services.mozilla.com/D45752
This commit is contained in:
Alastor Wu
2019-09-21 02:21:58 +00:00
parent fea64ef820
commit d585dd932c
7 changed files with 54 additions and 36 deletions

View File

@@ -984,7 +984,6 @@ class HTMLMediaElement::AudioChannelAgentCallback final
: mOwner(aOwner),
mAudioChannelVolume(1.0),
mPlayingThroughTheAudioChannel(false),
mAudioCapturedByWindow(false),
mSuspended(nsISuspendedTypes::NONE_SUSPENDED),
mIsOwnerAudible(IsOwnerAudible()),
mIsShutDown(false) {
@@ -1094,11 +1093,7 @@ class HTMLMediaElement::AudioChannelAgentCallback final
NS_IMETHODIMP WindowAudioCaptureChanged(bool aCapture) override {
MOZ_ASSERT(mAudioChannelAgent);
if (mAudioCapturedByWindow != aCapture) {
mAudioCapturedByWindow = aCapture;
AudioCaptureStreamChangeIfNeeded();
}
AudioCaptureStreamChangeIfNeeded();
return NS_OK;
}
@@ -1107,7 +1102,10 @@ class HTMLMediaElement::AudioChannelAgentCallback final
if (!IsPlayingStarted()) {
return;
}
mOwner->AudioCaptureStreamChange(mAudioCapturedByWindow);
MOZ_ASSERT(mAudioChannelAgent);
bool isCapturing = mAudioChannelAgent->IsWindowAudioCapturingEnabled();
mOwner->AudioCaptureStreamChange(isCapturing);
}
void NotifyAudioPlaybackChanged(AudibleChangedReasons aReason) {
@@ -1204,6 +1202,9 @@ class HTMLMediaElement::AudioChannelAgentCallback final
MOZ_ASSERT(mAudioChannelAgent->IsPlayingStarted());
mAudioChannelAgent->NotifyStoppedPlaying();
NotifyMediaStopped(mAudioChannelAgent->WindowID());
// If we have started audio capturing before, we have to tell media element
// to clear the output capturing stream.
mOwner->AudioCaptureStreamChange(false);
}
void SetSuspended(SuspendTypes aSuspend) {
@@ -1399,8 +1400,6 @@ class HTMLMediaElement::AudioChannelAgentCallback final
float mAudioChannelVolume;
// Is this media element playing?
bool mPlayingThroughTheAudioChannel;
// True if the sound is being captured by the window.
bool mAudioCapturedByWindow;
// We have different kinds of suspended cases,
// - SUSPENDED_PAUSE
// It's used when we temporary lost platform audio focus. MediaElement can