Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Use arts_suspend() in a loop to wait for arts to become ready.
Browse files Browse the repository at this point in the history
(Transplanted from hg changeset 331f27f01cdb to the 1.3 branch.)
  • Loading branch information
icculus committed Jan 2, 2012
1 parent 748b927 commit 7ed7d7a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/audio/arts/SDL_artsaudio.c
Expand Up @@ -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);

Expand All @@ -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* */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7ed7d7a

Please sign in to comment.