1 /* GStreamer OSS Mixer implementation
2 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * gstossmixer.c: mixer interface implementation for OSS
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
32 #include <sys/ioctl.h>
33 #include <sys/soundcard.h>
35 #include <gst/gst-i18n-plugin.h>
37 #include "gstossmixertrack.h"
39 GST_DEBUG_CATEGORY_EXTERN (oss_debug);
40 #define GST_CAT_DEFAULT oss_debug
42 #define MASK_BIT_IS_SET(mask, bit) \
45 G_DEFINE_TYPE (GstOssMixerTrack, gst_ossmixer_track, GST_TYPE_MIXER_TRACK);
48 gst_ossmixer_track_class_init (GstOssMixerTrackClass * klass)
54 gst_ossmixer_track_init (GstOssMixerTrack * track)
56 track->lvol = track->rvol = 0;
60 static const gchar **labels = NULL;
62 /* three functions: firstly, OSS has the nasty habit of inserting
63 * spaces in the labels, we want to get rid of them. Secondly,
64 * i18n is impossible with OSS' way of providing us with mixer
65 * labels, so we make a 'given' list of i18n'ed labels. Thirdly, I
66 * personally don't like the "1337" names that OSS gives to their
67 * labels ("Vol", "Mic", "Rec"), I'd rather see full names. */
73 gchar *origs[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS;
76 gchar *given, *wanted;
79 /* Note: this list is simply ripped from soundcard.h. For
80 * some people, some values might be missing (3D surround,
81 * etc.) - feel free to add them. That's the reason why
82 * I'm doing this in such a horribly complicated way. */
94 "Spkr ", _("Speaker")}
96 "Line ", _("Line-in")}
98 "Mic ", _("Microphone")}
108 "IGain", _("In-gain")}
110 "OGain", _("Out-gain")}
112 "Line1", _("Line-1")}
114 "Line2", _("Line-2")}
116 "Line3", _("Line-3")}
118 "Digital1", _("Digital-1")}
120 "Digital2", _("Digital-2")}
122 "Digital3", _("Digital-3")}
124 "PhoneIn", _("Phone-in")}
126 "PhoneOut", _("Phone-out")}
132 "Monitor", _("Monitor")}
137 labels = g_malloc (sizeof (gchar *) * SOUND_MIXER_NRDEVICES);
139 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
140 for (pos = 0; cases[pos].given != NULL; pos++) {
141 if (!strcmp (cases[pos].given, origs[i])) {
142 labels[i] = g_strdup (cases[pos].wanted);
146 if (cases[pos].given == NULL)
147 labels[i] = g_strdup (origs[i]);
152 gst_ossmixer_track_new (gint mixer_fd,
153 gint track_num, gint max_chans, gint flags)
155 GstOssMixerTrack *osstrack;
156 GstMixerTrack *track;
162 osstrack = g_object_new (GST_TYPE_OSSMIXER_TRACK, NULL);
163 track = GST_MIXER_TRACK (osstrack);
164 track->label = g_strdup (labels[track_num]);
165 track->num_channels = max_chans;
166 track->flags = flags;
167 track->min_volume = 0;
168 track->max_volume = 100;
169 osstrack->track_num = track_num;
172 if (ioctl (mixer_fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
173 g_warning ("Error getting device (%d) volume: %s",
174 osstrack->track_num, strerror (errno));
177 osstrack->lvol = (volume & 0xff);
178 if (track->num_channels == 2) {
179 osstrack->rvol = ((volume >> 8) & 0xff);