Skip to content

Commit

Permalink
Fixed infinite recursion if the WASAPI audio device couldn't be recov…
Browse files Browse the repository at this point in the history
…ered
  • Loading branch information
slouken committed Jul 28, 2017
1 parent f033ce6 commit 4a73420
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/audio/wasapi/SDL_wasapi.c
Expand Up @@ -605,24 +605,22 @@ WASAPI_CaptureFromDevice(_THIS, void *buffer, int buflen)
static void
WASAPI_FlushCapture(_THIS)
{
if (RecoverWasapiIfLost(this)) {
BYTE *ptr = NULL;
UINT32 frames = 0;
DWORD flags = 0;

/* just read until we stop getting packets, throwing them away. */
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. */
}
BYTE *ptr = NULL;
UINT32 frames = 0;
DWORD flags = 0;

/* just read until we stop getting packets, throwing them away. */
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);
}
SDL_AudioStreamClear(this->hidden->capturestream);
}

static void
Expand Down

0 comments on commit 4a73420

Please sign in to comment.