From e939a4d7a8f7412c2d6a29d19b78f35f5521abe9 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Mon, 16 Mar 2015 23:08:56 +1100 Subject: [PATCH] Bug 1139271: Part3. Only consider a Box to be available if entire content is available. r=k17e --- media/libstagefright/binding/Box.cpp | 18 ++++++++++++++++-- .../binding/include/mp4_demuxer/Box.h | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/media/libstagefright/binding/Box.cpp b/media/libstagefright/binding/Box.cpp index af802919e3b0..500a6d0a9aac 100644 --- a/media/libstagefright/binding/Box.cpp +++ b/media/libstagefright/binding/Box.cpp @@ -90,6 +90,12 @@ Box::Box(BoxContext* aContext, uint64_t aOffset, const Box* aParent) !byteRange->Contains(boxRange)) { return; } + + nsTArray content; + if (!Read(&content, boxRange)) { + return; + } + mRange = boxRange; } @@ -114,10 +120,16 @@ Box::FirstChild() const return Box(mContext, mChildOffset, this); } -void +bool Box::Read(nsTArray* aDest) { - aDest->SetLength(mRange.mEnd - mChildOffset); + return Read(aDest, mRange); +} + +bool +Box::Read(nsTArray* aDest, const MediaByteRange& aRange) +{ + aDest->SetLength(aRange.mEnd - mChildOffset); size_t bytes; if (!mContext->mSource->CachedReadAt(mChildOffset, aDest->Elements(), aDest->Length(), &bytes) || @@ -125,6 +137,8 @@ Box::Read(nsTArray* aDest) // Byte ranges are being reported incorrectly NS_WARNING("Read failed in mp4_demuxer::Box::Read()"); aDest->Clear(); + return false; } + return true; } } diff --git a/media/libstagefright/binding/include/mp4_demuxer/Box.h b/media/libstagefright/binding/include/mp4_demuxer/Box.h index 6f37efc83daa..e94d10ae093d 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/Box.h +++ b/media/libstagefright/binding/include/mp4_demuxer/Box.h @@ -48,7 +48,8 @@ public: Box Next() const; Box FirstChild() const; - void Read(nsTArray* aDest); + bool Read(nsTArray* aDest); + bool Read(nsTArray* aDest, const MediaByteRange& aRange); private: bool Contains(MediaByteRange aRange) const;