Bug 1269408: P9. Move handling logic of skip to next keyframe to its own function. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 06 May 2016 15:58:51 +1000
changeset 364206 b6fb72ebc0ce72be554b1cfb5e14afc7a5dbc56a
parent 364205 b5073a84782ace986e1e9cc58f866f21b4207f5e
child 364207 98a09981e948ed5d719573d9ff1469e21a142e61
push id17383
push userbmo:jyavenard@mozilla.com
push dateFri, 06 May 2016 06:16:15 +0000
reviewersgerald
bugs1269408
milestone49.0a1
Bug 1269408: P9. Move handling logic of skip to next keyframe to its own function. r?gerald MozReview-Commit-ID: EjCAFvdcdJ6
dom/media/MediaFormatReader.cpp
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -523,27 +523,16 @@ MediaFormatReader::RequestVideoData(bool
     return MediaDataPromise::CreateAndReject(CANCELED, __func__);
   }
 
   media::TimeUnit timeThreshold{media::TimeUnit::FromMicroseconds(aTimeThreshold)};
   // Ensure we have no pending seek going as ShouldSkip could return out of date
   // information.
   if (!mVideo.HasInternalSeekPending() &&
       ShouldSkip(aSkipToNextKeyframe, timeThreshold)) {
-    // Cancel any pending demux request.
-    mVideo.mDemuxRequest.DisconnectIfExists();
-
-    // I think it's still possible for an output to have been sent from the decoder
-    // and is currently sitting in our event queue waiting to be processed. The following
-    // flush won't clear it, and when we return to the event loop it'll be added to our
-    // output queue and be used.
-    // This code will count that as dropped, which was the intent, but not quite true.
-    mDecoder->NotifyDecodedFrames(0, 0, SizeOfVideoQueueInFrames());
-
-    Reset(TrackInfo::kVideoTrack);
     RefPtr<MediaDataPromise> p = mVideo.EnsurePromise(__func__);
     SkipVideoDemuxToNextKeyFrame(timeThreshold);
     return p;
   }
 
   RefPtr<MediaDataPromise> p = mVideo.EnsurePromise(__func__);
   NotifyDecodingRequested(TrackInfo::kVideoTrack);
 
@@ -1398,26 +1387,32 @@ MediaFormatReader::Reset(TrackType aTrac
 
   LOG("Reset(%s) END", TrackTypeToStr(aTrack));
 }
 
 void
 MediaFormatReader::SkipVideoDemuxToNextKeyFrame(media::TimeUnit aTimeThreshold)
 {
   MOZ_ASSERT(OnTaskQueue());
-
-  MOZ_ASSERT(mVideo.mDecoder);
-  MOZ_ASSERT(mVideo.HasPromise());
-  MOZ_ASSERT(!mVideo.mDecodingRequested);
   LOG("Skipping up to %lld", aTimeThreshold.ToMicroseconds());
 
-  if (mVideo.mError) {
-    mVideo.RejectPromise(DECODE_ERROR, __func__);
-    return;
+  // Cancel any pending demux request and pending demuxed samples.
+  mVideo.mDemuxRequest.DisconnectIfExists();
+
+  // I think it's still possible for an output to have been sent from the decoder
+  // and is currently sitting in our event queue waiting to be processed. The following
+  // flush won't clear it, and when we return to the event loop it'll be added to our
+  // output queue and be used.
+  // This code will count that as dropped, which was the intent, but not quite true.
+  mDecoder->NotifyDecodedFrames(0, 0, SizeOfVideoQueueInFrames());
+
+  if (mVideo.mTimeThreshold) {
+    LOGV("Internal Seek pending, cancelling it");
   }
+  Reset(TrackInfo::kVideoTrack);
 
   mSkipRequest.Begin(mVideo.mTrackDemuxer->SkipToNextRandomAccessPoint(aTimeThreshold)
                           ->Then(OwnerThread(), __func__, this,
                                  &MediaFormatReader::OnVideoSkipCompleted,
                                  &MediaFormatReader::OnVideoSkipFailed));
   return;
 }