Bug 1578615 - part4 : remove SUSPENDED_BLOCK related logic in AudioChannelWrapper. r=chunmin

Now `AudioChannelWrapper` would only start `AudioChannelAgent` when media starts and stop the agent when media stops. It won't handle any case with `SUSPENDED_BLOCK`.

It's clearer to know when we would start or stop the agent in AudioChannelWrapper.

In addition, in bug1577890, we will remove more unnecessary logic which is used for Fennec only in order to make `AudioChannelWrapper` cleaner.

Differential Revision: https://phabricator.services.mozilla.com/D44747
This commit is contained in:
alwu
2019-09-25 02:08:39 +00:00
parent 180d28d35d
commit 296e1af963
2 changed files with 12 additions and 61 deletions

View File

@@ -992,10 +992,9 @@ class HTMLMediaElement::AudioChannelAgentCallback final
MaybeCreateAudioChannelAgent();
}
void UpdateAudioChannelPlayingState(bool aForcePlaying = false) {
void UpdateAudioChannelPlayingState() {
MOZ_ASSERT(!mIsShutDown);
bool playingThroughTheAudioChannel =
aForcePlaying || IsPlayingThroughTheAudioChannel();
bool playingThroughTheAudioChannel = IsPlayingThroughTheAudioChannel();
if (playingThroughTheAudioChannel != mPlayingThroughTheAudioChannel) {
if (!MaybeCreateAudioChannelAgent()) {
@@ -1013,18 +1012,8 @@ class HTMLMediaElement::AudioChannelAgentCallback final
bool ShouldResetSuspend() const {
// The disposable-pause should be clear after media starts playing.
if (!mOwner->Paused() &&
mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE) {
return true;
}
// If the blocked media is paused, we don't need to resume it. We reset the
// mSuspended in order to unregister the agent.
if (mOwner->Paused() && mSuspended == nsISuspendedTypes::SUSPENDED_BLOCK) {
return true;
}
return false;
return !mOwner->Paused() &&
mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE;
}
void NotifyPlayStateChanged() {
@@ -1076,7 +1065,6 @@ class HTMLMediaElement::AudioChannelAgentCallback final
break;
case nsISuspendedTypes::SUSPENDED_PAUSE:
case nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE:
case nsISuspendedTypes::SUSPENDED_BLOCK:
Suspend(aSuspend);
break;
case nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE:
@@ -1127,21 +1115,6 @@ class HTMLMediaElement::AudioChannelAgentCallback final
mIsOwnerAudible == AudioChannelService::AudibleState::eAudible);
}
bool IsPlaybackBlocked() {
MOZ_ASSERT(!mIsShutDown);
// If the tab hasn't been activated yet, the media element in that tab can't
// be playback now until the tab goes to foreground first time or user
// clicks the unblocking tab icon.
if (!IsTabActivated()) {
// Even we haven't start playing yet, we still need to notify the audio
// channe system because we need to receive the resume notification later.
UpdateAudioChannelPlayingState(true /* force to start */);
return true;
}
return false;
}
void Shutdown() {
MOZ_ASSERT(!mIsShutDown);
if (mAudioChannelAgent && mAudioChannelAgent->IsPlayingStarted()) {
@@ -1310,17 +1283,9 @@ class HTMLMediaElement::AudioChannelAgentCallback final
}));
}
bool IsTabActivated() {
if (MaybeCreateAudioChannelAgent()) {
return !mAudioChannelAgent->ShouldBlockMedia();
}
return false;
}
bool IsSuspended() const {
return (mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE ||
mSuspended == nsISuspendedTypes::SUSPENDED_BLOCK);
mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE);
}
AudibleState IsOwnerAudible() const {
@@ -1389,10 +1354,6 @@ class HTMLMediaElement::AudioChannelAgentCallback final
// - SUSPENDED_PAUSE_DISPOSABLE
// It's used when user press the pause button on the remote media-control.
// MediaElement can be resumed by remote media-control or via play().
// - SUSPENDED_BLOCK
// It's used to reduce the power consumption, we won't play the auto-play
// audio/video in the page we have never visited before. MediaElement would
// be resumed when the page is active. See bug647429 for more details.
// - SUSPENDED_STOP_DISPOSABLE
// When we permanently lost platform audio focus, we should stop playing
// and stop the audio channel agent. MediaElement can only be restarted by
@@ -5815,16 +5776,9 @@ bool HTMLMediaElement::CanActivateAutoplay() {
return false;
}
if (mAudioChannelWrapper) {
// Note: SUSPENDED_PAUSE and SUSPENDED_BLOCK will be merged into one single
// state.
if (mAudioChannelWrapper->GetSuspendType() ==
nsISuspendedTypes::SUSPENDED_PAUSE ||
mAudioChannelWrapper->GetSuspendType() ==
nsISuspendedTypes::SUSPENDED_BLOCK ||
mAudioChannelWrapper->IsPlaybackBlocked()) {
return false;
}
if (mAudioChannelWrapper && mAudioChannelWrapper->GetSuspendType() ==
nsISuspendedTypes::SUSPENDED_PAUSE) {
return false;
}
return mReadyState >= HAVE_ENOUGH_DATA;
@@ -6519,9 +6473,9 @@ ImageContainer* HTMLMediaElement::GetImageContainer() {
return container ? container->GetImageContainer() : nullptr;
}
void HTMLMediaElement::UpdateAudioChannelPlayingState(bool aForcePlaying) {
void HTMLMediaElement::UpdateAudioChannelPlayingState() {
if (mAudioChannelWrapper) {
mAudioChannelWrapper->UpdateAudioChannelPlayingState(aForcePlaying);
mAudioChannelWrapper->UpdateAudioChannelPlayingState();
}
}
@@ -6535,11 +6489,8 @@ bool HTMLMediaElement::AudioChannelAgentBlockedPlay() {
return true;
}
// Note: SUSPENDED_PAUSE and SUSPENDED_BLOCK will be merged into one single
// state.
const auto suspendType = mAudioChannelWrapper->GetSuspendType();
return suspendType == nsISuspendedTypes::SUSPENDED_PAUSE ||
suspendType == nsISuspendedTypes::SUSPENDED_BLOCK;
return suspendType == nsISuspendedTypes::SUSPENDED_PAUSE;
}
static const char* VisibilityString(Visibility aVisibility) {