diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2018-11-07 17:00:36 +0900 |
---|---|---|
committer | Thierry Bultel <thierry.bultel@iot.bzh> | 2018-11-07 11:38:41 +0100 |
commit | 92e0380860dbc556ef2a1f9fbc0cd7eb99edad69 (patch) | |
tree | 041e305147b5148f87872d97f58ae24eda372679 | |
parent | 0e37ab93b7c611d4c1f94c4bfbee7acf312c9aec (diff) |
Handle too small card PCM buffer when writing
In the writing thread, handle the case when 'writing threshold'
was smaller than ALSA sound card's PCM buffer (defined in the driver).
This avoids waiting indefinitely for a buffer to contain a wanted number
of frames that it cannot contain.
Change-Id: Ie1aa69ea1a93471ed46d571c669ec08a1b827476
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r-- | plugins/alsa/alsa-core-pcm.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/plugins/alsa/alsa-core-pcm.c b/plugins/alsa/alsa-core-pcm.c index 509e1ac..f41aed0 100644 --- a/plugins/alsa/alsa-core-pcm.c +++ b/plugins/alsa/alsa-core-pcm.c @@ -555,7 +555,21 @@ static void *writeThreadEntry(void *handle) { alsa_ringbuf_t * rbuf = pcmCopyHandle->rbuf; - const snd_pcm_sframes_t threshold = 1000; + snd_pcm_status_t *pcmOutStatus; + snd_pcm_uframes_t pcmOutSize; + + snd_pcm_sframes_t threshold; + + snd_pcm_status_alloca(&pcmOutStatus); + snd_pcm_status(pcmOut, pcmOutStatus); + pcmOutSize = snd_pcm_status_get_avail_max(pcmOutStatus); + + /* This threshold is the expected space available in the hw output buffer + * The aim is to wait to have a significant amount of space, in order to + * avoid to write to the device too often, or take a very small amount of + * frames from the ring buffer. So basically, this saves some CPU load */ + + threshold = pcmOutSize / 3; for (;;) { |