[vlc-devel] [PATCH 23/48] hls: Reset stream

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


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

---
 modules/stream_filter/httplive.c |   56 +++++++++++++++++++++++++++++---------
 1 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 42a1ebe..1dc75a0 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -147,6 +147,7 @@ struct stream_sys_t
     bool        b_error;    /* parsing error */
     bool        b_aesmsg;   /* only print one time that the media is encrypted */
     bool        b_quit;
+    bool        b_reset;    /* Set to true when a stream should be reset */
 };
 
 /****************************************************************************
@@ -1520,6 +1521,7 @@ static int hls_DownloadSegmentData(stream_t *s, hls_stream_t *hls, segment_t *se
         msg_Err(s, "downloaded segment %d from stream %d failed",
                     segment->sequence, *cur_stream);
         vlc_mutex_unlock(&segment->lock);
+        p_sys->b_reset = true;
         return VLC_EGENERIC;
     }
     mtime_t duration = mdate() - start;
@@ -1533,6 +1535,7 @@ static int hls_DownloadSegmentData(stream_t *s, hls_stream_t *hls, segment_t *se
     if (hls_DecodeSegmentData(s, hls, segment) != VLC_SUCCESS)
     {
         vlc_mutex_unlock(&segment->lock);
+        p_sys->b_reset = true;
         return VLC_EGENERIC;
     }
 
@@ -1920,16 +1923,10 @@ static char *ReadLine(uint8_t *buffer, uint8_t **pos, const size_t len)
 /****************************************************************************
  * Open
  ****************************************************************************/
-static int Open(vlc_object_t *p_this)
+static int OpenWithPlaylist(stream_t *s, const char *m3u8_playlist)
 {
-    stream_t *s = (stream_t*)p_this;
     stream_sys_t *p_sys;
 
-    if (!isHTTPLiveStreaming(s))
-        return VLC_EGENERIC;
-
-    msg_Info(p_this, "HTTP Live Streaming (%s)", s->psz_path);
-
     /* Initialize crypto bit */
     vlc_gcrypt_init();
 
@@ -1938,12 +1935,18 @@ static int Open(vlc_object_t *p_this)
     if (p_sys == NULL)
         return VLC_ENOMEM;
 
-    p_sys->m3u8_playlist = NULL;
-    if (asprintf(&p_sys->m3u8_playlist,"%s://%s", s->psz_access, s->psz_path) < 0)
+    if (m3u8_playlist == NULL)
     {
-        free(p_sys);
-        return VLC_ENOMEM;
+        if (asprintf(&p_sys->m3u8_playlist,"%s://%s", s->psz_access, s->psz_path) < 0)
+        {
+            free(p_sys);
+            return VLC_ENOMEM;
+        }
     }
+    else
+        p_sys->m3u8_playlist = strdup(m3u8_playlist);
+
+    msg_Info(s, "Open stream %s", p_sys->m3u8_playlist );
 
     p_sys->bandwidth = 0;
     p_sys->b_live = true;
@@ -1951,6 +1954,7 @@ static int Open(vlc_object_t *p_this)
     p_sys->b_error = false;
     p_sys->b_aesmsg = false;
     p_sys->b_quit = false;
+    p_sys->b_reset = false;
 
     p_sys->hls_stream = vlc_array_new();
     if (p_sys->hls_stream == NULL)
@@ -1967,7 +1971,12 @@ static int Open(vlc_object_t *p_this)
 
     /* Parse HLS m3u8 content. */
     uint8_t *buffer = NULL;
-    ssize_t len = read_M3U8_from_stream(s->p_source, &buffer);
+    ssize_t len;
+
+    if (m3u8_playlist)
+      len = read_M3U8_from_url(s, p_sys->m3u8_playlist, &buffer);
+    else
+      len = read_M3U8_from_stream(s->p_source, &buffer);
     if (len < 0)
         goto fail;
     if (parse_M3U8(s, p_sys->hls_stream, buffer, len) != VLC_SUCCESS)
@@ -1985,7 +1994,10 @@ static int Open(vlc_object_t *p_this)
         goto fail;
 
     /* manage encryption key if needed */
-    hls_ManageSegmentKeys(s, hls_Get(p_sys->hls_stream, current));
+    if (hls_ManageSegmentKeys(s, hls_Get(p_sys->hls_stream, current)) != VLC_SUCCESS)
+    {
+        goto fail;
+    }
 
     if (p_sys->b_live && (p_sys->playback.segment < 0))
     {
@@ -2057,6 +2069,24 @@ fail:
     return VLC_EGENERIC;
 }
 
+static int Open(vlc_object_t *p_this)
+{
+    stream_t *s = (stream_t*)p_this;
+
+    if (!isHTTPLiveStreaming(s))
+        return VLC_EGENERIC;
+
+    /* Initialize crypto bit */
+    vlc_gcrypt_init();
+
+    msg_Info(p_this, "HTTP Live Streaming (%s)", s->psz_path);
+    msg_Info(p_this, "Compiled by %s on %s (%s)", VLC_CompileBy(), VLC_CompileHost(), __DATE__" "__TIME__ );
+
+    /* */
+    return OpenWithPlaylist(s, NULL);
+}
+
+
 /****************************************************************************
  * Close
  ****************************************************************************/
-- 
1.7.8.3




More information about the vlc-devel mailing list