From 947a0ca291d307272b5bc3fe74f3065e035a4fde Mon Sep 17 00:00:00 2001 From: Maciej Wilczynski Date: Sat, 15 Sep 2018 20:05:31 +0200 Subject: [PATCH 1/2] Add PA sink configuration option --- audio_pa.c | 18 ++++++++++++++++-- common.h | 4 +++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/audio_pa.c b/audio_pa.c index d8f8a9d3..aec4d992 100644 --- a/audio_pa.c +++ b/audio_pa.c @@ -85,6 +85,11 @@ static int init(__attribute__((unused)) int argc, __attribute__((unused)) char * if (config_lookup_string(config.cfg, "pa.application_name", &str)) { config.pa_application_name = (char *)str; } + + /* Get the PulseAudio sink name. */ + if (config_lookup_string(config.cfg, "pa.sink", &str)) { + config.pa_sink = (char *)str; + } } // finish collecting settings @@ -178,8 +183,17 @@ static void start(__attribute__((unused)) int sample_rate, // PA_STREAM_AUTO_TIMING_UPDATE; PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY; - // Connect stream to the default audio output sink - if (pa_stream_connect_playback(stream, NULL, &buffer_attr, stream_flags, NULL, NULL) != 0) + int connect_result; + + if (config.pa_sink) { + // Connect stream to the sink specified in the config + connect_result = pa_stream_connect_playback(stream, config.pa_sink, &buffer_attr, stream_flags, NULL, NULL); + } else { + // Connect stream to the default audio output sink + connect_result = pa_stream_connect_playback(stream, NULL, &buffer_attr, stream_flags, NULL, NULL); + } + + if (connect_result != 0) die("could not connect to the pulseaudio playback stream -- the error message is \"%s\".", pa_strerror(pa_context_errno(context))); diff --git a/common.h b/common.h index c25b166a..c5d03aa3 100644 --- a/common.h +++ b/common.h @@ -84,7 +84,9 @@ typedef struct { #ifdef CONFIG_PA char *pa_application_name; // the name under which Shairport Sync shows up as an "Application" in // the Sound Preferences in most desktop Linuxes. -// Defaults to "Shairport Sync". Shairport Sync must be playing to see it. + // Defaults to "Shairport Sync". Shairport Sync must be playing to see it. + + char *pa_sink; // the name (or id) of the sink that Shairport Sync will play on. #endif #ifdef CONFIG_METADATA int metadata_enabled; From 231b77d5439946bfa10b00ec0c075b8ac1043f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wilczy=C5=84ski?= Date: Sat, 15 Sep 2018 20:40:35 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bfd61851..45309fd3 100644 --- a/README.md +++ b/README.md @@ -326,7 +326,15 @@ alsa = }; ``` -The `pa` group is used to specify settings relevant to the PulseAudio backend. You can set the "Application Name" that will appear in the "Sound" control panel. +The `pa` group is used to specify settings relevant to the PulseAudio backend. You can set the "Application Name" that will appear in the "Sound" control panel. You can also set the sink name that audio will be pushed to. Here's an example `pa` group configuration: + +``` +pa = +{ + application_name = "Shairport Sync - Bedroom"; + sink = "server_bedroom"; // Sink name or ID. If not specified, the default sink will be used. +}; +``` Shairport Sync can run programs just before it starts to play an audio stream and just after it finishes. You specify them using the `sessioncontrol` group settings `run_this_before_play_begins` and `run_this_after_play_ends`. This is to facilitate situations where something has to be done before and after playing, e.g. switching on an amplifier beforehand and switching it off afterwards. Set the `wait_for_completion` value to `"yes"` for Shairport Sync to wait until the respective commands have been completed before continuing.