2003-12-06 00:02:20 +00:00
|
|
|
/* ALSA mixer implementation.
|
2003-11-16 21:56:30 +00:00
|
|
|
* Copyright (C) 2003 Leif Johnson <leif@ambient.2y.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., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstalsamixer.h"
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstElementDetails gst_alsa_mixer_details =
|
|
|
|
GST_ELEMENT_DETAILS ("Alsa Mixer",
|
|
|
|
"Generic/Audio",
|
|
|
|
"Control sound input and output levels with ALSA",
|
|
|
|
"Leif Johnson <leif@ambient.2y.net>");
|
|
|
|
|
|
|
|
static void gst_alsa_interface_init (GstImplementsInterfaceClass * klass);
|
|
|
|
|
|
|
|
static void gst_alsa_mixer_class_init (gpointer g_class, gpointer class_data);
|
|
|
|
static void gst_alsa_mixer_init (GstAlsaMixer * mixer);
|
|
|
|
static void gst_alsa_mixer_interface_init (GstMixerClass * klass);
|
|
|
|
static gboolean gst_alsa_mixer_supported (GstImplementsInterface * iface,
|
|
|
|
GType iface_type);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
|
|
|
/* GStreamer stuff */
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstElementStateReturn gst_alsa_mixer_change_state (GstElement * element);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_alsa_mixer_build_list (GstAlsaMixer * mixer);
|
|
|
|
static void gst_alsa_mixer_free_list (GstAlsaMixer * mixer);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
|
|
|
/* interface implementation */
|
2004-03-14 22:34:34 +00:00
|
|
|
static const GList *gst_alsa_mixer_list_tracks (GstMixer * mixer);
|
|
|
|
|
|
|
|
static void gst_alsa_mixer_set_volume (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gint * volumes);
|
|
|
|
static void gst_alsa_mixer_get_volume (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gint * volumes);
|
|
|
|
|
|
|
|
static void gst_alsa_mixer_set_record (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gboolean record);
|
|
|
|
static void gst_alsa_mixer_set_mute (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gboolean mute);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
|
|
|
/*** GOBJECT STUFF ************************************************************/
|
|
|
|
|
|
|
|
static GstAlsa *parent_class = NULL;
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_alsa_mixer_get_type (void)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
2003-12-06 00:02:20 +00:00
|
|
|
static GType alsa_mixer_type = 0;
|
|
|
|
|
|
|
|
if (!alsa_mixer_type) {
|
|
|
|
static const GTypeInfo alsa_mixer_info = {
|
|
|
|
sizeof (GstAlsaMixerClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
gst_alsa_mixer_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstAlsaMixer),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_alsa_mixer_init,
|
|
|
|
};
|
|
|
|
static const GInterfaceInfo alsa_iface_info = {
|
|
|
|
(GInterfaceInitFunc) gst_alsa_interface_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
static const GInterfaceInfo alsa_mixer_iface_info = {
|
|
|
|
(GInterfaceInitFunc) gst_alsa_mixer_interface_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
alsa_mixer_type =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_type_register_static (GST_TYPE_ALSA, "GstAlsaMixer", &alsa_mixer_info,
|
|
|
|
0);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_type_add_interface_static (alsa_mixer_type, GST_TYPE_IMPLEMENTS_INTERFACE,
|
2004-03-15 19:32:28 +00:00
|
|
|
&alsa_iface_info);
|
2004-03-14 22:34:34 +00:00
|
|
|
g_type_add_interface_static (alsa_mixer_type, GST_TYPE_MIXER,
|
2004-03-15 19:32:28 +00:00
|
|
|
&alsa_mixer_iface_info);
|
2003-12-06 00:02:20 +00:00
|
|
|
}
|
2003-11-16 21:56:30 +00:00
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
return alsa_mixer_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_alsa_mixer_class_init (gpointer g_class, gpointer class_data)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
GstElementClass *element_class;
|
|
|
|
GstAlsaClass *klass;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
klass = (GstAlsaClass *) g_class;
|
2003-12-06 00:02:20 +00:00
|
|
|
object_class = (GObjectClass *) g_class;
|
|
|
|
element_class = (GstElementClass *) g_class;
|
|
|
|
|
|
|
|
if (parent_class == NULL)
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ALSA);
|
|
|
|
|
|
|
|
element_class->change_state = gst_alsa_mixer_change_state;
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_alsa_mixer_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_alsa_mixer_init (GstAlsaMixer * mixer)
|
|
|
|
{
|
2004-03-15 06:34:44 +00:00
|
|
|
mixer->mixer_handle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_alsa_mixer_open (GstAlsaMixer * mixer)
|
|
|
|
{
|
|
|
|
gint err, device;
|
2003-12-06 00:02:20 +00:00
|
|
|
GstAlsa *alsa = GST_ALSA (mixer);
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
gchar *nocomma = NULL;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
mixer->mixer_handle = NULL;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
|
|
|
/* open and initialize the mixer device */
|
2004-03-14 22:34:34 +00:00
|
|
|
err = snd_mixer_open (&mixer->mixer_handle, 0);
|
2003-12-06 00:02:20 +00:00
|
|
|
if (err < 0 || mixer->mixer_handle == NULL) {
|
|
|
|
GST_ERROR_OBJECT (GST_OBJECT (mixer), "Cannot open mixer device.");
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
mixer->mixer_handle = NULL;
|
2004-03-15 06:34:44 +00:00
|
|
|
return FALSE;
|
2003-12-06 00:02:20 +00:00
|
|
|
}
|
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
if (!strncmp (alsa->device, "hw:", 3))
|
|
|
|
nocomma = g_strdup (alsa->device);
|
|
|
|
else if (!strncmp (alsa->device, "plughw:", 7))
|
|
|
|
nocomma = g_strdup (alsa->device + 4);
|
|
|
|
else
|
|
|
|
goto error;
|
|
|
|
|
2004-05-09 00:30:06 +00:00
|
|
|
if (strchr (nocomma, ','))
|
|
|
|
strchr (nocomma, ',')[0] = '\0';
|
|
|
|
|
|
|
|
if ((err = snd_mixer_attach (mixer->mixer_handle, nocomma)) < 0) {
|
2003-12-06 00:02:20 +00:00
|
|
|
GST_ERROR_OBJECT (GST_OBJECT (mixer),
|
2004-05-09 00:30:06 +00:00
|
|
|
"Cannot attach mixer to sound device `%s'.", nocomma);
|
2003-12-06 00:02:20 +00:00
|
|
|
goto error;
|
2003-11-16 21:56:30 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if ((err = snd_mixer_selem_register (mixer->mixer_handle, NULL, NULL)) < 0) {
|
2003-12-06 00:02:20 +00:00
|
|
|
GST_ERROR_OBJECT (GST_OBJECT (mixer), "Cannot register mixer elements.");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if ((err = snd_mixer_load (mixer->mixer_handle)) < 0) {
|
2003-12-06 00:02:20 +00:00
|
|
|
GST_ERROR_OBJECT (GST_OBJECT (mixer), "Cannot load mixer settings.");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2004-03-15 06:34:44 +00:00
|
|
|
/* I don't know how to get a device name from a mixer handle. So on
|
|
|
|
* to the ugly hacks here, then... */
|
2004-05-09 00:30:06 +00:00
|
|
|
if (sscanf (nocomma, "hw:%d", &device) == 1) {
|
2004-03-15 06:34:44 +00:00
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
if (!snd_card_get_name (device, &name))
|
|
|
|
alsa->cardname = name;
|
|
|
|
}
|
|
|
|
|
2004-05-09 00:30:06 +00:00
|
|
|
g_free (nocomma);
|
|
|
|
|
2004-03-15 06:34:44 +00:00
|
|
|
return TRUE;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
error:
|
2003-12-06 00:02:20 +00:00
|
|
|
snd_mixer_close (mixer->mixer_handle);
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
mixer->mixer_handle = NULL;
|
2004-05-09 00:30:06 +00:00
|
|
|
g_free (nocomma);
|
2004-03-15 06:34:44 +00:00
|
|
|
return FALSE;
|
2003-11-16 21:56:30 +00:00
|
|
|
}
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
static void
|
2004-03-15 06:34:44 +00:00
|
|
|
gst_alsa_mixer_close (GstAlsaMixer * mixer)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
2004-03-15 06:34:44 +00:00
|
|
|
GstAlsa *alsa = GST_ALSA (mixer);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
if (mixer->mixer_handle == NULL)
|
2004-03-14 22:34:34 +00:00
|
|
|
return;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-03-15 06:34:44 +00:00
|
|
|
if (alsa->cardname) {
|
|
|
|
g_free (alsa->cardname);
|
|
|
|
alsa->cardname = NULL;
|
|
|
|
}
|
2003-12-06 00:02:20 +00:00
|
|
|
snd_mixer_close (mixer->mixer_handle);
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
mixer->mixer_handle = NULL;
|
2003-11-16 21:56:30 +00:00
|
|
|
}
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_interface_init (GstImplementsInterfaceClass * klass)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
|
|
|
klass->supported = gst_alsa_mixer_supported;
|
|
|
|
}
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_interface_init (GstMixerClass * klass)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
ext/alsa/gstalsamixer.c: Setting mixer interface type to HARDWARE.
Original commit message from CVS:
2004-01-15 Julien MOUTTE <julien@moutte.net>
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_interface_init): Setting
mixer interface type to HARDWARE.
* gst-libs/gst/mixer/mixer.c: (gst_mixer_class_init): Adding a default
type to SOFTWARE.
* gst-libs/gst/mixer/mixer.h: Adding mixer interface type and macro.
* gst-libs/gst/mixer/mixertrack.h: Adding mixertrack flag SOFTWARE.
* gst/volume/gstvolume.c: (gst_volume_interface_supported),
(gst_volume_interface_init), (gst_volume_list_tracks),
(gst_volume_set_volume), (gst_volume_get_volume),
(gst_volume_set_mute), (gst_volume_mixer_init),
(gst_volume_dispose), (gst_volume_get_type), (volume_class_init),
(volume_init): Implementing mixer interface.
* gst/volume/gstvolume.h: Adding tracklist for mixer interface.
* sys/oss/gstosselement.c: (gst_osselement_get_type),
(gst_osselement_change_state): Removing some trailing commas in
structures.
* sys/oss/gstossmixer.c: (gst_ossmixer_interface_init): Setting mixer
interface type to HARDWARE.
* sys/v4l/gstv4lcolorbalance.c:
(gst_v4l_color_balance_interface_init): Setting colorbalance interface
type to HARDWARE.
* sys/v4l2/gstv4l2colorbalance.c:
(gst_v4l2_color_balance_interface_init): Setting colorbalance
interface type to HARDWARE.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_chain): use exactly the
same code than ximagesink for event handling.
2004-01-15 15:50:10 +00:00
|
|
|
GST_MIXER_TYPE (klass) = GST_MIXER_HARDWARE;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
/* set up the interface hooks */
|
2003-11-16 21:56:30 +00:00
|
|
|
klass->list_tracks = gst_alsa_mixer_list_tracks;
|
|
|
|
klass->set_volume = gst_alsa_mixer_set_volume;
|
|
|
|
klass->get_volume = gst_alsa_mixer_get_volume;
|
|
|
|
klass->set_mute = gst_alsa_mixer_set_mute;
|
|
|
|
klass->set_record = gst_alsa_mixer_set_record;
|
|
|
|
}
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_supported (GstImplementsInterface * iface, GType iface_type)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
|
|
|
g_assert (iface_type == GST_TYPE_MIXER);
|
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
return (GST_ALSA_MIXER (iface)->mixer_handle != NULL);
|
2003-11-16 21:56:30 +00:00
|
|
|
}
|
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_build_list (GstAlsaMixer * mixer)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
|
|
|
gint i, count;
|
|
|
|
snd_mixer_elem_t *element;
|
2004-01-18 01:05:42 +00:00
|
|
|
GstMixerTrack *track;
|
2004-05-07 04:56:56 +00:00
|
|
|
const GList *templates;
|
|
|
|
GstPadDirection dir = GST_PAD_UNKNOWN;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
g_return_if_fail (mixer->mixer_handle != NULL);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-05-07 04:56:56 +00:00
|
|
|
/* find direction */
|
|
|
|
templates =
|
|
|
|
gst_element_class_get_pad_template_list (GST_ELEMENT_GET_CLASS (mixer));
|
|
|
|
if (templates)
|
|
|
|
dir = GST_PAD_TEMPLATE (templates->data)->direction;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
count = snd_mixer_get_count (mixer->mixer_handle);
|
|
|
|
element = snd_mixer_first_elem (mixer->mixer_handle);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
|
|
|
/* build track list */
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
gint channels = 0;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!snd_mixer_selem_is_active (element))
|
|
|
|
continue;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
|
|
|
/* find out if this element can be an input */
|
2004-05-07 04:56:56 +00:00
|
|
|
if ((dir == GST_PAD_SRC || dir == GST_PAD_UNKNOWN) &&
|
|
|
|
(snd_mixer_selem_has_capture_channel (element, 0) ||
|
|
|
|
snd_mixer_selem_has_capture_switch (element) ||
|
|
|
|
snd_mixer_selem_is_capture_mono (element))) {
|
2004-03-14 22:34:34 +00:00
|
|
|
while (snd_mixer_selem_has_capture_channel (element, channels))
|
2004-03-15 19:32:28 +00:00
|
|
|
channels++;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-01-18 01:05:42 +00:00
|
|
|
track = gst_alsa_mixer_track_new
|
2004-03-15 19:32:28 +00:00
|
|
|
(element, i, channels, GST_MIXER_TRACK_INPUT);
|
2003-12-06 00:02:20 +00:00
|
|
|
mixer->tracklist = g_list_append (mixer->tracklist, track);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find out if this element can also be an output */
|
|
|
|
|
|
|
|
channels = 0;
|
|
|
|
|
2004-05-07 04:56:56 +00:00
|
|
|
if ((dir == GST_PAD_SINK || dir == GST_PAD_UNKNOWN) &&
|
|
|
|
(snd_mixer_selem_has_playback_channel (element, 0) ||
|
|
|
|
snd_mixer_selem_has_playback_switch (element) ||
|
|
|
|
snd_mixer_selem_is_playback_mono (element))) {
|
2004-03-14 22:34:34 +00:00
|
|
|
while (snd_mixer_selem_has_playback_channel (element, channels))
|
2004-03-15 19:32:28 +00:00
|
|
|
channels++;
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-01-18 01:05:42 +00:00
|
|
|
track = gst_alsa_mixer_track_new
|
2004-03-15 19:32:28 +00:00
|
|
|
(element, i, channels, GST_MIXER_TRACK_OUTPUT);
|
2003-12-06 00:02:20 +00:00
|
|
|
mixer->tracklist = g_list_append (mixer->tracklist, track);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
element = snd_mixer_elem_next (element);
|
2003-12-06 00:02:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_free_list (GstAlsaMixer * mixer)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
g_return_if_fail (mixer->mixer_handle != NULL);
|
2003-12-06 00:02:20 +00:00
|
|
|
|
2004-03-13 05:52:26 +00:00
|
|
|
g_list_foreach (mixer->tracklist, (GFunc) g_object_unref, NULL);
|
2003-12-06 00:02:20 +00:00
|
|
|
g_list_free (mixer->tracklist);
|
|
|
|
mixer->tracklist = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** GSTREAMER FUNCTIONS ******************************************************/
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_change_state (GstElement * element)
|
2003-12-06 00:02:20 +00:00
|
|
|
{
|
|
|
|
GstAlsaMixer *this;
|
|
|
|
|
|
|
|
g_return_val_if_fail (element != NULL, FALSE);
|
|
|
|
this = GST_ALSA_MIXER (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
2004-03-14 22:34:34 +00:00
|
|
|
case GST_STATE_NULL_TO_READY:
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
if (gst_alsa_mixer_open (this))
|
|
|
|
gst_alsa_mixer_build_list (this);
|
2004-03-14 22:34:34 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
if (this->mixer_handle != NULL) {
|
|
|
|
gst_alsa_mixer_free_list (this);
|
|
|
|
gst_alsa_mixer_close (this);
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-03-15 06:34:44 +00:00
|
|
|
break;
|
2003-12-06 00:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** INTERFACE IMPLEMENTATION *************************************************/
|
|
|
|
|
2003-11-16 21:56:30 +00:00
|
|
|
static const GList *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_list_tracks (GstMixer * mixer)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
2003-12-06 00:02:20 +00:00
|
|
|
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
|
2003-11-16 21:56:30 +00:00
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
if (!alsa_mixer->mixer_handle)
|
|
|
|
return NULL;
|
2003-11-16 21:56:30 +00:00
|
|
|
|
2003-12-06 00:02:20 +00:00
|
|
|
return (const GList *) alsa_mixer->tracklist;
|
2003-11-16 21:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_get_volume (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gint * volumes)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
|
|
|
gint i;
|
2003-12-06 00:02:20 +00:00
|
|
|
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
|
2003-11-16 21:56:30 +00:00
|
|
|
GstAlsaMixerTrack *alsa_track = (GstAlsaMixerTrack *) track;
|
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
g_return_if_fail (alsa_mixer->mixer_handle != NULL);
|
2003-11-16 21:56:30 +00:00
|
|
|
|
|
|
|
if (track->flags & GST_MIXER_TRACK_MUTE) {
|
|
|
|
for (i = 0; i < track->num_channels; i++)
|
|
|
|
volumes[i] = alsa_track->volumes[i];
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < track->num_channels; i++) {
|
|
|
|
long tmp;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
if (snd_mixer_selem_has_playback_channel (alsa_track->element, i)) {
|
2004-03-15 19:32:28 +00:00
|
|
|
snd_mixer_selem_get_playback_volume (alsa_track->element, i, &tmp);
|
|
|
|
volumes[i] = (gint) tmp;
|
2004-03-14 22:34:34 +00:00
|
|
|
} else if (snd_mixer_selem_has_capture_channel (alsa_track->element, i)) {
|
2004-03-15 19:32:28 +00:00
|
|
|
snd_mixer_selem_get_capture_volume (alsa_track->element, i, &tmp);
|
|
|
|
volumes[i] = (gint) tmp;
|
2003-11-16 21:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_set_volume (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gint * volumes)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
|
|
|
gint i;
|
2003-12-06 00:02:20 +00:00
|
|
|
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
|
2003-11-16 21:56:30 +00:00
|
|
|
GstAlsaMixerTrack *alsa_track = (GstAlsaMixerTrack *) track;
|
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
g_return_if_fail (alsa_mixer->mixer_handle != NULL);
|
2003-11-16 21:56:30 +00:00
|
|
|
|
|
|
|
/* only set the volume with ALSA lib if the track isn't muted. */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (!(track->flags & GST_MIXER_TRACK_MUTE)) {
|
2003-11-16 21:56:30 +00:00
|
|
|
for (i = 0; i < track->num_channels; i++) {
|
2004-03-14 22:34:34 +00:00
|
|
|
if (snd_mixer_selem_has_playback_channel (alsa_track->element, i))
|
2004-03-15 19:32:28 +00:00
|
|
|
snd_mixer_selem_set_playback_volume (alsa_track->element, i,
|
|
|
|
(long) volumes[i]);
|
2004-03-14 22:34:34 +00:00
|
|
|
else if (snd_mixer_selem_has_capture_channel (alsa_track->element, i))
|
2004-03-15 19:32:28 +00:00
|
|
|
snd_mixer_selem_set_capture_volume (alsa_track->element, i,
|
|
|
|
(long) volumes[i]);
|
2003-11-16 21:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < track->num_channels; i++)
|
|
|
|
alsa_track->volumes[i] = volumes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
|
|
|
gint i;
|
2003-12-06 00:02:20 +00:00
|
|
|
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
|
2003-11-16 21:56:30 +00:00
|
|
|
GstAlsaMixerTrack *alsa_track = (GstAlsaMixerTrack *) track;
|
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
g_return_if_fail (alsa_mixer->mixer_handle != NULL);
|
2003-11-16 21:56:30 +00:00
|
|
|
|
|
|
|
if (mute) {
|
|
|
|
track->flags |= GST_MIXER_TRACK_MUTE;
|
|
|
|
|
|
|
|
for (i = 0; i < track->num_channels; i++) {
|
2004-03-14 22:34:34 +00:00
|
|
|
if (snd_mixer_selem_has_capture_channel (alsa_track->element, i))
|
2004-03-15 19:32:28 +00:00
|
|
|
snd_mixer_selem_set_capture_volume (alsa_track->element, i, 0);
|
2004-03-14 22:34:34 +00:00
|
|
|
else if (snd_mixer_selem_has_playback_channel (alsa_track->element, i))
|
2004-03-15 19:32:28 +00:00
|
|
|
snd_mixer_selem_set_playback_volume (alsa_track->element, i, 0);
|
2003-11-16 21:56:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
track->flags &= ~GST_MIXER_TRACK_MUTE;
|
|
|
|
|
|
|
|
for (i = 0; i < track->num_channels; i++) {
|
2004-03-14 22:34:34 +00:00
|
|
|
if (snd_mixer_selem_has_capture_channel (alsa_track->element, i))
|
2004-03-15 19:32:28 +00:00
|
|
|
snd_mixer_selem_set_capture_volume (alsa_track->element, i,
|
|
|
|
alsa_track->volumes[i]);
|
2004-03-14 22:34:34 +00:00
|
|
|
else if (snd_mixer_selem_has_playback_channel (alsa_track->element, i))
|
2004-03-15 19:32:28 +00:00
|
|
|
snd_mixer_selem_set_playback_volume (alsa_track->element, i,
|
|
|
|
alsa_track->volumes[i]);
|
2003-11-16 21:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_alsa_mixer_set_record (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gboolean record)
|
2003-11-16 21:56:30 +00:00
|
|
|
{
|
2003-12-06 00:02:20 +00:00
|
|
|
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
|
2003-11-16 21:56:30 +00:00
|
|
|
|
ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 20:46:12 +00:00
|
|
|
g_return_if_fail (alsa_mixer->mixer_handle != NULL);
|
2003-11-16 21:56:30 +00:00
|
|
|
|
|
|
|
if (record) {
|
|
|
|
track->flags |= GST_MIXER_TRACK_RECORD;
|
|
|
|
} else {
|
|
|
|
track->flags &= ~GST_MIXER_TRACK_RECORD;
|
|
|
|
}
|
|
|
|
}
|