1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2025-01-28 08:09:40 +01:00

Cleanup alsadevicefinder

Signed-off-by: Jonas Kvinge <jonas@jkvinge.net>
This commit is contained in:
Jonas Kvinge 2018-05-22 22:36:32 +02:00
parent e5774ffcdc
commit f9c2801db1

View File

@ -42,10 +42,10 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
QList<Device> ret; QList<Device> ret;
//register int err; int result = -1;
int card = -1; int card = -1;
int dev = -1; int dev = -1;
int result = -1;
snd_ctl_card_info_t *cardinfo; snd_ctl_card_info_t *cardinfo;
snd_pcm_info_t *pcminfo; snd_pcm_info_t *pcminfo;
snd_ctl_t *handle; snd_ctl_t *handle;
@ -53,29 +53,28 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
snd_ctl_card_info_alloca(&cardinfo); snd_ctl_card_info_alloca(&cardinfo);
snd_pcm_info_alloca(&pcminfo); snd_pcm_info_alloca(&pcminfo);
card = -1;
snd_pcm_stream_name(SND_PCM_STREAM_PLAYBACK); snd_pcm_stream_name(SND_PCM_STREAM_PLAYBACK);
while (true) { while (true) {
result = snd_card_next(&card); result = snd_card_next(&card);
if (result < 0) { if (result < 0) {
qLog(Error) << "Unable to get soundcard: " << snd_strerror(result); qLog(Error) << "Unable to get soundcard:" << snd_strerror(result);
return ret; return ret;
} }
if (card < 0) return ret; if (card < 0) return ret;
char name[32]; char name[32];
sprintf(name, "hw:%d", card); sprintf(name, "hw:%d", card);
result = snd_ctl_open(&handle, name, 0); result = snd_ctl_open(&handle, name, 0);
if (result < 0) { if (result < 0) {
qLog(Error) << "Unable to open soundcard " << card << ": " << snd_strerror(result); qLog(Error) << "Unable to open soundcard" << card << ":" << snd_strerror(result);
continue; continue;
} }
result = snd_ctl_card_info(handle, cardinfo); result = snd_ctl_card_info(handle, cardinfo);
if (result < 0) { if (result < 0) {
qLog(Error) << "Control hardware failure for card " << card << ": " << snd_strerror(result); qLog(Error) << "Control hardware failure for card" << card << ":" << snd_strerror(result);
snd_ctl_close(handle); snd_ctl_close(handle);
continue; continue;
} }
@ -85,7 +84,7 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
result = snd_ctl_pcm_next_device(handle, &dev); result = snd_ctl_pcm_next_device(handle, &dev);
if (result < 0) { if (result < 0) {
qLog(Error) << "Unable to get PCM for card " << card << ": " << snd_strerror(result); qLog(Error) << "Unable to get PCM for card" << card << ":" << snd_strerror(result);
continue; continue;
} }
if (dev < 0) break; if (dev < 0) break;
@ -93,14 +92,13 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
snd_pcm_info_set_device(pcminfo, dev); snd_pcm_info_set_device(pcminfo, dev);
snd_pcm_info_set_subdevice(pcminfo, 0); snd_pcm_info_set_subdevice(pcminfo, 0);
snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK); snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK);
result = snd_ctl_pcm_info(handle, pcminfo); result = snd_ctl_pcm_info(handle, pcminfo);
if (result < 0) { if (result < 0) {
if (result != -ENOENT) qLog(Error) << "Unable to get control digital audio info for card " << card << ": " << snd_strerror(result); if (result != -ENOENT) qLog(Error) << "Unable to get control digital audio info for card" << card << ":" << snd_strerror(result);
continue; continue;
} }
snd_pcm_info_get_name(pcminfo);
Device device; Device device;
device.description = QString("%1 %2").arg(snd_ctl_card_info_get_name(cardinfo)).arg(snd_pcm_info_get_name(pcminfo)); device.description = QString("%1 %2").arg(snd_ctl_card_info_get_name(cardinfo)).arg(snd_pcm_info_get_name(pcminfo));
device.value = QString("hw:%1,%2").arg(card).arg(dev); device.value = QString("hw:%1,%2").arg(card).arg(dev);