Просмотр исходного кода

omx-il: fix ffmpeg/gst jpg decode do not exit

OMX should send back all buffers that allocted by ffmpeg/gst, otherwise it blocked.

Signed-off-by: Som Qin <som.qin@starfivetech.com>
Som Qin 1 год назад
Родитель
Сommit
96be66ca65

+ 10 - 0
soft_3rdpart/omx-il/component/image/common/SF_OMX_mjpeg_common.c

@@ -617,6 +617,16 @@ void CodaJ12FlushBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_U32 nPortNumber)
         }
         break;
     case OMX_OUTPUT_PORT_INDEX:
+        for(int i = 0; i < MCA_MAX_INDEX; i++){
+            pOMXBuffer = pSfCodaj12Implement->mesCacheArr[i].pBuffer;
+            LOG(SF_LOG_INFO, "Flush Buffer %p\r\n", pOMXBuffer);
+            if (pOMXBuffer != NULL)
+            {
+                pOMXBuffer->nFilledLen = 0;
+                pOMXBuffer->nFlags = OMX_BUFFERFLAG_EOS;
+                pSfOMXComponent->callbacks->FillBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
+            }
+        }
         while (OMX_TRUE)
         {
             if (msgrcv(pSfCodaj12Implement->sOutputMessageQueue, (void *)&data, BUFSIZ, 0, IPC_NOWAIT) < 0)

+ 10 - 7
soft_3rdpart/omx-il/component/image/common/SF_OMX_mjpeg_common.h

@@ -40,6 +40,8 @@
 #define CODAJ12_OUTPUT_BUF_NUMBER 4
 #define CODAJ12_INPUT_BUF_NUMBER 1
 
+#define MCA_MAX_INDEX 1
+
 typedef struct _SF_CODAJ12_FUNCTIONS
 {
     JpgRet (*JPU_Init)(void);
@@ -91,6 +93,13 @@ typedef struct _THREAD_HANDLE_TYPE {
     int                stack_size;
 } THREAD_HANDLE_TYPE;
 
+typedef struct Message
+{
+    long msg_type;
+    OMX_U32 msg_flag;
+    OMX_BUFFERHEADERTYPE *pBuffer;
+} Message;
+
 typedef struct _SF_CODAJ12_IMPLEMEMT
 {
     DecConfigParam *config;
@@ -106,6 +115,7 @@ typedef struct _SF_CODAJ12_IMPLEMEMT
     OMX_S32 sInputMessageQueue;
     OMX_S32 sOutputMessageQueue;
     OMX_S32 sBufferDoneQueue;
+    Message mesCacheArr[MCA_MAX_INDEX];
     OMX_HANDLETYPE pProcessThread;
     OMX_BOOL bThreadRunning;
     OMX_STATETYPE currentState;
@@ -113,13 +123,6 @@ typedef struct _SF_CODAJ12_IMPLEMEMT
     OMX_BOOL allocBufFlag;
 } SF_CODAJ12_IMPLEMEMT;
 
-typedef struct Message
-{
-    long msg_type;
-    OMX_U32 msg_flag;
-    OMX_BUFFERHEADERTYPE *pBuffer;
-} Message;
-
 enum port_index
 {
     OMX_INPUT_PORT_INDEX = 0,

+ 11 - 14
soft_3rdpart/omx-il/component/image/dec/SF_OMX_Mjpeg_decoder.c

@@ -33,7 +33,7 @@ static OMX_ERRORTYPE SF_OMX_EmptyThisBuffer(
     SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
     SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
 
-    LOG(SF_LOG_DEBUG, "nFilledLen = %d, nFlags = %d, pBuffer = %p\r\n", pBuffer->nFilledLen, pBuffer->nFlags, pBuffer->pBuffer);
+    LOG(SF_LOG_DEBUG, "nFilledLen = %d, nFlags = %d, header = %p, pBuffer = %p\r\n", pBuffer->nFilledLen, pBuffer->nFlags, pBuffer, pBuffer->pBuffer);
 
     if (pBuffer->nFilledLen == 0 || (pBuffer->nFlags & 0x1) == 0x1)
     {
@@ -78,9 +78,6 @@ EXIT:
     return ret;
 }
 
-#define MAX_INDEX 1
-#define MCA_MAX_INDEX 1
-Message mesCacheArr[MCA_MAX_INDEX];
 int MCAIndex = 0;
 int dataCount = 0;
 
@@ -100,7 +97,7 @@ static OMX_ERRORTYPE SF_OMX_FillThisBuffer(
     OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
     SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
     SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
-    LOG(SF_LOG_DEBUG, "nFilledLen = %d, nFlags = %d, pBuffer = %p\r\n", pBuffer->nFilledLen, pBuffer->nFlags, pBuffer->pBuffer);
+    LOG(SF_LOG_DEBUG, "nFilledLen = %d, nFlags = %d, header = %p, pBuffer = %p\r\n", pBuffer->nFilledLen, pBuffer->nFlags, pBuffer, pBuffer->pBuffer);
     // if (pSfCodaj12Implement->functions->Queue_Enqueue(&pSfCodaj12Implement->decodeBufferQueue, (void *)pBuffer->pBuffer) == FALSE)
     // {
     //     return OMX_ErrorInsufficientResources;
@@ -113,17 +110,17 @@ static OMX_ERRORTYPE SF_OMX_FillThisBuffer(
     // TODO start:
     // Temporary store one buff here to prevent the buff from being refill too soon.
     // It is a workaround for issue and should be fixed further.
-    MCAIndex = (dataCount++)%MCA_MAX_INDEX;
-    if(dataCount < MCA_MAX_INDEX)
+    MCAIndex = (dataCount)%MCA_MAX_INDEX;
+    if(dataCount++ < MCA_MAX_INDEX)
     {
-        mesCacheArr[MCAIndex] = data;
+        pSfCodaj12Implement->mesCacheArr[MCAIndex] = data;
         FunctionOut();
         return ret;
     }
     else
     {
-        outputData = mesCacheArr[MCAIndex];
-        mesCacheArr[MCAIndex] = data;
+        outputData = pSfCodaj12Implement->mesCacheArr[MCAIndex];
+        pSfCodaj12Implement->mesCacheArr[MCAIndex] = data;
     }
     // TODO end
 
@@ -247,8 +244,8 @@ static OMX_ERRORTYPE SF_OMX_AllocateBuffer(
         return OMX_ErrorInsufficientResources;
     }
     *ppBuffer = temp_bufferHeader;
-    LOG(SF_LOG_INFO, "nPortIndex = %d, pBuffer address = %p, nFilledLen = %d, nSizeBytes = %d\r\n",
-            nPortIndex, temp_bufferHeader->pBuffer, temp_bufferHeader->nFilledLen, nSizeBytes);
+    LOG(SF_LOG_INFO, "nPortIndex = %d, header = %p, pBuffer address = %p, nFilledLen = %d, nSizeBytes = %d\r\n",
+            nPortIndex, temp_bufferHeader, temp_bufferHeader->pBuffer, temp_bufferHeader->nFilledLen, nSizeBytes);
     FunctionOut();
     return ret;
 }
@@ -943,8 +940,8 @@ static OMX_BOOL FillBufferDone(SF_OMX_COMPONENT *pSfOMXComponent, OMX_BUFFERHEAD
         LOG(SF_LOG_WARN, "Decoding fps: %d \r\n", fps);
     }
 
-    LOG(SF_LOG_PERF, "OMX finish one buffer, address = %p, size = %d, nTimeStamp = %d, nFlags = %X\r\n",
-            pBuffer->pBuffer, pBuffer->nFilledLen, pBuffer->nTimeStamp, pBuffer->nFlags);
+    LOG(SF_LOG_PERF, "OMX finish one buffer, header = %p, address = %p, size = %d, nTimeStamp = %d, nFlags = %X\r\n",
+            pBuffer, pBuffer->pBuffer, pBuffer->nFilledLen, pBuffer->nTimeStamp, pBuffer->nFlags);
     // Following comment store data loal
     // {
     //     FILE *fb = fopen("./out.bcp", "ab+");