]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Add PipeWire sink target setting. Fix PipeWire node name code, duh, remove code that...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Fri, 6 Oct 2023 09:51:49 +0000 (10:51 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Fri, 6 Oct 2023 09:51:49 +0000 (10:51 +0100)
audio_pw.c
common.h
scripts/shairport-sync.conf

index f77b8766c9ec35c445423dadbf1c58ca4de6d9ac..1bd9c5ab2e88b7da446cebdd27c80cc994ed785e 100644 (file)
@@ -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);
index 3a392f684118a3c982b768e4409a1b953ddb3a58..a1d50d448131dad45b25d89a3ddf58a91a2eec23 100644 (file)
--- 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;
index cddffeb7276de400edfc984a761f21845d60baa3..79ef16cf4a91b63b196db6dda482b34b83250ce2 100644 (file)
@@ -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.