diff --git a/src/stream/FFmpegCatchupStream.cpp b/src/stream/FFmpegCatchupStream.cpp index 2cad6f52..31e7ee79 100644 --- a/src/stream/FFmpegCatchupStream.cpp +++ b/src/stream/FFmpegCatchupStream.cpp @@ -362,9 +362,9 @@ bool FFmpegCatchupStream::GetTimes(kodi::addon::InputstreamTimes& times) return true; } -void FFmpegCatchupStream::UpdateCurrentPTS() +void FFmpegCatchupStream::CurrentPTSUpdated() { - FFmpegStream::UpdateCurrentPTS(); + FFmpegStream::CurrentPTSUpdated(); if (m_currentPts != STREAM_NOPTS_VALUE) m_currentPts += m_seekOffset; } diff --git a/src/stream/FFmpegCatchupStream.h b/src/stream/FFmpegCatchupStream.h index 2bfb1d5f..df2f493c 100644 --- a/src/stream/FFmpegCatchupStream.h +++ b/src/stream/FFmpegCatchupStream.h @@ -43,7 +43,7 @@ class FFmpegCatchupStream : public FFmpegStream virtual bool IsRealTimeStream() override; protected: - void UpdateCurrentPTS() override; + void CurrentPTSUpdated() override; bool CheckReturnEmptyOnPacketResult(int result) override; long long GetCurrentLiveOffset() { return std::time(nullptr) - m_catchupBufferStartTime; } diff --git a/src/stream/FFmpegStream.cpp b/src/stream/FFmpegStream.cpp index 3e9ccfd4..bf019f89 100644 --- a/src/stream/FFmpegStream.cpp +++ b/src/stream/FFmpegStream.cpp @@ -434,7 +434,10 @@ DEMUX_PACKET* FFmpegStream::DemuxRead() // used to guess streamlength if (pPacket->dts != STREAM_NOPTS_VALUE && (pPacket->dts > m_currentPts || m_currentPts == STREAM_NOPTS_VALUE)) + { m_currentPts = pPacket->dts; + CurrentPTSUpdated(); + } // store internal id until we know the continuous id presented to player // the stream might not have been created yet @@ -795,8 +798,6 @@ bool FFmpegStream::Open(bool fileinfo) // if format can be nonblocking, let's use that m_pFormatContext->flags |= AVFMT_FLAG_NONBLOCK; - UpdateCurrentPTS(); - // select the correct program if requested m_initialProgramNumber = UINT_MAX; CVariant programProp(m_programProperty.empty() ? CVariant::VariantTypeNull : CVariant(m_programProperty)); @@ -1145,20 +1146,8 @@ void FFmpegStream::ResetVideoStreams() } } -void FFmpegStream::UpdateCurrentPTS() +void FFmpegStream::CurrentPTSUpdated() { - m_currentPts = STREAM_NOPTS_VALUE; - - int idx = av_find_default_stream_index(m_pFormatContext); - if (idx >= 0) - { - AVStream* stream = m_pFormatContext->streams[idx]; - if (stream && m_pkt.pkt.dts != (int64_t)AV_NOPTS_VALUE) - { - double ts = ConvertTimestamp(m_pkt.pkt.dts, stream->time_base.den, stream->time_base.num); - m_currentPts = ts; - } - } } double FFmpegStream::ConvertTimestamp(int64_t pts, int den, int num) @@ -1541,7 +1530,7 @@ bool FFmpegStream::SeekTime(double time, bool backwards, double* startpts) if (m_pFormatContext->iformat->read_seek) m_seekToKeyFrame = true; - UpdateCurrentPTS(); + m_currentPts = STREAM_NOPTS_VALUE; } } diff --git a/src/stream/FFmpegStream.h b/src/stream/FFmpegStream.h index 85d7de1f..0340514d 100644 --- a/src/stream/FFmpegStream.h +++ b/src/stream/FFmpegStream.h @@ -104,7 +104,7 @@ class FFmpegStream protected: virtual std::string GetStreamCodecName(int iStreamId); - virtual void UpdateCurrentPTS(); + virtual void CurrentPTSUpdated(); bool IsPaused() { return m_speed == STREAM_PLAYSPEED_PAUSE; } virtual bool CheckReturnEmptyOnPacketResult(int result);