/* MFC Init */ OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_Init(OMX_COMPONENTTYPE *pOMXComponent) { OMX_ERRORTYPE ret = OMX_ErrorNone; SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; SEC_OMX_BASEPORT *pSECPort = NULL; SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; OMX_HANDLETYPE hMFCHandle = NULL; OMX_S32 returnCodec = 0; FunctionIn(); pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; pMpeg4Enc->hMFCMpeg4Handle.bConfiguredMFC = OMX_FALSE; pSECComponent->bUseFlagEOF = OMX_FALSE; pSECComponent->bSaveFlagEOS = OMX_FALSE; /* MFC(Multi Format Codec) encoder and CMM(Codec Memory Management) driver open */ hMFCHandle = SsbSipMfcEncOpen(); if (hMFCHandle == NULL) { ret = OMX_ErrorInsufficientResources; goto EXIT; } pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle = hMFCHandle; /* set MFC ENC VIDEO PARAM and initialize MFC encoder instance */ if (pMpeg4Enc->hMFCMpeg4Handle.codecType == CODEC_TYPE_MPEG4) { Set_Mpeg4Enc_Param(&(pMpeg4Enc->hMFCMpeg4Handle.mpeg4MFCParam), pSECComponent); returnCodec = SsbSipMfcEncInit(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.mpeg4MFCParam)); } else { Set_H263Enc_Param(&(pMpeg4Enc->hMFCMpeg4Handle.h263MFCParam), pSECComponent); returnCodec = SsbSipMfcEncInit(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.h263MFCParam)); } if (returnCodec != MFC_RET_OK) { ret = OMX_ErrorInsufficientResources; goto EXIT; } /* allocate encoder's input buffer */ returnCodec = SsbSipMfcEncGetInBuf(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.inputInfo)); if (returnCodec != MFC_RET_OK) { ret = OMX_ErrorInsufficientResources; goto EXIT; } pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YPhyAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YPhyAddr; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CPhyAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CPhyAddr; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YVirAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YVirAddr; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CVirAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CVirAddr; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YSize = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YSize; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CSize = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CSize; SEC_OSAL_Memset(pSECComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); SEC_OSAL_Memset(pSECComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp = 0; EXIT: FunctionOut(); return ret; }
/* MFC Init */ OMX_ERRORTYPE SEC_MFC_H264Enc_Init(OMX_COMPONENTTYPE *pOMXComponent) { OMX_ERRORTYPE ret = OMX_ErrorNone; SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; SEC_H264ENC_HANDLE *pH264Enc = NULL; OMX_PTR hMFCHandle = NULL; OMX_S32 returnCodec = 0; FunctionIn(); pH264Enc = (SEC_H264ENC_HANDLE *)pSECComponent->hCodecHandle; pH264Enc->hMFCH264Handle.bConfiguredMFC = OMX_FALSE; pSECComponent->bUseFlagEOF = OMX_FALSE; pSECComponent->bSaveFlagEOS = OMX_FALSE; /* MFC(Multi Function Codec) encoder and CMM(Codec Memory Management) driver open */ hMFCHandle = (OMX_PTR)SsbSipMfcEncOpen(); if (hMFCHandle == NULL) { ret = OMX_ErrorInsufficientResources; goto EXIT; } pH264Enc->hMFCH264Handle.hMFCHandle = hMFCHandle; Set_H264ENC_Param(&(pH264Enc->hMFCH264Handle.mfcVideoAvc), pSECComponent); returnCodec = SsbSipMfcEncInit(hMFCHandle, &(pH264Enc->hMFCH264Handle.mfcVideoAvc)); if (returnCodec != MFC_RET_OK) { ret = OMX_ErrorInsufficientResources; goto EXIT; } /* Allocate encoder's input buffer */ returnCodec = SsbSipMfcEncGetInBuf(hMFCHandle, &(pH264Enc->hMFCH264Handle.inputInfo)); if (returnCodec != MFC_RET_OK) { ret = OMX_ErrorInsufficientResources; goto EXIT; } SEC_OSAL_Log(SEC_LOG_TRACE, "pH264Enc->hMFCH264Handle.inputInfo.YVirAddr : 0x%x", pH264Enc->hMFCH264Handle.inputInfo.YVirAddr); SEC_OSAL_Log(SEC_LOG_TRACE, "pH264Enc->hMFCH264Handle.inputInfo.CVirAddr : 0x%x", pH264Enc->hMFCH264Handle.inputInfo.CVirAddr); pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YPhyAddr = pH264Enc->hMFCH264Handle.inputInfo.YPhyAddr; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CPhyAddr = pH264Enc->hMFCH264Handle.inputInfo.CPhyAddr; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YVirAddr = pH264Enc->hMFCH264Handle.inputInfo.YVirAddr; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CVirAddr = pH264Enc->hMFCH264Handle.inputInfo.CVirAddr; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YSize = pH264Enc->hMFCH264Handle.inputInfo.YSize; pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CSize = pH264Enc->hMFCH264Handle.inputInfo.CSize; SEC_OSAL_Memset(pSECComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); SEC_OSAL_Memset(pSECComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); pH264Enc->hMFCH264Handle.indexTimestamp = 0; EXIT: FunctionOut(); return ret; }
OMX_ERRORTYPE SEC_OSAL_SignalCreate(OMX_HANDLETYPE *eventHandle) { SEC_OSAL_THREADEVENT *event; OMX_ERRORTYPE ret = OMX_ErrorNone; event = (SEC_OSAL_THREADEVENT *)SEC_OSAL_Malloc(sizeof(SEC_OSAL_THREADEVENT)); if (!event) { ret = OMX_ErrorInsufficientResources; goto EXIT; } SEC_OSAL_Memset(event, 0, sizeof(SEC_OSAL_THREADEVENT)); event->signal = OMX_FALSE; ret = SEC_OSAL_MutexCreate(&event->mutex); if (ret != OMX_ErrorNone) { SEC_OSAL_Free(event); goto EXIT; } if (pthread_cond_init(&event->condition, NULL)) { SEC_OSAL_MutexTerminate(event->mutex); SEC_OSAL_Free(event); ret = OMX_ErrorUndefined; goto EXIT; } *eventHandle = (OMX_HANDLETYPE)event; ret = OMX_ErrorNone; EXIT: return ret; }
OMX_ERRORTYPE SEC_OMX_BaseComponent_Constructor( OMX_IN OMX_HANDLETYPE hComponent) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_COMPONENTTYPE *pOMXComponent; SEC_OMX_BASECOMPONENT *pSECComponent = NULL; FunctionIn(); if (hComponent == NULL) { ret = OMX_ErrorBadParameter; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); goto EXIT; } pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; pSECComponent = SEC_OSAL_Malloc(sizeof(SEC_OMX_BASECOMPONENT)); if (pSECComponent == NULL) { ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); goto EXIT; } SEC_OSAL_Memset(pSECComponent, 0, sizeof(SEC_OMX_BASECOMPONENT)); pOMXComponent->pComponentPrivate = (OMX_PTR)pSECComponent; ret = SEC_OSAL_SemaphoreCreate(&pSECComponent->msgSemaphoreHandle); if (ret != OMX_ErrorNone) { ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); goto EXIT; } ret = SEC_OSAL_MutexCreate(&pSECComponent->compMutex); if (ret != OMX_ErrorNone) { ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); goto EXIT; } pSECComponent->bExitMessageHandlerThread = OMX_FALSE; SEC_OSAL_QueueCreate(&pSECComponent->messageQ); ret = SEC_OSAL_ThreadCreate(&pSECComponent->hMessageHandler, SEC_OMX_MessageHandlerThread, pOMXComponent); if (ret != OMX_ErrorNone) { ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); goto EXIT; } pOMXComponent->GetComponentVersion = &SEC_OMX_GetComponentVersion; pOMXComponent->SendCommand = &SEC_OMX_SendCommand; pOMXComponent->GetConfig = &SEC_OMX_GetConfig; pOMXComponent->GetExtensionIndex = &SEC_OMX_GetExtensionIndex; pOMXComponent->GetState = &SEC_OMX_GetState; pOMXComponent->SetCallbacks = &SEC_OMX_SetCallbacks; pOMXComponent->UseEGLImage = &SEC_OMX_UseEGLImage; EXIT: FunctionOut(); return ret; }
OMX_ERRORTYPE SEC_OSAL_QueueCreate(SEC_QUEUE *queueHandle) { int i = 0; SEC_QElem *newqelem = NULL; SEC_QElem *currentqelem = NULL; SEC_QUEUE *queue = (SEC_QUEUE *)queueHandle; OMX_ERRORTYPE ret = OMX_ErrorNone; if (!queue) return OMX_ErrorBadParameter; ret = SEC_OSAL_MutexCreate(&queue->qMutex); if (ret != OMX_ErrorNone) return ret; queue->first = (SEC_QElem *)SEC_OSAL_Malloc(sizeof(SEC_QElem)); if (queue->first == NULL) return OMX_ErrorInsufficientResources; SEC_OSAL_Memset(queue->first, 0, sizeof(SEC_QElem)); currentqelem = queue->last = queue->first; queue->numElem = 0; for (i = 0; i < (MAX_QUEUE_ELEMENTS - 2); i++) { newqelem = (SEC_QElem *)SEC_OSAL_Malloc(sizeof(SEC_QElem)); if (newqelem == NULL) { while (queue->first != NULL) { currentqelem = queue->first->qNext; SEC_OSAL_Free((OMX_PTR)queue->first); queue->first = currentqelem; } return OMX_ErrorInsufficientResources; } else { SEC_OSAL_Memset(newqelem, 0, sizeof(SEC_QElem)); currentqelem->qNext = newqelem; currentqelem = newqelem; } } currentqelem->qNext = queue->first; return OMX_ErrorNone; }
OMX_ERRORTYPE SEC_OMX_Component_Unregister(SEC_OMX_COMPONENT_REGLIST *componentList) { OMX_ERRORTYPE ret = OMX_ErrorNone; SEC_OSAL_Memset(componentList, 0, sizeof(SEC_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM); SEC_OSAL_Free(componentList); EXIT: return ret; }
OSCL_EXPORT_REF OMX_ERRORTYPE SEC_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_COMPONENTTYPE *pOMXComponent = NULL; SEC_OMX_BASECOMPONENT *pSECComponent = NULL; SEC_OMX_BASEPORT *pSECPort = NULL; SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; OMX_S32 codecType = -1; int i = 0; FunctionIn(); if ((hComponent == NULL) || (componentName == NULL)) { ret = OMX_ErrorBadParameter; SEC_OSAL_Log(SEC_LOG_ERROR, "%s: parameters are null, ret: %X", __FUNCTION__, ret); goto EXIT; } if (SEC_OSAL_Strcmp(SEC_OMX_COMPOMENT_MPEG4_ENC, componentName) == 0) { codecType = CODEC_TYPE_MPEG4; } else if (SEC_OSAL_Strcmp(SEC_OMX_COMPOMENT_H263_ENC, componentName) == 0) { codecType = CODEC_TYPE_H263; } else { ret = OMX_ErrorBadParameter; SEC_OSAL_Log(SEC_LOG_ERROR, "%s: componentName(%s) error, ret: %X", __FUNCTION__, componentName, ret); goto EXIT; } pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; ret = SEC_OMX_VideoEncodeComponentInit(pOMXComponent); if (ret != OMX_ErrorNone) { SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SEC_OMX_VideoDecodeComponentInit error, ret: %X", __FUNCTION__, ret); goto EXIT; } pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; pSECComponent->codecType = HW_VIDEO_CODEC; pSECComponent->componentName = (OMX_STRING)SEC_OSAL_Malloc(MAX_OMX_COMPONENT_NAME_SIZE); if (pSECComponent->componentName == NULL) { SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "%s: componentName alloc error, ret: %X", __FUNCTION__, ret); goto EXIT; } SEC_OSAL_Memset(pSECComponent->componentName, 0, MAX_OMX_COMPONENT_NAME_SIZE); pMpeg4Enc = SEC_OSAL_Malloc(sizeof(SEC_MPEG4ENC_HANDLE)); if (pMpeg4Enc == NULL) { SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SEC_MPEG4ENC_HANDLE alloc error, ret: %X", __FUNCTION__, ret); goto EXIT; } SEC_OSAL_Memset(pMpeg4Enc, 0, sizeof(SEC_MPEG4ENC_HANDLE)); pSECComponent->hCodecHandle = (OMX_HANDLETYPE)pMpeg4Enc; pMpeg4Enc->hMFCMpeg4Handle.codecType = codecType; if (codecType == CODEC_TYPE_MPEG4) SEC_OSAL_Strcpy(pSECComponent->componentName, SEC_OMX_COMPOMENT_MPEG4_ENC); else SEC_OSAL_Strcpy(pSECComponent->componentName, SEC_OMX_COMPOMENT_H263_ENC); /* Set componentVersion */ pSECComponent->componentVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; pSECComponent->componentVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; pSECComponent->componentVersion.s.nRevision = REVISION_NUMBER; pSECComponent->componentVersion.s.nStep = STEP_NUMBER; /* Set specVersion */ pSECComponent->specVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; pSECComponent->specVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; pSECComponent->specVersion.s.nRevision = REVISION_NUMBER; pSECComponent->specVersion.s.nStep = STEP_NUMBER; /* Android CapabilityFlags */ pSECComponent->capabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; pSECComponent->capabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE; pSECComponent->capabilityFlags.iOMXComponentUsesNALStartCodes = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentUsesFullAVCFrames = OMX_TRUE; /* Input port */ pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; pSECPort->portDefinition.format.video.nBitrate = 64000; pSECPort->portDefinition.format.video.xFramerate= (15 << 16); pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; pSECPort->portDefinition.format.video.pNativeRender = 0; pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "raw/video"); pSECPort->portDefinition.format.video.eColorFormat = SEC_OMX_COLOR_FormatNV12PhysicalAddress;//OMX_COLOR_FormatYUV420SemiPlanar; pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_INPUT_BUFFER_SIZE; pSECPort->portDefinition.bEnabled = OMX_TRUE; /* Output port */ pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; pSECPort->portDefinition.format.video.nBitrate = 64000; pSECPort->portDefinition.format.video.xFramerate= (15 << 16); if (codecType == CODEC_TYPE_MPEG4) { pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "video/mpeg4"); } else { pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "video/h263"); } pSECPort->portDefinition.format.video.pNativeRender = 0; pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused; pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE; pSECPort->portDefinition.bEnabled = OMX_TRUE; if (codecType == CODEC_TYPE_MPEG4) { for(i = 0; i < ALL_PORT_NUM; i++) { INIT_SET_SIZE_VERSION(&pMpeg4Enc->mpeg4Component[i], OMX_VIDEO_PARAM_MPEG4TYPE); pMpeg4Enc->mpeg4Component[i].nPortIndex = i; pMpeg4Enc->mpeg4Component[i].eProfile = OMX_VIDEO_MPEG4ProfileSimple; pMpeg4Enc->mpeg4Component[i].eLevel = OMX_VIDEO_MPEG4Level4; pMpeg4Enc->mpeg4Component[i].nPFrames = 10; pMpeg4Enc->mpeg4Component[i].nBFrames = 0; /* No support for B frames */ pMpeg4Enc->mpeg4Component[i].nMaxPacketSize = 256; /* Default value */ pMpeg4Enc->mpeg4Component[i].nAllowedPictureTypes = OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP; pMpeg4Enc->mpeg4Component[i].bGov = OMX_FALSE; } } else { for(i = 0; i < ALL_PORT_NUM; i++) { INIT_SET_SIZE_VERSION(&pMpeg4Enc->h263Component[i], OMX_VIDEO_PARAM_H263TYPE); pMpeg4Enc->h263Component[i].nPortIndex = i; pMpeg4Enc->h263Component[i].eProfile = OMX_VIDEO_H263ProfileBaseline; pMpeg4Enc->h263Component[i].eLevel = OMX_VIDEO_H263Level45; pMpeg4Enc->h263Component[i].nPFrames = 20; pMpeg4Enc->h263Component[i].nBFrames = 0; /* No support for B frames */ pMpeg4Enc->h263Component[i].bPLUSPTYPEAllowed = OMX_FALSE; pMpeg4Enc->h263Component[i].nAllowedPictureTypes = OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP; pMpeg4Enc->h263Component[i].bForceRoundingTypeToZero = OMX_TRUE; pMpeg4Enc->h263Component[i].nPictureHeaderRepetition = 0; pMpeg4Enc->h263Component[i].nGOBHeaderInterval = 0; } } pOMXComponent->GetParameter = &SEC_MFC_Mpeg4Enc_GetParameter; pOMXComponent->SetParameter = &SEC_MFC_Mpeg4Enc_SetParameter; pOMXComponent->SetConfig = &SEC_MFC_Mpeg4Enc_SetConfig; pOMXComponent->ComponentRoleEnum = &SEC_MFC_Mpeg4Enc_ComponentRoleEnum; pOMXComponent->ComponentDeInit = &SEC_OMX_ComponentDeinit; pSECComponent->sec_mfc_componentInit = &SEC_MFC_Mpeg4Enc_Init; pSECComponent->sec_mfc_componentTerminate = &SEC_MFC_Mpeg4Enc_Terminate; pSECComponent->sec_mfc_bufferProcess = &SEC_MFC_Mpeg4Enc_bufferProcess; pSECComponent->sec_checkInputFrame = NULL; pSECComponent->currentState = OMX_StateLoaded; ret = OMX_ErrorNone; EXIT: FunctionOut(); return ret; }
OSCL_EXPORT_REF OMX_ERRORTYPE SEC_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_COMPONENTTYPE *pOMXComponent = NULL; SEC_OMX_BASECOMPONENT *pSECComponent = NULL; SEC_OMX_BASEPORT *pSECPort = NULL; SEC_H264ENC_HANDLE *pH264Enc = NULL; int i = 0; FunctionIn(); if ((hComponent == NULL) || (componentName == NULL)) { ret = OMX_ErrorBadParameter; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); goto EXIT; } if (SEC_OSAL_Strcmp(SEC_OMX_COMPOMENT_H264_ENC, componentName) != 0) { ret = OMX_ErrorBadParameter; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, componentName:%s, Line:%d", componentName, __LINE__); goto EXIT; } pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; ret = SEC_OMX_VideoEncodeComponentInit(pOMXComponent); if (ret != OMX_ErrorNone) { SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_Error, Line:%d", __LINE__); goto EXIT; } pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; pSECComponent->codecType = HW_VIDEO_CODEC; pSECComponent->componentName = (OMX_STRING)SEC_OSAL_Malloc(MAX_OMX_COMPONENT_NAME_SIZE); if (pSECComponent->componentName == NULL) { SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); goto EXIT; } SEC_OSAL_Memset(pSECComponent->componentName, 0, MAX_OMX_COMPONENT_NAME_SIZE); pH264Enc = SEC_OSAL_Malloc(sizeof(SEC_H264ENC_HANDLE)); if (pH264Enc == NULL) { SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); goto EXIT; } SEC_OSAL_Memset(pH264Enc, 0, sizeof(SEC_H264ENC_HANDLE)); pSECComponent->hCodecHandle = (OMX_HANDLETYPE)pH264Enc; SEC_OSAL_Strcpy(pSECComponent->componentName, SEC_OMX_COMPOMENT_H264_ENC); /* Set componentVersion */ pSECComponent->componentVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; pSECComponent->componentVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; pSECComponent->componentVersion.s.nRevision = REVISION_NUMBER; pSECComponent->componentVersion.s.nStep = STEP_NUMBER; /* Set specVersion */ pSECComponent->specVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; pSECComponent->specVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; pSECComponent->specVersion.s.nRevision = REVISION_NUMBER; pSECComponent->specVersion.s.nStep = STEP_NUMBER; /* Android CapabilityFlags */ pSECComponent->capabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; pSECComponent->capabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE; pSECComponent->capabilityFlags.iOMXComponentUsesNALStartCodes = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE; pSECComponent->capabilityFlags.iOMXComponentUsesFullAVCFrames = OMX_TRUE; /* Input port */ pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; pSECPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/ pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_INPUT_BUFFER_SIZE; pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "raw/video"); pSECPort->portDefinition.format.video.eColorFormat = SEC_OMX_COLOR_FormatNV12PhysicalAddress; pSECPort->portDefinition.bEnabled = OMX_TRUE; /* Output port */ pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; pSECPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/ pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE; pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "video/avc"); pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused; pSECPort->portDefinition.bEnabled = OMX_TRUE; for(i = 0; i < ALL_PORT_NUM; i++) { INIT_SET_SIZE_VERSION(&pH264Enc->AVCComponent[i], OMX_VIDEO_PARAM_AVCTYPE); pH264Enc->AVCComponent[i].nPortIndex = i; pH264Enc->AVCComponent[i].eProfile = OMX_VIDEO_AVCProfileBaseline; pH264Enc->AVCComponent[i].eLevel = OMX_VIDEO_AVCLevel31; } pOMXComponent->GetParameter = &SEC_MFC_H264Enc_GetParameter; pOMXComponent->SetParameter = &SEC_MFC_H264Enc_SetParameter; pOMXComponent->SetConfig = &SEC_MFC_H264Enc_SetConfig; pOMXComponent->ComponentRoleEnum = &SEC_MFC_H264Enc_ComponentRoleEnum; pOMXComponent->ComponentDeInit = &SEC_OMX_ComponentDeinit; pSECComponent->sec_mfc_componentInit = &SEC_MFC_H264Enc_Init; pSECComponent->sec_mfc_componentTerminate = &SEC_MFC_H264Enc_Terminate; pSECComponent->sec_mfc_bufferProcess = &SEC_MFC_H264Enc_bufferProcess; pSECComponent->sec_checkInputFrame = NULL; pSECComponent->currentState = OMX_StateLoaded; ret = OMX_ErrorNone; EXIT: FunctionOut(); return ret; }
OMX_ERRORTYPE SEC_OMX_Component_Register(SEC_OMX_COMPONENT_REGLIST **compList, OMX_U32 *compNum) { OMX_ERRORTYPE ret = OMX_ErrorNone; int componentNum = 0, roleNum = 0, totalCompNum = 0; int read; char *libName; size_t len; const char *errorMsg; DIR *dir; struct dirent *d; int (*SEC_OMX_COMPONENT_Library_Register)(SECRegisterComponentType **secComponents); SECRegisterComponentType **secComponentsTemp; SEC_OMX_COMPONENT_REGLIST *componentList; FunctionIn(); dir = opendir(SEC_OMX_INSTALL_PATH); if (dir == NULL) { ret = OMX_ErrorUndefined; goto EXIT; } componentList = (SEC_OMX_COMPONENT_REGLIST *)SEC_OSAL_Malloc(sizeof(SEC_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM); SEC_OSAL_Memset(componentList, 0, sizeof(SEC_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM); libName = SEC_OSAL_Malloc(MAX_OMX_COMPONENT_LIBNAME_SIZE); while ((d = readdir(dir)) != NULL) { OMX_HANDLETYPE soHandle; SEC_OSAL_Log(SEC_LOG_ERROR, "%s", d->d_name); if (SEC_OSAL_Strncmp(d->d_name, "libOMX.SEC.", SEC_OSAL_Strlen("libOMX.SEC.")) == 0) { SEC_OSAL_Memset(libName, 0, MAX_OMX_COMPONENT_LIBNAME_SIZE); SEC_OSAL_Strcpy(libName, SEC_OMX_INSTALL_PATH); SEC_OSAL_Strcat(libName, d->d_name); SEC_OSAL_Log(SEC_LOG_ERROR, "Path & libName : %s", libName); if ((soHandle = SEC_OSAL_dlopen(libName, RTLD_NOW)) != NULL) { SEC_OSAL_dlerror(); /* clear error*/ if ((SEC_OMX_COMPONENT_Library_Register = SEC_OSAL_dlsym(soHandle, "SEC_OMX_COMPONENT_Library_Register")) != NULL) { int i = 0; unsigned int j = 0; componentNum = (*SEC_OMX_COMPONENT_Library_Register)(NULL); secComponentsTemp = (SECRegisterComponentType **)SEC_OSAL_Malloc(sizeof(SECRegisterComponentType*) * componentNum); for (i = 0; i < componentNum; i++) { secComponentsTemp[i] = SEC_OSAL_Malloc(sizeof(SECRegisterComponentType)); SEC_OSAL_Memset(secComponentsTemp[i], 0, sizeof(SECRegisterComponentType)); } (*SEC_OMX_COMPONENT_Library_Register)(secComponentsTemp); for (i = 0; i < componentNum; i++) { SEC_OSAL_Strcpy(componentList[totalCompNum].component.componentName, secComponentsTemp[i]->componentName); for (j = 0; j < secComponentsTemp[i]->totalRoleNum; j++) SEC_OSAL_Strcpy(componentList[totalCompNum].component.roles[j], secComponentsTemp[i]->roles[j]); componentList[totalCompNum].component.totalRoleNum = secComponentsTemp[i]->totalRoleNum; SEC_OSAL_Strcpy(componentList[totalCompNum].libName, libName); totalCompNum++; } for (i = 0; i < componentNum; i++) { SEC_OSAL_Free(secComponentsTemp[i]); } SEC_OSAL_Free(secComponentsTemp); } else { if ((errorMsg = SEC_OSAL_dlerror()) != NULL) SEC_OSAL_Log(SEC_LOG_WARNING, "dlsym failed: %s", errorMsg); } SEC_OSAL_dlclose(soHandle); } else { SEC_OSAL_Log(SEC_LOG_WARNING, "dlopen failed: %s", SEC_OSAL_dlerror()); } } else { /* not a component name line. skip */ continue; } } SEC_OSAL_Free(libName); closedir(dir); *compList = componentList; *compNum = totalCompNum; EXIT: FunctionOut(); return ret; }
OMX_ERRORTYPE SEC_OMX_Component_Register(SEC_OMX_COMPONENT_REGLIST **compList, OMX_U32 *compNum) { OMX_ERRORTYPE ret = OMX_ErrorNone; int componentNum = 0, roleNum = 0, totalCompNum = 0; int read; char *omxregistryfile = NULL; char *line = NULL; char *libName; FILE *omxregistryfp; size_t len; OMX_HANDLETYPE soHandle; const char *errorMsg; int (*SEC_OMX_COMPONENT_Library_Register)(SECRegisterComponentType **secComponents); SECRegisterComponentType **secComponentsTemp; SEC_OMX_COMPONENT_REGLIST *componentList; FunctionIn(); omxregistryfile = SEC_OSAL_Malloc(strlen("/system/etc/") + strlen(REGISTRY_FILENAME) + 2); SEC_OSAL_Strcpy(omxregistryfile, "/system/etc/"); SEC_OSAL_Strcat(omxregistryfile, REGISTRY_FILENAME); omxregistryfp = fopen(omxregistryfile, "r"); if (omxregistryfp == NULL) { ret = OMX_ErrorUndefined; goto EXIT; } SEC_OSAL_Free(omxregistryfile); fseek(omxregistryfp, 0, 0); componentList = (SEC_OMX_COMPONENT_REGLIST *)SEC_OSAL_Malloc(sizeof(SEC_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM); SEC_OSAL_Memset(componentList, 0, sizeof(SEC_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM); libName = SEC_OSAL_Malloc(MAX_OMX_COMPONENT_LIBNAME_SIZE); while ((read = getline(&line, &len, omxregistryfp)) != -1) { if ((*line == 'l') && (*(line + 1) == 'i') && (*(line + 2) == 'b') && (*(line + 3) == 'O') && (*(line + 4) == 'M') && (*(line + 5) == 'X')) { SEC_OSAL_Memset(libName, 0, MAX_OMX_COMPONENT_LIBNAME_SIZE); SEC_OSAL_Strncpy(libName, line, SEC_OSAL_Strlen(line)-1); SEC_OSAL_Log(SEC_LOG_TRACE, "libName : %s", libName); if ((soHandle = SEC_OSAL_dlopen(libName, RTLD_NOW)) != NULL) { SEC_OSAL_dlerror(); /* clear error*/ if ((SEC_OMX_COMPONENT_Library_Register = SEC_OSAL_dlsym(soHandle, "SEC_OMX_COMPONENT_Library_Register")) != NULL) { int i = 0, j = 0; componentNum = (*SEC_OMX_COMPONENT_Library_Register)(NULL); secComponentsTemp = (SECRegisterComponentType **)SEC_OSAL_Malloc(sizeof(SECRegisterComponentType*) * componentNum); for (i = 0; i < componentNum; i++) { secComponentsTemp[i] = SEC_OSAL_Malloc(sizeof(SECRegisterComponentType)); SEC_OSAL_Memset(secComponentsTemp[i], 0, sizeof(SECRegisterComponentType)); } (*SEC_OMX_COMPONENT_Library_Register)(secComponentsTemp); for (i = 0; i < componentNum; i++) { SEC_OSAL_Strcpy(componentList[totalCompNum].component.componentName, secComponentsTemp[i]->componentName); for (j = 0; j < secComponentsTemp[i]->totalRoleNum; j++) SEC_OSAL_Strcpy(componentList[totalCompNum].component.roles[j], secComponentsTemp[i]->roles[j]); componentList[totalCompNum].component.totalRoleNum = secComponentsTemp[i]->totalRoleNum; SEC_OSAL_Strcpy(componentList[totalCompNum].libName, libName); totalCompNum++; } for (i = 0; i < componentNum; i++) { SEC_OSAL_Free(secComponentsTemp[i]); } SEC_OSAL_Free(secComponentsTemp); } else { if ((errorMsg = SEC_OSAL_dlerror()) != NULL) SEC_OSAL_Log(SEC_LOG_WARNING, "dlsym failed: %s", errorMsg); } SEC_OSAL_dlclose(soHandle); } else { SEC_OSAL_Log(SEC_LOG_WARNING, "dlopen failed: %s", SEC_OSAL_dlerror()); } } else { /* not a component name line. skip */ continue; } } SEC_OSAL_Free(libName); fclose(omxregistryfp); *compList = componentList; *compNum = totalCompNum; EXIT: FunctionOut(); return ret; }
OMX_ERRORTYPE SEC_OMX_Port_Constructor(OMX_HANDLETYPE hComponent) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_COMPONENTTYPE *pOMXComponent = NULL; SEC_OMX_BASECOMPONENT *pSECComponent = NULL; SEC_OMX_BASEPORT *pSECPort = NULL; SEC_OMX_BASEPORT *pSECInputPort = NULL; SEC_OMX_BASEPORT *pSECOutputPort = NULL; int i = 0; FunctionIn(); if (hComponent == NULL) { ret = OMX_ErrorBadParameter; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); 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; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); goto EXIT; } pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; INIT_SET_SIZE_VERSION(&pSECComponent->portParam, OMX_PORT_PARAM_TYPE); pSECComponent->portParam.nPorts = ALL_PORT_NUM; pSECComponent->portParam.nStartPortNumber = INPUT_PORT_INDEX; pSECPort = SEC_OSAL_Malloc(sizeof(SEC_OMX_BASEPORT) * ALL_PORT_NUM); if (pSECPort == NULL) { ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); goto EXIT; } SEC_OSAL_Memset(pSECPort, 0, sizeof(SEC_OMX_BASEPORT) * ALL_PORT_NUM); pSECComponent->pSECPort = pSECPort; /* Input Port */ pSECInputPort = &pSECPort[INPUT_PORT_INDEX]; SEC_OSAL_QueueCreate(&pSECInputPort->bufferQ); pSECInputPort->bufferHeader = SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM); if (pSECInputPort->bufferHeader == NULL) { SEC_OSAL_Free(pSECPort); pSECPort = NULL; ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); goto EXIT; } SEC_OSAL_Memset(pSECInputPort->bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM); pSECInputPort->bufferStateAllocate = SEC_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM); if (pSECInputPort->bufferStateAllocate == NULL) { SEC_OSAL_Free(pSECInputPort->bufferHeader); pSECInputPort->bufferHeader = NULL; SEC_OSAL_Free(pSECPort); pSECPort = NULL; ret = OMX_ErrorInsufficientResources; SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); goto EXIT; } SEC_OSAL_Memset(pSECInputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM); pSECInputPort->bufferSemID = NULL; pSECInputPort->assignedBufferNum = 0; pSECInputPort->portState = OMX_StateMax; pSECInputPort->bIsPortFlushed = OMX_FALSE; pSECInputPort->bIsPortDisabled = OMX_FALSE; pSECInputPort->tunneledComponent = NULL; pSECInputPort->tunneledPort = 0; pSECInputPort->tunnelBufferNum = 0; pSECInputPort->bufferSupplier = OMX_BufferSupplyUnspecified; pSECInputPort->tunnelFlags = 0; pSECInputPort->eControlRate = OMX_Video_ControlRateDisable; ret = SEC_OSAL_SemaphoreCreate(&pSECInputPort->loadedResource); if (ret != OMX_ErrorNone) { SEC_OSAL_Free(pSECInputPort->bufferStateAllocate); pSECInputPort->bufferStateAllocate = NULL; SEC_OSAL_Free(pSECInputPort->bufferHeader); pSECInputPort->bufferHeader = NULL; SEC_OSAL_Free(pSECPort); pSECPort = NULL; goto EXIT; } ret = SEC_OSAL_SemaphoreCreate(&pSECInputPort->unloadedResource); if (ret != OMX_ErrorNone) { SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource); pSECInputPort->loadedResource = NULL; SEC_OSAL_Free(pSECInputPort->bufferStateAllocate); pSECInputPort->bufferStateAllocate = NULL; SEC_OSAL_Free(pSECInputPort->bufferHeader); pSECInputPort->bufferHeader = NULL; SEC_OSAL_Free(pSECPort); pSECPort = NULL; goto EXIT; } INIT_SET_SIZE_VERSION(&pSECInputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE); pSECInputPort->portDefinition.nPortIndex = INPUT_PORT_INDEX; pSECInputPort->portDefinition.eDir = OMX_DirInput; pSECInputPort->portDefinition.nBufferCountActual = 0; pSECInputPort->portDefinition.nBufferCountMin = 0; pSECInputPort->portDefinition.nBufferSize = 0; pSECInputPort->portDefinition.bEnabled = OMX_FALSE; pSECInputPort->portDefinition.bPopulated = OMX_FALSE; pSECInputPort->portDefinition.eDomain = OMX_PortDomainMax; pSECInputPort->portDefinition.bBuffersContiguous = OMX_FALSE; pSECInputPort->portDefinition.nBufferAlignment = 0; pSECInputPort->markType.hMarkTargetComponent = NULL; pSECInputPort->markType.pMarkData = NULL; /* Output Port */ pSECOutputPort = &pSECPort[OUTPUT_PORT_INDEX]; SEC_OSAL_QueueCreate(&pSECOutputPort->bufferQ); pSECOutputPort->bufferHeader = SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM); if (pSECOutputPort->bufferHeader == NULL) { SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource); pSECInputPort->unloadedResource = NULL; SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource); pSECInputPort->loadedResource = NULL; SEC_OSAL_Free(pSECInputPort->bufferStateAllocate); pSECInputPort->bufferStateAllocate = NULL; SEC_OSAL_Free(pSECInputPort->bufferHeader); pSECInputPort->bufferHeader = NULL; SEC_OSAL_Free(pSECPort); pSECPort = NULL; ret = OMX_ErrorInsufficientResources; goto EXIT; } SEC_OSAL_Memset(pSECOutputPort->bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM); pSECOutputPort->bufferStateAllocate = SEC_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM); if (pSECOutputPort->bufferStateAllocate == NULL) { SEC_OSAL_Free(pSECOutputPort->bufferHeader); pSECOutputPort->bufferHeader = NULL; SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource); pSECInputPort->unloadedResource = NULL; SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource); pSECInputPort->loadedResource = NULL; SEC_OSAL_Free(pSECInputPort->bufferStateAllocate); pSECInputPort->bufferStateAllocate = NULL; SEC_OSAL_Free(pSECInputPort->bufferHeader); pSECInputPort->bufferHeader = NULL; SEC_OSAL_Free(pSECPort); pSECPort = NULL; ret = OMX_ErrorInsufficientResources; goto EXIT; } SEC_OSAL_Memset(pSECOutputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM); pSECOutputPort->bufferSemID = NULL; pSECOutputPort->assignedBufferNum = 0; pSECOutputPort->portState = OMX_StateMax; pSECOutputPort->bIsPortFlushed = OMX_FALSE; pSECOutputPort->bIsPortDisabled = OMX_FALSE; pSECOutputPort->tunneledComponent = NULL; pSECOutputPort->tunneledPort = 0; pSECOutputPort->tunnelBufferNum = 0; pSECOutputPort->bufferSupplier = OMX_BufferSupplyUnspecified; pSECOutputPort->tunnelFlags = 0; pSECOutputPort->eControlRate = OMX_Video_ControlRateDisable; ret = SEC_OSAL_SemaphoreCreate(&pSECOutputPort->loadedResource); if (ret != OMX_ErrorNone) { SEC_OSAL_Free(pSECOutputPort->bufferStateAllocate); pSECOutputPort->bufferStateAllocate = NULL; SEC_OSAL_Free(pSECOutputPort->bufferHeader); pSECOutputPort->bufferHeader = NULL; SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource); pSECInputPort->unloadedResource = NULL; SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource); pSECInputPort->loadedResource = NULL; SEC_OSAL_Free(pSECInputPort->bufferStateAllocate); pSECInputPort->bufferStateAllocate = NULL; SEC_OSAL_Free(pSECInputPort->bufferHeader); pSECInputPort->bufferHeader = NULL; SEC_OSAL_Free(pSECPort); pSECPort = NULL; goto EXIT; } ret = SEC_OSAL_SemaphoreCreate(&pSECOutputPort->unloadedResource); if (ret != OMX_ErrorNone) { SEC_OSAL_SemaphoreTerminate(pSECOutputPort->loadedResource); pSECOutputPort->loadedResource = NULL; SEC_OSAL_Free(pSECOutputPort->bufferStateAllocate); pSECOutputPort->bufferStateAllocate = NULL; SEC_OSAL_Free(pSECOutputPort->bufferHeader); pSECOutputPort->bufferHeader = NULL; SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource); pSECInputPort->unloadedResource = NULL; SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource); pSECInputPort->loadedResource = NULL; SEC_OSAL_Free(pSECInputPort->bufferStateAllocate); pSECInputPort->bufferStateAllocate = NULL; SEC_OSAL_Free(pSECInputPort->bufferHeader); pSECInputPort->bufferHeader = NULL; SEC_OSAL_Free(pSECPort); pSECPort = NULL; goto EXIT; } INIT_SET_SIZE_VERSION(&pSECOutputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE); pSECOutputPort->portDefinition.nPortIndex = OUTPUT_PORT_INDEX; pSECOutputPort->portDefinition.eDir = OMX_DirOutput; pSECOutputPort->portDefinition.nBufferCountActual = 0; pSECOutputPort->portDefinition.nBufferCountMin = 0; pSECOutputPort->portDefinition.nBufferSize = 0; pSECOutputPort->portDefinition.bEnabled = OMX_FALSE; pSECOutputPort->portDefinition.bPopulated = OMX_FALSE; pSECOutputPort->portDefinition.eDomain = OMX_PortDomainMax; pSECOutputPort->portDefinition.bBuffersContiguous = OMX_FALSE; pSECOutputPort->portDefinition.nBufferAlignment = 0; pSECOutputPort->markType.hMarkTargetComponent = NULL; pSECOutputPort->markType.pMarkData = NULL; pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE; pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE; pSECComponent->checkTimeStamp.startTimeStamp = 0; pSECComponent->checkTimeStamp.nStartFlags = 0x0; pOMXComponent->EmptyThisBuffer = &SEC_OMX_EmptyThisBuffer; pOMXComponent->FillThisBuffer = &SEC_OMX_FillThisBuffer; ret = OMX_ErrorNone; EXIT: FunctionOut(); return ret; }
OMX_ERRORTYPE SEC_OMX_PortDisableProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex) { OMX_ERRORTYPE ret = OMX_ErrorNone; SEC_OMX_BASECOMPONENT *pSECComponent = NULL; OMX_S32 portIndex = 0; OMX_U32 i = 0, cnt = 0; SEC_OMX_DATABUFFER *flushBuffer = NULL; FunctionIn(); if (pOMXComponent == NULL) { ret = OMX_ErrorBadParameter; goto EXIT; } 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; cnt = (nPortIndex == ALL_PORT_INDEX ) ? ALL_PORT_NUM : 1; /* port flush*/ for(i = 0; i < cnt; i++) { if (nPortIndex == ALL_PORT_INDEX) portIndex = i; else portIndex = nPortIndex; pSECComponent->pSECPort[portIndex].bIsPortFlushed = OMX_TRUE; flushBuffer = &pSECComponent->secDataBuffer[portIndex]; SEC_OSAL_MutexLock(flushBuffer->bufferMutex); ret = SEC_OMX_FlushPort(pOMXComponent, portIndex); SEC_OSAL_MutexUnlock(flushBuffer->bufferMutex); pSECComponent->pSECPort[portIndex].bIsPortFlushed = OMX_FALSE; if (portIndex == INPUT_PORT_INDEX) { pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE; pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE; SEC_OSAL_Memset(pSECComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); SEC_OSAL_Memset(pSECComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); pSECComponent->getAllDelayBuffer = OMX_FALSE; pSECComponent->bSaveFlagEOS = OMX_FALSE; pSECComponent->reInputData = OMX_FALSE; } else if (portIndex == OUTPUT_PORT_INDEX) { pSECComponent->remainOutputData = OMX_FALSE; } } for(i = 0; i < cnt; i++) { if (nPortIndex == ALL_PORT_INDEX) portIndex = i; else portIndex = nPortIndex; ret = SEC_OMX_DisablePort(pOMXComponent, portIndex); pSECComponent->pSECPort[portIndex].bIsPortDisabled = OMX_FALSE; if (ret == OMX_ErrorNone) { pSECComponent->pCallbacks->EventHandler(pOMXComponent, pSECComponent->callbackData, OMX_EventCmdComplete, OMX_CommandPortDisable, portIndex, NULL); } } EXIT: if (ret != OMX_ErrorNone) { pSECComponent->pCallbacks->EventHandler(pOMXComponent, pSECComponent->callbackData, OMX_EventError, ret, 0, NULL); } FunctionOut(); return ret; }