Bug 1139271 - Part 2: Ignore partial moof. r=k17e, a=lsblakk
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 16 Mar 2015 23:08:56 +1100
changeset 250422 21384861c447
parent 250421 202177831c59
child 250423 f4c0cec35772
push id4583
push userryanvm@gmail.com
push date2015-03-18 16:53 +0000
treeherdermozilla-beta@067f83e99f66 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersk17e, lsblakk
bugs1139271
milestone37.0
Bug 1139271 - Part 2: Ignore partial moof. r=k17e, a=lsblakk
media/libstagefright/binding/MoofParser.cpp
media/libstagefright/binding/include/mp4_demuxer/MoofParser.h
--- a/media/libstagefright/binding/MoofParser.cpp
+++ b/media/libstagefright/binding/MoofParser.cpp
@@ -25,44 +25,53 @@ extern PRLogModuleInfo* GetDemuxerLog();
 #endif
 
 namespace mp4_demuxer
 {
 
 using namespace stagefright;
 using namespace mozilla;
 
-void
+bool
 MoofParser::RebuildFragmentedIndex(
   const nsTArray<mozilla::MediaByteRange>& aByteRanges)
 {
   BoxContext context(mSource, aByteRanges);
-  RebuildFragmentedIndex(context);
+  return RebuildFragmentedIndex(context);
 }
 
-void
+bool
 MoofParser::RebuildFragmentedIndex(BoxContext& aContext)
 {
+  bool foundValidMoof = false;
+
   for (Box box(&aContext, mOffset); 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, mEdts, mSinf);
 
+      if (!moof.IsValid() && !box.Next().IsAvailable()) {
+        // Moof isn't valid abort search for now.
+        break;
+      }
+
       if (!mMoofs.IsEmpty()) {
         // Stitch time ranges together in the case of a (hopefully small) time
         // range gap between moofs.
         mMoofs.LastElement().FixRounding(moof);
       }
 
       mMoofs.AppendElement(moof);
+      foundValidMoof = true;
     }
     mOffset = box.NextOffset();
   }
+  return foundValidMoof;
 }
 
 class BlockingStream : public Stream {
 public:
   explicit BlockingStream(Stream* aStream) : mStream(aStream)
   {
   }
 
@@ -95,18 +104,17 @@ MoofParser::BlockingReadNextMoof()
     MediaByteRange(0, std::numeric_limits<int64_t>::max()));
   nsRefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
 
   BoxContext context(stream, byteRanges);
   for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
     if (box.IsType("moof")) {
       byteRanges.Clear();
       byteRanges.AppendElement(MediaByteRange(mOffset, box.Range().mEnd));
-      RebuildFragmentedIndex(context);
-      return true;
+      return RebuildFragmentedIndex(context);
     }
   }
   return false;
 }
 
 
 Interval<Microseconds>
 MoofParser::GetCompositionRange(const nsTArray<MediaByteRange>& aByteRanges)
@@ -235,17 +243,19 @@ Moof::Moof(Box& aBox, Trex& aTrex, Mdhd&
   : mRange(aBox.Range())
   , mMaxRoundingError(0)
 {
   for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
     if (box.IsType("traf")) {
       ParseTraf(box, aTrex, aMdhd, aEdts, aSinf);
     }
   }
-  ProcessCenc();
+  if (IsValid()) {
+    ProcessCenc();
+  }
 }
 
 bool
 Moof::GetAuxInfo(AtomType aType, nsTArray<MediaByteRange>* aByteRanges)
 {
   aByteRanges->Clear();
 
   Saiz* saiz = nullptr;
--- a/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h
@@ -196,19 +196,19 @@ public:
     : mSource(aSource)
     , mOffset(0)
     , mTrex(aTrackId)
     , mMonitor(aMonitor)
   {
     // Setting the mTrex.mTrackId to 0 is a nasty work around for calculating
     // the composition range for MSE. We need an array of tracks.
   }
-  void RebuildFragmentedIndex(
+  bool RebuildFragmentedIndex(
     const nsTArray<mozilla::MediaByteRange>& aByteRanges);
-  void RebuildFragmentedIndex(BoxContext& aContext);
+  bool RebuildFragmentedIndex(BoxContext& aContext);
   Interval<Microseconds> GetCompositionRange(
     const nsTArray<mozilla::MediaByteRange>& aByteRanges);
   bool ReachedEnd();
   void ParseMoov(Box& aBox);
   void ParseTrak(Box& aBox);
   void ParseMdia(Box& aBox, Tkhd& aTkhd);
   void ParseMvex(Box& aBox);