From b5e0751dbb284d2987f5b44e64258c084f7d22ce Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Tue, 18 Sep 2012 20:10:05 +0200 Subject: [PATCH] Fix skip and fast forward --- videoomx.cc | 36 ++++++++++++++++++++++++------------ videoomx.h | 4 +++- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/videoomx.cc b/videoomx.cc index 18e43cb..13704f6 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -1577,6 +1577,7 @@ int VideoOMX::DestroyInputBufsOMX() //need s to be called with locked mutex input_bufs_omx_free.clear(); input_bufs_omx_present.clear(); input_time_present.clear(); + input_time_pts.clear(); input_is_last.clear(); input_bufs_omx_mutex.Unlock(); @@ -2026,7 +2027,7 @@ int VideoOMX::blank(void) ULLONG VideoOMX::getCurrentTimestamp() { if (iframemode) return 0; - return lastreftimePTS; + return cur_pts; } // to be removed @@ -2126,6 +2127,7 @@ void VideoOMX::ResetTimeOffsets() { lastrefvideotime=0; lastreftimeOMX=0; lastreftimePTS=0; + cur_pts=0; } long long VideoOMX::GetCurrentSystemTime() @@ -2237,12 +2239,13 @@ void VideoOMX::threadMethod() if (!paused) { input_bufs_omx_mutex.Lock(); if (input_bufs_omx_present.size()>0) { - + cur_pts=input_time_pts.front(); pict=input_bufs_omx_present.front(); time=input_time_present.front(); islast=input_is_last.front(); input_bufs_omx_present.pop_front(); input_time_present.pop_front(); + input_time_pts.pop_front(); input_is_last.pop_front(); } input_bufs_omx_mutex.Unlock(); @@ -2345,11 +2348,12 @@ void VideoOMX::DeinterlaceFix() } -void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer, long long time,bool islast) +void VideoOMX::PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer, long long time, long long pts,bool islast) { input_bufs_omx_mutex.Lock(); input_bufs_omx_present.push_back(buffer); input_time_present.push_back(time); + input_time_pts.push_back(pts); input_is_last.push_back(islast); input_bufs_omx_mutex.Unlock(); @@ -2450,7 +2454,7 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, if (packet.disconti) { firstsynched=false; if (cur_input_buf_omx) { - PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,true); + PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,lastreftimePTS, true); cur_input_buf_omx=NULL; } } @@ -2468,7 +2472,7 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, if ( packet.synched ) { if (cur_input_buf_omx) { cur_input_buf_omx->nFlags|=OMX_BUFFERFLAG_ENDOFFRAME; - PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,true); + PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,lastreftimePTS,true); cur_input_buf_omx=NULL;//write out old data @@ -2542,7 +2546,7 @@ UINT VideoOMX::DeliverMediaPacket(MediaPacket packet, *samplepos+=cancopy; // push old buffer out - PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,false); + PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,lastreftimePTS,false); cur_input_buf_omx=NULL; // get5 new buffer input_bufs_omx_mutex.Lock(); @@ -2633,7 +2637,7 @@ bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) { } cur_input_buf_omx->nTimeStamp = 0; - PutBufferToPres(cur_input_buf_omx, 0,false); + PutBufferToPres(cur_input_buf_omx, 0,0,false); cur_input_buf_omx = NULL; if (!cur_input_buf_omx) { @@ -2688,7 +2692,8 @@ bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) { } cur_input_buf_omx->nTimeStamp = 0; - PutBufferToPres(cur_input_buf_omx, 0,false); + + PutBufferToPres(cur_input_buf_omx, 0,0,false); cur_input_buf_omx = NULL; @@ -2698,13 +2703,20 @@ bool VideoOMX::displayIFrame(const UCHAR* buffer, UINT length) { int VideoOMX::EnterIframePlayback() { - clock_mutex.Lock(); if (cur_input_buf_omx) { - PutBufferToPres(cur_input_buf_omx, lastreftimeOMX,true); - + PutBufferToPres(cur_input_buf_omx, lastreftimeOMX, lastreftimePTS,true); cur_input_buf_omx = NULL; } - clock_mutex.Unlock(); + input_bufs_omx_mutex.Lock(); + while (input_bufs_omx_present.size()) { + input_bufs_omx_free.push_back(input_bufs_omx_present.front()); + input_bufs_omx_present.pop_front(); + } + input_time_present.clear(); + input_time_pts.clear(); + input_is_last.clear(); + input_bufs_omx_mutex.Unlock(); + iframemode=true; return 1; diff --git a/videoomx.h b/videoomx.h index be11fdf..9fd9caf 100644 --- a/videoomx.h +++ b/videoomx.h @@ -147,6 +147,7 @@ class VideoOMX : public Video, public Thread_TYPE long long startoffset; long long lastrefvideotime; long long lastrefaudiotime; + long long cur_pts; OMX_TICKS lastreftimeOMX; ULLONG lastreftimePTS; @@ -234,11 +235,12 @@ class VideoOMX : public Video, public Thread_TYPE list input_bufs_omx_free; list input_bufs_omx_present; list input_time_present; + list input_time_pts; list input_is_last; Mutex input_bufs_omx_mutex; OMX_BUFFERHEADERTYPE* cur_input_buf_omx; - void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer, long long time,bool is_last); + void PutBufferToPres(OMX_BUFFERHEADERTYPE* buffer, long long time,long long pts, bool is_last); void threadMethod(); void threadPostStopCleanup(); -- 2.39.5