0c0d95dc2e935e972f323bd0705aa3916f8bbd9b
[platform/upstream/gst-plugins-good.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 static void gst_sunaudiomixer_options_init (GstSunAudioMixerOptions * sun_opts);
44 static void gst_sunaudiomixer_options_class_init (gpointer g_class,
45     gpointer class_data);
46
47 static GstMixerOptionsClass *parent_class = NULL;
48
49 GType
50 gst_sunaudiomixer_options_get_type (void)
51 {
52   static GType opts_type = 0;
53
54   if (!opts_type) {
55     static const GTypeInfo opts_info = {
56       sizeof (GstSunAudioMixerOptionsClass),
57       NULL,
58       NULL,
59       gst_sunaudiomixer_options_class_init,
60       NULL,
61       NULL,
62       sizeof (GstSunAudioMixerOptions),
63       0,
64       (GInstanceInitFunc) gst_sunaudiomixer_options_init,
65     };
66
67     opts_type =
68         g_type_register_static (GST_TYPE_MIXER_OPTIONS,
69         "GstSunAudioMixerOptions", &opts_info, 0);
70   }
71
72   return opts_type;
73 }
74
75 static void
76 gst_sunaudiomixer_options_class_init (gpointer g_class, gpointer class_data)
77 {
78   parent_class = g_type_class_peek_parent (g_class);
79 }
80
81 static void
82 gst_sunaudiomixer_options_init (GstSunAudioMixerOptions * sun_opts)
83 {
84 }
85
86 GstMixerOptions *
87 gst_sunaudiomixer_options_new (GstSunAudioMixerCtrl * mixer, gint track_num)
88 {
89   GstMixerOptions *opts;
90   GstSunAudioMixerOptions *sun_opts;
91   GstMixerTrack *track;
92   const gchar *label;
93   gint i;
94   struct audio_info audioinfo;
95
96   if ((mixer == NULL) || (mixer->mixer_fd == -1)) {
97     g_warning ("mixer not initialized");
98     return NULL;
99   }
100
101   if (track_num != GST_SUNAUDIO_TRACK_RECSRC) {
102     g_warning ("invalid options track");
103     return (NULL);
104   }
105
106   label = N_("Record Source");
107
108   opts = g_object_new (GST_TYPE_SUNAUDIO_MIXER_OPTIONS,
109       "untranslated-label", label, NULL);
110   sun_opts = GST_SUNAUDIO_MIXER_OPTIONS (opts);
111   track = GST_MIXER_TRACK (opts);
112
113   /* save off names for the record sources */
114   sun_opts->names[0] = g_quark_from_string (_("Microphone"));
115   sun_opts->names[1] = g_quark_from_string (_("Line In"));
116   sun_opts->names[2] = g_quark_from_string (_("Internal CD"));
117   sun_opts->names[3] = g_quark_from_string (_("SPDIF In"));
118   sun_opts->names[4] = g_quark_from_string (_("AUX 1 In"));
119   sun_opts->names[5] = g_quark_from_string (_("AUX 2 In"));
120   sun_opts->names[6] = g_quark_from_string (_("Codec Loopback"));
121   sun_opts->names[7] = g_quark_from_string (_("SunVTS Loopback"));
122
123   /* set basic information */
124   track->label = g_strdup (_(label));
125   track->num_channels = 0;
126   track->min_volume = 0;
127   track->max_volume = 0;
128   track->flags =
129       GST_MIXER_TRACK_INPUT | GST_MIXER_TRACK_WHITELIST |
130       GST_MIXER_TRACK_NO_RECORD;
131
132   if (ioctl (mixer->mixer_fd, AUDIO_GETINFO, &audioinfo) < 0) {
133     g_warning ("Error getting audio device settings");
134     g_object_unref (G_OBJECT (sun_opts));
135     return NULL;
136   }
137
138   sun_opts->avail = audioinfo.record.avail_ports;
139   sun_opts->track_num = track_num;
140
141   for (i = 0; i < 8; i++) {
142     if ((1 << i) & audioinfo.record.avail_ports) {
143       const char *s = g_quark_to_string (sun_opts->names[i]);
144       opts->values = g_list_append (opts->values, g_strdup (s));
145     }
146   }
147
148   return opts;
149 }