Use arts_suspend() in a loop to wait for arts to become ready. SDL-1.2
authorRyan C. Gordon
Mon, 02 Jan 2012 15:07:26 -0500
branchSDL-1.2
changeset 6151331f27f01cdb
parent 6150 5f0b3693ab60
child 6153 9722c8d475c0
Use arts_suspend() in a loop to wait for arts to become ready.

Fixes Bugzilla #372.

Thanks to Patrice Mandin for the patch!
src/audio/arts/SDL_artsaudio.c
     1.1 --- a/src/audio/arts/SDL_artsaudio.c	Sun Jan 01 20:45:31 2012 -0500
     1.2 +++ b/src/audio/arts/SDL_artsaudio.c	Mon Jan 02 15:07:26 2012 -0500
     1.3 @@ -65,6 +65,7 @@
     1.4  static int (*SDL_NAME(arts_stream_get))(arts_stream_t s, arts_parameter_t param);
     1.5  static int (*SDL_NAME(arts_write))(arts_stream_t s, const void *buffer, 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 @@ -79,6 +80,7 @@
    1.12  	{ "arts_stream_get",	(void **)&SDL_NAME(arts_stream_get)	},
    1.13  	{ "arts_write",		(void **)&SDL_NAME(arts_write)		},
    1.14  	{ "arts_close_stream",	(void **)&SDL_NAME(arts_close_stream)	},
    1.15 +	{ "arts_suspend",	(void **)&SDL_NAME(arts_suspend)	},
    1.16  	{ "arts_suspended",	(void **)&SDL_NAME(arts_suspended)	},
    1.17  	{ "arts_error_text",	(void **)&SDL_NAME(arts_error_text)	},
    1.18  };
    1.19 @@ -128,6 +130,18 @@
    1.20  
    1.21  /* Audio driver bootstrap functions */
    1.22  
    1.23 +static int ARTS_Suspend(void)
    1.24 +{
    1.25 +	const Uint32 abortms = SDL_GetTicks() + 3000; /* give up after 3 secs */
    1.26 +	while ( (!SDL_NAME(arts_suspended)()) && (SDL_GetTicks() < abortms) ) {
    1.27 +		if ( SDL_NAME(arts_suspend)() ) {
    1.28 +			break;
    1.29 +		}
    1.30 +	}
    1.31 +
    1.32 +	return SDL_NAME(arts_suspended)();
    1.33 +}
    1.34 +
    1.35  static int Audio_Available(void)
    1.36  {
    1.37  	int available = 0;
    1.38 @@ -136,7 +150,7 @@
    1.39  		return available;
    1.40  	}
    1.41  	if ( SDL_NAME(arts_init)() == 0 ) {
    1.42 -		if ( SDL_NAME(arts_suspended)() ) {
    1.43 +		if ( ARTS_Suspend() ) {
    1.44  			/* Play a stream so aRts doesn't crash */
    1.45  			arts_stream_t stream2;
    1.46  			stream2=SDL_NAME(arts_play_stream)(44100, 16, 2, "SDL");
    1.47 @@ -307,7 +321,7 @@
    1.48  		SDL_SetError("Unable to initialize ARTS: %s", SDL_NAME(arts_error_text)(error_code));
    1.49  		return(-1);
    1.50  	}
    1.51 -	if ( ! SDL_NAME(arts_suspended)() ) {
    1.52 +	if ( ! ARTS_Suspend() ) {
    1.53  		SDL_SetError("ARTS can not open audio device");
    1.54  		return(-1);
    1.55  	}