wasapi: Deal with AUDCLNT_S_BUFFER_EMPTY when flushing audio device.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 18 May 2017 15:43:51 -0400
changeset 11009cca512965b67
parent 11008 c923c6eac264
child 11010 96de7fe65e32
wasapi: Deal with AUDCLNT_S_BUFFER_EMPTY when flushing audio device.
src/audio/wasapi/SDL_wasapi.c
     1.1 --- a/src/audio/wasapi/SDL_wasapi.c	Thu May 18 15:33:17 2017 -0400
     1.2 +++ b/src/audio/wasapi/SDL_wasapi.c	Thu May 18 15:43:51 2017 -0400
     1.3 @@ -609,9 +609,14 @@
     1.4          DWORD flags = 0;
     1.5  
     1.6          /* just read until we stop getting packets, throwing them away. */
     1.7 -        while (!WasapiFailed(this, IAudioCaptureClient_GetBuffer(this->hidden->capture, &ptr, &frames, &flags, NULL, NULL))) {
     1.8 -            if (WasapiFailed(this, IAudioCaptureClient_ReleaseBuffer(this->hidden->capture, frames))) {
     1.9 -                break;
    1.10 +        while (SDL_TRUE) {
    1.11 +            const HRESULT ret = IAudioCaptureClient_GetBuffer(this->hidden->capture, &ptr, &frames, &flags, NULL, NULL));
    1.12 +            if (ret == AUDCLNT_S_BUFFER_EMPTY) {
    1.13 +                break;  /* no more buffered data; we're done. */
    1.14 +            } else if (WasapiFailed(this, ret)) {
    1.15 +                break;  /* failed for some other reason, abort. */
    1.16 +            } else if (WasapiFailed(this, IAudioCaptureClient_ReleaseBuffer(this->hidden->capture, frames))) {
    1.17 +                break;  /* something broke. */
    1.18              }
    1.19          }
    1.20          SDL_AudioStreamClear(this->hidden->capturestream);