Remove ApplyStateToStateMachine and PLAY_STATE_SEEKING

This commit is contained in:
trav90
2017-07-02 00:21:04 -05:00
committed by Roy Tam
parent a18f275a4d
commit e8a4024fa7
11 changed files with 130 additions and 114 deletions
+48 -49
View File
@@ -279,7 +279,6 @@ void MediaDecoder::Pause()
MOZ_ASSERT(NS_IsMainThread());
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
if (mPlayState == PLAY_STATE_LOADING ||
mPlayState == PLAY_STATE_SEEKING ||
IsEnded()) {
mNextState = PLAY_STATE_PAUSED;
return;
@@ -438,6 +437,20 @@ MediaDecoder::OutputStreamData::~OutputStreamData()
mListener->Forget();
}
void MediaDecoder::UpdateDecodedStream()
{
MOZ_ASSERT(NS_IsMainThread());
GetReentrantMonitor().AssertCurrentThreadIn();
if (mDecodedStream) {
bool blockForPlayState = mPlayState != PLAY_STATE_PLAYING || mLogicallySeeking;
if (mDecodedStream->mHaveBlockedForPlayState != blockForPlayState) {
mDecodedStream->mStream->ChangeExplicitBlockerCount(blockForPlayState ? 1 : -1);
mDecodedStream->mHaveBlockedForPlayState = blockForPlayState;
}
}
}
void MediaDecoder::DestroyDecodedStream()
{
MOZ_ASSERT(NS_IsMainThread());
@@ -604,6 +617,8 @@ MediaDecoder::MediaDecoder() :
"MediaDecoder::mPlayState (Canonical)"),
mNextState(AbstractThread::MainThread(), PLAY_STATE_PAUSED,
"MediaDecoder::mNextState (Canonical)"),
mLogicallySeeking(AbstractThread::MainThread(), false,
"MediaDecoder::mLogicallySeeking (Canonical)"),
mIgnoreProgressData(false),
mInfiniteStream(false),
mOwner(nullptr),
@@ -795,7 +810,7 @@ nsresult MediaDecoder::Play()
ScheduleStateMachineThread();
if (IsEnded()) {
return Seek(0, SeekTarget::PrevSyncPoint);
} else if (mPlayState == PLAY_STATE_LOADING || mPlayState == PLAY_STATE_SEEKING) {
} else if (mPlayState == PLAY_STATE_LOADING) {
mNextState = PLAY_STATE_PLAYING;
return NS_OK;
}
@@ -808,6 +823,8 @@ nsresult MediaDecoder::Seek(double aTime, SeekTarget::Type aSeekType)
{
MOZ_ASSERT(NS_IsMainThread());
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
NS_ENSURE_TRUE(!mShuttingDown, NS_ERROR_FAILURE);
UpdateDormantState(false /* aDormantTimeout */, true /* aActivity */);
MOZ_ASSERT(aTime >= 0.0, "Cannot seek to a negative value.");
@@ -816,23 +833,33 @@ nsresult MediaDecoder::Seek(double aTime, SeekTarget::Type aSeekType)
nsresult rv = SecondsToUsecs(aTime, timeUsecs);
NS_ENSURE_SUCCESS(rv, rv);
mRequestedSeekTarget = SeekTarget(timeUsecs, aSeekType);
mLogicalPosition = aTime;
mWasEndedWhenEnteredDormant = false;
// If we are already in the seeking state, the new seek overrides the old one.
if (mPlayState != PLAY_STATE_LOADING) {
mSeekRequest.DisconnectIfExists();
mLogicallySeeking = true;
UpdateDecodedStream();
SeekTarget target = SeekTarget(timeUsecs, aSeekType);
CallSeek(target);
if (mPlayState == PLAY_STATE_ENDED) {
bool paused = false;
if (mOwner) {
paused = mOwner->GetPaused();
}
mNextState = paused ? PLAY_STATE_PAUSED : PLAY_STATE_PLAYING;
PinForSeek();
ChangeState(PLAY_STATE_SEEKING);
ChangeState(paused ? PLAY_STATE_PAUSED : PLAY_STATE_PLAYING);
}
return NS_OK;
}
return ScheduleStateMachineThread();
void MediaDecoder::CallSeek(const SeekTarget& aTarget)
{
mSeekRequest.DisconnectIfExists();
mSeekRequest.Begin(ProxyMediaCall(mDecoderStateMachine->TaskQueue(),
mDecoderStateMachine.get(), __func__,
&MediaDecoderStateMachine::Seek, aTarget)
->Then(AbstractThread::MainThread(), __func__, this,
&MediaDecoder::OnSeekResolved, &MediaDecoder::OnSeekRejected));
}
double MediaDecoder::GetCurrentTime()
@@ -921,7 +948,6 @@ MediaDecoder::PlayStateStr()
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";
@@ -958,12 +984,7 @@ void MediaDecoder::FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo,
// state if we're still set to the original
// loading state.
if (mPlayState == PLAY_STATE_LOADING && !mIsDormant) {
if (mRequestedSeekTarget.IsValid()) {
ChangeState(PLAY_STATE_SEEKING);
}
else {
ChangeState(mNextState);
}
ChangeState(mNextState);
}
// Run NotifySuspendedStatusChanged now to give us a chance to notice
@@ -1027,8 +1048,7 @@ bool MediaDecoder::IsSameOriginMedia()
bool MediaDecoder::IsSeeking() const
{
MOZ_ASSERT(NS_IsMainThread());
return !mIsDormant && (mPlayState == PLAY_STATE_SEEKING ||
(mPlayState == PLAY_STATE_LOADING && mRequestedSeekTarget.IsValid()));
return mLogicallySeeking;
}
bool MediaDecoder::IsEndedOrShutdown() const
@@ -1048,7 +1068,7 @@ void MediaDecoder::PlaybackEnded()
MOZ_ASSERT(NS_IsMainThread());
if (mShuttingDown ||
mPlayState == PLAY_STATE_SEEKING ||
mLogicallySeeking ||
mPlayState == PLAY_STATE_LOADING) {
return;
}
@@ -1232,24 +1252,19 @@ void MediaDecoder::OnSeekResolved(SeekResolveValue aVal)
// An additional seek was requested while the current seek was
// in operation.
if (mRequestedSeekTarget.IsValid()) {
ChangeState(PLAY_STATE_SEEKING);
seekWasAborted = true;
} else {
UnpinForSeek();
fireEnded = aVal.mAtEnd;
if (aVal.mAtEnd) {
ChangeState(PLAY_STATE_ENDED);
} else if (aVal.mEventVisibility != MediaDecoderEventVisibility::Suppressed) {
ChangeState(aVal.mAtEnd ? PLAY_STATE_ENDED : mNextState);
}
UnpinForSeek();
fireEnded = aVal.mAtEnd;
if (aVal.mAtEnd) {
ChangeState(PLAY_STATE_ENDED);
}
mLogicallySeeking = false;
UpdateDecodedStream();
}
UpdateLogicalPosition(aVal.mEventVisibility);
if (mOwner) {
if (!seekWasAborted && (aVal.mEventVisibility != MediaDecoderEventVisibility::Suppressed)) {
if (aVal.mEventVisibility != MediaDecoderEventVisibility::Suppressed) {
mOwner->SeekCompleted();
if (fireEnded) {
mOwner->PlaybackEnded();
@@ -1285,34 +1300,18 @@ void MediaDecoder::ChangeState(PlayState aState)
return;
}
if (mDecodedStream) {
bool blockForPlayState = aState != PLAY_STATE_PLAYING;
if (mDecodedStream->mHaveBlockedForPlayState != blockForPlayState) {
mDecodedStream->mStream->ChangeExplicitBlockerCount(blockForPlayState ? 1 : -1);
mDecodedStream->mHaveBlockedForPlayState = blockForPlayState;
}
}
DECODER_LOG("ChangeState %s => %s",
gPlayStateStr[mPlayState], gPlayStateStr[aState]);
mPlayState = aState;
UpdateDecodedStream();
if (mPlayState == PLAY_STATE_PLAYING) {
ConstructMediaTracks();
} else if (IsEnded()) {
RemoveMediaTracks();
}
// We should move this to the code that actually initiates the seek.
if (mPlayState == PLAY_STATE_SEEKING) {
mSeekRequest.Begin(ProxyMediaCall(mDecoderStateMachine->TaskQueue(),
mDecoderStateMachine.get(), __func__,
&MediaDecoderStateMachine::Seek, mRequestedSeekTarget)
->Then(AbstractThread::MainThread(), __func__, this,
&MediaDecoder::OnSeekResolved, &MediaDecoder::OnSeekRejected));
mRequestedSeekTarget.Reset();
}
ScheduleStateMachineThread();
CancelDormantTimer();