[vlc-devel] [PATCH] HLS: Wait for segment to be available
Frédéric Yhuel
fyhuel at viotech.net
Tue Apr 24 09:16:53 CEST 2012
Without this patch the playback could stop if the available bandwidth
is more or less equal to the lowest stream bitrate. With this patch,
the user might experience a few "freezes" at the begining and then
smooth playback afterwards.
---
modules/stream_filter/httplive.c | 24 +++++++++++++++++++++++-
1 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 433dca0..eb7dfee 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -2105,6 +2105,25 @@ check:
return segment;
}
+static segment_t *WaitForSegment(stream_t *s)
+{
+ stream_sys_t *p_sys = s->p_sys;
+
+ segment_t *segment = GetSegment(s);
+ vlc_mutex_lock(&p_sys->download.lock_wait);
+ while (segment == NULL)
+ {
+ if (p_sys->b_error || !vlc_object_alive(s))
+ break;
+ vlc_cond_timedwait(&p_sys->download.wait,
+ &p_sys->download.lock_wait, mdate() + 100000 );
+ segment = GetSegment(s);
+ }
+ vlc_mutex_unlock(&p_sys->download.lock_wait);
+
+ return segment;
+}
+
static int segment_RestorePos(segment_t *segment)
{
if (segment->data)
@@ -2130,9 +2149,12 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read)
/* Determine next segment to read. If this is a meta playlist and
* bandwidth conditions changed, then the stream might have switched
* to another bandwidth. */
- segment_t *segment = GetSegment(s);
+ segment_t *segment = WaitForSegment(s);
if (segment == NULL)
+ {
+ msg_Warn(s, "WaitForSegment() returned NULL");
break;
+ }
vlc_mutex_lock(&segment->lock);
if (segment->data->i_buffer == 0)
--
1.7.5.4
More information about the vlc-devel
mailing list