Bug 1423659 - Remove Ftyp and HasMetadata() since the rust parser doesn't need them. r=alfredo draft
authorbechen@mozilla.com <bechen@mozilla.com>
Tue, 09 Jan 2018 17:34:57 +0800
changeset 717571 a153b1872f0e2c18516e30bc93b6cd5b098e44af
parent 716136 168f8a884cf13a1db3ea285a0ae81499e8f54677
child 745310 85fabd53637f0f7051719e32ae95137b00ffe584
push id94738
push userbmo:bechen@mozilla.com
push dateTue, 09 Jan 2018 09:49:28 +0000
reviewersalfredo
bugs1423659
milestone59.0a1
Bug 1423659 - Remove Ftyp and HasMetadata() since the rust parser doesn't need them. r=alfredo MozReview-Commit-ID: AxPYSCG24fu
dom/media/gtest/mp4_demuxer/TestParser.cpp
dom/media/mp4/MoofParser.cpp
dom/media/mp4/MoofParser.h
--- a/dom/media/gtest/mp4_demuxer/TestParser.cpp
+++ b/dom/media/gtest/mp4_demuxer/TestParser.cpp
@@ -114,17 +114,16 @@ TEST(MoofParser, EmptyStream)
 
   MediaByteRangeSet byteRanges;
   EXPECT_FALSE(parser.RebuildFragmentedIndex(byteRanges));
 
   EXPECT_TRUE(parser.GetCompositionRange(byteRanges).IsNull());
   EXPECT_TRUE(parser.mInitRange.IsEmpty());
   EXPECT_EQ(0u, parser.mOffset);
   EXPECT_TRUE(parser.ReachedEnd());
-  EXPECT_FALSE(parser.HasMetadata());
   RefPtr<MediaByteBuffer> metadataBuffer = parser.Metadata();
   EXPECT_FALSE(metadataBuffer);
   EXPECT_TRUE(parser.FirstCompleteMediaSegment().IsEmpty());
   EXPECT_TRUE(parser.FirstCompleteMediaHeader().IsEmpty());
 }
 
 nsTArray<uint8_t>
 ReadTestFile(const char* aFilename)
@@ -390,17 +389,16 @@ TEST(MoofParser, test_case_mp4)
     ASSERT_FALSE(buffer.IsEmpty());
     RefPtr<ByteStream> stream = new TestStream(buffer.Elements(), buffer.Length());
 
     MoofParser parser(stream, 0, false);
     EXPECT_EQ(0u, parser.mOffset) << tests[test].mFilename;
     EXPECT_FALSE(parser.ReachedEnd()) << tests[test].mFilename;
     EXPECT_TRUE(parser.mInitRange.IsEmpty()) << tests[test].mFilename;
 
-    EXPECT_TRUE(parser.HasMetadata()) << tests[test].mFilename;
     RefPtr<MediaByteBuffer> metadataBuffer = parser.Metadata();
     EXPECT_TRUE(metadataBuffer) << tests[test].mFilename;
 
     EXPECT_FALSE(parser.mInitRange.IsEmpty()) << tests[test].mFilename;
     const MediaByteRangeSet byteRanges(
       MediaByteRange(0, int64_t(buffer.Length())));
     EXPECT_EQ(tests[test].mValidMoof,
               parser.RebuildFragmentedIndex(byteRanges))  << tests[test].mFilename;
@@ -437,17 +435,16 @@ TEST(MoofParser, test_case_mp4_subsets)
       while (size > 0) {
         RefPtr<TestStream> stream =
           new TestStream(buffer.Elements() + offset, size);
 
         MoofParser parser(stream, 0, false);
         MediaByteRangeSet byteRanges;
         EXPECT_FALSE(parser.RebuildFragmentedIndex(byteRanges));
         parser.GetCompositionRange(byteRanges);
-        parser.HasMetadata();
         RefPtr<MediaByteBuffer> metadataBuffer = parser.Metadata();
         parser.FirstCompleteMediaSegment();
         parser.FirstCompleteMediaHeader();
 
         if (stream->mHighestSuccessfulEndOffset <= 0) {
           // No successful reads -> Cutting down the size won't change anything.
           break;
         }
--- a/dom/media/mp4/MoofParser.cpp
+++ b/dom/media/mp4/MoofParser.cpp
@@ -169,33 +169,16 @@ MoofParser::ReadMetadata()
   int64_t length = std::numeric_limits<int64_t>::max();
   mSource->Length(&length);
   MediaByteRangeSet byteRanges;
   byteRanges += MediaByteRange(0, length);
   RefPtr<BlockingStream> stream = new BlockingStream(mSource);
 
   BoxContext context(stream, byteRanges);
   for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
-    if (box.IsType("ftyp")) {
-      RefPtr<MediaByteBuffer> data = new MediaByteBuffer();
-      CheckedInt<MediaByteBuffer::size_type> ftypLength = box.Range().Length();
-      if (!data->SetLength(ftypLength.value(), fallible)) {
-        LOG(Ftyp, "OOM");
-        return false;
-      }
-      size_t read;
-      bool rv = stream->ReadAt(box.Range().mStart, data->Elements(),
-                               ftypLength.value(), &read);
-      if (!rv || read != ftypLength.value()) {
-        return false;
-      }
-      mFtypData = data.forget();
-      mFtypBox = box;
-      continue;
-    }
     if (box.IsType("moov")) {
       RefPtr<MediaByteBuffer> data = new MediaByteBuffer();
       CheckedInt<MediaByteBuffer::size_type> moovLength = box.Range().Length();
       if (!data->SetLength(moovLength.value(), fallible)) {
         LOG(Moov, "OOM");
         return false;
       }
       size_t read;
@@ -204,52 +187,34 @@ MoofParser::ReadMetadata()
       if (!rv || read != moovLength.value()) {
         return false;
       }
       mMoovData = data.forget();
       mMoovBox = box;
       break;
     }
   }
-  mInitRange = mFtypBox.Range().Span(mMoovBox.Range());
+  mInitRange = mMoovBox.Range();
   return true;
 }
 
-bool
-MoofParser::HasMetadata()
-{
-  if (mFtypBox.IsAvailable() && mMoovBox.IsAvailable()) {
-    return true;
-  }
-  ReadMetadata();
-  return (mFtypBox.IsAvailable() && mMoovBox.IsAvailable());
-}
-
 already_AddRefed<mozilla::MediaByteBuffer>
 MoofParser::Metadata()
 {
   if (!ReadMetadata()) {
     return nullptr;
   }
-  MediaByteRange ftypRange = mFtypBox.Range();
   MediaByteRange moovRange = mMoovBox.Range();
-  CheckedInt<MediaByteBuffer::size_type> ftypLength = ftypRange.Length();
   CheckedInt<MediaByteBuffer::size_type> moovLength = moovRange.Length();
-  if (!ftypLength.isValid() || !moovLength.isValid()
-      || !ftypLength.value() || !moovLength.value()) {
-    // No ftyp or moov, or they cannot be used as array size.
+  if (!moovLength.isValid() || !moovLength.value()) {
+    // No moov, or  cannot be used as array size.
     return nullptr;
   }
-  CheckedInt<MediaByteBuffer::size_type> totalLength = ftypLength + moovLength;
-  if (!totalLength.isValid()) {
-    // Addition overflow, or sum cannot be used as array size.
-    return nullptr;
-  }
+
   RefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
-  metadata->AppendElements(mFtypData->Elements(), mFtypData->Length());
   metadata->AppendElements(mMoovData->Elements(), mMoovData->Length());
 
   return metadata.forget();
 }
 
 MP4Interval<Microseconds>
 MoofParser::GetCompositionRange(const MediaByteRangeSet& aByteRanges)
 {
--- a/dom/media/mp4/MoofParser.h
+++ b/dom/media/mp4/MoofParser.h
@@ -318,17 +318,17 @@ public:
 
   void ParseMinf(Box& aBox);
   void ParseStbl(Box& aBox);
   void ParseStsd(Box& aBox);
   void ParseEncrypted(Box& aBox);
   void ParseSinf(Box& aBox);
 
   bool BlockingReadNextMoof();
-  bool HasMetadata();
+
   already_AddRefed<mozilla::MediaByteBuffer> Metadata();
   MediaByteRange FirstCompleteMediaSegment();
   MediaByteRange FirstCompleteMediaHeader();
 
   mozilla::MediaByteRange mInitRange;
   RefPtr<ByteStream> mSource;
   uint64_t mOffset;
   Mvhd mMvhd;
@@ -338,22 +338,20 @@ public:
   Edts mEdts;
   Sinf mSinf;
 
   FallibleTArray<CencSampleEncryptionInfoEntry> mTrackSampleEncryptionInfoEntries;
   FallibleTArray<SampleToGroupEntry> mTrackSampleToGroupEntries;
 
   nsTArray<Moof>& Moofs() { return mMoofs; }
 private:
-  // Find the ftyp and moov and store them into mFtypBox/mMoovBox and mFtypData/mMoovData.
+  // Find moov and store it into mMoovBox and mMoovData.
   bool ReadMetadata();
   nsTArray<Moof> mMoofs;
   nsTArray<MediaByteRange> mMediaRanges;
   bool mIsAudio;
   uint64_t mLastDecodeTime;
-  Box mFtypBox;
-  RefPtr<mozilla::MediaByteBuffer> mFtypData;
   Box mMoovBox;
   RefPtr<mozilla::MediaByteBuffer> mMoovData;
 };
 }
 
 #endif