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;
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=(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=(VideoOMX*)Video::getInstance();
90 OMX_ERRORTYPE ImageOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
91 Log::getInstance()->log("ImageOmx", Log::NOTICE, "FillBufferDone");
92 ImageOMX *image=(ImageOMX *)buffer->pAppPrivate;
93 image->ReturnFillOMXBuffer(buffer);
97 void ImageOMX::ReturnFillOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
98 //input_bufs_omx_mutex.Lock();
99 omx_egl_filled = true;
100 //output_bufs_omx_full.push_back(buffer);
101 //input_bufs_omx_mutex.Unlock();
102 VideoOMX *video=(VideoOMX*)Video::getInstance();
109 int ImageOMX::play() {
112 lastAType=MPTYPE_MPEG_Image;
113 Log::getInstance()->log("Image", Log::DEBUG, "enter play");
115 ((VideoOMX*)Video::getInstance())->interlaceSwitch4Demux(); // switch resolution if necessary
117 if (!AllocateCodecsOMX()) {
127 int ImageOMX::AllocateCodecsOMX(unsigned char * buffer, unsigned int length)
130 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
132 //Log::getInstance()->log("Image", Log::NOTICE, "Allocate Codecs OMX");
133 //Clock, move later to Image
134 VideoOMX *video=(VideoOMX*)Video::getInstance();
136 OMX_PORT_PARAM_TYPE p_param;
137 memset(&p_param,0,sizeof(p_param));
138 p_param.nSize=sizeof(p_param);
139 p_param.nVersion.nVersion=OMX_VERSION;
145 error = OMX_GetHandle(&omx_imag_decode, L_VPE_OMX_IMAGE_DECODER, NULL, &callbacks);
146 if (error != OMX_ErrorNone) {
147 Log::getInstance()->log("Image", Log::DEBUG,
148 "Init OMX Image decoder failed %x", error);
149 video->UnlockClock();
155 error = OMX_GetParameter(omx_imag_decode, OMX_IndexParamImageInit, &p_param);
156 if (error != OMX_ErrorNone) {
157 Log::getInstance()->log("Image", Log::DEBUG,
158 "Init OMX Image rend OMX_GetParameter failed %x", error);
159 video->UnlockClock();
162 omx_image_input_port = p_param.nStartPortNumber;
163 omx_image_output_port = p_param.nStartPortNumber+1;
168 OMX_IMAGE_PARAM_PORTFORMATTYPE ft_type;
169 memset(&ft_type,0,sizeof(ft_type));
170 ft_type.nSize=sizeof(ft_type);
171 ft_type.nVersion.nVersion=OMX_VERSION;
173 ft_type.nPortIndex=omx_image_input_port;
177 case Jpeg: ft_type.eCompressionFormat=OMX_IMAGE_CodingJPEG;
179 case PNG: ft_type.eCompressionFormat=OMX_IMAGE_CodingPNG;
187 error=OMX_SetParameter(omx_imag_decode,OMX_IndexParamImagePortFormat,&ft_type);
188 if (error!=OMX_ErrorNone){
189 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX_IndexParamVImagePortFormat failed %x", error);
190 video->UnlockClock();
194 if (!video->DisablePort(omx_imag_decode,omx_image_input_port) || !video->DisablePort(omx_imag_decode,omx_image_output_port)) {
195 Log::getInstance()->log("Image", Log::DEBUG, "Disable Ports OMX Image decoder failed");
196 video->UnlockClock();
201 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
202 Log::getInstance()->log("Image", Log::DEBUG, "image decode idle ChangeComponentState");
203 video->UnlockClock();
209 if (!PrepareInputBufsOMX(true, buffer, length)) {
210 video->UnlockClock();
211 Log::getInstance()->log("Image", Log::DEBUG, "prepare input bufs failed");
221 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateExecuting)) {
222 Log::getInstance()->log("Image", Log::DEBUG, "omx_image_decode ChangeComponentState Execute");
223 video->UnlockClock();
230 if (!video->EnablePort(omx_imag_decode,omx_image_input_port,false)
232 Log::getInstance()->log("Image", Log::DEBUG, "Enable Ports OMXdecoder inputfailed");
233 video->UnlockClock();
240 video->UnlockClock();
245 //Log::getInstance()->log("Image", Log::NOTICE, "Allocate Codecs OMX finished");
255 unsigned char* ImageOMX::decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem)
257 if (pictInfValid) return buffer; // does support only one image at a Time;
258 // Log::getInstance()->log("Image", Log::DEBUG,
259 // "decodePicture 1");
260 EGLPictureCreator * pictcreat =dynamic_cast<EGLPictureCreator*>(Osd::getInstance());
261 curformat=Unsupported;
262 if (buffer[0]== 0xff && buffer[1] ==0xd8) curformat=Jpeg;
263 if (buffer[0]== 0x89 && buffer[1] ==0x50 && buffer[2] ==0x4e) curformat=PNG;
265 if (curformat == Unsupported) return buffer; // Jpeg magic numbers
266 // Log::getInstance()->log("Image", Log::DEBUG,
267 // "decodePicture 2");
268 VideoOMX *video=(VideoOMX*)Video::getInstance();
271 if (!pictcreat) return NULL;
274 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
275 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
277 if (!AllocateCodecsOMX(buffer,length)) {
278 DeAllocateCodecsOMX();
279 pthread_setcancelstate(oldcancelstate, NULL);
280 pthread_setcanceltype(oldcanceltype, NULL);
283 bool ret=intDecodePicture(index, buffer, length, pictcreat, video);
284 DeAllocateCodecsOMX();
285 pthread_setcancelstate(oldcancelstate, NULL);
286 pthread_setcanceltype(oldcanceltype, NULL);
287 if (ret && freemem) free(buffer);
289 if (ret) return NULL;
294 bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, EGLPictureCreator* pictcreat, VideoOMX *video)
296 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
299 OMX_BUFFERHEADERTYPE * bufhead;
301 input_bufs_omx_mutex.Lock();
303 while (input_bufs_omx_free.size()==0) {
304 input_bufs_omx_mutex.Unlock();
305 //Log::getInstance()->log("Image", Log::DEBUG, "DMP mark 6");
306 //Log::getInstance()->log("Image", Log::DEBUG, "Deliver MediaPacket no free sample");
307 //return 0; // we do not have a free media sample
310 if (count>100) return false;
313 input_bufs_omx_mutex.Lock();
316 bufhead=input_bufs_omx_free.front();
317 bufhead->nFilledLen=length;
318 //bufhead->nAllocLen= length;
320 bufhead->nTimeStamp=VideoOMX::intToOMXTicks(0);
321 //bufhead->pBuffer=buffer;
322 bufhead->pAppPrivate=this;
323 input_bufs_omx_free.pop_front();
324 input_bufs_omx_mutex.Unlock();
327 bufhead->nFilledLen=length;//bufhead->nAllocLen;
328 bufhead->nFlags=OMX_BUFFERFLAG_EOS;
329 video->ProtOMXEmptyThisBuffer(omx_imag_decode, bufhead);
334 // Log::getInstance()->log("Image", Log::DEBUG,
335 // "decodePicture 3");
337 video->WaitForEvent(omx_imag_decode,OMX_EventPortSettingsChanged);
341 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
342 memset(&port_def_type,0,sizeof(port_def_type));
343 port_def_type.nSize=sizeof(port_def_type);
344 port_def_type.nVersion.nVersion=OMX_VERSION;
345 port_def_type.nPortIndex=omx_image_output_port;
346 // Log::getInstance()->log("Image", Log::DEBUG,
347 // "decodePicture 3a");
349 error=OMX_GetParameter(omx_imag_decode,OMX_IndexParamPortDefinition, &port_def_type);
350 if (error != OMX_ErrorNone) {
351 Log::getInstance()->log("Image", Log::DEBUG,
352 "OMX_IndexParamPortDefinition fix failed %x", error);
353 video->UnlockClock();
356 // Log::getInstance()->log("Image", Log::DEBUG,
357 // "decodePicture 4");
367 video->DisablePort(omx_imag_decode,omx_image_output_port,false);
368 Log::getInstance()->log("Image", Log::DEBUG,
371 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortDisable,omx_image_output_port)) {
372 video->UnlockClock();
373 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end iop");
380 port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
381 port_def_type.format.image.nSliceHeight = 16;
382 port_def_type.format.image.nStride = 0;
385 //port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
386 //port_def_type.format.image.nSliceHeight = 32;
387 //port_def_type.format.image.nStride = 0;
388 port_def_type.format.image.nFrameHeight+=-(port_def_type.format.image.nFrameHeight%32); // The OpenMax png part is broken for the last slice
389 // so we cut the broken part, not nice but works
400 error = OMX_SetParameter(omx_imag_decode, OMX_IndexParamPortDefinition,
402 if (error != OMX_ErrorNone) {
403 Log::getInstance()->log("Image", Log::DEBUG,
404 "Set OMX_IndexParamPortDefinition1 failed %x", error);
405 video->UnlockClock();
410 // Log::getInstance()->log("Image", Log::DEBUG,
411 // "decodePicture 5 6");
412 error=OMX_GetHandle(&omx_egl_render,L_VPE_OMX_EGL_REND,NULL,&callbacks);
414 if (error!=OMX_ErrorNone){
415 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX EGL renderer failed %x", error);
416 video->UnlockClock();
420 OMX_PORT_PARAM_TYPE p_param;
421 memset(&p_param,0,sizeof(p_param));
422 p_param.nSize=sizeof(p_param);
423 p_param.nVersion.nVersion=OMX_VERSION;
425 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamVideoInit,&p_param);
426 if (error!=OMX_ErrorNone){
427 Log::getInstance()->log("Image", Log::DEBUG, "Init OMX EGL renderer OMX_GetParameter failed %x", error);
428 video->UnlockClock();
431 omx_egl_input_port=p_param.nStartPortNumber;
432 omx_egl_output_port=p_param.nStartPortNumber+1;
437 if (!video->DisablePort(omx_egl_render,omx_egl_input_port) || !video->DisablePort(omx_egl_render,omx_egl_output_port)) {
438 Log::getInstance()->log("Image", Log::DEBUG, "Disable Ports OMX Image decoder failed");
439 video->UnlockClock();
444 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
445 Log::getInstance()->log("Image", Log::DEBUG, "egl render idle ChangeComponentState");
446 video->UnlockClock();
454 /* if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortDisable,omx_egl_input_port)) {
455 video->UnlockClock();
456 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
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();
494 port_def_type.nBufferCountActual = 1;
495 EGLDisplay egl_display;
496 if (!pictcreat->getEGLPicture(pictInf, &egl_display)) {
497 Log::getInstance()->log("Image", Log::DEBUG,
498 "getEGLPict failed");
499 video->UnlockClock();
502 Log::getInstance()->log("Image", Log::DEBUG,
503 "getEGLPict %x",pictInf.reference);
505 port_def_type.format.video.pNativeWindow = egl_display;
506 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
508 if (error != OMX_ErrorNone) {
509 Log::getInstance()->log("Image", Log::DEBUG,
510 "Set OMX_IndexParamPortDefinition3 failed %x", error);
511 video->UnlockClock();
524 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,omx_egl_render,omx_egl_input_port);
525 if (error!=OMX_ErrorNone){
526 Log::getInstance()->log("Image", Log::DEBUG, "OMX_Setup tunnel decode to egl rend failed %x ");
527 video->UnlockClock();
531 if (!video->EnablePort(omx_imag_decode,omx_image_output_port,false) || !video->EnablePort(omx_egl_render,omx_egl_input_port,false)
533 Log::getInstance()->log("Image", Log::DEBUG, "Enable Ports OMXdecoder rend failed");
534 video->UnlockClock();
538 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortEnable,omx_image_output_port)) {
539 video->UnlockClock();
540 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end iop");
544 if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortEnable,omx_egl_input_port)) {
545 video->UnlockClock();
546 Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
550 // Log::getInstance()->log("Image", Log::DEBUG,
551 // "decodePicture 7");
552 video->WaitForEvent(omx_egl_render,OMX_EventPortSettingsChanged);
554 Log::getInstance()->log("Image", Log::DEBUG,
563 error=OMX_SendCommand(omx_egl_render/*dec*/,OMX_CommandPortEnable,omx_egl_output_port/*codec*/,0);
564 if (error!=OMX_ErrorNone){
565 Log::getInstance()->log("Image", Log::DEBUG, "Prepare omx_egl_output_port Send Command to enable port %x", error);
570 error=OMX_UseEGLImage(omx_egl_render/*dec*/,&buf_head_egl,omx_egl_output_port/*codec*/, this, pictInf.reference);
571 if (error!=OMX_ErrorNone){
572 Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_UseEGLImage failed %x", error);
573 video->UnlockClock();
576 buf_head_egl->pAppPrivate=this;
578 // Log::getInstance()->log("Image", Log::DEBUG,
579 // "decodePicture 8 a");
581 video->EnablePort(omx_imag_decode,omx_image_output_port,false);
583 if (!video->CommandFinished(omx_egl_render/*dec*/,OMX_CommandPortEnable, omx_egl_output_port /*codec*/)) {
584 video->UnlockClock();
591 Log::getInstance()->log("Image", Log::DEBUG,
592 "decodePicture 8 end");
594 if (!video->ChangeComponentState(omx_egl_render,OMX_StateExecuting)) {
595 Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_rendd ChangeComponentState Execute");
596 video->UnlockClock();
601 // Log::getInstance()->log("Image", Log::DEBUG,
602 // "decodePicture 9");
603 //video->EnablePort(omx_egl_render,omx_egl_output_port,false);
605 // Log::getInstance()->log("Image", Log::DEBUG,
606 // "decodePicture 10");
608 omx_egl_filled = false;
609 error = OMX_FillThisBuffer(omx_egl_render, buf_head_egl);
611 if (error!=OMX_ErrorNone){
612 Log::getInstance()->log("Image", Log::DEBUG, "OMX_FillThisBuffer failed %x", error);
613 video->UnlockClock();
617 video->UnlockClock();
618 while (!omx_egl_filled) {
622 Log::getInstance()->log("Image", Log::DEBUG, "No one filled my buffer");
629 omx_egl_filled = false;
631 // Log::getInstance()->log("Image", Log::DEBUG,
632 // "decodePicture left");
641 bool ImageOMX::getDecodedPicture(struct OsdVector::PictureInfo& pict_inf)
643 if (!pictInfValid) return false;
645 pictInfValid = false;
649 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=(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 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=(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");