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)
48 void ImageOMX::shutdown()
50 Log::getInstance()->log("ImageOMX", Log::DEBUG, "shutdown");
51 DeAllocateCodecsOMX();
58 OMX_ERRORTYPE ImageOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
60 //Log::getInstance()->log("Image", Log::NOTICE, "EmptyBufferDone");
61 ImageOMX *image=(ImageOMX *)buffer->pAppPrivate;
62 image->ReturnEmptyOMXBuffer(buffer);
67 void ImageOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
68 input_bufs_omx_mutex.Lock();
69 if (buffer->pBuffer) {
70 free(buffer->pBuffer);
71 buffer->pBuffer = NULL;
74 //Log::getInstance()->log("Image", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
75 input_bufs_omx_free.push_back(buffer);
76 //Log::getInstance()->log("Image", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
77 input_bufs_omx_mutex.Unlock();
80 OMX_ERRORTYPE ImageOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
81 Log::getInstance()->log("ImageOmx", Log::NOTICE, "FillBufferDone");
82 ImageOMX *image=(ImageOMX *)buffer->pAppPrivate;
83 image->ReturnFillOMXBuffer(buffer);
87 void ImageOMX::ReturnFillOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
88 //input_bufs_omx_mutex.Lock();
89 omx_egl_filled = true;
90 //output_bufs_omx_full.push_back(buffer);
91 //input_bufs_omx_mutex.Unlock();
97 int ImageOMX::play() {
100 lastAType=MPTYPE_MPEG_Image;
101 Log::getInstance()->log("Image", Log::DEBUG, "enter play");
103 ((VideoOMX*)Video::getInstance())->interlaceSwitch4Demux(); // switch resolution if necessary
105 if (!AllocateCodecsOMX()) {
115 int ImageOMX::AllocateCodecsOMX()
118 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
120 Log::getInstance()->log("Image", Log::NOTICE, "Allocate Codecs OMX");
121 //Clock, move later to Image
122 VideoOMX *video=(VideoOMX*)Video::getInstance();
124 OMX_PORT_PARAM_TYPE p_param;
125 memset(&p_param,0,sizeof(p_param));
126 p_param.nSize=sizeof(p_param);
127 p_param.nVersion.nVersion=OMX_VERSION;
133 error = OMX_GetHandle(&omx_imag_decode, VPE_OMX_IMAGE_DECODER, NULL, &callbacks);
134 if (error != OMX_ErrorNone) {
135 Log::getInstance()->log("Image", Log::DEBUG,
136 "Init OMX Image decoder failed %x", error);
137 video->UnlockClock();
138 DeAllocateCodecsOMX();
144 error = OMX_GetParameter(omx_imag_decode, OMX_IndexParamImageInit, &p_param);
145 if (error != OMX_ErrorNone) {
146 Log::getInstance()->log("Image", Log::DEBUG,
147 "Init OMX Image rend OMX_GetParameter failed %x", error);
148 video->UnlockClock();
149 DeAllocateCodecsOMX();
152 omx_image_input_port = p_param.nStartPortNumber;
153 omx_image_output_port = p_param.nStartPortNumber+1;
155 error=OMX_GetHandle(&omx_egl_render,VPE_OMX_EGL_REND,NULL,&callbacks);
157 if (error!=OMX_ErrorNone){
158 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX EGL renderer failed %x", error);
159 video->UnlockClock();
160 DeAllocateCodecsOMX();
164 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamVideoInit,&p_param);
165 if (error!=OMX_ErrorNone){
166 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX EGL renderer OMX_GetParameter failed %x", error);
167 video->UnlockClock();
168 DeAllocateCodecsOMX();
171 omx_egl_input_port=p_param.nStartPortNumber;
172 omx_egl_output_port=p_param.nStartPortNumber+1;
174 if (!video->DisablePort(omx_imag_decode,omx_image_input_port) || !video->DisablePort(omx_imag_decode,omx_image_output_port)) {
175 Log::getInstance()->log("Image", Log::DEBUG, "Disable Ports OMX Image decoder failed");
176 video->UnlockClock();
177 DeAllocateCodecsOMX();
182 if (!video->DisablePort(omx_egl_render,omx_egl_input_port) || !video->DisablePort(omx_egl_render,omx_egl_output_port)) {
183 Log::getInstance()->log("Image", Log::DEBUG, "Disable Ports OMX Image decoder failed");
184 video->UnlockClock();
185 DeAllocateCodecsOMX();
189 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
190 Log::getInstance()->log("Image", Log::DEBUG, "image decode idle ChangeComponentState");
191 video->UnlockClock();
192 DeAllocateCodecsOMX();
196 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
197 Log::getInstance()->log("Image", Log::DEBUG, "egl render idle ChangeComponentState");
198 video->UnlockClock();
199 DeAllocateCodecsOMX();
210 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,omx_egl_render,omx_egl_input_port);
211 if (error!=OMX_ErrorNone){
212 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel decode to egl rend failed %x ");
213 video->UnlockClock();
214 DeAllocateCodecsOMX();
218 if (!video->EnablePort(omx_imag_decode,omx_image_output_port,false) || !video->EnablePort(omx_egl_render,omx_egl_input_port,false)
220 Log::getInstance()->log("Image", Log::DEBUG, "Enable Ports OMXdecoder rend failed");
221 video->UnlockClock();
222 DeAllocateCodecsOMX();
227 OMX_IMAGE_PARAM_PORTFORMATTYPE ft_type;
228 memset(&ft_type,0,sizeof(ft_type));
229 ft_type.nSize=sizeof(ft_type);
230 ft_type.nVersion.nVersion=OMX_VERSION;
232 ft_type.nPortIndex=omx_image_input_port;
234 ft_type.eCompressionFormat=OMX_IMAGE_CodingJPEG;
236 error=OMX_SetParameter(omx_imag_decode,OMX_IndexParamImagePortFormat,&ft_type);
237 if (error!=OMX_ErrorNone){
238 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX_IndexParamVImagePortFormat failed %x", error);
239 video->UnlockClock();
240 DeAllocateCodecsOMX();
245 if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortEnable,omx_egl_input_port)) {
246 video->UnlockClock();
247 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
248 DeAllocateCodecsOMX();
253 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortEnable,omx_image_output_port)) {
254 video->UnlockClock();
255 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end iop");
256 DeAllocateCodecsOMX();
265 if (!PrepareInputBufsOMX(true)) {
266 video->UnlockClock();
267 Log::getInstance()->log("Image", Log::DEBUG, "prepare input bufs failed");
268 DeAllocateCodecsOMX();
274 /* error=OMX_SetupTunnel(omx_aud_dec,omx_codec_output_port,omx_aud_rend,omx_rend_input_port);
275 if (error!=OMX_ErrorNone){
276 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel dec to render failed %x", error);
277 video->UnlockClock();
278 DeAllocateCodecsOMX();
284 /* if (!video->EnablePort(omx_aud_dec,omx_codec_output_port,false) || !video->EnablePort(omx_aud_rend,omx_rend_input_port,false)
286 Log::getInstance()->log("Image", Log::DEBUG, "Enable Ports OMX codec rend failed");
287 video->UnlockClock();
288 DeAllocateCodecsOMX();
292 /* if ( !video->CommandFinished(omx_aud_dec,OMX_CommandPortEnable,omx_codec_output_port)
293 || !video->CommandFinished(omx_aud_rend,OMX_CommandPortEnable,omx_rend_input_port)) {
294 video->UnlockClock();
295 DeAllocateCodecsOMX();
299 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateExecuting)) {
300 Log::getInstance()->log("Image", Log::DEBUG, "omx_image_decode ChangeComponentState Execute");
301 video->UnlockClock();
302 DeAllocateCodecsOMX();
307 if (!video->ChangeComponentState(omx_egl_render,OMX_StateExecuting)) {
308 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_rendd ChangeComponentState Execute");
309 video->UnlockClock();
310 DeAllocateCodecsOMX();
314 if (!video->EnablePort(omx_imag_decode,omx_image_input_port,false)
316 Log::getInstance()->log("Image", Log::DEBUG, "Enable Ports OMXdecoder inputfailed");
317 video->UnlockClock();
318 DeAllocateCodecsOMX();
325 video->UnlockClock();
330 Log::getInstance()->log("Image", Log::NOTICE, "Allocate Codecs OMX finished");
336 bool ImageOMX::decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length)
338 if (pictInfValid) return false; // does support only one image at a Time;
339 Log::getInstance()->log("Image", Log::DEBUG,
341 EGLPictureCreator * pictcreat =dynamic_cast<EGLPictureCreator*>(Osd::getInstance());
342 if (buffer[0]!= 0xff || buffer[1] !=0xd8) return false; // Jpeg magic numbers
343 Log::getInstance()->log("Image", Log::DEBUG,
345 VideoOMX *video=(VideoOMX*)Video::getInstance();
349 if (!pictcreat) return false;
352 OMX_BUFFERHEADERTYPE * bufhead;
354 input_bufs_omx_mutex.Lock();
356 while (input_bufs_omx_free.size()==0) {
357 input_bufs_omx_mutex.Unlock();
358 //Log::getInstance()->log("Image", Log::DEBUG, "DMP mark 6");
359 //Log::getInstance()->log("Image", Log::DEBUG, "Deliver MediaPacket no free sample");
360 //return 0; // we do not have a free media sample
363 if (count>100) return false;
366 input_bufs_omx_mutex.Lock();
369 bufhead=input_bufs_omx_free.front();
370 bufhead->nFilledLen=length;
371 bufhead->nAllocLen= length;
373 bufhead->nTimeStamp=VideoOMX::intToOMXTicks(0);
374 bufhead->pBuffer=buffer;
375 bufhead->pAppPrivate=this;
376 input_bufs_omx_free.pop_front();
377 input_bufs_omx_mutex.Unlock();
380 bufhead->nFilledLen=bufhead->nAllocLen;
381 video->ProtOMXEmptyThisBuffer(omx_imag_decode, bufhead);
385 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
386 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
389 Log::getInstance()->log("Image", Log::DEBUG,
392 video->WaitForEvent(omx_imag_decode,OMX_EventPortSettingsChanged);
396 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
397 memset(&port_def_type,0,sizeof(port_def_type));
398 port_def_type.nSize=sizeof(port_def_type);
399 port_def_type.nVersion.nVersion=OMX_VERSION;
400 port_def_type.nPortIndex=omx_image_output_port;
402 error=OMX_GetParameter(omx_imag_decode,OMX_IndexParamPortDefinition, &port_def_type);
403 if (error != OMX_ErrorNone) {
404 Log::getInstance()->log("Image", Log::DEBUG,
405 "OMX_IndexParamPortDefinition fix failed %x", error);
406 video->UnlockClock();
407 pthread_setcancelstate(oldcancelstate, NULL);
408 pthread_setcanceltype(oldcanceltype, NULL);
411 Log::getInstance()->log("Image", Log::DEBUG,
420 video->DisablePort(omx_egl_render,omx_egl_output_port,true);
421 video->DisablePort(omx_egl_render,omx_egl_input_port,false);
422 Log::getInstance()->log("Image", Log::DEBUG,
424 video->DisablePort(omx_imag_decode,omx_image_output_port,false);
425 Log::getInstance()->log("Image", Log::DEBUG,
429 if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortDisable,omx_egl_input_port)) {
430 video->UnlockClock();
431 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
432 DeAllocateCodecsOMX();
437 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortDisable,omx_image_output_port)) {
438 video->UnlockClock();
439 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end iop");
440 DeAllocateCodecsOMX();
444 port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
445 port_def_type.format.image.nSliceHeight = 16;
446 port_def_type.format.image.nStride = 0;
447 error = OMX_SetParameter(omx_imag_decode, OMX_IndexParamPortDefinition,
449 if (error != OMX_ErrorNone) {
450 Log::getInstance()->log("Image", Log::DEBUG,
451 "Set OMX_IndexParamPortDefinition1 failed %x", error);
452 video->UnlockClock();
453 pthread_setcancelstate(oldcancelstate, NULL);
454 pthread_setcanceltype(oldcanceltype, NULL);
459 Log::getInstance()->log("Image", Log::DEBUG,
460 "decodePicture 5 6");
463 /* port_def_type.nPortIndex=omx_egl_input_port;
464 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
466 if (error != OMX_ErrorNone) {
467 Log::getInstance()->log("Image", Log::DEBUG,
468 "Set OMX_IndexParamPortDefinition3 failed %x", error);
469 video->UnlockClock();
470 pthread_setcancelstate(oldcancelstate, NULL);
471 pthread_setcanceltype(oldcanceltype, NULL);
475 pictInf.width = port_def_type.format.image.nFrameWidth;
476 pictInf.height = port_def_type.format.image.nFrameHeight;
477 pictInf.decoder = this;
478 pictInf.type = OsdVector::PictureInfo::RGBAMemBlock;
479 pictInf.lindex = index;
482 port_def_type.nPortIndex=omx_egl_output_port;
484 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamPortDefinition, &port_def_type);
485 if (error != OMX_ErrorNone) {
486 Log::getInstance()->log("Image", Log::DEBUG,
487 "OMX_IndexParamPortDefinition fix failed %x", error);
488 video->UnlockClock();
489 pthread_setcancelstate(oldcancelstate, NULL);
490 pthread_setcanceltype(oldcanceltype, NULL);
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();
502 pthread_setcancelstate(oldcancelstate, NULL);
503 pthread_setcanceltype(oldcanceltype, NULL);
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();
514 pthread_setcancelstate(oldcancelstate, NULL);
515 pthread_setcanceltype(oldcanceltype, NULL);
524 Log::getInstance()->log("Image", Log::DEBUG,
526 video->WaitForEvent(omx_egl_render,OMX_EventPortSettingsChanged);
528 Log::getInstance()->log("Image", Log::DEBUG,
531 error=OMX_SendCommand(omx_egl_render/*dec*/,OMX_CommandPortEnable,omx_egl_output_port/*codec*/,0);
532 if (error!=OMX_ErrorNone){
533 Log::getInstance()->log("Image", Log::DEBUG, "Prepare omx_egl_output_port Send Command to enable port %x", error);
537 OMX_BUFFERHEADERTYPE *buf_head_egl=NULL;
538 error=OMX_UseEGLImage(omx_egl_render/*dec*/,&buf_head_egl,omx_egl_output_port/*codec*/, this, pictInf.reference);
539 if (error!=OMX_ErrorNone){
540 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_UseEGLImage failed %x", error);
541 video->UnlockClock();
542 pthread_setcancelstate(oldcancelstate, NULL);
543 pthread_setcanceltype(oldcanceltype, NULL);
546 buf_head_egl->pAppPrivate=this;
548 Log::getInstance()->log("Image", Log::DEBUG,
549 "decodePicture 8 a");
555 Log::getInstance()->log("Image", Log::DEBUG,
556 "decodePicture 8 end");
558 video->EnablePort(omx_imag_decode,omx_image_output_port,false);
559 Log::getInstance()->log("Image", Log::DEBUG,
561 //video->EnablePort(omx_egl_render,omx_egl_output_port,false);
563 Log::getInstance()->log("Image", Log::DEBUG,
566 omx_egl_filled = false;
567 error = OMX_FillThisBuffer(omx_egl_render, buf_head_egl);
569 if (error!=OMX_ErrorNone){
570 Log::getInstance()->log("Image", Log::DEBUG, "OMX_FillThisBuffer failed %x", error);
571 video->UnlockClock();
572 pthread_setcancelstate(oldcancelstate, NULL);
573 pthread_setcanceltype(oldcanceltype, NULL);
577 video->UnlockClock();
578 while (!omx_egl_filled) {
582 pthread_setcancelstate(oldcancelstate, NULL);
583 pthread_setcanceltype(oldcanceltype, NULL);
584 Log::getInstance()->log("Image", Log::DEBUG, "No one filled my buffer");
591 omx_egl_filled = false;
594 error=OMX_FreeBuffer(omx_egl_render/*dec*/, omx_egl_output_port/*codec*/,buf_head_egl);
595 if (error!=OMX_ErrorNone){
596 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_FreeBuffer 2 failed %x", error);
597 pthread_setcancelstate(oldcancelstate, NULL);
598 pthread_setcanceltype(oldcanceltype, NULL);
604 video->UnlockClock();
605 pthread_setcancelstate(oldcancelstate, NULL);
606 pthread_setcanceltype(oldcanceltype, NULL);
607 Log::getInstance()->log("Image", Log::DEBUG,
608 "decodePicture left");
615 bool ImageOMX::getDecodedPicture(struct OsdVector::PictureInfo& pict_inf)
617 if (!pictInfValid) return false;
619 pictInfValid = false;
623 void ImageOMX::freeReference(void * ref)
629 int ImageOMX::PrepareInputBufsOMX(bool setportdef) //needs to be called with locvke omx clock mutex
631 VideoOMX *video=(VideoOMX*)Video::getInstance();
633 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
634 memset(&port_def_type,0,sizeof(port_def_type));
635 port_def_type.nSize=sizeof(port_def_type);
636 port_def_type.nVersion.nVersion=OMX_VERSION;
637 port_def_type.nPortIndex=omx_image_input_port;//omx_codec_input_port;
639 error=OMX_GetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
641 if (error!=OMX_ErrorNone){
642 Log::getInstance()->log("Image", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
647 port_def_type.nBufferCountActual=10;
648 port_def_type.nBufferSize=max(port_def_type.nBufferSize,1000000); // for transcoder important
650 error=OMX_SetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
652 if (error!=OMX_ErrorNone){
653 Log::getInstance()->log("Image", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
658 error=OMX_SendCommand(omx_imag_decode/*dec*/,OMX_CommandPortEnable,omx_image_input_port/*codec*/,0);
659 if (error!=OMX_ErrorNone){
660 Log::getInstance()->log("Image", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
664 input_bufs_omx_mutex.Lock();
665 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
666 OMX_BUFFERHEADERTYPE *buf_head=NULL;
667 error=OMX_UseBuffer(omx_imag_decode/*dec*/,&buf_head,omx_image_input_port/*codec*/,this,port_def_type.nBufferSize, NULL);
668 if (error!=OMX_ErrorNone){
669 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_UseBuffer failed %x", error);
670 input_bufs_omx_mutex.Unlock();
673 input_bufs_omx_all.push_back(buf_head);
674 input_bufs_omx_free.push_back(buf_head);
676 omx_first_frame=true;
679 input_bufs_omx_mutex.Unlock();
681 if (!video->CommandFinished(omx_imag_decode/*dec*/,OMX_CommandPortEnable, omx_image_input_port /*codec*/)) {
688 int ImageOMX::DestroyInputBufsOMX() //call with clock mutex locked
692 input_bufs_omx_mutex.Lock();
693 for (int i=0; i< input_bufs_omx_all.size();i++) {
694 Log::getInstance()->log("Image", Log::DEBUG, "OMX_FreeBuffer mark");
695 if (input_bufs_omx_all[i]->pBuffer) free(input_bufs_omx_all[i]->pBuffer);
696 error=OMX_FreeBuffer(omx_imag_decode/*dec*/,omx_image_input_port/*codec*/,input_bufs_omx_all[i]);
697 if (error!=OMX_ErrorNone){
698 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
699 input_bufs_omx_mutex.Unlock();
704 input_bufs_omx_all.clear();
705 input_bufs_omx_free.clear();
706 input_bufs_omx_mutex.Unlock();
710 int ImageOMX::DestroyInputBufsOMXwhilePlaying() //call with clock mutex locked
714 input_bufs_omx_mutex.Lock();
715 while (input_bufs_omx_all.size()>0) {
716 if (input_bufs_omx_free.size()>0) {
717 // Destroy one buffer
718 vector<OMX_BUFFERHEADERTYPE*>::iterator itty=input_bufs_omx_all.begin();
719 OMX_BUFFERHEADERTYPE* cur_buf=input_bufs_omx_free.front();
720 for (; itty!= input_bufs_omx_all.end();itty++) {
721 if ((*itty)==cur_buf) {
722 input_bufs_omx_all.erase(itty);
723 input_bufs_omx_free.pop_front();
728 input_bufs_omx_mutex.Unlock();
730 input_bufs_omx_mutex.Lock();
734 Log::getInstance()->log("Image", Log::DEBUG, "DestroyInputBufsOMXwhilePlaying %d %d", input_bufs_omx_all.size(),input_bufs_omx_free.size());
735 input_bufs_omx_mutex.Unlock();
740 int ImageOMX::DeAllocateCodecsOMX()
744 VideoOMX *video=(VideoOMX*)Video::getInstance();
745 Log::getInstance()->log("Image", Log::DEBUG, "enter deallocatecodecsomx");
749 Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 1");
751 Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 2");
754 if (omx_imag_decode/*dec*/) {
757 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
758 Log::getInstance()->log("Image", Log::DEBUG, "omx_imag_decode ChangeComponentState");
761 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
762 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_render ChangeComponentState");
765 // TODO proper deinit sequence
766 // first flush all buffers
768 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_input_port, NULL);
769 if (error!=OMX_ErrorNone) {
770 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
774 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_output_port, NULL);
775 if (error!=OMX_ErrorNone) {
776 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
780 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_input_port, NULL);
781 if (error!=OMX_ErrorNone) {
782 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
786 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_output_port, NULL);
787 if (error!=OMX_ErrorNone) {
788 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Flush rend in failed %x", error);
795 Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6");
797 if (!video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_input_port) ||
798 !video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_input_port) ||
799 !video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_output_port) ||
800 !video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_output_port)) {
801 Log::getInstance()->log("Image", Log::DEBUG, "flush cmd clock shed failed");
805 DestroyInputBufsOMX(); //We have to make sure that no buffers are in use
807 Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 7");
810 if (!video->DisablePort(omx_imag_decode,omx_image_output_port,true)) {
811 Log::getInstance()->log("Image", Log::DEBUG, "Disable Tunnel Port failed 1");
815 if (!video->DisablePort(omx_egl_render,omx_egl_input_port,true)) {
816 Log::getInstance()->log("Image", Log::DEBUG, "Disable Tunnel Port failed 4");
822 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,NULL,NULL);
823 if (error!=OMX_ErrorNone) {
824 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
828 error=OMX_SetupTunnel(omx_egl_render,omx_egl_input_port,NULL,NULL);
829 if (error!=OMX_ErrorNone) {
830 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
835 Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 8");
838 //error=OMX_FreeHandle(omx_aud_dec);
839 error=OMX_FreeHandle(omx_imag_decode);
840 if (error!=OMX_ErrorNone) {
841 Log::getInstance()->log("Image", Log::DEBUG, "FreeHandle failed %d", error);
843 error=OMX_FreeHandle(omx_egl_render);
844 if (error!=OMX_ErrorNone) {
845 Log::getInstance()->log("Image", Log::DEBUG, "FreeHandle failed %d", error);
847 video->UnlockClock();
849 omx_imag_decode/*dec*/=NULL;
850 omx_egl_render/*dec*/=NULL;
854 video->UnlockClock();
856 Log::getInstance()->log("Image", Log::DEBUG, "leave deallocate codecs OMX");