2 Copyright 2004-2005 Chris Tallon, 2009-12 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "mtdraspberry.h"
26 #include "woptionpane.h"
27 #include "osdopenvg.h"
36 //A lot of parts of this file are heavily inspired by xbmc omx implementations
38 VideoOMX::VideoOMX() {
43 cur_input_buf_omx = NULL;
44 omx_h264 = omx_mpeg2 = true;
48 offsetvideonotset = true;
49 offsetaudionotset = true;
61 deinterlace=2; //advanced
73 int VideoOMX::init(UCHAR tformat)
75 if (initted) return 0;
78 if (!setFormat(tformat)) { shutdown(); return 0; }
79 if (!setConnection(HDMI)) { shutdown(); return 0; }
80 if (!setAspectRatio(ASPECT4X3)) { shutdown(); return 0; }
81 if (!setMode(NORMAL)) { shutdown(); return 0; }
82 if (!setSource()) { shutdown(); return 0; }
83 if (!attachFrameBuffer()) { shutdown(); return 0; }
91 if (error != OMX_ErrorNone) {
92 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX failed %x",
111 OMX_ERRORTYPE VideoOMX::EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
112 OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
113 OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data) {
115 Log::getInstance()->log("Video", Log::NOTICE, "eventHandler %x %x %x %x %x",handle,event_type,data1,data2,event_data);
117 struct VPE_OMX_EVENT new_event;
118 new_event.handle=handle;
119 new_event.appdata=appdata;
120 new_event.event_type=event_type;
121 new_event.data1=data1;
122 new_event.data2=data2;
123 new_event.event_data=event_data;
125 VideoOMX *video=(VideoOMX *)getInstance();
126 video->AddOmxEvent(new_event);
128 /* switch (event_type) {
129 case OMX_EventCmdComplete: {
134 return OMX_ErrorNone;
138 void VideoOMX::AddOmxEvent(VPE_OMX_EVENT new_event)
140 omx_event_mutex.Lock();
141 omx_events.push_back(new_event);
142 omx_event_mutex.Unlock();
146 OMX_ERRORTYPE VideoOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
148 //Log::getInstance()->log("Video", Log::NOTICE, "EmptyBufferDone");
149 VideoOMX *video=(VideoOMX *)getInstance();
150 /* long long temp =buffer->nTimeStamp.nLowPart
151 | ((long long) buffer->nTimeStamp.nHighPart << 32);
152 Log::getInstance()->log("Video", Log::NOTICE, "EBD Video %lld %x",temp,buffer->nFlags);*/
153 video->ReturnEmptyOMXBuffer(buffer);
154 return OMX_ErrorNone;
158 void VideoOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
159 input_bufs_omx_mutex.Lock();
160 //Log::getInstance()->log("Video", Log::NOTICE, "ReturnEmptyOMXBuffer %d %d %d",input_bufs_omx_free.size(),input_bufs_omx_present.size(),input_bufs_omx_all.size());
161 input_bufs_omx_free.push_back(buffer);
162 //Log::getInstance()->log("Video", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
163 input_bufs_omx_mutex.Unlock();
166 OMX_ERRORTYPE VideoOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
167 Log::getInstance()->log("Video", Log::NOTICE, "FillBufferDone");
168 return OMX_ErrorNone;
173 int VideoOMX::shutdown()
175 if (!initted) return 0;
177 Log::getInstance()->log("Video", Log::NOTICE, "Shutdown video module");
179 DeAllocateCodecsOMX();
181 //vc_tv_show_info(0); // back to console
184 struct fb_var_screeninfo screeninfo;
185 fd_fbset=open("/dev/fb0",O_RDONLY);
187 Log::getInstance()->log("Video", Log::CRIT, "Could not open frame buffer device %d", fd_fbset);
190 if (ioctl(fd_fbset, FBIOGET_VSCREENINFO, &screeninfo)){
192 Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOGET_VSCREENINFO frame buffer device");
195 screeninfo.bits_per_pixel=8;
196 if (ioctl(fd_fbset, FBIOPUT_VSCREENINFO, &screeninfo)){
197 Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOPUT_VSCREENINFO frame buffer device");
199 screeninfo.bits_per_pixel=16;
200 if (ioctl(fd_fbset, FBIOPUT_VSCREENINFO, &screeninfo)){
201 Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOPUT_VSCREENINFO frame buffer device");
209 bool VideoOMX::loadOptionsfromServer(VDR* vdr)
211 Log::getInstance()->log("Video", Log::DEBUG, "VideoOMX config load");
212 char *name=vdr->configLoad("VideoOMX","SDDeinterlacing");
215 if (STRCASECMP(name, "None") == 0) {
217 }/* else if (STRCASECMP(name, "LineDouble") == 0) {
219 }*/ else if (STRCASECMP(name, "Advanced") == 0) {
221 } /*else if (STRCASECMP(name, "Crazy") == 0) {
222 deinterlace = 3; // this does not activate deinterlacing but a image filter, just for fun
224 Log::getInstance()->log("Video", Log::DEBUG, "Set deinterlacing to %s %d",name,deinterlace);
231 bool VideoOMX::handleOptionChanges(Option* option)
233 if (Video::handleOptionChanges(option))
235 switch (option->id) {
237 if (STRCASECMP(option->options[option->userSetChoice], "None") == 0) {
239 } /*else if (STRCASECMP(option->options[option->userSetChoice], "LineDouble")
242 }*/ else if (STRCASECMP(option->options[option->userSetChoice], "Advanced")
245 } /*else if (STRCASECMP(option->options[option->userSetChoice], "Crazy")
249 Log::getInstance()->log("Video", Log::DEBUG, "Set deinterlacing to %s %d",option->options[option->userSetChoice],deinterlace);
258 bool VideoOMX::saveOptionstoServer()
261 switch (deinterlace) {
263 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "None");
266 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "LineDouble");
269 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "Advanced");
272 VDR::getInstance()->configSave("VideoOMX","SDDeinterlacing", "Crazy");
279 /*Option(UINT id, const char* displayText, const char* configSection, const char* configKey, UINT optionType,
280 UINT numChoices, UINT defaultChoice, UINT startInt,
281 const char * const * options, const char * const * optionkeys = NULL, AbstractOption* handler=NULL);*/
283 bool VideoOMX::addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane)
285 if (!Video::addOptionsToPanes(panenumber,options,pane)) return false;
291 static const char* deinterlaceopts[]={"None",/*"LineDouble",*/"Advanced"/*,"Crazy"*/};
292 option = new Option(1,tr("SD Deinterlacing"), "VideoOMX","SDDeinterlacing",Option::TYPE_TEXT,/*4,2*/2,1,0,deinterlaceopts,NULL,false,this);
293 options->push_back(option);
294 pane->addOptionLine(option);
302 int VideoOMX::setTVsize(UCHAR ttvsize)
304 if (tvsize!=ttvsize) pendingmodechange=true;
309 void VideoOMX::executePendingModeChanges()
311 if (pendingmodechange) {
312 Log::getInstance()->log("Video", Log::NOTICE, "Execute pending mode change");
313 Osd::getInstance()->shutdown();
315 Osd::getInstance()->restore();
316 Osd::getInstance()->init((void*) "");
317 BoxStack::getInstance()->redrawAllBoxes();
322 int VideoOMX::setDefaultAspect()
324 return setAspectRatio(tvsize);
329 int VideoOMX::setFormat(UCHAR tformat)
331 if (!initted) return 0;
332 if ((tformat != PAL) && (tformat != NTSC)
333 && (tformat != PAL_M) && (tformat != NTSC_J)) return 0;
343 // selectVideoMode(0);
348 void VideoOMX::selectVideoMode(int interlaced)
350 TV_GET_STATE_RESP_T tvstate;
351 vc_tv_get_state(&tvstate);
353 if ((tvstate.state & VC_HDMI_UNPLUGGED)) {
355 Log::getInstance()->log("Video", Log::NOTICE, "HDMI unplugged");
358 Log::getInstance()->log("Video", Log::NOTICE, "HDMI plugged");
359 if (connection==COMPOSITERGB) {
361 Log::getInstance()->log("Video", Log::NOTICE, "SDTV set");
364 Log::getInstance()->log("Video", Log::NOTICE, "HDMI set");
370 TV_SUPPORTED_MODE_T all_supp_modes[TV_MAX_SUPPORTED_MODES];
371 HDMI_RES_GROUP_T pref_group;
372 TV_SUPPORTED_MODE_T *mymode=NULL;
373 TV_SUPPORTED_MODE_T *mymode_second_best=NULL;
374 bool got_optimum=false;
376 HDMI_RES_GROUP_T group=HDMI_RES_GROUP_CEA;
377 int all_my_modes=vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_CEA,
378 all_supp_modes,TV_MAX_SUPPORTED_MODES,
379 &pref_group,&pref_mode);
380 if (all_my_modes<=0) {
381 group=HDMI_RES_GROUP_DMT;
382 all_my_modes=vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_DMT,
383 all_supp_modes,TV_MAX_SUPPORTED_MODES,
384 &pref_group,&pref_mode);
385 Log::getInstance()->log("Video", Log::NOTICE, "No CEA fall back to DMT modes ");
392 if (format==PAL)target_fps=50;
393 else if (format==NTSC) target_fps=60;
395 //Now first determine native resolution
396 int native_width=1920;
397 int native_height=1080;
398 for (int i=0;i<all_my_modes;i++) {
399 if (all_supp_modes[i].native) {
400 mymode=all_supp_modes+i;
401 Log::getInstance()->log("Video", Log::NOTICE, "Found native mode %dx%d %d Hz i: %d",
402 mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode);
403 native_width=mymode->width;
404 native_height=mymode->height;
408 //Now find the mode which matches best
409 for (int i=0;i<all_my_modes;i++) {
410 TV_SUPPORTED_MODE_T *curmode=all_supp_modes+i;
411 if (curmode->width==native_width &&
412 curmode->height==native_height &&
413 curmode->frame_rate==target_fps) {
414 if(curmode->scan_mode==interlaced) {
417 Log::getInstance()->log("Video", Log::NOTICE, "Found optimum mode %dx%d %d Hz i: %d",
418 mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode);
420 mymode_second_best=curmode;
421 Log::getInstance()->log("Video", Log::NOTICE, "Found close to optimum mode %dx%d %d Hz i: %d",
422 mymode_second_best->width,mymode_second_best->height,
423 mymode_second_best->frame_rate,mymode_second_best->scan_mode);
428 Remote::getInstance()->shutdown();
431 Log::getInstance()->log("Video", Log::NOTICE, "Switch to optimum mode");
432 vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,group,mymode->code);
433 } else if (mymode_second_best) {
434 Log::getInstance()->log("Video", Log::NOTICE, "Switch to close to optimum mode");
435 vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,group,mymode_second_best->code);
437 Log::getInstance()->log("Video", Log::NOTICE, "Switch to prefered mode");
438 vc_tv_hdmi_power_on_best(1920,1080,target_fps,interlaced?HDMI_INTERLACED:HDMI_NONINTERLACED,
439 (EDID_MODE_MATCH_FLAG_T)(HDMI_MODE_MATCH_FRAMERATE|HDMI_MODE_MATCH_RESOLUTION|HDMI_MODE_MATCH_SCANMODE));
442 outputinterlaced=interlaced;
445 Log::getInstance()->log("Video", Log::NOTICE, "No CEA and DMT modes found analog tv case?");
446 Remote::getInstance()->shutdown();
448 SDTV_MODE_T setmode=SDTV_MODE_PAL;
449 SDTV_OPTIONS_T options;
454 Log::getInstance()->log("Video", Log::NOTICE, "SDTV aspect 16:9");
455 options.aspect=SDTV_ASPECT_16_9; break;
457 Log::getInstance()->log("Video", Log::NOTICE, "SDTV aspect 4:3");
458 options.aspect=SDTV_ASPECT_4_3; break;
460 Log::getInstance()->log("Video", Log::NOTICE, "SDTV aspect 14:9");
461 options.aspect=SDTV_ASPECT_14_9; break;
464 if (format==PAL) setmode=SDTV_MODE_PAL;
465 else if (format==NTSC) setmode=SDTV_MODE_NTSC;
466 else if (format==PAL_M)setmode=SDTV_MODE_PAL_M;
467 else if (format==NTSC_J) setmode=SDTV_MODE_NTSC_J;
468 vc_tv_sdtv_power_on(setmode,&options);
472 Remote::getInstance()->init("");
476 pendingmodechange=false;
481 int VideoOMX::setConnection(UCHAR tconnection)
483 if (!initted) return 0;
484 if ((tconnection != COMPOSITERGB) && (tconnection != HDMI)) return 0;
485 if (connection!=tconnection) pendingmodechange=true;
486 connection = tconnection;
488 // if (ioctl(fdVideo, AV_SET_VID_OUTPUT, connection) != 0) return 0;
492 int VideoOMX::setAspectRatio(UCHAR taspectRatio)
494 if (!initted) return 0;
495 if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
496 aspectRatio = taspectRatio;
498 Log::getInstance()->log("Video", Log::DEBUG, "Setting aspect to %i", aspectRatio);
500 // if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
504 int VideoOMX::setMode(UCHAR tmode)
506 if (!initted) return 0;
513 void VideoOMX::updateMode()
518 OMX_CONFIG_DISPLAYREGIONTYPE dispconf;
519 memset(&dispconf, 0, sizeof(dispconf));
520 dispconf.nSize = sizeof(dispconf);
521 dispconf.nVersion.nVersion = OMX_VERSION;
522 dispconf.nPortIndex = omx_rend_input_port;
524 dispconf.set = OMX_DISPLAY_SET_LAYER;
525 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
527 if (error != OMX_ErrorNone) {
528 Log::getInstance()->log("Video", Log::DEBUG,
529 "Set OMX_IndexConfigDisplayRegion1 failed %x", error);
530 clock_mutex.Unlock();
533 dispconf.set = OMX_DISPLAY_SET_FULLSCREEN;
534 if (mode != QUARTER && mode != EIGHTH) {
536 dispconf.fullscreen = OMX_TRUE;
538 dispconf.fullscreen = OMX_FALSE;
540 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
542 if (error != OMX_ErrorNone) {
543 Log::getInstance()->log("Video", Log::DEBUG,
544 "Set OMX_IndexConfigDisplayRegion2 failed %x", error);
545 clock_mutex.Unlock();
549 dispconf.set = OMX_DISPLAY_SET_MODE;
550 if (mode != QUARTER && mode != EIGHTH) {
551 dispconf.mode = (mode == NORMAL) ? OMX_DISPLAY_MODE_FILL
552 : OMX_DISPLAY_MODE_LETTERBOX;
554 dispconf.mode = OMX_DISPLAY_MODE_LETTERBOX;
556 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
558 if (error != OMX_ErrorNone) {
559 Log::getInstance()->log("Video", Log::DEBUG,
560 "Set OMX_IndexConfigDisplayRegion3 failed %x", error);
561 clock_mutex.Unlock();
565 if (mode == QUARTER || mode == EIGHTH) {
566 unsigned int display_width, display_height;
567 display_width = display_height = 0;
568 if (graphics_get_display_size(0, &display_width, &display_height)
570 Log::getInstance()->log("OSD", Log::WARN,
571 "Getting display size failed! (BCM API) ");
572 clock_mutex.Unlock();
575 //UnSetFullscreen with window
576 dispconf.set = OMX_DISPLAY_SET_DEST_RECT;
577 dispconf.dest_rect.x_offset
578 = (int) (xpos * ((float) display_width));
579 dispconf.dest_rect.y_offset = (int) (ypos
580 * ((float) display_height));
581 if (mode == QUARTER) {
582 dispconf.dest_rect.width = display_width >> 1;
583 dispconf.dest_rect.height = display_height >> 1;
584 } else if (mode == EIGHTH) {
585 dispconf.dest_rect.width = display_width >> 2;
586 dispconf.dest_rect.height = display_height >> 2;
588 error = OMX_SetParameter(omx_vid_rend,
589 OMX_IndexConfigDisplayRegion, &dispconf);
590 if (error != OMX_ErrorNone) {
591 Log::getInstance()->log("Video", Log::DEBUG,
592 "Set OMX_IndexConfigDisplayRegion failed %x", error);
593 clock_mutex.Unlock();
599 clock_mutex.Unlock();
602 int VideoOMX::signalOff()
605 Log::getInstance()->log("Video", Log::NOTICE, "signalOff");
607 Osd::getInstance()->stopUpdate(); // turn off drawing thread
612 int VideoOMX::signalOn()
615 Log::getInstance()->log("Video", Log::NOTICE, "signalOn");
616 Osd::getInstance()->shutdown();
618 Osd::getInstance()->restore();
619 Osd::getInstance()->init((void*)"");
620 BoxStack::getInstance()->redrawAllBoxes();
627 int VideoOMX::setSource()
629 if (!initted) return 0;
631 // What does this do...
632 // if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
636 int VideoOMX::setPosition(int x, int y) {
639 xpos = ((float) x*2.f) / ((float) screenWidth);
640 ypos = ((float) y*2.f) / ((float) screenHeight);
648 if (!initted) return 0;
650 // if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
654 void VideoOMX::interlaceSwitch4Demux() {
656 Demuxer *demux=Demuxer::getInstance();
657 if ( (outputinterlaced && !demux->getInterlaced())
658 || (!outputinterlaced && demux->getInterlaced())) {
659 if (hdmi && (demux->getHorizontalSize()>720 || demux->getInterlaced() )) { // only switch if hdmi and HD or interlaced SD material
660 Log::getInstance()->log("Video", Log::NOTICE, "switch interlacing %d",demux->getInterlaced());
661 Osd::getInstance()->shutdown();
663 selectVideoMode(demux->getInterlaced());
665 Osd::getInstance()->restore();
666 Osd::getInstance()->init((void*)"");
667 BoxStack::getInstance()->redrawAllBoxes();
676 int VideoOMX::play() {
680 Log::getInstance()->log("Video", Log::DEBUG, "enter play");
682 interlaceSwitch4Demux();
684 if (AllocateCodecsOMX()) {
686 // Otherwise fall back to libav
690 Log::getInstance()->log("Video", Log::NOTICE,
691 "Allocate Codecs OMX failed assume h264 unsupported");
694 Log::getInstance()->log("Video", Log::NOTICE,
695 "Allocate Codecs OMX failed assume mpeg2 unsupported");
704 int VideoOMX::initClock()
708 if (clock_references==0)
711 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
714 error=OMX_GetHandle(&omx_clock,VPE_OMX_CLOCK,NULL,&callbacks);
716 if (error!=OMX_ErrorNone) {
717 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX clock failed %x", error);
718 clock_mutex.Unlock();
719 DeAllocateCodecsOMX();
723 /* TODO Clock config to separate method */
724 OMX_PORT_PARAM_TYPE p_param;
725 memset(&p_param,0,sizeof(p_param));
726 p_param.nSize=sizeof(p_param);
727 p_param.nVersion.nVersion=OMX_VERSION;
728 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
729 if (error!=OMX_ErrorNone) {
730 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
731 clock_mutex.Unlock();
732 DeAllocateCodecsOMX();
735 omx_clock_output_port=p_param.nStartPortNumber;
737 for (unsigned int i=0;i<p_param.nPorts;i++) {
738 if (!DisablePort(omx_clock,p_param.nStartPortNumber+i,true) ) {
739 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX clock failed %d",i);
740 clock_mutex.Unlock();
741 DeAllocateCodecsOMX();
750 Log::getInstance()->log("Video", Log::DEBUG, "init omx clock %x %x",this,omx_clock);
752 clock_mutex.Unlock();
756 int VideoOMX::getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port)
760 *p_omx_clock_output_port=0;
767 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
768 memset(&refclock,0,sizeof(refclock));
769 refclock.nSize=sizeof(refclock);
770 refclock.nVersion.nVersion=OMX_VERSION;
772 refclock.eClock=OMX_TIME_RefClockAudio;
774 //refclock.eClock=OMX_TIME_RefClockVideo;
775 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
776 if (error!=OMX_ErrorNone){
777 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
778 clock_mutex.Unlock();
779 DeAllocateCodecsOMX();
783 OMX_PORT_PARAM_TYPE p_param;
784 memset(&p_param,0,sizeof(p_param));
785 p_param.nSize=sizeof(p_param);
786 p_param.nVersion.nVersion=OMX_VERSION;
787 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
788 if (error!=OMX_ErrorNone){
789 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
790 clock_mutex.Unlock();
791 DeAllocateCodecsOMX();
795 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
796 memset(&clock_conf,0,sizeof(clock_conf));
797 clock_conf.nSize=sizeof(clock_conf);
798 clock_conf.nVersion.nVersion=OMX_VERSION;
799 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
800 clock_conf.nStartTime=intToOMXTicks(0);
801 clock_conf.nOffset=intToOMXTicks(0);
802 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT1;
803 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
804 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
805 if (error!=OMX_ErrorNone) {
806 Log::getInstance()->log("Video", Log::DEBUG, "AuI Clock IndexConfigTimeClockState failed %x", error);
810 *p_omx_clock_output_port=p_param.nStartPortNumber+1;
811 *p_omx_clock=omx_clock;
812 clock_mutex.Unlock();
816 int VideoOMX::getClockVideoandInit()
825 if (clock_references==1) { // only if no audio is attached to this clock!
826 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
827 memset(&refclock,0,sizeof(refclock));
828 refclock.nSize=sizeof(refclock);
829 refclock.nVersion.nVersion=OMX_VERSION;
831 //refclock.eClock=OMX_TIME_RefClockAudio;
833 refclock.eClock=OMX_TIME_RefClockVideo;
834 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
835 if (error!=OMX_ErrorNone) {
836 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
837 clock_mutex.Unlock();
838 DeAllocateCodecsOMX();
843 OMX_PORT_PARAM_TYPE p_param;
844 memset(&p_param,0,sizeof(p_param));
845 p_param.nSize=sizeof(p_param);
846 p_param.nVersion.nVersion=OMX_VERSION;
847 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
848 if (error!=OMX_ErrorNone){
849 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
850 clock_mutex.Unlock();
851 DeAllocateCodecsOMX();
856 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
857 memset(&clock_conf,0,sizeof(clock_conf));
858 clock_conf.nSize=sizeof(clock_conf);
859 clock_conf.nVersion.nVersion=OMX_VERSION;
860 clock_conf.eState=OMX_TIME_ClockStateStopped;
861 clock_conf.nStartTime=intToOMXTicks(0);
862 clock_conf.nOffset=intToOMXTicks(0);
863 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
864 if (error!=OMX_ErrorNone) {
865 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
869 memset(&clock_conf,0,sizeof(clock_conf));
870 clock_conf.nSize=sizeof(clock_conf);
871 clock_conf.nVersion.nVersion=OMX_VERSION;
872 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
873 clock_conf.nStartTime=intToOMXTicks(0);
874 clock_conf.nOffset=intToOMXTicks(0);
875 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT0;
876 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
877 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
878 if (error!=OMX_ErrorNone) {
879 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
882 omx_clock_output_port=p_param.nStartPortNumber;
883 clock_mutex.Unlock();
888 void VideoOMX::clockUnpause()
892 if (clock_references>0) {
893 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
894 memset(&clock_conf,0,sizeof(clock_conf));
895 clock_conf.nSize=sizeof(clock_conf);
896 clock_conf.nVersion.nVersion=OMX_VERSION;
897 clock_conf.eState=OMX_TIME_ClockStateRunning;
898 clock_conf.nStartTime=intToOMXTicks(0);
899 clock_conf.nOffset=intToOMXTicks(0);
900 clock_conf.nWaitMask=OMX_CLOCKPORT1;
901 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
902 if (error!=OMX_ErrorNone) {
903 Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause IndexConfigTimeClockState failed %x", error);
906 clock_mutex.Unlock();
910 void VideoOMX::clockPause()
914 if (clock_references>0) {
915 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
916 memset(&clock_conf,0,sizeof(clock_conf));
917 clock_conf.nSize=sizeof(clock_conf);
918 clock_conf.nVersion.nVersion=OMX_VERSION;
919 clock_conf.eState=OMX_TIME_ClockStateStopped;
920 clock_conf.nStartTime=intToOMXTicks(0);
921 clock_conf.nOffset=intToOMXTicks(0);
922 clock_conf.nWaitMask=OMX_CLOCKPORT1;
923 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
924 if (error!=OMX_ErrorNone) {
925 Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause IndexConfigTimeClockState failed %x", error);
928 clock_mutex.Unlock();
933 int VideoOMX::AllocateCodecsOMX()
936 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
938 Demuxer* demux=Demuxer::getInstance();
941 deint_first_frame=false;
943 Log::getInstance()->log("Video", Log::NOTICE, "Allocate Codecs OMX");
944 //Clock, move later to audio including events
946 Log::getInstance()->log("Video", Log::NOTICE, "VideoType %d x %d i: %d", demux->getHorizontalSize(),demux->getVerticalSize(),demux->getInterlaced());
947 if (deinterlace!=0 && (demux->getHorizontalSize()<=720 ) && demux->getInterlaced()) { //only deinterlace SD material
949 deint_first_frame=true;
951 Log::getInstance()->log("Video", Log::NOTICE, "Deinterlacing activated %d",deinterlace);
956 if (!getClockVideoandInit()){
957 return 0;// get the clock and init it if necessary
962 Log::getInstance()->log("Video", Log::DEBUG, "idleClock failed");
969 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_H264_DECODER,NULL,&callbacks);
971 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_MPEG2_DECODER,NULL,&callbacks);
974 if (error!=OMX_ErrorNone){
975 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video decoder failed %x", error);
976 clock_mutex.Unlock();
977 DeAllocateCodecsOMX();
982 Log::getInstance()->log("Video", Log::DEBUG, "Nmark3 ");
983 OMX_PORT_PARAM_TYPE p_param;
984 memset(&p_param,0,sizeof(p_param));
985 p_param.nSize=sizeof(p_param);
986 p_param.nVersion.nVersion=OMX_VERSION;
987 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamVideoInit,&p_param);
988 if (error!=OMX_ErrorNone){
989 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX h264 decoder OMX_GetParameter failed %x", error);
990 clock_mutex.Unlock();
991 DeAllocateCodecsOMX();
994 omx_codec_input_port=p_param.nStartPortNumber;
995 omx_codec_output_port=p_param.nStartPortNumber+1;
997 if (!DisablePort(omx_vid_dec,omx_codec_input_port) || !DisablePort(omx_vid_dec,omx_codec_output_port)) {
998 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video decoder failed");
999 clock_mutex.Unlock();
1000 DeAllocateCodecsOMX();
1004 Log::getInstance()->log("Video", Log::DEBUG, "Nmark4 ");
1006 OMX_PARAM_BRCMVIDEODECODEERRORCONCEALMENTTYPE conceal;
1007 memset(&conceal,0,sizeof(conceal));
1008 conceal.nSize=sizeof(conceal);
1009 conceal.nVersion.nVersion=OMX_VERSION;
1010 conceal.bStartWithValidFrame=OMX_FALSE;
1012 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamBrcmVideoDecodeErrorConcealment,&conceal);
1013 if (error!=OMX_ErrorNone){
1014 Log::getInstance()->log("Video", Log::DEBUG, "OMX_IndexParamBrcmVideoDecodeErrorConcealment failed %x", error);
1015 clock_mutex.Unlock();
1016 DeAllocateCodecsOMX();
1021 error = OMX_GetHandle(&omx_vid_deint, VPE_OMX_VIDEO_DEINTERLACE, NULL,
1023 if (error != OMX_ErrorNone) {
1024 Log::getInstance()->log("Video", Log::DEBUG,
1025 "Init OMX video deinterlacer failed %x", error);
1026 clock_mutex.Unlock();
1027 DeAllocateCodecsOMX();
1031 error = OMX_GetParameter(omx_vid_deint, OMX_IndexParamImageInit,
1033 if (error != OMX_ErrorNone) {
1034 Log::getInstance()->log("Video", Log::DEBUG,
1035 "Init OMX video deinterlacer OMX_GetParameter failed %x",
1037 clock_mutex.Unlock();
1038 DeAllocateCodecsOMX();
1041 omx_deint_input_port = p_param.nStartPortNumber;
1042 omx_deint_output_port = p_param.nStartPortNumber + 1;
1044 if (!DisablePort(omx_vid_deint, omx_deint_input_port, true)
1045 || !DisablePort(omx_vid_deint, omx_deint_output_port, true)) {
1046 Log::getInstance()->log("Video", Log::DEBUG,
1047 "Disable Ports OMX video deint failed");
1048 clock_mutex.Unlock();
1049 DeAllocateCodecsOMX();
1056 error=OMX_GetHandle(&omx_vid_sched,VPE_OMX_VIDEO_SCHED,NULL,&callbacks);
1057 if (error!=OMX_ErrorNone){
1058 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler failed %x", error);
1059 clock_mutex.Unlock();
1060 DeAllocateCodecsOMX();
1066 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamVideoInit,&p_param);
1067 if (error!=OMX_ErrorNone){
1068 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1069 clock_mutex.Unlock();
1070 DeAllocateCodecsOMX();
1073 omx_shed_input_port=p_param.nStartPortNumber;
1074 omx_shed_output_port=p_param.nStartPortNumber+1;
1077 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamOtherInit,&p_param);
1078 if (error!=OMX_ErrorNone){
1079 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1080 clock_mutex.Unlock();
1081 DeAllocateCodecsOMX();
1084 omx_shed_clock_port=p_param.nStartPortNumber;
1085 Log::getInstance()->log("Video", Log::DEBUG, "scheduler ports %d %d %d ",omx_shed_input_port,omx_shed_output_port,omx_shed_clock_port);
1088 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true) || !DisablePort(omx_vid_sched,omx_shed_output_port,true)
1089 || !DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
1090 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video shed failed");
1091 clock_mutex.Unlock();
1092 DeAllocateCodecsOMX();
1097 error=OMX_GetHandle(&omx_vid_rend,VPE_OMX_VIDEO_REND,NULL,&callbacks);
1098 if (error!=OMX_ErrorNone){
1099 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend failed %x", error);
1100 clock_mutex.Unlock();
1101 DeAllocateCodecsOMX();
1105 error=OMX_GetParameter(omx_vid_rend,OMX_IndexParamVideoInit,&p_param);
1106 if (error!=OMX_ErrorNone){
1107 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend OMX_GetParameter failed %x", error);
1108 clock_mutex.Unlock();
1109 DeAllocateCodecsOMX();
1112 omx_rend_input_port=p_param.nStartPortNumber;
1113 //omx_rend_output_port=p_param.nStartPortNumber+1;
1116 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true) /*|| !DisablePort(omx_vid_rend,omx_rend_output_port)*/
1118 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video rend failed");
1119 clock_mutex.Unlock();
1120 DeAllocateCodecsOMX();
1128 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,omx_vid_sched,omx_shed_clock_port);
1129 if (error!=OMX_ErrorNone){
1130 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);
1131 clock_mutex.Unlock();
1132 DeAllocateCodecsOMX();
1136 if (!EnablePort(omx_clock,omx_clock_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_clock_port,false)
1138 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX clock shed failed");
1139 clock_mutex.Unlock();
1140 DeAllocateCodecsOMX();
1145 Log::getInstance()->log("Video", Log::DEBUG, "mark2 ");
1146 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1147 Log::getInstance()->log("Video", Log::DEBUG, "vid_sched idle ChangeComponentState");
1148 clock_mutex.Unlock();
1149 DeAllocateCodecsOMX();
1155 Log::getInstance()->log("Video", Log::DEBUG, "mark1 ");
1156 if ( !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_clock_port)) {
1157 clock_mutex.Unlock();
1158 DeAllocateCodecsOMX();
1165 Log::getInstance()->log("Video", Log::DEBUG, "mark1 special ");
1166 if ( !CommandFinished(omx_clock,OMX_CommandPortEnable,omx_clock_output_port)) {
1167 clock_mutex.Unlock();
1168 DeAllocateCodecsOMX();
1174 Log::getInstance()->log("Video", Log::DEBUG, "mark1b ");
1177 /* error=OMX_SendCommand(omx_vid_dec,OMX_CommandStateSet,OMX_StateIdle,0);
1178 if (error!=OMX_ErrorNone){
1179 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec Send Command to OMX State Idle %x", error);
1183 OMX_VIDEO_PARAM_PORTFORMATTYPE ft_type;
1184 memset(&ft_type,0,sizeof(ft_type));
1185 ft_type.nSize=sizeof(ft_type);
1186 ft_type.nVersion.nVersion=OMX_VERSION;
1188 ft_type.nPortIndex=omx_codec_input_port;
1190 ft_type.eCompressionFormat=OMX_VIDEO_CodingAVC;
1192 ft_type.eCompressionFormat=OMX_VIDEO_CodingMPEG2;
1197 ft_type.xFramerate=0*(1<<16);//25*(1<<16);//demux->getFrameRate()*(1<<16);
1198 Log::getInstance()->log("Video", Log::DEBUG, "Framerate: %d",demux->getFrameRate());
1199 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamVideoPortFormat,&ft_type);
1200 if (error!=OMX_ErrorNone){
1201 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexParamVideoPortFormat failed %x", error);
1202 clock_mutex.Unlock();
1203 DeAllocateCodecsOMX();
1208 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1209 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1210 clock_mutex.Unlock();
1211 DeAllocateCodecsOMX();
1216 if (!PrepareInputBufsOMX()) {
1217 clock_mutex.Unlock();
1218 DeAllocateCodecsOMX();
1223 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_sched,omx_shed_input_port);
1224 if (error!=OMX_ErrorNone){
1225 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to sched failed %x", error);
1226 clock_mutex.Unlock();
1227 DeAllocateCodecsOMX();
1233 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1235 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec shed failed");
1236 clock_mutex.Unlock();
1237 DeAllocateCodecsOMX();
1241 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1242 clock_mutex.Unlock();
1243 DeAllocateCodecsOMX();
1249 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_deint,omx_deint_input_port);
1250 if (error!=OMX_ErrorNone){
1251 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to deint failed %x", error);
1252 clock_mutex.Unlock();
1253 DeAllocateCodecsOMX();
1259 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_deint,omx_deint_input_port,false)
1261 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec deint failed");
1262 clock_mutex.Unlock();
1263 DeAllocateCodecsOMX();
1267 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_input_port)) {
1268 clock_mutex.Unlock();
1269 DeAllocateCodecsOMX();
1273 if (!ChangeComponentState(omx_vid_deint,OMX_StateIdle)) {
1274 Log::getInstance()->log("Video", Log::DEBUG, "vid_deint ChangeComponentState");
1275 clock_mutex.Unlock();
1276 DeAllocateCodecsOMX();
1280 OMX_CONFIG_IMAGEFILTERPARAMSTYPE imagefilter;
1281 memset(&imagefilter,0,sizeof(imagefilter));
1282 imagefilter.nSize=sizeof(imagefilter);
1283 imagefilter.nVersion.nVersion=OMX_VERSION;
1285 imagefilter.nPortIndex=omx_deint_output_port;
1286 imagefilter.nNumParams=1;
1287 imagefilter.nParams[0]=3;//???
1288 switch (deinterlace) {
1290 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceLineDouble; break;
1292 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceAdvanced; break;
1294 imagefilter.eImageFilter=OMX_ImageFilterFilm; break;
1298 error=OMX_SetConfig(omx_vid_deint,OMX_IndexConfigCommonImageFilterParameters,&imagefilter);
1299 if (error!=OMX_ErrorNone){
1300 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigCommonImageFilterParameters failed %x", error);
1301 clock_mutex.Unlock();
1302 DeAllocateCodecsOMX();
1307 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,omx_vid_sched,omx_shed_input_port);
1308 if (error!=OMX_ErrorNone){
1309 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel deint to sched failed %x", error);
1310 clock_mutex.Unlock();
1311 DeAllocateCodecsOMX();
1315 if (!EnablePort(omx_vid_deint,omx_deint_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1317 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX deint shed failed");
1318 clock_mutex.Unlock();
1319 DeAllocateCodecsOMX();
1323 if ( !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1324 clock_mutex.Unlock();
1325 DeAllocateCodecsOMX();
1331 if (!ChangeComponentState(omx_vid_dec,OMX_StateExecuting)) {
1332 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_dec ChangeComponentState Execute");
1333 clock_mutex.Unlock();
1334 DeAllocateCodecsOMX();
1338 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,omx_vid_rend,omx_rend_input_port);
1339 if (error!=OMX_ErrorNone){
1340 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel sched to rend failed %x", error);
1341 clock_mutex.Unlock();
1342 DeAllocateCodecsOMX();
1346 if (!EnablePort(omx_vid_sched,omx_shed_output_port,false) || !EnablePort(omx_vid_rend,omx_rend_input_port,false)
1348 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX shed rend failed");
1349 clock_mutex.Unlock();
1350 DeAllocateCodecsOMX();
1354 if (!CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_output_port)
1355 || !CommandFinished(omx_vid_rend,OMX_CommandPortEnable,omx_rend_input_port)) {
1356 clock_mutex.Unlock();
1357 DeAllocateCodecsOMX();
1361 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1362 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1363 clock_mutex.Unlock();
1364 DeAllocateCodecsOMX();
1369 if (!ChangeComponentState(omx_vid_deint,OMX_StateExecuting)) {
1370 Log::getInstance()->log("Video", Log::DEBUG, "vid_vid_deint ChangeComponentState");
1371 clock_mutex.Unlock();
1372 DeAllocateCodecsOMX();
1375 DisablePort(omx_vid_deint,omx_deint_output_port,false);
1376 DisablePort(omx_vid_deint,omx_deint_input_port,false);
1379 if (!ChangeComponentState(omx_vid_sched,OMX_StateExecuting)) {
1380 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_sched ChangeComponentState Execute");
1381 clock_mutex.Unlock();
1382 DeAllocateCodecsOMX();
1386 if (!ChangeComponentState(omx_vid_rend,OMX_StateExecuting)) {
1387 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_rend ChangeComponentState Execute");
1388 clock_mutex.Unlock();
1389 DeAllocateCodecsOMX();
1394 /*OMX_CONFIG_DISPLAYREGIONTYPE dispconf;
1395 memset(&dispconf,0,sizeof(dispconf));
1396 dispconf.nSize=sizeof(dispconf);
1397 dispconf.nVersion.nVersion=OMX_VERSION;
1399 dispconf.nPortIndex=omx_rend_input_port;
1401 dispconf.set=OMX_DISPLAY_SET_LAYER ;
1403 error=OMX_SetConfig(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1404 if (error!=OMX_ErrorNone){
1405 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1406 clock_mutex.Unlock();
1407 DeAllocateCodecsOMX();
1411 /* dispconf.set=OMX_DISPLAY_SET_FULLSCREEN ;
1412 dispconf.fullscreen=OMX_FALSE;
1413 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1414 if (error!=OMX_ErrorNone){
1415 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1416 clock_mutex.Unlock();
1417 DeAllocateCodecsOMX();
1421 dispconf.set=OMX_DISPLAY_SET_DEST_RECT;
1422 dispconf.dest_rect.x_offset=100;
1423 dispconf.dest_rect.y_offset=100;
1424 dispconf.dest_rect.width=640;
1425 dispconf.dest_rect.height=480;
1426 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1427 if (error!=OMX_ErrorNone){
1428 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1429 clock_mutex.Unlock();
1430 DeAllocateCodecsOMX();
1435 //playbacktimeoffset=-GetCurrentSystemTime();
1439 clock_mutex.Unlock();
1442 setClockExecutingandRunning();
1451 int VideoOMX::idleClock()
1453 OMX_ERRORTYPE error;
1454 OMX_STATETYPE temp_state;
1456 OMX_GetState(omx_clock,&temp_state);
1458 if (temp_state!=OMX_StateIdle) {
1459 if (!ChangeComponentState(omx_clock,OMX_StateIdle)) {
1460 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Idle failed");
1461 clock_mutex.Unlock();
1465 clock_mutex.Unlock();
1469 int VideoOMX::setClockExecutingandRunning()
1471 OMX_ERRORTYPE error;
1472 OMX_STATETYPE temp_state;
1474 OMX_GetState(omx_clock,&temp_state);
1476 if (temp_state!=OMX_StateExecuting) {
1477 if (!ChangeComponentState(omx_clock,OMX_StateExecuting)) {
1478 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Execute failed");
1479 clock_mutex.Unlock();
1480 DeAllocateCodecsOMX();
1485 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
1486 memset(&clock_conf,0,sizeof(clock_conf));
1487 clock_conf.nSize=sizeof(clock_conf);
1488 clock_conf.nVersion.nVersion=OMX_VERSION;
1489 clock_conf.eState=OMX_TIME_ClockStateRunning;
1490 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
1491 if (error!=OMX_ErrorNone) {
1492 Log::getInstance()->log("Video", Log::DEBUG, "Clock IndexConfigTimeClockState failed %x", error);
1493 clock_mutex.Unlock();
1494 DeAllocateCodecsOMX();
1497 clock_mutex.Unlock();
1503 int VideoOMX::ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type) //needs to be called with locked mutex
1505 OMX_ERRORTYPE error;
1506 error=OMX_SendCommand(handle,OMX_CommandStateSet,type,0);
1507 if (error!=OMX_ErrorNone){
1508 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to OMX State %x %x",handle,type, error);
1512 if (!CommandFinished(handle,OMX_CommandStateSet,type)) {
1520 int VideoOMX::EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1522 OMX_ERRORTYPE error;
1523 error=OMX_SendCommand(handle,OMX_CommandPortEnable,port,0);
1524 if (error!=OMX_ErrorNone){
1525 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to enable port %x %x",handle,port, error);
1529 if (!wait) return 1;
1530 if (!CommandFinished(handle,OMX_CommandPortEnable,port)) {
1538 int VideoOMX::DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1540 OMX_ERRORTYPE error;
1541 error=OMX_SendCommand(handle,OMX_CommandPortDisable,port,0);
1542 if (error!=OMX_ErrorNone){
1543 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to disable port %x %x",handle,port, error);
1547 if (!wait) return 1;
1548 if (!CommandFinished(handle,OMX_CommandPortDisable,port)) {
1556 int VideoOMX::WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event) //needs to be called with locked mutex
1560 omx_event_mutex.Lock();
1561 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1562 while (itty!=omx_events.end()) {
1564 VPE_OMX_EVENT current=*itty;
1565 if (current.handle==handle) { //this is ours
1566 if (current.event_type==OMX_EventError) {
1567 omx_events.erase(itty);
1568 omx_event_mutex.Unlock();
1569 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished on Error");
1572 } else if (current.event_type==event) {
1573 omx_events.erase(itty);
1574 omx_event_mutex.Unlock();
1575 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished Completed");
1582 omx_event_mutex.Unlock();
1587 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent waited too long %x %x",handle,event);
1592 int VideoOMX::clearEvents()
1594 omx_event_mutex.Lock();
1596 omx_event_mutex.Unlock();
1602 int VideoOMX::CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2) //needs to be called with locked mutex
1606 omx_event_mutex.Lock();
1607 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1608 while (itty!=omx_events.end()) {
1610 VPE_OMX_EVENT current=*itty;
1611 if (current.handle==handle) { //this is ours
1612 if (current.event_type==OMX_EventError) {
1613 omx_events.erase(itty);
1614 omx_event_mutex.Unlock();
1615 Log::getInstance()->log("Video", Log::DEBUG, "Command Finished on Error %x",current.data1);
1618 } else if (current.event_type==OMX_EventCmdComplete && current.data1==command && current.data2==data2) {
1619 omx_events.erase(itty);
1620 omx_event_mutex.Unlock();
1621 //Log::getInstance()->log("Video", Log::DEBUG, "Command Finished Completed");
1628 omx_event_mutex.Unlock();
1633 Log::getInstance()->log("Video", Log::DEBUG, "CommandFinished waited too long %x %x %x",handle,command, data2);
1642 int VideoOMX::PrepareInputBufsOMX() //needs to be called with locked mutex
1644 OMX_ERRORTYPE error;
1645 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
1646 memset(&port_def_type,0,sizeof(port_def_type));
1647 port_def_type.nSize=sizeof(port_def_type);
1648 port_def_type.nVersion.nVersion=OMX_VERSION;
1649 port_def_type.nPortIndex=omx_codec_input_port;
1651 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1653 if (error!=OMX_ErrorNone){
1654 Log::getInstance()->log("Video", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
1656 /* Log::getInstance()->log("Video", Log::DEBUG, "Port para %d %d %d %d %d %d %d", port_def_type.nBufferCountActual,
1657 port_def_type.nBufferCountMin,port_def_type.nBufferSize,port_def_type.bEnabled,port_def_type.bPopulated,
1658 port_def_type.bBuffersContiguous,port_def_type.nBufferAlignment);*/
1660 port_def_type.nBufferCountActual=100;
1661 port_def_type.nBufferSize=max(port_def_type.nBufferSize,200000); // for transcoder important
1663 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1665 if (error!=OMX_ErrorNone){
1666 Log::getInstance()->log("Video", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
1670 error=OMX_SendCommand(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port,0);
1671 if (error!=OMX_ErrorNone){
1672 Log::getInstance()->log("Video", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
1676 input_bufs_omx_mutex.Lock();
1677 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
1679 // unsigned char* new_buffer_data=(unsigned char*)malloc(port_def_type.nbufferSize);
1680 OMX_BUFFERHEADERTYPE *buf_head=NULL;
1681 /* error=OMX_Usebuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nbufferSize,new_buffer_data);
1682 if (error!=OMX_ErrorNone){
1683 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_Usebuffer failed %x", error);
1684 input_bufs_omx_mutex.Unlock();
1687 error=OMX_AllocateBuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nBufferSize);
1688 if (error!=OMX_ErrorNone){
1689 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_AllocateBuffer failed %x", error);
1690 input_bufs_omx_mutex.Unlock();
1693 input_bufs_omx_all.push_back(buf_head);
1694 input_bufs_omx_free.push_back(buf_head);
1696 omx_first_frame=true;
1699 cur_input_buf_omx=NULL;
1700 input_bufs_omx_mutex.Unlock();
1703 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark3");
1704 if (!CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port)) {
1707 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark4");
1712 int VideoOMX::DestroyInputBufsOMX() //need s to be called with locked mutex
1714 OMX_ERRORTYPE error;
1716 cur_input_buf_omx=NULL;
1717 input_bufs_omx_mutex.Lock();
1718 for (int i=0; i< input_bufs_omx_all.size();i++) {
1719 // free(input_bufs_omx_all[i]->pBuffer);
1720 // input_bufs_omx_all[i]->pBuffer=NULL;
1721 error=OMX_FreeBuffer(omx_vid_dec,omx_codec_input_port,input_bufs_omx_all[i]);
1722 if (error!=OMX_ErrorNone){
1723 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
1724 input_bufs_omx_mutex.Unlock();
1729 input_bufs_omx_all.clear();
1730 input_bufs_omx_free.clear();
1731 input_bufs_omx_mutex.Unlock();
1736 int VideoOMX::FlushRenderingPipe()
1738 OMX_ERRORTYPE error;
1742 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1743 omx_codec_output_port, NULL);
1744 if (error != OMX_ErrorNone) {
1745 Log::getInstance()->log("Video", Log::DEBUG,
1746 "OMX_Flush codec out 1 failed %x", error);
1750 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1751 omx_shed_input_port, NULL);
1752 if (error != OMX_ErrorNone) {
1753 Log::getInstance()->log("Video", Log::DEBUG,
1754 "OMX_Flush shed in 2 failed %x", error);
1758 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1759 omx_codec_output_port)) {
1760 Log::getInstance()->log("Video", Log::DEBUG,
1761 "flush cmd codec 3 failed");
1764 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1765 omx_shed_input_port)) {
1766 Log::getInstance()->log("Video", Log::DEBUG,
1767 "flush cmd shed 4 failed");
1770 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1771 omx_codec_output_port, NULL);
1772 if (error != OMX_ErrorNone) {
1773 Log::getInstance()->log("Video", Log::DEBUG,
1774 "OMX_Flush codec out 5 failed %x", error);
1778 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1779 omx_deint_input_port, NULL);
1780 if (error != OMX_ErrorNone) {
1781 Log::getInstance()->log("Video", Log::DEBUG,
1782 "OMX_Flush deint in 6 failed %x", error);
1786 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1787 omx_codec_output_port)) {
1788 Log::getInstance()->log("Video", Log::DEBUG,
1789 "flush cmd codec 7 failed");
1792 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1793 omx_deint_input_port)) {
1794 Log::getInstance()->log("Video", Log::DEBUG,
1795 "flush cmd deint 8 failed");
1799 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1800 omx_deint_output_port, NULL);
1801 if (error != OMX_ErrorNone) {
1802 Log::getInstance()->log("Video", Log::DEBUG,
1803 "OMX_Flush deint out 9 failed %x", error);
1807 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1808 omx_shed_input_port, NULL);
1809 if (error != OMX_ErrorNone) {
1810 Log::getInstance()->log("Video", Log::DEBUG,
1811 "OMX_Flush shed in 10 failed %x", error);
1815 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1816 omx_deint_output_port)) {
1817 Log::getInstance()->log("Video", Log::DEBUG,
1818 "flush cmd deint 11 failed");
1821 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1822 omx_shed_input_port)) {
1823 Log::getInstance()->log("Video", Log::DEBUG,
1824 "flush cmd shed 12 failed");
1834 error = OMX_SendCommand(omx_vid_rend, OMX_CommandFlush,
1835 omx_rend_input_port, NULL);
1836 if (error != OMX_ErrorNone) {
1837 Log::getInstance()->log("Video", Log::DEBUG,
1838 "OMX_Flush rend in failed %x", error);
1842 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1843 omx_shed_output_port, NULL);
1844 if (error != OMX_ErrorNone) {
1845 Log::getInstance()->log("Video", Log::DEBUG,
1846 "OMX_Flush shed out failed %x", error);
1852 if (!CommandFinished(omx_vid_rend, OMX_CommandFlush,
1853 omx_rend_input_port)) {
1854 Log::getInstance()->log("Video", Log::DEBUG,
1855 "flush cmd shed rend failed");
1858 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1859 omx_shed_output_port)) {
1860 Log::getInstance()->log("Video", Log::DEBUG,
1861 "flush cmd shed rend failed");
1866 int VideoOMX::DeAllocateCodecsOMX()
1868 OMX_ERRORTYPE error;
1870 Log::getInstance()->log("Video", Log::DEBUG, "enter deallocatecodecsomx");
1872 if (cur_input_buf_omx) {
1873 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_EOS;
1874 OMX_ERRORTYPE error=ProtOMXEmptyThisBuffer(omx_vid_dec,cur_input_buf_omx);
1875 if (error!=OMX_ErrorNone) {
1876 Log::getInstance()->log("Video", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error);
1879 cur_input_buf_omx=NULL;//write out old data
1884 // first stop the omx elements
1885 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1886 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1889 clock_mutex.Unlock();
1895 if (!ChangeComponentState(omx_vid_deint, OMX_StateIdle)) {
1896 Log::getInstance()->log("Video", Log::DEBUG,
1897 "vid_deint ChangeComponentState");
1903 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1904 Log::getInstance()->log("Video", Log::DEBUG, "vid_shed ChangeComponentState");
1908 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1909 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1915 // TODO proper deinit sequence
1916 // first flush all buffers
1917 FlushRenderingPipe();
1923 error=OMX_SendCommand(omx_clock,OMX_CommandFlush, omx_clock_output_port, NULL);
1924 if (error!=OMX_ErrorNone){
1925 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush clock out failed %x", error);
1929 error=OMX_SendCommand(omx_vid_sched,OMX_CommandFlush, omx_shed_clock_port, NULL);
1930 if (error!=OMX_ErrorNone){
1931 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush shed clock failed %x", error);
1935 if (!CommandFinished(omx_clock,OMX_CommandFlush,omx_clock_output_port) ||
1936 !CommandFinished(omx_vid_sched,OMX_CommandFlush,omx_shed_clock_port)) {
1937 Log::getInstance()->log("Video", Log::DEBUG, "flush cmd clock shed failed");
1943 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1944 omx_codec_input_port, NULL);
1945 if (error != OMX_ErrorNone) {
1946 Log::getInstance()->log("Video", Log::DEBUG,
1947 "OMX_Flush codec out failed %x", error);
1954 DestroyInputBufsOMX();
1957 if (!DisablePort(omx_vid_sched,omx_shed_output_port,true)) {
1958 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 2 ");
1960 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true)) {
1961 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 1");
1967 if (!DisablePort(omx_vid_dec,omx_codec_output_port,true)) {
1968 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6");
1973 if (!DisablePort(omx_vid_dec,omx_codec_input_port,true)) {
1974 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7");
1978 if (!DisablePort(omx_vid_deint,omx_deint_output_port,true)) {
1979 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6a");
1984 if (!DisablePort(omx_vid_deint,omx_deint_input_port,true)) {
1985 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7a");
1991 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true)) {
1992 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 3");
1995 if (!DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
1996 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 4");
1999 if (!DisablePort(omx_clock,omx_clock_output_port,true)) {
2000 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 5");
2006 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,NULL,NULL);
2007 if (error!=OMX_ErrorNone) {
2008 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2013 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_input_port,NULL,NULL);
2014 if (error!=OMX_ErrorNone) {
2015 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2019 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,NULL,NULL);
2020 if (error!=OMX_ErrorNone) {
2021 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2025 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_input_port,NULL,NULL);
2026 if (error!=OMX_ErrorNone) {
2027 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2032 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,NULL,NULL);
2033 if (error!=OMX_ErrorNone) {
2034 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2038 error=OMX_SetupTunnel(omx_vid_rend,omx_rend_input_port,NULL,NULL);
2039 if (error!=OMX_ErrorNone) {
2040 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2045 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,NULL,NULL);
2046 if (error!=OMX_ErrorNone) {
2047 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2051 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_clock_port,NULL,NULL);
2052 if (error!=OMX_ErrorNone) {
2053 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2060 error=OMX_FreeHandle(omx_vid_dec);
2061 error=OMX_FreeHandle(omx_vid_sched);
2062 error=OMX_FreeHandle(omx_vid_rend);
2063 if (dodeint) error=OMX_FreeHandle(omx_vid_deint);
2065 clock_mutex.Unlock();
2067 if (error!=OMX_ErrorNone) {
2068 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2070 } else clock_mutex.Unlock();
2071 Log::getInstance()->log("Video", Log::DEBUG, "leave deallocate codecs OMX");
2077 void VideoOMX::destroyClock()
2080 if (clock_references>0) {
2082 if (clock_references==0) {
2083 OMX_ERRORTYPE error;
2084 Log::getInstance()->log("Video", Log::DEBUG, "destroy omx clock");
2085 error=OMX_FreeHandle(omx_clock);
2086 if (error!=OMX_ErrorNone) {
2087 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2092 clock_mutex.Unlock();
2096 int VideoOMX::stop()
2098 if (!initted) return 0;
2101 //Check if libav mode
2102 DeAllocateCodecsOMX();
2107 // if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
2111 int VideoOMX::reset()
2113 if (!initted) return 0;
2116 DeAllocateCodecsOMX();
2117 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
2121 int VideoOMX::pause()
2123 if (!initted) return 0;
2124 Log::getInstance()->log("Video", Log::DEBUG, "enter pause");
2127 //maybe also change omx clock?
2128 //pausetimecode=GetCurrentSystemTime();
2134 int VideoOMX::unPause() // FIXME get rid - same as play!! Not here!
2136 if (!initted) return 0;
2137 Log::getInstance()->log("Video", Log::DEBUG, "enter unpause");
2140 // playbacktimeoffset+=GetCurrentSystemTime()-pausetimecode;
2141 paused=false; // may be also change omx clock
2147 int VideoOMX::fastForward()
2149 if (!initted) return 0;
2151 // if (ioctl(fdVideo, AV_SET_VID_libavWD, 1) != 0) return 0;
2155 int VideoOMX::unFastForward()
2157 if (!initted) return 0;
2159 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
2161 //// if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
2165 int VideoOMX::attachFrameBuffer()
2167 if (!initted) return 0;
2169 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2173 int VideoOMX::blank(void)
2175 // if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
2176 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2180 ULLONG VideoOMX::getCurrentTimestamp() {
2183 long long ncur_clock_time = cur_clock_time;
2187 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2188 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2190 OMX_ERRORTYPE error;
2191 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
2192 memset(&clock_conf, 0, sizeof(clock_conf));
2193 clock_conf.nSize = sizeof(clock_conf);
2194 clock_conf.nVersion.nVersion = OMX_VERSION;
2195 error= OMX_GetConfig(omx_clock, OMX_IndexConfigTimeClockState,
2197 if (error != OMX_ErrorNone) {
2198 Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp IndexConfigTimeClockState failed %x",error);
2201 if (clock_conf.eState == OMX_TIME_ClockStateRunning) {
2203 OMX_TIME_CONFIG_TIMESTAMPTYPE cur_time_stamp;
2204 memset(&cur_time_stamp, 0, sizeof(cur_time_stamp));
2205 cur_time_stamp.nSize = sizeof(cur_time_stamp);
2206 cur_time_stamp.nVersion.nVersion = OMX_VERSION;
2207 cur_time_stamp.nPortIndex = omx_clock_output_port;
2208 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2210 if (error != OMX_ErrorNone) {
2211 Log::getInstance()->log("Video",Log::DEBUG,"getCurrentTimestamp OMX_IndexConfigTimeCurrentMediaTime failed %x",error);
2213 long long temp = cur_time_stamp.nTimestamp.nLowPart
2214 | ((long long) cur_time_stamp.nTimestamp.nHighPart << 32);
2215 ncur_clock_time = cur_clock_time = temp * 10LL;
2218 clock_mutex.Unlock();
2219 pthread_setcancelstate(oldcancelstate, NULL);
2220 pthread_setcanceltype(oldcanceltype, NULL);
2223 //ncur_clock_time -= startoffset;
2224 ncur_clock_time -= lastreftimeOMX;
2225 long long result = lastreftimePTS;
2226 if (lastreftimePTS==0) return 0; // invalid time
2227 result += (long long) (ncur_clock_time / 10000LL * 90LL);
2229 result = (1LL << 33) - result;
2230 //Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp %lld %lld %lld %lld %lld %lld",ncur_clock_time,cur_clock_time,lastreftimeOMX,lastreftimePTS,result,startoffset);
2238 ULONG VideoOMX::timecodeToFrameNumber(ULLONG timecode)
2240 if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25);
2241 else return (ULONG)(((double)timecode / (double)90000) * (double)30);
2246 int VideoOMX::test()
2251 // return ioctl(fdVideo, AV_SET_VID_STC, &stc);
2258 int VideoOMX::test2()
2266 long long VideoOMX::SetStartOffset(long long curreftime, bool *rsync)
2270 startoffset=curreftime;//offset is set for audio
2272 offsetvideonotset=false;
2274 if (offsetvideonotset) {
2275 offsetvideonotset=false;
2278 if ( (curreftime-lastrefvideotime)>10000000LL
2279 || (curreftime-lastrefvideotime)<-10000000LL) {//if pts jumps to big resync
2280 startoffset+=curreftime-lastrefvideotime;
2281 lastrefaudiotime+=curreftime-lastrefvideotime;
2283 offsetaudionotset=true;
2290 lastrefvideotime=curreftime;
2296 long long VideoOMX::SetStartAudioOffset(long long curreftime, bool *rsync)
2300 startoffset=curreftime;
2302 offsetaudionotset=false;
2304 if (offsetaudionotset) {
2305 offsetaudionotset=false;
2308 if ( (curreftime-lastrefaudiotime)>10000000LL
2309 || (curreftime-lastrefaudiotime)<-10000000LL) {//if pts jumps to big resync
2310 startoffset+=curreftime-lastrefaudiotime;
2311 lastrefvideotime+=curreftime-lastrefaudiotime;
2313 offsetvideonotset=true;
2319 lastrefaudiotime=curreftime;
2324 void VideoOMX::ResetTimeOffsets() {
2325 offsetnotset=true; //called from demuxer
2326 offsetvideonotset=true;
2327 offsetaudionotset=true;
2336 void VideoOMX::DeinterlaceFix()
2340 Demuxer* demux=Demuxer::getInstance();
2341 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2342 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2344 OMX_ERRORTYPE error;
2345 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
2346 memset(&port_def_type,0,sizeof(port_def_type));
2347 port_def_type.nSize=sizeof(port_def_type);
2348 port_def_type.nVersion.nVersion=OMX_VERSION;
2349 port_def_type.nPortIndex=omx_codec_output_port;
2351 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
2352 if (error != OMX_ErrorNone) {
2353 Log::getInstance()->log("Video", Log::DEBUG,
2354 "OMX_IndexParamPortDefinition fix failed %x", error);
2355 clock_mutex.Unlock();
2359 if (port_def_type.format.video.nFrameWidth == demux->getHorizontalSize()
2360 && port_def_type.format.video.nFrameHeight == demux->getVerticalSize()){
2361 Log::getInstance()->log("Video", Log::DEBUG,
2362 "Deinit first frame fix");
2363 deint_first_frame=false;
2365 WaitForEvent(omx_vid_dec,OMX_EventPortSettingsChanged);
2366 DisablePort(omx_vid_dec,omx_codec_output_port,false);
2367 DisablePort(omx_vid_sched,omx_shed_input_port,false);
2368 DisablePort(omx_vid_deint,omx_deint_output_port,false);
2369 DisablePort(omx_vid_deint,omx_deint_input_port,false);
2371 port_def_type.nPortIndex=omx_deint_input_port;
2372 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2374 if (error != OMX_ErrorNone) {
2375 Log::getInstance()->log("Video", Log::DEBUG,
2376 "Set OMX_IndexParamPortDefinition1 failed %x", error);
2377 clock_mutex.Unlock();
2378 pthread_setcancelstate(oldcancelstate, NULL);
2379 pthread_setcanceltype(oldcanceltype, NULL);
2383 port_def_type.nPortIndex=omx_deint_output_port;
2384 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2386 if (error != OMX_ErrorNone) {
2387 Log::getInstance()->log("Video", Log::DEBUG,
2388 "Set OMX_IndexParamPortDefinition2 failed %x", error);
2389 clock_mutex.Unlock();
2390 pthread_setcancelstate(oldcancelstate, NULL);
2391 pthread_setcanceltype(oldcanceltype, NULL);
2396 EnablePort(omx_vid_dec,omx_codec_output_port,false);
2397 EnablePort(omx_vid_deint,omx_deint_input_port,false);
2398 EnablePort(omx_vid_deint,omx_deint_output_port,false);
2399 EnablePort(omx_vid_sched,omx_shed_input_port,false);
2401 clock_mutex.Unlock();
2402 pthread_setcancelstate(oldcancelstate, NULL);
2403 pthread_setcanceltype(oldcanceltype, NULL);
2410 void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer)
2413 OMX_ERRORTYPE error = ProtOMXEmptyThisBuffer(omx_vid_dec, buffer);
2414 if (error != OMX_ErrorNone) {
2415 Log::getInstance()->log("Video", Log::DEBUG,
2416 "OMX_EmptyThisBuffer failed %x", error);
2418 if (deint_first_frame && dodeint) DeinterlaceFix();
2422 OMX_ERRORTYPE VideoOMX::ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer)
2424 // protect the call to empty this buffer
2427 /* long long temp =buffer->nTimeStamp.nLowPart
2428 | ((long long) buffer->nTimeStamp.nHighPart << 32);*/
2430 //pthread_testcancel();
2431 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2432 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2435 /* OMX_ERRORTYPE error;
2436 OMX_TIME_CONFIG_TIMESTAMPTYPE timestamp;
2437 memset(×tamp, 0, sizeof(timestamp));
2438 timestamp.nSize = sizeof(timestamp);
2439 timestamp.nVersion.nVersion = OMX_VERSION;
2440 timestamp.nPortIndex =omx_clock_output_port;
2442 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2445 if (error != OMX_ErrorNone) {
2446 Log::getInstance()->log("Audio", Log::DEBUG,
2447 "Init OMX_IndexConfigAudioRenderingLatencyfailed %x %d", error,
2448 omx_rend_input_port);
2450 long long temp2 =timestamp.nTimestamp.nLowPart
2451 | ((long long) timestamp.nTimestamp.nHighPart << 32);
2454 Log::getInstance()->log("Video", Log::NOTICE, "OMXETB %x %lld %lld %x",handle,temp,temp2,buffer->nFlags);*/
2455 OMX_ERRORTYPE ret_val;
2456 ret_val=OMX_EmptyThisBuffer(handle,buffer);
2457 clock_mutex.Unlock();
2458 pthread_setcancelstate(oldcancelstate, NULL);
2459 pthread_setcanceltype(oldcanceltype, NULL);
2460 //pthread_testcancel();
2464 bool VideoOMX::detectIFrame(const UCHAR *buffer,unsigned int length)
2466 const UCHAR* curbuf=buffer;
2467 const UCHAR* curbufend=buffer+length;
2468 unsigned int detector=0xFFFFFFFF;
2469 bool gotaud=false; // have seen access unit delimiter
2471 while (curbuf!=curbufend) {
2475 if (detector==0x00000109) {
2477 detector=0xFFFFFFFF;
2478 } else if (gotaud &&detector==0x00000001) {
2480 if (curbuf!=curbufend) {
2481 unsigned char picttype=(*curbuf)& 0x1F;
2482 return picttype==0x07;
2486 if (detector==0x00000100) {
2488 if (curbuf==curbufend) return false;
2490 if (curbuf==curbufend) return false;
2491 unsigned char picttype=((*curbuf) >> 3) & 0x07;
2498 return false; // no frame found
2501 void VideoOMX::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
2504 mediapackets.clear();
2505 list<MediaPacket>::const_iterator begin=mplist.begin();
2506 list<MediaPacket>::const_iterator itty=mplist.begin();
2507 advance(itty,min(mplist.size(),10));
2508 mediapackets.insert(mediapackets.begin(),begin,itty);//front
2512 UINT VideoOMX::DeliverMediaSample(UCHAR* buffer, UINT *samplepos)
2515 while (consumed<mediapackets.size()) {
2516 DeliverMediaPacket(mediapackets[consumed], buffer, samplepos);
2517 if (*samplepos == mediapackets[consumed].length) {
2521 } else return consumed;
2526 UINT VideoOMX::DeliverMediaPacket(MediaPacket packet,
2527 const UCHAR* buffer,
2530 if (packet.type == MPTYPE_VIDEO_H264)
2540 //Later add fail back code for libav
2542 *samplepos+=packet.length;
2543 return packet.length;
2547 if (!omx_running) return 0; // if we are not runnig do not do this
2548 if (paused) return 0; //Block if we pause
2550 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 1");
2551 //Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX time %lld",packet.presentation_time);
2554 OMX_ERRORTYPE error;
2556 /*First Check, if we have an video sample*/
2560 return 0; //Not in iframe mode!
2564 if (packet.disconti) {
2566 if (cur_input_buf_omx) {
2567 PutBufferToPres(cur_input_buf_omx);
2568 cur_input_buf_omx=NULL;
2571 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2");
2572 /*Inspect PES-Header */
2574 // OMX_STATETYPE temp_state;
2575 // OMX_GetState(omx_vid_dec,&temp_state);
2577 if (*samplepos==0) {//stripheader
2578 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
2579 // if (h264) Log::getInstance()->log("Video", Log::DEBUG, "PES info %x %x %x %x",
2580 // buffer[packet.pos_buffer+0],buffer[packet.pos_buffer+1],buffer[packet.pos_buffer+2],buffer[packet.pos_buffer+3]);
2581 *samplepos+=headerstrip;
2582 if ( packet.synched ) {
2583 if (!firstsynched) {
2584 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2a");
2585 // check if this is an I frame, the decoder does not like non I frames at startup!
2586 if (!detectIFrame(buffer,packet.length)) {
2587 *samplepos=packet.length;//if we have not processed at least one
2588 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 3");
2589 return packet.length;//synched packet ignore it!
2592 if (cur_input_buf_omx) {
2593 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4a");
2594 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_ENDOFFRAME;
2595 PutBufferToPres(cur_input_buf_omx);
2596 cur_input_buf_omx=NULL;//write out old data
2598 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4b");
2603 if (!firstsynched) {//
2604 *samplepos=packet.length;//if we have not processed at least one
2605 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 5");
2606 return packet.length;//synched packet ignore it!
2610 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 6");
2611 if (!cur_input_buf_omx) {
2612 input_bufs_omx_mutex.Lock();
2613 if (input_bufs_omx_free.size()==0) {
2614 input_bufs_omx_mutex.Unlock();
2615 //Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample");
2616 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 7");
2617 return 0; // we do not have a free media sample
2620 cur_input_buf_omx=input_bufs_omx_free.front();
2621 cur_input_buf_omx->nFilledLen=0;
2622 cur_input_buf_omx->nOffset=0;
2623 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2624 input_bufs_omx_free.pop_front();
2625 input_bufs_omx_mutex.Unlock();
2631 if (cur_input_buf_omx->nFilledLen==0) {//will only be changed on first packet
2632 if (packet.synched) {
2633 // Log::getInstance()->log("Video", Log::DEBUG, "packet synched marker");
2635 //lastreftimePTS=packet.pts;
2636 if (omx_first_frame) { // TODO time
2637 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_STARTTIME;
2638 Log::getInstance()->log("Video", Log::DEBUG, "Starttime");
2639 omx_first_frame=false;
2641 cur_input_buf_omx->nFlags=0;
2642 //cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_TIME_UNKNOWN;
2644 lastreftimeOMX=packet.presentation_time;
2645 // Log::getInstance()->log("Video", Log::DEBUG, "Time code %lld pts %lld", lastreftimeOMX,packet.pts);
2646 lastreftimePTS=packet.pts;
2647 cur_input_buf_omx->nTimeStamp=intToOMXTicks(lastreftimeOMX/10LL); // the clock component is faulty;
2651 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2652 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2653 //Log::getInstance()->log("Video", Log::DEBUG, "packet unsynched marker");
2655 if (packet.disconti) cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_DISCONTINUITY;
2660 unsigned int haveToCopy=packet.length-*samplepos;
2661 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 8");
2663 while (haveToCopy> (cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen)) {
2664 //Log::getInstance()->log("Video", Log::DEBUG, "Big buffer %d %d %d",packet.length,cur_input_buf_omx->nAllocLen,cur_input_buf_omx->nFilledLen);
2665 unsigned int cancopy=cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen;
2666 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,buffer+packet.pos_buffer+*samplepos,cancopy);
2667 haveToCopy-=cancopy;
2668 cur_input_buf_omx->nFilledLen+=cancopy;
2669 *samplepos+=cancopy;
2670 // push old buffer out
2671 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 9");
2673 PutBufferToPres(cur_input_buf_omx);
2674 cur_input_buf_omx=NULL;
2676 input_bufs_omx_mutex.Lock();
2677 if (input_bufs_omx_free.size()==0) {
2678 input_bufs_omx_mutex.Unlock();
2679 // Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample2");
2680 return *samplepos; // we do not have a free media sample
2682 cur_input_buf_omx=input_bufs_omx_free.front();
2683 cur_input_buf_omx->nFilledLen=0;
2684 cur_input_buf_omx->nOffset=0;
2685 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2686 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2687 input_bufs_omx_free.pop_front();
2688 input_bufs_omx_mutex.Unlock();
2689 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 10");
2692 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,
2693 buffer+packet.pos_buffer+*samplepos,haveToCopy);
2694 cur_input_buf_omx->nFilledLen+=haveToCopy;
2696 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 11");
2698 *samplepos+=haveToCopy;
2707 bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) {
2708 if (!omx_running) return false;
2710 EnterIframePlayback();
2712 int haveToCopy = length;
2714 if (!cur_input_buf_omx) {
2715 input_bufs_omx_mutex.Lock();
2716 if (input_bufs_omx_free.size() == 0) {
2717 input_bufs_omx_mutex.Unlock();
2718 // Log::getInstance()->log("Video", Log::DEBUG,
2719 // "Deliver MediaPacket no free sample");
2720 return false; // we do not have a free media sample
2723 cur_input_buf_omx = input_bufs_omx_free.front();
2724 cur_input_buf_omx->nFilledLen = 0;
2725 cur_input_buf_omx->nOffset = 0;
2726 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2727 input_bufs_omx_free.pop_front();
2728 input_bufs_omx_mutex.Unlock();
2732 unsigned int pattern, packet_length;
2733 unsigned int headerstrip = 0;
2738 //Now we strip the pes header
2739 pattern = (buffer[0] << 16) | (buffer[1] << 8) | (buffer[2]);
2740 while (read_pos + 7 <= length) {
2741 pattern = ((pattern << 8) & 0xFFFFFFFF) | buffer[read_pos + 3];
2742 if (pattern < 0x000001E0 || pattern > 0x000001EF) {
2746 headerstrip = buffer[read_pos + 8] + 9/*is this right*/;
2747 packet_length = ((buffer[read_pos + 4] << 8)
2748 | (buffer[read_pos + 5])) + 6;
2749 if (read_pos + packet_length > length)
2752 if ((headerstrip < packet_length)
2753 && (cur_input_buf_omx->nFilledLen + packet_length
2754 - headerstrip) > cur_input_buf_omx->nAllocLen) {
2756 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2759 cur_input_buf_omx->nFlags
2760 |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2763 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2764 PutBufferToPres(cur_input_buf_omx);
2765 cur_input_buf_omx = NULL;
2767 if (!cur_input_buf_omx) {
2769 while (count < 100 && omx_running && iframemode) {
2772 input_bufs_omx_mutex.Lock();
2773 if (input_bufs_omx_free.size() == 0) {
2774 input_bufs_omx_mutex.Unlock();
2775 // Log::getInstance()->log("Video", Log::DEBUG,
2776 // "Ifrane no free sample");
2778 if (!omx_running) return false;
2781 cur_input_buf_omx = input_bufs_omx_free.front();
2782 cur_input_buf_omx->nFilledLen = 0;
2783 cur_input_buf_omx->nOffset = 0;
2784 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2785 cur_input_buf_omx->nFlags|= OMX_BUFFERFLAG_TIME_UNKNOWN;
2786 input_bufs_omx_free.pop_front();
2787 input_bufs_omx_mutex.Unlock();
2790 if (!cur_input_buf_omx)
2795 if (packet_length > headerstrip) {
2797 cur_input_buf_omx->pBuffer
2798 + cur_input_buf_omx->nFilledLen,
2799 buffer + read_pos + headerstrip,
2800 packet_length - headerstrip);
2801 cur_input_buf_omx->nFilledLen += packet_length
2804 read_pos += packet_length;
2806 pattern = (buffer[read_pos] << 16)
2807 | (buffer[read_pos + 1] << 8) | (buffer[read_pos + 2]);
2813 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2816 cur_input_buf_omx->nFlags |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2819 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2821 PutBufferToPres(cur_input_buf_omx);
2822 cur_input_buf_omx = NULL;
2825 MILLISLEEP(40); //Block a bit
2829 int VideoOMX::EnterIframePlayback()
2831 Log::getInstance()->log("Video", Log::DEBUG,
2832 "EnterIframePlayback");
2833 if (cur_input_buf_omx) {
2834 PutBufferToPres(cur_input_buf_omx);
2835 cur_input_buf_omx = NULL;
2837 Log::getInstance()->log("Video", Log::DEBUG,
2838 "EnterIframePlayback 2");
2839 ((AudioOMX*)Audio::getInstance())->DeAllocateCodecsOMX();
2840 DeAllocateCodecsOMX();
2841 AllocateCodecsOMX();
2842 Log::getInstance()->log("Video", Log::DEBUG,
2843 "leave IframePlayback");