[vlc-commits] HLS: implement pause

Rafaël Carré git at videolan.org
Tue Aug 27 14:41:57 CEST 2013


vlc/vlc-2.1 | branch: master | Rafaël Carré <funman at videolan.org> | Mon Aug 26 16:41:34 2013 +0200| [fdc515c4786920aac664315f1ec997cd17f22037] | committer: Jean-Baptiste Kempf

HLS: implement pause

Close #9234

(cherry picked from commit fc1655e16fda7fb79f5c520cf3209fc874961c66)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.1.git/?a=commit;h=fdc515c4786920aac664315f1ec997cd17f22037
---

 modules/stream_filter/httplive.c |   40 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index ae191f4..a65767d 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -147,6 +147,11 @@ struct stream_sys_t
     bool        b_live;     /* live stream? or vod? */
     bool        b_error;    /* parsing error */
     bool        b_aesmsg;   /* only print one time that the media is encrypted */
+
+    /* Shared data */
+    vlc_cond_t   wait;
+    vlc_mutex_t  lock;
+    bool         paused;
 };
 
 /****************************************************************************
@@ -1798,8 +1803,14 @@ static int Prefetch(stream_t *s, int *current)
  ****************************************************************************/
 static int hls_Download(stream_t *s, segment_t *segment)
 {
+    stream_sys_t *p_sys = s->p_sys;
     assert(segment);
 
+    vlc_mutex_lock(&p_sys->lock);
+    while (p_sys->paused)
+        vlc_cond_wait(&p_sys->wait, &p_sys->lock);
+    vlc_mutex_unlock(&p_sys->lock);
+
     stream_t *p_ts = stream_UrlNew(s, segment->url);
     if (p_ts == NULL)
         return VLC_EGENERIC;
@@ -2006,6 +2017,11 @@ static int Open(vlc_object_t *p_this)
     s->pf_peek = Peek;
     s->pf_control = Control;
 
+    p_sys->paused = false;
+
+    vlc_cond_init(&p_sys->wait);
+    vlc_mutex_init(&p_sys->lock);
+
     /* Parse HLS m3u8 content. */
     uint8_t *buffer = NULL;
     ssize_t len = read_M3U8_from_stream(s->p_source, &buffer);
@@ -2084,6 +2100,9 @@ fail:
     }
     vlc_array_destroy(p_sys->hls_stream);
 
+    vlc_mutex_destroy(&p_sys->lock);
+    vlc_cond_destroy(&p_sys->wait);
+
     /* */
     free(p_sys->m3u8);
     free(p_sys);
@@ -2100,6 +2119,11 @@ static void Close(vlc_object_t *p_this)
 
     assert(p_sys->hls_stream);
 
+    vlc_mutex_lock(&p_sys->lock);
+    p_sys->paused = false;
+    vlc_cond_signal(&p_sys->wait);
+    vlc_mutex_unlock(&p_sys->lock);
+
     /* */
     vlc_mutex_lock(&p_sys->download.lock_wait);
     /* negate the condition variable's predicate */
@@ -2127,6 +2151,10 @@ static void Close(vlc_object_t *p_this)
     vlc_array_destroy(p_sys->hls_stream);
 
     /* */
+
+    vlc_mutex_destroy(&p_sys->lock);
+    vlc_cond_destroy(&p_sys->wait);
+
     free(p_sys->m3u8);
     if (p_sys->peeked)
         block_Release (p_sys->peeked);
@@ -2609,15 +2637,25 @@ static int Control(stream_t *s, int i_query, va_list args)
             *(va_arg (args, bool *)) = hls_MaySeek(s);
             break;
         case STREAM_CAN_CONTROL_PACE:
+        case STREAM_CAN_PAUSE:
             *(va_arg (args, bool *)) = true;
             break;
         case STREAM_CAN_FASTSEEK:
-        case STREAM_CAN_PAUSE: /* TODO */
             *(va_arg (args, bool *)) = false;
             break;
         case STREAM_GET_POSITION:
             *(va_arg (args, uint64_t *)) = p_sys->playback.offset;
             break;
+        case STREAM_SET_PAUSE_STATE:
+        {
+            bool paused = va_arg (args, unsigned);
+
+            vlc_mutex_lock(&p_sys->lock);
+            p_sys->paused = paused;
+            vlc_cond_signal(&p_sys->wait);
+            vlc_mutex_unlock(&p_sys->lock);
+            break;
+        }
         case STREAM_SET_POSITION:
             if (hls_MaySeek(s))
             {



More information about the vlc-commits mailing list