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 static const char* TAG = "ImageOMX";
32 ImageOMX::ImageOMX(OsdVector::PictureReader * treader):OsdVector::PictureDecoder(treader)
38 omx_imag_decode/*dec*/=NULL;
39 omx_egl_render/*dec*/=NULL;
42 curformat = Unsupported;
44 strcpy(L_VPE_OMX_IMAGE_DECODER, VPE_OMX_IMAGE_DECODER);
45 strcpy(L_VPE_OMX_EGL_REND, VPE_OMX_EGL_REND);
55 // AllocateCodecsOMX();
58 void ImageOMX::shutdown()
60 LogNT::getInstance()->debug(TAG, "shutdown");
61 //DeAllocateCodecsOMX();
68 OMX_ERRORTYPE ImageOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE /*hcomp*/,OMX_IN OMX_PTR /*appdata*/,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
70 //LogNT::getInstance()->info(TAG, "EmptyBufferDone");
71 ImageOMX* image = static_cast<ImageOMX*>(buffer->pAppPrivate);
72 image->ReturnEmptyOMXBuffer(buffer);
77 void ImageOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
78 input_bufs_omx_mutex.lock();
79 /*if (buffer->pBuffer) {
80 free(buffer->pBuffer);
81 buffer->pBuffer = NULL;
84 //LogNT::getInstance()->info(TAG, "ReturnEmptyOMXBuffer {}",input_bufs_omx_free.size());
85 input_bufs_omx_free.push_back(buffer);
86 //LogNT::getInstance()->info(TAG, "ReturnEmptyOMXBuffer {}",input_bufs_omx_free.size());
87 input_bufs_omx_mutex.unlock();
88 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
93 OMX_ERRORTYPE ImageOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE /*hcomp*/, OMX_IN OMX_PTR /*appdata*/,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
94 LogNT::getInstance()->info(TAG, "FillBufferDone");
95 ImageOMX* image = static_cast<ImageOMX*>(buffer->pAppPrivate);
96 image->ReturnFillOMXBuffer(buffer);
100 void ImageOMX::ReturnFillOMXBuffer(OMX_BUFFERHEADERTYPE* /*buffer*/)
102 //input_bufs_omx_mutex.lock();
103 omx_egl_filled = true;
104 //output_bufs_omx_full.push_back(buffer);
105 //input_bufs_omx_mutex.unlock();
106 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
113 int ImageOMX::play() {
116 lastAType=MPTYPE_MPEG_Image;
117 Log::getInstance()->log("Image", Log::DEBUG, "enter play");
119 ((VideoOMX*)Video::getInstance())->interlaceSwitch4Demux(); // switch resolution if necessary
121 if (!AllocateCodecsOMX()) {
131 int ImageOMX::AllocateCodecsOMX(unsigned char * buffer, unsigned int length)
134 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
136 //LogNT::getInstance()->info(TAG, "Allocate Codecs OMX");
137 //Clock, move later to Image
138 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
140 OMX_PORT_PARAM_TYPE p_param;
141 memset(&p_param,0,sizeof(p_param));
142 p_param.nSize=sizeof(p_param);
143 p_param.nVersion.nVersion=OMX_VERSION;
149 error = OMX_GetHandle(&omx_imag_decode, L_VPE_OMX_IMAGE_DECODER, NULL, &callbacks);
150 if (error != OMX_ErrorNone) {
151 LogNT::getInstance()->debug(TAG,
152 "Init OMX Image decoder failed %x", error);
153 video->UnlockClock();
159 error = OMX_GetParameter(omx_imag_decode, OMX_IndexParamImageInit, &p_param);
160 if (error != OMX_ErrorNone) {
161 LogNT::getInstance()->debug(TAG,
162 "Init OMX Image rend OMX_GetParameter failed %x", error);
163 video->UnlockClock();
166 omx_image_input_port = p_param.nStartPortNumber;
167 omx_image_output_port = p_param.nStartPortNumber+1;
172 OMX_IMAGE_PARAM_PORTFORMATTYPE ft_type;
173 memset(&ft_type,0,sizeof(ft_type));
174 ft_type.nSize=sizeof(ft_type);
175 ft_type.nVersion.nVersion=OMX_VERSION;
177 ft_type.nPortIndex=omx_image_input_port;
181 case Jpeg: ft_type.eCompressionFormat=OMX_IMAGE_CodingJPEG;
183 case PNG: ft_type.eCompressionFormat=OMX_IMAGE_CodingPNG;
191 error=OMX_SetParameter(omx_imag_decode,OMX_IndexParamImagePortFormat,&ft_type);
192 if (error!=OMX_ErrorNone){
193 LogNT::getInstance()->debug(TAG, "Init OMX_IndexParamVImagePortFormat failed %x", error);
194 video->UnlockClock();
198 if (!video->DisablePort(omx_imag_decode,omx_image_input_port) || !video->DisablePort(omx_imag_decode,omx_image_output_port)) {
199 LogNT::getInstance()->debug(TAG, "Disable Ports OMX Image decoder failed");
200 video->UnlockClock();
205 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
206 LogNT::getInstance()->debug(TAG, "image decode idle ChangeComponentState");
207 video->UnlockClock();
213 if (!PrepareInputBufsOMX(true, buffer, length)) {
214 video->UnlockClock();
215 LogNT::getInstance()->debug(TAG, "prepare input bufs failed");
225 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateExecuting)) {
226 LogNT::getInstance()->debug(TAG, "omx_image_decode ChangeComponentState Execute");
227 video->UnlockClock();
234 if (!video->EnablePort(omx_imag_decode,omx_image_input_port,false)
236 LogNT::getInstance()->debug(TAG, "Enable Ports OMXdecoder inputfailed");
237 video->UnlockClock();
244 video->UnlockClock();
249 //LogNT::getInstance()->debug(TAG, "Allocate Codecs OMX finished");
259 unsigned char* ImageOMX::decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem)
261 if (pictInfValid) return buffer; // does support only one image at a Time;
262 // LogNT::getInstance()->debug(TAG,
263 // "decodePicture 1");
264 EGLPictureCreator * pictcreat =dynamic_cast<EGLPictureCreator*>(Osd::getInstance());
265 curformat=Unsupported;
266 if (buffer[0]== 0xff && buffer[1] ==0xd8) curformat=Jpeg;
267 if (buffer[0]== 0x89 && buffer[1] ==0x50 && buffer[2] ==0x4e) curformat=PNG;
269 if (curformat == Unsupported) return buffer; // Jpeg magic numbers
270 // LogNT::getInstance()->debug(TAG,
271 // "decodePicture 2");
272 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
275 if (!pictcreat) return NULL;
278 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
279 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
281 if (!AllocateCodecsOMX(buffer,length)) {
282 DeAllocateCodecsOMX();
283 pthread_setcancelstate(oldcancelstate, NULL);
284 pthread_setcanceltype(oldcanceltype, NULL);
287 bool ret=intDecodePicture(index, buffer, length, pictcreat, video);
288 DeAllocateCodecsOMX();
289 pthread_setcancelstate(oldcancelstate, NULL);
290 pthread_setcanceltype(oldcanceltype, NULL);
291 if (ret && freemem) free(buffer);
293 if (ret) return NULL;
298 bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char* /* buffer */, unsigned int length, EGLPictureCreator* pictcreat, VideoOMX *video)
300 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
303 OMX_BUFFERHEADERTYPE * bufhead;
305 input_bufs_omx_mutex.lock();
307 while (input_bufs_omx_free.size()==0) {
308 input_bufs_omx_mutex.unlock();
309 //LogNT::getInstance()->debug(TAG, "DMP mark 6");
310 //LogNT::getInstance()->debug(TAG, "Deliver MediaPacket no free sample");
311 //return 0; // we do not have a free media sample
314 if (count>100) return false;
317 input_bufs_omx_mutex.lock();
320 bufhead=input_bufs_omx_free.front();
321 bufhead->nFilledLen=length;
322 //bufhead->nAllocLen= length;
324 bufhead->nTimeStamp=VideoOMX::intToOMXTicks(0);
325 //bufhead->pBuffer=buffer;
326 bufhead->pAppPrivate=this;
327 input_bufs_omx_free.pop_front();
328 input_bufs_omx_mutex.unlock();
331 bufhead->nFilledLen=length;//bufhead->nAllocLen;
332 bufhead->nFlags=OMX_BUFFERFLAG_EOS;
333 video->ProtOMXEmptyThisBuffer(omx_imag_decode, bufhead);
338 // LogNT::getInstance()->debug(TAG,
339 // "decodePicture 3");
341 video->WaitForEvent(omx_imag_decode,OMX_EventPortSettingsChanged);
345 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
346 memset(&port_def_type,0,sizeof(port_def_type));
347 port_def_type.nSize=sizeof(port_def_type);
348 port_def_type.nVersion.nVersion=OMX_VERSION;
349 port_def_type.nPortIndex=omx_image_output_port;
350 // LogNT::getInstance()->debug(TAG,
351 // "decodePicture 3a");
353 error=OMX_GetParameter(omx_imag_decode,OMX_IndexParamPortDefinition, &port_def_type);
354 if (error != OMX_ErrorNone) {
355 LogNT::getInstance()->debug(TAG,
356 "OMX_IndexParamPortDefinition fix failed {:#x}", error);
357 video->UnlockClock();
360 // LogNT::getInstance()->debug(TAG,
361 // "decodePicture 4");
371 video->DisablePort(omx_imag_decode,omx_image_output_port,false);
372 LogNT::getInstance()->debug(TAG,
375 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortDisable,omx_image_output_port)) {
376 video->UnlockClock();
377 LogNT::getInstance()->debug(TAG, "commandfinishes end iop");
384 port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
385 port_def_type.format.image.nSliceHeight = 16;
386 port_def_type.format.image.nStride = 0;
389 //port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
390 //port_def_type.format.image.nSliceHeight = 32;
391 //port_def_type.format.image.nStride = 0;
392 port_def_type.format.image.nFrameHeight+=-(port_def_type.format.image.nFrameHeight%32); // The OpenMax png part is broken for the last slice
393 // so we cut the broken part, not nice but works
404 error = OMX_SetParameter(omx_imag_decode, OMX_IndexParamPortDefinition,
406 if (error != OMX_ErrorNone) {
407 LogNT::getInstance()->debug(TAG,
408 "Set OMX_IndexParamPortDefinition1 failed {:#x}", error);
409 video->UnlockClock();
414 // Log::getInstance()->log("Image", Log::DEBUG,
415 // "decodePicture 5 6");
416 error=OMX_GetHandle(&omx_egl_render,L_VPE_OMX_EGL_REND,NULL,&callbacks);
418 if (error!=OMX_ErrorNone){
419 LogNT::getInstance()->debug(TAG, "Init OMX EGL renderer failed {:#x}", error);
420 video->UnlockClock();
424 OMX_PORT_PARAM_TYPE p_param;
425 memset(&p_param,0,sizeof(p_param));
426 p_param.nSize=sizeof(p_param);
427 p_param.nVersion.nVersion=OMX_VERSION;
429 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamVideoInit,&p_param);
430 if (error!=OMX_ErrorNone){
431 LogNT::getInstance()->debug(TAG, "Init OMX EGL renderer OMX_GetParameter failed {:#x}", error);
432 video->UnlockClock();
435 omx_egl_input_port=p_param.nStartPortNumber;
436 omx_egl_output_port=p_param.nStartPortNumber+1;
441 if (!video->DisablePort(omx_egl_render,omx_egl_input_port) || !video->DisablePort(omx_egl_render,omx_egl_output_port)) {
442 LogNT::getInstance()->debug(TAG, "Disable Ports OMX Image decoder failed");
443 video->UnlockClock();
448 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
449 LogNT::getInstance()->debug(TAG, "egl render idle ChangeComponentState");
450 video->UnlockClock();
458 /* if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortDisable,omx_egl_input_port)) {
459 video->UnlockClock();
460 LogNT::getInstance()->debug(TAG, "commandfinishes end eip");
467 /* port_def_type.nPortIndex=omx_egl_input_port;
468 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
470 if (error != OMX_ErrorNone) {
471 LogNT::getInstance()->debug(TAG,
472 "Set OMX_IndexParamPortDefinition3 failed {:#x}", error);
473 video->UnlockClock();
474 pthread_setcancelstate(oldcancelstate, NULL);
475 pthread_setcanceltype(oldcanceltype, NULL);
479 pictInf.width = port_def_type.format.image.nFrameWidth;
480 pictInf.height = port_def_type.format.image.nFrameHeight;
481 pictInf.decoder = this;
482 pictInf.type = OsdVector::PictureInfo::RGBAMemBlock;
483 pictInf.lindex = index;
486 port_def_type.nPortIndex=omx_egl_output_port;
488 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamPortDefinition, &port_def_type);
489 if (error != OMX_ErrorNone) {
490 LogNT::getInstance()->debug(TAG,
491 "OMX_IndexParamPortDefinition fix failed {:#x}", error);
492 video->UnlockClock();
498 port_def_type.nBufferCountActual = 1;
499 EGLDisplay egl_display;
500 if (!pictcreat->getEGLPicture(pictInf, &egl_display)) {
501 LogNT::getInstance()->debug(TAG,
502 "getEGLPict failed");
503 video->UnlockClock();
506 LogNT::getInstance()->debug(TAG,
507 "getEGLPict {:#x}",pictInf.reference);
509 port_def_type.format.video.pNativeWindow = egl_display;
510 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
512 if (error != OMX_ErrorNone) {
513 LogNT::getInstance()->debug(TAG,
514 "Set OMX_IndexParamPortDefinition3 failed {:#x}", error);
515 video->UnlockClock();
528 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,omx_egl_render,omx_egl_input_port);
529 if (error!=OMX_ErrorNone){
530 LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel decode to egl rend failed");
531 video->UnlockClock();
535 if (!video->EnablePort(omx_imag_decode,omx_image_output_port,false) || !video->EnablePort(omx_egl_render,omx_egl_input_port,false)
537 LogNT::getInstance()->debug(TAG, "Enable Ports OMXdecoder rend failed");
538 video->UnlockClock();
542 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortEnable,omx_image_output_port)) {
543 video->UnlockClock();
544 LogNT::getInstance()->debug(TAG, "commandfinishes end iop");
548 if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortEnable,omx_egl_input_port)) {
549 video->UnlockClock();
550 LogNT::getInstance()->debug(TAG, "commandfinishes end eip");
554 // LogNT::getInstance()->debug(TAG,
555 // "decodePicture 7");
556 video->WaitForEvent(omx_egl_render,OMX_EventPortSettingsChanged);
558 LogNT::getInstance()->debug(TAG,
567 error=OMX_SendCommand(omx_egl_render/*dec*/,OMX_CommandPortEnable,omx_egl_output_port/*codec*/,0);
568 if (error!=OMX_ErrorNone){
569 LogNT::getInstance()->debug(TAG, "Prepare omx_egl_output_port Send Command to enable port {:#x}", error);
574 error=OMX_UseEGLImage(omx_egl_render/*dec*/,&buf_head_egl,omx_egl_output_port/*codec*/, this, pictInf.reference);
575 if (error!=OMX_ErrorNone){
576 LogNT::getInstance()->debug(TAG, "Use OMX_UseEGLImage failed {:#x}", error);
577 video->UnlockClock();
580 buf_head_egl->pAppPrivate=this;
582 // LogNT::getInstance()->debug(TAG,
583 // "decodePicture 8 a");
585 video->EnablePort(omx_imag_decode,omx_image_output_port,false);
587 if (!video->CommandFinished(omx_egl_render/*dec*/,OMX_CommandPortEnable, omx_egl_output_port /*codec*/)) {
588 video->UnlockClock();
595 LogNT::getInstance()->debug(TAG,
596 "decodePicture 8 end");
598 if (!video->ChangeComponentState(omx_egl_render,OMX_StateExecuting)) {
599 LogNT::getInstance()->debug(TAG, "omx_egl_rendd ChangeComponentState Execute");
600 video->UnlockClock();
605 // LogNT::getInstance()->debug(TAG,
606 // "decodePicture 9");
607 //video->EnablePort(omx_egl_render,omx_egl_output_port,false);
609 // LogNT::getInstance()->debug(TAG,
610 // "decodePicture 10");
612 omx_egl_filled = false;
613 error = OMX_FillThisBuffer(omx_egl_render, buf_head_egl);
615 if (error!=OMX_ErrorNone){
616 LogNT::getInstance()->debug(TAG, "OMX_FillThisBuffer failed {:#x}", error);
617 video->UnlockClock();
621 video->UnlockClock();
622 while (!omx_egl_filled) {
626 LogNT::getInstance()->debug(TAG, "No one filled my buffer");
633 omx_egl_filled = false;
635 // LogNT::getInstance()->debug(TAG,
636 // "decodePicture left");
645 bool ImageOMX::getDecodedPicture(struct OsdVector::PictureInfo& pict_inf)
647 if (!pictInfValid) return false;
649 pictInfValid = false;
653 void ImageOMX::freeReference(void* /* ref */)
657 int ImageOMX::PrepareInputBufsOMX(bool setportdef, unsigned char * buffer, unsigned int length) //needs to be called with locvke omx clock mutex
659 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
661 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
662 memset(&port_def_type,0,sizeof(port_def_type));
663 port_def_type.nSize=sizeof(port_def_type);
664 port_def_type.nVersion.nVersion=OMX_VERSION;
665 port_def_type.nPortIndex=omx_image_input_port;//omx_codec_input_port;
667 error=OMX_GetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
669 if (error!=OMX_ErrorNone){
670 LogNT::getInstance()->debug(TAG, "Get OMX OMX_IndexParamPortDefinition failed {:#x}", error);
675 port_def_type.nBufferCountActual=port_def_type.nBufferCountMin;
676 port_def_type.nBufferSize=max(port_def_type.nBufferSize,length); // for transcoder important
678 error=OMX_SetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
680 if (error!=OMX_ErrorNone){
681 LogNT::getInstance()->debug(TAG, "Set OMX OMX_IndexParamPortDefinition failed {:#x}", error);
686 error=OMX_SendCommand(omx_imag_decode/*dec*/,OMX_CommandPortEnable,omx_image_input_port/*codec*/,0);
687 if (error!=OMX_ErrorNone){
688 LogNT::getInstance()->debug(TAG, "Prepare Input bufs Send Command to enable port {:#x}", error);
692 input_bufs_omx_mutex.lock();
693 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
694 OMX_BUFFERHEADERTYPE *buf_head=NULL;
695 error=OMX_UseBuffer(omx_imag_decode/*dec*/,&buf_head,omx_image_input_port/*codec*/,this,port_def_type.nBufferSize, buffer);
696 if (error!=OMX_ErrorNone){
697 LogNT::getInstance()->debug(TAG, "Use OMX_UseBuffer failed {:#x}", error);
698 input_bufs_omx_mutex.unlock();
701 input_bufs_omx_all.push_back(buf_head);
702 input_bufs_omx_free.push_back(buf_head);
704 omx_first_frame=true;
707 input_bufs_omx_mutex.unlock();
709 if (!video->CommandFinished(omx_imag_decode/*dec*/,OMX_CommandPortEnable, omx_image_input_port /*codec*/)) {
716 int ImageOMX::DestroyInputBufsOMX() //call with clock mutex locked
720 input_bufs_omx_mutex.lock();
721 for (UINT i=0; i< input_bufs_omx_all.size();i++) {
722 LogNT::getInstance()->debug(TAG, "OMX_FreeBuffer mark");
723 //if (input_bufs_omx_all[i]->pBuffer) free(input_bufs_omx_all[i]->pBuffer);
724 input_bufs_omx_all[i]->pBuffer=NULL;
725 error=OMX_FreeBuffer(omx_imag_decode/*dec*/,omx_image_input_port/*codec*/,input_bufs_omx_all[i]);
726 if (error!=OMX_ErrorNone){
727 LogNT::getInstance()->debug(TAG, "Use OMX_FreeBuffer failed {:#x}", error);
728 input_bufs_omx_mutex.unlock();
733 input_bufs_omx_all.clear();
734 input_bufs_omx_free.clear();
735 input_bufs_omx_mutex.unlock();
740 int ImageOMX::DestroyInputBufsOMXwhilePlaying() //call with clock mutex locked
742 //OMX_ERRORTYPE error;
744 input_bufs_omx_mutex.lock();
745 while (input_bufs_omx_all.size()>0) {
746 if (input_bufs_omx_free.size()>0) {
747 // Destroy one buffer
748 std::vector<OMX_BUFFERHEADERTYPE*>::iterator itty=input_bufs_omx_all.begin();
749 OMX_BUFFERHEADERTYPE* cur_buf=input_bufs_omx_free.front();
750 for (; itty!= input_bufs_omx_all.end();itty++) {
751 if ((*itty)==cur_buf) {
752 input_bufs_omx_all.erase(itty);
753 input_bufs_omx_free.pop_front();
758 input_bufs_omx_mutex.unlock();
760 input_bufs_omx_mutex.lock();
764 LogNT::getInstance()->debug(TAG, "DestroyInputBufsOMXwhilePlaying {} {}", input_bufs_omx_all.size(),input_bufs_omx_free.size());
765 input_bufs_omx_mutex.unlock();
770 int ImageOMX::DeAllocateCodecsOMX()
774 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
775 // LogNT::getInstance()->debug(TAG, "enter deallocatecodecsomx");
779 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 1");
781 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 2");
784 if (omx_imag_decode/*dec*/) {
787 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
788 LogNT::getInstance()->debug(TAG, "omx_imag_decode ChangeComponentState");
791 if (omx_egl_render) {
793 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
794 LogNT::getInstance()->debug(TAG, "omx_egl_render ChangeComponentState");
796 /*if (!video->ChangeComponentState(omx_egl_render,OMX_StateLoaded,false)) {
797 LogNT::getInstance()->debug(TAG, "omx_egl_render ChangeComponentState");
801 /* if (!video->ChangeComponentState(omx_imag_decode,OMX_StateLoaded,false)) {
802 LogNT::getInstance()->debug(TAG, "omx_imag_decode ChangeComponentState");
807 // TODO proper deinit sequence
808 // first flush all buffers
812 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 3");
814 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_output_port, NULL);
815 if (error!=OMX_ErrorNone) {
816 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
820 if (omx_egl_render) {
822 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
823 LogNT::getInstance()->debug(TAG, "omx_egl_render ChangeComponentState");
826 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 4");
828 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_input_port, NULL);
829 if (error!=OMX_ErrorNone) {
830 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
834 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 5");
836 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_output_port, NULL);
837 if (error!=OMX_ErrorNone) {
838 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
842 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6");
844 if (!video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_input_port) ||
845 !video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_output_port)) {
846 LogNT::getInstance()->debug(TAG, "flush cmd clock shed failed");
848 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6 a");
850 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_input_port, NULL);
851 if (error!=OMX_ErrorNone) {
852 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
857 error=OMX_FreeBuffer(omx_egl_render/*dec*/, omx_egl_output_port/*codec*/,buf_head_egl);
858 if (error!=OMX_ErrorNone){
859 LogNT::getInstance()->debug(TAG, "Use OMX_FreeBuffer 2 failed {:#x}", error);
866 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6 b");
868 if (!video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_input_port) ||
869 !video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_output_port) ) {
870 LogNT::getInstance()->debug(TAG, "flush cmd clock shed failed");
873 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6 c");
876 DestroyInputBufsOMX(); //We have to make sure that no buffers are in use
878 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 7");
881 if (!video->DisablePort(omx_imag_decode,omx_image_output_port,true)) {
882 LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 1");
885 if (omx_egl_render) {
887 if (!video->DisablePort(omx_egl_render,omx_egl_input_port,true)) {
888 LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 4");
892 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,NULL,0);
893 if (error!=OMX_ErrorNone) {
894 LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error);
898 error=OMX_SetupTunnel(omx_egl_render,omx_egl_input_port,NULL,0);
899 if (error!=OMX_ErrorNone) {
900 LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error);
906 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 8");
909 //error=OMX_FreeHandle(omx_aud_dec);
910 error=OMX_FreeHandle(omx_imag_decode);
911 if (error!=OMX_ErrorNone) {
912 LogNT::getInstance()->debug(TAG, "FreeHandle failed {}", error);
914 if (omx_egl_render) {
915 error=OMX_FreeHandle(omx_egl_render);
916 if (error!=OMX_ErrorNone) {
917 LogNT::getInstance()->debug(TAG, "FreeHandle failed {}", error);
920 video->UnlockClock();
922 video->clearEventsForComponent(omx_imag_decode);
923 video->clearEventsForComponent(omx_egl_render); // removes spurious error messages
924 omx_imag_decode/*dec*/=NULL;
925 omx_egl_render/*dec*/=NULL;
929 video->UnlockClock();
931 // LogNT::getInstance()->debug(TAG, "leave deallocate codecs OMX");