ao_alsa: replace snd_pcm_status() with snd_pcm_avail() in get_space()

Fixes a bug with alsa dmix on Fedora 29. After several minutes,
audio suddenly becomes bad and muted.

Actually, I don't know what causes this. Probably this is a bug in alsa.
In any case, as snd_pcm_status() returns not only 'avail', but also other
fields such as tstamp, htstamp, etc, this could be considered a good
simplification, as only avail is required for this function.
This commit is contained in:
Muhammad Faiz 2018-05-11 22:35:10 +07:00 committed by Jan Ekström
parent 7f625ea29b
commit 945303a92e
1 changed files with 4 additions and 5 deletions

View File

@ -939,17 +939,16 @@ static void drain(struct ao *ao)
static int get_space(struct ao *ao)
{
struct priv *p = ao->priv;
snd_pcm_status_t *status;
int err;
snd_pcm_status_alloca(&status);
unsigned space = err = snd_pcm_avail(p->alsa);
if (err == -EPIPE) // EOF
return p->buffersize;
err = snd_pcm_status(p->alsa, status);
if (!check_device_present(ao, err))
goto alsa_error;
CHECK_ALSA_ERROR("cannot get pcm status");
CHECK_ALSA_ERROR("cannot get pcm avail");
unsigned space = snd_pcm_status_get_avail(status);
if (space > p->buffersize) // Buffer underrun?
space = p->buffersize;
return space / p->outburst * p->outburst;