Bug 1580659 - part4 : pulling the intial update after starting AudioChannelAgent. r=chunmin

Instead of calling those callback functions seperately, we could provide a function to pull those changes at once after starting the agent.

In addition, `WindowXXXChanged` are callback functions of `nsIAudioChannelAgentCallback`, so they should only be called by `AudioChannelAgent`, to indicate receiving the change from `AudioChannelService`. We should not call them directly.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
alwu 2019-09-24 21:17:59 +00:00
Родитель fbc98138ee
Коммит d158e0c4b2
6 изменённых файлов: 22 добавлений и 17 удалений

Просмотреть файл

@ -126,6 +126,17 @@ nsresult AudioChannelAgent::InitInternal(
return NS_OK;
}
void AudioChannelAgent::PullInitialUpdate() {
RefPtr<AudioChannelService> service = AudioChannelService::Get();
MOZ_ASSERT(service);
MOZ_ASSERT(mIsRegToService);
AudioPlaybackConfig config = service->GetMediaConfig(mWindow);
WindowVolumeChanged();
WindowSuspendChanged(config.mSuspend);
WindowAudioCaptureChanged(InnerWindowID(), config.mCapturedAudio);
}
NS_IMETHODIMP
AudioChannelAgent::NotifyStartedPlaying(AudioPlaybackConfig* aConfig,
uint8_t aAudible) {

Просмотреть файл

@ -30,6 +30,13 @@ class AudioChannelAgent : public nsIAudioChannelAgent {
AudioChannelAgent();
// nsIAudioChannelAgentCallback MUST call this function after calling
// NotifyStartedPlaying() to require the initial update for
// volume/suspend/audio-capturing which might set before starting the agent.
// Ex. starting the agent in a tab which has been muted before, so the agent
// should apply mute state to its callback.
void PullInitialUpdate();
void WindowVolumeChanged();
void WindowSuspendChanged(nsSuspendedTypes aSuspend);
void WindowAudioCaptureChanged(uint64_t aInnerWindowID, bool aCapture);

Просмотреть файл

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

Просмотреть файл

@ -628,9 +628,7 @@ void AudioDestinationNode::NotifyAudibleStateChanged(bool aAudible) {
return;
}
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
WindowAudioCaptureChanged(config.mCapturedAudio);
mAudioChannelAgent->PullInitialUpdate();
}
} // namespace dom

Просмотреть файл

@ -346,8 +346,7 @@ void nsSpeechTask::CreateAudioChannelAgent() {
return;
}
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
mAudioChannelAgent->PullInitialUpdate();
}
void nsSpeechTask::DestroyAudioChannelAgent() {

Просмотреть файл

@ -1114,15 +1114,7 @@ void nsNPAPIPluginInstance::NotifyStartedPlaying() {
return;
}
rv = WindowVolumeChanged(config.mVolume, config.mMuted);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
rv = WindowSuspendChanged(config.mSuspend);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
mAudioChannelAgent->PullInitialUpdate();
}
void nsNPAPIPluginInstance::NotifyStoppedPlaying() {