adaptivedemux2: Fix download helper with libsoup 3.0.x
authorJan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>
Thu, 18 Aug 2022 14:36:45 +0000 (16:36 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 18 Aug 2022 20:16:18 +0000 (20:16 +0000)
libsoup 3.0.x dispatches using a single source attached when the session
is created, so we need to create the session with the same context that
our download thread is later using.

2.74 or 3.1 will dispatch a response using the context which sent the
request. However, for any context other than the one that created the
session, this will also create and destroy sources, so there's still
some slight performance benefit.

Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1384
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2913>

subprojects/gst-plugins-good/ext/adaptivedemux2/downloadhelper.c

index 3541364078db49949f6b2086fd171bf541efbcaf..80b49751da3d4f41c8969272bc36f8968cf13a61 100644 (file)
@@ -609,10 +609,16 @@ downloadhelper_new (GstAdaptiveDemuxClock * clock)
       g_async_queue_new_full ((GDestroyNotify) g_object_unref);
   dh->transfer_requests_source = NULL;
 
+  /* libsoup 3.0 (not 2.74 or 3.1) dispatches using a single source attached
+   * when the session is created, so we need to ensure it matches here. */
+  g_main_context_push_thread_default (dh->transfer_context);
+
   /* Set 10 second timeout. Any longer is likely
    * an attempt to reuse an already closed connection */
   dh->session = _soup_session_new_with_options ("timeout", 10, NULL);
 
+  g_main_context_pop_thread_default (dh->transfer_context);
+
   return dh;
 }