Bug 1060704 - Save MP4 init segment for later; r=kinetik
authorAnthony Jones <ajones@mozilla.com>
Mon, 01 Sep 2014 20:45:48 +1200
changeset 224498 9a8b815c493e19075695f3d2b5227a2d6722bbc6
parent 224497 cccee89ab1bf14c12cde3915a92ce90bec540a42
child 224499 67b286d214e3e535edc25a589d5260c5b810a155
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1060704
milestone34.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 1060704 - Save MP4 init segment for later; r=kinetik
content/media/mediasource/SourceBuffer.cpp
media/libstagefright/binding/MoofParser.cpp
media/libstagefright/binding/include/mp4_demuxer/MoofParser.h
--- a/content/media/mediasource/SourceBuffer.cpp
+++ b/content/media/mediasource/SourceBuffer.cpp
@@ -192,27 +192,39 @@ public:
   {
     mp4_demuxer::MoofParser parser(new mp4_demuxer::BufferStream(aData, aLength), 0);
     parser.mMdhd.mTimescale = mTimescale;
 
     nsTArray<MediaByteRange> byteRanges;
     byteRanges.AppendElement(MediaByteRange(0, aLength));
     parser.RebuildFragmentedIndex(byteRanges);
 
+    if (IsInitSegmentPresent(aData, aLength)) {
+      const MediaByteRange& range = parser.mInitRange;
+      MSE_DEBUG("MP4ContainerParser(%p)::ParseStartAndEndTimestamps: Stashed init of %u bytes.",
+                this, range.mEnd - range.mStart);
+
+      mInitData.ReplaceElementsAt(0, mInitData.Length(),
+                                  aData + range.mStart,
+                                  range.mEnd - range.mStart);
+    }
+
     // Persist the timescale for when it is absent in later chunks
     mTimescale = parser.mMdhd.mTimescale;
 
     mp4_demuxer::Interval<mp4_demuxer::Microseconds> compositionRange =
         parser.GetCompositionRange();
 
     if (compositionRange.IsNull()) {
       return false;
     }
     aStart = static_cast<double>(compositionRange.start) / USECS_PER_S;
     aEnd = static_cast<double>(compositionRange.end) / USECS_PER_S;
+    MSE_DEBUG("MP4ContainerParser(%p)::ParseStartAndEndTimestamps: [%f, %f]",
+              this, aStart, aEnd);
     return true;
   }
 
   private:
     uint32_t mTimescale;
 };
 
 
--- a/media/libstagefright/binding/MoofParser.cpp
+++ b/media/libstagefright/binding/MoofParser.cpp
@@ -14,16 +14,17 @@ using namespace mozilla;
 void
 MoofParser::RebuildFragmentedIndex(const nsTArray<MediaByteRange>& aByteRanges)
 {
   BoxContext context(mSource, aByteRanges);
 
   Box box(&context, mOffset);
   for (; box.IsAvailable(); box = box.Next()) {
     if (box.IsType("moov")) {
+      mInitRange = MediaByteRange(0, box.Range().mEnd);
       ParseMoov(box);
     } else if (box.IsType("moof")) {
       Moof moof(box, mTrex, mMdhd);
 
       if (!mMoofs.IsEmpty()) {
         // Stitch time ranges together in the case of a (hopefully small) time
         // range gap between moofs.
         mMoofs.LastElement().FixRounding(moof);
--- a/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h
@@ -133,16 +133,17 @@ public:
     const nsTArray<mozilla::MediaByteRange>& aByteRanges);
   Interval<Microseconds> GetCompositionRange();
   bool ReachedEnd();
   void ParseMoov(Box& aBox);
   void ParseTrak(Box& aBox);
   void ParseMdia(Box& aBox, Tkhd& aTkhd);
   void ParseMvex(Box& aBox);
 
+  mozilla::MediaByteRange mInitRange;
   nsRefPtr<Stream> mSource;
   uint64_t mOffset;
   nsTArray<uint64_t> mMoofOffsets;
   Mdhd mMdhd;
   Trex mTrex;
   Tfdt mTfdt;
   nsTArray<Moof> mMoofs;
 };