Bug 1139271 - Part 3: Only consider a Box to be available if entire content is available. r=k17e, a=lsblakk
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 16 Mar 2015 23:08:56 +1100
changeset 250423 f4c0cec35772
parent 250422 21384861c447
child 250424 6a4e68222995
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 3: Only consider a Box to be available if entire content is available. r=k17e, a=lsblakk
media/libstagefright/binding/Box.cpp
media/libstagefright/binding/include/mp4_demuxer/Box.h
--- a/media/libstagefright/binding/Box.cpp
+++ b/media/libstagefright/binding/Box.cpp
@@ -85,16 +85,22 @@ Box::Box(BoxContext* aContext, uint64_t 
   mChildOffset = mBodyOffset + BoxOffset(mType);
 
   MediaByteRange boxRange(aOffset, aOffset + size);
   if (mChildOffset > boxRange.mEnd ||
       (mParent && !mParent->mRange.Contains(boxRange)) ||
       !byteRange->Contains(boxRange)) {
     return;
   }
+
+  nsTArray<uint8_t> content;
+  if (!Read(&content, boxRange)) {
+    return;
+  }
+
   mRange = boxRange;
 }
 
 Box::Box()
   : mContext(nullptr)
 {}
 
 Box
@@ -109,22 +115,30 @@ Box::FirstChild() const
 {
   MOZ_ASSERT(IsAvailable());
   if (mChildOffset == mRange.mEnd) {
     return Box();
   }
   return Box(mContext, mChildOffset, this);
 }
 
-void
+bool
 Box::Read(nsTArray<uint8_t>* aDest)
 {
-  aDest->SetLength(mRange.mEnd - mChildOffset);
+  return Read(aDest, mRange);
+}
+
+bool
+Box::Read(nsTArray<uint8_t>* aDest, const MediaByteRange& aRange)
+{
+  aDest->SetLength(aRange.mEnd - mChildOffset);
   size_t bytes;
   if (!mContext->mSource->CachedReadAt(mChildOffset, aDest->Elements(),
                                        aDest->Length(), &bytes) ||
       bytes != aDest->Length()) {
     // Byte ranges are being reported incorrectly
     NS_WARNING("Read failed in mp4_demuxer::Box::Read()");
     aDest->Clear();
+    return false;
   }
+  return true;
 }
 }
--- a/media/libstagefright/binding/include/mp4_demuxer/Box.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/Box.h
@@ -43,17 +43,18 @@ public:
   uint64_t Length() const { return mRange.mEnd - mRange.mStart; }
   uint64_t NextOffset() const { return mRange.mEnd; }
   const MediaByteRange& Range() const { return mRange; }
   const Box* Parent() const { return mParent; }
   bool IsType(const char* aType) const { return mType == AtomType(aType); }
 
   Box Next() const;
   Box FirstChild() const;
-  void Read(nsTArray<uint8_t>* aDest);
+  bool Read(nsTArray<uint8_t>* aDest);
+  bool Read(nsTArray<uint8_t>* aDest, const MediaByteRange& aRange);
 
 private:
   bool Contains(MediaByteRange aRange) const;
   BoxContext* mContext;
   mozilla::MediaByteRange mRange;
   uint64_t mBodyOffset;
   uint64_t mChildOffset;
   AtomType mType;