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>
34 #ifdef HAVE_OSS_INCLUDE_IN_SYS
35 # include <sys/soundcard.h>
37 # ifdef HAVE_OSS_INCLUDE_IN_ROOT
38 # include <soundcard.h>
40 # ifdef HAVE_OSS_INCLUDE_IN_MACHINE
41 # include <machine/soundcard.h>
43 # error "What to include?"
44 # endif /* HAVE_OSS_INCLUDE_IN_MACHINE */
45 # endif /* HAVE_OSS_INCLUDE_IN_ROOT */
46 #endif /* HAVE_OSS_INCLUDE_IN_SYS */
48 #include <gst/gst-i18n-plugin.h>
50 #include "gstossmixertrack.h"
52 GST_DEBUG_CATEGORY_EXTERN (oss_debug);
53 #define GST_CAT_DEFAULT oss_debug
55 #define MASK_BIT_IS_SET(mask, bit) \
58 G_DEFINE_TYPE (GstOssMixerTrack, gst_ossmixer_track, GST_TYPE_MIXER_TRACK);
61 gst_ossmixer_track_class_init (GstOssMixerTrackClass * klass)
67 gst_ossmixer_track_init (GstOssMixerTrack * track)
69 track->lvol = track->rvol = 0;
73 static const gchar **labels = NULL;
75 /* three functions: firstly, OSS has the nasty habit of inserting
76 * spaces in the labels, we want to get rid of them. Secondly,
77 * i18n is impossible with OSS' way of providing us with mixer
78 * labels, so we make a 'given' list of i18n'ed labels. Thirdly, I
79 * personally don't like the "1337" names that OSS gives to their
80 * labels ("Vol", "Mic", "Rec"), I'd rather see full names. */
86 const gchar *origs[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS;
93 /* Note: this list is simply ripped from soundcard.h. For
94 * some people, some values might be missing (3D surround,
95 * etc.) - feel free to add them. That's the reason why
96 * I'm doing this in such a horribly complicated way. */
98 "Vol ", _("Volume")}, {
99 "Bass ", _("Bass")}, {
100 "Trebl", _("Treble")}, {
101 "Synth", _("Synth")}, {
103 "Spkr ", _("Speaker")}, {
104 "Line ", _("Line-in")}, {
105 "Mic ", _("Microphone")}, {
107 "Mix ", _("Mixer")}, {
108 "Pcm2 ", _("PCM-2")}, {
109 "Rec ", _("Record")}, {
110 "IGain", _("In-gain")}, {
111 "OGain", _("Out-gain")}, {
112 "Line1", _("Line-1")}, {
113 "Line2", _("Line-2")}, {
114 "Line3", _("Line-3")}, {
115 "Digital1", _("Digital-1")}, {
116 "Digital2", _("Digital-2")}, {
117 "Digital3", _("Digital-3")}, {
118 "PhoneIn", _("Phone-in")}, {
119 "PhoneOut", _("Phone-out")}, {
120 "Video", _("Video")}, {
121 "Radio", _("Radio")}, {
122 "Monitor", _("Monitor")}, {
126 labels = g_malloc (sizeof (gchar *) * SOUND_MIXER_NRDEVICES);
128 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
129 for (pos = 0; cases[pos].given != NULL; pos++) {
130 if (!strcmp (cases[pos].given, origs[i])) {
131 labels[i] = g_strdup (cases[pos].wanted);
135 if (cases[pos].given == NULL)
136 labels[i] = g_strdup (origs[i]);
141 gst_ossmixer_track_new (gint mixer_fd,
142 gint track_num, gint max_chans, gint flags)
144 GstOssMixerTrack *osstrack;
145 GstMixerTrack *track;
151 osstrack = g_object_new (GST_TYPE_OSSMIXER_TRACK, NULL);
152 track = GST_MIXER_TRACK (osstrack);
153 track->label = g_strdup (labels[track_num]);
154 track->num_channels = max_chans;
155 track->flags = flags;
156 track->min_volume = 0;
157 track->max_volume = 100;
158 osstrack->track_num = track_num;
161 if (ioctl (mixer_fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
162 g_warning ("Error getting device (%d) volume: %s",
163 osstrack->track_num, strerror (errno));
166 osstrack->lvol = (volume & 0xff);
167 if (track->num_channels == 2) {
168 osstrack->rvol = ((volume >> 8) & 0xff);