2 Copyright 2004-2005 Chris Tallon, 2009-12 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.
23 #include "mtdraspberry.h"
26 #include "woptionpane.h"
27 #include "osdopenvg.h"
36 //A lot of parts of this file are heavily inspired by xbmc omx implementations
38 VideoOMX::VideoOMX() {
43 cur_input_buf_omx = NULL;
44 omx_h264 = omx_mpeg2 = true;
48 offsetvideonotset = true;
49 offsetaudionotset = true;
61 deinterlace=2; //advanced
73 int VideoOMX::init(UCHAR tformat)
75 if (initted) return 0;
78 if (!setFormat(tformat)) { shutdown(); return 0; }
79 if (!setConnection(HDMI)) { shutdown(); return 0; }
80 if (!setAspectRatio(ASPECT4X3)) { shutdown(); return 0; }
81 if (!setMode(NORMAL)) { shutdown(); return 0; }
82 if (!setSource()) { shutdown(); return 0; }
83 if (!attachFrameBuffer()) { shutdown(); return 0; }
91 if (error != OMX_ErrorNone) {
92 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX failed %x",
111 OMX_ERRORTYPE VideoOMX::EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
112 OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
113 OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data) {
115 Log::getInstance()->log("Video", Log::NOTICE, "eventHandler %x %x %x %x %x",handle,event_type,data1,data2,event_data);
117 struct VPE_OMX_EVENT new_event;
118 new_event.handle=handle;
119 new_event.appdata=appdata;
120 new_event.event_type=event_type;
121 new_event.data1=data1;
122 new_event.data2=data2;
123 new_event.event_data=event_data;
125 VideoOMX *video=(VideoOMX *)getInstance();
126 video->AddOmxEvent(new_event);
128 /* switch (event_type) {
129 case OMX_EventCmdComplete: {
134 return OMX_ErrorNone;
138 void VideoOMX::AddOmxEvent(VPE_OMX_EVENT new_event)
140 omx_event_mutex.Lock();
141 omx_events.push_back(new_event);
142 omx_event_mutex.Unlock();
146 OMX_ERRORTYPE VideoOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
148 //Log::getInstance()->log("Video", Log::NOTICE, "EmptyBufferDone");
149 VideoOMX *video=(VideoOMX *)getInstance();
150 /* long long temp =buffer->nTimeStamp.nLowPart
151 | ((long long) buffer->nTimeStamp.nHighPart << 32);
152 Log::getInstance()->log("Video", Log::NOTICE, "EBD Video %lld %x",temp,buffer->nFlags);*/
153 video->ReturnEmptyOMXBuffer(buffer);
154 return OMX_ErrorNone;
158 void VideoOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
159 input_bufs_omx_mutex.Lock();
160 //Log::getInstance()->log("Video", Log::NOTICE, "ReturnEmptyOMXBuffer %d %d %d",input_bufs_omx_free.size(),input_bufs_omx_present.size(),input_bufs_omx_all.size());
161 input_bufs_omx_free.push_back(buffer);
162 //Log::getInstance()->log("Video", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
163 input_bufs_omx_mutex.Unlock();
166 OMX_ERRORTYPE VideoOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
167 Log::getInstance()->log("Video", Log::NOTICE, "FillBufferDone");
168 return OMX_ErrorNone;
173 int VideoOMX::shutdown()
175 if (!initted) return 0;
177 Log::getInstance()->log("Video", Log::NOTICE, "Shutdown video module");
179 DeAllocateCodecsOMX();
181 //vc_tv_show_info(0); // back to console
184 struct fb_var_screeninfo screeninfo;
185 fd_fbset=open("/dev/fb0",O_RDONLY);
187 Log::getInstance()->log("Video", Log::CRIT, "Could not open frame buffer device %d", fd_fbset);
190 if (ioctl(fd_fbset, FBIOGET_VSCREENINFO, &screeninfo)){
192 Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOGET_VSCREENINFO frame buffer device");
195 screeninfo.bits_per_pixel=8;
196 if (ioctl(fd_fbset, FBIOPUT_VSCREENINFO, &screeninfo)){
197 Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOPUT_VSCREENINFO frame buffer device");
199 screeninfo.bits_per_pixel=16;
200 if (ioctl(fd_fbset, FBIOPUT_VSCREENINFO, &screeninfo)){
201 Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOPUT_VSCREENINFO frame buffer device");
209 bool VideoOMX::loadOptionsfromServer(VDR* vdr)
211 Log::getInstance()->log("Video", Log::DEBUG, "VideoOMX config load");
212 char *name=vdr->configLoad("VideoOMX","SDDeinterlacing");
215 if (STRCASECMP(name, "None") == 0) {
217 }/* else if (STRCASECMP(name, "LineDouble") == 0) {
219 }*/ else if (STRCASECMP(name, "Advanced") == 0) {
221 } /*else if (STRCASECMP(name, "Crazy") == 0) {
222 deinterlace = 3; // this does not activate deinterlacing but a image filter, just for fun
224 Log::getInstance()->log("Video", Log::DEBUG, "Set deinterlacing to %s %d",name,deinterlace);
231 bool VideoOMX::handleOptionChanges(Option* option)
233 if (Video::handleOptionChanges(option))
235 switch (option->id) {
237 if (STRCASECMP(option->options[option->userSetChoice], "None") == 0) {
239 } /*else if (STRCASECMP(option->options[option->userSetChoice], "LineDouble")
242 }*/ else if (STRCASECMP(option->options[option->userSetChoice], "Advanced")
245 } /*else if (STRCASECMP(option->options[option->userSetChoice], "Crazy")
249 Log::getInstance()->log("Video", Log::DEBUG, "Set deinterlacing to %s %d",option->options[option->userSetChoice],deinterlace);
258 bool VideoOMX::saveOptionstoServer()
261 switch (deinterlace) {
263 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "None");
266 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "LineDouble");
269 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "Advanced");
272 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "Crazy");
279 /*Option(UINT id, const char* displayText, const char* configSection, const char* configKey, UINT optionType,
280 UINT numChoices, UINT defaultChoice, UINT startInt,
281 const char * const * options, const char * const * optionkeys = NULL, AbstractOption* handler=NULL);*/
283 bool VideoOMX::addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane)
285 if (!Video::addOptionsToPanes(panenumber,options,pane)) return false;
291 static const char* deinterlaceopts[]={"None",/*"LineDouble",*/"Advanced"/*,"Crazy"*/};
292 option = new Option(1,tr("SD Deinterlacing"), "VideoOMX","SDDeinterlacing",Option::TYPE_TEXT,/*4,2*/2,1,0,deinterlaceopts,NULL,false,this);
293 options->push_back(option);
294 pane->addOptionLine(option);
302 int VideoOMX::setTVsize(UCHAR ttvsize)
304 if (tvsize!=ttvsize) pendingmodechange=true;
309 void VideoOMX::executePendingModeChanges()
311 if (pendingmodechange) {
312 Log::getInstance()->log("Video", Log::NOTICE, "Execute pending mode change");
313 Osd::getInstance()->shutdown();
315 Osd::getInstance()->restore();
316 Osd::getInstance()->init((void*) "");
317 BoxStack::getInstance()->redrawAllBoxes();
322 int VideoOMX::setDefaultAspect()
324 return setAspectRatio(tvsize);
329 int VideoOMX::setFormat(UCHAR tformat)
331 if (!initted) return 0;
332 if ((tformat != PAL) && (tformat != NTSC)
333 && (tformat != PAL_M) && (tformat != NTSC_J)) return 0;
343 // selectVideoMode(0);
348 void VideoOMX::selectVideoMode(int interlaced)
351 TV_SUPPORTED_MODE_T all_supp_modes[TV_MAX_SUPPORTED_MODES];
352 HDMI_RES_GROUP_T pref_group;
353 TV_SUPPORTED_MODE_T *mymode=NULL;
354 TV_SUPPORTED_MODE_T *mymode_second_best=NULL;
355 bool got_optimum=false;
357 HDMI_RES_GROUP_T group=HDMI_RES_GROUP_CEA;
358 int all_my_modes=vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_CEA,
359 all_supp_modes,TV_MAX_SUPPORTED_MODES,
360 &pref_group,&pref_mode);
361 if (all_my_modes<=0) {
362 group=HDMI_RES_GROUP_DMT;
363 all_my_modes=vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_DMT,
364 all_supp_modes,TV_MAX_SUPPORTED_MODES,
365 &pref_group,&pref_mode);
366 Log::getInstance()->log("Video", Log::NOTICE, "No CEA fall back to DMT modes ");
369 if (all_my_modes<=0 || connection==COMPOSITERGB ) {
371 Log::getInstance()->log("Video", Log::NOTICE, "No CEA and DMT modes found analog tv case?");
372 Remote::getInstance()->shutdown();
374 SDTV_MODE_T setmode=SDTV_MODE_PAL;
375 SDTV_OPTIONS_T options;
380 Log::getInstance()->log("Video", Log::NOTICE, "SDTV aspect 16:9");
381 options.aspect=SDTV_ASPECT_16_9; break;
383 Log::getInstance()->log("Video", Log::NOTICE, "SDTV aspect 4:3");
384 options.aspect=SDTV_ASPECT_4_3; break;
386 Log::getInstance()->log("Video", Log::NOTICE, "SDTV aspect 14:9");
387 options.aspect=SDTV_ASPECT_14_9; break;
390 if (format==PAL) setmode=SDTV_MODE_PAL;
391 else if (format==NTSC) setmode=SDTV_MODE_NTSC;
392 else if (format==PAL_M)setmode=SDTV_MODE_PAL_M;
393 else if (format==NTSC_J) setmode=SDTV_MODE_NTSC_J;
394 vc_tv_sdtv_power_on(setmode,&options);
399 if (format==PAL)target_fps=50;
400 else if (format==NTSC) target_fps=60;
402 //Now first determine native resolution
403 int native_width=1920;
404 int native_height=1080;
405 for (int i=0;i<all_my_modes;i++) {
406 if (all_supp_modes[i].native) {
407 mymode=all_supp_modes+i;
408 Log::getInstance()->log("Video", Log::NOTICE, "Found native mode %dx%d %d Hz i: %d",
409 mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode);
410 native_width=mymode->width;
411 native_height=mymode->height;
415 //Now find the mode which matches best
416 for (int i=0;i<all_my_modes;i++) {
417 TV_SUPPORTED_MODE_T *curmode=all_supp_modes+i;
418 if (curmode->width==native_width &&
419 curmode->height==native_height &&
420 curmode->frame_rate==target_fps) {
421 if(curmode->scan_mode==interlaced) {
424 Log::getInstance()->log("Video", Log::NOTICE, "Found optimum mode %dx%d %d Hz i: %d",
425 mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode);
427 mymode_second_best=curmode;
428 Log::getInstance()->log("Video", Log::NOTICE, "Found close to optimum mode %dx%d %d Hz i: %d",
429 mymode_second_best->width,mymode_second_best->height,
430 mymode_second_best->frame_rate,mymode_second_best->scan_mode);
435 Remote::getInstance()->shutdown();
438 Log::getInstance()->log("Video", Log::NOTICE, "Switch to optimum mode");
439 vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,group,mymode->code);
440 } else if (mymode_second_best) {
441 Log::getInstance()->log("Video", Log::NOTICE, "Switch to close to optimum mode");
442 vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,group,mymode_second_best->code);
444 Log::getInstance()->log("Video", Log::NOTICE, "Switch to prefered mode");
445 vc_tv_hdmi_power_on_best(1920,1080,target_fps,interlaced?HDMI_INTERLACED:HDMI_NONINTERLACED,
446 (EDID_MODE_MATCH_FLAG_T)(HDMI_MODE_MATCH_FRAMERATE|HDMI_MODE_MATCH_RESOLUTION|HDMI_MODE_MATCH_SCANMODE));
449 outputinterlaced=interlaced;
452 Remote::getInstance()->init("");
456 pendingmodechange=false;
461 int VideoOMX::setConnection(UCHAR tconnection)
463 if (!initted) return 0;
464 if ((tconnection != COMPOSITERGB) && (tconnection != HDMI)) return 0;
465 if (connection!=tconnection) pendingmodechange=true;
466 connection = tconnection;
468 // if (ioctl(fdVideo, AV_SET_VID_OUTPUT, connection) != 0) return 0;
472 int VideoOMX::setAspectRatio(UCHAR taspectRatio)
474 if (!initted) return 0;
475 if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
476 aspectRatio = taspectRatio;
478 Log::getInstance()->log("Video", Log::DEBUG, "Setting aspect to %i", aspectRatio);
480 // if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
484 int VideoOMX::setMode(UCHAR tmode)
486 if (!initted) return 0;
493 void VideoOMX::updateMode()
498 OMX_CONFIG_DISPLAYREGIONTYPE dispconf;
499 memset(&dispconf, 0, sizeof(dispconf));
500 dispconf.nSize = sizeof(dispconf);
501 dispconf.nVersion.nVersion = OMX_VERSION;
502 dispconf.nPortIndex = omx_rend_input_port;
504 dispconf.set = OMX_DISPLAY_SET_LAYER;
505 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
507 if (error != OMX_ErrorNone) {
508 Log::getInstance()->log("Video", Log::DEBUG,
509 "Set OMX_IndexConfigDisplayRegion1 failed %x", error);
510 clock_mutex.Unlock();
513 dispconf.set = OMX_DISPLAY_SET_FULLSCREEN;
514 if (mode != QUARTER && mode != EIGHTH) {
516 dispconf.fullscreen = OMX_TRUE;
518 dispconf.fullscreen = OMX_FALSE;
520 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
522 if (error != OMX_ErrorNone) {
523 Log::getInstance()->log("Video", Log::DEBUG,
524 "Set OMX_IndexConfigDisplayRegion2 failed %x", error);
525 clock_mutex.Unlock();
529 dispconf.set = OMX_DISPLAY_SET_MODE;
530 if (mode != QUARTER && mode != EIGHTH) {
531 dispconf.mode = (mode == NORMAL) ? OMX_DISPLAY_MODE_FILL
532 : OMX_DISPLAY_MODE_LETTERBOX;
534 dispconf.mode = OMX_DISPLAY_MODE_LETTERBOX;
536 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
538 if (error != OMX_ErrorNone) {
539 Log::getInstance()->log("Video", Log::DEBUG,
540 "Set OMX_IndexConfigDisplayRegion3 failed %x", error);
541 clock_mutex.Unlock();
545 if (mode == QUARTER || mode == EIGHTH) {
546 unsigned int display_width, display_height;
547 display_width = display_height = 0;
548 if (graphics_get_display_size(0, &display_width, &display_height)
550 Log::getInstance()->log("OSD", Log::WARN,
551 "Getting display size failed! (BCM API) ");
552 clock_mutex.Unlock();
555 //UnSetFullscreen with window
556 dispconf.set = OMX_DISPLAY_SET_DEST_RECT;
557 dispconf.dest_rect.x_offset
558 = (int) (xpos * ((float) display_width));
559 dispconf.dest_rect.y_offset = (int) (ypos
560 * ((float) display_height));
561 if (mode == QUARTER) {
562 dispconf.dest_rect.width = display_width >> 1;
563 dispconf.dest_rect.height = display_height >> 1;
564 } else if (mode == EIGHTH) {
565 dispconf.dest_rect.width = display_width >> 2;
566 dispconf.dest_rect.height = display_height >> 2;
568 error = OMX_SetParameter(omx_vid_rend,
569 OMX_IndexConfigDisplayRegion, &dispconf);
570 if (error != OMX_ErrorNone) {
571 Log::getInstance()->log("Video", Log::DEBUG,
572 "Set OMX_IndexConfigDisplayRegion failed %x", error);
573 clock_mutex.Unlock();
579 clock_mutex.Unlock();
582 int VideoOMX::signalOff()
585 Log::getInstance()->log("Video", Log::NOTICE, "signalOff");
587 Osd::getInstance()->stopUpdate(); // turn off drawing thread
592 int VideoOMX::signalOn()
595 Log::getInstance()->log("Video", Log::NOTICE, "signalOn");
596 Osd::getInstance()->shutdown();
598 Osd::getInstance()->restore();
599 Osd::getInstance()->init((void*)"");
600 BoxStack::getInstance()->redrawAllBoxes();
607 int VideoOMX::setSource()
609 if (!initted) return 0;
611 // What does this do...
612 // if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
616 int VideoOMX::setPosition(int x, int y) {
619 xpos = ((float) x*2.f) / ((float) screenWidth);
620 ypos = ((float) y*2.f) / ((float) screenHeight);
628 if (!initted) return 0;
630 // if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
634 void VideoOMX::interlaceSwitch4Demux() {
636 Demuxer *demux=Demuxer::getInstance();
637 if ( (outputinterlaced && !demux->getInterlaced())
638 || (!outputinterlaced && demux->getInterlaced())) {
639 if (hdmi && (demux->getHorizontalSize()>720 || demux->getInterlaced() )) { // only switch if hdmi and HD or interlaced SD material
640 Log::getInstance()->log("Video", Log::NOTICE, "switch interlacing %d",demux->getInterlaced());
641 Osd::getInstance()->shutdown();
642 selectVideoMode(demux->getInterlaced());
643 Osd::getInstance()->restore();
644 Osd::getInstance()->init((void*)"");
645 BoxStack::getInstance()->redrawAllBoxes();
654 int VideoOMX::play() {
658 Log::getInstance()->log("Video", Log::DEBUG, "enter play");
660 interlaceSwitch4Demux();
662 if (AllocateCodecsOMX()) {
664 // Otherwise fall back to libav
668 Log::getInstance()->log("Video", Log::NOTICE,
669 "Allocate Codecs OMX failed assume h264 unsupported");
672 Log::getInstance()->log("Video", Log::NOTICE,
673 "Allocate Codecs OMX failed assume mpeg2 unsupported");
682 int VideoOMX::initClock()
686 if (clock_references==0)
689 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
692 error=OMX_GetHandle(&omx_clock,VPE_OMX_CLOCK,NULL,&callbacks);
694 if (error!=OMX_ErrorNone) {
695 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX clock failed %x", error);
696 clock_mutex.Unlock();
697 DeAllocateCodecsOMX();
701 /* TODO Clock config to separate method */
702 OMX_PORT_PARAM_TYPE p_param;
703 memset(&p_param,0,sizeof(p_param));
704 p_param.nSize=sizeof(p_param);
705 p_param.nVersion.nVersion=OMX_VERSION;
706 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
707 if (error!=OMX_ErrorNone) {
708 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
709 clock_mutex.Unlock();
710 DeAllocateCodecsOMX();
713 omx_clock_output_port=p_param.nStartPortNumber;
715 for (unsigned int i=0;i<p_param.nPorts;i++) {
716 if (!DisablePort(omx_clock,p_param.nStartPortNumber+i,true) ) {
717 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX clock failed %d",i);
718 clock_mutex.Unlock();
719 DeAllocateCodecsOMX();
728 Log::getInstance()->log("Video", Log::DEBUG, "init omx clock %x %x",this,omx_clock);
730 clock_mutex.Unlock();
734 int VideoOMX::getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port)
738 *p_omx_clock_output_port=0;
745 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
746 memset(&refclock,0,sizeof(refclock));
747 refclock.nSize=sizeof(refclock);
748 refclock.nVersion.nVersion=OMX_VERSION;
750 refclock.eClock=OMX_TIME_RefClockAudio;
752 //refclock.eClock=OMX_TIME_RefClockVideo;
753 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
754 if (error!=OMX_ErrorNone){
755 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
756 clock_mutex.Unlock();
757 DeAllocateCodecsOMX();
761 OMX_PORT_PARAM_TYPE p_param;
762 memset(&p_param,0,sizeof(p_param));
763 p_param.nSize=sizeof(p_param);
764 p_param.nVersion.nVersion=OMX_VERSION;
765 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
766 if (error!=OMX_ErrorNone){
767 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
768 clock_mutex.Unlock();
769 DeAllocateCodecsOMX();
773 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
774 memset(&clock_conf,0,sizeof(clock_conf));
775 clock_conf.nSize=sizeof(clock_conf);
776 clock_conf.nVersion.nVersion=OMX_VERSION;
777 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
778 clock_conf.nStartTime=intToOMXTicks(0);
779 clock_conf.nOffset=intToOMXTicks(0);
780 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT1;
781 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
782 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
783 if (error!=OMX_ErrorNone) {
784 Log::getInstance()->log("Video", Log::DEBUG, "AuI Clock IndexConfigTimeClockState failed %x", error);
788 *p_omx_clock_output_port=p_param.nStartPortNumber+1;
789 *p_omx_clock=omx_clock;
790 clock_mutex.Unlock();
794 int VideoOMX::getClockVideoandInit()
803 if (clock_references==1) { // only if no audio is attached to this clock!
804 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
805 memset(&refclock,0,sizeof(refclock));
806 refclock.nSize=sizeof(refclock);
807 refclock.nVersion.nVersion=OMX_VERSION;
809 //refclock.eClock=OMX_TIME_RefClockAudio;
811 refclock.eClock=OMX_TIME_RefClockVideo;
812 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
813 if (error!=OMX_ErrorNone) {
814 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
815 clock_mutex.Unlock();
816 DeAllocateCodecsOMX();
821 OMX_PORT_PARAM_TYPE p_param;
822 memset(&p_param,0,sizeof(p_param));
823 p_param.nSize=sizeof(p_param);
824 p_param.nVersion.nVersion=OMX_VERSION;
825 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
826 if (error!=OMX_ErrorNone){
827 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
828 clock_mutex.Unlock();
829 DeAllocateCodecsOMX();
834 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
835 memset(&clock_conf,0,sizeof(clock_conf));
836 clock_conf.nSize=sizeof(clock_conf);
837 clock_conf.nVersion.nVersion=OMX_VERSION;
838 clock_conf.eState=OMX_TIME_ClockStateStopped;
839 clock_conf.nStartTime=intToOMXTicks(0);
840 clock_conf.nOffset=intToOMXTicks(0);
841 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
842 if (error!=OMX_ErrorNone) {
843 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
847 memset(&clock_conf,0,sizeof(clock_conf));
848 clock_conf.nSize=sizeof(clock_conf);
849 clock_conf.nVersion.nVersion=OMX_VERSION;
850 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
851 clock_conf.nStartTime=intToOMXTicks(0);
852 clock_conf.nOffset=intToOMXTicks(0);
853 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT0;
854 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
855 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
856 if (error!=OMX_ErrorNone) {
857 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
860 omx_clock_output_port=p_param.nStartPortNumber;
861 clock_mutex.Unlock();
866 void VideoOMX::clockUnpause()
870 if (clock_references>0) {
871 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
872 memset(&clock_conf,0,sizeof(clock_conf));
873 clock_conf.nSize=sizeof(clock_conf);
874 clock_conf.nVersion.nVersion=OMX_VERSION;
875 clock_conf.eState=OMX_TIME_ClockStateRunning;
876 clock_conf.nStartTime=intToOMXTicks(0);
877 clock_conf.nOffset=intToOMXTicks(0);
878 clock_conf.nWaitMask=OMX_CLOCKPORT1;
879 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
880 if (error!=OMX_ErrorNone) {
881 Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause IndexConfigTimeClockState failed %x", error);
884 clock_mutex.Unlock();
888 void VideoOMX::clockPause()
892 if (clock_references>0) {
893 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
894 memset(&clock_conf,0,sizeof(clock_conf));
895 clock_conf.nSize=sizeof(clock_conf);
896 clock_conf.nVersion.nVersion=OMX_VERSION;
897 clock_conf.eState=OMX_TIME_ClockStateStopped;
898 clock_conf.nStartTime=intToOMXTicks(0);
899 clock_conf.nOffset=intToOMXTicks(0);
900 clock_conf.nWaitMask=OMX_CLOCKPORT1;
901 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
902 if (error!=OMX_ErrorNone) {
903 Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause IndexConfigTimeClockState failed %x", error);
906 clock_mutex.Unlock();
911 int VideoOMX::AllocateCodecsOMX()
914 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
916 Demuxer* demux=Demuxer::getInstance();
919 deint_first_frame=false;
921 Log::getInstance()->log("Video", Log::NOTICE, "Allocate Codecs OMX");
922 //Clock, move later to audio including events
924 Log::getInstance()->log("Video", Log::NOTICE, "VideoType %d x %d i: %d", demux->getHorizontalSize(),demux->getVerticalSize(),demux->getInterlaced());
925 if (deinterlace!=0 && (demux->getHorizontalSize()<=720 ) && demux->getInterlaced()) { //only deinterlace SD material
927 deint_first_frame=true;
929 Log::getInstance()->log("Video", Log::NOTICE, "Deinterlacing activated %d",deinterlace);
934 if (!getClockVideoandInit()){
935 return 0;// get the clock and init it if necessary
940 Log::getInstance()->log("Video", Log::DEBUG, "idleClock failed");
947 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_H264_DECODER,NULL,&callbacks);
949 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_MPEG2_DECODER,NULL,&callbacks);
952 if (error!=OMX_ErrorNone){
953 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video decoder failed %x", error);
954 clock_mutex.Unlock();
955 DeAllocateCodecsOMX();
960 Log::getInstance()->log("Video", Log::DEBUG, "Nmark3 ");
961 OMX_PORT_PARAM_TYPE p_param;
962 memset(&p_param,0,sizeof(p_param));
963 p_param.nSize=sizeof(p_param);
964 p_param.nVersion.nVersion=OMX_VERSION;
965 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamVideoInit,&p_param);
966 if (error!=OMX_ErrorNone){
967 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX h264 decoder OMX_GetParameter failed %x", error);
968 clock_mutex.Unlock();
969 DeAllocateCodecsOMX();
972 omx_codec_input_port=p_param.nStartPortNumber;
973 omx_codec_output_port=p_param.nStartPortNumber+1;
975 if (!DisablePort(omx_vid_dec,omx_codec_input_port) || !DisablePort(omx_vid_dec,omx_codec_output_port)) {
976 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video decoder failed");
977 clock_mutex.Unlock();
978 DeAllocateCodecsOMX();
982 Log::getInstance()->log("Video", Log::DEBUG, "Nmark4 ");
984 OMX_PARAM_BRCMVIDEODECODEERRORCONCEALMENTTYPE conceal;
985 memset(&conceal,0,sizeof(conceal));
986 conceal.nSize=sizeof(conceal);
987 conceal.nVersion.nVersion=OMX_VERSION;
988 conceal.bStartWithValidFrame=OMX_FALSE;
990 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamBrcmVideoDecodeErrorConcealment,&conceal);
991 if (error!=OMX_ErrorNone){
992 Log::getInstance()->log("Video", Log::DEBUG, "OMX_IndexParamBrcmVideoDecodeErrorConcealment failed %x", error);
993 clock_mutex.Unlock();
994 DeAllocateCodecsOMX();
999 error = OMX_GetHandle(&omx_vid_deint, VPE_OMX_VIDEO_DEINTERLACE, NULL,
1001 if (error != OMX_ErrorNone) {
1002 Log::getInstance()->log("Video", Log::DEBUG,
1003 "Init OMX video deinterlacer failed %x", error);
1004 clock_mutex.Unlock();
1005 DeAllocateCodecsOMX();
1009 error = OMX_GetParameter(omx_vid_deint, OMX_IndexParamImageInit,
1011 if (error != OMX_ErrorNone) {
1012 Log::getInstance()->log("Video", Log::DEBUG,
1013 "Init OMX video deinterlacer OMX_GetParameter failed %x",
1015 clock_mutex.Unlock();
1016 DeAllocateCodecsOMX();
1019 omx_deint_input_port = p_param.nStartPortNumber;
1020 omx_deint_output_port = p_param.nStartPortNumber + 1;
1022 if (!DisablePort(omx_vid_deint, omx_deint_input_port, true)
1023 || !DisablePort(omx_vid_deint, omx_deint_output_port, true)) {
1024 Log::getInstance()->log("Video", Log::DEBUG,
1025 "Disable Ports OMX video deint failed");
1026 clock_mutex.Unlock();
1027 DeAllocateCodecsOMX();
1034 error=OMX_GetHandle(&omx_vid_sched,VPE_OMX_VIDEO_SCHED,NULL,&callbacks);
1035 if (error!=OMX_ErrorNone){
1036 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler failed %x", error);
1037 clock_mutex.Unlock();
1038 DeAllocateCodecsOMX();
1044 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamVideoInit,&p_param);
1045 if (error!=OMX_ErrorNone){
1046 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1047 clock_mutex.Unlock();
1048 DeAllocateCodecsOMX();
1051 omx_shed_input_port=p_param.nStartPortNumber;
1052 omx_shed_output_port=p_param.nStartPortNumber+1;
1055 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamOtherInit,&p_param);
1056 if (error!=OMX_ErrorNone){
1057 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1058 clock_mutex.Unlock();
1059 DeAllocateCodecsOMX();
1062 omx_shed_clock_port=p_param.nStartPortNumber;
1063 Log::getInstance()->log("Video", Log::DEBUG, "scheduler ports %d %d %d ",omx_shed_input_port,omx_shed_output_port,omx_shed_clock_port);
1066 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true) || !DisablePort(omx_vid_sched,omx_shed_output_port,true)
1067 || !DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
1068 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video shed failed");
1069 clock_mutex.Unlock();
1070 DeAllocateCodecsOMX();
1075 error=OMX_GetHandle(&omx_vid_rend,VPE_OMX_VIDEO_REND,NULL,&callbacks);
1076 if (error!=OMX_ErrorNone){
1077 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend failed %x", error);
1078 clock_mutex.Unlock();
1079 DeAllocateCodecsOMX();
1083 error=OMX_GetParameter(omx_vid_rend,OMX_IndexParamVideoInit,&p_param);
1084 if (error!=OMX_ErrorNone){
1085 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend OMX_GetParameter failed %x", error);
1086 clock_mutex.Unlock();
1087 DeAllocateCodecsOMX();
1090 omx_rend_input_port=p_param.nStartPortNumber;
1091 //omx_rend_output_port=p_param.nStartPortNumber+1;
1094 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true) /*|| !DisablePort(omx_vid_rend,omx_rend_output_port)*/
1096 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video rend failed");
1097 clock_mutex.Unlock();
1098 DeAllocateCodecsOMX();
1106 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,omx_vid_sched,omx_shed_clock_port);
1107 if (error!=OMX_ErrorNone){
1108 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel clock to sched failed %x %d %d", error,omx_clock_output_port,omx_shed_clock_port);
1109 clock_mutex.Unlock();
1110 DeAllocateCodecsOMX();
1114 if (!EnablePort(omx_clock,omx_clock_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_clock_port,false)
1116 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX clock shed failed");
1117 clock_mutex.Unlock();
1118 DeAllocateCodecsOMX();
1123 Log::getInstance()->log("Video", Log::DEBUG, "mark2 ");
1124 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1125 Log::getInstance()->log("Video", Log::DEBUG, "vid_sched idle ChangeComponentState");
1126 clock_mutex.Unlock();
1127 DeAllocateCodecsOMX();
1133 Log::getInstance()->log("Video", Log::DEBUG, "mark1 ");
1134 if ( !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_clock_port)) {
1135 clock_mutex.Unlock();
1136 DeAllocateCodecsOMX();
1143 Log::getInstance()->log("Video", Log::DEBUG, "mark1 special ");
1144 if ( !CommandFinished(omx_clock,OMX_CommandPortEnable,omx_clock_output_port)) {
1145 clock_mutex.Unlock();
1146 DeAllocateCodecsOMX();
1152 Log::getInstance()->log("Video", Log::DEBUG, "mark1b ");
1155 /* error=OMX_SendCommand(omx_vid_dec,OMX_CommandStateSet,OMX_StateIdle,0);
1156 if (error!=OMX_ErrorNone){
1157 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec Send Command to OMX State Idle %x", error);
1161 OMX_VIDEO_PARAM_PORTFORMATTYPE ft_type;
1162 memset(&ft_type,0,sizeof(ft_type));
1163 ft_type.nSize=sizeof(ft_type);
1164 ft_type.nVersion.nVersion=OMX_VERSION;
1166 ft_type.nPortIndex=omx_codec_input_port;
1168 ft_type.eCompressionFormat=OMX_VIDEO_CodingAVC;
1170 ft_type.eCompressionFormat=OMX_VIDEO_CodingMPEG2;
1175 ft_type.xFramerate=0*(1<<16);//25*(1<<16);//demux->getFrameRate()*(1<<16);
1176 Log::getInstance()->log("Video", Log::DEBUG, "Framerate: %d",demux->getFrameRate());
1177 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamVideoPortFormat,&ft_type);
1178 if (error!=OMX_ErrorNone){
1179 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexParamVideoPortFormat failed %x", error);
1180 clock_mutex.Unlock();
1181 DeAllocateCodecsOMX();
1186 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1187 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1188 clock_mutex.Unlock();
1189 DeAllocateCodecsOMX();
1194 if (!PrepareInputBufsOMX()) {
1195 clock_mutex.Unlock();
1196 DeAllocateCodecsOMX();
1201 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_sched,omx_shed_input_port);
1202 if (error!=OMX_ErrorNone){
1203 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to sched failed %x", error);
1204 clock_mutex.Unlock();
1205 DeAllocateCodecsOMX();
1211 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1213 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec shed failed");
1214 clock_mutex.Unlock();
1215 DeAllocateCodecsOMX();
1219 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1220 clock_mutex.Unlock();
1221 DeAllocateCodecsOMX();
1227 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_deint,omx_deint_input_port);
1228 if (error!=OMX_ErrorNone){
1229 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to deint failed %x", error);
1230 clock_mutex.Unlock();
1231 DeAllocateCodecsOMX();
1237 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_deint,omx_deint_input_port,false)
1239 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec deint failed");
1240 clock_mutex.Unlock();
1241 DeAllocateCodecsOMX();
1245 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_input_port)) {
1246 clock_mutex.Unlock();
1247 DeAllocateCodecsOMX();
1251 if (!ChangeComponentState(omx_vid_deint,OMX_StateIdle)) {
1252 Log::getInstance()->log("Video", Log::DEBUG, "vid_deint ChangeComponentState");
1253 clock_mutex.Unlock();
1254 DeAllocateCodecsOMX();
1258 OMX_CONFIG_IMAGEFILTERPARAMSTYPE imagefilter;
1259 memset(&imagefilter,0,sizeof(imagefilter));
1260 imagefilter.nSize=sizeof(imagefilter);
1261 imagefilter.nVersion.nVersion=OMX_VERSION;
1263 imagefilter.nPortIndex=omx_deint_output_port;
1264 imagefilter.nNumParams=1;
1265 imagefilter.nParams[0]=3;//???
1266 switch (deinterlace) {
1268 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceLineDouble; break;
1270 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceAdvanced; break;
1272 imagefilter.eImageFilter=OMX_ImageFilterFilm; break;
1276 error=OMX_SetConfig(omx_vid_deint,OMX_IndexConfigCommonImageFilterParameters,&imagefilter);
1277 if (error!=OMX_ErrorNone){
1278 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigCommonImageFilterParameters failed %x", error);
1279 clock_mutex.Unlock();
1280 DeAllocateCodecsOMX();
1285 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,omx_vid_sched,omx_shed_input_port);
1286 if (error!=OMX_ErrorNone){
1287 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel deint to sched failed %x", error);
1288 clock_mutex.Unlock();
1289 DeAllocateCodecsOMX();
1293 if (!EnablePort(omx_vid_deint,omx_deint_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1295 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX deint shed failed");
1296 clock_mutex.Unlock();
1297 DeAllocateCodecsOMX();
1301 if ( !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1302 clock_mutex.Unlock();
1303 DeAllocateCodecsOMX();
1309 if (!ChangeComponentState(omx_vid_dec,OMX_StateExecuting)) {
1310 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_dec ChangeComponentState Execute");
1311 clock_mutex.Unlock();
1312 DeAllocateCodecsOMX();
1316 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,omx_vid_rend,omx_rend_input_port);
1317 if (error!=OMX_ErrorNone){
1318 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel sched to rend failed %x", error);
1319 clock_mutex.Unlock();
1320 DeAllocateCodecsOMX();
1324 if (!EnablePort(omx_vid_sched,omx_shed_output_port,false) || !EnablePort(omx_vid_rend,omx_rend_input_port,false)
1326 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX shed rend failed");
1327 clock_mutex.Unlock();
1328 DeAllocateCodecsOMX();
1332 if (!CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_output_port)
1333 || !CommandFinished(omx_vid_rend,OMX_CommandPortEnable,omx_rend_input_port)) {
1334 clock_mutex.Unlock();
1335 DeAllocateCodecsOMX();
1339 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1340 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1341 clock_mutex.Unlock();
1342 DeAllocateCodecsOMX();
1347 if (!ChangeComponentState(omx_vid_deint,OMX_StateExecuting)) {
1348 Log::getInstance()->log("Video", Log::DEBUG, "vid_vid_deint ChangeComponentState");
1349 clock_mutex.Unlock();
1350 DeAllocateCodecsOMX();
1353 DisablePort(omx_vid_deint,omx_deint_output_port,false);
1354 DisablePort(omx_vid_deint,omx_deint_input_port,false);
1357 if (!ChangeComponentState(omx_vid_sched,OMX_StateExecuting)) {
1358 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_sched ChangeComponentState Execute");
1359 clock_mutex.Unlock();
1360 DeAllocateCodecsOMX();
1364 if (!ChangeComponentState(omx_vid_rend,OMX_StateExecuting)) {
1365 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_rend ChangeComponentState Execute");
1366 clock_mutex.Unlock();
1367 DeAllocateCodecsOMX();
1372 /*OMX_CONFIG_DISPLAYREGIONTYPE dispconf;
1373 memset(&dispconf,0,sizeof(dispconf));
1374 dispconf.nSize=sizeof(dispconf);
1375 dispconf.nVersion.nVersion=OMX_VERSION;
1377 dispconf.nPortIndex=omx_rend_input_port;
1379 dispconf.set=OMX_DISPLAY_SET_LAYER ;
1381 error=OMX_SetConfig(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1382 if (error!=OMX_ErrorNone){
1383 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1384 clock_mutex.Unlock();
1385 DeAllocateCodecsOMX();
1389 /* dispconf.set=OMX_DISPLAY_SET_FULLSCREEN ;
1390 dispconf.fullscreen=OMX_FALSE;
1391 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1392 if (error!=OMX_ErrorNone){
1393 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1394 clock_mutex.Unlock();
1395 DeAllocateCodecsOMX();
1399 dispconf.set=OMX_DISPLAY_SET_DEST_RECT;
1400 dispconf.dest_rect.x_offset=100;
1401 dispconf.dest_rect.y_offset=100;
1402 dispconf.dest_rect.width=640;
1403 dispconf.dest_rect.height=480;
1404 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1405 if (error!=OMX_ErrorNone){
1406 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1407 clock_mutex.Unlock();
1408 DeAllocateCodecsOMX();
1413 //playbacktimeoffset=-GetCurrentSystemTime();
1417 clock_mutex.Unlock();
1420 setClockExecutingandRunning();
1429 int VideoOMX::idleClock()
1431 OMX_ERRORTYPE error;
1432 OMX_STATETYPE temp_state;
1434 OMX_GetState(omx_clock,&temp_state);
1436 if (temp_state!=OMX_StateIdle) {
1437 if (!ChangeComponentState(omx_clock,OMX_StateIdle)) {
1438 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Idle failed");
1439 clock_mutex.Unlock();
1443 clock_mutex.Unlock();
1447 int VideoOMX::setClockExecutingandRunning()
1449 OMX_ERRORTYPE error;
1450 OMX_STATETYPE temp_state;
1452 OMX_GetState(omx_clock,&temp_state);
1454 if (temp_state!=OMX_StateExecuting) {
1455 if (!ChangeComponentState(omx_clock,OMX_StateExecuting)) {
1456 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Execute failed");
1457 clock_mutex.Unlock();
1458 DeAllocateCodecsOMX();
1463 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
1464 memset(&clock_conf,0,sizeof(clock_conf));
1465 clock_conf.nSize=sizeof(clock_conf);
1466 clock_conf.nVersion.nVersion=OMX_VERSION;
1467 clock_conf.eState=OMX_TIME_ClockStateRunning;
1468 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
1469 if (error!=OMX_ErrorNone) {
1470 Log::getInstance()->log("Video", Log::DEBUG, "Clock IndexConfigTimeClockState failed %x", error);
1471 clock_mutex.Unlock();
1472 DeAllocateCodecsOMX();
1475 clock_mutex.Unlock();
1481 int VideoOMX::ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type) //needs to be called with locked mutex
1483 OMX_ERRORTYPE error;
1484 error=OMX_SendCommand(handle,OMX_CommandStateSet,type,0);
1485 if (error!=OMX_ErrorNone){
1486 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to OMX State %x %x",handle,type, error);
1490 if (!CommandFinished(handle,OMX_CommandStateSet,type)) {
1498 int VideoOMX::EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1500 OMX_ERRORTYPE error;
1501 error=OMX_SendCommand(handle,OMX_CommandPortEnable,port,0);
1502 if (error!=OMX_ErrorNone){
1503 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to enable port %x %x",handle,port, error);
1507 if (!wait) return 1;
1508 if (!CommandFinished(handle,OMX_CommandPortEnable,port)) {
1516 int VideoOMX::DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1518 OMX_ERRORTYPE error;
1519 error=OMX_SendCommand(handle,OMX_CommandPortDisable,port,0);
1520 if (error!=OMX_ErrorNone){
1521 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to disable port %x %x",handle,port, error);
1525 if (!wait) return 1;
1526 if (!CommandFinished(handle,OMX_CommandPortDisable,port)) {
1534 int VideoOMX::WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event) //needs to be called with locked mutex
1538 omx_event_mutex.Lock();
1539 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1540 while (itty!=omx_events.end()) {
1542 VPE_OMX_EVENT current=*itty;
1543 if (current.handle==handle) { //this is ours
1544 if (current.event_type==OMX_EventError) {
1545 omx_events.erase(itty);
1546 omx_event_mutex.Unlock();
1547 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished on Error");
1550 } else if (current.event_type==event) {
1551 omx_events.erase(itty);
1552 omx_event_mutex.Unlock();
1553 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished Completed");
1560 omx_event_mutex.Unlock();
1565 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent waited too long %x %x",handle,event);
1570 int VideoOMX::clearEvents()
1572 omx_event_mutex.Lock();
1574 omx_event_mutex.Unlock();
1580 int VideoOMX::CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2) //needs to be called with locked mutex
1584 omx_event_mutex.Lock();
1585 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1586 while (itty!=omx_events.end()) {
1588 VPE_OMX_EVENT current=*itty;
1589 if (current.handle==handle) { //this is ours
1590 if (current.event_type==OMX_EventError) {
1591 omx_events.erase(itty);
1592 omx_event_mutex.Unlock();
1593 Log::getInstance()->log("Video", Log::DEBUG, "Command Finished on Error %x",current.data1);
1596 } else if (current.event_type==OMX_EventCmdComplete && current.data1==command && current.data2==data2) {
1597 omx_events.erase(itty);
1598 omx_event_mutex.Unlock();
1599 //Log::getInstance()->log("Video", Log::DEBUG, "Command Finished Completed");
1606 omx_event_mutex.Unlock();
1611 Log::getInstance()->log("Video", Log::DEBUG, "CommandFinished waited too long %x %x %x",handle,command, data2);
1620 int VideoOMX::PrepareInputBufsOMX() //needs to be called with locked mutex
1622 OMX_ERRORTYPE error;
1623 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
1624 memset(&port_def_type,0,sizeof(port_def_type));
1625 port_def_type.nSize=sizeof(port_def_type);
1626 port_def_type.nVersion.nVersion=OMX_VERSION;
1627 port_def_type.nPortIndex=omx_codec_input_port;
1629 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1631 if (error!=OMX_ErrorNone){
1632 Log::getInstance()->log("Video", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
1634 /* Log::getInstance()->log("Video", Log::DEBUG, "Port para %d %d %d %d %d %d %d", port_def_type.nBufferCountActual,
1635 port_def_type.nBufferCountMin,port_def_type.nBufferSize,port_def_type.bEnabled,port_def_type.bPopulated,
1636 port_def_type.bBuffersContiguous,port_def_type.nBufferAlignment);*/
1638 port_def_type.nBufferCountActual=100;
1639 port_def_type.nBufferSize=max(port_def_type.nBufferSize,200000); // for transcoder important
1641 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1643 if (error!=OMX_ErrorNone){
1644 Log::getInstance()->log("Video", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
1648 error=OMX_SendCommand(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port,0);
1649 if (error!=OMX_ErrorNone){
1650 Log::getInstance()->log("Video", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
1654 input_bufs_omx_mutex.Lock();
1655 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
1657 // unsigned char* new_buffer_data=(unsigned char*)malloc(port_def_type.nbufferSize);
1658 OMX_BUFFERHEADERTYPE *buf_head=NULL;
1659 /* error=OMX_Usebuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nbufferSize,new_buffer_data);
1660 if (error!=OMX_ErrorNone){
1661 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_Usebuffer failed %x", error);
1662 input_bufs_omx_mutex.Unlock();
1665 error=OMX_AllocateBuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nBufferSize);
1666 if (error!=OMX_ErrorNone){
1667 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_AllocateBuffer failed %x", error);
1668 input_bufs_omx_mutex.Unlock();
1671 input_bufs_omx_all.push_back(buf_head);
1672 input_bufs_omx_free.push_back(buf_head);
1674 omx_first_frame=true;
1677 cur_input_buf_omx=NULL;
1678 input_bufs_omx_mutex.Unlock();
1681 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark3");
1682 if (!CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port)) {
1685 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark4");
1690 int VideoOMX::DestroyInputBufsOMX() //need s to be called with locked mutex
1692 OMX_ERRORTYPE error;
1694 cur_input_buf_omx=NULL;
1695 input_bufs_omx_mutex.Lock();
1696 for (int i=0; i< input_bufs_omx_all.size();i++) {
1697 // free(input_bufs_omx_all[i]->pBuffer);
1698 // input_bufs_omx_all[i]->pBuffer=NULL;
1699 error=OMX_FreeBuffer(omx_vid_dec,omx_codec_input_port,input_bufs_omx_all[i]);
1700 if (error!=OMX_ErrorNone){
1701 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
1702 input_bufs_omx_mutex.Unlock();
1707 input_bufs_omx_all.clear();
1708 input_bufs_omx_free.clear();
1709 input_bufs_omx_mutex.Unlock();
1714 int VideoOMX::FlushRenderingPipe()
1716 OMX_ERRORTYPE error;
1720 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1721 omx_codec_output_port, NULL);
1722 if (error != OMX_ErrorNone) {
1723 Log::getInstance()->log("Video", Log::DEBUG,
1724 "OMX_Flush codec out 1 failed %x", error);
1728 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1729 omx_shed_input_port, NULL);
1730 if (error != OMX_ErrorNone) {
1731 Log::getInstance()->log("Video", Log::DEBUG,
1732 "OMX_Flush shed in 2 failed %x", error);
1736 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1737 omx_codec_output_port)) {
1738 Log::getInstance()->log("Video", Log::DEBUG,
1739 "flush cmd codec 3 failed");
1742 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1743 omx_shed_input_port)) {
1744 Log::getInstance()->log("Video", Log::DEBUG,
1745 "flush cmd shed 4 failed");
1748 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1749 omx_codec_output_port, NULL);
1750 if (error != OMX_ErrorNone) {
1751 Log::getInstance()->log("Video", Log::DEBUG,
1752 "OMX_Flush codec out 5 failed %x", error);
1756 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1757 omx_deint_input_port, NULL);
1758 if (error != OMX_ErrorNone) {
1759 Log::getInstance()->log("Video", Log::DEBUG,
1760 "OMX_Flush deint in 6 failed %x", error);
1764 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1765 omx_codec_output_port)) {
1766 Log::getInstance()->log("Video", Log::DEBUG,
1767 "flush cmd codec 7 failed");
1770 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1771 omx_deint_input_port)) {
1772 Log::getInstance()->log("Video", Log::DEBUG,
1773 "flush cmd deint 8 failed");
1777 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1778 omx_deint_output_port, NULL);
1779 if (error != OMX_ErrorNone) {
1780 Log::getInstance()->log("Video", Log::DEBUG,
1781 "OMX_Flush deint out 9 failed %x", error);
1785 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1786 omx_shed_input_port, NULL);
1787 if (error != OMX_ErrorNone) {
1788 Log::getInstance()->log("Video", Log::DEBUG,
1789 "OMX_Flush shed in 10 failed %x", error);
1793 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1794 omx_deint_output_port)) {
1795 Log::getInstance()->log("Video", Log::DEBUG,
1796 "flush cmd deint 11 failed");
1799 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1800 omx_shed_input_port)) {
1801 Log::getInstance()->log("Video", Log::DEBUG,
1802 "flush cmd shed 12 failed");
1812 error = OMX_SendCommand(omx_vid_rend, OMX_CommandFlush,
1813 omx_rend_input_port, NULL);
1814 if (error != OMX_ErrorNone) {
1815 Log::getInstance()->log("Video", Log::DEBUG,
1816 "OMX_Flush rend in failed %x", error);
1820 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1821 omx_shed_output_port, NULL);
1822 if (error != OMX_ErrorNone) {
1823 Log::getInstance()->log("Video", Log::DEBUG,
1824 "OMX_Flush shed out failed %x", error);
1830 if (!CommandFinished(omx_vid_rend, OMX_CommandFlush,
1831 omx_rend_input_port)) {
1832 Log::getInstance()->log("Video", Log::DEBUG,
1833 "flush cmd shed rend failed");
1836 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1837 omx_shed_output_port)) {
1838 Log::getInstance()->log("Video", Log::DEBUG,
1839 "flush cmd shed rend failed");
1844 int VideoOMX::DeAllocateCodecsOMX()
1846 OMX_ERRORTYPE error;
1848 Log::getInstance()->log("Video", Log::DEBUG, "enter deallocatecodecsomx");
1850 if (cur_input_buf_omx) {
1851 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_EOS;
1852 OMX_ERRORTYPE error=ProtOMXEmptyThisBuffer(omx_vid_dec,cur_input_buf_omx);
1853 if (error!=OMX_ErrorNone) {
1854 Log::getInstance()->log("Video", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error);
1857 cur_input_buf_omx=NULL;//write out old data
1862 // first stop the omx elements
1863 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1864 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1867 clock_mutex.Unlock();
1873 if (!ChangeComponentState(omx_vid_deint, OMX_StateIdle)) {
1874 Log::getInstance()->log("Video", Log::DEBUG,
1875 "vid_deint ChangeComponentState");
1881 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1882 Log::getInstance()->log("Video", Log::DEBUG, "vid_shed ChangeComponentState");
1886 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1887 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1893 // TODO proper deinit sequence
1894 // first flush all buffers
1895 FlushRenderingPipe();
1901 error=OMX_SendCommand(omx_clock,OMX_CommandFlush, omx_clock_output_port, NULL);
1902 if (error!=OMX_ErrorNone){
1903 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush clock out failed %x", error);
1907 error=OMX_SendCommand(omx_vid_sched,OMX_CommandFlush, omx_shed_clock_port, NULL);
1908 if (error!=OMX_ErrorNone){
1909 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush shed clock failed %x", error);
1913 if (!CommandFinished(omx_clock,OMX_CommandFlush,omx_clock_output_port) ||
1914 !CommandFinished(omx_vid_sched,OMX_CommandFlush,omx_shed_clock_port)) {
1915 Log::getInstance()->log("Video", Log::DEBUG, "flush cmd clock shed failed");
1921 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1922 omx_codec_input_port, NULL);
1923 if (error != OMX_ErrorNone) {
1924 Log::getInstance()->log("Video", Log::DEBUG,
1925 "OMX_Flush codec out failed %x", error);
1932 DestroyInputBufsOMX();
1935 if (!DisablePort(omx_vid_sched,omx_shed_output_port,true)) {
1936 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 2 ");
1938 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true)) {
1939 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 1");
1945 if (!DisablePort(omx_vid_dec,omx_codec_output_port,true)) {
1946 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6");
1951 if (!DisablePort(omx_vid_dec,omx_codec_input_port,true)) {
1952 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7");
1956 if (!DisablePort(omx_vid_deint,omx_deint_output_port,true)) {
1957 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6a");
1962 if (!DisablePort(omx_vid_deint,omx_deint_input_port,true)) {
1963 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7a");
1969 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true)) {
1970 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 3");
1973 if (!DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
1974 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 4");
1977 if (!DisablePort(omx_clock,omx_clock_output_port,true)) {
1978 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 5");
1984 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,NULL,NULL);
1985 if (error!=OMX_ErrorNone) {
1986 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
1991 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_input_port,NULL,NULL);
1992 if (error!=OMX_ErrorNone) {
1993 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
1997 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,NULL,NULL);
1998 if (error!=OMX_ErrorNone) {
1999 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2003 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_input_port,NULL,NULL);
2004 if (error!=OMX_ErrorNone) {
2005 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2010 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,NULL,NULL);
2011 if (error!=OMX_ErrorNone) {
2012 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2016 error=OMX_SetupTunnel(omx_vid_rend,omx_rend_input_port,NULL,NULL);
2017 if (error!=OMX_ErrorNone) {
2018 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2023 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,NULL,NULL);
2024 if (error!=OMX_ErrorNone) {
2025 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2029 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_clock_port,NULL,NULL);
2030 if (error!=OMX_ErrorNone) {
2031 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2038 error=OMX_FreeHandle(omx_vid_dec);
2039 error=OMX_FreeHandle(omx_vid_sched);
2040 error=OMX_FreeHandle(omx_vid_rend);
2041 if (dodeint) error=OMX_FreeHandle(omx_vid_deint);
2043 clock_mutex.Unlock();
2045 if (error!=OMX_ErrorNone) {
2046 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2048 } else clock_mutex.Unlock();
2049 Log::getInstance()->log("Video", Log::DEBUG, "leave deallocate codecs OMX");
2055 void VideoOMX::destroyClock()
2058 if (clock_references>0) {
2060 if (clock_references==0) {
2061 OMX_ERRORTYPE error;
2062 Log::getInstance()->log("Video", Log::DEBUG, "destroy omx clock");
2063 error=OMX_FreeHandle(omx_clock);
2064 if (error!=OMX_ErrorNone) {
2065 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2070 clock_mutex.Unlock();
2074 int VideoOMX::stop()
2076 if (!initted) return 0;
2079 //Check if libav mode
2080 DeAllocateCodecsOMX();
2085 // if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
2089 int VideoOMX::reset()
2091 if (!initted) return 0;
2094 DeAllocateCodecsOMX();
2095 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
2099 int VideoOMX::pause()
2101 if (!initted) return 0;
2102 Log::getInstance()->log("Video", Log::DEBUG, "enter pause");
2105 //maybe also change omx clock?
2106 //pausetimecode=GetCurrentSystemTime();
2112 int VideoOMX::unPause() // FIXME get rid - same as play!! Not here!
2114 if (!initted) return 0;
2115 Log::getInstance()->log("Video", Log::DEBUG, "enter unpause");
2118 // playbacktimeoffset+=GetCurrentSystemTime()-pausetimecode;
2119 paused=false; // may be also change omx clock
2125 int VideoOMX::fastForward()
2127 if (!initted) return 0;
2129 // if (ioctl(fdVideo, AV_SET_VID_libavWD, 1) != 0) return 0;
2133 int VideoOMX::unFastForward()
2135 if (!initted) return 0;
2137 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
2139 //// if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
2143 int VideoOMX::attachFrameBuffer()
2145 if (!initted) return 0;
2147 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2151 int VideoOMX::blank(void)
2153 // if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
2154 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2158 ULLONG VideoOMX::getCurrentTimestamp() {
2161 long long ncur_clock_time = cur_clock_time;
2165 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2166 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2168 OMX_ERRORTYPE error;
2169 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
2170 memset(&clock_conf, 0, sizeof(clock_conf));
2171 clock_conf.nSize = sizeof(clock_conf);
2172 clock_conf.nVersion.nVersion = OMX_VERSION;
2173 error= OMX_GetConfig(omx_clock, OMX_IndexConfigTimeClockState,
2175 if (error != OMX_ErrorNone) {
2176 Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp IndexConfigTimeClockState failed %x",error);
2179 if (clock_conf.eState == OMX_TIME_ClockStateRunning) {
2181 OMX_TIME_CONFIG_TIMESTAMPTYPE cur_time_stamp;
2182 memset(&cur_time_stamp, 0, sizeof(cur_time_stamp));
2183 cur_time_stamp.nSize = sizeof(cur_time_stamp);
2184 cur_time_stamp.nVersion.nVersion = OMX_VERSION;
2185 cur_time_stamp.nPortIndex = omx_clock_output_port;
2186 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2188 if (error != OMX_ErrorNone) {
2189 Log::getInstance()->log("Video",Log::DEBUG,"getCurrentTimestamp OMX_IndexConfigTimeCurrentMediaTime failed %x",error);
2191 long long temp = cur_time_stamp.nTimestamp.nLowPart
2192 | ((long long) cur_time_stamp.nTimestamp.nHighPart << 32);
2193 ncur_clock_time = cur_clock_time = temp * 10LL;
2196 clock_mutex.Unlock();
2197 pthread_setcancelstate(oldcancelstate, NULL);
2198 pthread_setcanceltype(oldcanceltype, NULL);
2201 //ncur_clock_time -= startoffset;
2202 ncur_clock_time -= lastreftimeOMX;
2203 long long result = lastreftimePTS;
2204 if (lastreftimePTS==0) return 0; // invalid time
2205 result += (long long) (ncur_clock_time / 10000LL * 90LL);
2207 result = (1LL << 33) - result;
2208 //Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp %lld %lld %lld %lld %lld %lld",ncur_clock_time,cur_clock_time,lastreftimeOMX,lastreftimePTS,result,startoffset);
2216 ULONG VideoOMX::timecodeToFrameNumber(ULLONG timecode)
2218 if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25);
2219 else return (ULONG)(((double)timecode / (double)90000) * (double)30);
2224 int VideoOMX::test()
2229 // return ioctl(fdVideo, AV_SET_VID_STC, &stc);
2236 int VideoOMX::test2()
2244 long long VideoOMX::SetStartOffset(long long curreftime, bool *rsync)
2248 startoffset=curreftime;//offset is set for audio
2250 offsetvideonotset=false;
2252 if (offsetvideonotset) {
2253 offsetvideonotset=false;
2256 if ( (curreftime-lastrefvideotime)>10000000LL
2257 || (curreftime-lastrefvideotime)<-10000000LL) {//if pts jumps to big resync
2258 startoffset+=curreftime-lastrefvideotime;
2259 lastrefaudiotime+=curreftime-lastrefvideotime;
2261 offsetaudionotset=true;
2268 lastrefvideotime=curreftime;
2274 long long VideoOMX::SetStartAudioOffset(long long curreftime, bool *rsync)
2278 startoffset=curreftime;
2280 offsetaudionotset=false;
2282 if (offsetaudionotset) {
2283 offsetaudionotset=false;
2286 if ( (curreftime-lastrefaudiotime)>10000000LL
2287 || (curreftime-lastrefaudiotime)<-10000000LL) {//if pts jumps to big resync
2288 startoffset+=curreftime-lastrefaudiotime;
2289 lastrefvideotime+=curreftime-lastrefaudiotime;
2291 offsetvideonotset=true;
2297 lastrefaudiotime=curreftime;
2302 void VideoOMX::ResetTimeOffsets() {
2303 offsetnotset=true; //called from demuxer
2304 offsetvideonotset=true;
2305 offsetaudionotset=true;
2314 void VideoOMX::DeinterlaceFix()
2318 Demuxer* demux=Demuxer::getInstance();
2319 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2320 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2322 OMX_ERRORTYPE error;
2323 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
2324 memset(&port_def_type,0,sizeof(port_def_type));
2325 port_def_type.nSize=sizeof(port_def_type);
2326 port_def_type.nVersion.nVersion=OMX_VERSION;
2327 port_def_type.nPortIndex=omx_codec_output_port;
2329 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
2330 if (error != OMX_ErrorNone) {
2331 Log::getInstance()->log("Video", Log::DEBUG,
2332 "OMX_IndexParamPortDefinition fix failed %x", error);
2333 clock_mutex.Unlock();
2337 if (port_def_type.format.video.nFrameWidth == demux->getHorizontalSize()
2338 && port_def_type.format.video.nFrameHeight == demux->getVerticalSize()){
2339 Log::getInstance()->log("Video", Log::DEBUG,
2340 "Deinit first frame fix");
2341 deint_first_frame=false;
2343 WaitForEvent(omx_vid_dec,OMX_EventPortSettingsChanged);
2344 DisablePort(omx_vid_dec,omx_codec_output_port,false);
2345 DisablePort(omx_vid_sched,omx_shed_input_port,false);
2346 DisablePort(omx_vid_deint,omx_deint_output_port,false);
2347 DisablePort(omx_vid_deint,omx_deint_input_port,false);
2349 port_def_type.nPortIndex=omx_deint_input_port;
2350 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2352 if (error != OMX_ErrorNone) {
2353 Log::getInstance()->log("Video", Log::DEBUG,
2354 "Set OMX_IndexParamPortDefinition1 failed %x", error);
2355 clock_mutex.Unlock();
2356 pthread_setcancelstate(oldcancelstate, NULL);
2357 pthread_setcanceltype(oldcanceltype, NULL);
2361 port_def_type.nPortIndex=omx_deint_output_port;
2362 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2364 if (error != OMX_ErrorNone) {
2365 Log::getInstance()->log("Video", Log::DEBUG,
2366 "Set OMX_IndexParamPortDefinition2 failed %x", error);
2367 clock_mutex.Unlock();
2368 pthread_setcancelstate(oldcancelstate, NULL);
2369 pthread_setcanceltype(oldcanceltype, NULL);
2374 EnablePort(omx_vid_dec,omx_codec_output_port,false);
2375 EnablePort(omx_vid_deint,omx_deint_input_port,false);
2376 EnablePort(omx_vid_deint,omx_deint_output_port,false);
2377 EnablePort(omx_vid_sched,omx_shed_input_port,false);
2379 clock_mutex.Unlock();
2380 pthread_setcancelstate(oldcancelstate, NULL);
2381 pthread_setcanceltype(oldcanceltype, NULL);
2388 void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer)
2391 OMX_ERRORTYPE error = ProtOMXEmptyThisBuffer(omx_vid_dec, buffer);
2392 if (error != OMX_ErrorNone) {
2393 Log::getInstance()->log("Video", Log::DEBUG,
2394 "OMX_EmptyThisBuffer failed %x", error);
2396 if (deint_first_frame && dodeint) DeinterlaceFix();
2400 OMX_ERRORTYPE VideoOMX::ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer)
2402 // protect the call to empty this buffer
2405 /* long long temp =buffer->nTimeStamp.nLowPart
2406 | ((long long) buffer->nTimeStamp.nHighPart << 32);*/
2408 //pthread_testcancel();
2409 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2410 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2413 /* OMX_ERRORTYPE error;
2414 OMX_TIME_CONFIG_TIMESTAMPTYPE timestamp;
2415 memset(×tamp, 0, sizeof(timestamp));
2416 timestamp.nSize = sizeof(timestamp);
2417 timestamp.nVersion.nVersion = OMX_VERSION;
2418 timestamp.nPortIndex =omx_clock_output_port;
2420 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2423 if (error != OMX_ErrorNone) {
2424 Log::getInstance()->log("Audio", Log::DEBUG,
2425 "Init OMX_IndexConfigAudioRenderingLatencyfailed %x %d", error,
2426 omx_rend_input_port);
2428 long long temp2 =timestamp.nTimestamp.nLowPart
2429 | ((long long) timestamp.nTimestamp.nHighPart << 32);
2432 Log::getInstance()->log("Video", Log::NOTICE, "OMXETB %x %lld %lld %x",handle,temp,temp2,buffer->nFlags);*/
2433 OMX_ERRORTYPE ret_val;
2434 ret_val=OMX_EmptyThisBuffer(handle,buffer);
2435 clock_mutex.Unlock();
2436 pthread_setcancelstate(oldcancelstate, NULL);
2437 pthread_setcanceltype(oldcanceltype, NULL);
2438 //pthread_testcancel();
2442 bool VideoOMX::detectIFrame(const UCHAR *buffer,unsigned int length)
2444 const UCHAR* curbuf=buffer;
2445 const UCHAR* curbufend=buffer+length;
2446 unsigned int detector=0xFFFFFFFF;
2447 bool gotaud=false; // have seen access unit delimiter
2449 while (curbuf!=curbufend) {
2453 if (detector==0x00000109) {
2455 detector=0xFFFFFFFF;
2456 } else if (gotaud &&detector==0x00000001) {
2458 if (curbuf!=curbufend) {
2459 unsigned char picttype=(*curbuf)& 0x1F;
2460 return picttype==0x07;
2464 if (detector==0x00000100) {
2466 if (curbuf==curbufend) return false;
2468 if (curbuf==curbufend) return false;
2469 unsigned char picttype=((*curbuf) >> 3) & 0x07;
2476 return false; // no frame found
2479 void VideoOMX::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
2482 mediapackets.clear();
2483 list<MediaPacket>::const_iterator begin=mplist.begin();
2484 list<MediaPacket>::const_iterator itty=mplist.begin();
2485 advance(itty,min(mplist.size(),10));
2486 mediapackets.insert(mediapackets.begin(),begin,itty);//front
2490 UINT VideoOMX::DeliverMediaSample(UCHAR* buffer, UINT *samplepos)
2493 while (consumed<mediapackets.size()) {
2494 DeliverMediaPacket(mediapackets[consumed], buffer, samplepos);
2495 if (*samplepos == mediapackets[consumed].length) {
2499 } else return consumed;
2504 UINT VideoOMX::DeliverMediaPacket(MediaPacket packet,
2505 const UCHAR* buffer,
2508 if (packet.type == MPTYPE_VIDEO_H264)
2518 //Later add fail back code for libav
2520 *samplepos+=packet.length;
2521 return packet.length;
2525 if (!omx_running) return 0; // if we are not runnig do not do this
2526 if (paused) return 0; //Block if we pause
2528 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 1");
2529 //Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX time %lld",packet.presentation_time);
2532 OMX_ERRORTYPE error;
2534 /*First Check, if we have an video sample*/
2538 return 0; //Not in iframe mode!
2542 if (packet.disconti) {
2544 if (cur_input_buf_omx) {
2545 PutBufferToPres(cur_input_buf_omx);
2546 cur_input_buf_omx=NULL;
2549 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2");
2550 /*Inspect PES-Header */
2552 // OMX_STATETYPE temp_state;
2553 // OMX_GetState(omx_vid_dec,&temp_state);
2555 if (*samplepos==0) {//stripheader
2556 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
2557 // if (h264) Log::getInstance()->log("Video", Log::DEBUG, "PES info %x %x %x %x",
2558 // buffer[packet.pos_buffer+0],buffer[packet.pos_buffer+1],buffer[packet.pos_buffer+2],buffer[packet.pos_buffer+3]);
2559 *samplepos+=headerstrip;
2560 if ( packet.synched ) {
2561 if (!firstsynched) {
2562 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2a");
2563 // check if this is an I frame, the decoder does not like non I frames at startup!
2564 if (!detectIFrame(buffer,packet.length)) {
2565 *samplepos=packet.length;//if we have not processed at least one
2566 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 3");
2567 return packet.length;//synched packet ignore it!
2570 if (cur_input_buf_omx) {
2571 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4a");
2572 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_ENDOFFRAME;
2573 PutBufferToPres(cur_input_buf_omx);
2574 cur_input_buf_omx=NULL;//write out old data
2576 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4b");
2581 if (!firstsynched) {//
2582 *samplepos=packet.length;//if we have not processed at least one
2583 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 5");
2584 return packet.length;//synched packet ignore it!
2588 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 6");
2589 if (!cur_input_buf_omx) {
2590 input_bufs_omx_mutex.Lock();
2591 if (input_bufs_omx_free.size()==0) {
2592 input_bufs_omx_mutex.Unlock();
2593 //Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample");
2594 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 7");
2595 return 0; // we do not have a free media sample
2598 cur_input_buf_omx=input_bufs_omx_free.front();
2599 cur_input_buf_omx->nFilledLen=0;
2600 cur_input_buf_omx->nOffset=0;
2601 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2602 input_bufs_omx_free.pop_front();
2603 input_bufs_omx_mutex.Unlock();
2609 if (cur_input_buf_omx->nFilledLen==0) {//will only be changed on first packet
2610 if (packet.synched) {
2611 // Log::getInstance()->log("Video", Log::DEBUG, "packet synched marker");
2613 //lastreftimePTS=packet.pts;
2614 if (omx_first_frame) { // TODO time
2615 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_STARTTIME;
2616 Log::getInstance()->log("Video", Log::DEBUG, "Starttime");
2617 omx_first_frame=false;
2619 cur_input_buf_omx->nFlags=0;
2620 //cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_TIME_UNKNOWN;
2622 lastreftimeOMX=packet.presentation_time;
2623 // Log::getInstance()->log("Video", Log::DEBUG, "Time code %lld pts %lld", lastreftimeOMX,packet.pts);
2624 lastreftimePTS=packet.pts;
2625 cur_input_buf_omx->nTimeStamp=intToOMXTicks(lastreftimeOMX/10LL); // the clock component is faulty;
2629 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2630 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2631 //Log::getInstance()->log("Video", Log::DEBUG, "packet unsynched marker");
2633 if (packet.disconti) cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_DISCONTINUITY;
2638 unsigned int haveToCopy=packet.length-*samplepos;
2639 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 8");
2641 while (haveToCopy> (cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen)) {
2642 //Log::getInstance()->log("Video", Log::DEBUG, "Big buffer %d %d %d",packet.length,cur_input_buf_omx->nAllocLen,cur_input_buf_omx->nFilledLen);
2643 unsigned int cancopy=cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen;
2644 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,buffer+packet.pos_buffer+*samplepos,cancopy);
2645 haveToCopy-=cancopy;
2646 cur_input_buf_omx->nFilledLen+=cancopy;
2647 *samplepos+=cancopy;
2648 // push old buffer out
2649 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 9");
2651 PutBufferToPres(cur_input_buf_omx);
2652 cur_input_buf_omx=NULL;
2654 input_bufs_omx_mutex.Lock();
2655 if (input_bufs_omx_free.size()==0) {
2656 input_bufs_omx_mutex.Unlock();
2657 // Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample2");
2658 return *samplepos; // we do not have a free media sample
2660 cur_input_buf_omx=input_bufs_omx_free.front();
2661 cur_input_buf_omx->nFilledLen=0;
2662 cur_input_buf_omx->nOffset=0;
2663 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2664 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2665 input_bufs_omx_free.pop_front();
2666 input_bufs_omx_mutex.Unlock();
2667 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 10");
2670 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,
2671 buffer+packet.pos_buffer+*samplepos,haveToCopy);
2672 cur_input_buf_omx->nFilledLen+=haveToCopy;
2674 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 11");
2676 *samplepos+=haveToCopy;
2685 bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) {
2686 if (!omx_running) return false;
2688 EnterIframePlayback();
2690 int haveToCopy = length;
2692 if (!cur_input_buf_omx) {
2693 input_bufs_omx_mutex.Lock();
2694 if (input_bufs_omx_free.size() == 0) {
2695 input_bufs_omx_mutex.Unlock();
2696 // Log::getInstance()->log("Video", Log::DEBUG,
2697 // "Deliver MediaPacket no free sample");
2698 return false; // we do not have a free media sample
2701 cur_input_buf_omx = input_bufs_omx_free.front();
2702 cur_input_buf_omx->nFilledLen = 0;
2703 cur_input_buf_omx->nOffset = 0;
2704 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2705 input_bufs_omx_free.pop_front();
2706 input_bufs_omx_mutex.Unlock();
2710 unsigned int pattern, packet_length;
2711 unsigned int headerstrip = 0;
2716 //Now we strip the pes header
2717 pattern = (buffer[0] << 16) | (buffer[1] << 8) | (buffer[2]);
2718 while (read_pos + 7 <= length) {
2719 pattern = ((pattern << 8) & 0xFFFFFFFF) | buffer[read_pos + 3];
2720 if (pattern < 0x000001E0 || pattern > 0x000001EF) {
2724 headerstrip = buffer[read_pos + 8] + 9/*is this right*/;
2725 packet_length = ((buffer[read_pos + 4] << 8)
2726 | (buffer[read_pos + 5])) + 6;
2727 if (read_pos + packet_length > length)
2730 if ((headerstrip < packet_length)
2731 && (cur_input_buf_omx->nFilledLen + packet_length
2732 - headerstrip) > cur_input_buf_omx->nAllocLen) {
2734 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2737 cur_input_buf_omx->nFlags
2738 |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2741 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2742 PutBufferToPres(cur_input_buf_omx);
2743 cur_input_buf_omx = NULL;
2745 if (!cur_input_buf_omx) {
2747 while (count < 100 && omx_running && iframemode) {
2750 input_bufs_omx_mutex.Lock();
2751 if (input_bufs_omx_free.size() == 0) {
2752 input_bufs_omx_mutex.Unlock();
2753 // Log::getInstance()->log("Video", Log::DEBUG,
2754 // "Ifrane no free sample");
2756 if (!omx_running) return false;
2759 cur_input_buf_omx = input_bufs_omx_free.front();
2760 cur_input_buf_omx->nFilledLen = 0;
2761 cur_input_buf_omx->nOffset = 0;
2762 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2763 cur_input_buf_omx->nFlags|= OMX_BUFFERFLAG_TIME_UNKNOWN;
2764 input_bufs_omx_free.pop_front();
2765 input_bufs_omx_mutex.Unlock();
2768 if (!cur_input_buf_omx)
2773 if (packet_length > headerstrip) {
2775 cur_input_buf_omx->pBuffer
2776 + cur_input_buf_omx->nFilledLen,
2777 buffer + read_pos + headerstrip,
2778 packet_length - headerstrip);
2779 cur_input_buf_omx->nFilledLen += packet_length
2782 read_pos += packet_length;
2784 pattern = (buffer[read_pos] << 16)
2785 | (buffer[read_pos + 1] << 8) | (buffer[read_pos + 2]);
2791 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2794 cur_input_buf_omx->nFlags |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2797 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2799 PutBufferToPres(cur_input_buf_omx);
2800 cur_input_buf_omx = NULL;
2803 MILLISLEEP(40); //Block a bit
2807 int VideoOMX::EnterIframePlayback()
2809 Log::getInstance()->log("Video", Log::DEBUG,
2810 "EnterIframePlayback");
2811 if (cur_input_buf_omx) {
2812 PutBufferToPres(cur_input_buf_omx);
2813 cur_input_buf_omx = NULL;
2815 Log::getInstance()->log("Video", Log::DEBUG,
2816 "EnterIframePlayback 2");
2817 ((AudioOMX*)Audio::getInstance())->DeAllocateCodecsOMX();
2818 DeAllocateCodecsOMX();
2819 AllocateCodecsOMX();
2820 Log::getInstance()->log("Video", Log::DEBUG,
2821 "leave IframePlayback");