Bug 1324371. Part 1 - remove IsAudioSeekComplete(). r?kaku
We don't need to wait for pending audio requests before finish seeking.
MozReview-Commit-ID: BWoivb9Gjux
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1321,20 +1321,17 @@ private:
// seek is actually performed, the ThenValue of SeekPromise has already
// been set so that it won't be postponed.
RefPtr<Runnable> r = mAsyncSeekTask = new AysncNextFrameSeekTask(this);
OwnerThread()->Dispatch(r.forget());
}
void HandleAudioDecoded(MediaData* aAudio) override
{
- MOZ_ASSERT(aAudio);
- MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
mMaster->Push(aAudio);
- MaybeFinishSeek();
}
void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) override
{
MOZ_ASSERT(aVideo);
MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
if (aVideo->mTime > mCurrentTime) {
@@ -1351,21 +1348,18 @@ private:
void HandleNotDecoded(MediaData::Type aType, const MediaResult& aError) override
{
MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
switch (aType) {
case MediaData::AUDIO_DATA:
{
- // We don't really handle audio deocde error here. Let MDSM to trigger further
- // audio decoding tasks if it needs to play audio, and MDSM will then receive
- // the decoding state from MediaDecoderReader.
-
- MaybeFinishSeek();
+ // 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();
}
@@ -1394,21 +1388,17 @@ private:
}
default:
MOZ_ASSERT_UNREACHABLE("We cannot handle RAW_DATA or NULL_DATA here.");
}
}
void HandleAudioWaited(MediaData::Type aType) override
{
- MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
-
- // We don't make an audio decode request here, instead, let MDSM to
- // trigger further audio decode tasks if MDSM itself needs to play audio.
- MaybeFinishSeek();
+ // We don't care about audio in this state.
}
void HandleVideoWaited(MediaData::Type aType) override
{
MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
if (NeedMoreVideo()) {
RequestVideoData();
@@ -1419,19 +1409,17 @@ private:
void HandleNotWaited(const WaitForDataRejectValue& aRejection) override
{
MOZ_ASSERT(!mSeekJob.mPromise.IsEmpty(), "Seek shouldn't be finished");
switch(aRejection.mType) {
case MediaData::AUDIO_DATA:
{
- // We don't make an audio decode request here, instead, let MDSM to
- // trigger further audio decode tasks if MDSM itself needs to play audio.
- MaybeFinishSeek();
+ // We don't care about audio in this state.
break;
}
case MediaData::VIDEO_DATA:
{
if (NeedMoreVideo()) {
// Error out if we can't finish video seeking.
mMaster->DecodeError(NS_ERROR_DOM_MEDIA_CANCELED);
return;
@@ -1463,23 +1451,16 @@ private:
!VideoQueue().IsFinished();
}
bool IsVideoRequestPending() const
{
return Reader()->IsRequestingVideoData() || Reader()->IsWaitingVideoData();
}
- bool IsAudioSeekComplete() const
- {
- // Don't finish seek until there are no pending requests. Otherwise, we might
- // lose audio samples for the promise is resolved asynchronously.
- return !Reader()->IsRequestingAudioData() && !Reader()->IsWaitingAudioData();
- }
-
bool IsVideoSeekComplete() const
{
// Don't finish seek until there are no pending requests. Otherwise, we might
// lose video samples for the promise is resolved asynchronously.
return !IsVideoRequestPending() && !NeedMoreVideo();
}
// Update the seek target's time before resolving this seek task, the updated
@@ -1493,17 +1474,17 @@ private:
mSeekJob.mTarget->SetTime(mDuration);
} else {
MOZ_ASSERT(false, "No data!");
}
}
void MaybeFinishSeek()
{
- if (IsAudioSeekComplete() && IsVideoSeekComplete()) {
+ if (IsVideoSeekComplete()) {
UpdateSeekTargetTime();
auto time = mSeekJob.mTarget->GetTime().ToMicroseconds();
DiscardFrames(AudioQueue(), [time] (int64_t aSampleTime) {
return aSampleTime < time;
});
SeekCompleted();