Bug 1515471 - Add gtest for mp4 sample description entry lookup. r=jya
authorBryce Van Dyk <bvandyk@mozilla.com>
Fri, 04 Jan 2019 17:57:18 +0000
changeset 509671 8bbbc4ae3211427848d827d96c62dd0220374b6f
parent 509670 416d0d25d932ececd8f54036429f3fb91e4c351d
child 509672 87219897a280cfc756aa1cf883324512285fdd74
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1515471
milestone66.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 1515471 - Add gtest for mp4 sample description entry lookup. r=jya Differential Revision: https://phabricator.services.mozilla.com/D15442
dom/media/gtest/mp4_demuxer/TestParser.cpp
--- a/dom/media/gtest/mp4_demuxer/TestParser.cpp
+++ b/dom/media/gtest/mp4_demuxer/TestParser.cpp
@@ -431,16 +431,58 @@ TEST(MoofParser, test_case_mp4) {
         << tests[test].mFilename;
     EXPECT_TRUE(parser.FirstCompleteMediaSegment().IsEmpty())
         << tests[test].mFilename;
     EXPECT_EQ(tests[test].mHeader, !parser.FirstCompleteMediaHeader().IsEmpty())
         << tests[test].mFilename;
   }
 }
 
+TEST(MoofParser, test_case_sample_description_entries) {
+  const TestFileData* tests = testFiles;
+  size_t length = ArrayLength(testFiles);
+
+  for (size_t test = 0; test < length; ++test) {
+    nsTArray<uint8_t> buffer = ReadTestFile(tests[test].mFilename);
+    ASSERT_FALSE(buffer.IsEmpty());
+    RefPtr<ByteStream> stream =
+        new TestStream(buffer.Elements(), buffer.Length());
+
+    // Parse the first track. Treating it as audio is hacky, but this doesn't
+    // affect how we read the sample description entries.
+    MoofParser parser(stream, 1, false);
+    EXPECT_EQ(0u, parser.mOffset) << tests[test].mFilename;
+    EXPECT_FALSE(parser.ReachedEnd()) << tests[test].mFilename;
+    EXPECT_TRUE(parser.mInitRange.IsEmpty()) << tests[test].mFilename;
+
+    // Explicitly don't call parser.Metadata() so that the parser itself will
+    // read the metadata as if we're in a fragmented case. Otherwise the parser
+    // won't read the sample description table.
+
+    const MediaByteRangeSet byteRanges(
+        MediaByteRange(0, int64_t(buffer.Length())));
+    EXPECT_EQ(tests[test].mValidMoof, parser.RebuildFragmentedIndex(byteRanges))
+        << tests[test].mFilename;
+
+    // We only care about crypto data from the samples descriptions right now.
+    // This test should be expanded should we read further information.
+    if (tests[test].mHasCrypto) {
+      uint32_t numEncryptedEntries = 0;
+      // It's possible to have multiple sample description entries, but we only
+      // expect one to carry crypto info for encrypted tracks.
+      for (SampleDescriptionEntry entry : parser.mSampleDescriptions) {
+        if (entry.mIsEncryptedEntry) {
+          numEncryptedEntries++;
+        }
+      }
+      EXPECT_EQ(1u, numEncryptedEntries) << tests[test].mFilename;
+    }
+  }
+}
+
 // 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
 // as a sanity check on changes to the parser, but is too taxing to run as part
 // of normal test execution.
 #if 0
 TEST(MoofParser, test_case_mp4_subsets) {
   const size_t step = 1u;