Bug 1123498 - Test for MP4Reader's demuxer skip-to-next-keyframe. r=mattwoodrow

This commit is contained in:
Chris Pearce 2015-02-02 13:48:36 +13:00
parent f55829d7eb
commit 25ec09169f
2 changed files with 33 additions and 1 deletions

View File

@ -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

View File

@ -331,3 +331,34 @@ TEST(MP4Demuxer, CENCFrag)
}
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++;
}
}