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,12,11)) { 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,parx,pary);
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, "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, int tparx,int tpary)
494 if (!initted) return 0;
495 //if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
496 aspectRatio = taspectRatio;
500 Log::getInstance()->log("Video", Log::DEBUG, "Setting aspect to %i: PAR %d %d", aspectRatio,parx,pary);
503 // if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
507 int VideoOMX::setMode(UCHAR tmode)
509 if (!initted) return 0;
516 void VideoOMX::updateMode()
522 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
523 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
525 OMX_CONFIG_DISPLAYREGIONTYPE dispconf;
526 memset(&dispconf, 0, sizeof(dispconf));
527 dispconf.nSize = sizeof(dispconf);
528 dispconf.nVersion.nVersion = OMX_VERSION;
529 dispconf.nPortIndex = omx_rend_input_port;
531 dispconf.set = OMX_DISPLAY_SET_LAYER;
532 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
534 if (error != OMX_ErrorNone) {
535 Log::getInstance()->log("Video", Log::DEBUG,
536 "Set OMX_IndexConfigDisplayRegion1 failed %x", error);
537 clock_mutex.Unlock();
542 dispconf.pixel_x =parx;
543 dispconf.pixel_y=pary;
544 dispconf.set = OMX_DISPLAY_SET_PIXEL;
545 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
547 if (error != OMX_ErrorNone) {
548 Log::getInstance()->log("Video", Log::DEBUG,
549 "Set OMX_IndexConfigDisplayRegion5 failed %x", error);
550 clock_mutex.Unlock();
556 dispconf.set = OMX_DISPLAY_SET_FULLSCREEN;
557 if (mode != QUARTER && mode != EIGHTH) {
559 dispconf.fullscreen = OMX_TRUE;
561 dispconf.fullscreen = OMX_FALSE;
563 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
565 if (error != OMX_ErrorNone) {
566 Log::getInstance()->log("Video", Log::DEBUG,
567 "Set OMX_IndexConfigDisplayRegion2 failed %x", error);
568 clock_mutex.Unlock();
572 dispconf.set = OMX_DISPLAY_SET_MODE;
573 if (mode != QUARTER && mode != EIGHTH) {
574 dispconf.mode = (mode == NORMAL) ? OMX_DISPLAY_MODE_FILL
575 : OMX_DISPLAY_MODE_LETTERBOX;
577 dispconf.mode = OMX_DISPLAY_MODE_LETTERBOX;
579 error = OMX_SetParameter(omx_vid_rend, OMX_IndexConfigDisplayRegion,
581 if (error != OMX_ErrorNone) {
582 Log::getInstance()->log("Video", Log::DEBUG,
583 "Set OMX_IndexConfigDisplayRegion3 failed %x", error);
584 clock_mutex.Unlock();
588 if (mode == QUARTER || mode == EIGHTH) {
589 unsigned int display_width, display_height;
590 display_width = display_height = 0;
591 if (graphics_get_display_size(0, &display_width, &display_height)
593 Log::getInstance()->log("OSD", Log::WARN,
594 "Getting display size failed! (BCM API) ");
595 clock_mutex.Unlock();
598 //UnSetFullscreen with window
599 dispconf.set = OMX_DISPLAY_SET_DEST_RECT;
600 dispconf.dest_rect.x_offset
601 = (int) (xpos * ((float) display_width));
602 dispconf.dest_rect.y_offset = (int) (ypos
603 * ((float) display_height));
604 if (mode == QUARTER) {
605 dispconf.dest_rect.width = display_width >> 1;
606 dispconf.dest_rect.height = display_height >> 1;
607 } else if (mode == EIGHTH) {
608 dispconf.dest_rect.width = display_width >> 2;
609 dispconf.dest_rect.height = display_height >> 2;
611 error = OMX_SetParameter(omx_vid_rend,
612 OMX_IndexConfigDisplayRegion, &dispconf);
613 if (error != OMX_ErrorNone) {
614 Log::getInstance()->log("Video", Log::DEBUG,
615 "Set OMX_IndexConfigDisplayRegion failed %x", error);
616 clock_mutex.Unlock();
620 clock_mutex.Unlock();
621 pthread_setcancelstate(oldcancelstate, NULL);
622 pthread_setcanceltype(oldcanceltype, NULL);
625 clock_mutex.Unlock();
628 int VideoOMX::signalOff()
631 Log::getInstance()->log("Video", Log::NOTICE, "signalOff");
632 Osd::getInstance()->stopUpdate(); // turn off drawing thread
633 Remote::getInstance()->shutdown();
635 Remote::getInstance()->init("");
640 int VideoOMX::signalOn()
643 Osd::getInstance()->shutdown();
644 Log::getInstance()->log("Video", Log::NOTICE, "signalOn");
646 Osd::getInstance()->restore();
647 Osd::getInstance()->init((void*)"");
648 BoxStack::getInstance()->redrawAllBoxes();
655 int VideoOMX::setSource()
657 if (!initted) return 0;
659 // What does this do...
660 // if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
664 int VideoOMX::setPosition(int x, int y) {
667 xpos = ((float) x*2.f) / ((float) screenWidth);
668 ypos = ((float) y*2.f) / ((float) screenHeight);
676 if (!initted) return 0;
678 // if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
682 void VideoOMX::interlaceSwitch4Demux() {
684 Demuxer *demux=Demuxer::getInstance();
685 if ( (outputinterlaced && !demux->getInterlaced())
686 || (!outputinterlaced && demux->getInterlaced())) {
687 if (hdmi && (demux->getHorizontalSize()>720 || demux->getInterlaced() )) { // only switch if hdmi and HD or interlaced SD material
688 Log::getInstance()->log("Video", Log::NOTICE, "switch interlacing %d",demux->getInterlaced());
691 int set_interlaced=0;
692 if (demux->getHorizontalSize()>720 && demux->getInterlaced()) {
695 selectVideoMode(set_interlaced);
697 Osd::getInstance()->shutdown();
698 Osd::getInstance()->restore();
699 Osd::getInstance()->init((void*)"");
700 BoxStack::getInstance()->redrawAllBoxes();
709 int VideoOMX::play() {
713 Log::getInstance()->log("Video", Log::DEBUG, "enter play");
715 interlaceSwitch4Demux();
717 if (AllocateCodecsOMX()) {
719 // Otherwise fall back to libav
723 Log::getInstance()->log("Video", Log::NOTICE,
724 "Allocate Codecs OMX failed assume h264 unsupported");
727 Log::getInstance()->log("Video", Log::NOTICE,
728 "Allocate Codecs OMX failed assume mpeg2 unsupported");
737 int VideoOMX::initClock()
741 if (clock_references==0)
744 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
747 error=OMX_GetHandle(&omx_clock,VPE_OMX_CLOCK,NULL,&callbacks);
749 if (error!=OMX_ErrorNone) {
750 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX clock failed %x", error);
751 clock_mutex.Unlock();
752 DeAllocateCodecsOMX();
756 /* TODO Clock config to separate method */
757 OMX_PORT_PARAM_TYPE p_param;
758 memset(&p_param,0,sizeof(p_param));
759 p_param.nSize=sizeof(p_param);
760 p_param.nVersion.nVersion=OMX_VERSION;
761 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
762 if (error!=OMX_ErrorNone) {
763 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
764 clock_mutex.Unlock();
765 DeAllocateCodecsOMX();
768 omx_clock_output_port=p_param.nStartPortNumber;
770 for (unsigned int i=0;i<p_param.nPorts;i++) {
771 if (!DisablePort(omx_clock,p_param.nStartPortNumber+i,true) ) {
772 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX clock failed %d",i);
773 clock_mutex.Unlock();
774 DeAllocateCodecsOMX();
783 Log::getInstance()->log("Video", Log::DEBUG, "init omx clock %x %x",this,omx_clock);
785 clock_mutex.Unlock();
789 int VideoOMX::getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port)
793 *p_omx_clock_output_port=0;
800 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
801 memset(&refclock,0,sizeof(refclock));
802 refclock.nSize=sizeof(refclock);
803 refclock.nVersion.nVersion=OMX_VERSION;
805 refclock.eClock=OMX_TIME_RefClockAudio;
807 //refclock.eClock=OMX_TIME_RefClockVideo;
808 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
809 if (error!=OMX_ErrorNone){
810 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
811 clock_mutex.Unlock();
812 DeAllocateCodecsOMX();
816 OMX_PORT_PARAM_TYPE p_param;
817 memset(&p_param,0,sizeof(p_param));
818 p_param.nSize=sizeof(p_param);
819 p_param.nVersion.nVersion=OMX_VERSION;
820 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
821 if (error!=OMX_ErrorNone){
822 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
823 clock_mutex.Unlock();
824 DeAllocateCodecsOMX();
828 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
829 memset(&clock_conf,0,sizeof(clock_conf));
830 clock_conf.nSize=sizeof(clock_conf);
831 clock_conf.nVersion.nVersion=OMX_VERSION;
832 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
833 clock_conf.nStartTime=intToOMXTicks(0);
834 clock_conf.nOffset=intToOMXTicks(0);
835 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT1;
836 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
837 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
838 if (error!=OMX_ErrorNone) {
839 Log::getInstance()->log("Video", Log::DEBUG, "AuI Clock IndexConfigTimeClockState failed %x", error);
843 *p_omx_clock_output_port=p_param.nStartPortNumber+1;
844 *p_omx_clock=omx_clock;
845 clock_mutex.Unlock();
849 int VideoOMX::getClockVideoandInit()
858 if (clock_references==1) { // only if no audio is attached to this clock!
859 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
860 memset(&refclock,0,sizeof(refclock));
861 refclock.nSize=sizeof(refclock);
862 refclock.nVersion.nVersion=OMX_VERSION;
864 //refclock.eClock=OMX_TIME_RefClockAudio;
866 refclock.eClock=OMX_TIME_RefClockVideo;
867 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
868 if (error!=OMX_ErrorNone) {
869 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
870 clock_mutex.Unlock();
871 DeAllocateCodecsOMX();
876 OMX_PORT_PARAM_TYPE p_param;
877 memset(&p_param,0,sizeof(p_param));
878 p_param.nSize=sizeof(p_param);
879 p_param.nVersion.nVersion=OMX_VERSION;
880 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
881 if (error!=OMX_ErrorNone){
882 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
883 clock_mutex.Unlock();
884 DeAllocateCodecsOMX();
889 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
890 memset(&clock_conf,0,sizeof(clock_conf));
891 clock_conf.nSize=sizeof(clock_conf);
892 clock_conf.nVersion.nVersion=OMX_VERSION;
893 clock_conf.eState=OMX_TIME_ClockStateStopped;
894 clock_conf.nStartTime=intToOMXTicks(0);
895 clock_conf.nOffset=intToOMXTicks(0);
896 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
897 if (error!=OMX_ErrorNone) {
898 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
902 memset(&clock_conf,0,sizeof(clock_conf));
903 clock_conf.nSize=sizeof(clock_conf);
904 clock_conf.nVersion.nVersion=OMX_VERSION;
905 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
906 clock_conf.nStartTime=intToOMXTicks(0);
907 clock_conf.nOffset=intToOMXTicks(0);
908 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT0;
909 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
910 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
911 if (error!=OMX_ErrorNone) {
912 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
915 omx_clock_output_port=p_param.nStartPortNumber;
916 clock_mutex.Unlock();
921 void VideoOMX::clockUnpause()
924 Log::getInstance()->log("Video", Log::NOTICE, "enter Clockunpause");
926 if (clock_references>0 && clockpaused) {
927 OMX_TIME_CONFIG_SCALETYPE scale_type;
928 memset(&scale_type,0,sizeof(scale_type));
929 scale_type.nSize=sizeof(scale_type);
930 scale_type.nVersion.nVersion=OMX_VERSION;
931 scale_type.xScale=1<<16;
932 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeScale,&scale_type);
933 if (error!=OMX_ErrorNone) {
934 Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause OMX_IndexConfigTimeScale failed %x", error);
936 Log::getInstance()->log("Video", Log::NOTICE, "set playback speed ClockUnpause");
939 clock_mutex.Unlock();
943 void VideoOMX::clockPause()
946 Log::getInstance()->log("Video", Log::NOTICE, "enter ClockPause");
948 if (clock_references>0 && !clockpaused) {
949 OMX_TIME_CONFIG_SCALETYPE scale_type;
950 memset(&scale_type,0,sizeof(scale_type));
951 scale_type.nSize=sizeof(scale_type);
952 scale_type.nVersion.nVersion=OMX_VERSION;
954 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeScale,&scale_type);
955 if (error!=OMX_ErrorNone) {
956 Log::getInstance()->log("Video", Log::DEBUG, "ClockPause OMX_IndexConfigTimeScale failed %x", error);
958 Log::getInstance()->log("Video", Log::NOTICE, "set playback speed ClockPause");
961 clock_mutex.Unlock();
966 int VideoOMX::AllocateCodecsOMX()
969 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
971 Demuxer* demux=Demuxer::getInstance();
974 deint_first_frame=false;
976 Log::getInstance()->log("Video", Log::NOTICE, "Allocate Codecs OMX");
977 //Clock, move later to audio including events
979 Log::getInstance()->log("Video", Log::NOTICE, "VideoType %d x %d i: %d", demux->getHorizontalSize(),demux->getVerticalSize(),demux->getInterlaced());
980 if (deinterlace!=0 && (demux->getHorizontalSize()<=720 ) && demux->getInterlaced()) { //only deinterlace SD material
982 deint_first_frame=true;
984 Log::getInstance()->log("Video", Log::NOTICE, "Deinterlacing activated %d",deinterlace);
989 if (!getClockVideoandInit()){
990 return 0;// get the clock and init it if necessary
995 Log::getInstance()->log("Video", Log::DEBUG, "idleClock failed");
1002 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_H264_DECODER,NULL,&callbacks);
1004 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_MPEG2_DECODER,NULL,&callbacks);
1007 if (error!=OMX_ErrorNone){
1008 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video decoder failed %x", error);
1009 clock_mutex.Unlock();
1010 DeAllocateCodecsOMX();
1015 Log::getInstance()->log("Video", Log::DEBUG, "Nmark3 ");
1016 OMX_PORT_PARAM_TYPE p_param;
1017 memset(&p_param,0,sizeof(p_param));
1018 p_param.nSize=sizeof(p_param);
1019 p_param.nVersion.nVersion=OMX_VERSION;
1020 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamVideoInit,&p_param);
1021 if (error!=OMX_ErrorNone){
1022 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX h264 decoder OMX_GetParameter failed %x", error);
1023 clock_mutex.Unlock();
1024 DeAllocateCodecsOMX();
1027 omx_codec_input_port=p_param.nStartPortNumber;
1028 omx_codec_output_port=p_param.nStartPortNumber+1;
1030 if (!DisablePort(omx_vid_dec,omx_codec_input_port) || !DisablePort(omx_vid_dec,omx_codec_output_port)) {
1031 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video decoder failed");
1032 clock_mutex.Unlock();
1033 DeAllocateCodecsOMX();
1037 Log::getInstance()->log("Video", Log::DEBUG, "Nmark4 ");
1039 OMX_PARAM_BRCMVIDEODECODEERRORCONCEALMENTTYPE conceal;
1040 memset(&conceal,0,sizeof(conceal));
1041 conceal.nSize=sizeof(conceal);
1042 conceal.nVersion.nVersion=OMX_VERSION;
1043 conceal.bStartWithValidFrame=OMX_FALSE;
1045 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamBrcmVideoDecodeErrorConcealment,&conceal);
1046 if (error!=OMX_ErrorNone){
1047 Log::getInstance()->log("Video", Log::DEBUG, "OMX_IndexParamBrcmVideoDecodeErrorConcealment failed %x", error);
1048 clock_mutex.Unlock();
1049 DeAllocateCodecsOMX();
1054 error = OMX_GetHandle(&omx_vid_deint, VPE_OMX_VIDEO_DEINTERLACE, NULL,
1056 if (error != OMX_ErrorNone) {
1057 Log::getInstance()->log("Video", Log::DEBUG,
1058 "Init OMX video deinterlacer failed %x", error);
1059 clock_mutex.Unlock();
1060 DeAllocateCodecsOMX();
1064 error = OMX_GetParameter(omx_vid_deint, OMX_IndexParamImageInit,
1066 if (error != OMX_ErrorNone) {
1067 Log::getInstance()->log("Video", Log::DEBUG,
1068 "Init OMX video deinterlacer OMX_GetParameter failed %x",
1070 clock_mutex.Unlock();
1071 DeAllocateCodecsOMX();
1074 omx_deint_input_port = p_param.nStartPortNumber;
1075 omx_deint_output_port = p_param.nStartPortNumber + 1;
1077 if (!DisablePort(omx_vid_deint, omx_deint_input_port, true)
1078 || !DisablePort(omx_vid_deint, omx_deint_output_port, true)) {
1079 Log::getInstance()->log("Video", Log::DEBUG,
1080 "Disable Ports OMX video deint failed");
1081 clock_mutex.Unlock();
1082 DeAllocateCodecsOMX();
1089 error=OMX_GetHandle(&omx_vid_sched,VPE_OMX_VIDEO_SCHED,NULL,&callbacks);
1090 if (error!=OMX_ErrorNone){
1091 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler failed %x", error);
1092 clock_mutex.Unlock();
1093 DeAllocateCodecsOMX();
1099 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamVideoInit,&p_param);
1100 if (error!=OMX_ErrorNone){
1101 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1102 clock_mutex.Unlock();
1103 DeAllocateCodecsOMX();
1106 omx_shed_input_port=p_param.nStartPortNumber;
1107 omx_shed_output_port=p_param.nStartPortNumber+1;
1110 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamOtherInit,&p_param);
1111 if (error!=OMX_ErrorNone){
1112 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1113 clock_mutex.Unlock();
1114 DeAllocateCodecsOMX();
1117 omx_shed_clock_port=p_param.nStartPortNumber;
1118 Log::getInstance()->log("Video", Log::DEBUG, "scheduler ports %d %d %d ",omx_shed_input_port,omx_shed_output_port,omx_shed_clock_port);
1121 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true) || !DisablePort(omx_vid_sched,omx_shed_output_port,true)
1122 || !DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
1123 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video shed failed");
1124 clock_mutex.Unlock();
1125 DeAllocateCodecsOMX();
1130 error=OMX_GetHandle(&omx_vid_rend,VPE_OMX_VIDEO_REND,NULL,&callbacks);
1131 if (error!=OMX_ErrorNone){
1132 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend failed %x", error);
1133 clock_mutex.Unlock();
1134 DeAllocateCodecsOMX();
1138 error=OMX_GetParameter(omx_vid_rend,OMX_IndexParamVideoInit,&p_param);
1139 if (error!=OMX_ErrorNone){
1140 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend OMX_GetParameter failed %x", error);
1141 clock_mutex.Unlock();
1142 DeAllocateCodecsOMX();
1145 omx_rend_input_port=p_param.nStartPortNumber;
1146 //omx_rend_output_port=p_param.nStartPortNumber+1;
1149 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true) /*|| !DisablePort(omx_vid_rend,omx_rend_output_port)*/
1151 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video rend failed");
1152 clock_mutex.Unlock();
1153 DeAllocateCodecsOMX();
1161 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,omx_vid_sched,omx_shed_clock_port);
1162 if (error!=OMX_ErrorNone){
1163 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);
1164 clock_mutex.Unlock();
1165 DeAllocateCodecsOMX();
1169 if (!EnablePort(omx_clock,omx_clock_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_clock_port,false)
1171 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX clock shed failed");
1172 clock_mutex.Unlock();
1173 DeAllocateCodecsOMX();
1178 Log::getInstance()->log("Video", Log::DEBUG, "mark2 ");
1179 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1180 Log::getInstance()->log("Video", Log::DEBUG, "vid_sched idle ChangeComponentState");
1181 clock_mutex.Unlock();
1182 DeAllocateCodecsOMX();
1188 Log::getInstance()->log("Video", Log::DEBUG, "mark1 ");
1189 if ( !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_clock_port)) {
1190 clock_mutex.Unlock();
1191 DeAllocateCodecsOMX();
1198 Log::getInstance()->log("Video", Log::DEBUG, "mark1 special ");
1199 if ( !CommandFinished(omx_clock,OMX_CommandPortEnable,omx_clock_output_port)) {
1200 clock_mutex.Unlock();
1201 DeAllocateCodecsOMX();
1207 Log::getInstance()->log("Video", Log::DEBUG, "mark1b ");
1210 /* error=OMX_SendCommand(omx_vid_dec,OMX_CommandStateSet,OMX_StateIdle,0);
1211 if (error!=OMX_ErrorNone){
1212 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec Send Command to OMX State Idle %x", error);
1216 OMX_VIDEO_PARAM_PORTFORMATTYPE ft_type;
1217 memset(&ft_type,0,sizeof(ft_type));
1218 ft_type.nSize=sizeof(ft_type);
1219 ft_type.nVersion.nVersion=OMX_VERSION;
1221 ft_type.nPortIndex=omx_codec_input_port;
1223 ft_type.eCompressionFormat=OMX_VIDEO_CodingAVC;
1225 ft_type.eCompressionFormat=OMX_VIDEO_CodingMPEG2;
1230 ft_type.xFramerate=0*(1<<16);//25*(1<<16);//demux->getFrameRate()*(1<<16);
1231 Log::getInstance()->log("Video", Log::DEBUG, "Framerate: %d",demux->getFrameRate());
1232 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamVideoPortFormat,&ft_type);
1233 if (error!=OMX_ErrorNone){
1234 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexParamVideoPortFormat failed %x", error);
1235 clock_mutex.Unlock();
1236 DeAllocateCodecsOMX();
1241 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1242 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1243 clock_mutex.Unlock();
1244 DeAllocateCodecsOMX();
1249 if (!PrepareInputBufsOMX()) {
1250 clock_mutex.Unlock();
1251 DeAllocateCodecsOMX();
1256 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_sched,omx_shed_input_port);
1257 if (error!=OMX_ErrorNone){
1258 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to sched failed %x", error);
1259 clock_mutex.Unlock();
1260 DeAllocateCodecsOMX();
1266 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1268 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec shed failed");
1269 clock_mutex.Unlock();
1270 DeAllocateCodecsOMX();
1274 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1275 clock_mutex.Unlock();
1276 DeAllocateCodecsOMX();
1282 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_deint,omx_deint_input_port);
1283 if (error!=OMX_ErrorNone){
1284 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to deint failed %x", error);
1285 clock_mutex.Unlock();
1286 DeAllocateCodecsOMX();
1292 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_deint,omx_deint_input_port,false)
1294 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec deint failed");
1295 clock_mutex.Unlock();
1296 DeAllocateCodecsOMX();
1300 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_input_port)) {
1301 clock_mutex.Unlock();
1302 DeAllocateCodecsOMX();
1306 if (!ChangeComponentState(omx_vid_deint,OMX_StateIdle)) {
1307 Log::getInstance()->log("Video", Log::DEBUG, "vid_deint ChangeComponentState");
1308 clock_mutex.Unlock();
1309 DeAllocateCodecsOMX();
1313 OMX_CONFIG_IMAGEFILTERPARAMSTYPE imagefilter;
1314 memset(&imagefilter,0,sizeof(imagefilter));
1315 imagefilter.nSize=sizeof(imagefilter);
1316 imagefilter.nVersion.nVersion=OMX_VERSION;
1318 imagefilter.nPortIndex=omx_deint_output_port;
1319 imagefilter.nNumParams=1;
1320 imagefilter.nParams[0]=3;//???
1321 switch (deinterlace) {
1323 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceLineDouble; break;
1325 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceAdvanced; break;
1327 imagefilter.eImageFilter=OMX_ImageFilterFilm; break;
1331 error=OMX_SetConfig(omx_vid_deint,OMX_IndexConfigCommonImageFilterParameters,&imagefilter);
1332 if (error!=OMX_ErrorNone){
1333 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigCommonImageFilterParameters failed %x", error);
1334 clock_mutex.Unlock();
1335 DeAllocateCodecsOMX();
1340 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,omx_vid_sched,omx_shed_input_port);
1341 if (error!=OMX_ErrorNone){
1342 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel deint to sched failed %x", error);
1343 clock_mutex.Unlock();
1344 DeAllocateCodecsOMX();
1348 if (!EnablePort(omx_vid_deint,omx_deint_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1350 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX deint shed failed");
1351 clock_mutex.Unlock();
1352 DeAllocateCodecsOMX();
1356 if ( !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1357 clock_mutex.Unlock();
1358 DeAllocateCodecsOMX();
1364 if (!ChangeComponentState(omx_vid_dec,OMX_StateExecuting)) {
1365 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_dec ChangeComponentState Execute");
1366 clock_mutex.Unlock();
1367 DeAllocateCodecsOMX();
1371 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,omx_vid_rend,omx_rend_input_port);
1372 if (error!=OMX_ErrorNone){
1373 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel sched to rend failed %x", error);
1374 clock_mutex.Unlock();
1375 DeAllocateCodecsOMX();
1379 if (!EnablePort(omx_vid_sched,omx_shed_output_port,false) || !EnablePort(omx_vid_rend,omx_rend_input_port,false)
1381 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX shed rend failed");
1382 clock_mutex.Unlock();
1383 DeAllocateCodecsOMX();
1387 if (!CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_output_port)
1388 || !CommandFinished(omx_vid_rend,OMX_CommandPortEnable,omx_rend_input_port)) {
1389 clock_mutex.Unlock();
1390 DeAllocateCodecsOMX();
1394 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1395 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1396 clock_mutex.Unlock();
1397 DeAllocateCodecsOMX();
1402 if (!ChangeComponentState(omx_vid_deint,OMX_StateExecuting)) {
1403 Log::getInstance()->log("Video", Log::DEBUG, "vid_vid_deint ChangeComponentState");
1404 clock_mutex.Unlock();
1405 DeAllocateCodecsOMX();
1408 DisablePort(omx_vid_deint,omx_deint_output_port,false);
1409 DisablePort(omx_vid_deint,omx_deint_input_port,false);
1412 if (!ChangeComponentState(omx_vid_sched,OMX_StateExecuting)) {
1413 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_sched ChangeComponentState Execute");
1414 clock_mutex.Unlock();
1415 DeAllocateCodecsOMX();
1419 if (!ChangeComponentState(omx_vid_rend,OMX_StateExecuting)) {
1420 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_rend ChangeComponentState Execute");
1421 clock_mutex.Unlock();
1422 DeAllocateCodecsOMX();
1427 /*OMX_CONFIG_DISPLAYREGIONTYPE dispconf;
1428 memset(&dispconf,0,sizeof(dispconf));
1429 dispconf.nSize=sizeof(dispconf);
1430 dispconf.nVersion.nVersion=OMX_VERSION;
1432 dispconf.nPortIndex=omx_rend_input_port;
1434 dispconf.set=OMX_DISPLAY_SET_LAYER ;
1436 error=OMX_SetConfig(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1437 if (error!=OMX_ErrorNone){
1438 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1439 clock_mutex.Unlock();
1440 DeAllocateCodecsOMX();
1444 /* dispconf.set=OMX_DISPLAY_SET_FULLSCREEN ;
1445 dispconf.fullscreen=OMX_FALSE;
1446 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1447 if (error!=OMX_ErrorNone){
1448 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1449 clock_mutex.Unlock();
1450 DeAllocateCodecsOMX();
1454 dispconf.set=OMX_DISPLAY_SET_DEST_RECT;
1455 dispconf.dest_rect.x_offset=100;
1456 dispconf.dest_rect.y_offset=100;
1457 dispconf.dest_rect.width=640;
1458 dispconf.dest_rect.height=480;
1459 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1460 if (error!=OMX_ErrorNone){
1461 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1462 clock_mutex.Unlock();
1463 DeAllocateCodecsOMX();
1468 //playbacktimeoffset=-GetCurrentSystemTime();
1472 clock_mutex.Unlock();
1476 setClockExecutingandRunning();
1485 int VideoOMX::idleClock()
1487 OMX_ERRORTYPE error;
1488 OMX_STATETYPE temp_state;
1490 OMX_GetState(omx_clock,&temp_state);
1492 if (temp_state!=OMX_StateIdle) {
1493 if (!ChangeComponentState(omx_clock,OMX_StateIdle)) {
1494 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Idle failed");
1495 clock_mutex.Unlock();
1499 clock_mutex.Unlock();
1503 int VideoOMX::setClockExecutingandRunning()
1505 OMX_ERRORTYPE error;
1506 OMX_STATETYPE temp_state;
1508 OMX_GetState(omx_clock,&temp_state);
1510 if (temp_state!=OMX_StateExecuting) {
1511 if (!ChangeComponentState(omx_clock,OMX_StateExecuting)) {
1512 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Execute failed");
1513 clock_mutex.Unlock();
1514 DeAllocateCodecsOMX();
1519 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
1520 memset(&clock_conf,0,sizeof(clock_conf));
1521 clock_conf.nSize=sizeof(clock_conf);
1522 clock_conf.nVersion.nVersion=OMX_VERSION;
1523 clock_conf.eState=OMX_TIME_ClockStateRunning;
1524 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
1525 if (error!=OMX_ErrorNone) {
1526 Log::getInstance()->log("Video", Log::DEBUG, "Clock IndexConfigTimeClockState failed %x", error);
1527 clock_mutex.Unlock();
1528 DeAllocateCodecsOMX();
1531 clock_mutex.Unlock();
1537 int VideoOMX::ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type) //needs to be called with locked mutex
1539 OMX_ERRORTYPE error;
1540 error=OMX_SendCommand(handle,OMX_CommandStateSet,type,0);
1541 if (error!=OMX_ErrorNone){
1542 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to OMX State %x %x",handle,type, error);
1546 if (!CommandFinished(handle,OMX_CommandStateSet,type)) {
1554 int VideoOMX::EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1556 OMX_ERRORTYPE error;
1557 error=OMX_SendCommand(handle,OMX_CommandPortEnable,port,0);
1558 if (error!=OMX_ErrorNone){
1559 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to enable port %x %x",handle,port, error);
1563 if (!wait) return 1;
1564 if (!CommandFinished(handle,OMX_CommandPortEnable,port)) {
1572 int VideoOMX::DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1574 OMX_ERRORTYPE error;
1575 error=OMX_SendCommand(handle,OMX_CommandPortDisable,port,0);
1576 if (error!=OMX_ErrorNone){
1577 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to disable port %x %x",handle,port, error);
1581 if (!wait) return 1;
1582 if (!CommandFinished(handle,OMX_CommandPortDisable,port)) {
1590 int VideoOMX::WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event) //needs to be called with locked mutex
1594 omx_event_mutex.Lock();
1595 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1596 while (itty!=omx_events.end()) {
1598 VPE_OMX_EVENT current=*itty;
1599 if (current.handle==handle) { //this is ours
1600 if (current.event_type==OMX_EventError) {
1601 omx_events.erase(itty);
1602 omx_event_mutex.Unlock();
1603 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished on Error");
1606 } else if (current.event_type==event) {
1607 omx_events.erase(itty);
1608 omx_event_mutex.Unlock();
1609 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished Completed");
1616 omx_event_mutex.Unlock();
1621 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent waited too long %x %x",handle,event);
1626 int VideoOMX::clearEvents()
1628 omx_event_mutex.Lock();
1630 omx_event_mutex.Unlock();
1636 int VideoOMX::CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2) //needs to be called with locked mutex
1640 omx_event_mutex.Lock();
1641 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1642 while (itty!=omx_events.end()) {
1644 VPE_OMX_EVENT current=*itty;
1645 if (current.handle==handle) { //this is ours
1646 if (current.event_type==OMX_EventError) {
1647 omx_events.erase(itty);
1648 omx_event_mutex.Unlock();
1649 Log::getInstance()->log("Video", Log::DEBUG, "Command Finished on Error %x",current.data1);
1652 } else if (current.event_type==OMX_EventCmdComplete && current.data1==command && current.data2==data2) {
1653 omx_events.erase(itty);
1654 omx_event_mutex.Unlock();
1655 //Log::getInstance()->log("Video", Log::DEBUG, "Command Finished Completed");
1662 omx_event_mutex.Unlock();
1667 Log::getInstance()->log("Video", Log::DEBUG, "CommandFinished waited too long %x %x %x",handle,command, data2);
1676 int VideoOMX::PrepareInputBufsOMX() //needs to be called with locked mutex
1678 OMX_ERRORTYPE error;
1679 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
1680 memset(&port_def_type,0,sizeof(port_def_type));
1681 port_def_type.nSize=sizeof(port_def_type);
1682 port_def_type.nVersion.nVersion=OMX_VERSION;
1683 port_def_type.nPortIndex=omx_codec_input_port;
1685 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1687 if (error!=OMX_ErrorNone){
1688 Log::getInstance()->log("Video", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
1690 /* Log::getInstance()->log("Video", Log::DEBUG, "Port para %d %d %d %d %d %d %d", port_def_type.nBufferCountActual,
1691 port_def_type.nBufferCountMin,port_def_type.nBufferSize,port_def_type.bEnabled,port_def_type.bPopulated,
1692 port_def_type.bBuffersContiguous,port_def_type.nBufferAlignment);*/
1694 port_def_type.nBufferCountActual=100;
1695 port_def_type.nBufferSize=max(port_def_type.nBufferSize,200000); // for transcoder important
1697 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1699 if (error!=OMX_ErrorNone){
1700 Log::getInstance()->log("Video", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
1704 error=OMX_SendCommand(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port,0);
1705 if (error!=OMX_ErrorNone){
1706 Log::getInstance()->log("Video", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
1710 input_bufs_omx_mutex.Lock();
1711 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
1713 // unsigned char* new_buffer_data=(unsigned char*)malloc(port_def_type.nbufferSize);
1714 OMX_BUFFERHEADERTYPE *buf_head=NULL;
1715 /* error=OMX_Usebuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nbufferSize,new_buffer_data);
1716 if (error!=OMX_ErrorNone){
1717 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_Usebuffer failed %x", error);
1718 input_bufs_omx_mutex.Unlock();
1721 error=OMX_AllocateBuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nBufferSize);
1722 if (error!=OMX_ErrorNone){
1723 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_AllocateBuffer failed %x", error);
1724 input_bufs_omx_mutex.Unlock();
1727 input_bufs_omx_all.push_back(buf_head);
1728 input_bufs_omx_free.push_back(buf_head);
1730 omx_first_frame=true;
1733 cur_input_buf_omx=NULL;
1734 input_bufs_omx_mutex.Unlock();
1737 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark3");
1738 if (!CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port)) {
1741 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark4");
1746 int VideoOMX::DestroyInputBufsOMX() //need s to be called with locked mutex
1748 OMX_ERRORTYPE error;
1750 cur_input_buf_omx=NULL;
1751 input_bufs_omx_mutex.Lock();
1752 for (int i=0; i< input_bufs_omx_all.size();i++) {
1753 // free(input_bufs_omx_all[i]->pBuffer);
1754 // input_bufs_omx_all[i]->pBuffer=NULL;
1755 error=OMX_FreeBuffer(omx_vid_dec,omx_codec_input_port,input_bufs_omx_all[i]);
1756 if (error!=OMX_ErrorNone){
1757 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
1758 input_bufs_omx_mutex.Unlock();
1763 input_bufs_omx_all.clear();
1764 input_bufs_omx_free.clear();
1765 input_bufs_omx_mutex.Unlock();
1770 int VideoOMX::FlushRenderingPipe()
1772 OMX_ERRORTYPE error;
1776 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1777 omx_codec_output_port, NULL);
1778 if (error != OMX_ErrorNone) {
1779 Log::getInstance()->log("Video", Log::DEBUG,
1780 "OMX_Flush codec out 1 failed %x", error);
1784 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1785 omx_shed_input_port, NULL);
1786 if (error != OMX_ErrorNone) {
1787 Log::getInstance()->log("Video", Log::DEBUG,
1788 "OMX_Flush shed in 2 failed %x", error);
1792 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1793 omx_codec_output_port)) {
1794 Log::getInstance()->log("Video", Log::DEBUG,
1795 "flush cmd codec 3 failed");
1798 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1799 omx_shed_input_port)) {
1800 Log::getInstance()->log("Video", Log::DEBUG,
1801 "flush cmd shed 4 failed");
1804 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1805 omx_codec_output_port, NULL);
1806 if (error != OMX_ErrorNone) {
1807 Log::getInstance()->log("Video", Log::DEBUG,
1808 "OMX_Flush codec out 5 failed %x", error);
1812 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1813 omx_deint_input_port, NULL);
1814 if (error != OMX_ErrorNone) {
1815 Log::getInstance()->log("Video", Log::DEBUG,
1816 "OMX_Flush deint in 6 failed %x", error);
1820 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1821 omx_codec_output_port)) {
1822 Log::getInstance()->log("Video", Log::DEBUG,
1823 "flush cmd codec 7 failed");
1826 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1827 omx_deint_input_port)) {
1828 Log::getInstance()->log("Video", Log::DEBUG,
1829 "flush cmd deint 8 failed");
1833 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1834 omx_deint_output_port, NULL);
1835 if (error != OMX_ErrorNone) {
1836 Log::getInstance()->log("Video", Log::DEBUG,
1837 "OMX_Flush deint out 9 failed %x", error);
1841 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1842 omx_shed_input_port, NULL);
1843 if (error != OMX_ErrorNone) {
1844 Log::getInstance()->log("Video", Log::DEBUG,
1845 "OMX_Flush shed in 10 failed %x", error);
1849 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1850 omx_deint_output_port)) {
1851 Log::getInstance()->log("Video", Log::DEBUG,
1852 "flush cmd deint 11 failed");
1855 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1856 omx_shed_input_port)) {
1857 Log::getInstance()->log("Video", Log::DEBUG,
1858 "flush cmd shed 12 failed");
1868 error = OMX_SendCommand(omx_vid_rend, OMX_CommandFlush,
1869 omx_rend_input_port, NULL);
1870 if (error != OMX_ErrorNone) {
1871 Log::getInstance()->log("Video", Log::DEBUG,
1872 "OMX_Flush rend in failed %x", error);
1876 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1877 omx_shed_output_port, NULL);
1878 if (error != OMX_ErrorNone) {
1879 Log::getInstance()->log("Video", Log::DEBUG,
1880 "OMX_Flush shed out failed %x", error);
1886 if (!CommandFinished(omx_vid_rend, OMX_CommandFlush,
1887 omx_rend_input_port)) {
1888 Log::getInstance()->log("Video", Log::DEBUG,
1889 "flush cmd shed rend failed");
1892 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1893 omx_shed_output_port)) {
1894 Log::getInstance()->log("Video", Log::DEBUG,
1895 "flush cmd shed rend failed");
1900 int VideoOMX::DeAllocateCodecsOMX()
1902 OMX_ERRORTYPE error;
1904 Log::getInstance()->log("Video", Log::DEBUG, "enter deallocatecodecsomx");
1906 if (cur_input_buf_omx) {
1907 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_EOS;
1908 OMX_ERRORTYPE error=ProtOMXEmptyThisBuffer(omx_vid_dec,cur_input_buf_omx);
1909 if (error!=OMX_ErrorNone) {
1910 Log::getInstance()->log("Video", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error);
1913 cur_input_buf_omx=NULL;//write out old data
1918 // first stop the omx elements
1919 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1920 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1923 clock_mutex.Unlock();
1929 if (!ChangeComponentState(omx_vid_deint, OMX_StateIdle)) {
1930 Log::getInstance()->log("Video", Log::DEBUG,
1931 "vid_deint ChangeComponentState");
1937 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1938 Log::getInstance()->log("Video", Log::DEBUG, "vid_shed ChangeComponentState");
1942 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1943 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1949 // TODO proper deinit sequence
1950 // first flush all buffers
1951 FlushRenderingPipe();
1957 error=OMX_SendCommand(omx_clock,OMX_CommandFlush, omx_clock_output_port, NULL);
1958 if (error!=OMX_ErrorNone){
1959 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush clock out failed %x", error);
1963 error=OMX_SendCommand(omx_vid_sched,OMX_CommandFlush, omx_shed_clock_port, NULL);
1964 if (error!=OMX_ErrorNone){
1965 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush shed clock failed %x", error);
1969 if (!CommandFinished(omx_clock,OMX_CommandFlush,omx_clock_output_port) ||
1970 !CommandFinished(omx_vid_sched,OMX_CommandFlush,omx_shed_clock_port)) {
1971 Log::getInstance()->log("Video", Log::DEBUG, "flush cmd clock shed failed");
1977 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1978 omx_codec_input_port, NULL);
1979 if (error != OMX_ErrorNone) {
1980 Log::getInstance()->log("Video", Log::DEBUG,
1981 "OMX_Flush codec out failed %x", error);
1988 DestroyInputBufsOMX();
1991 if (!DisablePort(omx_vid_sched,omx_shed_output_port,true)) {
1992 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 2 ");
1994 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true)) {
1995 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 1");
2001 if (!DisablePort(omx_vid_dec,omx_codec_output_port,true)) {
2002 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6");
2007 if (!DisablePort(omx_vid_dec,omx_codec_input_port,true)) {
2008 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7");
2012 if (!DisablePort(omx_vid_deint,omx_deint_output_port,true)) {
2013 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6a");
2018 if (!DisablePort(omx_vid_deint,omx_deint_input_port,true)) {
2019 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7a");
2025 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true)) {
2026 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 3");
2029 if (!DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
2030 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 4");
2033 if (!DisablePort(omx_clock,omx_clock_output_port,true)) {
2034 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 5");
2040 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,NULL,NULL);
2041 if (error!=OMX_ErrorNone) {
2042 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2047 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_input_port,NULL,NULL);
2048 if (error!=OMX_ErrorNone) {
2049 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2053 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,NULL,NULL);
2054 if (error!=OMX_ErrorNone) {
2055 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2059 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_input_port,NULL,NULL);
2060 if (error!=OMX_ErrorNone) {
2061 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2066 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,NULL,NULL);
2067 if (error!=OMX_ErrorNone) {
2068 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2072 error=OMX_SetupTunnel(omx_vid_rend,omx_rend_input_port,NULL,NULL);
2073 if (error!=OMX_ErrorNone) {
2074 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2079 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,NULL,NULL);
2080 if (error!=OMX_ErrorNone) {
2081 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2085 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_clock_port,NULL,NULL);
2086 if (error!=OMX_ErrorNone) {
2087 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2094 error=OMX_FreeHandle(omx_vid_dec);
2095 error=OMX_FreeHandle(omx_vid_sched);
2096 error=OMX_FreeHandle(omx_vid_rend);
2097 if (dodeint) error=OMX_FreeHandle(omx_vid_deint);
2099 clock_mutex.Unlock();
2101 if (error!=OMX_ErrorNone) {
2102 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2104 } else clock_mutex.Unlock();
2105 Log::getInstance()->log("Video", Log::DEBUG, "leave deallocate codecs OMX");
2111 void VideoOMX::destroyClock()
2114 if (clock_references>0) {
2116 if (clock_references==0) {
2117 OMX_ERRORTYPE error;
2118 Log::getInstance()->log("Video", Log::DEBUG, "destroy omx clock");
2119 error=OMX_FreeHandle(omx_clock);
2120 if (error!=OMX_ErrorNone) {
2121 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2126 clock_mutex.Unlock();
2130 int VideoOMX::stop()
2132 if (!initted) return 0;
2135 //Check if libav mode
2136 DeAllocateCodecsOMX();
2141 // if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
2145 int VideoOMX::reset()
2147 if (!initted) return 0;
2150 DeAllocateCodecsOMX();
2151 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
2155 int VideoOMX::pause()
2157 if (!initted) return 0;
2158 Log::getInstance()->log("Video", Log::DEBUG, "enter pause");
2160 // ignore it audio handles this
2164 int VideoOMX::unPause() // FIXME get rid - same as play!! Not here!
2166 if (!initted) return 0;
2167 Log::getInstance()->log("Video", Log::DEBUG, "enter unpause");
2170 //ignore it audio handles this
2175 int VideoOMX::fastForward()
2177 if (!initted) return 0;
2179 // if (ioctl(fdVideo, AV_SET_VID_libavWD, 1) != 0) return 0;
2183 int VideoOMX::unFastForward()
2185 if (!initted) return 0;
2187 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
2189 //// if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
2193 int VideoOMX::attachFrameBuffer()
2195 if (!initted) return 0;
2197 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2201 int VideoOMX::blank(void)
2203 // if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
2204 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2208 ULLONG VideoOMX::getCurrentTimestamp() {
2211 long long ncur_clock_time = cur_clock_time;
2215 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2216 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2218 OMX_ERRORTYPE error;
2219 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
2220 memset(&clock_conf, 0, sizeof(clock_conf));
2221 clock_conf.nSize = sizeof(clock_conf);
2222 clock_conf.nVersion.nVersion = OMX_VERSION;
2223 error= OMX_GetConfig(omx_clock, OMX_IndexConfigTimeClockState,
2225 if (error != OMX_ErrorNone) {
2226 Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp IndexConfigTimeClockState failed %x",error);
2229 if (clock_conf.eState == OMX_TIME_ClockStateRunning) {
2231 OMX_TIME_CONFIG_TIMESTAMPTYPE cur_time_stamp;
2232 memset(&cur_time_stamp, 0, sizeof(cur_time_stamp));
2233 cur_time_stamp.nSize = sizeof(cur_time_stamp);
2234 cur_time_stamp.nVersion.nVersion = OMX_VERSION;
2235 cur_time_stamp.nPortIndex = omx_clock_output_port;
2236 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2238 if (error != OMX_ErrorNone) {
2239 Log::getInstance()->log("Video",Log::DEBUG,"getCurrentTimestamp OMX_IndexConfigTimeCurrentMediaTime failed %x",error);
2241 long long temp = cur_time_stamp.nTimestamp.nLowPart
2242 | ((long long) cur_time_stamp.nTimestamp.nHighPart << 32);
2243 ncur_clock_time = cur_clock_time = temp * 10LL;
2246 clock_mutex.Unlock();
2247 pthread_setcancelstate(oldcancelstate, NULL);
2248 pthread_setcanceltype(oldcanceltype, NULL);
2251 //ncur_clock_time -= startoffset;
2252 ncur_clock_time -= lastreftimeOMX;
2253 long long result = lastreftimePTS;
2254 if (lastreftimePTS==0) return 0; // invalid time
2255 result += (long long) (ncur_clock_time / 10000LL * 90LL);
2257 result = (1LL << 33) - result;
2258 //Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp %lld %lld %lld %lld %lld %lld",ncur_clock_time,cur_clock_time,lastreftimeOMX,lastreftimePTS,result,startoffset);
2266 ULONG VideoOMX::timecodeToFrameNumber(ULLONG timecode)
2268 if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25);
2269 else return (ULONG)(((double)timecode / (double)90000) * (double)30);
2274 int VideoOMX::test()
2279 // return ioctl(fdVideo, AV_SET_VID_STC, &stc);
2286 int VideoOMX::test2()
2294 long long VideoOMX::SetStartOffset(long long curreftime, bool *rsync)
2298 startoffset=curreftime;//offset is set for audio
2300 offsetvideonotset=false;
2302 if (offsetvideonotset) {
2303 offsetvideonotset=false;
2306 if ( (curreftime-lastrefvideotime)>10000000LL
2307 || (curreftime-lastrefvideotime)<-10000000LL) {//if pts jumps to big resync
2308 startoffset+=curreftime-lastrefvideotime;
2309 lastrefaudiotime+=curreftime-lastrefvideotime;
2311 offsetaudionotset=true;
2318 lastrefvideotime=curreftime;
2324 long long VideoOMX::SetStartAudioOffset(long long curreftime, bool *rsync)
2328 startoffset=curreftime;
2330 offsetaudionotset=false;
2332 if (offsetaudionotset) {
2333 offsetaudionotset=false;
2336 if ( (curreftime-lastrefaudiotime)>10000000LL
2337 || (curreftime-lastrefaudiotime)<-10000000LL) {//if pts jumps to big resync
2338 startoffset+=curreftime-lastrefaudiotime;
2339 lastrefvideotime+=curreftime-lastrefaudiotime;
2341 offsetvideonotset=true;
2347 lastrefaudiotime=curreftime;
2352 void VideoOMX::ResetTimeOffsets() {
2353 offsetnotset=true; //called from demuxer
2354 offsetvideonotset=true;
2355 offsetaudionotset=true;
2364 void VideoOMX::DeinterlaceFix()
2368 Demuxer* demux=Demuxer::getInstance();
2369 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2370 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2372 OMX_ERRORTYPE error;
2373 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
2374 memset(&port_def_type,0,sizeof(port_def_type));
2375 port_def_type.nSize=sizeof(port_def_type);
2376 port_def_type.nVersion.nVersion=OMX_VERSION;
2377 port_def_type.nPortIndex=omx_codec_output_port;
2379 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
2380 if (error != OMX_ErrorNone) {
2381 Log::getInstance()->log("Video", Log::DEBUG,
2382 "OMX_IndexParamPortDefinition fix failed %x", error);
2383 clock_mutex.Unlock();
2387 if (port_def_type.format.video.nFrameWidth == demux->getHorizontalSize()
2388 && port_def_type.format.video.nFrameHeight == demux->getVerticalSize()){
2389 Log::getInstance()->log("Video", Log::DEBUG,
2390 "Deinit first frame fix");
2391 deint_first_frame=false;
2393 WaitForEvent(omx_vid_dec,OMX_EventPortSettingsChanged);
2394 DisablePort(omx_vid_dec,omx_codec_output_port,false);
2395 DisablePort(omx_vid_sched,omx_shed_input_port,false);
2396 DisablePort(omx_vid_deint,omx_deint_output_port,false);
2397 DisablePort(omx_vid_deint,omx_deint_input_port,false);
2399 port_def_type.nPortIndex=omx_deint_input_port;
2400 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2402 if (error != OMX_ErrorNone) {
2403 Log::getInstance()->log("Video", Log::DEBUG,
2404 "Set OMX_IndexParamPortDefinition1 failed %x", error);
2405 clock_mutex.Unlock();
2406 pthread_setcancelstate(oldcancelstate, NULL);
2407 pthread_setcanceltype(oldcanceltype, NULL);
2411 port_def_type.nPortIndex=omx_deint_output_port;
2412 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2414 if (error != OMX_ErrorNone) {
2415 Log::getInstance()->log("Video", Log::DEBUG,
2416 "Set OMX_IndexParamPortDefinition2 failed %x", error);
2417 clock_mutex.Unlock();
2418 pthread_setcancelstate(oldcancelstate, NULL);
2419 pthread_setcanceltype(oldcanceltype, NULL);
2424 EnablePort(omx_vid_dec,omx_codec_output_port,false);
2425 EnablePort(omx_vid_deint,omx_deint_input_port,false);
2426 EnablePort(omx_vid_deint,omx_deint_output_port,false);
2427 EnablePort(omx_vid_sched,omx_shed_input_port,false);
2429 clock_mutex.Unlock();
2430 pthread_setcancelstate(oldcancelstate, NULL);
2431 pthread_setcanceltype(oldcanceltype, NULL);
2438 void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer)
2441 OMX_ERRORTYPE error = ProtOMXEmptyThisBuffer(omx_vid_dec, buffer);
2442 if (error != OMX_ErrorNone) {
2443 Log::getInstance()->log("Video", Log::DEBUG,
2444 "OMX_EmptyThisBuffer failed %x", error);
2446 if (deint_first_frame && dodeint) DeinterlaceFix();
2450 OMX_ERRORTYPE VideoOMX::ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer)
2452 // protect the call to empty this buffer
2455 /* long long temp =buffer->nTimeStamp.nLowPart
2456 | ((long long) buffer->nTimeStamp.nHighPart << 32);*/
2458 //pthread_testcancel();
2459 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2460 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2463 /* OMX_ERRORTYPE error;
2464 OMX_TIME_CONFIG_TIMESTAMPTYPE timestamp;
2465 memset(×tamp, 0, sizeof(timestamp));
2466 timestamp.nSize = sizeof(timestamp);
2467 timestamp.nVersion.nVersion = OMX_VERSION;
2468 timestamp.nPortIndex =omx_clock_output_port;
2470 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2473 if (error != OMX_ErrorNone) {
2474 Log::getInstance()->log("Audio", Log::DEBUG,
2475 "Init OMX_IndexConfigAudioRenderingLatencyfailed %x %d", error,
2476 omx_rend_input_port);
2478 long long temp2 =timestamp.nTimestamp.nLowPart
2479 | ((long long) timestamp.nTimestamp.nHighPart << 32);
2482 Log::getInstance()->log("Video", Log::NOTICE, "OMXETB %x %lld %lld %x",handle,temp,temp2,buffer->nFlags);*/
2483 OMX_ERRORTYPE ret_val;
2484 ret_val=OMX_EmptyThisBuffer(handle,buffer);
2485 clock_mutex.Unlock();
2486 pthread_setcancelstate(oldcancelstate, NULL);
2487 pthread_setcanceltype(oldcanceltype, NULL);
2488 //pthread_testcancel();
2492 bool VideoOMX::detectIFrame(const UCHAR *buffer,unsigned int length)
2494 const UCHAR* curbuf=buffer;
2495 const UCHAR* curbufend=buffer+length;
2496 unsigned int detector=0xFFFFFFFF;
2497 bool gotaud=false; // have seen access unit delimiter
2499 while (curbuf!=curbufend) {
2503 if (detector==0x00000109) {
2505 detector=0xFFFFFFFF;
2506 } else if (gotaud &&detector==0x00000001) {
2508 if (curbuf!=curbufend) {
2509 unsigned char picttype=(*curbuf)& 0x1F;
2510 return picttype==0x07;
2514 if (detector==0x00000100) {
2516 if (curbuf==curbufend) return false;
2518 if (curbuf==curbufend) return false;
2519 unsigned char picttype=((*curbuf) >> 3) & 0x07;
2526 return false; // no frame found
2529 void VideoOMX::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
2532 mediapackets.clear();
2533 list<MediaPacket>::const_iterator begin=mplist.begin();
2534 list<MediaPacket>::const_iterator itty=mplist.begin();
2535 advance(itty,min(mplist.size(),10));
2536 mediapackets.insert(mediapackets.begin(),begin,itty);//front
2540 UINT VideoOMX::DeliverMediaSample(UCHAR* buffer, UINT *samplepos)
2543 while (consumed<mediapackets.size()) {
2544 DeliverMediaPacket(mediapackets[consumed], buffer, samplepos);
2545 if (*samplepos == mediapackets[consumed].length) {
2549 } else return consumed;
2554 UINT VideoOMX::DeliverMediaPacket(MediaPacket packet,
2555 const UCHAR* buffer,
2558 if (packet.type == MPTYPE_VIDEO_H264)
2568 //Later add fail back code for libav
2570 *samplepos+=packet.length;
2571 return packet.length;
2575 if (!omx_running) return 0; // if we are not runnig do not do this
2576 if (isClockPaused()) return 0; //Block if we pause
2578 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 1");
2579 //Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX time %lld",packet.presentation_time);
2582 OMX_ERRORTYPE error;
2584 /*First Check, if we have an video sample*/
2588 return 0; //Not in iframe mode!
2592 if (packet.disconti) {
2594 if (cur_input_buf_omx) {
2595 PutBufferToPres(cur_input_buf_omx);
2596 cur_input_buf_omx=NULL;
2599 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2");
2600 /*Inspect PES-Header */
2602 // OMX_STATETYPE temp_state;
2603 // OMX_GetState(omx_vid_dec,&temp_state);
2605 if (*samplepos==0) {//stripheader
2606 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
2607 // if (h264) Log::getInstance()->log("Video", Log::DEBUG, "PES info %x %x %x %x",
2608 // buffer[packet.pos_buffer+0],buffer[packet.pos_buffer+1],buffer[packet.pos_buffer+2],buffer[packet.pos_buffer+3]);
2609 *samplepos+=headerstrip;
2610 if ( packet.synched ) {
2611 if (!firstsynched) {
2612 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2a");
2613 // check if this is an I frame, the decoder does not like non I frames at startup!
2614 if (!detectIFrame(buffer,packet.length)) {
2615 *samplepos=packet.length;//if we have not processed at least one
2616 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 3");
2617 return packet.length;//synched packet ignore it!
2620 if (cur_input_buf_omx) {
2621 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4a");
2622 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_ENDOFFRAME;
2623 PutBufferToPres(cur_input_buf_omx);
2624 cur_input_buf_omx=NULL;//write out old data
2626 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4b");
2631 if (!firstsynched) {//
2632 *samplepos=packet.length;//if we have not processed at least one
2633 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 5");
2634 return packet.length;//synched packet ignore it!
2638 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 6");
2639 if (!cur_input_buf_omx) {
2640 input_bufs_omx_mutex.Lock();
2641 if (input_bufs_omx_free.size()==0) {
2642 input_bufs_omx_mutex.Unlock();
2643 //Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample");
2644 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 7");
2645 return 0; // we do not have a free media sample
2648 cur_input_buf_omx=input_bufs_omx_free.front();
2649 cur_input_buf_omx->nFilledLen=0;
2650 cur_input_buf_omx->nOffset=0;
2651 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2652 input_bufs_omx_free.pop_front();
2653 input_bufs_omx_mutex.Unlock();
2659 if (cur_input_buf_omx->nFilledLen==0) {//will only be changed on first packet
2660 if (packet.synched) {
2661 // Log::getInstance()->log("Video", Log::DEBUG, "packet synched marker");
2663 //lastreftimePTS=packet.pts;
2664 if (omx_first_frame) { // TODO time
2665 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_STARTTIME;
2666 Log::getInstance()->log("Video", Log::DEBUG, "Starttime");
2667 omx_first_frame=false;
2669 cur_input_buf_omx->nFlags=0;
2670 //cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_TIME_UNKNOWN;
2672 lastreftimeOMX=packet.presentation_time;
2673 // Log::getInstance()->log("Video", Log::DEBUG, "Time code %lld pts %lld", lastreftimeOMX,packet.pts);
2674 lastreftimePTS=packet.pts;
2675 cur_input_buf_omx->nTimeStamp=intToOMXTicks(lastreftimeOMX/10LL); // the clock component is faulty;
2679 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2680 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2681 //Log::getInstance()->log("Video", Log::DEBUG, "packet unsynched marker");
2683 if (packet.disconti) cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_DISCONTINUITY;
2688 unsigned int haveToCopy=packet.length-*samplepos;
2689 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 8");
2691 while (haveToCopy> (cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen)) {
2692 //Log::getInstance()->log("Video", Log::DEBUG, "Big buffer %d %d %d",packet.length,cur_input_buf_omx->nAllocLen,cur_input_buf_omx->nFilledLen);
2693 unsigned int cancopy=cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen;
2694 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,buffer+packet.pos_buffer+*samplepos,cancopy);
2695 haveToCopy-=cancopy;
2696 cur_input_buf_omx->nFilledLen+=cancopy;
2697 *samplepos+=cancopy;
2698 // push old buffer out
2699 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 9");
2701 PutBufferToPres(cur_input_buf_omx);
2702 cur_input_buf_omx=NULL;
2704 input_bufs_omx_mutex.Lock();
2705 if (input_bufs_omx_free.size()==0) {
2706 input_bufs_omx_mutex.Unlock();
2707 // Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample2");
2708 return *samplepos; // we do not have a free media sample
2710 cur_input_buf_omx=input_bufs_omx_free.front();
2711 cur_input_buf_omx->nFilledLen=0;
2712 cur_input_buf_omx->nOffset=0;
2713 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2714 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2715 input_bufs_omx_free.pop_front();
2716 input_bufs_omx_mutex.Unlock();
2717 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 10");
2720 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,
2721 buffer+packet.pos_buffer+*samplepos,haveToCopy);
2722 cur_input_buf_omx->nFilledLen+=haveToCopy;
2724 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 11");
2726 *samplepos+=haveToCopy;
2735 bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) {
2736 if (!omx_running) return false;
2738 EnterIframePlayback();
2740 int haveToCopy = length;
2742 if (!cur_input_buf_omx) {
2743 input_bufs_omx_mutex.Lock();
2744 if (input_bufs_omx_free.size() == 0) {
2745 input_bufs_omx_mutex.Unlock();
2746 // Log::getInstance()->log("Video", Log::DEBUG,
2747 // "Deliver MediaPacket no free sample");
2748 return false; // we do not have a free media sample
2751 cur_input_buf_omx = input_bufs_omx_free.front();
2752 cur_input_buf_omx->nFilledLen = 0;
2753 cur_input_buf_omx->nOffset = 0;
2754 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2755 input_bufs_omx_free.pop_front();
2756 input_bufs_omx_mutex.Unlock();
2760 unsigned int pattern, packet_length;
2761 unsigned int headerstrip = 0;
2766 //Now we strip the pes header
2767 pattern = (buffer[0] << 16) | (buffer[1] << 8) | (buffer[2]);
2768 while (read_pos + 7 <= length) {
2769 pattern = ((pattern << 8) & 0xFFFFFFFF) | buffer[read_pos + 3];
2770 if (pattern < 0x000001E0 || pattern > 0x000001EF) {
2774 headerstrip = buffer[read_pos + 8] + 9/*is this right*/;
2775 packet_length = ((buffer[read_pos + 4] << 8)
2776 | (buffer[read_pos + 5])) + 6;
2777 if (read_pos + packet_length > length)
2780 if ((headerstrip < packet_length)
2781 && (cur_input_buf_omx->nFilledLen + packet_length
2782 - headerstrip) > cur_input_buf_omx->nAllocLen) {
2784 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2787 cur_input_buf_omx->nFlags
2788 |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2791 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2792 PutBufferToPres(cur_input_buf_omx);
2793 cur_input_buf_omx = NULL;
2795 if (!cur_input_buf_omx) {
2797 while (count < 100 && omx_running && iframemode) {
2800 input_bufs_omx_mutex.Lock();
2801 if (input_bufs_omx_free.size() == 0) {
2802 input_bufs_omx_mutex.Unlock();
2803 // Log::getInstance()->log("Video", Log::DEBUG,
2804 // "Ifrane no free sample");
2806 if (!omx_running) return false;
2809 cur_input_buf_omx = input_bufs_omx_free.front();
2810 cur_input_buf_omx->nFilledLen = 0;
2811 cur_input_buf_omx->nOffset = 0;
2812 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2813 cur_input_buf_omx->nFlags|= OMX_BUFFERFLAG_TIME_UNKNOWN;
2814 input_bufs_omx_free.pop_front();
2815 input_bufs_omx_mutex.Unlock();
2818 if (!cur_input_buf_omx)
2823 if (packet_length > headerstrip) {
2825 cur_input_buf_omx->pBuffer
2826 + cur_input_buf_omx->nFilledLen,
2827 buffer + read_pos + headerstrip,
2828 packet_length - headerstrip);
2829 cur_input_buf_omx->nFilledLen += packet_length
2832 read_pos += packet_length;
2834 pattern = (buffer[read_pos] << 16)
2835 | (buffer[read_pos + 1] << 8) | (buffer[read_pos + 2]);
2841 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2844 cur_input_buf_omx->nFlags |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2847 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2849 PutBufferToPres(cur_input_buf_omx);
2850 cur_input_buf_omx = NULL;
2853 MILLISLEEP(40); //Block a bit
2857 int VideoOMX::EnterIframePlayback()
2859 Log::getInstance()->log("Video", Log::DEBUG,
2860 "EnterIframePlayback");
2861 if (cur_input_buf_omx) {
2862 PutBufferToPres(cur_input_buf_omx);
2863 cur_input_buf_omx = NULL;
2865 Log::getInstance()->log("Video", Log::DEBUG,
2866 "EnterIframePlayback 2");
2867 ((AudioOMX*)Audio::getInstance())->DeAllocateCodecsOMX();
2868 DeAllocateCodecsOMX();
2869 AllocateCodecsOMX();
2870 Log::getInstance()->log("Video", Log::DEBUG,
2871 "leave IframePlayback");