souphttpsrc: Post context message after setting up the context from the source's...
authorSebastian Dröge <sebastian@centricular.com>
Sat, 29 Jan 2022 10:54:23 +0000 (12:54 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sat, 29 Jan 2022 16:22:48 +0000 (16:22 +0000)
This simplifies the code and especially the locking a bit, and makes
sure we only export the session after it is fully set up.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1603>

subprojects/gst-plugins-good/ext/soup/gstsouphttpsrc.c

index c8aad9b..a488b06 100644 (file)
@@ -1031,27 +1031,6 @@ thread_func (gpointer user_data)
   _soup_session_add_feature_by_type (session->session,
       _soup_cookie_jar_get_type ());
 
-  if (src->session_is_shared) {
-    GstContext *context;
-    GstMessage *message;
-    GstStructure *s;
-
-    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, session, NULL);
-
-    /* during this time the src is locked by the parent thread,
-     * which is waiting, so this is safe to do
-     */
-    GST_OBJECT_UNLOCK (src);
-    gst_element_set_context (GST_ELEMENT_CAST (src), context);
-    message = gst_message_new_have_context (GST_OBJECT_CAST (src), context);
-    gst_element_post_message (GST_ELEMENT_CAST (src), message);
-    GST_OBJECT_LOCK (src);
-  }
-
   /* soup2: connect the authenticate handler for the src that spawned the
    * session (i.e. the first owner); other users of this session will connect
    * their own after fetching the external session; the callback will handle
@@ -1199,6 +1178,22 @@ gst_soup_http_src_session_open (GstSoupHTTPSrc * src)
 
   GST_OBJECT_UNLOCK (src);
 
+  if (src->session_is_shared) {
+    GstContext *context;
+    GstMessage *message;
+    GstStructure *s;
+
+    GST_DEBUG_OBJECT (src->session, "Sharing session %p", src->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_element_set_context (GST_ELEMENT_CAST (src), context);
+    message = gst_message_new_have_context (GST_OBJECT_CAST (src), context);
+    gst_element_post_message (GST_ELEMENT_CAST (src), message);
+  }
+
   return TRUE;
 
 err: