Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
authorRyan C. Gordon
Sat, 10 Oct 2009 07:34:15 +0000
changeset 33624e83cdb58134
parent 3361 d559edc85610
child 3363 90aec03bf9fd
Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.
src/audio/alsa/SDL_alsa_audio.c
src/audio/alsa/SDL_alsa_audio.h
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Sat Oct 10 06:51:42 2009 +0000
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Sat Oct 10 07:34:15 2009 +0000
     1.3 @@ -25,7 +25,6 @@
     1.4  
     1.5  #include <sys/types.h>
     1.6  #include <signal.h>             /* For kill() */
     1.7 -#include <dlfcn.h>
     1.8  #include <errno.h>
     1.9  #include <string.h>
    1.10  
    1.11 @@ -35,6 +34,9 @@
    1.12  #include "../SDL_audio_c.h"
    1.13  #include "SDL_alsa_audio.h"
    1.14  
    1.15 +#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
    1.16 +#include "SDL_loadso.h"
    1.17 +#endif
    1.18  
    1.19  /* The tag name used by ALSA audio */
    1.20  #define DRIVER_NAME         "alsa"
    1.21 @@ -60,16 +62,16 @@
    1.22    (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_t);
    1.23  static int (*ALSA_snd_pcm_hw_params_set_channels)
    1.24    (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int);
    1.25 -static int (*ALSA_snd_pcm_hw_params_get_channels) (const snd_pcm_hw_params_t
    1.26 -                                                   *);
    1.27 -static unsigned int (*ALSA_snd_pcm_hw_params_set_rate_near)
    1.28 -  (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int, int *);
    1.29 -static snd_pcm_uframes_t(*ALSA_snd_pcm_hw_params_set_period_size_near)
    1.30 -  (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t, int *);
    1.31 +static int (*ALSA_snd_pcm_hw_params_set_rate_near)
    1.32 +  (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
    1.33 +static int (*ALSA_snd_pcm_hw_params_set_period_size_near)
    1.34 +  (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t *, int *);
    1.35 +static int (*ALSA_snd_pcm_hw_params_get_channels)
    1.36 +  (const snd_pcm_hw_params_t *, unsigned int *);
    1.37  static snd_pcm_sframes_t(*ALSA_snd_pcm_hw_params_get_period_size)
    1.38    (const snd_pcm_hw_params_t *);
    1.39 -static unsigned int (*ALSA_snd_pcm_hw_params_set_periods_near)
    1.40 -  (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int, int *);
    1.41 +static int (*ALSA_snd_pcm_hw_params_set_periods_near)
    1.42 +  (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
    1.43  static int (*ALSA_snd_pcm_hw_params_get_periods) (snd_pcm_hw_params_t *);
    1.44  static int (*ALSA_snd_pcm_hw_params) (snd_pcm_t *, snd_pcm_hw_params_t *);
    1.45  static int (*ALSA_snd_pcm_sw_params_current) (snd_pcm_t *,
    1.46 @@ -92,22 +94,10 @@
    1.47  static int
    1.48  load_alsa_sym(const char *fn, void **addr)
    1.49  {
    1.50 -    /*
    1.51 -     * !!! FIXME:
    1.52 -     * Eventually, this will deal with fallbacks, version changes, and
    1.53 -     *  missing symbols we can workaround. But for now, it doesn't.
    1.54 -     */
    1.55 -
    1.56 -#if HAVE_DLVSYM
    1.57 -    *addr = dlvsym(alsa_handle, fn, "ALSA_0.9");
    1.58 -    if (*addr == NULL)
    1.59 -#endif
    1.60 -    {
    1.61 -        *addr = dlsym(alsa_handle, fn);
    1.62 -        if (*addr == NULL) {
    1.63 -            SDL_SetError("dlsym('%s') failed: %s", fn, strerror(errno));
    1.64 -            return 0;
    1.65 -        }
    1.66 +    *addr = SDL_LoadFunction(alsa_handle, fn);
    1.67 +    if (*addr == NULL) {
    1.68 +        /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
    1.69 +        return 0;
    1.70      }
    1.71  
    1.72      return 1;
    1.73 @@ -159,7 +149,7 @@
    1.74  UnloadALSALibrary(void)
    1.75  {
    1.76      if (alsa_handle != NULL) {
    1.77 -        dlclose(alsa_handle);
    1.78 +		SDL_UnloadObject(alsa_handle);
    1.79          alsa_handle = NULL;
    1.80      }
    1.81  }
    1.82 @@ -169,11 +159,10 @@
    1.83  {
    1.84      int retval = 0;
    1.85      if (alsa_handle == NULL) {
    1.86 -        alsa_handle = dlopen(alsa_library, RTLD_NOW);
    1.87 +        alsa_handle = SDL_LoadObject(alsa_library);
    1.88          if (alsa_handle == NULL) {
    1.89              retval = -1;
    1.90 -            SDL_SetError("ALSA: dlopen('%s') failed: %s\n",
    1.91 -                         alsa_library, strerror(errno));
    1.92 +            /* Don't call SDL_SetError(): SDL_LoadObject already did. */
    1.93          } else {
    1.94              retval = load_alsa_syms();
    1.95              if (retval < 0) {
    1.96 @@ -380,6 +369,9 @@
    1.97      snd_pcm_format_t format = 0;
    1.98      snd_pcm_uframes_t frames = 0;
    1.99      SDL_AudioFormat test_format = 0;
   1.100 +    unsigned int rate = 0;
   1.101 +    unsigned int periods = 0;
   1.102 +    unsigned int channels = 0;
   1.103  
   1.104      /* Initialize all variables that we clean on shutdown */
   1.105      this->hidden = (struct SDL_PrivateAudioData *)
   1.106 @@ -483,33 +475,44 @@
   1.107      /* Set the number of channels */
   1.108      status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams,
   1.109                                                   this->spec.channels);
   1.110 +    channels = this->spec.channels;
   1.111      if (status < 0) {
   1.112 -        status = ALSA_snd_pcm_hw_params_get_channels(hwparams);
   1.113 -        if ((status <= 0) || (status > 2)) {
   1.114 +        status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
   1.115 +        if (status < 0) {
   1.116              ALSA_CloseDevice(this);
   1.117              SDL_SetError("ALSA: Couldn't set audio channels");
   1.118              return 0;
   1.119          }
   1.120 -        this->spec.channels = status;
   1.121 +        this->spec.channels = channels;
   1.122      }
   1.123  
   1.124      /* Set the audio rate */
   1.125 +    rate = this->spec.freq;
   1.126      status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
   1.127 -                                                  this->spec.freq, NULL);
   1.128 +                                                  &rate, NULL);
   1.129      if (status < 0) {
   1.130          ALSA_CloseDevice(this);
   1.131          SDL_SetError("ALSA: Couldn't set audio frequency: %s",
   1.132                       ALSA_snd_strerror(status));
   1.133          return 0;
   1.134      }
   1.135 -    this->spec.freq = status;
   1.136 +    this->spec.freq = rate;
   1.137  
   1.138      /* Set the buffer size, in samples */
   1.139      frames = this->spec.samples;
   1.140 -    frames = ALSA_snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams,
   1.141 -                                                         frames, NULL);
   1.142 +    status = ALSA_snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams,
   1.143 +                                                         &frames, NULL);
   1.144 +    if ( status < 0 ) {
   1.145 +        ALSA_CloseDevice(this);
   1.146 +        SDL_SetError("ALSA: Couldn't set audio frequency: %s",
   1.147 +                     ALSA_snd_strerror(status));
   1.148 +        return(-1);
   1.149 +    }
   1.150      this->spec.samples = frames;
   1.151 -    ALSA_snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, 2, NULL);
   1.152 +
   1.153 +    periods = 2;
   1.154 +    ALSA_snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams,
   1.155 +                                            &periods, NULL);
   1.156  
   1.157      /* "set" the hardware with the desired parameters */
   1.158      status = ALSA_snd_pcm_hw_params(pcm_handle, hwparams);
     2.1 --- a/src/audio/alsa/SDL_alsa_audio.h	Sat Oct 10 06:51:42 2009 +0000
     2.2 +++ b/src/audio/alsa/SDL_alsa_audio.h	Sat Oct 10 07:34:15 2009 +0000
     2.3 @@ -24,8 +24,6 @@
     2.4  #ifndef _ALSA_PCM_audio_h
     2.5  #define _ALSA_PCM_audio_h
     2.6  
     2.7 -#define ALSA_PCM_OLD_HW_PARAMS_API
     2.8 -#define ALSA_PCM_OLD_SW_PARAMS_API
     2.9  #include <alsa/asoundlib.h>
    2.10  
    2.11  #include "../SDL_sysaudio.h"