mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.19k stars 570 forks source link

[Problem]: Can't use shairport-sync with pulse audio and on other devices NOT PLAYING showing "Connecting..." forever #1596

Closed deeeemiss closed 1 year ago

deeeemiss commented 1 year ago

What happened?

I have two problems: the first one is that I can't connect Shairport-Sync to PulseAudio, it shows me this error when I try to launch the service with the audio_backend on "pa":

fatal error: Invalid audio backend "pa" selected!

The configuration file is below (general and pa).

The command shairport-sync -h shows me this: Available mDNS backends: avahi Available audio backends: alsa (default) and nothing more (about audio backends).

The second problem I have is that if I play a song with my iPhone on shairport-sync, if I go on my iPad to control music it shows me "Connecting..." and doesn't work, how can I solve that?

Relevant log output

// General Settings
general =
{
        name = "Echo Input - Soggiorno"; // This means "Hostname" -- see below. This is the name the service will advertise to iTunes.
//              The default is "Hostname" -- i.e. the machine's hostname with the first letter capitalised (ASCII only.)
//              You can use the following substitutions:
//                              %h for the hostname,
//                              %H for the Hostname (i.e. with first letter capitalised (ASCII only)),
//                              %v for the version number, e.g. 3.0 and
//                              %V for the full version string, e.g. 3.3-OpenSSL-Avahi-ALSA-soxr-metadata-sysconfdir:/etc
//              Overall length can not exceed 50 characters. Example: "Shairport Sync %v on %H".
//      password = "secret"; // (AirPlay 1 only) leave this commented out if you don't want to require a password
//      interpolation = "auto"; // aka "stuffing". Default is "auto". Alternatives are "basic" or "soxr". Choose "soxr" only if you have a reasonably fast processor and Shairport Sync has been built with>
//      output_backend = "pa"; // Run "shairport-sync -h" to get a list of all output_backends, e.g. "alsa", "pipe", "stdout". The default is the first one.
//      mdns_backend = "avahi"; // Run "shairport-sync -h" to get a list of all mdns_backends. The default is the first one.
//      interface = "name"; // Use this advanced setting to specify the interface on which Shairport Sync should provide its service. Leave it commented out to get the default, which is to select the int>
//      port = <number>; // Listen for service requests on this port. 5000 for AirPlay 1, 7000 for AirPlay 2
//      udp_port_base = 6001; // (AirPlay 1 only) start allocating UDP ports from this port number when needed
//      udp_port_range = 10; // (AirPlay 1 only) look for free ports in this number of places, starting at the UDP port base. Allow at least 10, though only three are needed in a steady state.
//      airplay_device_id_offset = 0; // (AirPlay 2 only) add this to the default airplay_device_id calculated from one of the device's MAC address
//      airplay_device_id = 0x<six-digit_hexadecimal_number>L; // (AirPlay 2 only) use this as the airplay_device_id e.g. 0xDCA632D4E8F3L -- remember the "L" at the end as it's a 64-bit quantity!
//      regtype = "<string>"; // Use this advanced setting to set the service type and transport to be advertised by Zeroconf/Bonjour. Default is "_raop._tcp" for AirPlay 1, "_airplay._tcp" for AirPlay 2.

//      drift_tolerance_in_seconds = 0.002; // allow a timing error of this number of seconds of drift away from exact synchronisation before attempting to correct it
//      resync_threshold_in_seconds = 0.050; // a synchronisation error greater than this number of seconds will cause resynchronisation; 0 disables it

//      playback_mode = "stereo"; // This can be "stereo", "mono", "reverse stereo", "both left" or "both right". Default is "stereo".
//      alac_decoder = "hammerton"; // This can be "hammerton" or "apple". This advanced setting allows you to choose
//              the original Shairport decoder by David Hammerton or the Apple Lossless Audio Codec (ALAC) decoder written by Apple.
//              If you build Shairport Sync with the flag --with-apple-alac, the Apple ALAC decoder will be chosen by default.

        ignore_volume_control = "yes"; // set this to "yes" if you want the volume to be at 100% no matter what the source's volume control is set to.
//      volume_range_db = 60 ; // use this advanced setting to set the range, in dB, you want between the maximum volume and the minimum volume. Range is 30 to 150 dB. Leave it commented out to use mixer>
//      volume_max_db = 0.0 ; // use this advanced setting, which must have a decimal point in it, to set the maximum volume, in dB, you wish to use.
//              The setting is for the hardware mixer, if chosen, or the software mixer otherwise. The value must be in the mixer's range (0.0 to -96.2 for the software mixer).
//              Leave it commented out to use mixer's maximum volume.
//      volume_control_profile = "standard" ; // use this advanced setting to specify how the airplay volume is transferred to the mixer volume.
//              "standard" makes the volume change more quickly at lower volumes and slower at higher volumes.
//              "flat" makes the volume change at the same rate at all volumes.
//      volume_control_combined_hardware_priority = "no"; // when extending the volume range by combining the built-in software attenuator with the hardware mixer attenuator, set this to "yes" to reduce >
//      run_this_when_volume_is_set = "/full/path/to/application/and/args"; //  Run the specified application whenever the volume control is set or changed.
//              The desired AirPlay volume is appended to the end of the command line – leave a space if you want it treated as an extra argument.
//              AirPlay volume goes from 0 to -30 and -144 means "mute".

//      audio_backend_latency_offset_in_seconds = 0.0; // This is added to the latency requested by the player to delay or advance the output by a fixed amount.
//              Use it, for example, to compensate for a fixed delay in the audio back end.
E.g. if the output device, e.g. a soundbar, takes 100 ms to process audio, set this to -0.1 to deliver the audio
//              to the output device 100 ms early, allowing it time to process the audio and output it perfectly in sync.
//      audio_backend_buffer_desired_length_in_seconds = 0.2; // If set too small, buffer underflow occurs on low-powered machines.
//              Too long and the response time to volume changes becomes annoying.
//              Default is 0.2 seconds in the alsa backend, 0.35 seconds in the pa backend and 1.0 seconds otherwise.
//      audio_backend_buffer_interpolation_threshold_in_seconds = 0.075; // Advanced feature. If the buffer size drops below this, stop using time-consuming interpolation like soxr to avoid dropouts due >
//      audio_backend_silent_lead_in_time = "auto"; // This optional advanced setting, either "auto" or a positive number, sets the length of the period of silence that precedes the start of the audio.
//              The default is "auto" -- the silent lead-in starts as soon as the player starts sending packets.
//              Values greater than the latency are ignored. Values that are too low will affect initial synchronisation.

//      dbus_service_bus = "system"; // The Shairport Sync dbus interface, if selected at compilation, will appear
//              as "org.gnome.ShairportSync" on the whichever bus you specify here: "system" (default) or "session".
//      mpris_service_bus = "system"; // The Shairport Sync mpris interface, if selected at compilation, will appear
//              as "org.gnome.ShairportSync" on the whichever bus you specify here: "system" (default) or "session".

//      resend_control_first_check_time = 0.10; // Use this optional advanced setting to set the wait time in seconds before deciding a packet is missing.
//      resend_control_check_interval_time = 0.25; //  Use this optional advanced setting to set the time in seconds between requests for a missing packet.
//      resend_control_last_check_time = 0.10; // Use this optional advanced setting to set the latest time, in seconds, by which the last check should be done before the estimated time of a missing pack>
//      missing_port_dacp_scan_interval_seconds = 2.0; // Use this optional advanced setting to set the time interval between scans for a DACP port number if no port number has been provided by the playe>
};

// Parameters for the "pa" PulseAudio  backend.
// For this section to be operative, Shairport Sync must be built with the following configuration flag:
// --with-pa
pa =
{
        server = "host"; // Set this to override the default pulseaudio server that should be used.
        sink = "Sink Name"; // Set this to override the default pulseaudio sink that should be used. (Untested)
        application_name = "Shairport Sync"; //Set this to the name that should appear in the Sounds "Applications" tab when Shairport Sync is active.
};

Configuration Information.

Display Config Start.

From "uname -a": Linux raspberrypi 5.15.76-v7l+ #1597 SMP Fri Nov 4 12:14:58 GMT 2022 armv7l GNU/Linux

From /etc/os-release: Raspbian GNU/Linux 11 (bullseye)

From /sys/firmware/devicetree/base/model: Raspberry Pi 4 Model B Rev 1.4

Shairport Sync Version String: 4.1.1-2-g6240fd83-AirPlay2-OpenSSL-Avahi-ALSA-soxr-sysconfdir:/etc

Command Line: shairport-sync --displayConfig

Configuration File: /etc/shairport-sync.conf

Configuration File Settings: general : { name = "Echo Input - Soggiorno"; ignore_volume_control = "yes"; }; pa : { server = "host"; sink = "Sink Name"; application_name = "Shairport Sync"; };

Display Config End. Goodbye!

How did you install Shairport Sync?

Built from source

Check previous issues

mikebrady commented 1 year ago

Thanks for the post. Referring to the two issues you mention,

  1. To use Shairport Sync with PulseAudio, you need to build in the pa backend. To do this, at the ./configure... step, add in the flag --with-pa. You may need to add in a library too; if so, the error message will suggest it.

  2. Shairport Sync, unfortunately, does not support the remote control protocols necessary to do this. This is because the protocols have not been published. AFAIK they have not yet been figured out.

deeeemiss commented 1 year ago

Ok thanks for the reply; regard the first problem I already used the flag --with-pa but later in the process, so after I've installed it and be sure that it works I redo the ./configure command with the flag but nothing changes. Maybe I have to reinstall everything from the start? For the second problem it doesn't matter (I found that older devices e.g. iPhone 5s with the latest iOS available the remote works, but with an iPhone Xr with iOS 16.2 it doesn't works, maybe this can be helpful for you).

Thanks again Mike!

mikebrady commented 1 year ago

Thanks. Regarding the first problem, the sequence should be something like this, just adding in the --with-pa and adding a $ make clean for luck:

$ git clone https://github.com/mikebrady/shairport-sync.git
$ cd shairport-sync
$ autoreconf -fi
$ ./configure --sysconfdir=/etc --with-alsa \
    --with-soxr --with-avahi --with-ssl=openssl --with-systemd --with-airplay-2 --with-pa
$ make clean
$ make
# make install
deeeemiss commented 1 year ago

Ok, I've done everything with make clean and it worked (in shairport-sync -h it shows in available audio backends that was added "pa"), but now there's another problem, when I try to start shairport-sync it shows me this (in the configuration file I've uncommented the line that enable pa audio backend): fatal error: pa context is not good -- the error message "Connection refused".

mikebrady commented 1 year ago

Thanks. So, if you stop the Shairport Sync service:

$ sudo systemctl stop shairport-sync

and start it from the command line:

$ shairport-sync -v

does it work then?

Also, could you post the output from $ shairport-sync --displayConfig again, please?

deeeemiss commented 1 year ago

I've tried to stop the service and restart it with shairport-sync -v but it doesn't work anyway, here's the output:

0.001991611 "shairport.c:2200" Startup in AirPlay 2 mode, with features 0x405c4a00,0x1c340 on device "e4:5f:01:03:22:18".
         0.000122796 "shairport.c:2239" Version String: "4.1.1-2-g6240fd83-AirPlay2-OpenSSL-Avahi-ALSA-pa-soxr-sysconfdir:/etc"
         0.000033778 "shairport.c:2258" Command Line: "shairport-sync -v".
         0.000114111 "shairport.c:2265" libsodium initialised.
         0.000387908 "shairport.c:2290" libgcrypt initialised.
         0.000036666 "shairport.c:2294" Log Verbosity is 1.
         0.106578963 "audio_pa.c:143" *fatal error: pa context is not good -- the error message "Connection refused".
         0.000047926 "shairport.c:1677" emergency exit

shairport-sync --displayConfig output is this:

>> Display Config Start.

From "uname -a":
 Linux raspberrypi 5.15.76-v7l+ #1597 SMP Fri Nov 4 12:14:58 GMT 2022 armv7l GNU/Linux

From /etc/os-release:
 Raspbian GNU/Linux 11 (bullseye)

From /sys/firmware/devicetree/base/model:
 Raspberry Pi 4 Model B Rev 1.4

Shairport Sync Version String:
 4.1.1-2-g6240fd83-AirPlay2-OpenSSL-Avahi-ALSA-pa-soxr-sysconfdir:/etc

Command Line:
 shairport-sync --displayConfig

Configuration File:
 /etc/shairport-sync.conf

Configuration File Settings:
 general : 
 {
   name = "Echo Input - Soggiorno";
   output_backend = "pa";
   ignore_volume_control = "yes";
 };
 pa : 
 {
   server = "host";
   sink = "Sink Name";
   application_name = "Shairport Sync";
 };

>> Display Config End.
>> Goodbye!
mikebrady commented 1 year ago

Thanks. (I edited the comment a little for layout.) Let me suggest that you comment out all the pa settings and see whether that works from the command line.

deeeemiss commented 1 year ago

Ok, that worked for a little bit but with no audio; so I tried to find a solution because I was thinking it was the bluetooth PulseAudio Service, but it works well and nothing is wrong. Then I noticed that shairport-sync no more start on boot and when I do the command sudo systemctl status shairport-sync this is the output:

shairport-sync.service - Shairport Sync - AirPlay Audio Receiver
     Loaded: loaded (/lib/systemd/system/shairport-sync.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2022-12-21 11:49:06 CET; 14min ago
   Main PID: 675 (code=exited, status=1/FAILURE)
        CPU: 154ms

Dec 21 11:49:04 raspberrypi systemd[1]: Started Shairport Sync - AirPlay Audio Receiver.
Dec 21 11:49:06 raspberrypi shairport-sync[675]: Failed to create secure directory (/home/shairport-sync/.config/pulse): No such file or directory
Dec 21 11:49:06 raspberrypi shairport-sync[675]: fatal error: failed to connect to the pulseaudio context -- the error message is "Connection refused".
Dec 21 11:49:06 raspberrypi systemd[1]: shairport-sync.service: Main process exited, code=exited, status=1/FAILURE
Dec 21 11:49:06 raspberrypi systemd[1]: shairport-sync.service: Failed with result 'exit-code'.

I was thinking that maybe the fact that has no volume is a bit related to this problem.

PS: when I start it normal with shairport-sync -v it works but always without audio.

Sorry also for the layout of the code in the past comment but I didn't know how to edit in that way.

mikebrady commented 1 year ago

Thanks for the update.

Ok, that worked for a little bit but with no audio...

It would be worth continuing to play with that a little, so try to get audio out of it. What should be happening is that the audio should be routed to the default audio device, which will be an alsa "pseudo-device" that routes the audio into the PulseAudio system. The nqptp daemon should be installed and running, and the firewall should allow ports 319 and 320 to pass UDP traffic.

If you do:

$ shairport-sync -v --statistics

you'll see something a bit like this if audio is coming through to Shairport Sync:

         0.039848021 "rtsp.c:4335" Connection 1: Current volume (-24.000000) requested
         5.342425102 "rtsp.c:3299" Connection 1. AP2 Buffered Audio Stream.
         0.578427968 "player.c:2774" Connection 1: Playback started at frame 3576207123 -- AirPlay 2 Buffered.
         7.933596508 "player.c:2591" Sync Error ms | Net Sync PPM | All Sync PPM | Min DAC Queue | Min Buffers | Min Buffer Size | Output FPS (r) | Output FPS (c)
         0.000196198 "player.c:2591"          1.66            0.0            0.0            7386            46              230k              N/A              N/A
         7.999195726 "player.c:2591"          0.72            0.0            0.0            7458            46             3214k         44100.00         44100.15
         7.991056507 "player.c:2591"          1.11            0.0            0.0            7458            46             3269k         44100.12         44100.27
         8.004760257 "player.c:2591"          0.79            0.0            0.0            7462            46             3218k         44100.16         44100.32
         8.015777237 "player.c:2591"          0.54            0.0            0.0            7434            46             3224k         44100.14         44100.29
         8.000669997 "player.c:2591"          1.04            0.0            0.0            7450            46             3236k         44100.09         44100.24

The exact items on each likes will be different, but each line at an interval of about eight seconds indicates that Shairport Sync is receiving and processing audio.

Then I noticed that shairport-sync no more start on boot...

This is because the PulseAudio service is not a "system service"; it's a "user service", which means that it is not available until the user has logged in. Generally, the user has to have logged in through the GUI.

deeeemiss commented 1 year ago

Ok thank you for your replies, in these days I've tried to fix the issues I was having; the issue "no audio" I was having, was fixed by a full fresh install of shairport-sync, because I've done the shairport-sync -v --statistics before the re-installlation and find out shairport-sync was receiving the audio. The other issue was the bluetooth and I've fixed in a rough way; I didn't use the bluetooth inside the raspberry because for some reasons it didn't worked (and I've tried a lot of times), instead I've bought a bluetooth transmitter on Amazon and connected to the Raspberry, now it works like a charm.

Thank you so much for your availability, wish you the best.

0d0a commented 1 year ago

I created a user service and a timer My shairport-sync conf has all pa references remmed out as MikeBrady suggested. my user system file and user timer files : shairport-sync.service.docx shairport-sync.timer.docx Files should be placed in ~/config/systemd/user/ and the servicefile must be disabled. It will be enabled after boot and when user has loggged in by the shairport-sync.timer (OnBootSec=1min)

samleemc commented 3 months ago

I created a user service and a timer My shairport-sync conf has all pa references remmed out as MikeBrady suggested. my user system file and user timer files : shairport-sync.service.docx shairport-sync.timer.docx Files should be placed in ~/config/systemd/user/ and the servicefile must be disabled. It will be enabled after boot and when user has loggged in by the shairport-sync.timer (OnBootSec=1min)

do you mind to explain a bit more how the timer is related to the service file? and how to disable the service file?