src/audio/android/SDL_androidaudio.c
changeset 7612 627d571587d3
parent 7191 75360622e65f
child 7613 27e0ae109c71
     1.1 --- a/src/audio/android/SDL_androidaudio.c	Thu Aug 08 15:04:30 2013 -0700
     1.2 +++ b/src/audio/android/SDL_androidaudio.c	Thu Aug 08 21:25:09 2013 -0300
     1.3 @@ -50,7 +50,7 @@
     1.4  
     1.5      audioDevice = this;
     1.6  
     1.7 -    this->hidden = SDL_malloc(sizeof(*(this->hidden)));
     1.8 +    this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc(sizeof(*(this->hidden)));
     1.9      if (!this->hidden) {
    1.10          return SDL_OutOfMemory();
    1.11      }
    1.12 @@ -91,6 +91,13 @@
    1.13          /* Init failed? */
    1.14          return SDL_SetError("Java-side initialization failed!");
    1.15      }
    1.16 +    
    1.17 +    /* Audio thread is started here, after audio buffers and Java's AudioTrack are in place and ready to go */
    1.18 +    this->thread = SDL_CreateThread(SDL_RunAudio, "AndroidAudioThread", this);
    1.19 +    if (this->thread == NULL) {
    1.20 +        AndroidAUD_CloseDevice(this);
    1.21 +        return SDL_SetError("Couldn't create audio thread");
    1.22 +    }
    1.23  
    1.24      return 0;
    1.25  }
    1.26 @@ -110,6 +117,10 @@
    1.27  static void
    1.28  AndroidAUD_CloseDevice(_THIS)
    1.29  {
    1.30 +    /* At this point SDL_CloseAudioDevice via close_audio_device took care of terminating the audio thread
    1.31 +       so it's safe to terminate the Java side buffer and AudioTrack
    1.32 +     */
    1.33 +   
    1.34      if (this->hidden != NULL) {
    1.35          SDL_free(this->hidden);
    1.36          this->hidden = NULL;
    1.37 @@ -143,13 +154,7 @@
    1.38      "android", "SDL Android audio driver", AndroidAUD_Init, 0
    1.39  };
    1.40  
    1.41 -/* Called by the Java code to start the audio processing on a thread */
    1.42 -void
    1.43 -Android_RunAudioThread()
    1.44 -{
    1.45 -    SDL_RunAudio(audioDevice);
    1.46 -}
    1.47 -
    1.48  #endif /* SDL_AUDIO_DRIVER_ANDROID */
    1.49  
    1.50  /* vi: set ts=4 sw=4 expandtab: */
    1.51 +