Home | History | Annotate | Download | only in dec
      1 /*
      2  *
      3  * Copyright 2010 Samsung Electronics S.LSI Co. LTD
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 /*
     19  * @file        SEC_OMX_Vdec.c
     20  * @brief
     21  * @author      SeungBeom Kim (sbcrux.kim (at) samsung.com)
     22  *              HyeYeon Chung (hyeon.chung (at) samsung.com)
     23  *              Yunji Kim (yunji.kim (at) samsung.com)
     24  * @version     1.0
     25  * @history
     26  *   2010.7.15 : Create
     27  */
     28 
     29 #include <stdio.h>
     30 #include <stdlib.h>
     31 #include <string.h>
     32 #include "SEC_OMX_Macros.h"
     33 #include "SEC_OSAL_Event.h"
     34 #include "SEC_OMX_Vdec.h"
     35 #include "SEC_OMX_Basecomponent.h"
     36 #include "SEC_OSAL_Thread.h"
     37 
     38 #undef  SEC_LOG_TAG
     39 #define SEC_LOG_TAG    "SEC_VIDEO_DEC"
     40 #define SEC_LOG_OFF
     41 #include "SEC_OSAL_Log.h"
     42 
     43 #define ONE_FRAME_OUTPUT  /* only one frame output for Android */
     44 #define S5PC110_DECODE_OUT_DATA_BUFFER /* for Android s5pc110 0copy*/
     45 
     46 
     47 inline void SEC_UpdateFrameSize(OMX_COMPONENTTYPE *pOMXComponent)
     48 {
     49     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
     50     SEC_OMX_BASEPORT      *secInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX];
     51     SEC_OMX_BASEPORT      *secOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX];
     52 
     53     if ((secOutputPort->portDefinition.format.video.nFrameWidth !=
     54             secInputPort->portDefinition.format.video.nFrameWidth) ||
     55         (secOutputPort->portDefinition.format.video.nFrameHeight !=
     56             secInputPort->portDefinition.format.video.nFrameHeight)) {
     57         OMX_U32 width = 0, height = 0;
     58 
     59         secOutputPort->portDefinition.format.video.nFrameWidth =
     60             secInputPort->portDefinition.format.video.nFrameWidth;
     61         secOutputPort->portDefinition.format.video.nFrameHeight =
     62             secInputPort->portDefinition.format.video.nFrameHeight;
     63         width = secOutputPort->portDefinition.format.video.nStride =
     64             secInputPort->portDefinition.format.video.nStride;
     65         height = secOutputPort->portDefinition.format.video.nSliceHeight =
     66             secInputPort->portDefinition.format.video.nSliceHeight;
     67 
     68         switch(secOutputPort->portDefinition.format.video.eColorFormat) {
     69         case OMX_COLOR_FormatYUV420Planar:
     70         case OMX_COLOR_FormatYUV420SemiPlanar:
     71             if (width && height)
     72                 secOutputPort->portDefinition.nBufferSize = (width * height * 3) / 2;
     73             break;
     74         default:
     75             if (width && height)
     76                 secOutputPort->portDefinition.nBufferSize = width * height * 2;
     77             break;
     78         }
     79     }
     80 
     81   return ;
     82 }
     83 
     84 OMX_ERRORTYPE SEC_OMX_UseBuffer(
     85     OMX_IN OMX_HANDLETYPE            hComponent,
     86     OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr,
     87     OMX_IN OMX_U32                   nPortIndex,
     88     OMX_IN OMX_PTR                   pAppPrivate,
     89     OMX_IN OMX_U32                   nSizeBytes,
     90     OMX_IN OMX_U8                   *pBuffer)
     91 {
     92     OMX_ERRORTYPE          ret = OMX_ErrorNone;
     93     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
     94     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
     95     SEC_OMX_BASEPORT      *pSECPort = NULL;
     96     OMX_BUFFERHEADERTYPE  *temp_bufferHeader = NULL;
     97     int                    i = 0;
     98 
     99     FunctionIn();
    100 
    101     if (hComponent == NULL) {
    102         ret = OMX_ErrorBadParameter;
    103         goto EXIT;
    104     }
    105     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    106     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    107     if (ret != OMX_ErrorNone) {
    108         goto EXIT;
    109     }
    110 
    111     if (pOMXComponent->pComponentPrivate == NULL) {
    112         ret = OMX_ErrorBadParameter;
    113         goto EXIT;
    114     }
    115     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    116 
    117     pSECPort = &pSECComponent->pSECPort[nPortIndex];
    118     if (nPortIndex >= pSECComponent->portParam.nPorts) {
    119         ret = OMX_ErrorBadPortIndex;
    120         goto EXIT;
    121     }
    122     if (pSECPort->portState != OMX_StateIdle) {
    123         ret = OMX_ErrorIncorrectStateOperation;
    124         goto EXIT;
    125     }
    126 
    127     if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
    128         ret = OMX_ErrorBadPortIndex;
    129         goto EXIT;
    130     }
    131 
    132     temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
    133     if (temp_bufferHeader == NULL) {
    134         ret = OMX_ErrorInsufficientResources;
    135         goto EXIT;
    136     }
    137     SEC_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
    138 
    139     for (i = 0; i < pSECPort->portDefinition.nBufferCountActual; i++) {
    140         if (pSECPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
    141             pSECPort->bufferHeader[i] = temp_bufferHeader;
    142             pSECPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
    143             INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
    144             temp_bufferHeader->pBuffer        = pBuffer;
    145             temp_bufferHeader->nAllocLen      = nSizeBytes;
    146             temp_bufferHeader->pAppPrivate    = pAppPrivate;
    147             if ( nPortIndex == INPUT_PORT_INDEX)
    148                 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
    149             else
    150                 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
    151 
    152             pSECPort->assignedBufferNum++;
    153             if (pSECPort->assignedBufferNum == pSECPort->portDefinition.nBufferCountActual) {
    154                 pSECPort->portDefinition.bPopulated = OMX_TRUE;
    155                 /* SEC_OSAL_MutexLock(pSECComponent->compMutex); */
    156                 SEC_OSAL_SemaphorePost(pSECPort->loadedResource);
    157                 /* SEC_OSAL_MutexUnlock(pSECComponent->compMutex); */
    158             }
    159             *ppBufferHdr = temp_bufferHeader;
    160             ret = OMX_ErrorNone;
    161             goto EXIT;
    162         }
    163     }
    164     ret = OMX_ErrorInsufficientResources;
    165 
    166 EXIT:
    167     FunctionOut();
    168 
    169     return ret;
    170 }
    171 
    172 OMX_ERRORTYPE SEC_OMX_AllocateBuffer(
    173     OMX_IN OMX_HANDLETYPE            hComponent,
    174     OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer,
    175     OMX_IN OMX_U32                   nPortIndex,
    176     OMX_IN OMX_PTR                   pAppPrivate,
    177     OMX_IN OMX_U32                   nSizeBytes)
    178 {
    179     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    180     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    181     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    182     SEC_OMX_BASEPORT      *pSECPort = NULL;
    183     OMX_BUFFERHEADERTYPE  *temp_bufferHeader = NULL;
    184     OMX_U8                *temp_buffer = NULL;
    185     int                    i = 0;
    186 
    187     FunctionIn();
    188 
    189     if (hComponent == NULL) {
    190         ret = OMX_ErrorBadParameter;
    191         goto EXIT;
    192     }
    193     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    194     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    195     if (ret != OMX_ErrorNone) {
    196         goto EXIT;
    197     }
    198 
    199     if (pOMXComponent->pComponentPrivate == NULL) {
    200         ret = OMX_ErrorBadParameter;
    201         goto EXIT;
    202     }
    203     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    204 
    205     pSECPort = &pSECComponent->pSECPort[nPortIndex];
    206     if (nPortIndex >= pSECComponent->portParam.nPorts) {
    207         ret = OMX_ErrorBadPortIndex;
    208         goto EXIT;
    209     }
    210 /*
    211     if (pSECPort->portState != OMX_StateIdle ) {
    212         ret = OMX_ErrorIncorrectStateOperation;
    213         goto EXIT;
    214     }
    215 */
    216     if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
    217         ret = OMX_ErrorBadPortIndex;
    218         goto EXIT;
    219     }
    220 
    221     temp_buffer = SEC_OSAL_Malloc(sizeof(OMX_U8) * nSizeBytes);
    222     if (temp_buffer == NULL) {
    223         ret = OMX_ErrorInsufficientResources;
    224         goto EXIT;
    225     }
    226 
    227     temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE));
    228     if (temp_bufferHeader == NULL) {
    229         SEC_OSAL_Free(temp_buffer);
    230         temp_buffer = NULL;
    231         ret = OMX_ErrorInsufficientResources;
    232         goto EXIT;
    233     }
    234     SEC_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
    235 
    236     for (i = 0; i < pSECPort->portDefinition.nBufferCountActual; i++) {
    237         if (pSECPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) {
    238             pSECPort->bufferHeader[i] = temp_bufferHeader;
    239             pSECPort->bufferStateAllocate[i] = (BUFFER_STATE_ALLOCATED | HEADER_STATE_ALLOCATED);
    240             INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
    241             temp_bufferHeader->pBuffer        = temp_buffer;
    242             temp_bufferHeader->nAllocLen      = nSizeBytes;
    243             temp_bufferHeader->pAppPrivate    = pAppPrivate;
    244             if ( nPortIndex == INPUT_PORT_INDEX)
    245                 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX;
    246             else
    247                 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX;
    248             pSECPort->assignedBufferNum++;
    249             if (pSECPort->assignedBufferNum == pSECPort->portDefinition.nBufferCountActual) {
    250                 pSECPort->portDefinition.bPopulated = OMX_TRUE;
    251                 /* SEC_OSAL_MutexLock(pSECComponent->compMutex); */
    252                 SEC_OSAL_SemaphorePost(pSECPort->loadedResource);
    253                 /* SEC_OSAL_MutexUnlock(pSECComponent->compMutex); */
    254             }
    255             *ppBuffer = temp_bufferHeader;
    256             ret = OMX_ErrorNone;
    257             goto EXIT;
    258         }
    259     }
    260     ret = OMX_ErrorInsufficientResources;
    261 
    262 EXIT:
    263     FunctionOut();
    264 
    265     return ret;
    266 }
    267 
    268 OMX_ERRORTYPE SEC_OMX_FreeBuffer(
    269     OMX_IN OMX_HANDLETYPE hComponent,
    270     OMX_IN OMX_U32        nPortIndex,
    271     OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
    272 {
    273     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    274     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    275     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    276     SEC_OMX_BASEPORT      *pSECPort = NULL;
    277     OMX_BUFFERHEADERTYPE  *temp_bufferHeader = NULL;
    278     OMX_U8                *temp_buffer = NULL;
    279     int                    i = 0;
    280 
    281     FunctionIn();
    282 
    283     if (hComponent == NULL) {
    284         ret = OMX_ErrorBadParameter;
    285         goto EXIT;
    286     }
    287     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    288     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    289     if (ret != OMX_ErrorNone) {
    290         goto EXIT;
    291     }
    292 
    293     if (pOMXComponent->pComponentPrivate == NULL) {
    294         ret = OMX_ErrorBadParameter;
    295         goto EXIT;
    296     }
    297     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    298     pSECPort = &pSECComponent->pSECPort[nPortIndex];
    299 
    300     if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
    301         ret = OMX_ErrorBadPortIndex;
    302         goto EXIT;
    303     }
    304 
    305     if ((pSECPort->portState != OMX_StateLoaded) && (pSECPort->portState != OMX_StateInvalid)) {
    306         (*(pSECComponent->pCallbacks->EventHandler)) (pOMXComponent,
    307                         pSECComponent->callbackData,
    308                         (OMX_U32)OMX_EventError,
    309                         (OMX_U32)OMX_ErrorPortUnpopulated,
    310                         nPortIndex, NULL);
    311     }
    312 
    313     for (i = 0; i < pSECPort->portDefinition.nBufferCountActual; i++) {
    314         if (((pSECPort->bufferStateAllocate[i] | BUFFER_STATE_FREE) != 0) && (pSECPort->bufferHeader[i] != NULL)) {
    315             if (pSECPort->bufferHeader[i]->pBuffer == pBufferHdr->pBuffer) {
    316                 if (pSECPort->bufferStateAllocate[i] & BUFFER_STATE_ALLOCATED) {
    317                     SEC_OSAL_Free(pSECPort->bufferHeader[i]->pBuffer);
    318                     pSECPort->bufferHeader[i]->pBuffer = NULL;
    319                     pBufferHdr->pBuffer = NULL;
    320                 } else if (pSECPort->bufferStateAllocate[i] & BUFFER_STATE_ASSIGNED) {
    321                     ; /* None*/
    322                 }
    323                 pSECPort->assignedBufferNum--;
    324                 if (pSECPort->bufferStateAllocate[i] & HEADER_STATE_ALLOCATED) {
    325                     SEC_OSAL_Free(pSECPort->bufferHeader[i]);
    326                     pSECPort->bufferHeader[i] = NULL;
    327                     pBufferHdr = NULL;
    328                 }
    329                 pSECPort->bufferStateAllocate[i] = BUFFER_STATE_FREE;
    330                 ret = OMX_ErrorNone;
    331                 goto EXIT;
    332             }
    333         }
    334     }
    335 
    336 EXIT:
    337     if (ret == OMX_ErrorNone) {
    338         if ( pSECPort->assignedBufferNum == 0 ) {
    339             SEC_OSAL_Log(SEC_LOG_TRACE, "pSECPort->unloadedResource signal set");
    340             /* SEC_OSAL_MutexLock(pSECComponent->compMutex); */
    341             SEC_OSAL_SemaphorePost(pSECPort->unloadedResource);
    342             /* SEC_OSAL_MutexUnlock(pSECComponent->compMutex); */
    343             pSECPort->portDefinition.bPopulated = OMX_FALSE;
    344         }
    345     }
    346 
    347     FunctionOut();
    348 
    349     return ret;
    350 }
    351 
    352 OMX_ERRORTYPE SEC_OMX_AllocateTunnelBuffer(SEC_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
    353 {
    354     OMX_ERRORTYPE                 ret = OMX_ErrorNone;
    355     SEC_OMX_BASEPORT             *pSECPort = NULL;
    356     OMX_BUFFERHEADERTYPE         *temp_bufferHeader = NULL;
    357     OMX_U8                       *temp_buffer = NULL;
    358     OMX_U32                       bufferSize = 0;
    359     OMX_PARAM_PORTDEFINITIONTYPE  portDefinition;
    360 
    361     ret = OMX_ErrorTunnelingUnsupported;
    362 EXIT:
    363     return ret;
    364 }
    365 
    366 OMX_ERRORTYPE SEC_OMX_FreeTunnelBuffer(SEC_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex)
    367 {
    368     OMX_ERRORTYPE ret = OMX_ErrorNone;
    369     SEC_OMX_BASEPORT* pSECPort = NULL;
    370     OMX_BUFFERHEADERTYPE* temp_bufferHeader = NULL;
    371     OMX_U8 *temp_buffer = NULL;
    372     OMX_U32 bufferSize = 0;
    373 
    374     ret = OMX_ErrorTunnelingUnsupported;
    375 EXIT:
    376     return ret;
    377 }
    378 
    379 OMX_ERRORTYPE SEC_OMX_ComponentTunnelRequest(
    380     OMX_IN OMX_HANDLETYPE hComp,
    381     OMX_IN OMX_U32        nPort,
    382     OMX_IN OMX_HANDLETYPE hTunneledComp,
    383     OMX_IN OMX_U32        nTunneledPort,
    384     OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup)
    385 {
    386     OMX_ERRORTYPE ret = OMX_ErrorNone;
    387 
    388     ret = OMX_ErrorTunnelingUnsupported;
    389 EXIT:
    390     return ret;
    391 }
    392 
    393 OMX_BOOL SEC_Check_BufferProcess_State(SEC_OMX_BASECOMPONENT *pSECComponent)
    394 {
    395     if ((pSECComponent->currentState == OMX_StateExecuting) &&
    396         (pSECComponent->pSECPort[INPUT_PORT_INDEX].portState == OMX_StateIdle) &&
    397         (pSECComponent->pSECPort[OUTPUT_PORT_INDEX].portState == OMX_StateIdle) &&
    398         (pSECComponent->transientState != SEC_OMX_TransStateExecutingToIdle) &&
    399         (pSECComponent->transientState != SEC_OMX_TransStateIdleToExecuting)) {
    400         return OMX_TRUE;
    401     } else {
    402         return OMX_FALSE;
    403     }
    404 }
    405 
    406 static OMX_ERRORTYPE SEC_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
    407 {
    408     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    409     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    410     SEC_OMX_BASEPORT      *secOMXInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX];
    411     SEC_OMX_BASEPORT      *secOMXOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX];
    412     SEC_OMX_DATABUFFER    *dataBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX];
    413     OMX_BUFFERHEADERTYPE  *bufferHeader = dataBuffer->bufferHeader;
    414 
    415     FunctionIn();
    416 
    417     if (bufferHeader != NULL) {
    418         if (secOMXInputPort->markType.hMarkTargetComponent != NULL ) {
    419             bufferHeader->hMarkTargetComponent      = secOMXInputPort->markType.hMarkTargetComponent;
    420             bufferHeader->pMarkData                 = secOMXInputPort->markType.pMarkData;
    421             secOMXInputPort->markType.hMarkTargetComponent = NULL;
    422             secOMXInputPort->markType.pMarkData = NULL;
    423         }
    424 
    425         if (bufferHeader->hMarkTargetComponent != NULL) {
    426             if (bufferHeader->hMarkTargetComponent == pOMXComponent) {
    427                 pSECComponent->pCallbacks->EventHandler(pOMXComponent,
    428                                 pSECComponent->callbackData,
    429                                 OMX_EventMark,
    430                                 0, 0, bufferHeader->pMarkData);
    431             } else {
    432                 pSECComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent;
    433                 pSECComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData;
    434             }
    435         }
    436 
    437         if (CHECK_PORT_TUNNELED(secOMXInputPort)) {
    438             OMX_FillThisBuffer(secOMXInputPort->tunneledComponent, bufferHeader);
    439         } else {
    440             bufferHeader->nFilledLen = 0;
    441             pSECComponent->pCallbacks->EmptyBufferDone(pOMXComponent, pSECComponent->callbackData, bufferHeader);
    442         }
    443     }
    444 
    445     if ((pSECComponent->currentState == OMX_StatePause) &&
    446         ((!CHECK_PORT_BEING_FLUSHED(secOMXInputPort) && !CHECK_PORT_BEING_FLUSHED(secOMXOutputPort)))) {
    447         SEC_OSAL_SignalReset(pSECComponent->pauseEvent);
    448         SEC_OSAL_SignalWait(pSECComponent->pauseEvent, DEF_MAX_WAIT_TIME);
    449     }
    450 
    451     dataBuffer->dataValid     = OMX_FALSE;
    452     dataBuffer->dataLen       = 0;
    453     dataBuffer->remainDataLen = 0;
    454     dataBuffer->usedDataLen   = 0;
    455     dataBuffer->bufferHeader  = NULL;
    456     dataBuffer->nFlags        = 0;
    457     dataBuffer->timeStamp     = 0;
    458 
    459 EXIT:
    460     FunctionOut();
    461 
    462     return ret;
    463 }
    464 
    465 OMX_ERRORTYPE SEC_InputBufferGetQueue(SEC_OMX_BASECOMPONENT *pSECComponent)
    466 {
    467     OMX_ERRORTYPE       ret = OMX_ErrorNone;
    468     SEC_OMX_BASEPORT   *pSECPort = NULL;
    469     SEC_OMX_DATABUFFER *dataBuffer = NULL;
    470     SEC_OMX_MESSAGE*    message = NULL;
    471     SEC_OMX_DATABUFFER *inputUseBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX];
    472 
    473     FunctionIn();
    474 
    475     pSECPort= &pSECComponent->pSECPort[INPUT_PORT_INDEX];
    476     dataBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX];
    477 
    478     if (pSECComponent->currentState != OMX_StateExecuting) {
    479         ret = OMX_ErrorUndefined;
    480         goto EXIT;
    481     } else {
    482         SEC_OSAL_SemaphoreWait(pSECPort->bufferSemID);
    483         SEC_OSAL_MutexLock(inputUseBuffer->bufferMutex);
    484         if (dataBuffer->dataValid != OMX_TRUE) {
    485             message = (SEC_OMX_MESSAGE *)SEC_OSAL_Dequeue(&pSECPort->bufferQ);
    486             if (message == NULL) {
    487                 ret = OMX_ErrorUndefined;
    488                 SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex);
    489                 goto EXIT;
    490             }
    491 
    492             dataBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
    493             dataBuffer->allocSize = dataBuffer->bufferHeader->nAllocLen;
    494             dataBuffer->dataLen = dataBuffer->bufferHeader->nFilledLen;
    495             dataBuffer->remainDataLen = dataBuffer->dataLen;
    496             dataBuffer->usedDataLen = 0;
    497             dataBuffer->dataValid = OMX_TRUE;
    498             dataBuffer->nFlags = dataBuffer->bufferHeader->nFlags;
    499             dataBuffer->timeStamp = dataBuffer->bufferHeader->nTimeStamp;
    500 
    501             SEC_OSAL_Free(message);
    502 
    503             if (dataBuffer->allocSize <= dataBuffer->dataLen)
    504                 SEC_OSAL_Log(SEC_LOG_WARNING, "Input Buffer Full, Check input buffer size! allocSize:%d, dataLen:%d", dataBuffer->allocSize, dataBuffer->dataLen);
    505         }
    506         SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex);
    507         ret = OMX_ErrorNone;
    508     }
    509 EXIT:
    510     FunctionOut();
    511 
    512     return ret;
    513 }
    514 
    515 static OMX_ERRORTYPE SEC_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent)
    516 {
    517     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    518     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    519     SEC_OMX_BASEPORT      *secOMXInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX];
    520     SEC_OMX_BASEPORT      *secOMXOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX];
    521     SEC_OMX_DATABUFFER    *dataBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX];
    522     OMX_BUFFERHEADERTYPE  *bufferHeader = dataBuffer->bufferHeader;
    523 
    524     FunctionIn();
    525 
    526     if (bufferHeader != NULL) {
    527         bufferHeader->nFilledLen = dataBuffer->remainDataLen;
    528         bufferHeader->nOffset    = 0;
    529         bufferHeader->nFlags     = dataBuffer->nFlags;
    530         bufferHeader->nTimeStamp = dataBuffer->timeStamp;
    531 
    532         if (pSECComponent->propagateMarkType.hMarkTargetComponent != NULL) {
    533             bufferHeader->hMarkTargetComponent = pSECComponent->propagateMarkType.hMarkTargetComponent;
    534             bufferHeader->pMarkData = pSECComponent->propagateMarkType.pMarkData;
    535             pSECComponent->propagateMarkType.hMarkTargetComponent = NULL;
    536             pSECComponent->propagateMarkType.pMarkData = NULL;
    537         }
    538 
    539         if (bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) {
    540             pSECComponent->pCallbacks->EventHandler(pOMXComponent,
    541                             pSECComponent->callbackData,
    542                             OMX_EventBufferFlag,
    543                             OUTPUT_PORT_INDEX,
    544                             bufferHeader->nFlags, NULL);
    545         }
    546 
    547         if (CHECK_PORT_TUNNELED(secOMXOutputPort)) {
    548             OMX_EmptyThisBuffer(secOMXOutputPort->tunneledComponent, bufferHeader);
    549         } else {
    550             pSECComponent->pCallbacks->FillBufferDone(pOMXComponent, pSECComponent->callbackData, bufferHeader);
    551         }
    552     }
    553 
    554     if ((pSECComponent->currentState == OMX_StatePause) &&
    555         ((!CHECK_PORT_BEING_FLUSHED(secOMXInputPort) && !CHECK_PORT_BEING_FLUSHED(secOMXOutputPort)))) {
    556         SEC_OSAL_SignalReset(pSECComponent->pauseEvent);
    557         SEC_OSAL_SignalWait(pSECComponent->pauseEvent, DEF_MAX_WAIT_TIME);
    558     }
    559 
    560     /* reset dataBuffer */
    561     dataBuffer->dataValid     = OMX_FALSE;
    562     dataBuffer->dataLen       = 0;
    563     dataBuffer->remainDataLen = 0;
    564     dataBuffer->usedDataLen   = 0;
    565     dataBuffer->bufferHeader  = NULL;
    566     dataBuffer->nFlags        = 0;
    567     dataBuffer->timeStamp     = 0;
    568 
    569 EXIT:
    570     FunctionOut();
    571 
    572     return ret;
    573 }
    574 
    575 OMX_ERRORTYPE SEC_OutputBufferGetQueue(SEC_OMX_BASECOMPONENT *pSECComponent)
    576 {
    577     OMX_ERRORTYPE       ret = OMX_ErrorNone;
    578     SEC_OMX_BASEPORT   *pSECPort = NULL;
    579     SEC_OMX_DATABUFFER *dataBuffer = NULL;
    580     SEC_OMX_MESSAGE    *message = NULL;
    581     SEC_OMX_DATABUFFER *outputUseBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX];
    582 
    583     FunctionIn();
    584 
    585     pSECPort= &pSECComponent->pSECPort[OUTPUT_PORT_INDEX];
    586     dataBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX];
    587 
    588     if (pSECComponent->currentState != OMX_StateExecuting) {
    589         ret = OMX_ErrorUndefined;
    590         goto EXIT;
    591     } else {
    592         SEC_OSAL_SemaphoreWait(pSECPort->bufferSemID);
    593         SEC_OSAL_MutexLock(outputUseBuffer->bufferMutex);
    594         if (dataBuffer->dataValid != OMX_TRUE) {
    595             message = (SEC_OMX_MESSAGE *)SEC_OSAL_Dequeue(&pSECPort->bufferQ);
    596             if (message == NULL) {
    597                 ret = OMX_ErrorUndefined;
    598                 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex);
    599                 goto EXIT;
    600             }
    601 
    602             dataBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData);
    603             dataBuffer->allocSize = dataBuffer->bufferHeader->nAllocLen;
    604             dataBuffer->dataLen = 0; //dataBuffer->bufferHeader->nFilledLen;
    605             dataBuffer->remainDataLen = dataBuffer->dataLen;
    606             dataBuffer->usedDataLen = 0; //dataBuffer->bufferHeader->nOffset;
    607             dataBuffer->dataValid =OMX_TRUE;
    608             /* dataBuffer->nFlags = dataBuffer->bufferHeader->nFlags; */
    609             /* dataBuffer->nTimeStamp = dataBuffer->bufferHeader->nTimeStamp; */
    610 #ifdef S5PC110_DECODE_OUT_DATA_BUFFER
    611             pSECComponent->processData[OUTPUT_PORT_INDEX].dataBuffer = dataBuffer->bufferHeader->pBuffer;
    612             pSECComponent->processData[OUTPUT_PORT_INDEX].allocSize = dataBuffer->bufferHeader->nAllocLen;
    613 #endif
    614             SEC_OSAL_Free(message);
    615         }
    616         SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex);
    617         ret = OMX_ErrorNone;
    618     }
    619 EXIT:
    620     FunctionOut();
    621 
    622     return ret;
    623 
    624 }
    625 
    626 static OMX_ERRORTYPE SEC_BufferReset(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 portIndex)
    627 {
    628     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    629     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    630     /* SEC_OMX_BASEPORT      *pSECPort = &pSECComponent->pSECPort[portIndex]; */
    631     SEC_OMX_DATABUFFER    *dataBuffer = &pSECComponent->secDataBuffer[portIndex];
    632     /* OMX_BUFFERHEADERTYPE  *bufferHeader = dataBuffer->bufferHeader; */
    633 
    634     dataBuffer->dataValid     = OMX_FALSE;
    635     dataBuffer->dataLen       = 0;
    636     dataBuffer->remainDataLen = 0;
    637     dataBuffer->usedDataLen   = 0;
    638     dataBuffer->bufferHeader  = NULL;
    639     dataBuffer->nFlags        = 0;
    640     dataBuffer->timeStamp     = 0;
    641 
    642     return ret;
    643 }
    644 
    645 static OMX_ERRORTYPE SEC_DataReset(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 portIndex)
    646 {
    647     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    648     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    649     /* SEC_OMX_BASEPORT      *pSECPort = &pSECComponent->pSECPort[portIndex]; */
    650     /* SEC_OMX_DATABUFFER    *dataBuffer = &pSECComponent->secDataBuffer[portIndex]; */
    651     /* OMX_BUFFERHEADERTYPE  *bufferHeader = dataBuffer->bufferHeader; */
    652     SEC_OMX_DATA          *processData = &pSECComponent->processData[portIndex];
    653 
    654     processData->dataLen       = 0;
    655     processData->remainDataLen = 0;
    656     processData->usedDataLen   = 0;
    657     processData->nFlags        = 0;
    658     processData->timeStamp     = 0;
    659 
    660     return ret;
    661 }
    662 
    663 OMX_BOOL SEC_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent)
    664 {
    665     OMX_BOOL               ret = OMX_FALSE;
    666     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    667     SEC_OMX_DATABUFFER    *inputUseBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX];
    668     SEC_OMX_DATA          *inputData = &pSECComponent->processData[INPUT_PORT_INDEX];
    669     OMX_U32                copySize = 0;
    670     OMX_BYTE               checkInputStream = NULL;
    671     OMX_U32                checkInputStreamLen = 0;
    672     OMX_U32                checkedSize = 0;
    673     OMX_BOOL               flagEOF = OMX_FALSE;
    674     OMX_BOOL               previousFrameEOF = OMX_FALSE;
    675 
    676     FunctionIn();
    677 
    678     if (inputUseBuffer->dataValid == OMX_TRUE) {
    679         checkInputStream = inputUseBuffer->bufferHeader->pBuffer + inputUseBuffer->usedDataLen;
    680         checkInputStreamLen = inputUseBuffer->remainDataLen;
    681 
    682         if (inputData->dataLen == 0) {
    683             previousFrameEOF = OMX_TRUE;
    684         } else {
    685             previousFrameEOF = OMX_FALSE;
    686         }
    687         if ((pSECComponent->bUseFlagEOF == OMX_TRUE) &&
    688            !(inputUseBuffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) {
    689             flagEOF = OMX_TRUE;
    690             checkedSize = checkInputStreamLen;
    691         } else {
    692             pSECComponent->bUseFlagEOF = OMX_FALSE;
    693             checkedSize = pSECComponent->sec_checkInputFrame(checkInputStream, checkInputStreamLen, inputUseBuffer->nFlags, previousFrameEOF, &flagEOF);
    694         }
    695 
    696         if (flagEOF == OMX_TRUE) {
    697             copySize = checkedSize;
    698             SEC_OSAL_Log(SEC_LOG_TRACE, "sec_checkInputFrame : OMX_TRUE");
    699         } else {
    700             copySize = checkInputStreamLen;
    701             SEC_OSAL_Log(SEC_LOG_TRACE, "sec_checkInputFrame : OMX_FALSE");
    702         }
    703 
    704         if (inputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS)
    705             pSECComponent->bSaveFlagEOS = OMX_TRUE;
    706 
    707         if (((inputData->allocSize) - (inputData->dataLen)) >= copySize) {
    708             if (copySize > 0)
    709                 SEC_OSAL_Memcpy(inputData->dataBuffer + inputData->dataLen, checkInputStream, copySize);
    710 
    711             inputUseBuffer->dataLen -= copySize;
    712             inputUseBuffer->remainDataLen -= copySize;
    713             inputUseBuffer->usedDataLen += copySize;
    714 
    715             inputData->dataLen += copySize;
    716             inputData->remainDataLen += copySize;
    717 
    718             if (previousFrameEOF == OMX_TRUE) {
    719                 inputData->timeStamp = inputUseBuffer->timeStamp;
    720                 inputData->nFlags = inputUseBuffer->nFlags;
    721             }
    722 
    723             if (pSECComponent->bUseFlagEOF == OMX_TRUE) {
    724                 if (pSECComponent->bSaveFlagEOS == OMX_TRUE) {
    725                     inputData->nFlags |= OMX_BUFFERFLAG_EOS;
    726                     flagEOF = OMX_TRUE;
    727                     pSECComponent->bSaveFlagEOS = OMX_FALSE;
    728                 } else {
    729                     inputData->nFlags = (inputData->nFlags & (~OMX_BUFFERFLAG_EOS));
    730                 }
    731             } else {
    732                 if ((checkedSize == checkInputStreamLen) && (pSECComponent->bSaveFlagEOS == OMX_TRUE)) {
    733                     if ((inputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) &&
    734                         ((inputData->nFlags & OMX_BUFFERFLAG_CODECCONFIG) ||
    735                         (inputData->dataLen == 0))) {
    736                     inputData->nFlags |= OMX_BUFFERFLAG_EOS;
    737                     flagEOF = OMX_TRUE;
    738                     pSECComponent->bSaveFlagEOS = OMX_FALSE;
    739                     } else if ((inputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) &&
    740                                (!(inputData->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) &&
    741                                (inputData->dataLen != 0)) {
    742                         inputData->nFlags = (inputData->nFlags & (~OMX_BUFFERFLAG_EOS));
    743                         flagEOF = OMX_TRUE;
    744                         pSECComponent->bSaveFlagEOS = OMX_TRUE;
    745                     }
    746                 } else {
    747                     inputData->nFlags = (inputUseBuffer->nFlags & (~OMX_BUFFERFLAG_EOS));
    748                 }
    749             }
    750 
    751             if(((inputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) &&
    752                (inputData->dataLen <= 0) && (flagEOF == OMX_TRUE)) {
    753                 inputData->dataLen = inputData->previousDataLen;
    754                 inputData->remainDataLen = inputData->previousDataLen;
    755             }
    756         } else {
    757             /*????????????????????????????????? Error ?????????????????????????????????*/
    758             SEC_DataReset(pOMXComponent, INPUT_PORT_INDEX);
    759             flagEOF = OMX_FALSE;
    760         }
    761 
    762         if (inputUseBuffer->remainDataLen == 0)
    763             SEC_InputBufferReturn(pOMXComponent);
    764         else
    765             inputUseBuffer->dataValid = OMX_TRUE;
    766     }
    767 
    768     if (flagEOF == OMX_TRUE) {
    769         if (pSECComponent->checkTimeStamp.needSetStartTimeStamp == OMX_TRUE) {
    770             pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_TRUE;
    771             pSECComponent->checkTimeStamp.startTimeStamp = inputData->timeStamp;
    772             pSECComponent->checkTimeStamp.nStartFlags = inputData->nFlags;
    773             pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE;
    774         }
    775 
    776         ret = OMX_TRUE;
    777     } else {
    778         ret = OMX_FALSE;
    779     }
    780 
    781     FunctionOut();
    782 
    783     return ret;
    784 }
    785 
    786 OMX_BOOL SEC_Postprocess_OutputData(OMX_COMPONENTTYPE *pOMXComponent)
    787 {
    788     OMX_BOOL               ret = OMX_FALSE;
    789     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    790     SEC_OMX_DATABUFFER    *outputUseBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX];
    791     SEC_OMX_DATA          *outputData = &pSECComponent->processData[OUTPUT_PORT_INDEX];
    792     OMX_U32                copySize = 0;
    793 
    794     FunctionIn();
    795 
    796     if (outputUseBuffer->dataValid == OMX_TRUE) {
    797         if (pSECComponent->checkTimeStamp.needCheckStartTimeStamp == OMX_TRUE) {
    798             if ((pSECComponent->checkTimeStamp.startTimeStamp == outputData->timeStamp) &&
    799                 (pSECComponent->checkTimeStamp.nStartFlags == outputData->nFlags)){
    800                 pSECComponent->checkTimeStamp.startTimeStamp = -19761123;
    801                 pSECComponent->checkTimeStamp.nStartFlags = 0x0;
    802                 pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE;
    803                 pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
    804             } else {
    805                 SEC_DataReset(pOMXComponent, OUTPUT_PORT_INDEX);
    806 
    807                 ret = OMX_TRUE;
    808                 goto EXIT;
    809             }
    810         } else if (pSECComponent->checkTimeStamp.needSetStartTimeStamp == OMX_TRUE) {
    811             SEC_DataReset(pOMXComponent, OUTPUT_PORT_INDEX);
    812 
    813             ret = OMX_TRUE;
    814             goto EXIT;
    815         }
    816 
    817         if (outputData->remainDataLen <= (outputUseBuffer->allocSize - outputUseBuffer->dataLen)) {
    818             copySize = outputData->remainDataLen;
    819 #ifndef S5PC110_DECODE_OUT_DATA_BUFFER
    820             if (copySize > 0)
    821                 SEC_OSAL_Memcpy((outputUseBuffer->bufferHeader->pBuffer + outputUseBuffer->dataLen),
    822                         (outputData->dataBuffer + outputData->usedDataLen),
    823                          copySize);
    824 #endif
    825 
    826             outputUseBuffer->dataLen += copySize;
    827             outputUseBuffer->remainDataLen += copySize;
    828             outputUseBuffer->nFlags = outputData->nFlags;
    829             outputUseBuffer->timeStamp = outputData->timeStamp;
    830 
    831             ret = OMX_TRUE;
    832 
    833             /* reset outputData */
    834             SEC_DataReset(pOMXComponent, OUTPUT_PORT_INDEX);
    835 
    836 #ifdef ONE_FRAME_OUTPUT  /* only one frame output for Android */
    837             if ((outputUseBuffer->remainDataLen > 0) ||
    838                 (outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS))
    839                 SEC_OutputBufferReturn(pOMXComponent);
    840 #else
    841             if ((outputUseBuffer->remainDataLen > 0) ||
    842                 ((outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) {
    843                 SEC_OutputBufferReturn(pOMXComponent);
    844             } else {
    845                 outputUseBuffer->dataValid = OMX_TRUE;
    846             }
    847 #endif
    848         } else {
    849             SEC_OSAL_Log(SEC_LOG_ERROR, "output buffer is smaller than decoded data size Out Length");
    850 
    851             copySize = outputUseBuffer->allocSize - outputUseBuffer->dataLen;
    852 
    853 #ifndef S5PC110_DECODE_OUT_DATA_BUFFER
    854             SEC_OSAL_Memcpy((outputUseBuffer->bufferHeader->pBuffer + outputUseBuffer->dataLen),
    855                     (outputData->dataBuffer + outputData->usedDataLen),
    856                      copySize);
    857 #endif
    858             outputUseBuffer->dataLen += copySize;
    859             outputUseBuffer->remainDataLen += copySize;
    860             outputUseBuffer->nFlags = 0;
    861             outputUseBuffer->timeStamp = outputData->timeStamp;
    862 
    863             ret = OMX_FALSE;
    864 
    865             outputData->remainDataLen -= copySize;
    866             outputData->usedDataLen += copySize;
    867 
    868             SEC_OutputBufferReturn(pOMXComponent);
    869         }
    870     } else {
    871         ret = OMX_FALSE;
    872     }
    873 
    874 EXIT:
    875     FunctionOut();
    876 
    877     return ret;
    878 }
    879 
    880 OMX_ERRORTYPE SEC_OMX_BufferProcess(OMX_HANDLETYPE hComponent)
    881 {
    882     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    883     OMX_COMPONENTTYPE     *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    884     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    885     SEC_OMX_BASEPORT      *secInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX];
    886     SEC_OMX_BASEPORT      *secOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX];
    887     SEC_OMX_DATABUFFER    *inputUseBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX];
    888     SEC_OMX_DATABUFFER    *outputUseBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX];
    889     SEC_OMX_DATA          *inputData = &pSECComponent->processData[INPUT_PORT_INDEX];
    890     SEC_OMX_DATA          *outputData = &pSECComponent->processData[OUTPUT_PORT_INDEX];
    891     OMX_U32                copySize = 0;
    892 
    893     pSECComponent->remainOutputData = OMX_FALSE;
    894     pSECComponent->reInputData = OMX_FALSE;
    895 
    896     FunctionIn();
    897 
    898     while (!pSECComponent->bExitBufferProcessThread) {
    899         SEC_OSAL_SleepMillisec(0);
    900 
    901         if (((pSECComponent->currentState == OMX_StatePause) ||
    902             (pSECComponent->currentState == OMX_StateIdle) ||
    903             (pSECComponent->transientState == SEC_OMX_TransStateLoadedToIdle) ||
    904             (pSECComponent->transientState == SEC_OMX_TransStateExecutingToIdle)) &&
    905             (pSECComponent->transientState != SEC_OMX_TransStateIdleToLoaded)&&
    906             ((!CHECK_PORT_BEING_FLUSHED(secInputPort) && !CHECK_PORT_BEING_FLUSHED(secOutputPort)))) {
    907             SEC_OSAL_SignalReset(pSECComponent->pauseEvent);
    908             SEC_OSAL_SignalWait(pSECComponent->pauseEvent, DEF_MAX_WAIT_TIME);
    909         }
    910 
    911         while (SEC_Check_BufferProcess_State(pSECComponent) && !pSECComponent->bExitBufferProcessThread) {
    912             SEC_OSAL_SleepMillisec(0);
    913 
    914             SEC_OSAL_MutexLock(outputUseBuffer->bufferMutex);
    915             if ((outputUseBuffer->dataValid != OMX_TRUE) &&
    916                 (!CHECK_PORT_BEING_FLUSHED(secOutputPort))) {
    917                 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex);
    918                 ret = SEC_OutputBufferGetQueue(pSECComponent);
    919                 if ((ret == OMX_ErrorUndefined) ||
    920                     (secInputPort->portState != OMX_StateIdle) ||
    921                     (secOutputPort->portState != OMX_StateIdle)) {
    922                     break;
    923                 }
    924             } else {
    925                 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex);
    926             }
    927 
    928             if (pSECComponent->remainOutputData == OMX_FALSE) {
    929                 if (pSECComponent->reInputData == OMX_FALSE) {
    930                     SEC_OSAL_MutexLock(inputUseBuffer->bufferMutex);
    931                     if ((SEC_Preprocessor_InputData(pOMXComponent) == OMX_FALSE) &&
    932                         (!CHECK_PORT_BEING_FLUSHED(secInputPort))) {
    933                             SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex);
    934                             ret = SEC_InputBufferGetQueue(pSECComponent);
    935                             break;
    936                         }
    937 
    938                     SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex);
    939                 }
    940 
    941                 SEC_OSAL_MutexLock(inputUseBuffer->bufferMutex);
    942                 SEC_OSAL_MutexLock(outputUseBuffer->bufferMutex);
    943                 ret = pSECComponent->sec_mfc_bufferProcess(pOMXComponent, inputData, outputData);
    944                 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex);
    945                 SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex);
    946 
    947                 if (ret == OMX_ErrorInputDataDecodeYet)
    948                     pSECComponent->reInputData = OMX_TRUE;
    949                 else
    950                     pSECComponent->reInputData = OMX_FALSE;
    951             }
    952 
    953             SEC_OSAL_MutexLock(outputUseBuffer->bufferMutex);
    954 
    955             if (SEC_Postprocess_OutputData(pOMXComponent) == OMX_FALSE)
    956                 pSECComponent->remainOutputData = OMX_TRUE;
    957             else
    958                 pSECComponent->remainOutputData = OMX_FALSE;
    959 
    960             SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex);
    961         }
    962     }
    963 
    964 EXIT:
    965     FunctionOut();
    966 
    967     return ret;
    968 }
    969 
    970 OMX_ERRORTYPE SEC_OMX_VideoDecodeGetParameter(
    971     OMX_IN OMX_HANDLETYPE hComponent,
    972     OMX_IN OMX_INDEXTYPE  nParamIndex,
    973     OMX_INOUT OMX_PTR     ComponentParameterStructure)
    974 {
    975     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    976     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    977     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    978     SEC_OMX_BASEPORT      *pSECPort = NULL;
    979 
    980     FunctionIn();
    981 
    982     if (hComponent == NULL) {
    983         ret = OMX_ErrorBadParameter;
    984         goto EXIT;
    985     }
    986     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    987     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    988     if (ret != OMX_ErrorNone) {
    989         goto EXIT;
    990     }
    991 
    992     if (pOMXComponent->pComponentPrivate == NULL) {
    993         ret = OMX_ErrorBadParameter;
    994         goto EXIT;
    995     }
    996     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    997 
    998     if (pSECComponent->currentState == OMX_StateInvalid ) {
    999         ret = OMX_StateInvalid;
   1000         goto EXIT;
   1001     }
   1002 
   1003     if (ComponentParameterStructure == NULL) {
   1004         ret = OMX_ErrorBadParameter;
   1005         goto EXIT;
   1006     }
   1007 
   1008     switch (nParamIndex) {
   1009     case OMX_IndexParamVideoInit:
   1010     {
   1011         OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
   1012         ret = SEC_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE));
   1013         if (ret != OMX_ErrorNone) {
   1014             goto EXIT;
   1015         }
   1016 
   1017         portParam->nPorts           = pSECComponent->portParam.nPorts;
   1018         portParam->nStartPortNumber = pSECComponent->portParam.nStartPortNumber;
   1019         ret = OMX_ErrorNone;
   1020     }
   1021         break;
   1022     case OMX_IndexParamVideoPortFormat:
   1023     {
   1024         OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
   1025         OMX_U32                         portIndex = portFormat->nPortIndex;
   1026         OMX_U32                         index    = portFormat->nIndex;
   1027         SEC_OMX_BASEPORT               *pSECPort = NULL;
   1028         OMX_PARAM_PORTDEFINITIONTYPE   *portDefinition = NULL;
   1029         OMX_U32                         supportFormatNum = 0; /* supportFormatNum = N-1 */
   1030 
   1031         ret = SEC_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1032         if (ret != OMX_ErrorNone) {
   1033             goto EXIT;
   1034         }
   1035 
   1036         if ((portIndex >= pSECComponent->portParam.nPorts)) {
   1037             ret = OMX_ErrorBadPortIndex;
   1038             goto EXIT;
   1039         }
   1040 
   1041 
   1042         if (portIndex == INPUT_PORT_INDEX) {
   1043             supportFormatNum = INPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1;
   1044             if (index > supportFormatNum) {
   1045                 ret = OMX_ErrorNoMore;
   1046                 goto EXIT;
   1047             }
   1048 
   1049             pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX];
   1050             portDefinition = &pSECPort->portDefinition;
   1051 
   1052             portFormat->eCompressionFormat = portDefinition->format.video.eCompressionFormat;
   1053             portFormat->eColorFormat       = portDefinition->format.video.eColorFormat;
   1054             portFormat->xFramerate           = portDefinition->format.video.xFramerate;
   1055         } else if (portIndex == OUTPUT_PORT_INDEX) {
   1056             supportFormatNum = OUTPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1;
   1057             if (index > supportFormatNum) {
   1058                 ret = OMX_ErrorNoMore;
   1059                 goto EXIT;
   1060             }
   1061 
   1062             pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX];
   1063             portDefinition = &pSECPort->portDefinition;
   1064 
   1065             switch (index) {
   1066             case supportFormat_1:
   1067                 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
   1068                 portFormat->eColorFormat       = OMX_COLOR_FormatYUV420Planar;
   1069                 portFormat->xFramerate           = portDefinition->format.video.xFramerate;
   1070                 break;
   1071             case supportFormat_2:
   1072                 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
   1073                 portFormat->eColorFormat       = OMX_COLOR_FormatYUV420SemiPlanar;
   1074                 portFormat->xFramerate         = portDefinition->format.video.xFramerate;
   1075                 break;
   1076             case supportFormat_3:
   1077                 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
   1078                 portFormat->eColorFormat       = SEC_OMX_COLOR_FormatNV12PhysicalAddress;
   1079                 portFormat->xFramerate           = portDefinition->format.video.xFramerate;
   1080                 break;
   1081             }
   1082         }
   1083         ret = OMX_ErrorNone;
   1084     }
   1085         break;
   1086     case OMX_IndexParamVideoBitrate:
   1087     {
   1088         OMX_VIDEO_PARAM_BITRATETYPE  *videoRateControl = (OMX_VIDEO_PARAM_BITRATETYPE *)ComponentParameterStructure;
   1089         OMX_U32                       portIndex = videoRateControl->nPortIndex;
   1090         SEC_OMX_BASEPORT         *pSECPort = NULL;
   1091         OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL;
   1092 
   1093         if ((portIndex != INPUT_PORT_INDEX)) {
   1094             ret = OMX_ErrorBadPortIndex;
   1095             goto EXIT;
   1096         } else {
   1097             pSECPort = &pSECComponent->pSECPort[portIndex];
   1098             portDefinition = &pSECPort->portDefinition;
   1099 
   1100             videoRateControl->eControlRate = pSECPort->eControlRate;
   1101             videoRateControl->nTargetBitrate = portDefinition->format.video.nBitrate;
   1102         }
   1103         ret = OMX_ErrorNone;
   1104     }
   1105         break;
   1106     default:
   1107     {
   1108         ret = SEC_OMX_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
   1109     }
   1110         break;
   1111     }
   1112 
   1113 EXIT:
   1114     FunctionOut();
   1115 
   1116     return ret;
   1117 }
   1118 OMX_ERRORTYPE SEC_OMX_VideoDecodeSetParameter(
   1119     OMX_IN OMX_HANDLETYPE hComponent,
   1120     OMX_IN OMX_INDEXTYPE  nIndex,
   1121     OMX_IN OMX_PTR        ComponentParameterStructure)
   1122 {
   1123     OMX_ERRORTYPE          ret = OMX_ErrorNone;
   1124     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
   1125     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
   1126     SEC_OMX_BASEPORT      *pSECPort = NULL;
   1127 
   1128     FunctionIn();
   1129 
   1130     if (hComponent == NULL) {
   1131         ret = OMX_ErrorBadParameter;
   1132         goto EXIT;
   1133     }
   1134     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   1135     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
   1136     if (ret != OMX_ErrorNone) {
   1137         goto EXIT;
   1138     }
   1139 
   1140     if (pOMXComponent->pComponentPrivate == NULL) {
   1141         ret = OMX_ErrorBadParameter;
   1142         goto EXIT;
   1143     }
   1144     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1145 
   1146     if (pSECComponent->currentState == OMX_StateInvalid ) {
   1147         ret = OMX_StateInvalid;
   1148         goto EXIT;
   1149     }
   1150 
   1151     if (ComponentParameterStructure == NULL) {
   1152         ret = OMX_ErrorBadParameter;
   1153         goto EXIT;
   1154     }
   1155 
   1156     switch (nIndex) {
   1157     case OMX_IndexParamVideoPortFormat:
   1158     {
   1159         OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
   1160         OMX_U32                         portIndex = portFormat->nPortIndex;
   1161         OMX_U32                         index    = portFormat->nIndex;
   1162         SEC_OMX_BASEPORT               *pSECPort = NULL;
   1163         OMX_PARAM_PORTDEFINITIONTYPE   *portDefinition = NULL;
   1164         OMX_U32                         supportFormatNum = 0;
   1165 
   1166         ret = SEC_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
   1167         if (ret != OMX_ErrorNone) {
   1168             goto EXIT;
   1169         }
   1170 
   1171         if ((portIndex >= pSECComponent->portParam.nPorts)) {
   1172             ret = OMX_ErrorBadPortIndex;
   1173             goto EXIT;
   1174         } else {
   1175             pSECPort = &pSECComponent->pSECPort[portIndex];
   1176             portDefinition = &pSECPort->portDefinition;
   1177 
   1178             portDefinition->format.video.eColorFormat       = portFormat->eColorFormat;
   1179             portDefinition->format.video.eCompressionFormat = portFormat->eCompressionFormat;
   1180             portDefinition->format.video.xFramerate         = portFormat->xFramerate;
   1181         }
   1182     }
   1183         break;
   1184     case OMX_IndexParamVideoBitrate:
   1185     {
   1186         OMX_VIDEO_PARAM_BITRATETYPE  *videoRateControl = (OMX_VIDEO_PARAM_BITRATETYPE *)ComponentParameterStructure;
   1187         OMX_U32                       portIndex = videoRateControl->nPortIndex;
   1188         SEC_OMX_BASEPORT             *pSECPort = NULL;
   1189         OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL;
   1190 
   1191         if ((portIndex != INPUT_PORT_INDEX)) {
   1192             ret = OMX_ErrorBadPortIndex;
   1193             goto EXIT;
   1194         } else {
   1195             pSECPort = &pSECComponent->pSECPort[portIndex];
   1196             portDefinition = &pSECPort->portDefinition;
   1197 
   1198             pSECPort->eControlRate = videoRateControl->eControlRate;
   1199             portDefinition->format.video.nBitrate = videoRateControl->nTargetBitrate;
   1200         }
   1201         ret = OMX_ErrorNone;
   1202     }
   1203         break;
   1204     default:
   1205     {
   1206         ret = SEC_OMX_SetParameter(hComponent, nIndex, ComponentParameterStructure);
   1207     }
   1208         break;
   1209     }
   1210 
   1211 EXIT:
   1212     FunctionOut();
   1213 
   1214     return ret;
   1215 }
   1216 
   1217 OMX_ERRORTYPE SEC_OMX_VideoDecodeComponentInit(OMX_IN OMX_HANDLETYPE hComponent)
   1218 {
   1219     OMX_ERRORTYPE          ret = OMX_ErrorNone;
   1220     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
   1221     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
   1222     SEC_OMX_BASEPORT      *pSECPort = NULL;
   1223 
   1224     FunctionIn();
   1225 
   1226     if (hComponent == NULL) {
   1227         ret = OMX_ErrorBadParameter;
   1228         goto EXIT;
   1229     }
   1230     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   1231     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
   1232     if (ret != OMX_ErrorNone) {
   1233         SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_Error, Line:%d", __LINE__);
   1234         goto EXIT;
   1235     }
   1236 
   1237     ret = SEC_OMX_BaseComponent_Constructor(pOMXComponent);
   1238     if (ret != OMX_ErrorNone) {
   1239         SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_Error, Line:%d", __LINE__);
   1240         goto EXIT;
   1241     }
   1242 
   1243     ret = SEC_OMX_Port_Constructor(pOMXComponent);
   1244     if (ret != OMX_ErrorNone) {
   1245         SEC_OMX_BaseComponent_Destructor(pOMXComponent);
   1246         SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_Error, Line:%d", __LINE__);
   1247         goto EXIT;
   1248     }
   1249 
   1250     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1251     pSECComponent->bSaveFlagEOS = OMX_FALSE;
   1252 
   1253     /* Input port */
   1254     pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX];
   1255     pSECPort->portDefinition.nBufferCountActual = MAX_VIDEO_INPUTBUFFER_NUM;
   1256     pSECPort->portDefinition.nBufferCountMin = MAX_VIDEO_INPUTBUFFER_NUM;
   1257     pSECPort->portDefinition.nBufferSize = 0;
   1258     pSECPort->portDefinition.eDomain = OMX_PortDomainVideo;
   1259 
   1260     pSECPort->portDefinition.format.video.cMIMEType = SEC_OSAL_Malloc(MAX_OMX_MIMETYPE_SIZE);
   1261     SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "raw/video");
   1262     pSECPort->portDefinition.format.video.pNativeRender = 0;
   1263     pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE;
   1264     pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
   1265 
   1266     pSECPort->portDefinition.format.video.nFrameWidth = 0;
   1267     pSECPort->portDefinition.format.video.nFrameHeight= 0;
   1268     pSECPort->portDefinition.format.video.nStride = 0;
   1269     pSECPort->portDefinition.format.video.nSliceHeight = 0;
   1270     pSECPort->portDefinition.format.video.nBitrate = 64000;
   1271     pSECPort->portDefinition.format.video.xFramerate = (15 << 16);
   1272     pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused;
   1273     pSECPort->portDefinition.format.video.pNativeWindow = NULL;
   1274 
   1275     /* Output port */
   1276     pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX];
   1277     pSECPort->portDefinition.nBufferCountActual = MAX_VIDEO_OUTPUTBUFFER_NUM;
   1278     pSECPort->portDefinition.nBufferCountMin = MAX_VIDEO_OUTPUTBUFFER_NUM;
   1279     pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE;
   1280     pSECPort->portDefinition.eDomain = OMX_PortDomainVideo;
   1281 
   1282     pSECPort->portDefinition.format.video.cMIMEType = SEC_OSAL_Malloc(MAX_OMX_MIMETYPE_SIZE);
   1283     SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "raw/video");
   1284     pSECPort->portDefinition.format.video.pNativeRender = 0;
   1285     pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE;
   1286     pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
   1287 
   1288     pSECPort->portDefinition.format.video.nFrameWidth = 0;
   1289     pSECPort->portDefinition.format.video.nFrameHeight= 0;
   1290     pSECPort->portDefinition.format.video.nStride = 0;
   1291     pSECPort->portDefinition.format.video.nSliceHeight = 0;
   1292     pSECPort->portDefinition.format.video.nBitrate = 64000;
   1293     pSECPort->portDefinition.format.video.xFramerate = (15 << 16);
   1294     pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused;
   1295     pSECPort->portDefinition.format.video.pNativeWindow = NULL;
   1296 
   1297     pOMXComponent->UseBuffer              = &SEC_OMX_UseBuffer;
   1298     pOMXComponent->AllocateBuffer         = &SEC_OMX_AllocateBuffer;
   1299     pOMXComponent->FreeBuffer             = &SEC_OMX_FreeBuffer;
   1300     pOMXComponent->ComponentTunnelRequest = &SEC_OMX_ComponentTunnelRequest;
   1301 
   1302     pSECComponent->sec_AllocateTunnelBuffer = &SEC_OMX_AllocateTunnelBuffer;
   1303     pSECComponent->sec_FreeTunnelBuffer     = &SEC_OMX_FreeTunnelBuffer;
   1304     pSECComponent->sec_BufferProcess        = &SEC_OMX_BufferProcess;
   1305     pSECComponent->sec_BufferReset          = &SEC_BufferReset;
   1306     pSECComponent->sec_InputBufferReturn    = &SEC_InputBufferReturn;
   1307     pSECComponent->sec_OutputBufferReturn   = &SEC_OutputBufferReturn;
   1308 
   1309 EXIT:
   1310     FunctionOut();
   1311 
   1312     return ret;
   1313 }
   1314 
   1315 OMX_ERRORTYPE SEC_OMX_VideoDecodeComponentDeinit(OMX_IN OMX_HANDLETYPE hComponent)
   1316 {
   1317     OMX_ERRORTYPE          ret = OMX_ErrorNone;
   1318     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
   1319     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
   1320     SEC_OMX_BASEPORT      *pSECPort = NULL;
   1321     int                    i = 0;
   1322 
   1323     FunctionIn();
   1324 
   1325     if (hComponent == NULL) {
   1326         ret = OMX_ErrorBadParameter;
   1327         goto EXIT;
   1328     }
   1329     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
   1330     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
   1331     if (ret != OMX_ErrorNone) {
   1332         goto EXIT;
   1333     }
   1334 
   1335     if (pOMXComponent->pComponentPrivate == NULL) {
   1336         ret = OMX_ErrorBadParameter;
   1337         goto EXIT;
   1338     }
   1339     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
   1340 
   1341     for(i = 0; i < ALL_PORT_NUM; i++) {
   1342         pSECPort = &pSECComponent->pSECPort[i];
   1343         SEC_OSAL_Free(pSECPort->portDefinition.format.video.cMIMEType);
   1344         pSECPort->portDefinition.format.video.cMIMEType = NULL;
   1345     }
   1346 
   1347     ret = SEC_OMX_Port_Destructor(pOMXComponent);
   1348 
   1349     ret = SEC_OMX_BaseComponent_Destructor(hComponent);
   1350 
   1351 EXIT:
   1352     FunctionOut();
   1353 
   1354     return ret;
   1355 }
   1356