Prevent PulseAudio driver to lock its mutex for too long

This commit is contained in:
Marcelo Fernandez 2018-05-01 10:44:08 -03:00
parent 007d1754e3
commit cf4371a0ad
1 changed files with 11 additions and 2 deletions

View File

@ -340,13 +340,22 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) {
bytes = byte_size; bytes = byte_size;
} }
int ret = pa_stream_write(ad->pa_str, ptr, bytes, NULL, 0LL, PA_SEEK_RELATIVE); ret = pa_stream_write(ad->pa_str, ptr, bytes, NULL, 0LL, PA_SEEK_RELATIVE);
if (ret >= 0) { if (ret >= 0) {
byte_size -= bytes; byte_size -= bytes;
ptr = (const char *)ptr + bytes; ptr = (const char *)ptr + bytes;
} }
} else { } else {
pa_mainloop_iterate(ad->pa_ml, 1, NULL); ret = pa_mainloop_iterate(ad->pa_ml, 0, NULL);
if (ret == 0) {
// If pa_mainloop_iterate returns 0 sleep for 1 msec to wait
// for the stream to be able to process more bytes
ad->unlock();
OS::get_singleton()->delay_usec(1000);
ad->lock();
}
} }
} }
} }