mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-01-14 17:46:17 +01:00
Cleanup alsadevicefinder
Signed-off-by: Jonas Kvinge <jonas@jkvinge.net>
This commit is contained in:
parent
e5774ffcdc
commit
f9c2801db1
@ -42,10 +42,10 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
|
||||
|
||||
QList<Device> ret;
|
||||
|
||||
//register int err;
|
||||
int result = -1;
|
||||
int card = -1;
|
||||
int dev = -1;
|
||||
int result = -1;
|
||||
|
||||
snd_ctl_card_info_t *cardinfo;
|
||||
snd_pcm_info_t *pcminfo;
|
||||
snd_ctl_t *handle;
|
||||
@ -53,29 +53,28 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
|
||||
snd_ctl_card_info_alloca(&cardinfo);
|
||||
snd_pcm_info_alloca(&pcminfo);
|
||||
|
||||
card = -1;
|
||||
|
||||
snd_pcm_stream_name(SND_PCM_STREAM_PLAYBACK);
|
||||
|
||||
while (true) {
|
||||
|
||||
result = snd_card_next(&card);
|
||||
if (result < 0) {
|
||||
qLog(Error) << "Unable to get soundcard: " << snd_strerror(result);
|
||||
qLog(Error) << "Unable to get soundcard:" << snd_strerror(result);
|
||||
return ret;
|
||||
}
|
||||
if (card < 0) return ret;
|
||||
|
||||
char name[32];
|
||||
sprintf(name, "hw:%d", card);
|
||||
|
||||
result = snd_ctl_open(&handle, name, 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;
|
||||
}
|
||||
result = snd_ctl_card_info(handle, cardinfo);
|
||||
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);
|
||||
continue;
|
||||
}
|
||||
@ -85,7 +84,7 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
|
||||
|
||||
result = snd_ctl_pcm_next_device(handle, &dev);
|
||||
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;
|
||||
}
|
||||
if (dev < 0) break;
|
||||
@ -93,14 +92,13 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
|
||||
snd_pcm_info_set_device(pcminfo, dev);
|
||||
snd_pcm_info_set_subdevice(pcminfo, 0);
|
||||
snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK);
|
||||
|
||||
result = snd_ctl_pcm_info(handle, pcminfo);
|
||||
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;
|
||||
}
|
||||
|
||||
snd_pcm_info_get_name(pcminfo);
|
||||
|
||||
Device device;
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user