mirror of https://gerrit.osmocom.org/gapk
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.
This commit is contained in:
parent
6c42261cd2
commit
83aa99e7a9
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue