Skip to content

Commit

Permalink
Remove and ignore streams containing no segments.
Browse files Browse the repository at this point in the history
Some streams (France 24) ; have one stream that contains no segment whatsoever in one of the backup stream. So remove it after parsing it.
Unfortunately, that particular stream marks the over playback as VOD. Ideally we should ignore all tags from a stream that is going to be deleted. TODO
  • Loading branch information
jyavenard committed May 20, 2012
1 parent 8e324c6 commit d613b99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions mythtv/libs/libmythtv/HLS/httplivestreambuffer.cpp
Expand Up @@ -1396,7 +1396,7 @@ class PlaylistWorker : public MThread
/* Parse HLS m3u8 content. */
err = m_parent->ParseM3U8(&buffer, streams);
}
m_parent->AlignStreams(streams);
m_parent->SanitizeStreams(streams);
return err;
}

Expand Down Expand Up @@ -2292,7 +2292,7 @@ int HLSRingBuffer::ChooseSegment(int stream)
* Streams may not be all starting at the same sequence number, so attempt
* to align their starting sequence
*/
void HLSRingBuffer::AlignStreams(StreamsList *streams)
void HLSRingBuffer::SanitizeStreams(StreamsList *streams)
{
// no lock is required as, at this stage, no threads have either been started
// or we are working on a stream list unique to PlaylistWorker
Expand All @@ -2303,9 +2303,16 @@ void HLSRingBuffer::AlignStreams(StreamsList *streams)
QMap<int,int> idstart;
int count = streams->size();
// Find the highest starting sequence for each stream
for (int n = 0; n < count; n++)
for (int n = count - 1 ; n >= 0; n--)
{
HLSStream *hls = GetStream(n, streams);
if (hls->NumSegments() == 0)
{
streams->removeAt(n);
count--;
continue; // remove it
}

int id = hls->Id();
int start = hls->StartSequence();
if (!idstart.contains(id))
Expand All @@ -2324,8 +2331,6 @@ void HLSRingBuffer::AlignStreams(StreamsList *streams)
HLSStream *hls = GetStream(n, streams);
int id = hls->Id();
int seq = hls->StartSequence();
if (hls->NumSegments() == 0)
continue; // Invalid streams
int newstart= idstart.value(id);
int todrop = newstart - seq;
if (todrop == 0)
Expand Down Expand Up @@ -2382,12 +2387,12 @@ bool HLSRingBuffer::OpenFile(const QString &lfilename, uint retry_ms)
return false;
}

SanitizeStreams();

/* HLS standard doesn't provide any guaranty about streams
being sorted by bitrate, so we sort them, higher bitrate being first */
qSort(m_streams.begin(), m_streams.end(), HLSStream::IsGreater);

AlignStreams();

// if we want as close to live. We should be selecting a further segment
// m_live ? ChooseSegment(0) : 0;
m_startup = 0;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/HLS/httplivestreambuffer.h
Expand Up @@ -91,7 +91,7 @@ class HLSRingBuffer : public RingBuffer
int NumSegments(void) const;
int ChooseSegment(int stream);
int64_t SizeMedia(void) const;
void AlignStreams(StreamsList *streams = NULL);
void SanitizeStreams(StreamsList *streams = NULL);

// private member variables
QString m_m3u8; // M3U8 url
Expand Down

0 comments on commit d613b99

Please sign in to comment.