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();
686 if (hdmi) { // only switch if hdmi and HD or interlaced SD material
690 int set_interlaced=0;
691 if (demux->getHorizontalSize()>720 && demux->getInterlaced()) {
694 Log::getInstance()->log("Video", Log::NOTICE, "switch interlacing %d %d %d",demux->getInterlaced(),outputinterlaced,set_interlaced);
695 if (outputinterlaced!=set_interlaced) {
696 selectVideoMode(set_interlaced);
697 Osd::getInstance()->shutdown();
698 Osd::getInstance()->restore();
699 Osd::getInstance()->init((void*)"");
700 BoxStack::getInstance()->redrawAllBoxes();
712 int VideoOMX::play() {
716 Log::getInstance()->log("Video", Log::DEBUG, "enter play");
718 interlaceSwitch4Demux();
720 if (AllocateCodecsOMX()) {
722 // Otherwise fall back to libav
726 Log::getInstance()->log("Video", Log::NOTICE,
727 "Allocate Codecs OMX failed assume h264 unsupported");
730 Log::getInstance()->log("Video", Log::NOTICE,
731 "Allocate Codecs OMX failed assume mpeg2 unsupported");
740 int VideoOMX::initClock()
744 if (clock_references==0)
747 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
750 error=OMX_GetHandle(&omx_clock,VPE_OMX_CLOCK,NULL,&callbacks);
752 if (error!=OMX_ErrorNone) {
753 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX clock failed %x", error);
754 clock_mutex.Unlock();
755 DeAllocateCodecsOMX();
759 /* TODO Clock config to separate method */
760 OMX_PORT_PARAM_TYPE p_param;
761 memset(&p_param,0,sizeof(p_param));
762 p_param.nSize=sizeof(p_param);
763 p_param.nVersion.nVersion=OMX_VERSION;
764 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
765 if (error!=OMX_ErrorNone) {
766 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
767 clock_mutex.Unlock();
768 DeAllocateCodecsOMX();
771 omx_clock_output_port=p_param.nStartPortNumber;
773 for (unsigned int i=0;i<p_param.nPorts;i++) {
774 if (!DisablePort(omx_clock,p_param.nStartPortNumber+i,true) ) {
775 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX clock failed %d",i);
776 clock_mutex.Unlock();
777 DeAllocateCodecsOMX();
786 Log::getInstance()->log("Video", Log::DEBUG, "init omx clock %x %x",this,omx_clock);
788 clock_mutex.Unlock();
792 int VideoOMX::getClockAudioandInit(OMX_HANDLETYPE *p_omx_clock,OMX_U32 *p_omx_clock_output_port)
796 *p_omx_clock_output_port=0;
803 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
804 memset(&refclock,0,sizeof(refclock));
805 refclock.nSize=sizeof(refclock);
806 refclock.nVersion.nVersion=OMX_VERSION;
808 refclock.eClock=OMX_TIME_RefClockAudio;
810 //refclock.eClock=OMX_TIME_RefClockVideo;
811 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
812 if (error!=OMX_ErrorNone){
813 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
814 clock_mutex.Unlock();
815 DeAllocateCodecsOMX();
819 OMX_PORT_PARAM_TYPE p_param;
820 memset(&p_param,0,sizeof(p_param));
821 p_param.nSize=sizeof(p_param);
822 p_param.nVersion.nVersion=OMX_VERSION;
823 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
824 if (error!=OMX_ErrorNone){
825 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
826 clock_mutex.Unlock();
827 DeAllocateCodecsOMX();
831 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
832 memset(&clock_conf,0,sizeof(clock_conf));
833 clock_conf.nSize=sizeof(clock_conf);
834 clock_conf.nVersion.nVersion=OMX_VERSION;
835 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
836 clock_conf.nStartTime=intToOMXTicks(0);
837 clock_conf.nOffset=intToOMXTicks(0);
838 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT1;
839 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
840 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
841 if (error!=OMX_ErrorNone) {
842 Log::getInstance()->log("Video", Log::DEBUG, "AuI Clock IndexConfigTimeClockState failed %x", error);
846 *p_omx_clock_output_port=p_param.nStartPortNumber+1;
847 *p_omx_clock=omx_clock;
848 clock_mutex.Unlock();
852 int VideoOMX::getClockVideoandInit()
861 if (clock_references==1) { // only if no audio is attached to this clock!
862 OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refclock;
863 memset(&refclock,0,sizeof(refclock));
864 refclock.nSize=sizeof(refclock);
865 refclock.nVersion.nVersion=OMX_VERSION;
867 //refclock.eClock=OMX_TIME_RefClockAudio;
869 refclock.eClock=OMX_TIME_RefClockVideo;
870 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeActiveRefClock,&refclock);
871 if (error!=OMX_ErrorNone) {
872 Log::getInstance()->log("Video", Log::DEBUG, "Clock OMX_IndexConfigTimeActiveRefClock failed %x", error);
873 clock_mutex.Unlock();
874 DeAllocateCodecsOMX();
879 OMX_PORT_PARAM_TYPE p_param;
880 memset(&p_param,0,sizeof(p_param));
881 p_param.nSize=sizeof(p_param);
882 p_param.nVersion.nVersion=OMX_VERSION;
883 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
884 if (error!=OMX_ErrorNone){
885 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
886 clock_mutex.Unlock();
887 DeAllocateCodecsOMX();
892 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
893 memset(&clock_conf,0,sizeof(clock_conf));
894 clock_conf.nSize=sizeof(clock_conf);
895 clock_conf.nVersion.nVersion=OMX_VERSION;
896 clock_conf.eState=OMX_TIME_ClockStateStopped;
897 clock_conf.nStartTime=intToOMXTicks(0);
898 clock_conf.nOffset=intToOMXTicks(0);
899 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
900 if (error!=OMX_ErrorNone) {
901 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
905 memset(&clock_conf,0,sizeof(clock_conf));
906 clock_conf.nSize=sizeof(clock_conf);
907 clock_conf.nVersion.nVersion=OMX_VERSION;
908 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
909 clock_conf.nStartTime=intToOMXTicks(0);
910 clock_conf.nOffset=intToOMXTicks(0);
911 if (clock_references==1) clock_conf.nWaitMask=OMX_CLOCKPORT0;
912 else clock_conf.nWaitMask=OMX_CLOCKPORT0|OMX_CLOCKPORT1;
913 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
914 if (error!=OMX_ErrorNone) {
915 Log::getInstance()->log("Video", Log::DEBUG, "VuI Clock IndexConfigTimeClockState failed %x", error);
918 omx_clock_output_port=p_param.nStartPortNumber;
919 clock_mutex.Unlock();
924 void VideoOMX::clockUnpause()
927 Log::getInstance()->log("Video", Log::NOTICE, "enter Clockunpause");
929 if (clock_references>0 && clockpaused) {
930 OMX_TIME_CONFIG_SCALETYPE scale_type;
931 memset(&scale_type,0,sizeof(scale_type));
932 scale_type.nSize=sizeof(scale_type);
933 scale_type.nVersion.nVersion=OMX_VERSION;
934 scale_type.xScale=1<<16;
935 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeScale,&scale_type);
936 if (error!=OMX_ErrorNone) {
937 Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause OMX_IndexConfigTimeScale failed %x", error);
939 Log::getInstance()->log("Video", Log::NOTICE, "set playback speed ClockUnpause");
942 clock_mutex.Unlock();
946 void VideoOMX::clockPause()
949 Log::getInstance()->log("Video", Log::NOTICE, "enter ClockPause");
951 if (clock_references>0 && !clockpaused) {
952 OMX_TIME_CONFIG_SCALETYPE scale_type;
953 memset(&scale_type,0,sizeof(scale_type));
954 scale_type.nSize=sizeof(scale_type);
955 scale_type.nVersion.nVersion=OMX_VERSION;
957 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeScale,&scale_type);
958 if (error!=OMX_ErrorNone) {
959 Log::getInstance()->log("Video", Log::DEBUG, "ClockPause OMX_IndexConfigTimeScale failed %x", error);
961 Log::getInstance()->log("Video", Log::NOTICE, "set playback speed ClockPause");
964 clock_mutex.Unlock();
969 int VideoOMX::AllocateCodecsOMX()
972 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
974 Demuxer* demux=Demuxer::getInstance();
977 deint_first_frame=false;
979 Log::getInstance()->log("Video", Log::NOTICE, "Allocate Codecs OMX");
980 //Clock, move later to audio including events
982 Log::getInstance()->log("Video", Log::NOTICE, "VideoType %d x %d i: %d", demux->getHorizontalSize(),demux->getVerticalSize(),demux->getInterlaced());
983 if (deinterlace!=0 && /*(demux->getHorizontalSize()<=720 ) &&*/ demux->getInterlaced()) { //only deinterlace SD material
985 deint_first_frame=true;
987 Log::getInstance()->log("Video", Log::NOTICE, "Deinterlacing activated %d",deinterlace);
992 if (!getClockVideoandInit()){
993 return 0;// get the clock and init it if necessary
998 Log::getInstance()->log("Video", Log::DEBUG, "idleClock failed");
1005 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_H264_DECODER,NULL,&callbacks);
1007 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_MPEG2_DECODER,NULL,&callbacks);
1010 if (error!=OMX_ErrorNone){
1011 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video decoder failed %x", error);
1012 clock_mutex.Unlock();
1013 DeAllocateCodecsOMX();
1018 Log::getInstance()->log("Video", Log::DEBUG, "Nmark3 ");
1019 OMX_PORT_PARAM_TYPE p_param;
1020 memset(&p_param,0,sizeof(p_param));
1021 p_param.nSize=sizeof(p_param);
1022 p_param.nVersion.nVersion=OMX_VERSION;
1023 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamVideoInit,&p_param);
1024 if (error!=OMX_ErrorNone){
1025 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX h264 decoder OMX_GetParameter failed %x", error);
1026 clock_mutex.Unlock();
1027 DeAllocateCodecsOMX();
1030 omx_codec_input_port=p_param.nStartPortNumber;
1031 omx_codec_output_port=p_param.nStartPortNumber+1;
1033 if (!DisablePort(omx_vid_dec,omx_codec_input_port) || !DisablePort(omx_vid_dec,omx_codec_output_port)) {
1034 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video decoder failed");
1035 clock_mutex.Unlock();
1036 DeAllocateCodecsOMX();
1040 Log::getInstance()->log("Video", Log::DEBUG, "Nmark4 ");
1042 OMX_PARAM_BRCMVIDEODECODEERRORCONCEALMENTTYPE conceal;
1043 memset(&conceal,0,sizeof(conceal));
1044 conceal.nSize=sizeof(conceal);
1045 conceal.nVersion.nVersion=OMX_VERSION;
1046 conceal.bStartWithValidFrame=OMX_FALSE;
1048 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamBrcmVideoDecodeErrorConcealment,&conceal);
1049 if (error!=OMX_ErrorNone){
1050 Log::getInstance()->log("Video", Log::DEBUG, "OMX_IndexParamBrcmVideoDecodeErrorConcealment failed %x", error);
1051 clock_mutex.Unlock();
1052 DeAllocateCodecsOMX();
1057 error = OMX_GetHandle(&omx_vid_deint, VPE_OMX_VIDEO_DEINTERLACE, NULL,
1059 if (error != OMX_ErrorNone) {
1060 Log::getInstance()->log("Video", Log::DEBUG,
1061 "Init OMX video deinterlacer failed %x", error);
1062 clock_mutex.Unlock();
1063 DeAllocateCodecsOMX();
1067 error = OMX_GetParameter(omx_vid_deint, OMX_IndexParamImageInit,
1069 if (error != OMX_ErrorNone) {
1070 Log::getInstance()->log("Video", Log::DEBUG,
1071 "Init OMX video deinterlacer OMX_GetParameter failed %x",
1073 clock_mutex.Unlock();
1074 DeAllocateCodecsOMX();
1077 omx_deint_input_port = p_param.nStartPortNumber;
1078 omx_deint_output_port = p_param.nStartPortNumber + 1;
1080 if (!DisablePort(omx_vid_deint, omx_deint_input_port, true)
1081 || !DisablePort(omx_vid_deint, omx_deint_output_port, true)) {
1082 Log::getInstance()->log("Video", Log::DEBUG,
1083 "Disable Ports OMX video deint failed");
1084 clock_mutex.Unlock();
1085 DeAllocateCodecsOMX();
1092 error=OMX_GetHandle(&omx_vid_sched,VPE_OMX_VIDEO_SCHED,NULL,&callbacks);
1093 if (error!=OMX_ErrorNone){
1094 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler failed %x", error);
1095 clock_mutex.Unlock();
1096 DeAllocateCodecsOMX();
1102 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamVideoInit,&p_param);
1103 if (error!=OMX_ErrorNone){
1104 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1105 clock_mutex.Unlock();
1106 DeAllocateCodecsOMX();
1109 omx_shed_input_port=p_param.nStartPortNumber;
1110 omx_shed_output_port=p_param.nStartPortNumber+1;
1113 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamOtherInit,&p_param);
1114 if (error!=OMX_ErrorNone){
1115 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
1116 clock_mutex.Unlock();
1117 DeAllocateCodecsOMX();
1120 omx_shed_clock_port=p_param.nStartPortNumber;
1121 Log::getInstance()->log("Video", Log::DEBUG, "scheduler ports %d %d %d ",omx_shed_input_port,omx_shed_output_port,omx_shed_clock_port);
1124 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true) || !DisablePort(omx_vid_sched,omx_shed_output_port,true)
1125 || !DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
1126 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video shed failed");
1127 clock_mutex.Unlock();
1128 DeAllocateCodecsOMX();
1133 error=OMX_GetHandle(&omx_vid_rend,VPE_OMX_VIDEO_REND,NULL,&callbacks);
1134 if (error!=OMX_ErrorNone){
1135 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend failed %x", error);
1136 clock_mutex.Unlock();
1137 DeAllocateCodecsOMX();
1141 error=OMX_GetParameter(omx_vid_rend,OMX_IndexParamVideoInit,&p_param);
1142 if (error!=OMX_ErrorNone){
1143 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend OMX_GetParameter failed %x", error);
1144 clock_mutex.Unlock();
1145 DeAllocateCodecsOMX();
1148 omx_rend_input_port=p_param.nStartPortNumber;
1149 //omx_rend_output_port=p_param.nStartPortNumber+1;
1152 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true) /*|| !DisablePort(omx_vid_rend,omx_rend_output_port)*/
1154 Log::getInstance()->log("Video", Log::DEBUG, "Disable Ports OMX video rend failed");
1155 clock_mutex.Unlock();
1156 DeAllocateCodecsOMX();
1164 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,omx_vid_sched,omx_shed_clock_port);
1165 if (error!=OMX_ErrorNone){
1166 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);
1167 clock_mutex.Unlock();
1168 DeAllocateCodecsOMX();
1172 if (!EnablePort(omx_clock,omx_clock_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_clock_port,false)
1174 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX clock shed failed");
1175 clock_mutex.Unlock();
1176 DeAllocateCodecsOMX();
1181 Log::getInstance()->log("Video", Log::DEBUG, "mark2 ");
1182 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1183 Log::getInstance()->log("Video", Log::DEBUG, "vid_sched idle ChangeComponentState");
1184 clock_mutex.Unlock();
1185 DeAllocateCodecsOMX();
1191 Log::getInstance()->log("Video", Log::DEBUG, "mark1 ");
1192 if ( !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_clock_port)) {
1193 clock_mutex.Unlock();
1194 DeAllocateCodecsOMX();
1201 Log::getInstance()->log("Video", Log::DEBUG, "mark1 special ");
1202 if ( !CommandFinished(omx_clock,OMX_CommandPortEnable,omx_clock_output_port)) {
1203 clock_mutex.Unlock();
1204 DeAllocateCodecsOMX();
1210 Log::getInstance()->log("Video", Log::DEBUG, "mark1b ");
1213 /* error=OMX_SendCommand(omx_vid_dec,OMX_CommandStateSet,OMX_StateIdle,0);
1214 if (error!=OMX_ErrorNone){
1215 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec Send Command to OMX State Idle %x", error);
1219 OMX_VIDEO_PARAM_PORTFORMATTYPE ft_type;
1220 memset(&ft_type,0,sizeof(ft_type));
1221 ft_type.nSize=sizeof(ft_type);
1222 ft_type.nVersion.nVersion=OMX_VERSION;
1224 ft_type.nPortIndex=omx_codec_input_port;
1226 ft_type.eCompressionFormat=OMX_VIDEO_CodingAVC;
1228 ft_type.eCompressionFormat=OMX_VIDEO_CodingMPEG2;
1233 ft_type.xFramerate=0*(1<<16);//25*(1<<16);//demux->getFrameRate()*(1<<16);
1234 Log::getInstance()->log("Video", Log::DEBUG, "Framerate: %d",demux->getFrameRate());
1235 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamVideoPortFormat,&ft_type);
1236 if (error!=OMX_ErrorNone){
1237 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexParamVideoPortFormat failed %x", error);
1238 clock_mutex.Unlock();
1239 DeAllocateCodecsOMX();
1244 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1245 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1246 clock_mutex.Unlock();
1247 DeAllocateCodecsOMX();
1252 if (!PrepareInputBufsOMX()) {
1253 clock_mutex.Unlock();
1254 DeAllocateCodecsOMX();
1259 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_sched,omx_shed_input_port);
1260 if (error!=OMX_ErrorNone){
1261 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to sched failed %x", error);
1262 clock_mutex.Unlock();
1263 DeAllocateCodecsOMX();
1269 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1271 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec shed failed");
1272 clock_mutex.Unlock();
1273 DeAllocateCodecsOMX();
1277 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1278 clock_mutex.Unlock();
1279 DeAllocateCodecsOMX();
1285 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_deint,omx_deint_input_port);
1286 if (error!=OMX_ErrorNone){
1287 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to deint failed %x", error);
1288 clock_mutex.Unlock();
1289 DeAllocateCodecsOMX();
1295 if (!EnablePort(omx_vid_dec,omx_codec_output_port,false) || !EnablePort(omx_vid_deint,omx_deint_input_port,false)
1297 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX codec deint failed");
1298 clock_mutex.Unlock();
1299 DeAllocateCodecsOMX();
1303 if ( !CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_output_port) || !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_input_port)) {
1304 clock_mutex.Unlock();
1305 DeAllocateCodecsOMX();
1309 if (!ChangeComponentState(omx_vid_deint,OMX_StateIdle)) {
1310 Log::getInstance()->log("Video", Log::DEBUG, "vid_deint ChangeComponentState");
1311 clock_mutex.Unlock();
1312 DeAllocateCodecsOMX();
1316 OMX_CONFIG_IMAGEFILTERPARAMSTYPE imagefilter;
1317 memset(&imagefilter,0,sizeof(imagefilter));
1318 imagefilter.nSize=sizeof(imagefilter);
1319 imagefilter.nVersion.nVersion=OMX_VERSION;
1321 imagefilter.nPortIndex=omx_deint_output_port;
1322 imagefilter.nNumParams=1;
1323 imagefilter.nParams[0]=3;//???
1324 switch (deinterlace) {
1326 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceLineDouble; break;
1328 imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceAdvanced; break;
1330 imagefilter.eImageFilter=OMX_ImageFilterFilm; break;
1334 error=OMX_SetConfig(omx_vid_deint,OMX_IndexConfigCommonImageFilterParameters,&imagefilter);
1335 if (error!=OMX_ErrorNone){
1336 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigCommonImageFilterParameters failed %x", error);
1337 clock_mutex.Unlock();
1338 DeAllocateCodecsOMX();
1343 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,omx_vid_sched,omx_shed_input_port);
1344 if (error!=OMX_ErrorNone){
1345 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel deint to sched failed %x", error);
1346 clock_mutex.Unlock();
1347 DeAllocateCodecsOMX();
1351 if (!EnablePort(omx_vid_deint,omx_deint_output_port,false) || !EnablePort(omx_vid_sched,omx_shed_input_port,false)
1353 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX deint shed failed");
1354 clock_mutex.Unlock();
1355 DeAllocateCodecsOMX();
1359 if ( !CommandFinished(omx_vid_deint,OMX_CommandPortEnable,omx_deint_output_port) || !CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_input_port)) {
1360 clock_mutex.Unlock();
1361 DeAllocateCodecsOMX();
1367 if (!ChangeComponentState(omx_vid_dec,OMX_StateExecuting)) {
1368 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_dec ChangeComponentState Execute");
1369 clock_mutex.Unlock();
1370 DeAllocateCodecsOMX();
1374 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,omx_vid_rend,omx_rend_input_port);
1375 if (error!=OMX_ErrorNone){
1376 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel sched to rend failed %x", error);
1377 clock_mutex.Unlock();
1378 DeAllocateCodecsOMX();
1382 if (!EnablePort(omx_vid_sched,omx_shed_output_port,false) || !EnablePort(omx_vid_rend,omx_rend_input_port,false)
1384 Log::getInstance()->log("Video", Log::DEBUG, "Enable Ports OMX shed rend failed");
1385 clock_mutex.Unlock();
1386 DeAllocateCodecsOMX();
1390 if (!CommandFinished(omx_vid_sched,OMX_CommandPortEnable,omx_shed_output_port)
1391 || !CommandFinished(omx_vid_rend,OMX_CommandPortEnable,omx_rend_input_port)) {
1392 clock_mutex.Unlock();
1393 DeAllocateCodecsOMX();
1397 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1398 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1399 clock_mutex.Unlock();
1400 DeAllocateCodecsOMX();
1405 if (!ChangeComponentState(omx_vid_deint,OMX_StateExecuting)) {
1406 Log::getInstance()->log("Video", Log::DEBUG, "vid_vid_deint ChangeComponentState");
1407 clock_mutex.Unlock();
1408 DeAllocateCodecsOMX();
1411 DisablePort(omx_vid_deint,omx_deint_output_port,false);
1412 DisablePort(omx_vid_deint,omx_deint_input_port,false);
1415 if (!ChangeComponentState(omx_vid_sched,OMX_StateExecuting)) {
1416 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_sched ChangeComponentState Execute");
1417 clock_mutex.Unlock();
1418 DeAllocateCodecsOMX();
1422 if (!ChangeComponentState(omx_vid_rend,OMX_StateExecuting)) {
1423 Log::getInstance()->log("Video", Log::DEBUG, "omx_vid_rend ChangeComponentState Execute");
1424 clock_mutex.Unlock();
1425 DeAllocateCodecsOMX();
1430 /*OMX_CONFIG_DISPLAYREGIONTYPE dispconf;
1431 memset(&dispconf,0,sizeof(dispconf));
1432 dispconf.nSize=sizeof(dispconf);
1433 dispconf.nVersion.nVersion=OMX_VERSION;
1435 dispconf.nPortIndex=omx_rend_input_port;
1437 dispconf.set=OMX_DISPLAY_SET_LAYER ;
1439 error=OMX_SetConfig(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1440 if (error!=OMX_ErrorNone){
1441 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1442 clock_mutex.Unlock();
1443 DeAllocateCodecsOMX();
1447 /* dispconf.set=OMX_DISPLAY_SET_FULLSCREEN ;
1448 dispconf.fullscreen=OMX_FALSE;
1449 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1450 if (error!=OMX_ErrorNone){
1451 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1452 clock_mutex.Unlock();
1453 DeAllocateCodecsOMX();
1457 dispconf.set=OMX_DISPLAY_SET_DEST_RECT;
1458 dispconf.dest_rect.x_offset=100;
1459 dispconf.dest_rect.y_offset=100;
1460 dispconf.dest_rect.width=640;
1461 dispconf.dest_rect.height=480;
1462 error=OMX_SetParameter(omx_vid_rend,OMX_IndexConfigDisplayRegion,&dispconf);
1463 if (error!=OMX_ErrorNone){
1464 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexConfigDisplayRegion failed %x", error);
1465 clock_mutex.Unlock();
1466 DeAllocateCodecsOMX();
1471 //playbacktimeoffset=-GetCurrentSystemTime();
1475 clock_mutex.Unlock();
1479 setClockExecutingandRunning();
1488 int VideoOMX::idleClock()
1490 OMX_ERRORTYPE error;
1491 OMX_STATETYPE temp_state;
1493 OMX_GetState(omx_clock,&temp_state);
1495 if (temp_state!=OMX_StateIdle) {
1496 if (!ChangeComponentState(omx_clock,OMX_StateIdle)) {
1497 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Idle failed");
1498 clock_mutex.Unlock();
1502 clock_mutex.Unlock();
1506 int VideoOMX::setClockExecutingandRunning()
1508 OMX_ERRORTYPE error;
1509 OMX_STATETYPE temp_state;
1511 OMX_GetState(omx_clock,&temp_state);
1513 if (temp_state!=OMX_StateExecuting) {
1514 if (!ChangeComponentState(omx_clock,OMX_StateExecuting)) {
1515 Log::getInstance()->log("Video", Log::DEBUG, "omx_clock ChangeComponentState Execute failed");
1516 clock_mutex.Unlock();
1517 DeAllocateCodecsOMX();
1522 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
1523 memset(&clock_conf,0,sizeof(clock_conf));
1524 clock_conf.nSize=sizeof(clock_conf);
1525 clock_conf.nVersion.nVersion=OMX_VERSION;
1526 clock_conf.eState=OMX_TIME_ClockStateRunning;
1527 error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
1528 if (error!=OMX_ErrorNone) {
1529 Log::getInstance()->log("Video", Log::DEBUG, "Clock IndexConfigTimeClockState failed %x", error);
1530 clock_mutex.Unlock();
1531 DeAllocateCodecsOMX();
1534 clock_mutex.Unlock();
1540 int VideoOMX::ChangeComponentState(OMX_HANDLETYPE handle,OMX_STATETYPE type) //needs to be called with locked mutex
1542 OMX_ERRORTYPE error;
1543 error=OMX_SendCommand(handle,OMX_CommandStateSet,type,0);
1544 if (error!=OMX_ErrorNone){
1545 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to OMX State %x %x",handle,type, error);
1549 if (!CommandFinished(handle,OMX_CommandStateSet,type)) {
1557 int VideoOMX::EnablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1559 OMX_ERRORTYPE error;
1560 error=OMX_SendCommand(handle,OMX_CommandPortEnable,port,0);
1561 if (error!=OMX_ErrorNone){
1562 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to enable port %x %x",handle,port, error);
1566 if (!wait) return 1;
1567 if (!CommandFinished(handle,OMX_CommandPortEnable,port)) {
1575 int VideoOMX::DisablePort(OMX_HANDLETYPE handle,OMX_U32 port,bool wait) //needs to be called with locked mutex
1577 OMX_ERRORTYPE error;
1578 error=OMX_SendCommand(handle,OMX_CommandPortDisable,port,0);
1579 if (error!=OMX_ErrorNone){
1580 Log::getInstance()->log("Video", Log::DEBUG, "handle %x Send Command to disable port %x %x",handle,port, error);
1584 if (!wait) return 1;
1585 if (!CommandFinished(handle,OMX_CommandPortDisable,port)) {
1593 int VideoOMX::WaitForEvent(OMX_HANDLETYPE handle,OMX_U32 event) //needs to be called with locked mutex
1597 omx_event_mutex.Lock();
1598 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1599 while (itty!=omx_events.end()) {
1601 VPE_OMX_EVENT current=*itty;
1602 if (current.handle==handle) { //this is ours
1603 if (current.event_type==OMX_EventError) {
1604 omx_events.erase(itty);
1605 omx_event_mutex.Unlock();
1606 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished on Error");
1609 } else if (current.event_type==event) {
1610 omx_events.erase(itty);
1611 omx_event_mutex.Unlock();
1612 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent Finished Completed");
1619 omx_event_mutex.Unlock();
1624 Log::getInstance()->log("Video", Log::DEBUG, "WaitForEvent waited too long %x %x",handle,event);
1629 int VideoOMX::clearEvents()
1631 omx_event_mutex.Lock();
1633 omx_event_mutex.Unlock();
1639 int VideoOMX::CommandFinished(OMX_HANDLETYPE handle,OMX_U32 command,OMX_U32 data2) //needs to be called with locked mutex
1643 omx_event_mutex.Lock();
1644 list<VPE_OMX_EVENT>::iterator itty=omx_events.begin();
1645 while (itty!=omx_events.end()) {
1647 VPE_OMX_EVENT current=*itty;
1648 if (current.handle==handle) { //this is ours
1649 if (current.event_type==OMX_EventError) {
1650 omx_events.erase(itty);
1651 omx_event_mutex.Unlock();
1652 Log::getInstance()->log("Video", Log::DEBUG, "Command Finished on Error %x",current.data1);
1655 } else if (current.event_type==OMX_EventCmdComplete && current.data1==command && current.data2==data2) {
1656 omx_events.erase(itty);
1657 omx_event_mutex.Unlock();
1658 //Log::getInstance()->log("Video", Log::DEBUG, "Command Finished Completed");
1665 omx_event_mutex.Unlock();
1670 Log::getInstance()->log("Video", Log::DEBUG, "CommandFinished waited too long %x %x %x",handle,command, data2);
1679 int VideoOMX::PrepareInputBufsOMX() //needs to be called with locked mutex
1681 OMX_ERRORTYPE error;
1682 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
1683 memset(&port_def_type,0,sizeof(port_def_type));
1684 port_def_type.nSize=sizeof(port_def_type);
1685 port_def_type.nVersion.nVersion=OMX_VERSION;
1686 port_def_type.nPortIndex=omx_codec_input_port;
1688 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1690 if (error!=OMX_ErrorNone){
1691 Log::getInstance()->log("Video", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
1693 /* Log::getInstance()->log("Video", Log::DEBUG, "Port para %d %d %d %d %d %d %d", port_def_type.nBufferCountActual,
1694 port_def_type.nBufferCountMin,port_def_type.nBufferSize,port_def_type.bEnabled,port_def_type.bPopulated,
1695 port_def_type.bBuffersContiguous,port_def_type.nBufferAlignment);*/
1697 port_def_type.nBufferCountActual=100;
1698 port_def_type.nBufferSize=max(port_def_type.nBufferSize,200000); // for transcoder important
1700 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
1702 if (error!=OMX_ErrorNone){
1703 Log::getInstance()->log("Video", Log::DEBUG, "Set OMX OMX_IndexParamPortDefinition failed %x", error);
1707 error=OMX_SendCommand(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port,0);
1708 if (error!=OMX_ErrorNone){
1709 Log::getInstance()->log("Video", Log::DEBUG, "Prepare Input bufs Send Command to enable port %x", error);
1713 input_bufs_omx_mutex.Lock();
1714 for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
1716 // unsigned char* new_buffer_data=(unsigned char*)malloc(port_def_type.nbufferSize);
1717 OMX_BUFFERHEADERTYPE *buf_head=NULL;
1718 /* error=OMX_Usebuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nbufferSize,new_buffer_data);
1719 if (error!=OMX_ErrorNone){
1720 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_Usebuffer failed %x", error);
1721 input_bufs_omx_mutex.Unlock();
1724 error=OMX_AllocateBuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nBufferSize);
1725 if (error!=OMX_ErrorNone){
1726 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_AllocateBuffer failed %x", error);
1727 input_bufs_omx_mutex.Unlock();
1730 input_bufs_omx_all.push_back(buf_head);
1731 input_bufs_omx_free.push_back(buf_head);
1733 omx_first_frame=true;
1736 cur_input_buf_omx=NULL;
1737 input_bufs_omx_mutex.Unlock();
1740 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark3");
1741 if (!CommandFinished(omx_vid_dec,OMX_CommandPortEnable,omx_codec_input_port)) {
1744 Log::getInstance()->log("Video", Log::DEBUG, "PrepareInputBufsOMX mark4");
1749 int VideoOMX::DestroyInputBufsOMX() //need s to be called with locked mutex
1751 OMX_ERRORTYPE error;
1753 cur_input_buf_omx=NULL;
1754 input_bufs_omx_mutex.Lock();
1755 for (int i=0; i< input_bufs_omx_all.size();i++) {
1756 // free(input_bufs_omx_all[i]->pBuffer);
1757 // input_bufs_omx_all[i]->pBuffer=NULL;
1758 error=OMX_FreeBuffer(omx_vid_dec,omx_codec_input_port,input_bufs_omx_all[i]);
1759 if (error!=OMX_ErrorNone){
1760 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
1761 input_bufs_omx_mutex.Unlock();
1766 input_bufs_omx_all.clear();
1767 input_bufs_omx_free.clear();
1768 input_bufs_omx_mutex.Unlock();
1773 int VideoOMX::FlushRenderingPipe()
1775 OMX_ERRORTYPE error;
1779 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1780 omx_codec_output_port, NULL);
1781 if (error != OMX_ErrorNone) {
1782 Log::getInstance()->log("Video", Log::DEBUG,
1783 "OMX_Flush codec out 1 failed %x", error);
1787 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1788 omx_shed_input_port, NULL);
1789 if (error != OMX_ErrorNone) {
1790 Log::getInstance()->log("Video", Log::DEBUG,
1791 "OMX_Flush shed in 2 failed %x", error);
1795 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1796 omx_codec_output_port)) {
1797 Log::getInstance()->log("Video", Log::DEBUG,
1798 "flush cmd codec 3 failed");
1801 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1802 omx_shed_input_port)) {
1803 Log::getInstance()->log("Video", Log::DEBUG,
1804 "flush cmd shed 4 failed");
1807 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1808 omx_codec_output_port, NULL);
1809 if (error != OMX_ErrorNone) {
1810 Log::getInstance()->log("Video", Log::DEBUG,
1811 "OMX_Flush codec out 5 failed %x", error);
1815 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1816 omx_deint_input_port, NULL);
1817 if (error != OMX_ErrorNone) {
1818 Log::getInstance()->log("Video", Log::DEBUG,
1819 "OMX_Flush deint in 6 failed %x", error);
1823 if (!CommandFinished(omx_vid_dec, OMX_CommandFlush,
1824 omx_codec_output_port)) {
1825 Log::getInstance()->log("Video", Log::DEBUG,
1826 "flush cmd codec 7 failed");
1829 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1830 omx_deint_input_port)) {
1831 Log::getInstance()->log("Video", Log::DEBUG,
1832 "flush cmd deint 8 failed");
1836 error = OMX_SendCommand(omx_vid_deint, OMX_CommandFlush,
1837 omx_deint_output_port, NULL);
1838 if (error != OMX_ErrorNone) {
1839 Log::getInstance()->log("Video", Log::DEBUG,
1840 "OMX_Flush deint out 9 failed %x", error);
1844 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1845 omx_shed_input_port, NULL);
1846 if (error != OMX_ErrorNone) {
1847 Log::getInstance()->log("Video", Log::DEBUG,
1848 "OMX_Flush shed in 10 failed %x", error);
1852 if (!CommandFinished(omx_vid_deint, OMX_CommandFlush,
1853 omx_deint_output_port)) {
1854 Log::getInstance()->log("Video", Log::DEBUG,
1855 "flush cmd deint 11 failed");
1858 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1859 omx_shed_input_port)) {
1860 Log::getInstance()->log("Video", Log::DEBUG,
1861 "flush cmd shed 12 failed");
1871 error = OMX_SendCommand(omx_vid_rend, OMX_CommandFlush,
1872 omx_rend_input_port, NULL);
1873 if (error != OMX_ErrorNone) {
1874 Log::getInstance()->log("Video", Log::DEBUG,
1875 "OMX_Flush rend in failed %x", error);
1879 error = OMX_SendCommand(omx_vid_sched, OMX_CommandFlush,
1880 omx_shed_output_port, NULL);
1881 if (error != OMX_ErrorNone) {
1882 Log::getInstance()->log("Video", Log::DEBUG,
1883 "OMX_Flush shed out failed %x", error);
1889 if (!CommandFinished(omx_vid_rend, OMX_CommandFlush,
1890 omx_rend_input_port)) {
1891 Log::getInstance()->log("Video", Log::DEBUG,
1892 "flush cmd shed rend failed");
1895 if (!CommandFinished(omx_vid_sched, OMX_CommandFlush,
1896 omx_shed_output_port)) {
1897 Log::getInstance()->log("Video", Log::DEBUG,
1898 "flush cmd shed rend failed");
1903 int VideoOMX::DeAllocateCodecsOMX()
1905 OMX_ERRORTYPE error;
1907 Log::getInstance()->log("Video", Log::DEBUG, "enter deallocatecodecsomx");
1909 if (cur_input_buf_omx) {
1910 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_EOS;
1911 OMX_ERRORTYPE error=ProtOMXEmptyThisBuffer(omx_vid_dec,cur_input_buf_omx);
1912 if (error!=OMX_ErrorNone) {
1913 Log::getInstance()->log("Video", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error);
1916 cur_input_buf_omx=NULL;//write out old data
1921 // first stop the omx elements
1922 if (!ChangeComponentState(omx_vid_dec,OMX_StateIdle)) {
1923 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec ChangeComponentState");
1926 clock_mutex.Unlock();
1932 if (!ChangeComponentState(omx_vid_deint, OMX_StateIdle)) {
1933 Log::getInstance()->log("Video", Log::DEBUG,
1934 "vid_deint ChangeComponentState");
1940 if (!ChangeComponentState(omx_vid_sched,OMX_StateIdle)) {
1941 Log::getInstance()->log("Video", Log::DEBUG, "vid_shed ChangeComponentState");
1945 if (!ChangeComponentState(omx_vid_rend,OMX_StateIdle)) {
1946 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend ChangeComponentState");
1952 // TODO proper deinit sequence
1953 // first flush all buffers
1954 FlushRenderingPipe();
1960 error=OMX_SendCommand(omx_clock,OMX_CommandFlush, omx_clock_output_port, NULL);
1961 if (error!=OMX_ErrorNone){
1962 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush clock out failed %x", error);
1966 error=OMX_SendCommand(omx_vid_sched,OMX_CommandFlush, omx_shed_clock_port, NULL);
1967 if (error!=OMX_ErrorNone){
1968 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Flush shed clock failed %x", error);
1972 if (!CommandFinished(omx_clock,OMX_CommandFlush,omx_clock_output_port) ||
1973 !CommandFinished(omx_vid_sched,OMX_CommandFlush,omx_shed_clock_port)) {
1974 Log::getInstance()->log("Video", Log::DEBUG, "flush cmd clock shed failed");
1980 error = OMX_SendCommand(omx_vid_dec, OMX_CommandFlush,
1981 omx_codec_input_port, NULL);
1982 if (error != OMX_ErrorNone) {
1983 Log::getInstance()->log("Video", Log::DEBUG,
1984 "OMX_Flush codec out failed %x", error);
1991 DestroyInputBufsOMX();
1994 if (!DisablePort(omx_vid_sched,omx_shed_output_port,true)) {
1995 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 2 ");
1997 if (!DisablePort(omx_vid_rend,omx_rend_input_port,true)) {
1998 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 1");
2004 if (!DisablePort(omx_vid_dec,omx_codec_output_port,true)) {
2005 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6");
2010 if (!DisablePort(omx_vid_dec,omx_codec_input_port,true)) {
2011 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7");
2015 if (!DisablePort(omx_vid_deint,omx_deint_output_port,true)) {
2016 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 6a");
2021 if (!DisablePort(omx_vid_deint,omx_deint_input_port,true)) {
2022 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 7a");
2028 if (!DisablePort(omx_vid_sched,omx_shed_input_port,true)) {
2029 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 3");
2032 if (!DisablePort(omx_vid_sched,omx_shed_clock_port,true)) {
2033 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 4");
2036 if (!DisablePort(omx_clock,omx_clock_output_port,true)) {
2037 Log::getInstance()->log("Video", Log::DEBUG, "Disable Tunnel Port failed 5");
2043 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,NULL,NULL);
2044 if (error!=OMX_ErrorNone) {
2045 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2050 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_input_port,NULL,NULL);
2051 if (error!=OMX_ErrorNone) {
2052 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2056 error=OMX_SetupTunnel(omx_vid_deint,omx_deint_output_port,NULL,NULL);
2057 if (error!=OMX_ErrorNone) {
2058 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2062 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_input_port,NULL,NULL);
2063 if (error!=OMX_ErrorNone) {
2064 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2069 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,NULL,NULL);
2070 if (error!=OMX_ErrorNone) {
2071 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2075 error=OMX_SetupTunnel(omx_vid_rend,omx_rend_input_port,NULL,NULL);
2076 if (error!=OMX_ErrorNone) {
2077 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2082 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,NULL,NULL);
2083 if (error!=OMX_ErrorNone) {
2084 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2088 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_clock_port,NULL,NULL);
2089 if (error!=OMX_ErrorNone) {
2090 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
2097 error=OMX_FreeHandle(omx_vid_dec);
2098 error=OMX_FreeHandle(omx_vid_sched);
2099 error=OMX_FreeHandle(omx_vid_rend);
2100 if (dodeint) error=OMX_FreeHandle(omx_vid_deint);
2102 clock_mutex.Unlock();
2104 if (error!=OMX_ErrorNone) {
2105 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2107 } else clock_mutex.Unlock();
2108 Log::getInstance()->log("Video", Log::DEBUG, "leave deallocate codecs OMX");
2114 void VideoOMX::destroyClock()
2117 if (clock_references>0) {
2119 if (clock_references==0) {
2120 OMX_ERRORTYPE error;
2121 Log::getInstance()->log("Video", Log::DEBUG, "destroy omx clock");
2122 error=OMX_FreeHandle(omx_clock);
2123 if (error!=OMX_ErrorNone) {
2124 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
2129 clock_mutex.Unlock();
2133 int VideoOMX::stop()
2135 if (!initted) return 0;
2138 //Check if libav mode
2139 DeAllocateCodecsOMX();
2144 // if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
2148 int VideoOMX::reset()
2150 if (!initted) return 0;
2153 DeAllocateCodecsOMX();
2154 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
2158 int VideoOMX::pause()
2160 if (!initted) return 0;
2161 Log::getInstance()->log("Video", Log::DEBUG, "enter pause");
2163 // ignore it audio handles this
2167 int VideoOMX::unPause() // FIXME get rid - same as play!! Not here!
2169 if (!initted) return 0;
2170 Log::getInstance()->log("Video", Log::DEBUG, "enter unpause");
2173 //ignore it audio handles this
2178 int VideoOMX::fastForward()
2180 if (!initted) return 0;
2182 // if (ioctl(fdVideo, AV_SET_VID_libavWD, 1) != 0) return 0;
2186 int VideoOMX::unFastForward()
2188 if (!initted) return 0;
2190 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
2192 //// if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
2196 int VideoOMX::attachFrameBuffer()
2198 if (!initted) return 0;
2200 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2204 int VideoOMX::blank(void)
2206 // if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
2207 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
2211 ULLONG VideoOMX::getCurrentTimestamp() {
2214 long long ncur_clock_time = cur_clock_time;
2218 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2219 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2221 OMX_ERRORTYPE error;
2222 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
2223 memset(&clock_conf, 0, sizeof(clock_conf));
2224 clock_conf.nSize = sizeof(clock_conf);
2225 clock_conf.nVersion.nVersion = OMX_VERSION;
2226 error= OMX_GetConfig(omx_clock, OMX_IndexConfigTimeClockState,
2228 if (error != OMX_ErrorNone) {
2229 Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp IndexConfigTimeClockState failed %x",error);
2232 if (clock_conf.eState == OMX_TIME_ClockStateRunning) {
2234 OMX_TIME_CONFIG_TIMESTAMPTYPE cur_time_stamp;
2235 memset(&cur_time_stamp, 0, sizeof(cur_time_stamp));
2236 cur_time_stamp.nSize = sizeof(cur_time_stamp);
2237 cur_time_stamp.nVersion.nVersion = OMX_VERSION;
2238 cur_time_stamp.nPortIndex = omx_clock_output_port;
2239 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2241 if (error != OMX_ErrorNone) {
2242 Log::getInstance()->log("Video",Log::DEBUG,"getCurrentTimestamp OMX_IndexConfigTimeCurrentMediaTime failed %x",error);
2244 long long temp = cur_time_stamp.nTimestamp.nLowPart
2245 | ((long long) cur_time_stamp.nTimestamp.nHighPart << 32);
2246 ncur_clock_time = cur_clock_time = temp * 10LL;
2249 clock_mutex.Unlock();
2250 pthread_setcancelstate(oldcancelstate, NULL);
2251 pthread_setcanceltype(oldcanceltype, NULL);
2254 //ncur_clock_time -= startoffset;
2255 ncur_clock_time -= lastreftimeOMX;
2256 long long result = lastreftimePTS;
2257 if (lastreftimePTS==0) return 0; // invalid time
2258 result += (long long) (ncur_clock_time / 10000LL * 90LL);
2260 result = (1LL << 33) - result;
2261 //Log::getInstance()->log("Video", Log::DEBUG,"getCurrentTimestamp %lld %lld %lld %lld %lld %lld",ncur_clock_time,cur_clock_time,lastreftimeOMX,lastreftimePTS,result,startoffset);
2269 ULONG VideoOMX::timecodeToFrameNumber(ULLONG timecode)
2271 if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25);
2272 else return (ULONG)(((double)timecode / (double)90000) * (double)30);
2277 int VideoOMX::test()
2282 // return ioctl(fdVideo, AV_SET_VID_STC, &stc);
2289 int VideoOMX::test2()
2297 long long VideoOMX::SetStartOffset(long long curreftime, bool *rsync)
2301 startoffset=curreftime;//offset is set for audio
2303 offsetvideonotset=false;
2305 if (offsetvideonotset) {
2306 offsetvideonotset=false;
2309 if ( (curreftime-lastrefvideotime)>10000000LL
2310 || (curreftime-lastrefvideotime)<-10000000LL) {//if pts jumps to big resync
2311 startoffset+=curreftime-lastrefvideotime;
2312 lastrefaudiotime+=curreftime-lastrefvideotime;
2314 offsetaudionotset=true;
2321 lastrefvideotime=curreftime;
2327 long long VideoOMX::SetStartAudioOffset(long long curreftime, bool *rsync)
2331 startoffset=curreftime;
2333 offsetaudionotset=false;
2335 if (offsetaudionotset) {
2336 offsetaudionotset=false;
2339 if ( (curreftime-lastrefaudiotime)>10000000LL
2340 || (curreftime-lastrefaudiotime)<-10000000LL) {//if pts jumps to big resync
2341 startoffset+=curreftime-lastrefaudiotime;
2342 lastrefvideotime+=curreftime-lastrefaudiotime;
2344 offsetvideonotset=true;
2350 lastrefaudiotime=curreftime;
2355 void VideoOMX::ResetTimeOffsets() {
2356 offsetnotset=true; //called from demuxer
2357 offsetvideonotset=true;
2358 offsetaudionotset=true;
2367 void VideoOMX::DeinterlaceFix()
2371 Demuxer* demux=Demuxer::getInstance();
2372 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2373 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2375 OMX_ERRORTYPE error;
2376 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
2377 memset(&port_def_type,0,sizeof(port_def_type));
2378 port_def_type.nSize=sizeof(port_def_type);
2379 port_def_type.nVersion.nVersion=OMX_VERSION;
2380 port_def_type.nPortIndex=omx_codec_output_port;
2382 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
2383 if (error != OMX_ErrorNone) {
2384 Log::getInstance()->log("Video", Log::DEBUG,
2385 "OMX_IndexParamPortDefinition fix failed %x", error);
2386 clock_mutex.Unlock();
2390 if (port_def_type.format.video.nFrameWidth == demux->getHorizontalSize()
2391 && port_def_type.format.video.nFrameHeight == demux->getVerticalSize()){
2392 Log::getInstance()->log("Video", Log::DEBUG,
2393 "Deinit first frame fix");
2394 deint_first_frame=false;
2396 WaitForEvent(omx_vid_dec,OMX_EventPortSettingsChanged);
2397 DisablePort(omx_vid_dec,omx_codec_output_port,false);
2398 DisablePort(omx_vid_sched,omx_shed_input_port,false);
2399 DisablePort(omx_vid_deint,omx_deint_output_port,false);
2400 DisablePort(omx_vid_deint,omx_deint_input_port,false);
2402 port_def_type.nPortIndex=omx_deint_input_port;
2403 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2405 if (error != OMX_ErrorNone) {
2406 Log::getInstance()->log("Video", Log::DEBUG,
2407 "Set OMX_IndexParamPortDefinition1 failed %x", error);
2408 clock_mutex.Unlock();
2409 pthread_setcancelstate(oldcancelstate, NULL);
2410 pthread_setcanceltype(oldcanceltype, NULL);
2414 port_def_type.nPortIndex=omx_deint_output_port;
2415 error = OMX_SetParameter(omx_vid_deint, OMX_IndexParamPortDefinition,
2417 if (error != OMX_ErrorNone) {
2418 Log::getInstance()->log("Video", Log::DEBUG,
2419 "Set OMX_IndexParamPortDefinition2 failed %x", error);
2420 clock_mutex.Unlock();
2421 pthread_setcancelstate(oldcancelstate, NULL);
2422 pthread_setcanceltype(oldcanceltype, NULL);
2427 EnablePort(omx_vid_dec,omx_codec_output_port,false);
2428 EnablePort(omx_vid_deint,omx_deint_input_port,false);
2429 EnablePort(omx_vid_deint,omx_deint_output_port,false);
2430 EnablePort(omx_vid_sched,omx_shed_input_port,false);
2432 clock_mutex.Unlock();
2433 pthread_setcancelstate(oldcancelstate, NULL);
2434 pthread_setcanceltype(oldcanceltype, NULL);
2441 void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer)
2444 OMX_ERRORTYPE error = ProtOMXEmptyThisBuffer(omx_vid_dec, buffer);
2445 if (error != OMX_ErrorNone) {
2446 Log::getInstance()->log("Video", Log::DEBUG,
2447 "OMX_EmptyThisBuffer failed %x", error);
2449 if (deint_first_frame && dodeint) DeinterlaceFix();
2453 OMX_ERRORTYPE VideoOMX::ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFERHEADERTYPE* buffer)
2455 // protect the call to empty this buffer
2458 /* long long temp =buffer->nTimeStamp.nLowPart
2459 | ((long long) buffer->nTimeStamp.nHighPart << 32);*/
2461 //pthread_testcancel();
2462 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
2463 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
2466 /* OMX_ERRORTYPE error;
2467 OMX_TIME_CONFIG_TIMESTAMPTYPE timestamp;
2468 memset(×tamp, 0, sizeof(timestamp));
2469 timestamp.nSize = sizeof(timestamp);
2470 timestamp.nVersion.nVersion = OMX_VERSION;
2471 timestamp.nPortIndex =omx_clock_output_port;
2473 error = OMX_GetConfig(omx_clock, OMX_IndexConfigTimeCurrentMediaTime,
2476 if (error != OMX_ErrorNone) {
2477 Log::getInstance()->log("Audio", Log::DEBUG,
2478 "Init OMX_IndexConfigAudioRenderingLatencyfailed %x %d", error,
2479 omx_rend_input_port);
2481 long long temp2 =timestamp.nTimestamp.nLowPart
2482 | ((long long) timestamp.nTimestamp.nHighPart << 32);
2485 Log::getInstance()->log("Video", Log::NOTICE, "OMXETB %x %lld %lld %x",handle,temp,temp2,buffer->nFlags);*/
2486 OMX_ERRORTYPE ret_val;
2487 ret_val=OMX_EmptyThisBuffer(handle,buffer);
2488 clock_mutex.Unlock();
2489 pthread_setcancelstate(oldcancelstate, NULL);
2490 pthread_setcanceltype(oldcanceltype, NULL);
2491 //pthread_testcancel();
2495 bool VideoOMX::detectIFrame(const UCHAR *buffer,unsigned int length)
2497 const UCHAR* curbuf=buffer;
2498 const UCHAR* curbufend=buffer+length;
2499 unsigned int detector=0xFFFFFFFF;
2500 bool gotaud=false; // have seen access unit delimiter
2502 while (curbuf!=curbufend) {
2506 if (detector==0x00000109) {
2508 detector=0xFFFFFFFF;
2509 } else if (gotaud &&detector==0x00000001) {
2511 if (curbuf!=curbufend) {
2512 unsigned char picttype=(*curbuf)& 0x1F;
2513 return picttype==0x07;
2517 if (detector==0x00000100) {
2519 if (curbuf==curbufend) return false;
2521 if (curbuf==curbufend) return false;
2522 unsigned char picttype=((*curbuf) >> 3) & 0x07;
2529 return false; // no frame found
2532 void VideoOMX::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
2535 mediapackets.clear();
2536 list<MediaPacket>::const_iterator begin=mplist.begin();
2537 list<MediaPacket>::const_iterator itty=mplist.begin();
2538 advance(itty,min(mplist.size(),10));
2539 mediapackets.insert(mediapackets.begin(),begin,itty);//front
2543 UINT VideoOMX::DeliverMediaSample(UCHAR* buffer, UINT *samplepos)
2546 while (consumed<mediapackets.size()) {
2547 DeliverMediaPacket(mediapackets[consumed], buffer, samplepos);
2548 if (*samplepos == mediapackets[consumed].length) {
2552 } else return consumed;
2557 UINT VideoOMX::DeliverMediaPacket(MediaPacket packet,
2558 const UCHAR* buffer,
2561 if (packet.type == MPTYPE_VIDEO_H264)
2571 //Later add fail back code for libav
2573 *samplepos+=packet.length;
2574 return packet.length;
2578 if (!omx_running) return 0; // if we are not runnig do not do this
2579 if (isClockPaused()) return 0; //Block if we pause
2581 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 1");
2582 //Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX time %lld",packet.presentation_time);
2585 OMX_ERRORTYPE error;
2587 /*First Check, if we have an video sample*/
2591 return 0; //Not in iframe mode!
2595 if (packet.disconti) {
2597 if (cur_input_buf_omx) {
2598 PutBufferToPres(cur_input_buf_omx);
2599 cur_input_buf_omx=NULL;
2602 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2");
2603 /*Inspect PES-Header */
2605 // OMX_STATETYPE temp_state;
2606 // OMX_GetState(omx_vid_dec,&temp_state);
2608 if (*samplepos==0) {//stripheader
2609 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
2610 // if (h264) Log::getInstance()->log("Video", Log::DEBUG, "PES info %x %x %x %x",
2611 // buffer[packet.pos_buffer+0],buffer[packet.pos_buffer+1],buffer[packet.pos_buffer+2],buffer[packet.pos_buffer+3]);
2612 *samplepos+=headerstrip;
2613 if ( packet.synched ) {
2614 if (!firstsynched) {
2615 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 2a");
2616 // check if this is an I frame, the decoder does not like non I frames at startup!
2617 if (!detectIFrame(buffer,packet.length)) {
2618 *samplepos=packet.length;//if we have not processed at least one
2619 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 3");
2620 return packet.length;//synched packet ignore it!
2623 if (cur_input_buf_omx) {
2624 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4a");
2625 cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_ENDOFFRAME;
2626 PutBufferToPres(cur_input_buf_omx);
2627 cur_input_buf_omx=NULL;//write out old data
2629 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 4b");
2634 if (!firstsynched) {//
2635 *samplepos=packet.length;//if we have not processed at least one
2636 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 5");
2637 return packet.length;//synched packet ignore it!
2641 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 6");
2642 if (!cur_input_buf_omx) {
2643 input_bufs_omx_mutex.Lock();
2644 if (input_bufs_omx_free.size()==0) {
2645 input_bufs_omx_mutex.Unlock();
2646 //Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample");
2647 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 7");
2648 return 0; // we do not have a free media sample
2651 cur_input_buf_omx=input_bufs_omx_free.front();
2652 cur_input_buf_omx->nFilledLen=0;
2653 cur_input_buf_omx->nOffset=0;
2654 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2655 input_bufs_omx_free.pop_front();
2656 input_bufs_omx_mutex.Unlock();
2662 if (cur_input_buf_omx->nFilledLen==0) {//will only be changed on first packet
2663 if (packet.synched) {
2664 // Log::getInstance()->log("Video", Log::DEBUG, "packet synched marker");
2666 //lastreftimePTS=packet.pts;
2667 if (omx_first_frame) { // TODO time
2668 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_STARTTIME;
2669 Log::getInstance()->log("Video", Log::DEBUG, "Starttime");
2670 omx_first_frame=false;
2672 cur_input_buf_omx->nFlags=0;
2673 //cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_TIME_UNKNOWN;
2675 lastreftimeOMX=packet.presentation_time;
2676 // Log::getInstance()->log("Video", Log::DEBUG, "Time code %lld pts %lld", lastreftimeOMX,packet.pts);
2677 lastreftimePTS=packet.pts;
2678 cur_input_buf_omx->nTimeStamp=intToOMXTicks(lastreftimeOMX/10LL); // the clock component is faulty;
2682 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2683 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2684 //Log::getInstance()->log("Video", Log::DEBUG, "packet unsynched marker");
2686 if (packet.disconti) cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_DISCONTINUITY;
2691 unsigned int haveToCopy=packet.length-*samplepos;
2692 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 8");
2694 while (haveToCopy> (cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen)) {
2695 //Log::getInstance()->log("Video", Log::DEBUG, "Big buffer %d %d %d",packet.length,cur_input_buf_omx->nAllocLen,cur_input_buf_omx->nFilledLen);
2696 unsigned int cancopy=cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen;
2697 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,buffer+packet.pos_buffer+*samplepos,cancopy);
2698 haveToCopy-=cancopy;
2699 cur_input_buf_omx->nFilledLen+=cancopy;
2700 *samplepos+=cancopy;
2701 // push old buffer out
2702 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 9");
2704 PutBufferToPres(cur_input_buf_omx);
2705 cur_input_buf_omx=NULL;
2707 input_bufs_omx_mutex.Lock();
2708 if (input_bufs_omx_free.size()==0) {
2709 input_bufs_omx_mutex.Unlock();
2710 // Log::getInstance()->log("Video", Log::DEBUG, "Deliver MediaPacket no free sample2");
2711 return *samplepos; // we do not have a free media sample
2713 cur_input_buf_omx=input_bufs_omx_free.front();
2714 cur_input_buf_omx->nFilledLen=0;
2715 cur_input_buf_omx->nOffset=0;
2716 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
2717 cur_input_buf_omx->nTimeStamp=intToOMXTicks(0);
2718 input_bufs_omx_free.pop_front();
2719 input_bufs_omx_mutex.Unlock();
2720 //Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 10");
2723 memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,
2724 buffer+packet.pos_buffer+*samplepos,haveToCopy);
2725 cur_input_buf_omx->nFilledLen+=haveToCopy;
2727 // Log::getInstance()->log("Video", Log::DEBUG, "DMP mark 11");
2729 *samplepos+=haveToCopy;
2738 bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) {
2739 if (!omx_running) return false;
2741 EnterIframePlayback();
2743 int haveToCopy = length;
2745 if (!cur_input_buf_omx) {
2746 input_bufs_omx_mutex.Lock();
2747 if (input_bufs_omx_free.size() == 0) {
2748 input_bufs_omx_mutex.Unlock();
2749 // Log::getInstance()->log("Video", Log::DEBUG,
2750 // "Deliver MediaPacket no free sample");
2751 return false; // we do not have a free media sample
2754 cur_input_buf_omx = input_bufs_omx_free.front();
2755 cur_input_buf_omx->nFilledLen = 0;
2756 cur_input_buf_omx->nOffset = 0;
2757 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2758 input_bufs_omx_free.pop_front();
2759 input_bufs_omx_mutex.Unlock();
2763 unsigned int pattern, packet_length;
2764 unsigned int headerstrip = 0;
2769 //Now we strip the pes header
2770 pattern = (buffer[0] << 16) | (buffer[1] << 8) | (buffer[2]);
2771 while (read_pos + 7 <= length) {
2772 pattern = ((pattern << 8) & 0xFFFFFFFF) | buffer[read_pos + 3];
2773 if (pattern < 0x000001E0 || pattern > 0x000001EF) {
2777 headerstrip = buffer[read_pos + 8] + 9/*is this right*/;
2778 packet_length = ((buffer[read_pos + 4] << 8)
2779 | (buffer[read_pos + 5])) + 6;
2780 if (read_pos + packet_length > length)
2783 if ((headerstrip < packet_length)
2784 && (cur_input_buf_omx->nFilledLen + packet_length
2785 - headerstrip) > cur_input_buf_omx->nAllocLen) {
2787 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2790 cur_input_buf_omx->nFlags
2791 |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2794 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2795 PutBufferToPres(cur_input_buf_omx);
2796 cur_input_buf_omx = NULL;
2798 if (!cur_input_buf_omx) {
2800 while (count < 100 && omx_running && iframemode) {
2803 input_bufs_omx_mutex.Lock();
2804 if (input_bufs_omx_free.size() == 0) {
2805 input_bufs_omx_mutex.Unlock();
2806 // Log::getInstance()->log("Video", Log::DEBUG,
2807 // "Ifrane no free sample");
2809 if (!omx_running) return false;
2812 cur_input_buf_omx = input_bufs_omx_free.front();
2813 cur_input_buf_omx->nFilledLen = 0;
2814 cur_input_buf_omx->nOffset = 0;
2815 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2816 cur_input_buf_omx->nFlags|= OMX_BUFFERFLAG_TIME_UNKNOWN;
2817 input_bufs_omx_free.pop_front();
2818 input_bufs_omx_mutex.Unlock();
2821 if (!cur_input_buf_omx)
2826 if (packet_length > headerstrip) {
2828 cur_input_buf_omx->pBuffer
2829 + cur_input_buf_omx->nFilledLen,
2830 buffer + read_pos + headerstrip,
2831 packet_length - headerstrip);
2832 cur_input_buf_omx->nFilledLen += packet_length
2835 read_pos += packet_length;
2837 pattern = (buffer[read_pos] << 16)
2838 | (buffer[read_pos + 1] << 8) | (buffer[read_pos + 2]);
2844 cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME;
2847 cur_input_buf_omx->nFlags |= OMX_BUFFERFLAG_TIME_UNKNOWN;
2850 cur_input_buf_omx->nTimeStamp = intToOMXTicks(0);
2852 PutBufferToPres(cur_input_buf_omx);
2853 cur_input_buf_omx = NULL;
2856 MILLISLEEP(40); //Block a bit
2860 int VideoOMX::EnterIframePlayback()
2862 Log::getInstance()->log("Video", Log::DEBUG,
2863 "EnterIframePlayback");
2864 if (cur_input_buf_omx) {
2865 PutBufferToPres(cur_input_buf_omx);
2866 cur_input_buf_omx = NULL;
2868 Log::getInstance()->log("Video", Log::DEBUG,
2869 "EnterIframePlayback 2");
2870 ((AudioOMX*)Audio::getInstance())->DeAllocateCodecsOMX();
2871 DeAllocateCodecsOMX();
2872 AllocateCodecsOMX();
2873 Log::getInstance()->log("Video", Log::DEBUG,
2874 "leave IframePlayback");