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, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "woptionpane.h"
27 #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;
50 // AllocateCodecsOMX();
53 void ImageOMX::shutdown()
55 Log::getInstance()->log("ImageOMX", Log::DEBUG, "shutdown");
56 //DeAllocateCodecsOMX();
63 OMX_ERRORTYPE ImageOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
65 //Log::getInstance()->log("Image", Log::NOTICE, "EmptyBufferDone");
66 ImageOMX *image=(ImageOMX *)buffer->pAppPrivate;
67 image->ReturnEmptyOMXBuffer(buffer);
72 void ImageOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
73 input_bufs_omx_mutex.Lock();
74 /*if (buffer->pBuffer) {
75 free(buffer->pBuffer);
76 buffer->pBuffer = NULL;
79 //Log::getInstance()->log("Image", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
80 input_bufs_omx_free.push_back(buffer);
81 //Log::getInstance()->log("Image", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
82 input_bufs_omx_mutex.Unlock();
83 VideoOMX *video=(VideoOMX*)Video::getInstance();
87 OMX_ERRORTYPE ImageOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
88 Log::getInstance()->log("ImageOmx", Log::NOTICE, "FillBufferDone");
89 ImageOMX *image=(ImageOMX *)buffer->pAppPrivate;
90 image->ReturnFillOMXBuffer(buffer);
94 void ImageOMX::ReturnFillOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
95 //input_bufs_omx_mutex.Lock();
96 omx_egl_filled = true;
97 //output_bufs_omx_full.push_back(buffer);
98 //input_bufs_omx_mutex.Unlock();
99 VideoOMX *video=(VideoOMX*)Video::getInstance();
106 int ImageOMX::play() {
109 lastAType=MPTYPE_MPEG_Image;
110 Log::getInstance()->log("Image", Log::DEBUG, "enter play");
112 ((VideoOMX*)Video::getInstance())->interlaceSwitch4Demux(); // switch resolution if necessary
114 if (!AllocateCodecsOMX()) {
124 int ImageOMX::AllocateCodecsOMX(unsigned char * buffer, unsigned int length)
127 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
129 //Log::getInstance()->log("Image", Log::NOTICE, "Allocate Codecs OMX");
130 //Clock, move later to Image
131 VideoOMX *video=(VideoOMX*)Video::getInstance();
133 OMX_PORT_PARAM_TYPE p_param;
134 memset(&p_param,0,sizeof(p_param));
135 p_param.nSize=sizeof(p_param);
136 p_param.nVersion.nVersion=OMX_VERSION;
142 error = OMX_GetHandle(&omx_imag_decode, VPE_OMX_IMAGE_DECODER, NULL, &callbacks);
143 if (error != OMX_ErrorNone) {
144 Log::getInstance()->log("Image", Log::DEBUG,
145 "Init OMX Image decoder failed %x", error);
146 video->UnlockClock();
152 error = OMX_GetParameter(omx_imag_decode, OMX_IndexParamImageInit, &p_param);
153 if (error != OMX_ErrorNone) {
154 Log::getInstance()->log("Image", Log::DEBUG,
155 "Init OMX Image rend OMX_GetParameter failed %x", error);
156 video->UnlockClock();
159 omx_image_input_port = p_param.nStartPortNumber;
160 omx_image_output_port = p_param.nStartPortNumber+1;
165 OMX_IMAGE_PARAM_PORTFORMATTYPE ft_type;
166 memset(&ft_type,0,sizeof(ft_type));
167 ft_type.nSize=sizeof(ft_type);
168 ft_type.nVersion.nVersion=OMX_VERSION;
170 ft_type.nPortIndex=omx_image_input_port;
174 case Jpeg: ft_type.eCompressionFormat=OMX_IMAGE_CodingJPEG;
176 case PNG: ft_type.eCompressionFormat=OMX_IMAGE_CodingPNG;
181 error=OMX_SetParameter(omx_imag_decode,OMX_IndexParamImagePortFormat,&ft_type);
182 if (error!=OMX_ErrorNone){
183 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX_IndexParamVImagePortFormat failed %x", error);
184 video->UnlockClock();
188 if (!video->DisablePort(omx_imag_decode,omx_image_input_port) || !video->DisablePort(omx_imag_decode,omx_image_output_port)) {
189 Log::getInstance()->log("Image", Log::DEBUG, "Disable Ports OMX Image decoder failed");
190 video->UnlockClock();
195 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
196 Log::getInstance()->log("Image", Log::DEBUG, "image decode idle ChangeComponentState");
197 video->UnlockClock();
203 if (!PrepareInputBufsOMX(true, buffer, length)) {
204 video->UnlockClock();
205 Log::getInstance()->log("Image", Log::DEBUG, "prepare input bufs failed");
215 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateExecuting)) {
216 Log::getInstance()->log("Image", Log::DEBUG, "omx_image_decode ChangeComponentState Execute");
217 video->UnlockClock();
224 if (!video->EnablePort(omx_imag_decode,omx_image_input_port,false)
226 Log::getInstance()->log("Image", Log::DEBUG, "Enable Ports OMXdecoder inputfailed");
227 video->UnlockClock();
234 video->UnlockClock();
239 //Log::getInstance()->log("Image", Log::NOTICE, "Allocate Codecs OMX finished");
249 unsigned char* ImageOMX::decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem)
251 if (pictInfValid) return buffer; // does support only one image at a Time;
252 // Log::getInstance()->log("Image", Log::DEBUG,
253 // "decodePicture 1");
254 EGLPictureCreator * pictcreat =dynamic_cast<EGLPictureCreator*>(Osd::getInstance());
255 curformat=Unsupported;
256 if (buffer[0]== 0xff && buffer[1] ==0xd8) curformat=Jpeg;
257 if (buffer[0]== 0x89 && buffer[1] ==0x50 && buffer[2] ==0x4e) curformat=PNG;
259 if (curformat == Unsupported) return buffer; // Jpeg magic numbers
260 // Log::getInstance()->log("Image", Log::DEBUG,
261 // "decodePicture 2");
262 VideoOMX *video=(VideoOMX*)Video::getInstance();
265 if (!pictcreat) return false;
268 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
269 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
271 if (!AllocateCodecsOMX(buffer,length)) {
272 DeAllocateCodecsOMX();
273 pthread_setcancelstate(oldcancelstate, NULL);
274 pthread_setcanceltype(oldcanceltype, NULL);
277 bool ret=intDecodePicture(index, buffer, length, pictcreat, video);
278 DeAllocateCodecsOMX();
279 pthread_setcancelstate(oldcancelstate, NULL);
280 pthread_setcanceltype(oldcanceltype, NULL);
281 if (ret && freemem) free(buffer);
283 if (ret) return NULL;
288 bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, EGLPictureCreator* pictcreat, VideoOMX *video)
290 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
293 OMX_BUFFERHEADERTYPE * bufhead;
295 input_bufs_omx_mutex.Lock();
297 while (input_bufs_omx_free.size()==0) {
298 input_bufs_omx_mutex.Unlock();
299 //Log::getInstance()->log("Image", Log::DEBUG, "DMP mark 6");
300 //Log::getInstance()->log("Image", Log::DEBUG, "Deliver MediaPacket no free sample");
301 //return 0; // we do not have a free media sample
304 if (count>100) return false;
307 input_bufs_omx_mutex.Lock();
310 bufhead=input_bufs_omx_free.front();
311 bufhead->nFilledLen=length;
312 //bufhead->nAllocLen= length;
314 bufhead->nTimeStamp=VideoOMX::intToOMXTicks(0);
315 //bufhead->pBuffer=buffer;
316 bufhead->pAppPrivate=this;
317 input_bufs_omx_free.pop_front();
318 input_bufs_omx_mutex.Unlock();
321 bufhead->nFilledLen=length;//bufhead->nAllocLen;
322 bufhead->nFlags=OMX_BUFFERFLAG_EOS;
323 video->ProtOMXEmptyThisBuffer(omx_imag_decode, bufhead);
328 // Log::getInstance()->log("Image", Log::DEBUG,
329 // "decodePicture 3");
331 video->WaitForEvent(omx_imag_decode,OMX_EventPortSettingsChanged);
335 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
336 memset(&port_def_type,0,sizeof(port_def_type));
337 port_def_type.nSize=sizeof(port_def_type);
338 port_def_type.nVersion.nVersion=OMX_VERSION;
339 port_def_type.nPortIndex=omx_image_output_port;
340 // Log::getInstance()->log("Image", Log::DEBUG,
341 // "decodePicture 3a");
343 error=OMX_GetParameter(omx_imag_decode,OMX_IndexParamPortDefinition, &port_def_type);
344 if (error != OMX_ErrorNone) {
345 Log::getInstance()->log("Image", Log::DEBUG,
346 "OMX_IndexParamPortDefinition fix failed %x", error);
347 video->UnlockClock();
350 // Log::getInstance()->log("Image", Log::DEBUG,
351 // "decodePicture 4");
361 video->DisablePort(omx_imag_decode,omx_image_output_port,false);
362 Log::getInstance()->log("Image", Log::DEBUG,
365 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortDisable,omx_image_output_port)) {
366 video->UnlockClock();
367 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end iop");
374 port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
375 port_def_type.format.image.nSliceHeight = 16;
376 port_def_type.format.image.nStride = 0;
379 //port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
380 //port_def_type.format.image.nSliceHeight = 32;
381 //port_def_type.format.image.nStride = 0;
382 port_def_type.format.image.nFrameHeight+=-(port_def_type.format.image.nFrameHeight%32); // The OpenMax png part is broken for the last slice
383 // so we cut the broken part, not nice but works
391 error = OMX_SetParameter(omx_imag_decode, OMX_IndexParamPortDefinition,
393 if (error != OMX_ErrorNone) {
394 Log::getInstance()->log("Image", Log::DEBUG,
395 "Set OMX_IndexParamPortDefinition1 failed %x", error);
396 video->UnlockClock();
401 // Log::getInstance()->log("Image", Log::DEBUG,
402 // "decodePicture 5 6");
403 error=OMX_GetHandle(&omx_egl_render,VPE_OMX_EGL_REND,NULL,&callbacks);
405 if (error!=OMX_ErrorNone){
406 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX EGL renderer failed %x", error);
407 video->UnlockClock();
411 OMX_PORT_PARAM_TYPE p_param;
412 memset(&p_param,0,sizeof(p_param));
413 p_param.nSize=sizeof(p_param);
414 p_param.nVersion.nVersion=OMX_VERSION;
416 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamVideoInit,&p_param);
417 if (error!=OMX_ErrorNone){
418 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX EGL renderer OMX_GetParameter failed %x", error);
419 video->UnlockClock();
422 omx_egl_input_port=p_param.nStartPortNumber;
423 omx_egl_output_port=p_param.nStartPortNumber+1;
428 if (!video->DisablePort(omx_egl_render,omx_egl_input_port) || !video->DisablePort(omx_egl_render,omx_egl_output_port)) {
429 Log::getInstance()->log("Image", Log::DEBUG, "Disable Ports OMX Image decoder failed");
430 video->UnlockClock();
435 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
436 Log::getInstance()->log("Image", Log::DEBUG, "egl render idle ChangeComponentState");
437 video->UnlockClock();
445 /* if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortDisable,omx_egl_input_port)) {
446 video->UnlockClock();
447 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
454 /* port_def_type.nPortIndex=omx_egl_input_port;
455 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
457 if (error != OMX_ErrorNone) {
458 Log::getInstance()->log("Image", Log::DEBUG,
459 "Set OMX_IndexParamPortDefinition3 failed %x", error);
460 video->UnlockClock();
461 pthread_setcancelstate(oldcancelstate, NULL);
462 pthread_setcanceltype(oldcanceltype, NULL);
466 pictInf.width = port_def_type.format.image.nFrameWidth;
467 pictInf.height = port_def_type.format.image.nFrameHeight;
468 pictInf.decoder = this;
469 pictInf.type = OsdVector::PictureInfo::RGBAMemBlock;
470 pictInf.lindex = index;
473 port_def_type.nPortIndex=omx_egl_output_port;
475 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamPortDefinition, &port_def_type);
476 if (error != OMX_ErrorNone) {
477 Log::getInstance()->log("Image", Log::DEBUG,
478 "OMX_IndexParamPortDefinition fix failed %x", error);
479 video->UnlockClock();
485 port_def_type.nBufferCountActual = 1;
486 EGLDisplay egl_display;
487 if (!pictcreat->getEGLPicture(pictInf, &egl_display)) {
488 Log::getInstance()->log("Image", Log::DEBUG,
489 "getEGLPict failed");
490 video->UnlockClock();
493 Log::getInstance()->log("Image", Log::DEBUG,
494 "getEGLPict %x",pictInf.reference);
496 port_def_type.format.video.pNativeWindow = egl_display;
497 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
499 if (error != OMX_ErrorNone) {
500 Log::getInstance()->log("Image", Log::DEBUG,
501 "Set OMX_IndexParamPortDefinition3 failed %x", error);
502 video->UnlockClock();
515 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,omx_egl_render,omx_egl_input_port);
516 if (error!=OMX_ErrorNone){
517 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel decode to egl rend failed %x ");
518 video->UnlockClock();
522 if (!video->EnablePort(omx_imag_decode,omx_image_output_port,false) || !video->EnablePort(omx_egl_render,omx_egl_input_port,false)
524 Log::getInstance()->log("Image", Log::DEBUG, "Enable Ports OMXdecoder rend failed");
525 video->UnlockClock();
529 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortEnable,omx_image_output_port)) {
530 video->UnlockClock();
531 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end iop");
535 if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortEnable,omx_egl_input_port)) {
536 video->UnlockClock();
537 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
541 // Log::getInstance()->log("Image", Log::DEBUG,
542 // "decodePicture 7");
543 video->WaitForEvent(omx_egl_render,OMX_EventPortSettingsChanged);
545 Log::getInstance()->log("Image", Log::DEBUG,
554 error=OMX_SendCommand(omx_egl_render/*dec*/,OMX_CommandPortEnable,omx_egl_output_port/*codec*/,0);
555 if (error!=OMX_ErrorNone){
556 Log::getInstance()->log("Image", Log::DEBUG, "Prepare omx_egl_output_port Send Command to enable port %x", error);
561 error=OMX_UseEGLImage(omx_egl_render/*dec*/,&buf_head_egl,omx_egl_output_port/*codec*/, this, pictInf.reference);
562 if (error!=OMX_ErrorNone){
563 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_UseEGLImage failed %x", error);
564 video->UnlockClock();
567 buf_head_egl->pAppPrivate=this;
569 // Log::getInstance()->log("Image", Log::DEBUG,
570 // "decodePicture 8 a");
572 video->EnablePort(omx_imag_decode,omx_image_output_port,false);
574 if (!video->CommandFinished(omx_egl_render/*dec*/,OMX_CommandPortEnable, omx_egl_output_port /*codec*/)) {
575 video->UnlockClock();
582 Log::getInstance()->log("Image", Log::DEBUG,
583 "decodePicture 8 end");
585 if (!video->ChangeComponentState(omx_egl_render,OMX_StateExecuting)) {
586 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_rendd ChangeComponentState Execute");
587 video->UnlockClock();
592 // Log::getInstance()->log("Image", Log::DEBUG,
593 // "decodePicture 9");
594 //video->EnablePort(omx_egl_render,omx_egl_output_port,false);
596 // Log::getInstance()->log("Image", Log::DEBUG,
597 // "decodePicture 10");
599 omx_egl_filled = false;
600 error = OMX_FillThisBuffer(omx_egl_render, buf_head_egl);
602 if (error!=OMX_ErrorNone){
603 Log::getInstance()->log("Image", Log::DEBUG, "OMX_FillThisBuffer failed %x", error);
604 video->UnlockClock();
608 video->UnlockClock();
609 while (!omx_egl_filled) {
613 Log::getInstance()->log("Image", Log::DEBUG, "No one filled my buffer");
620 omx_egl_filled = false;
622 // Log::getInstance()->log("Image", Log::DEBUG,
623 // "decodePicture left");
632 bool ImageOMX::getDecodedPicture(struct OsdVector::PictureInfo& pict_inf)
634 if (!pictInfValid) return false;
636 pictInfValid = false;
640 void ImageOMX::freeReference(void * ref)
646 int ImageOMX::PrepareInputBufsOMX(bool setportdef, unsigned char * buffer, unsigned int length) //needs to be called with locvke omx clock mutex
648 VideoOMX *video=(VideoOMX*)Video::getInstance();
650 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
651 memset(&port_def_type,0,sizeof(port_def_type));
652 port_def_type.nSize=sizeof(port_def_type);
653 port_def_type.nVersion.nVersion=OMX_VERSION;
654 port_def_type.nPortIndex=omx_image_input_port;//omx_codec_input_port;
656 error=OMX_GetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
658 if (error!=OMX_ErrorNone){
659 Log::getInstance()->log("Image", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
664 port_def_type.nBufferCountActual=port_def_type.nBufferCountMin;
665 port_def_type.nBufferSize=max(port_def_type.nBufferSize,length); // for transcoder important
667 error=OMX_SetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
669 if (error!=OMX_ErrorNone){
670 Log::getInstance()->log("Image", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
675 error=OMX_SendCommand(omx_imag_decode/*dec*/,OMX_CommandPortEnable,omx_image_input_port/*codec*/,0);
676 if (error!=OMX_ErrorNone){
677 Log::getInstance()->log("Image", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
681 input_bufs_omx_mutex.Lock();
682 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
683 OMX_BUFFERHEADERTYPE *buf_head=NULL;
684 error=OMX_UseBuffer(omx_imag_decode/*dec*/,&buf_head,omx_image_input_port/*codec*/,this,port_def_type.nBufferSize, buffer);
685 if (error!=OMX_ErrorNone){
686 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_UseBuffer failed %x", error);
687 input_bufs_omx_mutex.Unlock();
690 input_bufs_omx_all.push_back(buf_head);
691 input_bufs_omx_free.push_back(buf_head);
693 omx_first_frame=true;
696 input_bufs_omx_mutex.Unlock();
698 if (!video->CommandFinished(omx_imag_decode/*dec*/,OMX_CommandPortEnable, omx_image_input_port /*codec*/)) {
705 int ImageOMX::DestroyInputBufsOMX() //call with clock mutex locked
709 input_bufs_omx_mutex.Lock();
710 for (int i=0; i< input_bufs_omx_all.size();i++) {
711 Log::getInstance()->log("Image", Log::DEBUG, "OMX_FreeBuffer mark");
712 //if (input_bufs_omx_all[i]->pBuffer) free(input_bufs_omx_all[i]->pBuffer);
713 input_bufs_omx_all[i]->pBuffer=NULL;
714 error=OMX_FreeBuffer(omx_imag_decode/*dec*/,omx_image_input_port/*codec*/,input_bufs_omx_all[i]);
715 if (error!=OMX_ErrorNone){
716 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
717 input_bufs_omx_mutex.Unlock();
722 input_bufs_omx_all.clear();
723 input_bufs_omx_free.clear();
724 input_bufs_omx_mutex.Unlock();
728 int ImageOMX::DestroyInputBufsOMXwhilePlaying() //call with clock mutex locked
732 input_bufs_omx_mutex.Lock();
733 while (input_bufs_omx_all.size()>0) {
734 if (input_bufs_omx_free.size()>0) {
735 // Destroy one buffer
736 vector<OMX_BUFFERHEADERTYPE*>::iterator itty=input_bufs_omx_all.begin();
737 OMX_BUFFERHEADERTYPE* cur_buf=input_bufs_omx_free.front();
738 for (; itty!= input_bufs_omx_all.end();itty++) {
739 if ((*itty)==cur_buf) {
740 input_bufs_omx_all.erase(itty);
741 input_bufs_omx_free.pop_front();
746 input_bufs_omx_mutex.Unlock();
748 input_bufs_omx_mutex.Lock();
752 Log::getInstance()->log("Image", Log::DEBUG, "DestroyInputBufsOMXwhilePlaying %d %d", input_bufs_omx_all.size(),input_bufs_omx_free.size());
753 input_bufs_omx_mutex.Unlock();
758 int ImageOMX::DeAllocateCodecsOMX()
762 VideoOMX *video=(VideoOMX*)Video::getInstance();
763 // Log::getInstance()->log("Image", Log::DEBUG, "enter deallocatecodecsomx");
767 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 1");
769 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 2");
772 if (omx_imag_decode/*dec*/) {
775 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
776 Log::getInstance()->log("Image", Log::DEBUG, "omx_imag_decode ChangeComponentState");
779 if (omx_egl_render) {
781 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
782 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_render ChangeComponentState");
784 /*if (!video->ChangeComponentState(omx_egl_render,OMX_StateLoaded,false)) {
785 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_render ChangeComponentState");
789 /* if (!video->ChangeComponentState(omx_imag_decode,OMX_StateLoaded,false)) {
790 Log::getInstance()->log("Image", Log::DEBUG, "omx_imag_decode ChangeComponentState");
795 // TODO proper deinit sequence
796 // first flush all buffers
800 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 3");
802 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_output_port, NULL);
803 if (error!=OMX_ErrorNone) {
804 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
808 if (omx_egl_render) {
810 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
811 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_render ChangeComponentState");
814 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 4");
816 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_input_port, NULL);
817 if (error!=OMX_ErrorNone) {
818 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
822 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 5");
824 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_output_port, NULL);
825 if (error!=OMX_ErrorNone) {
826 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
830 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6");
832 if (!video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_input_port) ||
833 !video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_output_port)) {
834 Log::getInstance()->log("Image", Log::DEBUG, "flush cmd clock shed failed");
836 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 a");
838 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_input_port, NULL);
839 if (error!=OMX_ErrorNone) {
840 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
845 error=OMX_FreeBuffer(omx_egl_render/*dec*/, omx_egl_output_port/*codec*/,buf_head_egl);
846 if (error!=OMX_ErrorNone){
847 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_FreeBuffer 2 failed %x", error);
854 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 b");
856 if (!video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_input_port) ||
857 !video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_output_port) ) {
858 Log::getInstance()->log("Image", Log::DEBUG, "flush cmd clock shed failed");
861 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6 c");
864 DestroyInputBufsOMX(); //We have to make sure that no buffers are in use
866 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 7");
869 if (!video->DisablePort(omx_imag_decode,omx_image_output_port,true)) {
870 Log::getInstance()->log("Image", Log::DEBUG, "Disable Tunnel Port failed 1");
873 if (omx_egl_render) {
875 if (!video->DisablePort(omx_egl_render,omx_egl_input_port,true)) {
876 Log::getInstance()->log("Image", Log::DEBUG, "Disable Tunnel Port failed 4");
880 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,NULL,NULL);
881 if (error!=OMX_ErrorNone) {
882 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
886 error=OMX_SetupTunnel(omx_egl_render,omx_egl_input_port,NULL,NULL);
887 if (error!=OMX_ErrorNone) {
888 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
894 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 8");
897 //error=OMX_FreeHandle(omx_aud_dec);
898 error=OMX_FreeHandle(omx_imag_decode);
899 if (error!=OMX_ErrorNone) {
900 Log::getInstance()->log("Image", Log::DEBUG, "FreeHandle failed %d", error);
902 if (omx_egl_render) {
903 error=OMX_FreeHandle(omx_egl_render);
904 if (error!=OMX_ErrorNone) {
905 Log::getInstance()->log("Image", Log::DEBUG, "FreeHandle failed %d", error);
908 video->UnlockClock();
910 video->clearEventsForComponent(omx_imag_decode);
911 video->clearEventsForComponent(omx_egl_render); // removes spurious error messages
912 omx_imag_decode/*dec*/=NULL;
913 omx_egl_render/*dec*/=NULL;
917 video->UnlockClock();
919 // Log::getInstance()->log("Image", Log::DEBUG, "leave deallocate codecs OMX");