mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.3k stars 574 forks source link

[Problem]: Audio Out of Sync When Streaming To Multiple Airplay2 Instances #1622

Closed YutongGu closed 1 year ago

YutongGu commented 1 year ago

What happened?

While experimenting with playing to multiple AirPlay 2 instances, I occasionally encounter a problem where one of the streams become out of sync with the others by a small amount of time (about a second). About 50% of the time, pausing and then resuming the audio playback will fix the issue. This happens when streaming to a shairport-sync Airplay2 instance and a non-shairport-sync Airplay2 instance.

I've been able to reproduce it by connecting to a second Airplay2 instance after already streaming to another Airplay2 instance. Things seem to start in sync if I were to first connect to each individual Airplay2 instance first and then start the stream.

Shairport-sync githash: ceb3331bd0b5bc5ae44c9e0a95bc1f1ffadcb627

Relevant log output

No response

Configuration Information.

Linux jukeaudio 4.14.114-v7 https://github.com/mikebrady/shairport-sync/issues/1 SMP Tue Jul 30 13:37:58 UTC 2019 armv7l armv7l armv7l GNU/Linux 5.3.9-OpenSSL-Avahi-ALSA-stdout-pipe-metadata-sysconfdir:/etc

How did you install Shairport Sync?

Built from source

Check previous issues

mikebrady commented 1 year ago

Thanks for the post. Could you update Shairport Sync to the latest version, please? In fact, it would be good to be on the development branch of both Shairport Sync itself and NQPTP.

dasl- commented 1 year ago

I had a similar issue that may have been specific to using shairport-sync on raspberry pi hardware. I wonder if that applies to your use case, or if my fix would help in your use case? https://github.com/mikebrady/shairport-sync/issues/1563#issuecomment-1328166125

YutongGu commented 1 year ago

Thanks for the post. Could you update Shairport Sync to the latest version, please? In fact, it would be good to be on the development branch of both Shairport Sync itself and NQPTP.

I would do that but I need the old commit where NQPTP was able to support multiple Shairport-Sync instances on a single device. For testing purposes, I suppose I can update to the latest.

Also, I'm using the pipe option instead of alsa for outputting audio so I don't think @dasl-'s fix applies here unfortunately.

YutongGu commented 1 year ago

@mikebrady I just tested the latest nqptp and and shairport sync and it doesn't seem to be an issue. However, i would prefer not to move onto the latest until NQPTP supports multiple clients again. Is there a commit that I can backport that will fix this issue for me?

mikebrady commented 1 year ago

Thanks for the update. Unfortunately, there are no plans to update NQPTP to multiple users at this time. Backporting the fixes would be a major effort, I’m afraid — the improvements occurred over quite a few updates.

YutongGu commented 1 year ago

Thanks for the feedback. I think it would be a major improvement to not have to run docker if I want multiple instances of Airplay2 on a single device.

I reviewed the changes from the commit that removed the support of multiple users on NQPTP and was able to revert the relevant portions to get it to work. I've tested it out and it appears work as I expect. I went ahead and created a PR for these changes which you can review here:

https://github.com/mikebrady/nqptp/pull/19

Some additional changes had to be propogated to Shairport Sync which I've also made a PR for:

https://github.com/mikebrady/shairport-sync/pull/1655

YutongGu commented 1 year ago

After doing some more testing I'm finding that I'm still occasionally getting out of sync audio when disconnecting and reconnecting from shairport-sync airplay2 instances.

Separately, I'm also experiencing an issue with slowly drifting out of sync after a while with an official Airplay2 device such as Homepod or an Airplay2-enabled TV.

github-actions[bot] commented 1 year ago

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

mikebrady commented 1 year ago

Hi there. I'm afraid I have not been able to reproduce this problem, but FYI, here have been changes and improvements to NQPTP in the latest release, 4.2 and 4.2.1.

YutongGu commented 1 year ago

Hi @mikebrady. I've figured out the cause. It was because I had enabled writing metadata to a named pipe with no reader attached on the other end. This was somehow causing the streams to go out of sync. I was also not rate limiting the speed at which I was reading the audio buffer that precedes each audio stream and that was causing things to go out of sync as well.

With these issues identified and resolved, I am getting solid synchronization with my method of running multiple instances of Airplay2 mentioned in this thread.