Loading media/libstagefright/MPEG4Extractor.cpp +60 −8 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ public: const sp<SampleTable> &sampleTable, Vector<SidxEntry> &sidx, off64_t firstMoofOffset); virtual status_t init(); virtual status_t start(MetaData *params = NULL); virtual status_t stop(); Loading Loading @@ -1924,7 +1925,10 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) { if (mLastTrack == NULL) { return ERROR_MALFORMED; } parseSegmentIndex(data_offset, chunk_data_size); status_t err = parseSegmentIndex(data_offset, chunk_data_size); if (err != OK) { return err; } *offset += chunk_size; return UNKNOWN_ERROR; // stop parsing after sidx } Loading Loading @@ -2369,9 +2373,13 @@ sp<MediaSource> MPEG4Extractor::getTrack(size_t index) { ALOGV("getTrack called, pssh: %d", mPssh.size()); return new MPEG4Source( sp<MPEG4Source> source = new MPEG4Source( track->meta, mDataSource, track->timescale, track->sampleTable, mSidxEntries, mMoofOffset); if (source->init() != OK) { return NULL; } return source; } // static Loading Loading @@ -2548,6 +2556,7 @@ MPEG4Source::MPEG4Source( mSegments(sidx), mFirstMoofOffset(firstMoofOffset), mCurrentMoofOffset(firstMoofOffset), mNextMoofOffset(-1), mCurrentTime(0), mCurrentSampleInfoAllocSize(0), mCurrentSampleInfoSizes(NULL), Loading Loading @@ -2596,10 +2605,14 @@ MPEG4Source::MPEG4Source( CHECK(format->findInt32(kKeyTrackID, &mTrackId)); } status_t MPEG4Source::init() { if (mFirstMoofOffset != 0) { off64_t offset = mFirstMoofOffset; parseChunk(&offset); return parseChunk(&offset); } return OK; } MPEG4Source::~MPEG4Source() { Loading Loading @@ -2715,9 +2728,41 @@ status_t MPEG4Source::parseChunk(off64_t *offset) { } } if (chunk_type == FOURCC('m', 'o', 'o', 'f')) { // *offset points to the mdat box following this moof parseChunk(offset); // doesn't actually parse it, just updates offset // *offset points to the box following this moof. Find the next moof from there. while (true) { if (mDataSource->readAt(*offset, hdr, 8) < 8) { return ERROR_END_OF_STREAM; } chunk_size = ntohl(hdr[0]); chunk_type = ntohl(hdr[1]); if (chunk_size == 1) { // ISO/IEC 14496-12:2012, 8.8.4 Movie Fragment Box, moof is a Box // which is defined in 4.2 Object Structure. // When chunk_size==1, 8 bytes follows as "largesize". if (mDataSource->readAt(*offset + 8, &chunk_size, 8) < 8) { return ERROR_IO; } chunk_size = ntoh64(chunk_size); if (chunk_size < 16) { // The smallest valid chunk is 16 bytes long in this case. return ERROR_MALFORMED; } } else if (chunk_size == 0) { // next box extends to end of file. } else if (chunk_size < 8) { // The smallest valid chunk is 8 bytes long in this case. return ERROR_MALFORMED; } if (chunk_type == FOURCC('m', 'o', 'o', 'f')) { mNextMoofOffset = *offset; break; } else if (chunk_size == 0) { break; } *offset += chunk_size; } } break; } Loading Loading @@ -3572,9 +3617,13 @@ status_t MPEG4Source::fragmentedRead( totalOffset += se->mSize; } mCurrentMoofOffset = totalOffset; mNextMoofOffset = -1; mCurrentSamples.clear(); mCurrentSampleIndex = 0; parseChunk(&totalOffset); status_t err = parseChunk(&totalOffset); if (err != OK) { return err; } mCurrentTime = totalTime * mTimescale / 1000000ll; } Loading @@ -3601,7 +3650,10 @@ status_t MPEG4Source::fragmentedRead( mCurrentMoofOffset = nextMoof; mCurrentSamples.clear(); mCurrentSampleIndex = 0; parseChunk(&nextMoof); status_t err = parseChunk(&nextMoof); if (err != OK) { return err; } if (mCurrentSampleIndex >= mCurrentSamples.size()) { return ERROR_END_OF_STREAM; } Loading Loading
media/libstagefright/MPEG4Extractor.cpp +60 −8 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ public: const sp<SampleTable> &sampleTable, Vector<SidxEntry> &sidx, off64_t firstMoofOffset); virtual status_t init(); virtual status_t start(MetaData *params = NULL); virtual status_t stop(); Loading Loading @@ -1924,7 +1925,10 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) { if (mLastTrack == NULL) { return ERROR_MALFORMED; } parseSegmentIndex(data_offset, chunk_data_size); status_t err = parseSegmentIndex(data_offset, chunk_data_size); if (err != OK) { return err; } *offset += chunk_size; return UNKNOWN_ERROR; // stop parsing after sidx } Loading Loading @@ -2369,9 +2373,13 @@ sp<MediaSource> MPEG4Extractor::getTrack(size_t index) { ALOGV("getTrack called, pssh: %d", mPssh.size()); return new MPEG4Source( sp<MPEG4Source> source = new MPEG4Source( track->meta, mDataSource, track->timescale, track->sampleTable, mSidxEntries, mMoofOffset); if (source->init() != OK) { return NULL; } return source; } // static Loading Loading @@ -2548,6 +2556,7 @@ MPEG4Source::MPEG4Source( mSegments(sidx), mFirstMoofOffset(firstMoofOffset), mCurrentMoofOffset(firstMoofOffset), mNextMoofOffset(-1), mCurrentTime(0), mCurrentSampleInfoAllocSize(0), mCurrentSampleInfoSizes(NULL), Loading Loading @@ -2596,10 +2605,14 @@ MPEG4Source::MPEG4Source( CHECK(format->findInt32(kKeyTrackID, &mTrackId)); } status_t MPEG4Source::init() { if (mFirstMoofOffset != 0) { off64_t offset = mFirstMoofOffset; parseChunk(&offset); return parseChunk(&offset); } return OK; } MPEG4Source::~MPEG4Source() { Loading Loading @@ -2715,9 +2728,41 @@ status_t MPEG4Source::parseChunk(off64_t *offset) { } } if (chunk_type == FOURCC('m', 'o', 'o', 'f')) { // *offset points to the mdat box following this moof parseChunk(offset); // doesn't actually parse it, just updates offset // *offset points to the box following this moof. Find the next moof from there. while (true) { if (mDataSource->readAt(*offset, hdr, 8) < 8) { return ERROR_END_OF_STREAM; } chunk_size = ntohl(hdr[0]); chunk_type = ntohl(hdr[1]); if (chunk_size == 1) { // ISO/IEC 14496-12:2012, 8.8.4 Movie Fragment Box, moof is a Box // which is defined in 4.2 Object Structure. // When chunk_size==1, 8 bytes follows as "largesize". if (mDataSource->readAt(*offset + 8, &chunk_size, 8) < 8) { return ERROR_IO; } chunk_size = ntoh64(chunk_size); if (chunk_size < 16) { // The smallest valid chunk is 16 bytes long in this case. return ERROR_MALFORMED; } } else if (chunk_size == 0) { // next box extends to end of file. } else if (chunk_size < 8) { // The smallest valid chunk is 8 bytes long in this case. return ERROR_MALFORMED; } if (chunk_type == FOURCC('m', 'o', 'o', 'f')) { mNextMoofOffset = *offset; break; } else if (chunk_size == 0) { break; } *offset += chunk_size; } } break; } Loading Loading @@ -3572,9 +3617,13 @@ status_t MPEG4Source::fragmentedRead( totalOffset += se->mSize; } mCurrentMoofOffset = totalOffset; mNextMoofOffset = -1; mCurrentSamples.clear(); mCurrentSampleIndex = 0; parseChunk(&totalOffset); status_t err = parseChunk(&totalOffset); if (err != OK) { return err; } mCurrentTime = totalTime * mTimescale / 1000000ll; } Loading @@ -3601,7 +3650,10 @@ status_t MPEG4Source::fragmentedRead( mCurrentMoofOffset = nextMoof; mCurrentSamples.clear(); mCurrentSampleIndex = 0; parseChunk(&nextMoof); status_t err = parseChunk(&nextMoof); if (err != OK) { return err; } if (mCurrentSampleIndex >= mCurrentSamples.size()) { return ERROR_END_OF_STREAM; } Loading