From a57a9a491272aa884494b2ec7854960827a73742 Mon Sep 17 00:00:00 2001 From: James Dong Date: Fri, 15 Jul 2011 15:25:36 -0700 Subject: 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 --- media/libstagefright/OMXCodec.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'media/libstagefright') diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 5cab60e..78349a6 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; } } -- cgit v1.1