Use arts_suspend() in a loop to wait for arts to become ready.
authorRyan C. Gordon
Mon, 02 Jan 2012 15:16:45 -0500
changeset 6152ff0bc7241515
parent 6148 36f5d9fc9c39
child 6156 160a69849b9e
Use arts_suspend() in a loop to wait for arts to become ready.

(Transplanted from hg changeset 331f27f01cdb to the 1.3 branch.)
src/audio/arts/SDL_artsaudio.c
     1.1 --- a/src/audio/arts/SDL_artsaudio.c	Mon Jan 02 00:47:54 2012 -0500
     1.2 +++ b/src/audio/arts/SDL_artsaudio.c	Mon Jan 02 15:16:45 2012 -0500
     1.3 @@ -61,6 +61,7 @@
     1.4  static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
     1.5                                      int count);
     1.6  static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
     1.7 +static int (*SDL_NAME(arts_suspend))(void);
     1.8  static int (*SDL_NAME(arts_suspended)) (void);
     1.9  static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
    1.10  
    1.11 @@ -78,6 +79,7 @@
    1.12      SDL_ARTS_SYM(arts_stream_get),
    1.13      SDL_ARTS_SYM(arts_write),
    1.14      SDL_ARTS_SYM(arts_close_stream),
    1.15 +    SDL_ARTS_SYM(arts_suspend),
    1.16      SDL_ARTS_SYM(arts_suspended),
    1.17      SDL_ARTS_SYM(arts_error_text),
    1.18  /* *INDENT-ON* */
    1.19 @@ -216,6 +218,17 @@
    1.20      }
    1.21  }
    1.22  
    1.23 +static int
    1.24 +ARTS_Suspend(void)
    1.25 +{
    1.26 +    const Uint32 abortms = SDL_GetTicks() + 3000; /* give up after 3 secs */
    1.27 +    while ( (!SDL_NAME(arts_suspended)()) && (SDL_GetTicks() < abortms) ) {
    1.28 +        if ( SDL_NAME(arts_suspend)() ) {
    1.29 +            break;
    1.30 +        }
    1.31 +    }
    1.32 +    return SDL_NAME(arts_suspended)();
    1.33 +}
    1.34  
    1.35  static int
    1.36  ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
    1.37 @@ -270,7 +283,7 @@
    1.38          return 0;
    1.39      }
    1.40  
    1.41 -    if (!SDL_NAME(arts_suspended) ()) {
    1.42 +    if (!ARTS_Suspend()) {
    1.43          ARTS_CloseDevice(this);
    1.44          SDL_SetError("ARTS can not open audio device");
    1.45          return 0;
    1.46 @@ -346,7 +359,7 @@
    1.47          }
    1.48  
    1.49          /* Play a stream so aRts doesn't crash */
    1.50 -        if (SDL_NAME(arts_suspended) ()) {
    1.51 +        if (ARTS_Suspend()) {
    1.52              arts_stream_t stream;
    1.53              stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
    1.54              SDL_NAME(arts_write) (stream, "", 0);