sunaudio: Fix switch setting on some devices. Add debug. Fix a FIXME.
[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 GST_DEBUG_CATEGORY_EXTERN (sunaudio_debug);
44 #define GST_CAT_DEFAULT sunaudio_debug
45
46 #define MASK_BIT_IS_SET(mask, bit) \
47   (mask & (1 << bit))
48
49 G_DEFINE_TYPE (GstSunAudioMixerTrack, gst_sunaudiomixer_track,
50     GST_TYPE_MIXER_TRACK);
51
52 static void
53 gst_sunaudiomixer_track_class_init (GstSunAudioMixerTrackClass * klass)
54 {
55   /* nop */
56 }
57
58 static void
59 gst_sunaudiomixer_track_init (GstSunAudioMixerTrack * track)
60 {
61   track->gain = 0;
62   track->balance = AUDIO_MID_BALANCE;
63   track->track_num = 0;
64 }
65
66 GstMixerTrack *
67 gst_sunaudiomixer_track_new (GstSunAudioTrackType track_num)
68 {
69   const gchar *labels[] = { N_("Volume"),
70     N_("Gain"),
71     N_("Monitor"),
72     N_("Built-in Speaker"),
73     N_("Headphone"),
74     N_("Line Out"),
75     N_("SPDIF Out"),
76     N_("AUX 1 Out"),
77     N_("AUX 2 Out"),
78   };
79
80
81   GstSunAudioMixerTrack *sunaudiotrack;
82   GstMixerTrack *track;
83   const gchar *untranslated_label;
84
85   if ((guint) track_num < G_N_ELEMENTS (labels))
86     untranslated_label = labels[track_num];
87   else
88     untranslated_label = NULL;
89
90   sunaudiotrack = g_object_new (GST_TYPE_SUNAUDIO_MIXER_TRACK,
91       "untranslated-label", untranslated_label, NULL);
92
93   GST_DEBUG_OBJECT (sunaudiotrack, "Creating new mixer track of type %d: %s",
94       track_num, GST_STR_NULL (untranslated_label));
95
96   switch (track_num) {
97     case GST_SUNAUDIO_TRACK_OUTPUT:
98       /* these are sliders */
99       track = GST_MIXER_TRACK (sunaudiotrack);
100       track->label = g_strdup (_(untranslated_label));
101       track->num_channels = 2;
102       track->flags = GST_MIXER_TRACK_OUTPUT | GST_MIXER_TRACK_WHITELIST |
103           GST_MIXER_TRACK_MASTER;
104       track->min_volume = 0;
105       track->max_volume = 255;
106       sunaudiotrack->track_num = track_num;
107       sunaudiotrack->gain = (0 & 0xff);
108       sunaudiotrack->balance = AUDIO_MID_BALANCE;
109       break;
110     case GST_SUNAUDIO_TRACK_RECORD:
111       /* these are sliders */
112       track = GST_MIXER_TRACK (sunaudiotrack);
113       track->label = g_strdup (_(untranslated_label));
114       track->num_channels = 2;
115       track->flags = GST_MIXER_TRACK_INPUT | GST_MIXER_TRACK_NO_RECORD |
116           GST_MIXER_TRACK_WHITELIST;
117       track->min_volume = 0;
118       track->max_volume = 255;
119       sunaudiotrack->track_num = track_num;
120       sunaudiotrack->gain = (0 & 0xff);
121       sunaudiotrack->balance = AUDIO_MID_BALANCE;
122       break;
123     case GST_SUNAUDIO_TRACK_MONITOR:
124       /* these are sliders */
125       track = GST_MIXER_TRACK (sunaudiotrack);
126       track->label = g_strdup (_(untranslated_label));
127       track->num_channels = 2;
128       track->flags = GST_MIXER_TRACK_INPUT | GST_MIXER_TRACK_NO_RECORD;
129       track->min_volume = 0;
130       track->max_volume = 255;
131       sunaudiotrack->track_num = track_num;
132       sunaudiotrack->gain = (0 & 0xff);
133       sunaudiotrack->balance = AUDIO_MID_BALANCE;
134       break;
135     case GST_SUNAUDIO_TRACK_SPEAKER:
136     case GST_SUNAUDIO_TRACK_HP:
137     case GST_SUNAUDIO_TRACK_LINEOUT:
138     case GST_SUNAUDIO_TRACK_SPDIFOUT:
139     case GST_SUNAUDIO_TRACK_AUX1OUT:
140     case GST_SUNAUDIO_TRACK_AUX2OUT:
141       /* these are switches */
142       track = GST_MIXER_TRACK (sunaudiotrack);
143       track->label = g_strdup (_(untranslated_label));
144       track->num_channels = 0;
145       track->flags = GST_MIXER_TRACK_OUTPUT | GST_MIXER_TRACK_WHITELIST;
146       track->min_volume = 0;
147       track->max_volume = 255;
148       sunaudiotrack->track_num = track_num;
149       sunaudiotrack->gain = (0 & 0xff);
150       sunaudiotrack->balance = AUDIO_MID_BALANCE;
151       break;
152     default:
153       g_warning ("Unknown sun audio track num %d", track_num);
154       track = NULL;
155   }
156
157   return track;
158 }