How to gracefully recover from -EPIPE errors in ALSA?

I have a sound application that uses ALSA drivers for Linux, and the code works very well on an Intel Linux desktop machine. However, I would also like to support the Raspberry Pi, and I get periodic mutes and buffering on this platform. In fairness, it should be noted that problems also occur in Intel Linux, but they are not accompanied by unpleasant static bursts, which are probably associated with the ALSA driver on this platform.

In any case, I get two types of errors. First, my call to snd_pcm_wait() sometimes returns the -EPIPE code. I will catch this code and then try to call snd_pcm_recover() and then snd_pcm_prepare() , but the next time snd_pcm_writei() is called, some static distortion still occurs. Is this the right way to recover from such mistakes? Is there any way to recover from this without static?

When snd_pcm_wait() returns successfully, I call snd_pcm_avail_update() ... should I also do this after successfully returning from snd_pcm_recover() ?

The second problem is that sometimes snd_pcm_writei() also returns a -EPIPE return -EPIPE . Again, I try to call snd_pcm_recover() in this case, but still get audible clicks or other nasty things. Is there a way to extract more elegantly from this error?

+4
source share
1 answer

Interrupts can occur at any time, so any function can return -EPIPE .

snd_pcm_recover() already called snd_pcm_prepare() if it succeeded; you don’t need to call him again.

When a device is prepared, its buffer is reset. In other words, it is known to be completely empty, so you do not need to check how many frames are available.

Due to reset, you should only hear data that was written to the buffer after that. Any static information will represent the remaining garbage from underloading and indicates a driver error. Nothing your application can do there.

+2
source

Source: https://habr.com/ru/post/1439192/


All Articles