diff options
author | Youness Alaoui <youness.alaoui@collabora.co.uk> | 2011-08-31 03:01:58 +0000 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2011-08-31 12:10:32 +0200 |
commit | 917708df82b1bb50401c85bbe3d7573650ecd929 (patch) | |
tree | 7be41316c38389b307a7ea3c44bfdecd5b2924a8 /gst/hls | |
parent | 4724b9a5b6e8f9435055613775328d7c33c74cd6 (diff) | |
download | gstreamer-plugins-bad-917708df82b1bb50401c85bbe3d7573650ecd929.tar.gz |
hlsdemux: start/stop update thread and keep track of status
Diffstat (limited to 'gst/hls')
-rw-r--r-- | gst/hls/gsthlsdemux.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/gst/hls/gsthlsdemux.c b/gst/hls/gsthlsdemux.c index 4a9b0aca2..41284e483 100644 --- a/gst/hls/gsthlsdemux.c +++ b/gst/hls/gsthlsdemux.c @@ -102,6 +102,7 @@ static void gst_hls_demux_loop (GstHLSDemux * demux); static void gst_hls_demux_stop (GstHLSDemux * demux); static void gst_hls_demux_stop_fetcher_locked (GstHLSDemux * demux, gboolean cancelled); +static void gst_hls_demux_stop_update (GstHLSDemux * demux); static gboolean gst_hls_demux_start_update (GstHLSDemux * demux); static gboolean gst_hls_demux_cache_fragments (GstHLSDemux * demux); static gboolean gst_hls_demux_schedule (GstHLSDemux * demux); @@ -379,9 +380,7 @@ gst_hls_demux_src_event (GstPad * pad, GstEvent * event) g_mutex_lock (demux->fetcher_lock); gst_hls_demux_stop_fetcher_locked (demux, TRUE); g_mutex_unlock (demux->fetcher_lock); - g_mutex_lock (demux->thread_lock); - g_cond_signal (demux->thread_cond); - g_mutex_unlock (demux->thread_lock); + gst_hls_demux_stop_update (demux); gst_task_pause (demux->task); /* wait for streaming to finish */ @@ -658,9 +657,7 @@ gst_hls_demux_stop (GstHLSDemux * demux) g_mutex_unlock (demux->fetcher_lock); if (GST_TASK_STATE (demux->task) != GST_TASK_STOPPED) gst_task_stop (demux->task); - g_mutex_lock (demux->thread_lock); - g_cond_signal (demux->thread_cond); - g_mutex_unlock (demux->thread_lock); + gst_hls_demux_stop_update (demux); } static void @@ -897,6 +894,7 @@ gst_hls_demux_update_thread (GstHLSDemux * demux) * switch to a different bitrate */ g_mutex_lock (demux->thread_lock); + GST_DEBUG_OBJECT (demux, "Started updates thread"); while (TRUE) { /* block until the next scheduled update or the signal to quit this thread */ if (g_cond_timed_wait (demux->thread_cond, demux->thread_lock, @@ -939,19 +937,40 @@ gst_hls_demux_update_thread (GstHLSDemux * demux) quit: { + GST_DEBUG_OBJECT (demux, "Stopped updates thread"); + demux->updates_thread = NULL; g_mutex_unlock (demux->thread_lock); return TRUE; } } + +static void +gst_hls_demux_stop_update (GstHLSDemux * demux) +{ + GError *error; + + GST_DEBUG_OBJECT (demux, "Stopping updates thread"); + while (demux->updates_thread) { + g_mutex_lock (demux->thread_lock); + g_cond_signal (demux->thread_cond); + g_mutex_unlock (demux->thread_lock); + } +} + static gboolean gst_hls_demux_start_update (GstHLSDemux * demux) { GError *error; /* creates a new thread for the updates */ - demux->updates_thread = g_thread_create ( - (GThreadFunc) gst_hls_demux_update_thread, demux, FALSE, &error); + g_mutex_lock (demux->thread_lock); + if (demux->updates_thread == NULL) { + GST_DEBUG_OBJECT (demux, "Starting updates thread"); + demux->updates_thread = g_thread_create ( + (GThreadFunc) gst_hls_demux_update_thread, demux, FALSE, &error); + } + g_mutex_unlock (demux->thread_lock); return (error != NULL); } |