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

Commit

Permalink
Check to make sure we can connect to PulseAudio before we use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Feb 27, 2013
1 parent e62ea4f commit 1f6bca4
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/audio/pulseaudio/SDL_pulseaudio.c
Expand Up @@ -205,6 +205,27 @@ load_pulseaudio_syms(void)
}


/* Check to see if we can connect to PulseAudio */
static SDL_bool
CheckPulseAudioAvailable()
{
pa_simple *s;
pa_sample_spec ss;

ss.format = PA_SAMPLE_S16NE;
ss.channels = 1;
ss.rate = 22050;

s = PULSEAUDIO_pa_simple_new(NULL, "SDL", PA_STREAM_PLAYBACK, NULL,
"Test", &ss, NULL, NULL, NULL);
if (s) {
PULSEAUDIO_pa_simple_free(s);
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}

/* This function waits until it is possible to write a full sound buffer */
static void
PULSEAUDIO_WaitDevice(_THIS)
Expand Down Expand Up @@ -476,14 +497,17 @@ PULSEAUDIO_Deinitialize(void)
UnloadPulseAudioLibrary();
}


static int
PULSEAUDIO_Init(SDL_AudioDriverImpl * impl)
{
if (LoadPulseAudioLibrary() < 0) {
return 0;
}

if (!CheckPulseAudioAvailable()) {
return 0;
}

/* Set the function pointers */
impl->OpenDevice = PULSEAUDIO_OpenDevice;
impl->PlayDevice = PULSEAUDIO_PlayDevice;
Expand Down

0 comments on commit 1f6bca4

Please sign in to comment.