diff --git a/dom/media/gtest/MockMediaResource.cpp b/dom/media/gtest/MockMediaResource.cpp index b8b1ebaf92c..03cc0e5e273 100644 --- a/dom/media/gtest/MockMediaResource.cpp +++ b/dom/media/gtest/MockMediaResource.cpp @@ -60,7 +60,8 @@ MockMediaResource::ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, int64_t MockMediaResource::GetLength() { - return fseek(mFileHandle, 0, SEEK_END); + fseek(mFileHandle, 0, SEEK_END); + return ftell(mFileHandle); } void diff --git a/dom/media/gtest/TestMP4Demuxer.cpp b/dom/media/gtest/TestMP4Demuxer.cpp index 9559eb6a670..0aee4190cd1 100644 --- a/dom/media/gtest/TestMP4Demuxer.cpp +++ b/dom/media/gtest/TestMP4Demuxer.cpp @@ -331,3 +331,34 @@ TEST(MP4Demuxer, CENCFrag) } EXPECT_EQ(ArrayLength(audio), i); } + +TEST(MP4Demuxer, GetNextKeyframe) +{ + nsRefPtr 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 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++; + } +}