Skip to content

Commit

Permalink
pulseaudio: Just read/dump captured data in FlushCapture.
Browse files Browse the repository at this point in the history
Apparently pa_stream_flush() doesn't work as expected:

https://lists.freedesktop.org/archives/pulseaudio-discuss/2012-April/013328.html

Fixes Bugzilla #4087.
  • Loading branch information
icculus committed Feb 17, 2018
1 parent 6867f61 commit 97494f5
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/audio/pulseaudio/SDL_pulseaudio.c
Expand Up @@ -249,12 +249,6 @@ getAppName(void)
return "SDL Application"; /* oh well. */
}

static void
stream_operation_complete_no_op(pa_stream *s, int success, void *userdata)
{
/* no-op for pa_stream_drain(), etc, to use for callback. */
}

static void
WaitForPulseOperation(pa_mainloop *mainloop, pa_operation *o)
{
Expand Down Expand Up @@ -426,14 +420,31 @@ static void
PULSEAUDIO_FlushCapture(_THIS)
{
struct SDL_PrivateAudioData *h = this->hidden;
const void *data = NULL;
size_t nbytes = 0;

if (h->capturebuf != NULL) {
PULSEAUDIO_pa_stream_drop(h->stream);
h->capturebuf = NULL;
h->capturelen = 0;
}

WaitForPulseOperation(h->mainloop, PULSEAUDIO_pa_stream_flush(h->stream, stream_operation_complete_no_op, NULL));
while (SDL_TRUE) {
if (PULSEAUDIO_pa_context_get_state(h->context) != PA_CONTEXT_READY ||
PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY ||
PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
SDL_OpenedAudioDeviceDisconnected(this);
return; /* uhoh, pulse failed! */
}

if (PULSEAUDIO_pa_stream_readable_size(h->stream) == 0) {
break; /* no data available, so we're done. */
}

/* 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. */
}
}

static void
Expand Down

0 comments on commit 97494f5

Please sign in to comment.