Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c812f07 authored by Praveen Chavan's avatar Praveen Chavan Committed by Linux Build Service Account
Browse files

stagefright: Remove additional deep-copy of encoder buffers

MPEG4Writer makes a copy of encoded buffer to avoid holding on
to the read buffer. This is not needed with MediaCodecSource,
as the encoded-output buffer is already copied to a heap buffer.
This saves a copy and some power.

However, cloning the buffer is still needed for upstream sources
that cannot afford to keep the buffers with writer up until they
are released.
So, pass a hint in buffer's metadata to indicate if it is OK
to delay the release and not copy the buffer.

Change-Id: I9661dafa4d45ff87364f5dfb1b2f7d01552a83fe
parent 06b71368
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -173,6 +173,10 @@ enum {
    kKeyTrackIsDefault    = 'dflt', // bool (int32_t)
    // Similar to MediaFormat.KEY_IS_FORCED_SUBTITLE but pertains to av tracks as well.
    kKeyTrackIsForced     = 'frcd', // bool (int32_t)

    // Indicate if it is OK to hold on to the MediaBuffer and not
    // release it immediately
    kKeyCanDeferRelease   = 'drel', // bool (int32_t)
};

enum {
+19 −9
Original line number Diff line number Diff line
@@ -2160,15 +2160,25 @@ status_t MPEG4Writer::Track::threadEntry() {
            continue;
        }

        MediaBuffer *copy = NULL;
        int32_t deferRelease = false;
        // Check if the upstream source hints it is OK to hold on to the
        // buffer without releasing immediately and avoid cloning the buffer
        buffer->meta_data()->findInt32(kKeyCanDeferRelease, &deferRelease);
        if (deferRelease) {
            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
        MediaBuffer *copy = new MediaBuffer(buffer->range_length());
            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) StripStartcode(copy);

+1 −0
Original line number Diff line number Diff line
@@ -698,6 +698,7 @@ status_t MediaCodecSource::doMoreWork(int32_t numInput, int32_t numOutput) {

            MediaBuffer *mbuf = new MediaBuffer(outbuf->size());
            memcpy(mbuf->data(), outbuf->data(), outbuf->size());
            mbuf->meta_data()->setInt32(kKeyCanDeferRelease, true);

            if (!(flags & MediaCodec::BUFFER_FLAG_CODECCONFIG)) {
                if (mIsVideo) {