static OMX_ERRORTYPE SEC_OMX_CommandQueue( SEC_OMX_BASECOMPONENT *pSECComponent, OMX_COMMANDTYPE Cmd, OMX_U32 nParam, OMX_PTR pCmdData) { OMX_ERRORTYPE ret = OMX_ErrorNone; SEC_OMX_MESSAGE *command = (SEC_OMX_MESSAGE *)SEC_OSAL_Malloc(sizeof(SEC_OMX_MESSAGE)); if (command == NULL) { ret = OMX_ErrorInsufficientResources; goto EXIT; } command->messageType = (OMX_U32)Cmd; command->messageParam = nParam; command->pCmdData = pCmdData; ret = SEC_OSAL_Queue(&pSECComponent->messageQ, (void *)command); if (ret != 0) { ret = OMX_ErrorUndefined; goto EXIT; } ret = SEC_OSAL_SemaphorePost(pSECComponent->msgSemaphoreHandle); EXIT: return ret; }
OMX_ERRORTYPE SEC_OMX_FillThisBuffer( OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_BUFFERHEADERTYPE *pBuffer) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_COMPONENTTYPE *pOMXComponent = NULL; SEC_OMX_BASECOMPONENT *pSECComponent = NULL; SEC_OMX_BASEPORT *pSECPort = NULL; OMX_BOOL findBuffer = OMX_FALSE; SEC_OMX_MESSAGE *message; OMX_U32 i = 0; FunctionIn(); if (hComponent == NULL) { ret = OMX_ErrorBadParameter; goto EXIT; } pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); if (ret != OMX_ErrorNone) { goto EXIT; } if (pOMXComponent->pComponentPrivate == NULL) { ret = OMX_ErrorBadParameter; goto EXIT; } pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; if (pSECComponent->currentState == OMX_StateInvalid) { ret = OMX_ErrorInvalidState; goto EXIT; } if (pBuffer == NULL) { ret = OMX_ErrorBadParameter; goto EXIT; } if (pBuffer->nOutputPortIndex != OUTPUT_PORT_INDEX) { ret = OMX_ErrorBadPortIndex; goto EXIT; } ret = SEC_OMX_Check_SizeVersion(pBuffer, sizeof(OMX_BUFFERHEADERTYPE)); if (ret != OMX_ErrorNone) { goto EXIT; } if ((pSECComponent->currentState != OMX_StateIdle) && (pSECComponent->currentState != OMX_StateExecuting) && (pSECComponent->currentState != OMX_StatePause)) { ret = OMX_ErrorIncorrectStateOperation; goto EXIT; } pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; if ((!CHECK_PORT_ENABLED(pSECPort)) || ((CHECK_PORT_BEING_FLUSHED(pSECPort) || CHECK_PORT_BEING_DISABLED(pSECPort)) && (!CHECK_PORT_TUNNELED(pSECPort) || !CHECK_PORT_BUFFER_SUPPLIER(pSECPort))) || ((pSECComponent->transientState == SEC_OMX_TransStateExecutingToIdle) && (CHECK_PORT_TUNNELED(pSECPort) && !CHECK_PORT_BUFFER_SUPPLIER(pSECPort)))) { ret = OMX_ErrorIncorrectStateOperation; goto EXIT; } for (i = 0; i < pSECPort->portDefinition.nBufferCountActual; i++) { if (pBuffer == pSECPort->bufferHeader[i]) { findBuffer = OMX_TRUE; break; } } if (findBuffer == OMX_FALSE) { ret = OMX_ErrorBadParameter; goto EXIT; } else { ret = OMX_ErrorNone; } message = SEC_OSAL_Malloc(sizeof(SEC_OMX_MESSAGE)); if (message == NULL) { ret = OMX_ErrorInsufficientResources; goto EXIT; } message->messageType = SEC_OMX_CommandFillBuffer; message->messageParam = (OMX_U32) i; message->pCmdData = (OMX_PTR)pBuffer; SEC_OSAL_Queue(&pSECPort->bufferQ, (void *)message); SEC_OSAL_SemaphorePost(pSECPort->bufferSemID); EXIT: FunctionOut(); return ret; }
OMX_ERRORTYPE SEC_OMX_FlushPort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex) { OMX_ERRORTYPE ret = OMX_ErrorNone; SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; SEC_OMX_BASEPORT *pSECPort = NULL; OMX_BUFFERHEADERTYPE *bufferHeader = NULL; SEC_OMX_MESSAGE *message = NULL; OMX_U32 flushNum = 0; OMX_S32 semValue = 0; FunctionIn(); pSECPort = &pSECComponent->pSECPort[portIndex]; while (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) > 0) { SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[portIndex].bufferSemID, &semValue); if (semValue == 0) SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[portIndex].bufferSemID); SEC_OSAL_SemaphoreWait(pSECComponent->pSECPort[portIndex].bufferSemID); message = (SEC_OMX_MESSAGE *)SEC_OSAL_Dequeue(&pSECPort->bufferQ); if (message != NULL) { bufferHeader = (OMX_BUFFERHEADERTYPE *)message->pCmdData; bufferHeader->nFilledLen = 0; if (CHECK_PORT_TUNNELED(pSECPort) && !CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { if (portIndex) { OMX_EmptyThisBuffer(pSECPort->tunneledComponent, bufferHeader); } else { OMX_FillThisBuffer(pSECPort->tunneledComponent, bufferHeader); } SEC_OSAL_Free(message); message = NULL; } else if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { SEC_OSAL_Log(SEC_LOG_ERROR, "Tunneled mode is not working, Line:%d", __LINE__); ret = OMX_ErrorNotImplemented; SEC_OSAL_Queue(&pSECPort->bufferQ, pSECPort); goto EXIT; } else { if (portIndex == OUTPUT_PORT_INDEX) { pSECComponent->pCallbacks->FillBufferDone(pOMXComponent, pSECComponent->callbackData, bufferHeader); } else { pSECComponent->pCallbacks->EmptyBufferDone(pOMXComponent, pSECComponent->callbackData, bufferHeader); } SEC_OSAL_Free(message); message = NULL; } } } if (pSECComponent->secDataBuffer[portIndex].dataValid == OMX_TRUE) { if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { message = SEC_OSAL_Malloc(sizeof(SEC_OMX_MESSAGE)); message->pCmdData = pSECComponent->secDataBuffer[portIndex].bufferHeader; message->messageType = 0; message->messageParam = -1; SEC_OSAL_Queue(&pSECPort->bufferQ, message); pSECComponent->sec_BufferReset(pOMXComponent, portIndex); } else { if (portIndex == INPUT_PORT_INDEX) pSECComponent->sec_InputBufferReturn(pOMXComponent); else if (portIndex == OUTPUT_PORT_INDEX) pSECComponent->sec_OutputBufferReturn(pOMXComponent); } } if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { while (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) < pSECPort->assignedBufferNum) { SEC_OSAL_SemaphoreWait(pSECComponent->pSECPort[portIndex].bufferSemID); } if (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) != pSECPort->assignedBufferNum) SEC_OSAL_SetElemNum(&pSECPort->bufferQ, pSECPort->assignedBufferNum); } else { while(1) { int cnt; SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[portIndex].bufferSemID, &cnt); if (cnt == 0) break; SEC_OSAL_SemaphoreWait(pSECComponent->pSECPort[portIndex].bufferSemID); } SEC_OSAL_SetElemNum(&pSECPort->bufferQ, 0); } pSECComponent->processData[portIndex].dataLen = 0; pSECComponent->processData[portIndex].nFlags = 0; pSECComponent->processData[portIndex].remainDataLen = 0; pSECComponent->processData[portIndex].timeStamp = 0; pSECComponent->processData[portIndex].usedDataLen = 0; EXIT: FunctionOut(); return ret; }