# HG changeset patch # User Sam Lantinga # Date 1361925112 28800 # Node ID e56ed2eb139e2348f45e8f52a5ba3c91b462ac09 # Parent 361bebe92c66f3fe7bf082d837d4f0e455b370f8 Check to make sure we can connect to PulseAudio before we use it. diff -r 361bebe92c66 -r e56ed2eb139e src/audio/pulseaudio/SDL_pulseaudio.c --- a/src/audio/pulseaudio/SDL_pulseaudio.c Tue Feb 26 20:41:28 2013 -0800 +++ b/src/audio/pulseaudio/SDL_pulseaudio.c Tue Feb 26 16:31:52 2013 -0800 @@ -205,6 +205,27 @@ } +/* 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) @@ -476,7 +497,6 @@ UnloadPulseAudioLibrary(); } - static int PULSEAUDIO_Init(SDL_AudioDriverImpl * impl) { @@ -484,6 +504,10 @@ return 0; } + if (!CheckPulseAudioAvailable()) { + return 0; + } + /* Set the function pointers */ impl->OpenDevice = PULSEAUDIO_OpenDevice; impl->PlayDevice = PULSEAUDIO_PlayDevice;