From 832e05fc58f7a5a736415d9e7a49563f9e3d7c4c Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 23 Aug 2014 16:05:40 +0200 Subject: [PATCH] Hardware accelerated decoding is now working --- imageomx.cc | 79 +++++++++++++++++++++++++---------------------------- videoomx.cc | 19 ++++++++++++- videoomx.h | 1 + 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/imageomx.cc b/imageomx.cc index cd9bc7b..e12b86a 100644 --- a/imageomx.cc +++ b/imageomx.cc @@ -241,12 +241,12 @@ int ImageOMX::AllocateCodecsOMX(unsigned char * buffer, unsigned int length) bool ImageOMX::decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length) { if (pictInfValid) return false; // does support only one image at a Time; - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 1"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 1"); EGLPictureCreator * pictcreat =dynamic_cast(Osd::getInstance()); if (buffer[0]!= 0xff || buffer[1] !=0xd8) return false; // Jpeg magic numbers - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 2"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 2"); VideoOMX *video=(VideoOMX*)Video::getInstance(); @@ -312,8 +312,8 @@ bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigne video->LockClock(); - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 3"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 3"); video->WaitForEvent(omx_imag_decode,OMX_EventPortSettingsChanged); @@ -324,8 +324,8 @@ bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigne port_def_type.nSize=sizeof(port_def_type); port_def_type.nVersion.nVersion=OMX_VERSION; port_def_type.nPortIndex=omx_image_output_port; - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 3a"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 3a"); error=OMX_GetParameter(omx_imag_decode,OMX_IndexParamPortDefinition, &port_def_type); if (error != OMX_ErrorNone) { @@ -334,8 +334,8 @@ bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigne video->UnlockClock(); return false; } - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 4"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 4"); @@ -370,8 +370,8 @@ bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigne } - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 5 6"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 5 6"); error=OMX_GetHandle(&omx_egl_render,VPE_OMX_EGL_REND,NULL,&callbacks); if (error!=OMX_ErrorNone){ @@ -510,8 +510,8 @@ bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigne return 0; } - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 7"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 7"); video->WaitForEvent(omx_egl_render,OMX_EventPortSettingsChanged); Log::getInstance()->log("Image", Log::DEBUG, @@ -538,8 +538,8 @@ bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigne } buf_head_egl->pAppPrivate=this; - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 8 a"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 8 a"); video->EnablePort(omx_imag_decode,omx_image_output_port,false); @@ -561,12 +561,12 @@ bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigne } - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 9"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 9"); //video->EnablePort(omx_egl_render,omx_egl_output_port,false); - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture 10"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture 10"); omx_egl_filled = false; error = OMX_FillThisBuffer(omx_egl_render, buf_head_egl); @@ -591,8 +591,8 @@ bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigne } omx_egl_filled = false; - Log::getInstance()->log("Image", Log::DEBUG, - "decodePicture left"); +// Log::getInstance()->log("Image", Log::DEBUG, +// "decodePicture left"); @@ -732,13 +732,13 @@ int ImageOMX::DeAllocateCodecsOMX() OMX_ERRORTYPE error; omx_running=false; VideoOMX *video=(VideoOMX*)Video::getInstance(); - Log::getInstance()->log("Image", Log::DEBUG, "enter deallocatecodecsomx"); +// Log::getInstance()->log("Image", Log::DEBUG, "enter deallocatecodecsomx"); - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 1"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 1"); - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 2"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 2"); video->LockClock(); if (omx_imag_decode/*dec*/) { @@ -769,7 +769,7 @@ int ImageOMX::DeAllocateCodecsOMX() - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 3"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 3"); error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_output_port, NULL); if (error!=OMX_ErrorNone) { @@ -783,7 +783,7 @@ int ImageOMX::DeAllocateCodecsOMX() Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_render ChangeComponentState"); } - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 4"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 4"); error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_input_port, NULL); if (error!=OMX_ErrorNone) { @@ -791,7 +791,7 @@ int ImageOMX::DeAllocateCodecsOMX() } - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 5"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 5"); error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_output_port, NULL); if (error!=OMX_ErrorNone) { @@ -799,13 +799,13 @@ int ImageOMX::DeAllocateCodecsOMX() } - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6"); if (!video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_input_port) || !video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_output_port)) { Log::getInstance()->log("Image", Log::DEBUG, "flush cmd clock shed failed"); } - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 a"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 a"); } error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_input_port, NULL); if (error!=OMX_ErrorNone) { @@ -823,26 +823,19 @@ int ImageOMX::DeAllocateCodecsOMX() buf_head_egl=NULL; - - - - - - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 b"); - - +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 b"); if (!video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_input_port) || !video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_output_port) ) { Log::getInstance()->log("Image", Log::DEBUG, "flush cmd clock shed failed"); } - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 c"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 c"); DestroyInputBufsOMX(); //We have to make sure that no buffers are in use - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 7"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 7"); //todo flushing if (!video->DisablePort(omx_imag_decode,omx_image_output_port,true)) { @@ -870,7 +863,7 @@ int ImageOMX::DeAllocateCodecsOMX() } - Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 8"); +// Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 8"); //error=OMX_FreeHandle(omx_aud_dec); @@ -886,6 +879,8 @@ int ImageOMX::DeAllocateCodecsOMX() } video->UnlockClock(); + video->clearEventsForComponent(omx_imag_decode); + video->clearEventsForComponent(omx_egl_render); // removes spurious error messages omx_imag_decode/*dec*/=NULL; omx_egl_render/*dec*/=NULL; @@ -893,7 +888,7 @@ int ImageOMX::DeAllocateCodecsOMX() video->UnlockClock(); } - Log::getInstance()->log("Image", Log::DEBUG, "leave deallocate codecs OMX"); +// Log::getInstance()->log("Image", Log::DEBUG, "leave deallocate codecs OMX"); return 1; } diff --git a/videoomx.cc b/videoomx.cc index 81a37d4..6298602 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -136,7 +136,7 @@ OMX_ERRORTYPE VideoOMX::EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1, OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data) { - Log::getInstance()->log("Video", Log::NOTICE, "eventHandler %x %x %x %x %x",handle,event_type,data1,data2,event_data); + //Log::getInstance()->log("Video", Log::NOTICE, "eventHandler %x %x %x %x %x",handle,event_type,data1,data2,event_data); struct VPE_OMX_EVENT new_event; new_event.handle=handle; @@ -1735,6 +1735,23 @@ int VideoOMX::clearEvents() return 1; } +int VideoOMX::clearEventsForComponent(OMX_HANDLETYPE handle) +{ + omx_event_mutex.Lock(); + list::iterator itty=omx_events.begin(); + while (itty!=omx_events.end()) { + VPE_OMX_EVENT current=*itty; + if (current.handle==handle) { //this is ours + itty=omx_events.erase(itty); + continue; + } + itty++; + + } + omx_event_mutex.Unlock(); + return 1; +} + void VideoOMX::checkForStalledBuffers() { //Log::getInstance()->log("Video", Log::DEBUG, "Check stalled"); diff --git a/videoomx.h b/videoomx.h index 5a2c39c..8e72a51 100644 --- a/videoomx.h +++ b/videoomx.h @@ -211,6 +211,7 @@ class VideoOMX : public Video int EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait); int DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait=true); int clearEvents(); + int clearEventsForComponent(OMX_HANDLETYPE handle); void checkForStalledBuffers(); -- 2.39.5