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

Commit c666687f authored by Chong Zhang's avatar Chong Zhang
Browse files

Tuning of buffer dequeue code to reduce stalls

Queue as many inputs as possible without blocking, then
block on output. Also change the blocking time to 10ms
but allow a little more retries.

Finally, assign a non-zero pts to the image samples to
suppress warnings from MediaCodec about 0 pts.

bug: 78475896

Change-Id: I57c4096a93bc5de0a413968224843a69df667df8
parent 67f280ee
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -628,7 +628,7 @@ status_t MPEG4Extractor::readMetaData() {
            track->meta.setInt32(kKeyTrackID, imageIndex);
            track->includes_expensive_metadata = false;
            track->skipTrack = false;
            track->timescale = 0;
            track->timescale = 1000000;
        }
    }

+19 −22
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@

namespace android {

static const int64_t kBufferTimeOutUs = 30000ll; // 30 msec
static const size_t kRetryCount = 20; // must be >0
static const int64_t kBufferTimeOutUs = 10000ll; // 10 msec
static const size_t kRetryCount = 50; // must be >0

//static
VideoFrame *allocVideoFrame(const sp<MetaData> &trackMeta,
@@ -253,10 +253,13 @@ status_t FrameDecoder::extractInternal(
        uint32_t flags = 0;
        sp<MediaCodecBuffer> codecBuffer = NULL;

        // Queue as many inputs as we possibly can, then block on dequeuing
        // outputs. After getting each output, come back and queue the inputs
        // again to keep the decoder busy.
        while (haveMoreInputs) {
            err = decoder->dequeueInputBuffer(&inputIndex, kBufferTimeOutUs);
            err = decoder->dequeueInputBuffer(&inputIndex, 0);
            if (err != OK) {
                ALOGW("Timed out waiting for input");
                ALOGV("Timed out waiting for input");
                if (retriesLeft) {
                    err = OK;
                }
@@ -295,8 +298,6 @@ status_t FrameDecoder::extractInternal(
            }

            mediaBuffer->release();
            break;
        }

            if (haveMoreInputs && inputIndex < inputBuffers.size()) {
                ALOGV("QueueInput: size=%zu ts=%" PRId64 " us flags=%x",
@@ -312,10 +313,6 @@ status_t FrameDecoder::extractInternal(
                if (flags & MediaCodec::BUFFER_FLAG_EOS) {
                    haveMoreInputs = false;
                }

            // we don't expect an output from codec config buffer
            if (flags & MediaCodec::BUFFER_FLAG_CODECCONFIG) {
                continue;
            }
        }