pulseaudio: Just read/dump captured data in FlushCapture.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 17 Feb 2018 18:30:21 -0500
changeset 11878625cdd85edfe
parent 11877 2a25e8690229
child 11879 c3a05f3b1f8b
pulseaudio: Just read/dump captured data in FlushCapture.

Apparently pa_stream_flush() doesn't work as expected:

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

Fixes Bugzilla #4087.
src/audio/pulseaudio/SDL_pulseaudio.c
     1.1 --- a/src/audio/pulseaudio/SDL_pulseaudio.c	Fri Feb 16 14:56:28 2018 -0500
     1.2 +++ b/src/audio/pulseaudio/SDL_pulseaudio.c	Sat Feb 17 18:30:21 2018 -0500
     1.3 @@ -250,12 +250,6 @@
     1.4  }
     1.5  
     1.6  static void
     1.7 -stream_operation_complete_no_op(pa_stream *s, int success, void *userdata)
     1.8 -{
     1.9 -    /* no-op for pa_stream_drain(), etc, to use for callback. */
    1.10 -}
    1.11 -
    1.12 -static void
    1.13  WaitForPulseOperation(pa_mainloop *mainloop, pa_operation *o)
    1.14  {
    1.15      /* This checks for NO errors currently. Either fix that, check results elsewhere, or do things you don't care about. */
    1.16 @@ -426,6 +420,8 @@
    1.17  PULSEAUDIO_FlushCapture(_THIS)
    1.18  {
    1.19      struct SDL_PrivateAudioData *h = this->hidden;
    1.20 +    const void *data = NULL;
    1.21 +    size_t nbytes = 0;
    1.22  
    1.23      if (h->capturebuf != NULL) {
    1.24          PULSEAUDIO_pa_stream_drop(h->stream);
    1.25 @@ -433,7 +429,22 @@
    1.26          h->capturelen = 0;
    1.27      }
    1.28  
    1.29 -    WaitForPulseOperation(h->mainloop, PULSEAUDIO_pa_stream_flush(h->stream, stream_operation_complete_no_op, NULL));
    1.30 +    while (SDL_TRUE) {
    1.31 +        if (PULSEAUDIO_pa_context_get_state(h->context) != PA_CONTEXT_READY ||
    1.32 +            PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY ||
    1.33 +            PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
    1.34 +            SDL_OpenedAudioDeviceDisconnected(this);
    1.35 +            return;  /* uhoh, pulse failed! */
    1.36 +        }
    1.37 +
    1.38 +        if (PULSEAUDIO_pa_stream_readable_size(h->stream) == 0) {
    1.39 +            break;  /* no data available, so we're done. */
    1.40 +        }
    1.41 +
    1.42 +        /* a new fragment is available! Just dump it. */
    1.43 +        PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes);
    1.44 +        PULSEAUDIO_pa_stream_drop(h->stream);  /* drop this fragment. */
    1.45 +    }
    1.46  }
    1.47  
    1.48  static void