From f84a117b870b7158a86f547fbd678a9b6d75b521 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Mon, 10 Sep 2012 08:44:44 +0200 Subject: [PATCH] Fix segfault in clockunpause and enhance video frame skipping --- videoomx.cc | 67 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/videoomx.cc b/videoomx.cc index 7bda5c7..63374e6 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -677,19 +677,20 @@ void VideoOMX::clockUnpause() { OMX_ERRORTYPE error; clock_mutex.Lock(); - OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf; - memset(&clock_conf,0,sizeof(clock_conf)); - clock_conf.nSize=sizeof(clock_conf); - clock_conf.nVersion.nVersion=OMX_VERSION; - clock_conf.eState=OMX_TIME_ClockStateRunning; - clock_conf.nStartTime=0; - clock_conf.nOffset=0; - clock_conf.nWaitMask=OMX_CLOCKPORT1; - error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf); - if (error!=OMX_ErrorNone) { - Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause IndexConfigTimeClockState failed %x", error); + if (clock_references>0) { + OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf; + memset(&clock_conf,0,sizeof(clock_conf)); + clock_conf.nSize=sizeof(clock_conf); + clock_conf.nVersion.nVersion=OMX_VERSION; + clock_conf.eState=OMX_TIME_ClockStateRunning; + clock_conf.nStartTime=0; + clock_conf.nOffset=0; + clock_conf.nWaitMask=OMX_CLOCKPORT1; + error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf); + if (error!=OMX_ErrorNone) { + Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause IndexConfigTimeClockState failed %x", error); + } } - clock_mutex.Unlock(); } @@ -698,17 +699,19 @@ void VideoOMX::clockPause() { OMX_ERRORTYPE error; clock_mutex.Lock(); - OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf; - memset(&clock_conf,0,sizeof(clock_conf)); - clock_conf.nSize=sizeof(clock_conf); - clock_conf.nVersion.nVersion=OMX_VERSION; - clock_conf.eState=OMX_TIME_ClockStateStopped; - clock_conf.nStartTime=0; - clock_conf.nOffset=0; - clock_conf.nWaitMask=OMX_CLOCKPORT1; - error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf); - if (error!=OMX_ErrorNone) { - Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause IndexConfigTimeClockState failed %x", error); + if (clock_references>0) { + OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf; + memset(&clock_conf,0,sizeof(clock_conf)); + clock_conf.nSize=sizeof(clock_conf); + clock_conf.nVersion.nVersion=OMX_VERSION; + clock_conf.eState=OMX_TIME_ClockStateStopped; + clock_conf.nStartTime=0; + clock_conf.nOffset=0; + clock_conf.nWaitMask=OMX_CLOCKPORT1; + error=OMX_SetConfig(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf); + if (error!=OMX_ErrorNone) { + Log::getInstance()->log("Video", Log::DEBUG, "ClockUnpause IndexConfigTimeClockState failed %x", error); + } } clock_mutex.Unlock(); } @@ -2297,11 +2300,11 @@ OMX_ERRORTYPE VideoOMX::ProtOMXEmptyThisBuffer(OMX_HANDLETYPE handle, OMX_BUFFER void VideoOMX::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos) { - mediapackets.clear(); - list::const_iterator begin=mplist.begin(); - list::const_iterator itty=mplist.begin(); - advance(itty,min(mplist.size(),50)); - mediapackets.insert(mediapackets.begin(),begin,itty);//front + mediapackets.clear(); + list::const_iterator begin=mplist.begin(); + list::const_iterator itty=mplist.begin(); + advance(itty,min(mplist.size(),10)); + mediapackets.insert(mediapackets.begin(),begin,itty);//front } UINT VideoOMX::DeliverMediaSample(UCHAR* buffer, UINT *samplepos) @@ -2344,7 +2347,13 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, if (!omx_running) return 0; // if we are not runnig do not do this if (paused) return 0; //Block if we pause - long long current_media_time=GetCurrentSystemTime()+playbacktimeoffset; + if (packet.synched && FrameSkip(packet.presentation_time)) { + *samplepos=packet.length; + Log::getInstance()->log("Video", Log::DEBUG, "DeliverMediaPacketOMX Frameskip"); + *samplepos=packet.length; + return packet.length; + } + //long long current_media_time=GetCurrentSystemTime()+playbacktimeoffset; /* if (packet.synched && (packet.presentation_time<0 /*|| // preroll skip frames (packet.presentation_time+5000000LL)<(current_media_time)*)) { // we are late skip -- 2.39.5