[vlc-devel] [PATCH 16/48] hls: use bool quit

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


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

---
 modules/stream_filter/httplive.c |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 6569bd2..ecac6fe 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -144,6 +144,7 @@ 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 */
+    bool        b_quit;
 };
 
 /****************************************************************************
@@ -1565,7 +1566,7 @@ static void* hls_Thread(void *p_this)
 
     int canc = vlc_savecancel();
 
-    while (vlc_object_alive(s))
+    while (vlc_object_alive(s) && p_sys->b_quit == false)
     {
         hls_stream_t *hls = hls_Get(p_sys->hls_stream, p_sys->download.stream);
         assert(hls);
@@ -1588,6 +1589,7 @@ static void* hls_Thread(void *p_this)
                 vlc_cond_wait(&p_sys->download.wait, &p_sys->download.lock_wait);
                 if (!vlc_object_alive(s)) break;
                 if (p_sys->b_live) break;
+                if (p_sys->b_quit) break;
             }
             /* */
             if (p_sys->download.seek >= 0)
@@ -1599,6 +1601,7 @@ static void* hls_Thread(void *p_this)
         }
 
         if (!vlc_object_alive(s)) break;
+        if (p_sys->b_quit) break;
 
         vlc_mutex_lock(&hls->lock);
         segment_t *segment = segment_GetSegment(hls, p_sys->download.segment);
@@ -1616,6 +1619,7 @@ static void* hls_Thread(void *p_this)
             (hls_DownloadSegmentData(s, hls, segment, &p_sys->download.stream) != VLC_SUCCESS))
         {
             if (!vlc_object_alive(s)) break;
+            if (p_sys->b_quit) break;
 
             if (!p_sys->b_live)
             {
@@ -1637,6 +1641,7 @@ static void* hls_Thread(void *p_this)
         vlc_mutex_unlock(&p_sys->download.lock_wait);
     }
 
+    msg_Err(s, "Leaving thread hls_Thread() (is_alive=%d, b_quit=%d)", vlc_object_alive(s), p_sys->b_quit);
     vlc_restorecancel(canc);
     return NULL;
 }
@@ -1651,7 +1656,7 @@ static void* hls_Reload(void *p_this)
     int canc = vlc_savecancel();
 
     double wait = 0.5;
-    while (vlc_object_alive(s))
+    while (vlc_object_alive(s) && p_sys->b_quit == false)
     {
         mtime_t now = mdate();
         if (now >= p_sys->playlist.wakeup)
@@ -1691,6 +1696,7 @@ static void* hls_Reload(void *p_this)
         mwait(now + 1000000);
     }
 
+    msg_Err(s, "Leaving thread hls_Reload() (is_alive=%d, b_quit=%d)", vlc_object_alive(s), p_sys->b_quit);
     vlc_restorecancel(canc);
     return NULL;
 }
@@ -1804,7 +1810,7 @@ static int hls_Download(stream_t *s, segment_t *segment)
         if (length <= 0)
             break;
         curlen += length;
-    } while (vlc_object_alive(s));
+    } while (vlc_object_alive(s) && s->p_sys->b_quit == false);
 
     stream_Delete(p_ts);
     return VLC_SUCCESS;
@@ -1929,6 +1935,8 @@ static int Open(vlc_object_t *p_this)
     p_sys->b_live = true;
     p_sys->b_meta = false;
     p_sys->b_error = false;
+    p_sys->b_aesmsg = false;
+    p_sys->b_quit = false;
 
     p_sys->hls_stream = vlc_array_new();
     if (p_sys->hls_stream == NULL)
@@ -2041,12 +2049,15 @@ static void Close(vlc_object_t *p_this)
 
     assert(p_sys->hls_stream);
 
+    p_sys->b_quit = true;
+
     /* */
     vlc_mutex_lock(&p_sys->download.lock_wait);
     vlc_cond_signal(&p_sys->download.wait);
     vlc_mutex_unlock(&p_sys->download.lock_wait);
 
     /* */
+    msg_Err(s, "Waiting for thread reload playlist to finished (is_alive=%d)", vlc_object_alive(s));
     if (p_sys->b_live)
         vlc_join(p_sys->reload, NULL);
     vlc_join(p_sys->thread, NULL);
@@ -2097,7 +2108,7 @@ static segment_t *GetSegment(stream_t *s)
     /* Was the HLS stream changed to another bitrate? */
     int i_stream = 0;
     segment = NULL;
-    while(vlc_object_alive(s))
+    while(vlc_object_alive(s) && p_sys->b_quit == false)
     {
         /* Is the next segment ready */
         hls_stream_t *hls = hls_Get(p_sys->hls_stream, i_stream);
@@ -2217,7 +2228,7 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read)
         }
         vlc_mutex_unlock(&segment->lock);
 
-    } while ((i_read > 0) && vlc_object_alive(s));
+    } while ((i_read > 0) && vlc_object_alive(s) && p_sys->b_quit == false);
 
     return copied;
 }
@@ -2283,7 +2294,7 @@ again:
         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)
+        if (!vlc_object_alive(s) || s->b_error || p_sys->b_quit)
             return 0; /* eof? */
         goto again;
     }
@@ -2493,7 +2504,7 @@ static int segment_Seek(stream_t *s, const uint64_t pos)
                 (p_sys->download.segment < (count - 6)))
         {
             vlc_cond_wait(&p_sys->download.wait, &p_sys->download.lock_wait);
-            if (!vlc_object_alive(s) || s->b_error) break;
+            if (!vlc_object_alive(s) || s->b_error || p_sys->b_quit) break;
         }
         vlc_mutex_unlock(&p_sys->download.lock_wait);
 
-- 
1.7.8.3




More information about the vlc-devel mailing list