Stagefright: Return error if codec takes too long to return a buffer.
There are many scenarios where the codec may not return a valid buffer.
In such a case, the OMXCodec::read() call hangs indefitely. Therefore,
wait() call is replaced with waitRelative() so that it timesout after a
few seconds and we exit gracefully.
Change-Id: Ie03c5d1e979b71f6253efcaa0665aa5e541cebe2
Signed-off-by: Anu Sundararajan <sanuradha@ti.com>
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index b5d00bf..ccda13f 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -3015,6 +3015,8 @@
status_t OMXCodec::read(
MediaBuffer **buffer, const ReadOptions *options) {
+
+ status_t wait_status = 0;
*buffer = NULL;
Mutex::Autolock autoLock(mLock);
@@ -3084,12 +3086,20 @@
}
while (mSeekTimeUs >= 0) {
- mBufferFilled.wait(mLock);
+ wait_status = mBufferFilled.waitRelative(mLock, 3000000000);
+ if (wait_status) {
+ LOGE("Timed out waiting for the buffer! Line %d", __LINE__);
+ return UNKNOWN_ERROR;
+ }
}
}
while (mState != ERROR && !mNoMoreOutputData && mFilledBuffers.empty()) {
- mBufferFilled.wait(mLock);
+ wait_status = mBufferFilled.waitRelative(mLock, 3000000000);
+ if (wait_status) {
+ LOGE("Timed out waiting for the buffer! Line %d", __LINE__);
+ return UNKNOWN_ERROR;
+ }
}
if (mState == ERROR) {