Bug 1127203 - Be more consistent about when and how we apply the fuzz factor. r=mattwoodrow, a=sledru
authorBobby Holley <bobbyholley@gmail.com>
Fri, 30 Jan 2015 17:45:49 -0800
changeset 243630 3dc1818e2427
parent 243629 08954688351c
child 243631 858dc45e6536
push id4420
push userryanvm@gmail.com
push date2015-02-02 16:43 +0000
treeherdermozilla-beta@e98376bbdf79 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, sledru
bugs1127203
milestone36.0
Bug 1127203 - Be more consistent about when and how we apply the fuzz factor. r=mattwoodrow, a=sledru
dom/media/mediasource/MediaSourceReader.cpp
dom/media/mediasource/MediaSourceReader.h
--- a/dom/media/mediasource/MediaSourceReader.cpp
+++ b/dom/media/mediasource/MediaSourceReader.cpp
@@ -223,20 +223,18 @@ MediaSourceReader::OnAudioNotDecoded(Not
 
   // End of stream. Force switching past this stream to another reader by
   // switching to the end of the buffered range.
   MOZ_ASSERT(aReason == END_OF_STREAM);
   if (mAudioReader) {
     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) {
     mAudioReader->Seek(mLastAudioTime, 0)
                 ->Then(GetTaskQueue(), __func__, this,
                        &MediaSourceReader::RequestAudioDataComplete,
                        &MediaSourceReader::RequestAudioDataFailed);
     return;
   }
 
   CheckForWaitOrEndOfStream(MediaData::AUDIO_DATA, mLastAudioTime);
@@ -340,20 +338,18 @@ MediaSourceReader::OnVideoNotDecoded(Not
 
   // End of stream. Force switching past this stream to another reader by
   // switching to the end of the buffered range.
   MOZ_ASSERT(aReason == END_OF_STREAM);
   if (mVideoReader) {
     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) {
     mVideoReader->Seek(mLastVideoTime, 0)
                 ->Then(GetTaskQueue(), __func__, this,
                        &MediaSourceReader::RequestVideoDataComplete,
                        &MediaSourceReader::RequestVideoDataFailed);
     return;
   }
 
   CheckForWaitOrEndOfStream(MediaData::VIDEO_DATA, mLastVideoTime);
@@ -470,42 +466,56 @@ MediaSourceReader::HaveData(int64_t aTar
 {
   TrackBuffer* trackBuffer = aType == MediaData::AUDIO_DATA ? mAudioTrack : mVideoTrack;
   MOZ_ASSERT(trackBuffer);
   nsRefPtr<MediaDecoderReader> reader = SelectReader(aTarget, EOS_FUZZ_US, trackBuffer->Decoders());
   return !!reader;
 }
 
 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<MediaDecoderReader> 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<MediaDecoderReader> 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;
     MSE_DEBUGV("MediaSourceReader(%p)::SwitchAudioReader switched reader to %p", this, mAudioReader.get());
     return READER_NEW;
   }
   return newReader ? READER_EXISTING : READER_ERROR;
 }
 
 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<MediaDecoderReader> 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<MediaDecoderReader> 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;
     MSE_DEBUGV("MediaSourceReader(%p)::SwitchVideoReader switched reader to %p", this, mVideoReader.get());
     return READER_NEW;
   }
   return newReader ? READER_EXISTING : READER_ERROR;
 }
--- a/dom/media/mediasource/MediaSourceReader.h
+++ b/dom/media/mediasource/MediaSourceReader.h
@@ -148,18 +148,19 @@ private:
   // contains aTarget (or up to aTolerance after target). Both
   // aTarget and aTolerance are in microseconds.
   enum SwitchReaderResult {
     READER_ERROR = -1,
     READER_EXISTING = 0,
     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 RequestAudioDataComplete(int64_t aTime);
   void RequestAudioDataFailed(nsresult aResult);
   void RequestVideoDataComplete(int64_t aTime);
   void RequestVideoDataFailed(nsresult aResult);
   // Will reject the MediaPromise with END_OF_STREAM if mediasource has ended
   // or with WAIT_FOR_DATA otherwise.
   void CheckForWaitOrEndOfStream(MediaData::Type aType, int64_t aTime /* microseconds */);