This squashed commit comprises a long series of improvements, bug fixes, optimizations, and new feature additions:

- 48,000 frames per second operation,
 - 48k lossless stereo, 5.1 and 7.1 surround sound
 - Multichannel and multi rate operation on ALSA, PipeWire, PulseAudio, FreeBSD, stdout and unix pipe output backends.

Automatic, flexible and controllable output format (rate, sample format and channel count) selection.

Full FFmpeg integration to support transcoding, resampling, and new audio formats.

Better operation on lower powered devices down to e.g. Raspberry Pi B.

Reduced Docker image sizes with a slimmed-down FFmpeg library.

Enhanced timestamp handling for better synchronization.

Improved the sync error calculation.

A new "vernier" resampling and interpolation method for low-power CPUs.

Bug fixes and minor enhancements.

Note -- there are many breaking changes from previous versions of Shairport Sync!
This commit is contained in:
Mike Brady
2025-02-23 13:31:17 +00:00
parent 588e6a5b7b
commit 60143518c2
110 changed files with 12416 additions and 7759 deletions
+38 -9
View File
@@ -4,7 +4,7 @@
* All rights reserved.
*
* Modifications for audio synchronisation
* and related work, copyright (c) Mike Brady 2014
* and related work, copyright (c) Mike Brady 2014--2025
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
@@ -40,6 +40,8 @@
#include <unistd.h>
static int fd = -1;
static int warned = 0;
static unsigned int bytes_per_frame = 0;
char *pipename = NULL;
char *default_pipe_name = "/tmp/shairport-sync-audio";
@@ -77,11 +79,13 @@ static int play(void *buf, int samples, __attribute__((unused)) int sample_type,
// if it's got a reader, write to it.
if (fd > 0) {
// int rc = non_blocking_write(fd, buf, samples * 4);
int rc = write(fd, buf, samples * 4);
if ((rc < 0) && (errno != EPIPE)) {
if (bytes_per_frame == 0)
debug(1, "pipe: bytes per frame not initialised before play()!");
int rc = write(fd, buf, samples * bytes_per_frame);
if ((rc < 0) && (errno != EPIPE) && (warned == 0)) {
strerror_r(errno, (char *)errorstring, 1024);
debug(1, "audio_pip play: error %d writing to the pipe named \"%s\": \"%s\".", errno,
pipename, errorstring);
debug(1, "error %d writing to the pipe named \"%s\": \"%s\".", errno, pipename, errorstring);
warned = 1;
}
}
return 0;
@@ -102,9 +106,13 @@ static int init(int argc, char **argv) {
config.audio_backend_buffer_desired_length = 1.0;
config.audio_backend_latency_offset = 0;
// do the "general" audio options. Note, these options are in the "general" stanza!
parse_general_audio_options();
// get settings from settings file, passing in defaults for format_set, rate_set and channel_set
// Note, these options may be in the "general" stanza or the named stanza
#ifdef CONFIG_AIRPLAY_2
parse_audio_options("pipe", (1 << SPS_FORMAT_S32_LE), (1 << SPS_RATE_48000), (1 << 2));
#else
parse_audio_options("pipe", (1 << SPS_FORMAT_S16_LE), (1 << SPS_RATE_44100), (1 << 2));
#endif
if (config.cfg != NULL) {
/* Get the Output Pipename. */
const char *str;
@@ -145,11 +153,32 @@ static void help(void) {
printf(" Provide the pipe's pathname. The default is \"%s\".\n", default_pipe_name);
}
static int32_t get_configuration(unsigned int channels, unsigned int rate, unsigned int format) {
// use the standard format/rate/channel search to get a suitable configuration. No
// check_configuration() method needs to be passed to search_for_suitable_configuration() because
// it will always return a valid choice based on any settings and the defaults
return search_for_suitable_configuration(channels, rate, format, NULL);
}
static int configure(int32_t requested_encoded_format, __attribute__((unused)) char **channel_map) {
int response = 0;
unsigned int bytes_per_sample =
sps_format_sample_size(FORMAT_FROM_ENCODED_FORMAT(requested_encoded_format));
if (bytes_per_sample == 0) {
debug(1, "pipe: unknown output format.");
bytes_per_sample = 4; // emergency hack
response = EINVAL;
}
bytes_per_frame = bytes_per_sample * CHANNELS_FROM_ENCODED_FORMAT(requested_encoded_format);
return response;
}
audio_output audio_pipe = {.name = "pipe",
.help = &help,
.init = &init,
.deinit = &deinit,
.prepare = NULL,
.get_configuration = &get_configuration,
.configure = &configure,
.start = &start,
.stop = &stop,
.is_running = NULL,