]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Actually implement auto-connection, and document it.
authorJörn Nettingsmeier <nettings@luchtbeweging.nl>
Sat, 16 Feb 2019 18:45:51 +0000 (18:45 +0000)
committerJörn Nettingsmeier <nettings@luchtbeweging.nl>
Sat, 16 Feb 2019 18:45:51 +0000 (18:45 +0000)
audio_jack.c
scripts/shairport-sync.conf

index 6f4e341613b40ca38242db4ef90786f5126f1686..d98be5469107b0367f25f85fac32fc1bda211756 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "audio.h"
 #include "common.h"
+#include <stdlib.h>
 #include <errno.h>
 #include <limits.h>
 #include <pthread.h>
@@ -156,6 +157,7 @@ static void info(const char *desc) {
 }
 
 int jack_init(__attribute__((unused)) int argc, __attribute__((unused)) char **argv) {
+  int i;
   config.audio_backend_latency_offset = 0;
   config.audio_backend_buffer_desired_length = 0.500;
   config.audio_backend_buffer_interpolation_threshold_in_seconds =
@@ -206,7 +208,7 @@ int jack_init(__attribute__((unused)) int argc, __attribute__((unused)) char **a
   jack_set_error_function(&error);
   jack_set_info_function(&info);
 
-  for (int i=0; i < NPORTS; i++) {
+  for (i=0; i < NPORTS; i++) {
     port[i] = jack_port_register(client, port_name[i], JACK_DEFAULT_AUDIO_TYPE,
                                  JackPortIsOutput, 0);
   }
@@ -218,14 +220,40 @@ int jack_init(__attribute__((unused)) int argc, __attribute__((unused)) char **a
 
   if (config.jack_autoconnect_pattern != NULL) {
     debug(1, "config.jack_autoconnect_pattern is %s.", config.jack_autoconnect_pattern);
-    const char** port_list = jack_get_ports(client, config.jack_autoconnect_pattern, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput);
-    while (*port_list != NULL) {
-      debug(1, "Found matching JACK port %s.", *port_list);
-      port_list++;
-      // FIXME: implement actual connection, warn user if more than 2 hits.
+    const char** port_list = jack_get_ports(client, config.jack_autoconnect_pattern,
+                                            JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput);
+    for (i=0; i<NPORTS ; i++) {
+      char* full_port_name[NPORTS];
+      full_port_name[i] = malloc(sizeof(char) * jack_port_name_size());
+      sprintf(full_port_name[i], "%s:%s", config.jack_client_name, port_name[i]);
+      if (port_list[i] != NULL) {
+        int err;
+        debug(1, "Connecting %s to %s.", full_port_name[i], port_list[i]);
+        err = jack_connect(client, full_port_name[i], port_list[i]);
+        switch (err) {
+        case EEXIST:
+          inform("The requested connection from %s to %s already exists.",
+                 full_port_name[i], port_list[i]);
+          break;
+        case 0:
+          // success
+          break;
+        default:
+          inform("JACK error no. %d occured while trying to connect %s to %s.",
+                 err, full_port_name[i], port_list[i]);
+          break;
+        }
+      } else {
+        inform("No matching port found in %s to connect %s to. You may not hear audio.",
+               config.jack_autoconnect_pattern, full_port_name[i]);
+      }
+      free(full_port_name[i]);
+    }
+    while (port_list[i++] != NULL) {
+      inform("Additional matching port %s found. Check that the connections are what you intended.");
     }
+    jack_free(port_list);
   }
-  
   pthread_mutex_unlock(&client_mutex);
 
   return 0;
index addbd1ee27ee83f79e45e02d4dd669e9c33c2ac4..a5403fe4d557a003e45bb1f46ea3e4244ef5a1c8 100644 (file)
@@ -108,8 +108,14 @@ pa =
 // Parameters for the "jack" JACK Audio Connection Kit backend.
 jack =
 {
-//     client_name = "shairport-sync"; //Set this to the name of the client that should appear in "Connections" when Shairport Sync is active.
-//     autoconnect_pattern = ""; //Set this to a pattern that describes the ports you would like to connect to automatically when we start up, like "system:playback_?"
+//     client_name = "shairport-sync"; // Set this to the name of the client that should appear in "Connections" when Shairport Sync is active.
+//     autoconnect_pattern = ""; // Set this to a POSIX regular expression pattern that describes the ports you would like to connect to
+//                                   automatically. Examples:
+//                                   "system:playback_[12]"
+//                                   "some_app_[0-9]*:in-[LR]"
+//                                   "jack_mixer:in_2[78]"
+//                                   Beware: if you make a syntax error, libjack might crash. In that case, fix it and start over.
+//                                   For a good overview, look here: https://www.ibm.com/support/knowledgecenter/SS8NLW_11.0.1/com.ibm.swg.im.infosphere.dataexpl.engine.doc/c_posix-regex-examples.html
 };
 
 // Parameters for the "pipe" audio back end, a back end that directs raw CD-style audio output to a pipe. No interpolation is done.