mirror of
https://github.com/librespot-org/librespot.git
synced 2026-04-27 08:15:50 +03:00
[GH-ISSUE #1195] Unbuffered sinks write packets as they become availible ending track after a few seconds #555
Labels
No labels
A-Alsa
SpotifyAPI
Tokio 1.0
audio
bug
can't reproduce
compilation
dependencies
duplicate
enhancement
good first issue
help wanted
high priority
imported
imported
invalid
new api
pull-request
question
reverse engineering
wiki
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/librespot#555
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @JoeyEamigh on GitHub (Aug 6, 2023).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/1195
Describe the bug
When using a sink that doesn't control the rate at which audio is received such as the
pipesink, packets are written as soon as they are received, causing the song to end after just a few seconds of playback. Same issue occurred withgstreamerwhen piping tofakesink, if that helps.This is a resurfacing of #521.
To reproduce
Steps to reproduce the behavior:
librespotwith '--backend pipe --device /dev/null'Log
The verbose log doesn't help much here, as everything logged is working as it should. I was able to narrow down the issue to this line:
github.com/librespot-org/librespot@f037e46aee/playback/src/player.rs (L1660)By timing the function when using the
alsaorpulseaudiobackend,sink.writetakes about 40ms a packet with default settings, whereas the same function with thepipebackend piping to/dev/nullwill complete the write in about 220μs. Once the packet write is complete, the loop insideimpl Future for PlayerInternalwill restart, immediately starting the process of passing the next packet.Host (what you are running
librespoton):Additional context
Unfortunately, I am slightly out of my depth when it comes to properly timing all of the different types of audio packets that librespot supports, nor do I understand the intricacies of the different audio backends and how they handle buffering and such. Pull request #659 ascribed this to the decoder, which does not seem to be the case because even when using
symphoniapackets are written at the same speed, even if it takes marginally longer to decode them.The throttling could happen in the decoder if determined appropriate, but that may become a bottleneck on lower-end chips. Instead, I am going to explore passing the packet position to the sink's write function and throttling it from there. I will publish my work on a fork, but since I do not know the extend this affects other backends nor why it works with some fifo pipes, I will let y'all point me in the right direction as to how to upstream a comprehensive fix.
This took a lot of debugging to narrow down the issue, so I hope it can help improve this amazing tool!
@kingosticks commented on GitHub (Aug 7, 2023):
This has come up a few times before, I can't find the other examples now. The key point here which you've already mentioned is that this is all working as intended and we've previously not considered this a bug. It's always been up the consumer to block librespot, that's the correct way to use the library.
@JoeyEamigh commented on GitHub (Aug 23, 2023):
Thank you for the response!