Skip to content
Permalink
Browse files

Use arts_suspend() in a loop to wait for arts to become ready.

Fixes Bugzilla #372.

Thanks to Patrice Mandin for the patch!
  • Loading branch information
icculus committed Jan 2, 2012
1 parent fcd1633 commit 6ac9979e60495c23983a1a75b7337bc9bd89d63d
Showing with 16 additions and 2 deletions.
  1. +16 −2 src/audio/arts/SDL_artsaudio.c
@@ -65,6 +65,7 @@ static int (*SDL_NAME(arts_stream_set))(arts_stream_t s, arts_parameter_t param,
static int (*SDL_NAME(arts_stream_get))(arts_stream_t s, arts_parameter_t param);
static int (*SDL_NAME(arts_write))(arts_stream_t s, const void *buffer, int count);
static void (*SDL_NAME(arts_close_stream))(arts_stream_t s);
static int (*SDL_NAME(arts_suspend))(void);
static int (*SDL_NAME(arts_suspended))(void);
static const char *(*SDL_NAME(arts_error_text))(int errorcode);

@@ -79,6 +80,7 @@ static struct {
{ "arts_stream_get", (void **)&SDL_NAME(arts_stream_get) },
{ "arts_write", (void **)&SDL_NAME(arts_write) },
{ "arts_close_stream", (void **)&SDL_NAME(arts_close_stream) },
{ "arts_suspend", (void **)&SDL_NAME(arts_suspend) },
{ "arts_suspended", (void **)&SDL_NAME(arts_suspended) },
{ "arts_error_text", (void **)&SDL_NAME(arts_error_text) },
};
@@ -128,6 +130,18 @@ static int LoadARTSLibrary(void)

/* Audio driver bootstrap functions */

static int ARTS_Suspend(void)
{
const Uint32 abortms = SDL_GetTicks() + 3000; /* give up after 3 secs */
while ( (!SDL_NAME(arts_suspended)()) && (SDL_GetTicks() < abortms) ) {
if ( SDL_NAME(arts_suspend)() ) {
break;
}
}

return SDL_NAME(arts_suspended)();
}

static int Audio_Available(void)
{
int available = 0;
@@ -136,7 +150,7 @@ static int Audio_Available(void)
return available;
}
if ( SDL_NAME(arts_init)() == 0 ) {
if ( SDL_NAME(arts_suspended)() ) {
if ( ARTS_Suspend() ) {
/* Play a stream so aRts doesn't crash */
arts_stream_t stream2;
stream2=SDL_NAME(arts_play_stream)(44100, 16, 2, "SDL");
@@ -307,7 +321,7 @@ static int ARTS_OpenAudio(_THIS, SDL_AudioSpec *spec)
SDL_SetError("Unable to initialize ARTS: %s", SDL_NAME(arts_error_text)(error_code));
return(-1);
}
if ( ! SDL_NAME(arts_suspended)() ) {
if ( ! ARTS_Suspend() ) {
SDL_SetError("ARTS can not open audio device");
return(-1);
}

0 comments on commit 6ac9979

Please sign in to comment.