diff options
author | Ryan C. Gordon <icculus@icculus.org> | 2012-01-02 15:07:26 -0500 |
---|---|---|
committer | Ryan C. Gordon <icculus@icculus.org> | 2012-01-02 15:07:26 -0500 |
commit | 63415c656078416425a15e32494f80675fe644de (patch) | |
tree | d85041a627adf68715e477de550c45514d6d5967 | |
parent | b0602ed5089594c4d9800ba463cc8e090e7ec8c4 (diff) |
Use arts_suspend() in a loop to wait for arts to become ready.
Fixes Bugzilla #372.
Thanks to Patrice Mandin for the patch!
--HG--
branch : SDL-1.2
-rw-r--r-- | src/audio/arts/SDL_artsaudio.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/audio/arts/SDL_artsaudio.c b/src/audio/arts/SDL_artsaudio.c index 94da4d72cb..373f8c1677 100644 --- a/src/audio/arts/SDL_artsaudio.c +++ b/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); } |