#include "audio.h"
#include "common.h"
+#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <pthread.h>
}
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 =
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);
}
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;
// 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.