2005-12-14 17:58:48 +00:00
|
|
|
/* Copyright (C) 2001 CodeFactory AB
|
|
|
|
* Copyright (C) 2001 Thomas Nyberg <thomas@codefactory.se>
|
|
|
|
* Copyright (C) 2001-2002 Andy Wingo <apwingo@eos.ncsu.edu>
|
|
|
|
* Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
|
|
|
* Copyright (C) 2005 Tim-Philipp Müller <tim centricular net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstalsadeviceprobe.h"
|
|
|
|
|
2011-12-21 10:58:53 +00:00
|
|
|
#if 0
|
2010-12-07 10:30:28 +00:00
|
|
|
G_LOCK_DEFINE_STATIC (probe_lock);
|
|
|
|
|
2005-12-14 17:58:48 +00:00
|
|
|
static const GList *
|
|
|
|
gst_alsa_device_property_probe_get_properties (GstPropertyProbe * probe)
|
|
|
|
{
|
|
|
|
GObjectClass *klass = G_OBJECT_GET_CLASS (probe);
|
|
|
|
static GList *list = NULL;
|
|
|
|
|
2010-12-07 10:30:28 +00:00
|
|
|
G_LOCK (probe_lock);
|
2005-12-14 17:58:48 +00:00
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
|
|
|
pspec = g_object_class_find_property (klass, "device");
|
|
|
|
list = g_list_append (NULL, pspec);
|
|
|
|
}
|
|
|
|
|
2010-12-07 10:30:28 +00:00
|
|
|
G_UNLOCK (probe_lock);
|
2005-12-14 17:58:48 +00:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2006-05-18 17:19:39 +00:00
|
|
|
static GList *
|
|
|
|
gst_alsa_get_device_list (snd_pcm_stream_t stream)
|
2005-12-14 17:58:48 +00:00
|
|
|
{
|
|
|
|
snd_ctl_t *handle;
|
2009-08-08 13:54:41 +00:00
|
|
|
int card, dev;
|
2005-12-14 17:58:48 +00:00
|
|
|
snd_ctl_card_info_t *info;
|
|
|
|
snd_pcm_info_t *pcminfo;
|
|
|
|
gboolean mixer = (stream == -1);
|
2006-05-18 17:19:39 +00:00
|
|
|
GList *list = NULL;
|
2005-12-14 17:58:48 +00:00
|
|
|
|
|
|
|
if (stream == -1)
|
|
|
|
stream = 0;
|
|
|
|
|
2007-09-16 01:56:21 +00:00
|
|
|
snd_ctl_card_info_malloc (&info);
|
|
|
|
snd_pcm_info_malloc (&pcminfo);
|
2005-12-14 17:58:48 +00:00
|
|
|
card = -1;
|
|
|
|
|
|
|
|
if (snd_card_next (&card) < 0 || card < 0) {
|
|
|
|
/* no soundcard found */
|
2008-04-24 09:27:35 +00:00
|
|
|
GST_WARNING ("No soundcard found");
|
|
|
|
goto beach;
|
2005-12-14 17:58:48 +00:00
|
|
|
}
|
2006-05-18 17:19:39 +00:00
|
|
|
|
2005-12-14 17:58:48 +00:00
|
|
|
while (card >= 0) {
|
|
|
|
gchar name[32];
|
|
|
|
|
|
|
|
g_snprintf (name, sizeof (name), "hw:%d", card);
|
2009-08-08 13:54:41 +00:00
|
|
|
if (snd_ctl_open (&handle, name, 0) < 0) {
|
2005-12-14 17:58:48 +00:00
|
|
|
goto next_card;
|
|
|
|
}
|
2009-08-08 13:54:41 +00:00
|
|
|
if (snd_ctl_card_info (handle, info) < 0) {
|
2005-12-14 17:58:48 +00:00
|
|
|
snd_ctl_close (handle);
|
|
|
|
goto next_card;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mixer) {
|
2006-05-18 17:19:39 +00:00
|
|
|
list = g_list_append (list, g_strdup (name));
|
2005-12-14 17:58:48 +00:00
|
|
|
} else {
|
|
|
|
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);
|
2009-08-08 13:54:41 +00:00
|
|
|
if (snd_ctl_pcm_info (handle, pcminfo) < 0) {
|
2005-12-14 17:58:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_device = g_strdup_printf ("hw:%d,%d", card, dev);
|
2006-05-18 17:19:39 +00:00
|
|
|
list = g_list_append (list, gst_device);
|
2005-12-14 17:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
snd_ctl_close (handle);
|
|
|
|
next_card:
|
|
|
|
if (snd_card_next (&card) < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-24 09:27:35 +00:00
|
|
|
beach:
|
2007-09-16 01:56:21 +00:00
|
|
|
snd_ctl_card_info_free (info);
|
|
|
|
snd_pcm_info_free (pcminfo);
|
|
|
|
|
2006-05-18 17:19:39 +00:00
|
|
|
return list;
|
2005-12-14 17:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_alsa_device_property_probe_probe_property (GstPropertyProbe * probe,
|
|
|
|
guint prop_id, const GParamSpec * pspec)
|
|
|
|
{
|
2006-05-18 17:19:39 +00:00
|
|
|
if (!g_str_equal (pspec->name, "device")) {
|
2005-12-14 17:58:48 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_alsa_device_property_probe_needs_probe (GstPropertyProbe * probe,
|
|
|
|
guint prop_id, const GParamSpec * pspec)
|
|
|
|
{
|
2006-05-18 17:19:39 +00:00
|
|
|
/* don't cache probed data */
|
|
|
|
return TRUE;
|
2005-12-14 17:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GValueArray *
|
2006-05-18 17:19:39 +00:00
|
|
|
gst_alsa_device_property_probe_get_values (GstPropertyProbe * probe,
|
|
|
|
guint prop_id, const GParamSpec * pspec)
|
2005-12-14 17:58:48 +00:00
|
|
|
{
|
2006-05-18 17:19:39 +00:00
|
|
|
GstElementClass *klass;
|
|
|
|
const GList *templates;
|
|
|
|
snd_pcm_stream_t mode = -1;
|
2005-12-14 17:58:48 +00:00
|
|
|
GValueArray *array;
|
2006-05-18 17:19:39 +00:00
|
|
|
GValue value = { 0, };
|
|
|
|
GList *l, *list;
|
2005-12-14 17:58:48 +00:00
|
|
|
|
2006-05-18 17:19:39 +00:00
|
|
|
if (!g_str_equal (pspec->name, "device")) {
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
|
2005-12-14 17:58:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-18 17:19:39 +00:00
|
|
|
klass = GST_ELEMENT_GET_CLASS (GST_ELEMENT (probe));
|
2005-12-14 17:58:48 +00:00
|
|
|
|
2006-05-18 17:19:39 +00:00
|
|
|
/* I'm pretty sure ALSA has a good way to do this. However, their cool
|
|
|
|
* auto-generated documentation is pretty much useless if you try to
|
|
|
|
* do function-wise look-ups. */
|
|
|
|
/* we assume one pad template at max [zero=mixer] */
|
|
|
|
templates = gst_element_class_get_pad_template_list (klass);
|
|
|
|
if (templates) {
|
|
|
|
if (GST_PAD_TEMPLATE_DIRECTION (templates->data) == GST_PAD_SRC)
|
|
|
|
mode = SND_PCM_STREAM_CAPTURE;
|
|
|
|
else
|
|
|
|
mode = SND_PCM_STREAM_PLAYBACK;
|
|
|
|
}
|
2005-12-14 17:58:48 +00:00
|
|
|
|
2006-05-18 17:19:39 +00:00
|
|
|
list = gst_alsa_get_device_list (mode);
|
2005-12-14 17:58:48 +00:00
|
|
|
|
2006-05-18 17:19:39 +00:00
|
|
|
if (list == NULL) {
|
|
|
|
GST_LOG_OBJECT (probe, "No devices found");
|
2005-12-14 17:58:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-18 17:19:39 +00:00
|
|
|
array = g_value_array_new (g_list_length (list));
|
|
|
|
g_value_init (&value, G_TYPE_STRING);
|
|
|
|
for (l = list; l != NULL; l = l->next) {
|
2006-10-05 15:55:21 +00:00
|
|
|
GST_LOG_OBJECT (probe, "Found device: %s", (gchar *) l->data);
|
2006-05-18 17:19:39 +00:00
|
|
|
g_value_take_string (&value, (gchar *) l->data);
|
|
|
|
l->data = NULL;
|
|
|
|
g_value_array_append (array, &value);
|
|
|
|
}
|
|
|
|
g_value_unset (&value);
|
|
|
|
g_list_free (list);
|
|
|
|
|
|
|
|
return array;
|
2005-12-14 17:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_alsa_property_probe_interface_init (GstPropertyProbeInterface * iface)
|
|
|
|
{
|
|
|
|
iface->get_properties = gst_alsa_device_property_probe_get_properties;
|
|
|
|
iface->probe_property = gst_alsa_device_property_probe_probe_property;
|
|
|
|
iface->needs_probe = gst_alsa_device_property_probe_needs_probe;
|
|
|
|
iface->get_values = gst_alsa_device_property_probe_get_values;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-05-18 17:19:39 +00:00
|
|
|
gst_alsa_type_add_device_property_probe_interface (GType type)
|
2005-12-14 17:58:48 +00:00
|
|
|
{
|
|
|
|
static const GInterfaceInfo probe_iface_info = {
|
|
|
|
(GInterfaceInitFunc) gst_alsa_property_probe_interface_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
g_type_add_interface_static (type, GST_TYPE_PROPERTY_PROBE,
|
|
|
|
&probe_iface_info);
|
|
|
|
}
|
2011-12-21 10:58:53 +00:00
|
|
|
#endif
|