diff options
author | Andreas Huber <andih@google.com> | 2010-04-21 15:16:28 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-04-21 15:16:28 -0700 |
commit | 21ec5bd3f88a2e7b20f75067b68ae547146853b3 (patch) | |
tree | f2a48c8652db62cfd8ca62dd5ad3ae6cec88078d | |
parent | 2fb88637de061d762ec8919c6adc3f6fd2f6f772 (diff) | |
parent | b052eae44afe8a1febceb2287d728af9e0df4828 (diff) | |
download | omap3-21ec5bd3f88a2e7b20f75067b68ae547146853b3.tar.gz |
am b052eae4: Fixes a race condition in the hardware mp3 OMX driver code.
Merge commit 'b052eae44afe8a1febceb2287d728af9e0df4828' into froyo-plus-aosp
* commit 'b052eae44afe8a1febceb2287d728af9e0df4828':
Fixes a race condition in the hardware mp3 OMX driver code.
-rw-r--r-- | omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_Utils.c | 55 | ||||
-rw-r--r-- | omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Decoder.c | 35 |
2 files changed, 46 insertions, 44 deletions
diff --git a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_Utils.c b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_Utils.c index 2909d9a..91709f6 100644 --- a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_Utils.c +++ b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_Utils.c @@ -551,6 +551,25 @@ OMX_ERRORTYPE MP3DEC_FreeCompResources(OMX_HANDLETYPE pComponent) return eError; } +static void signalAlloBufThresholdIfNecessary( + MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) { +#ifndef UNDER_CE + pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); + if (pComponentPrivate->AlloBuf_waitingsignal) { + pComponentPrivate->AlloBuf_waitingsignal = 0; + pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); + } + pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); +#else + if (pComponentPrivate->AlloBuf_waitingsignal) { + // I am fairly sure this will suffer from similar issues without + // proper mutex protection and a loop under WinCE... + pComponentPrivate->AlloBuf_waitingsignal = 0; + OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event)); + } +#endif +} + /* ================================================================================= * */ /** @@ -1469,17 +1488,8 @@ OMX_U32 MP3DEC_HandleCommand (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled = OMX_TRUE; OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled = %d\n", pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled); - - if(pComponentPrivate->AlloBuf_waitingsignal){ - pComponentPrivate->AlloBuf_waitingsignal = 0; -#ifndef UNDER_CE - pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); - pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); - pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); -#else - OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event)); -#endif - } + + signalAlloBufThresholdIfNecessary(pComponentPrivate); OMX_PRCOMM2(pComponentPrivate->dbg, "setting output port to enabled\n"); } } @@ -1493,13 +1503,8 @@ OMX_U32 MP3DEC_HandleCommand (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) MP3D_INPUT_PORT, NULL); - if(pComponentPrivate->AlloBuf_waitingsignal){ - pComponentPrivate->AlloBuf_waitingsignal = 0; - pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); - pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); - pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); - } - + signalAlloBufThresholdIfNecessary(pComponentPrivate); + //MP3DECFill_LCMLInitParamsEx(pHandle, 0); // queue the pending buffers received while doing the config for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) { @@ -1540,12 +1545,7 @@ OMX_U32 MP3DEC_HandleCommand (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) MP3D_OUTPUT_PORT, NULL); - if(pComponentPrivate->AlloBuf_waitingsignal){ - pComponentPrivate->AlloBuf_waitingsignal = 0; - pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); - pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); - pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); - } + signalAlloBufThresholdIfNecessary(pComponentPrivate); OMX_PRINT2(pComponentPrivate->dbg, "reconfigOut = %d!, but should be true!\n",pComponentPrivate->reconfigOutputPort); if(pComponentPrivate->reconfigOutputPort){ //make sure new VA's are used @@ -1625,12 +1625,7 @@ OMX_U32 MP3DEC_HandleCommand (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) MP3D_OUTPUT_PORT, NULL); - if(pComponentPrivate->AlloBuf_waitingsignal){ - pComponentPrivate->AlloBuf_waitingsignal = 0; - pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); - pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); - pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); - } + signalAlloBufThresholdIfNecessary(pComponentPrivate); MP3DEC_CleanupInitParamsEx(pHandle,commandData); MP3DECFill_LCMLInitParamsEx(pHandle, -1); diff --git a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Decoder.c b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Decoder.c index 7703961..5eb55c7 100644 --- a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Decoder.c +++ b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Decoder.c @@ -1821,7 +1821,24 @@ static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp, return eError; } - +static void waitForAlloBufThreshold( + MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) { +#ifndef UNDER_CE + pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); + pComponentPrivate->AlloBuf_waitingsignal = 1; + while (pComponentPrivate->AlloBuf_waitingsignal) { + pthread_cond_wait( + &pComponentPrivate->AlloBuf_threshold, + &pComponentPrivate->AlloBuf_mutex); + } + pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); +#else + // I am fairly sure this will suffer from similar issues without + // proper mutex protection and a loop under WinCE... + pComponentPrivate->AlloBuf_waitingsignal = 1; + OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event)); +#endif +} /* ================================================================================= * */ /** @@ -1875,14 +1892,7 @@ static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent, MP3D_OMX_CONF_CHECK_CMD(pPortDef, 1, 1); if(!pPortDef->bEnabled){ - pComponentPrivate->AlloBuf_waitingsignal = 1; -#ifndef UNDER_CE - pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); - pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex); - pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); -#else - OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event)); -#endif + waitForAlloBufThreshold(pComponentPrivate); } OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE); @@ -2273,11 +2283,8 @@ static OMX_ERRORTYPE UseBuffer ( pComponentPrivate)->pPortDef[nPortIndex]; MP3D_OMX_CONF_CHECK_CMD(pPortDef, 1, 1); - if(!pPortDef->bEnabled){ - pComponentPrivate->AlloBuf_waitingsignal = 1; - pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); - pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex); - pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); + if(!pPortDef->bEnabled) { + waitForAlloBufThreshold(pComponentPrivate); } OMX_PRCOMM2(pComponentPrivate->dbg, ":: pPortDef = %p\n",pPortDef); OMX_PRCOMM2(pComponentPrivate->dbg, ":: pPortDef->bEnabled = %d\n",pPortDef->bEnabled); |