1 diff --git a/ext/adaptivedemux2/meson.build b/ext/adaptivedemux2/meson.build
2 index 711b38a2a9..67a789f664 100644
3 --- a/ext/adaptivedemux2/meson.build
4 +++ b/ext/adaptivedemux2/meson.build
5 @@ -82,7 +82,7 @@ soup_link_args = []
8 default_library = get_option('default_library')
9 -if host_system != 'linux' or default_library in ['static', 'both']
10 +if default_library in ['static', 'both']
11 if soup_ver_opt in ['auto', '3']
12 libsoup3_dep = dependency('libsoup-3.0', allow_fallback: true,
13 required: soup_ver_opt == '3' and soup_opt.enabled())
14 @@ -120,7 +120,7 @@ adaptive_deps = [gmodule_dep, gst_dep, gsttag_dep, gstnet_dep, gstbase_dep, gstp
15 adaptive_args = [gst_plugins_good_args, soup_loader_args, hls_cargs,
16 '-DGST_ISOFF_API=G_GNUC_INTERNAL']
18 -if host_system != 'linux'
20 adaptivedemux2 = library('gstadaptivedemux2',
21 c_args: [adaptive_args, soup_link_args],
22 dependencies: [adaptive_deps, soup_link_deps],
23 diff --git a/ext/soup/gstsouploader.c b/ext/soup/gstsouploader.c
24 index 9192e4dac5..8082b2614d 100644
25 --- a/ext/soup/gstsouploader.c
26 +++ b/ext/soup/gstsouploader.c
27 @@ -34,12 +34,18 @@ GST_DEBUG_CATEGORY (gst_soup_debug);
31 -#if defined(__APPLE__) || defined(G_OS_WIN32)
32 -#error "dlopen of libsoup is only supported on Linux"
33 +#if defined(G_OS_WIN32)
34 +#error "dlopen of libsoup is only supported on Darwin and Linux"
37 +#if defined(__APPLE__)
38 +#define LIBSOUP_3_SONAME "libsoup-3.0.0.dylib"
39 +#define LIBSOUP_2_SONAME "libsoup-2.4.1.dylib"
40 +#define LIBSOUP_COMMON_SYMBOL "soup_get_major_version"
42 #define LIBSOUP_3_SONAME "libsoup-3.0.so.0"
43 #define LIBSOUP_2_SONAME "libsoup-2.4.so.1"
46 #define LOAD_SYMBOL(name) G_STMT_START { \
47 if (!g_module_symbol (module, G_STRINGIFY (name), (gpointer *) &G_PASTE (vtable->_, name))) { \
48 @@ -156,7 +162,46 @@ gst_soup_load_library (void)
49 GST_DEBUG_CATEGORY_INIT (gst_soup_debug, "soup", 0, "soup");
52 -#ifdef HAVE_RTLD_NOLOAD
53 +#if defined(__APPLE__)
54 + g_autofree gchar* libsoup_path = NULL;
56 + /* In order to avoid causing conflicts we detect if libsoup 2 or 3 is loaded already.
57 + * Darwin has to probe by checking for symbols because `dlopen` called with a dylib
58 + * basename will try to locate it via the process’s rpath stack (and not find it). */
60 + gpointer func = NULL;
61 + Dl_info info = { 0 };
63 + GModule* module = g_module_open (NULL, 0);
64 + if (g_module_symbol (module, LIBSOUP_COMMON_SYMBOL, &func)
65 + && dladdr (func, &info) && info.dli_sname) {
66 + libsoup_path = g_strndup(info.dli_fname, PATH_MAX - 1);
67 + g_autofree gchar* image_name = g_path_get_basename (libsoup_path);
69 + /* Make sure `libsoup_path` points to a dylib that actually exists and
70 + * contains the libsoup symbol that was queried. */
71 + gpointer handle = dlopen (libsoup_path, RTLD_NOW | RTLD_NOLOAD);
72 + gboolean has_symbol = dlsym (handle, LIBSOUP_COMMON_SYMBOL) != NULL;
73 + if (handle && has_symbol && g_str_equal (image_name, LIBSOUP_3_SONAME)) {
74 + libsoup_sonames[0] = libsoup_path;
75 + GST_DEBUG ("LibSoup 3 found");
76 + } else if (handle && has_symbol && g_str_equal (image_name, LIBSOUP_2_SONAME)) {
77 + libsoup_sonames[0] = libsoup_path;
78 + GST_DEBUG ("LibSoup 2 found");
80 + g_clear_pointer (&libsoup_path, g_free);
82 + g_clear_pointer (&handle, dlclose);
84 + g_module_close (module);
86 + if (!libsoup_sonames[0]) {
87 + GST_DEBUG ("Trying all libsoups");
88 + libsoup_sonames[0] = LIBSOUP_3_SONAME;
89 + libsoup_sonames[1] = LIBSOUP_2_SONAME;
92 +#elif defined(HAVE_RTLD_NOLOAD)
94 gpointer handle = NULL;
96 diff --git a/ext/soup/meson.build b/ext/soup/meson.build
97 index aaa01dbcf6..83b7cf3fbf 100644
98 --- a/ext/soup/meson.build
99 +++ b/ext/soup/meson.build
100 @@ -20,8 +20,8 @@ soup_link_deps = []
101 libsoup2_dep = disabler()
102 libsoup3_dep = disabler()
103 default_library = get_option('default_library')
104 -soup_lookup_dep = get_option('soup-lookup-dep') and host_system == 'linux'
105 -if host_system != 'linux' or default_library in ['static', 'both'] or soup_lookup_dep
106 +soup_lookup_dep = get_option('soup-lookup-dep')
107 +if default_library in ['static', 'both'] or soup_lookup_dep
108 if soup_ver_opt in ['auto', '3']
109 libsoup3_dep = dependency('libsoup-3.0', allow_fallback: true,
110 required: soup_ver_opt == '3' and soup_opt.enabled())
111 @@ -33,7 +33,7 @@ if host_system != 'linux' or default_library in ['static', 'both'] or soup_looku
115 -if host_system != 'linux' or default_library in ['static', 'both']
116 +if default_library in ['static', 'both']
117 if libsoup3_dep.found()
118 soup_link_deps += libsoup3_dep
119 soup_link_args += '-DLINK_SOUP=3'
120 @@ -60,7 +60,7 @@ soup_library_kwargs = {
121 soup_library_deps = [gst_dep, gstbase_dep, gsttag_dep, gmodule_dep, gio_dep, libdl_dep]
122 soup_library_c_args = gst_plugins_good_args
124 -if host_system != 'linux'
126 gstsouphttpsrc = library('gstsoup',
127 c_args : soup_library_c_args + soup_link_args,
128 dependencies : soup_library_deps + soup_link_deps,