[Simon McVittie] > It would probably be useful to let upstream know that this regressed > somewhere between 2.28.0 and commit 38d11e5c: that might be helpful when > narrowing down what change caused this.
It is already reported in the forwarded issue. I investigated further, and now believe the problem is in the PULSEAUDIO_FlushCapture(), which seem to be unable to flush the data faster than pulseaudio is producing data, causing it to keep flushing while the client is waiting for audio. The following patch solved the problem for the test program, by recording up front how much data to flush, and then stop flushing once at least that amount has been dropped. diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index 2fb2f31c6..d434a35e2 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -497,7 +497,7 @@ static void PULSEAUDIO_FlushCapture(_THIS) { struct SDL_PrivateAudioData *h = this->hidden; const void *data = NULL; - size_t nbytes = 0; + size_t nbytes = 0, buflen = 0; PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop); @@ -507,18 +507,20 @@ static void PULSEAUDIO_FlushCapture(_THIS) h->capturelen = 0; } - while (SDL_AtomicGet(&this->enabled) && (PULSEAUDIO_pa_stream_readable_size(h->stream) > 0)) { + buflen = PULSEAUDIO_pa_stream_readable_size(h->stream); + while (SDL_AtomicGet(&this->enabled) && (buflen > 0)) { PULSEAUDIO_pa_threaded_mainloop_wait(pulseaudio_threaded_mainloop); if ((PULSEAUDIO_pa_context_get_state(pulseaudio_context) != PA_CONTEXT_READY) || (PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY)) { /*printf("PULSEAUDIO DEVICE FAILURE IN FLUSHCAPTURE!\n");*/ SDL_OpenedAudioDeviceDisconnected(this); break; } - - if (PULSEAUDIO_pa_stream_readable_size(h->stream) > 0) { + if (buflen > 0) { + /*printf("pulseaudio device flushcapture loop dump frament size=%ld\n", buflen);*/ /* a new fragment is available! Just dump it. */ PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes); PULSEAUDIO_pa_stream_drop(h->stream); /* drop this fragment. */ + buflen -= nbytes; } } I will pass it upstream too. -- Happy hacking Petter Reinholdtsen