Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / sys / sunaudio / gstsunaudiomixeroptions.c
1 /*
2  * GStreamer SunAudio mixer track implementation
3  * Copyright (C) 2009 Sun Microsystems, Inc.,
4  *               Brian Cameron <brian.cameron@sun.com>
5  *               Garrett D'Amore <garrett.damore@sun.com>
6  *
7  * gstsunaudiomixeroptions.c: Sun Audio mixer options object
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <fcntl.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <sys/ioctl.h>
35 #include <sys/audio.h>
36 #include <sys/mixer.h>
37
38 #include <gst/gst-i18n-plugin.h>
39
40 #include "gstsunaudiomixeroptions.h"
41 #include "gstsunaudiomixertrack.h"
42
43 GST_DEBUG_CATEGORY_EXTERN (sunaudio_debug);
44 #define GST_CAT_DEFAULT sunaudio_debug
45
46 static void gst_sunaudiomixer_options_init (GstSunAudioMixerOptions * sun_opts);
47 static void gst_sunaudiomixer_options_class_init (gpointer g_class,
48     gpointer class_data);
49
50 static GstMixerOptionsClass *parent_class = NULL;
51
52 GType
53 gst_sunaudiomixer_options_get_type (void)
54 {
55   static GType opts_type = 0;
56
57   if (!opts_type) {
58     static const GTypeInfo opts_info = {
59       sizeof (GstSunAudioMixerOptionsClass),
60       NULL,
61       NULL,
62       gst_sunaudiomixer_options_class_init,
63       NULL,
64       NULL,
65       sizeof (GstSunAudioMixerOptions),
66       0,
67       (GInstanceInitFunc) gst_sunaudiomixer_options_init,
68     };
69
70     opts_type =
71         g_type_register_static (GST_TYPE_MIXER_OPTIONS,
72         "GstSunAudioMixerOptions", &opts_info, 0);
73   }
74
75   return opts_type;
76 }
77
78 static void
79 gst_sunaudiomixer_options_class_init (gpointer g_class, gpointer class_data)
80 {
81   parent_class = g_type_class_peek_parent (g_class);
82 }
83
84 static void
85 gst_sunaudiomixer_options_init (GstSunAudioMixerOptions * sun_opts)
86 {
87 }
88
89 GstMixerOptions *
90 gst_sunaudiomixer_options_new (GstSunAudioMixerCtrl * mixer, gint track_num)
91 {
92   GstMixerOptions *opts;
93   GstSunAudioMixerOptions *sun_opts;
94   GstMixerTrack *track;
95   const gchar *label;
96   gint i;
97   struct audio_info audioinfo;
98
99   if ((mixer == NULL) || (mixer->mixer_fd == -1)) {
100     g_warning ("mixer not initialized");
101     return NULL;
102   }
103
104   if (track_num != GST_SUNAUDIO_TRACK_RECSRC) {
105     g_warning ("invalid options track");
106     return (NULL);
107   }
108
109   label = N_("Record Source");
110
111   opts = g_object_new (GST_TYPE_SUNAUDIO_MIXER_OPTIONS,
112       "untranslated-label", label, NULL);
113   sun_opts = GST_SUNAUDIO_MIXER_OPTIONS (opts);
114   track = GST_MIXER_TRACK (opts);
115
116   GST_DEBUG_OBJECT (opts, "New mixer options, track %d: %s",
117       track_num, GST_STR_NULL (label));
118
119   /* save off names for the record sources */
120   sun_opts->names[0] = g_quark_from_string (_("Microphone"));
121   sun_opts->names[1] = g_quark_from_string (_("Line In"));
122   sun_opts->names[2] = g_quark_from_string (_("Internal CD"));
123   sun_opts->names[3] = g_quark_from_string (_("SPDIF In"));
124   sun_opts->names[4] = g_quark_from_string (_("AUX 1 In"));
125   sun_opts->names[5] = g_quark_from_string (_("AUX 2 In"));
126   sun_opts->names[6] = g_quark_from_string (_("Codec Loopback"));
127   sun_opts->names[7] = g_quark_from_string (_("SunVTS Loopback"));
128
129   /* set basic information */
130   track->label = g_strdup (_(label));
131   track->num_channels = 0;
132   track->min_volume = 0;
133   track->max_volume = 0;
134   track->flags =
135       GST_MIXER_TRACK_INPUT | GST_MIXER_TRACK_WHITELIST |
136       GST_MIXER_TRACK_NO_RECORD;
137
138   if (ioctl (mixer->mixer_fd, AUDIO_GETINFO, &audioinfo) < 0) {
139     g_warning ("Error getting audio device settings");
140     g_object_unref (G_OBJECT (sun_opts));
141     return NULL;
142   }
143
144   sun_opts->avail = audioinfo.record.avail_ports;
145   sun_opts->track_num = track_num;
146
147   for (i = 0; i < 8; i++) {
148     if ((1 << i) & audioinfo.record.avail_ports) {
149       const char *s = g_quark_to_string (sun_opts->names[i]);
150       opts->values = g_list_append (opts->values, g_strdup (s));
151       GST_DEBUG_OBJECT (opts, "option for track %d: %s",
152           track_num, GST_STR_NULL (s));
153     }
154   }
155
156   return opts;
157 }