aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-09-02 21:34:02 +0700
committerHarald Welte <laforge@gnumonks.org>2017-09-02 17:02:37 +0200
commit83aa99e7a9a1ff0d6949b4c71cd8817e2668b341 (patch)
treefd9ea554c08fc7560ec0f2fa199844c73cd1e633 /src
parent6c42261cd2b8075904e3df9ec987ffe52c6adb2b (diff)
pq_alsa.c: handle output buffer underrun
On some systems the ALSA output buffer is pretty big, and if the audio samples are not being passed into the buffer quickly enough, it becomes starved for data, resulting in an error called underrun. Previously, when it happenned, GAPK used to stop processing with the following message (where X is a random number): [+] PQ: Adding ALSA output (dev='default', blk_len=320) [!] pq_execute(): abort, item returned -1 [+] Processed X frames According to the ALSA documentation, the pcm_handle changes its state when the problem happens, and should be recovered using the snd_pcm_prepare() call. This change actually does that.
Diffstat (limited to 'src')
-rw-r--r--src/pq_alsa.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/pq_alsa.c b/src/pq_alsa.c
index 9cee426..a3435dd 100644
--- a/src/pq_alsa.c
+++ b/src/pq_alsa.c
@@ -57,7 +57,15 @@ pq_cb_alsa_output(void *_state, uint8_t *out, const uint8_t *in, unsigned int in
struct pq_state_alsa *state = _state;
unsigned int num_samples = in_len/2;
int rv;
+
rv = snd_pcm_writei(state->pcm_handle, in, num_samples);
+ if (rv == -EPIPE) {
+ /* Recover from buffer underrun */
+ snd_pcm_prepare(state->pcm_handle);
+ /* Send a new sample again */
+ rv = snd_pcm_writei(state->pcm_handle, in, num_samples);
+ }
+
return rv == num_samples ? 0 : -1;
}