Start Android Audio Thread after audio buffer and AudioTrack are ready.

Also, it starts the Audio Thread from the native side, putting the code in line
with other backends.
This commit is contained in:
Gabriel Jacobo 2013-08-08 21:25:09 -03:00
parent 98a222e974
commit 610264fb0b
4 changed files with 20 additions and 52 deletions

View file

@ -50,7 +50,7 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture)
audioDevice = this;
this->hidden = SDL_malloc(sizeof(*(this->hidden)));
this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc(sizeof(*(this->hidden)));
if (!this->hidden) {
return SDL_OutOfMemory();
}
@ -91,6 +91,13 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture)
/* Init failed? */
return SDL_SetError("Java-side initialization failed!");
}
/* Audio thread is started here, after audio buffers and Java's AudioTrack are in place and ready to go */
this->thread = SDL_CreateThread(SDL_RunAudio, "AndroidAudioThread", this);
if (this->thread == NULL) {
AndroidAUD_CloseDevice(this);
return SDL_SetError("Couldn't create audio thread");
}
return 0;
}
@ -110,6 +117,10 @@ AndroidAUD_GetDeviceBuf(_THIS)
static void
AndroidAUD_CloseDevice(_THIS)
{
/* At this point SDL_CloseAudioDevice via close_audio_device took care of terminating the audio thread
so it's safe to terminate the Java side buffer and AudioTrack
*/
if (this->hidden != NULL) {
SDL_free(this->hidden);
this->hidden = NULL;
@ -143,13 +154,7 @@ AudioBootStrap ANDROIDAUD_bootstrap = {
"android", "SDL Android audio driver", AndroidAUD_Init, 0
};
/* Called by the Java code to start the audio processing on a thread */
void
Android_RunAudioThread()
{
SDL_RunAudio(audioDevice);
}
#endif /* SDL_AUDIO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -32,6 +32,8 @@ struct SDL_PrivateAudioData
{
};
static void AndroidAUD_CloseDevice(_THIS);
#endif /* _SDL_androidaudio_h */
/* vi: set ts=4 sw=4 expandtab: */