Bug 1409946 - ensure we could always get keyframe while seeking. r=jya
authorAlastor Wu <alwu@mozilla.com>
Mon, 06 Nov 2017 18:35:49 +0800
changeset 443730 55c1cb6938fc2a9a55345d4202548872259a28a6
parent 443729 917324392dd4c13def255b1ec2aa293fe99c99ee
child 443731 2167381ba50140af4db113eb121f1341daa60441
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1409946, 1359058
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1409946 - ensure we could always get keyframe while seeking. r=jya Since MDSM won't treat EOS as an erorr now, so we could revert bug1359058 p2. MozReview-Commit-ID: JqkIrOiBu8v
dom/media/fmp4/MP4Demuxer.cpp
--- a/dom/media/fmp4/MP4Demuxer.cpp
+++ b/dom/media/fmp4/MP4Demuxer.cpp
@@ -405,20 +405,31 @@ RefPtr<MP4TrackDemuxer::SeekPromise>
 MP4TrackDemuxer::Seek(const media::TimeUnit& aTime)
 {
   auto seekTime = aTime;
   mQueuedSample = nullptr;
 
   mIterator->Seek(seekTime.ToMicroseconds());
 
   // Check what time we actually seeked to.
-  mQueuedSample = GetNextSample();
-  if (mQueuedSample) {
-    seekTime = mQueuedSample->mTime;
-  }
+  do {
+    RefPtr<MediaRawData> sample = GetNextSample();
+    if (!sample) {
+      return SeekPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_END_OF_STREAM,
+                                          __func__);
+    }
+    if (!sample->Size()) {
+      // This sample can't be decoded, continue searching.
+      continue;
+    }
+    if (sample->mKeyframe) {
+      mQueuedSample = sample;
+      seekTime = mQueuedSample->mTime;
+    }
+  } while (!mQueuedSample);
 
   SetNextKeyFrameTime();
 
   return SeekPromise::CreateAndResolve(seekTime, __func__);
 }
 
 already_AddRefed<MediaRawData>
 MP4TrackDemuxer::GetNextSample()