mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.2k stars 571 forks source link

Lip Sync Issue with latest Update [Resolved?] #728

Closed rockrabbit closed 3 years ago

rockrabbit commented 6 years ago

Greetings,

Just did a Fresh Pi Stretch Install after I was noticing some issues. Installed Shairport-sync using ALAC like I normally do.

I stream movies from my Mac to my Apple TV 4K and then Airplay the Audio to the PI. Done this for quite sometime without issue, but now there is a noticeable lip sync delay issue.

Not 100 sure if it is Shairport as I also opted to run the latest Beta on my ATV, but the timing seems to lean towards Shairport.

If there is a Fix, Work Around or any suggestion to get the timing back on track, I'd be one very happy camper!

alsa output device name is "hw:1".
Version: "3.2.1-mbedTLS-Avahi-ALSA-convolution-sysconfdir:/etc"
statistics_requester status is 0.
daemon status is 0.
deamon pid file path is "/var/run/shairport-sync/shairport-sync.pid".
rtsp listening port is 5000.
udp base port is 6001.
udp port range is 100.
player name is "PiThree".
backend is "alsa".
on-start action is "(null)".
on-stop action is "(null)".
wait-cmd status is 0.
on-start returns output is 0.
mdns backend "(null)".
stuffing option is "0" (0-basic, 1-soxr).
resync time is 0.050000 seconds.
allow a session to be interrupted: 0.
busy timeout time is 120.
drift tolerance is 0.001995 seconds.
password is "(null)".
ignore_volume_control is 0.
volume_max_db is not set
playback_mode is 0 (0-stereo, 1-mono, 1-reverse_stereo, 2-both_left, 3-both_right).
disable_synchronization is 0.
use_mmap_if_available is 1.
output_rate is 44100.
output_format is 3 (0-unknown, 1-S8, 2-U8, 3-S16, 4-S24, 5-S24_3LE, 6-S24_3BE, 7-S32).
audio backend desired buffer length is 0.150000 seconds.
audio backend latency offset is 0.000000 seconds.
audio backend silence lead-in time is -1.000000 seconds. A value -1.0 means use the default.
volume range in dB (zero means use the range specified by the mixer): 0.
zeroconf regtype is "_raop._tcp".
decoders_supported field is 3.
use_apple_decoder is 1.
alsa_use_hardware_mute is 0.
no special mdns service interface was requested.
configuration file name "/etc/shairport-sync.conf" resolves to "/etc/shairport-sync.conf".
convolution is 0.
convolution IR file is "(null)"
convolution max length 8192
convolution gain is 0.000000
loudness is 0.
loudness reference level is -20.000000
disable resend requests is off.
diagnostic_drop_packet_fraction is 0.000000. A value of 0.0 means no packets will be dropped deliberately.
Unable to listen on IPv4 port 5000. The error is: "Address already in use".
Unable to listen on IPv6 port 5000. The error is: "Address already in use".
fatal error: Could not establish a service on port 5000 -- program terminating. Is another instance of Shairport Sync running on this device?
Request to shut down all rtsp conversation threads
asking playing threads to stop
*** Error in `./shairport-sync': corrupted double-linked list: 0x01b31370 ***
Aborted
mikebrady commented 6 years ago

Thanks for the post! Let me have a look at this. What is the situation: is the audio coming out of Shairport Sync ahead or behind the video? Are you also listening to the audio on the speakers of the TV?

There is something slightly odd in the logs – it looks like Apple ALAC support is enabled, but the version string doesn't include it.

Finally, can you get that *** Error... to occur every time?

rockrabbit commented 6 years ago

rebooted the pi and yes, every time I run ./shairport-sync -v I end up with the tail of ..

disable resend requests is off.
diagnostic_drop_packet_fraction is 0.000000. A value of 0.0 means no packets will be dropped deliberately.
Unable to listen on IPv4 port 5000. The error is: "Address already in use".
Unable to listen on IPv6 port 5000. The error is: "Address already in use".
fatal error: Could not establish a service on port 5000 -- program terminating. Is another instance of Shairport Sync running on this device?
Request to shut down all rtsp conversation threads
asking playing threads to stop
*** Error in ./shairport-sync': corrupted double-linked list: 0x00d88370 ***
Aborted

The player works.. Music, Audio.. its just when Airplay via the ATV 4k that there is a noticeable out of sync issue.

ATV >> PI >> USB to Bryston BDA-1 DAC >> Tube Mono Blocks

Volume is controlled through Apple Remote via ATV

ATV is set for Stereo Audio

● shairport-sync.service - Shairport Sync - AirPlay Audio Receiver
   Loaded: loaded (/lib/systemd/system/shairport-sync.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-08-09 07:01:32 EDT; 6min ago
 Main PID: 493 (shairport-sync)
   CGroup: /system.slice/shairport-sync.service
           └─493 /usr/local/bin/shairport-sync

Aug 09 07:01:32 raspberrypi systemd[1]: Started Shairport Sync - AirPlay Audio Receiver.'

Do you need me to Enable Logs at 2?

rockrabbit commented 6 years ago

Mike,

Thinking this may not be a Shairport Issue, but rather a PLEX issue.

Would still like to know why I'm getting that error though?

mikebrady commented 6 years ago

Thanks. I'm going to try to reproduce the error -- I'd like to know too!

mikebrady commented 6 years ago

Could you just give me the version string of the build you are using, please? The response from:

$ shairport-sync -V

would be great. I want to ensure I'm building the exact same code.

rockrabbit commented 6 years ago

Here is my Textedit File that I keep to setup my Pi Zero and Pi Three:

First get all the tools:

sudo apt-get -y install build-essential git xmltoman autoconf automake libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev avahi-daemon libavahi-client-dev libmbedtls-dev libsndfile1-dev

Next setup the PhatDAC on the PiZero:

curl -sS get.pimoroni.com/phatdac | bash

Now install ALAC:

git clone https://github.com/mikebrady/alac.git

cd alac

sudo autoreconf -fi

sudo ./configure

sudo make

sudo make install

sudo ldconfig -v

cd

Finally install Shairport-Sync:

sudo git clone https://github.com/mikebrady/shairport-sync.git

cd shairport-sync

sudo autoreconf -fi 

sudo ./configure --with-alsa --with-avahi --with-systemd --with-apple-alac --sysconfdir=/etc --with-ssl=mbedtls --with-convolution

sudo make

sudo make install

sudo systemctl enable shairport-sync

sudo nano /etc/shairport-sync.conf

edit areas:

Name = PiZero  PiThree
output_backend = alsa
alac_decoder = apple
output_device = “hw:1” <— BDA-1 USB DAC
output_device = “hw:0” <— PHAT DAC
output_rate = 176400 <— PHAT DAC
output_format = “S32” <— PHAT DAC

sudo reboot

—————————————————————————————————

Upgrade Shairport

cd shairport-sync

sudo git pull

sudo autoreconf -fi

sudo ./configure --with-alsa --with-avahi --with-systemd --with-apple-alac --sysconfdir=/etc --with-ssl=mbedtls --with-convolution

sudo make

sudo make install

sudo systemctl daemon-reload

sudo systemctl restart shairport-sync

Shairport Debugging

sudo systemctl status shairport-sync

sudo git checkout development

sudo git checkout master
rockrabbit commented 6 years ago

Version String:

Version: "3.2.1-mbedTLS-Avahi-ALSA-convolution-sysconfdir:/etc"

mikebrady commented 6 years ago

Thanks for all that. This is what I'm getting; no crash, I'm afraid:

pi@raspberrypi:~/shairport-sync $ ./shairport-sync -v 
alsa output device name is "hw:2".
Version: "3.2.1-mbedTLS-Avahi-ALSA-convolution-sysconfdir:/etc"
statistics_requester status is 0.
daemon status is 0.
deamon pid file path is "/var/run/shairport-sync/shairport-sync.pid".
rtsp listening port is 5000.
udp base port is 6001.
udp port range is 100.
player name is "Raspberrypi".
backend is "(null)".
on-start action is "(null)".
on-stop action is "(null)".
wait-cmd status is 0.
on-start returns output is 0.
mdns backend "(null)".
stuffing option is "0" (0-basic, 1-soxr).
resync time is 0.050000 seconds.
allow a session to be interrupted: 0.
busy timeout time is 120.
drift tolerance is 0.001995 seconds.
password is "(null)".
ignore_volume_control is 0.
volume_max_db is not set
playback_mode is 0 (0-stereo, 1-mono, 1-reverse_stereo, 2-both_left, 3-both_right).
disable_synchronization is 0.
use_mmap_if_available is 1.
output_rate is 44100.
output_format is 3 (0-unknown, 1-S8, 2-U8, 3-S16, 4-S24, 5-S24_3LE, 6-S24_3BE, 7-S32).
audio backend desired buffer length is 0.150000 seconds.
audio backend latency offset is 0.000000 seconds.
audio backend silence lead-in time is -1.000000 seconds. A value -1.0 means use the default.
volume range in dB (zero means use the range specified by the mixer): 0.
zeroconf regtype is "_raop._tcp".
decoders_supported field is 3.
use_apple_decoder is 1.
alsa_use_hardware_mute is 0.
no special mdns service interface was requested.
configuration file name "/etc/shairport-sync.conf" resolves to "/etc/shairport-sync.conf".
convolution is 0.
convolution IR file is "(null)"
convolution max length 8192
convolution gain is 0.000000
loudness is 0.
loudness reference level is -20.000000
disable resend requests is off.
diagnostic_drop_packet_fraction is 0.000000. A value of 0.0 means no packets will be dropped deliberately.
Unable to listen on IPv4 port 5000. The error is: "Address already in use".
Unable to listen on IPv6 port 5000. The error is: "Address already in use".
fatal error: Could not establish a service on port 5000 -- program terminating. Is another instance of Shairport Sync running on this device?
Request to shut down all rtsp conversation threads
asking playing threads to stop
pi@raspberrypi:~/shairport-sync $

The device hw:2 is a USB DAC. If you can still cause the crash to happen at will, could you try:

 $ gdb --args ./shairport-sync -v

When it pauses at:

Reading symbols from ./shairport-sync...done.
(gdb)

enter run. When it crashes, enter the command bt and let us see the result?

rockrabbit commented 6 years ago
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x769c1824 in __GI_abort () at abort.c:89
#2  0x769faf78 in __libc_message (do_abort=do_abort@entry=2, fmt=<optimized out>) at ../sysdeps/posix/libc_fatal.c:175
#3  0x76a01ad4 in malloc_printerr (action=<optimized out>, str=0x76ab3f04 "corrupted double-linked list", ptr=<optimized out>, 
    ar_ptr=<optimized out>) at malloc.c:5049
#4  0x76a02d28 in _int_free (av=0x76ad0794 <main_arena>, p=0x5b320, have_lock=0) at malloc.c:4052
#5  0x76d355fc in ?? () from /usr/lib/arm-linux-gnueabihf/libconfig.so.9
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
rockrabbit commented 6 years ago

BTW, confirmed the issue with timing re Lip Sync.

I pulled out my old Airport Express and Airplay to it via the ATV is perfect!

mikebrady commented 6 years ago

Thanks for that -- I'll look into it. You mentioned that it might be "a PLEX issue". Could you say what you meant by that?

rockrabbit commented 6 years ago

I use PLEX as my Media Server on my Mac. We can Null the PLEX at this point.. the Sync issue is with Shairport. The Airport Express is Perfect!

mikebrady commented 6 years ago

Thanks again for all this. I may come back to you with another request regarding that bug -- the backtrace is tantalising with the information it contains, but I might need little more. If so, I'll ask, so thanks in advance!

I'll look into the sync issue over the weekend; it'll take a little time to set up a test rig.

mikebrady commented 6 years ago

Okay, so I have set up an Airport Express and a Shairport Sync system and am driving them both from an Apple TV 2 (not a 4K!) and I'm afraid I can't detect any difference in lip-sync -- both are good.

Not sure when I'\ll get an ATK4K -- TBH I'm waiting for the next iteration from Apple....

rockrabbit commented 6 years ago

Raspberry Pi 3 running the latest firmware and always up to date - Tested with Ethernet and Wi-Fi - Lip Sync Lag ATV 4K running the latest TVos Beta - Gigabit Ethernet Airport Express - 802.11n (2nd Generation) - Wi-FI

With AE and ATV4K no issues at all.. Perfect

Source is a Mac Mini Late 2016 running the Latest PLEX Server and using the PLEX app on the ATV

Picked up the ATV 4K New for $100 and sold my ATV 4th Gen for... $100

So if your source is iTunes running DD or PCM.. ok.. PLEX transcodes DTS on the Fly to either DD or PCM. Source files are almost always MKV.

I have the ATV 4K set to output PCM (Stereo) as that is my setup.. 2.0!

Honestly, with its Airport Express now snugly sitting behind the gear doing the Audio for iTunes and PLEX as PCM... happy days!

Kinda in the attitude to retire the Pi from this duty and just leave the Pi Zero doing it's great job of being my secondary bathroom rig!

Feel free to close this thread unless you suddenly want me to load different software versions of Shairport and be Testing to see if anything gets resolved.

Cannot thank you enough for your hard work!

mikebrady commented 6 years ago

Thanks for the encouragement! When I have an ATV4K or similar, I'll return to this. There are reports of lip-sync issues with Plex, not related to Shairport Sync. It's hard to see how these might relate to your issue, if at all, but maybe worth a look.

Meanwhile, the bug. The diagnostic you reported indicated that the problem is associated with reading the configuration file. More specifically it seems that Shairport Sync is incorrectly releasing a configuration string twice before it terminates. Unfortunately, some of the information in the backtrace has been removed because the compiler did too much optimisation to allow the debugger to recover the entire scenario. So, I wonder if you would rebuild Shairport Sync but with compiler options set to be more suitable for a debugger. If you look at your list of steps to "Upgrade Shairport" above, do everything again, but replace the line that reads:

sudo ./configure --with-alsa --with-avahi --with-systemd --with-apple-alac --sysconfdir=/etc --with-ssl=mbedtls --with-convolution

with

sudo ./configure --with-alsa --with-avahi --with-systemd --with-apple-alac --sysconfdir=/etc --with-ssl=mbedtls --with-convolution CFLAGS="-g -Og"

That is, use exactly the same line but add in CFLAGS="-g -Og". This will give the debugger gdb the best chance to decipher the backtrace completely. If you could do this and rerun the gdb session up to and including the backtrace bt command and post the result, it would be great.

mikebrady commented 5 years ago

Just circling back to this, we did identify a lip-sync issue moving up to iOS 12 and mac OS Mojave which is fixed in 3.2.2. Maybe that was part of the issue.

github-actions[bot] commented 3 years ago

This issue has been inactive for 60 days so will be closed 7 days from now. To prevent this, please remove the "stale" label or post a comment.