From a57a9a491272aa884494b2ec7854960827a73742 Mon Sep 17 00:00:00 2001 From: James Dong Date: Fri, 15 Jul 2011 15:25:36 -0700 Subject: [PATCH] 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 --- include/media/stagefright/OMXCodec.h | 1 + media/libstagefright/OMXCodec.cpp | 33 +++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h index a042ddbbf2..77492cae18 100644 --- a/include/media/stagefright/OMXCodec.h +++ b/include/media/stagefright/OMXCodec.h @@ -329,6 +329,7 @@ private: void restorePatchedDataPointer(BufferInfo *info); status_t applyRotation(); + status_t waitForBufferFilled_l(); int64_t retrieveDecodingTimeUs(bool isCodecSpecific); diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 5cab60e5fb..78349a6a83 100755 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -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; @@ -3184,6 +3188,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) { @@ -3616,6 +3630,7 @@ sp OMXCodec::getFormat() { status_t OMXCodec::read( MediaBuffer **buffer, const ReadOptions *options) { + status_t err = OK; *buffer = NULL; Mutex::Autolock autoLock(mLock); @@ -3656,7 +3671,9 @@ status_t OMXCodec::read( if (seeking) { while (mState == RECONFIGURING) { - mBufferFilled.wait(mLock); + if ((err = waitForBufferFilled_l()) != OK) { + return err; + } } if (mState != EXECUTING) { @@ -3687,19 +3704,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; } } -- 2.11.0