Home | History | Annotate | Download | only in common
      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_Baseport.c
     20  * @brief
     21  * @author     SeungBeom Kim (sbcrux.kim (at) samsung.com)
     22  *             HyeYeon Chung (hyeon.chung (at) samsung.com)
     23  * @version    1.0
     24  * @history
     25  *    2010.7.15 : Create
     26  */
     27 
     28 #include <stdio.h>
     29 #include <stdlib.h>
     30 #include <string.h>
     31 
     32 #include "SEC_OMX_Macros.h"
     33 #include "SEC_OSAL_Event.h"
     34 #include "SEC_OSAL_Semaphore.h"
     35 #include "SEC_OSAL_Mutex.h"
     36 
     37 #include "SEC_OMX_Baseport.h"
     38 #include "SEC_OMX_Basecomponent.h"
     39 
     40 #undef  SEC_LOG_TAG
     41 #define SEC_LOG_TAG    "SEC_BASE_PORT"
     42 #define SEC_LOG_OFF
     43 #include "SEC_OSAL_Log.h"
     44 
     45 
     46 OMX_ERRORTYPE SEC_OMX_FlushPort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
     47 {
     48     OMX_ERRORTYPE          ret = OMX_ErrorNone;
     49     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
     50     SEC_OMX_BASEPORT      *pSECPort = NULL;
     51     OMX_BUFFERHEADERTYPE  *bufferHeader = NULL;
     52     SEC_OMX_MESSAGE       *message = NULL;
     53     OMX_U32                flushNum = 0;
     54     OMX_S32                semValue = 0;
     55 
     56     FunctionIn();
     57 
     58     pSECPort = &pSECComponent->pSECPort[portIndex];
     59     while (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) > 0) {
     60         SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[portIndex].bufferSemID, &semValue);
     61         if (semValue == 0)
     62             SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[portIndex].bufferSemID);
     63         SEC_OSAL_SemaphoreWait(pSECComponent->pSECPort[portIndex].bufferSemID);
     64 
     65         message = (SEC_OMX_MESSAGE *)SEC_OSAL_Dequeue(&pSECPort->bufferQ);
     66         if (message != NULL) {
     67             bufferHeader = (OMX_BUFFERHEADERTYPE *)message->pCmdData;
     68             bufferHeader->nFilledLen = 0;
     69 
     70             if (CHECK_PORT_TUNNELED(pSECPort) && !CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
     71                 if (portIndex) {
     72                     OMX_EmptyThisBuffer(pSECPort->tunneledComponent, bufferHeader);
     73                 } else {
     74                     OMX_FillThisBuffer(pSECPort->tunneledComponent, bufferHeader);
     75                 }
     76                 SEC_OSAL_Free(message);
     77                 message = NULL;
     78             } else if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
     79                 SEC_OSAL_Log(SEC_LOG_ERROR, "Tunneled mode is not working, Line:%d", __LINE__);
     80                 ret = OMX_ErrorNotImplemented;
     81                 SEC_OSAL_Queue(&pSECPort->bufferQ, pSECPort);
     82                 goto EXIT;
     83             } else {
     84                 if (portIndex == OUTPUT_PORT_INDEX) {
     85                     pSECComponent->pCallbacks->FillBufferDone(pOMXComponent, pSECComponent->callbackData, bufferHeader);
     86                 } else {
     87                     pSECComponent->pCallbacks->EmptyBufferDone(pOMXComponent, pSECComponent->callbackData, bufferHeader);
     88                 }
     89 
     90                 SEC_OSAL_Free(message);
     91                 message = NULL;
     92             }
     93         }
     94     }
     95 
     96     if (pSECComponent->secDataBuffer[portIndex].dataValid == OMX_TRUE) {
     97         if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
     98             message = SEC_OSAL_Malloc(sizeof(SEC_OMX_MESSAGE));
     99             message->pCmdData = pSECComponent->secDataBuffer[portIndex].bufferHeader;
    100             message->messageType = 0;
    101             message->messageParam = -1;
    102             SEC_OSAL_Queue(&pSECPort->bufferQ, message);
    103             pSECComponent->sec_BufferReset(pOMXComponent, portIndex);
    104         } else {
    105             if (portIndex == INPUT_PORT_INDEX)
    106                 pSECComponent->sec_InputBufferReturn(pOMXComponent);
    107             else if (portIndex == OUTPUT_PORT_INDEX)
    108                 pSECComponent->sec_OutputBufferReturn(pOMXComponent);
    109         }
    110     }
    111 
    112     if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
    113         while (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) < pSECPort->assignedBufferNum) {
    114             SEC_OSAL_SemaphoreWait(pSECComponent->pSECPort[portIndex].bufferSemID);
    115         }
    116         if (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) != pSECPort->assignedBufferNum)
    117             SEC_OSAL_SetElemNum(&pSECPort->bufferQ, pSECPort->assignedBufferNum);
    118     } else {
    119         while(1) {
    120             int cnt;
    121             SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[portIndex].bufferSemID, &cnt);
    122             if (cnt == 0)
    123                 break;
    124             SEC_OSAL_SemaphoreWait(pSECComponent->pSECPort[portIndex].bufferSemID);
    125         }
    126         SEC_OSAL_SetElemNum(&pSECPort->bufferQ, 0);
    127     }
    128 
    129     pSECComponent->processData[portIndex].dataLen       = 0;
    130     pSECComponent->processData[portIndex].nFlags        = 0;
    131     pSECComponent->processData[portIndex].remainDataLen = 0;
    132     pSECComponent->processData[portIndex].timeStamp     = 0;
    133     pSECComponent->processData[portIndex].usedDataLen   = 0;
    134 
    135 EXIT:
    136     FunctionOut();
    137 
    138     return ret;
    139 }
    140 
    141 OMX_ERRORTYPE SEC_OMX_BufferFlushProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex)
    142 {
    143     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    144     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    145     SEC_OMX_BASEPORT      *pSECPort = NULL;
    146     OMX_S32                portIndex = 0;
    147     OMX_U32                i = 0, cnt = 0;
    148     SEC_OMX_DATABUFFER    *flushBuffer = NULL;
    149 
    150     FunctionIn();
    151 
    152     if (pOMXComponent == NULL) {
    153         ret = OMX_ErrorBadParameter;
    154         goto EXIT;
    155     }
    156     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    157     if (ret != OMX_ErrorNone) {
    158         goto EXIT;
    159     }
    160 
    161     if (pOMXComponent->pComponentPrivate == NULL) {
    162         ret = OMX_ErrorBadParameter;
    163         goto EXIT;
    164     }
    165     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    166 
    167     cnt = (nPortIndex == ALL_PORT_INDEX ) ? ALL_PORT_NUM : 1;
    168 
    169     for (i = 0; i < cnt; i++) {
    170         if (nPortIndex == ALL_PORT_INDEX)
    171             portIndex = i;
    172         else
    173             portIndex = nPortIndex;
    174 
    175         SEC_OSAL_SignalSet(pSECComponent->pauseEvent);
    176 
    177         flushBuffer = &pSECComponent->secDataBuffer[portIndex];
    178 
    179         SEC_OSAL_MutexLock(flushBuffer->bufferMutex);
    180         ret = SEC_OMX_FlushPort(pOMXComponent, portIndex);
    181         SEC_OSAL_MutexUnlock(flushBuffer->bufferMutex);
    182 
    183         pSECComponent->pSECPort[portIndex].bIsPortFlushed = OMX_FALSE;
    184 
    185         if (ret == OMX_ErrorNone) {
    186             SEC_OSAL_Log(SEC_LOG_TRACE,"OMX_CommandFlush EventCmdComplete");
    187             pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
    188                             pSECComponent->callbackData,
    189                             OMX_EventCmdComplete,
    190                             OMX_CommandFlush, portIndex, NULL);
    191         }
    192 
    193         if (portIndex == INPUT_PORT_INDEX) {
    194             pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE;
    195             pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
    196             SEC_OSAL_Memset(pSECComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP);
    197             SEC_OSAL_Memset(pSECComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS);
    198             pSECComponent->getAllDelayBuffer = OMX_FALSE;
    199             pSECComponent->bSaveFlagEOS = OMX_FALSE;
    200             pSECComponent->reInputData = OMX_FALSE;
    201         } else if (portIndex == OUTPUT_PORT_INDEX) {
    202             pSECComponent->remainOutputData = OMX_FALSE;
    203         }
    204     }
    205 
    206 EXIT:
    207     if (ret != OMX_ErrorNone) {
    208             pSECComponent->pCallbacks->EventHandler(pOMXComponent,
    209                             pSECComponent->callbackData,
    210                             OMX_EventError,
    211                             ret, 0, NULL);
    212     }
    213 
    214     FunctionOut();
    215 
    216     return ret;
    217 }
    218 
    219 OMX_ERRORTYPE SEC_OMX_BufferFlushProcessNoEvent(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex)
    220 {
    221     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    222     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    223     SEC_OMX_BASEPORT      *pSECPort = NULL;
    224     OMX_S32                portIndex = 0;
    225     OMX_U32                i = 0, cnt = 0;
    226     SEC_OMX_DATABUFFER    *flushBuffer = NULL;
    227 
    228     FunctionIn();
    229 
    230     if (pOMXComponent == NULL) {
    231         ret = OMX_ErrorBadParameter;
    232         goto EXIT;
    233     }
    234     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    235     if (ret != OMX_ErrorNone) {
    236         goto EXIT;
    237     }
    238 
    239     if (pOMXComponent->pComponentPrivate == NULL) {
    240         ret = OMX_ErrorBadParameter;
    241         goto EXIT;
    242     }
    243     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    244 
    245     cnt = (nPortIndex == ALL_PORT_INDEX ) ? ALL_PORT_NUM : 1;
    246 
    247     for (i = 0; i < cnt; i++) {
    248         if (nPortIndex == ALL_PORT_INDEX)
    249             portIndex = i;
    250         else
    251             portIndex = nPortIndex;
    252 
    253         pSECComponent->pSECPort[portIndex].bIsPortFlushed = OMX_TRUE;
    254 
    255         SEC_OSAL_SignalSet(pSECComponent->pauseEvent);
    256 
    257         flushBuffer = &pSECComponent->secDataBuffer[portIndex];
    258 
    259         SEC_OSAL_MutexLock(flushBuffer->bufferMutex);
    260         ret = SEC_OMX_FlushPort(pOMXComponent, portIndex);
    261         SEC_OSAL_MutexUnlock(flushBuffer->bufferMutex);
    262 
    263         pSECComponent->pSECPort[portIndex].bIsPortFlushed = OMX_FALSE;
    264 
    265         if (portIndex == INPUT_PORT_INDEX) {
    266             pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE;
    267             pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
    268             SEC_OSAL_Memset(pSECComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP);
    269             SEC_OSAL_Memset(pSECComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS);
    270             pSECComponent->getAllDelayBuffer = OMX_FALSE;
    271             pSECComponent->bSaveFlagEOS = OMX_FALSE;
    272             pSECComponent->remainOutputData = OMX_FALSE;
    273             pSECComponent->reInputData = OMX_FALSE;
    274         }
    275     }
    276 
    277 EXIT:
    278     if (ret != OMX_ErrorNone) {
    279         pSECComponent->pCallbacks->EventHandler(pOMXComponent,
    280                             pSECComponent->callbackData,
    281                             OMX_EventError,
    282                             ret, 0, NULL);
    283     }
    284 
    285     FunctionOut();
    286 
    287     return ret;
    288 }
    289 
    290 
    291 OMX_ERRORTYPE SEC_OMX_EnablePort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
    292 {
    293     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    294     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    295     SEC_OMX_BASEPORT      *pSECPort = NULL;
    296     OMX_U32                i = 0, cnt = 0;
    297 
    298     FunctionIn();
    299 
    300     pSECPort = &pSECComponent->pSECPort[portIndex];
    301     pSECPort->portDefinition.bEnabled = OMX_TRUE;
    302 
    303     if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
    304         ret = pSECComponent->sec_AllocateTunnelBuffer(pSECPort, portIndex);
    305         if (OMX_ErrorNone != ret) {
    306             goto EXIT;
    307         }
    308         pSECPort->portDefinition.bPopulated = OMX_TRUE;
    309         if (pSECComponent->currentState == OMX_StateExecuting) {
    310             for (i=0; i<pSECPort->tunnelBufferNum; i++) {
    311                 SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[portIndex].bufferSemID);
    312             }
    313         }
    314     } else if (CHECK_PORT_TUNNELED(pSECPort) && !CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
    315         if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) {
    316             SEC_OSAL_SemaphoreWait(pSECPort->loadedResource);
    317             pSECPort->portDefinition.bPopulated = OMX_TRUE;
    318         }
    319     } else {
    320         if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) {
    321             SEC_OSAL_SemaphoreWait(pSECPort->loadedResource);
    322             pSECPort->portDefinition.bPopulated = OMX_TRUE;
    323         }
    324     }
    325     ret = OMX_ErrorNone;
    326 
    327 EXIT:
    328     FunctionOut();
    329 
    330     return ret;
    331 }
    332 
    333 OMX_ERRORTYPE SEC_OMX_PortEnableProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex)
    334 {
    335     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    336     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    337     OMX_S32                portIndex = 0;
    338     OMX_U32                i = 0, cnt = 0;
    339 
    340     FunctionIn();
    341 
    342     if (pOMXComponent == NULL) {
    343         ret = OMX_ErrorBadParameter;
    344         goto EXIT;
    345     }
    346     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    347     if (ret != OMX_ErrorNone) {
    348         goto EXIT;
    349     }
    350 
    351     if (pOMXComponent->pComponentPrivate == NULL) {
    352         ret = OMX_ErrorBadParameter;
    353         goto EXIT;
    354     }
    355     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    356 
    357     cnt = (nPortIndex == ALL_PORT_INDEX) ? ALL_PORT_NUM : 1;
    358 
    359     for (i = 0; i < cnt; i++) {
    360         if (nPortIndex == ALL_PORT_INDEX)
    361             portIndex = i;
    362         else
    363             portIndex = nPortIndex;
    364 
    365         ret = SEC_OMX_EnablePort(pOMXComponent, portIndex);
    366         if (ret == OMX_ErrorNone) {
    367             pSECComponent->pCallbacks->EventHandler(pOMXComponent,
    368                             pSECComponent->callbackData,
    369                             OMX_EventCmdComplete,
    370                             OMX_CommandPortEnable, portIndex, NULL);
    371         }
    372     }
    373 
    374 EXIT:
    375     if (ret != OMX_ErrorNone) {
    376             pSECComponent->pCallbacks->EventHandler(pOMXComponent,
    377                             pSECComponent->callbackData,
    378                             OMX_EventError,
    379                             ret, 0, NULL);
    380         }
    381 
    382     FunctionOut();
    383 
    384     return ret;
    385 }
    386 
    387 OMX_ERRORTYPE SEC_OMX_DisablePort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex)
    388 {
    389     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    390     SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    391     SEC_OMX_BASEPORT      *pSECPort = NULL;
    392     OMX_U32                i = 0, elemNum = 0;
    393     SEC_OMX_MESSAGE       *message;
    394 
    395     FunctionIn();
    396 
    397     pSECPort = &pSECComponent->pSECPort[portIndex];
    398 
    399     if (!CHECK_PORT_ENABLED(pSECPort)) {
    400         ret = OMX_ErrorNone;
    401         goto EXIT;
    402     }
    403 
    404     if (pSECComponent->currentState!=OMX_StateLoaded) {
    405         if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
    406             while (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) >0 ) {
    407                 message = (SEC_OMX_MESSAGE*)SEC_OSAL_Dequeue(&pSECPort->bufferQ);
    408                 SEC_OSAL_Free(message);
    409             }
    410             ret = pSECComponent->sec_FreeTunnelBuffer(pSECPort, portIndex);
    411             if (OMX_ErrorNone != ret) {
    412                 goto EXIT;
    413             }
    414             pSECPort->portDefinition.bPopulated = OMX_FALSE;
    415         } else if (CHECK_PORT_TUNNELED(pSECPort) && !CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
    416             pSECPort->portDefinition.bPopulated = OMX_FALSE;
    417             SEC_OSAL_SemaphoreWait(pSECPort->unloadedResource);
    418         } else {
    419             if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
    420                 while (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) >0 ) {
    421                     message = (SEC_OMX_MESSAGE*)SEC_OSAL_Dequeue(&pSECPort->bufferQ);
    422                     SEC_OSAL_Free(message);
    423                 }
    424             }
    425             pSECPort->portDefinition.bPopulated = OMX_FALSE;
    426             SEC_OSAL_SemaphoreWait(pSECPort->unloadedResource);
    427         }
    428     }
    429     pSECPort->portDefinition.bEnabled = OMX_FALSE;
    430     ret = OMX_ErrorNone;
    431 
    432 EXIT:
    433     FunctionOut();
    434 
    435     return ret;
    436 }
    437 
    438 OMX_ERRORTYPE SEC_OMX_PortDisableProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex)
    439 {
    440     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    441     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    442     OMX_S32                portIndex = 0;
    443     OMX_U32                i = 0, cnt = 0;
    444     SEC_OMX_DATABUFFER      *flushBuffer = NULL;
    445 
    446     FunctionIn();
    447 
    448     if (pOMXComponent == NULL) {
    449         ret = OMX_ErrorBadParameter;
    450         goto EXIT;
    451     }
    452     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    453     if (ret != OMX_ErrorNone) {
    454         goto EXIT;
    455     }
    456 
    457     if (pOMXComponent->pComponentPrivate == NULL) {
    458         ret = OMX_ErrorBadParameter;
    459         goto EXIT;
    460     }
    461     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    462 
    463     cnt = (nPortIndex == ALL_PORT_INDEX ) ? ALL_PORT_NUM : 1;
    464 
    465     /* port flush*/
    466     for(i = 0; i < cnt; i++) {
    467         if (nPortIndex == ALL_PORT_INDEX)
    468             portIndex = i;
    469         else
    470             portIndex = nPortIndex;
    471 
    472         pSECComponent->pSECPort[portIndex].bIsPortFlushed = OMX_TRUE;
    473 
    474         flushBuffer = &pSECComponent->secDataBuffer[portIndex];
    475 
    476         SEC_OSAL_MutexLock(flushBuffer->bufferMutex);
    477         ret = SEC_OMX_FlushPort(pOMXComponent, portIndex);
    478         SEC_OSAL_MutexUnlock(flushBuffer->bufferMutex);
    479 
    480         pSECComponent->pSECPort[portIndex].bIsPortFlushed = OMX_FALSE;
    481 
    482         if (portIndex == INPUT_PORT_INDEX) {
    483             pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE;
    484             pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
    485             SEC_OSAL_Memset(pSECComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP);
    486             SEC_OSAL_Memset(pSECComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS);
    487             pSECComponent->getAllDelayBuffer = OMX_FALSE;
    488             pSECComponent->bSaveFlagEOS = OMX_FALSE;
    489             pSECComponent->reInputData = OMX_FALSE;
    490         } else if (portIndex == OUTPUT_PORT_INDEX) {
    491             pSECComponent->remainOutputData = OMX_FALSE;
    492         }
    493     }
    494 
    495     for(i = 0; i < cnt; i++) {
    496         if (nPortIndex == ALL_PORT_INDEX)
    497             portIndex = i;
    498         else
    499             portIndex = nPortIndex;
    500 
    501         ret = SEC_OMX_DisablePort(pOMXComponent, portIndex);
    502         pSECComponent->pSECPort[portIndex].bIsPortDisabled = OMX_FALSE;
    503         if (ret == OMX_ErrorNone) {
    504             pSECComponent->pCallbacks->EventHandler(pOMXComponent,
    505                             pSECComponent->callbackData,
    506                             OMX_EventCmdComplete,
    507                             OMX_CommandPortDisable, portIndex, NULL);
    508         }
    509     }
    510 
    511 EXIT:
    512     if (ret != OMX_ErrorNone) {
    513         pSECComponent->pCallbacks->EventHandler(pOMXComponent,
    514                         pSECComponent->callbackData,
    515                         OMX_EventError,
    516                         ret, 0, NULL);
    517     }
    518 
    519     FunctionOut();
    520 
    521     return ret;
    522 }
    523 
    524 OMX_ERRORTYPE SEC_OMX_EmptyThisBuffer(
    525     OMX_IN OMX_HANDLETYPE        hComponent,
    526     OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
    527 {
    528     OMX_ERRORTYPE           ret = OMX_ErrorNone;
    529     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    530     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    531     SEC_OMX_BASEPORT      *pSECPort = NULL;
    532     OMX_BOOL               findBuffer = OMX_FALSE;
    533     SEC_OMX_MESSAGE       *message;
    534     OMX_U32                i = 0;
    535 
    536     FunctionIn();
    537 
    538     if (hComponent == NULL) {
    539         ret = OMX_ErrorBadParameter;
    540         goto EXIT;
    541     }
    542     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    543     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    544     if (ret != OMX_ErrorNone) {
    545         goto EXIT;
    546     }
    547 
    548     if (pOMXComponent->pComponentPrivate == NULL) {
    549         ret = OMX_ErrorBadParameter;
    550         goto EXIT;
    551     }
    552     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    553     if (pSECComponent->currentState == OMX_StateInvalid) {
    554         ret = OMX_ErrorInvalidState;
    555         goto EXIT;
    556     }
    557 
    558     if (pBuffer == NULL) {
    559         ret = OMX_ErrorBadParameter;
    560         goto EXIT;
    561     }
    562     if (pBuffer->nInputPortIndex != INPUT_PORT_INDEX) {
    563         ret = OMX_ErrorBadPortIndex;
    564         goto EXIT;
    565     }
    566 
    567     ret = SEC_OMX_Check_SizeVersion(pBuffer, sizeof(OMX_BUFFERHEADERTYPE));
    568     if (ret != OMX_ErrorNone) {
    569         goto EXIT;
    570     }
    571 
    572     if ((pSECComponent->currentState != OMX_StateIdle) &&
    573         (pSECComponent->currentState != OMX_StateExecuting) &&
    574         (pSECComponent->currentState != OMX_StatePause)) {
    575         ret = OMX_ErrorIncorrectStateOperation;
    576         goto EXIT;
    577     }
    578 
    579     pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX];
    580     if ((!CHECK_PORT_ENABLED(pSECPort)) ||
    581         ((CHECK_PORT_BEING_FLUSHED(pSECPort) || CHECK_PORT_BEING_DISABLED(pSECPort)) &&
    582         (!CHECK_PORT_TUNNELED(pSECPort) || !CHECK_PORT_BUFFER_SUPPLIER(pSECPort))) ||
    583         ((pSECComponent->transientState == SEC_OMX_TransStateExecutingToIdle) &&
    584         (CHECK_PORT_TUNNELED(pSECPort) && !CHECK_PORT_BUFFER_SUPPLIER(pSECPort)))) {
    585         ret = OMX_ErrorIncorrectStateOperation;
    586         goto EXIT;
    587     }
    588 
    589     for (i = 0; i < pSECPort->portDefinition.nBufferCountActual; i++) {
    590         if (pBuffer == pSECPort->bufferHeader[i]) {
    591             findBuffer = OMX_TRUE;
    592             break;
    593         }
    594     }
    595 
    596     if (findBuffer == OMX_FALSE) {
    597         ret = OMX_ErrorBadParameter;
    598         goto EXIT;
    599     } else {
    600         ret = OMX_ErrorNone;
    601     }
    602 
    603     message = SEC_OSAL_Malloc(sizeof(SEC_OMX_MESSAGE));
    604     if (message == NULL) {
    605         ret = OMX_ErrorInsufficientResources;
    606         goto EXIT;
    607     }
    608     message->messageType = SEC_OMX_CommandEmptyBuffer;
    609     message->messageParam = (OMX_U32) i;
    610     message->pCmdData = (OMX_PTR)pBuffer;
    611 
    612     SEC_OSAL_Queue(&pSECPort->bufferQ, (void *)message);
    613     SEC_OSAL_SemaphorePost(pSECPort->bufferSemID);
    614 
    615 EXIT:
    616     FunctionOut();
    617 
    618     return ret;
    619 }
    620 
    621 OMX_ERRORTYPE SEC_OMX_FillThisBuffer(
    622     OMX_IN OMX_HANDLETYPE        hComponent,
    623     OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
    624 {
    625     OMX_ERRORTYPE           ret = OMX_ErrorNone;
    626     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    627     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    628     SEC_OMX_BASEPORT      *pSECPort = NULL;
    629     OMX_BOOL               findBuffer = OMX_FALSE;
    630     SEC_OMX_MESSAGE       *message;
    631     OMX_U32                i = 0;
    632 
    633     FunctionIn();
    634 
    635     if (hComponent == NULL) {
    636         ret = OMX_ErrorBadParameter;
    637         goto EXIT;
    638     }
    639     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    640     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    641     if (ret != OMX_ErrorNone) {
    642         goto EXIT;
    643     }
    644 
    645     if (pOMXComponent->pComponentPrivate == NULL) {
    646         ret = OMX_ErrorBadParameter;
    647         goto EXIT;
    648     }
    649     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    650     if (pSECComponent->currentState == OMX_StateInvalid) {
    651         ret = OMX_ErrorInvalidState;
    652         goto EXIT;
    653     }
    654 
    655     if (pBuffer == NULL) {
    656         ret = OMX_ErrorBadParameter;
    657         goto EXIT;
    658     }
    659     if (pBuffer->nOutputPortIndex != OUTPUT_PORT_INDEX) {
    660         ret = OMX_ErrorBadPortIndex;
    661         goto EXIT;
    662     }
    663 
    664     ret = SEC_OMX_Check_SizeVersion(pBuffer, sizeof(OMX_BUFFERHEADERTYPE));
    665     if (ret != OMX_ErrorNone) {
    666         goto EXIT;
    667     }
    668 
    669     if ((pSECComponent->currentState != OMX_StateIdle) &&
    670         (pSECComponent->currentState != OMX_StateExecuting) &&
    671         (pSECComponent->currentState != OMX_StatePause)) {
    672         ret = OMX_ErrorIncorrectStateOperation;
    673         goto EXIT;
    674     }
    675 
    676     pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX];
    677     if ((!CHECK_PORT_ENABLED(pSECPort)) ||
    678         ((CHECK_PORT_BEING_FLUSHED(pSECPort) || CHECK_PORT_BEING_DISABLED(pSECPort)) &&
    679         (!CHECK_PORT_TUNNELED(pSECPort) || !CHECK_PORT_BUFFER_SUPPLIER(pSECPort))) ||
    680         ((pSECComponent->transientState == SEC_OMX_TransStateExecutingToIdle) &&
    681         (CHECK_PORT_TUNNELED(pSECPort) && !CHECK_PORT_BUFFER_SUPPLIER(pSECPort)))) {
    682         ret = OMX_ErrorIncorrectStateOperation;
    683         goto EXIT;
    684     }
    685 
    686     for (i = 0; i < pSECPort->portDefinition.nBufferCountActual; i++) {
    687         if (pBuffer == pSECPort->bufferHeader[i]) {
    688             findBuffer = OMX_TRUE;
    689             break;
    690         }
    691     }
    692 
    693     if (findBuffer == OMX_FALSE) {
    694         ret = OMX_ErrorBadParameter;
    695         goto EXIT;
    696     } else {
    697         ret = OMX_ErrorNone;
    698     }
    699 
    700     message = SEC_OSAL_Malloc(sizeof(SEC_OMX_MESSAGE));
    701     if (message == NULL) {
    702         ret = OMX_ErrorInsufficientResources;
    703         goto EXIT;
    704     }
    705     message->messageType = SEC_OMX_CommandFillBuffer;
    706     message->messageParam = (OMX_U32) i;
    707     message->pCmdData = (OMX_PTR)pBuffer;
    708 
    709     SEC_OSAL_Queue(&pSECPort->bufferQ, (void *)message);
    710     SEC_OSAL_SemaphorePost(pSECPort->bufferSemID);
    711 
    712 EXIT:
    713     FunctionOut();
    714 
    715     return ret;
    716 }
    717 
    718 OMX_ERRORTYPE SEC_OMX_Port_Constructor(OMX_HANDLETYPE hComponent)
    719 {
    720     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    721     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    722     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    723     SEC_OMX_BASEPORT      *pSECPort = NULL;
    724     SEC_OMX_BASEPORT      *pSECInputPort = NULL;
    725     SEC_OMX_BASEPORT      *pSECOutputPort = NULL;
    726     int i = 0;
    727 
    728     FunctionIn();
    729 
    730     if (hComponent == NULL) {
    731         ret = OMX_ErrorBadParameter;
    732         SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__);
    733         goto EXIT;
    734     }
    735     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    736     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    737     if (ret != OMX_ErrorNone) {
    738         goto EXIT;
    739     }
    740 
    741     if (pOMXComponent->pComponentPrivate == NULL) {
    742         ret = OMX_ErrorBadParameter;
    743         SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__);
    744         goto EXIT;
    745     }
    746     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    747 
    748     INIT_SET_SIZE_VERSION(&pSECComponent->portParam, OMX_PORT_PARAM_TYPE);
    749     pSECComponent->portParam.nPorts = ALL_PORT_NUM;
    750     pSECComponent->portParam.nStartPortNumber = INPUT_PORT_INDEX;
    751 
    752     pSECPort = SEC_OSAL_Malloc(sizeof(SEC_OMX_BASEPORT) * ALL_PORT_NUM);
    753     if (pSECPort == NULL) {
    754         ret = OMX_ErrorInsufficientResources;
    755         SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
    756         goto EXIT;
    757     }
    758     SEC_OSAL_Memset(pSECPort, 0, sizeof(SEC_OMX_BASEPORT) * ALL_PORT_NUM);
    759     pSECComponent->pSECPort = pSECPort;
    760 
    761     /* Input Port */
    762     pSECInputPort = &pSECPort[INPUT_PORT_INDEX];
    763 
    764     SEC_OSAL_QueueCreate(&pSECInputPort->bufferQ);
    765 
    766     pSECInputPort->bufferHeader = SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM);
    767     if (pSECInputPort->bufferHeader == NULL) {
    768         SEC_OSAL_Free(pSECPort);
    769         pSECPort = NULL;
    770         ret = OMX_ErrorInsufficientResources;
    771         SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
    772         goto EXIT;
    773     }
    774     SEC_OSAL_Memset(pSECInputPort->bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM);
    775 
    776     pSECInputPort->bufferStateAllocate = SEC_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM);
    777     if (pSECInputPort->bufferStateAllocate == NULL) {
    778         SEC_OSAL_Free(pSECInputPort->bufferHeader);
    779         pSECInputPort->bufferHeader = NULL;
    780         SEC_OSAL_Free(pSECPort);
    781         pSECPort = NULL;
    782         ret = OMX_ErrorInsufficientResources;
    783         SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
    784         goto EXIT;
    785     }
    786     SEC_OSAL_Memset(pSECInputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM);
    787 
    788     pSECInputPort->bufferSemID = NULL;
    789     pSECInputPort->assignedBufferNum = 0;
    790     pSECInputPort->portState = OMX_StateMax;
    791     pSECInputPort->bIsPortFlushed = OMX_FALSE;
    792     pSECInputPort->bIsPortDisabled = OMX_FALSE;
    793     pSECInputPort->tunneledComponent = NULL;
    794     pSECInputPort->tunneledPort = 0;
    795     pSECInputPort->tunnelBufferNum = 0;
    796     pSECInputPort->bufferSupplier = OMX_BufferSupplyUnspecified;
    797     pSECInputPort->tunnelFlags = 0;
    798     pSECInputPort->eControlRate = OMX_Video_ControlRateDisable;
    799     ret = SEC_OSAL_SemaphoreCreate(&pSECInputPort->loadedResource);
    800     if (ret != OMX_ErrorNone) {
    801         SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
    802         pSECInputPort->bufferStateAllocate = NULL;
    803         SEC_OSAL_Free(pSECInputPort->bufferHeader);
    804         pSECInputPort->bufferHeader = NULL;
    805         SEC_OSAL_Free(pSECPort);
    806         pSECPort = NULL;
    807         goto EXIT;
    808     }
    809     ret = SEC_OSAL_SemaphoreCreate(&pSECInputPort->unloadedResource);
    810     if (ret != OMX_ErrorNone) {
    811         SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
    812         pSECInputPort->loadedResource = NULL;
    813         SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
    814         pSECInputPort->bufferStateAllocate = NULL;
    815         SEC_OSAL_Free(pSECInputPort->bufferHeader);
    816         pSECInputPort->bufferHeader = NULL;
    817         SEC_OSAL_Free(pSECPort);
    818         pSECPort = NULL;
    819         goto EXIT;
    820     }
    821 
    822     INIT_SET_SIZE_VERSION(&pSECInputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE);
    823     pSECInputPort->portDefinition.nPortIndex = INPUT_PORT_INDEX;
    824     pSECInputPort->portDefinition.eDir = OMX_DirInput;
    825     pSECInputPort->portDefinition.nBufferCountActual = 0;
    826     pSECInputPort->portDefinition.nBufferCountMin = 0;
    827     pSECInputPort->portDefinition.nBufferSize = 0;
    828     pSECInputPort->portDefinition.bEnabled = OMX_FALSE;
    829     pSECInputPort->portDefinition.bPopulated = OMX_FALSE;
    830     pSECInputPort->portDefinition.eDomain = OMX_PortDomainMax;
    831     pSECInputPort->portDefinition.bBuffersContiguous = OMX_FALSE;
    832     pSECInputPort->portDefinition.nBufferAlignment = 0;
    833     pSECInputPort->markType.hMarkTargetComponent = NULL;
    834     pSECInputPort->markType.pMarkData = NULL;
    835     pSECInputPort->bUseAndroidNativeBuffer = OMX_FALSE;
    836     pSECInputPort->bStoreMetaDataInBuffer = OMX_FALSE;
    837 
    838     /* Output Port */
    839     pSECOutputPort = &pSECPort[OUTPUT_PORT_INDEX];
    840 
    841     SEC_OSAL_QueueCreate(&pSECOutputPort->bufferQ);
    842 
    843     pSECOutputPort->bufferHeader = SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM);
    844     if (pSECOutputPort->bufferHeader == NULL) {
    845         SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource);
    846         pSECInputPort->unloadedResource = NULL;
    847         SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
    848         pSECInputPort->loadedResource = NULL;
    849         SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
    850         pSECInputPort->bufferStateAllocate = NULL;
    851         SEC_OSAL_Free(pSECInputPort->bufferHeader);
    852         pSECInputPort->bufferHeader = NULL;
    853         SEC_OSAL_Free(pSECPort);
    854         pSECPort = NULL;
    855         ret = OMX_ErrorInsufficientResources;
    856         goto EXIT;
    857     }
    858     SEC_OSAL_Memset(pSECOutputPort->bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM);
    859 
    860     pSECOutputPort->bufferStateAllocate = SEC_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM);
    861     if (pSECOutputPort->bufferStateAllocate == NULL) {
    862         SEC_OSAL_Free(pSECOutputPort->bufferHeader);
    863         pSECOutputPort->bufferHeader = NULL;
    864 
    865         SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource);
    866         pSECInputPort->unloadedResource = NULL;
    867         SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
    868         pSECInputPort->loadedResource = NULL;
    869         SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
    870         pSECInputPort->bufferStateAllocate = NULL;
    871         SEC_OSAL_Free(pSECInputPort->bufferHeader);
    872         pSECInputPort->bufferHeader = NULL;
    873         SEC_OSAL_Free(pSECPort);
    874         pSECPort = NULL;
    875         ret = OMX_ErrorInsufficientResources;
    876         goto EXIT;
    877     }
    878     SEC_OSAL_Memset(pSECOutputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM);
    879 
    880     pSECOutputPort->bufferSemID = NULL;
    881     pSECOutputPort->assignedBufferNum = 0;
    882     pSECOutputPort->portState = OMX_StateMax;
    883     pSECOutputPort->bIsPortFlushed = OMX_FALSE;
    884     pSECOutputPort->bIsPortDisabled = OMX_FALSE;
    885     pSECOutputPort->tunneledComponent = NULL;
    886     pSECOutputPort->tunneledPort = 0;
    887     pSECOutputPort->tunnelBufferNum = 0;
    888     pSECOutputPort->bufferSupplier = OMX_BufferSupplyUnspecified;
    889     pSECOutputPort->tunnelFlags = 0;
    890     pSECOutputPort->eControlRate = OMX_Video_ControlRateDisable;
    891     ret = SEC_OSAL_SemaphoreCreate(&pSECOutputPort->loadedResource);
    892     if (ret != OMX_ErrorNone) {
    893         SEC_OSAL_Free(pSECOutputPort->bufferStateAllocate);
    894         pSECOutputPort->bufferStateAllocate = NULL;
    895         SEC_OSAL_Free(pSECOutputPort->bufferHeader);
    896         pSECOutputPort->bufferHeader = NULL;
    897 
    898         SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource);
    899         pSECInputPort->unloadedResource = NULL;
    900         SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
    901         pSECInputPort->loadedResource = NULL;
    902         SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
    903         pSECInputPort->bufferStateAllocate = NULL;
    904         SEC_OSAL_Free(pSECInputPort->bufferHeader);
    905         pSECInputPort->bufferHeader = NULL;
    906         SEC_OSAL_Free(pSECPort);
    907         pSECPort = NULL;
    908         goto EXIT;
    909     }
    910     ret = SEC_OSAL_SemaphoreCreate(&pSECOutputPort->unloadedResource);
    911     if (ret != OMX_ErrorNone) {
    912         SEC_OSAL_SemaphoreTerminate(pSECOutputPort->loadedResource);
    913         pSECOutputPort->loadedResource = NULL;
    914         SEC_OSAL_Free(pSECOutputPort->bufferStateAllocate);
    915         pSECOutputPort->bufferStateAllocate = NULL;
    916         SEC_OSAL_Free(pSECOutputPort->bufferHeader);
    917         pSECOutputPort->bufferHeader = NULL;
    918 
    919         SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource);
    920         pSECInputPort->unloadedResource = NULL;
    921         SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
    922         pSECInputPort->loadedResource = NULL;
    923         SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
    924         pSECInputPort->bufferStateAllocate = NULL;
    925         SEC_OSAL_Free(pSECInputPort->bufferHeader);
    926         pSECInputPort->bufferHeader = NULL;
    927         SEC_OSAL_Free(pSECPort);
    928         pSECPort = NULL;
    929         goto EXIT;
    930     }
    931 
    932     INIT_SET_SIZE_VERSION(&pSECOutputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE);
    933     pSECOutputPort->portDefinition.nPortIndex = OUTPUT_PORT_INDEX;
    934     pSECOutputPort->portDefinition.eDir = OMX_DirOutput;
    935     pSECOutputPort->portDefinition.nBufferCountActual = 0;
    936     pSECOutputPort->portDefinition.nBufferCountMin = 0;
    937     pSECOutputPort->portDefinition.nBufferSize = 0;
    938     pSECOutputPort->portDefinition.bEnabled = OMX_FALSE;
    939     pSECOutputPort->portDefinition.bPopulated = OMX_FALSE;
    940     pSECOutputPort->portDefinition.eDomain = OMX_PortDomainMax;
    941     pSECOutputPort->portDefinition.bBuffersContiguous = OMX_FALSE;
    942     pSECOutputPort->portDefinition.nBufferAlignment = 0;
    943     pSECOutputPort->markType.hMarkTargetComponent = NULL;
    944     pSECOutputPort->markType.pMarkData = NULL;
    945     pSECOutputPort->bUseAndroidNativeBuffer = OMX_FALSE;
    946     pSECOutputPort->bStoreMetaDataInBuffer = OMX_FALSE;
    947 
    948     pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE;
    949     pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
    950     pSECComponent->checkTimeStamp.startTimeStamp = 0;
    951     pSECComponent->checkTimeStamp.nStartFlags = 0x0;
    952 
    953     pOMXComponent->EmptyThisBuffer = &SEC_OMX_EmptyThisBuffer;
    954     pOMXComponent->FillThisBuffer  = &SEC_OMX_FillThisBuffer;
    955 
    956     ret = OMX_ErrorNone;
    957 EXIT:
    958     FunctionOut();
    959 
    960     return ret;
    961 }
    962 
    963 OMX_ERRORTYPE SEC_OMX_Port_Destructor(OMX_HANDLETYPE hComponent)
    964 {
    965     OMX_ERRORTYPE          ret = OMX_ErrorNone;
    966     OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    967     SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    968     SEC_OMX_BASEPORT      *pSECPort = NULL;
    969 
    970     FunctionIn();
    971 
    972     int i = 0;
    973 
    974     if (hComponent == NULL) {
    975         ret = OMX_ErrorBadParameter;
    976         goto EXIT;
    977     }
    978     pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    979     ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    980     if (ret != OMX_ErrorNone) {
    981         goto EXIT;
    982     }
    983     if (pOMXComponent->pComponentPrivate == NULL) {
    984         ret = OMX_ErrorBadParameter;
    985         goto EXIT;
    986     }
    987     pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    988     for (i = 0; i < ALL_PORT_NUM; i++) {
    989         pSECPort = &pSECComponent->pSECPort[i];
    990 
    991         SEC_OSAL_SemaphoreTerminate(pSECPort->loadedResource);
    992         pSECPort->loadedResource = NULL;
    993         SEC_OSAL_SemaphoreTerminate(pSECPort->unloadedResource);
    994         pSECPort->unloadedResource = NULL;
    995         SEC_OSAL_Free(pSECPort->bufferStateAllocate);
    996         pSECPort->bufferStateAllocate = NULL;
    997         SEC_OSAL_Free(pSECPort->bufferHeader);
    998         pSECPort->bufferHeader = NULL;
    999 
   1000         SEC_OSAL_QueueTerminate(&pSECPort->bufferQ);
   1001     }
   1002     SEC_OSAL_Free(pSECComponent->pSECPort);
   1003     pSECComponent->pSECPort = NULL;
   1004     ret = OMX_ErrorNone;
   1005 EXIT:
   1006     FunctionOut();
   1007 
   1008     return ret;
   1009 }
   1010