From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Fri, 6 Oct 2023 09:51:49 +0000 (+0100) Subject: Add PipeWire sink target setting. Fix PipeWire node name code, duh, remove code that... X-Git-Tag: 4.3.2^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98679bbb54f5aaeda859e34aa28425647b8d179e;p=thirdparty%2Fshairport-sync.git Add PipeWire sink target setting. Fix PipeWire node name code, duh, remove code that was double-deallocating settings strings. --- diff --git a/audio_pw.c b/audio_pw.c index f77b8766..1bd9c5ab 100644 --- a/audio_pw.c +++ b/audio_pw.c @@ -173,13 +173,6 @@ static void deinit(void) { pw_thread_loop_destroy(data.loop); pw_deinit(); free(audio_lmb); // deallocate that buffer - if (config.pw_application_name) - free(config.pw_application_name); - if (config.pw_node_name) - free(config.pw_node_name); - config.pw_application_name = config.pw_node_name = NULL; - - } static int init(__attribute__((unused)) int argc, __attribute__((unused)) char **argv) { @@ -196,21 +189,25 @@ static int init(__attribute__((unused)) int argc, __attribute__((unused)) char * // get settings from settings file // do the "general" audio options. Note, these options are in the "general" stanza! parse_general_audio_options(); - - + // now any PipeWire-specific options if (config.cfg != NULL) { const char *str; - /* Get the Application Name. */ + // Get the optional Application Name, if provided. if (config_lookup_string(config.cfg, "pw.application_name", &str)) { config.pw_application_name = (char *)str; } - /* Get the PipeWire node name. */ - if (config_lookup_string(config.cfg, "pa.node_name", &str)) { + // Get the optional PipeWire node name, if provided. + if (config_lookup_string(config.cfg, "pw.node_name", &str)) { config.pw_node_name = (char *)str; } + + // Get the optional PipeWire sink target name, if provided. + if (config_lookup_string(config.cfg, "pw.sink_target", &str)) { + config.pw_sink_target = (char *)str; + } } // finished collecting settings @@ -247,12 +244,15 @@ static int init(__attribute__((unused)) int argc, __attribute__((unused)) char * char* nodename = config.pw_node_name; if (nodename == NULL) nodename = "Shairport Sync"; - - props = pw_properties_new(PW_KEY_MEDIA_TYPE, "Audio", PW_KEY_MEDIA_CATEGORY, "Playback", PW_KEY_MEDIA_ROLE, "Music", PW_KEY_APP_NAME, appname, PW_KEY_NODE_NAME, nodename, NULL); + + if (config.pw_sink_target != NULL) { + debug(3, "setting sink target to \"%s\".", config.pw_sink_target); + pw_properties_set(props, PW_KEY_TARGET_OBJECT, config.pw_sink_target); + } data.stream = pw_stream_new_simple(pw_thread_loop_get_loop(data.loop), config.appName, props, &stream_events, &data); diff --git a/common.h b/common.h index 3a392f68..a1d50d44 100644 --- a/common.h +++ b/common.h @@ -149,6 +149,7 @@ typedef struct { // Defaults to "Shairport Sync". char *pw_node_name; // defaults to the application's name, usually "shairport-sync". + char *pw_sink_target; // leave this unset if you don't want to change the sink_target. #endif #ifdef CONFIG_METADATA int metadata_enabled; diff --git a/scripts/shairport-sync.conf b/scripts/shairport-sync.conf index cddffeb7..79ef16cf 100644 --- a/scripts/shairport-sync.conf +++ b/scripts/shairport-sync.conf @@ -160,7 +160,8 @@ sndio = pw = { // application_name = "Shairport Sync"; // Set this to the name that should appear in the Sounds "Applications" or "Volume Levels". -// node_name = "Shairport Sync"; // This appears in some PipeWire CLI tool outputs +// node_name = "Shairport Sync"; // This appears in some PipeWire CLI tool outputs. +// sink_target = ""; // Leave this commented out to get the sink target already chosen by the PipeWire system. }; // Parameters for the "pa" PulseAudio backend.