bee770430588205d8af0f339ae580d3f3b939c72
[platform/upstream/gst-plugins-good.git] / sys / sunaudio / gstsunaudiomixertrack.c
1 /*
2  * GStreamer
3  * Copyright (C) 2005,2008, 2009 Sun Microsystems, Inc.,
4  *               Brian Cameron <brian.cameron@sun.com>
5  * Copyright (C) 2009 Sun Microsystems, Inc.,
6  *               Garrett D'Amore <garrett.damore@sun.com>
7  *
8  * gstsunaudiomixer.c: mixer interface implementation for OSS
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <fcntl.h>
33 #include <unistd.h>
34 #include <string.h>
35 #include <errno.h>
36 #include <sys/ioctl.h>
37 #include <sys/audioio.h>
38
39 #include <gst/gst-i18n-plugin.h>
40
41 #include "gstsunaudiomixertrack.h"
42
43 #define MASK_BIT_IS_SET(mask, bit) \
44   (mask & (1 << bit))
45
46 G_DEFINE_TYPE (GstSunAudioMixerTrack, gst_sunaudiomixer_track,
47     GST_TYPE_MIXER_TRACK)
48
49      static void
50          gst_sunaudiomixer_track_class_init (GstSunAudioMixerTrackClass * klass)
51 {
52   /* nop */
53 }
54
55 static void
56 gst_sunaudiomixer_track_init (GstSunAudioMixerTrack * track)
57 {
58   track->gain = 0;
59   track->balance = AUDIO_MID_BALANCE;
60   track->track_num = 0;
61 }
62
63 GstMixerTrack *
64 gst_sunaudiomixer_track_new (GstSunAudioTrackType track_num)
65 {
66   const gchar *labels[] = { N_("Volume"),
67     N_("Gain"),
68     N_("Monitor"),
69     N_("Built-in Speaker"),
70     N_("Headphone"),
71     N_("Line Out"),
72     N_("SPDIF Out"),
73     N_("AUX 1 Out"),
74     N_("AUX 2 Out"),
75   };
76
77
78   GstSunAudioMixerTrack *sunaudiotrack;
79   GstMixerTrack *track;
80   GObjectClass *klass;
81   const gchar *untranslated_label;
82
83   if ((guint) track_num < G_N_ELEMENTS (labels))
84     untranslated_label = labels[track_num];
85   else
86     untranslated_label = NULL;
87
88   /* FIXME: remove this check once we depend on -base >= 0.10.12.1 */
89   klass = G_OBJECT_CLASS (g_type_class_ref (GST_TYPE_SUNAUDIO_MIXER_TRACK));
90   if (g_object_class_find_property (klass, "untranslated-label")) {
91     sunaudiotrack = g_object_new (GST_TYPE_SUNAUDIO_MIXER_TRACK,
92         "untranslated-label", untranslated_label, NULL);
93   } else {
94     sunaudiotrack = g_object_new (GST_TYPE_SUNAUDIO_MIXER_TRACK, NULL);
95   }
96   g_type_class_unref (klass);
97
98   switch (track_num) {
99     case GST_SUNAUDIO_TRACK_OUTPUT:
100       /* these are sliders */
101       track = GST_MIXER_TRACK (sunaudiotrack);
102       track->label = g_strdup (_(untranslated_label));
103       track->num_channels = 2;
104       track->flags = GST_MIXER_TRACK_OUTPUT | GST_MIXER_TRACK_WHITELIST |
105           GST_MIXER_TRACK_MASTER;
106       track->min_volume = 0;
107       track->max_volume = 255;
108       sunaudiotrack->track_num = track_num;
109       sunaudiotrack->gain = (0 & 0xff);
110       sunaudiotrack->balance = AUDIO_MID_BALANCE;
111       break;
112     case GST_SUNAUDIO_TRACK_RECORD:
113       /* these are sliders */
114       track = GST_MIXER_TRACK (sunaudiotrack);
115       track->label = g_strdup (_(untranslated_label));
116       track->num_channels = 2;
117       track->flags = GST_MIXER_TRACK_INPUT | GST_MIXER_TRACK_NO_RECORD |
118           GST_MIXER_TRACK_WHITELIST;
119       track->min_volume = 0;
120       track->max_volume = 255;
121       sunaudiotrack->track_num = track_num;
122       sunaudiotrack->gain = (0 & 0xff);
123       sunaudiotrack->balance = AUDIO_MID_BALANCE;
124       break;
125     case GST_SUNAUDIO_TRACK_MONITOR:
126       /* these are sliders */
127       track = GST_MIXER_TRACK (sunaudiotrack);
128       track->label = g_strdup (_(untranslated_label));
129       track->num_channels = 2;
130       track->flags = GST_MIXER_TRACK_INPUT | GST_MIXER_TRACK_NO_RECORD;
131       track->min_volume = 0;
132       track->max_volume = 255;
133       sunaudiotrack->track_num = track_num;
134       sunaudiotrack->gain = (0 & 0xff);
135       sunaudiotrack->balance = AUDIO_MID_BALANCE;
136       break;
137     case GST_SUNAUDIO_TRACK_SPEAKER:
138     case GST_SUNAUDIO_TRACK_HP:
139     case GST_SUNAUDIO_TRACK_LINEOUT:
140     case GST_SUNAUDIO_TRACK_SPDIFOUT:
141     case GST_SUNAUDIO_TRACK_AUX1OUT:
142     case GST_SUNAUDIO_TRACK_AUX2OUT:
143       /* these are switches */
144       track = GST_MIXER_TRACK (sunaudiotrack);
145       track->label = g_strdup (_(untranslated_label));
146       track->num_channels = 0;
147       track->flags = GST_MIXER_TRACK_OUTPUT | GST_MIXER_TRACK_WHITELIST;
148       track->min_volume = 0;
149       track->max_volume = 255;
150       sunaudiotrack->track_num = track_num;
151       sunaudiotrack->gain = (0 & 0xff);
152       sunaudiotrack->balance = AUDIO_MID_BALANCE;
153       break;
154     default:
155       g_warning ("Unknown sun audio track num %d", track_num);
156       track = NULL;
157   }
158
159   return track;
160 }