audio: Only allocate fake_stream if we're using the standard audio threads.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 09 Aug 2016 00:44:59 -0400
changeset 102714a1faf81a620
parent 10270 4d99b888e7e5
child 10272 2b8bb76140a5
audio: Only allocate fake_stream if we're using the standard audio threads.
src/audio/SDL_audio.c
     1.1 --- a/src/audio/SDL_audio.c	Tue Aug 09 00:44:05 2016 -0400
     1.2 +++ b/src/audio/SDL_audio.c	Tue Aug 09 00:44:59 2016 -0400
     1.3 @@ -1149,7 +1149,6 @@
     1.4      SDL_AudioDevice *device;
     1.5      SDL_bool build_cvt;
     1.6      void *handle = NULL;
     1.7 -    Uint32 stream_len;
     1.8      int i = 0;
     1.9  
    1.10      if (!SDL_WasInit(SDL_INIT_AUDIO)) {
    1.11 @@ -1338,19 +1337,6 @@
    1.12          }
    1.13      }
    1.14  
    1.15 -    /* Allocate a fake audio memory buffer */
    1.16 -    stream_len = (device->convert.needed) ? device->convert.len_cvt : 0;
    1.17 -    if (device->spec.size > stream_len) {
    1.18 -        stream_len = device->spec.size;
    1.19 -    }
    1.20 -    SDL_assert(stream_len > 0);
    1.21 -    device->fake_stream = (Uint8 *) SDL_malloc(stream_len);
    1.22 -    if (device->fake_stream == NULL) {
    1.23 -        close_audio_device(device);
    1.24 -        SDL_OutOfMemory();
    1.25 -        return 0;
    1.26 -    }
    1.27 -
    1.28      if (device->spec.callback == NULL) {  /* use buffer queueing? */
    1.29          /* pool a few packets to start. Enough for two callbacks. */
    1.30          const int packetlen = SDL_AUDIOBUFFERQUEUE_PACKETLEN;
    1.31 @@ -1377,6 +1363,20 @@
    1.32      if (!current_audio.impl.ProvidesOwnCallbackThread) {
    1.33          /* Start the audio thread */
    1.34  
    1.35 +        /* Allocate a fake audio buffer; only used by our internal threads. */
    1.36 +        Uint32 stream_len = (device->convert.needed) ? device->convert.len_cvt : 0;
    1.37 +        if (device->spec.size > stream_len) {
    1.38 +            stream_len = device->spec.size;
    1.39 +        }
    1.40 +        SDL_assert(stream_len > 0);
    1.41 +
    1.42 +        device->fake_stream = (Uint8 *) SDL_malloc(stream_len);
    1.43 +        if (device->fake_stream == NULL) {
    1.44 +            close_audio_device(device);
    1.45 +            SDL_OutOfMemory();
    1.46 +            return 0;
    1.47 +        }
    1.48 +
    1.49          /* !!! FIXME: we don't force the audio thread stack size here because it calls into user code, but maybe we should? */
    1.50          /* buffer queueing callback only needs a few bytes, so make the stack tiny. */
    1.51          char name[64];