Skip to content

Commit

Permalink
IPTV/HLS/M3U Skip segments from the past
Browse files Browse the repository at this point in the history
Start recording, and playback in case of Live TV, from a segment
that is near live and discard all segments older than that.
Previously, recording started from the oldest segment.

Refs #936
  • Loading branch information
kmdewaal committed Nov 27, 2024
1 parent 5334bb6 commit 15b6a01
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mythtv/libs/libmythtv/recorders/HLS/HLSReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,29 @@ bool HLSReader::ParseM3U8(const QByteArray& buffer, HLSRecStream* stream)
return false;
}

// For near-live skip all segments that are in the past.
if (m_curSeq < 0)
{
// Compute number of segments for 20 seconds buffer from live.
// If the duration is not know keep 4 segments.
int numseg = 4;
if (hls->TargetDuration() > 0s)
{
numseg = 20s / hls->TargetDuration();
numseg = std::clamp(numseg, 2, 20);
}

if (new_segments.size() > numseg)
{
int size_before = new_segments.size();
SegmentContainer::iterator Iseg = new_segments.begin() + (new_segments.size() - numseg);
new_segments.erase(new_segments.begin(), Iseg);
LOG(VB_RECORD, LOG_INFO, LOC +
QString(" Read last %1 segments instead of %2 for near-live")
.arg(new_segments.size()).arg(size_before));
}
}

SegmentContainer::iterator Inew = new_segments.begin();
SegmentContainer::iterator Iseg = m_segments.end() - 1;

Expand Down

0 comments on commit 15b6a01

Please sign in to comment.