am 1f3d61f9: am bd828233: Use the correct data offset by remembering the offset of the enclosing \'moof\'

* commit '1f3d61f99c5cbe65a2cd32985445fc9ffa12adca':
  Use the correct data offset by remembering the offset of the enclosing 'moof'
diff --git a/media/libmediaplayerservice/nuplayer/mp4/Parser.cpp b/media/libmediaplayerservice/nuplayer/mp4/Parser.cpp
index 6850842..f664e92 100644
--- a/media/libmediaplayerservice/nuplayer/mp4/Parser.cpp
+++ b/media/libmediaplayerservice/nuplayer/mp4/Parser.cpp
@@ -239,7 +239,7 @@
             mBuffer = new ABuffer(512 * 1024);
             mBuffer->setRange(0, 0);
 
-            enter(0, 0);
+            enter(0ll, 0, 0);
 
             (new AMessage(kWhatProceed, id()))->post();
             break;
@@ -529,7 +529,7 @@
         ALOGV("%sentering box of type '%s'",
                 IndentString(mStack.size()), Fourcc2String(type));
 
-        enter(type, size - offset);
+        enter(mBufferPos - offset, type, size - offset);
     } else {
         if (!fitsContainer(size)) {
             return -EINVAL;
@@ -819,8 +819,9 @@
     return -EAGAIN;
 }
 
-void Parser::enter(uint32_t type, uint64_t size) {
+void Parser::enter(off64_t offset, uint32_t type, uint64_t size) {
     Container container;
+    container.mOffset = offset;
     container.mType = type;
     container.mExtendsToEOF = (size == 0);
     container.mBytesRemaining = size;
@@ -1484,13 +1485,18 @@
     }
 
     if (!(flags & TrackFragmentHeaderInfo::kBaseDataOffsetPresent)) {
-        CHECK(!mStack.isEmpty());
+        // This should point to the position of the first byte of the
+        // enclosing 'moof' container for the first track and
+        // the end of the data of the preceding fragment for subsequent
+        // tracks.
 
-        // This should point to the start of the data inside the 'mdat' box
-        // following the current 'moof' box.
+        CHECK_GE(mStack.size(), 2u);
 
         mTrackFragmentHeaderInfo.mBaseDataOffset =
-            mBufferPos + mStack.itemAt(mStack.size() - 1).mBytesRemaining + 8;
+            mStack.itemAt(mStack.size() - 2).mOffset;
+
+        // XXX TODO: This does not do the right thing for the 2nd and
+        // subsequent tracks yet.
     }
 
     mTrackFragmentHeaderInfo.mDataOffset =
diff --git a/media/libmediaplayerservice/nuplayer/mp4/Parser.h b/media/libmediaplayerservice/nuplayer/mp4/Parser.h
index c8f9ad4..0d8d0f5 100644
--- a/media/libmediaplayerservice/nuplayer/mp4/Parser.h
+++ b/media/libmediaplayerservice/nuplayer/mp4/Parser.h
@@ -71,6 +71,7 @@
     };
 
     struct Container {
+        uint64_t mOffset;
         uint64_t mBytesRemaining;
         uint32_t mType;
         bool mExtendsToEOF;
@@ -164,7 +165,7 @@
     status_t onProceed();
     status_t onDequeueAccessUnit(size_t trackIndex, sp<ABuffer> *accessUnit);
 
-    void enter(uint32_t type, uint64_t size);
+    void enter(off64_t offset, uint32_t type, uint64_t size);
 
     uint16_t readU16(size_t offset);
     uint32_t readU32(size_t offset);