From adabc38439be609d6bb721906c2546a646aadf25 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 18 May 2017 15:43:51 -0400 Subject: [PATCH] wasapi: Deal with AUDCLNT_S_BUFFER_EMPTY when flushing audio device. --- src/audio/wasapi/SDL_wasapi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c index a004e47e91c59..fb9da1c32b432 100644 --- a/src/audio/wasapi/SDL_wasapi.c +++ b/src/audio/wasapi/SDL_wasapi.c @@ -609,9 +609,14 @@ WASAPI_FlushCapture(_THIS) DWORD flags = 0; /* just read until we stop getting packets, throwing them away. */ - while (!WasapiFailed(this, IAudioCaptureClient_GetBuffer(this->hidden->capture, &ptr, &frames, &flags, NULL, NULL))) { - if (WasapiFailed(this, IAudioCaptureClient_ReleaseBuffer(this->hidden->capture, frames))) { - break; + while (SDL_TRUE) { + const HRESULT ret = IAudioCaptureClient_GetBuffer(this->hidden->capture, &ptr, &frames, &flags, NULL, NULL)); + if (ret == AUDCLNT_S_BUFFER_EMPTY) { + break; /* no more buffered data; we're done. */ + } else if (WasapiFailed(this, ret)) { + break; /* failed for some other reason, abort. */ + } else if (WasapiFailed(this, IAudioCaptureClient_ReleaseBuffer(this->hidden->capture, frames))) { + break; /* something broke. */ } } SDL_AudioStreamClear(this->hidden->capturestream);