From: Satish Kumar Reddy Date: Mon, 29 Oct 2012 04:33:17 +0000 (+0900) Subject: video/osal: Support both DMABUF and virtual address X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=faa0e22c3bf6d0ef7b61540179e6b13f4a2b2a3b;p=GitHub%2FLineageOS%2Fandroid_hardware_samsung_slsi_openmax.git video/osal: Support both DMABUF and virtual address DMABUF can be enabled by this marco BOARD_USE_DMA_BUF Change-Id: Ie38db57250368dae208a8cca3cc7d7a73f5a6e63 Signed-off-by: Satish Kumar Reddy Signed-off-by: Huisung Kang --- diff --git a/component/video/dec/Android.mk b/component/video/dec/Android.mk index 59254b3..5d3ff78 100644 --- a/component/video/dec/Android.mk +++ b/component/video/dec/Android.mk @@ -33,4 +33,8 @@ LOCAL_STATIC_LIBRARIES += libExynosOMX_OSAL libcsc_helper LOCAL_CFLAGS += -DUSE_ANB endif +ifeq ($(BOARD_USE_DMA_BUF), true) +LOCAL_CFLAGS += -DUSE_DMA_BUF +endif + include $(BUILD_STATIC_LIBRARY) diff --git a/component/video/dec/Exynos_OMX_Vdec.c b/component/video/dec/Exynos_OMX_Vdec.c index 31d96eb..098e646 100644 --- a/component/video/dec/Exynos_OMX_Vdec.c +++ b/component/video/dec/Exynos_OMX_Vdec.c @@ -238,11 +238,13 @@ OMX_BOOL Exynos_CSC_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA pYUVBuf[2] = (unsigned char *)pOutputBuf + imageSize + imageSize / 4; csc_get_method(pVideoDec->csc_handle, &csc_method); +#ifdef USE_DMA_BUF if (csc_method == CSC_METHOD_HW) { pSrcBuf[0] = dstOutputData->buffer.multiPlaneBuffer.fd[0]; pSrcBuf[1] = dstOutputData->buffer.multiPlaneBuffer.fd[1]; pSrcBuf[2] = dstOutputData->buffer.multiPlaneBuffer.fd[2]; } +#endif #ifdef USE_ANB if (exynosOutputPort->bIsANBEnabled == OMX_TRUE) { @@ -252,23 +254,26 @@ OMX_BOOL Exynos_CSC_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA width = stride; outputUseBuffer->dataLen = sizeof(void *); - if (csc_method == CSC_METHOD_SW) { - pYUVBuf[0] = (unsigned char *)planes[0].addr; - pYUVBuf[1] = (unsigned char *)planes[1].addr; - pYUVBuf[2] = (unsigned char *)planes[2].addr; - } else { + pYUVBuf[0] = (unsigned char *)planes[0].addr; + pYUVBuf[1] = (unsigned char *)planes[1].addr; + pYUVBuf[2] = (unsigned char *)planes[2].addr; +#ifdef USE_DMA_BUF + if (csc_method == CSC_METHOD_HW) { pYUVBuf[0] = (unsigned char *)planes[0].fd; pYUVBuf[1] = (unsigned char *)planes[1].fd; pYUVBuf[2] = (unsigned char *)planes[2].fd; } +#endif } #endif +#ifdef USE_DMA_BUF if ((exynosOutputPort->bIsANBEnabled == OMX_FALSE) && (csc_method == CSC_METHOD_HW)) { pYUVBuf[0] = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, pOutputBuf); pYUVBuf[1] = NULL; pYUVBuf[2] = NULL; } +#endif if (pVideoDec->csc_set_format == OMX_FALSE) { csc_set_src_format( diff --git a/component/video/dec/Exynos_OMX_VdecControl.c b/component/video/dec/Exynos_OMX_VdecControl.c index 447bb74..a99b8be 100644 --- a/component/video/dec/Exynos_OMX_VdecControl.c +++ b/component/video/dec/Exynos_OMX_VdecControl.c @@ -1522,9 +1522,11 @@ OMX_ERRORTYPE Exynos_Shared_ANBBufferToData(EXYNOS_OMX_DATABUFFER *pUseBuffer, E if (nPlane == TWO_PLANE) { /* Case of Shared Buffer, Only support two PlaneBuffer */ pData->buffer.multiPlaneBuffer.dataBuffer[0] = planes[0].addr; - pData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd; pData->buffer.multiPlaneBuffer.dataBuffer[1] = planes[1].addr; +#ifdef USE_DMA_BUF + pData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd; pData->buffer.multiPlaneBuffer.fd[1] = planes[1].fd; +#endif } else { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not support plane"); ret = OMX_ErrorNotImplemented; diff --git a/component/video/dec/h264/Android.mk b/component/video/dec/h264/Android.mk index 60c9993..3890fc2 100644 --- a/component/video/dec/h264/Android.mk +++ b/component/video/dec/h264/Android.mk @@ -17,6 +17,10 @@ ifeq ($(BOARD_USE_ANB), true) LOCAL_CFLAGS += -DUSE_ANB endif +ifeq ($(BOARD_USE_DMA_BUF), true) +LOCAL_CFLAGS += -DUSE_DMA_BUF +endif + ifeq ($(BOARD_USE_S3D_SUPPORT), true) LOCAL_CFLAGS += -DUSE_S3D_SUPPORT endif diff --git a/component/video/dec/h264/Exynos_OMX_H264dec.c b/component/video/dec/h264/Exynos_OMX_H264dec.c index b834316..9de204d 100644 --- a/component/video/dec/h264/Exynos_OMX_H264dec.c +++ b/component/video/dec/h264/Exynos_OMX_H264dec.c @@ -309,7 +309,11 @@ OMX_ERRORTYPE H264CodecOpen(EXYNOS_H264DEC_HANDLE *pH264Dec) } /* alloc context, open, querycap */ +#ifdef USE_DMA_BUF pH264Dec->hMFCH264Handle.hMFCHandle = pH264Dec->hMFCH264Handle.pDecOps->Init(V4L2_MEMORY_DMABUF); +#else + pH264Dec->hMFCH264Handle.hMFCHandle = pH264Dec->hMFCH264Handle.pDecOps->Init(V4L2_MEMORY_USERPTR); +#endif if (pH264Dec->hMFCH264Handle.hMFCHandle == NULL) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate context buffer"); ret = OMX_ErrorInsufficientResources; diff --git a/component/video/dec/mpeg4/Android.mk b/component/video/dec/mpeg4/Android.mk index 21d5fb6..4875212 100644 --- a/component/video/dec/mpeg4/Android.mk +++ b/component/video/dec/mpeg4/Android.mk @@ -17,6 +17,10 @@ ifeq ($(BOARD_USE_ANB), true) LOCAL_CFLAGS += -DUSE_ANB endif +ifeq ($(BOARD_USE_DMA_BUF), true) +LOCAL_CFLAGS += -DUSE_DMA_BUF +endif + LOCAL_ARM_MODE := arm LOCAL_STATIC_LIBRARIES := libExynosOMX_Vdec libExynosOMX_OSAL libExynosOMX_Basecomponent \ diff --git a/component/video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c b/component/video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c index 9c7238b..f0e9222 100644 --- a/component/video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c +++ b/component/video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c @@ -410,7 +410,11 @@ OMX_ERRORTYPE Mpeg4CodecOpen(EXYNOS_MPEG4DEC_HANDLE *pMpeg4Dec) } /* alloc context, open, querycap */ +#ifdef USE_DMA_BUF pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.pDecOps->Init(V4L2_MEMORY_DMABUF); +#else + pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.pDecOps->Init(V4L2_MEMORY_USERPTR); +#endif if (pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle == NULL) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate context buffer"); ret = OMX_ErrorInsufficientResources; diff --git a/component/video/dec/vp8/Android.mk b/component/video/dec/vp8/Android.mk index 041f86b..124b13a 100644 --- a/component/video/dec/vp8/Android.mk +++ b/component/video/dec/vp8/Android.mk @@ -17,6 +17,10 @@ ifeq ($(BOARD_USE_ANB), true) LOCAL_CFLAGS += -DUSE_ANB endif +ifeq ($(BOARD_USE_DMA_BUF), true) +LOCAL_CFLAGS += -DUSE_DMA_BUF +endif + LOCAL_ARM_MODE := arm LOCAL_STATIC_LIBRARIES := libExynosOMX_Vdec libExynosOMX_OSAL libExynosOMX_Basecomponent \ diff --git a/component/video/dec/vp8/Exynos_OMX_Vp8dec.c b/component/video/dec/vp8/Exynos_OMX_Vp8dec.c index 0565065..cbc06ff 100644 --- a/component/video/dec/vp8/Exynos_OMX_Vp8dec.c +++ b/component/video/dec/vp8/Exynos_OMX_Vp8dec.c @@ -225,7 +225,11 @@ OMX_ERRORTYPE VP8CodecOpen(EXYNOS_VP8DEC_HANDLE *pVp8Dec) } /* alloc context, open, querycap */ +#ifdef USE_DMA_BUF pVp8Dec->hMFCVp8Handle.hMFCHandle = pVp8Dec->hMFCVp8Handle.pDecOps->Init(V4L2_MEMORY_DMABUF); +#else + pVp8Dec->hMFCVp8Handle.hMFCHandle = pVp8Dec->hMFCVp8Handle.pDecOps->Init(V4L2_MEMORY_USERPTR); +#endif if (pVp8Dec->hMFCVp8Handle.hMFCHandle == NULL) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate context buffer"); ret = OMX_ErrorInsufficientResources; diff --git a/component/video/enc/Android.mk b/component/video/enc/Android.mk index fb87bc8..dd168c9 100644 --- a/component/video/enc/Android.mk +++ b/component/video/enc/Android.mk @@ -38,6 +38,10 @@ ifeq ($(BOARD_USE_STOREMETADATA), true) LOCAL_CFLAGS += -DUSE_STOREMETADATA endif +ifeq ($(BOARD_USE_DMA_BUF), true) +LOCAL_CFLAGS += -DUSE_DMA_BUF +endif + LOCAL_SHARED_LIBRARIES := libcsc include $(BUILD_STATIC_LIBRARY) diff --git a/component/video/enc/Exynos_OMX_Venc.c b/component/video/enc/Exynos_OMX_Venc.c index a5fcd17..ac0cbbe 100644 --- a/component/video/enc/Exynos_OMX_Venc.c +++ b/component/video/enc/Exynos_OMX_Venc.c @@ -227,21 +227,25 @@ OMX_BOOL Exynos_CSC_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA Exynos_OSAL_LockANBHandle((OMX_U32)ppBuf[0], nFrameWidth, nFrameHeight, OMX_COLOR_FormatAndroidOpaque, planes); imageSize = nFrameWidth * nFrameHeight * 3; /* RGB888 */ +#ifdef USE_DMA_BUF if (csc_method == CSC_METHOD_HW) pSrcBuf[0] = (unsigned char *)planes[0].fd; else - pSrcBuf[0] = planes[0].addr; +#endif + pSrcBuf[0] = planes[0].addr; pSrcBuf[1] = NULL; pSrcBuf[2] = NULL; } } else #endif { +#ifdef USE_DMA_BUF if (csc_method == CSC_METHOD_HW) { pSrcBuf[0] = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, checkInputStream); pSrcBuf[1] = NULL; pSrcBuf[2] = NULL; } +#endif switch (eColorFormat) { case OMX_COLOR_FormatYUV420Planar: @@ -367,6 +371,7 @@ OMX_BOOL Exynos_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ } else { /* kMetadataBufferTypeCameraSource */ Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)inputUseBuffer->bufferHeader->pBuffer, ppBuf); +#ifdef USE_DMA_BUF srcInputData->buffer.multiPlaneBuffer.fd[0] = ppBuf[0]; srcInputData->buffer.multiPlaneBuffer.fd[1] = ppBuf[1]; allocSize[0] = nFrameWidth * nFrameHeight; @@ -383,7 +388,13 @@ OMX_BOOL Exynos_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_ /* input buffers are 2 plane. */ srcInputData->buffer.multiPlaneBuffer.dataBuffer[2] = NULL; srcInputData->buffer.multiPlaneBuffer.fd[2] = -1; - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s:%d YAddr: 0x%x CbCrAddr: 0x%x", __FUNCTION__, __LINE__, (unsigned int)ppBuf[0], (unsigned int)ppBuf[0]); +#else + for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { + srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] = ppBuf[plane]; + } + srcInputData->buffer.multiPlaneBuffer.dataBuffer[2] = NULL; +#endif + Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s:%d YAddr: 0x%x CbCrAddr: 0x%x", __FUNCTION__, __LINE__, (unsigned int)ppBuf[0], (unsigned int)ppBuf[1]); } } #endif diff --git a/component/video/enc/h264/Android.mk b/component/video/enc/h264/Android.mk index 971875c..11c6b7f 100644 --- a/component/video/enc/h264/Android.mk +++ b/component/video/enc/h264/Android.mk @@ -17,6 +17,10 @@ ifeq ($(BOARD_USE_METADATABUFFERTYPE), true) LOCAL_CFLAGS += -DUSE_METADATABUFFERTYPE endif +ifeq ($(BOARD_USE_DMA_BUF), true) +LOCAL_CFLAGS += -DUSE_DMA_BUF +endif + LOCAL_ARM_MODE := arm LOCAL_STATIC_LIBRARIES := libExynosOMX_Venc libExynosOMX_OSAL libExynosOMX_Basecomponent \ diff --git a/component/video/enc/h264/Exynos_OMX_H264enc.c b/component/video/enc/h264/Exynos_OMX_H264enc.c index b2caa7d..001e4a0 100644 --- a/component/video/enc/h264/Exynos_OMX_H264enc.c +++ b/component/video/enc/h264/Exynos_OMX_H264enc.c @@ -459,7 +459,11 @@ OMX_ERRORTYPE H264CodecOpen(EXYNOS_H264ENC_HANDLE *pH264Enc) } /* alloc context, open, querycap */ +#ifdef USE_DMA_BUF pH264Enc->hMFCH264Handle.hMFCHandle = pH264Enc->hMFCH264Handle.pEncOps->Init(V4L2_MEMORY_DMABUF); +#else + pH264Enc->hMFCH264Handle.hMFCHandle = pH264Enc->hMFCH264Handle.pEncOps->Init(V4L2_MEMORY_USERPTR); +#endif if (pH264Enc->hMFCH264Handle.hMFCHandle == NULL) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate context buffer"); ret = OMX_ErrorInsufficientResources; diff --git a/component/video/enc/mpeg4/Android.mk b/component/video/enc/mpeg4/Android.mk index 4672382..a5c0fa4 100644 --- a/component/video/enc/mpeg4/Android.mk +++ b/component/video/enc/mpeg4/Android.mk @@ -17,6 +17,10 @@ ifeq ($(BOARD_USE_METADATABUFFERTYPE), true) LOCAL_CFLAGS += -DUSE_METADATABUFFERTYPE endif +ifeq ($(BOARD_USE_DMA_BUF), true) +LOCAL_CFLAGS += -DUSE_DMA_BUF +endif + LOCAL_ARM_MODE := arm LOCAL_STATIC_LIBRARIES := libExynosOMX_Venc libExynosOMX_OSAL libExynosOMX_Basecomponent \ diff --git a/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c b/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c index 1723f98..8d723b4 100644 --- a/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c +++ b/component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c @@ -581,7 +581,11 @@ OMX_ERRORTYPE Mpeg4CodecOpen(EXYNOS_MPEG4ENC_HANDLE *pMpeg4Enc) } /* alloc context, open, querycap */ +#ifdef USE_DMA_BUF pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle = pMpeg4Enc->hMFCMpeg4Handle.pEncOps->Init(V4L2_MEMORY_DMABUF); +#else + pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle = pMpeg4Enc->hMFCMpeg4Handle.pEncOps->Init(V4L2_MEMORY_USERPTR); +#endif if (pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle == NULL) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate context buffer"); ret = OMX_ErrorInsufficientResources; diff --git a/osal/Android.mk b/osal/Android.mk index 2dd4b92..287dded 100644 --- a/osal/Android.mk +++ b/osal/Android.mk @@ -25,6 +25,10 @@ ifeq ($(BOARD_USE_ANB_OUTBUF_SHARE), true) LOCAL_CFLAGS += -DUSE_ANB_OUTBUF_SHARE endif +ifeq ($(BOARD_USE_DMA_BUF), true) +LOCAL_CFLAGS += -DUSE_DMA_BUF +endif + LOCAL_STATIC_LIBRARIES := liblog libcutils libExynosVideoApi LOCAL_C_INCLUDES := \ diff --git a/osal/Exynos_OSAL_Android.cpp b/osal/Exynos_OSAL_Android.cpp index 5185d7c..c2346f3 100644 --- a/osal/Exynos_OSAL_Android.cpp +++ b/osal/Exynos_OSAL_Android.cpp @@ -37,7 +37,9 @@ #include #include #include +#ifdef USE_DMA_BUF #include +#endif #include "Exynos_OSAL_Semaphore.h" #include "Exynos_OMX_Baseport.h" @@ -74,7 +76,9 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle( OMX_ERRORTYPE ret = OMX_ErrorNone; GraphicBufferMapper &mapper = GraphicBufferMapper::get(); buffer_handle_t bufferHandle = (buffer_handle_t) handle; +#ifdef USE_DMA_BUF private_handle_t *priv_hnd = (private_handle_t *) bufferHandle; +#endif Rect bounds(width, height); ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes; void *vaddr[MAX_BUFFER_PLANE]; @@ -100,14 +104,16 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle( goto EXIT; } +#ifdef USE_DMA_BUF vplanes[0].fd = priv_hnd->fd; vplanes[0].offset = 0; - vplanes[0].addr = vaddr[0]; vplanes[1].fd = priv_hnd->fd1; vplanes[1].offset = 0; - vplanes[1].addr = vaddr[1]; vplanes[2].fd = priv_hnd->fd2; vplanes[2].offset = 0; +#endif + vplanes[0].addr = vaddr[0]; + vplanes[1].addr = vaddr[1]; vplanes[2].addr = vaddr[2]; Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr); @@ -250,16 +256,18 @@ OMX_ERRORTYPE useAndroidNativeBuffer( Exynos_OSAL_LockANB(temp_bufferHeader->pBuffer, width, height, pExynosPort->portDefinition.format.video.eColorFormat, &stride, planes); +#ifdef USE_DMA_BUF pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd; - pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr; pExynosPort->extendBufferHeader[i].buf_fd[1] = planes[1].fd; - pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr; pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd; +#endif + pExynosPort->extendBufferHeader[i].pYUVBuf[0] = planes[0].addr; + pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr; pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr; Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer); - Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x (fd:%d), pYUVBuf[1]:0x%x (fd:%d)", - i, pExynosPort->extendBufferHeader[i].pYUVBuf[0], planes[0].fd, - pExynosPort->extendBufferHeader[i].pYUVBuf[1], planes[1].fd); + Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "useAndroidNativeBuffer: buf %d pYUVBuf[0]:0x%x , pYUVBuf[1]:0x%x ", + i, pExynosPort->extendBufferHeader[i].pYUVBuf[0], + pExynosPort->extendBufferHeader[i].pYUVBuf[1]); pExynosPort->assignedBufferNum++; if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) { diff --git a/osal/Exynos_OSAL_SharedMemory.c b/osal/Exynos_OSAL_SharedMemory.c index 9707594..bcc632a 100644 --- a/osal/Exynos_OSAL_SharedMemory.c +++ b/osal/Exynos_OSAL_SharedMemory.c @@ -271,6 +271,7 @@ EXIT: return; } +#ifdef USE_DMA_BUF OMX_PTR Exynos_OSAL_SharedMemory_Map(OMX_HANDLETYPE handle, OMX_U32 size, unsigned int ionfd) { EXYNOS_SHARED_MEMORY *pHandle = (EXYNOS_SHARED_MEMORY *)handle; @@ -381,6 +382,7 @@ void Exynos_OSAL_SharedMemory_Unmap(OMX_HANDLETYPE handle, unsigned int ionfd) EXIT: return; } +#endif int Exynos_OSAL_SharedMemory_VirtToION(OMX_HANDLETYPE handle, OMX_PTR pBuffer) {