X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=ext%2Fsoup%2Fgstsouphttpclientsink.c;h=d8f46df9d30a482168204eedb7ea0c579e62f86d;hb=93e3ed5a869afb79f9658f22ced4691ce475e8a1;hp=af238277feadcfce35784bc73db67df64f7dfff7;hpb=692e00cc00d772fe2b01f518cb9ac88d124807d1;p=platform%2Fupstream%2Fgstreamer.git diff --git a/ext/soup/gstsouphttpclientsink.c b/ext/soup/gstsouphttpclientsink.c index af23827..d8f46df 100644 --- a/ext/soup/gstsouphttpclientsink.c +++ b/ext/soup/gstsouphttpclientsink.c @@ -42,6 +42,8 @@ #include #include "gstsouphttpclientsink.h" +#include + GST_DEBUG_CATEGORY_STATIC (souphttpclientsink_dbg); #define GST_CAT_DEFAULT souphttpclientsink_dbg @@ -445,6 +447,20 @@ gst_soup_http_client_sink_get_times (GstBaseSink * sink, GstBuffer * buffer, } +static gboolean +thread_ready_idle_cb (gpointer data) +{ + GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (data); + + GST_LOG_OBJECT (souphttpsink, "thread ready"); + + g_mutex_lock (souphttpsink->mutex); + g_cond_signal (souphttpsink->cond); + g_mutex_unlock (souphttpsink->mutex); + + return FALSE; /* only run once */ +} + static gpointer thread_func (gpointer ptr) { @@ -452,7 +468,6 @@ thread_func (gpointer ptr) GST_DEBUG ("thread start"); - souphttpsink->loop = g_main_loop_new (souphttpsink->context, TRUE); g_main_loop_run (souphttpsink->loop); GST_DEBUG ("thread quit"); @@ -468,12 +483,35 @@ gst_soup_http_client_sink_start (GstBaseSink * sink) if (souphttpsink->prop_session) { souphttpsink->session = souphttpsink->prop_session; } else { + GSource *source; GError *error = NULL; souphttpsink->context = g_main_context_new (); + /* set up idle source to signal when the main loop is running and + * it's safe for ::stop() to call g_main_loop_quit() */ + source = g_idle_source_new (); + g_source_set_callback (source, thread_ready_idle_cb, sink, NULL); + g_source_attach (source, souphttpsink->context); + g_source_unref (source); + + souphttpsink->loop = g_main_loop_new (souphttpsink->context, TRUE); + + g_mutex_lock (souphttpsink->mutex); + + /* FIXME: error handling */ +#if !GLIB_CHECK_VERSION (2, 31, 0) souphttpsink->thread = g_thread_create (thread_func, souphttpsink, TRUE, &error); +#else + souphttpsink->thread = g_thread_try_new ("souphttpclientsink-thread", + thread_func, souphttpsink, &error); +#endif + + GST_LOG_OBJECT (souphttpsink, "waiting for main loop thread to start up"); + g_cond_wait (souphttpsink->cond, souphttpsink->mutex); + g_mutex_unlock (souphttpsink->mutex); + GST_LOG_OBJECT (souphttpsink, "main loop thread running"); souphttpsink->session = soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT,