summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/matroska
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2015-10-29 14:10:48 -0700
committerSteve Kondik <steve@cyngn.com>2015-11-07 01:56:44 -0800
commitd831e2ea5e74c06bd6fb9e8b61d710f466a507cc (patch)
tree914cdb3838cff3fdb23a1a48aa0dc5373c90cbad /media/libstagefright/matroska
parent5e05fbd57a5372c17c10c34bc130511dab8451ca (diff)
downloadframeworks_av-d831e2ea5e74c06bd6fb9e8b61d710f466a507cc.zip
frameworks_av-d831e2ea5e74c06bd6fb9e8b61d710f466a507cc.tar.gz
frameworks_av-d831e2ea5e74c06bd6fb9e8b61d710f466a507cc.tar.bz2
MatroskaExtractor: don't use new buffer unless necessary
When the NAL size length is 4 bytes, we can store the start code in the space occupied by the NAL size length and avoid allocating a new buffer and copying the data into it. Also fix potential memory leak. Change-Id: I29dd72a0616dfae66ddd7b7f9478678e356df440
Diffstat (limited to 'media/libstagefright/matroska')
-rw-r--r--media/libstagefright/matroska/MatroskaExtractor.cpp23
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(