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

Commit e432a000 authored by James Dong's avatar James Dong Committed by Android (Google) Code Review
Browse files

Merge "Do not wait forever for output buffers in OMXCodec.cpp and error out in...

Merge "Do not wait forever for output buffers in OMXCodec.cpp and error out in case time out happens"
parents d40e2c67 d9ac621f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -329,6 +329,7 @@ private:
    void restorePatchedDataPointer(BufferInfo *info);

    status_t applyRotation();
    status_t waitForBufferFilled_l();

    int64_t retrieveDecodingTimeUs(bool isCodecSpecific);

+23 −10
Original line number Diff line number Diff line
@@ -48,6 +48,10 @@

namespace android {

// Treat time out as an error if we have not received any output
// buffers after 3 seconds.
const static int64_t kBufferFilledEventTimeOutUs = 3000000000LL;

struct CodecInfo {
    const char *mime;
    const char *codec;
@@ -3191,6 +3195,16 @@ void OMXCodec::setState(State newState) {
    mBufferFilled.signal();
}

status_t OMXCodec::waitForBufferFilled_l() {
    status_t err = mBufferFilled.waitRelative(mLock, kBufferFilledEventTimeOutUs);
    if (err != OK) {
        LOGE("Timed out waiting for buffers from video encoder: %d/%d",
            countBuffersWeOwn(mPortBuffers[kPortIndexInput]),
            countBuffersWeOwn(mPortBuffers[kPortIndexOutput]));
    }
    return err;
}

void OMXCodec::setRawAudioFormat(
        OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels) {

@@ -3623,6 +3637,7 @@ sp<MetaData> OMXCodec::getFormat() {

status_t OMXCodec::read(
        MediaBuffer **buffer, const ReadOptions *options) {
    status_t err = OK;
    *buffer = NULL;

    Mutex::Autolock autoLock(mLock);
@@ -3663,7 +3678,9 @@ status_t OMXCodec::read(

    if (seeking) {
        while (mState == RECONFIGURING) {
            mBufferFilled.wait(mLock);
            if ((err = waitForBufferFilled_l()) != OK) {
                return err;
            }
        }

        if (mState != EXECUTING) {
@@ -3694,19 +3711,15 @@ status_t OMXCodec::read(
        }

        while (mSeekTimeUs >= 0) {
            mBufferFilled.wait(mLock);
            if ((err = waitForBufferFilled_l()) != OK) {
                return err;
            }
        }
    }

    while (mState != ERROR && !mNoMoreOutputData && mFilledBuffers.empty()) {
        if (mIsEncoder) {
            if (NO_ERROR != mBufferFilled.waitRelative(mLock, 3000000000LL)) {
                LOGW("Timed out waiting for buffers from video encoder: %d/%d",
                    countBuffersWeOwn(mPortBuffers[kPortIndexInput]),
                    countBuffersWeOwn(mPortBuffers[kPortIndexOutput]));
            }
        } else {
            mBufferFilled.wait(mLock);
        if ((err = waitForBufferFilled_l()) != OK) {
            return err;
        }
    }