[vlc-devel] [PATCH 10/48] hls: Wait for segment in peek

Hugo Beauzée-Luyssen beauze.h at gmail.com
Mon Jan 9 16:16:19 CET 2012


From: Luc Saillard <luc.saillard at sfr.com>

---
 modules/stream_filter/httplive.c |   34 +++++++++++++++++++++++++++++-----
 1 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index ecddc01..3f0a7f4 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -2,6 +2,7 @@
  * httplive.c: HTTP Live Streaming stream filter
  *****************************************************************************
  * Copyright (C) 2010-2011 M2X BV
+ * Copyright (C) 2004-2011 the VideoLAN team
  * $Id$
  *
  * Author: Jean-Paul Saman <jpsaman _AT_ videolan _DOT_ org>
@@ -1579,10 +1580,8 @@ static void* hls_Thread(void *p_this)
                    (p_sys->download.seek == -1))
             {
                 vlc_cond_wait(&p_sys->download.wait, &p_sys->download.lock_wait);
-                if (p_sys->b_live /*&& (mdate() >= p_sys->playlist.wakeup)*/)
-                    break;
-                if (!vlc_object_alive(s))
-                    break;
+                if (!vlc_object_alive(s)) break;
+                if (p_sys->b_live) break;
             }
             /* */
             if (p_sys->download.seek >= 0)
@@ -2244,12 +2243,37 @@ static int Peek(stream_t *s, const uint8_t **pp_peek, unsigned int i_peek)
     segment_t *segment;
     unsigned int len = i_peek;
 
+again:
+    if (p_sys->b_reset)
+    {
+        msg_Err(s, "Please wait while closing stream... and reopen it");
+        char *original_playlist = strdup(p_sys->m3u8_playlist);
+        Close((vlc_object_t *)s);
+        OpenWithPlaylist(s, original_playlist);
+        free(original_playlist);
+        p_sys = s->p_sys;
+    }
+
     segment = GetSegment(s);
     if (segment == NULL)
     {
         msg_Err(s, "segment %d should have been available (stream %d)",
                 p_sys->playback.segment, p_sys->playback.stream);
-        return 0; /* eof? */
+
+        msg_Info(s, "Waiting for segment to be downloaded");
+
+        vlc_mutex_lock(&p_sys->download.lock_wait);
+
+        /* wake up the download segment thread if blocked */
+        vlc_cond_signal(&p_sys->download.wait);
+
+        mtime_t timeout = mdate() + 5000000;
+        if( vlc_cond_timedwait( &p_sys->download.wait, &p_sys->download.lock_wait, timeout ) )
+            msg_Warn(s, "Peek() reached timeout");
+        vlc_mutex_unlock(&p_sys->download.lock_wait);
+        if (!vlc_object_alive(s) || s->b_error)
+            return 0; /* eof? */
+        goto again;
     }
 
     vlc_mutex_lock(&segment->lock);
-- 
1.7.8.3




More information about the vlc-devel mailing list