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/>.
25 #include "woptionpane.h"
27 #include "osdopenvg.h"
31 static const char* TAG = "ImageOMX";
33 ImageOMX::ImageOMX(OsdVector::PictureReader * treader):OsdVector::PictureDecoder(treader)
39 omx_imag_decode/*dec*/=NULL;
40 omx_egl_render/*dec*/=NULL;
43 curformat = Unsupported;
45 strcpy(L_VPE_OMX_IMAGE_DECODER, VPE_OMX_IMAGE_DECODER);
46 strcpy(L_VPE_OMX_EGL_REND, VPE_OMX_EGL_REND);
56 // AllocateCodecsOMX();
59 void ImageOMX::shutdown()
61 LogNT::getInstance()->debug(TAG, "shutdown");
62 //DeAllocateCodecsOMX();
69 OMX_ERRORTYPE ImageOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE /*hcomp*/,OMX_IN OMX_PTR /*appdata*/,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
71 //LogNT::getInstance()->info(TAG, "EmptyBufferDone");
72 ImageOMX* image = static_cast<ImageOMX*>(buffer->pAppPrivate);
73 image->ReturnEmptyOMXBuffer(buffer);
78 void ImageOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
79 input_bufs_omx_mutex.lock();
80 /*if (buffer->pBuffer) {
81 free(buffer->pBuffer);
82 buffer->pBuffer = NULL;
85 //LogNT::getInstance()->info(TAG, "ReturnEmptyOMXBuffer {}",input_bufs_omx_free.size());
86 input_bufs_omx_free.push_back(buffer);
87 //LogNT::getInstance()->info(TAG, "ReturnEmptyOMXBuffer {}",input_bufs_omx_free.size());
88 input_bufs_omx_mutex.unlock();
89 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
94 OMX_ERRORTYPE ImageOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE /*hcomp*/, OMX_IN OMX_PTR /*appdata*/,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
95 LogNT::getInstance()->info(TAG, "FillBufferDone");
96 ImageOMX* image = static_cast<ImageOMX*>(buffer->pAppPrivate);
97 image->ReturnFillOMXBuffer(buffer);
101 void ImageOMX::ReturnFillOMXBuffer(OMX_BUFFERHEADERTYPE* /*buffer*/)
103 //input_bufs_omx_mutex.lock();
104 omx_egl_filled = true;
105 //output_bufs_omx_full.push_back(buffer);
106 //input_bufs_omx_mutex.unlock();
107 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
114 int ImageOMX::play() {
117 lastAType=MPTYPE_MPEG_Image;
118 Log::getInstance()->log("Image", Log::DEBUG, "enter play");
120 ((VideoOMX*)Video::getInstance())->interlaceSwitch4Demux(); // switch resolution if necessary
122 if (!AllocateCodecsOMX()) {
132 int ImageOMX::AllocateCodecsOMX(unsigned char * buffer, unsigned int length)
135 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
137 //LogNT::getInstance()->info(TAG, "Allocate Codecs OMX");
138 //Clock, move later to Image
139 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
141 OMX_PORT_PARAM_TYPE p_param;
142 memset(&p_param,0,sizeof(p_param));
143 p_param.nSize=sizeof(p_param);
144 p_param.nVersion.nVersion=OMX_VERSION;
150 error = OMX_GetHandle(&omx_imag_decode, L_VPE_OMX_IMAGE_DECODER, NULL, &callbacks);
151 if (error != OMX_ErrorNone) {
152 LogNT::getInstance()->debug(TAG,
153 "Init OMX Image decoder failed %x", error);
154 video->UnlockClock();
160 error = OMX_GetParameter(omx_imag_decode, OMX_IndexParamImageInit, &p_param);
161 if (error != OMX_ErrorNone) {
162 LogNT::getInstance()->debug(TAG,
163 "Init OMX Image rend OMX_GetParameter failed %x", error);
164 video->UnlockClock();
167 omx_image_input_port = p_param.nStartPortNumber;
168 omx_image_output_port = p_param.nStartPortNumber+1;
173 OMX_IMAGE_PARAM_PORTFORMATTYPE ft_type;
174 memset(&ft_type,0,sizeof(ft_type));
175 ft_type.nSize=sizeof(ft_type);
176 ft_type.nVersion.nVersion=OMX_VERSION;
178 ft_type.nPortIndex=omx_image_input_port;
182 case Jpeg: ft_type.eCompressionFormat=OMX_IMAGE_CodingJPEG;
184 case PNG: ft_type.eCompressionFormat=OMX_IMAGE_CodingPNG;
192 error=OMX_SetParameter(omx_imag_decode,OMX_IndexParamImagePortFormat,&ft_type);
193 if (error!=OMX_ErrorNone){
194 LogNT::getInstance()->debug(TAG, "Init OMX_IndexParamVImagePortFormat failed %x", error);
195 video->UnlockClock();
199 if (!video->DisablePort(omx_imag_decode,omx_image_input_port) || !video->DisablePort(omx_imag_decode,omx_image_output_port)) {
200 LogNT::getInstance()->debug(TAG, "Disable Ports OMX Image decoder failed");
201 video->UnlockClock();
206 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
207 LogNT::getInstance()->debug(TAG, "image decode idle ChangeComponentState");
208 video->UnlockClock();
214 if (!PrepareInputBufsOMX(true, buffer, length)) {
215 video->UnlockClock();
216 LogNT::getInstance()->debug(TAG, "prepare input bufs failed");
226 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateExecuting)) {
227 LogNT::getInstance()->debug(TAG, "omx_image_decode ChangeComponentState Execute");
228 video->UnlockClock();
235 if (!video->EnablePort(omx_imag_decode,omx_image_input_port,false)
237 LogNT::getInstance()->debug(TAG, "Enable Ports OMXdecoder inputfailed");
238 video->UnlockClock();
245 video->UnlockClock();
250 //LogNT::getInstance()->debug(TAG, "Allocate Codecs OMX finished");
260 unsigned char* ImageOMX::decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem)
262 if (pictInfValid) return buffer; // does support only one image at a Time;
263 // LogNT::getInstance()->debug(TAG,
264 // "decodePicture 1");
265 EGLPictureCreator * pictcreat =dynamic_cast<EGLPictureCreator*>(Osd::getInstance());
266 curformat=Unsupported;
267 if (buffer[0]== 0xff && buffer[1] ==0xd8) curformat=Jpeg;
268 if (buffer[0]== 0x89 && buffer[1] ==0x50 && buffer[2] ==0x4e) curformat=PNG;
270 if (curformat == Unsupported) return buffer; // Jpeg magic numbers
271 // LogNT::getInstance()->debug(TAG,
272 // "decodePicture 2");
273 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
276 if (!pictcreat) return NULL;
279 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
280 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
282 if (!AllocateCodecsOMX(buffer,length)) {
283 DeAllocateCodecsOMX();
284 pthread_setcancelstate(oldcancelstate, NULL);
285 pthread_setcanceltype(oldcanceltype, NULL);
288 bool ret=intDecodePicture(index, buffer, length, pictcreat, video);
289 DeAllocateCodecsOMX();
290 pthread_setcancelstate(oldcancelstate, NULL);
291 pthread_setcanceltype(oldcanceltype, NULL);
292 if (ret && freemem) free(buffer);
294 if (ret) return NULL;
299 bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char* /* buffer */, unsigned int length, EGLPictureCreator* pictcreat, VideoOMX *video)
301 static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
304 OMX_BUFFERHEADERTYPE * bufhead;
306 input_bufs_omx_mutex.lock();
308 while (input_bufs_omx_free.size()==0) {
309 input_bufs_omx_mutex.unlock();
310 //LogNT::getInstance()->debug(TAG, "DMP mark 6");
311 //LogNT::getInstance()->debug(TAG, "Deliver MediaPacket no free sample");
312 //return 0; // we do not have a free media sample
315 if (count>100) return false;
318 input_bufs_omx_mutex.lock();
321 bufhead=input_bufs_omx_free.front();
322 bufhead->nFilledLen=length;
323 //bufhead->nAllocLen= length;
325 bufhead->nTimeStamp=VideoOMX::intToOMXTicks(0);
326 //bufhead->pBuffer=buffer;
327 bufhead->pAppPrivate=this;
328 input_bufs_omx_free.pop_front();
329 input_bufs_omx_mutex.unlock();
332 bufhead->nFilledLen=length;//bufhead->nAllocLen;
333 bufhead->nFlags=OMX_BUFFERFLAG_EOS;
334 video->ProtOMXEmptyThisBuffer(omx_imag_decode, bufhead);
339 // LogNT::getInstance()->debug(TAG,
340 // "decodePicture 3");
342 video->WaitForEvent(omx_imag_decode,OMX_EventPortSettingsChanged);
346 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
347 memset(&port_def_type,0,sizeof(port_def_type));
348 port_def_type.nSize=sizeof(port_def_type);
349 port_def_type.nVersion.nVersion=OMX_VERSION;
350 port_def_type.nPortIndex=omx_image_output_port;
351 // LogNT::getInstance()->debug(TAG,
352 // "decodePicture 3a");
354 error=OMX_GetParameter(omx_imag_decode,OMX_IndexParamPortDefinition, &port_def_type);
355 if (error != OMX_ErrorNone) {
356 LogNT::getInstance()->debug(TAG,
357 "OMX_IndexParamPortDefinition fix failed {:#x}", error);
358 video->UnlockClock();
361 // LogNT::getInstance()->debug(TAG,
362 // "decodePicture 4");
372 video->DisablePort(omx_imag_decode,omx_image_output_port,false);
373 LogNT::getInstance()->debug(TAG,
376 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortDisable,omx_image_output_port)) {
377 video->UnlockClock();
378 LogNT::getInstance()->debug(TAG, "commandfinishes end iop");
385 port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
386 port_def_type.format.image.nSliceHeight = 16;
387 port_def_type.format.image.nStride = 0;
390 //port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
391 //port_def_type.format.image.nSliceHeight = 32;
392 //port_def_type.format.image.nStride = 0;
393 port_def_type.format.image.nFrameHeight+=-(port_def_type.format.image.nFrameHeight%32); // The OpenMax png part is broken for the last slice
394 // so we cut the broken part, not nice but works
405 error = OMX_SetParameter(omx_imag_decode, OMX_IndexParamPortDefinition,
407 if (error != OMX_ErrorNone) {
408 LogNT::getInstance()->debug(TAG,
409 "Set OMX_IndexParamPortDefinition1 failed {:#x}", error);
410 video->UnlockClock();
415 // Log::getInstance()->log("Image", Log::DEBUG,
416 // "decodePicture 5 6");
417 error=OMX_GetHandle(&omx_egl_render,L_VPE_OMX_EGL_REND,NULL,&callbacks);
419 if (error!=OMX_ErrorNone){
420 LogNT::getInstance()->debug(TAG, "Init OMX EGL renderer failed {:#x}", error);
421 video->UnlockClock();
425 OMX_PORT_PARAM_TYPE p_param;
426 memset(&p_param,0,sizeof(p_param));
427 p_param.nSize=sizeof(p_param);
428 p_param.nVersion.nVersion=OMX_VERSION;
430 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamVideoInit,&p_param);
431 if (error!=OMX_ErrorNone){
432 LogNT::getInstance()->debug(TAG, "Init OMX EGL renderer OMX_GetParameter failed {:#x}", error);
433 video->UnlockClock();
436 omx_egl_input_port=p_param.nStartPortNumber;
437 omx_egl_output_port=p_param.nStartPortNumber+1;
442 if (!video->DisablePort(omx_egl_render,omx_egl_input_port) || !video->DisablePort(omx_egl_render,omx_egl_output_port)) {
443 LogNT::getInstance()->debug(TAG, "Disable Ports OMX Image decoder failed");
444 video->UnlockClock();
449 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
450 LogNT::getInstance()->debug(TAG, "egl render idle ChangeComponentState");
451 video->UnlockClock();
459 /* if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortDisable,omx_egl_input_port)) {
460 video->UnlockClock();
461 LogNT::getInstance()->debug(TAG, "commandfinishes end eip");
468 /* port_def_type.nPortIndex=omx_egl_input_port;
469 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
471 if (error != OMX_ErrorNone) {
472 LogNT::getInstance()->debug(TAG,
473 "Set OMX_IndexParamPortDefinition3 failed {:#x}", error);
474 video->UnlockClock();
475 pthread_setcancelstate(oldcancelstate, NULL);
476 pthread_setcanceltype(oldcanceltype, NULL);
480 pictInf.width = port_def_type.format.image.nFrameWidth;
481 pictInf.height = port_def_type.format.image.nFrameHeight;
482 pictInf.decoder = this;
483 pictInf.type = OsdVector::PictureInfo::RGBAMemBlock;
484 pictInf.lindex = index;
487 port_def_type.nPortIndex=omx_egl_output_port;
489 error=OMX_GetParameter(omx_egl_render,OMX_IndexParamPortDefinition, &port_def_type);
490 if (error != OMX_ErrorNone) {
491 LogNT::getInstance()->debug(TAG,
492 "OMX_IndexParamPortDefinition fix failed {:#x}", error);
493 video->UnlockClock();
499 port_def_type.nBufferCountActual = 1;
500 EGLDisplay egl_display;
501 if (!pictcreat->getEGLPicture(pictInf, &egl_display)) {
502 LogNT::getInstance()->debug(TAG,
503 "getEGLPict failed");
504 video->UnlockClock();
507 LogNT::getInstance()->debug(TAG,
508 "getEGLPict {:#x}", (long) pictInf.reference);
510 port_def_type.format.video.pNativeWindow = egl_display;
511 error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
513 if (error != OMX_ErrorNone) {
514 LogNT::getInstance()->debug(TAG,
515 "Set OMX_IndexParamPortDefinition3 failed {:#x}", error);
516 video->UnlockClock();
529 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,omx_egl_render,omx_egl_input_port);
530 if (error!=OMX_ErrorNone){
531 LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel decode to egl rend failed");
532 video->UnlockClock();
536 if (!video->EnablePort(omx_imag_decode,omx_image_output_port,false) || !video->EnablePort(omx_egl_render,omx_egl_input_port,false)
538 LogNT::getInstance()->debug(TAG, "Enable Ports OMXdecoder rend failed");
539 video->UnlockClock();
543 if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortEnable,omx_image_output_port)) {
544 video->UnlockClock();
545 LogNT::getInstance()->debug(TAG, "commandfinishes end iop");
549 if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortEnable,omx_egl_input_port)) {
550 video->UnlockClock();
551 LogNT::getInstance()->debug(TAG, "commandfinishes end eip");
555 // LogNT::getInstance()->debug(TAG,
556 // "decodePicture 7");
557 video->WaitForEvent(omx_egl_render,OMX_EventPortSettingsChanged);
559 LogNT::getInstance()->debug(TAG,
568 error=OMX_SendCommand(omx_egl_render/*dec*/,OMX_CommandPortEnable,omx_egl_output_port/*codec*/,0);
569 if (error!=OMX_ErrorNone){
570 LogNT::getInstance()->debug(TAG, "Prepare omx_egl_output_port Send Command to enable port {:#x}", error);
575 error=OMX_UseEGLImage(omx_egl_render/*dec*/,&buf_head_egl,omx_egl_output_port/*codec*/, this, pictInf.reference);
576 if (error!=OMX_ErrorNone){
577 LogNT::getInstance()->debug(TAG, "Use OMX_UseEGLImage failed {:#x}", error);
578 video->UnlockClock();
581 buf_head_egl->pAppPrivate=this;
583 // LogNT::getInstance()->debug(TAG,
584 // "decodePicture 8 a");
586 video->EnablePort(omx_imag_decode,omx_image_output_port,false);
588 if (!video->CommandFinished(omx_egl_render/*dec*/,OMX_CommandPortEnable, omx_egl_output_port /*codec*/)) {
589 video->UnlockClock();
596 LogNT::getInstance()->debug(TAG,
597 "decodePicture 8 end");
599 if (!video->ChangeComponentState(omx_egl_render,OMX_StateExecuting)) {
600 LogNT::getInstance()->debug(TAG, "omx_egl_rendd ChangeComponentState Execute");
601 video->UnlockClock();
606 // LogNT::getInstance()->debug(TAG,
607 // "decodePicture 9");
608 //video->EnablePort(omx_egl_render,omx_egl_output_port,false);
610 // LogNT::getInstance()->debug(TAG,
611 // "decodePicture 10");
613 omx_egl_filled = false;
614 error = OMX_FillThisBuffer(omx_egl_render, buf_head_egl);
616 if (error!=OMX_ErrorNone){
617 LogNT::getInstance()->debug(TAG, "OMX_FillThisBuffer failed {:#x}", error);
618 video->UnlockClock();
622 video->UnlockClock();
623 while (!omx_egl_filled) {
627 LogNT::getInstance()->debug(TAG, "No one filled my buffer");
634 omx_egl_filled = false;
636 // LogNT::getInstance()->debug(TAG,
637 // "decodePicture left");
646 bool ImageOMX::getDecodedPicture(struct OsdVector::PictureInfo& pict_inf)
648 if (!pictInfValid) return false;
650 pictInfValid = false;
654 void ImageOMX::freeReference(void* /* ref */)
658 int ImageOMX::PrepareInputBufsOMX(bool setportdef, unsigned char * buffer, unsigned int length) //needs to be called with locvke omx clock mutex
660 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
662 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
663 memset(&port_def_type,0,sizeof(port_def_type));
664 port_def_type.nSize=sizeof(port_def_type);
665 port_def_type.nVersion.nVersion=OMX_VERSION;
666 port_def_type.nPortIndex=omx_image_input_port;//omx_codec_input_port;
668 error=OMX_GetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
670 if (error!=OMX_ErrorNone){
671 LogNT::getInstance()->debug(TAG, "Get OMX OMX_IndexParamPortDefinition failed {:#x}", error);
676 port_def_type.nBufferCountActual=port_def_type.nBufferCountMin;
677 port_def_type.nBufferSize=max(port_def_type.nBufferSize,length); // for transcoder important
679 error=OMX_SetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
681 if (error!=OMX_ErrorNone){
682 LogNT::getInstance()->debug(TAG, "Set OMX OMX_IndexParamPortDefinition failed {:#x}", error);
687 error=OMX_SendCommand(omx_imag_decode/*dec*/,OMX_CommandPortEnable,omx_image_input_port/*codec*/,0);
688 if (error!=OMX_ErrorNone){
689 LogNT::getInstance()->debug(TAG, "Prepare Input bufs Send Command to enable port {:#x}", error);
693 input_bufs_omx_mutex.lock();
694 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
695 OMX_BUFFERHEADERTYPE *buf_head=NULL;
696 error=OMX_UseBuffer(omx_imag_decode/*dec*/,&buf_head,omx_image_input_port/*codec*/,this,port_def_type.nBufferSize, buffer);
697 if (error!=OMX_ErrorNone){
698 LogNT::getInstance()->debug(TAG, "Use OMX_UseBuffer failed {:#x}", error);
699 input_bufs_omx_mutex.unlock();
702 input_bufs_omx_all.push_back(buf_head);
703 input_bufs_omx_free.push_back(buf_head);
705 omx_first_frame=true;
708 input_bufs_omx_mutex.unlock();
710 if (!video->CommandFinished(omx_imag_decode/*dec*/,OMX_CommandPortEnable, omx_image_input_port /*codec*/)) {
717 int ImageOMX::DestroyInputBufsOMX() //call with clock mutex locked
721 input_bufs_omx_mutex.lock();
722 for (UINT i=0; i< input_bufs_omx_all.size();i++) {
723 LogNT::getInstance()->debug(TAG, "OMX_FreeBuffer mark");
724 //if (input_bufs_omx_all[i]->pBuffer) free(input_bufs_omx_all[i]->pBuffer);
725 input_bufs_omx_all[i]->pBuffer=NULL;
726 error=OMX_FreeBuffer(omx_imag_decode/*dec*/,omx_image_input_port/*codec*/,input_bufs_omx_all[i]);
727 if (error!=OMX_ErrorNone){
728 LogNT::getInstance()->debug(TAG, "Use OMX_FreeBuffer failed {:#x}", error);
729 input_bufs_omx_mutex.unlock();
734 input_bufs_omx_all.clear();
735 input_bufs_omx_free.clear();
736 input_bufs_omx_mutex.unlock();
741 int ImageOMX::DestroyInputBufsOMXwhilePlaying() //call with clock mutex locked
743 //OMX_ERRORTYPE error;
745 input_bufs_omx_mutex.lock();
746 while (input_bufs_omx_all.size()>0) {
747 if (input_bufs_omx_free.size()>0) {
748 // Destroy one buffer
749 std::vector<OMX_BUFFERHEADERTYPE*>::iterator itty=input_bufs_omx_all.begin();
750 OMX_BUFFERHEADERTYPE* cur_buf=input_bufs_omx_free.front();
751 for (; itty!= input_bufs_omx_all.end();itty++) {
752 if ((*itty)==cur_buf) {
753 input_bufs_omx_all.erase(itty);
754 input_bufs_omx_free.pop_front();
759 input_bufs_omx_mutex.unlock();
761 input_bufs_omx_mutex.lock();
765 LogNT::getInstance()->debug(TAG, "DestroyInputBufsOMXwhilePlaying {} {}", input_bufs_omx_all.size(),input_bufs_omx_free.size());
766 input_bufs_omx_mutex.unlock();
771 int ImageOMX::DeAllocateCodecsOMX()
775 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
776 // LogNT::getInstance()->debug(TAG, "enter deallocatecodecsomx");
780 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 1");
782 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 2");
785 if (omx_imag_decode/*dec*/) {
788 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
789 LogNT::getInstance()->debug(TAG, "omx_imag_decode ChangeComponentState");
792 if (omx_egl_render) {
794 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
795 LogNT::getInstance()->debug(TAG, "omx_egl_render ChangeComponentState");
797 /*if (!video->ChangeComponentState(omx_egl_render,OMX_StateLoaded,false)) {
798 LogNT::getInstance()->debug(TAG, "omx_egl_render ChangeComponentState");
802 /* if (!video->ChangeComponentState(omx_imag_decode,OMX_StateLoaded,false)) {
803 LogNT::getInstance()->debug(TAG, "omx_imag_decode ChangeComponentState");
808 // TODO proper deinit sequence
809 // first flush all buffers
813 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 3");
815 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_output_port, NULL);
816 if (error!=OMX_ErrorNone) {
817 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
821 if (omx_egl_render) {
823 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
824 LogNT::getInstance()->debug(TAG, "omx_egl_render ChangeComponentState");
827 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 4");
829 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_input_port, NULL);
830 if (error!=OMX_ErrorNone) {
831 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
835 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 5");
837 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_output_port, NULL);
838 if (error!=OMX_ErrorNone) {
839 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
843 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6");
845 if (!video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_input_port) ||
846 !video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_output_port)) {
847 LogNT::getInstance()->debug(TAG, "flush cmd clock shed failed");
849 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6 a");
851 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_input_port, NULL);
852 if (error!=OMX_ErrorNone) {
853 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
858 error=OMX_FreeBuffer(omx_egl_render/*dec*/, omx_egl_output_port/*codec*/,buf_head_egl);
859 if (error!=OMX_ErrorNone){
860 LogNT::getInstance()->debug(TAG, "Use OMX_FreeBuffer 2 failed {:#x}", error);
867 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6 b");
869 if (!video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_input_port) ||
870 !video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_output_port) ) {
871 LogNT::getInstance()->debug(TAG, "flush cmd clock shed failed");
874 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6 c");
877 DestroyInputBufsOMX(); //We have to make sure that no buffers are in use
879 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 7");
882 if (!video->DisablePort(omx_imag_decode,omx_image_output_port,true)) {
883 LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 1");
886 if (omx_egl_render) {
888 if (!video->DisablePort(omx_egl_render,omx_egl_input_port,true)) {
889 LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 4");
893 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,NULL,0);
894 if (error!=OMX_ErrorNone) {
895 LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error);
899 error=OMX_SetupTunnel(omx_egl_render,omx_egl_input_port,NULL,0);
900 if (error!=OMX_ErrorNone) {
901 LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error);
907 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 8");
910 //error=OMX_FreeHandle(omx_aud_dec);
911 error=OMX_FreeHandle(omx_imag_decode);
912 if (error!=OMX_ErrorNone) {
913 LogNT::getInstance()->debug(TAG, "FreeHandle failed {}", error);
915 if (omx_egl_render) {
916 error=OMX_FreeHandle(omx_egl_render);
917 if (error!=OMX_ErrorNone) {
918 LogNT::getInstance()->debug(TAG, "FreeHandle failed {}", error);
921 video->UnlockClock();
923 video->clearEventsForComponent(omx_imag_decode);
924 video->clearEventsForComponent(omx_egl_render); // removes spurious error messages
925 omx_imag_decode/*dec*/=NULL;
926 omx_egl_render/*dec*/=NULL;
930 video->UnlockClock();
932 // LogNT::getInstance()->debug(TAG, "leave deallocate codecs OMX");