From 306c482476b2f3c3285ba8851cbbb2ffc463ac18 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Mon, 16 Mar 2015 23:08:56 +1100 Subject: [PATCH] Bug 1139271: Part2. Ignore partial moof. r=k17e --- media/libstagefright/binding/MoofParser.cpp | 22 ++++++++++++++----- .../binding/include/mp4_demuxer/MoofParser.h | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/media/libstagefright/binding/MoofParser.cpp b/media/libstagefright/binding/MoofParser.cpp index d31e72df1493..5e0c95f162b1 100644 --- a/media/libstagefright/binding/MoofParser.cpp +++ b/media/libstagefright/binding/MoofParser.cpp @@ -30,17 +30,19 @@ namespace mp4_demuxer using namespace stagefright; using namespace mozilla; -void +bool MoofParser::RebuildFragmentedIndex( const nsTArray& 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); @@ -48,6 +50,11 @@ MoofParser::RebuildFragmentedIndex(BoxContext& aContext) } else if (box.IsType("moof")) { Moof moof(box, mTrex, mMdhd, mEdts, mSinf, mIsAudio); + 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. @@ -55,9 +62,11 @@ MoofParser::RebuildFragmentedIndex(BoxContext& aContext) } mMoofs.AppendElement(moof); + foundValidMoof = true; } mOffset = box.NextOffset(); } + return foundValidMoof; } class BlockingStream : public Stream { @@ -100,8 +109,7 @@ MoofParser::BlockingReadNextMoof() if (box.IsType("moof")) { byteRanges.Clear(); byteRanges.AppendElement(MediaByteRange(mOffset, box.Range().mEnd)); - RebuildFragmentedIndex(context); - return true; + return RebuildFragmentedIndex(context); } } return false; @@ -240,7 +248,9 @@ Moof::Moof(Box& aBox, Trex& aTrex, Mdhd& aMdhd, Edts& aEdts, Sinf& aSinf, bool a ParseTraf(box, aTrex, aMdhd, aEdts, aSinf, aIsAudio); } } - ProcessCenc(); + if (IsValid()) { + ProcessCenc(); + } } bool diff --git a/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h b/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h index 42dc61b46d77..551f61ca032b 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h +++ b/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h @@ -202,9 +202,9 @@ public: // 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& aByteRanges); - void RebuildFragmentedIndex(BoxContext& aContext); + bool RebuildFragmentedIndex(BoxContext& aContext); Interval GetCompositionRange( const nsTArray& aByteRanges); bool ReachedEnd();