From 6dfe5a02711cfd47d041a01554c467874ede525f Mon Sep 17 00:00:00 2001 From: Taehwan Kim Date: Fri, 7 Dec 2012 00:30:05 +0000 Subject: [PATCH] venc: cleaned up related code with codec buffer added new functions to extract the most used code. 1. alloc codec buffer 2. free codec buffer 3. regist codec buffer Change-Id: I0c4988fe577421658291013d65105125ab816e22 Signed-off-by: Taehwan Kim --- component/video/enc/Exynos_OMX_Venc.c | 99 ++++++++++ component/video/enc/h264/Exynos_OMX_H264enc.c | 169 +++++++++--------- .../video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c | 169 +++++++++--------- 3 files changed, 267 insertions(+), 170 deletions(-) diff --git a/component/video/enc/Exynos_OMX_Venc.c b/component/video/enc/Exynos_OMX_Venc.c index 118c516..62b4c9e 100644 --- a/component/video/enc/Exynos_OMX_Venc.c +++ b/component/video/enc/Exynos_OMX_Venc.c @@ -80,6 +80,105 @@ inline void Exynos_UpdateFrameSize(OMX_COMPONENTTYPE *pOMXComponent) return; } +void Exynos_Free_CodecBuffers( + OMX_COMPONENTTYPE *pOMXComponent, + OMX_U32 nPortIndex) +{ + OMX_ERRORTYPE ret = OMX_ErrorNone; + EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; + EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; + CODEC_ENC_BUFFER **ppCodecBuffer = NULL; + + OMX_U32 nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoEnc->pMFCEncInputBuffer[0]); + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + } else { + ppCodecBuffer = &(pVideoEnc->pMFCEncOutputBuffer[0]); + nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE; + } + + for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { + if (ppCodecBuffer[i] != NULL) { + for (j = 0; j < nPlaneCnt; j++) { + if (ppCodecBuffer[i]->pVirAddr[j] != NULL) + Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, ppCodecBuffer[i]->pVirAddr[j]); + } + + Exynos_OSAL_Free(ppCodecBuffer[i]); + ppCodecBuffer[i] = NULL; + } + } + + FunctionOut(); +} + +OMX_ERRORTYPE Exynos_Allocate_CodecBuffers( + OMX_COMPONENTTYPE *pOMXComponent, + OMX_U32 nPortIndex, + OMX_U32 nBufferCnt, + OMX_U32 nPlaneSize[MFC_OUTPUT_BUFFER_PLANE]) +{ + OMX_ERRORTYPE ret = OMX_ErrorNone; + EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; + EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; + MEMORY_TYPE eMemoryType = NORMAL_MEMORY; + CODEC_ENC_BUFFER **ppCodecBuffer = NULL; + + OMX_U32 nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoEnc->pMFCEncInputBuffer[0]); + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + } else { + ppCodecBuffer = &(pVideoEnc->pMFCEncOutputBuffer[0]); + nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE; + } + + for (i = 0; i < nBufferCnt; i++) { + ppCodecBuffer[i] = (CODEC_ENC_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_ENC_BUFFER)); + if (ppCodecBuffer[i] == NULL) { + Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc codec buffer"); + ret = OMX_ErrorInsufficientResources; + goto EXIT; + } + Exynos_OSAL_Memset(ppCodecBuffer[i], 0, sizeof(CODEC_ENC_BUFFER)); + + for (j = 0; j < nPlaneCnt; j++) { + ppCodecBuffer[i]->pVirAddr[j] = + (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, nPlaneSize[j], eMemoryType); + if (ppCodecBuffer[i]->pVirAddr[j] == NULL) { + Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc plane"); + ret = OMX_ErrorInsufficientResources; + goto EXIT; + } + + ppCodecBuffer[i]->fd[j] = + Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, ppCodecBuffer[i]->pVirAddr[j]); + ppCodecBuffer[i]->bufferSize[j] = nPlaneSize[j]; + Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "PORT[%d]: pMFCCodecBuffer[%d]->pVirAddr[%d]: 0x%x", nPortIndex, i, j, ppCodecBuffer[i]->pVirAddr[j]); + } + + ppCodecBuffer[i]->dataSize = 0; + } + + return OMX_ErrorNone; + +EXIT: + Exynos_Free_CodecBuffers(pOMXComponent, nPortIndex); + + FunctionOut(); + + return ret; +} + OMX_BOOL Exynos_Check_BufferProcess_State(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 nPortIndex) { OMX_BOOL ret = OMX_FALSE; diff --git a/component/video/enc/h264/Exynos_OMX_H264enc.c b/component/video/enc/h264/Exynos_OMX_H264enc.c index 126b023..8b6433e 100644 --- a/component/video/enc/h264/Exynos_OMX_H264enc.c +++ b/component/video/enc/h264/Exynos_OMX_H264enc.c @@ -686,6 +686,67 @@ EXIT: return ret; } +OMX_ERRORTYPE H264CodecRegistCodecBuffers( + OMX_COMPONENTTYPE *pOMXComponent, + OMX_U32 nPortIndex, + OMX_U32 nBufferCnt) +{ + OMX_ERRORTYPE ret = OMX_ErrorNone; + EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; + EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; + EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)pVideoEnc->hCodecHandle; + void *hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; + CODEC_ENC_BUFFER **ppCodecBuffer = NULL; + ExynosVideoEncBufferOps *pBufOps = NULL; + ExynosVideoPlane *pPlanes = NULL; + + OMX_U32 nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoEnc->pMFCEncInputBuffer[0]); + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + pBufOps = pH264Enc->hMFCH264Handle.pInbufOps; + } else { + ppCodecBuffer = &(pVideoEnc->pMFCEncOutputBuffer[0]); + nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE; + pBufOps = pH264Enc->hMFCH264Handle.pOutbufOps; + } + + pPlanes = (ExynosVideoPlane *)Exynos_OSAL_Malloc(sizeof(ExynosVideoPlane) * nPlaneCnt); + if (pPlanes == NULL) { + ret = OMX_ErrorInsufficientResources; + goto EXIT; + } + + /* Register buffer */ + for (i = 0; i < nBufferCnt; i++) { + for (j = 0; j < nPlaneCnt; j++) { + pPlanes[j].addr = ppCodecBuffer[i]->pVirAddr[j]; + pPlanes[j].fd = ppCodecBuffer[i]->fd[j]; + pPlanes[j].allocSize = ppCodecBuffer[i]->bufferSize[j]; + } + + if (pBufOps->Register(hMFCHandle, pPlanes, nPlaneCnt) != VIDEO_ERROR_NONE) { + Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "PORT[%d]: Failed to Register buffer", nPortIndex); + ret = OMX_ErrorInsufficientResources; + Exynos_OSAL_Free(pPlanes); + goto EXIT; + } + } + + Exynos_OSAL_Free(pPlanes); + + ret = OMX_ErrorNone; + +EXIT: + FunctionOut(); + + return ret; +} + OMX_ERRORTYPE H264CodecEnqueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) { OMX_ERRORTYPE ret = OMX_ErrorNone; @@ -830,19 +891,9 @@ OMX_ERRORTYPE H264CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DAT int plane; if (pExynosInputPort->bufferProcessType & BUFFER_COPY) { - /* Register input buffer */ - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - planes[plane].addr = pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[plane]; - planes[plane].allocSize = pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[plane]; - planes[plane].fd = pVideoEnc->pMFCEncInputBuffer[i]->fd[plane]; - } - if (pInbufOps->Register(hMFCHandle, planes, MFC_INPUT_BUFFER_PLANE) != VIDEO_ERROR_NONE) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - } + ret = H264CodecRegistCodecBuffers(pOMXComponent, INPUT_PORT_INDEX, MFC_INPUT_BUFFER_NUM_MAX); + if (ret != OMX_ErrorNone) + goto EXIT; } else if (pExynosInputPort->bufferProcessType & BUFFER_SHARE) { if (pExynosInputPort->bStoreMetaData == OMX_TRUE) { /*************/ @@ -919,30 +970,18 @@ OMX_ERRORTYPE H264CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) OMX_U32 dataLen[MFC_OUTPUT_BUFFER_PLANE] = {0}; if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) { - /* Register input buffer */ - for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { - ExynosVideoPlane plane; - pVideoEnc->pMFCEncOutputBuffer[i] = (CODEC_ENC_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_ENC_BUFFER)); - pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0] = - (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, OutBufferSize, NORMAL_MEMORY); - if (pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0] == NULL) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc output buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - pVideoEnc->pMFCEncOutputBuffer[i]->fd[0] = - Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0]); - pVideoEnc->pMFCEncOutputBuffer[i]->bufferSize[0] = OutBufferSize; + OMX_U32 nPlaneSize[MFC_OUTPUT_BUFFER_PLANE] = {0}; + nPlaneSize[0] = OutBufferSize; + ret = Exynos_Allocate_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, MFC_OUTPUT_BUFFER_NUM_MAX, nPlaneSize); + if (ret != OMX_ErrorNone) + goto EXIT; - plane.addr = pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0]; - plane.fd = pVideoEnc->pMFCEncOutputBuffer[i]->fd[0]; - plane.allocSize = pVideoEnc->pMFCEncOutputBuffer[i]->bufferSize[0]; + ret = H264CodecRegistCodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, MFC_OUTPUT_BUFFER_NUM_MAX); + if (ret != OMX_ErrorNone) + goto EXIT; - if (pOutbufOps->Register(hMFCHandle, &plane, MFC_OUTPUT_BUFFER_PLANE) != VIDEO_ERROR_NONE) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register output buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } + /* Enqueue output buffer */ + for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { pOutbufOps->Enqueue(hMFCHandle, (unsigned char **)pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr, (unsigned int *)dataLen, MFC_OUTPUT_BUFFER_PLANE, NULL); } @@ -1562,41 +1601,19 @@ OMX_ERRORTYPE Exynos_H264Enc_Init(OMX_COMPONENTTYPE *pOMXComponent) if ((pExynosInputPort->bStoreMetaData != OMX_TRUE) && (eColorFormat != OMX_COLOR_FormatAndroidOpaque)) { if (pExynosInputPort->bufferProcessType & BUFFER_COPY) { + OMX_U32 nPlaneSize[MFC_INPUT_BUFFER_PLANE] = {0, }; + nPlaneSize[0] = DEFAULT_MFC_INPUT_YBUFFER_SIZE; + nPlaneSize[1] = DEFAULT_MFC_INPUT_CBUFFER_SIZE; + Exynos_OSAL_SemaphoreCreate(&pExynosInputPort->codecSemID); Exynos_OSAL_QueueCreate(&pExynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - pVideoEnc->pMFCEncInputBuffer[i] = Exynos_OSAL_Malloc(sizeof(CODEC_ENC_BUFFER)); - /* Use ION Allocator */ - /*Alloc Y-Buffer */ - pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0] = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, DEFAULT_MFC_INPUT_YBUFFER_SIZE, NORMAL_MEMORY); - pVideoEnc->pMFCEncInputBuffer[i]->fd[0] = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0]); - pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[0] = DEFAULT_MFC_INPUT_YBUFFER_SIZE; - /*Alloc C-Buffer */ - pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1] = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, DEFAULT_MFC_INPUT_CBUFFER_SIZE, NORMAL_MEMORY); - pVideoEnc->pMFCEncInputBuffer[i]->fd[1] = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1]); - pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[1] = DEFAULT_MFC_INPUT_CBUFFER_SIZE; - - pVideoEnc->pMFCEncInputBuffer[i]->dataSize = 0; - - if ((pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0] == NULL) || - (pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1] == NULL)) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Fail input buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - - /* MFC input buffers are 1 plane. */ - pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[2] = NULL; - pVideoEnc->pMFCEncInputBuffer[i]->fd[2] = -1; - pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[2] = 0; - - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]); - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]->pVirAddr[0]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0]); - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]->pVirAddr[1]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1]); + ret = Exynos_Allocate_CodecBuffers(pOMXComponent, INPUT_PORT_INDEX, MFC_INPUT_BUFFER_NUM_MAX, nPlaneSize); + if (ret != OMX_ErrorNone) + goto EXIT; + for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) Exynos_CodecBufferEnqueue(pExynosComponent, INPUT_PORT_INDEX, pVideoEnc->pMFCEncInputBuffer[i]); - } } else if (pExynosInputPort->bufferProcessType & BUFFER_SHARE) { /*************/ /* TBD */ @@ -1675,15 +1692,7 @@ OMX_ERRORTYPE Exynos_H264Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) pH264Enc->bSourceStart = OMX_FALSE; if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) { - for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { - if (pVideoEnc->pMFCEncOutputBuffer[i] != NULL) { - if (pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0]); - Exynos_OSAL_Free(pVideoEnc->pMFCEncOutputBuffer[i]); - pVideoEnc->pMFCEncOutputBuffer[i] = NULL; - } - } - + Exynos_Free_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX); Exynos_OSAL_QueueTerminate(&pExynosOutputPort->codecBufferQ); Exynos_OSAL_SemaphoreTerminate(pExynosOutputPort->codecSemID); } else if (pExynosOutputPort->bufferProcessType & BUFFER_SHARE) { @@ -1694,17 +1703,7 @@ OMX_ERRORTYPE Exynos_H264Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) } if (pExynosInputPort->bufferProcessType & BUFFER_COPY) { - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - if (pVideoEnc->pMFCEncInputBuffer[i] != NULL) { - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - if (pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[plane] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[plane]); - } - Exynos_OSAL_Free(pVideoEnc->pMFCEncInputBuffer[i]); - pVideoEnc->pMFCEncInputBuffer[i] = NULL; - } - } - + Exynos_Free_CodecBuffers(pOMXComponent, INPUT_PORT_INDEX); Exynos_OSAL_QueueTerminate(&pExynosInputPort->codecBufferQ); Exynos_OSAL_SemaphoreTerminate(pExynosInputPort->codecSemID); } else if (pExynosInputPort->bufferProcessType & BUFFER_SHARE) { diff --git a/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c b/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c index 66382ed..2344c43 100644 --- a/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c +++ b/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c @@ -808,6 +808,67 @@ EXIT: return ret; } +OMX_ERRORTYPE Mpeg4CodecRegistCodecBuffers( + OMX_COMPONENTTYPE *pOMXComponent, + OMX_U32 nPortIndex, + OMX_U32 nBufferCnt) +{ + OMX_ERRORTYPE ret = OMX_ErrorNone; + EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; + EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; + EXYNOS_MPEG4ENC_HANDLE *pMpeg4Enc = (EXYNOS_MPEG4ENC_HANDLE *)pVideoEnc->hCodecHandle; + void *hMFCHandle = pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle; + CODEC_ENC_BUFFER **ppCodecBuffer = NULL; + ExynosVideoEncBufferOps *pBufOps = NULL; + ExynosVideoPlane *pPlanes = NULL; + + OMX_U32 nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoEnc->pMFCEncInputBuffer[0]); + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + pBufOps = pMpeg4Enc->hMFCMpeg4Handle.pInbufOps; + } else { + ppCodecBuffer = &(pVideoEnc->pMFCEncOutputBuffer[0]); + nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE; + pBufOps = pMpeg4Enc->hMFCMpeg4Handle.pOutbufOps; + } + + pPlanes = (ExynosVideoPlane *)Exynos_OSAL_Malloc(sizeof(ExynosVideoPlane) * nPlaneCnt); + if (pPlanes == NULL) { + ret = OMX_ErrorInsufficientResources; + goto EXIT; + } + + /* Register buffer */ + for (i = 0; i < nBufferCnt; i++) { + for (j = 0; j < nPlaneCnt; j++) { + pPlanes[j].addr = ppCodecBuffer[i]->pVirAddr[j]; + pPlanes[j].fd = ppCodecBuffer[i]->fd[j]; + pPlanes[j].allocSize = ppCodecBuffer[i]->bufferSize[j]; + } + + if (pBufOps->Register(hMFCHandle, pPlanes, nPlaneCnt) != VIDEO_ERROR_NONE) { + Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "PORT[%d]: Failed to Register buffer", nPortIndex); + ret = OMX_ErrorInsufficientResources; + Exynos_OSAL_Free(pPlanes); + goto EXIT; + } + } + + Exynos_OSAL_Free(pPlanes); + + ret = OMX_ErrorNone; + +EXIT: + FunctionOut(); + + return ret; +} + OMX_ERRORTYPE Mpeg4CodecEnqueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) { OMX_ERRORTYPE ret = OMX_ErrorNone; @@ -956,19 +1017,9 @@ OMX_ERRORTYPE Mpeg4CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DA int plane; if (pExynosInputPort->bufferProcessType & BUFFER_COPY) { - /* Register input buffer */ - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - planes[plane].addr = pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[plane]; - planes[plane].allocSize = pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[plane]; - planes[plane].fd = pVideoEnc->pMFCEncInputBuffer[i]->fd[plane]; - } - if (pInbufOps->Register(hMFCHandle, planes, MFC_INPUT_BUFFER_PLANE) != VIDEO_ERROR_NONE) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - } + ret = Mpeg4CodecRegistCodecBuffers(pOMXComponent, INPUT_PORT_INDEX, MFC_INPUT_BUFFER_NUM_MAX); + if (ret != OMX_ErrorNone) + goto EXIT; } else if (pExynosInputPort->bufferProcessType & BUFFER_SHARE) { if (pExynosInputPort->bStoreMetaData == OMX_TRUE) { /*************/ @@ -1052,30 +1103,18 @@ OMX_ERRORTYPE Mpeg4CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) OMX_U32 dataLen[MFC_OUTPUT_BUFFER_PLANE] = {0}; if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) { - /* Register input buffer */ - for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { - ExynosVideoPlane plane; - pVideoEnc->pMFCEncOutputBuffer[i] = (CODEC_ENC_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_ENC_BUFFER)); - pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0] = - (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, OutBufferSize, NORMAL_MEMORY); - if (pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0] == NULL) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc output buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - pVideoEnc->pMFCEncOutputBuffer[i]->fd[0] = - Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0]); - pVideoEnc->pMFCEncOutputBuffer[i]->bufferSize[0] = OutBufferSize; + OMX_U32 nPlaneSize[MFC_OUTPUT_BUFFER_PLANE] = {0}; + nPlaneSize[0] = OutBufferSize; + ret = Exynos_Allocate_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, MFC_OUTPUT_BUFFER_NUM_MAX, nPlaneSize); + if (ret != OMX_ErrorNone) + goto EXIT; - plane.addr = pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0]; - plane.fd = pVideoEnc->pMFCEncOutputBuffer[i]->fd[0]; - plane.allocSize = pVideoEnc->pMFCEncOutputBuffer[i]->bufferSize[0]; + ret = Mpeg4CodecRegistCodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, MFC_OUTPUT_BUFFER_NUM_MAX); + if (ret != OMX_ErrorNone) + goto EXIT; - if (pOutbufOps->Register(hMFCHandle, &plane, MFC_OUTPUT_BUFFER_PLANE) != VIDEO_ERROR_NONE) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register output buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } + /* Enqueue output buffer */ + for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { pOutbufOps->Enqueue(hMFCHandle, (unsigned char **)pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr, (unsigned int *)dataLen, MFC_OUTPUT_BUFFER_PLANE, NULL); } @@ -1772,41 +1811,19 @@ OMX_ERRORTYPE Exynos_Mpeg4Enc_Init(OMX_COMPONENTTYPE *pOMXComponent) if ((pExynosInputPort->bStoreMetaData != OMX_TRUE) && (eColorFormat != OMX_COLOR_FormatAndroidOpaque)) { if (pExynosInputPort->bufferProcessType & BUFFER_COPY) { + OMX_U32 nPlaneSize[MFC_INPUT_BUFFER_PLANE] = {0, }; + nPlaneSize[0] = DEFAULT_MFC_INPUT_YBUFFER_SIZE; + nPlaneSize[1] = DEFAULT_MFC_INPUT_CBUFFER_SIZE; + Exynos_OSAL_SemaphoreCreate(&pExynosInputPort->codecSemID); Exynos_OSAL_QueueCreate(&pExynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - pVideoEnc->pMFCEncInputBuffer[i] = Exynos_OSAL_Malloc(sizeof(CODEC_ENC_BUFFER)); - /* Use ION Allocator */ - /*Alloc Y-Buffer */ - pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0] = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, DEFAULT_MFC_INPUT_YBUFFER_SIZE, NORMAL_MEMORY); - pVideoEnc->pMFCEncInputBuffer[i]->fd[0] = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0]); - pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[0] = DEFAULT_MFC_INPUT_YBUFFER_SIZE; - /*Alloc C-Buffer */ - pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1] = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, DEFAULT_MFC_INPUT_CBUFFER_SIZE, NORMAL_MEMORY); - pVideoEnc->pMFCEncInputBuffer[i]->fd[1] = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1]); - pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[1] = DEFAULT_MFC_INPUT_CBUFFER_SIZE; - - pVideoEnc->pMFCEncInputBuffer[i]->dataSize = 0; - - if ((pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0] == NULL) || - (pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1] == NULL)) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Fail input buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - - /* MFC input buffers are 1 plane. */ - pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[2] = NULL; - pVideoEnc->pMFCEncInputBuffer[i]->fd[2] = -1; - pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[2] = 0; - - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]); - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]->pVirAddr[0]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0]); - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]->pVirAddr[1]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1]); + ret = Exynos_Allocate_CodecBuffers(pOMXComponent, INPUT_PORT_INDEX, MFC_INPUT_BUFFER_NUM_MAX, nPlaneSize); + if (ret != OMX_ErrorNone) + goto EXIT; + for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) Exynos_CodecBufferEnqueue(pExynosComponent, INPUT_PORT_INDEX, pVideoEnc->pMFCEncInputBuffer[i]); - } } else if (pExynosInputPort->bufferProcessType & BUFFER_SHARE) { /*************/ /* TBD */ @@ -1885,15 +1902,7 @@ OMX_ERRORTYPE Exynos_Mpeg4Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) pMpeg4Enc->bSourceStart = OMX_FALSE; if (pExynosOutputPort->bufferProcessType & BUFFER_COPY) { - for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { - if (pVideoEnc->pMFCEncOutputBuffer[i] != NULL) { - if (pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncOutputBuffer[i]->pVirAddr[0]); - Exynos_OSAL_Free(pVideoEnc->pMFCEncOutputBuffer[i]); - pVideoEnc->pMFCEncOutputBuffer[i] = NULL; - } - } - + Exynos_Free_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX); Exynos_OSAL_QueueTerminate(&pExynosOutputPort->codecBufferQ); Exynos_OSAL_SemaphoreTerminate(pExynosOutputPort->codecSemID); } else if (pExynosOutputPort->bufferProcessType & BUFFER_SHARE) { @@ -1904,17 +1913,7 @@ OMX_ERRORTYPE Exynos_Mpeg4Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) } if (pExynosInputPort->bufferProcessType & BUFFER_COPY) { - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - if (pVideoEnc->pMFCEncInputBuffer[i] != NULL) { - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - if (pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[plane] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[plane]); - } - Exynos_OSAL_Free(pVideoEnc->pMFCEncInputBuffer[i]); - pVideoEnc->pMFCEncInputBuffer[i] = NULL; - } - } - + Exynos_Free_CodecBuffers(pOMXComponent, INPUT_PORT_INDEX); Exynos_OSAL_QueueTerminate(&pExynosInputPort->codecBufferQ); Exynos_OSAL_SemaphoreTerminate(pExynosInputPort->codecSemID); } else if (pExynosInputPort->bufferProcessType & BUFFER_SHARE) { -- 2.20.1