tizen 2.3 release
[framework/multimedia/gst-plugins-base0.10.git] / ext / alsa / gstalsamixeroptions.c
1 /* ALSA mixer object implementation.
2  * Copyright (C) 2003 Leif Johnson <leif@ambient.2y.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "gstalsamixeroptions.h"
25
26 static void gst_alsa_mixer_options_init (GstAlsaMixerOptions * alsa_opts);
27 static void gst_alsa_mixer_options_class_init (gpointer g_class,
28     gpointer class_data);
29
30 static GstMixerOptionsClass *parent_class = NULL;
31
32 GType
33 gst_alsa_mixer_options_get_type (void)
34 {
35   static GType opts_type = 0;
36
37   if (!opts_type) {
38     static const GTypeInfo opts_info = {
39       sizeof (GstAlsaMixerOptionsClass),
40       NULL,
41       NULL,
42       gst_alsa_mixer_options_class_init,
43       NULL,
44       NULL,
45       sizeof (GstAlsaMixerOptions),
46       0,
47       (GInstanceInitFunc) gst_alsa_mixer_options_init,
48     };
49
50     opts_type =
51         g_type_register_static (GST_TYPE_MIXER_OPTIONS, "GstAlsaMixerOptions",
52         &opts_info, 0);
53   }
54
55   return opts_type;
56 }
57
58 static void
59 gst_alsa_mixer_options_class_init (gpointer g_class, gpointer class_data)
60 {
61   parent_class = g_type_class_peek_parent (g_class);
62 }
63
64 static void
65 gst_alsa_mixer_options_init (GstAlsaMixerOptions * alsa_opts)
66 {
67 }
68
69 GstMixerOptions *
70 gst_alsa_mixer_options_new (snd_mixer_elem_t * element, gint track_num)
71 {
72   GstMixerOptions *opts;
73   GstAlsaMixerOptions *alsa_opts;
74   GstMixerTrack *track;
75   const gchar *label;
76   guint index;
77   gint num, i;
78   gchar str[256];
79
80   label = snd_mixer_selem_get_name (element);
81   index = snd_mixer_selem_get_index (element);
82
83   GST_LOG ("[%s,%u]", label, index);
84
85   opts = g_object_new (GST_ALSA_MIXER_OPTIONS_TYPE,
86       "untranslated-label", label, "index", index, NULL);
87   alsa_opts = (GstAlsaMixerOptions *) opts;
88   track = (GstMixerTrack *) opts;
89
90   /* set basic information */
91   track->label = g_strdup (label);      /* FIXME: translate this? */
92   track->num_channels = 0;
93   track->flags = 0;
94   alsa_opts->element = element;
95   alsa_opts->track_num = track_num;
96
97   /* get enumerations for switch/options object */
98   num = snd_mixer_selem_get_enum_items (element);
99   for (i = 0; i < num; i++) {
100     if (snd_mixer_selem_get_enum_item_name (element, i, 255, str) < 0) {
101       g_object_unref (G_OBJECT (alsa_opts));
102       return NULL;
103     }
104
105     opts->values = g_list_append (opts->values, g_strdup (str));
106   }
107
108   return opts;
109 }