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
|
#ifdef HAVE_ALSA
|
||||||
void **hints, **n;
|
void **hints, **n;
|
||||||
if (snd_device_name_hint(-1, "pcm", &hints) < 0) {
|
int card = -1;
|
||||||
qWarning()<<"no alsa devices available";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
n = hints;
|
|
||||||
|
|
||||||
|
while (snd_card_next(&card) == 0 && card >= 0) {
|
||||||
|
if (snd_device_name_hint(card, "pcm", &hints) < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
n = hints;
|
||||||
while (*n != NULL) {
|
while (*n != NULL) {
|
||||||
char *name = snd_device_name_get_hint(*n, "NAME");
|
char *name = snd_device_name_get_hint(*n, "NAME");
|
||||||
char *descr = snd_device_name_get_hint(*n, "DESC");
|
char *descr = snd_device_name_get_hint(*n, "DESC");
|
||||||
@@ -143,9 +144,11 @@ void QGstreamerAudioInputSelector::updateAlsaDevices()
|
|||||||
free(descr);
|
free(descr);
|
||||||
if (io != NULL)
|
if (io != NULL)
|
||||||
free(io);
|
free(io);
|
||||||
n++;
|
++n;
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_device_name_free_hint(hints);
|
snd_device_name_free_hint(hints);
|
||||||
|
}
|
||||||
#endif
|
#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)
|
#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
|
||||||
// Create a list of all current audio devices that support mode
|
// Create a list of all current audio devices that support mode
|
||||||
void **hints, **n;
|
void **hints;
|
||||||
char *name, *descr, *io;
|
char *name, *descr, *io;
|
||||||
|
int card = -1;
|
||||||
if(snd_device_name_hint(-1, "pcm", &hints) < 0) {
|
|
||||||
qWarning() << "no alsa devices available";
|
|
||||||
return devices;
|
|
||||||
}
|
|
||||||
n = hints;
|
|
||||||
|
|
||||||
if(mode == QAudio::AudioInput) {
|
if(mode == QAudio::AudioInput) {
|
||||||
filter = "Input";
|
filter = "Input";
|
||||||
@@ -360,6 +355,11 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
|
|||||||
filter = "Output";
|
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) {
|
while (*n != NULL) {
|
||||||
name = snd_device_name_get_hint(*n, "NAME");
|
name = snd_device_name_get_hint(*n, "NAME");
|
||||||
if (name != 0 && qstrcmp(name, "null") != 0) {
|
if (name != 0 && qstrcmp(name, "null") != 0) {
|
||||||
@@ -381,7 +381,9 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
|
|||||||
free(name);
|
free(name);
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_device_name_free_hint(hints);
|
snd_device_name_free_hint(hints);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
char* name;
|
char* name;
|
||||||
@@ -422,14 +424,15 @@ void QAudioDeviceInfoInternal::checkSurround()
|
|||||||
surround51 = false;
|
surround51 = false;
|
||||||
surround71 = false;
|
surround71 = false;
|
||||||
|
|
||||||
void **hints, **n;
|
void **hints;
|
||||||
char *name, *descr, *io;
|
char *name, *descr, *io;
|
||||||
|
int card = -1;
|
||||||
|
|
||||||
if(snd_device_name_hint(-1, "pcm", &hints) < 0)
|
while (snd_card_next(&card) == 0 && card >= 0) {
|
||||||
return;
|
if (snd_device_name_hint(card, "pcm", &hints) < 0)
|
||||||
|
continue;
|
||||||
n = hints;
|
|
||||||
|
|
||||||
|
void **n = hints;
|
||||||
while (*n != NULL) {
|
while (*n != NULL) {
|
||||||
name = snd_device_name_get_hint(*n, "NAME");
|
name = snd_device_name_get_hint(*n, "NAME");
|
||||||
descr = snd_device_name_get_hint(*n, "DESC");
|
descr = snd_device_name_get_hint(*n, "DESC");
|
||||||
@@ -453,7 +456,9 @@ void QAudioDeviceInfoInternal::checkSurround()
|
|||||||
free(io);
|
free(io);
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_device_name_free_hint(hints);
|
snd_device_name_free_hint(hints);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|||||||
Reference in New Issue
Block a user