From f98dfa3c8fec8912b6770a8ab03f0501c5133b3c Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 29 Jan 2015 22:11:11 -0800 Subject: [PATCH] Bug 1126465 - Factor out the seeking phases into helper methods. r=mattwoodrow --- dom/media/mediasource/MediaSourceReader.cpp | 40 ++++++++++++++------- dom/media/mediasource/MediaSourceReader.h | 2 ++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/dom/media/mediasource/MediaSourceReader.cpp b/dom/media/mediasource/MediaSourceReader.cpp index 5921de1832b3..c2d13b21c267 100644 --- a/dom/media/mediasource/MediaSourceReader.cpp +++ b/dom/media/mediasource/MediaSourceReader.cpp @@ -750,17 +750,23 @@ MediaSourceReader::OnVideoSeekCompleted(int64_t aTime) if (mAudioTrack) { mPendingSeekTime = aTime; + DoAudioSeek(); + } else { + mPendingSeekTime = -1; + mSeekPromise.Resolve(aTime, __func__); + } +} + +void +MediaSourceReader::DoAudioSeek() +{ mAudioIsSeeking = true; SwitchAudioReader(mPendingSeekTime); mAudioReader->Seek(mPendingSeekTime, 0) ->Then(GetTaskQueue(), __func__, this, &MediaSourceReader::OnAudioSeekCompleted, &MediaSourceReader::OnSeekFailed); - MSE_DEBUG("MediaSourceReader(%p)::Seek audio reader=%p", this, mAudioReader.get()); - return; - } - mPendingSeekTime = -1; - mSeekPromise.Resolve(aTime, __func__); + MSE_DEBUG("MediaSourceReader(%p)::DoAudioSeek reader=%p", this, mAudioReader.get()); } void @@ -817,18 +823,26 @@ MediaSourceReader::AttemptSeek() mLastVideoTime = mPendingSeekTime; if (mVideoTrack) { - mVideoIsSeeking = true; - SwitchVideoReader(mPendingSeekTime); - mVideoReader->Seek(mPendingSeekTime, 0) - ->Then(GetTaskQueue(), __func__, this, - &MediaSourceReader::OnVideoSeekCompleted, - &MediaSourceReader::OnSeekFailed); - MSE_DEBUG("MediaSourceReader(%p)::Seek video reader=%p", this, mVideoReader.get()); + DoVideoSeek(); + } else if (mAudioTrack) { + DoAudioSeek(); } else { - OnVideoSeekCompleted(mPendingSeekTime); + MOZ_CRASH(); } } +void +MediaSourceReader::DoVideoSeek() +{ + mVideoIsSeeking = true; + SwitchVideoReader(mPendingSeekTime); + mVideoReader->Seek(mPendingSeekTime, 0) + ->Then(GetTaskQueue(), __func__, this, + &MediaSourceReader::OnVideoSeekCompleted, + &MediaSourceReader::OnSeekFailed); + MSE_DEBUG("MediaSourceReader(%p)::DoVideoSeek reader=%p", this, mVideoReader.get()); +} + nsresult MediaSourceReader::GetBuffered(dom::TimeRanges* aBuffered) { diff --git a/dom/media/mediasource/MediaSourceReader.h b/dom/media/mediasource/MediaSourceReader.h index e1ff4914b661..b3a72b4ab189 100644 --- a/dom/media/mediasource/MediaSourceReader.h +++ b/dom/media/mediasource/MediaSourceReader.h @@ -61,6 +61,8 @@ public: void OnVideoDecoded(VideoData* aSample); void OnVideoNotDecoded(NotDecodedReason aReason); + void DoVideoSeek(); + void DoAudioSeek(); void OnVideoSeekCompleted(int64_t aTime); void OnAudioSeekCompleted(int64_t aTime); void OnSeekFailed(nsresult aResult);