From: Hackseung Lee Date: Fri, 17 Nov 2017 09:11:29 +0000 (+0900) Subject: OMX_EmptyThisBuffer:remove OMX_BUFFERFLAG_EOS option X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Fsandbox%2Fhackseung%2Fhello_video2;p=platform%2Fadaptation%2Fbroadcom%2Flibomxil-vc4.git OMX_EmptyThisBuffer:remove OMX_BUFFERFLAG_EOS option OMX_EmptyThisBuffer 할 때 OMX_BUFFERFLAG_EOS을 사용 했기 때문에 callback.FillBufferDone에서 nFilledLen == 0이 콜백 됬음. Change-Id: Ibf4040496a53f4cebf2ce69510d5453552f083d6 Signed-off-by: Hackseung Lee --- diff --git a/hello_video2_normal.cpp b/hello_video2_normal.cpp index 2a57128..74de4d8 100644 --- a/hello_video2_normal.cpp +++ b/hello_video2_normal.cpp @@ -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; diff --git a/hello_video2_normal.h b/hello_video2_normal.h index 525f9f0..43203a5 100644 --- a/hello_video2_normal.h +++ b/hello_video2_normal.h @@ -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); diff --git a/hello_video2_tizen.cpp b/hello_video2_tizen.cpp index e85be7a..725219c 100644 --- a/hello_video2_tizen.cpp +++ b/hello_video2_tizen.cpp @@ -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; diff --git a/hello_video2_tizen.h b/hello_video2_tizen.h index 7308521..f25e9e1 100644 --- a/hello_video2_tizen.h +++ b/hello_video2_tizen.h @@ -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);