From 12d831fc391bf916eeaa20faf1a42be057c30c80 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 20 Nov 2020 11:52:57 +0100 Subject: [PATCH] pulse-server: request dbus name Request the org.pulseaudio.Server dbus name. This makes gnome-shell reconnect automatically. --- src/modules/meson.build | 8 ++- src/modules/module-protocol-pulse/dbus-name.c | 64 +++++++++++++++++++ .../module-protocol-pulse/pulse-server.c | 3 + 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/modules/module-protocol-pulse/dbus-name.c diff --git a/src/modules/meson.build b/src/modules/meson.build index 1bac7414d..e4bec5f99 100644 --- a/src/modules/meson.build +++ b/src/modules/meson.build @@ -88,6 +88,12 @@ pipewire_module_protocol_native = shared_library('pipewire-module-protocol-nativ dependencies : pipewire_module_protocol_deps, ) +pipewire_module_protocol_pulse_deps = pipewire_module_protocol_deps + +if dbus_dep.found() + pipewire_module_protocol_pulse_deps += dbus_dep +endif + pipewire_module_protocol_pulse = shared_library('pipewire-module-protocol-pulse', [ 'module-protocol-pulse.c', 'module-protocol-pulse/pulse-server.c', @@ -97,7 +103,7 @@ pipewire_module_protocol_pulse = shared_library('pipewire-module-protocol-pulse' install : true, install_dir : modules_install_dir, install_rpath: modules_install_dir, - dependencies : pipewire_module_protocol_deps, + dependencies : pipewire_module_protocol_pulse_deps, ) pipewire_module_client_node = shared_library('pipewire-module-client-node', diff --git a/src/modules/module-protocol-pulse/dbus-name.c b/src/modules/module-protocol-pulse/dbus-name.c new file mode 100644 index 000000000..dfd1faca6 --- /dev/null +++ b/src/modules/module-protocol-pulse/dbus-name.c @@ -0,0 +1,64 @@ +/* pulseaudio server + * + * Copyright © 2019 Wim Taymans + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +static int dbus_request_name(struct pw_context *context, const char *name) +{ + struct spa_dbus *dbus; + struct spa_dbus_connection *conn; + const struct spa_support *support; + uint32_t n_support; + DBusConnection *bus; + DBusError error; + + support = pw_context_get_support(context, &n_support); + + dbus = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DBus); + if (dbus == NULL) + return -ENOTSUP; + + conn = spa_dbus_get_connection(dbus, SPA_DBUS_TYPE_SESSION); + if (conn == NULL) + return -errno; + + bus = spa_dbus_connection_get(conn); + + dbus_error_init(&error); + + if (dbus_bus_request_name(bus, name, + DBUS_NAME_FLAG_DO_NOT_QUEUE, + &error) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + return 0; + + if (dbus_error_is_set(&error)) + pw_log_error("Failed to acquire %s: %s: %s", name, error.name, error.message); + else + pw_log_error("D-Bus name %s already taken.", name); + + dbus_error_free(&error); + + return -EEXIST; +} diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 0f1b3a53d..8a5c90af1 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -71,6 +71,7 @@ #include "volume.c" #include "message.c" #include "manager.h" +#include "dbus-name.c" #define NAME "pulse-server" @@ -5270,6 +5271,8 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context, pw_free_strv(addr); free(free_str); + dbus_request_name(context, "org.pulseaudio.Server"); + return (struct pw_protocol_pulse*)impl; error_free: