video/osal: Support both DMABUF and virtual address
authorSatish Kumar Reddy <palli.satish@samsung.com>
Mon, 29 Oct 2012 04:33:17 +0000 (13:33 +0900)
committerHuisung Kang <hs1218.kang@samsung.com>
Mon, 29 Oct 2012 04:54:22 +0000 (13:54 +0900)
DMABUF can be enabled by this marco BOARD_USE_DMA_BUF

Change-Id: Ie38db57250368dae208a8cca3cc7d7a73f5a6e63
Signed-off-by: Satish Kumar Reddy <palli.satish@samsung.com>
Signed-off-by: Huisung Kang <hs1218.kang@samsung.com>
18 files changed:
component/video/dec/Android.mk
component/video/dec/Exynos_OMX_Vdec.c
component/video/dec/Exynos_OMX_VdecControl.c
component/video/dec/h264/Android.mk
component/video/dec/h264/Exynos_OMX_H264dec.c
component/video/dec/mpeg4/Android.mk
component/video/dec/mpeg4/Exynos_OMX_Mpeg4dec.c
component/video/dec/vp8/Android.mk
component/video/dec/vp8/Exynos_OMX_Vp8dec.c
component/video/enc/Android.mk
component/video/enc/Exynos_OMX_Venc.c
component/video/enc/h264/Android.mk
component/video/enc/h264/Exynos_OMX_H264enc.c
component/video/enc/mpeg4/Android.mk
component/video/enc/mpeg4/Exynos_OMX_Mpeg4enc.c
osal/Android.mk
osal/Exynos_OSAL_Android.cpp
osal/Exynos_OSAL_SharedMemory.c

index 59254b3348a2f77693756aea60cbd3b291a6f559..5d3ff7813f4b9255a7ecab1549fe00f711c630ae 100644 (file)
@@ -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)
index 31d96eb00f54fe2a9bc1fab4a9bcfbe715517d87..098e646d71b0dc74d2ecbf93207be5c439ba1a68 100644 (file)
@@ -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(
index 447bb749d5665fa4641cc0f2920e397a2198f67a..a99b8bed4e2525909f5598739195955b9d18b7cb 100644 (file)
@@ -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;
index 60c999333c2287cc516aee7e87d9fc69f746a3ca..3890fc29908e0de534a35f97fda1d102ccbe2b3e 100644 (file)
@@ -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
index b834316ff775722dc93d3a86ecddcd561ac6df3e..9de204d10dd1009cad706631d4a45818527ca970 100644 (file)
@@ -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;
index 21d5fb69e2251e94df0444a336d4a2ab7f048d2c..487521271b2fe013d95aa5522183fc2356ea9539 100644 (file)
@@ -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 \
index 9c7238b6cbd3c0a7bf0abbe9edbea95f597769c0..f0e92220cb168bd911317850aa79ab2bffda6920 100644 (file)
@@ -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;
index 041f86b18ba326740db7f7067211a397895957d1..124b13a982bd37127332eaf0c1575fc04d03e5c1 100644 (file)
@@ -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 \
index 05650654fbb222dcb892ec88338525d5204ec313..cbc06ff06997a2bfb6a6436a9f6565a4e4a5eda3 100644 (file)
@@ -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;
index fb87bc855e263ba24634ddd3a4ca8354ad77f023..dd168c9e8f481a60afda64e476431d9a1d04823a 100644 (file)
@@ -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)
index a5fcd1782a318917e3a4203e6758291a1809635d..ac0cbbea3f81736c3d8b89e6d82f6ea1012e42a3 100644 (file)
@@ -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
index 971875ca1149295082a4df56da15af317fa5517f..11c6b7ff491fd6b9cf35ad242724882e8824ffe0 100644 (file)
@@ -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 \
index b2caa7ddb82e9bbeafd5e5f4841bf494462156d8..001e4a05e0c467dbec75feddb88cc638ee64527f 100644 (file)
@@ -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;
index 467238238eaa6e8ff1196c06445aa39f47179606..a5c0fa420d2a3a4082e244a7cd634122a8548022 100644 (file)
@@ -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 \
index 1723f98cf12a4bd679e7903bde8a172d85c978f3..8d723b485d19e885e77ff04559afc949b101b2a3 100644 (file)
@@ -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;
index 2dd4b928f9086650ea9a86acb8c5d860093e95c7..287dded31ffd4941ef2df6eed3e00fd043c3f4b7 100644 (file)
@@ -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 := \
index 5185d7c5ffbb05dfa0232bf7f9e606c623cbfff9..c2346f3aab7e94c2718cd0615634040c2df5a6b0 100644 (file)
@@ -37,7 +37,9 @@
 #include <hardware/hardware.h>
 #include <media/hardware/OMXPluginBase.h>
 #include <media/hardware/MetadataBufferType.h>
+#ifdef USE_DMA_BUF
 #include <gralloc_priv.h>
+#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) {
index 970759404c7274e72a101e7044c7b4ca7c3cbe6f..bcc632a65637aea31019e315b1e5212d3356ea4d 100644 (file)
@@ -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)
 {