Commit 885758b3 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Merged r4990:4991 from branches/SDL-1.2: ALSA 1.0 API and dlvsym() removal.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404007
parent 2e3beaf8
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <signal.h> /* For kill() */ #include <signal.h> /* For kill() */
#include <dlfcn.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
...@@ -35,6 +34,9 @@ ...@@ -35,6 +34,9 @@
#include "../SDL_audio_c.h" #include "../SDL_audio_c.h"
#include "SDL_alsa_audio.h" #include "SDL_alsa_audio.h"
#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
#include "SDL_loadso.h"
#endif
/* The tag name used by ALSA audio */ /* The tag name used by ALSA audio */
#define DRIVER_NAME "alsa" #define DRIVER_NAME "alsa"
...@@ -60,16 +62,16 @@ static int (*ALSA_snd_pcm_hw_params_set_format) ...@@ -60,16 +62,16 @@ static int (*ALSA_snd_pcm_hw_params_set_format)
(snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_t); (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_t);
static int (*ALSA_snd_pcm_hw_params_set_channels) static int (*ALSA_snd_pcm_hw_params_set_channels)
(snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int); (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int);
static int (*ALSA_snd_pcm_hw_params_get_channels) (const snd_pcm_hw_params_t static int (*ALSA_snd_pcm_hw_params_set_rate_near)
*); (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
static unsigned int (*ALSA_snd_pcm_hw_params_set_rate_near) static int (*ALSA_snd_pcm_hw_params_set_period_size_near)
(snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int, int *); (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t *, int *);
static snd_pcm_uframes_t(*ALSA_snd_pcm_hw_params_set_period_size_near) static int (*ALSA_snd_pcm_hw_params_get_channels)
(snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t, int *); (const snd_pcm_hw_params_t *, unsigned int *);
static snd_pcm_sframes_t(*ALSA_snd_pcm_hw_params_get_period_size) static snd_pcm_sframes_t(*ALSA_snd_pcm_hw_params_get_period_size)
(const snd_pcm_hw_params_t *); (const snd_pcm_hw_params_t *);
static unsigned int (*ALSA_snd_pcm_hw_params_set_periods_near) static int (*ALSA_snd_pcm_hw_params_set_periods_near)
(snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int, int *); (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
static int (*ALSA_snd_pcm_hw_params_get_periods) (snd_pcm_hw_params_t *); static int (*ALSA_snd_pcm_hw_params_get_periods) (snd_pcm_hw_params_t *);
static int (*ALSA_snd_pcm_hw_params) (snd_pcm_t *, snd_pcm_hw_params_t *); static int (*ALSA_snd_pcm_hw_params) (snd_pcm_t *, snd_pcm_hw_params_t *);
static int (*ALSA_snd_pcm_sw_params_current) (snd_pcm_t *, static int (*ALSA_snd_pcm_sw_params_current) (snd_pcm_t *,
...@@ -92,22 +94,10 @@ static void *alsa_handle = NULL; ...@@ -92,22 +94,10 @@ static void *alsa_handle = NULL;
static int static int
load_alsa_sym(const char *fn, void **addr) load_alsa_sym(const char *fn, void **addr)
{ {
/* *addr = SDL_LoadFunction(alsa_handle, fn);
* !!! FIXME: if (*addr == NULL) {
* Eventually, this will deal with fallbacks, version changes, and /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
* missing symbols we can workaround. But for now, it doesn't. return 0;
*/
#if HAVE_DLVSYM
*addr = dlvsym(alsa_handle, fn, "ALSA_0.9");
if (*addr == NULL)
#endif
{
*addr = dlsym(alsa_handle, fn);
if (*addr == NULL) {
SDL_SetError("dlsym('%s') failed: %s", fn, strerror(errno));
return 0;
}
} }
return 1; return 1;
...@@ -159,7 +149,7 @@ static void ...@@ -159,7 +149,7 @@ static void
UnloadALSALibrary(void) UnloadALSALibrary(void)
{ {
if (alsa_handle != NULL) { if (alsa_handle != NULL) {
dlclose(alsa_handle); SDL_UnloadObject(alsa_handle);
alsa_handle = NULL; alsa_handle = NULL;
} }
} }
...@@ -169,11 +159,10 @@ LoadALSALibrary(void) ...@@ -169,11 +159,10 @@ LoadALSALibrary(void)
{ {
int retval = 0; int retval = 0;
if (alsa_handle == NULL) { if (alsa_handle == NULL) {
alsa_handle = dlopen(alsa_library, RTLD_NOW); alsa_handle = SDL_LoadObject(alsa_library);
if (alsa_handle == NULL) { if (alsa_handle == NULL) {
retval = -1; retval = -1;
SDL_SetError("ALSA: dlopen('%s') failed: %s\n", /* Don't call SDL_SetError(): SDL_LoadObject already did. */
alsa_library, strerror(errno));
} else { } else {
retval = load_alsa_syms(); retval = load_alsa_syms();
if (retval < 0) { if (retval < 0) {
...@@ -380,6 +369,9 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) ...@@ -380,6 +369,9 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
snd_pcm_format_t format = 0; snd_pcm_format_t format = 0;
snd_pcm_uframes_t frames = 0; snd_pcm_uframes_t frames = 0;
SDL_AudioFormat test_format = 0; SDL_AudioFormat test_format = 0;
unsigned int rate = 0;
unsigned int periods = 0;
unsigned int channels = 0;
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *) this->hidden = (struct SDL_PrivateAudioData *)
...@@ -483,33 +475,44 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture) ...@@ -483,33 +475,44 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
/* Set the number of channels */ /* Set the number of channels */
status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams, status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams,
this->spec.channels); this->spec.channels);
channels = this->spec.channels;
if (status < 0) { if (status < 0) {
status = ALSA_snd_pcm_hw_params_get_channels(hwparams); status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
if ((status <= 0) || (status > 2)) { if (status < 0) {
ALSA_CloseDevice(this); ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't set audio channels"); SDL_SetError("ALSA: Couldn't set audio channels");
return 0; return 0;
} }
this->spec.channels = status; this->spec.channels = channels;
} }
/* Set the audio rate */ /* Set the audio rate */
rate = this->spec.freq;
status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
this->spec.freq, NULL); &rate, NULL);
if (status < 0) { if (status < 0) {
ALSA_CloseDevice(this); ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't set audio frequency: %s", SDL_SetError("ALSA: Couldn't set audio frequency: %s",
ALSA_snd_strerror(status)); ALSA_snd_strerror(status));
return 0; return 0;
} }
this->spec.freq = status; this->spec.freq = rate;
/* Set the buffer size, in samples */ /* Set the buffer size, in samples */
frames = this->spec.samples; frames = this->spec.samples;
frames = ALSA_snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, status = ALSA_snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams,
frames, NULL); &frames, NULL);
if ( status < 0 ) {
ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't set audio frequency: %s",
ALSA_snd_strerror(status));
return(-1);
}
this->spec.samples = frames; this->spec.samples = frames;
ALSA_snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, 2, NULL);
periods = 2;
ALSA_snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams,
&periods, NULL);
/* "set" the hardware with the desired parameters */ /* "set" the hardware with the desired parameters */
status = ALSA_snd_pcm_hw_params(pcm_handle, hwparams); status = ALSA_snd_pcm_hw_params(pcm_handle, hwparams);
......
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#ifndef _ALSA_PCM_audio_h #ifndef _ALSA_PCM_audio_h
#define _ALSA_PCM_audio_h #define _ALSA_PCM_audio_h
#define ALSA_PCM_OLD_HW_PARAMS_API
#define ALSA_PCM_OLD_SW_PARAMS_API
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment