change alsa pcm device discovery to find more than 1 device per card.

Original commit message from CVS:
change alsa pcm device discovery to find more than 1 device per card.
code review by Ronald.
This commit is contained in:
Stéphane Loeuillet 2004-04-30 01:20:54 +00:00
parent f9b2782a96
commit a8192d32b3
3 changed files with 65 additions and 17 deletions

View file

@ -1,3 +1,10 @@
2004-04-29 Stephane Loeuillet <stephane.loeuillet@tiscali.fr>
* ext/alsa/gstalsa.c : (gst_alsa_class_probe_devices)
* ext/alsa/gstalsa.h :
change alsa pcm device discovery to find more than 1 device
per card. code review by Ronald.
2004-04-29 David Schleef <ds@schleef.org>
* sys/oss/gstosselement.c: (gst_osselement_rate_probe_check):

View file

@ -312,6 +312,61 @@ gst_alsa_probe_get_properties (GstPropertyProbe * probe)
return list;
}
static void
device_list (snd_pcm_stream_t stream, GstAlsaClass * klass)
{
snd_ctl_t *handle;
int card, err, dev;
snd_ctl_card_info_t *info;
snd_pcm_info_t *pcminfo;
snd_ctl_card_info_alloca (&info);
snd_pcm_info_alloca (&pcminfo);
card = -1;
if (snd_card_next (&card) < 0 || card < 0) {
/* no soundcard found */
return;
}
while (card >= 0) {
char name[32];
sprintf (name, "hw:%d", card);
if ((err = snd_ctl_open (&handle, name, 0)) < 0) {
goto next_card;
}
if ((err = snd_ctl_card_info (handle, info)) < 0) {
snd_ctl_close (handle);
goto next_card;
}
dev = -1;
while (1) {
gchar *gst_device;
snd_ctl_pcm_next_device (handle, &dev);
if (dev < 0)
break;
snd_pcm_info_set_device (pcminfo, dev);
snd_pcm_info_set_subdevice (pcminfo, 0);
snd_pcm_info_set_stream (pcminfo, stream);
if ((err = snd_ctl_pcm_info (handle, pcminfo)) < 0) {
continue;
}
gst_device = g_strdup_printf ("hw:%d,%d", card, dev);
klass->devices = g_list_append (klass->devices, gst_device);
}
snd_ctl_close (handle);
next_card:
if (snd_card_next (&card) < 0) {
break;
}
}
}
static gboolean
gst_alsa_class_probe_devices (GstAlsaClass * klass, gboolean check)
{
@ -322,10 +377,6 @@ gst_alsa_class_probe_devices (GstAlsaClass * klass, gboolean check)
* do function-wise look-ups. */
if (!init && !check) {
#define MAX_DEVICES 16 /* random number */
gint num, res;
gchar *dev;
snd_pcm_t *pcm;
snd_pcm_stream_t mode = 0;
const GList *templates;
@ -339,19 +390,7 @@ gst_alsa_class_probe_devices (GstAlsaClass * klass, gboolean check)
mode = SND_PCM_STREAM_PLAYBACK;
}
for (num = 0; num < MAX_DEVICES; num++) {
dev = g_strdup_printf ("hw:%d", num);
if (!(res = snd_pcm_open (&pcm, dev, mode, SND_PCM_NONBLOCK)) ||
res == -EBUSY) {
klass->devices = g_list_append (klass->devices, dev);
if (res != -EBUSY)
snd_pcm_close (pcm);
} else {
g_free (dev);
}
}
device_list (mode, klass);
init = TRUE;
}

View file

@ -26,6 +26,8 @@
#define ALSA_PCM_NEW_SW_PARAMS_API
#include <alsa/asoundlib.h>
#include <alsa/control.h>
#include <alsa/error.h>
#include <gst/gst.h>