Alsa: fix crash when detecting devices.
Some old versions of Alsa crash when snd_device_name_hint(-1, ...) is called. This patch works around the problem by iterating manually over all the available sound cards. Change-Id: Ic380a371acc15013d137553ff30d68bed5af664e Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
67b86a9fbd
commit
0ab81ef59f
@@ -119,12 +119,13 @@ void QGstreamerAudioInputSelector::updateAlsaDevices()
|
||||
{
|
||||
#ifdef HAVE_ALSA
|
||||
void **hints, **n;
|
||||
if (snd_device_name_hint(-1, "pcm", &hints) < 0) {
|
||||
qWarning()<<"no alsa devices available";
|
||||
return;
|
||||
}
|
||||
n = hints;
|
||||
int card = -1;
|
||||
|
||||
while (snd_card_next(&card) == 0 && card >= 0) {
|
||||
if (snd_device_name_hint(card, "pcm", &hints) < 0)
|
||||
continue;
|
||||
|
||||
n = hints;
|
||||
while (*n != NULL) {
|
||||
char *name = snd_device_name_get_hint(*n, "NAME");
|
||||
char *descr = snd_device_name_get_hint(*n, "DESC");
|
||||
@@ -143,9 +144,11 @@ void QGstreamerAudioInputSelector::updateAlsaDevices()
|
||||
free(descr);
|
||||
if (io != NULL)
|
||||
free(io);
|
||||
n++;
|
||||
++n;
|
||||
}
|
||||
|
||||
snd_device_name_free_hint(hints);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -345,14 +345,9 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
|
||||
|
||||
#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
|
||||
// Create a list of all current audio devices that support mode
|
||||
void **hints, **n;
|
||||
void **hints;
|
||||
char *name, *descr, *io;
|
||||
|
||||
if(snd_device_name_hint(-1, "pcm", &hints) < 0) {
|
||||
qWarning() << "no alsa devices available";
|
||||
return devices;
|
||||
}
|
||||
n = hints;
|
||||
int card = -1;
|
||||
|
||||
if(mode == QAudio::AudioInput) {
|
||||
filter = "Input";
|
||||
@@ -360,6 +355,11 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
|
||||
filter = "Output";
|
||||
}
|
||||
|
||||
while (snd_card_next(&card) == 0 && card >= 0) {
|
||||
if (snd_device_name_hint(card, "pcm", &hints) < 0)
|
||||
continue;
|
||||
|
||||
void **n = hints;
|
||||
while (*n != NULL) {
|
||||
name = snd_device_name_get_hint(*n, "NAME");
|
||||
if (name != 0 && qstrcmp(name, "null") != 0) {
|
||||
@@ -381,7 +381,9 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
|
||||
free(name);
|
||||
++n;
|
||||
}
|
||||
|
||||
snd_device_name_free_hint(hints);
|
||||
}
|
||||
#else
|
||||
int idx = 0;
|
||||
char* name;
|
||||
@@ -422,14 +424,15 @@ void QAudioDeviceInfoInternal::checkSurround()
|
||||
surround51 = false;
|
||||
surround71 = false;
|
||||
|
||||
void **hints, **n;
|
||||
void **hints;
|
||||
char *name, *descr, *io;
|
||||
int card = -1;
|
||||
|
||||
if(snd_device_name_hint(-1, "pcm", &hints) < 0)
|
||||
return;
|
||||
|
||||
n = hints;
|
||||
while (snd_card_next(&card) == 0 && card >= 0) {
|
||||
if (snd_device_name_hint(card, "pcm", &hints) < 0)
|
||||
continue;
|
||||
|
||||
void **n = hints;
|
||||
while (*n != NULL) {
|
||||
name = snd_device_name_get_hint(*n, "NAME");
|
||||
descr = snd_device_name_get_hint(*n, "DESC");
|
||||
@@ -453,7 +456,9 @@ void QAudioDeviceInfoInternal::checkSurround()
|
||||
free(io);
|
||||
++n;
|
||||
}
|
||||
|
||||
snd_device_name_free_hint(hints);
|
||||
}
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user