54 Commits
Author SHA1 Message Date
Mike Brady 83ae1d286b Add a new exit handler to enable Shairport Sync to exit cleanly — that is, on exit, to clean up everything, e.g. open files, ports, sockets, devices, threads, it has been using.
If cleanup isn’t finished after one second, exit will occur unconditionally.
Use the new exit handler for normal exit, for SIGINT and SIGTERM handling, for abnormal exit after fatal errors, and for handling quit requests from the D-Bus and MPRIS interfaces.

When an unfixable error occurs without an installed unfixable error handler, unlock the mutex protecting Shairport Sync’s alsa backend to permit a clean exit.

Fix a very low-level mutex-locking error that interfered with debugging.

Simplify much mutex lock handling.
Remove lots of old and unused code, variables and definitions.

Update audio_sndio.c to remove some harmless compiler warnings.

Undo adding two seconds for messages to be output before _Exit() on die() to allow messages to be output...
Undo making die() exit unconditionally.
2026-07-16 14:51:06 +01:00
Mike Brady 16b6534ad3 further changes to remove compilation warnings on 32-bit builds 2025-12-31 19:02:16 +00:00
Mike Brady e05448aecc Check for configuration strings that are given but turn out to be empty, issue a warning and ignore them. 2025-04-14 10:40:26 +01:00
Mike Brady 60143518c2 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!
2025-02-23 13:31:17 +00:00
Mike Brady 597aba0ca6 Use an explicit 'is_running' flag in the sndio back end. Correct/improve some sndio documentation. 2024-07-22 10:28:30 +01:00
Mike Brady fd880056fb Squashed commit of the following:
Add three parameters to the backend play() function call -- (1) a flag indicating whether the samples are timed or not. If timed, (2) the timestamp and (3) the local time at which the first frame should be heard.
    Update missing pipewire library message.
    Makefile.am fix.
    Update the SHM version and fix the SHM name so that it works with FreeBSD.
    Remove redundant (?) AC_HEADER_STDC check.
    Fix compilation and installation under FreeBSD -- changes to allow building in a separate directory broke the FreeBSD build process.
    Add AC_CHECK_LIB for gcrypt in case PKG_CHECK_MODULES fails to find it.
    Find gcrypt using pkg-config
    Add code to detect when the RTSP channel goes idle for a period, and use it to reset clocks and timings, etc. so that SPS resumes correctly where the source has gone to sleep while playing a realtime stream and has subsequently woken up.
    Don't exit if a UDP Clock Control packet is empty. Also check minimum packet size.
    Remove some very experimental code which may cause memory and port leaks.
    Strip file path from the filename used in debug messages, information messages, warnings and fatal error messages.
    BB fix to Makefile.am -- overwriting the DBUS stuff with MPRIS definitions, duh.
    Fix some problems building on FreeBSD and tidy up the use of the "sed" editor.
    Fix some problems building on picore.
    Fix an uninitialised variable
    start using the "nqptp" SMI
2022-09-12 15:19:52 +01:00
Mike Brady 432b56c656 Remove stats function from audio_sndio backend, as it's too inaccurate. Also remove non-sensible infput frame rate from summary. 2022-05-23 14:00:28 +01:00
Mike Brady 55d5d496f3 use pthread push/pull to cleanly kill this code. add a stats function -- not quite working yet. 2022-05-19 20:24:30 +01:00
Mike Brady b386c22a0c Merge branch 'development' of https://github.com/mikebrady/shairport-sync into development
Merge.
2021-12-07 17:49:04 +00:00
Anton Lindqvist 57af5f3c10 avoid recursive mutex acquisition in sndio backend
Ending a RTSP session while running on OpenBSD using sndio backend causes the
following crash:

	#0  thrkill ()
	#1  0x000005208224403e in _libc_abort
	#2  0x00000520821b77be in _rthread_mutex_trylock
	#3  _rthread_mutex_timedlock
	#4  0x0000051e0d54e2c0 in stop ()
	#5  0x0000051e0d544e85 in player_thread_cleanup_handler
	#6  0x0000052082243126 in _libc_pthread_exit
	#7  0x000005209a158700 in sigthr_handler
	#8  <signal handler called>
	#9  _thread_sys_poll ()
	#10 0x000005208223533e in _libc_poll_cancel
	#11 0x00000520df54c9a0 in sio_psleep
	#12 0x00000520df54cc1f in sio_write
	#13 0x0000051e0d54e27a in play
	#14 0x0000051e0d547fc0 in player_thread_func
	#15 0x000005209a158cc1 in _rthread_start
	#16 0x000005208223565a in __tfork_thread

The player thread is blocking inside sio_write() -> poll(2) while the thread is
being terminated. The stop routine tied to the same backend is invoked through
player_thread_cleanup_handler() which tries to acquire the mutex which it
already acquired before invoking sio_write(). Avoiding blocking writes would
require switching to async I/O which is quite an undertaking.

The fact that there's only one `struct sio_hdl *' instance in the compilation
unit sort of implies there can only be one player thread at a time. Therefore
fix the crash by only trying to acquire the mutex and continue as usual if it's
already acquired.
2021-12-05 09:08:01 +01:00
Mike Brady 14bfba2724 Add code to check divisions and mods for a potrntial divide by zero problem. MAy cause SPS to terminate but leave a log message. 2021-11-21 21:47:32 +00:00
Mike Brady cd9da86fc3 Add a 'stats' function to the audio back ends to replace the 'rate_info' function. Zero all except the alsa back end. 2021-11-20 13:59:16 +00:00
Mike Brady 54d761ff7d Clean up some of the wording and layout of the configuration file
Clean up and improve the way lead-in sillence is used to give a more accurate sync time to the first packet of audio.
Allow very good sync to occur with 0.3 seconds of lead-in silence.
Improve the use of the buffer offset.
Format some other files.
2020-05-18 16:55:09 +01:00
Mike Brady c2655b0388 Use nanosecond time in audio_sndio 2020-02-25 15:53:56 +00:00
Mike Brady 85ba78b619 More fixes to allow gcc-10 to compile without error 2020-02-13 17:57:30 +00:00
Chris Boot b9cf91b2bb More typo fixes across the tree
Previously I have made spelling changes as caught by Debian's lintian
tool, which has a short list of common misspellings that it tests for.
This time I decided to run codespell against the source and fix all the
obvious problems it came up with. It also uses a list of misspellings
but it's much larger than lintian's, but also has some false positives
so I went over the list by hand.

The command I used to do check the source was:
git ls-tree -rz --name-only HEAD | xargs -0 codespell -L minimise,errorstring
2019-07-27 00:05:38 -03:00
Mike Brady c8b0be30b4 find . \( -name \*.cpp -or -name \*.h -or -name \*.c \) -exec clang-format -i -style='{BasedOnStyle: llvm, IndentWidth: 2, ColumnLimit: 100}' '{}' \; 2019-06-19 19:06:54 +01:00
Mike Brady 83c0405d03 Add automatic bit depth and speed selection for alsa devices. Set rate and format to "auto" by default. Always look for the greatest bit depth, but the lowest multiple of 44,100.
Improve support for big-endian CPUs by adding support for explicit -endian formats, i.e. S16_LE, S16_BE, S24_LE, S24_BE, S32_LE, S32_BE.

For the "disable_standby_mode" setting, change "while_active" to "auto".
2019-05-07 10:19:04 +01:00
Mike Brady dc393b9859 make the formats rate unsigned to avoid a warning. 2019-02-27 19:30:32 +00:00
Mike Brady 1b47023c78 Make a dying error message a bit more meaningful. 2019-02-27 18:45:45 +00:00
Mike Brady 03eb21a946 Check rate when gwtting negotiated sndio parameters back. 2019-02-27 18:27:53 +00:00
Mike Brady 20967812ad Fix a bug in the activity_monitor software that could lock up a player thread so that it couln't be cancelled. If a player was cancelled while performing an activity script, the activity_monitor_mutex would remain locked. 2019-02-26 15:23:11 +00:00
Mike Brady aa5698fce2 Remove the preflight call - don't seem to need it. 2019-01-27 15:53:36 +00:00
Mike Brady caf06c5aba Add the idea of a preflight message to tell the backend that frames will be coming... 2019-01-07 17:34:50 +00:00
Mike Brady 80f15e1f57 clang format 2019-01-04 17:26:55 +00:00
Mike Brady 5e38fcd50f Add default values for the interpolation threshold 2019-01-04 17:06:21 +00:00
Mike Brady 8cabb16f25 Initial very rough attempt at a jackaudio backend. 2018-08-31 12:39:18 +01:00
Mike Brady ea20840d6c Make the play function return a status (ignored for the present). Clean up audio_alsa by removing all the die calls and placing the alsa_mutex calls in pthread cleanup routines. 2018-07-29 13:45:42 +01:00
Mike Brady 3fbd47ad05 Fix minor warnings from some of the backend modules and make the configure messages a little more helpful. 2018-05-18 15:22:20 +01:00
Mike Brady 0cd8a2ce90 Remove more causes of warnings at -Wextra levels 2018-03-07 22:05:11 +00:00
Mike Brady 75b91495a1 Remove a thread lock and unlock from the onmove callback procedure -- it was locking up on Linux 2017-08-13 10:34:38 +01:00
Mike Brady c677ad483e Merging to master branch 3.0rc0 2017-08-03 19:20:58 +02:00
Mike Brady e513e5330c Tidy up source using clang-format 2017-07-31 11:57:57 +02:00
Mike Brady 3a18070698 make sndio formats case-insensitive, fix a little error message 2017-07-29 17:20:58 +02:00
Mike Brady 66929ce344 Update manual and make the sndio format settings conform to the alsa settings 2017-07-29 17:18:11 +02:00
Mike Brady b7864b4ecf Move common audio backend settings like buffer size and offsets to the "general" settings stanza. Improve the resync code a little. 2017-07-21 12:29:03 +02:00
Mike Brady 4d169d7b3b Improve the delay function by estimating the number of frames played during the interval 2017-04-17 17:00:18 +01:00
Mike Brady 67aed3a359 Fix a few crashing bugs if there was no configuration file at all 2017-04-16 22:12:17 +01:00
Mike Brady 2caeeb3581 Fix an error that prevented it from reporting delay correctly. 2017-04-16 18:43:11 +01:00
Mike Brady 225efa127a Improve debug messages a little 2017-04-16 18:40:05 +01:00
Tobias Kortkamp da12c44978 Rewrite and unbreak sndio backend 2017-04-15 02:28:53 +02:00
Mike Brady 0ad34287c3 Stop the "ao", "pulse" and "sndio" backends from complaining about the new output rate and format information. 2017-03-13 19:10:08 +00:00
Mike Brady 4c88f350a6 Stop checking for default rate and depth. Now, simply ignore the rate and depth information. 2017-03-12 16:06:14 +00:00
Mike Brady 064bd293c5 Tidy up with a clang-format 2016-09-11 10:35:53 +01:00
Mike Brady 01e5128507 Add ability to set output format and output rate 2016-08-19 12:51:15 +01:00
Mike Brady 107df039fa Update copyright notice 2016-03-03 15:05:55 +00:00
Mike Brady 4c70223f5a Work in progress, doesn't compile 2015-11-05 18:03:58 +00:00
Mke Brady 87a0475c16 Reformat using clang-format. 2015-06-01 23:16:50 +01:00
Mke Brady 54250f7552 Simplify init function, add defaults for latency offset and buffer size. Remove redundant timer stuff from audio_dummy.c. 2015-06-01 21:38:56 +01:00
Mike Brady df7a046b63 Pass in libconfig info during init. 2015-05-04 17:16:53 +01:00