2 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * mixer.c: mixer design virtual class function wrappers
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.
27 #include "interfaces-marshal.h"
31 * @short_description: Interface for elements that provide mixer operations
37 SIGNAL_RECORD_TOGGLED,
38 SIGNAL_VOLUME_CHANGED,
39 SIGNAL_OPTION_CHANGED,
43 static void gst_mixer_class_init (GstMixerClass * klass);
45 static guint gst_mixer_signals[LAST_SIGNAL] = { 0 };
48 gst_mixer_get_type (void)
50 static GType gst_mixer_type = 0;
52 if (!gst_mixer_type) {
53 static const GTypeInfo gst_mixer_info = {
54 sizeof (GstMixerClass),
55 (GBaseInitFunc) gst_mixer_class_init,
65 gst_mixer_type = g_type_register_static (G_TYPE_INTERFACE,
66 "GstMixer", &gst_mixer_info, 0);
67 g_type_interface_add_prerequisite (gst_mixer_type,
68 GST_TYPE_IMPLEMENTS_INTERFACE);
71 return gst_mixer_type;
75 gst_mixer_class_init (GstMixerClass * klass)
77 static gboolean initialized = FALSE;
80 gst_mixer_signals[SIGNAL_RECORD_TOGGLED] =
81 g_signal_new ("record-toggled",
82 GST_TYPE_MIXER, G_SIGNAL_RUN_LAST,
83 G_STRUCT_OFFSET (GstMixerClass, record_toggled),
85 gst_interfaces_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2,
86 GST_TYPE_MIXER_TRACK, G_TYPE_BOOLEAN);
87 gst_mixer_signals[SIGNAL_MUTE_TOGGLED] =
88 g_signal_new ("mute-toggled",
89 GST_TYPE_MIXER, G_SIGNAL_RUN_LAST,
90 G_STRUCT_OFFSET (GstMixerClass, mute_toggled),
92 gst_interfaces_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2,
93 GST_TYPE_MIXER_TRACK, G_TYPE_BOOLEAN);
94 gst_mixer_signals[SIGNAL_VOLUME_CHANGED] =
95 g_signal_new ("volume-changed",
96 GST_TYPE_MIXER, G_SIGNAL_RUN_LAST,
97 G_STRUCT_OFFSET (GstMixerClass, volume_changed),
99 gst_interfaces_marshal_VOID__OBJECT_POINTER, G_TYPE_NONE, 2,
100 GST_TYPE_MIXER_TRACK, G_TYPE_POINTER);
101 gst_mixer_signals[SIGNAL_OPTION_CHANGED] =
102 g_signal_new ("option-changed",
103 GST_TYPE_MIXER, G_SIGNAL_RUN_LAST,
104 G_STRUCT_OFFSET (GstMixerClass, option_changed),
106 gst_interfaces_marshal_VOID__OBJECT_STRING, G_TYPE_NONE, 2,
107 GST_TYPE_MIXER_OPTIONS, G_TYPE_STRING);
112 klass->mixer_type = GST_MIXER_SOFTWARE;
114 /* default virtual functions */
115 klass->list_tracks = NULL;
116 klass->set_volume = NULL;
117 klass->get_volume = NULL;
118 klass->set_mute = NULL;
119 klass->set_record = NULL;
120 klass->set_option = NULL;
121 klass->get_option = NULL;
125 * gst_mixer_list_tracks:
126 * @mixer: the #GstMixer (a #GstElement) to get the tracks from.
128 * Returns a list of available tracks for this mixer/element. Note
129 * that it is allowed for sink (output) elements to only provide
130 * the output tracks in this list. Likewise, for sources (inputs),
131 * it is allowed to only provide input elements in this list.
133 * Returns: A #GList consisting of zero or more #GstMixerTracks.
137 gst_mixer_list_tracks (GstMixer * mixer)
139 GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer);
141 if (klass->list_tracks) {
142 return klass->list_tracks (mixer);
149 * gst_mixer_set_volume:
150 * @mixer: The #GstMixer (a #GstElement) that owns the track.
151 * @track: The #GstMixerTrack to set the volume on.
152 * @volumes: an array of integers (of size track->num_channels)
153 * that gives the wanted volume for each channel in
156 * Sets the volume on each channel in a track. Short note about
157 * naming: a track is defined as one separate stream owned by
158 * the mixer/element, such as 'Line-in' or 'Microphone'. A
159 * channel is said to be a mono-stream inside this track. A
160 * stereo track thus contains two channels.
164 gst_mixer_set_volume (GstMixer * mixer, GstMixerTrack * track, gint * volumes)
166 GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer);
168 if (klass->set_volume) {
169 klass->set_volume (mixer, track, volumes);
174 * gst_mixer_get_volume:
175 * @mixer: the #GstMixer (a #GstElement) that owns the track
176 * @track: the GstMixerTrack to get the volume from.
177 * @volumes: a pre-allocated array of integers (of size
178 * track->num_channels) to store the current volume
179 * of each channel in the given track in.
181 * Get the current volume(s) on the given track.
185 gst_mixer_get_volume (GstMixer * mixer, GstMixerTrack * track, gint * volumes)
187 GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer);
189 if (klass->get_volume) {
190 klass->get_volume (mixer, track, volumes);
194 for (i = 0; i < track->num_channels; i++) {
201 * gst_mixer_set_mute:
202 * @mixer: the #GstMixer (a #GstElement) that owns the track.
203 * @track: the #GstMixerTrack to operate on.
204 * @mute: a boolean value indicating whether to turn on or off
207 * Mutes or unmutes the given channel. To find out whether a
208 * track is currently muted, use GST_MIXER_TRACK_HAS_FLAG ().
212 gst_mixer_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
214 GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer);
216 if (klass->set_mute) {
217 klass->set_mute (mixer, track, mute);
222 * gst_mixer_set_record:
223 * @mixer: The #GstMixer (a #GstElement) that owns the track.
224 * @track: the #GstMixerTrack to operate on.
225 * @record: a boolean value that indicates whether to turn on
228 * Enables or disables recording on the given track. Note that
229 * this is only possible on input tracks, not on output tracks
230 * (see GST_MIXER_TRACK_HAS_FLAG () and the GST_MIXER_TRACK_INPUT
235 gst_mixer_set_record (GstMixer * mixer, GstMixerTrack * track, gboolean record)
237 GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer);
239 if (klass->set_record) {
240 klass->set_record (mixer, track, record);
245 * gst_mixer_set_option:
246 * @mixer: The #GstMixer (a #GstElement) that owns the optionlist.
247 * @opts: The #GstMixerOptions that we operate on.
248 * @value: The requested new option value.
250 * Sets a name/value option in the mixer to the requested value.
254 gst_mixer_set_option (GstMixer * mixer, GstMixerOptions * opts, gchar * value)
256 GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer);
258 if (klass->set_option) {
259 klass->set_option (mixer, opts, value);
264 * gst_mixer_get_option:
265 * @mixer: The #GstMixer (a #GstElement) that owns the optionlist.
266 * @opts: The #GstMixerOptions that we operate on.
268 * Get the current value of a name/value option in the mixer.
270 * Returns: current value of the name/value option.
274 gst_mixer_get_option (GstMixer * mixer, GstMixerOptions * opts)
276 GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer);
278 if (klass->get_option) {
279 return klass->get_option (mixer, opts);
286 gst_mixer_mute_toggled (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
288 g_signal_emit (G_OBJECT (mixer),
289 gst_mixer_signals[SIGNAL_MUTE_TOGGLED], 0, track, mute);
291 g_signal_emit_by_name (G_OBJECT (track), "mute_toggled", mute);
295 gst_mixer_record_toggled (GstMixer * mixer,
296 GstMixerTrack * track, gboolean record)
298 g_signal_emit (G_OBJECT (mixer),
299 gst_mixer_signals[SIGNAL_RECORD_TOGGLED], 0, track, record);
301 g_signal_emit_by_name (G_OBJECT (track), "record_toggled", record);
305 gst_mixer_volume_changed (GstMixer * mixer,
306 GstMixerTrack * track, gint * volumes)
308 g_signal_emit (G_OBJECT (mixer),
309 gst_mixer_signals[SIGNAL_VOLUME_CHANGED], 0, track, volumes);
311 g_signal_emit_by_name (G_OBJECT (track), "volume_changed", volumes);
315 gst_mixer_option_changed (GstMixer * mixer,
316 GstMixerOptions * opts, gchar * value)
318 g_signal_emit (G_OBJECT (mixer),
319 gst_mixer_signals[SIGNAL_OPTION_CHANGED], 0, opts, value);
321 g_signal_emit_by_name (G_OBJECT (opts), "value_changed", value);