aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2009-08-27 01:47:41 -0700
committerChris Robinson <[email protected]>2009-08-27 01:47:41 -0700
commit45dc8048193162edbb886921cfcf2955c5232626 (patch)
treed99e7a4cb49400b5395be15c69c34d3ad59c989e /Alc
parent81db01ebf1d6b608339b5288785f3c514dbcff27 (diff)
Store copies of the device names in the individual backends
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c18
-rw-r--r--Alc/alsa.c97
-rw-r--r--Alc/dsound.c46
-rw-r--r--Alc/oss.c8
-rw-r--r--Alc/portaudio.c4
-rw-r--r--Alc/pulseaudio.c10
-rw-r--r--Alc/solaris.c4
-rw-r--r--Alc/wave.c4
-rw-r--r--Alc/winmm.c30
9 files changed, 147 insertions, 74 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index a47a03d2..588ba903 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -351,43 +351,37 @@ static void InitAL(void)
}
}
-ALCchar *AppendDeviceList(char *name)
+void AppendDeviceList(const ALCchar *name)
{
static size_t pos;
- ALCchar *ret = alcDeviceList+pos;
if(pos >= sizeof(alcDeviceList))
{
AL_PRINT("Not enough room to add %s!\n", name);
- return alcDeviceList + sizeof(alcDeviceList) - 1;
+ return;
}
pos += snprintf(alcDeviceList+pos, sizeof(alcDeviceList)-pos-1, "%s", name) + 1;
- return ret;
}
-ALCchar *AppendAllDeviceList(char *name)
+void AppendAllDeviceList(const ALCchar *name)
{
static size_t pos;
- ALCchar *ret = alcAllDeviceList+pos;
if(pos >= sizeof(alcAllDeviceList))
{
AL_PRINT("Not enough room to add %s!\n", name);
- return alcAllDeviceList + sizeof(alcAllDeviceList) - 1;
+ return;
}
pos += snprintf(alcAllDeviceList+pos, sizeof(alcAllDeviceList)-pos-1, "%s", name) + 1;
- return ret;
}
-ALCchar *AppendCaptureDeviceList(char *name)
+void AppendCaptureDeviceList(const ALCchar *name)
{
static size_t pos;
- ALCchar *ret = alcCaptureDeviceList+pos;
if(pos >= sizeof(alcCaptureDeviceList))
{
AL_PRINT("Not enough room to add %s!\n", name);
- return alcCaptureDeviceList + sizeof(alcCaptureDeviceList) - 1;
+ return;
}
pos += snprintf(alcCaptureDeviceList+pos, sizeof(alcCaptureDeviceList)-pos-1, "%s", name) + 1;
- return ret;
}
/*
diff --git a/Alc/alsa.c b/Alc/alsa.c
index 35f7ae8a..89b8bbae 100644
--- a/Alc/alsa.c
+++ b/Alc/alsa.c
@@ -108,11 +108,13 @@ MAKE_FUNC(snd_ctl_card_info_get_name);
MAKE_FUNC(snd_card_next);
#undef MAKE_FUNC
-#define MAX_ALL_DEVICES 32
-static ALCchar *alsaDevice;
-static DevMap allDevNameMap[MAX_ALL_DEVICES];
-static DevMap allCaptureDevNameMap[MAX_ALL_DEVICES];
+static const ALCchar alsaDevice[] = "ALSA Software";
+static DevMap *allDevNameMap;
+static ALuint numDevNames;
+static DevMap *allCaptureDevNameMap;
+static ALuint numCaptureDevNames;
+
static int xrun_recovery(snd_pcm_t *handle, int err)
{
@@ -363,7 +365,7 @@ static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceNam
{
size_t idx;
- for(idx = 0;idx < MAX_ALL_DEVICES;idx++)
+ for(idx = 0;idx < numDevNames;idx++)
{
if(allDevNameMap[idx].name &&
strcmp(deviceName, allDevNameMap[idx].name) == 0)
@@ -597,7 +599,7 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam
{
size_t idx;
- for(idx = 0;idx < MAX_ALL_DEVICES;idx++)
+ for(idx = 0;idx < numCaptureDevNames;idx++)
{
if(allCaptureDevNameMap[idx].name &&
strcmp(deviceName, allCaptureDevNameMap[idx].name) == 0)
@@ -885,8 +887,10 @@ LOAD_FUNC(snd_card_next);
if(psnd_card_next(&card) < 0 || card < 0)
AL_PRINT("no playback cards found...\n");
- alsaDevice = AppendDeviceList("ALSA Software");
- allDevNameMap[0].name = AppendAllDeviceList("ALSA Software on default");
+ AppendDeviceList(alsaDevice);
+ allDevNameMap = malloc(sizeof(DevMap) * 1);
+ allDevNameMap[0].name = strdup("ALSA Software on default");
+ AppendAllDeviceList(allDevNameMap[0].name);
while (card >= 0) {
sprintf(name, "hw:%d", card);
@@ -901,8 +905,9 @@ LOAD_FUNC(snd_card_next);
}
dev = -1;
- while (idx < MAX_ALL_DEVICES) {
+ while(1) {
const char *cname, *dname;
+ void *temp;
if (psnd_ctl_pcm_next_device(handle, &dev)<0)
AL_PRINT("snd_ctl_pcm_next_device failed\n");
@@ -918,14 +923,20 @@ LOAD_FUNC(snd_card_next);
continue;
}
- cname = psnd_ctl_card_info_get_name(info);
- dname = psnd_pcm_info_get_name(pcminfo);
- snprintf(name, sizeof(name), "ALSA Software on %s [%s] (hw:%d,%d)",
- cname, dname, card, dev);
- allDevNameMap[idx].name = AppendAllDeviceList(name);
- allDevNameMap[idx].card = card;
- allDevNameMap[idx].dev = dev;
- idx++;
+ temp = realloc(allDevNameMap, sizeof(DevMap) * (idx+1));
+ if(temp)
+ {
+ allDevNameMap = temp;
+ cname = psnd_ctl_card_info_get_name(info);
+ dname = psnd_pcm_info_get_name(pcminfo);
+ snprintf(name, sizeof(name), "ALSA Software on %s [%s] (hw:%d,%d)",
+ cname, dname, card, dev);
+ AppendAllDeviceList(name);
+ allDevNameMap[idx].name = strdup(name);
+ allDevNameMap[idx].card = card;
+ allDevNameMap[idx].dev = dev;
+ idx++;
+ }
}
psnd_ctl_close(handle);
next_card:
@@ -934,6 +945,7 @@ next_card:
break;
}
}
+ numDevNames = idx;
stream = SND_PCM_STREAM_CAPTURE;
@@ -946,9 +958,11 @@ next_card:
return;
}
- allCaptureDevNameMap[0].name = AppendCaptureDeviceList("ALSA Capture on default");
- idx = 1;
+ allCaptureDevNameMap = malloc(sizeof(DevMap) * 1);
+ allCaptureDevNameMap[0].name = strdup("ALSA Capture on default");
+ AppendCaptureDeviceList(allCaptureDevNameMap[0].name);
+ idx = 1;
while (card >= 0) {
sprintf(name, "hw:%d", card);
handle = NULL;
@@ -961,8 +975,9 @@ next_card:
else if (err >= 0)
{
dev = -1;
- while (idx < MAX_ALL_DEVICES) {
+ while(1) {
const char *cname, *dname;
+ void *temp;
if (psnd_ctl_pcm_next_device(handle, &dev)<0)
AL_PRINT("snd_ctl_pcm_next_device failed\n");
@@ -977,14 +992,20 @@ next_card:
continue;
}
- cname = psnd_ctl_card_info_get_name(info);
- dname = psnd_pcm_info_get_name(pcminfo);
- snprintf(name, sizeof(name), "ALSA Capture on %s [%s] (hw:%d,%d)",
- cname, dname, card, dev);
- allCaptureDevNameMap[idx].name = AppendCaptureDeviceList(name);
- allCaptureDevNameMap[idx].card = card;
- allCaptureDevNameMap[idx].dev = dev;
- idx++;
+ temp = realloc(allCaptureDevNameMap, sizeof(DevMap) * (idx+1));
+ if(temp)
+ {
+ allCaptureDevNameMap = temp;
+ cname = psnd_ctl_card_info_get_name(info);
+ dname = psnd_pcm_info_get_name(pcminfo);
+ snprintf(name, sizeof(name), "ALSA Capture on %s [%s] (hw:%d,%d)",
+ cname, dname, card, dev);
+ AppendCaptureDeviceList(name);
+ allCaptureDevNameMap[idx].name = strdup(name);
+ allCaptureDevNameMap[idx].card = card;
+ allCaptureDevNameMap[idx].dev = dev;
+ idx++;
+ }
}
}
if(handle) psnd_ctl_close(handle);
@@ -993,10 +1014,30 @@ next_card:
break;
}
}
+ numCaptureDevNames = idx;
+
psnd_pcm_info_free(pcminfo);
psnd_ctl_card_info_free(info);
}
void alc_alsa_deinit(void)
{
+ ALuint i;
+
+ for(i = 0;i < numDevNames;++i)
+ free(allDevNameMap[i].name);
+ free(allDevNameMap);
+ allDevNameMap = NULL;
+ numDevNames = 0;
+
+ for(i = 0;i < numCaptureDevNames;++i)
+ free(allCaptureDevNameMap[i].name);
+ free(allCaptureDevNameMap);
+ allCaptureDevNameMap = NULL;
+ numCaptureDevNames = 0;
+
+#ifdef HAVE_DLFCN_H
+ dlclose(alsa_handle);
+ alsa_handle = NULL;
+#endif
}
diff --git a/Alc/dsound.c b/Alc/dsound.c
index d50ecadb..644407b8 100644
--- a/Alc/dsound.c
+++ b/Alc/dsound.c
@@ -69,7 +69,8 @@ typedef struct {
ALCchar *name;
GUID guid;
} DevMap;
-static DevMap DeviceList[16];
+static DevMap *DeviceList;
+static ALuint NumDevices;
static ALuint DSoundProc(ALvoid *ptr)
@@ -447,26 +448,33 @@ BackendFuncs DSoundFuncs = {
static BOOL CALLBACK DSoundEnumDevices(LPGUID guid, LPCSTR desc, LPCSTR drvname, LPVOID data)
{
- size_t *iter = data;
+ (void)data;
(void)drvname;
if(guid)
{
char str[128];
- snprintf(str, sizeof(str), "DirectSound Software on %s", desc);
- DeviceList[*iter].name = AppendAllDeviceList(str);
- DeviceList[*iter].guid = *guid;
- (*iter)++;
+ void *temp;
+
+ temp = realloc(DeviceList, sizeof(DevMap) * (NumDevices+1));
+ if(temp)
+ {
+ DeviceList = temp;
+
+ snprintf(str, sizeof(str), "DirectSound Software on %s", desc);
+ AppendAllDeviceList(str);
+
+ DeviceList[NumDevices].name = strdup(str);
+ DeviceList[NumDevices].guid = *guid;
+ NumDevices++;
+ }
}
- else
- DeviceList[0].name = AppendDeviceList("DirectSound Software");
return TRUE;
}
void alcDSoundInit(BackendFuncs *FuncList)
{
- size_t iter = 1;
HRESULT hr;
*FuncList = DSoundFuncs;
@@ -501,11 +509,29 @@ LOAD_FUNC(DirectSoundEnumerateA);
num_frags = GetConfigValueInt("dsound", "periods", 4);
if(num_frags < 2) num_frags = 2;
- hr = pDirectSoundEnumerateA(DSoundEnumDevices, &iter);
+ DeviceList = malloc(sizeof(DevMap) * 1);
+ DeviceList[0].name = strdup("DirectSound Software");
+ NumDevices = 1;
+
+ AppendDeviceList(DeviceList[0].name);
+
+ hr = pDirectSoundEnumerateA(DSoundEnumDevices, NULL);
if(FAILED(hr))
AL_PRINT("Error enumerating DirectSound devices (%#x)!\n", (unsigned int)hr);
}
void alcDSoundDeinit(void)
{
+ ALuint i;
+
+ for(i = 0;i < NumDevices;++i)
+ free(DeviceList[i].name);
+ free(DeviceList);
+ DeviceList = NULL;
+ NumDevices = 0;
+
+#ifdef _WIN32
+ FreeLibrary(ds_handle);
+ ds_handle = NULL;
+#endif
}
diff --git a/Alc/oss.c b/Alc/oss.c
index aaa2e47a..5fe67c53 100644
--- a/Alc/oss.c
+++ b/Alc/oss.c
@@ -47,8 +47,8 @@
#define SOUND_MIXER_WRITE MIXER_WRITE
#endif
-static char *oss_device;
-static char *oss_device_capture;
+static const ALCchar oss_device[] = "OSS Software";
+static const ALCchar oss_device_capture[] = "OSS Capture";
typedef struct {
int fd;
@@ -474,10 +474,10 @@ void alc_oss_init(BackendFuncs *func_list)
{
*func_list = oss_funcs;
- oss_device = AppendDeviceList("OSS Software");
+ AppendDeviceList(oss_device);
AppendAllDeviceList(oss_device);
- oss_device_capture = AppendCaptureDeviceList("OSS Capture");
+ AppendCaptureDeviceList(oss_device_capture);
}
void alc_oss_deinit(void)
diff --git a/Alc/portaudio.c b/Alc/portaudio.c
index 01e82e73..6d1b6837 100644
--- a/Alc/portaudio.c
+++ b/Alc/portaudio.c
@@ -44,7 +44,7 @@ MAKE_FUNC(Pa_GetDefaultOutputDevice);
#undef MAKE_FUNC
-static char *pa_device;
+static const ALCchar pa_device[] = "PortAudio Software";
typedef struct {
PaStream *stream;
@@ -248,7 +248,7 @@ void alc_pa_init(BackendFuncs *func_list)
return;
}
- pa_device = AppendDeviceList("PortAudio Software");
+ AppendDeviceList(pa_device);
AppendAllDeviceList(pa_device);
}
diff --git a/Alc/pulseaudio.c b/Alc/pulseaudio.c
index dd3621c1..4bce7379 100644
--- a/Alc/pulseaudio.c
+++ b/Alc/pulseaudio.c
@@ -108,8 +108,8 @@ typedef struct {
pa_context *context;
} pulse_data;
-static char *pulse_device;
-static char *pulse_capture_device;
+static const ALCchar pulse_device[] = "PulseAudio Software";
+static const ALCchar pulse_capture_device[] = "PulseAudio Capture";
// PulseAudio Event Callbacks {{{
static void stream_state_callback(pa_stream *stream, void *pdata) //{{{
@@ -205,7 +205,7 @@ static void stream_read_callback(pa_stream *stream, size_t length, void *pdata)
} //}}}
//}}}
-static ALCboolean pulse_open(ALCdevice *device, ALCchar *device_name) //{{{
+static ALCboolean pulse_open(ALCdevice *device, const ALCchar *device_name) //{{{
{
pulse_data *data = ppa_xmalloc0(sizeof(pulse_data));
@@ -696,10 +696,10 @@ LOAD_FUNC(pa_threaded_mainloop_lock);
#undef LOAD_FUNC
- pulse_device = AppendDeviceList("PulseAudio Software");
+ AppendDeviceList(pulse_device);
AppendAllDeviceList(pulse_device);
- pulse_capture_device = AppendCaptureDeviceList("PulseAudio Capture");
+ AppendCaptureDeviceList(pulse_capture_device);
} //}}}
void alc_pulse_deinit(void) //{{{
diff --git a/Alc/solaris.c b/Alc/solaris.c
index 5f0ebf17..5c7716f6 100644
--- a/Alc/solaris.c
+++ b/Alc/solaris.c
@@ -37,7 +37,7 @@
#include <sys/audioio.h>
-static char *solaris_device;
+static const ALCchar solaris_device[] = "Solaris Software";
typedef struct {
int fd;
@@ -279,7 +279,7 @@ void alc_solaris_init(BackendFuncs *func_list)
{
*func_list = solaris_funcs;
- solaris_device = AppendDeviceList("Solaris Software");
+ AppendDeviceList(solaris_device);
AppendAllDeviceList(solaris_device);
}
diff --git a/Alc/wave.c b/Alc/wave.c
index da98113e..578b769e 100644
--- a/Alc/wave.c
+++ b/Alc/wave.c
@@ -40,7 +40,7 @@ typedef struct {
} wave_data;
-static ALCchar *waveDevice;
+static const ALCchar waveDevice[] = "Wave File Writer";
static ALuint WaveProc(ALvoid *ptr)
@@ -367,7 +367,7 @@ void alc_wave_init(BackendFuncs *func_list)
{
*func_list = wave_funcs;
- waveDevice = AppendDeviceList("Wave File Writer");
+ AppendDeviceList(waveDevice);
AppendAllDeviceList(waveDevice);
}
diff --git a/Alc/winmm.c b/Alc/winmm.c
index 9b16b9eb..3b226f29 100644
--- a/Alc/winmm.c
+++ b/Alc/winmm.c
@@ -50,7 +50,8 @@ typedef struct {
} WinMMData;
-static ALCchar *CaptureDeviceList[16];
+static ALCchar **CaptureDeviceList;
+static ALuint NumCaptureDevices;
/*
WaveInProc
@@ -181,12 +182,12 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName
WinMMData *pData = NULL;
ALint lDeviceID = 0;
ALint lBufferSize;
- ALint i;
+ ALuint i;
// Find the Device ID matching the deviceName if valid
if (deviceName)
{
- for(i = 0;CaptureDeviceList[i];i++)
+ for(i = 0;i < NumCaptureDevices;i++)
{
if (!strcmp(deviceName, CaptureDeviceList[i]))
{
@@ -194,7 +195,7 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName
break;
}
}
- if(!CaptureDeviceList[i])
+ if(i == NumCaptureDevices)
return ALC_FALSE;
}
pDevice->szDeviceName = CaptureDeviceList[lDeviceID];
@@ -423,24 +424,35 @@ BackendFuncs WinMMFuncs = {
void alcWinMMInit(BackendFuncs *FuncList)
{
- ALint lNumDevs;
- ALint lLoop;
+ ALuint lLoop;
*FuncList = WinMMFuncs;
- lNumDevs = waveInGetNumDevs();
- for (lLoop = 0; lLoop < lNumDevs; lLoop++)
+ NumCaptureDevices = waveInGetNumDevs();
+ CaptureDeviceList = malloc(sizeof(ALCchar*) * NumCaptureDevices);
+ for(lLoop = 0; lLoop < NumCaptureDevices; lLoop++)
{
WAVEINCAPS WaveInCaps;
+
+ CaptureDeviceList[lLoop] = strdup("");
if(waveInGetDevCaps(lLoop, &WaveInCaps, sizeof(WAVEINCAPS)) == MMSYSERR_NOERROR)
{
char name[128];
snprintf(name, sizeof(name), "WaveIn on %s", WaveInCaps.szPname);
- CaptureDeviceList[lLoop] = AppendCaptureDeviceList(name);
+ AppendCaptureDeviceList(name);
+ CaptureDeviceList[lLoop] = strdup(name);
}
}
}
void alcWinMMDeinit()
{
+ ALuint lLoop;
+
+ for(lLoop = 0; lLoop < NumCaptureDevices; lLoop++)
+ free(CaptureDeviceList[lLoop]);
+ free(CaptureDeviceList);
+ CaptureDeviceList = NULL;
+
+ NumCaptureDevices = 0;
}