]> git.sesse.net Git - vlc/commitdiff
stream_filter/httplive.c: reloading playlist check before download segments
authorJean-Paul Saman <jean-paul.saman@m2x.nl>
Fri, 31 Dec 2010 14:31:49 +0000 (15:31 +0100)
committerJean-Paul Saman <jean-paul.saman@m2x.nl>
Fri, 31 Dec 2010 16:55:22 +0000 (17:55 +0100)
Rearrange hls_Thread logic with live playback in mind. In case all segments have been
downloaded, then make sure that reloading the playlist file happens before downloading
the next segment. This is also true when it is time to reload the playlist.

modules/stream_filter/httplive.c

index ba2c87c2f038a6af0b4ef9b4ac1880cb8758df4d..237eed46e233a7440ac7f00d6c6f473e7b98f1aa 100644 (file)
@@ -1206,14 +1206,15 @@ static void* hls_Thread(vlc_object_t *p_this)
         vlc_mutex_unlock(&hls->lock);
 
         /* Is there a new segment to process? */
-        if ((p_sys->playback.segment < (count - 6)) ||
+        if ((!p_sys->b_live && (p_sys->playback.segment < (count - 6))) ||
             (client->segment >= count))
         {
             /* wait */
             vlc_mutex_lock(&client->lock_wait);
             while (((client->segment - p_sys->playback.segment > 6) ||
                     (client->segment >= count)) &&
-                   (client->seek == -1))
+                   (client->seek == -1) &&
+                   (mdate() < p_sys->playlist.wakeup))
             {
                 vlc_cond_wait(&client->wait, &client->lock_wait);
                 if (!vlc_object_alive(p_this)) break;
@@ -1229,6 +1230,32 @@ static void* hls_Thread(vlc_object_t *p_this)
 
         if (!vlc_object_alive(p_this)) break;
 
+        /* reload the m3u8 index file */
+        if (p_sys->b_live)
+        {
+            double wait = 1;
+            mtime_t now = mdate();
+            if (now >= p_sys->playlist.wakeup)
+            {
+                if (hls_ReloadPlaylist(client->s) != VLC_SUCCESS)
+                {
+                    /* No change in playlist, then backoff */
+                    p_sys->playlist.tries++;
+                    if (p_sys->playlist.tries == 1) wait = 0.5;
+                    else if (p_sys->playlist.tries == 2) wait = 1;
+                    else if (p_sys->playlist.tries >= 3) wait = 3;
+                }
+                else p_sys->playlist.tries = 0;
+
+                /* determine next time to update playlist */
+                p_sys->playlist.last = now;
+                p_sys->playlist.wakeup = now + ((mtime_t)(hls->duration * wait)
+                                                * (mtime_t)1000000);
+            }
+
+            if (!vlc_object_alive(p_this)) break;
+        }
+
         vlc_mutex_lock(&hls->lock);
         segment_t *segment = segment_GetSegment(hls, client->segment);
         assert(segment);
@@ -1236,6 +1263,8 @@ static void* hls_Thread(vlc_object_t *p_this)
 
         if (Download(client->s, hls, segment, &client->current) != VLC_SUCCESS)
         {
+            if (!vlc_object_alive(p_this)) break;
+
             if (!p_sys->b_live)
             {
                 p_sys->b_error = true;
@@ -1255,30 +1284,6 @@ static void* hls_Thread(vlc_object_t *p_this)
             client->segment++;
         vlc_cond_signal(&client->wait);
         vlc_mutex_unlock(&client->lock_wait);
-
-        /* reload the m3u8 index file */
-        if (p_sys->b_live)
-        {
-            double wait = 1;
-            mtime_t now = mdate();
-            if (now >= p_sys->playlist.wakeup)
-            {
-                if (hls_ReloadPlaylist(client->s) != VLC_SUCCESS)
-                {
-                    /* No change in playlist, then backoff */
-                    p_sys->playlist.tries++;
-                    if (p_sys->playlist.tries == 1) wait = 0.5;
-                    else if (p_sys->playlist.tries == 2) wait = 1;
-                    else if (p_sys->playlist.tries >= 3) wait = 3;
-                }
-                else p_sys->playlist.tries = 0;
-
-                /* determine next time to update playlist */
-                p_sys->playlist.last = now;
-                p_sys->playlist.wakeup = now + ((mtime_t)(hls->duration * wait)
-                                                * (mtime_t)1000000);
-            }
-        }
     }
 
     vlc_restorecancel(canc);