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[200];
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,
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,
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();
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
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);
1705 int VideoOMX::PrepareInputBufsOMX() //needs to be called with locked mutex
1707 OMX_ERRORTYPE error;
1708 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
1709 memset(&port_def_type,0,sizeof(port_def_type));
1710 port_def_type.nSize=sizeof(port_def_type);
1711 port_def_type.nVersion.nVersion=OMX_VERSION;
1712 port_def_type.nPortIndex=omx_codec_input_port;
1714 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1716 if (error!=OMX_ErrorNone){
1717 Log::getInstance()->log("Video", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
1719 /* Log::getInstance()->log("Video", Log::DEBUG, "Port para %d %d %d %d %d %d %d", port_def_type.nBufferCountActual,
1720 port_def_type.nBufferCountMin,port_def_type.nBufferSize,port_def_type.bEnabled,port_def_type.bPopulated,
1721 port_def_type.bBuffersContiguous,port_def_type.nBufferAlignment);*/
1723 port_def_type.nBufferCountActual=100;
1724 port_def_type.nBufferSize=max(port_def_type.nBufferSize,200000); // for transcoder important
1726 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1728 if (error!=OMX_ErrorNone){
1729 Log::getInstance()->log("Video", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
1733 error=OMX_SendCommand(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port,0);
1734 if (error!=OMX_ErrorNone){
1735 Log::getInstance()->log("Video", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
1739 input_bufs_omx_mutex.Lock();
1740 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
1742 // unsigned char* new_buffer_data=(unsigned char*)malloc(port_def_type.nbufferSize);
1743 OMX_BUFFERHEADERTYPE *buf_head=NULL;
1744 /* error=OMX_Usebuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nbufferSize,new_buffer_data);
1745 if (error!=OMX_ErrorNone){
1746 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_Usebuffer failed %x", error);
1747 input_bufs_omx_mutex.Unlock();
1750 error=OMX_AllocateBuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nBufferSize);
1751 if (error!=OMX_ErrorNone){
1752 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_AllocateBuffer failed %x", error);
1753 input_bufs_omx_mutex.Unlock();
1756 input_bufs_omx_all.push_back(buf_head);
1757 input_bufs_omx_free.push_back(buf_head);
1759 omx_first_frame=true;
1762 cur_input_buf_omx=NULL;
1763 input_bufs_omx_mutex.Unlock();
1766 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark3");
1767 if (!CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port)) {
1770 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark4");
1775 int VideoOMX::DestroyInputBufsOMX() //need s to be called with locked mutex
1777 OMX_ERRORTYPE error;
1779 cur_input_buf_omx=NULL;
1780 input_bufs_omx_mutex.Lock();
1781 for (int i=0; i< input_bufs_omx_all.size();i++) {
1782 // free(input_bufs_omx_all[i]->pBuffer);
1783 // input_bufs_omx_all[i]->pBuffer=NULL;
1784 error=OMX_FreeBuffer(omx_vid_dec,omx_codec_input_port,input_bufs_omx_all[i]);
1785 if (error!=OMX_ErrorNone){
1786 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
1787 input_bufs_omx_mutex.Unlock();
1792 input_bufs_omx_all.clear();
1793 input_bufs_omx_free.clear();
1794 input_bufs_omx_mutex.Unlock();
1799 int VideoOMX::FlushRenderingPipe()
1801 OMX_ERRORTYPE error;
1805 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1806 omx_codec_output_port, NULL);
1807 if (error != OMX_ErrorNone) {
1808 Log::getInstance()->log("Video", Log::DEBUG,
1809 "OMX_Flush codec out 1 failed %x", error);
1813 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1814 omx_shed_input_port, NULL);
1815 if (error != OMX_ErrorNone) {
1816 Log::getInstance()->log("Video", Log::DEBUG,
1817 "OMX_Flush shed in 2 failed %x", error);
1821 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1822 omx_codec_output_port)) {
1823 Log::getInstance()->log("Video", Log::DEBUG,
1824 "flush cmd codec 3 failed");
1827 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1828 omx_shed_input_port)) {
1829 Log::getInstance()->log("Video", Log::DEBUG,
1830 "flush cmd shed 4 failed");
1833 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1834 omx_codec_output_port, NULL);
1835 if (error != OMX_ErrorNone) {
1836 Log::getInstance()->log("Video", Log::DEBUG,
1837 "OMX_Flush codec out 5 failed %x", error);
1841 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1842 omx_deint_input_port, NULL);
1843 if (error != OMX_ErrorNone) {
1844 Log::getInstance()->log("Video", Log::DEBUG,
1845 "OMX_Flush deint in 6 failed %x", error);
1849 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1850 omx_codec_output_port)) {
1851 Log::getInstance()->log("Video", Log::DEBUG,
1852 "flush cmd codec 7 failed");
1855 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1856 omx_deint_input_port)) {
1857 Log::getInstance()->log("Video", Log::DEBUG,
1858 "flush cmd deint 8 failed");
1862 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1863 omx_deint_output_port, NULL);
1864 if (error != OMX_ErrorNone) {
1865 Log::getInstance()->log("Video", Log::DEBUG,
1866 "OMX_Flush deint out 9 failed %x", error);
1870 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1871 omx_shed_input_port, NULL);
1872 if (error != OMX_ErrorNone) {
1873 Log::getInstance()->log("Video", Log::DEBUG,
1874 "OMX_Flush shed in 10 failed %x", error);
1878 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1879 omx_deint_output_port)) {
1880 Log::getInstance()->log("Video", Log::DEBUG,
1881 "flush cmd deint 11 failed");
1884 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1885 omx_shed_input_port)) {
1886 Log::getInstance()->log("Video", Log::DEBUG,
1887 "flush cmd shed 12 failed");
1897 error = OMX_SendCommand(omx_vid_rend, OMX_CommandFlush,
1898 omx_rend_input_port, NULL);
1899 if (error != OMX_ErrorNone) {
1900 Log::getInstance()->log("Video", Log::DEBUG,
1901 "OMX_Flush rend in failed %x", error);
1905 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1906 omx_shed_output_port, NULL);
1907 if (error != OMX_ErrorNone) {
1908 Log::getInstance()->log("Video", Log::DEBUG,
1909 "OMX_Flush shed out failed %x", error);
1915 if (!CommandFinished(omx_vid_rend, OMX_CommandFlush,
1916 omx_rend_input_port)) {
1917 Log::getInstance()->log("Video", Log::DEBUG,
1918 "flush cmd shed rend failed");
1921 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1922 omx_shed_output_port)) {
1923 Log::getInstance()->log("Video", Log::DEBUG,
1924 "flush cmd shed rend failed");
1929 int VideoOMX::DeAllocateCodecsOMX()
1931 OMX_ERRORTYPE error;
1933 Log::getInstance()->log("Video", Log::DEBUG, "enter deallocatecodecsomx");
1935 if (cur_input_buf_omx) {
1936 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_EOS;
1937 OMX_ERRORTYPE error=ProtOMXEmptyThisBuffer(omx_vid_dec,cur_input_buf_omx);
1938 if (error!=OMX_ErrorNone) {
1939 Log::getInstance()->log("Video", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error);
1942 cur_input_buf_omx=NULL;//write out old data
1947 // first stop the omx elements
1948 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1949 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1952 clock_mutex.Unlock();
1958 if (!ChangeComponentState(omx_vid_deint, OMX_StateIdle)) {
1959 Log::getInstance()->log("Video", Log::DEBUG,
1960 "vid_deint ChangeComponentState");
1966 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1967 Log::getInstance()->log("Video", Log::DEBUG, "vid_shed ChangeComponentState");
1971 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1972 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1978 // TODO proper deinit sequence
1979 // first flush all buffers
1980 FlushRenderingPipe();
1986 error=OMX_SendCommand(omx_clock,OMX_CommandFlush, omx_clock_output_port, NULL);
1987 if (error!=OMX_ErrorNone){
1988 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush clock out failed %x", error);
1992 error=OMX_SendCommand(omx_vid_sched,OMX_CommandFlush, omx_shed_clock_port, NULL);
1993 if (error!=OMX_ErrorNone){
1994 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush shed clock failed %x", error);
1998 if (!CommandFinished(omx_clock,OMX_CommandFlush,omx_clock_output_port) ||
1999 !CommandFinished(omx_vid_sched,OMX_CommandFlush,omx_shed_clock_port)) {
2000 Log::getInstance()->log("Video", Log::DEBUG, "flush cmd clock shed failed");
2006 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
2007 omx_codec_input_port, NULL);
2008 if (error != OMX_ErrorNone) {
2009 Log::getInstance()->log("Video", Log::DEBUG,
2010 "OMX_Flush codec out failed %x", error);
2017 DestroyInputBufsOMX();
2020 if (!DisablePort(omx_vid_sched,omx_shed_output_port,true)) {
2021 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 2 ");
2023 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true)) {
2024 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 1");
2030 if (!DisablePort(omx_vid_dec,omx_codec_output_port,true)) {
2031 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6");
2036 if (!DisablePort(omx_vid_dec,omx_codec_input_port,true)) {
2037 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7");
2041 if (!DisablePort(omx_vid_deint,omx_deint_output_port,true)) {
2042 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6a");
2047 if (!DisablePort(omx_vid_deint,omx_deint_input_port,true)) {
2048 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7a");
2054 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true)) {
2055 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 3");
2058 if (!DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
2059 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 4");
2062 if (!DisablePort(omx_clock,omx_clock_output_port,true)) {
2063 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 5");
2069 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,NULL,NULL);
2070 if (error!=OMX_ErrorNone) {
2071 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2076 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_input_port,NULL,NULL);
2077 if (error!=OMX_ErrorNone) {
2078 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2082 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,NULL,NULL);
2083 if (error!=OMX_ErrorNone) {
2084 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2088 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_input_port,NULL,NULL);
2089 if (error!=OMX_ErrorNone) {
2090 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2095 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,NULL,NULL);
2096 if (error!=OMX_ErrorNone) {
2097 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2101 error=OMX_SetupTunnel(omx_vid_rend,omx_rend_input_port,NULL,NULL);
2102 if (error!=OMX_ErrorNone) {
2103 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2108 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,NULL,NULL);
2109 if (error!=OMX_ErrorNone) {
2110 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2114 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_clock_port,NULL,NULL);
2115 if (error!=OMX_ErrorNone) {
2116 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2123 error=OMX_FreeHandle(omx_vid_dec);
2124 error=OMX_FreeHandle(omx_vid_sched);
2125 error=OMX_FreeHandle(omx_vid_rend);
2126 if (dodeint) error=OMX_FreeHandle(omx_vid_deint);
2128 clock_mutex.Unlock();
2130 if (error!=OMX_ErrorNone) {
2131 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2133 } else clock_mutex.Unlock();
2134 Log::getInstance()->log("Video", Log::DEBUG, "leave deallocate codecs OMX");
2140 void VideoOMX::destroyClock()
2143 if (clock_references>0) {
2145 if (clock_references==0) {
2146 OMX_ERRORTYPE error;
2147 Log::getInstance()->log("Video", Log::DEBUG, "destroy omx clock");
2148 error=OMX_FreeHandle(omx_clock);
2149 if (error!=OMX_ErrorNone) {
2150 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2155 clock_mutex.Unlock();
2159 int VideoOMX::stop()
2161 if (!initted) return 0;
2164 //Check if libav mode
2165 DeAllocateCodecsOMX();
2170 // if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
2174 int VideoOMX::reset()
2176 if (!initted) return 0;
2179 DeAllocateCodecsOMX();
2180 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
2184 int VideoOMX::pause()
2186 if (!initted) return 0;
2187 Log::getInstance()->log("Video", Log::DEBUG, "enter pause");
2189 // ignore it audio handles this
2193 int VideoOMX::unPause() // FIXME get rid - same as play!! Not here!
2195 if (!initted) return 0;
2196 Log::getInstance()->log("Video", Log::DEBUG, "enter unpause");
2199 //ignore it audio handles this
2204 int VideoOMX::fastForward()
2206 if (!initted) return 0;
2208 // if (ioctl(fdVideo, AV_SET_VID_libavWD, 1) != 0) return 0;
2212 int VideoOMX::unFastForward()
2214 if (!initted) return 0;
2216 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
2218 //// if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
2222 int VideoOMX::attachFrameBuffer()
2224 if (!initted) return 0;
2226 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2230 int VideoOMX::blank(void)
2232 // if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
2233 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2237 ULLONG VideoOMX::getCurrentTimestamp() {
2240 long long ncur_clock_time = cur_clock_time;
2244 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2245 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2247 OMX_ERRORTYPE error;
2248 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
2249 memset(&clock_conf, 0, sizeof(clock_conf));
2250 clock_conf.nSize = sizeof(clock_conf);
2251 clock_conf.nVersion.nVersion = OMX_VERSION;
2252 error= OMX_GetConfig(omx_clock, OMX_IndexConfigTimeClockState,
2254 if (error != OMX_ErrorNone) {
2255 Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp IndexConfigTimeClockState failed %x",error);
2258 if (clock_conf.eState == OMX_TIME_ClockStateRunning) {
2260 OMX_TIME_CONFIG_TIMESTAMPTYPE cur_time_stamp;
2261 memset(&cur_time_stamp, 0, sizeof(cur_time_stamp));
2262 cur_time_stamp.nSize = sizeof(cur_time_stamp);
2263 cur_time_stamp.nVersion.nVersion = OMX_VERSION;
2264 cur_time_stamp.nPortIndex = omx_clock_output_port;
2265 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2267 if (error != OMX_ErrorNone) {
2268 Log::getInstance()->log("Video",Log::DEBUG,"getCurrentTimestamp OMX_IndexConfigTimeCurrentMediaTime failed %x",error);
2270 long long temp = cur_time_stamp.nTimestamp.nLowPart
2271 | ((long long) cur_time_stamp.nTimestamp.nHighPart << 32);
2272 ncur_clock_time = cur_clock_time = temp * 10LL;
2275 clock_mutex.Unlock();
2276 pthread_setcancelstate(oldcancelstate, NULL);
2277 pthread_setcanceltype(oldcanceltype, NULL);
2280 //ncur_clock_time -= startoffset;
2281 ncur_clock_time -= lastreftimeOMX;
2282 long long result = lastreftimePTS;
2283 if (lastreftimePTS==0) return 0; // invalid time
2284 result += (long long) (ncur_clock_time / 10000LL * 90LL);
2286 result = (1LL << 33) - result;
2287 //Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp %lld %lld %lld %lld %lld %lld",ncur_clock_time,cur_clock_time,lastreftimeOMX,lastreftimePTS,result,startoffset);
2295 ULONG VideoOMX::timecodeToFrameNumber(ULLONG timecode)
2297 if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25);
2298 else return (ULONG)(((double)timecode / (double)90000) * (double)30);
2303 int VideoOMX::test()
2308 // return ioctl(fdVideo, AV_SET_VID_STC, &stc);
2315 int VideoOMX::test2()
2323 long long VideoOMX::SetStartOffset(long long curreftime, bool *rsync)
2327 startoffset=curreftime;//offset is set for audio
2329 offsetvideonotset=false;
2331 if (offsetvideonotset) {
2332 offsetvideonotset=false;
2335 if ( (curreftime-lastrefvideotime)>10000000LL
2336 || (curreftime-lastrefvideotime)<-10000000LL) {//if pts jumps to big resync
2337 startoffset+=curreftime-lastrefvideotime;
2338 lastrefaudiotime+=curreftime-lastrefvideotime;
2340 offsetaudionotset=true;
2347 lastrefvideotime=curreftime;
2353 long long VideoOMX::SetStartAudioOffset(long long curreftime, bool *rsync)
2357 startoffset=curreftime;
2359 offsetaudionotset=false;
2361 if (offsetaudionotset) {
2362 offsetaudionotset=false;
2365 if ( (curreftime-lastrefaudiotime)>10000000LL
2366 || (curreftime-lastrefaudiotime)<-10000000LL) {//if pts jumps to big resync
2367 startoffset+=curreftime-lastrefaudiotime;
2368 lastrefvideotime+=curreftime-lastrefaudiotime;
2370 offsetvideonotset=true;
2376 lastrefaudiotime=curreftime;
2381 void VideoOMX::ResetTimeOffsets() {
2382 offsetnotset=true; //called from demuxer
2383 offsetvideonotset=true;
2384 offsetaudionotset=true;
2393 void VideoOMX::FirstFrameFix()
2397 Demuxer* demux=Demuxer::getInstance();
2398 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2399 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2401 OMX_ERRORTYPE error;
2402 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
2403 memset(&port_def_type,0,sizeof(port_def_type));
2404 port_def_type.nSize=sizeof(port_def_type);
2405 port_def_type.nVersion.nVersion=OMX_VERSION;
2406 port_def_type.nPortIndex=omx_codec_output_port;
2408 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
2409 if (error != OMX_ErrorNone) {
2410 Log::getInstance()->log("Video", Log::DEBUG,
2411 "OMX_IndexParamPortDefinition fix failed %x", error);
2412 clock_mutex.Unlock();
2416 if (port_def_type.format.video.nFrameWidth == demux->getHorizontalSize()
2417 && port_def_type.format.video.nFrameHeight == demux->getVerticalSize()){
2418 Log::getInstance()->log("Video", Log::DEBUG,
2419 "Deinit first frame fix");
2422 WaitForEvent(omx_vid_dec,OMX_EventPortSettingsChanged);
2423 DisablePort(omx_vid_dec,omx_codec_output_port,false);
2424 DisablePort(omx_vid_sched,omx_shed_input_port,false);
2426 DisablePort(omx_vid_deint,omx_deint_output_port,false);
2427 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);
2456 EnablePort(omx_vid_dec,omx_codec_output_port,false);
2458 EnablePort(omx_vid_deint,omx_deint_input_port,false);
2459 EnablePort(omx_vid_deint,omx_deint_output_port,false);
2461 EnablePort(omx_vid_sched,omx_shed_input_port,false);
2463 clock_mutex.Unlock();
2464 pthread_setcancelstate(oldcancelstate, NULL);
2465 pthread_setcanceltype(oldcanceltype, NULL);
2472 void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer)
2475 OMX_ERRORTYPE error = ProtOMXEmptyThisBuffer(omx_vid_dec, buffer);
2476 if (error != OMX_ErrorNone) {
2477 Log::getInstance()->log("Video", Log::DEBUG,
2478 "OMX_EmptyThisBuffer failed %x", error);
2480 if (first_frame) FirstFrameFix();
2484 OMX_ERRORTYPE VideoOMX::ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer)
2486 // protect the call to empty this buffer
2489 /* long long temp =buffer->nTimeStamp.nLowPart
2490 | ((long long) buffer->nTimeStamp.nHighPart << 32);*/
2492 //pthread_testcancel();
2493 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2494 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2497 /* OMX_ERRORTYPE error;
2498 OMX_TIME_CONFIG_TIMESTAMPTYPE timestamp;
2499 memset(×tamp, 0, sizeof(timestamp));
2500 timestamp.nSize = sizeof(timestamp);
2501 timestamp.nVersion.nVersion = OMX_VERSION;
2502 timestamp.nPortIndex =omx_clock_output_port;
2504 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2507 if (error != OMX_ErrorNone) {
2508 Log::getInstance()->log("Audio", Log::DEBUG,
2509 "Init OMX_IndexConfigAudioRenderingLatencyfailed %x %d", error,
2510 omx_rend_input_port);
2512 long long temp2 =timestamp.nTimestamp.nLowPart
2513 | ((long long) timestamp.nTimestamp.nHighPart << 32);
2516 Log::getInstance()->log("Video", Log::NOTICE, "OMXETB %x %lld %lld %x",handle,temp,temp2,buffer->nFlags);*/
2517 OMX_ERRORTYPE ret_val;
2518 ret_val=OMX_EmptyThisBuffer(handle,buffer);
2519 clock_mutex.Unlock();
2520 pthread_setcancelstate(oldcancelstate, NULL);
2521 pthread_setcanceltype(oldcanceltype, NULL);
2522 //pthread_testcancel();
2526 bool VideoOMX::detectIFrame(const UCHAR *buffer,unsigned int length)
2528 const UCHAR* curbuf=buffer;
2529 const UCHAR* curbufend=buffer+length;
2530 unsigned int detector=0xFFFFFFFF;
2531 bool gotaud=false; // have seen access unit delimiter
2533 while (curbuf!=curbufend) {
2537 if (detector==0x00000109) {
2539 detector=0xFFFFFFFF;
2540 } else if (gotaud &&detector==0x00000001) {
2542 if (curbuf!=curbufend) {
2543 unsigned char picttype=(*curbuf)& 0x1F;
2544 return picttype==0x07;
2548 if (detector==0x00000100) {
2550 if (curbuf==curbufend) return false;
2552 if (curbuf==curbufend) return false;
2553 unsigned char picttype=((*curbuf) >> 3) & 0x07;
2560 return false; // no frame found
2565 bool VideoOMX::DrainTargetBufferFull()
2567 //Check, if we have OMX output buffers
2569 input_bufs_omx_mutex.Lock();
2570 full=(input_bufs_omx_free.size()==0);
2571 input_bufs_omx_mutex.Unlock();
2576 void VideoOMX::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
2579 mediapackets.clear();
2580 list<MediaPacket>::const_iterator begin=mplist.begin();
2581 list<MediaPacket>::const_iterator itty=mplist.begin();
2582 advance(itty,min(mplist.size(),10));
2583 mediapackets.insert(mediapackets.begin(),begin,itty);//front
2587 UINT VideoOMX::DeliverMediaSample(UCHAR* buffer, UINT *samplepos)
2590 while (consumed<mediapackets.size()) {
2591 DeliverMediaPacket(mediapackets[consumed], buffer, samplepos);
2592 if (*samplepos == mediapackets[consumed].length) {
2596 } else return consumed;
2601 UINT VideoOMX::DeliverMediaPacket(MediaPacket packet,
2602 const UCHAR* buffer,
2605 if (packet.type == MPTYPE_VIDEO_H264)
2615 //Later add fail back code for libav
2617 *samplepos+=packet.length;
2618 return packet.length;
2622 if (!omx_running) return 0; // if we are not runnig do not do this
2623 if (isClockPaused()) return 0; //Block if we pause
2625 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 1");
2626 //Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX time %lld",packet.presentation_time);
2629 OMX_ERRORTYPE error;
2631 /*First Check, if we have an video sample*/
2635 return 0; //Not in iframe mode!
2639 if (packet.disconti) {
2641 if (cur_input_buf_omx) {
2642 PutBufferToPres(cur_input_buf_omx);
2643 cur_input_buf_omx=NULL;
2646 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2");
2647 /*Inspect PES-Header */
2649 // OMX_STATETYPE temp_state;
2650 // OMX_GetState(omx_vid_dec,&temp_state);
2652 if (*samplepos==0) {//stripheader
2653 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
2654 // if (h264) Log::getInstance()->log("Video", Log::DEBUG, "PES info %x %x %x %x",
2655 // buffer[packet.pos_buffer+0],buffer[packet.pos_buffer+1],buffer[packet.pos_buffer+2],buffer[packet.pos_buffer+3]);
2656 *samplepos+=headerstrip;
2657 if (headerstrip>=packet.length) {
2658 *samplepos=packet.length;// Packet is obviously damaged
2659 return packet.length;//skip it!
2661 if ( packet.synched ) {
2662 if (!firstsynched) {
2663 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2a");
2664 // check if this is an I frame, the decoder does not like non I frames at startup!
2665 if (!detectIFrame(buffer,packet.length)) {
2666 *samplepos=packet.length;//if we have not processed at least one
2667 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 3");
2668 return packet.length;//synched packet ignore it!
2671 if (cur_input_buf_omx) {
2672 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4a");
2673 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_ENDOFFRAME;
2674 PutBufferToPres(cur_input_buf_omx);
2675 cur_input_buf_omx=NULL;//write out old data
2677 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4b");
2682 if (!firstsynched) {//
2683 *samplepos=packet.length;//if we have not processed at least one
2684 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 5");
2685 return packet.length;//synched packet ignore it!
2689 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 6");
2690 if (!cur_input_buf_omx) {
2691 input_bufs_omx_mutex.Lock();
2692 if (input_bufs_omx_free.size()==0) {
2693 input_bufs_omx_mutex.Unlock();
2694 //Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample");
2695 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 7");
2696 return 0; // we do not have a free media sample
2699 cur_input_buf_omx=input_bufs_omx_free.front();
2700 cur_input_buf_omx->nFilledLen=0;
2701 cur_input_buf_omx->nOffset=0;
2702 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2703 input_bufs_omx_free.pop_front();
2704 input_bufs_omx_mutex.Unlock();
2710 if (cur_input_buf_omx->nFilledLen==0) {//will only be changed on first packet
2711 if (packet.synched) {
2712 // Log::getInstance()->log("Video", Log::DEBUG, "packet synched marker");
2714 //lastreftimePTS=packet.pts;
2715 if (omx_first_frame) { // TODO time
2716 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_STARTTIME;
2717 Log::getInstance()->log("Video", Log::DEBUG, "Starttime");
2718 omx_first_frame=false;
2720 cur_input_buf_omx->nFlags=0;
2721 //cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_TIME_UNKNOWN;
2723 lastreftimeOMX=packet.presentation_time;
2724 // Log::getInstance()->log("Video", Log::DEBUG, "Time code %lld pts %lld", lastreftimeOMX,packet.pts);
2725 lastreftimePTS=packet.pts;
2726 cur_input_buf_omx->nTimeStamp=intToOMXTicks(lastreftimeOMX/10LL); // the clock component is faulty;
2730 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2731 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2732 //Log::getInstance()->log("Video", Log::DEBUG, "packet unsynched marker");
2734 if (packet.disconti) cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_DISCONTINUITY;
2739 unsigned int haveToCopy=packet.length-*samplepos;
2740 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 8");
2742 while (haveToCopy> (cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen)) {
2743 //Log::getInstance()->log("Video", Log::DEBUG, "Big buffer %d %d %d",packet.length,cur_input_buf_omx->nAllocLen,cur_input_buf_omx->nFilledLen);
2744 unsigned int cancopy=cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen;
2745 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,buffer+packet.pos_buffer+*samplepos,cancopy);
2746 haveToCopy-=cancopy;
2747 cur_input_buf_omx->nFilledLen+=cancopy;
2748 *samplepos+=cancopy;
2749 // push old buffer out
2750 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 9");
2752 PutBufferToPres(cur_input_buf_omx);
2753 cur_input_buf_omx=NULL;
2755 input_bufs_omx_mutex.Lock();
2756 if (input_bufs_omx_free.size()==0) {
2757 input_bufs_omx_mutex.Unlock();
2758 // Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample2");
2759 return *samplepos; // we do not have a free media sample
2761 cur_input_buf_omx=input_bufs_omx_free.front();
2762 cur_input_buf_omx->nFilledLen=0;
2763 cur_input_buf_omx->nOffset=0;
2764 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2765 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2766 input_bufs_omx_free.pop_front();
2767 input_bufs_omx_mutex.Unlock();
2768 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 10");
2771 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,
2772 buffer+packet.pos_buffer+*samplepos,haveToCopy);
2773 cur_input_buf_omx->nFilledLen+=haveToCopy;
2775 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 11");
2777 *samplepos+=haveToCopy;
2786 bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) {
2787 if (!omx_running) return false;
2789 EnterIframePlayback();
2791 int haveToCopy = length;
2793 if (!cur_input_buf_omx) {
2794 input_bufs_omx_mutex.Lock();
2795 if (input_bufs_omx_free.size() == 0) {
2796 input_bufs_omx_mutex.Unlock();
2797 // Log::getInstance()->log("Video", Log::DEBUG,
2798 // "Deliver MediaPacket no free sample");
2799 return false; // we do not have a free media sample
2802 cur_input_buf_omx = input_bufs_omx_free.front();
2803 cur_input_buf_omx->nFilledLen = 0;
2804 cur_input_buf_omx->nOffset = 0;
2805 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2806 input_bufs_omx_free.pop_front();
2807 input_bufs_omx_mutex.Unlock();
2811 unsigned int pattern, packet_length;
2812 unsigned int headerstrip = 0;
2817 //Now we strip the pes header
2818 pattern = (buffer[0] << 16) | (buffer[1] << 8) | (buffer[2]);
2819 while (read_pos + 7 <= length) {
2820 pattern = ((pattern << 8) & 0xFFFFFFFF) | buffer[read_pos + 3];
2821 if (pattern < 0x000001E0 || pattern > 0x000001EF) {
2825 headerstrip = buffer[read_pos + 8] + 9/*is this right*/;
2826 packet_length = ((buffer[read_pos + 4] << 8)
2827 | (buffer[read_pos + 5])) + 6;
2828 if (read_pos + packet_length > length)
2831 if ((headerstrip < packet_length)
2832 && (cur_input_buf_omx->nFilledLen + packet_length
2833 - headerstrip) > cur_input_buf_omx->nAllocLen) {
2835 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2838 cur_input_buf_omx->nFlags
2839 |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2842 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2843 PutBufferToPres(cur_input_buf_omx);
2844 cur_input_buf_omx = NULL;
2846 if (!cur_input_buf_omx) {
2848 while (count < 100 && omx_running && iframemode) {
2851 input_bufs_omx_mutex.Lock();
2852 if (input_bufs_omx_free.size() == 0) {
2853 input_bufs_omx_mutex.Unlock();
2854 // Log::getInstance()->log("Video", Log::DEBUG,
2855 // "Ifrane no free sample");
2857 if (!omx_running) return false;
2860 cur_input_buf_omx = input_bufs_omx_free.front();
2861 cur_input_buf_omx->nFilledLen = 0;
2862 cur_input_buf_omx->nOffset = 0;
2863 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2864 cur_input_buf_omx->nFlags|= OMX_BUFFERFLAG_TIME_UNKNOWN;
2865 input_bufs_omx_free.pop_front();
2866 input_bufs_omx_mutex.Unlock();
2869 if (!cur_input_buf_omx)
2874 if (packet_length > headerstrip) {
2876 cur_input_buf_omx->pBuffer
2877 + cur_input_buf_omx->nFilledLen,
2878 buffer + read_pos + headerstrip,
2879 packet_length - headerstrip);
2880 cur_input_buf_omx->nFilledLen += packet_length
2883 read_pos += packet_length;
2885 pattern = (buffer[read_pos] << 16)
2886 | (buffer[read_pos + 1] << 8) | (buffer[read_pos + 2]);
2892 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2895 cur_input_buf_omx->nFlags |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2898 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2900 PutBufferToPres(cur_input_buf_omx);
2901 cur_input_buf_omx = NULL;
2904 MILLISLEEP(40); //Block a bit
2908 int VideoOMX::EnterIframePlayback()
2910 Log::getInstance()->log("Video", Log::DEBUG,
2911 "EnterIframePlayback");
2912 if (cur_input_buf_omx) {
2913 PutBufferToPres(cur_input_buf_omx);
2914 cur_input_buf_omx = NULL;
2916 Log::getInstance()->log("Video", Log::DEBUG,
2917 "EnterIframePlayback 2");
2918 ((AudioOMX*)Audio::getInstance())->DeAllocateCodecsOMX();
2919 DeAllocateCodecsOMX();
2920 AllocateCodecsOMX();
2921 Log::getInstance()->log("Video", Log::DEBUG,
2922 "leave IframePlayback");