Skip to content

Commit

Permalink
Add PipeWire sink target setting. Fix PipeWire node name code, duh, r…
Browse files Browse the repository at this point in the history
…emove code that was double-deallocating settings strings.
  • Loading branch information
mikebrady committed Oct 6, 2023
1 parent 420fe4c commit 98679bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
28 changes: 14 additions & 14 deletions audio_pw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion scripts/shairport-sync.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<sink target name>"; // Leave this commented out to get the sink target already chosen by the PipeWire system.
};

// Parameters for the "pa" PulseAudio backend.
Expand Down

0 comments on commit 98679bb

Please sign in to comment.