summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--media/libavextensions/stagefright/AVExtensions.h3
-rw-r--r--media/libstagefright/MPEG4Writer.cpp26
-rw-r--r--media/libstagefright/MediaCodecSource.cpp2
3 files changed, 22 insertions, 9 deletions
diff --git a/media/libavextensions/stagefright/AVExtensions.h b/media/libavextensions/stagefright/AVExtensions.h
index 9c712e4..17ea475 100644
--- a/media/libavextensions/stagefright/AVExtensions.h
+++ b/media/libavextensions/stagefright/AVExtensions.h
@@ -161,6 +161,9 @@ struct AVUtils {
virtual bool useQCHWEncoder(const sp<AMessage> &, AString &) { return false; }
+ virtual bool canDeferRelease(const sp<MetaData> &/*meta*/) { return false; }
+ virtual void setDeferRelease(sp<MetaData> &/*meta*/) {}
+
struct HEVCMuxer {
virtual bool reassembleHEVCCSD(const AString &mime, sp<ABuffer> csd0, sp<MetaData> &meta);
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 94f40b4..cb9df29 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -2284,15 +2284,23 @@ status_t MPEG4Writer::Track::threadEntry() {
continue;
}
- // Make a deep copy of the MediaBuffer and Metadata and release
- // the original as soon as we can
- MediaBuffer *copy = new MediaBuffer(buffer->range_length());
- memcpy(copy->data(), (uint8_t *)buffer->data() + buffer->range_offset(),
- buffer->range_length());
- copy->set_range(0, buffer->range_length());
- meta_data = new MetaData(*buffer->meta_data().get());
- buffer->release();
- buffer = NULL;
+ MediaBuffer *copy = NULL;
+ // Check if the upstream source hints it is OK to hold on to the
+ // buffer without releasing immediately and avoid cloning the buffer
+ if (AVUtils::get()->canDeferRelease(buffer->meta_data())) {
+ copy = buffer;
+ meta_data = new MetaData(*buffer->meta_data().get());
+ } else {
+ // Make a deep copy of the MediaBuffer and Metadata and release
+ // the original as soon as we can
+ copy = new MediaBuffer(buffer->range_length());
+ memcpy(copy->data(), (uint8_t *)buffer->data() + buffer->range_offset(),
+ buffer->range_length());
+ copy->set_range(0, buffer->range_length());
+ meta_data = new MetaData(*buffer->meta_data().get());
+ buffer->release();
+ buffer = NULL;
+ }
if (mIsAvc || mIsHEVC) StripStartcode(copy);
diff --git a/media/libstagefright/MediaCodecSource.cpp b/media/libstagefright/MediaCodecSource.cpp
index dbd9cb0..925be14 100644
--- a/media/libstagefright/MediaCodecSource.cpp
+++ b/media/libstagefright/MediaCodecSource.cpp
@@ -759,6 +759,8 @@ void MediaCodecSource::onMessageReceived(const sp<AMessage> &msg) {
MediaBuffer *mbuf = new MediaBuffer(outbuf->size());
memcpy(mbuf->data(), outbuf->data(), outbuf->size());
+ sp<MetaData> meta = mbuf->meta_data();
+ AVUtils::get()->setDeferRelease(meta);
if (!(flags & MediaCodec::BUFFER_FLAG_CODECCONFIG)) {
if (mIsVideo) {