diff options
author | Chris Robinson <[email protected]> | 2010-03-09 06:09:29 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-03-09 06:09:29 -0800 |
commit | 8feb089f5ca9166810cb2655356db2006cd22496 (patch) | |
tree | c998636a4749690683d471d366f52b24d5cc729e /Alc/alsa.c | |
parent | 2ba3a88ace65803393c7f4bdb1b9e158a644d05e (diff) |
Build device lists only when needed
Diffstat (limited to 'Alc/alsa.c')
-rw-r--r-- | Alc/alsa.c | 26 |
1 files changed, 20 insertions, 6 deletions
@@ -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); |