snapcast icon indicating copy to clipboard operation
snapcast copied to clipboard

Dsnoop and EAGAIN Handling

Open Jacob-Bishop opened this issue 3 months ago • 0 comments

Describe the bug Thanks for this excellent piece of software. I have a working sound pipline using alsa loop, that goes audio source -> alsa plug pcm -> dmix -> loop in -> loop out -> plug -> snapcast server. However, I tried adding a dsnoop pcm in between the loop_out and plug pcms, but doing so causes clicking noises in the audio stream. It's not entirely clear to me whether fault here lies with alsa, snapcast, or my settings.

  1. Digging through your code, it looks like this is happening due to your handling of EAGAIN https://github.com/badaix/snapcast/blob/86cd4b2b63e750a72e0dfe6a46d47caf01426c8d/server/streamreader/alsa_stream.cpp#L312. Is there room in Snapcast's latency budget to retry this read instead of immediately giving up and sending silence? For what it's worth, based on a very cursory control-F, it looks like aplay has some sort of retry logic for this case https://github.com/alsa-project/alsa-utils/blob/906a56f9ff136211e53db201383a47d9b0ee445d/aplay/aplay.c#L2170.

  2. I tried increasing the snapcast buffer to 1000 ms (from 10 ms, I'm on a wired connection). I also tried increasing the number of fragments to 8. Neither seemed to help. On the alsa side, I tried increasing the period_size and buffer size to 2048/8092. This helped somewhat, but didn't solve the issue. Are there other settings on either the snapcast or alsa side that I should be adjusting?

Environment details

  • OS: Linux, 6.6.7-arch1-1
  • Snapcast version 0.25.0, installed binary from github release
  • Hardware: Fairly beefy X86_64 CPU, I don't think processing power is the issue?

Jacob-Bishop avatar Mar 18 '24 05:03 Jacob-Bishop