aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-03-09 06:09:29 -0800
committerChris Robinson <[email protected]>2010-03-09 06:09:29 -0800
commit8feb089f5ca9166810cb2655356db2006cd22496 (patch)
treec998636a4749690683d471d366f52b24d5cc729e /Alc
parent2ba3a88ace65803393c7f4bdb1b9e158a644d05e (diff)
Build device lists only when needed
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c8
-rw-r--r--Alc/alsa.c26
-rw-r--r--Alc/dsound.c70
-rw-r--r--Alc/winmm.c3
4 files changed, 64 insertions, 43 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 40538a64..7332fd9e 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -681,9 +681,6 @@ ALCAPI ALCdevice* ALCAPIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, AL
if(deviceName && !deviceName[0])
deviceName = NULL;
- if(!alcCaptureDeviceList)
- ProbeCaptureDeviceList();
-
pDevice = malloc(sizeof(ALCdevice));
if (pDevice)
{
@@ -1689,11 +1686,6 @@ ALCAPI ALCdevice* ALCAPIENTRY alcOpenDevice(const ALCchar *deviceName)
if(deviceName && !deviceName[0])
deviceName = NULL;
- if(!alcDeviceList)
- ProbeDeviceList();
- if(!alcAllDeviceList)
- ProbeAllDeviceList();
-
device = malloc(sizeof(ALCdevice));
if (device)
{
diff --git a/Alc/alsa.c b/Alc/alsa.c
index a8893370..debab873 100644
--- a/Alc/alsa.c
+++ b/Alc/alsa.c
@@ -535,14 +535,21 @@ static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceNam
char driver[64];
int i;
+ if(!alsa_load())
+ return ALC_FALSE;
+
strncpy(driver, GetConfigValue("alsa", "device", "default"), sizeof(driver)-1);
driver[sizeof(driver)-1] = 0;
+
if(!deviceName)
deviceName = alsaDevice;
else if(strcmp(deviceName, alsaDevice) != 0)
{
size_t idx;
+ if(!allDevNameMap)
+ allDevNameMap = probe_devices(SND_PCM_STREAM_PLAYBACK, &numDevNames);
+
for(idx = 0;idx < numDevNames;idx++)
{
if(allDevNameMap[idx].name &&
@@ -554,12 +561,12 @@ static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceNam
}
}
if(idx == numDevNames)
+ {
+ alsa_unload();
return ALC_FALSE;
+ }
}
- if(!alsa_load())
- return ALC_FALSE;
-
data = (alsa_data*)calloc(1, sizeof(alsa_data));
i = psnd_pcm_open(&data->pcmHandle, driver, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
@@ -829,8 +836,15 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam
char *err;
int i;
+ if(!alsa_load())
+ return ALC_FALSE;
+
strncpy(driver, GetConfigValue("alsa", "capture", "default"), sizeof(driver)-1);
driver[sizeof(driver)-1] = 0;
+
+ if(!allCaptureDevNameMap)
+ allCaptureDevNameMap = probe_devices(SND_PCM_STREAM_CAPTURE, &numCaptureDevNames);
+
if(!deviceName)
deviceName = allCaptureDevNameMap[0].name;
else
@@ -849,12 +863,12 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam
}
}
if(idx == numCaptureDevNames)
+ {
+ alsa_unload();
return ALC_FALSE;
+ }
}
- if(!alsa_load())
- return ALC_FALSE;
-
data = (alsa_data*)calloc(1, sizeof(alsa_data));
i = psnd_pcm_open(&data->pcmHandle, driver, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
diff --git a/Alc/dsound.c b/Alc/dsound.c
index 41583525..7894585d 100644
--- a/Alc/dsound.c
+++ b/Alc/dsound.c
@@ -122,6 +122,33 @@ void DSoundUnload(void)
}
+static BOOL CALLBACK DSoundEnumDevices(LPGUID guid, LPCSTR desc, LPCSTR drvname, LPVOID data)
+{
+ (void)data;
+ (void)drvname;
+
+ if(guid)
+ {
+ char str[128];
+ void *temp;
+
+ temp = realloc(DeviceList, sizeof(DevMap) * (NumDevices+1));
+ if(temp)
+ {
+ DeviceList = temp;
+
+ snprintf(str, sizeof(str), "DirectSound Software on %s", desc);
+
+ DeviceList[NumDevices].name = strdup(str);
+ DeviceList[NumDevices].guid = *guid;
+ NumDevices++;
+ }
+ }
+
+ return TRUE;
+}
+
+
static ALuint DSoundProc(ALvoid *ptr)
{
ALCdevice *pDevice = (ALCdevice*)ptr;
@@ -208,11 +235,22 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam
LPGUID guid = NULL;
HRESULT hr;
+ if(!DSoundLoad())
+ return ALC_FALSE;
+
if(!deviceName)
deviceName = dsDevice;
else if(strcmp(deviceName, dsDevice) != 0)
{
ALuint i;
+
+ if(!DeviceList)
+ {
+ hr = pDirectSoundEnumerateA(DSoundEnumDevices, NULL);
+ if(FAILED(hr))
+ AL_PRINT("Error enumerating DirectSound devices (%#x)!\n", (unsigned int)hr);
+ }
+
for(i = 0;i < NumDevices;i++)
{
if(strcmp(deviceName, DeviceList[i].name) == 0)
@@ -222,14 +260,13 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam
}
}
if(i == NumDevices)
+ {
+ DSoundUnload();
return ALC_FALSE;
+ }
}
- if(!DSoundLoad())
- return ALC_FALSE;
-
//Initialise requested device
-
pData = calloc(1, sizeof(DSoundData));
if(!pData)
{
@@ -506,31 +543,6 @@ BackendFuncs DSoundFuncs = {
DSoundAvailableSamples
};
-static BOOL CALLBACK DSoundEnumDevices(LPGUID guid, LPCSTR desc, LPCSTR drvname, LPVOID data)
-{
- (void)data;
- (void)drvname;
-
- if(guid)
- {
- char str[128];
- void *temp;
-
- temp = realloc(DeviceList, sizeof(DevMap) * (NumDevices+1));
- if(temp)
- {
- DeviceList = temp;
-
- snprintf(str, sizeof(str), "DirectSound Software on %s", desc);
-
- DeviceList[NumDevices].name = strdup(str);
- DeviceList[NumDevices].guid = *guid;
- NumDevices++;
- }
- }
-
- return TRUE;
-}
void alcDSoundInit(BackendFuncs *FuncList)
{
diff --git a/Alc/winmm.c b/Alc/winmm.c
index 54ec2f30..8f27519e 100644
--- a/Alc/winmm.c
+++ b/Alc/winmm.c
@@ -207,6 +207,9 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName
ALint lBufferSize;
ALuint i;
+ if(!CaptureDeviceList)
+ ProbeDevices();
+
// Find the Device ID matching the deviceName if valid
if(deviceName)
{