forked from auracaster/pyalsaaudio
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
+20
-8
@@ -1464,24 +1464,36 @@ static PyObject *alsapcm_write(alsapcm_t *self, PyObject *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = snd_pcm_state(self->handle);
|
snd_pcm_state_t state = snd_pcm_state(self->handle);
|
||||||
if ((state != SND_PCM_STATE_XRUN && state != SND_PCM_STATE_SETUP) ||
|
|
||||||
(res = snd_pcm_prepare(self->handle)) >= 0) {
|
if (state != SND_PCM_STATE_SETUP) {
|
||||||
|
res = snd_pcm_prepare(self->handle));
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = snd_pcm_writei(self->handle, data, datalen/self->framesize);
|
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) {
|
if (res == -EAGAIN) {
|
||||||
rc = PyLong_FromLong(0);
|
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),
|
PyErr_Format(ALSAAudioError, "%s [%s]", snd_strerror(res),
|
||||||
self->cardname);
|
self->cardname);
|
||||||
}
|
|
||||||
else {
|
#if PY_MAJOR_VERSION >= 3
|
||||||
rc = PyLong_FromLong(res);
|
PyBuffer_Release(&buf);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
|||||||
Reference in New Issue
Block a user