2 Copyright 2004-2005 Chris Tallon, 2009,2014 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP. If not, see <https://www.gnu.org/licenses/>.
24 #include "woptionpane.h"
26 #include "osdopenvg.h"
30 ImageOMX::ImageOMX(OsdVector::PictureReader * treader):OsdVector::PictureDecoder(treader)
36 omx_imag_decode/*dec*/=NULL;
37 omx_egl_render/*dec*/=NULL;
40 curformat = Unsupported;
42 strcpy(L_VPE_OMX_IMAGE_DECODER, VPE_OMX_IMAGE_DECODER);
43 strcpy(L_VPE_OMX_EGL_REND, VPE_OMX_EGL_REND);
53 // AllocateCodecsOMX();
56 void ImageOMX::shutdown()
58 Log::getInstance()->log("ImageOMX", Log::DEBUG, "shutdown");
59 //DeAllocateCodecsOMX();
66 OMX_ERRORTYPE ImageOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE /*hcomp*/,OMX_IN OMX_PTR /*appdata*/,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
68 //Log::getInstance()->log("Image", Log::NOTICE, "EmptyBufferDone");
69 ImageOMX* image = static_cast<ImageOMX*>(buffer->pAppPrivate);
70 image->ReturnEmptyOMXBuffer(buffer);
75 void ImageOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
76 input_bufs_omx_mutex.lock();
77 /*if (buffer->pBuffer) {
78 free(buffer->pBuffer);
79 buffer->pBuffer = NULL;
82 //Log::getInstance()->log("Image", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
83 input_bufs_omx_free.push_back(buffer);
84 //Log::getInstance()->log("Image", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
85 input_bufs_omx_mutex.unlock();
86 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
91 OMX_ERRORTYPE ImageOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE /*hcomp*/, OMX_IN OMX_PTR /*appdata*/,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
92 Log::getInstance()->log("ImageOmx", Log::NOTICE, "FillBufferDone");
93 ImageOMX* image = static_cast<ImageOMX*>(buffer->pAppPrivate);
94 image->ReturnFillOMXBuffer(buffer);
98 void ImageOMX::ReturnFillOMXBuffer(OMX_BUFFERHEADERTYPE* /*buffer*/)
100 //input_bufs_omx_mutex.lock();
101 omx_egl_filled = true;
102 //output_bufs_omx_full.push_back(buffer);
103 //input_bufs_omx_mutex.unlock();
104 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
111 int ImageOMX::play() {
114 lastAType=MPTYPE_MPEG_Image;
115 Log::getInstance()->log("Image", Log::DEBUG, "enter play");
117 ((VideoOMX*)Video::getInstance())->interlaceSwitch4Demux(); // switch resolution if necessary
119 if (!AllocateCodecsOMX()) {
129 int ImageOMX::AllocateCodecsOMX(unsigned char * buffer, unsigned int length)
132 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
134 //Log::getInstance()->log("Image", Log::NOTICE, "Allocate Codecs OMX");
135 //Clock, move later to Image
136 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
138 OMX_PORT_PARAM_TYPE p_param;
139 memset(&p_param,0,sizeof(p_param));
140 p_param.nSize=sizeof(p_param);
141 p_param.nVersion.nVersion=OMX_VERSION;
147 error = OMX_GetHandle(&omx_imag_decode, L_VPE_OMX_IMAGE_DECODER, NULL, &callbacks);
148 if (error != OMX_ErrorNone) {
149 Log::getInstance()->log("Image", Log::DEBUG,
150 "Init OMX Image decoder failed %x", error);
151 video->UnlockClock();
157 error = OMX_GetParameter(omx_imag_decode, OMX_IndexParamImageInit, &p_param);
158 if (error != OMX_ErrorNone) {
159 Log::getInstance()->log("Image", Log::DEBUG,
160 "Init OMX Image rend OMX_GetParameter failed %x", error);
161 video->UnlockClock();
164 omx_image_input_port = p_param.nStartPortNumber;
165 omx_image_output_port = p_param.nStartPortNumber+1;
170 OMX_IMAGE_PARAM_PORTFORMATTYPE ft_type;
171 memset(&ft_type,0,sizeof(ft_type));
172 ft_type.nSize=sizeof(ft_type);
173 ft_type.nVersion.nVersion=OMX_VERSION;
175 ft_type.nPortIndex=omx_image_input_port;
179 case Jpeg: ft_type.eCompressionFormat=OMX_IMAGE_CodingJPEG;
181 case PNG: ft_type.eCompressionFormat=OMX_IMAGE_CodingPNG;
189 error=OMX_SetParameter(omx_imag_decode,OMX_IndexParamImagePortFormat,&ft_type);
190 if (error!=OMX_ErrorNone){
191 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX_IndexParamVImagePortFormat failed %x", error);
192 video->UnlockClock();
196 if (!video->DisablePort(omx_imag_decode,omx_image_input_port) || !video->DisablePort(omx_imag_decode,omx_image_output_port)) {
197 Log::getInstance()->log("Image", Log::DEBUG, "Disable Ports OMX Image decoder failed");
198 video->UnlockClock();
203 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
204 Log::getInstance()->log("Image", Log::DEBUG, "image decode idle ChangeComponentState");
205 video->UnlockClock();
211 if (!PrepareInputBufsOMX(true, buffer, length)) {
212 video->UnlockClock();
213 Log::getInstance()->log("Image", Log::DEBUG, "prepare input bufs failed");
223 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateExecuting)) {
224 Log::getInstance()->log("Image", Log::DEBUG, "omx_image_decode ChangeComponentState Execute");
225 video->UnlockClock();
232 if (!video->EnablePort(omx_imag_decode,omx_image_input_port,false)
234 Log::getInstance()->log("Image", Log::DEBUG, "Enable Ports OMXdecoder inputfailed");
235 video->UnlockClock();
242 video->UnlockClock();
247 //Log::getInstance()->log("Image", Log::NOTICE, "Allocate Codecs OMX finished");
257 unsigned char* ImageOMX::decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem)
259 if (pictInfValid) return buffer; // does support only one image at a Time;
260 // Log::getInstance()->log("Image", Log::DEBUG,
261 // "decodePicture 1");
262 EGLPictureCreator * pictcreat =dynamic_cast<EGLPictureCreator*>(Osd::getInstance());
263 curformat=Unsupported;
264 if (buffer[0]== 0xff && buffer[1] ==0xd8) curformat=Jpeg;
265 if (buffer[0]== 0x89 && buffer[1] ==0x50 && buffer[2] ==0x4e) curformat=PNG;
267 if (curformat == Unsupported) return buffer; // Jpeg magic numbers
268 // Log::getInstance()->log("Image", Log::DEBUG,
269 // "decodePicture 2");
270 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
273 if (!pictcreat) return NULL;
276 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
277 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
279 if (!AllocateCodecsOMX(buffer,length)) {
280 DeAllocateCodecsOMX();
281 pthread_setcancelstate(oldcancelstate, NULL);
282 pthread_setcanceltype(oldcanceltype, NULL);
285 bool ret=intDecodePicture(index, buffer, length, pictcreat, video);
286 DeAllocateCodecsOMX();
287 pthread_setcancelstate(oldcancelstate, NULL);
288 pthread_setcanceltype(oldcanceltype, NULL);
289 if (ret && freemem) free(buffer);
291 if (ret) return NULL;
296 bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char* /* buffer */, unsigned int length, EGLPictureCreator* pictcreat, VideoOMX *video)
298 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
301 OMX_BUFFERHEADERTYPE * bufhead;
303 input_bufs_omx_mutex.lock();
305 while (input_bufs_omx_free.size()==0) {
306 input_bufs_omx_mutex.unlock();
307 //Log::getInstance()->log("Image", Log::DEBUG, "DMP mark 6");
308 //Log::getInstance()->log("Image", Log::DEBUG, "Deliver MediaPacket no free sample");
309 //return 0; // we do not have a free media sample
312 if (count>100) return false;
315 input_bufs_omx_mutex.lock();
318 bufhead=input_bufs_omx_free.front();
319 bufhead->nFilledLen=length;
320 //bufhead->nAllocLen= length;
322 bufhead->nTimeStamp=VideoOMX::intToOMXTicks(0);
323 //bufhead->pBuffer=buffer;
324 bufhead->pAppPrivate=this;
325 input_bufs_omx_free.pop_front();
326 input_bufs_omx_mutex.unlock();
329 bufhead->nFilledLen=length;//bufhead->nAllocLen;
330 bufhead->nFlags=OMX_BUFFERFLAG_EOS;
331 video->ProtOMXEmptyThisBuffer(omx_imag_decode, bufhead);
336 // Log::getInstance()->log("Image", Log::DEBUG,
337 // "decodePicture 3");
339 video->WaitForEvent(omx_imag_decode,OMX_EventPortSettingsChanged);
343 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
344 memset(&port_def_type,0,sizeof(port_def_type));
345 port_def_type.nSize=sizeof(port_def_type);
346 port_def_type.nVersion.nVersion=OMX_VERSION;
347 port_def_type.nPortIndex=omx_image_output_port;
348 // Log::getInstance()->log("Image", Log::DEBUG,
349 // "decodePicture 3a");
351 error=OMX_GetParameter(omx_imag_decode,OMX_IndexParamPortDefinition, &port_def_type);
352 if (error != OMX_ErrorNone) {
353 Log::getInstance()->log("Image", Log::DEBUG,
354 "OMX_IndexParamPortDefinition fix failed %x", error);
355 video->UnlockClock();
358 // Log::getInstance()->log("Image", Log::DEBUG,
359 // "decodePicture 4");
369 video->DisablePort(omx_imag_decode,omx_image_output_port,false);
370 Log::getInstance()->log("Image", Log::DEBUG,
373 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortDisable,omx_image_output_port)) {
374 video->UnlockClock();
375 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end iop");
382 port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
383 port_def_type.format.image.nSliceHeight = 16;
384 port_def_type.format.image.nStride = 0;
387 //port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
388 //port_def_type.format.image.nSliceHeight = 32;
389 //port_def_type.format.image.nStride = 0;
390 port_def_type.format.image.nFrameHeight+=-(port_def_type.format.image.nFrameHeight%32); // The OpenMax png part is broken for the last slice
391 // so we cut the broken part, not nice but works
402 error = OMX_SetParameter(omx_imag_decode, OMX_IndexParamPortDefinition,
404 if (error != OMX_ErrorNone) {
405 Log::getInstance()->log("Image", Log::DEBUG,
406 "Set OMX_IndexParamPortDefinition1 failed %x", error);
407 video->UnlockClock();
412 // Log::getInstance()->log("Image", Log::DEBUG,
413 // "decodePicture 5 6");
414 error=OMX_GetHandle(&omx_egl_render,L_VPE_OMX_EGL_REND,NULL,&callbacks);
416 if (error!=OMX_ErrorNone){
417 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX EGL renderer failed %x", error);
418 video->UnlockClock();
422 OMX_PORT_PARAM_TYPE p_param;
423 memset(&p_param,0,sizeof(p_param));
424 p_param.nSize=sizeof(p_param);
425 p_param.nVersion.nVersion=OMX_VERSION;
427 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamVideoInit,&p_param);
428 if (error!=OMX_ErrorNone){
429 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX EGL renderer OMX_GetParameter failed %x", error);
430 video->UnlockClock();
433 omx_egl_input_port=p_param.nStartPortNumber;
434 omx_egl_output_port=p_param.nStartPortNumber+1;
439 if (!video->DisablePort(omx_egl_render,omx_egl_input_port) || !video->DisablePort(omx_egl_render,omx_egl_output_port)) {
440 Log::getInstance()->log("Image", Log::DEBUG, "Disable Ports OMX Image decoder failed");
441 video->UnlockClock();
446 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
447 Log::getInstance()->log("Image", Log::DEBUG, "egl render idle ChangeComponentState");
448 video->UnlockClock();
456 /* if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortDisable,omx_egl_input_port)) {
457 video->UnlockClock();
458 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
465 /* port_def_type.nPortIndex=omx_egl_input_port;
466 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
468 if (error != OMX_ErrorNone) {
469 Log::getInstance()->log("Image", Log::DEBUG,
470 "Set OMX_IndexParamPortDefinition3 failed %x", error);
471 video->UnlockClock();
472 pthread_setcancelstate(oldcancelstate, NULL);
473 pthread_setcanceltype(oldcanceltype, NULL);
477 pictInf.width = port_def_type.format.image.nFrameWidth;
478 pictInf.height = port_def_type.format.image.nFrameHeight;
479 pictInf.decoder = this;
480 pictInf.type = OsdVector::PictureInfo::RGBAMemBlock;
481 pictInf.lindex = index;
484 port_def_type.nPortIndex=omx_egl_output_port;
486 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamPortDefinition, &port_def_type);
487 if (error != OMX_ErrorNone) {
488 Log::getInstance()->log("Image", Log::DEBUG,
489 "OMX_IndexParamPortDefinition fix failed %x", error);
490 video->UnlockClock();
496 port_def_type.nBufferCountActual = 1;
497 EGLDisplay egl_display;
498 if (!pictcreat->getEGLPicture(pictInf, &egl_display)) {
499 Log::getInstance()->log("Image", Log::DEBUG,
500 "getEGLPict failed");
501 video->UnlockClock();
504 Log::getInstance()->log("Image", Log::DEBUG,
505 "getEGLPict %x",pictInf.reference);
507 port_def_type.format.video.pNativeWindow = egl_display;
508 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
510 if (error != OMX_ErrorNone) {
511 Log::getInstance()->log("Image", Log::DEBUG,
512 "Set OMX_IndexParamPortDefinition3 failed %x", error);
513 video->UnlockClock();
526 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,omx_egl_render,omx_egl_input_port);
527 if (error!=OMX_ErrorNone){
528 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel decode to egl rend failed %x ");
529 video->UnlockClock();
533 if (!video->EnablePort(omx_imag_decode,omx_image_output_port,false) || !video->EnablePort(omx_egl_render,omx_egl_input_port,false)
535 Log::getInstance()->log("Image", Log::DEBUG, "Enable Ports OMXdecoder rend failed");
536 video->UnlockClock();
540 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortEnable,omx_image_output_port)) {
541 video->UnlockClock();
542 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end iop");
546 if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortEnable,omx_egl_input_port)) {
547 video->UnlockClock();
548 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
552 // Log::getInstance()->log("Image", Log::DEBUG,
553 // "decodePicture 7");
554 video->WaitForEvent(omx_egl_render,OMX_EventPortSettingsChanged);
556 Log::getInstance()->log("Image", Log::DEBUG,
565 error=OMX_SendCommand(omx_egl_render/*dec*/,OMX_CommandPortEnable,omx_egl_output_port/*codec*/,0);
566 if (error!=OMX_ErrorNone){
567 Log::getInstance()->log("Image", Log::DEBUG, "Prepare omx_egl_output_port Send Command to enable port %x", error);
572 error=OMX_UseEGLImage(omx_egl_render/*dec*/,&buf_head_egl,omx_egl_output_port/*codec*/, this, pictInf.reference);
573 if (error!=OMX_ErrorNone){
574 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_UseEGLImage failed %x", error);
575 video->UnlockClock();
578 buf_head_egl->pAppPrivate=this;
580 // Log::getInstance()->log("Image", Log::DEBUG,
581 // "decodePicture 8 a");
583 video->EnablePort(omx_imag_decode,omx_image_output_port,false);
585 if (!video->CommandFinished(omx_egl_render/*dec*/,OMX_CommandPortEnable, omx_egl_output_port /*codec*/)) {
586 video->UnlockClock();
593 Log::getInstance()->log("Image", Log::DEBUG,
594 "decodePicture 8 end");
596 if (!video->ChangeComponentState(omx_egl_render,OMX_StateExecuting)) {
597 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_rendd ChangeComponentState Execute");
598 video->UnlockClock();
603 // Log::getInstance()->log("Image", Log::DEBUG,
604 // "decodePicture 9");
605 //video->EnablePort(omx_egl_render,omx_egl_output_port,false);
607 // Log::getInstance()->log("Image", Log::DEBUG,
608 // "decodePicture 10");
610 omx_egl_filled = false;
611 error = OMX_FillThisBuffer(omx_egl_render, buf_head_egl);
613 if (error!=OMX_ErrorNone){
614 Log::getInstance()->log("Image", Log::DEBUG, "OMX_FillThisBuffer failed %x", error);
615 video->UnlockClock();
619 video->UnlockClock();
620 while (!omx_egl_filled) {
624 Log::getInstance()->log("Image", Log::DEBUG, "No one filled my buffer");
631 omx_egl_filled = false;
633 // Log::getInstance()->log("Image", Log::DEBUG,
634 // "decodePicture left");
643 bool ImageOMX::getDecodedPicture(struct OsdVector::PictureInfo& pict_inf)
645 if (!pictInfValid) return false;
647 pictInfValid = false;
651 void ImageOMX::freeReference(void* /* ref */)
655 int ImageOMX::PrepareInputBufsOMX(bool setportdef, unsigned char * buffer, unsigned int length) //needs to be called with locvke omx clock mutex
657 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
659 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
660 memset(&port_def_type,0,sizeof(port_def_type));
661 port_def_type.nSize=sizeof(port_def_type);
662 port_def_type.nVersion.nVersion=OMX_VERSION;
663 port_def_type.nPortIndex=omx_image_input_port;//omx_codec_input_port;
665 error=OMX_GetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
667 if (error!=OMX_ErrorNone){
668 Log::getInstance()->log("Image", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
673 port_def_type.nBufferCountActual=port_def_type.nBufferCountMin;
674 port_def_type.nBufferSize=max(port_def_type.nBufferSize,length); // for transcoder important
676 error=OMX_SetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
678 if (error!=OMX_ErrorNone){
679 Log::getInstance()->log("Image", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
684 error=OMX_SendCommand(omx_imag_decode/*dec*/,OMX_CommandPortEnable,omx_image_input_port/*codec*/,0);
685 if (error!=OMX_ErrorNone){
686 Log::getInstance()->log("Image", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
690 input_bufs_omx_mutex.lock();
691 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
692 OMX_BUFFERHEADERTYPE *buf_head=NULL;
693 error=OMX_UseBuffer(omx_imag_decode/*dec*/,&buf_head,omx_image_input_port/*codec*/,this,port_def_type.nBufferSize, buffer);
694 if (error!=OMX_ErrorNone){
695 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_UseBuffer failed %x", error);
696 input_bufs_omx_mutex.unlock();
699 input_bufs_omx_all.push_back(buf_head);
700 input_bufs_omx_free.push_back(buf_head);
702 omx_first_frame=true;
705 input_bufs_omx_mutex.unlock();
707 if (!video->CommandFinished(omx_imag_decode/*dec*/,OMX_CommandPortEnable, omx_image_input_port /*codec*/)) {
714 int ImageOMX::DestroyInputBufsOMX() //call with clock mutex locked
718 input_bufs_omx_mutex.lock();
719 for (UINT i=0; i< input_bufs_omx_all.size();i++) {
720 Log::getInstance()->log("Image", Log::DEBUG, "OMX_FreeBuffer mark");
721 //if (input_bufs_omx_all[i]->pBuffer) free(input_bufs_omx_all[i]->pBuffer);
722 input_bufs_omx_all[i]->pBuffer=NULL;
723 error=OMX_FreeBuffer(omx_imag_decode/*dec*/,omx_image_input_port/*codec*/,input_bufs_omx_all[i]);
724 if (error!=OMX_ErrorNone){
725 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
726 input_bufs_omx_mutex.unlock();
731 input_bufs_omx_all.clear();
732 input_bufs_omx_free.clear();
733 input_bufs_omx_mutex.unlock();
738 int ImageOMX::DestroyInputBufsOMXwhilePlaying() //call with clock mutex locked
740 //OMX_ERRORTYPE error;
742 input_bufs_omx_mutex.lock();
743 while (input_bufs_omx_all.size()>0) {
744 if (input_bufs_omx_free.size()>0) {
745 // Destroy one buffer
746 std::vector<OMX_BUFFERHEADERTYPE*>::iterator itty=input_bufs_omx_all.begin();
747 OMX_BUFFERHEADERTYPE* cur_buf=input_bufs_omx_free.front();
748 for (; itty!= input_bufs_omx_all.end();itty++) {
749 if ((*itty)==cur_buf) {
750 input_bufs_omx_all.erase(itty);
751 input_bufs_omx_free.pop_front();
756 input_bufs_omx_mutex.unlock();
758 input_bufs_omx_mutex.lock();
762 Log::getInstance()->log("Image", Log::DEBUG, "DestroyInputBufsOMXwhilePlaying %d %d", input_bufs_omx_all.size(),input_bufs_omx_free.size());
763 input_bufs_omx_mutex.unlock();
768 int ImageOMX::DeAllocateCodecsOMX()
772 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
773 // Log::getInstance()->log("Image", Log::DEBUG, "enter deallocatecodecsomx");
777 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 1");
779 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 2");
782 if (omx_imag_decode/*dec*/) {
785 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
786 Log::getInstance()->log("Image", Log::DEBUG, "omx_imag_decode ChangeComponentState");
789 if (omx_egl_render) {
791 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
792 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_render ChangeComponentState");
794 /*if (!video->ChangeComponentState(omx_egl_render,OMX_StateLoaded,false)) {
795 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_render ChangeComponentState");
799 /* if (!video->ChangeComponentState(omx_imag_decode,OMX_StateLoaded,false)) {
800 Log::getInstance()->log("Image", Log::DEBUG, "omx_imag_decode ChangeComponentState");
805 // TODO proper deinit sequence
806 // first flush all buffers
810 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 3");
812 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_output_port, NULL);
813 if (error!=OMX_ErrorNone) {
814 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
818 if (omx_egl_render) {
820 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
821 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_render ChangeComponentState");
824 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 4");
826 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_input_port, NULL);
827 if (error!=OMX_ErrorNone) {
828 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
832 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 5");
834 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_output_port, NULL);
835 if (error!=OMX_ErrorNone) {
836 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
840 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6");
842 if (!video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_input_port) ||
843 !video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_output_port)) {
844 Log::getInstance()->log("Image", Log::DEBUG, "flush cmd clock shed failed");
846 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 a");
848 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_input_port, NULL);
849 if (error!=OMX_ErrorNone) {
850 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
855 error=OMX_FreeBuffer(omx_egl_render/*dec*/, omx_egl_output_port/*codec*/,buf_head_egl);
856 if (error!=OMX_ErrorNone){
857 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_FreeBuffer 2 failed %x", error);
864 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 b");
866 if (!video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_input_port) ||
867 !video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_output_port) ) {
868 Log::getInstance()->log("Image", Log::DEBUG, "flush cmd clock shed failed");
871 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 c");
874 DestroyInputBufsOMX(); //We have to make sure that no buffers are in use
876 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 7");
879 if (!video->DisablePort(omx_imag_decode,omx_image_output_port,true)) {
880 Log::getInstance()->log("Image", Log::DEBUG, "Disable Tunnel Port failed 1");
883 if (omx_egl_render) {
885 if (!video->DisablePort(omx_egl_render,omx_egl_input_port,true)) {
886 Log::getInstance()->log("Image", Log::DEBUG, "Disable Tunnel Port failed 4");
890 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,NULL,0);
891 if (error!=OMX_ErrorNone) {
892 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
896 error=OMX_SetupTunnel(omx_egl_render,omx_egl_input_port,NULL,0);
897 if (error!=OMX_ErrorNone) {
898 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
904 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 8");
907 //error=OMX_FreeHandle(omx_aud_dec);
908 error=OMX_FreeHandle(omx_imag_decode);
909 if (error!=OMX_ErrorNone) {
910 Log::getInstance()->log("Image", Log::DEBUG, "FreeHandle failed %d", error);
912 if (omx_egl_render) {
913 error=OMX_FreeHandle(omx_egl_render);
914 if (error!=OMX_ErrorNone) {
915 Log::getInstance()->log("Image", Log::DEBUG, "FreeHandle failed %d", error);
918 video->UnlockClock();
920 video->clearEventsForComponent(omx_imag_decode);
921 video->clearEventsForComponent(omx_egl_render); // removes spurious error messages
922 omx_imag_decode/*dec*/=NULL;
923 omx_egl_render/*dec*/=NULL;
927 video->UnlockClock();
929 // Log::getInstance()->log("Image", Log::DEBUG, "leave deallocate codecs OMX");