Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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

(Transplanted from hg changeset 331f27f01cdb to the 1.3 branch.)
  • Loading branch information
icculus committed Jan 2, 2012
1 parent 748b927 commit 7ed7d7a1e5bfa9f8064e51be1ad15b8af1107fd2
Showing with 15 additions and 2 deletions.
  1. +15 −2 src/audio/arts/SDL_artsaudio.c
@@ -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);

0 comments on commit 7ed7d7a

Please sign in to comment.