Check to make sure we can connect to PulseAudio before we use it.
authorSam Lantinga
Tue, 26 Feb 2013 16:31:52 -0800
changeset 6933e56ed2eb139e
parent 6932 361bebe92c66
child 6934 3ce238619067
Check to make sure we can connect to PulseAudio before we use it.
src/audio/pulseaudio/SDL_pulseaudio.c
     1.1 --- a/src/audio/pulseaudio/SDL_pulseaudio.c	Tue Feb 26 20:41:28 2013 -0800
     1.2 +++ b/src/audio/pulseaudio/SDL_pulseaudio.c	Tue Feb 26 16:31:52 2013 -0800
     1.3 @@ -205,6 +205,27 @@
     1.4  }
     1.5  
     1.6  
     1.7 +/* Check to see if we can connect to PulseAudio */
     1.8 +static SDL_bool
     1.9 +CheckPulseAudioAvailable()
    1.10 +{
    1.11 +    pa_simple *s;
    1.12 +    pa_sample_spec ss;
    1.13 +
    1.14 +    ss.format = PA_SAMPLE_S16NE;
    1.15 +    ss.channels = 1;
    1.16 +    ss.rate = 22050;
    1.17 +
    1.18 +    s = PULSEAUDIO_pa_simple_new(NULL, "SDL", PA_STREAM_PLAYBACK, NULL,
    1.19 +                                 "Test", &ss, NULL, NULL, NULL);
    1.20 +    if (s) {
    1.21 +        PULSEAUDIO_pa_simple_free(s);
    1.22 +        return SDL_TRUE;
    1.23 +    } else {
    1.24 +        return SDL_FALSE;
    1.25 +    }
    1.26 +}
    1.27 +
    1.28  /* This function waits until it is possible to write a full sound buffer */
    1.29  static void
    1.30  PULSEAUDIO_WaitDevice(_THIS)
    1.31 @@ -476,7 +497,6 @@
    1.32      UnloadPulseAudioLibrary();
    1.33  }
    1.34  
    1.35 -
    1.36  static int
    1.37  PULSEAUDIO_Init(SDL_AudioDriverImpl * impl)
    1.38  {
    1.39 @@ -484,6 +504,10 @@
    1.40          return 0;
    1.41      }
    1.42  
    1.43 +    if (!CheckPulseAudioAvailable()) {
    1.44 +        return 0;
    1.45 +    }
    1.46 +
    1.47      /* Set the function pointers */
    1.48      impl->OpenDevice = PULSEAUDIO_OpenDevice;
    1.49      impl->PlayDevice = PULSEAUDIO_PlayDevice;