Build device lists only when needed

This commit is contained in:
Chris Robinson 2010-03-09 06:09:29 -08:00
parent 2ba3a88ace
commit 8feb089f5c
4 changed files with 64 additions and 43 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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)
{

View File

@ -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)
{