OMX_EmptyThisBuffer:remove OMX_BUFFERFLAG_EOS option sandbox/hackseung/hello_video2
authorHackseung Lee <lhs@dignsys.com>
Fri, 17 Nov 2017 09:11:29 +0000 (18:11 +0900)
committerHackseung Lee <lhs@dignsys.com>
Fri, 17 Nov 2017 09:11:49 +0000 (18:11 +0900)
OMX_EmptyThisBuffer 할 때 OMX_BUFFERFLAG_EOS을 사용 했기 때문에
callback.FillBufferDone에서 nFilledLen == 0이 콜백 됬음.

Change-Id: Ibf4040496a53f4cebf2ce69510d5453552f083d6
Signed-off-by: Hackseung Lee <lhs@dignsys.com>
hello_video2_normal.cpp
hello_video2_normal.h
hello_video2_tizen.cpp
hello_video2_tizen.h

index 2a571287d5c3ab1ebf3d240d93bb21b5d0911319..74de4d8ed5b17ae16ce83d46faa09d35e6747e3c 100644 (file)
@@ -22,6 +22,8 @@ static void *__port_settings_changed_thread(void *data)
        while (1) {
                OMWaitForXPortSettingsChanged();
 
+               fprintf(stderr, "Port settings changed...\n");
+
                hello_video->port_settings_changed();
                hello_video->fill_buffer();
        }
@@ -145,13 +147,7 @@ unsigned int hello_video2::FindAllNALu(unsigned char *source, unsigned int size,
        unsigned int num = 0;
        for (unsigned int i = 0; i < size; i++)
        {
-#if 0
-               if (source[i] == 0x00)
-               if (source[i + 1] == 0x00)
-               if (source[i + 2] == 0x00)
-#else
                if ((source[i] + source[i + 1] + source[i + 2]) == 0x00)
-#endif
                if (source[i + 3] == 0x01)
                {
 //                     fprintf(stderr, "%s[%d]i(%d)\n", __func__, __LINE__, i);
@@ -176,8 +172,10 @@ OMX_ERRORTYPE eventHandler(OMX_HANDLETYPE hComp, OMX_PTR pAppD,
                                                                OMX_EVENTTYPE event, OMX_U32 data1,
                                                                OMX_U32 data2, OMX_PTR eventData)
 {
-       fprintf(stderr, "%s[%d]\n", __func__, __LINE__);
        switch(event) {
+       case OMX_EventPortSettingsChanged:
+               OMXWakeupPortSettingsChanged();
+               break;
        case OMX_EventCmdComplete:
                switch (data1) {
                case OMX_CommandStateSet:
@@ -206,12 +204,8 @@ OMX_ERRORTYPE eventHandler(OMX_HANDLETYPE hComp, OMX_PTR pAppD,
        case OMX_EventError:
                fprintf(stderr, "Err:%s[%d]%s\n.", __func__, __LINE__, hello_video2::OMX_strerror((OMX_ERRORTYPE) data1));
                break;
-       case OMX_EventPortSettingsChanged:
-               fprintf(stderr, "Port settings changed...\n");
-               OMXWakeupPortSettingsChanged();
-               break;
        case OMX_EventBufferFlag:
-               fprintf(stderr, "%s[%d]OMX_EventBufferFlag\n", __func__, __LINE__);
+               fprintf(stderr, "%s[%d]OMX_EventBufferFlag, data1(%d), data1(%d)\n", __func__, __LINE__, data1, data2);
                break;
        case OMX_EventResourcesAcquired:
                fprintf(stderr, "%s[%d]OMX_EventResourcesAcquired\n", __func__, __LINE__);
@@ -247,8 +241,6 @@ OMX_ERRORTYPE bufferFilled(OMX_HANDLETYPE hComp, OMX_PTR pAppD, OMX_BUFFERHEADER
        fprintf(stderr, "phello_video2->output_buffer_usage:0x%08x,pAppPrivate:0x%08x,nFilledLenL:%d\n", phello_video2->output_buffer_usage, *((unsigned int *)buffer->pAppPrivate), buffer->nFilledLen);
        OMXWakeUpFilled();
 
-       OMXWakeUpFilled();
-
        if (buffer->nFilledLen == 0) {
                        phello_video2->fill_buffer();
 
@@ -267,7 +259,7 @@ hello_video2::hello_video2()
        bcm_host_init();
 
        hello_video2::Init();
-       
+
        input_buffer_usage = 0;
        output_buffer_usage = 0;
        input_buffer_number[0] = 0;
@@ -319,7 +311,7 @@ hello_video2::hello_video2()
 
 /******************************************************************************/
 
-hello_video2::~hello_video2() 
+hello_video2::~hello_video2()
 {
 }
 
@@ -565,8 +557,9 @@ OMX_ERRORTYPE hello_video2::set_state(OMX_STATETYPE nState)
 {
        OMX_SendCommand(component, OMX_CommandStateSet, nState, NULL);
        OMXWaitForState(nState);
+
        return OMX_ErrorNone;
-};
+}
 
 OMX_ERRORTYPE hello_video2::block_until_port_changed(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_BOOL bEnabled) {
        OMX_ERRORTYPE r;
@@ -634,7 +627,7 @@ OMX_ERRORTYPE hello_video2::decode_frame(unsigned char * data, unsigned int size
                        void * pStart = &data[nalu[i].pos];
                        memcpy(iBuffer->pBuffer, pStart, nalu[i].size);
                        iBuffer->nOffset = 0;
-                       iBuffer->nFlags = OMX_BUFFERFLAG_EOS;
+//                     iBuffer->nFlags = OMX_BUFFERFLAG_EOS;
                        iBuffer->nFilledLen = nalu[i].size;
                        input_buffer_usage ^= *((unsigned int *)iBuffer->pAppPrivate);
                        OMX_EmptyThisBuffer(component, iBuffer);
@@ -724,11 +717,13 @@ OMX_ERRORTYPE hello_video2::fill_buffer(OMX_PTR pAppD, OMX_BUFFERHEADERTYPE *buf
 
        return OMX_ErrorNone;
 }
+
 OMX_ERRORTYPE hello_video2::fill_buffer()
 {
        OMX_BUFFERHEADERTYPE *out_buffer;
 
        out_buffer = get_free_output_buffer();
+
        OMX_FillThisBuffer(component, out_buffer);
 
        return OMX_ErrorNone;
@@ -835,10 +830,10 @@ OMX_ERRORTYPE hello_video2::prepare_input_buffers(unsigned int num)
                ErrorCode = OMX_AllocateBuffer(component, &input_buffer_header[i], 130, pPrivateData, input_port_def.nBufferSize);
 
                if (ErrorCode == OMX_ErrorNone) {
-                       fprintf(stderr, "Okay:prepare_input_buffers:Output buffer %u allocated,%d.\n", i + 1, input_port_def.nBufferSize);
+                       fprintf(stderr, "Okay:prepare_input_buffers:Input buffer %u allocated,%d.\n", i + 1, input_port_def.nBufferSize);
                }
                else {
-                       fprintf(stderr, "Err:prepare_input_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));                      
+                       fprintf(stderr, "Err:prepare_input_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
                }
        }
 
@@ -873,7 +868,7 @@ OMX_ERRORTYPE hello_video2::prepare_output_buffers(unsigned int num)
                        fprintf(stderr, "Okay:prepare_output_buffers: Port %d: Output buffer %d: allocated %d:buff %p:output_buffer_usage 0x%x\n", output_port_def.nPortIndex, i + 1, output_port_def.nBufferSize, buf, output_buffer_usage);
                }
                else {
-                       fprintf(stderr, "Err:prepare_output_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));                     
+                       fprintf(stderr, "Err:prepare_output_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
                }
        }
 
@@ -890,9 +885,10 @@ OMX_BUFFERHEADERTYPE * hello_video2::get_free_input_buffer()
                                return input_buffer_header[i];
                        }
                }
-               OMXWaitForEmpty();
        }
 
+       GetFreeOutBufferUnlock();
+
        return NULL;
 }
 
@@ -900,10 +896,12 @@ OMX_BUFFERHEADERTYPE * hello_video2::get_free_input_buffer()
 
 OMX_BUFFERHEADERTYPE * hello_video2::get_free_output_buffer()
 {
+       GetFreeOutBufferLock();
+
        if (output_buffer_usage == 0) {
                for (unsigned int i = 0; i < output_port_def.nBufferCountActual; i++) {
-                       output_buffer_usage |= 0x1 < i;
-               }               
+                       output_buffer_usage |= 0x1 << i;
+               }
        }
 
        while (true)
@@ -911,13 +909,13 @@ OMX_BUFFERHEADERTYPE * hello_video2::get_free_output_buffer()
                for (unsigned int i = 0; i < output_port_def.nBufferCountActual; i++) {
                        if ((output_buffer_usage & *((unsigned int *)output_buffer_header[i]->pAppPrivate)) != 0) {
                                output_buffer_usage &= ~(*((unsigned int *)output_buffer_header[i]->pAppPrivate));
-                               fprintf(stderr, "get_free_output_buffer:0x%08x\n", output_buffer_usage);
+                               GetFreeOutBufferUnlock();
+                               fprintf(stderr, "get_free_output_buffer:output_buffer_usage==0x%08x\n", output_buffer_usage);
                                return output_buffer_header[i];
                        }
                }
-               fprintf(stderr, "OMXWaitForFilled wait..\n");
+
                OMXWaitForFilled();
-               fprintf(stderr, "OMXWaitForFilled done!.\n");
        }
 
        return NULL;
@@ -952,7 +950,7 @@ int main (int argc, char **argv)
 ////////////////////////////////////////////////////////////////////
 //                                                                //
 //       I dont worry form now.                                   //
-//                                                                //   
+//                                                                //
 ////////////////////////////////////////////////////////////////////
 
        return 0;
index 525f9f09d3dd3db535805f7eb74bd742be4a6abd..43203a50d5a95c454c15de92a77339480a0b23c2 100644 (file)
@@ -28,7 +28,7 @@ typedef struct
        void** data;
 } DUMP_FILE_INFO;
 
-pthread_mutex_t OMXMutex, OMXEmptyMutex, OMXFilledMutex, OMXPortSettingsChangedMutex;
+pthread_mutex_t OMXMutex, OMXEmptyMutex, OMXFilledMutex, OMXPortSettingsChangedMutex, OMXGetFreeOutBufferMutex;
 pthread_cond_t OMXStateCond, OMXEmptyCond, OMXFilledCond, OMXPortSettingsChangedCond;
 
 void mutex_init()
@@ -49,6 +49,10 @@ void mutex_init()
                printf("Can't init port settings changed mutex.\n");
        }
 
+       if (pthread_mutex_init(&OMXGetFreeOutBufferMutex, NULL) != 0) {
+               printf("Can't init OMXGetFreeOutBufferMutex mutex.\n");
+       }
+
        OMXStateCond = PTHREAD_COND_INITIALIZER;
        OMXEmptyCond = PTHREAD_COND_INITIALIZER;
        OMXFilledCond = PTHREAD_COND_INITIALIZER;
@@ -110,7 +114,20 @@ public:
 /*****************************************************************************/
 
 hello_video2 * phello_video2 = NULL;
-/**/
+
+/*****************************************************************************/
+
+void GetFreeOutBufferLock()
+{
+       pthread_mutex_lock(&OMXGetFreeOutBufferMutex);
+}
+void GetFreeOutBufferUnlock()
+{
+       pthread_mutex_unlock(&OMXGetFreeOutBufferMutex);
+}
+
+/*****************************************************************************/
+
 void OMXWaitForState(OMX_STATETYPE nState)
 {
        pthread_mutex_lock(&OMXMutex);
index e85be7a7a4d62b3135eed7f6ca984cacf39cf87b..725219c8f945f5c36dfbfa7b24b715cb70a1d837 100644 (file)
@@ -147,13 +147,7 @@ unsigned int hello_video2::FindAllNALu(unsigned char *source, unsigned int size,
        unsigned int num = 0;
        for (unsigned int i = 0; i < size; i++)
        {
-#if 0
-               if (source[i] == 0x00)
-               if (source[i + 1] == 0x00)
-               if (source[i + 2] == 0x00)
-#else
                if ((source[i] + source[i + 1] + source[i + 2]) == 0x00)
-#endif
                if (source[i + 3] == 0x01)
                {
 //                     fprintf(stderr, "%s[%d]i(%d)\n", __func__, __LINE__, i);
@@ -236,7 +230,7 @@ OMX_ERRORTYPE bufferFilled(OMX_HANDLETYPE hComp, OMX_PTR pAppD, OMX_BUFFERHEADER
 {
        fprintf(stderr, "phello_video2->output_buffer_usage:0x%08x,pAppPrivate:0x%08x,nFilledLenL:%d\n", phello_video2->output_buffer_usage, *((unsigned int *)buffer->pAppPrivate), buffer->nFilledLen);
        OMXWakeUpFilled();
-       
+
        fprintf(stderr, "buffer filled done:%p\n", buffer->pBuffer);
        if (buffer->nFilledLen == 0) {
                phello_video2->fill_buffer();
@@ -315,7 +309,7 @@ hello_video2::hello_video2()
 
 /******************************************************************************/
 
-hello_video2::~hello_video2() 
+hello_video2::~hello_video2()
 {
 }
 
@@ -561,8 +555,9 @@ OMX_ERRORTYPE hello_video2::set_state(OMX_STATETYPE nState)
 {
        OMX_SendCommand(component, OMX_CommandStateSet, nState, NULL);
        OMXWaitForState(nState);
+
        return OMX_ErrorNone;
-};
+}
 
 OMX_ERRORTYPE hello_video2::block_until_port_changed(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_BOOL bEnabled) {
        OMX_ERRORTYPE r;
@@ -630,7 +625,7 @@ OMX_ERRORTYPE hello_video2::decode_frame(unsigned char * data, unsigned int size
                        void * pStart = &data[nalu[i].pos];
                        memcpy(iBuffer->pBuffer, pStart, nalu[i].size);
                        iBuffer->nOffset = 0;
-                       iBuffer->nFlags = OMX_BUFFERFLAG_EOS;
+//                     iBuffer->nFlags = OMX_BUFFERFLAG_EOS;
                        iBuffer->nFilledLen = nalu[i].size;
                        input_buffer_usage ^= *((unsigned int *)iBuffer->pAppPrivate);
                        OMX_EmptyThisBuffer(component, iBuffer);
@@ -834,10 +829,10 @@ OMX_ERRORTYPE hello_video2::prepare_input_buffers(unsigned int num)
                ErrorCode = OMX_AllocateBuffer(component, &input_buffer_header[i], 130, pPrivateData, input_port_def.nBufferSize);
 
                if (ErrorCode == OMX_ErrorNone) {
-                       fprintf(stderr, "Okay:prepare_input_buffers:Output buffer %u allocated,%d.\n", i + 1, input_port_def.nBufferSize);
+                       fprintf(stderr, "Okay:prepare_input_buffers:Input buffer %u allocated,%d.\n", i + 1, input_port_def.nBufferSize);
                }
                else {
-                       fprintf(stderr, "Err:prepare_input_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));                      
+                       fprintf(stderr, "Err:prepare_input_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
                }
        }
 
@@ -867,18 +862,18 @@ OMX_ERRORTYPE hello_video2::prepare_output_buffers(unsigned int num)
                } else {
                        buf = (OMX_U8*)malloc(output_port_def.nBufferSize);
                }
-               
+
 #if 1 // Check if handle_bo.ptr is valid.
                memset(handle_bo.ptr, 0x00, output_port_def.nBufferSize);
 #endif // Check
 
-               ErrorCode = OMX_UseBuffer(component, &output_buffer_header[i], output_port_def.nPortIndex, pPrivateData, output_port_def.nBufferSize, buf);
+               ErrorCode = OMX_UseBuffer(component, &output_buffer_header[i], output_port_def.nPortIndex, pPrivateData, output_port_def.nBufferSize, buf + 8);
 
                if (ErrorCode == OMX_ErrorNone) {
                        fprintf(stderr, "Okay:prepare_output_buffers: Port %d: Output buffer %d: allocated %d:buff %p:output_buffer_usage 0x%x\n", output_port_def.nPortIndex, i + 1, output_port_def.nBufferSize, buf, output_buffer_usage);
                }
                else {
-                       fprintf(stderr, "Err:prepare_output_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));                     
+                       fprintf(stderr, "Err:prepare_output_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
                }
        }
 
@@ -905,10 +900,12 @@ OMX_BUFFERHEADERTYPE * hello_video2::get_free_input_buffer()
 
 OMX_BUFFERHEADERTYPE * hello_video2::get_free_output_buffer()
 {
+       GetFreeOutBufferLock();
+
        if (output_buffer_usage == 0) {
                for (unsigned int i = 0; i < output_port_def.nBufferCountActual; i++) {
-                       output_buffer_usage |= 0x1 < i;
-               }               
+                       output_buffer_usage |= 0x1 << i;
+               }
        }
 
        while (true)
@@ -916,13 +913,13 @@ OMX_BUFFERHEADERTYPE * hello_video2::get_free_output_buffer()
                for (unsigned int i = 0; i < output_port_def.nBufferCountActual; i++) {
                        if ((output_buffer_usage & *((unsigned int *)output_buffer_header[i]->pAppPrivate)) != 0) {
                                output_buffer_usage &= ~(*((unsigned int *)output_buffer_header[i]->pAppPrivate));
-                               fprintf(stderr, "get_free_output_buffer:0x%08x\n", output_buffer_usage);
+                               GetFreeOutBufferUnlock();
+                               fprintf(stderr, "get_free_output_buffer:output_buffer_usage==0x%08x\n", output_buffer_usage);
                                return output_buffer_header[i];
                        }
                }
-               fprintf(stderr, "OMXWaitForFilled wait..\n");
+
                OMXWaitForFilled();
-               fprintf(stderr, "OMXWaitForFilled done!.\n");
        }
 
        return NULL;
@@ -958,7 +955,7 @@ int main (int argc, char **argv)
 ////////////////////////////////////////////////////////////////////
 //                                                                //
 //       I dont worry form now.                                   //
-//                                                                //   
+//                                                                //
 ////////////////////////////////////////////////////////////////////
 
        return 0;
index 73085217a426a07f7d7f6b46592387a72ea9b708..f25e9e1ebf8a4613e3510f959f92bd5facd8b766 100644 (file)
@@ -31,7 +31,7 @@ typedef struct
        void** data;
 } DUMP_FILE_INFO;
 
-pthread_mutex_t OMXMutex, OMXEmptyMutex, OMXFilledMutex, OMXPortSettingsChangedMutex;
+pthread_mutex_t OMXMutex, OMXEmptyMutex, OMXFilledMutex, OMXPortSettingsChangedMutex, OMXGetFreeOutBufferMutex;
 pthread_cond_t OMXStateCond, OMXEmptyCond, OMXFilledCond, OMXPortSettingsChangedCond;
 
 void mutex_init()
@@ -52,6 +52,10 @@ void mutex_init()
                printf("Can't init port settings changed mutex.\n");
        }
 
+       if (pthread_mutex_init(&OMXGetFreeOutBufferMutex, NULL) != 0) {
+               printf("Can't init OMXGetFreeOutBufferMutex mutex.\n");
+       }
+
        OMXStateCond = PTHREAD_COND_INITIALIZER;
        OMXEmptyCond = PTHREAD_COND_INITIALIZER;
        OMXFilledCond = PTHREAD_COND_INITIALIZER;
@@ -114,6 +118,20 @@ public:
 /*****************************************************************************/
 
 hello_video2 * phello_video2 = NULL;
+
+/*****************************************************************************/
+
+void GetFreeOutBufferLock()
+{
+       pthread_mutex_lock(&OMXGetFreeOutBufferMutex);
+}
+void GetFreeOutBufferUnlock()
+{
+       pthread_mutex_unlock(&OMXGetFreeOutBufferMutex);
+}
+
+/*****************************************************************************/
+
 void OMXWaitForState(OMX_STATETYPE nState)
 {
        pthread_mutex_lock(&OMXMutex);