Bug 1128332 - Part 3: Re-attempt to decode from last failed position. r=mattwoodrow, a=sledru
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 18 Mar 2015 14:10:58 +1100
changeset 248534 030201a8f8ed02688e76cac652bf7f938e76929f
parent 248533 a3ddca520a581a2d9267f417320d798e3b30ca5a
child 248535 8333cdfb08e80d69fdd70f2da5931473e07a4262
push id7856
push userryanvm@gmail.com
push dateMon, 30 Mar 2015 13:25:20 +0000
treeherdermozilla-aurora@7049015f9ce3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, sledru
bugs1128332
milestone38.0a2
Bug 1128332 - Part 3: Re-attempt to decode from last failed position. r=mattwoodrow, a=sledru
dom/media/mediasource/MediaSourceReader.cpp
--- a/dom/media/mediasource/MediaSourceReader.cpp
+++ b/dom/media/mediasource/MediaSourceReader.cpp
@@ -230,16 +230,17 @@ MediaSourceReader::OnAudioNotDecoded(Not
   MSE_DEBUG("aReason=%u IsEnded: %d", aReason, IsEnded());
   if (aReason == CANCELED) {
     mAudioPromise.Reject(CANCELED, __func__);
     return;
   }
 
   // If End of stream. Force switching past this stream to another reader by
   // switching to the end of the buffered range.
+  int64_t lastAudioTime = mLastAudioTime;
   if (aReason == END_OF_STREAM && mAudioSourceDecoder) {
     AdjustEndTime(&mLastAudioTime, mAudioSourceDecoder);
   }
 
   SwitchSourceResult result = SwitchAudioSource(&mLastAudioTime);
   // See if we can find a different source that can pick up where we left off.
   if (result == SOURCE_NEW) {
     GetAudioReader()->ResetDecode();
@@ -255,16 +256,22 @@ MediaSourceReader::OnAudioNotDecoded(Not
   // Otherwise we can assume that the data was either evicted or explicitely
   // removed from the source buffer and we should wait for new data.
   if (aReason == DECODE_ERROR && result != SOURCE_NONE) {
     mAudioPromise.Reject(DECODE_ERROR, __func__);
     return;
   }
 
   CheckForWaitOrEndOfStream(MediaData::AUDIO_DATA, mLastAudioTime);
+
+  if (mLastAudioTime - lastAudioTime >= EOS_FUZZ_US) {
+    // No decoders are available to switch to. We will re-attempt from the last
+    // failing position.
+    mLastAudioTime = lastAudioTime;
+  }
 }
 
 nsRefPtr<MediaDecoderReader::VideoDataPromise>
 MediaSourceReader::RequestVideoData(bool aSkipToNextKeyframe, int64_t aTimeThreshold)
 {
   nsRefPtr<VideoDataPromise> p = mVideoPromise.Ensure(__func__);
   MSE_DEBUGV("RequestVideoData(%d, %lld), mLastVideoTime=%lld",
              aSkipToNextKeyframe, aTimeThreshold, mLastVideoTime);
@@ -368,16 +375,17 @@ MediaSourceReader::OnVideoNotDecoded(Not
 
   if (aReason == CANCELED) {
     mVideoPromise.Reject(CANCELED, __func__);
     return;
   }
 
   // if End of stream. Force switching past this stream to another reader by
   // switching to the end of the buffered range.
+  int64_t lastVideoTime = mLastVideoTime;
   if (aReason == END_OF_STREAM && mVideoSourceDecoder) {
     AdjustEndTime(&mLastVideoTime, mVideoSourceDecoder);
   }
 
   // See if we can find a different reader that can pick up where we left off.
   SwitchSourceResult result = SwitchVideoSource(&mLastVideoTime);
   if (result == SOURCE_NEW) {
     GetVideoReader()->ResetDecode();
@@ -393,16 +401,22 @@ MediaSourceReader::OnVideoNotDecoded(Not
   // Otherwise we can assume that the data was either evicted or explicitely
   // removed from the source buffer and we should wait for new data.
   if (aReason == DECODE_ERROR && result != SOURCE_NONE) {
     mVideoPromise.Reject(DECODE_ERROR, __func__);
     return;
   }
 
   CheckForWaitOrEndOfStream(MediaData::VIDEO_DATA, mLastVideoTime);
+
+  if (mLastVideoTime - lastVideoTime >= EOS_FUZZ_US) {
+    // No decoders are available to switch to. We will re-attempt from the last
+    // failing position.
+    mLastVideoTime = lastVideoTime;
+  }
 }
 
 void
 MediaSourceReader::CheckForWaitOrEndOfStream(MediaData::Type aType, int64_t aTime)
 {
   // If the entire MediaSource is done, generate an EndOfStream.
   if (IsNearEnd(aType, aTime)) {
     if (aType == MediaData::AUDIO_DATA) {