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();
605 // usleep(100000); -- This delay triggers the race bug
608 // LogNT::getInstance()->debug(TAG,
609 // "decodePicture 9");
610 //video->EnablePort(omx_egl_render,omx_egl_output_port,false);
612 // LogNT::getInstance()->debug(TAG,
613 // "decodePicture 10");
615 omx_egl_filled = false;
616 error = OMX_FillThisBuffer(omx_egl_render, buf_head_egl);
618 if (error!=OMX_ErrorNone){
619 LogNT::getInstance()->debug(TAG, "OMX_FillThisBuffer failed {:#x}", error);
620 video->UnlockClock();
624 video->UnlockClock();
625 while (!omx_egl_filled) {
629 LogNT::getInstance()->debug(TAG, "No one filled my buffer");
636 omx_egl_filled = false;
638 // LogNT::getInstance()->debug(TAG,
639 // "decodePicture left");
648 bool ImageOMX::getDecodedPicture(struct OsdVector::PictureInfo& pict_inf)
650 if (!pictInfValid) return false;
652 pictInfValid = false;
656 void ImageOMX::freeReference(void* /* ref */)
660 int ImageOMX::PrepareInputBufsOMX(bool setportdef, unsigned char * buffer, unsigned int length) //needs to be called with locvke omx clock mutex
662 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
664 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
665 memset(&port_def_type,0,sizeof(port_def_type));
666 port_def_type.nSize=sizeof(port_def_type);
667 port_def_type.nVersion.nVersion=OMX_VERSION;
668 port_def_type.nPortIndex=omx_image_input_port;//omx_codec_input_port;
670 error=OMX_GetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
672 if (error!=OMX_ErrorNone){
673 LogNT::getInstance()->debug(TAG, "Get OMX OMX_IndexParamPortDefinition failed {:#x}", error);
678 port_def_type.nBufferCountActual=port_def_type.nBufferCountMin;
679 port_def_type.nBufferSize=max(port_def_type.nBufferSize,length); // for transcoder important
681 error=OMX_SetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
683 if (error!=OMX_ErrorNone){
684 LogNT::getInstance()->debug(TAG, "Set OMX OMX_IndexParamPortDefinition failed {:#x}", error);
689 error=OMX_SendCommand(omx_imag_decode/*dec*/,OMX_CommandPortEnable,omx_image_input_port/*codec*/,0);
690 if (error!=OMX_ErrorNone){
691 LogNT::getInstance()->debug(TAG, "Prepare Input bufs Send Command to enable port {:#x}", error);
695 input_bufs_omx_mutex.lock();
696 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
697 OMX_BUFFERHEADERTYPE *buf_head=NULL;
698 error=OMX_UseBuffer(omx_imag_decode/*dec*/,&buf_head,omx_image_input_port/*codec*/,this,port_def_type.nBufferSize, buffer);
699 if (error!=OMX_ErrorNone){
700 LogNT::getInstance()->debug(TAG, "Use OMX_UseBuffer failed {:#x}", error);
701 input_bufs_omx_mutex.unlock();
704 input_bufs_omx_all.push_back(buf_head);
705 input_bufs_omx_free.push_back(buf_head);
707 omx_first_frame=true;
710 input_bufs_omx_mutex.unlock();
712 if (!video->CommandFinished(omx_imag_decode/*dec*/,OMX_CommandPortEnable, omx_image_input_port /*codec*/)) {
719 int ImageOMX::DestroyInputBufsOMX() //call with clock mutex locked
723 input_bufs_omx_mutex.lock();
724 for (UINT i=0; i< input_bufs_omx_all.size();i++) {
725 LogNT::getInstance()->debug(TAG, "OMX_FreeBuffer mark");
726 //if (input_bufs_omx_all[i]->pBuffer) free(input_bufs_omx_all[i]->pBuffer);
727 input_bufs_omx_all[i]->pBuffer=NULL;
728 error=OMX_FreeBuffer(omx_imag_decode/*dec*/,omx_image_input_port/*codec*/,input_bufs_omx_all[i]);
729 if (error!=OMX_ErrorNone){
730 LogNT::getInstance()->debug(TAG, "Use OMX_FreeBuffer failed {:#x}", error);
731 input_bufs_omx_mutex.unlock();
736 input_bufs_omx_all.clear();
737 input_bufs_omx_free.clear();
738 input_bufs_omx_mutex.unlock();
743 int ImageOMX::DestroyInputBufsOMXwhilePlaying() //call with clock mutex locked
745 //OMX_ERRORTYPE error;
747 input_bufs_omx_mutex.lock();
748 while (input_bufs_omx_all.size()>0) {
749 if (input_bufs_omx_free.size()>0) {
750 // Destroy one buffer
751 std::vector<OMX_BUFFERHEADERTYPE*>::iterator itty=input_bufs_omx_all.begin();
752 OMX_BUFFERHEADERTYPE* cur_buf=input_bufs_omx_free.front();
753 for (; itty!= input_bufs_omx_all.end();itty++) {
754 if ((*itty)==cur_buf) {
755 input_bufs_omx_all.erase(itty);
756 input_bufs_omx_free.pop_front();
761 input_bufs_omx_mutex.unlock();
763 input_bufs_omx_mutex.lock();
767 LogNT::getInstance()->debug(TAG, "DestroyInputBufsOMXwhilePlaying {} {}", input_bufs_omx_all.size(),input_bufs_omx_free.size());
768 input_bufs_omx_mutex.unlock();
773 int ImageOMX::DeAllocateCodecsOMX()
777 VideoOMX* video = static_cast<VideoOMX*>(Video::getInstance());
778 // LogNT::getInstance()->debug(TAG, "enter deallocatecodecsomx");
782 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 1");
784 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 2");
787 if (omx_imag_decode/*dec*/) {
790 if (!video->ChangeComponentState(omx_imag_decode,OMX_StateIdle)) {
791 LogNT::getInstance()->debug(TAG, "omx_imag_decode ChangeComponentState");
794 if (omx_egl_render) {
796 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
797 LogNT::getInstance()->debug(TAG, "omx_egl_render ChangeComponentState");
799 /*if (!video->ChangeComponentState(omx_egl_render,OMX_StateLoaded,false)) {
800 LogNT::getInstance()->debug(TAG, "omx_egl_render ChangeComponentState");
804 /* if (!video->ChangeComponentState(omx_imag_decode,OMX_StateLoaded,false)) {
805 LogNT::getInstance()->debug(TAG, "omx_imag_decode ChangeComponentState");
810 // TODO proper deinit sequence
811 // first flush all buffers
815 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 3");
817 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_output_port, NULL);
818 if (error!=OMX_ErrorNone) {
819 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
823 if (omx_egl_render) {
825 if (!video->ChangeComponentState(omx_egl_render,OMX_StateIdle)) {
826 LogNT::getInstance()->debug(TAG, "omx_egl_render ChangeComponentState");
829 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 4");
831 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_input_port, NULL);
832 if (error!=OMX_ErrorNone) {
833 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
837 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 5");
839 error=OMX_SendCommand(omx_egl_render,OMX_CommandFlush, omx_egl_output_port, NULL);
840 if (error!=OMX_ErrorNone) {
841 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
845 // Log::getInstance()->log("Image", Log::DEBUG, "deallocatecodecsomx mark 6");
847 if (!video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_input_port) ||
848 !video->CommandFinished(omx_egl_render,OMX_CommandFlush,omx_egl_output_port)) {
849 LogNT::getInstance()->debug(TAG, "flush cmd clock shed failed");
851 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6 a");
853 error=OMX_SendCommand(omx_imag_decode,OMX_CommandFlush, omx_image_input_port, NULL);
854 if (error!=OMX_ErrorNone) {
855 LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error);
860 error=OMX_FreeBuffer(omx_egl_render/*dec*/, omx_egl_output_port/*codec*/,buf_head_egl);
861 if (error!=OMX_ErrorNone){
862 LogNT::getInstance()->debug(TAG, "Use OMX_FreeBuffer 2 failed {:#x}", error);
869 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6 b");
871 if (!video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_input_port) ||
872 !video->CommandFinished(omx_imag_decode,OMX_CommandFlush,omx_image_output_port) ) {
873 LogNT::getInstance()->debug(TAG, "flush cmd clock shed failed");
876 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6 c");
879 DestroyInputBufsOMX(); //We have to make sure that no buffers are in use
881 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 7");
884 if (!video->DisablePort(omx_imag_decode,omx_image_output_port,true)) {
885 LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 1");
888 if (omx_egl_render) {
890 if (!video->DisablePort(omx_egl_render,omx_egl_input_port,true)) {
891 LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 4");
895 error=OMX_SetupTunnel(omx_imag_decode,omx_image_output_port,NULL,0);
896 if (error!=OMX_ErrorNone) {
897 LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error);
901 error=OMX_SetupTunnel(omx_egl_render,omx_egl_input_port,NULL,0);
902 if (error!=OMX_ErrorNone) {
903 LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error);
909 // LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 8");
912 //error=OMX_FreeHandle(omx_aud_dec);
913 error=OMX_FreeHandle(omx_imag_decode);
914 if (error!=OMX_ErrorNone) {
915 LogNT::getInstance()->debug(TAG, "FreeHandle failed {}", error);
917 if (omx_egl_render) {
918 error=OMX_FreeHandle(omx_egl_render);
919 if (error!=OMX_ErrorNone) {
920 LogNT::getInstance()->debug(TAG, "FreeHandle failed {}", error);
923 video->UnlockClock();
925 video->clearEventsForComponent(omx_imag_decode);
926 video->clearEventsForComponent(omx_egl_render); // removes spurious error messages
927 omx_imag_decode/*dec*/=NULL;
928 omx_egl_render/*dec*/=NULL;
932 video->UnlockClock();
934 // LogNT::getInstance()->debug(TAG, "leave deallocate codecs OMX");