Browse Source

omx-il: Store buffer header pointer in struct PortContainerExternal.

remove GetOMXBufferByAddr, StoreOMXBuffer, ClearOMXBuffer

Signed-off-by: Som Qin <som.qin@starfivetech.com>
Som Qin 1 year ago
parent
commit
0fda10b55b

+ 7 - 14
soft_3rdpart/omx-il/component/video/dec/SF_OMX_Vdec_decoder.c

@@ -78,7 +78,7 @@ static void OnEventArrived(Component com, unsigned long event, void *data, void
     switch (event)
     {
     case COMPONENT_EVENT_DEC_EMPTY_BUFFER_DONE:
-        pOMXBuffer = GetOMXBufferByAddr(pSfOMXComponent, (OMX_U8 *)pPortContainerExternal->pBuffer);
+        pOMXBuffer = (OMX_BUFFERHEADERTYPE *)pPortContainerExternal->pAppPrivate;
         if (pOMXBuffer == NULL)
         {
             LOG(SF_LOG_WARN, "Could not find omx buffer by address\r\n");
@@ -90,7 +90,7 @@ static void OnEventArrived(Component com, unsigned long event, void *data, void
     {
         struct timeval tv;
 
-        pOMXBuffer = GetOMXBufferByAddr(pSfOMXComponent, (OMX_U8 *)pPortContainerExternal->pBuffer);
+        pOMXBuffer = (OMX_BUFFERHEADERTYPE *)pPortContainerExternal->pAppPrivate;
         if (pOMXBuffer == NULL)
         {
             LOG(SF_LOG_WARN, "Could not find omx buffer by address\r\n");
@@ -213,6 +213,7 @@ static OMX_ERRORTYPE SF_OMX_EmptyThisBuffer(
     pPortContainerExternal->pBuffer = pBuffer->pBuffer;
     pPortContainerExternal->nFilledLen = pBuffer->nFilledLen;
     pPortContainerExternal->nFlags = pBuffer->nFlags;
+    pPortContainerExternal->pAppPrivate = (void*)pBuffer;
 
     if (pSfVideoImplement->functions->Queue_Enqueue(pFeederComponent->srcPort.inputQ, (void *)pPortContainerExternal) != OMX_TRUE)
     {
@@ -262,6 +263,7 @@ static OMX_ERRORTYPE SF_OMX_FillThisBuffer(
     memset(pPortContainerExternal, 0, sizeof(PortContainerExternal));
     pPortContainerExternal->pBuffer = pBuffer->pBuffer;
     pPortContainerExternal->nFilledLen = pBuffer->nAllocLen;
+    pPortContainerExternal->pAppPrivate = (void*)pBuffer;
 
     if (gInitTimeStamp != 0)
     {
@@ -332,9 +334,9 @@ static OMX_ERRORTYPE SF_OMX_UseBuffer(
         temp_bufferHeader->pOutputPortPrivate = (OMX_PTR)nOutBufIndex;
         nOutBufIndex ++;
     }
-    ret = StoreOMXBuffer(pSfOMXComponent, temp_bufferHeader);
+
     LOG(SF_LOG_INFO, "pBuffer address = %p, nOutBufIndex = %d\r\n", temp_bufferHeader->pBuffer, (OMX_U64)(temp_bufferHeader->pOutputPortPrivate));
-    LOG(SF_LOG_PERF, "alloc size = %d, buffer count = %d\r\n",nSizeBytes, GetOMXBufferCount(pSfOMXComponent));
+
 EXIT:
     FunctionOut();
 
@@ -406,8 +408,6 @@ static OMX_ERRORTYPE SF_OMX_AllocateBuffer(
     }
     *ppBuffer = temp_bufferHeader;
     LOG(SF_LOG_INFO, "pBuffer address = %p\r\n", temp_bufferHeader->pBuffer);
-    ret = StoreOMXBuffer(pSfOMXComponent, temp_bufferHeader);
-    LOG(SF_LOG_PERF, "alloc size = %d, buffer count = %d\r\n",nSizeBytes, GetOMXBufferCount(pSfOMXComponent));
 
     FunctionOut();
 
@@ -1078,16 +1078,9 @@ static OMX_ERRORTYPE SF_OMX_FreeBuffer(
     OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
 {
     OMX_ERRORTYPE ret = OMX_ErrorNone;
-    OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
-    SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
 
     FunctionIn();
-    if (ClearOMXBuffer(pSfOMXComponent, pBufferHdr) != OMX_ErrorNone)
-    {
-        LOG(SF_LOG_ERR, "Could not found pBufferHdr = %p\r\n", pBufferHdr);
-        return OMX_ErrorBadParameter;
-    }
-    LOG(SF_LOG_PERF, "buffer count = %d\r\n", GetOMXBufferCount(pSfOMXComponent));
+
     if (nPortIndex == 1) {
         LOG(SF_LOG_INFO, "free %p on output buffer\r\n", pBufferHdr->pBuffer);
         pBufferHdr->pBuffer = NULL;

+ 6 - 12
soft_3rdpart/omx-il/component/video/enc/SF_OMX_Venc_encoder.c

@@ -75,7 +75,7 @@ static void OnEventArrived(Component com, unsigned long event, void *data, void
     switch (event)
     {
     case COMPONENT_EVENT_ENC_EMPTY_BUFFER_DONE:
-        pOMXBuffer = GetOMXBufferByAddr(pSfOMXComponent, (OMX_U8 *)pPortContainerExternal->pBuffer);
+        pOMXBuffer = (OMX_BUFFERHEADERTYPE *)pPortContainerExternal->pAppPrivate;
         if (pOMXBuffer == NULL)
         {
             LOG(SF_LOG_WARN, "Could not find omx buffer by address\r\n");
@@ -84,12 +84,11 @@ static void OnEventArrived(Component com, unsigned long event, void *data, void
         pSfOMXComponent->callbacks->EmptyBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
         LOG(SF_LOG_PERF, "OMX empty one buffer, address = %p, size = %d, nTimeStamp = %d, nFlags = %X\r\n",
         pOMXBuffer->pBuffer, pOMXBuffer->nFilledLen, pOMXBuffer->nTimeStamp, pOMXBuffer->nFlags);
-        ClearOMXBuffer(pSfOMXComponent, pOMXBuffer);
         break;
     case COMPONENT_EVENT_ENC_FILL_BUFFER_DONE:
     {
         struct timeval tv;
-        pOMXBuffer = GetOMXBufferByAddr(pSfOMXComponent, (OMX_U8 *)pPortContainerExternal->pBuffer);
+        pOMXBuffer = (OMX_BUFFERHEADERTYPE *)pPortContainerExternal->pAppPrivate;
         if (pOMXBuffer == NULL)
         {
             LOG(SF_LOG_WARN, "Could not find omx buffer by address\r\n");
@@ -129,7 +128,6 @@ static void OnEventArrived(Component com, unsigned long event, void *data, void
         ComponentImpl *pRendererComponent = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
         LOG(SF_LOG_PERF, "output queue count=%d/%d\r\n", pSfVideoImplement->functions->Queue_Get_Cnt(pRendererComponent->sinkPort.inputQ),
                                                     pSfOMXComponent->portDefinition[1].nBufferCountActual);
-        ClearOMXBuffer(pSfOMXComponent, pOMXBuffer);
     }
     break;
     case COMPONENT_EVENT_ENC_REGISTER_FB:
@@ -178,6 +176,7 @@ static OMX_ERRORTYPE SF_OMX_EmptyThisBuffer(
     pPortContainerExternal->nFilledLen = pBuffer->nFilledLen;
     pPortContainerExternal->nFlags = pBuffer->nFlags;
     pPortContainerExternal->nBufferIndex = (OMX_U32)pBuffer->pInputPortPrivate;
+    pPortContainerExternal->pAppPrivate = (void*)pBuffer;
     LOG(SF_LOG_INFO, "Index = %lu, Address = %p, Flag = %X\r\n",(OMX_U64)(pBuffer->pInputPortPrivate), pBuffer->pBuffer, pBuffer->nFlags);
     if (pSfVideoImplement->functions->Queue_Enqueue(pFeederComponent->srcPort.inputQ, (void *)pPortContainerExternal) != OMX_TRUE)
     {
@@ -190,9 +189,6 @@ static OMX_ERRORTYPE SF_OMX_EmptyThisBuffer(
     free(pPortContainerExternal);
     pFeederComponent->pause = OMX_FALSE;
 
-    ret = StoreOMXBuffer(pSfOMXComponent, pBuffer);
-    LOG(SF_LOG_PERF, "buffer count = %d\r\n", GetOMXBufferCount(pSfOMXComponent));
-
 EXIT:
     FunctionOut();
 
@@ -224,6 +220,7 @@ static OMX_ERRORTYPE SF_OMX_FillThisBuffer(
     memset(pPortContainerExternal, 0, sizeof(PortContainerExternal));
     pPortContainerExternal->pBuffer = pBuffer->pBuffer;
     pPortContainerExternal->nFilledLen = pBuffer->nAllocLen;
+    pPortContainerExternal->pAppPrivate = (void*)pBuffer;
     if (pSfVideoImplement->functions->Queue_Enqueue(pRendererComponent->sinkPort.inputQ, (void *)pPortContainerExternal) == -1)
     {
         LOG(SF_LOG_ERR, "%p:%p FAIL\r\n", pRendererComponent->sinkPort.inputQ, pPortContainerExternal);
@@ -234,8 +231,7 @@ static OMX_ERRORTYPE SF_OMX_FillThisBuffer(
                                                         pSfOMXComponent->portDefinition[1].nBufferCountActual);
     free(pPortContainerExternal);
     pRendererComponent->pause = OMX_FALSE;
-    ret = StoreOMXBuffer(pSfOMXComponent, pBuffer);
-    LOG(SF_LOG_PERF, "buffer count = %d\r\n", GetOMXBufferCount(pSfOMXComponent));
+
 EXIT:
     FunctionOut();
 
@@ -1137,10 +1133,8 @@ static OMX_ERRORTYPE SF_OMX_FreeBuffer(
     OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
 {
     OMX_ERRORTYPE ret = OMX_ErrorNone;
-    OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
-    SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
     FunctionIn();
-    LOG(SF_LOG_PERF, "buffer count = %d\r\n", GetOMXBufferCount(pSfOMXComponent));
+
     free(pBufferHdr);
 
     FunctionOut();

+ 0 - 78
soft_3rdpart/omx-il/core/SF_OMX_Core.c

@@ -227,84 +227,6 @@ OMX_API OMX_ERRORTYPE OMX_GetRolesOfComponent(
     return ret;
 }
 
-OMX_ERRORTYPE ClearOMXBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_BUFFERHEADERTYPE *pBuffer)
-{
-    OMX_U32 i = 0;
-    for (i = 0; i < sizeof(pSfOMXComponent->pBufferArray) / sizeof(pSfOMXComponent->pBufferArray[0]); i++)
-    {
-        if (pSfOMXComponent->pBufferArray[i] == pBuffer)
-        {
-            pSfOMXComponent->pBufferArray[i] = NULL;
-            LOG(SF_LOG_DEBUG, "Clear OMX buffer %p at index %d\r\n", pBuffer, i);
-            return OMX_ErrorNone;
-        }
-    }
-    if (i == sizeof(pSfOMXComponent->pBufferArray) / sizeof(pSfOMXComponent->pBufferArray[0]))
-    {
-        LOG(SF_LOG_ERR, "Could Not found omx buffer!\r\n");
-    }
-    return OMX_ErrorBadParameter;
-}
-
-OMX_U32 GetOMXBufferCount(SF_OMX_COMPONENT *pSfOMXComponent)
-{
-    OMX_U32 i = 0;
-    OMX_U32 count = 0;
-    for (i = 0; i < sizeof(pSfOMXComponent->pBufferArray) / sizeof(pSfOMXComponent->pBufferArray[0]); i++)
-    {
-        if (pSfOMXComponent->pBufferArray[i] != NULL)
-        {
-            LOG(SF_LOG_DEBUG, "find OMX buffer %p at index %d\r\n", pSfOMXComponent->pBufferArray[i], i);
-            count++;
-        }
-    }
-
-    return count;
-}
-
-OMX_ERRORTYPE StoreOMXBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_BUFFERHEADERTYPE *pBuffer)
-{
-    OMX_U32 i = 0;
-    for (i = 0; i < sizeof(pSfOMXComponent->pBufferArray) / sizeof(pSfOMXComponent->pBufferArray[0]); i++)
-    {
-        if (pSfOMXComponent->pBufferArray[i] == NULL)
-        {
-            pSfOMXComponent->pBufferArray[i] = pBuffer;
-            LOG(SF_LOG_DEBUG, "Store OMX buffer %p at index %d\r\n", pBuffer, i);
-            return OMX_ErrorNone;
-        }
-    }
-    if (i == sizeof(pSfOMXComponent->pBufferArray))
-    {
-        LOG(SF_LOG_ERR, "Buffer arrary full!\r\n");
-    }
-    return OMX_ErrorInsufficientResources;
-}
-
-OMX_BUFFERHEADERTYPE *GetOMXBufferByAddr(SF_OMX_COMPONENT *pSfOMXComponent, OMX_U8 *pAddr)
-{
-    OMX_U32 i = 0;
-    OMX_BUFFERHEADERTYPE *pOMXBuffer;
-    FunctionIn();
-    LOG(SF_LOG_INFO, "ADDR=%p\r\n", pAddr);
-    for (i = 0; i < sizeof(pSfOMXComponent->pBufferArray) / sizeof(pSfOMXComponent->pBufferArray[0]); i++)
-    {
-        pOMXBuffer = pSfOMXComponent->pBufferArray[i];
-        LOG(SF_LOG_DEBUG, "Compare OMX buffer %p at index %d with addr %p\r\n", pOMXBuffer, i, pAddr);
-        if (pOMXBuffer == NULL)
-        {
-            continue;
-        }
-        if (pOMXBuffer->pBuffer == pAddr)
-        {
-            return pOMXBuffer;
-        }
-    }
-    LOG(SF_LOG_ERR, "could not find buffer!\r\n");
-
-    FunctionOut();
-    return NULL;
-}
 void SF_LogMsgAppend(int level, const char *format, ...)
 {
     va_list ptr;

+ 0 - 4
soft_3rdpart/omx-il/core/SF_OMX_Core.h

@@ -101,10 +101,6 @@ extern "C"
 #endif
 
 int GetNumberOfComponent();
-OMX_BUFFERHEADERTYPE *GetOMXBufferByAddr(SF_OMX_COMPONENT *pSfOMXComponent, OMX_U8 *pAddr);
-OMX_ERRORTYPE StoreOMXBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_BUFFERHEADERTYPE *pBuffer);
-OMX_ERRORTYPE ClearOMXBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_BUFFERHEADERTYPE *pBuffer);
-OMX_U32 GetOMXBufferCount(SF_OMX_COMPONENT *pSfOMXComponent);
 
 #ifdef __cplusplus
 }

+ 2 - 0
soft_3rdpart/wave511/code/sample_v2/component/component.h

@@ -155,6 +155,8 @@ typedef struct PortContainerExternal
                                      buffer */
     Uint32 nOffset;            /**< start offset of valid data in bytes from
                                      the start of the buffer */
+    void*  pAppPrivate;        /**< pointer to any data the application
+                                     wants to associate with this buffer */
     Uint32 nBufferIndex;
     Uint32 nTickCount;         /**< Optional entry that the component and
                                      application can update with a tick count

+ 2 - 0
soft_3rdpart/wave521/code/sample_v2/component/component.h

@@ -148,6 +148,8 @@ typedef struct PortContainerExternal
                                      buffer */
     Uint32 nOffset;            /**< start offset of valid data in bytes from
                                      the start of the buffer */
+    void*  pAppPrivate;        /**< pointer to any data the application
+                                     wants to associate with this buffer */
     Uint32 nBufferIndex;
     Uint32 nTickCount;         /**< Optional entry that the component and
                                      application can update with a tick count