FDH2 / UxPlay

AirPlay Unix mirroring server
GNU General Public License v3.0
1.34k stars 72 forks source link

2 sec stuttering at the start of stream - buffering issue? #221

Closed geekmiki closed 9 months ago

geekmiki commented 9 months ago

Hi, There is a 2 sec stuttering when starting a stream, independently of the service/app I am using (Apple Music, Spotify, direct link to mp3 stream), as if there was buffering. It is inconsistent, happens maybe 10 times in a row and then once every 3 tracks. Is there a way to define a buffer level before starting to play in order to mitigate the issue?

Thanks.

fduncanh commented 9 months ago

please give more details of your system (e.g. desktop or r Pi etc) operating system and so on.

geekmiki commented 9 months ago

Thanks for your reply. I'm running Arch Linux on a laptop (Ryzen 7 5800H, 32GB RAM). The audio server is Pipewire. Is there anything else you need?

fduncanh commented 9 months ago

apple music is availble here for testing. please name a specific music track to listen to that you hear this on.

geekmiki commented 9 months ago

I don't think it's related to a particular song, it happens with any song I play. You could try "TM NETWORK - Get wild", I just played it (lossless quality) and it stuttered/distorted when it started.

I tried shairplay and the stutter is not there.

fduncanh commented 9 months ago

@geekmiki

Yes I hear it. (using TM NETWORK - Get Wild) and compared it with shairplay which doesn't have it.

When I use the timestamp-based synchronization option "uxplay -async" which synchronizes ALAC lossless audio with video on the iOS device (for example to keep the audio in sync with lyrics text showing on the iOS device) its not there.

The drawback of using -async option is that the iOS client delays its own video for a few seconds (I did not find a way to tell the client not to use such a long delay, which may be because it is not receiving/understanding the latency info sent by UxPlay) so there is a delay between making a pause or track-change request on the iOS device, and hearing it happen in the (delayed) audio stream.

with the default " uxplay -async no" option (equivalent to just "uxplay" with no options) , gstreamer just plays what arrives when it arrives, using a clock based on the 44.1 kHz encoding. The artifact may be due to initializing or some buffer issue.

shairplay does not have the delay. I'll look at the shairplay code to see if its doing something that uxplay has missed to communicate latency info to the iOS client.

Originally uxplay was derived from shairplay derivatives which had stripped out the ALAC loss-free music feature and replaced it with screen mirror video with AAC audio. The audio-only mode was restored many authors later: (shairplay -> AirPlay server -> rpiplay ->uxplay) in uxplay v 1.39.

fduncanh commented 9 months ago

https://stackoverflow.com/questions/9997882/detecting-the-airplay-latency

geekmiki commented 9 months ago

All good, -async does solve the issue. Thanks for your support and the great work done on UxPlay.

fduncanh commented 9 months ago

Based on your input, it might be best to make -async the default for ALAC audio mode, and let the user use "-async no" if they want to switch it off.