Commit 5fa2cb67 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Use arts_suspend() in a loop to wait for arts to become ready.

(Transplanted from hg changeset 331f27f01cdb to the 1.3 branch.)
parent eb81637a
......@@ -61,6 +61,7 @@ static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
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 @@ static struct
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 @@ ARTS_CloseDevice(_THIS)
}
}
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 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
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 @@ ARTS_Init(SDL_AudioDriverImpl * impl)
}
/* 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment