From 0338e992ff63acb598b71df1a9bfb8535ee42d53 Mon Sep 17 00:00:00 2001 From: Ross Nicholson Date: Thu, 8 Aug 2019 21:55:09 -0700 Subject: [PATCH] [VideoPlayer] Fix TS resume point, related to PR16314 - backport --- .../DVDDemuxers/DVDDemuxFFmpeg.cpp | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp index c83509a5b0574..6445470f6f54d 100644 --- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp +++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp @@ -31,6 +31,10 @@ #include "utils/StringUtils.h" #include "utils/URIUtils.h" +#ifdef TARGET_POSIX +#include "platform/linux/XTimeUtils.h" +#endif + #ifdef HAVE_LIBBLURAY #include "DVDInputStreams/DVDInputStreamBluray.h" #endif @@ -1165,6 +1169,25 @@ bool CDVDDemuxFFmpeg::SeekTime(double time, bool backwards, double *startpts) if (m_checkvideo) { + XbmcThreads::EndTime timer(1000); + + while (!IsVideoReady()) + { + DemuxPacket* pkt = Read(); + if (pkt) + CDVDDemuxUtils::FreeDemuxPacket(pkt); + else + Sleep(10); + m_pkt.result = -1; + av_packet_unref(&m_pkt.pkt); + + if (timer.IsTimePast()) + { + CLog::Log(LOGERROR, "CDVDDemuxFFmpeg::%s - Timed out waiting for video to be ready", __FUNCTION__); + return false; + } + } + AVStream* st = m_pFormatContext->streams[m_seekStream]; seek_pts = av_rescale(m_startTime + time / 1000, st->time_base.den, st->time_base.num); } @@ -2135,7 +2158,7 @@ bool CDVDDemuxFFmpeg::IsVideoReady() { if (!m_startTime) { - m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den); + m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den) - 0.000001; m_seekStream = i; } return true; @@ -2153,7 +2176,7 @@ bool CDVDDemuxFFmpeg::IsVideoReady() st = m_pFormatContext->streams[idx]; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - m_startTime = static_cast(av_rescale(st->cur_dts, st->time_base.num, st->time_base.den)); + m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den) - 0.000001; m_seekStream = i; break; } @@ -2171,7 +2194,7 @@ bool CDVDDemuxFFmpeg::IsVideoReady() { if (!m_startTime) { - m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den); + m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den) - 0.000001; m_seekStream = i; } return true; @@ -2188,7 +2211,7 @@ bool CDVDDemuxFFmpeg::IsVideoReady() st = m_pFormatContext->streams[i]; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - m_startTime = static_cast(av_rescale(st->cur_dts, st->time_base.num, st->time_base.den)); + m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den) - 0.000001; m_seekStream = i; break; }