Bug 1324371. Part 5 - add FinishSeek() and remove MaybeFinishSeek(). r?kaku
MozReview-Commit-ID: FvbLdPQWZ82
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1273,23 +1273,22 @@ public:
private:
void DoSeekInternal()
{
auto currentTime = mCurrentTime;
DiscardFrames(VideoQueue(), [currentTime] (int64_t aSampleTime) {
return aSampleTime <= currentTime;
});
- if (NeedMoreVideo() &&
- !Reader()->IsRequestingVideoData() &&
- !Reader()->IsWaitingVideoData()) {
+ if (!NeedMoreVideo()) {
+ FinishSeek();
+ } else if (!Reader()->IsRequestingVideoData() &&
+ !Reader()->IsWaitingVideoData()) {
RequestVideoData();
}
-
- MaybeFinishSeek(); // Might resolve mSeekTaskPromise and modify audio queue.
}
class AysncNextFrameSeekTask : public Runnable
{
public:
explicit AysncNextFrameSeekTask(NextFrameSeekingState* aStateObject)
: mStateObj(aStateObject)
{
@@ -1334,22 +1333,20 @@ private:
void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) override
{
MOZ_ASSERT(aVideo);
MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
MOZ_ASSERT(NeedMoreVideo());
if (aVideo->mTime > mCurrentTime) {
mMaster->Push(aVideo);
+ FinishSeek();
} else {
RequestVideoData();
- return;
}
-
- MaybeFinishSeek();
}
void HandleNotDecoded(MediaData::Type aType, const MediaResult& aError) override
{
MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
MOZ_ASSERT(NeedMoreVideo());
switch (aType) {
@@ -1358,39 +1355,36 @@ private:
// We don't care about audio decode errors in this state which will be
// handled by other states after seeking.
break;
}
case MediaData::VIDEO_DATA:
{
if (aError == NS_ERROR_DOM_MEDIA_END_OF_STREAM) {
VideoQueue().Finish();
+ FinishSeek();
+ break;
}
// Video seek not finished.
- if (NeedMoreVideo()) {
- switch (aError.Code()) {
- case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
- Reader()->WaitForData(MediaData::VIDEO_DATA);
- break;
- case NS_ERROR_DOM_MEDIA_CANCELED:
- RequestVideoData();
- break;
- case NS_ERROR_DOM_MEDIA_END_OF_STREAM:
- MOZ_ASSERT(false, "Shouldn't want more data for ended video.");
- break;
- default:
- // Raise an error since we can't finish video seek anyway.
- mMaster->DecodeError(aError);
- break;
- }
- return;
+ switch (aError.Code()) {
+ case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
+ Reader()->WaitForData(MediaData::VIDEO_DATA);
+ break;
+ case NS_ERROR_DOM_MEDIA_CANCELED:
+ RequestVideoData();
+ break;
+ case NS_ERROR_DOM_MEDIA_END_OF_STREAM:
+ MOZ_ASSERT(false, "Shouldn't want more data for ended video.");
+ break;
+ default:
+ // Raise an error since we can't finish video seek anyway.
+ mMaster->DecodeError(aError);
+ break;
}
-
- MaybeFinishSeek();
break;
}
default:
MOZ_ASSERT_UNREACHABLE("We cannot handle RAW_DATA or NULL_DATA here.");
}
}
void HandleAudioWaited(MediaData::Type aType) override
@@ -1455,28 +1449,25 @@ private:
mSeekJob.mTarget->SetTime(TimeUnit::FromMicroseconds(data->mTime));
} else if (VideoQueue().AtEndOfStream()) {
mSeekJob.mTarget->SetTime(mDuration);
} else {
MOZ_ASSERT(false, "No data!");
}
}
- void MaybeFinishSeek()
+ void FinishSeek()
{
- if (!NeedMoreVideo()) {
- UpdateSeekTargetTime();
-
- auto time = mSeekJob.mTarget->GetTime().ToMicroseconds();
- DiscardFrames(AudioQueue(), [time] (int64_t aSampleTime) {
- return aSampleTime < time;
- });
-
- SeekCompleted();
- }
+ MOZ_ASSERT(!NeedMoreVideo());
+ UpdateSeekTargetTime();
+ auto time = mSeekJob.mTarget->GetTime().ToMicroseconds();
+ DiscardFrames(AudioQueue(), [time] (int64_t aSampleTime) {
+ return aSampleTime < time;
+ });
+ SeekCompleted();
}
/*
* Internal state.
*/
int64_t mCurrentTime;
media::TimeUnit mDuration;
RefPtr<AysncNextFrameSeekTask> mAsyncSeekTask;