mirror of
https://github.com/larsimmisch/pyalsaaudio.git
synced 2026-04-16 16:15:31 +00:00
Restore previous behaviour of calling snd_pcm_prepare in case of XRUN (#131)
This commit is contained in:
committed by
Oswald Buddenhagen
parent
07ac637b1c
commit
438e52e3fc
28
alsaaudio.c
28
alsaaudio.c
@@ -1464,24 +1464,36 @@ static PyObject *alsapcm_write(alsapcm_t *self, PyObject *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
state = snd_pcm_state(self->handle);
|
||||
if ((state != SND_PCM_STATE_XRUN && state != SND_PCM_STATE_SETUP) ||
|
||||
(res = snd_pcm_prepare(self->handle)) >= 0) {
|
||||
snd_pcm_state_t state = snd_pcm_state(self->handle);
|
||||
|
||||
if (state != SND_PCM_STATE_SETUP) {
|
||||
res = snd_pcm_prepare(self->handle));
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
res = snd_pcm_writei(self->handle, data, datalen/self->framesize);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (res == -EPIPE) {
|
||||
/* EPIPE means underrun */
|
||||
res = snd_pcm_recover(self->handle, res, 1);
|
||||
if (res >= 0) {
|
||||
res = snd_pcm_writei(self->handle, data, datalen/self->framesize);
|
||||
}
|
||||
}
|
||||
}
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (res == -EAGAIN) {
|
||||
rc = PyLong_FromLong(0);
|
||||
}
|
||||
else if (res < 0)
|
||||
res = snd_pcm_prepare(self->handle);
|
||||
if (res < 0)
|
||||
{
|
||||
PyErr_Format(ALSAAudioError, "%s [%s]", snd_strerror(res),
|
||||
self->cardname);
|
||||
}
|
||||
else {
|
||||
rc = PyLong_FromLong(res);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyBuffer_Release(&buf);
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
|
||||
Reference in New Issue
Block a user