Dne 14. 05. 20 v 23:06 sylvain.bertrand@gmail.com napsal(a):
On Thu, May 14, 2020 at 03:52:25PM +0200, Jaroslav Kysela wrote:
NAK: You should not call drain when the PCM handle is in the SETUP field. It's an obvious caller problem. The streaming should be active somehow.
The pb here is the non-blocking calls of the drain function: in my test case, the first call to the drain function switches the pcm in draining state, but the pcm will be switched to the setup state somewhen in between 2 drain function calls! Naively, I was calling the drain function on a regular time basis to see if the draining was finished, namely expecting 0 to be returned.
Then if I understood you well, the right way(tm) to use the drain function in non-block mode, is to call only once the drain function, then inspect the state of the pcm till it not anymore in the draining state.
Am I right? Or did I miss something again?
I looked to this problem again and the original patch seems more appropriate. The snd_pcm_drain() should return zero, if the state is SETUP, because there is no further work.
I applied your patch:
https://github.com/alsa-project/alsa-lib/commit/1b9104b5ff10be7f60441f622436...
with the (sanity) optimization in:
https://github.com/alsa-project/alsa-lib/commit/0b7f1441bb82903d45a29bf83c84...
It basically doesn't allow to call the plugin callback (otherwise we need to review all plugin drain callbacks, if the SETUP state is handled properly).
Thank you for your suggestion, Jaroslav
regards,