1 /* GStreamer OSS4 mixer on/off switch control
2 * Copyright (C) 2007-2008 Tim-Philipp Müller <tim centricular net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 /* A simple ON/OFF 'switch' in gnome-volume-control / GstMixer is represented
21 * by a GstMixerTrack with no channels.
28 #include <gst/gst-i18n-plugin.h>
30 #define NO_LEGACY_MIXER
31 #include "oss4-mixer-switch.h"
32 #include "oss4-soundcard.h"
34 GST_DEBUG_CATEGORY_EXTERN (oss4mixer_debug);
35 #define GST_CAT_DEFAULT oss4mixer_debug
37 /* GstMixerTrack is a plain GObject, so let's just use the GLib macro here */
38 G_DEFINE_TYPE (GstOss4MixerSwitch, gst_oss4_mixer_switch, GST_TYPE_MIXER_TRACK);
41 gst_oss4_mixer_switch_class_init (GstOss4MixerSwitchClass * klass)
43 /* nothing to do here */
47 gst_oss4_mixer_switch_init (GstOss4MixerSwitch * s)
49 /* nothing to do here */
53 gst_oss4_mixer_switch_set (GstOss4MixerSwitch * s, gboolean disabled)
58 track = GST_MIXER_TRACK (s);
60 newval = disabled ? GST_MIXER_TRACK_MUTE : 0;
62 if (newval == (track->flags & GST_MIXER_TRACK_MUTE)) {
63 GST_LOG_OBJECT (s, "switch is already %d, doing nothing", newval);
67 if (!gst_oss4_mixer_set_control_val (s->mixer, s->mc, !disabled)) {
68 GST_WARNING_OBJECT (s, "could not set switch to %d", !disabled);
73 track->flags |= GST_MIXER_TRACK_MUTE;
75 track->flags &= ~GST_MIXER_TRACK_MUTE;
78 GST_LOG_OBJECT (s, "set switch to %d", newval);
84 gst_oss4_mixer_switch_get (GstOss4MixerSwitch * s, gboolean * disabled)
89 track = GST_MIXER_TRACK (s);
91 if (!gst_oss4_mixer_get_control_val (s->mixer, s->mc, &enabled)
93 GST_WARNING_OBJECT (s, "could not get switch state");
98 track->flags &= ~GST_MIXER_TRACK_MUTE;
100 track->flags |= GST_MIXER_TRACK_MUTE;
102 *disabled = (enabled == 0);
108 gst_oss4_mixer_switch_new (GstOss4Mixer * mixer, GstOss4MixerControl * mc)
110 GstOss4MixerSwitch *s;
111 GstMixerTrack *track;
114 s = g_object_new (GST_TYPE_OSS4_MIXER_SWITCH, "untranslated-label",
115 mc->mixext.extname, NULL);
120 track = GST_MIXER_TRACK (s);
122 /* caller will set track->label and track->flags */
124 track->num_channels = 0;
125 track->min_volume = 0;
126 track->max_volume = 0;
128 if (!gst_oss4_mixer_get_control_val (s->mixer, s->mc, &cur) || cur < 0)
132 track->flags &= ~GST_MIXER_TRACK_MUTE;
134 track->flags |= GST_MIXER_TRACK_MUTE;
140 /* This is called from the watch thread */
142 gst_oss4_mixer_switch_process_change_unlocked (GstMixerTrack * track)
144 GstOss4MixerSwitch *s = GST_OSS4_MIXER_SWITCH_CAST (track);
149 gst_mixer_mute_toggled (GST_MIXER (s->mixer), track, !s->mc->last_val);