cleanup WASAPI_PrepDevice

- reorganize the loop which checks for the right wave-format
- use the return value of UpdateAudioStream
- ensure SetError is called in SDL_NewAudioStream
This commit is contained in:
pionere 2022-01-19 14:51:42 +01:00 committed by Ryan C. Gordon
parent c9e8d1573a
commit f91211eb17
2 changed files with 6 additions and 10 deletions

View file

@ -1664,6 +1664,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream)); retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream));
if (!retval) { if (!retval) {
SDL_OutOfMemory();
return NULL; return NULL;
} }

View file

@ -209,7 +209,7 @@ UpdateAudioStream(_THIS, const SDL_AudioSpec *oldspec)
} }
if (!this->stream) { if (!this->stream) {
return -1; return -1; /* SDL_NewAudioStream should have called SDL_SetError. */
} }
} }
@ -512,9 +512,8 @@ WASAPI_PrepDevice(_THIS, const SDL_bool updatestream)
IAudioRenderClient *render = NULL; IAudioRenderClient *render = NULL;
IAudioCaptureClient *capture = NULL; IAudioCaptureClient *capture = NULL;
WAVEFORMATEX *waveformat = NULL; WAVEFORMATEX *waveformat = NULL;
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); SDL_AudioFormat test_format;
SDL_AudioFormat wasapi_format = 0; SDL_AudioFormat wasapi_format = 0;
SDL_bool valid_format = SDL_FALSE;
HRESULT ret = S_OK; HRESULT ret = S_OK;
DWORD streamflags = 0; DWORD streamflags = 0;
@ -543,16 +542,14 @@ WASAPI_PrepDevice(_THIS, const SDL_bool updatestream)
/* Make sure we have a valid format that we can convert to whatever WASAPI wants. */ /* Make sure we have a valid format that we can convert to whatever WASAPI wants. */
wasapi_format = WaveFormatToSDLFormat(waveformat); wasapi_format = WaveFormatToSDLFormat(waveformat);
while ((!valid_format) && (test_format)) { for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) {
if (test_format == wasapi_format) { if (test_format == wasapi_format) {
this->spec.format = test_format; this->spec.format = test_format;
valid_format = SDL_TRUE;
break; break;
} }
test_format = SDL_NextAudioFormat();
} }
if (!valid_format) { if (!test_format) {
return SDL_SetError("WASAPI: Unsupported audio format"); return SDL_SetError("WASAPI: Unsupported audio format");
} }
@ -631,9 +628,7 @@ WASAPI_PrepDevice(_THIS, const SDL_bool updatestream)
} }
if (updatestream) { if (updatestream) {
if (UpdateAudioStream(this, &oldspec) == -1) { return UpdateAudioStream(this, &oldspec);
return -1;
}
} }
return 0; /* good to go. */ return 0; /* good to go. */