Support M
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos5.git] / exynos_omx / openmax / exynos_omx / osal / Exynos_OSAL_Android.cpp
index 5c99e9c144c1ca0ffbeb0d5ee33efc7ff5face69..b128aafe39d68dae01f6c4be9712d16cedd5e432 100644 (file)
@@ -72,6 +72,7 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle(
     OMX_IN OMX_U32 width,
     OMX_IN OMX_U32 height,
     OMX_IN OMX_COLOR_FORMATTYPE format,
+    OMX_OUT OMX_U32 *pStride,
     OMX_OUT OMX_PTR planes)
 {
     FunctionIn();
@@ -80,7 +81,7 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle(
     GraphicBufferMapper &mapper = GraphicBufferMapper::get();
     buffer_handle_t bufferHandle = (buffer_handle_t) handle;
     private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
-    Rect bounds(width, height);
+    Rect bounds((uint32_t)width, (uint32_t)height);
     ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes;
     void *vaddr[MAX_BUFFER_PLANE];
 
@@ -115,6 +116,8 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle(
     vplanes[2].offset = 0;
     vplanes[2].addr = vaddr[2];
 
+    *pStride = priv_hnd->stride;
+
     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
 
 EXIT:
@@ -178,43 +181,6 @@ EXIT:
     return nStride;
 }
 
-OMX_ERRORTYPE Exynos_OSAL_LockANB(
-    OMX_IN OMX_PTR pBuffer,
-    OMX_IN OMX_U32 width,
-    OMX_IN OMX_U32 height,
-    OMX_IN OMX_COLOR_FORMATTYPE format,
-    OMX_OUT OMX_U32 *pStride,
-    OMX_OUT OMX_PTR planes)
-{
-    FunctionIn();
-
-    OMX_ERRORTYPE ret = OMX_ErrorNone;
-    android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
-
-    ret = Exynos_OSAL_LockANBHandle((OMX_U32)pANB->handle, width, height, format, planes);
-    *pStride = pANB->stride;
-
-EXIT:
-    FunctionOut();
-
-    return ret;
-}
-
-OMX_ERRORTYPE Exynos_OSAL_UnlockANB(OMX_IN OMX_PTR pBuffer)
-{
-    FunctionIn();
-
-    OMX_ERRORTYPE ret = OMX_ErrorNone;
-    android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
-
-    ret = Exynos_OSAL_UnlockANBHandle((OMX_U32)pANB->handle);
-
-EXIT:
-    FunctionOut();
-
-    return ret;
-}
-
 OMX_ERRORTYPE Exynos_OSAL_LockMetaData(
     OMX_IN OMX_PTR pBuffer,
     OMX_IN OMX_U32 width,
@@ -230,8 +196,7 @@ OMX_ERRORTYPE Exynos_OSAL_LockMetaData(
 
     ret = Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)pBuffer, &pBuf);
     if (ret == OMX_ErrorNone) {
-        ret = Exynos_OSAL_LockANBHandle((OMX_U32)pBuf, width, height, format, planes);
-        *pStride = Exynos_OSAL_GetANBStride((OMX_U32)pBuf);
+        ret = Exynos_OSAL_LockANBHandle((OMX_U32)pBuf, width, height, format, pStride, planes);
     }
 
 EXIT:
@@ -261,6 +226,8 @@ OMX_HANDLETYPE Exynos_OSAL_RefANB_Create()
 {
     int i = 0;
     EXYNOS_OMX_REF_HANDLE *phREF = NULL;
+    gralloc_module_t      *module = NULL;
+
     OMX_ERRORTYPE err = OMX_ErrorNone;
 
     FunctionIn();
@@ -276,6 +243,9 @@ OMX_HANDLETYPE Exynos_OSAL_RefANB_Create()
         phREF->SharedBuffer[i].BufferFd2 = -1;
     }
 
+    hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&module);
+    phREF->pGrallocModule = (OMX_PTR)module;
+
     err = Exynos_OSAL_MutexCreate(&phREF->hMutex);
     if (err != OMX_ErrorNone) {
         Exynos_OSAL_Free(phREF);
@@ -302,7 +272,7 @@ OMX_ERRORTYPE Exynos_OSAL_RefANB_Reset(OMX_HANDLETYPE hREF)
         goto EXIT;
     }
 
-    hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&module);
+    module = (gralloc_module_t *)phREF->pGrallocModule;
 
     Exynos_OSAL_MutexLock(phREF->hMutex);
     for (i = 0; i < MAX_BUFFER_REF; i++) {
@@ -345,6 +315,8 @@ OMX_ERRORTYPE Exynos_OSAL_RefANB_Terminate(OMX_HANDLETYPE hREF)
 
     Exynos_OSAL_RefANB_Reset(phREF);
 
+    phREF->pGrallocModule = NULL;
+
     ret = Exynos_OSAL_MutexTerminate(phREF->hMutex);
     if (ret != OMX_ErrorNone)
         goto EXIT;
@@ -362,7 +334,7 @@ OMX_ERRORTYPE Exynos_OSAL_RefANB_Increase(OMX_HANDLETYPE hREF, OMX_PTR pBuffer)
 {
     int i;
     OMX_ERRORTYPE ret = OMX_ErrorNone;
-    buffer_handle_t bufferHandle = (buffer_handle_t) pBuffer;//pANB->handle;
+    buffer_handle_t bufferHandle = (buffer_handle_t) pBuffer; //pANB->handle
     private_handle_t *priv_hnd = (private_handle_t *) bufferHandle;
     EXYNOS_OMX_REF_HANDLE *phREF = (EXYNOS_OMX_REF_HANDLE *)hREF;
     gralloc_module_t* module = NULL;
@@ -378,7 +350,7 @@ OMX_ERRORTYPE Exynos_OSAL_RefANB_Increase(OMX_HANDLETYPE hREF, OMX_PTR pBuffer)
         goto EXIT;
     }
 
-    hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&module);
+    module = (gralloc_module_t *)phREF->pGrallocModule;
 
     Exynos_OSAL_MutexLock(phREF->hMutex);
 
@@ -442,13 +414,18 @@ OMX_ERRORTYPE Exynos_OSAL_RefANB_Decrease(OMX_HANDLETYPE hREF, OMX_U32 BufferFd)
         goto EXIT;
     }
 
+    module = (gralloc_module_t *)phREF->pGrallocModule;
+
     Exynos_OSAL_MutexLock(phREF->hMutex);
-    hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&module);
+
     for (i = 0; i < MAX_BUFFER_REF; i++) {
         if (phREF->SharedBuffer[i].BufferFd == BufferFd) {
-            ion_decRef(getIonFd(module), phREF->SharedBuffer[i].pIonHandle);
-            ion_decRef(getIonFd(module), phREF->SharedBuffer[i].pIonHandle1);
-            ion_decRef(getIonFd(module), phREF->SharedBuffer[i].pIonHandle2);
+            if (phREF->SharedBuffer[i].BufferFd > -1)
+                ion_decRef(getIonFd(module), phREF->SharedBuffer[i].pIonHandle);
+            if (phREF->SharedBuffer[i].BufferFd1 > -1)
+                ion_decRef(getIonFd(module), phREF->SharedBuffer[i].pIonHandle1);
+            if (phREF->SharedBuffer[i].BufferFd2 > -1)
+                ion_decRef(getIonFd(module), phREF->SharedBuffer[i].pIonHandle2);
             phREF->SharedBuffer[i].cnt--;
             if (phREF->SharedBuffer[i].cnt == 0) {
                 phREF->SharedBuffer[i].BufferFd    = -1;
@@ -518,7 +495,8 @@ OMX_ERRORTYPE useAndroidNativeBuffer(
             pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader;
             pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED);
             INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE);
-            temp_bufferHeader->pBuffer        = pBuffer;
+            android_native_buffer_t *pANB = (android_native_buffer_t *) pBuffer;
+            temp_bufferHeader->pBuffer = (OMX_U8 *)pANB->handle;
             temp_bufferHeader->nAllocLen      = nSizeBytes;
             temp_bufferHeader->pAppPrivate    = pAppPrivate;
             if (nPortIndex == INPUT_PORT_INDEX)
@@ -528,7 +506,7 @@ OMX_ERRORTYPE useAndroidNativeBuffer(
 
             width = pExynosPort->portDefinition.format.video.nFrameWidth;
             height = pExynosPort->portDefinition.format.video.nFrameHeight;
-            Exynos_OSAL_LockANB(temp_bufferHeader->pBuffer, width, height,
+            Exynos_OSAL_LockANBHandle((OMX_U32)temp_bufferHeader->pBuffer, width, height,
                                 pExynosPort->portDefinition.format.video.eColorFormat,
                                 &stride, planes);
             pExynosPort->extendBufferHeader[i].buf_fd[0] = planes[0].fd;
@@ -537,7 +515,7 @@ OMX_ERRORTYPE useAndroidNativeBuffer(
             pExynosPort->extendBufferHeader[i].pYUVBuf[1] = planes[1].addr;
             pExynosPort->extendBufferHeader[i].buf_fd[2] = planes[2].fd;
             pExynosPort->extendBufferHeader[i].pYUVBuf[2] = planes[2].addr;
-            Exynos_OSAL_UnlockANB(temp_bufferHeader->pBuffer);
+            Exynos_OSAL_UnlockANBHandle((OMX_U32)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);
@@ -718,6 +696,12 @@ OMX_ERRORTYPE Exynos_OSAL_SetANBParameter(
             pExynosPort->bufferProcessType = BUFFER_SHARE;
             pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
             Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "OMX_IndexParamEnableAndroidBuffers & bufferProcessType change to BUFFER_SHARE");
+        } else if ((portIndex == OUTPUT_PORT_INDEX) &&
+            (pExynosPort->bStoreMetaData == OMX_FALSE && pExynosPort->bIsANBEnabled == OMX_FALSE) &&
+            pExynosPort->bufferProcessType == BUFFER_SHARE) {
+            pExynosPort->bufferProcessType = (EXYNOS_OMX_BUFFERPROCESS_TYPE)(BUFFER_COPY | BUFFER_ANBSHARE);
+            pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
+            Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "No OMX_IndexParamEnableAndroidBuffers => reset bufferProcessType");
         }
     }
         break;
@@ -811,6 +795,12 @@ OMX_ERRORTYPE Exynos_OSAL_SetANBParameter(
                 pExynosPort->bufferProcessType = BUFFER_SHARE;
                 pExynosPort->portDefinition.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_SEC_COLOR_FormatNV12Tiled;
                 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "OMX_IndexParamStoreMetaDataBuffer & bufferProcessType change to BUFFER_SHARE");
+            } else if ((portIndex == OUTPUT_PORT_INDEX) &&
+                (pExynosPort->bStoreMetaData == OMX_FALSE && pExynosPort->bIsANBEnabled == OMX_FALSE) &&
+                pExynosPort->bufferProcessType == BUFFER_SHARE) {
+                pExynosPort->bufferProcessType = (EXYNOS_OMX_BUFFERPROCESS_TYPE)(BUFFER_COPY | BUFFER_ANBSHARE);
+                pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
+                Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "No OMX_IndexParamStoreMetaDataBuffer => reset bufferProcessType");
             }
 
         }