Use arts_suspend() in a loop to wait for arts to become ready.
Fixes Bugzilla #372.
Thanks to Patrice Mandin for the patch!
--- a/src/audio/arts/SDL_artsaudio.c Sun Jan 01 20:45:31 2012 -0500
+++ b/src/audio/arts/SDL_artsaudio.c Mon Jan 02 15:07:26 2012 -0500
@@ -65,6 +65,7 @@
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 @@
{ "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 @@
/* 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 @@
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 @@
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);
}