[GH-ISSUE #373] sluggish reaction to user input on Libreelec Kodi #249

Closed
opened 2026-02-27 19:29:38 +03:00 by kerem · 9 comments
Owner

Originally created by @dfrieling on GitHub (Sep 22, 2019).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/373

I am using librespot (version 2019-07-23) with libreelec (9.1.501) on Kodi with Raspberry pi 4. It works OK but has quite a sluggish reaction to user input on the remote control (smartphone): when pressing pause or changing the volume it takes at least 2 seconds to reflect.
I've been using librespot for years and it didn't have this delay. I believe it was introduced when switching to use Kodi as audio playback device. When using ALSA it was fine. But I could be mistaking and actually the delay is caused by another change.

Checking in kodi's log I see it takes approx. 1 sec to see this message in the log
NOTICE: Librespot: pausing librespot playback
and another 1 sec to actually pause the playback

Any ideas how to debug the problem?

Originally created by @dfrieling on GitHub (Sep 22, 2019). Original GitHub issue: https://github.com/librespot-org/librespot/issues/373 I am using librespot (version 2019-07-23) with libreelec (9.1.501) on Kodi with Raspberry pi 4. It works OK but has quite a sluggish reaction to user input on the remote control (smartphone): when pressing pause or changing the volume it takes at least 2 seconds to reflect. I've been using librespot for years and it didn't have this delay. I believe it was introduced when switching to use Kodi as audio playback device. When using ALSA it was fine. But I could be mistaking and actually the delay is caused by another change. Checking in kodi's log I see it takes approx. 1 sec to see this message in the log ` NOTICE: Librespot: pausing librespot playback` and another 1 sec to actually pause the playback Any ideas how to debug the problem?
kerem 2026-02-27 19:29:38 +03:00
  • closed this issue
  • added the
    audio
    wiki
    labels
Author
Owner

@willstott101 commented on GitHub (Sep 22, 2019):

That first delay is unavoidable, the second is probably due to audio buffer size.
Do you know which audio backend you're using?

<!-- gh-comment-id:533874717 --> @willstott101 commented on GitHub (Sep 22, 2019): That first delay is unavoidable, the second is probably due to audio buffer size. Do you know which audio backend you're using?
Author
Owner

@willstott101 commented on GitHub (Sep 22, 2019):

Sorry, I misread that, is kodi receiving the audio via the pipe output?

<!-- gh-comment-id:533874754 --> @willstott101 commented on GitHub (Sep 22, 2019): Sorry, I misread that, is kodi receiving the audio via the pipe output?
Author
Owner

@devgianlu commented on GitHub (Sep 22, 2019):

Probably something similar to https://github.com/librespot-org/librespot-java/pull/120#issuecomment-519194594, the pipe size may be the issue as I discovered: https://github.com/librespot-org/librespot-java/issues/121#issuecomment-522345917

<!-- gh-comment-id:533875440 --> @devgianlu commented on GitHub (Sep 22, 2019): Probably something similar to https://github.com/librespot-org/librespot-java/pull/120#issuecomment-519194594, the pipe size may be the issue as I discovered: https://github.com/librespot-org/librespot-java/issues/121#issuecomment-522345917
Author
Owner

@dfrieling commented on GitHub (Sep 22, 2019):

The Kodi addon runs librespot with the following params:
librespot --backend pulseaudio --bitrate 320 --cache /storage/.kodi/userdata/addon_data/service.librespot/cache --device-type TV --disable-audio-cache --name Kodi (LibreELEC) --notify-kodi

<!-- gh-comment-id:533876227 --> @dfrieling commented on GitHub (Sep 22, 2019): The Kodi addon runs librespot with the following params: ` librespot --backend pulseaudio --bitrate 320 --cache /storage/.kodi/userdata/addon_data/service.librespot/cache --device-type TV --disable-audio-cache --name Kodi (LibreELEC) --notify-kodi`
Author
Owner

@dfrieling commented on GitHub (Sep 22, 2019):

pipe size is 1048576, executed on the RPi4:

cat /proc/sys/fs/pipe-max-size 1048576

<!-- gh-comment-id:533876307 --> @dfrieling commented on GitHub (Sep 22, 2019): pipe size is 1048576, executed on the RPi4: ` cat /proc/sys/fs/pipe-max-size 1048576`
Author
Owner

@devgianlu commented on GitHub (Sep 22, 2019):

pipe size is 1048576, executed on the RPi4:

cat /proc/sys/fs/pipe-max-size 1048576

You're not using "pipe" so this has nothing to do with it. Must be some other issue.

<!-- gh-comment-id:533876453 --> @devgianlu commented on GitHub (Sep 22, 2019): > pipe size is 1048576, executed on the RPi4: > > ` cat /proc/sys/fs/pipe-max-size 1048576` You're not using "pipe" so this has nothing to do with it. Must be some other issue.
Author
Owner

@dfrieling commented on GitHub (Sep 25, 2019):

just compiled the current HEAD for Rpi with alsa support using master/contrib/Dockerfile.Rpi, with that it works with a delay of <0.5 sec. Very much looks like using pulseaudio + kodi is the problem.

@awiouy would be happy to have your thoughts on this - is a delay of ~2sec expected when using librespot with libreelec kodi+pulseaudio or did you manage to get it to react instantaneously?

<!-- gh-comment-id:535170168 --> @dfrieling commented on GitHub (Sep 25, 2019): just compiled the current HEAD for Rpi with **alsa support** using `master/contrib/Dockerfile.Rpi`, with that it works with a delay of <0.5 sec. Very much looks like using pulseaudio + kodi is the problem. @awiouy would be happy to have your thoughts on this - is a delay of ~2sec expected when using librespot with libreelec kodi+pulseaudio or did you manage to get it to react instantaneously?
Author
Owner

@willstott101 commented on GitHub (Sep 26, 2019):

Here we explicitly use PA's default buffer setup.
https://github.com/librespot-org/librespot/blob/master/playback/src/audio_backend/pulseaudio.rs#L90

According to this page that can usually be up to 2s
https://freedesktop.org/software/pulseaudio/doxygen/structpa__buffer__attr.html#abef20d3a6cab53f716846125353e56a4

Changing the volume will always be that slow unless the buffer size is reduced. However skipping/pausing we could conceivably drain the buffer to respond faster.

<!-- gh-comment-id:535465839 --> @willstott101 commented on GitHub (Sep 26, 2019): Here we explicitly use PA's default buffer setup. https://github.com/librespot-org/librespot/blob/master/playback/src/audio_backend/pulseaudio.rs#L90 According to this page that can usually be up to 2s https://freedesktop.org/software/pulseaudio/doxygen/structpa__buffer__attr.html#abef20d3a6cab53f716846125353e56a4 Changing the volume will always be that slow unless the buffer size is reduced. However skipping/pausing we could conceivably drain the buffer to respond faster.
Author
Owner

@rpardini commented on GitHub (Dec 25, 2020):

It seems like CoreELEC/LibreELEC Kodi "librespot" Kodi plugin uses librespot in an interesting way.

Kodi itself holds the ALSA output device, starts an RTP listener on port 24642, setups PulseAudio to output to Null, forwards Null via RTP back to Kodi, and starts librespot outputting to pulseaudio. The whole thing adds 3000ms or more latency to my setup.

But, it does allow unified device setup in Kodi and lyrics/visualizations of the sound stream produced by librespot in Kodi (!) in a way that "just works", albeit with some sluggishness.

Lowering buffer sizes all-around that chain uses CPU a lot and does not make things much better.

For people bothered by this: switch Kodi to use PulseAudio, make PulseAudio output to ALSA device. Kodi and Kodi/librespot still works sluggish, but you can run a second/separate instance of librespot that outputs directly to Pulse->ALSA with minimal lag, but no Kodi integration.

<!-- gh-comment-id:751249344 --> @rpardini commented on GitHub (Dec 25, 2020): It seems like CoreELEC/LibreELEC Kodi "librespot" Kodi plugin uses librespot in an interesting way. Kodi itself holds the ALSA output device, starts an RTP listener on port 24642, setups PulseAudio to output to Null, forwards Null via RTP back to Kodi, and starts librespot outputting to pulseaudio. The whole thing adds 3000ms or more latency to my setup. But, it does allow unified device setup in Kodi and lyrics/visualizations of the sound stream produced by librespot in Kodi (!) in a way that "just works", albeit with some sluggishness. Lowering buffer sizes all-around that chain uses CPU a lot and does not make things much better. For people bothered by this: switch Kodi to use PulseAudio, make PulseAudio output to ALSA device. Kodi and Kodi/librespot still works sluggish, but you can run a second/separate instance of librespot that outputs directly to Pulse->ALSA with minimal lag, but no Kodi integration.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#249
No description provided.