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

Frédéric Yhuel fyhuel at viotech.net
Fri Apr 13 16:43:23 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 |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 433dca0..3e956a7 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -2131,8 +2131,19 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read)
          * bandwidth conditions changed, then the stream might have switched
          * to another bandwidth. */
         segment_t *segment = GetSegment(s);
-        if (segment == NULL)
-            break;
+        vlc_mutex_lock(&p_sys->download.lock_wait);
+        while (segment == NULL)
+        {
+            msg_Dbg(s, "GetSegment returned NULL");
+            if (p_sys->b_error)
+            {
+                vlc_mutex_unlock(&p_sys->download.lock_wait);
+                break;
+            }
+            vlc_cond_wait(&p_sys->download.wait, &p_sys->download.lock_wait);
+            segment = GetSegment(s);
+        }
+        vlc_mutex_unlock(&p_sys->download.lock_wait);
 
         vlc_mutex_lock(&segment->lock);
         if (segment->data->i_buffer == 0)
-- 
1.7.5.4




More information about the vlc-devel mailing list