--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -879,25 +879,26 @@ public:
EventVisibility aVisibility)
{
MOZ_ASSERT(aSeekJob.mTarget.IsAccurate() || aSeekJob.mTarget.IsFast());
return SeekingState::Enter(Move(aSeekJob), aVisibility);
}
void Exit() override
{
- SeekingState::Exit();
+ // Disconnect MediaDecoder.
+ mSeekJob.RejectIfExists(__func__);
// Disconnect MediaDecoderReaderWrapper.
mSeekRequest.DisconnectIfExists();
}
void HandleAudioDecoded(MediaData* aAudio) override
{
- MOZ_ASSERT(mSeekTaskRequest.Exists(), "Seek shouldn't be finished");
+ MOZ_ASSERT(!mDoneAudioSeeking || !mDoneVideoSeeking, "Seek shouldn't be finished");
RefPtr<MediaData> audio(aAudio);
MOZ_ASSERT(audio);
// The MDSM::mDecodedAudioEndTime will be updated once the whole SeekTask is
// resolved.
SSAMPLELOG("HandleAudioDecoded [%lld,%lld]", audio->mTime, audio->GetEndTime());
@@ -914,31 +915,31 @@ public:
if (mSeekJob.mTarget.IsFast()) {
// Non-precise seek; we can stop the seek at the first sample.
mSeekedAudioData = audio;
mDoneAudioSeeking = true;
} else {
nsresult rv = DropAudioUpToSeekTarget(audio);
if (NS_FAILED(rv)) {
- mTask->RejectIfExist(rv, __func__);
+ OnSeekTaskRejected(rv);
return;
}
}
if (!mDoneAudioSeeking) {
RequestAudioData();
return;
}
MaybeFinishSeek();
}
void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) override
{
- MOZ_ASSERT(mSeekTaskRequest.Exists(), "Seek shouldn't be finished");
+ MOZ_ASSERT(!mDoneAudioSeeking || !mDoneVideoSeeking, "Seek shouldn't be finished");
RefPtr<MediaData> video(aVideo);
MOZ_ASSERT(video);
// The MDSM::mDecodedVideoEndTime will be updated once the whole SeekTask is
// resolved.
SSAMPLELOG("HandleVideoDecoded [%lld,%lld]", video->mTime, video->GetEndTime());
@@ -947,31 +948,31 @@ public:
if (mSeekJob.mTarget.IsFast()) {
// Non-precise seek. We can stop the seek at the first sample.
mSeekedVideoData = video;
mDoneVideoSeeking = true;
} else {
nsresult rv = DropVideoUpToSeekTarget(video.get());
if (NS_FAILED(rv)) {
- mTask->RejectIfExist(rv, __func__);
+ OnSeekTaskRejected(rv);
return;
}
}
if (!mDoneVideoSeeking) {
RequestVideoData();
return;
}
MaybeFinishSeek();
}
void HandleNotDecoded(MediaData::Type aType, const MediaResult& aError) override
{
- MOZ_ASSERT(mSeekTaskRequest.Exists(), "Seek shouldn't be finished");
+ MOZ_ASSERT(!mDoneAudioSeeking || !mDoneVideoSeeking, "Seek shouldn't be finished");
SSAMPLELOG("OnNotDecoded type=%d reason=%u", aType, aError.Code());
// Ignore pending requests from video-only seek.
if (aType == MediaData::AUDIO_DATA && mSeekJob.mTarget.IsVideoOnly()) {
return;
}
@@ -1004,54 +1005,48 @@ public:
mSeekedVideoData = mFirstVideoFrameAfterSeek.forget();
}
}
MaybeFinishSeek();
return;
}
// This is a decode error, delegate to the generic error path.
- mTask->RejectIfExist(aError, __func__);
+ OnSeekTaskRejected(aError);
}
void HandleAudioWaited(MediaData::Type aType) override
{
- MOZ_ASSERT(mSeekTaskRequest.Exists(), "Seek shouldn't be finished");
+ MOZ_ASSERT(!mDoneAudioSeeking || !mDoneVideoSeeking, "Seek shouldn't be finished");
// Ignore pending requests from video-only seek.
if (mSeekJob.mTarget.IsVideoOnly()) {
return;
}
RequestAudioData();
}
void HandleVideoWaited(MediaData::Type aType) override
{
- MOZ_ASSERT(mSeekTaskRequest.Exists(), "Seek shouldn't be finished");
+ MOZ_ASSERT(!mDoneAudioSeeking || !mDoneVideoSeeking, "Seek shouldn't be finished");
RequestVideoData();
}
void HandleNotWaited(const WaitForDataRejectValue& aRejection) override
{
- MOZ_ASSERT(mSeekTaskRequest.Exists(), "Seek shouldn't be finished");
+ MOZ_ASSERT(!mDoneAudioSeeking || !mDoneVideoSeeking, "Seek shouldn't be finished");
}
private:
void CreateSeekTask() override
{
mCurrentTimeBeforeSeek = TimeUnit::FromMicroseconds(mMaster->GetMediaTime());
mDoneAudioSeeking = !Info().HasAudio() || mSeekJob.mTarget.IsVideoOnly();
mDoneVideoSeeking = !Info().HasVideo();
-
- mSeekTask = new AccurateSeekTask(
- mMaster->mDecoderID, OwnerThread(), Reader(), mSeekJob.mTarget,
- Info(), mMaster->Duration(), mMaster->GetMediaTime());
-
- mTask = static_cast<AccurateSeekTask*>(mSeekTask.get());
}
void ResetMDSM() override
{
if (mSeekJob.mTarget.IsVideoOnly()) {
mMaster->Reset(TrackInfo::kVideoTrack);
} else {
mMaster->Reset();
@@ -1064,26 +1059,16 @@ private:
mSeekRequest.Begin(Reader()->Seek(mSeekJob.mTarget, mMaster->Duration())
->Then(OwnerThread(), __func__,
[this] (media::TimeUnit aUnit) {
OnSeekResolved(aUnit);
},
[this] (nsresult aResult) {
OnSeekRejected(aResult);
}));
-
- // Let SeekTask handle the following operations once the demuxer seeking is done.
- mSeekTaskRequest.Begin(mSeekTask->Seek(mMaster->Duration())
- ->Then(OwnerThread(), __func__,
- [this] (const SeekTaskResolveValue& aValue) {
- OnSeekTaskResolved(aValue);
- },
- [this] (const SeekTaskRejectValue& aValue) {
- OnSeekTaskRejected(aValue);
- }));
}
int64_t CalculateNewCurrentTime() const override
{
const int64_t seekTime = mSeekJob.mTarget.GetTime().ToMicroseconds();
// For the accurate seek, we always set the newCurrentTime = seekTime so that
// the updated HTMLMediaElement.currentTime will always be the seek target;
@@ -1125,17 +1110,17 @@ private:
RequestAudioData();
}
}
void OnSeekRejected(nsresult aResult) {
mSeekRequest.Complete();
MOZ_ASSERT(NS_FAILED(aResult), "Cancels should also disconnect mSeekRequest");
- mTask->RejectIfExist(aResult, __func__);
+ OnSeekTaskRejected(aResult);
}
void RequestAudioData()
{
MOZ_ASSERT(!mDoneAudioSeeking);
MOZ_ASSERT(!Reader()->IsRequestingAudioData());
MOZ_ASSERT(!Reader()->IsWaitingAudioData());
Reader()->RequestAudioData();
@@ -1274,60 +1259,56 @@ private:
}
return NS_OK;
}
void MaybeFinishSeek()
{
if (mDoneAudioSeeking && mDoneVideoSeeking) {
- mTask->Resolve(__func__); // Call to MDSM::SeekCompleted();
+ OnSeekTaskResolved();
}
}
- void OnSeekTaskResolved(const SeekTaskResolveValue& aValue)
+ void OnSeekTaskResolved()
{
- mSeekTaskRequest.Complete();
-
- if (aValue.mSeekedAudioData) {
- mMaster->Push(aValue.mSeekedAudioData);
+ if (mSeekedAudioData) {
+ mMaster->Push(mSeekedAudioData);
mMaster->mDecodedAudioEndTime = std::max(
- aValue.mSeekedAudioData->GetEndTime(), mMaster->mDecodedAudioEndTime);
+ mSeekedAudioData->GetEndTime(), mMaster->mDecodedAudioEndTime);
}
- if (aValue.mSeekedVideoData) {
- mMaster->Push(aValue.mSeekedVideoData);
+ if (mSeekedVideoData) {
+ mMaster->Push(mSeekedVideoData);
mMaster->mDecodedVideoEndTime = std::max(
- aValue.mSeekedVideoData->GetEndTime(), mMaster->mDecodedVideoEndTime);
+ mSeekedVideoData->GetEndTime(), mMaster->mDecodedVideoEndTime);
}
- if (aValue.mIsAudioQueueFinished) {
+ if (mIsAudioQueueFinished) {
AudioQueue().Finish();
}
- if (aValue.mIsVideoQueueFinished) {
+ if (mIsVideoQueueFinished) {
VideoQueue().Finish();
}
SeekCompleted();
}
- void OnSeekTaskRejected(const SeekTaskRejectValue& aValue)
+ void OnSeekTaskRejected(MediaResult aError)
{
- mSeekTaskRequest.Complete();
-
- if (aValue.mIsAudioQueueFinished) {
+ if (mIsAudioQueueFinished) {
AudioQueue().Finish();
}
- if (aValue.mIsVideoQueueFinished) {
+ if (mIsVideoQueueFinished) {
VideoQueue().Finish();
}
- mMaster->DecodeError(aValue.mError);
+ mMaster->DecodeError(aError);
}
/*
* Track the current seek promise made by the reader.
*/
MozPromiseRequestHolder<MediaDecoderReader::SeekPromise> mSeekRequest;
/*