diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2018-10-31 05:30:11 +0200 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2018-10-31 05:30:11 +0200 |
commit | 4bbf9b9b6b3b4c656a83d038c9397f58712a5cc2 (patch) | |
tree | e909378817020da74af8be6e45c63bee52356e16 | |
parent | bfe1e062938c71c0a7ae4d86ca6a250cf374e6af (diff) |
store open mode to avoid state changes
we don't have to reopen the device if it's already nonblocking or not
for example.
-rw-r--r-- | libasound.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libasound.c b/libasound.c index 404cbd9..8a3dd62 100644 --- a/libasound.c +++ b/libasound.c @@ -149,6 +149,7 @@ struct _snd_pcm { const char *name; snd_pcm_uframes_t position, written; snd_pcm_stream_t stream; + int mode; bool started; }; @@ -193,6 +194,7 @@ device_open(snd_pcm_t *pcm, const char *name, snd_pcm_stream_t stream, int mode) } sio_onmove(hdl, onmove, pcm); + pcm->mode = mode; return hdl; } @@ -231,8 +233,10 @@ snd_pcm_name(snd_pcm_t *pcm) int snd_pcm_nonblock(snd_pcm_t *pcm, int nonblock) { - WARNX("snd_pcm_nonblock(%d)", nonblock); + if ((pcm->mode == SND_PCM_NONBLOCK && nonblock) || (!pcm->mode && !nonblock)) + return 0; + WARNX("snd_pcm_nonblock(%d)", nonblock); snd_pcm_drain(pcm); sio_close(pcm->hdl); |