diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 2fc0b30815e..2d040272a3f 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -573,7 +573,7 @@ HTMLMediaElement::Ended() } if (mDecoder) { - return mDecoder->IsEndedOrShutdown(); + return mDecoder->IsEnded(); } return false; @@ -2199,7 +2199,7 @@ HTMLMediaElement::Play(ErrorResult& aRv) // Even if we just did Load() or ResumeLoad(), we could already have a decoder // here if we managed to clone an existing decoder. if (mDecoder) { - if (mDecoder->IsEndedOrShutdown()) { + if (mDecoder->IsEnded()) { SetCurrentTime(0); } if (!mPausedForInactiveDocumentOrChannel) { @@ -3177,7 +3177,7 @@ void HTMLMediaElement::PlaybackEnded() // We changed state which can affect AddRemoveSelfReference AddRemoveSelfReference(); - NS_ASSERTION(!mDecoder || mDecoder->IsEndedOrShutdown(), + NS_ASSERTION(!mDecoder || mDecoder->IsEnded(), "Decoder fired ended, but not in ended state"); // Discard all output streams that have finished now. @@ -3414,7 +3414,7 @@ void HTMLMediaElement::UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatu return; } - if (mDownloadSuspendedByCache && mDecoder && !mDecoder->IsEndedOrShutdown()) { + if (mDownloadSuspendedByCache && mDecoder && !mDecoder->IsEnded()) { // The decoder has signaled that the download has been suspended by the // media cache. So move readyState into HAVE_ENOUGH_DATA, in case there's // script waiting for a "canplaythrough" event; without this forced @@ -3697,7 +3697,7 @@ bool HTMLMediaElement::IsPlaybackEnded() const // the current playback position is equal to the effective end of the media resource. // See bug 449157. return mReadyState >= nsIDOMHTMLMediaElement::HAVE_METADATA && - mDecoder ? mDecoder->IsEndedOrShutdown() : false; + mDecoder ? mDecoder->IsEnded() : false; } already_AddRefed HTMLMediaElement::GetCurrentPrincipal() @@ -3771,7 +3771,7 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement, bool aSuspendE #endif if (mDecoder) { mDecoder->Resume(false); - if (!mPaused && !mDecoder->IsEndedOrShutdown()) { + if (!mPaused && !mDecoder->IsEnded()) { mDecoder->Play(); } } else if (mSrcStream) { @@ -3832,7 +3832,7 @@ void HTMLMediaElement::AddRemoveSelfReference() bool needSelfReference = !mShuttingDown && ownerDoc->IsActive() && (mDelayingLoadEvent || - (!mPaused && mDecoder && !mDecoder->IsEndedOrShutdown()) || + (!mPaused && mDecoder && !mDecoder->IsEnded()) || (!mPaused && mSrcStream && !mSrcStream->IsFinished()) || (mDecoder && mDecoder->IsSeeking()) || CanActivateAutoplay() || diff --git a/dom/media/AbstractMediaDecoder.h b/dom/media/AbstractMediaDecoder.h index cd6179b1844..401eec8c9a0 100644 --- a/dom/media/AbstractMediaDecoder.h +++ b/dom/media/AbstractMediaDecoder.h @@ -35,11 +35,6 @@ static inline bool IsCurrentThread(nsIThread* aThread) { return NS_GetCurrentThread() == aThread; } -enum class MediaDecoderEventVisibility : int8_t { - Observable, - Suppressed -}; - /** * The AbstractMediaDecoder class describes the public interface for a media decoder * and is used by the MediaReader classes. @@ -95,9 +90,9 @@ public: // Return true if the transport layer supports seeking. virtual bool IsMediaSeekable() = 0; - virtual void MetadataLoaded(nsAutoPtr aInfo, nsAutoPtr aTags, MediaDecoderEventVisibility aEventVisibility) = 0; + virtual void MetadataLoaded(nsAutoPtr aInfo, nsAutoPtr aTags, bool aRestoredFromDormant) = 0; virtual void QueueMetadata(int64_t aTime, nsAutoPtr aInfo, nsAutoPtr aTags) = 0; - virtual void FirstFrameLoaded(nsAutoPtr aInfo, MediaDecoderEventVisibility aEventVisibility) = 0; + virtual void FirstFrameLoaded(nsAutoPtr aInfo, bool aRestoredFromDormant) = 0; virtual void RemoveMediaTracks() = 0; @@ -171,17 +166,17 @@ protected: MetadataContainer(AbstractMediaDecoder* aDecoder, nsAutoPtr aInfo, nsAutoPtr aTags, - MediaDecoderEventVisibility aEventVisibility) + bool aRestoredFromDormant) : mDecoder(aDecoder), mInfo(aInfo), mTags(aTags), - mEventVisibility(aEventVisibility) + mRestoredFromDormant(aRestoredFromDormant) {} nsRefPtr mDecoder; nsAutoPtr mInfo; nsAutoPtr mTags; - MediaDecoderEventVisibility mEventVisibility; + bool mRestoredFromDormant; }; class MetadataEventRunner : public nsRunnable, private MetadataContainer @@ -190,13 +185,13 @@ public: MetadataEventRunner(AbstractMediaDecoder* aDecoder, nsAutoPtr aInfo, nsAutoPtr aTags, - MediaDecoderEventVisibility aEventVisibility = MediaDecoderEventVisibility::Observable) - : MetadataContainer(aDecoder, aInfo, aTags, aEventVisibility) + bool aRestoredFromDormant = false) + : MetadataContainer(aDecoder, aInfo, aTags, aRestoredFromDormant) {} NS_IMETHOD Run() MOZ_OVERRIDE { - mDecoder->MetadataLoaded(mInfo, mTags, mEventVisibility); + mDecoder->MetadataLoaded(mInfo, mTags, mRestoredFromDormant); return NS_OK; } }; @@ -206,13 +201,13 @@ class FirstFrameLoadedEventRunner : public nsRunnable, private MetadataContainer public: FirstFrameLoadedEventRunner(AbstractMediaDecoder* aDecoder, nsAutoPtr aInfo, - MediaDecoderEventVisibility aEventVisibility = MediaDecoderEventVisibility::Observable) - : MetadataContainer(aDecoder, aInfo, nsAutoPtr(nullptr), aEventVisibility) + bool aRestoredFromDormant = false) + : MetadataContainer(aDecoder, aInfo, nsAutoPtr(nullptr), aRestoredFromDormant) {} NS_IMETHOD Run() MOZ_OVERRIDE { - mDecoder->FirstFrameLoaded(mInfo, mEventVisibility); + mDecoder->FirstFrameLoaded(mInfo, mRestoredFromDormant); return NS_OK; } }; @@ -223,16 +218,16 @@ public: MetadataUpdatedEventRunner(AbstractMediaDecoder* aDecoder, nsAutoPtr aInfo, nsAutoPtr aTags, - MediaDecoderEventVisibility aEventVisibility = MediaDecoderEventVisibility::Observable) - : MetadataContainer(aDecoder, aInfo, aTags, aEventVisibility) + bool aRestoredFromDormant = false) + : MetadataContainer(aDecoder, aInfo, aTags, aRestoredFromDormant) {} NS_IMETHOD Run() MOZ_OVERRIDE { nsAutoPtr info(new MediaInfo()); *info = *mInfo; - mDecoder->MetadataLoaded(info, mTags, mEventVisibility); - mDecoder->FirstFrameLoaded(mInfo, mEventVisibility); + mDecoder->MetadataLoaded(info, mTags, mRestoredFromDormant); + mDecoder->FirstFrameLoaded(mInfo, mRestoredFromDormant); return NS_OK; } }; diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 12b557e909f..8c21f7fa08b 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -150,11 +150,6 @@ void MediaDecoder::UpdateDormantState(bool aDormantTimeout, bool aActivity) return; } - DECODER_LOG("UpdateDormantState aTimeout=%d aActivity=%d mIsDormant=%d " - "ownerActive=%d ownerHidden=%d mIsHeuristicDormant=%d mPlayState=%s", - aDormantTimeout, aActivity, mIsDormant, mOwner->IsActive(), - mOwner->IsHidden(), mIsHeuristicDormant, PlayStateStr()); - bool prevDormant = mIsDormant; mIsDormant = false; if (!mOwner->IsActive()) { @@ -170,7 +165,7 @@ void MediaDecoder::UpdateDormantState(bool aDormantTimeout, bool aActivity) mIsHeuristicDormant = false; if (mIsHeuristicDormantSupported && mOwner->IsHidden()) { if (aDormantTimeout && !aActivity && - (mPlayState == PLAY_STATE_PAUSED || IsEnded())) { + (mPlayState == PLAY_STATE_PAUSED || mPlayState == PLAY_STATE_ENDED)) { // Enable heuristic dormant mIsHeuristicDormant = true; } else if(prevHeuristicDormant && !aActivity) { @@ -189,30 +184,19 @@ void MediaDecoder::UpdateDormantState(bool aDormantTimeout, bool aActivity) } if (mIsDormant) { - DECODER_LOG("UpdateDormantState() entering DORMANT state"); // enter dormant state - nsCOMPtr event = - NS_NewRunnableMethodWithArg( - mDecoderStateMachine, - &MediaDecoderStateMachine::SetDormant, - true); - mDecoderStateMachine->GetStateMachineThread()->Dispatch(event, NS_DISPATCH_NORMAL); + mDecoderStateMachine->SetDormant(true); + + int64_t timeUsecs = 0; + SecondsToUsecs(mCurrentTime, timeUsecs); + mRequestedSeekTarget = SeekTarget(timeUsecs, SeekTarget::Accurate); - if (IsEnded()) { - mWasEndedWhenEnteredDormant = true; - } mNextState = mPlayState; ChangeState(PLAY_STATE_LOADING); } else { - DECODER_LOG("UpdateDormantState() leaving DORMANT state"); // exit dormant state // trigger to state machine. - nsCOMPtr event = - NS_NewRunnableMethodWithArg( - mDecoderStateMachine, - &MediaDecoderStateMachine::SetDormant, - false); - mDecoderStateMachine->GetStateMachineThread()->Dispatch(event, NS_DISPATCH_NORMAL); + mDecoderStateMachine->SetDormant(false); } } @@ -236,7 +220,7 @@ void MediaDecoder::StartDormantTimer() !mOwner || !mOwner->IsHidden() || (mPlayState != PLAY_STATE_PAUSED && - !IsEnded())) + mPlayState != PLAY_STATE_ENDED)) { return; } @@ -263,7 +247,7 @@ void MediaDecoder::Pause() ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); if (mPlayState == PLAY_STATE_LOADING || mPlayState == PLAY_STATE_SEEKING || - IsEnded()) { + mPlayState == PLAY_STATE_ENDED) { mNextState = PLAY_STATE_PAUSED; return; } @@ -596,7 +580,6 @@ MediaDecoder::MediaDecoder() : mMinimizePreroll(false), mMediaTracksConstructed(false), mIsDormant(false), - mWasEndedWhenEnteredDormant(false), mIsHeuristicDormantSupported( Preferences::GetBool("media.decoder.heuristic.dormant.enabled", false)), mHeuristicDormantTimeout( @@ -765,12 +748,13 @@ nsresult MediaDecoder::Play() } nsresult res = ScheduleStateMachineThread(); NS_ENSURE_SUCCESS(res,res); - if (IsEnded()) { - return Seek(0, SeekTarget::PrevSyncPoint); - } else if (mPlayState == PLAY_STATE_LOADING || mPlayState == PLAY_STATE_SEEKING) { + if (mPlayState == PLAY_STATE_LOADING || mPlayState == PLAY_STATE_SEEKING) { mNextState = PLAY_STATE_PLAYING; return NS_OK; } + if (mPlayState == PLAY_STATE_ENDED) { + return Seek(0, SeekTarget::PrevSyncPoint); + } ChangeState(PLAY_STATE_PLAYING); return NS_OK; @@ -790,7 +774,6 @@ nsresult MediaDecoder::Seek(double aTime, SeekTarget::Type aSeekType) mRequestedSeekTarget = SeekTarget(timeUsecs, aSeekType); mCurrentTime = aTime; - mWasEndedWhenEnteredDormant = false; // If we are already in the seeking state, the new seek overrides the old one. if (mPlayState != PLAY_STATE_LOADING) { @@ -855,7 +838,7 @@ MediaDecoder::IsExpectingMoreData() void MediaDecoder::MetadataLoaded(nsAutoPtr aInfo, nsAutoPtr aTags, - MediaDecoderEventVisibility aEventVisibility) + bool aRestoredFromDormant) { MOZ_ASSERT(NS_IsMainThread()); @@ -885,29 +868,14 @@ void MediaDecoder::MetadataLoaded(nsAutoPtr aInfo, // Make sure the element and the frame (if any) are told about // our new size. Invalidate(); - if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) { + if (!aRestoredFromDormant) { mOwner->MetadataLoaded(mInfo, nsAutoPtr(aTags.forget())); } } } -const char* -MediaDecoder::PlayStateStr() -{ - switch (mPlayState) { - case PLAY_STATE_START: return "PLAY_STATE_START"; - case PLAY_STATE_LOADING: return "PLAY_STATE_LOADING"; - case PLAY_STATE_PAUSED: return "PLAY_STATE_PAUSED"; - case PLAY_STATE_PLAYING: return "PLAY_STATE_PLAYING"; - case PLAY_STATE_SEEKING: return "PLAY_STATE_SEEKING"; - case PLAY_STATE_ENDED: return "PLAY_STATE_ENDED"; - case PLAY_STATE_SHUTDOWN: return "PLAY_STATE_SHUTDOWN"; - default: return "INVALID_PLAY_STATE"; - } -} - void MediaDecoder::FirstFrameLoaded(nsAutoPtr aInfo, - MediaDecoderEventVisibility aEventVisibility) + bool aRestoredFromDormant) { MOZ_ASSERT(NS_IsMainThread()); @@ -915,17 +883,15 @@ void MediaDecoder::FirstFrameLoaded(nsAutoPtr aInfo, return; } - NS_ASSERTION(!mIsDormant, "Expected not to be dormant here"); - - DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d mPlayState=%s mIsDormant=%d", + DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d", aInfo->mAudio.mChannels, aInfo->mAudio.mRate, - aInfo->HasAudio(), aInfo->HasVideo(), PlayStateStr(), mIsDormant); + aInfo->HasAudio(), aInfo->HasVideo()); mInfo = aInfo.forget(); if (mOwner) { Invalidate(); - if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) { + if (!aRestoredFromDormant) { mOwner->FirstFrameLoaded(); } } @@ -1011,16 +977,10 @@ bool MediaDecoder::IsSeeking() const (mPlayState == PLAY_STATE_LOADING && mRequestedSeekTarget.IsValid())); } -bool MediaDecoder::IsEndedOrShutdown() const -{ - MOZ_ASSERT(NS_IsMainThread()); - return IsEnded() || mPlayState == PLAY_STATE_SHUTDOWN; -} - bool MediaDecoder::IsEnded() const { - return mPlayState == PLAY_STATE_ENDED || - (mWasEndedWhenEnteredDormant && (mPlayState != PLAY_STATE_SHUTDOWN)); + MOZ_ASSERT(NS_IsMainThread()); + return mPlayState == PLAY_STATE_ENDED || mPlayState == PLAY_STATE_SHUTDOWN; } void MediaDecoder::PlaybackEnded() @@ -1203,15 +1163,14 @@ void MediaDecoder::NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) void MediaDecoder::UpdateReadyStateForData() { MOZ_ASSERT(NS_IsMainThread()); - if (!mOwner || mShuttingDown || !mDecoderStateMachine) { + if (!mOwner || mShuttingDown || !mDecoderStateMachine) return; - } MediaDecoderOwner::NextFrameStatus frameStatus = mDecoderStateMachine->GetNextFrameStatus(); mOwner->UpdateReadyStateForData(frameStatus); } -void MediaDecoder::SeekingStopped(MediaDecoderEventVisibility aEventVisibility) +void MediaDecoder::SeekingStopped() { MOZ_ASSERT(NS_IsMainThread()); @@ -1229,17 +1188,15 @@ void MediaDecoder::SeekingStopped(MediaDecoderEventVisibility aEventVisibility) seekWasAborted = true; } else { UnpinForSeek(); - if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) { - ChangeState(mNextState); - } + ChangeState(mNextState); } } - PlaybackPositionChanged(aEventVisibility); + PlaybackPositionChanged(); if (mOwner) { UpdateReadyStateForData(); - if (!seekWasAborted && (aEventVisibility != MediaDecoderEventVisibility::Suppressed)) { + if (!seekWasAborted) { mOwner->SeekCompleted(); } } @@ -1247,7 +1204,7 @@ void MediaDecoder::SeekingStopped(MediaDecoderEventVisibility aEventVisibility) // This is called when seeking stopped *and* we're at the end of the // media. -void MediaDecoder::SeekingStoppedAtEnd(MediaDecoderEventVisibility aEventVisibility) +void MediaDecoder::SeekingStoppedAtEnd() { MOZ_ASSERT(NS_IsMainThread()); @@ -1271,11 +1228,11 @@ void MediaDecoder::SeekingStoppedAtEnd(MediaDecoderEventVisibility aEventVisibil } } - PlaybackPositionChanged(aEventVisibility); + PlaybackPositionChanged(); if (mOwner) { UpdateReadyStateForData(); - if (!seekWasAborted && (aEventVisibility != MediaDecoderEventVisibility::Suppressed)) { + if (!seekWasAborted) { mOwner->SeekCompleted(); if (fireEnded) { mOwner->PlaybackEnded(); @@ -1284,7 +1241,7 @@ void MediaDecoder::SeekingStoppedAtEnd(MediaDecoderEventVisibility aEventVisibil } } -void MediaDecoder::SeekingStarted(MediaDecoderEventVisibility aEventVisibility) +void MediaDecoder::SeekingStarted() { MOZ_ASSERT(NS_IsMainThread()); if (mShuttingDown) @@ -1292,9 +1249,7 @@ void MediaDecoder::SeekingStarted(MediaDecoderEventVisibility aEventVisibility) if (mOwner) { UpdateReadyStateForData(); - if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) { - mOwner->SeekStarted(); - } + mOwner->SeekStarted(); } } @@ -1326,7 +1281,7 @@ void MediaDecoder::ChangeState(PlayState aState) if (mPlayState == PLAY_STATE_PLAYING) { ConstructMediaTracks(); - } else if (IsEnded()) { + } else if (mPlayState == PLAY_STATE_ENDED) { RemoveMediaTracks(); } @@ -1362,7 +1317,7 @@ void MediaDecoder::ApplyStateToStateMachine(PlayState aState) } } -void MediaDecoder::PlaybackPositionChanged(MediaDecoderEventVisibility aEventVisibility) +void MediaDecoder::PlaybackPositionChanged() { MOZ_ASSERT(NS_IsMainThread()); if (mShuttingDown) @@ -1398,9 +1353,7 @@ void MediaDecoder::PlaybackPositionChanged(MediaDecoderEventVisibility aEventVis // frame has reflowed and the size updated beforehand. Invalidate(); - if (mOwner && - (aEventVisibility != MediaDecoderEventVisibility::Suppressed) && - lastTime != mCurrentTime) { + if (mOwner && lastTime != mCurrentTime) { FireTimeUpdate(); } } diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index 62eff590349..52ec12b08d6 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -235,22 +235,16 @@ struct SeekTarget { SeekTarget() : mTime(-1.0) , mType(SeekTarget::Invalid) - , mEventVisibility(MediaDecoderEventVisibility::Observable) { } - SeekTarget(int64_t aTimeUsecs, - Type aType, - MediaDecoderEventVisibility aEventVisibility = - MediaDecoderEventVisibility::Observable) + SeekTarget(int64_t aTimeUsecs, Type aType) : mTime(aTimeUsecs) , mType(aType) - , mEventVisibility(aEventVisibility) { } SeekTarget(const SeekTarget& aOther) : mTime(aOther.mTime) , mType(aOther.mType) - , mEventVisibility(aOther.mEventVisibility) { } bool IsValid() const { @@ -266,7 +260,6 @@ struct SeekTarget { // "Fast" seeks to the seek point preceeding mTime, whereas // "Accurate" seeks as close as possible to mTime. Type mType; - MediaDecoderEventVisibility mEventVisibility; }; class MediaDecoder : public nsIObserver, @@ -583,10 +576,9 @@ public: // Call on the main thread only. virtual bool IsSeeking() const; - // Return true if the decoder has reached the end of playback or the decoder - // has shutdown. + // Return true if the decoder has reached the end of playback. // Call on the main thread only. - virtual bool IsEndedOrShutdown() const; + virtual bool IsEnded() const; // Set the duration of the media resource in units of seconds. // This is called via a channel listener if it can pick up the duration @@ -774,12 +766,12 @@ public: // state machine. Call on the main thread only. virtual void MetadataLoaded(nsAutoPtr aInfo, nsAutoPtr aTags, - MediaDecoderEventVisibility aEventVisibility) MOZ_OVERRIDE; + bool aRestoredFromDormant) MOZ_OVERRIDE; // Called when the first audio and/or video from the media file has been loaded // by the state machine. Call on the main thread only. virtual void FirstFrameLoaded(nsAutoPtr aInfo, - MediaDecoderEventVisibility aEventVisibility) MOZ_OVERRIDE; + bool aRestoredFromDormant) MOZ_OVERRIDE; // Called from MetadataLoaded(). Creates audio tracks and adds them to its // owner's audio track list, and implies to video tracks respectively. @@ -803,20 +795,20 @@ public: // Seeking has stopped. Inform the element on the main // thread. - void SeekingStopped(MediaDecoderEventVisibility aEventVisibility = MediaDecoderEventVisibility::Observable); + void SeekingStopped(); // Seeking has stopped at the end of the resource. Inform the element on the main // thread. - void SeekingStoppedAtEnd(MediaDecoderEventVisibility aEventVisibility = MediaDecoderEventVisibility::Observable); + void SeekingStoppedAtEnd(); // Seeking has started. Inform the element on the main // thread. - void SeekingStarted(MediaDecoderEventVisibility aEventVisibility = MediaDecoderEventVisibility::Observable); + void SeekingStarted(); // Called when the backend has changed the current playback // position. It dispatches a timeupdate event and invalidates the frame. // This must be called on the main thread only. - virtual void PlaybackPositionChanged(MediaDecoderEventVisibility aEventVisibility = MediaDecoderEventVisibility::Observable); + virtual void PlaybackPositionChanged(); // Calls mElement->UpdateReadyStateForData, telling it whether we have // data for the next frame and if we're buffering. Main thread only. @@ -1036,9 +1028,6 @@ protected: // Cancel a timer for heuristic dormant. void CancelDormantTimer(); - // Return true if the decoder has reached the end of playback - bool IsEnded() const; - /****** * The following members should be accessed with the decoder lock held. ******/ @@ -1156,8 +1145,6 @@ protected: // Ensures our media stream has been unpinned. void UnpinForSeek(); - const char* PlayStateStr(); - // This should only ever be accessed from the main thread. // It is set in Init and cleared in Shutdown when the element goes away. // The decoder does not add a reference the element. @@ -1207,12 +1194,6 @@ protected: // True if MediaDecoder is in dormant state. bool mIsDormant; - // True if MediaDecoder was PLAY_STATE_ENDED state, when entering to dormant. - // When MediaCodec is in dormant during PLAY_STATE_ENDED state, PlayState - // becomes different from PLAY_STATE_ENDED. But the MediaDecoder need to act - // as in PLAY_STATE_ENDED state to MediaDecoderOwner. - bool mWasEndedWhenEnteredDormant; - // True if heuristic dormant is supported. const bool mIsHeuristicDormantSupported; diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 8741139753f..8a158e9a05f 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -1245,10 +1245,7 @@ void MediaDecoderStateMachine::UpdatePlaybackPosition(int64_t aTime) if (!mPositionChangeQueued || fragmentEnded) { mPositionChangeQueued = true; nsCOMPtr event = - NS_NewRunnableMethodWithArg( - mDecoder, - &MediaDecoder::PlaybackPositionChanged, - MediaDecoderEventVisibility::Observable); + NS_NewRunnableMethod(mDecoder, &MediaDecoder::PlaybackPositionChanged); NS_DispatchToMainThread(event); } @@ -1457,12 +1454,8 @@ bool MediaDecoderStateMachine::IsDormantNeeded() void MediaDecoderStateMachine::SetDormant(bool aDormant) { - MOZ_ASSERT(OnStateMachineThread(), "Should be on state machine thread."); - ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); - - if (mState == DECODER_STATE_SHUTDOWN) { - return; - } + NS_ASSERTION(NS_IsMainThread(), "Should be on main thread."); + AssertCurrentThreadInMonitor(); if (!mReader) { return; @@ -1471,22 +1464,12 @@ void MediaDecoderStateMachine::SetDormant(bool aDormant) DECODER_LOG("SetDormant=%d", aDormant); if (aDormant) { - if (mState == DECODER_STATE_SEEKING) { - if (mQueuedSeekTarget.IsValid()) { - // Keep latest seek target - } else if (mSeekTarget.IsValid()) { + if (mState == DECODER_STATE_SEEKING && !mQueuedSeekTarget.IsValid()) { + if (mSeekTarget.IsValid()) { mQueuedSeekTarget = mSeekTarget; } else if (mCurrentSeekTarget.IsValid()) { mQueuedSeekTarget = mCurrentSeekTarget; - } else { - mQueuedSeekTarget = SeekTarget(mCurrentFrameTime, - SeekTarget::Accurate, - MediaDecoderEventVisibility::Suppressed); } - } else { - mQueuedSeekTarget = SeekTarget(mCurrentFrameTime, - SeekTarget::Accurate, - MediaDecoderEventVisibility::Suppressed); } mSeekTarget.Reset(); mCurrentSeekTarget.Reset(); @@ -1592,11 +1575,6 @@ void MediaDecoderStateMachine::PlayInternal() DispatchDecodeTasksIfNeeded(); } - if (mDecodingFrozenAtStateDecoding) { - mDecodingFrozenAtStateDecoding = false; - DispatchDecodeTasksIfNeeded(); - } - // Some state transitions still happen synchronously on the main thread. So // if the main thread invokes Play() and then Seek(), the seek will initiate // synchronously on the main thread, and the asynchronous PlayInternal task @@ -1618,6 +1596,11 @@ void MediaDecoderStateMachine::PlayInternal() StartDecoding(); } + if (mDecodingFrozenAtStateDecoding) { + mDecodingFrozenAtStateDecoding = false; + DispatchDecodeTasksIfNeeded(); + } + ScheduleStateMachine(); } @@ -1757,7 +1740,7 @@ MediaDecoderStateMachine::StartSeek(const SeekTarget& aTarget) seekTime = std::max(mStartTime, seekTime); NS_ASSERTION(seekTime >= mStartTime && seekTime <= end, "Can only seek in range [0,duration]"); - mSeekTarget = SeekTarget(seekTime, aTarget.mType, aTarget.mEventVisibility); + mSeekTarget = SeekTarget(seekTime, aTarget.mType); DECODER_LOG("Changed state to SEEKING (to %lld)", mSeekTarget.mTime); SetState(DECODER_STATE_SEEKING); @@ -2274,11 +2257,8 @@ MediaDecoderStateMachine::EnqueueLoadedMetadataEvent() { nsAutoPtr info(new MediaInfo()); *info = mInfo; - MediaDecoderEventVisibility visibility = mSentLoadedMetadataEvent? - MediaDecoderEventVisibility::Suppressed : - MediaDecoderEventVisibility::Observable; nsCOMPtr metadataLoadedEvent = - new MetadataEventRunner(mDecoder, info, mMetadataTags, visibility); + new MetadataEventRunner(mDecoder, info, mMetadataTags, mSentLoadedMetadataEvent); NS_DispatchToMainThread(metadataLoadedEvent, NS_DISPATCH_NORMAL); mSentLoadedMetadataEvent = true; } @@ -2288,11 +2268,8 @@ MediaDecoderStateMachine::EnqueueFirstFrameLoadedEvent() { nsAutoPtr info(new MediaInfo()); *info = mInfo; - MediaDecoderEventVisibility visibility = mSentFirstFrameLoadedEvent? - MediaDecoderEventVisibility::Suppressed : - MediaDecoderEventVisibility::Observable; nsCOMPtr event = - new FirstFrameLoadedEventRunner(mDecoder, info, visibility); + new FirstFrameLoadedEventRunner(mDecoder, info, mSentFirstFrameLoadedEvent); NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL); mSentFirstFrameLoadedEvent = true; } @@ -2497,10 +2474,7 @@ void MediaDecoderStateMachine::DecodeSeek() { ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor()); nsCOMPtr startEvent = - NS_NewRunnableMethodWithArg( - mDecoder, - &MediaDecoder::SeekingStarted, - mCurrentSeekTarget.mEventVisibility); + NS_NewRunnableMethod(mDecoder, &MediaDecoder::SeekingStarted); NS_DispatchToMainThread(startEvent, NS_DISPATCH_SYNC); } if (mState != DECODER_STATE_SEEKING) { @@ -2578,15 +2552,6 @@ MediaDecoderStateMachine::OnSeekFailed(nsresult aResult) // Try again. mCurrentSeekTarget = mSeekTarget; mSeekTarget.Reset(); - { - ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor()); - nsCOMPtr startEvent = - NS_NewRunnableMethodWithArg( - mDecoder, - &MediaDecoder::SeekingStarted, - mCurrentSeekTarget.mEventVisibility); - NS_DispatchToMainThread(startEvent, NS_DISPATCH_SYNC); - } mReader->Seek(mCurrentSeekTarget.mTime, mEndTime) ->Then(DecodeTaskQueue(), __func__, this, &MediaDecoderStateMachine::OnSeekCompleted, @@ -2673,20 +2638,14 @@ MediaDecoderStateMachine::SeekCompleted() // this if we're playing a live stream, since the end of media will advance // once we download more data! DECODER_LOG("Changed state from SEEKING (to %lld) to COMPLETED", seekTime); - stopEvent = NS_NewRunnableMethodWithArg( - mDecoder, - &MediaDecoder::SeekingStoppedAtEnd, - mCurrentSeekTarget.mEventVisibility); + stopEvent = NS_NewRunnableMethod(mDecoder, &MediaDecoder::SeekingStoppedAtEnd); // Explicitly set our state so we don't decode further, and so // we report playback ended to the media element. SetState(DECODER_STATE_COMPLETED); DispatchDecodeTasksIfNeeded(); } else { DECODER_LOG("Changed state from SEEKING (to %lld) to DECODING", seekTime); - stopEvent = NS_NewRunnableMethodWithArg( - mDecoder, - &MediaDecoder::SeekingStopped, - mCurrentSeekTarget.mEventVisibility); + stopEvent = NS_NewRunnableMethod(mDecoder, &MediaDecoder::SeekingStopped); StartDecoding(); } diff --git a/dom/media/mediasource/SourceBufferDecoder.cpp b/dom/media/mediasource/SourceBufferDecoder.cpp index 4e67697cc32..64944f580d8 100644 --- a/dom/media/mediasource/SourceBufferDecoder.cpp +++ b/dom/media/mediasource/SourceBufferDecoder.cpp @@ -99,14 +99,14 @@ SourceBufferDecoder::IsMediaSeekable() void SourceBufferDecoder::MetadataLoaded(nsAutoPtr aInfo, nsAutoPtr aTags, - MediaDecoderEventVisibility aEventVisibility) + bool aRestoredFromDormant) { MSE_DEBUG("UNIMPLEMENTED"); } void SourceBufferDecoder::FirstFrameLoaded(nsAutoPtr aInfo, - MediaDecoderEventVisibility aEventVisibility) + bool aRestoredFromDormant) { MSE_DEBUG("UNIMPLEMENTED"); } diff --git a/dom/media/mediasource/SourceBufferDecoder.h b/dom/media/mediasource/SourceBufferDecoder.h index 7107f960bdf..aabb07bb007 100644 --- a/dom/media/mediasource/SourceBufferDecoder.h +++ b/dom/media/mediasource/SourceBufferDecoder.h @@ -48,11 +48,8 @@ public: virtual SourceBufferResource* GetResource() const MOZ_FINAL MOZ_OVERRIDE; virtual ReentrantMonitor& GetReentrantMonitor() MOZ_FINAL MOZ_OVERRIDE; virtual VideoFrameContainer* GetVideoFrameContainer() MOZ_FINAL MOZ_OVERRIDE; - virtual void MetadataLoaded(nsAutoPtr aInfo, - nsAutoPtr aTags, - MediaDecoderEventVisibility aEventVisibility) MOZ_FINAL MOZ_OVERRIDE; - virtual void FirstFrameLoaded(nsAutoPtr aInfo, - MediaDecoderEventVisibility aEventVisibility) MOZ_FINAL MOZ_OVERRIDE; + virtual void MetadataLoaded(nsAutoPtr aInfo, nsAutoPtr aTags, bool aRestoredFromDormant) MOZ_FINAL MOZ_OVERRIDE; + virtual void FirstFrameLoaded(nsAutoPtr aInfo, bool aRestoredFromDormant) MOZ_FINAL MOZ_OVERRIDE; virtual void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) MOZ_FINAL MOZ_OVERRIDE; virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) MOZ_FINAL MOZ_OVERRIDE; virtual void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded, uint32_t aDropped) MOZ_FINAL MOZ_OVERRIDE; diff --git a/dom/media/omx/AudioOffloadPlayer.cpp b/dom/media/omx/AudioOffloadPlayer.cpp index 4b4f9a6eff8..1d10241c6bb 100644 --- a/dom/media/omx/AudioOffloadPlayer.cpp +++ b/dom/media/omx/AudioOffloadPlayer.cpp @@ -360,11 +360,8 @@ status_t AudioOffloadPlayer::SeekTo(int64_t aTimeUs, bool aDispatchSeekEvents) mDispatchSeekEvents = aDispatchSeekEvents; if (mDispatchSeekEvents) { - nsCOMPtr nsEvent = - NS_NewRunnableMethodWithArg( - mObserver, - &MediaDecoder::SeekingStarted, - MediaDecoderEventVisibility::Observable); + nsCOMPtr nsEvent = NS_NewRunnableMethod(mObserver, + &MediaDecoder::SeekingStarted); NS_DispatchToCurrentThread(nsEvent); } @@ -383,11 +380,8 @@ status_t AudioOffloadPlayer::SeekTo(int64_t aTimeUs, bool aDispatchSeekEvents) if (mDispatchSeekEvents) { mDispatchSeekEvents = false; AUDIO_OFFLOAD_LOG(PR_LOG_DEBUG, ("Fake seek complete during pause")); - nsCOMPtr nsEvent = - NS_NewRunnableMethodWithArg( - mObserver, - &MediaDecoder::SeekingStopped, - MediaDecoderEventVisibility::Observable); + nsCOMPtr nsEvent = NS_NewRunnableMethod(mObserver, + &MediaDecoder::SeekingStopped); NS_DispatchToCurrentThread(nsEvent); } } @@ -446,11 +440,8 @@ void AudioOffloadPlayer::NotifyAudioEOS() void AudioOffloadPlayer::NotifyPositionChanged() { - nsCOMPtr nsEvent = - NS_NewRunnableMethodWithArg( - mObserver, - &MediaOmxCommonDecoder::PlaybackPositionChanged, - MediaDecoderEventVisibility::Observable); + nsCOMPtr nsEvent = NS_NewRunnableMethod(mObserver, + &MediaOmxCommonDecoder::PlaybackPositionChanged); NS_DispatchToMainThread(nsEvent); } @@ -568,11 +559,8 @@ size_t AudioOffloadPlayer::FillBuffer(void* aData, size_t aSize) if (mDispatchSeekEvents && !mSeekDuringPause) { mDispatchSeekEvents = false; AUDIO_OFFLOAD_LOG(PR_LOG_DEBUG, ("FillBuffer posting SEEK_COMPLETE")); - nsCOMPtr nsEvent = - NS_NewRunnableMethodWithArg( - mObserver, - &MediaDecoder::SeekingStopped, - MediaDecoderEventVisibility::Observable); + nsCOMPtr nsEvent = NS_NewRunnableMethod(mObserver, + &MediaDecoder::SeekingStopped); NS_DispatchToMainThread(nsEvent, NS_DISPATCH_NORMAL); } else if (mSeekDuringPause) { diff --git a/dom/media/omx/MediaOmxCommonDecoder.cpp b/dom/media/omx/MediaOmxCommonDecoder.cpp index 2844f95be86..21f8ed8b618 100644 --- a/dom/media/omx/MediaOmxCommonDecoder.cpp +++ b/dom/media/omx/MediaOmxCommonDecoder.cpp @@ -58,10 +58,10 @@ MediaOmxCommonDecoder::CheckDecoderCanOffloadAudio() void MediaOmxCommonDecoder::FirstFrameLoaded(nsAutoPtr aInfo, - MediaDecoderEventVisibility aEventVisibility) + bool aRestoredFromDormant) { MOZ_ASSERT(NS_IsMainThread()); - MediaDecoder::FirstFrameLoaded(aInfo, aEventVisibility); + MediaDecoder::FirstFrameLoaded(aInfo, aRestoredFromDormant); ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); if (!CheckDecoderCanOffloadAudio()) { @@ -203,7 +203,7 @@ MediaOmxCommonDecoder::ApplyStateToStateMachine(PlayState aState) } void -MediaOmxCommonDecoder::PlaybackPositionChanged(MediaDecoderEventVisibility aEventVisibility) +MediaOmxCommonDecoder::PlaybackPositionChanged() { MOZ_ASSERT(NS_IsMainThread()); if (!mAudioOffloadPlayer) { @@ -220,9 +220,7 @@ MediaOmxCommonDecoder::PlaybackPositionChanged(MediaDecoderEventVisibility aEven ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); mCurrentTime = mAudioOffloadPlayer->GetMediaTimeSecs(); } - if (mOwner && - (aEventVisibility != MediaDecoderEventVisibility::Suppressed) && - lastTime != mCurrentTime) { + if (mOwner && lastTime != mCurrentTime) { FireTimeUpdate(); } } diff --git a/dom/media/omx/MediaOmxCommonDecoder.h b/dom/media/omx/MediaOmxCommonDecoder.h index a770a2acd84..63b32243d46 100644 --- a/dom/media/omx/MediaOmxCommonDecoder.h +++ b/dom/media/omx/MediaOmxCommonDecoder.h @@ -24,12 +24,11 @@ public: MediaOmxCommonDecoder(); virtual void FirstFrameLoaded(nsAutoPtr aInfo, - MediaDecoderEventVisibility aEventVisibility); + bool aRestoredFromDormant); virtual void ChangeState(PlayState aState); virtual void ApplyStateToStateMachine(PlayState aState); virtual void SetVolume(double aVolume); - virtual void PlaybackPositionChanged(MediaDecoderEventVisibility aEventVisibility = - MediaDecoderEventVisibility::Observable); + virtual void PlaybackPositionChanged(); virtual void UpdateReadyStateForData(); virtual void SetElementVisibility(bool aIsVisible); virtual void SetPlatformCanOffloadAudio(bool aCanOffloadAudio); diff --git a/dom/media/test/mochitest.ini b/dom/media/test/mochitest.ini index 2bd3e265e00..1daec2cb2a9 100644 --- a/dom/media/test/mochitest.ini +++ b/dom/media/test/mochitest.ini @@ -364,8 +364,6 @@ skip-if = (toolkit == 'android' && processor == 'x86') #x86 only bug 914439 [test_defaultMuted.html] [test_delay_load.html] skip-if = buildapp == 'b2g' && toolkit != 'gonk' # bug 1082984 -[test_dormant_playback.html] -skip-if = (os == 'win' && os_version == '5.1') || (os != 'win' && toolkit != 'gonk') [test_eme_access_control.html] skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s # bug 1043403, bug 1057908 [test_eme_canvas_blocked.html] diff --git a/dom/media/test/test_dormant_playback.html b/dom/media/test/test_dormant_playback.html deleted file mode 100644 index 98d44098640..00000000000 --- a/dom/media/test/test_dormant_playback.html +++ /dev/null @@ -1,82 +0,0 @@ - - - - - Media test: Test resuming from dormant does not emit seek related events - - - - -

- -
-
-
- - diff --git a/dom/media/webaudio/BufferDecoder.cpp b/dom/media/webaudio/BufferDecoder.cpp index 6fd72a934e6..0a32fdff865 100644 --- a/dom/media/webaudio/BufferDecoder.cpp +++ b/dom/media/webaudio/BufferDecoder.cpp @@ -141,13 +141,13 @@ BufferDecoder::IsMediaSeekable() } void -BufferDecoder::MetadataLoaded(nsAutoPtr aInfo, nsAutoPtr aTags, MediaDecoderEventVisibility aEventVisibility) +BufferDecoder::MetadataLoaded(nsAutoPtr aInfo, nsAutoPtr aTags, bool aRestoredFromDormant) { // ignore } void -BufferDecoder::FirstFrameLoaded(nsAutoPtr aInfo, MediaDecoderEventVisibility aEventVisibility) +BufferDecoder::FirstFrameLoaded(nsAutoPtr aInfo, bool aRestoredFromDormant) { // ignore } diff --git a/dom/media/webaudio/BufferDecoder.h b/dom/media/webaudio/BufferDecoder.h index 404551c0179..070d62bab36 100644 --- a/dom/media/webaudio/BufferDecoder.h +++ b/dom/media/webaudio/BufferDecoder.h @@ -60,12 +60,9 @@ public: virtual bool IsMediaSeekable() MOZ_FINAL MOZ_OVERRIDE; - virtual void MetadataLoaded(nsAutoPtr aInfo, - nsAutoPtr aTags, - MediaDecoderEventVisibility aEventVisibility) MOZ_FINAL MOZ_OVERRIDE; + virtual void MetadataLoaded(nsAutoPtr aInfo, nsAutoPtr aTags, bool aRestoredFromDormant) MOZ_FINAL MOZ_OVERRIDE; virtual void QueueMetadata(int64_t aTime, nsAutoPtr aInfo, nsAutoPtr aTags) MOZ_FINAL MOZ_OVERRIDE; - virtual void FirstFrameLoaded(nsAutoPtr aInfo, - MediaDecoderEventVisibility aEventVisibility) MOZ_FINAL MOZ_OVERRIDE; + virtual void FirstFrameLoaded(nsAutoPtr aInfo, bool aRestoredFromDormant) MOZ_FINAL MOZ_OVERRIDE; virtual void RemoveMediaTracks() MOZ_FINAL MOZ_OVERRIDE;