Skip to content

Commit

Permalink
Remove calls to UpdateCurrentPTS. We haven't read a packet at any of …
Browse files Browse the repository at this point in the history
…these points, so m_pkt.pkt.dts is invalid. m_currentPts will be updated when a valid packet is read. A new override CurrentPTSUpdated() will be called when this happens so catchup streams can update their internal references
  • Loading branch information
phunkyfish committed Jan 31, 2024
1 parent d301796 commit 51560b9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/stream/FFmpegCatchupStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream/FFmpegCatchupStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
21 changes: 5 additions & 16 deletions src/stream/FFmpegStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stream/FFmpegStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 51560b9

Please sign in to comment.