Bug 1580659 - part3 : call 'WindowAudioCaptureChanged()' explicitly. r=chunmin,karlt

Previously `AudioChannelService` called `WindowAudioCaptureChanged()` implicitly whenever we added the agent to the service [1], which made the audio capturing callback happen before finishing registration.

There are two drawbacks,
(1) it's hard to be aware of that the audio capturing callback would be called before finishing `AudioChannelAgent::NotifyStartedPlaying()` [2], which causes unclear call flow.

(2) If someone checks `AudioChannelAgent::IsPlayingStarted()` [3] inside audio capturing callback, then we would find that the `mIsRegToService` is false even if we have registered the agent to `AudioChannelService` because `mIsRegToService` is updated in the last line in the `AudioChannelAgent::NotifyStartedPlaying()`, but the audio capturing callback could be executed before that.

[1] https://searchfox.org/mozilla-central/rev/a777ff11b6d700a698c61e5bd17e73b044304494/dom/audiochannel/AudioChannelService.cpp#723
[2] https://searchfox.org/mozilla-central/rev/a777ff11b6d700a698c61e5bd17e73b044304494/dom/audiochannel/AudioChannelAgent.cpp#144
[3] https://searchfox.org/mozilla-central/rev/a777ff11b6d700a698c61e5bd17e73b044304494/dom/audiochannel/AudioChannelAgent.cpp#285

Differential Revision: https://phabricator.services.mozilla.com/D45750

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alastor Wu 2019-09-24 06:55:43 +00:00
parent 08fa1387dc
commit 5d31bee21f
5 changed files with 12 additions and 9 deletions

View File

@ -155,7 +155,11 @@ AudioChannelAgent::NotifyStartedPlaying(AudioPlaybackConfig* aConfig,
config.mMuted ? "true" : "false", config.mVolume,
SuspendTypeToStr(config.mSuspend)));
aConfig->SetConfig(config.mVolume, config.mMuted, config.mSuspend);
aConfig->mVolume = config.mVolume;
aConfig->mMuted = config.mMuted;
aConfig->mSuspend = config.mSuspend;
aConfig->mCapturedAudio = config.mCapturedAudio;
mIsRegToService = true;
return NS_OK;
}

View File

@ -321,7 +321,9 @@ AudioPlaybackConfig AudioChannelService::GetMediaConfig(
AudioPlaybackConfig config(1.0, false, nsISuspendedTypes::NONE_SUSPENDED);
if (!aWindow) {
config.SetConfig(0.0, true, nsISuspendedTypes::SUSPENDED_BLOCK);
config.mVolume = 0.0;
config.mMuted = true;
config.mSuspend = nsISuspendedTypes::SUSPENDED_BLOCK;
return config;
}
@ -338,6 +340,7 @@ AudioPlaybackConfig AudioChannelService::GetMediaConfig(
config.mSuspend = winData->mOwningAudioFocus
? config.mSuspend
: nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE;
config.mCapturedAudio = winData->mIsAudioCaptured;
}
config.mVolume *= window->GetAudioVolume();
@ -716,7 +719,6 @@ void AudioChannelService::AudioChannelWindow::AppendAgent(
RequestAudioFocus(aAgent);
AppendAgentAndIncreaseAgentsNum(aAgent);
AudioCapturedChanged(aAgent, AudioCaptureState::eCapturing);
if (aAudible == AudibleState::eAudible) {
AudioAudibleChanged(aAgent, AudibleState::eAudible,
AudibleChangedReasons::eDataAudibleChanged);

View File

@ -38,15 +38,10 @@ class AudioPlaybackConfig {
mSuspend(aSuspended),
mNumberOfAgents(0) {}
void SetConfig(float aVolume, bool aMuted, uint32_t aSuspended) {
mVolume = aVolume;
mMuted = aMuted;
mSuspend = aSuspended;
}
float mVolume;
bool mMuted;
uint32_t mSuspend;
bool mCapturedAudio = false;
uint32_t mNumberOfAgents;
};

View File

@ -1198,6 +1198,7 @@ class HTMLMediaElement::AudioChannelAgentCallback final
NotifyMediaStarted(mAudioChannelAgent->WindowID());
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
WindowAudioCaptureChanged(config.mCapturedAudio);
}
void StopAudioChanelAgent() {

View File

@ -630,6 +630,7 @@ void AudioDestinationNode::NotifyAudibleStateChanged(bool aAudible) {
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
WindowAudioCaptureChanged(config.mCapturedAudio);
}
} // namespace dom