From: Sebastian Dröge Date: Fri, 28 Jan 2022 13:33:04 +0000 (+0200) Subject: souphttpsrc: Don't use the source element after setup from the session thread X-Git-Tag: 1.20.0~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=42f5873eeb505991e44d34039a24594b2b059f17;p=platform%2Fupstream%2Fgstreamer.git souphttpsrc: Don't use the source element after setup from the session thread The source element might be gone already if the session is shared with other source elements. As a consequence, do all logging via the session object instead of using the source element. Part-of: --- diff --git a/subprojects/gst-plugins-good/ext/soup/gstsouphttpclientsink.c b/subprojects/gst-plugins-good/ext/soup/gstsouphttpclientsink.c index df3a969..e094b2e 100644 --- a/subprojects/gst-plugins-good/ext/soup/gstsouphttpclientsink.c +++ b/subprojects/gst-plugins-good/ext/soup/gstsouphttpclientsink.c @@ -598,7 +598,7 @@ gst_soup_http_client_sink_start (GstBaseSink * sink) /* Set up logging */ gst_soup_util_log_setup (souphttpsink->session, souphttpsink->log_level, - GST_ELEMENT (souphttpsink)); + G_OBJECT (souphttpsink)); return TRUE; } diff --git a/subprojects/gst-plugins-good/ext/soup/gstsouphttpsrc.c b/subprojects/gst-plugins-good/ext/soup/gstsouphttpsrc.c index 09f535c..c8aad9b 100644 --- a/subprojects/gst-plugins-good/ext/soup/gstsouphttpsrc.c +++ b/subprojects/gst-plugins-good/ext/soup/gstsouphttpsrc.c @@ -985,18 +985,19 @@ static gpointer thread_func (gpointer user_data) { GstSoupHTTPSrc *src = user_data; + GstSoupSession *session = src->session; GMainContext *ctx; GST_DEBUG_OBJECT (src, "thread start"); - ctx = g_main_loop_get_context (src->session->loop); + ctx = g_main_loop_get_context (session->loop); g_main_context_push_thread_default (ctx); /* We explicitly set User-Agent to NULL here and overwrite it per message * to be able to have the same session with different User-Agents per * source */ - src->session->session = + session->session = _soup_session_new_with_options ("user-agent", NULL, "timeout", src->timeout, "tls-interaction", src->tls_interaction, /* Unset the limit the number of maximum allowed connections */ @@ -1015,20 +1016,19 @@ thread_func (gpointer user_data) g_object_unref (proxy_resolver); } } else { - g_object_set (src->session->session, "ssl-strict", src->ssl_strict, NULL); + g_object_set (session->session, "ssl-strict", src->ssl_strict, NULL); if (src->proxy != NULL) { - g_object_set (src->session->session, "proxy-uri", src->proxy->soup_uri, - NULL); + g_object_set (session->session, "proxy-uri", src->proxy->soup_uri, NULL); } } - gst_soup_util_log_setup (src->session->session, src->log_level, - GST_ELEMENT (src)); + gst_soup_util_log_setup (session->session, src->log_level, + G_OBJECT (session)); if (gst_soup_loader_get_api_version () < 3) { - _soup_session_add_feature_by_type (src->session->session, + _soup_session_add_feature_by_type (session->session, _soup_content_decoder_get_type ()); } - _soup_session_add_feature_by_type (src->session->session, + _soup_session_add_feature_by_type (session->session, _soup_cookie_jar_get_type ()); if (src->session_is_shared) { @@ -1036,11 +1036,11 @@ thread_func (gpointer user_data) GstMessage *message; GstStructure *s; - GST_DEBUG_OBJECT (src, "Sharing session %p", src->session->session); + GST_DEBUG_OBJECT (session, "Sharing session %p", session->session); context = gst_context_new (GST_SOUP_SESSION_CONTEXT, TRUE); s = gst_context_writable_structure (context); - gst_structure_set (s, "session", GST_TYPE_SOUP_SESSION, src->session, NULL); + gst_structure_set (s, "session", GST_TYPE_SOUP_SESSION, session, NULL); /* during this time the src is locked by the parent thread, * which is waiting, so this is safe to do @@ -1059,7 +1059,7 @@ thread_func (gpointer user_data) * and exits early if it does not) */ if (gst_soup_loader_get_api_version () < 3) { - g_signal_connect (src->session->session, "authenticate", + g_signal_connect (session->session, "authenticate", G_CALLBACK (gst_soup_http_src_authenticate_cb_2), src); } @@ -1077,11 +1077,17 @@ thread_func (gpointer user_data) } } - g_main_loop_run (src->session->loop); + /* Once the main loop is running, the source element that created this + * session might disappear if the session is shared with other source + * elements. + */ + src = NULL; + + g_main_loop_run (session->loop); g_main_context_pop_thread_default (ctx); - GST_DEBUG_OBJECT (src, "thread stop"); + GST_DEBUG_OBJECT (session, "thread stop"); return NULL; } @@ -1165,6 +1171,8 @@ gst_soup_http_src_session_open (GstSoupHTTPSrc * src) src->session = GST_SOUP_SESSION (g_object_new (GST_TYPE_SOUP_SESSION, NULL)); + GST_DEBUG_OBJECT (src, "Created session %p", src->session); + ctx = g_main_context_new (); src->session->loop = g_main_loop_new (ctx, FALSE); diff --git a/subprojects/gst-plugins-good/ext/soup/gstsouputils.c b/subprojects/gst-plugins-good/ext/soup/gstsouputils.c index a3e402f..d732c1a 100644 --- a/subprojects/gst-plugins-good/ext/soup/gstsouputils.c +++ b/subprojects/gst-plugins-good/ext/soup/gstsouputils.c @@ -63,26 +63,26 @@ gst_soup_util_log_printer_cb (SoupLogger G_GNUC_UNUSED * logger, { gchar c; c = gst_soup_util_log_make_level_tag (level); - GST_TRACE_OBJECT (GST_ELEMENT (user_data), "HTTP_SESSION(%c): %c %s", c, + GST_TRACE_OBJECT (G_OBJECT (user_data), "HTTP_SESSION(%c): %c %s", c, direction, data); } void gst_soup_util_log_setup (SoupSession * session, SoupLoggerLogLevel level, - GstElement * element) + GObject * object) { SoupLogger *logger; if (!level) { - GST_INFO_OBJECT (element, "Not attaching a logger with level 0"); + GST_INFO_OBJECT (object, "Not attaching a logger with level 0"); return; } - g_assert (session && element); + g_assert (session && object); if (gst_debug_category_get_threshold (GST_CAT_DEFAULT) < GST_LEVEL_TRACE) { - GST_INFO_OBJECT (element, "Not setting up HTTP session logger. " + GST_INFO_OBJECT (object, "Not setting up HTTP session logger. " "Need at least GST_LEVEL_TRACE"); return; } @@ -91,7 +91,7 @@ gst_soup_util_log_setup (SoupSession * session, SoupLoggerLogLevel level, logger = _soup_logger_new (level); _soup_logger_set_printer (logger, gst_soup_util_log_printer_cb, - gst_object_ref (element), (GDestroyNotify) gst_object_unref); + gst_object_ref (object), (GDestroyNotify) gst_object_unref); /* Attach logger to session */ _soup_session_add_feature (session, (SoupSessionFeature *) logger); diff --git a/subprojects/gst-plugins-good/ext/soup/gstsouputils.h b/subprojects/gst-plugins-good/ext/soup/gstsouputils.h index 54aee1a..2ac84a8 100644 --- a/subprojects/gst-plugins-good/ext/soup/gstsouputils.h +++ b/subprojects/gst-plugins-good/ext/soup/gstsouputils.h @@ -30,7 +30,7 @@ G_BEGIN_DECLS void gst_soup_util_log_setup (SoupSession * session, SoupLoggerLogLevel level, - GstElement * element); + GObject * object); G_END_DECLS