From c80adb0b597f5dbc6fd8ffcb4bd246f38e32f781 Mon Sep 17 00:00:00 2001 From: "yuzhuohuang@qq.com" Date: Thu, 22 Dec 2011 10:12:12 +0800 Subject: [PATCH] Fixed stuttering bug for video with frame rate other then 23.976. --- src/subtitles/RTS.cpp | 27 ++++++++++++++++++++------- src/subtitles/RTS.h | 2 +- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/subtitles/RTS.cpp b/src/subtitles/RTS.cpp index 6487097..303f19b 100644 --- a/src/subtitles/RTS.cpp +++ b/src/subtitles/RTS.cpp @@ -3013,8 +3013,21 @@ STDMETHODIMP CRenderedTextSubtitle::NonDelegatingQueryInterface(REFIID riid, voi STDMETHODIMP_(POSITION) CRenderedTextSubtitle::GetStartPosition(REFERENCE_TIME rt, double fps) { + + //DbgLog((LOG_TRACE, 3, "rt:%lu", (ULONG)rt/10000)); m_fps = fps;//fix me: check is fps changed and do some re-init thing + if (m_fps>0) + { + m_period = 1000/m_fps; + } + else + { + //Todo: fix me. max has been defined as a macro. Use #define NOMINMAX to fix it. + //std::numeric_limits::max(); + m_period = INT_MAX; + } + int iSegment; int subIndex = 1;//If a segment has animate effect then it corresponds to several subpics. //subIndex, 1 based, indicates which subpic the result corresponds to. @@ -3026,7 +3039,7 @@ STDMETHODIMP_(POSITION) CRenderedTextSubtitle::GetStartPosition(REFERENCE_TIME r { int start = TranslateSegmentStart(iSegment, fps); if(rt > start) - subIndex = (rt-start)/RTS_ANIMATE_SUBPIC_DUR + 1; + subIndex = (rt-start)/m_period + 1; } //DbgLog((LOG_TRACE, 3, "animated:%d seg:%d idx:%d DUR:%d rt:%lu", stss->animated, iSegment, subIndex, RTS_ANIMATE_SUBPIC_DUR, (ULONG)rt/10000)); return (POSITION)(subIndex | (iSegment< end) ret = end; } @@ -3124,9 +3137,9 @@ STDMETHODIMP_(VOID) CRenderedTextSubtitle::GetStartStop(POSITION pos, double fps { if(stss->animated) { - start += (subIndex-1)*RTS_ANIMATE_SUBPIC_DUR; - if(start+RTS_ANIMATE_SUBPIC_DUR < stop) - stop = start+RTS_ANIMATE_SUBPIC_DUR; + start += (subIndex-1)*m_period; + if(start+m_period < stop) + stop = start+m_period; } //DbgLog((LOG_TRACE, 3, "animated:%d seg:%d idx:%d start:%d stop:%lu", stss->animated, iSegment, subIndex, (ULONG)start, (ULONG)stop)); start *= 10000i64; diff --git a/src/subtitles/RTS.h b/src/subtitles/RTS.h index 3cdf8d0..4b2b9ae 100644 --- a/src/subtitles/RTS.h +++ b/src/subtitles/RTS.h @@ -31,7 +31,6 @@ #define RTS_POS_SEGMENT_INDEX_BITS 16 #define RTS_POS_SUB_INDEX_MASK ((1<