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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c
index 147a9d1..7db64f5 100644
--- a/src/audio/SDL_audiocvt.c
+++ b/src/audio/SDL_audiocvt.c
@@ -1664,6 +1664,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream));
if (!retval) {
+ SDL_OutOfMemory();
return NULL;
}
diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index bfb82f0..b556f58 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -209,7 +209,7 @@ UpdateAudioStream(_THIS, const SDL_AudioSpec *oldspec)
}
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;
IAudioCaptureClient *capture = NULL;
WAVEFORMATEX *waveformat = NULL;
- SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
+ SDL_AudioFormat test_format;
SDL_AudioFormat wasapi_format = 0;
- SDL_bool valid_format = SDL_FALSE;
HRESULT ret = S_OK;
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. */
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) {
this->spec.format = test_format;
- valid_format = SDL_TRUE;
break;
}
- test_format = SDL_NextAudioFormat();
}
- if (!valid_format) {
+ if (!test_format) {
return SDL_SetError("WASAPI: Unsupported audio format");
}
@@ -631,9 +628,7 @@ WASAPI_PrepDevice(_THIS, const SDL_bool updatestream)
}
if (updatestream) {
- if (UpdateAudioStream(this, &oldspec) == -1) {
- return -1;
- }
+ return UpdateAudioStream(this, &oldspec);
}
return 0; /* good to go. */