diff options
-rw-r--r-- | media/libstagefright/matroska/MatroskaExtractor.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/media/libstagefright/matroska/MatroskaExtractor.cpp b/media/libstagefright/matroska/MatroskaExtractor.cpp index ff81379..06057d0 100644 --- a/media/libstagefright/matroska/MatroskaExtractor.cpp +++ b/media/libstagefright/matroska/MatroskaExtractor.cpp @@ -548,6 +548,7 @@ status_t MatroskaSource::readBlock() { mPendingFrames.clear(); mBlockIter.advance(); + mbuf->release(); return ERROR_IO; } @@ -668,9 +669,11 @@ status_t MatroskaSource::read( if (pass == 1) { memcpy(&dstPtr[dstOffset], "\x00\x00\x00\x01", 4); - memcpy(&dstPtr[dstOffset + 4], - &srcPtr[srcOffset + mNALSizeLen], - NALsize); + if (frame != buffer) { + memcpy(&dstPtr[dstOffset + 4], + &srcPtr[srcOffset + mNALSizeLen], + NALsize); + } } dstOffset += 4; // 0x00 00 00 01 @@ -692,7 +695,13 @@ status_t MatroskaSource::read( if (pass == 0) { dstSize = dstOffset; - buffer = new MediaBuffer(dstSize); + if (dstSize == srcSize && mNALSizeLen == 4) { + // In this special case we can re-use the input buffer by substituting + // each 4-byte nal size with a 4-byte start code + buffer = frame; + } else { + buffer = new MediaBuffer(dstSize); + } int64_t timeUs; CHECK(frame->meta_data()->findInt64(kKeyTime, &timeUs)); @@ -706,8 +715,10 @@ status_t MatroskaSource::read( } } - frame->release(); - frame = NULL; + if (frame != buffer) { + frame->release(); + frame = NULL; + } if (targetSampleTimeUs >= 0ll) { buffer->meta_data()->setInt64( |