Bug 654787 - part7: Stop playing and decoding when looping is cancelled; r=jwwang

MozReview-Commit-ID: BQKVsmDSqpJ

--HG--
extra : rebase_source : 64377f37dd6d1fd2a7a550843ffc805688a4d488
This commit is contained in:
Chun-Min Chang 2017-11-21 18:15:08 +08:00
Родитель 1a75cd91ef
Коммит f7ef7354b3
1 изменённых файлов: 47 добавлений и 22 удалений

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

@ -608,27 +608,7 @@ public:
mOnVideoPopped.DisconnectIfExists();
}
void Step() override
{
if (mMaster->mPlayState != MediaDecoder::PLAY_STATE_PLAYING &&
mMaster->IsPlaying()) {
// We're playing, but the element/decoder is in paused state. Stop
// playing!
mMaster->StopPlayback();
}
// Start playback if necessary so that the clock can be properly queried.
if (!mIsPrerolling) {
mMaster->MaybeStartPlayback();
}
mMaster->UpdatePlaybackPositionPeriodically();
MOZ_ASSERT(!mMaster->IsPlaying() || mMaster->IsStateMachineScheduled(),
"Must have timer scheduled");
MaybeStartBuffering();
}
void Step() override;
State GetState() const override
{
@ -2311,6 +2291,51 @@ DecodingState::Enter()
}
}
void
MediaDecoderStateMachine::
DecodingState::Step()
{
if (mMaster->mPlayState != MediaDecoder::PLAY_STATE_PLAYING &&
mMaster->IsPlaying()) {
// We're playing, but the element/decoder is in paused state. Stop
// playing!
mMaster->StopPlayback();
}
// Start playback if necessary so that the clock can be properly queried.
if (!mIsPrerolling) {
mMaster->MaybeStartPlayback();
}
TimeUnit before = mMaster->GetMediaTime();
mMaster->UpdatePlaybackPositionPeriodically();
// After looping is cancelled, the time won't be corrected, and therefore we
// can check it to see if the end of the media track is reached.
TimeUnit adjusted = mMaster->GetClock();
Reader()->AdjustByLooping(adjusted);
// Make sure the media is started before comparing the time, or it's
// meaningless. Without checking IsStarted(), the media will be terminated
// immediately after seeking forward. When the state is just transited from
// seeking state, GetClock() is smaller than GetMediaTime(), since
// GetMediaTime() is updated upon seek is completed while GetClock() will be
// updated after the media is started again.
if (mMaster->mMediaSink->IsStarted() && !mMaster->mLooping &&
adjusted < before) {
mMaster->StopPlayback();
mMaster->mAudioDataRequest.DisconnectIfExists();
AudioQueue().Finish();
mMaster->mAudioCompleted = true;
SetState<CompletedState>();
return;
}
MOZ_ASSERT(!mMaster->IsPlaying() || mMaster->IsStateMachineScheduled(),
"Must have timer scheduled");
MaybeStartBuffering();
}
void
MediaDecoderStateMachine::
DecodingState::HandleEndOfAudio()
@ -3480,7 +3505,7 @@ MediaDecoderStateMachine::UpdatePlaybackPositionPeriodically()
// Once looping was turned on, the time is probably larger than the duration
// of the media track, so the time over the end should be corrected.
mReader->AdjustByLooping(clockTime);
bool loopback = clockTime < GetMediaTime();
bool loopback = clockTime < GetMediaTime() && mLooping;
// Skip frames up to the frame at the playback position, and figure out
// the time remaining until it's time to display the next frame and drop