Bug 1519919 - Add gtest to ensure MoofParser does not parse all tracks when given track_id 0. r=jya

Add a copy of bipbop.mp4 that has been fragmented via `mp4box.exe bipbop.mp4
-dash 10000 -subsegs-per-sidx -1` and then hex edited the track_id for video to
be 0. Add this to our already existing MP4Metadata and MoofParser gtests.

Also construct a new gtest to ensure that requesting track 0 from the MoofParser
doesn't result in all tracks being parsed. Historically this would have happened
and could result in bad metadata if the caller expected just track 0 to be
parsed.

Differential Revision: https://phabricator.services.mozilla.com/D17069

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Bryce Van Dyk 2019-01-28 20:04:11 +00:00
parent 5c4ed3e654
commit bbaf9090c4
3 changed files with 56 additions and 0 deletions

View File

@ -234,6 +234,8 @@ static const TestFileData testFiles[] = {
false, 0},
{"test_case_1410565.mp4", false, 0, false, 0, 0, 0, 0, 0, false, 955100,
true, true, 2}, // negative 'timescale'
{"test_case_1519617-video-has-track_id-0.mp4", true, 1, true, 10032000, 400,
300, 1, 10032000, false, 0, true, true, 2}, // Uses bad track id 0
};
TEST(MP4Metadata, test_case_mp4) {
@ -478,6 +480,59 @@ TEST(MoofParser, test_case_sample_description_entries) {
}
}
// We should gracefully handle track_id 0 since Bug 1519617. We'd previously
// used id 0 to trigger special handling in the MoofParser to read multiple
// track metadata, but since muxers use track id 0 in the wild, we want to
// make sure they can't accidentally trigger such handling.
TEST(MoofParser, test_case_track_id_0_does_not_read_multitracks) {
const char* zeroTrackIdFileName =
"test_case_1519617-video-has-track_id-0.mp4";
nsTArray<uint8_t> buffer = ReadTestFile(zeroTrackIdFileName);
ASSERT_FALSE(buffer.IsEmpty());
RefPtr<ByteStream> stream =
new TestStream(buffer.Elements(), buffer.Length());
// Parse track id 0. We expect to only get metadata from that track, not the
// other track with id 2.
const uint32_t videoTrackId = 0;
MoofParser parser(stream, videoTrackId, false);
// Explicitly don't call parser.Metadata() so that the parser itself will
// read the metadata as if we're in a fragmented case. Otherwise we won't
// read the trak data.
const MediaByteRangeSet byteRanges(
MediaByteRange(0, int64_t(buffer.Length())));
EXPECT_TRUE(parser.RebuildFragmentedIndex(byteRanges))
<< "MoofParser should find a valid moof as the file contains one!";
// Verify we only have data from track 0, if we parsed multiple tracks we'd
// find some of the audio track metadata here. Only check for values that
// differ between tracks.
const uint32_t videoTimescale = 90000;
const uint32_t videoSampleDuration = 3000;
const uint32_t videoSampleFlags = 0x10000;
const uint32_t videoNumSampleDescriptionEntries = 1;
EXPECT_EQ(videoTimescale, parser.mMdhd.mTimescale)
<< "Wrong timescale for video track! If value is 22050, we've read from "
"the audio track!";
EXPECT_EQ(videoTrackId, parser.mTrex.mTrackId)
<< "Wrong track id for video track! If value is 2, we've read from the "
"audio track!";
EXPECT_EQ(videoSampleDuration, parser.mTrex.mDefaultSampleDuration)
<< "Wrong sample duration for video track! If value is 1024, we've read "
"from the audio track!";
EXPECT_EQ(videoSampleFlags, parser.mTrex.mDefaultSampleFlags)
<< "Wrong sample flags for video track! If value is 0x2000000 (note "
"that's hex), we've read from the audio track!";
EXPECT_EQ(videoNumSampleDescriptionEntries,
parser.mSampleDescriptions.Length())
<< "Wrong number of sample descriptions for video track! If value is 2, "
"then we've read sample description information from video and audio "
"tracks!";
}
// This test was disabled by Bug 1224019 for producing way too much output.
// This test no longer produces such output, as we've moved away from
// stagefright, but it does take a long time to run. I can be useful to enable

View File

@ -42,6 +42,7 @@ TEST_HARNESS_FILES.gtest += [
'test_case_1389527.mp4',
'test_case_1395244.mp4',
'test_case_1410565.mp4',
'test_case_1519617-video-has-track_id-0.mp4',
]
UNIFIED_SOURCES += ['TestMP4.cpp',]