From 9acf6dac10d4c493cf307521550215e117c4df46 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 30 Jan 2015 17:45:49 -0800 Subject: [PATCH] Bug 1127203 - Be more consistent about when and how we apply the fuzz factor. r=mattwoodrow --- dom/media/mediasource/MediaSourceReader.cpp | 34 +++++++++++++-------- dom/media/mediasource/MediaSourceReader.h | 4 +-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/dom/media/mediasource/MediaSourceReader.cpp b/dom/media/mediasource/MediaSourceReader.cpp index fe37dfc8afee..9452d775a848 100644 --- a/dom/media/mediasource/MediaSourceReader.cpp +++ b/dom/media/mediasource/MediaSourceReader.cpp @@ -225,10 +225,8 @@ MediaSourceReader::OnAudioNotDecoded(NotDecodedReason aReason) AdjustEndTime(&mLastAudioTime, mAudioReader); } - // See if we can find a different reader that can pick up where we left off. We use the - // EOS_FUZZ_US to allow for the fact that our end time can be inaccurate due to bug - // 1065207. - if (SwitchAudioReader(mLastAudioTime, EOS_FUZZ_US) == READER_NEW) { + // See if we can find a different reader that can pick up where we left off. + if (SwitchAudioReader(mLastAudioTime) == READER_NEW) { mAudioSeekRequest.Begin(mAudioReader->Seek(mLastAudioTime, 0) ->RefableThen(GetTaskQueue(), __func__, this, &MediaSourceReader::CompleteAudioSeekAndDoRequest, @@ -337,10 +335,8 @@ MediaSourceReader::OnVideoNotDecoded(NotDecodedReason aReason) AdjustEndTime(&mLastVideoTime, mVideoReader); } - // See if we can find a different reader that can pick up where we left off. We use the - // EOS_FUZZ_US to allow for the fact that our end time can be inaccurate due to bug - // 1065207. - if (SwitchVideoReader(mLastVideoTime, EOS_FUZZ_US) == READER_NEW) { + // See if we can find a different reader that can pick up where we left off. + if (SwitchVideoReader(mLastVideoTime) == READER_NEW) { mVideoSeekRequest.Begin(mVideoReader->Seek(mLastVideoTime, 0) ->RefableThen(GetTaskQueue(), __func__, this, &MediaSourceReader::CompleteVideoSeekAndDoRequest, @@ -472,14 +468,21 @@ MediaSourceReader::HaveData(int64_t aTarget, MediaData::Type aType) } MediaSourceReader::SwitchReaderResult -MediaSourceReader::SwitchAudioReader(int64_t aTarget, int64_t aTolerance) +MediaSourceReader::SwitchAudioReader(int64_t aTarget) { ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); // XXX: Can't handle adding an audio track after ReadMetadata. if (!mAudioTrack) { return READER_ERROR; } - nsRefPtr newReader = SelectReader(aTarget, aTolerance, mAudioTrack->Decoders()); + + // We first search without the tolerance and then search with it, so that, in + // the case of perfectly-aligned data, we don't prematurely jump to a new + // reader and skip the last few samples of the current one. + nsRefPtr newReader = SelectReader(aTarget, /* aTolerance = */ 0, mAudioTrack->Decoders()); + if (!newReader) { + newReader = SelectReader(aTarget, EOS_FUZZ_US, mAudioTrack->Decoders()); + } if (newReader && newReader != mAudioReader) { mAudioReader->SetIdle(); mAudioReader = newReader; @@ -490,14 +493,21 @@ MediaSourceReader::SwitchAudioReader(int64_t aTarget, int64_t aTolerance) } MediaSourceReader::SwitchReaderResult -MediaSourceReader::SwitchVideoReader(int64_t aTarget, int64_t aTolerance) +MediaSourceReader::SwitchVideoReader(int64_t aTarget) { ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); // XXX: Can't handle adding a video track after ReadMetadata. if (!mVideoTrack) { return READER_ERROR; } - nsRefPtr newReader = SelectReader(aTarget, aTolerance, mVideoTrack->Decoders()); + + // We first search without the tolerance and then search with it, so that, in + // the case of perfectly-aligned data, we don't prematurely jump to a new + // reader and skip the last few samples of the current one. + nsRefPtr newReader = SelectReader(aTarget, /* aTolerance = */ 0, mVideoTrack->Decoders()); + if (!newReader) { + newReader = SelectReader(aTarget, EOS_FUZZ_US, mVideoTrack->Decoders()); + } if (newReader && newReader != mVideoReader) { mVideoReader->SetIdle(); mVideoReader = newReader; diff --git a/dom/media/mediasource/MediaSourceReader.h b/dom/media/mediasource/MediaSourceReader.h index 4e3a012b8a9d..99f427f936f2 100644 --- a/dom/media/mediasource/MediaSourceReader.h +++ b/dom/media/mediasource/MediaSourceReader.h @@ -163,8 +163,8 @@ private: READER_NEW = 1, }; - SwitchReaderResult SwitchAudioReader(int64_t aTarget, int64_t aTolerance = 0); - SwitchReaderResult SwitchVideoReader(int64_t aTarget, int64_t aTolerance = 0); + SwitchReaderResult SwitchAudioReader(int64_t aTarget); + SwitchReaderResult SwitchVideoReader(int64_t aTarget); void DoAudioRequest(); void DoVideoRequest();