From 288e5eb69590ba65d84d83f935829e4cdc270757 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:40:42 +0100 Subject: [PATCH] Change node_name default to "Shairport Sync", parameterise a few settings. --- audio_pw.c | 19 ++++++++++--------- scripts/shairport-sync.conf | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/audio_pw.c b/audio_pw.c index 0dd38939..f77b8766 100644 --- a/audio_pw.c +++ b/audio_pw.c @@ -207,7 +207,7 @@ static int init(__attribute__((unused)) int argc, __attribute__((unused)) char * config.pw_application_name = (char *)str; } - /* Get the PulseAudio node name. */ + /* Get the PipeWire node name. */ if (config_lookup_string(config.cfg, "pa.node_name", &str)) { config.pw_node_name = (char *)str; } @@ -246,7 +246,7 @@ static int init(__attribute__((unused)) int argc, __attribute__((unused)) char * char* nodename = config.pw_node_name; if (nodename == NULL) - nodename = config.appName; + nodename = "Shairport Sync"; @@ -257,15 +257,15 @@ static int init(__attribute__((unused)) int argc, __attribute__((unused)) char * data.stream = pw_stream_new_simple(pw_thread_loop_get_loop(data.loop), config.appName, props, &stream_events, &data); - /* Make one parameter with the supported formats. The SPA_PARAM_EnumFormat - * id means that this is a format enumeration (of 1 value). */ + // Make one parameter with the supported formats. The SPA_PARAM_EnumFormat + // id means that this is a format enumeration (of 1 value). params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &SPA_AUDIO_INFO_RAW_INIT(.format = DEFAULT_FORMAT, .channels = DEFAULT_CHANNELS, .rate = DEFAULT_RATE)); - /* Now connect this stream. We ask that our process function is - * called in a realtime thread. */ + // Now connect this stream. We ask that our process function is + // called in a realtime thread. pw_stream_connect(data.stream, PW_DIRECTION_OUTPUT, PW_ID_ANY, PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_RT_PROCESS, @@ -284,7 +284,7 @@ static int play(__attribute__((unused)) void *buf, int samples, __attribute__((unused)) uint64_t playtime) { // copy the samples into the queue debug(3, "play %u samples; %u bytes already in the buffer.", samples, audio_occupancy); - size_t bytes_to_transfer = samples * 2 * 2; + size_t bytes_to_transfer = samples * DEFAULT_CHANNELS * DEFAULT_BYTES_PER_SAMPLE; pthread_mutex_lock(&buffer_mutex); size_t bytes_available = audio_size - audio_occupancy; if (bytes_available < bytes_to_transfer) @@ -351,11 +351,12 @@ int delay(long *the_delay) { */ } else { - debug(1, "can't get time info."); + warn("Shairport Sync's PipeWire backend can not get timing information from the PipeWire " + "system. Is PipeWire running?"); } pthread_mutex_lock(&buffer_mutex); - result = total_delay_now_frames_long + audio_occupancy / (2 * 2); + result = total_delay_now_frames_long + audio_occupancy / (DEFAULT_BYTES_PER_SAMPLE * DEFAULT_CHANNELS); pthread_mutex_unlock(&buffer_mutex); *the_delay = result; return reply; diff --git a/scripts/shairport-sync.conf b/scripts/shairport-sync.conf index 001a88d2..cddffeb7 100644 --- a/scripts/shairport-sync.conf +++ b/scripts/shairport-sync.conf @@ -159,8 +159,8 @@ sndio = // --with-pw pw = { -// application_name = "Shairport Sync"; // Set this to the name that should appear in the Sounds "Applications". -// node_name = ""; // This is normally "shairport-sync". +// 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 }; // Parameters for the "pa" PulseAudio backend.