diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp
index 05c24891bc3d..c36296b4278b 100644
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2519,10 +2519,6 @@ HTMLMediaElement::Seek(double aTime,
// MediaDecoderReaders.
mPlayingBeforeSeek = IsPotentiallyPlaying();
- // Set the Variable if the Seekstarted while active playing
- if (mPlayingThroughTheAudioChannel) {
- mPlayingThroughTheAudioChannelBeforeSeek = true;
- }
// The media backend is responsible for dispatching the timeupdate
// event if it changes the playback position as a result of the seek.
@@ -3458,14 +3454,11 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed& aNo
mAutoplayEnabled(true),
mPaused(true),
mMuted(0),
- mAudioChannelSuspended(nsISuspendedTypes::NONE_SUSPENDED),
mStatsShowing(false),
mAllowCasting(false),
mIsCasting(false),
mAudioCaptured(false),
- mAudioCapturedByWindow(false),
mPlayingBeforeSeek(false),
- mPlayingThroughTheAudioChannelBeforeSeek(false),
mPausedForInactiveDocumentOrChannel(false),
mEventDeliveryPaused(false),
mIsRunningLoadMethod(false),
@@ -3487,14 +3480,11 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed& aNo
mWaitingForKey(NOT_WAITING_FOR_KEY),
mDownloadSuspendedByCache(false, "HTMLMediaElement::mDownloadSuspendedByCache"),
mAudioChannel(AudioChannelService::GetDefaultAudioChannel()),
- mAudioChannelVolume(1.0),
- mPlayingThroughTheAudioChannel(false),
mDisableVideo(false),
mHasUserInteraction(false),
mFirstFrameLoaded(false),
mDefaultPlaybackStartPosition(0.0),
mIsAudioTrackAudible(false),
- mAudible(IsAudible()),
mVisibilityState(Visibility::APPROXIMATELY_NONVISIBLE),
mErrorSink(new ErrorSink(this)),
mAudioChannelWrapper(new AudioChannelAgentCallback(this, mAudioChannel))
@@ -3516,7 +3506,6 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed& aNo
mWatchManager.Watch(mReadyState, &HTMLMediaElement::UpdateReadyStateInternal);
mShutdownObserver->Subscribe(this);
- MaybeCreateAudioChannelAgent();
}
HTMLMediaElement::~HTMLMediaElement()
@@ -3557,7 +3546,6 @@ HTMLMediaElement::~HTMLMediaElement()
}
WakeLockRelease();
- mAudioChannelAgent = nullptr;
}
void HTMLMediaElement::StopSuspendingAfterFirstFrame()
@@ -5093,8 +5081,6 @@ void HTMLMediaElement::SeekCompleted()
if (mCurrentPlayRangeStart == -1.0) {
mCurrentPlayRangeStart = CurrentTime();
}
- // Unset the variable on seekend
- mPlayingThroughTheAudioChannelBeforeSeek = false;
}
void HTMLMediaElement::NotifySuspendedByCache(bool aIsSuspended)
@@ -6337,74 +6323,6 @@ ImageContainer* HTMLMediaElement::GetImageContainer()
return container ? container->GetImageContainer() : nullptr;
}
-bool
-HTMLMediaElement::MaybeCreateAudioChannelAgent()
-{
- if (mAudioChannelAgent) {
- return true;
- }
-
- mAudioChannelAgent = new AudioChannelAgent();
- nsresult rv = mAudioChannelAgent->InitWithWeakCallback(OwnerDoc()->GetInnerWindow(),
- static_cast(mAudioChannel),
- this);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- mAudioChannelAgent = nullptr;
- MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
- ("HTMLMediaElement, Fail to initialize the audio channel agent,"
- " this = %p\n", this));
- return false;
- }
-
- return true;
-}
-
-bool
-HTMLMediaElement::IsPlayingThroughTheAudioChannel() const
-{
- // If we have an error, we are not playing.
- if (mErrorSink->mError) {
- return false;
- }
-
- // It might be resumed from remote, we should keep the audio channel agent.
- if (IsSuspendedByAudioChannel()) {
- return true;
- }
-
- // Are we paused
- if (mPaused) {
- return false;
- }
-
- // We should consider any bfcached page or inactive document as non-playing.
- if (!IsActive()) {
- return false;
- }
-
- // A loop always is playing
- if (HasAttr(kNameSpaceID_None, nsGkAtoms::loop)) {
- return true;
- }
-
- // If we are actually playing...
- if (IsCurrentlyPlaying()) {
- return true;
- }
-
- // If we are seeking, we consider it as playing
- if (mPlayingThroughTheAudioChannelBeforeSeek) {
- return true;
- }
-
- // If we are playing an external stream.
- if (mSrcAttrStream) {
- return true;
- }
-
- return false;
-}
-
void
HTMLMediaElement::UpdateAudioChannelPlayingState(bool aForcePlaying)
{
@@ -6413,177 +6331,6 @@ HTMLMediaElement::UpdateAudioChannelPlayingState(bool aForcePlaying)
}
}
-void
-HTMLMediaElement::NotifyAudioChannelAgent(bool aPlaying)
-{
- if (aPlaying) {
- // The reason we don't call NotifyStartedPlaying after the media element
- // really becomes audible is because there is another case needs to block
- // element as early as we can, we would hear sound leaking if we block it
- // too late. In that case (block autoplay in non-visited-tab), we need to
- // create a connection before decoding, because we don't want user hearing
- // any sound.
- AudioPlaybackConfig config;
- nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config,
- IsAudible());
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return;
- }
-
- WindowVolumeChanged(config.mVolume, config.mMuted);
- WindowSuspendChanged(config.mSuspend);
- } else {
- mAudioChannelAgent->NotifyStoppedPlaying();
- }
-}
-
-NS_IMETHODIMP
-HTMLMediaElement::WindowVolumeChanged(float aVolume, bool aMuted)
-{
- MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
- ("HTMLMediaElement, WindowVolumeChanged, this = %p, "
- "aVolume = %f, aMuted = %d\n", this, aVolume, aMuted));
-
- if (mAudioChannelVolume != aVolume) {
- mAudioChannelVolume = aVolume;
- SetVolumeInternal();
- }
-
- if (aMuted && !ComputedMuted()) {
- SetMutedInternal(mMuted | MUTED_BY_AUDIO_CHANNEL);
- } else if (!aMuted && ComputedMuted()) {
- SetMutedInternal(mMuted & ~MUTED_BY_AUDIO_CHANNEL);
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-HTMLMediaElement::WindowSuspendChanged(SuspendTypes aSuspend)
-{
- MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
- ("HTMLMediaElement, WindowSuspendChanged, this = %p, "
- "aSuspend = %d\n", this, aSuspend));
-
- switch (aSuspend) {
- case nsISuspendedTypes::NONE_SUSPENDED:
- ResumeFromAudioChannel();
- break;
- case nsISuspendedTypes::SUSPENDED_PAUSE:
- case nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE:
- PauseByAudioChannel(aSuspend);
- break;
- case nsISuspendedTypes::SUSPENDED_BLOCK:
- BlockByAudioChannel();
- break;
- case nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE:
- SetAudioChannelSuspended(nsISuspendedTypes::NONE_SUSPENDED);
- Pause();
- break;
- default:
- MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
- ("HTMLMediaElement, WindowSuspendChanged, this = %p, "
- "Error : unknown suspended type!\n", this));
- }
-
- return NS_OK;
-}
-
-void
-HTMLMediaElement::ResumeFromAudioChannel()
-{
- if (!IsSuspendedByAudioChannel()) {
- return;
- }
-
- switch (mAudioChannelSuspended) {
- case nsISuspendedTypes::SUSPENDED_PAUSE:
- case nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE:
- ResumeFromAudioChannelPaused(mAudioChannelSuspended);
- break;
- case nsISuspendedTypes::SUSPENDED_BLOCK:
- ResumeFromAudioChannelBlocked();
- break;
- default:
- MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
- ("HTMLMediaElement, ResumeFromAudioChannel, this = %p, "
- "Error : resume without suspended!\n", this));
- }
-}
-
-void
-HTMLMediaElement::ResumeFromAudioChannelPaused(SuspendTypes aSuspend)
-{
- MOZ_ASSERT(mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
- mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE);
-
- SetAudioChannelSuspended(nsISuspendedTypes::NONE_SUSPENDED);
- nsresult rv = Play();
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return;
- }
- DispatchAsyncEvent(NS_LITERAL_STRING("mozinterruptend"));
-}
-
-void
-HTMLMediaElement::ResumeFromAudioChannelBlocked()
-{
- MOZ_ASSERT(mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_BLOCK);
-
- SetAudioChannelSuspended(nsISuspendedTypes::NONE_SUSPENDED);
- nsresult rv = Play();
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return;
- }
-}
-
-void
-HTMLMediaElement::PauseByAudioChannel(SuspendTypes aSuspend)
-{
- if (IsSuspendedByAudioChannel()) {
- return;
- }
-
- SetAudioChannelSuspended(aSuspend);
- Pause();
- DispatchAsyncEvent(NS_LITERAL_STRING("mozinterruptbegin"));
-}
-
-void
-HTMLMediaElement::BlockByAudioChannel()
-{
- if (IsSuspendedByAudioChannel()) {
- return;
- }
-
- SetAudioChannelSuspended(nsISuspendedTypes::SUSPENDED_BLOCK);
-}
-
-void
-HTMLMediaElement::SetAudioChannelSuspended(SuspendTypes aSuspend)
-{
- if (mAudioChannelSuspended == aSuspend) {
- return;
- }
-
- MaybeNotifyMediaResumed(aSuspend);
- mAudioChannelSuspended = aSuspend;
- MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
- ("HTMLMediaElement, SetAudioChannelSuspended, this = %p, "
- "aSuspend = %d\n", this, aSuspend));
-
- NotifyAudioPlaybackChanged(
- AudioChannelService::AudibleChangedReasons::ePauseStateChanged);
-}
-
-bool
-HTMLMediaElement::IsSuspendedByAudioChannel() const
-{
- return (mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
- mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE ||
- mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_BLOCK);
-}
-
bool
HTMLMediaElement::IsAllowedToPlay()
{
@@ -6611,36 +6358,6 @@ HTMLMediaElement::IsAllowedToPlay()
return false;
}
-bool
-HTMLMediaElement::IsAllowedToPlayByAudioChannel()
-{
- // The media element has already been paused or blocked, so it can't start
- // playback again by script or user's intend until resuming by audio channel.
- if (mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
- mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_BLOCK) {
- return false;
- }
-
- // 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 (MaybeCreateAudioChannelAgent() && !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 false;
- }
-
- return true;
-}
-
-bool
-HTMLMediaElement::IsTabActivated() const
-{
- MOZ_ASSERT(mAudioChannelAgent);
- return !mAudioChannelAgent->ShouldBlockMedia();
-}
-
static const char* VisibilityString(Visibility aVisibility) {
switch(aVisibility) {
case Visibility::UNTRACKED: {
@@ -6922,17 +6639,6 @@ HTMLMediaElement::CannotDecryptWaitingForKey()
}
}
-NS_IMETHODIMP HTMLMediaElement::WindowAudioCaptureChanged(bool aCapture)
-{
- MOZ_ASSERT(mAudioChannelAgent);
-
- if (mAudioCapturedByWindow != aCapture) {
- mAudioCapturedByWindow = aCapture;
- AudioCaptureStreamChangeIfNeeded();
- }
- return NS_OK;
-}
-
AudioTrackList*
HTMLMediaElement::AudioTracks()
{
@@ -7056,59 +6762,6 @@ HTMLMediaElement::NotifyAudioPlaybackChanged(AudibleChangedReasons aReason)
}
}
-bool
-HTMLMediaElement::IsAudible() const
-{
- // Muted or the volume should not be ~0
- if (Muted() || (std::fabs(Volume()) <= 1e-7)) {
- return false;
- }
-
- // No sound can be heard during suspending.
- if (IsSuspendedByAudioChannel()) {
- return false;
- }
-
- // Silent audio track.
- if (!mIsAudioTrackAudible) {
- return false;
- }
-
- return true;
-}
-
-void
-HTMLMediaElement::MaybeNotifyMediaResumed(SuspendTypes aSuspend)
-{
- // In fennec, we should send the notification when media is resumed from the
- // pause-disposable which was called by media control.
- if (mAudioChannelSuspended != nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE &&
- aSuspend != nsISuspendedTypes::NONE_SUSPENDED) {
- return;
- }
-
- MOZ_ASSERT(mAudioChannelAgent);
- uint64_t windowID = mAudioChannelAgent->WindowID();
- NS_DispatchToMainThread(NS_NewRunnableFunction([windowID]() -> void {
- nsCOMPtr observerService =
- services::GetObserverService();
- if (NS_WARN_IF(!observerService)) {
- return;
- }
-
- nsCOMPtr wrapper =
- do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID);
- if (NS_WARN_IF(!wrapper)) {
- return;
- }
-
- wrapper->SetData(windowID);
- observerService->NotifyObservers(wrapper,
- "media-playback-resumed",
- u"active");
- }));
-}
-
bool
HTMLMediaElement::ShouldElementBePaused()
{
diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h
index 600803c55305..d2f032554734 100644
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -48,7 +48,6 @@ class MediaResource;
class MediaDecoder;
class VideoFrameContainer;
namespace dom {
-class AudioChannelAgent;
class MediaKeys;
class TextTrack;
class TimeRanges;
@@ -1204,9 +1203,6 @@ protected:
// next block of audio samples) preceeding seek target.
already_AddRefed Seek(double aTime, SeekTarget::Type aSeekType, ErrorResult& aRv);
- // A method to check if we are playing through the AudioChannel.
- bool IsPlayingThroughTheAudioChannel() const;
-
// Update the audio channel playing state
void UpdateAudioChannelPlayingState(bool aForcePlaying = false);
@@ -1222,68 +1218,18 @@ protected:
// Recomputes ready state and fires events as necessary based on current state.
void UpdateReadyStateInternal();
- // Notifies the audio channel agent when the element starts or stops playing.
- void NotifyAudioChannelAgent(bool aPlaying);
-
- // True if we create the audio channel agent successfully or we already have
- // one. The agent is used to communicate with the AudioChannelService. eg.
- // notify we are playing/audible and receive muted/unmuted/suspend/resume
- // commands from AudioChannelService.
- bool MaybeCreateAudioChannelAgent();
-
// Determine if the element should be paused because of suspend conditions.
bool ShouldElementBePaused();
// Create or destroy the captured stream.
void AudioCaptureStreamChange(bool aCapture);
- /**
- * We have different kinds of suspended cases,
- * - SUSPENDED_PAUSE
- * It's used when we temporary lost platform audio focus. MediaElement can
- * only be resumed when we gain the audio focus again.
- *
- * - SUSPENDED_PAUSE_DISPOSABLE
- * It's used when user press the pause botton on the remote media-control.
- * MediaElement can be resumed by reomte media-control or via play().
- *
- * - SUSPENDED_BLOCK
- * It's used to reduce the power comsuption, 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 shuold stop playing
- * and stop the audio channel agent. MediaElement can only be restarted by
- * play().
- */
- void PauseByAudioChannel(SuspendTypes aSuspend);
- void BlockByAudioChannel();
-
- void ResumeFromAudioChannel();
- void ResumeFromAudioChannelPaused(SuspendTypes aSuspend);
- void ResumeFromAudioChannelBlocked();
-
- bool IsSuspendedByAudioChannel() const;
- void SetAudioChannelSuspended(SuspendTypes aSuspend);
-
// A method to check whether the media element is allowed to start playback.
bool IsAllowedToPlay();
- bool IsAllowedToPlayByAudioChannel();
// If the network state is empty and then we would trigger DoLoad().
void MaybeDoLoad();
- // True if the tab which media element belongs to has been to foreground at
- // least once or activated by manually clicking the unblocking tab icon.
- bool IsTabActivated() const;
-
- bool IsAudible() const;
-
- // It's used for fennec only, send the notification when the user resumes the
- // media which was paused by media control.
- void MaybeNotifyMediaResumed(SuspendTypes aSuspend);
-
class nsAsyncEventRunner;
using nsGenericHTMLElement::DispatchEvent;
// For nsAsyncEventRunner.
@@ -1504,7 +1450,6 @@ protected:
};
uint32_t mMuted;
- SuspendTypes mAudioChannelSuspended;
// True if the media statistics are currently being shown by the builtin
// video controls
@@ -1521,19 +1466,12 @@ protected:
// True if the sound is being captured.
bool mAudioCaptured;
- // True if the sound is being captured by the window.
- bool mAudioCapturedByWindow;
-
// If TRUE then the media element was actively playing before the currently
// in progress seeking. If FALSE then the media element is either not seeking
// or was not actively playing before the current seek. Used to decide whether
// to raise the 'waiting' event as per 4.7.1.8 in HTML 5 specification.
bool mPlayingBeforeSeek;
- // if TRUE then the seek started while content was in active playing state
- // if FALSE then the seek started while the content was not playing.
- bool mPlayingThroughTheAudioChannelBeforeSeek;
-
// True iff this element is paused because the document is inactive or has
// been suspended by the audio channel service.
bool mPausedForInactiveDocumentOrChannel;
@@ -1629,21 +1567,11 @@ protected:
// Audio Channel.
AudioChannel mAudioChannel;
- // The audio channel volume
- float mAudioChannelVolume;
-
- // Is this media element playing?
- bool mPlayingThroughTheAudioChannel;
-
// Disable the video playback by track selection. This flag might not be
// enough if we ever expand the ability of supporting multi-tracks video
// playback.
bool mDisableVideo;
- // An agent used to join audio channel service and its life cycle would equal
- // to media element.
- RefPtr mAudioChannelAgent;
-
RefPtr mTextTrackManager;
RefPtr mAudioTrackList;
@@ -1735,9 +1663,6 @@ private:
// True if the audio track is not silent.
bool mIsAudioTrackAudible;
- // True if media element is audible for users.
- bool mAudible;
-
Visibility mVisibilityState;
UniquePtr mErrorSink;