src/audio/arts/SDL_artsaudio.c
changeset 6152 ff0bc7241515
parent 6138 4c64952a58fb
child 6885 700f1b25f77f
--- a/src/audio/arts/SDL_artsaudio.c	Mon Jan 02 00:47:54 2012 -0500
+++ b/src/audio/arts/SDL_artsaudio.c	Mon Jan 02 15:16:45 2012 -0500
@@ -61,6 +61,7 @@
 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);
 
@@ -78,6 +79,7 @@
     SDL_ARTS_SYM(arts_stream_get),
     SDL_ARTS_SYM(arts_write),
     SDL_ARTS_SYM(arts_close_stream),
+    SDL_ARTS_SYM(arts_suspend),
     SDL_ARTS_SYM(arts_suspended),
     SDL_ARTS_SYM(arts_error_text),
 /* *INDENT-ON* */
@@ -216,6 +218,17 @@
     }
 }
 
+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
 ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
@@ -270,7 +283,7 @@
         return 0;
     }
 
-    if (!SDL_NAME(arts_suspended) ()) {
+    if (!ARTS_Suspend()) {
         ARTS_CloseDevice(this);
         SDL_SetError("ARTS can not open audio device");
         return 0;
@@ -346,7 +359,7 @@
         }
 
         /* Play a stream so aRts doesn't crash */
-        if (SDL_NAME(arts_suspended) ()) {
+        if (ARTS_Suspend()) {
             arts_stream_t stream;
             stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
             SDL_NAME(arts_write) (stream, "", 0);