exynos_omx: multi_thread: Fix the wrong type casting and data access.
authorSeungBeom Kim <sbcrux.kim@samsung.com>
Wed, 23 Jul 2014 06:04:13 +0000 (15:04 +0900)
committerLajos Molnar <lajos@google.com>
Wed, 30 Jul 2014 01:03:01 +0000 (01:03 +0000)
The case of using AndroidNativeBuffer,
Errors can happen in Exynos_OSAL_RefANB_Increase by wrong type casting and data access.
The cause, there was a omit to commit merge.
(currently don't need. =>  https://partner-android-review.googlesource.com/#/c/28006/2)

Bug: 10192533
Change-Id: Ie296d6a25da447c4d29b671dc722019cd57aa994
Signed-off-by: SeungBeom Kim <sbcrux.kim@samsung.com>
exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_Vdec.c
exynos_omx/openmax/exynos_omx/component/video/dec/Exynos_OMX_VdecControl.c
exynos_omx/openmax/exynos_omx/component/video/enc/Exynos_OMX_Venc.c
exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Android.cpp
exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Android.h

index 8a2add6f585ce435cf2148b2a5627e57a27e3865..8d0e6d5bd8fb9f4390afe1f0a483195250385f25 100644 (file)
@@ -397,7 +397,7 @@ OMX_BOOL Exynos_CSC_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA
         ExynosVideoPlane planes[MAX_BUFFER_PLANE];
         OMX_U32 stride;
         if (exynosOutputPort->bIsANBEnabled == OMX_TRUE) {
-            Exynos_OSAL_LockANB(pOutputBuf, width, height, exynosOutputPort->portDefinition.format.video.eColorFormat, &stride, planes);
+            Exynos_OSAL_LockANBHandle(pOutputBuf, width, height, exynosOutputPort->portDefinition.format.video.eColorFormat, &stride, planes);
         } else if (exynosOutputPort->bStoreMetaData == OMX_TRUE) {
             Exynos_OSAL_LockMetaData(pOutputBuf, width, height, exynosOutputPort->portDefinition.format.video.eColorFormat, &stride, planes);
         }
@@ -460,7 +460,7 @@ OMX_BOOL Exynos_CSC_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA
 
 #ifdef USE_ANB
     if (exynosOutputPort->bIsANBEnabled == OMX_TRUE) {
-        Exynos_OSAL_UnlockANB(pOutputBuf);
+        Exynos_OSAL_UnlockANBHandle(pOutputBuf);
     } else if (exynosOutputPort->bStoreMetaData == OMX_TRUE) {
         Exynos_OSAL_UnlockMetaData(pOutputBuf);
     }
index cd97b44cb4b17a129df82a2a56372b6c3f33f3e3..dda45d9c78ace6ebf6b1f2bf30551057b207c894 100644 (file)
@@ -1509,7 +1509,7 @@ OMX_ERRORTYPE Exynos_Shared_ANBBufferToData(EXYNOS_OMX_DATABUFFER *pUseBuffer, E
         OMX_U32 stride;
         if ((pUseBuffer->bufferHeader != NULL) && (pUseBuffer->bufferHeader->pBuffer != NULL)) {
             if (pExynosPort->bIsANBEnabled == OMX_TRUE) {
-                Exynos_OSAL_LockANB(pUseBuffer->bufferHeader->pBuffer, width, height, pExynosPort->portDefinition.format.video.eColorFormat, &stride, planes);
+                Exynos_OSAL_LockANBHandle(pUseBuffer->bufferHeader->pBuffer, width, height, pExynosPort->portDefinition.format.video.eColorFormat, &stride, planes);
             } else if (pExynosPort->bStoreMetaData == OMX_TRUE) {
                 Exynos_OSAL_LockMetaData(pUseBuffer->bufferHeader->pBuffer, width, height, pExynosPort->portDefinition.format.video.eColorFormat, &stride, planes);
             }
@@ -1570,7 +1570,7 @@ OMX_ERRORTYPE Exynos_Shared_DataToANBBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_D
     }
 
     if (pExynosPort->bIsANBEnabled == OMX_TRUE) {
-        Exynos_OSAL_UnlockANB(pUseBuffer->bufferHeader->pBuffer);
+        Exynos_OSAL_UnlockANBHandle(pUseBuffer->bufferHeader->pBuffer);
     } else if (pExynosPort->bStoreMetaData == OMX_TRUE) {
         Exynos_OSAL_UnlockMetaData(pUseBuffer->bufferHeader->pBuffer);
     } else {
index 5c0b583897f0c8b19ccc682dd2b522b405516ea1..c7dc24aa90fda69f2c9419e624cc68a02ffcf049 100644 (file)
@@ -322,10 +322,11 @@ OMX_BOOL Exynos_CSC_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA
         Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)inputUseBuffer->bufferHeader->pBuffer, ppBuf);
         if (eColorFormat == OMX_COLOR_FormatAndroidOpaque) {
             ExynosVideoPlane planes[MAX_BUFFER_PLANE];
-            size_t i;
+            OMX_U32 stride;
+            int i;
 
             csc_src_color_format = omx_2_hal_pixel_format((unsigned int)Exynos_OSAL_GetANBColorFormat(ppBuf[0]));
-            Exynos_OSAL_LockANBHandle((OMX_U32)ppBuf[0], nFrameWidth, nFrameHeight, OMX_COLOR_FormatAndroidOpaque, planes);
+            Exynos_OSAL_LockANBHandle((OMX_U32)ppBuf[0], nFrameWidth, nFrameHeight, OMX_COLOR_FormatAndroidOpaque, &stride, planes);
 
 #if defined(USE_CSC_GSCALER) || defined(USE_CSC_G2D)
             csc_method = CSC_METHOD_HW;
@@ -472,8 +473,9 @@ OMX_BOOL Exynos_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_
 
                     if (eColorFormat == OMX_COLOR_FormatAndroidOpaque) {
                         ExynosVideoPlane planes[MAX_BUFFER_PLANE];
+                        OMX_U32 stride;
 
-                        Exynos_OSAL_LockANBHandle((OMX_U32)ppBuf[0], nFrameWidth, nFrameHeight, OMX_COLOR_FormatYUV420SemiPlanar, planes);
+                        Exynos_OSAL_LockANBHandle((OMX_U32)ppBuf[0], nFrameWidth, nFrameHeight, OMX_COLOR_FormatYUV420SemiPlanar, &stride, planes);
 
                         srcInputData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd;
                         srcInputData->buffer.multiPlaneBuffer.fd[1] = planes[1].fd;
index 294a1c15a28ed8c9199c4b077797ac4e2bf5db02..fb64735b74713193dc42c4e4236a1b7c6c38362b 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();
@@ -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:
@@ -369,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;
@@ -527,7 +492,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)
@@ -537,7 +503,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;
@@ -546,7 +512,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);
index 18e0b4179d03a88161a691156b1a62c3b368ac42..424579f452846d53e1e69e974a6be5917e74e8eb 100644 (file)
@@ -66,15 +66,6 @@ OMX_ERRORTYPE Exynos_OSAL_SetANBParameter(OMX_IN OMX_HANDLETYPE hComponent,
                                           OMX_IN OMX_INDEXTYPE nIndex,
                                           OMX_IN OMX_PTR ComponentParameterStructure);
 
-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);
-
-OMX_ERRORTYPE Exynos_OSAL_UnlockANB(OMX_IN OMX_PTR pBuffer);
-
 OMX_ERRORTYPE Exynos_OSAL_LockMetaData(OMX_IN OMX_PTR pBuffer,
                                        OMX_IN OMX_U32 width,
                                        OMX_IN OMX_U32 height,
@@ -88,6 +79,7 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle(OMX_IN OMX_U32 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);
 
 OMX_ERRORTYPE Exynos_OSAL_UnlockANBHandle(OMX_IN OMX_U32 pBuffer);