Bug 1077264 - Keep searching until one correct fragment is found. r=kentuckyfriedtakahe
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 04 Oct 2014 10:55:46 +1000
changeset 208925 70af7ba3c01058433897bae0d95c9f5281df5a0b
parent 208924 314fd7709123e77ae8fd22faae5530c108535a21
child 208926 9fb226440c14b0c6663783823c39dc6a61707ce4
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerskentuckyfriedtakahe
bugs1077264
milestone35.0a1
Bug 1077264 - Keep searching until one correct fragment is found. r=kentuckyfriedtakahe
media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
--- a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
+++ b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
@@ -3563,41 +3563,39 @@ status_t MPEG4Source::fragmentedRead(
     bool isSyncSample = false;
     bool newBuffer = false;
     if (mBuffer == NULL) {
         newBuffer = true;
 
         if (mCurrentSampleIndex >= mCurrentSamples.size()) {
             // move to next fragment
             off64_t nextMoof = mNextMoofOffset; // lastSample.offset + lastSample.size;
-
-            // If we're pointing to a segment type or sidx box then we skip them.
+            mCurrentSamples.clear();
+            mCurrentSampleIndex = 0;
+            mTrackFragmentData.mPresent = false;
             uint32_t hdr[2];
             do {
                 if (mDataSource->readAt(nextMoof, hdr, 8) < 8) {
                     return ERROR_END_OF_STREAM;
                 }
                 uint64_t chunk_size = ntohl(hdr[0]);
                 uint32_t chunk_type = ntohl(hdr[1]);
 
-                if (chunk_type != FOURCC('s', 't', 'y', 'p') &&
-                    chunk_type != FOURCC('s', 'i', 'd', 'x')) {
-                    break;
+                // If we're pointing to a segment type or sidx box then we skip them.
+                if (chunk_type == FOURCC('s', 't', 'y', 'p') ||
+                    chunk_type == FOURCC('s', 'i', 'd', 'x')) {
+                    nextMoof += chunk_size;
+                    continue;
                 }
-                nextMoof += chunk_size;
-            } while(true);
-
-            mCurrentMoofOffset = nextMoof;
-            mCurrentSamples.clear();
-            mCurrentSampleIndex = 0;
-            mTrackFragmentData.mPresent = false;
-            parseChunk(&nextMoof);
-            if (mCurrentSampleIndex >= mCurrentSamples.size()) {
-                return ERROR_END_OF_STREAM;
-            }
+                mCurrentMoofOffset = nextMoof;
+                status_t ret = parseChunk(&nextMoof);
+                if (ret != OK) {
+                    return ret;
+                }
+            } while (mCurrentSamples.size() == 0);
 
             if (mTrackFragmentData.mPresent) {
                 mCurrentTime = mTrackFragmentData.mBaseMediaDecodeTime;
             }
         }
 
         const Sample *smpl = &mCurrentSamples[mCurrentSampleIndex];
         offset = smpl->offset;