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"
38 //A lot of parts of this file are heavily inspired by xbmc omx implementations
40 VideoOMX::VideoOMX() {
45 cur_input_buf_omx = NULL;
46 omx_h264 = omx_mpeg2 = true;
50 offsetvideonotset = true;
51 offsetaudionotset = true;
59 mpeg2_supported=false;
64 deinterlace=2; //advanced
76 int VideoOMX::init(UCHAR tformat)
78 if (initted) return 0;
81 int ret=vc_gencmd_send("codec_enabled MPG2");
83 Log::getInstance()->log("Video", Log::DEBUG, "vc_gencmd_send failed %x",ret);
86 ret=vc_gencmd_read_response(buffer,sizeof(buffer));
88 Log::getInstance()->log("Video", Log::DEBUG, "vc_gencmd_read_response failed %x",ret);
90 if (STRCASECMP(buffer,"MPG2=enabled")==0) {
92 } else if (STRCASECMP(buffer,"MPG2=disabled")==0) {
93 mpeg2_supported=false;
95 Log::getInstance()->log("Video", Log::DEBUG, "Undefined mpg codec answer %s",buffer);
100 if (!setFormat(tformat)) { shutdown(); return 0; }
101 if (!setConnection(HDMI)) { shutdown(); return 0; }
102 if (!setAspectRatio(ASPECT4X3,12,11)) { shutdown(); return 0; }
103 if (!setMode(NORMAL)) { shutdown(); return 0; }
104 if (!setSource()) { shutdown(); return 0; }
105 if (!attachFrameBuffer()) { shutdown(); return 0; }
107 setTVsize(ASPECT16X9);
113 if (error != OMX_ErrorNone) {
114 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX failed %x",
133 OMX_ERRORTYPE VideoOMX::EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
134 OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
135 OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data) {
137 Log::getInstance()->log("Video", Log::NOTICE, "eventHandler %x %x %x %x %x",handle,event_type,data1,data2,event_data);
139 struct VPE_OMX_EVENT new_event;
140 new_event.handle=handle;
141 new_event.appdata=appdata;
142 new_event.event_type=event_type;
143 new_event.data1=data1;
144 new_event.data2=data2;
145 new_event.event_data=event_data;
147 VideoOMX *video=(VideoOMX *)getInstance();
148 video->AddOmxEvent(new_event);
150 /* switch (event_type) {
151 case OMX_EventCmdComplete: {
156 return OMX_ErrorNone;
160 void VideoOMX::AddOmxEvent(VPE_OMX_EVENT new_event)
162 omx_event_mutex.Lock();
163 omx_events.push_back(new_event);
164 omx_event_mutex.Unlock();
168 OMX_ERRORTYPE VideoOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
170 //Log::getInstance()->log("Video", Log::NOTICE, "EmptyBufferDone");
171 VideoOMX *video=(VideoOMX *)getInstance();
172 /* long long temp =buffer->nTimeStamp.nLowPart
173 | ((long long) buffer->nTimeStamp.nHighPart << 32);
174 Log::getInstance()->log("Video", Log::NOTICE, "EBD Video %lld %x",temp,buffer->nFlags);*/
175 video->ReturnEmptyOMXBuffer(buffer);
176 return OMX_ErrorNone;
180 void VideoOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
181 input_bufs_omx_mutex.Lock();
182 //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());
183 input_bufs_omx_free.push_back(buffer);
184 //Log::getInstance()->log("Video", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
185 input_bufs_omx_mutex.Unlock();
188 OMX_ERRORTYPE VideoOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
189 Log::getInstance()->log("Video", Log::NOTICE, "FillBufferDone");
190 return OMX_ErrorNone;
195 int VideoOMX::shutdown()
197 if (!initted) return 0;
199 Log::getInstance()->log("Video", Log::NOTICE, "Shutdown video module");
201 DeAllocateCodecsOMX();
203 //vc_tv_show_info(0); // back to console
206 struct fb_var_screeninfo screeninfo;
207 fd_fbset=open("/dev/fb0",O_RDONLY);
209 Log::getInstance()->log("Video", Log::CRIT, "Could not open frame buffer device %d", fd_fbset);
212 if (ioctl(fd_fbset, FBIOGET_VSCREENINFO, &screeninfo)){
214 Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOGET_VSCREENINFO frame buffer device");
217 screeninfo.bits_per_pixel=8;
218 if (ioctl(fd_fbset, FBIOPUT_VSCREENINFO, &screeninfo)){
219 Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOPUT_VSCREENINFO frame buffer device");
221 screeninfo.bits_per_pixel=16;
222 if (ioctl(fd_fbset, FBIOPUT_VSCREENINFO, &screeninfo)){
223 Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOPUT_VSCREENINFO frame buffer device");
231 bool VideoOMX::loadOptionsfromServer(VDR* vdr)
233 Log::getInstance()->log("Video", Log::DEBUG, "VideoOMX config load");
234 char *name=vdr->configLoad("VideoOMX","SDDeinterlacing");
237 if (STRCASECMP(name, "None") == 0) {
239 }/* else if (STRCASECMP(name, "LineDouble") == 0) {
241 }*/ else if (STRCASECMP(name, "Advanced") == 0) {
243 } /*else if (STRCASECMP(name, "Crazy") == 0) {
244 deinterlace = 3; // this does not activate deinterlacing but a image filter, just for fun
246 Log::getInstance()->log("Video", Log::DEBUG, "Set deinterlacing to %s %d",name,deinterlace);
253 bool VideoOMX::handleOptionChanges(Option* option)
255 if (Video::handleOptionChanges(option))
257 switch (option->id) {
259 if (STRCASECMP(option->options[option->userSetChoice], "None") == 0) {
261 } /*else if (STRCASECMP(option->options[option->userSetChoice], "LineDouble")
264 }*/ else if (STRCASECMP(option->options[option->userSetChoice], "Advanced")
267 } /*else if (STRCASECMP(option->options[option->userSetChoice], "Crazy")
271 Log::getInstance()->log("Video", Log::DEBUG, "Set deinterlacing to %s %d",option->options[option->userSetChoice],deinterlace);
280 bool VideoOMX::saveOptionstoServer()
283 switch (deinterlace) {
285 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "None");
288 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "LineDouble");
291 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "Advanced");
294 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "Crazy");
301 /*Option(UINT id, const char* displayText, const char* configSection, const char* configKey, UINT optionType,
302 UINT numChoices, UINT defaultChoice, UINT startInt,
303 const char * const * options, const char * const * optionkeys = NULL, AbstractOption* handler=NULL);*/
305 bool VideoOMX::addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane)
307 if (!Video::addOptionsToPanes(panenumber,options,pane)) return false;
313 static const char* deinterlaceopts[]={"None",/*"LineDouble",*/"Advanced"/*,"Crazy"*/};
314 option = new Option(1,tr("SD Deinterlacing"), "VideoOMX","SDDeinterlacing",Option::TYPE_TEXT,/*4,2*/2,1,0,deinterlaceopts,NULL,false,this);
315 options->push_back(option);
316 pane->addOptionLine(option);
324 int VideoOMX::setTVsize(UCHAR ttvsize)
326 if (tvsize!=ttvsize) pendingmodechange=true;
331 UCHAR VideoOMX::getTVsize() {
333 return ASPECT16X9; // in order that aspect ratio changes are reported
337 void VideoOMX::executePendingModeChanges()
339 if (pendingmodechange) {
340 Log::getInstance()->log("Video", Log::NOTICE, "Execute pending mode change");
341 Osd::getInstance()->shutdown();
343 Osd::getInstance()->restore();
344 Osd::getInstance()->init((void*) "");
345 BoxStack::getInstance()->redrawAllBoxes();
350 int VideoOMX::setDefaultAspect()
352 return setAspectRatio(tvsize,parx,pary);
357 int VideoOMX::setFormat(UCHAR tformat)
359 if (!initted) return 0;
360 if ((tformat != PAL) && (tformat != NTSC)
361 && (tformat != PAL_M) && (tformat != NTSC_J)) return 0;
371 // selectVideoMode(0);
376 void VideoOMX::selectVideoMode(int interlaced)
378 TV_GET_STATE_RESP_T tvstate;
379 vc_tv_get_state(&tvstate);
381 if ((tvstate.state & VC_HDMI_UNPLUGGED)) {
383 Log::getInstance()->log("Video", Log::NOTICE, "HDMI unplugged");
386 Log::getInstance()->log("Video", Log::NOTICE, "HDMI plugged");
387 if (connection==COMPOSITERGB) {
389 Log::getInstance()->log("Video", Log::NOTICE, "SDTV set");
392 Log::getInstance()->log("Video", Log::NOTICE, "HDMI set");
398 TV_SUPPORTED_MODE_T all_supp_modes[TV_MAX_SUPPORTED_MODES];
399 HDMI_RES_GROUP_T pref_group;
400 TV_SUPPORTED_MODE_T *mymode=NULL;
401 TV_SUPPORTED_MODE_T *mymode_second_best=NULL;
402 bool got_optimum=false;
404 HDMI_RES_GROUP_T group=HDMI_RES_GROUP_CEA;
405 int all_my_modes=vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_CEA,
406 all_supp_modes,TV_MAX_SUPPORTED_MODES,
407 &pref_group,&pref_mode);
408 if (all_my_modes<=0) {
409 group=HDMI_RES_GROUP_DMT;
410 all_my_modes=vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_DMT,
411 all_supp_modes,TV_MAX_SUPPORTED_MODES,
412 &pref_group,&pref_mode);
413 Log::getInstance()->log("Video", Log::NOTICE, "No CEA fall back to DMT modes ");
420 if (format==PAL)target_fps=50;
421 else if (format==NTSC) target_fps=60;
423 //Now first determine native resolution
424 int native_width=1920;
425 int native_height=1080;
426 for (int i=0;i<all_my_modes;i++) {
427 if (all_supp_modes[i].native) {
428 mymode=all_supp_modes+i;
429 Log::getInstance()->log("Video", Log::NOTICE, "Found native mode %dx%d %d Hz i: %d",
430 mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode);
431 native_width=mymode->width;
432 native_height=mymode->height;
436 //Now find the mode which matches best
437 for (int i=0;i<all_my_modes;i++) {
438 TV_SUPPORTED_MODE_T *curmode=all_supp_modes+i;
439 if (curmode->width==native_width &&
440 curmode->height==native_height &&
441 curmode->frame_rate==target_fps) {
442 if(curmode->scan_mode==interlaced) {
445 Log::getInstance()->log("Video", Log::NOTICE, "Found optimum mode %dx%d %d Hz i: %d",
446 mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode);
448 mymode_second_best=curmode;
449 Log::getInstance()->log("Video", Log::NOTICE, "Found close to optimum mode %dx%d %d Hz i: %d",
450 mymode_second_best->width,mymode_second_best->height,
451 mymode_second_best->frame_rate,mymode_second_best->scan_mode);
456 Remote::getInstance()->shutdown();
459 Log::getInstance()->log("Video", Log::NOTICE, "Switch to optimum mode");
460 vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,group,mymode->code);
461 } else if (mymode_second_best) {
462 Log::getInstance()->log("Video", Log::NOTICE, "Switch to close to optimum mode");
463 vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,group,mymode_second_best->code);
465 Log::getInstance()->log("Video", Log::NOTICE, "Switch to prefered mode");
466 vc_tv_hdmi_power_on_best(1920,1080,target_fps,interlaced?HDMI_INTERLACED:HDMI_NONINTERLACED,
467 (EDID_MODE_MATCH_FLAG_T)(HDMI_MODE_MATCH_FRAMERATE|HDMI_MODE_MATCH_RESOLUTION|HDMI_MODE_MATCH_SCANMODE));
470 outputinterlaced=interlaced;
473 Log::getInstance()->log("Video", Log::NOTICE, "Analog tv case");
474 Remote::getInstance()->shutdown();
476 SDTV_MODE_T setmode=SDTV_MODE_PAL;
477 SDTV_OPTIONS_T options;
482 Log::getInstance()->log("Video", Log::NOTICE, "SDTV aspect 16:9");
483 options.aspect=SDTV_ASPECT_16_9; break;
485 Log::getInstance()->log("Video", Log::NOTICE, "SDTV aspect 4:3");
486 options.aspect=SDTV_ASPECT_4_3; break;
488 Log::getInstance()->log("Video", Log::NOTICE, "SDTV aspect 14:9");
489 options.aspect=SDTV_ASPECT_14_9; break;
492 if (format==PAL) setmode=SDTV_MODE_PAL;
493 else if (format==NTSC) setmode=SDTV_MODE_NTSC;
494 else if (format==PAL_M)setmode=SDTV_MODE_PAL_M;
495 else if (format==NTSC_J) setmode=SDTV_MODE_NTSC_J;
496 vc_tv_sdtv_power_on(setmode,&options);
500 Remote::getInstance()->init("");
504 pendingmodechange=false;
509 int VideoOMX::setConnection(UCHAR tconnection)
511 if (!initted) return 0;
512 if ((tconnection != COMPOSITERGB) && (tconnection != HDMI)) return 0;
513 if (connection!=tconnection) pendingmodechange=true;
514 connection = tconnection;
516 // if (ioctl(fdVideo, AV_SET_VID_OUTPUT, connection) != 0) return 0;
520 int VideoOMX::setAspectRatio(UCHAR taspectRatio, int tparx,int tpary)
522 if (!initted) return 0;
523 //if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
524 aspectRatio = taspectRatio;
528 Log::getInstance()->log("Video", Log::DEBUG, "Setting aspect to %i: PAR %d %d", aspectRatio,parx,pary);
531 // if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
535 int VideoOMX::setMode(UCHAR tmode)
537 if (!initted) return 0;
544 void VideoOMX::updateMode()
550 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
551 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
553 OMX_CONFIG_DISPLAYREGIONTYPE dispconf;
554 memset(&dispconf, 0, sizeof(dispconf));
555 dispconf.nSize = sizeof(dispconf);
556 dispconf.nVersion.nVersion = OMX_VERSION;
557 dispconf.nPortIndex = omx_rend_input_port;
559 dispconf.set = OMX_DISPLAY_SET_LAYER;
560 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
562 if (error != OMX_ErrorNone) {
563 Log::getInstance()->log("Video", Log::DEBUG,
564 "Set OMX_IndexConfigDisplayRegion1 failed %x", error);
565 clock_mutex.Unlock();
570 dispconf.pixel_x =parx;
571 dispconf.pixel_y=pary;
572 dispconf.set = OMX_DISPLAY_SET_PIXEL;
573 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
575 if (error != OMX_ErrorNone) {
576 Log::getInstance()->log("Video", Log::DEBUG,
577 "Set OMX_IndexConfigDisplayRegion5 failed %x", error);
578 clock_mutex.Unlock();
584 dispconf.set = OMX_DISPLAY_SET_FULLSCREEN;
585 if (mode != QUARTER && mode != EIGHTH) {
587 dispconf.fullscreen = OMX_TRUE;
589 dispconf.fullscreen = OMX_FALSE;
591 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
593 if (error != OMX_ErrorNone) {
594 Log::getInstance()->log("Video", Log::DEBUG,
595 "Set OMX_IndexConfigDisplayRegion2 failed %x", error);
596 clock_mutex.Unlock();
600 dispconf.set = OMX_DISPLAY_SET_MODE;
601 if (mode != QUARTER && mode != EIGHTH) {
602 dispconf.mode = (mode == NORMAL) ? OMX_DISPLAY_MODE_FILL
603 : OMX_DISPLAY_MODE_LETTERBOX;
605 dispconf.mode = OMX_DISPLAY_MODE_LETTERBOX;
607 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
609 if (error != OMX_ErrorNone) {
610 Log::getInstance()->log("Video", Log::DEBUG,
611 "Set OMX_IndexConfigDisplayRegion3 failed %x", error);
612 clock_mutex.Unlock();
616 if (mode == QUARTER || mode == EIGHTH) {
617 unsigned int display_width, display_height;
618 display_width = display_height = 0;
619 if (graphics_get_display_size(0, &display_width, &display_height)
621 Log::getInstance()->log("OSD", Log::WARN,
622 "Getting display size failed! (BCM API) ");
623 clock_mutex.Unlock();
626 //UnSetFullscreen with window
627 dispconf.set = OMX_DISPLAY_SET_DEST_RECT;
628 dispconf.dest_rect.x_offset
629 = (int) (xpos * ((float) display_width));
630 dispconf.dest_rect.y_offset = (int) (ypos
631 * ((float) display_height));
632 if (mode == QUARTER) {
633 dispconf.dest_rect.width = display_width >> 1;
634 dispconf.dest_rect.height = display_height >> 1;
635 } else if (mode == EIGHTH) {
636 dispconf.dest_rect.width = display_width >> 2;
637 dispconf.dest_rect.height = display_height >> 2;
639 error = OMX_SetParameter(omx_vid_rend,
640 OMX_IndexConfigDisplayRegion, &dispconf);
641 if (error != OMX_ErrorNone) {
642 Log::getInstance()->log("Video", Log::DEBUG,
643 "Set OMX_IndexConfigDisplayRegion failed %x", error);
644 clock_mutex.Unlock();
648 clock_mutex.Unlock();
649 pthread_setcancelstate(oldcancelstate, NULL);
650 pthread_setcanceltype(oldcanceltype, NULL);
653 clock_mutex.Unlock();
656 int VideoOMX::signalOff()
659 Log::getInstance()->log("Video", Log::NOTICE, "signalOff");
660 Osd::getInstance()->stopUpdate(); // turn off drawing thread
661 Remote::getInstance()->shutdown();
663 Remote::getInstance()->init("");
668 int VideoOMX::signalOn()
671 Osd::getInstance()->shutdown();
672 Log::getInstance()->log("Video", Log::NOTICE, "signalOn");
674 Osd::getInstance()->restore();
675 Osd::getInstance()->init((void*)"");
676 BoxStack::getInstance()->redrawAllBoxes();
683 int VideoOMX::setSource()
685 if (!initted) return 0;
687 // What does this do...
688 // if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
692 int VideoOMX::setPosition(int x, int y) {
695 xpos = ((float) x*2.f) / ((float) screenWidth);
696 ypos = ((float) y*2.f) / ((float) screenHeight);
704 if (!initted) return 0;
706 // if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
710 void VideoOMX::interlaceSwitch4Demux() {
712 Demuxer *demux=Demuxer::getInstance();
714 if (hdmi) { // only switch if hdmi and HD or interlaced SD material
718 int set_interlaced=0;
719 if (demux->getHorizontalSize()>720 && demux->getInterlaced()) {
722 Log::getInstance()->log("Video", Log::NOTICE, "switch interlacing %d %d %d",demux->getInterlaced(),outputinterlaced,set_interlaced);
723 if (outputinterlaced!=set_interlaced) {
724 selectVideoMode(set_interlaced);
725 Osd::getInstance()->shutdown();
726 Osd::getInstance()->restore();
727 Osd::getInstance()->init((void*)"");
728 BoxStack::getInstance()->redrawAllBoxes();
740 int VideoOMX::play() {
744 Log::getInstance()->log("Video", Log::DEBUG, "enter play");
746 interlaceSwitch4Demux();
748 if (AllocateCodecsOMX()) {
750 // Otherwise fall back to libav
754 Log::getInstance()->log("Video", Log::NOTICE,
755 "Allocate Codecs OMX failed assume h264 unsupported");
758 Log::getInstance()->log("Video", Log::NOTICE,
759 "Allocate Codecs OMX failed assume mpeg2 unsupported");
768 int VideoOMX::initClock()
772 if (clock_references==0)
775 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
778 error=OMX_GetHandle(&omx_clock,VPE_OMX_CLOCK,NULL,&callbacks);
780 if (error!=OMX_ErrorNone) {
781 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX clock failed %x", error);
782 clock_mutex.Unlock();
783 DeAllocateCodecsOMX();
787 /* TODO Clock config to separate method */
788 OMX_PORT_PARAM_TYPE p_param;
789 memset(&p_param,0,sizeof(p_param));
790 p_param.nSize=sizeof(p_param);
791 p_param.nVersion.nVersion=OMX_VERSION;
792 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
793 if (error!=OMX_ErrorNone) {
794 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
795 clock_mutex.Unlock();
796 DeAllocateCodecsOMX();
799 omx_clock_output_port=p_param.nStartPortNumber;
801 for (unsigned int i=0;i<p_param.nPorts;i++) {
802 if (!DisablePort(omx_clock,p_param.nStartPortNumber+i,true) ) {
803 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX clock failed %d",i);
804 clock_mutex.Unlock();
805 DeAllocateCodecsOMX();
814 Log::getInstance()->log("Video", Log::DEBUG, "init omx clock %x %x",this,omx_clock);
816 clock_mutex.Unlock();
820 int VideoOMX::getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port)
824 *p_omx_clock_output_port=0;
831 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
832 memset(&refclock,0,sizeof(refclock));
833 refclock.nSize=sizeof(refclock);
834 refclock.nVersion.nVersion=OMX_VERSION;
836 refclock.eClock=OMX_TIME_RefClockAudio;
838 //refclock.eClock=OMX_TIME_RefClockVideo;
839 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
840 if (error!=OMX_ErrorNone){
841 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
842 clock_mutex.Unlock();
843 DeAllocateCodecsOMX();
847 OMX_PORT_PARAM_TYPE p_param;
848 memset(&p_param,0,sizeof(p_param));
849 p_param.nSize=sizeof(p_param);
850 p_param.nVersion.nVersion=OMX_VERSION;
851 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
852 if (error!=OMX_ErrorNone){
853 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
854 clock_mutex.Unlock();
855 DeAllocateCodecsOMX();
859 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
860 memset(&clock_conf,0,sizeof(clock_conf));
861 clock_conf.nSize=sizeof(clock_conf);
862 clock_conf.nVersion.nVersion=OMX_VERSION;
863 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
864 clock_conf.nStartTime=intToOMXTicks(0);
865 clock_conf.nOffset=intToOMXTicks(0);
866 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT1;
867 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
868 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
869 if (error!=OMX_ErrorNone) {
870 Log::getInstance()->log("Video", Log::DEBUG, "AuI Clock IndexConfigTimeClockState failed %x", error);
874 *p_omx_clock_output_port=p_param.nStartPortNumber+1;
875 *p_omx_clock=omx_clock;
876 clock_mutex.Unlock();
880 int VideoOMX::getClockVideoandInit()
889 if (clock_references==1) { // only if no audio is attached to this clock!
890 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
891 memset(&refclock,0,sizeof(refclock));
892 refclock.nSize=sizeof(refclock);
893 refclock.nVersion.nVersion=OMX_VERSION;
895 //refclock.eClock=OMX_TIME_RefClockAudio;
897 refclock.eClock=OMX_TIME_RefClockVideo;
898 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
899 if (error!=OMX_ErrorNone) {
900 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
901 clock_mutex.Unlock();
902 DeAllocateCodecsOMX();
907 OMX_PORT_PARAM_TYPE p_param;
908 memset(&p_param,0,sizeof(p_param));
909 p_param.nSize=sizeof(p_param);
910 p_param.nVersion.nVersion=OMX_VERSION;
911 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
912 if (error!=OMX_ErrorNone){
913 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
914 clock_mutex.Unlock();
915 DeAllocateCodecsOMX();
920 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
921 memset(&clock_conf,0,sizeof(clock_conf));
922 clock_conf.nSize=sizeof(clock_conf);
923 clock_conf.nVersion.nVersion=OMX_VERSION;
924 clock_conf.eState=OMX_TIME_ClockStateStopped;
925 clock_conf.nStartTime=intToOMXTicks(0);
926 clock_conf.nOffset=intToOMXTicks(0);
927 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
928 if (error!=OMX_ErrorNone) {
929 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
933 memset(&clock_conf,0,sizeof(clock_conf));
934 clock_conf.nSize=sizeof(clock_conf);
935 clock_conf.nVersion.nVersion=OMX_VERSION;
936 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
937 clock_conf.nStartTime=intToOMXTicks(0);
938 clock_conf.nOffset=intToOMXTicks(0);
939 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT0;
940 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
941 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
942 if (error!=OMX_ErrorNone) {
943 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
946 omx_clock_output_port=p_param.nStartPortNumber;
947 clock_mutex.Unlock();
952 void VideoOMX::clockUnpause()
955 Log::getInstance()->log("Video", Log::NOTICE, "enter Clockunpause");
957 if (clock_references>0 && clockpaused) {
958 OMX_TIME_CONFIG_SCALETYPE scale_type;
959 memset(&scale_type,0,sizeof(scale_type));
960 scale_type.nSize=sizeof(scale_type);
961 scale_type.nVersion.nVersion=OMX_VERSION;
962 scale_type.xScale=1<<16;
963 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeScale,&scale_type);
964 if (error!=OMX_ErrorNone) {
965 Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause OMX_IndexConfigTimeScale failed %x", error);
967 Log::getInstance()->log("Video", Log::NOTICE, "set playback speed ClockUnpause");
970 clock_mutex.Unlock();
974 void VideoOMX::clockPause()
977 Log::getInstance()->log("Video", Log::NOTICE, "enter ClockPause");
979 if (clock_references>0 && !clockpaused) {
980 OMX_TIME_CONFIG_SCALETYPE scale_type;
981 memset(&scale_type,0,sizeof(scale_type));
982 scale_type.nSize=sizeof(scale_type);
983 scale_type.nVersion.nVersion=OMX_VERSION;
985 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeScale,&scale_type);
986 if (error!=OMX_ErrorNone) {
987 Log::getInstance()->log("Video", Log::DEBUG, "ClockPause OMX_IndexConfigTimeScale failed %x", error);
989 Log::getInstance()->log("Video", Log::NOTICE, "set playback speed ClockPause");
992 clock_mutex.Unlock();
997 int VideoOMX::AllocateCodecsOMX()
1000 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
1002 Demuxer* demux=Demuxer::getInstance();
1005 deint_first_frame=false;
1007 Log::getInstance()->log("Video", Log::NOTICE, "Allocate Codecs OMX");
1008 //Clock, move later to audio including events
1010 Log::getInstance()->log("Video", Log::NOTICE, "VideoType %d x %d i: %d", demux->getHorizontalSize(),demux->getVerticalSize(),demux->getInterlaced());
1011 if (deinterlace!=0 && /*(demux->getHorizontalSize()<=720 ) &&*/ demux->getInterlaced()) { //only deinterlace SD material
1013 deint_first_frame=true;
1015 Log::getInstance()->log("Video", Log::NOTICE, "Deinterlacing activated %d",deinterlace);
1020 if (!getClockVideoandInit()){
1021 return 0;// get the clock and init it if necessary
1026 Log::getInstance()->log("Video", Log::DEBUG, "idleClock failed");
1033 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_H264_DECODER,NULL,&callbacks);
1035 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_MPEG2_DECODER,NULL,&callbacks);
1038 if (error!=OMX_ErrorNone){
1039 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video decoder failed %x", error);
1040 clock_mutex.Unlock();
1041 DeAllocateCodecsOMX();
1046 Log::getInstance()->log("Video", Log::DEBUG, "Nmark3 ");
1047 OMX_PORT_PARAM_TYPE p_param;
1048 memset(&p_param,0,sizeof(p_param));
1049 p_param.nSize=sizeof(p_param);
1050 p_param.nVersion.nVersion=OMX_VERSION;
1051 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamVideoInit,&p_param);
1052 if (error!=OMX_ErrorNone){
1053 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX h264 decoder OMX_GetParameter failed %x", error);
1054 clock_mutex.Unlock();
1055 DeAllocateCodecsOMX();
1058 omx_codec_input_port=p_param.nStartPortNumber;
1059 omx_codec_output_port=p_param.nStartPortNumber+1;
1061 if (!DisablePort(omx_vid_dec,omx_codec_input_port) || !DisablePort(omx_vid_dec,omx_codec_output_port)) {
1062 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video decoder failed");
1063 clock_mutex.Unlock();
1064 DeAllocateCodecsOMX();
1068 Log::getInstance()->log("Video", Log::DEBUG, "Nmark4 ");
1070 OMX_PARAM_BRCMVIDEODECODEERRORCONCEALMENTTYPE conceal;
1071 memset(&conceal,0,sizeof(conceal));
1072 conceal.nSize=sizeof(conceal);
1073 conceal.nVersion.nVersion=OMX_VERSION;
1074 conceal.bStartWithValidFrame=OMX_FALSE;
1076 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamBrcmVideoDecodeErrorConcealment,&conceal);
1077 if (error!=OMX_ErrorNone){
1078 Log::getInstance()->log("Video", Log::DEBUG, "OMX_IndexParamBrcmVideoDecodeErrorConcealment failed %x", error);
1079 clock_mutex.Unlock();
1080 DeAllocateCodecsOMX();
1085 error = OMX_GetHandle(&omx_vid_deint, VPE_OMX_VIDEO_DEINTERLACE, NULL,
1087 if (error != OMX_ErrorNone) {
1088 Log::getInstance()->log("Video", Log::DEBUG,
1089 "Init OMX video deinterlacer failed %x", error);
1090 clock_mutex.Unlock();
1091 DeAllocateCodecsOMX();
1095 error = OMX_GetParameter(omx_vid_deint, OMX_IndexParamImageInit,
1097 if (error != OMX_ErrorNone) {
1098 Log::getInstance()->log("Video", Log::DEBUG,
1099 "Init OMX video deinterlacer OMX_GetParameter failed %x",
1101 clock_mutex.Unlock();
1102 DeAllocateCodecsOMX();
1105 omx_deint_input_port = p_param.nStartPortNumber;
1106 omx_deint_output_port = p_param.nStartPortNumber + 1;
1108 if (!DisablePort(omx_vid_deint, omx_deint_input_port, true)
1109 || !DisablePort(omx_vid_deint, omx_deint_output_port, true)) {
1110 Log::getInstance()->log("Video", Log::DEBUG,
1111 "Disable Ports OMX video deint failed");
1112 clock_mutex.Unlock();
1113 DeAllocateCodecsOMX();
1120 error=OMX_GetHandle(&omx_vid_sched,VPE_OMX_VIDEO_SCHED,NULL,&callbacks);
1121 if (error!=OMX_ErrorNone){
1122 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler failed %x", error);
1123 clock_mutex.Unlock();
1124 DeAllocateCodecsOMX();
1130 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamVideoInit,&p_param);
1131 if (error!=OMX_ErrorNone){
1132 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1133 clock_mutex.Unlock();
1134 DeAllocateCodecsOMX();
1137 omx_shed_input_port=p_param.nStartPortNumber;
1138 omx_shed_output_port=p_param.nStartPortNumber+1;
1141 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamOtherInit,&p_param);
1142 if (error!=OMX_ErrorNone){
1143 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1144 clock_mutex.Unlock();
1145 DeAllocateCodecsOMX();
1148 omx_shed_clock_port=p_param.nStartPortNumber;
1149 Log::getInstance()->log("Video", Log::DEBUG, "scheduler ports %d %d %d ",omx_shed_input_port,omx_shed_output_port,omx_shed_clock_port);
1152 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true) || !DisablePort(omx_vid_sched,omx_shed_output_port,true)
1153 || !DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
1154 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video shed failed");
1155 clock_mutex.Unlock();
1156 DeAllocateCodecsOMX();
1161 error=OMX_GetHandle(&omx_vid_rend,VPE_OMX_VIDEO_REND,NULL,&callbacks);
1162 if (error!=OMX_ErrorNone){
1163 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend failed %x", error);
1164 clock_mutex.Unlock();
1165 DeAllocateCodecsOMX();
1169 error=OMX_GetParameter(omx_vid_rend,OMX_IndexParamVideoInit,&p_param);
1170 if (error!=OMX_ErrorNone){
1171 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend OMX_GetParameter failed %x", error);
1172 clock_mutex.Unlock();
1173 DeAllocateCodecsOMX();
1176 omx_rend_input_port=p_param.nStartPortNumber;
1177 //omx_rend_output_port=p_param.nStartPortNumber+1;
1180 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true) /*|| !DisablePort(omx_vid_rend,omx_rend_output_port)*/
1182 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video rend failed");
1183 clock_mutex.Unlock();
1184 DeAllocateCodecsOMX();
1192 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,omx_vid_sched,omx_shed_clock_port);
1193 if (error!=OMX_ErrorNone){
1194 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);
1195 clock_mutex.Unlock();
1196 DeAllocateCodecsOMX();
1200 if (!EnablePort(omx_clock,omx_clock_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_clock_port,false)
1202 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX clock shed failed");
1203 clock_mutex.Unlock();
1204 DeAllocateCodecsOMX();
1209 Log::getInstance()->log("Video", Log::DEBUG, "mark2 ");
1210 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1211 Log::getInstance()->log("Video", Log::DEBUG, "vid_sched idle ChangeComponentState");
1212 clock_mutex.Unlock();
1213 DeAllocateCodecsOMX();
1219 Log::getInstance()->log("Video", Log::DEBUG, "mark1 ");
1220 if ( !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_clock_port)) {
1221 clock_mutex.Unlock();
1222 DeAllocateCodecsOMX();
1229 Log::getInstance()->log("Video", Log::DEBUG, "mark1 special ");
1230 if ( !CommandFinished(omx_clock,OMX_CommandPortEnable,omx_clock_output_port)) {
1231 clock_mutex.Unlock();
1232 DeAllocateCodecsOMX();
1238 Log::getInstance()->log("Video", Log::DEBUG, "mark1b ");
1241 /* error=OMX_SendCommand(omx_vid_dec,OMX_CommandStateSet,OMX_StateIdle,0);
1242 if (error!=OMX_ErrorNone){
1243 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec Send Command to OMX State Idle %x", error);
1247 OMX_VIDEO_PARAM_PORTFORMATTYPE ft_type;
1248 memset(&ft_type,0,sizeof(ft_type));
1249 ft_type.nSize=sizeof(ft_type);
1250 ft_type.nVersion.nVersion=OMX_VERSION;
1252 ft_type.nPortIndex=omx_codec_input_port;
1254 ft_type.eCompressionFormat=OMX_VIDEO_CodingAVC;
1256 ft_type.eCompressionFormat=OMX_VIDEO_CodingMPEG2;
1261 ft_type.xFramerate=0*(1<<16);//25*(1<<16);//demux->getFrameRate()*(1<<16);
1262 Log::getInstance()->log("Video", Log::DEBUG, "Framerate: %d",demux->getFrameRate());
1263 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamVideoPortFormat,&ft_type);
1264 if (error!=OMX_ErrorNone){
1265 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexParamVideoPortFormat failed %x", error);
1266 clock_mutex.Unlock();
1267 DeAllocateCodecsOMX();
1272 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1273 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1274 clock_mutex.Unlock();
1275 DeAllocateCodecsOMX();
1280 if (!PrepareInputBufsOMX()) {
1281 clock_mutex.Unlock();
1282 DeAllocateCodecsOMX();
1287 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_sched,omx_shed_input_port);
1288 if (error!=OMX_ErrorNone){
1289 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to sched failed %x", error);
1290 clock_mutex.Unlock();
1291 DeAllocateCodecsOMX();
1297 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1299 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec shed failed");
1300 clock_mutex.Unlock();
1301 DeAllocateCodecsOMX();
1305 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1306 clock_mutex.Unlock();
1307 DeAllocateCodecsOMX();
1313 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_deint,omx_deint_input_port);
1314 if (error!=OMX_ErrorNone){
1315 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to deint failed %x", error);
1316 clock_mutex.Unlock();
1317 DeAllocateCodecsOMX();
1323 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_deint,omx_deint_input_port,false)
1325 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec deint failed");
1326 clock_mutex.Unlock();
1327 DeAllocateCodecsOMX();
1331 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_input_port)) {
1332 clock_mutex.Unlock();
1333 DeAllocateCodecsOMX();
1337 if (!ChangeComponentState(omx_vid_deint,OMX_StateIdle)) {
1338 Log::getInstance()->log("Video", Log::DEBUG, "vid_deint ChangeComponentState");
1339 clock_mutex.Unlock();
1340 DeAllocateCodecsOMX();
1344 OMX_CONFIG_IMAGEFILTERPARAMSTYPE imagefilter;
1345 memset(&imagefilter,0,sizeof(imagefilter));
1346 imagefilter.nSize=sizeof(imagefilter);
1347 imagefilter.nVersion.nVersion=OMX_VERSION;
1349 imagefilter.nPortIndex=omx_deint_output_port;
1350 imagefilter.nNumParams=1;
1351 imagefilter.nParams[0]=3;//???
1352 switch (deinterlace) {
1354 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceLineDouble; break;
1356 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceAdvanced; break;
1358 imagefilter.eImageFilter=OMX_ImageFilterFilm; break;
1362 error=OMX_SetConfig(omx_vid_deint,OMX_IndexConfigCommonImageFilterParameters,&imagefilter);
1363 if (error!=OMX_ErrorNone){
1364 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigCommonImageFilterParameters failed %x", error);
1365 clock_mutex.Unlock();
1366 DeAllocateCodecsOMX();
1371 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,omx_vid_sched,omx_shed_input_port);
1372 if (error!=OMX_ErrorNone){
1373 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel deint to sched failed %x", error);
1374 clock_mutex.Unlock();
1375 DeAllocateCodecsOMX();
1379 if (!EnablePort(omx_vid_deint,omx_deint_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1381 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX deint shed failed");
1382 clock_mutex.Unlock();
1383 DeAllocateCodecsOMX();
1387 if ( !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1388 clock_mutex.Unlock();
1389 DeAllocateCodecsOMX();
1395 if (!ChangeComponentState(omx_vid_dec,OMX_StateExecuting)) {
1396 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_dec ChangeComponentState Execute");
1397 clock_mutex.Unlock();
1398 DeAllocateCodecsOMX();
1402 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,omx_vid_rend,omx_rend_input_port);
1403 if (error!=OMX_ErrorNone){
1404 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel sched to rend failed %x", error);
1405 clock_mutex.Unlock();
1406 DeAllocateCodecsOMX();
1410 if (!EnablePort(omx_vid_sched,omx_shed_output_port,false) || !EnablePort(omx_vid_rend,omx_rend_input_port,false)
1412 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX shed rend failed");
1413 clock_mutex.Unlock();
1414 DeAllocateCodecsOMX();
1418 if (!CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_output_port)
1419 || !CommandFinished(omx_vid_rend,OMX_CommandPortEnable,omx_rend_input_port)) {
1420 clock_mutex.Unlock();
1421 DeAllocateCodecsOMX();
1425 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1426 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1427 clock_mutex.Unlock();
1428 DeAllocateCodecsOMX();
1433 if (!ChangeComponentState(omx_vid_deint,OMX_StateExecuting)) {
1434 Log::getInstance()->log("Video", Log::DEBUG, "vid_vid_deint ChangeComponentState");
1435 clock_mutex.Unlock();
1436 DeAllocateCodecsOMX();
1439 DisablePort(omx_vid_deint,omx_deint_output_port,false);
1440 DisablePort(omx_vid_deint,omx_deint_input_port,false);
1443 if (!ChangeComponentState(omx_vid_sched,OMX_StateExecuting)) {
1444 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_sched ChangeComponentState Execute");
1445 clock_mutex.Unlock();
1446 DeAllocateCodecsOMX();
1450 if (!ChangeComponentState(omx_vid_rend,OMX_StateExecuting)) {
1451 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_rend ChangeComponentState Execute");
1452 clock_mutex.Unlock();
1453 DeAllocateCodecsOMX();
1458 /*OMX_CONFIG_DISPLAYREGIONTYPE dispconf;
1459 memset(&dispconf,0,sizeof(dispconf));
1460 dispconf.nSize=sizeof(dispconf);
1461 dispconf.nVersion.nVersion=OMX_VERSION;
1463 dispconf.nPortIndex=omx_rend_input_port;
1465 dispconf.set=OMX_DISPLAY_SET_LAYER ;
1467 error=OMX_SetConfig(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1468 if (error!=OMX_ErrorNone){
1469 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1470 clock_mutex.Unlock();
1471 DeAllocateCodecsOMX();
1475 /* dispconf.set=OMX_DISPLAY_SET_FULLSCREEN ;
1476 dispconf.fullscreen=OMX_FALSE;
1477 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1478 if (error!=OMX_ErrorNone){
1479 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1480 clock_mutex.Unlock();
1481 DeAllocateCodecsOMX();
1485 dispconf.set=OMX_DISPLAY_SET_DEST_RECT;
1486 dispconf.dest_rect.x_offset=100;
1487 dispconf.dest_rect.y_offset=100;
1488 dispconf.dest_rect.width=640;
1489 dispconf.dest_rect.height=480;
1490 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1491 if (error!=OMX_ErrorNone){
1492 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1493 clock_mutex.Unlock();
1494 DeAllocateCodecsOMX();
1499 //playbacktimeoffset=-GetCurrentSystemTime();
1503 clock_mutex.Unlock();
1507 setClockExecutingandRunning();
1516 int VideoOMX::idleClock()
1518 OMX_ERRORTYPE error;
1519 OMX_STATETYPE temp_state;
1521 OMX_GetState(omx_clock,&temp_state);
1523 if (temp_state!=OMX_StateIdle) {
1524 if (!ChangeComponentState(omx_clock,OMX_StateIdle)) {
1525 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Idle failed");
1526 clock_mutex.Unlock();
1530 clock_mutex.Unlock();
1534 int VideoOMX::setClockExecutingandRunning()
1536 OMX_ERRORTYPE error;
1537 OMX_STATETYPE temp_state;
1539 OMX_GetState(omx_clock,&temp_state);
1541 if (temp_state!=OMX_StateExecuting) {
1542 if (!ChangeComponentState(omx_clock,OMX_StateExecuting)) {
1543 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Execute failed");
1544 clock_mutex.Unlock();
1545 DeAllocateCodecsOMX();
1550 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
1551 memset(&clock_conf,0,sizeof(clock_conf));
1552 clock_conf.nSize=sizeof(clock_conf);
1553 clock_conf.nVersion.nVersion=OMX_VERSION;
1554 clock_conf.eState=OMX_TIME_ClockStateRunning;
1555 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
1556 if (error!=OMX_ErrorNone) {
1557 Log::getInstance()->log("Video", Log::DEBUG, "Clock IndexConfigTimeClockState failed %x", error);
1558 clock_mutex.Unlock();
1559 DeAllocateCodecsOMX();
1562 clock_mutex.Unlock();
1568 int VideoOMX::ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type) //needs to be called with locked mutex
1570 OMX_ERRORTYPE error;
1571 error=OMX_SendCommand(handle,OMX_CommandStateSet,type,0);
1572 if (error!=OMX_ErrorNone){
1573 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to OMX State %x %x",handle,type, error);
1577 if (!CommandFinished(handle,OMX_CommandStateSet,type)) {
1585 int VideoOMX::EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1587 OMX_ERRORTYPE error;
1588 error=OMX_SendCommand(handle,OMX_CommandPortEnable,port,0);
1589 if (error!=OMX_ErrorNone){
1590 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to enable port %x %x",handle,port, error);
1594 if (!wait) return 1;
1595 if (!CommandFinished(handle,OMX_CommandPortEnable,port)) {
1603 int VideoOMX::DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1605 OMX_ERRORTYPE error;
1606 error=OMX_SendCommand(handle,OMX_CommandPortDisable,port,0);
1607 if (error!=OMX_ErrorNone){
1608 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to disable port %x %x",handle,port, error);
1612 if (!wait) return 1;
1613 if (!CommandFinished(handle,OMX_CommandPortDisable,port)) {
1621 int VideoOMX::WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event) //needs to be called with locked mutex
1625 omx_event_mutex.Lock();
1626 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1627 while (itty!=omx_events.end()) {
1629 VPE_OMX_EVENT current=*itty;
1630 if (current.handle==handle) { //this is ours
1631 if (current.event_type==OMX_EventError) {
1632 omx_events.erase(itty);
1633 omx_event_mutex.Unlock();
1634 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished on Error");
1637 } else if (current.event_type==event) {
1638 omx_events.erase(itty);
1639 omx_event_mutex.Unlock();
1640 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished Completed");
1647 omx_event_mutex.Unlock();
1652 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent waited too long %x %x",handle,event);
1657 int VideoOMX::clearEvents()
1659 omx_event_mutex.Lock();
1661 omx_event_mutex.Unlock();
1667 int VideoOMX::CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2) //needs to be called with locked mutex
1671 omx_event_mutex.Lock();
1672 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1673 while (itty!=omx_events.end()) {
1675 VPE_OMX_EVENT current=*itty;
1676 if (current.handle==handle) { //this is ours
1677 if (current.event_type==OMX_EventError) {
1678 omx_events.erase(itty);
1679 omx_event_mutex.Unlock();
1680 Log::getInstance()->log("Video", Log::DEBUG, "Command Finished on Error %x",current.data1);
1683 } else if (current.event_type==OMX_EventCmdComplete && current.data1==command && current.data2==data2) {
1684 omx_events.erase(itty);
1685 omx_event_mutex.Unlock();
1686 //Log::getInstance()->log("Video", Log::DEBUG, "Command Finished Completed");
1693 omx_event_mutex.Unlock();
1698 Log::getInstance()->log("Video", Log::DEBUG, "CommandFinished waited too long %x %x %x",handle,command, data2);
1707 int VideoOMX::PrepareInputBufsOMX() //needs to be called with locked mutex
1709 OMX_ERRORTYPE error;
1710 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
1711 memset(&port_def_type,0,sizeof(port_def_type));
1712 port_def_type.nSize=sizeof(port_def_type);
1713 port_def_type.nVersion.nVersion=OMX_VERSION;
1714 port_def_type.nPortIndex=omx_codec_input_port;
1716 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1718 if (error!=OMX_ErrorNone){
1719 Log::getInstance()->log("Video", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
1721 /* Log::getInstance()->log("Video", Log::DEBUG, "Port para %d %d %d %d %d %d %d", port_def_type.nBufferCountActual,
1722 port_def_type.nBufferCountMin,port_def_type.nBufferSize,port_def_type.bEnabled,port_def_type.bPopulated,
1723 port_def_type.bBuffersContiguous,port_def_type.nBufferAlignment);*/
1725 port_def_type.nBufferCountActual=100;
1726 port_def_type.nBufferSize=max(port_def_type.nBufferSize,200000); // for transcoder important
1728 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1730 if (error!=OMX_ErrorNone){
1731 Log::getInstance()->log("Video", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
1735 error=OMX_SendCommand(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port,0);
1736 if (error!=OMX_ErrorNone){
1737 Log::getInstance()->log("Video", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
1741 input_bufs_omx_mutex.Lock();
1742 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
1744 // unsigned char* new_buffer_data=(unsigned char*)malloc(port_def_type.nbufferSize);
1745 OMX_BUFFERHEADERTYPE *buf_head=NULL;
1746 /* error=OMX_Usebuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nbufferSize,new_buffer_data);
1747 if (error!=OMX_ErrorNone){
1748 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_Usebuffer failed %x", error);
1749 input_bufs_omx_mutex.Unlock();
1752 error=OMX_AllocateBuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nBufferSize);
1753 if (error!=OMX_ErrorNone){
1754 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_AllocateBuffer failed %x", error);
1755 input_bufs_omx_mutex.Unlock();
1758 input_bufs_omx_all.push_back(buf_head);
1759 input_bufs_omx_free.push_back(buf_head);
1761 omx_first_frame=true;
1764 cur_input_buf_omx=NULL;
1765 input_bufs_omx_mutex.Unlock();
1768 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark3");
1769 if (!CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port)) {
1772 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark4");
1777 int VideoOMX::DestroyInputBufsOMX() //need s to be called with locked mutex
1779 OMX_ERRORTYPE error;
1781 cur_input_buf_omx=NULL;
1782 input_bufs_omx_mutex.Lock();
1783 for (int i=0; i< input_bufs_omx_all.size();i++) {
1784 // free(input_bufs_omx_all[i]->pBuffer);
1785 // input_bufs_omx_all[i]->pBuffer=NULL;
1786 error=OMX_FreeBuffer(omx_vid_dec,omx_codec_input_port,input_bufs_omx_all[i]);
1787 if (error!=OMX_ErrorNone){
1788 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
1789 input_bufs_omx_mutex.Unlock();
1794 input_bufs_omx_all.clear();
1795 input_bufs_omx_free.clear();
1796 input_bufs_omx_mutex.Unlock();
1801 int VideoOMX::FlushRenderingPipe()
1803 OMX_ERRORTYPE error;
1807 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1808 omx_codec_output_port, NULL);
1809 if (error != OMX_ErrorNone) {
1810 Log::getInstance()->log("Video", Log::DEBUG,
1811 "OMX_Flush codec out 1 failed %x", error);
1815 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1816 omx_shed_input_port, NULL);
1817 if (error != OMX_ErrorNone) {
1818 Log::getInstance()->log("Video", Log::DEBUG,
1819 "OMX_Flush shed in 2 failed %x", error);
1823 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1824 omx_codec_output_port)) {
1825 Log::getInstance()->log("Video", Log::DEBUG,
1826 "flush cmd codec 3 failed");
1829 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1830 omx_shed_input_port)) {
1831 Log::getInstance()->log("Video", Log::DEBUG,
1832 "flush cmd shed 4 failed");
1835 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1836 omx_codec_output_port, NULL);
1837 if (error != OMX_ErrorNone) {
1838 Log::getInstance()->log("Video", Log::DEBUG,
1839 "OMX_Flush codec out 5 failed %x", error);
1843 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1844 omx_deint_input_port, NULL);
1845 if (error != OMX_ErrorNone) {
1846 Log::getInstance()->log("Video", Log::DEBUG,
1847 "OMX_Flush deint in 6 failed %x", error);
1851 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1852 omx_codec_output_port)) {
1853 Log::getInstance()->log("Video", Log::DEBUG,
1854 "flush cmd codec 7 failed");
1857 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1858 omx_deint_input_port)) {
1859 Log::getInstance()->log("Video", Log::DEBUG,
1860 "flush cmd deint 8 failed");
1864 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1865 omx_deint_output_port, NULL);
1866 if (error != OMX_ErrorNone) {
1867 Log::getInstance()->log("Video", Log::DEBUG,
1868 "OMX_Flush deint out 9 failed %x", error);
1872 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1873 omx_shed_input_port, NULL);
1874 if (error != OMX_ErrorNone) {
1875 Log::getInstance()->log("Video", Log::DEBUG,
1876 "OMX_Flush shed in 10 failed %x", error);
1880 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1881 omx_deint_output_port)) {
1882 Log::getInstance()->log("Video", Log::DEBUG,
1883 "flush cmd deint 11 failed");
1886 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1887 omx_shed_input_port)) {
1888 Log::getInstance()->log("Video", Log::DEBUG,
1889 "flush cmd shed 12 failed");
1899 error = OMX_SendCommand(omx_vid_rend, OMX_CommandFlush,
1900 omx_rend_input_port, NULL);
1901 if (error != OMX_ErrorNone) {
1902 Log::getInstance()->log("Video", Log::DEBUG,
1903 "OMX_Flush rend in failed %x", error);
1907 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1908 omx_shed_output_port, NULL);
1909 if (error != OMX_ErrorNone) {
1910 Log::getInstance()->log("Video", Log::DEBUG,
1911 "OMX_Flush shed out failed %x", error);
1917 if (!CommandFinished(omx_vid_rend, OMX_CommandFlush,
1918 omx_rend_input_port)) {
1919 Log::getInstance()->log("Video", Log::DEBUG,
1920 "flush cmd shed rend failed");
1923 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1924 omx_shed_output_port)) {
1925 Log::getInstance()->log("Video", Log::DEBUG,
1926 "flush cmd shed rend failed");
1931 int VideoOMX::DeAllocateCodecsOMX()
1933 OMX_ERRORTYPE error;
1935 Log::getInstance()->log("Video", Log::DEBUG, "enter deallocatecodecsomx");
1937 if (cur_input_buf_omx) {
1938 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_EOS;
1939 OMX_ERRORTYPE error=ProtOMXEmptyThisBuffer(omx_vid_dec,cur_input_buf_omx);
1940 if (error!=OMX_ErrorNone) {
1941 Log::getInstance()->log("Video", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error);
1944 cur_input_buf_omx=NULL;//write out old data
1949 // first stop the omx elements
1950 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1951 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1954 clock_mutex.Unlock();
1960 if (!ChangeComponentState(omx_vid_deint, OMX_StateIdle)) {
1961 Log::getInstance()->log("Video", Log::DEBUG,
1962 "vid_deint ChangeComponentState");
1968 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1969 Log::getInstance()->log("Video", Log::DEBUG, "vid_shed ChangeComponentState");
1973 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1974 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1980 // TODO proper deinit sequence
1981 // first flush all buffers
1982 FlushRenderingPipe();
1988 error=OMX_SendCommand(omx_clock,OMX_CommandFlush, omx_clock_output_port, NULL);
1989 if (error!=OMX_ErrorNone){
1990 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush clock out failed %x", error);
1994 error=OMX_SendCommand(omx_vid_sched,OMX_CommandFlush, omx_shed_clock_port, NULL);
1995 if (error!=OMX_ErrorNone){
1996 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush shed clock failed %x", error);
2000 if (!CommandFinished(omx_clock,OMX_CommandFlush,omx_clock_output_port) ||
2001 !CommandFinished(omx_vid_sched,OMX_CommandFlush,omx_shed_clock_port)) {
2002 Log::getInstance()->log("Video", Log::DEBUG, "flush cmd clock shed failed");
2008 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
2009 omx_codec_input_port, NULL);
2010 if (error != OMX_ErrorNone) {
2011 Log::getInstance()->log("Video", Log::DEBUG,
2012 "OMX_Flush codec out failed %x", error);
2019 DestroyInputBufsOMX();
2022 if (!DisablePort(omx_vid_sched,omx_shed_output_port,true)) {
2023 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 2 ");
2025 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true)) {
2026 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 1");
2032 if (!DisablePort(omx_vid_dec,omx_codec_output_port,true)) {
2033 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6");
2038 if (!DisablePort(omx_vid_dec,omx_codec_input_port,true)) {
2039 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7");
2043 if (!DisablePort(omx_vid_deint,omx_deint_output_port,true)) {
2044 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6a");
2049 if (!DisablePort(omx_vid_deint,omx_deint_input_port,true)) {
2050 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7a");
2056 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true)) {
2057 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 3");
2060 if (!DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
2061 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 4");
2064 if (!DisablePort(omx_clock,omx_clock_output_port,true)) {
2065 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 5");
2071 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,NULL,NULL);
2072 if (error!=OMX_ErrorNone) {
2073 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2078 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_input_port,NULL,NULL);
2079 if (error!=OMX_ErrorNone) {
2080 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2084 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,NULL,NULL);
2085 if (error!=OMX_ErrorNone) {
2086 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2090 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_input_port,NULL,NULL);
2091 if (error!=OMX_ErrorNone) {
2092 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2097 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,NULL,NULL);
2098 if (error!=OMX_ErrorNone) {
2099 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2103 error=OMX_SetupTunnel(omx_vid_rend,omx_rend_input_port,NULL,NULL);
2104 if (error!=OMX_ErrorNone) {
2105 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2110 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,NULL,NULL);
2111 if (error!=OMX_ErrorNone) {
2112 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2116 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_clock_port,NULL,NULL);
2117 if (error!=OMX_ErrorNone) {
2118 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2125 error=OMX_FreeHandle(omx_vid_dec);
2126 error=OMX_FreeHandle(omx_vid_sched);
2127 error=OMX_FreeHandle(omx_vid_rend);
2128 if (dodeint) error=OMX_FreeHandle(omx_vid_deint);
2130 clock_mutex.Unlock();
2132 if (error!=OMX_ErrorNone) {
2133 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2135 } else clock_mutex.Unlock();
2136 Log::getInstance()->log("Video", Log::DEBUG, "leave deallocate codecs OMX");
2142 void VideoOMX::destroyClock()
2145 if (clock_references>0) {
2147 if (clock_references==0) {
2148 OMX_ERRORTYPE error;
2149 Log::getInstance()->log("Video", Log::DEBUG, "destroy omx clock");
2150 error=OMX_FreeHandle(omx_clock);
2151 if (error!=OMX_ErrorNone) {
2152 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2157 clock_mutex.Unlock();
2161 int VideoOMX::stop()
2163 if (!initted) return 0;
2166 //Check if libav mode
2167 DeAllocateCodecsOMX();
2172 // if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
2176 int VideoOMX::reset()
2178 if (!initted) return 0;
2181 DeAllocateCodecsOMX();
2182 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
2186 int VideoOMX::pause()
2188 if (!initted) return 0;
2189 Log::getInstance()->log("Video", Log::DEBUG, "enter pause");
2191 // ignore it audio handles this
2195 int VideoOMX::unPause() // FIXME get rid - same as play!! Not here!
2197 if (!initted) return 0;
2198 Log::getInstance()->log("Video", Log::DEBUG, "enter unpause");
2201 //ignore it audio handles this
2206 int VideoOMX::fastForward()
2208 if (!initted) return 0;
2210 // if (ioctl(fdVideo, AV_SET_VID_libavWD, 1) != 0) return 0;
2214 int VideoOMX::unFastForward()
2216 if (!initted) return 0;
2218 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
2220 //// if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
2224 int VideoOMX::attachFrameBuffer()
2226 if (!initted) return 0;
2228 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2232 int VideoOMX::blank(void)
2234 // if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
2235 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2239 ULLONG VideoOMX::getCurrentTimestamp() {
2242 long long ncur_clock_time = cur_clock_time;
2246 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2247 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2249 OMX_ERRORTYPE error;
2250 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
2251 memset(&clock_conf, 0, sizeof(clock_conf));
2252 clock_conf.nSize = sizeof(clock_conf);
2253 clock_conf.nVersion.nVersion = OMX_VERSION;
2254 error= OMX_GetConfig(omx_clock, OMX_IndexConfigTimeClockState,
2256 if (error != OMX_ErrorNone) {
2257 Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp IndexConfigTimeClockState failed %x",error);
2260 if (clock_conf.eState == OMX_TIME_ClockStateRunning) {
2262 OMX_TIME_CONFIG_TIMESTAMPTYPE cur_time_stamp;
2263 memset(&cur_time_stamp, 0, sizeof(cur_time_stamp));
2264 cur_time_stamp.nSize = sizeof(cur_time_stamp);
2265 cur_time_stamp.nVersion.nVersion = OMX_VERSION;
2266 cur_time_stamp.nPortIndex = omx_clock_output_port;
2267 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2269 if (error != OMX_ErrorNone) {
2270 Log::getInstance()->log("Video",Log::DEBUG,"getCurrentTimestamp OMX_IndexConfigTimeCurrentMediaTime failed %x",error);
2272 long long temp = cur_time_stamp.nTimestamp.nLowPart
2273 | ((long long) cur_time_stamp.nTimestamp.nHighPart << 32);
2274 ncur_clock_time = cur_clock_time = temp * 10LL;
2277 clock_mutex.Unlock();
2278 pthread_setcancelstate(oldcancelstate, NULL);
2279 pthread_setcanceltype(oldcanceltype, NULL);
2282 //ncur_clock_time -= startoffset;
2283 ncur_clock_time -= lastreftimeOMX;
2284 long long result = lastreftimePTS;
2285 if (lastreftimePTS==0) return 0; // invalid time
2286 result += (long long) (ncur_clock_time / 10000LL * 90LL);
2288 result = (1LL << 33) - result;
2289 //Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp %lld %lld %lld %lld %lld %lld",ncur_clock_time,cur_clock_time,lastreftimeOMX,lastreftimePTS,result,startoffset);
2297 ULONG VideoOMX::timecodeToFrameNumber(ULLONG timecode)
2299 if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25);
2300 else return (ULONG)(((double)timecode / (double)90000) * (double)30);
2305 int VideoOMX::test()
2310 // return ioctl(fdVideo, AV_SET_VID_STC, &stc);
2317 int VideoOMX::test2()
2325 long long VideoOMX::SetStartOffset(long long curreftime, bool *rsync)
2329 startoffset=curreftime;//offset is set for audio
2331 offsetvideonotset=false;
2333 if (offsetvideonotset) {
2334 offsetvideonotset=false;
2337 if ( (curreftime-lastrefvideotime)>10000000LL
2338 || (curreftime-lastrefvideotime)<-10000000LL) {//if pts jumps to big resync
2339 startoffset+=curreftime-lastrefvideotime;
2340 lastrefaudiotime+=curreftime-lastrefvideotime;
2342 offsetaudionotset=true;
2349 lastrefvideotime=curreftime;
2355 long long VideoOMX::SetStartAudioOffset(long long curreftime, bool *rsync)
2359 startoffset=curreftime;
2361 offsetaudionotset=false;
2363 if (offsetaudionotset) {
2364 offsetaudionotset=false;
2367 if ( (curreftime-lastrefaudiotime)>10000000LL
2368 || (curreftime-lastrefaudiotime)<-10000000LL) {//if pts jumps to big resync
2369 startoffset+=curreftime-lastrefaudiotime;
2370 lastrefvideotime+=curreftime-lastrefaudiotime;
2372 offsetvideonotset=true;
2378 lastrefaudiotime=curreftime;
2383 void VideoOMX::ResetTimeOffsets() {
2384 offsetnotset=true; //called from demuxer
2385 offsetvideonotset=true;
2386 offsetaudionotset=true;
2395 void VideoOMX::DeinterlaceFix()
2399 Demuxer* demux=Demuxer::getInstance();
2400 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2401 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2403 OMX_ERRORTYPE error;
2404 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
2405 memset(&port_def_type,0,sizeof(port_def_type));
2406 port_def_type.nSize=sizeof(port_def_type);
2407 port_def_type.nVersion.nVersion=OMX_VERSION;
2408 port_def_type.nPortIndex=omx_codec_output_port;
2410 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
2411 if (error != OMX_ErrorNone) {
2412 Log::getInstance()->log("Video", Log::DEBUG,
2413 "OMX_IndexParamPortDefinition fix failed %x", error);
2414 clock_mutex.Unlock();
2418 if (port_def_type.format.video.nFrameWidth == demux->getHorizontalSize()
2419 && port_def_type.format.video.nFrameHeight == demux->getVerticalSize()){
2420 Log::getInstance()->log("Video", Log::DEBUG,
2421 "Deinit first frame fix");
2422 deint_first_frame=false;
2424 WaitForEvent(omx_vid_dec,OMX_EventPortSettingsChanged);
2425 DisablePort(omx_vid_dec,omx_codec_output_port,false);
2426 DisablePort(omx_vid_sched,omx_shed_input_port,false);
2427 DisablePort(omx_vid_deint,omx_deint_output_port,false);
2428 DisablePort(omx_vid_deint,omx_deint_input_port,false);
2430 port_def_type.nPortIndex=omx_deint_input_port;
2431 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2433 if (error != OMX_ErrorNone) {
2434 Log::getInstance()->log("Video", Log::DEBUG,
2435 "Set OMX_IndexParamPortDefinition1 failed %x", error);
2436 clock_mutex.Unlock();
2437 pthread_setcancelstate(oldcancelstate, NULL);
2438 pthread_setcanceltype(oldcanceltype, NULL);
2442 port_def_type.nPortIndex=omx_deint_output_port;
2443 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2445 if (error != OMX_ErrorNone) {
2446 Log::getInstance()->log("Video", Log::DEBUG,
2447 "Set OMX_IndexParamPortDefinition2 failed %x", error);
2448 clock_mutex.Unlock();
2449 pthread_setcancelstate(oldcancelstate, NULL);
2450 pthread_setcanceltype(oldcanceltype, NULL);
2455 EnablePort(omx_vid_dec,omx_codec_output_port,false);
2456 EnablePort(omx_vid_deint,omx_deint_input_port,false);
2457 EnablePort(omx_vid_deint,omx_deint_output_port,false);
2458 EnablePort(omx_vid_sched,omx_shed_input_port,false);
2460 clock_mutex.Unlock();
2461 pthread_setcancelstate(oldcancelstate, NULL);
2462 pthread_setcanceltype(oldcanceltype, NULL);
2469 void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer)
2472 OMX_ERRORTYPE error = ProtOMXEmptyThisBuffer(omx_vid_dec, buffer);
2473 if (error != OMX_ErrorNone) {
2474 Log::getInstance()->log("Video", Log::DEBUG,
2475 "OMX_EmptyThisBuffer failed %x", error);
2477 if (deint_first_frame && dodeint) DeinterlaceFix();
2481 OMX_ERRORTYPE VideoOMX::ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer)
2483 // protect the call to empty this buffer
2486 /* long long temp =buffer->nTimeStamp.nLowPart
2487 | ((long long) buffer->nTimeStamp.nHighPart << 32);*/
2489 //pthread_testcancel();
2490 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2491 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2494 /* OMX_ERRORTYPE error;
2495 OMX_TIME_CONFIG_TIMESTAMPTYPE timestamp;
2496 memset(×tamp, 0, sizeof(timestamp));
2497 timestamp.nSize = sizeof(timestamp);
2498 timestamp.nVersion.nVersion = OMX_VERSION;
2499 timestamp.nPortIndex =omx_clock_output_port;
2501 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2504 if (error != OMX_ErrorNone) {
2505 Log::getInstance()->log("Audio", Log::DEBUG,
2506 "Init OMX_IndexConfigAudioRenderingLatencyfailed %x %d", error,
2507 omx_rend_input_port);
2509 long long temp2 =timestamp.nTimestamp.nLowPart
2510 | ((long long) timestamp.nTimestamp.nHighPart << 32);
2513 Log::getInstance()->log("Video", Log::NOTICE, "OMXETB %x %lld %lld %x",handle,temp,temp2,buffer->nFlags);*/
2514 OMX_ERRORTYPE ret_val;
2515 ret_val=OMX_EmptyThisBuffer(handle,buffer);
2516 clock_mutex.Unlock();
2517 pthread_setcancelstate(oldcancelstate, NULL);
2518 pthread_setcanceltype(oldcanceltype, NULL);
2519 //pthread_testcancel();
2523 bool VideoOMX::detectIFrame(const UCHAR *buffer,unsigned int length)
2525 const UCHAR* curbuf=buffer;
2526 const UCHAR* curbufend=buffer+length;
2527 unsigned int detector=0xFFFFFFFF;
2528 bool gotaud=false; // have seen access unit delimiter
2530 while (curbuf!=curbufend) {
2534 if (detector==0x00000109) {
2536 detector=0xFFFFFFFF;
2537 } else if (gotaud &&detector==0x00000001) {
2539 if (curbuf!=curbufend) {
2540 unsigned char picttype=(*curbuf)& 0x1F;
2541 return picttype==0x07;
2545 if (detector==0x00000100) {
2547 if (curbuf==curbufend) return false;
2549 if (curbuf==curbufend) return false;
2550 unsigned char picttype=((*curbuf) >> 3) & 0x07;
2557 return false; // no frame found
2560 void VideoOMX::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
2563 mediapackets.clear();
2564 list<MediaPacket>::const_iterator begin=mplist.begin();
2565 list<MediaPacket>::const_iterator itty=mplist.begin();
2566 advance(itty,min(mplist.size(),10));
2567 mediapackets.insert(mediapackets.begin(),begin,itty);//front
2571 UINT VideoOMX::DeliverMediaSample(UCHAR* buffer, UINT *samplepos)
2574 while (consumed<mediapackets.size()) {
2575 DeliverMediaPacket(mediapackets[consumed], buffer, samplepos);
2576 if (*samplepos == mediapackets[consumed].length) {
2580 } else return consumed;
2585 UINT VideoOMX::DeliverMediaPacket(MediaPacket packet,
2586 const UCHAR* buffer,
2589 if (packet.type == MPTYPE_VIDEO_H264)
2599 //Later add fail back code for libav
2601 *samplepos+=packet.length;
2602 return packet.length;
2606 if (!omx_running) return 0; // if we are not runnig do not do this
2607 if (isClockPaused()) return 0; //Block if we pause
2609 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 1");
2610 //Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX time %lld",packet.presentation_time);
2613 OMX_ERRORTYPE error;
2615 /*First Check, if we have an video sample*/
2619 return 0; //Not in iframe mode!
2623 if (packet.disconti) {
2625 if (cur_input_buf_omx) {
2626 PutBufferToPres(cur_input_buf_omx);
2627 cur_input_buf_omx=NULL;
2630 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2");
2631 /*Inspect PES-Header */
2633 // OMX_STATETYPE temp_state;
2634 // OMX_GetState(omx_vid_dec,&temp_state);
2636 if (*samplepos==0) {//stripheader
2637 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
2638 // if (h264) Log::getInstance()->log("Video", Log::DEBUG, "PES info %x %x %x %x",
2639 // buffer[packet.pos_buffer+0],buffer[packet.pos_buffer+1],buffer[packet.pos_buffer+2],buffer[packet.pos_buffer+3]);
2640 *samplepos+=headerstrip;
2641 if ( packet.synched ) {
2642 if (!firstsynched) {
2643 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2a");
2644 // check if this is an I frame, the decoder does not like non I frames at startup!
2645 if (!detectIFrame(buffer,packet.length)) {
2646 *samplepos=packet.length;//if we have not processed at least one
2647 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 3");
2648 return packet.length;//synched packet ignore it!
2651 if (cur_input_buf_omx) {
2652 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4a");
2653 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_ENDOFFRAME;
2654 PutBufferToPres(cur_input_buf_omx);
2655 cur_input_buf_omx=NULL;//write out old data
2657 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4b");
2662 if (!firstsynched) {//
2663 *samplepos=packet.length;//if we have not processed at least one
2664 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 5");
2665 return packet.length;//synched packet ignore it!
2669 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 6");
2670 if (!cur_input_buf_omx) {
2671 input_bufs_omx_mutex.Lock();
2672 if (input_bufs_omx_free.size()==0) {
2673 input_bufs_omx_mutex.Unlock();
2674 //Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample");
2675 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 7");
2676 return 0; // we do not have a free media sample
2679 cur_input_buf_omx=input_bufs_omx_free.front();
2680 cur_input_buf_omx->nFilledLen=0;
2681 cur_input_buf_omx->nOffset=0;
2682 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2683 input_bufs_omx_free.pop_front();
2684 input_bufs_omx_mutex.Unlock();
2690 if (cur_input_buf_omx->nFilledLen==0) {//will only be changed on first packet
2691 if (packet.synched) {
2692 // Log::getInstance()->log("Video", Log::DEBUG, "packet synched marker");
2694 //lastreftimePTS=packet.pts;
2695 if (omx_first_frame) { // TODO time
2696 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_STARTTIME;
2697 Log::getInstance()->log("Video", Log::DEBUG, "Starttime");
2698 omx_first_frame=false;
2700 cur_input_buf_omx->nFlags=0;
2701 //cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_TIME_UNKNOWN;
2703 lastreftimeOMX=packet.presentation_time;
2704 // Log::getInstance()->log("Video", Log::DEBUG, "Time code %lld pts %lld", lastreftimeOMX,packet.pts);
2705 lastreftimePTS=packet.pts;
2706 cur_input_buf_omx->nTimeStamp=intToOMXTicks(lastreftimeOMX/10LL); // the clock component is faulty;
2710 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2711 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2712 //Log::getInstance()->log("Video", Log::DEBUG, "packet unsynched marker");
2714 if (packet.disconti) cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_DISCONTINUITY;
2719 unsigned int haveToCopy=packet.length-*samplepos;
2720 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 8");
2722 while (haveToCopy> (cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen)) {
2723 //Log::getInstance()->log("Video", Log::DEBUG, "Big buffer %d %d %d",packet.length,cur_input_buf_omx->nAllocLen,cur_input_buf_omx->nFilledLen);
2724 unsigned int cancopy=cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen;
2725 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,buffer+packet.pos_buffer+*samplepos,cancopy);
2726 haveToCopy-=cancopy;
2727 cur_input_buf_omx->nFilledLen+=cancopy;
2728 *samplepos+=cancopy;
2729 // push old buffer out
2730 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 9");
2732 PutBufferToPres(cur_input_buf_omx);
2733 cur_input_buf_omx=NULL;
2735 input_bufs_omx_mutex.Lock();
2736 if (input_bufs_omx_free.size()==0) {
2737 input_bufs_omx_mutex.Unlock();
2738 // Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample2");
2739 return *samplepos; // we do not have a free media sample
2741 cur_input_buf_omx=input_bufs_omx_free.front();
2742 cur_input_buf_omx->nFilledLen=0;
2743 cur_input_buf_omx->nOffset=0;
2744 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2745 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2746 input_bufs_omx_free.pop_front();
2747 input_bufs_omx_mutex.Unlock();
2748 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 10");
2751 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,
2752 buffer+packet.pos_buffer+*samplepos,haveToCopy);
2753 cur_input_buf_omx->nFilledLen+=haveToCopy;
2755 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 11");
2757 *samplepos+=haveToCopy;
2766 bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) {
2767 if (!omx_running) return false;
2769 EnterIframePlayback();
2771 int haveToCopy = length;
2773 if (!cur_input_buf_omx) {
2774 input_bufs_omx_mutex.Lock();
2775 if (input_bufs_omx_free.size() == 0) {
2776 input_bufs_omx_mutex.Unlock();
2777 // Log::getInstance()->log("Video", Log::DEBUG,
2778 // "Deliver MediaPacket no free sample");
2779 return false; // we do not have a free media sample
2782 cur_input_buf_omx = input_bufs_omx_free.front();
2783 cur_input_buf_omx->nFilledLen = 0;
2784 cur_input_buf_omx->nOffset = 0;
2785 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2786 input_bufs_omx_free.pop_front();
2787 input_bufs_omx_mutex.Unlock();
2791 unsigned int pattern, packet_length;
2792 unsigned int headerstrip = 0;
2797 //Now we strip the pes header
2798 pattern = (buffer[0] << 16) | (buffer[1] << 8) | (buffer[2]);
2799 while (read_pos + 7 <= length) {
2800 pattern = ((pattern << 8) & 0xFFFFFFFF) | buffer[read_pos + 3];
2801 if (pattern < 0x000001E0 || pattern > 0x000001EF) {
2805 headerstrip = buffer[read_pos + 8] + 9/*is this right*/;
2806 packet_length = ((buffer[read_pos + 4] << 8)
2807 | (buffer[read_pos + 5])) + 6;
2808 if (read_pos + packet_length > length)
2811 if ((headerstrip < packet_length)
2812 && (cur_input_buf_omx->nFilledLen + packet_length
2813 - headerstrip) > cur_input_buf_omx->nAllocLen) {
2815 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2818 cur_input_buf_omx->nFlags
2819 |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2822 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2823 PutBufferToPres(cur_input_buf_omx);
2824 cur_input_buf_omx = NULL;
2826 if (!cur_input_buf_omx) {
2828 while (count < 100 && omx_running && iframemode) {
2831 input_bufs_omx_mutex.Lock();
2832 if (input_bufs_omx_free.size() == 0) {
2833 input_bufs_omx_mutex.Unlock();
2834 // Log::getInstance()->log("Video", Log::DEBUG,
2835 // "Ifrane no free sample");
2837 if (!omx_running) return false;
2840 cur_input_buf_omx = input_bufs_omx_free.front();
2841 cur_input_buf_omx->nFilledLen = 0;
2842 cur_input_buf_omx->nOffset = 0;
2843 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2844 cur_input_buf_omx->nFlags|= OMX_BUFFERFLAG_TIME_UNKNOWN;
2845 input_bufs_omx_free.pop_front();
2846 input_bufs_omx_mutex.Unlock();
2849 if (!cur_input_buf_omx)
2854 if (packet_length > headerstrip) {
2856 cur_input_buf_omx->pBuffer
2857 + cur_input_buf_omx->nFilledLen,
2858 buffer + read_pos + headerstrip,
2859 packet_length - headerstrip);
2860 cur_input_buf_omx->nFilledLen += packet_length
2863 read_pos += packet_length;
2865 pattern = (buffer[read_pos] << 16)
2866 | (buffer[read_pos + 1] << 8) | (buffer[read_pos + 2]);
2872 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2875 cur_input_buf_omx->nFlags |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2878 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2880 PutBufferToPres(cur_input_buf_omx);
2881 cur_input_buf_omx = NULL;
2884 MILLISLEEP(40); //Block a bit
2888 int VideoOMX::EnterIframePlayback()
2890 Log::getInstance()->log("Video", Log::DEBUG,
2891 "EnterIframePlayback");
2892 if (cur_input_buf_omx) {
2893 PutBufferToPres(cur_input_buf_omx);
2894 cur_input_buf_omx = NULL;
2896 Log::getInstance()->log("Video", Log::DEBUG,
2897 "EnterIframePlayback 2");
2898 ((AudioOMX*)Audio::getInstance())->DeAllocateCodecsOMX();
2899 DeAllocateCodecsOMX();
2900 AllocateCodecsOMX();
2901 Log::getInstance()->log("Video", Log::DEBUG,
2902 "leave IframePlayback");