From f8d511af096144c3c33d823f879ae0e471ae5284 Mon Sep 17 00:00:00 2001 From: SeungBeom Kim Date: Fri, 2 Aug 2013 10:05:22 +0900 Subject: [PATCH] exynos_omx: multi_thread: Code clean up. for GED Code and S.LSI code synchronization. Change-Id: I10f450cbd688a7802ade7bbb6e3623646611062b Signed-off-by: SeungBeom Kim Bug: 10192533 --- .../mfc_v4l2/dec/src/ExynosVideoDecoder.c | 2 +- .../component/common/Exynos_OMX_Baseport.c | 1 + .../common/Exynos_OMX_Resourcemanager.c | 2 +- .../component/video/dec/Exynos_OMX_Vdec.c | 127 ++++++++++- .../video/dec/Exynos_OMX_VdecControl.c | 110 +--------- .../video/dec/Exynos_OMX_VdecControl.h | 6 +- .../video/dec/h264/Exynos_OMX_H264dec.c | 157 +++++++------- .../video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c | 154 +++++++------- .../video/dec/vp8/Exynos_OMX_Vp8dec.c | 153 +++++++------- .../component/video/enc/Exynos_OMX_Venc.c | 156 ++++++++++---- .../video/enc/Exynos_OMX_VencControl.c | 121 ++--------- .../video/enc/Exynos_OMX_VencControl.h | 198 +++++++++--------- .../video/enc/h264/Exynos_OMX_H264enc.c | 178 ++++++++-------- .../video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c | 176 ++++++++-------- .../exynos_omx/osal/Exynos_OSAL_Android.cpp | 1 - .../exynos_omx/osal/Exynos_OSAL_Queue.c | 2 +- .../osal/Exynos_OSAL_SharedMemory.c | 5 +- 17 files changed, 783 insertions(+), 766 deletions(-) diff --git a/exynos_omx/codecs/exynos_codecs/video/exynos5/mfc_v4l2/dec/src/ExynosVideoDecoder.c b/exynos_omx/codecs/exynos_codecs/video/exynos5/mfc_v4l2/dec/src/ExynosVideoDecoder.c index 12275ee..3aaa74f 100644 --- a/exynos_omx/codecs/exynos_codecs/video/exynos5/mfc_v4l2/dec/src/ExynosVideoDecoder.c +++ b/exynos_omx/codecs/exynos_codecs/video/exynos5/mfc_v4l2/dec/src/ExynosVideoDecoder.c @@ -1484,7 +1484,7 @@ static ExynosVideoErrorType MFC_Decoder_Enqueue_Inbuf( if ((((OMX_BUFFERHEADERTYPE *)pPrivate)->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { buf.flags |= V4L2_BUF_FLAG_LAST_FRAME; - ALOGD("%s: OMX_BUFFERFLAG_EOS => LAST_FRAME: 0x%x", __func__, + ALOGV("%s: OMX_BUFFERFLAG_EOS => LAST_FRAME: 0x%x", __func__, !!(buf.flags & V4L2_BUF_FLAG_LAST_FRAME)); } diff --git a/exynos_omx/openmax/exynos_omx/component/common/Exynos_OMX_Baseport.c b/exynos_omx/openmax/exynos_omx/component/common/Exynos_OMX_Baseport.c index 9c0c42d..f512457 100644 --- a/exynos_omx/openmax/exynos_omx/component/common/Exynos_OMX_Baseport.c +++ b/exynos_omx/openmax/exynos_omx/component/common/Exynos_OMX_Baseport.c @@ -870,6 +870,7 @@ OMX_ERRORTYPE Exynos_ResetCodecData(EXYNOS_OMX_DATA *pData) pData->timeStamp = 0; pData->pPrivate = NULL; pData->bufferHeader = NULL; + pData->allocSize = 0; EXIT: return ret; diff --git a/exynos_omx/openmax/exynos_omx/component/common/Exynos_OMX_Resourcemanager.c b/exynos_omx/openmax/exynos_omx/component/common/Exynos_OMX_Resourcemanager.c index 6645fb2..6e9aa9d 100644 --- a/exynos_omx/openmax/exynos_omx/component/common/Exynos_OMX_Resourcemanager.c +++ b/exynos_omx/openmax/exynos_omx/component/common/Exynos_OMX_Resourcemanager.c @@ -372,7 +372,7 @@ OMX_ERRORTYPE Exynos_OMX_Release_Resource(OMX_COMPONENTTYPE *pOMXComponent) Exynos_OSAL_MutexLock(ghVideoRMComponentListMutex); pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; - + if (pExynosComponent->codecType == HW_VIDEO_DEC_CODEC) { pComponentTemp = gpVideoDecRMWaitingList; if (gpVideoDecRMComponentList == NULL) { diff --git a/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_Vdec.c b/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_Vdec.c index 1179b1b..aac1a9c 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_Vdec.c +++ b/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_Vdec.c @@ -34,6 +34,7 @@ #include "Exynos_OMX_Vdec.h" #include "Exynos_OMX_VdecControl.h" #include "Exynos_OMX_Basecomponent.h" +#include "Exynos_OSAL_SharedMemory.h" #include "Exynos_OSAL_Thread.h" #include "Exynos_OSAL_Semaphore.h" #include "Exynos_OSAL_Mutex.h" @@ -111,6 +112,108 @@ 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_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; + CODEC_DEC_BUFFER **ppCodecBuffer = NULL; + + OMX_U32 nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoDec->pMFCDecInputBuffer[0]); + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + } else { + ppCodecBuffer = &(pVideoDec->pMFCDecOutputBuffer[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(pVideoDec->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_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; + MEMORY_TYPE eMemoryType = NORMAL_MEMORY; + CODEC_DEC_BUFFER **ppCodecBuffer = NULL; + + OMX_U32 nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (pVideoDec->bDRMPlayerMode == OMX_TRUE) + eMemoryType = SECURE_MEMORY; + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoDec->pMFCDecInputBuffer[0]); + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + } else { + ppCodecBuffer = &(pVideoDec->pMFCDecOutputBuffer[0]); + nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE; + } + + for (i = 0; i < nBufferCnt; i++) { + ppCodecBuffer[i] = (CODEC_DEC_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_DEC_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_DEC_BUFFER)); + + for (j = 0; j < nPlaneCnt; j++) { + ppCodecBuffer[i]->pVirAddr[j] = + (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->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(pVideoDec->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; @@ -195,11 +298,7 @@ OMX_ERRORTYPE Exynos_Output_CodecBufferToData(EXYNOS_OMX_BASECOMPONENT *pExynosC CODEC_DEC_BUFFER *pCodecBuffer = (CODEC_DEC_BUFFER *)codecBuffer; int i = 0; - for (i = 0; i < MAX_BUFFER_PLANE; i++) { - pData->buffer.multiPlaneBuffer.dataBuffer[i] = pCodecBuffer->pVirAddr[i]; - pData->buffer.multiPlaneBuffer.fd[i] = pCodecBuffer->fd[i]; - pData->allocSize += pCodecBuffer->bufferSize[i]; - } + pData->allocSize = 0; pData->dataLen = 0; pData->usedDataLen = 0; pData->remainDataLen = 0; @@ -209,6 +308,12 @@ OMX_ERRORTYPE Exynos_Output_CodecBufferToData(EXYNOS_OMX_BASECOMPONENT *pExynosC pData->pPrivate = codecBuffer; pData->bufferHeader = NULL; + for (i = 0; i < MAX_BUFFER_PLANE; i++) { + pData->buffer.multiPlaneBuffer.dataBuffer[i] = pCodecBuffer->pVirAddr[i]; + pData->buffer.multiPlaneBuffer.fd[i] = pCodecBuffer->fd[i]; + pData->allocSize += pCodecBuffer->bufferSize[i]; + } + return ret; } @@ -437,7 +542,7 @@ OMX_BOOL Exynos_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ ret = OMX_FALSE; } - Exynos_InputBufferReturn(pOMXComponent); + Exynos_InputBufferReturn(pOMXComponent, inputUseBuffer); } if ((srcInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { @@ -548,7 +653,7 @@ OMX_BOOL Exynos_Postprocess_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ if ((outputUseBuffer->remainDataLen > 0) || ((outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) || (CHECK_PORT_BEING_FLUSHED(exynosOutputPort))) { - Exynos_OutputBufferReturn(pOMXComponent); + Exynos_OutputBufferReturn(pOMXComponent, outputUseBuffer); } } else { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "csc_convert Error"); @@ -562,7 +667,7 @@ OMX_BOOL Exynos_Postprocess_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ outputUseBuffer->remainDataLen = 0; outputUseBuffer->nFlags = dstOutputData->nFlags; outputUseBuffer->timeStamp = dstOutputData->timeStamp; - Exynos_OutputBufferReturn(pOMXComponent); + Exynos_OutputBufferReturn(pOMXComponent, outputUseBuffer); } else { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "output buffer is smaller than decoded data size Out Length"); pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, @@ -574,7 +679,7 @@ OMX_BOOL Exynos_Postprocess_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ if ((outputUseBuffer->remainDataLen > 0) || ((outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) || (CHECK_PORT_BEING_FLUSHED(exynosOutputPort))) - Exynos_OutputBufferReturn(pOMXComponent); + Exynos_OutputBufferReturn(pOMXComponent, outputUseBuffer); } } else { ret = OMX_FALSE; @@ -702,7 +807,7 @@ OMX_ERRORTYPE Exynos_OMX_SrcOutputBufferProcess(OMX_HANDLETYPE hComponent) } if (exynosInputPort->bufferProcessType == BUFFER_SHARE) { Exynos_Shared_DataToBuffer(&srcOutputData, srcOutputUseBuffer); - Exynos_InputBufferReturn(pOMXComponent); + Exynos_InputBufferReturn(pOMXComponent, srcOutputUseBuffer); } Exynos_ResetCodecData(&srcOutputData); } @@ -808,7 +913,7 @@ OMX_ERRORTYPE Exynos_OMX_DstOutputBufferProcess(OMX_HANDLETYPE hComponent) EXYNOS_OMX_BASEPORT *exynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; EXYNOS_OMX_DATABUFFER *dstOutputUseBuffer = &exynosOutputPort->way.port2WayDataBuffer.outputDataBuffer; EXYNOS_OMX_DATA *pDstOutputData = &exynosOutputPort->processData; - + FunctionIn(); while (!pVideoDec->bExitBufferProcessThread) { diff --git a/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_VdecControl.c b/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_VdecControl.c index 17c05f2..f5eb04e 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_VdecControl.c +++ b/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_VdecControl.c @@ -448,14 +448,14 @@ OMX_ERRORTYPE Exynos_OMX_FlushPort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 por Exynos_OMX_GetFlushBuffer(pExynosPort, pDataPortBuffer); if (portIndex == INPUT_PORT_INDEX) { if (pDataPortBuffer[0]->dataValid == OMX_TRUE) - Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[0]); + Exynos_InputBufferReturn(pOMXComponent, pDataPortBuffer[0]); if (pDataPortBuffer[1]->dataValid == OMX_TRUE) - Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[1]); + Exynos_InputBufferReturn(pOMXComponent, pDataPortBuffer[1]); } else if (portIndex == OUTPUT_PORT_INDEX) { if (pDataPortBuffer[0]->dataValid == OMX_TRUE) - Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[0]); + Exynos_OutputBufferReturn(pOMXComponent, pDataPortBuffer[0]); if (pDataPortBuffer[1]->dataValid == OMX_TRUE) - Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[1]); + Exynos_OutputBufferReturn(pOMXComponent, pDataPortBuffer[1]); } if (pExynosComponent->bMultiThreadProcess == OMX_TRUE) { @@ -603,59 +603,7 @@ EXIT: return ret; } -OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent) -{ - OMX_ERRORTYPE ret = OMX_ErrorNone; - EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; - EXYNOS_OMX_BASEPORT *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; - EXYNOS_OMX_DATABUFFER *dataBuffer = NULL; - OMX_BUFFERHEADERTYPE *bufferHeader = NULL; - - FunctionIn(); - - if ((exynosOMXInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.inputDataBuffer); - } else if (exynosOMXInputPort->bufferProcessType == BUFFER_SHARE) { - dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.outputDataBuffer); - } - - bufferHeader = dataBuffer->bufferHeader; - - if (bufferHeader != NULL) { - if (exynosOMXInputPort->markType.hMarkTargetComponent != NULL ) { - bufferHeader->hMarkTargetComponent = exynosOMXInputPort->markType.hMarkTargetComponent; - bufferHeader->pMarkData = exynosOMXInputPort->markType.pMarkData; - exynosOMXInputPort->markType.hMarkTargetComponent = NULL; - exynosOMXInputPort->markType.pMarkData = NULL; - } - - if (bufferHeader->hMarkTargetComponent != NULL) { - if (bufferHeader->hMarkTargetComponent == pOMXComponent) { - pExynosComponent->pCallbacks->EventHandler(pOMXComponent, - pExynosComponent->callbackData, - OMX_EventMark, - 0, 0, bufferHeader->pMarkData); - } else { - pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent; - pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData; - } - } - - bufferHeader->nFilledLen = 0; - bufferHeader->nOffset = 0; - Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader); - } - - /* reset dataBuffer */ - Exynos_ResetDataBuffer(dataBuffer); - -EXIT: - FunctionOut(); - - return ret; -} - -OMX_ERRORTYPE Exynos_FlushInputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer) +OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer) { OMX_ERRORTYPE ret = OMX_ErrorNone; EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; @@ -751,17 +699,15 @@ EXIT: return ret; } -OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent) +OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer) { OMX_ERRORTYPE ret = OMX_ErrorNone; EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; - EXYNOS_OMX_DATABUFFER *dataBuffer = NULL; OMX_BUFFERHEADERTYPE *bufferHeader = NULL; FunctionIn(); - dataBuffer = &(exynosOMXOutputPort->way.port2WayDataBuffer.outputDataBuffer); bufferHeader = dataBuffer->bufferHeader; if (bufferHeader != NULL) { @@ -801,50 +747,6 @@ EXIT: return ret; } -OMX_ERRORTYPE Exynos_FlushOutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer) -{ - OMX_ERRORTYPE ret = OMX_ErrorNone; - EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; - EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; - OMX_BUFFERHEADERTYPE *bufferHeader = NULL; - - FunctionIn(); - - bufferHeader = dataBuffer->bufferHeader; - - if (bufferHeader != NULL) { - bufferHeader->nFilledLen = dataBuffer->remainDataLen; - bufferHeader->nOffset = 0; - bufferHeader->nFlags = dataBuffer->nFlags; - bufferHeader->nTimeStamp = dataBuffer->timeStamp; - - if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) { - bufferHeader->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent; - bufferHeader->pMarkData = pExynosComponent->propagateMarkType.pMarkData; - pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL; - pExynosComponent->propagateMarkType.pMarkData = NULL; - } - - if ((bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { - Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"event OMX_BUFFERFLAG_EOS!!!"); - pExynosComponent->pCallbacks->EventHandler(pOMXComponent, - pExynosComponent->callbackData, - OMX_EventBufferFlag, - OUTPUT_PORT_INDEX, - bufferHeader->nFlags, NULL); - } - Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader); - } - - /* reset dataBuffer */ - Exynos_ResetDataBuffer(dataBuffer); - -EXIT: - FunctionOut(); - - return ret; -} - OMX_ERRORTYPE Exynos_OutputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent) { OMX_ERRORTYPE ret = OMX_ErrorUndefined; diff --git a/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_VdecControl.h b/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_VdecControl.h index 23011fa..ec2f253 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_VdecControl.h +++ b/exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_VdecControl.h @@ -87,11 +87,9 @@ OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetExtensionIndex( OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE *pIndexType); -OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent); -OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent); +OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer); +OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer); OMX_ERRORTYPE Exynos_OMX_BufferFlush(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent); -OMX_ERRORTYPE Exynos_FlushInputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer); -OMX_ERRORTYPE Exynos_FlushOutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer); #ifdef USE_ANB OMX_ERRORTYPE Exynos_Shared_ANBBufferToData(EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_PLANE nPlane); diff --git a/exynos_omx/openmax/exynos_omx/component/video/dec/h264/Exynos_OMX_H264dec.c b/exynos_omx/openmax/exynos_omx/component/video/dec/h264/Exynos_OMX_H264dec.c index c88bf70..44a4c20 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/dec/h264/Exynos_OMX_H264dec.c +++ b/exynos_omx/openmax/exynos_omx/component/video/dec/h264/Exynos_OMX_H264dec.c @@ -529,6 +529,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_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; + EXYNOS_H264DEC_HANDLE *pH264Dec = (EXYNOS_H264DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; + void *hMFCHandle = pH264Dec->hMFCH264Handle.hMFCHandle; + CODEC_DEC_BUFFER **ppCodecBuffer = NULL; + ExynosVideoDecBufferOps *pBufOps = NULL; + ExynosVideoPlane *pPlanes = NULL; + + OMX_U32 nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoDec->pMFCDecInputBuffer[0]); + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + pBufOps = pH264Dec->hMFCH264Handle.pInbufOps; + } else { + ppCodecBuffer = &(pVideoDec->pMFCDecOutputBuffer[0]); + nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE; + pBufOps = pH264Dec->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; @@ -546,6 +607,11 @@ OMX_ERRORTYPE H264CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U3 FunctionIn(); + if ((nPortIndex != INPUT_PORT_INDEX) && (nPortIndex != OUTPUT_PORT_INDEX)) { + ret = OMX_ErrorBadPortIndex; + goto EXIT; + } + if ((nPortIndex == INPUT_PORT_INDEX) && (pH264Dec->bSourceStart == OMX_TRUE)) { Exynos_CodecBufferReset(pExynosComponent, INPUT_PORT_INDEX); @@ -655,18 +721,9 @@ OMX_ERRORTYPE H264CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DAT } if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - /* Register input buffer */ - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - ExynosVideoPlane plane; - plane.addr = pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[0]; - plane.allocSize = pVideoDec->pMFCDecInputBuffer[i]->bufferSize[0]; - plane.fd = pVideoDec->pMFCDecInputBuffer[i]->fd[0]; - if (pInbufOps->Register(hMFCHandle, &plane, 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) { /* Register input buffer */ for (i = 0; i < pExynosInputPort->portDefinition.nBufferCountActual; i++) { @@ -861,31 +918,11 @@ OMX_ERRORTYPE H264CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) pH264Dec->hMFCH264Handle.codecOutbufConf.nFrameHeight >> 1); if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - MEMORY_TYPE memoryType; - if (pVideoDec->bDRMPlayerMode == OMX_TRUE) - memoryType = SECURE_MEMORY; - else - memoryType = NORMAL_MEMORY; + ret = Exynos_Allocate_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, nOutbufs, nAllocLen); + if (ret != OMX_ErrorNone) + goto EXIT; - /* Register output buffer */ for (i = 0; i < nOutbufs; i++) { - pVideoDec->pMFCDecOutputBuffer[i] = (CODEC_DEC_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_DEC_BUFFER)); - Exynos_OSAL_Memset(pVideoDec->pMFCDecOutputBuffer[i], 0, sizeof(CODEC_DEC_BUFFER)); - - for (plane = 0; plane < MFC_OUTPUT_BUFFER_PLANE; plane++) { - pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane] = - (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, nAllocLen[plane], memoryType); - if (pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane] == NULL) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc output buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - pVideoDec->pMFCDecOutputBuffer[i]->fd[plane] = - Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, - pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane]); - pVideoDec->pMFCDecOutputBuffer[i]->bufferSize[plane] = nAllocLen[plane]; - } - /* Enqueue output buffer */ pOutbufOps->ExtensionEnqueue(hMFCHandle, (unsigned char **)pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr, @@ -893,6 +930,7 @@ OMX_ERRORTYPE H264CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) (unsigned int *)pVideoDec->pMFCDecOutputBuffer[i]->bufferSize, (unsigned int *)dataLen, MFC_OUTPUT_BUFFER_PLANE, NULL); } + if (pOutbufOps->Run(hMFCHandle) != VIDEO_ERROR_NONE) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run output buffer"); ret = OMX_ErrorInsufficientResources; @@ -1440,30 +1478,16 @@ OMX_ERRORTYPE Exynos_H264Dec_Init(OMX_COMPONENTTYPE *pOMXComponent) pOutbufOps = pH264Dec->hMFCH264Handle.pOutbufOps; if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { + OMX_U32 nPlaneSize[MFC_INPUT_BUFFER_PLANE] = {DEFAULT_MFC_INPUT_BUFFER_SIZE}; Exynos_OSAL_SemaphoreCreate(&pExynosInputPort->codecSemID); Exynos_OSAL_QueueCreate(&pExynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - pVideoDec->pMFCDecInputBuffer[i] = Exynos_OSAL_Malloc(sizeof(CODEC_DEC_BUFFER)); - Exynos_OSAL_Memset(pVideoDec->pMFCDecInputBuffer[i], 0, sizeof(CODEC_DEC_BUFFER)); - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]); - - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - /* Use ION Allocator */ - pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane] = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, DEFAULT_MFC_INPUT_BUFFER_SIZE, NORMAL_MEMORY); - pVideoDec->pMFCDecInputBuffer[i]->fd[plane] = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane]); - pVideoDec->pMFCDecInputBuffer[i]->bufferSize[plane] = DEFAULT_MFC_INPUT_BUFFER_SIZE; - pVideoDec->pMFCDecInputBuffer[i]->dataSize = 0; - if (pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane] == NULL) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Fail input buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]->pVirAddr[%d]: 0x%x", i, plane, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane]); - } + 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, pVideoDec->pMFCDecInputBuffer[i]); - } } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { /*************/ /* TBD */ @@ -1549,18 +1573,7 @@ OMX_ERRORTYPE Exynos_H264Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent) pH264Dec->bSourceStart = OMX_FALSE; if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { - if (pVideoDec->pMFCDecOutputBuffer[i] != NULL) { - for (plane = 0; plane < MFC_OUTPUT_BUFFER_PLANE; plane++) { - if (pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane]); - } - - Exynos_OSAL_Free(pVideoDec->pMFCDecOutputBuffer[i]); - pVideoDec->pMFCDecOutputBuffer[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) { @@ -1571,17 +1584,7 @@ OMX_ERRORTYPE Exynos_H264Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent) } if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - if (pVideoDec->pMFCDecInputBuffer[i] != NULL) { - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - if (pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane]); - } - Exynos_OSAL_Free(pVideoDec->pMFCDecInputBuffer[i]); - pVideoDec->pMFCDecInputBuffer[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/exynos_omx/openmax/exynos_omx/component/video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c b/exynos_omx/openmax/exynos_omx/component/video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c index 95aa02a..02e04ce 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c +++ b/exynos_omx/openmax/exynos_omx/component/video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c @@ -633,6 +633,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_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; + EXYNOS_MPEG4DEC_HANDLE *pMpeg4Dec = (EXYNOS_MPEG4DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; + void *hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle; + CODEC_DEC_BUFFER **ppCodecBuffer = NULL; + ExynosVideoDecBufferOps *pBufOps = NULL; + ExynosVideoPlane *pPlanes = NULL; + + OMX_U32 nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoDec->pMFCDecInputBuffer[0]); + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + pBufOps = pMpeg4Dec->hMFCMpeg4Handle.pInbufOps; + } else { + ppCodecBuffer = &(pVideoDec->pMFCDecOutputBuffer[0]); + nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE; + pBufOps = pMpeg4Dec->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; @@ -650,6 +711,11 @@ OMX_ERRORTYPE Mpeg4CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U FunctionIn(); + if ((nPortIndex != INPUT_PORT_INDEX) && (nPortIndex != OUTPUT_PORT_INDEX)) { + ret = OMX_ErrorBadPortIndex; + goto EXIT; + } + if ((nPortIndex == INPUT_PORT_INDEX) && (pMpeg4Dec->bSourceStart == OMX_TRUE)) { Exynos_CodecBufferReset(pExynosComponent, INPUT_PORT_INDEX); @@ -763,18 +829,9 @@ OMX_ERRORTYPE Mpeg4CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DA } if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - /* Register input buffer */ - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - ExynosVideoPlane plane; - plane.addr = pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[0]; - plane.allocSize = pVideoDec->pMFCDecInputBuffer[i]->bufferSize[0]; - plane.fd = pVideoDec->pMFCDecInputBuffer[i]->fd[0]; - if (pInbufOps->Register(hMFCHandle, &plane, 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) { /* Register input buffer */ for (i = 0; i < pExynosInputPort->portDefinition.nBufferCountActual; i++) { @@ -940,25 +997,11 @@ OMX_ERRORTYPE Mpeg4CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) pMpeg4Dec->hMFCMpeg4Handle.codecOutbufConf.nFrameHeight >> 1); if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - /* Register output buffer */ - for (i = 0; i < nOutbufs; i++) { - pVideoDec->pMFCDecOutputBuffer[i] = (CODEC_DEC_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_DEC_BUFFER)); - Exynos_OSAL_Memset(pVideoDec->pMFCDecOutputBuffer[i], 0, sizeof(CODEC_DEC_BUFFER)); - - for (plane = 0; plane < MFC_OUTPUT_BUFFER_PLANE; plane++) { - pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane] = - (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, nAllocLen[plane], NORMAL_MEMORY); - if (pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane] == NULL) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc output buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - pVideoDec->pMFCDecOutputBuffer[i]->fd[plane] = - Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, - pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane]); - pVideoDec->pMFCDecOutputBuffer[i]->bufferSize[plane] = nAllocLen[plane]; - } + ret = Exynos_Allocate_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, nOutbufs, nAllocLen); + if (ret != OMX_ErrorNone) + goto EXIT; + for (i = 0; i < nOutbufs; i++) { /* Enqueue output buffer */ pOutbufOps->ExtensionEnqueue(hMFCHandle, (unsigned char **)pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr, @@ -966,6 +1009,7 @@ OMX_ERRORTYPE Mpeg4CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) (unsigned int *)pVideoDec->pMFCDecOutputBuffer[i]->bufferSize, (unsigned int *)dataLen, MFC_OUTPUT_BUFFER_PLANE, NULL); } + if (pOutbufOps->Run(hMFCHandle) != VIDEO_ERROR_NONE) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run output buffer"); ret = OMX_ErrorInsufficientResources; @@ -1577,30 +1621,15 @@ OMX_ERRORTYPE Exynos_Mpeg4Dec_Init(OMX_COMPONENTTYPE *pOMXComponent) pOutbufOps = pMpeg4Dec->hMFCMpeg4Handle.pOutbufOps; if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { + OMX_U32 nPlaneSize[MFC_INPUT_BUFFER_PLANE] = {DEFAULT_MFC_INPUT_BUFFER_SIZE}; Exynos_OSAL_SemaphoreCreate(&pExynosInputPort->codecSemID); Exynos_OSAL_QueueCreate(&pExynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); + 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++) { - pVideoDec->pMFCDecInputBuffer[i] = Exynos_OSAL_Malloc(sizeof(CODEC_DEC_BUFFER)); - Exynos_OSAL_Memset(pVideoDec->pMFCDecInputBuffer[i], 0, sizeof(CODEC_DEC_BUFFER)); - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]); - - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - /* Use ION Allocator */ - pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane] = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, DEFAULT_MFC_INPUT_BUFFER_SIZE, NORMAL_MEMORY); - pVideoDec->pMFCDecInputBuffer[i]->fd[plane] = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane]); - pVideoDec->pMFCDecInputBuffer[i]->bufferSize[plane] = DEFAULT_MFC_INPUT_BUFFER_SIZE; - pVideoDec->pMFCDecInputBuffer[i]->dataSize = 0; - if (pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane] == NULL) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Fail input buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]->pVirAddr[%d]: 0x%x", i, plane, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane]); - } - + for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoDec->pMFCDecInputBuffer[i]); - } } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { /*************/ /* TBD */ @@ -1678,18 +1707,7 @@ OMX_ERRORTYPE Exynos_Mpeg4Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent) pMpeg4Dec->bSourceStart = OMX_FALSE; if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { - if (pVideoDec->pMFCDecOutputBuffer[i] != NULL) { - for (plane = 0; plane < MFC_OUTPUT_BUFFER_PLANE; plane++) { - if (pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane]); - } - - Exynos_OSAL_Free(pVideoDec->pMFCDecOutputBuffer[i]); - pVideoDec->pMFCDecOutputBuffer[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) { @@ -1700,17 +1718,7 @@ OMX_ERRORTYPE Exynos_Mpeg4Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent) } if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - if (pVideoDec->pMFCDecInputBuffer[i] != NULL) { - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - if (pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane]); - } - Exynos_OSAL_Free(pVideoDec->pMFCDecInputBuffer[i]); - pVideoDec->pMFCDecInputBuffer[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/exynos_omx/openmax/exynos_omx/component/video/dec/vp8/Exynos_OMX_Vp8dec.c b/exynos_omx/openmax/exynos_omx/component/video/dec/vp8/Exynos_OMX_Vp8dec.c index bb8310d..1e84929 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/dec/vp8/Exynos_OMX_Vp8dec.c +++ b/exynos_omx/openmax/exynos_omx/component/video/dec/vp8/Exynos_OMX_Vp8dec.c @@ -448,6 +448,67 @@ EXIT: return ret; } +OMX_ERRORTYPE VP8CodecRegistCodecBuffers( + 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_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; + EXYNOS_VP8DEC_HANDLE *pVp8Dec = (EXYNOS_VP8DEC_HANDLE *)((EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; + void *hMFCHandle = pVp8Dec->hMFCVp8Handle.hMFCHandle; + CODEC_DEC_BUFFER **ppCodecBuffer = NULL; + ExynosVideoDecBufferOps *pBufOps = NULL; + ExynosVideoPlane *pPlanes = NULL; + + OMX_U32 nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoDec->pMFCDecInputBuffer[0]); + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + pBufOps = pVp8Dec->hMFCVp8Handle.pInbufOps; + } else { + ppCodecBuffer = &(pVideoDec->pMFCDecOutputBuffer[0]); + nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE; + pBufOps = pVp8Dec->hMFCVp8Handle.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 VP8CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) { OMX_ERRORTYPE ret = OMX_ErrorNone; @@ -465,6 +526,11 @@ OMX_ERRORTYPE VP8CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 FunctionIn(); + if ((nPortIndex != INPUT_PORT_INDEX) && (nPortIndex != OUTPUT_PORT_INDEX)) { + ret = OMX_ErrorBadPortIndex; + goto EXIT; + } + if ((nPortIndex == INPUT_PORT_INDEX) && (pVp8Dec->bSourceStart == OMX_TRUE)) { Exynos_CodecBufferReset(pExynosComponent, INPUT_PORT_INDEX); @@ -574,18 +640,9 @@ OMX_ERRORTYPE VP8CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA } if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - /* Register input buffer */ - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - ExynosVideoPlane plane; - plane.addr = pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[0]; - plane.allocSize = pVideoDec->pMFCDecInputBuffer[i]->bufferSize[0]; - plane.fd = pVideoDec->pMFCDecInputBuffer[i]->fd[0]; - if (pInbufOps->Register(hMFCHandle, &plane, MFC_INPUT_BUFFER_PLANE) != VIDEO_ERROR_NONE) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - } + ret = VP8CodecRegistCodecBuffers(pOMXComponent, INPUT_PORT_INDEX, MFC_INPUT_BUFFER_NUM_MAX); + if (ret != OMX_ErrorNone) + goto EXIT; } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { /* Register input buffer */ for (i = 0; i < pExynosInputPort->portDefinition.nBufferCountActual; i++) { @@ -751,25 +808,10 @@ OMX_ERRORTYPE VP8CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) pVp8Dec->hMFCVp8Handle.codecOutbufConf.nFrameHeight >> 1); if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - /* Register output buffer */ + ret = Exynos_Allocate_CodecBuffers(pOMXComponent, OUTPUT_PORT_INDEX, nOutbufs, nAllocLen); + if (ret != OMX_ErrorNone) + goto EXIT; for (i = 0; i < nOutbufs; i++) { - pVideoDec->pMFCDecOutputBuffer[i] = (CODEC_DEC_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_DEC_BUFFER)); - Exynos_OSAL_Memset(pVideoDec->pMFCDecOutputBuffer[i], 0, sizeof(CODEC_DEC_BUFFER)); - - for (plane = 0; plane < MFC_OUTPUT_BUFFER_PLANE; plane++) { - pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane] = - (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, nAllocLen[plane], NORMAL_MEMORY); - if (pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane] == NULL) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc output buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - pVideoDec->pMFCDecOutputBuffer[i]->fd[plane] = - Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, - pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane]); - pVideoDec->pMFCDecOutputBuffer[i]->bufferSize[plane] = nAllocLen[plane]; - } - /* Enqueue output buffer */ pOutbufOps->ExtensionEnqueue(hMFCHandle, (unsigned char **)pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr, @@ -777,6 +819,7 @@ OMX_ERRORTYPE VP8CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) (unsigned int *)pVideoDec->pMFCDecOutputBuffer[i]->bufferSize, (unsigned int *)dataLen, MFC_OUTPUT_BUFFER_PLANE, NULL); } + if (pOutbufOps->Run(hMFCHandle) != VIDEO_ERROR_NONE) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run output buffer"); ret = OMX_ErrorInsufficientResources; @@ -1168,30 +1211,15 @@ OMX_ERRORTYPE Exynos_VP8Dec_Init(OMX_COMPONENTTYPE *pOMXComponent) pOutbufOps = pVp8Dec->hMFCVp8Handle.pOutbufOps; if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { + OMX_U32 nPlaneSize[MFC_INPUT_BUFFER_PLANE] = {DEFAULT_MFC_INPUT_BUFFER_SIZE}; Exynos_OSAL_SemaphoreCreate(&pExynosInputPort->codecSemID); Exynos_OSAL_QueueCreate(&pExynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); + 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++) { - pVideoDec->pMFCDecInputBuffer[i] = Exynos_OSAL_Malloc(sizeof(CODEC_DEC_BUFFER)); - Exynos_OSAL_Memset(pVideoDec->pMFCDecInputBuffer[i], 0, sizeof(CODEC_DEC_BUFFER)); - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]: 0x%x", i, pVideoDec->pMFCDecInputBuffer[i]); - - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - /* Use ION Allocator */ - pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane] = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, DEFAULT_MFC_INPUT_BUFFER_SIZE, NORMAL_MEMORY); - pVideoDec->pMFCDecInputBuffer[i]->fd[plane] = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane]); - pVideoDec->pMFCDecInputBuffer[i]->bufferSize[plane] = DEFAULT_MFC_INPUT_BUFFER_SIZE; - pVideoDec->pMFCDecInputBuffer[i]->dataSize = 0; - if (pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane] == NULL) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Fail input buffer"); - ret = OMX_ErrorInsufficientResources; - goto EXIT; - } - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoDec->pMFCDecInputBuffer[%d]->pVirAddr[%d]: 0x%x", i, plane, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane]); - } - + for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoDec->pMFCDecInputBuffer[i]); - } } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { /*************/ /* TBD */ @@ -1269,18 +1297,7 @@ OMX_ERRORTYPE Exynos_VP8Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent) pVp8Dec->bSourceStart = OMX_FALSE; if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { - if (pVideoDec->pMFCDecOutputBuffer[i] != NULL) { - for (plane = 0; plane < MFC_OUTPUT_BUFFER_PLANE; plane++) { - if (pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pVideoDec->pMFCDecOutputBuffer[i]->pVirAddr[plane]); - } - - Exynos_OSAL_Free(pVideoDec->pMFCDecOutputBuffer[i]); - pVideoDec->pMFCDecOutputBuffer[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) { @@ -1291,17 +1308,7 @@ OMX_ERRORTYPE Exynos_VP8Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent) } if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { - if (pVideoDec->pMFCDecInputBuffer[i] != NULL) { - for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { - if (pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane] != NULL) - Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pVideoDec->pMFCDecInputBuffer[i]->pVirAddr[plane]); - } - Exynos_OSAL_Free(pVideoDec->pMFCDecInputBuffer[i]); - pVideoDec->pMFCDecInputBuffer[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/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_Venc.c b/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_Venc.c index 68ceaaf..092265d 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_Venc.c +++ b/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_Venc.c @@ -80,6 +80,110 @@ 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 nBufferCnt = 0, nPlaneCnt = 0; + int i, j; + + FunctionIn(); + + if (nPortIndex == INPUT_PORT_INDEX) { + ppCodecBuffer = &(pVideoEnc->pMFCEncInputBuffer[0]); + nBufferCnt = MFC_INPUT_BUFFER_NUM_MAX; + nPlaneCnt = MFC_INPUT_BUFFER_PLANE; + } else { + ppCodecBuffer = &(pVideoEnc->pMFCEncOutputBuffer[0]); + nBufferCnt = MFC_OUTPUT_BUFFER_NUM_MAX; + nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE; + } + + for (i = 0; i < nBufferCnt; 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 = SYSTEM_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; +#ifdef USE_CSC_HW + eMemoryType = NORMAL_MEMORY; +#endif + } + + 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; @@ -344,7 +448,7 @@ OMX_BOOL Exynos_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ if (inputUseBuffer->dataLen <= 0) { if (!(inputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS)) { - Exynos_InputBufferReturn(pOMXComponent); + Exynos_InputBufferReturn(pOMXComponent, inputUseBuffer); /* reset dataBuffer */ Exynos_ResetDataBuffer(inputUseBuffer); @@ -446,7 +550,7 @@ OMX_BOOL Exynos_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ if (((exynosInputPort->bStoreMetaData == OMX_TRUE) && (eColorFormat == OMX_COLOR_FormatAndroidOpaque)) || (exynosInputPort->bStoreMetaData == OMX_FALSE)) { - Exynos_InputBufferReturn(pOMXComponent); + Exynos_InputBufferReturn(pOMXComponent, inputUseBuffer); } else { inputUseBuffer->dataValid = OMX_TRUE; } @@ -527,7 +631,7 @@ OMX_BOOL Exynos_Postprocess_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ if ((outputUseBuffer->remainDataLen > 0) || (outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS)) { - Exynos_OutputBufferReturn(pOMXComponent); + Exynos_OutputBufferReturn(pOMXComponent, outputUseBuffer); } } else { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "output buffer is smaller than encoded data size Out Length"); @@ -540,7 +644,7 @@ OMX_BOOL Exynos_Postprocess_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ if ((outputUseBuffer->remainDataLen > 0) || ((outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) || (CHECK_PORT_BEING_FLUSHED(exynosOutputPort))) - Exynos_OutputBufferReturn(pOMXComponent); + Exynos_OutputBufferReturn(pOMXComponent, outputUseBuffer); } } else { ret = OMX_FALSE; @@ -580,41 +684,19 @@ OMX_ERRORTYPE Exynos_OMX_ExtensionSetup(OMX_HANDLETYPE hComponent) } if ((exynosInputPort->bufferProcessType & BUFFER_COPY) == 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(&exynosInputPort->codecSemID); Exynos_OSAL_QueueCreate(&exynosInputPort->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 (exynosInputPort->bufferProcessType == BUFFER_SHARE) { /*************/ /* TBD */ @@ -752,7 +834,7 @@ OMX_ERRORTYPE Exynos_OMX_SrcOutputBufferProcess(OMX_HANDLETYPE hComponent) } if (exynosInputPort->bufferProcessType == BUFFER_SHARE) { Exynos_Shared_DataToBuffer(&srcOutputData, srcOutputUseBuffer); - Exynos_InputBufferReturn(pOMXComponent); + Exynos_InputBufferReturn(pOMXComponent, srcOutputUseBuffer); } Exynos_ResetCodecData(&srcOutputData); } @@ -776,7 +858,7 @@ OMX_ERRORTYPE Exynos_OMX_DstInputBufferProcess(OMX_HANDLETYPE hComponent) EXYNOS_OMX_BASEPORT *exynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; EXYNOS_OMX_DATABUFFER *dstInputUseBuffer = &exynosOutputPort->way.port2WayDataBuffer.inputDataBuffer; EXYNOS_OMX_DATA dstInputData; - + FunctionIn(); while (!pVideoEnc->bExitBufferProcessThread) { @@ -843,7 +925,7 @@ OMX_ERRORTYPE Exynos_OMX_DstOutputBufferProcess(OMX_HANDLETYPE hComponent) EXYNOS_OMX_BASEPORT *exynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; EXYNOS_OMX_DATABUFFER *dstOutputUseBuffer = &exynosOutputPort->way.port2WayDataBuffer.outputDataBuffer; EXYNOS_OMX_DATA *pDstOutputData = &exynosOutputPort->processData; - + FunctionIn(); while (!pVideoEnc->bExitBufferProcessThread) { diff --git a/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_VencControl.c b/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_VencControl.c index aa1315b..5c5858a 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_VencControl.c +++ b/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_VencControl.c @@ -82,11 +82,12 @@ OMX_ERRORTYPE Exynos_OMX_UseBuffer( } pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; - pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; if (nPortIndex >= pExynosComponent->portParam.nPorts) { ret = OMX_ErrorBadPortIndex; goto EXIT; } + pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; + if (pExynosPort->portState != OMX_StateIdle) { ret = OMX_ErrorIncorrectStateOperation; goto EXIT; @@ -176,11 +177,11 @@ OMX_ERRORTYPE Exynos_OMX_AllocateBuffer( pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; - pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; if (nPortIndex >= pExynosComponent->portParam.nPorts) { ret = OMX_ErrorBadPortIndex; goto EXIT; } + pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; /* if (pExynosPort->portState != OMX_StateIdle ) { ret = OMX_ErrorIncorrectStateOperation; @@ -281,6 +282,11 @@ OMX_ERRORTYPE Exynos_OMX_FreeBuffer( } pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; + + if (nPortIndex >= pExynosComponent->portParam.nPorts) { + ret = OMX_ErrorBadPortIndex; + goto EXIT; + } pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { @@ -436,14 +442,14 @@ OMX_ERRORTYPE Exynos_OMX_FlushPort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 por Exynos_OMX_GetFlushBuffer(pExynosPort, pDataPortBuffer); if (portIndex == INPUT_PORT_INDEX) { if (pDataPortBuffer[0]->dataValid == OMX_TRUE) - Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[0]); + Exynos_InputBufferReturn(pOMXComponent, pDataPortBuffer[0]); if (pDataPortBuffer[1]->dataValid == OMX_TRUE) - Exynos_FlushInputBufferReturn(pOMXComponent, pDataPortBuffer[1]); + Exynos_InputBufferReturn(pOMXComponent, pDataPortBuffer[1]); } else if (portIndex == OUTPUT_PORT_INDEX) { if (pDataPortBuffer[0]->dataValid == OMX_TRUE) - Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[0]); + Exynos_OutputBufferReturn(pOMXComponent, pDataPortBuffer[0]); if (pDataPortBuffer[1]->dataValid == OMX_TRUE) - Exynos_FlushOutputBufferReturn(pOMXComponent, pDataPortBuffer[1]); + Exynos_OutputBufferReturn(pOMXComponent, pDataPortBuffer[1]); } if (pExynosComponent->bMultiThreadProcess == OMX_TRUE) { @@ -577,67 +583,15 @@ EXIT: return ret; } -OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent) +OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer) { OMX_ERRORTYPE ret = OMX_ErrorNone; EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; EXYNOS_OMX_BASEPORT *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; - EXYNOS_OMX_DATABUFFER *dataBuffer = NULL; OMX_BUFFERHEADERTYPE *bufferHeader = NULL; FunctionIn(); - if ((exynosOMXInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { - dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.inputDataBuffer); - } else if (exynosOMXInputPort->bufferProcessType == BUFFER_SHARE) { - dataBuffer = &(exynosOMXInputPort->way.port2WayDataBuffer.outputDataBuffer); - } - - bufferHeader = dataBuffer->bufferHeader; - - if (bufferHeader != NULL) { - if (exynosOMXInputPort->markType.hMarkTargetComponent != NULL ) { - bufferHeader->hMarkTargetComponent = exynosOMXInputPort->markType.hMarkTargetComponent; - bufferHeader->pMarkData = exynosOMXInputPort->markType.pMarkData; - exynosOMXInputPort->markType.hMarkTargetComponent = NULL; - exynosOMXInputPort->markType.pMarkData = NULL; - } - - if (bufferHeader->hMarkTargetComponent != NULL) { - if (bufferHeader->hMarkTargetComponent == pOMXComponent) { - pExynosComponent->pCallbacks->EventHandler(pOMXComponent, - pExynosComponent->callbackData, - OMX_EventMark, - 0, 0, bufferHeader->pMarkData); - } else { - pExynosComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent; - pExynosComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData; - } - } - - bufferHeader->nFilledLen = 0; - bufferHeader->nOffset = 0; - Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader); - } - - /* reset dataBuffer */ - Exynos_ResetDataBuffer(dataBuffer); - -EXIT: - FunctionOut(); - - return ret; -} - -OMX_ERRORTYPE Exynos_FlushInputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer) -{ - OMX_ERRORTYPE ret = OMX_ErrorNone; - EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; - EXYNOS_OMX_BASEPORT *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; - OMX_BUFFERHEADERTYPE *bufferHeader = NULL; - - FunctionIn(); - bufferHeader = dataBuffer->bufferHeader; if (bufferHeader != NULL) { @@ -725,17 +679,15 @@ EXIT: return ret; } -OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent) +OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer) { OMX_ERRORTYPE ret = OMX_ErrorNone; EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; - EXYNOS_OMX_DATABUFFER *dataBuffer = NULL; OMX_BUFFERHEADERTYPE *bufferHeader = NULL; FunctionIn(); - dataBuffer = &(exynosOMXOutputPort->way.port2WayDataBuffer.outputDataBuffer); bufferHeader = dataBuffer->bufferHeader; if (bufferHeader != NULL) { @@ -772,50 +724,6 @@ EXIT: return ret; } -OMX_ERRORTYPE Exynos_FlushOutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer) -{ - OMX_ERRORTYPE ret = OMX_ErrorNone; - EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; - EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; - OMX_BUFFERHEADERTYPE *bufferHeader = NULL; - - FunctionIn(); - - bufferHeader = dataBuffer->bufferHeader; - - if (bufferHeader != NULL) { - bufferHeader->nFilledLen = dataBuffer->remainDataLen; - bufferHeader->nOffset = 0; - bufferHeader->nFlags = dataBuffer->nFlags; - bufferHeader->nTimeStamp = dataBuffer->timeStamp; - - if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) { - bufferHeader->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent; - bufferHeader->pMarkData = pExynosComponent->propagateMarkType.pMarkData; - pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL; - pExynosComponent->propagateMarkType.pMarkData = NULL; - } - - if ((bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { - Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"event OMX_BUFFERFLAG_EOS!!!"); - pExynosComponent->pCallbacks->EventHandler(pOMXComponent, - pExynosComponent->callbackData, - OMX_EventBufferFlag, - OUTPUT_PORT_INDEX, - bufferHeader->nFlags, NULL); - } - Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader); - } - - /* reset dataBuffer */ - Exynos_ResetDataBuffer(dataBuffer); - -EXIT: - FunctionOut(); - - return ret; -} - OMX_ERRORTYPE Exynos_OutputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent) { OMX_ERRORTYPE ret = OMX_ErrorUndefined; @@ -1167,7 +1075,6 @@ OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetParameter( videoQuantizationControl->nQpB = pVideoEnc->quantization.nQpB; } ret = OMX_ErrorNone; - } break; case OMX_IndexParamPortDefinition: diff --git a/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_VencControl.h b/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_VencControl.h index 61bd7bb..9a8b99f 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_VencControl.h +++ b/exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_VencControl.h @@ -1,100 +1,98 @@ -/* - * - * Copyright 2012 Samsung Electronics S.LSI Co. LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * @file Exynos_OMX_VencControl.h - * @brief - * @author SeungBeom Kim (sbcrux.kim@samsung.com) - * @version 2.0.0 - * @history - * 2012.02.20 : Create - */ - -#ifndef EXYNOS_OMX_VIDEO_ENCODECONTROL -#define EXYNOS_OMX_VIDEO_ENCODECONTROL - -#include "OMX_Component.h" -#include "Exynos_OMX_Def.h" -#include "Exynos_OSAL_Queue.h" -#include "Exynos_OMX_Baseport.h" -#include "Exynos_OMX_Basecomponent.h" - - -#ifdef __cplusplus -extern "C" { -#endif - -OMX_ERRORTYPE Exynos_OMX_UseBuffer( - OMX_IN OMX_HANDLETYPE hComponent, - OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr, - OMX_IN OMX_U32 nPortIndex, - OMX_IN OMX_PTR pAppPrivate, - OMX_IN OMX_U32 nSizeBytes, - OMX_IN OMX_U8 *pBuffer); -OMX_ERRORTYPE Exynos_OMX_AllocateBuffer( - OMX_IN OMX_HANDLETYPE hComponent, - OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer, - OMX_IN OMX_U32 nPortIndex, - OMX_IN OMX_PTR pAppPrivate, - OMX_IN OMX_U32 nSizeBytes); -OMX_ERRORTYPE Exynos_OMX_FreeBuffer( - OMX_IN OMX_HANDLETYPE hComponent, - OMX_IN OMX_U32 nPortIndex, - OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr); -OMX_ERRORTYPE Exynos_OMX_AllocateTunnelBuffer( - EXYNOS_OMX_BASEPORT *pOMXBasePort, - OMX_U32 nPortIndex); -OMX_ERRORTYPE Exynos_OMX_FreeTunnelBuffer( - EXYNOS_OMX_BASEPORT *pOMXBasePort, - OMX_U32 nPortIndex); -OMX_ERRORTYPE Exynos_OMX_ComponentTunnelRequest( - OMX_IN OMX_HANDLETYPE hComp, - OMX_IN OMX_U32 nPort, - OMX_IN OMX_HANDLETYPE hTunneledComp, - OMX_IN OMX_U32 nTunneledPort, - OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup); -OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetParameter( - OMX_IN OMX_HANDLETYPE hComponent, - OMX_IN OMX_INDEXTYPE nParamIndex, - OMX_INOUT OMX_PTR ComponentParameterStructure); -OMX_ERRORTYPE Exynos_OMX_VideoEncodeSetParameter( - OMX_IN OMX_HANDLETYPE hComponent, - OMX_IN OMX_INDEXTYPE nIndex, - OMX_IN OMX_PTR ComponentParameterStructure); -OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetConfig( - OMX_HANDLETYPE hComponent, - OMX_INDEXTYPE nIndex, - OMX_PTR pComponentConfigStructure); -OMX_ERRORTYPE Exynos_OMX_VideoEncodeSetConfig( - OMX_HANDLETYPE hComponent, - OMX_INDEXTYPE nIndex, - OMX_PTR pComponentConfigStructure); -OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetExtensionIndex( - OMX_IN OMX_HANDLETYPE hComponent, - OMX_IN OMX_STRING cParameterName, - OMX_OUT OMX_INDEXTYPE *pIndexType); -OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent); -OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent); -OMX_ERRORTYPE Exynos_OMX_BufferFlush(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent); -OMX_ERRORTYPE Exynos_FlushInputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer); -OMX_ERRORTYPE Exynos_FlushOutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer); -#ifdef __cplusplus -} -#endif - -#endif - +/* + * + * Copyright 2012 Samsung Electronics S.LSI Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @file Exynos_OMX_VencControl.h + * @brief + * @author SeungBeom Kim (sbcrux.kim@samsung.com) + * @version 2.0.0 + * @history + * 2012.02.20 : Create + */ + +#ifndef EXYNOS_OMX_VIDEO_ENCODECONTROL +#define EXYNOS_OMX_VIDEO_ENCODECONTROL + +#include "OMX_Component.h" +#include "Exynos_OMX_Def.h" +#include "Exynos_OSAL_Queue.h" +#include "Exynos_OMX_Baseport.h" +#include "Exynos_OMX_Basecomponent.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +OMX_ERRORTYPE Exynos_OMX_UseBuffer( + OMX_IN OMX_HANDLETYPE hComponent, + OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr, + OMX_IN OMX_U32 nPortIndex, + OMX_IN OMX_PTR pAppPrivate, + OMX_IN OMX_U32 nSizeBytes, + OMX_IN OMX_U8 *pBuffer); +OMX_ERRORTYPE Exynos_OMX_AllocateBuffer( + OMX_IN OMX_HANDLETYPE hComponent, + OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer, + OMX_IN OMX_U32 nPortIndex, + OMX_IN OMX_PTR pAppPrivate, + OMX_IN OMX_U32 nSizeBytes); +OMX_ERRORTYPE Exynos_OMX_FreeBuffer( + OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_U32 nPortIndex, + OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr); +OMX_ERRORTYPE Exynos_OMX_AllocateTunnelBuffer( + EXYNOS_OMX_BASEPORT *pOMXBasePort, + OMX_U32 nPortIndex); +OMX_ERRORTYPE Exynos_OMX_FreeTunnelBuffer( + EXYNOS_OMX_BASEPORT *pOMXBasePort, + OMX_U32 nPortIndex); +OMX_ERRORTYPE Exynos_OMX_ComponentTunnelRequest( + OMX_IN OMX_HANDLETYPE hComp, + OMX_IN OMX_U32 nPort, + OMX_IN OMX_HANDLETYPE hTunneledComp, + OMX_IN OMX_U32 nTunneledPort, + OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup); +OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetParameter( + OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_INDEXTYPE nParamIndex, + OMX_INOUT OMX_PTR ComponentParameterStructure); +OMX_ERRORTYPE Exynos_OMX_VideoEncodeSetParameter( + OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_INDEXTYPE nIndex, + OMX_IN OMX_PTR ComponentParameterStructure); +OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetConfig( + OMX_HANDLETYPE hComponent, + OMX_INDEXTYPE nIndex, + OMX_PTR pComponentConfigStructure); +OMX_ERRORTYPE Exynos_OMX_VideoEncodeSetConfig( + OMX_HANDLETYPE hComponent, + OMX_INDEXTYPE nIndex, + OMX_PTR pComponentConfigStructure); +OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetExtensionIndex( + OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_STRING cParameterName, + OMX_OUT OMX_INDEXTYPE *pIndexType); +OMX_ERRORTYPE Exynos_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer); +OMX_ERRORTYPE Exynos_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATABUFFER *dataBuffer); +OMX_ERRORTYPE Exynos_OMX_BufferFlush(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent); +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/exynos_omx/openmax/exynos_omx/component/video/enc/h264/Exynos_OMX_H264enc.c b/exynos_omx/openmax/exynos_omx/component/video/enc/h264/Exynos_OMX_H264enc.c index 1349a0a..12f8178 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/enc/h264/Exynos_OMX_H264enc.c +++ b/exynos_omx/openmax/exynos_omx/component/video/enc/h264/Exynos_OMX_H264enc.c @@ -691,6 +691,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; @@ -708,6 +769,11 @@ OMX_ERRORTYPE H264CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U3 FunctionIn(); + if ((nPortIndex != INPUT_PORT_INDEX) && (nPortIndex != OUTPUT_PORT_INDEX)) { + ret = OMX_ErrorBadPortIndex; + goto EXIT; + } + if ((nPortIndex == INPUT_PORT_INDEX) && (pH264Enc->bSourceStart == OMX_TRUE)) { Exynos_CodecBufferReset(pExynosComponent, INPUT_PORT_INDEX); @@ -843,19 +909,9 @@ OMX_ERRORTYPE H264CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DAT int plane; if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == 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) { /*************/ @@ -932,35 +988,23 @@ OMX_ERRORTYPE H264CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) OMX_U32 dataLen[MFC_OUTPUT_BUFFER_PLANE] = {0}; if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == 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); } } else if ((pExynosOutputPort->bufferProcessType & BUFFER_SHARE) == BUFFER_SHARE) { - /* Register input buffer */ + /* Register output buffer */ /*************/ /* TBD */ /*************/ @@ -970,7 +1014,7 @@ OMX_ERRORTYPE H264CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) plane.fd = pExynosOutputPort->extendBufferHeader[i].buf_fd[0]; plane.allocSize = OutBufferSize; if (pOutbufOps->Register(hMFCHandle, &plane, MFC_OUTPUT_BUFFER_PLANE) != VIDEO_ERROR_NONE) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); + Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register output buffer"); ret = OMX_ErrorInsufficientResources; goto EXIT; } @@ -1585,41 +1629,19 @@ OMX_ERRORTYPE Exynos_H264Enc_Init(OMX_COMPONENTTYPE *pOMXComponent) if ((pExynosInputPort->bStoreMetaData != OMX_TRUE) && (eColorFormat != OMX_COLOR_FormatAndroidOpaque)) { if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == 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 */ @@ -1683,15 +1705,7 @@ OMX_ERRORTYPE Exynos_H264Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) pH264Enc->bSourceStart = OMX_FALSE; if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == 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) { @@ -1702,17 +1716,7 @@ OMX_ERRORTYPE Exynos_H264Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) } if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == 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/exynos_omx/openmax/exynos_omx/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c b/exynos_omx/openmax/exynos_omx/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c index 51c20b7..883f12b 100644 --- a/exynos_omx/openmax/exynos_omx/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c +++ b/exynos_omx/openmax/exynos_omx/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c @@ -819,6 +819,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; @@ -836,6 +897,11 @@ OMX_ERRORTYPE Mpeg4CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U FunctionIn(); + if ((nPortIndex != INPUT_PORT_INDEX) && (nPortIndex != OUTPUT_PORT_INDEX)) { + ret = OMX_ErrorBadPortIndex; + goto EXIT; + } + if ((nPortIndex == INPUT_PORT_INDEX) && (pMpeg4Enc->bSourceStart == OMX_TRUE)) { Exynos_CodecBufferReset(pExynosComponent, INPUT_PORT_INDEX); @@ -968,19 +1034,9 @@ OMX_ERRORTYPE Mpeg4CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DA int plane; if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == 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) { /*************/ @@ -1064,30 +1120,18 @@ OMX_ERRORTYPE Mpeg4CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) OMX_U32 dataLen[MFC_OUTPUT_BUFFER_PLANE] = {0}; if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == 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); } @@ -1102,7 +1146,7 @@ OMX_ERRORTYPE Mpeg4CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) plane.fd = pExynosOutputPort->extendBufferHeader[i].buf_fd[0]; plane.allocSize = OutBufferSize; if (pOutbufOps->Register(hMFCHandle, &plane, MFC_OUTPUT_BUFFER_PLANE) != VIDEO_ERROR_NONE) { - Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); + Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register output buffer"); ret = OMX_ErrorInsufficientResources; goto EXIT; } @@ -1783,41 +1827,19 @@ OMX_ERRORTYPE Exynos_Mpeg4Enc_Init(OMX_COMPONENTTYPE *pOMXComponent) if ((pExynosInputPort->bStoreMetaData != OMX_TRUE) && (eColorFormat != OMX_COLOR_FormatAndroidOpaque)) { if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == 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 */ @@ -1881,15 +1903,7 @@ OMX_ERRORTYPE Exynos_Mpeg4Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) pMpeg4Enc->bSourceStart = OMX_FALSE; if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == 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) { @@ -1900,17 +1914,7 @@ OMX_ERRORTYPE Exynos_Mpeg4Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) } if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == 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/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Android.cpp b/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Android.cpp index 7f10331..e5d5f71 100644 --- a/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Android.cpp +++ b/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Android.cpp @@ -682,7 +682,6 @@ OMX_ERRORTYPE Exynos_OSAL_SetANBParameter( goto EXIT; } - switch (nIndex) { case OMX_IndexParamEnableAndroidBuffers: { diff --git a/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Queue.c b/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Queue.c index 4f226f7..fa9583c 100644 --- a/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Queue.c +++ b/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Queue.c @@ -167,7 +167,7 @@ int Exynos_OSAL_SetElemNum(EXYNOS_QUEUE *queueHandle, int ElemNum) return -1; Exynos_OSAL_MutexLock(queue->qMutex); - queue->numElem = ElemNum; + queue->numElem = ElemNum; Exynos_OSAL_MutexUnlock(queue->qMutex); return ElemNum; } diff --git a/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_SharedMemory.c b/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_SharedMemory.c index 775d48b..76f0d16 100644 --- a/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_SharedMemory.c +++ b/exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_SharedMemory.c @@ -50,7 +50,7 @@ typedef struct _EXYNOS_SHAREDMEM_LIST OMX_U32 IONBuffer; OMX_PTR mapAddr; OMX_U32 allocSize; - bool owner; + OMX_BOOL owner; struct _EXYNOS_SHAREDMEM_LIST *pNextMemory; } EXYNOS_SHAREDMEM_LIST; @@ -152,7 +152,7 @@ OMX_PTR Exynos_OSAL_SharedMemory_Alloc(OMX_HANDLETYPE handle, OMX_U32 size, MEMO pElement = (EXYNOS_SHAREDMEM_LIST *)Exynos_OSAL_Malloc(sizeof(EXYNOS_SHAREDMEM_LIST)); Exynos_OSAL_Memset(pElement, 0, sizeof(EXYNOS_SHAREDMEM_LIST)); - pElement->owner = true; + pElement->owner = OMX_TRUE; switch (memoryType) { case SECURE_MEMORY: @@ -174,7 +174,6 @@ OMX_PTR Exynos_OSAL_SharedMemory_Alloc(OMX_HANDLETYPE handle, OMX_U32 size, MEMO } IONBuffer = ion_alloc((ion_client)pHandle->hIONHandle, size, 0, mask, flag); - if (IONBuffer <= 0) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "ion_alloc Error: %d", IONBuffer); Exynos_OSAL_Free((OMX_PTR)pElement); -- 2.20.1