[vlc-devel] [PATCH] HLS: Wait for segment to be available

Frédéric Yhuel fyhuel at viotech.net
Mon Apr 16 09:47:20 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 |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index e1e533a..3e41add 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -2109,6 +2109,24 @@ 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)
+            break;
+        vlc_cond_wait(&p_sys->download.wait, &p_sys->download.lock_wait);
+        segment = GetSegment(s);
+    }
+    vlc_mutex_unlock(&p_sys->download.lock_wait);
+
+    return segment;
+}
+
 static int segment_RestorePos(segment_t *segment)
 {
     if (segment->data)
@@ -2134,9 +2152,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