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

Commit d9ac621f authored by James Dong's avatar James Dong
Browse files

Do not wait forever for output buffers in OMXCodec.cpp and error out in case time out happens

o Deal with vendor codec hang bug

Change-Id: Ic8449afd43045f09a9e0bd3d1be9a320e59ccabe
parent f604c6f6
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -329,6 +329,7 @@ private:
    void restorePatchedDataPointer(BufferInfo *info);
    void restorePatchedDataPointer(BufferInfo *info);


    status_t applyRotation();
    status_t applyRotation();
    status_t waitForBufferFilled_l();


    int64_t retrieveDecodingTimeUs(bool isCodecSpecific);
    int64_t retrieveDecodingTimeUs(bool isCodecSpecific);


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


namespace android {
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 {
struct CodecInfo {
    const char *mime;
    const char *mime;
    const char *codec;
    const char *codec;
@@ -3184,6 +3188,16 @@ void OMXCodec::setState(State newState) {
    mBufferFilled.signal();
    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(
void OMXCodec::setRawAudioFormat(
        OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels) {
        OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels) {


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


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


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


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


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


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


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