Workaround older libpulse that fails in pa_context_new() with a NULL appname.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 30 Jul 2013 01:32:26 -0400
changeset 7545adb619b0af9c
parent 7544 0508756e7886
child 7546 f9ff5e066e49
Workaround older libpulse that fails in pa_context_new() with a NULL appname.

Newer libpulses do sane defaults if you pass a NULL there. In lieu of a
proper way to specify this in SDL at the moment, this will do.

Fixes Bugzilla #1119.
src/audio/pulseaudio/SDL_pulseaudio.c
     1.1 --- a/src/audio/pulseaudio/SDL_pulseaudio.c	Tue Jul 30 01:30:32 2013 -0400
     1.2 +++ b/src/audio/pulseaudio/SDL_pulseaudio.c	Tue Jul 30 01:32:26 2013 -0400
     1.3 @@ -65,6 +65,7 @@
     1.4  #endif /* pulseaudio <= 0.9.10 */
     1.5  
     1.6  
     1.7 +static const char *(*PULSEAUDIO_pa_get_library_version) (void);
     1.8  static pa_simple *(*PULSEAUDIO_pa_simple_new) (const char *, const char *,
     1.9      pa_stream_direction_t, const char *, const char *, const pa_sample_spec *,
    1.10      const pa_channel_map *, const pa_buffer_attr *, int *);
    1.11 @@ -177,6 +178,7 @@
    1.12  static int
    1.13  load_pulseaudio_syms(void)
    1.14  {
    1.15 +    SDL_PULSEAUDIO_SYM(pa_get_library_version);
    1.16      SDL_PULSEAUDIO_SYM(pa_simple_new);
    1.17      SDL_PULSEAUDIO_SYM(pa_simple_free);
    1.18      SDL_PULSEAUDIO_SYM(pa_mainloop_new);
    1.19 @@ -322,6 +324,28 @@
    1.20  }
    1.21  
    1.22  
    1.23 +static __inline__ int
    1.24 +squashVersion(const int major, const int minor, const int patch)
    1.25 +{
    1.26 +    return ((major & 0xFF) << 16) | ((minor & 0xFF) << 8) | (patch & 0xFF);
    1.27 +}
    1.28 +
    1.29 +/* Workaround for older pulse: pa_context_new() must have non-NULL appname */
    1.30 +static const char *
    1.31 +getAppName(void)
    1.32 +{
    1.33 +    const char *verstr = PULSEAUDIO_pa_get_library_version();
    1.34 +    if (verstr != NULL) {
    1.35 +        int maj, min, patch;
    1.36 +        if (SDL_sscanf(verstr, "%d.%d.%d", &maj, &min, &patch) == 3) {
    1.37 +            if (squashVersion(maj, min, patch) >= squashVersion(0, 9, 15)) {
    1.38 +                return NULL;  /* 0.9.15+ handles NULL correctly. */
    1.39 +            }
    1.40 +        }
    1.41 +    }
    1.42 +    return "SDL Application";  /* oh well. */
    1.43 +}
    1.44 +
    1.45  static int
    1.46  PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
    1.47  {
    1.48 @@ -432,7 +456,7 @@
    1.49      }
    1.50  
    1.51      h->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(h->mainloop);
    1.52 -    h->context = PULSEAUDIO_pa_context_new(h->mainloop_api, NULL);
    1.53 +    h->context = PULSEAUDIO_pa_context_new(h->mainloop_api, getAppName());
    1.54      if (!h->context) {
    1.55          PULSEAUDIO_CloseDevice(this);
    1.56          return SDL_SetError("pa_context_new() failed");