Bug 1123498 - Test for MP4Reader's demuxer skip-to-next-keyframe. r=mattwoodrow a=testonly
☠☠ backed out by 751da1d2f7b1 ☠ ☠
authorChris Pearce <cpearce@mozilla.com>
Mon, 02 Feb 2015 13:48:36 +1300
changeset 240470 1d9e4d1fe90e164a2a41f627cb8a21cf46fb191c
parent 240469 70a37bdb8ec56f877f3378d385f83c71e735541c
child 240471 751da1d2f7b10a780a419ace5f3c435a78da6dee
push id7558
push userrgiles@mozilla.com
push dateMon, 02 Feb 2015 22:18:21 +0000
treeherdermozilla-aurora@1d9e4d1fe90e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, testonly
bugs1123498
milestone37.0a2
Bug 1123498 - Test for MP4Reader's demuxer skip-to-next-keyframe. r=mattwoodrow a=testonly
dom/media/gtest/MockMediaResource.cpp
dom/media/gtest/TestMP4Demuxer.cpp
--- a/dom/media/gtest/MockMediaResource.cpp
+++ b/dom/media/gtest/MockMediaResource.cpp
@@ -55,17 +55,18 @@ MockMediaResource::ReadAt(int64_t aOffse
   mEntry--;
 
   return ferror(mFileHandle) ? NS_ERROR_FAILURE : NS_OK;
 }
 
 int64_t
 MockMediaResource::GetLength()
 {
-  return fseek(mFileHandle, 0, SEEK_END);
+  fseek(mFileHandle, 0, SEEK_END);
+  return ftell(mFileHandle);
 }
 
 void
 MockMediaResource::MockClearBufferedRanges()
 {
   mRanges.Clear();
 }
 
--- a/dom/media/gtest/TestMP4Demuxer.cpp
+++ b/dom/media/gtest/TestMP4Demuxer.cpp
@@ -326,8 +326,39 @@ TEST(MP4Demuxer, CENCFrag)
 
   i = 0;
   while (!!(sample = d->DemuxAudioSample())) {
     nsCString text = ToCryptoString(sample->crypto);
     EXPECT_STREQ(audio[i++], text.get());
   }
   EXPECT_EQ(ArrayLength(audio), i);
 }
+
+TEST(MP4Demuxer, GetNextKeyframe)
+{
+  nsRefPtr<MP4DemuxerBinding> b = new MP4DemuxerBinding("gizmo-frag.mp4");
+  MonitorAutoLock mon(b->mMonitor);
+  MP4Demuxer* d = b->demuxer;
+
+  EXPECT_TRUE(d->Init());
+
+  // Insert a [0,end] buffered range, to simulate Moof's being buffered
+  // via MSE.
+  auto len = b->resource->GetLength();
+  b->resource->MockAddBufferedRange(0, len);
+
+  // Rebuild the index so that it can be used to find the keyframes.
+  nsTArray<MediaByteRange> ranges;
+  EXPECT_TRUE(NS_SUCCEEDED(b->resource->GetCachedRanges(ranges)));
+  d->UpdateIndex(ranges);
+
+  // gizmp-frag has two keyframes; one at dts=cts=0, and another at
+  // dts=cts=1000000. Verify we get expected results.
+
+  MP4Sample* sample;
+  size_t i = 0;
+  const int64_t keyframe = 1000000;
+  while (!!(sample = d->DemuxVideoSample())) {
+    int64_t expected = (sample->decode_timestamp < keyframe) ? keyframe : -1;
+    EXPECT_EQ(d->GetNextKeyframeTime(), expected);
+    i++;
+  }
+}