mixer.c 24.3 KB
Newer Older
Ronald S. Bultje's avatar
Ronald S. Bultje committed
1
2
/* GStreamer Mixer
 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
Ronald S. Bultje's avatar
Ronald S. Bultje committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *
 * mixer.c: mixer design virtual class function wrappers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

26
#include "mixer.h"
27
#include "interfaces-marshal.h"
28

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
29
30
#define GST_MIXER_MESSAGE_NAME "gst-mixer-message"

31
32
33
34
35
/**
 * SECTION:gstmixer
 * @short_description: Interface for elements that provide mixer operations
 */

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
36
#ifndef GST_DISABLE_DEPRECATED
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
37
38
enum
{
39
40
41
42
  SIGNAL_MUTE_TOGGLED,
  SIGNAL_RECORD_TOGGLED,
  SIGNAL_VOLUME_CHANGED,
  SIGNAL_OPTION_CHANGED,
43
44
  LAST_SIGNAL
};
Ronald S. Bultje's avatar
Ronald S. Bultje committed
45

46
47
static guint gst_mixer_signals[LAST_SIGNAL] = { 0 };

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
48
49
50
51
#endif

static void gst_mixer_class_init (GstMixerClass * klass);

Ronald S. Bultje's avatar
Ronald S. Bultje committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
GType
gst_mixer_get_type (void)
{
  static GType gst_mixer_type = 0;

  if (!gst_mixer_type) {
    static const GTypeInfo gst_mixer_info = {
      sizeof (GstMixerClass),
      (GBaseInitFunc) gst_mixer_class_init,
      NULL,
      NULL,
      NULL,
      NULL,
      0,
      0,
      NULL,
    };

    gst_mixer_type = g_type_register_static (G_TYPE_INTERFACE,
71
        "GstMixer", &gst_mixer_info, 0);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
72
    g_type_interface_add_prerequisite (gst_mixer_type,
73
        GST_TYPE_IMPLEMENTS_INTERFACE);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
74
75
76
77
78
79
  }

  return gst_mixer_type;
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
80
gst_mixer_class_init (GstMixerClass * klass)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
81
{
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
82
#ifndef GST_DISABLE_DEPRECATED
83
  static gboolean initialized = FALSE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
84

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
85
  /* signals (deprecated) */
86
  if (!initialized) {
87
    gst_mixer_signals[SIGNAL_RECORD_TOGGLED] =
88
89
90
91
        g_signal_new ("record-toggled",
        GST_TYPE_MIXER, G_SIGNAL_RUN_LAST,
        G_STRUCT_OFFSET (GstMixerClass, record_toggled),
        NULL, NULL,
92
        gst_interfaces_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2,
93
        GST_TYPE_MIXER_TRACK, G_TYPE_BOOLEAN);
94
    gst_mixer_signals[SIGNAL_MUTE_TOGGLED] =
95
96
97
98
        g_signal_new ("mute-toggled",
        GST_TYPE_MIXER, G_SIGNAL_RUN_LAST,
        G_STRUCT_OFFSET (GstMixerClass, mute_toggled),
        NULL, NULL,
99
        gst_interfaces_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2,
100
        GST_TYPE_MIXER_TRACK, G_TYPE_BOOLEAN);
101
    gst_mixer_signals[SIGNAL_VOLUME_CHANGED] =
102
103
104
105
        g_signal_new ("volume-changed",
        GST_TYPE_MIXER, G_SIGNAL_RUN_LAST,
        G_STRUCT_OFFSET (GstMixerClass, volume_changed),
        NULL, NULL,
106
        gst_interfaces_marshal_VOID__OBJECT_POINTER, G_TYPE_NONE, 2,
107
        GST_TYPE_MIXER_TRACK, G_TYPE_POINTER);
108
109
110
111
112
    gst_mixer_signals[SIGNAL_OPTION_CHANGED] =
        g_signal_new ("option-changed",
        GST_TYPE_MIXER, G_SIGNAL_RUN_LAST,
        G_STRUCT_OFFSET (GstMixerClass, option_changed),
        NULL, NULL,
113
        gst_interfaces_marshal_VOID__OBJECT_STRING, G_TYPE_NONE, 2,
114
        GST_TYPE_MIXER_OPTIONS, G_TYPE_STRING);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
115

116
117
    initialized = TRUE;
  }
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
118
#endif
119

120
  klass->mixer_type = GST_MIXER_SOFTWARE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
121

Ronald S. Bultje's avatar
Ronald S. Bultje committed
122
  /* default virtual functions */
123
  klass->list_tracks = NULL;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
124
125
126
127
  klass->set_volume = NULL;
  klass->get_volume = NULL;
  klass->set_mute = NULL;
  klass->set_record = NULL;
128
129
  klass->set_option = NULL;
  klass->get_option = NULL;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
130
131
}

132
/**
Johan Dahlin's avatar
Johan Dahlin committed
133
 * gst_mixer_list_tracks:
134
135
 * @mixer: the #GstMixer (a #GstElement) to get the tracks from.
 *
136
 * Returns a list of available tracks for this mixer/element. Note
137
138
139
140
141
 * that it is allowed for sink (output) elements to only provide
 * the output tracks in this list. Likewise, for sources (inputs),
 * it is allowed to only provide input elements in this list.
 *
 * Returns: A #GList consisting of zero or more #GstMixerTracks.
142
143
 *          The list is owned by the #GstMixer instance and must not be freed
 *          or modified.
144
145
 */

Ronald S. Bultje's avatar
Ronald S. Bultje committed
146
const GList *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
147
gst_mixer_list_tracks (GstMixer * mixer)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
148
{
149
150
151
152
153
  GstMixerClass *klass;

  g_return_val_if_fail (mixer != NULL, NULL);

  klass = GST_MIXER_GET_CLASS (mixer);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
154

155
156
  if (klass->list_tracks) {
    return klass->list_tracks (mixer);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
157
158
159
160
161
  }

  return NULL;
}

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
 * gst_mixer_set_volume:
 * @mixer: The #GstMixer (a #GstElement) that owns the track.
 * @track: The #GstMixerTrack to set the volume on.
 * @volumes: an array of integers (of size track->num_channels)
 *           that gives the wanted volume for each channel in
 *           this track.
 *
 * Sets the volume on each channel in a track. Short note about
 * naming: a track is defined as one separate stream owned by
 * the mixer/element, such as 'Line-in' or 'Microphone'. A
 * channel is said to be a mono-stream inside this track. A
 * stereo track thus contains two channels.
 */

Ronald S. Bultje's avatar
Ronald S. Bultje committed
177
void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
178
gst_mixer_set_volume (GstMixer * mixer, GstMixerTrack * track, gint * volumes)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
179
{
180
181
182
183
184
185
186
  GstMixerClass *klass;

  g_return_if_fail (mixer != NULL);
  g_return_if_fail (track != NULL);
  g_return_if_fail (volumes != NULL);

  klass = GST_MIXER_GET_CLASS (mixer);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
187
188

  if (klass->set_volume) {
189
    klass->set_volume (mixer, track, volumes);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
190
191
192
  }
}

193
/**
194
195
196
197
198
199
200
201
202
203
 * gst_mixer_get_volume:
 * @mixer: the #GstMixer (a #GstElement) that owns the track
 * @track: the GstMixerTrack to get the volume from.
 * @volumes: a pre-allocated array of integers (of size
 *           track->num_channels) to store the current volume
 *           of each channel in the given track in.
 *
 * Get the current volume(s) on the given track.
 */

Ronald S. Bultje's avatar
Ronald S. Bultje committed
204
void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
205
gst_mixer_get_volume (GstMixer * mixer, GstMixerTrack * track, gint * volumes)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
206
{
207
208
209
210
211
212
213
  GstMixerClass *klass;

  g_return_if_fail (mixer != NULL);
  g_return_if_fail (track != NULL);
  g_return_if_fail (volumes != NULL);

  klass = GST_MIXER_GET_CLASS (mixer);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
214
215

  if (klass->get_volume) {
216
    klass->get_volume (mixer, track, volumes);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
217
218
219
  } else {
    gint i;

220
    for (i = 0; i < track->num_channels; i++) {
Ronald S. Bultje's avatar
Ronald S. Bultje committed
221
222
223
224
225
      volumes[i] = 0;
    }
  }
}

226
227
228
229
230
231
232
233
234
235
236
/**
 * gst_mixer_set_mute:
 * @mixer: the #GstMixer (a #GstElement) that owns the track.
 * @track: the #GstMixerTrack to operate on.
 * @mute: a boolean value indicating whether to turn on or off
 *        muting.
 *
 * Mutes or unmutes the given channel. To find out whether a
 * track is currently muted, use GST_MIXER_TRACK_HAS_FLAG ().
 */

Ronald S. Bultje's avatar
Ronald S. Bultje committed
237
void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
238
gst_mixer_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
239
{
240
241
242
243
244
245
  GstMixerClass *klass;

  g_return_if_fail (mixer != NULL);
  g_return_if_fail (track != NULL);

  klass = GST_MIXER_GET_CLASS (mixer);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
246
247

  if (klass->set_mute) {
248
    klass->set_mute (mixer, track, mute);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
249
250
251
  }
}

252
253
254
255
256
257
258
259
260
261
262
263
264
/**
 * gst_mixer_set_record:
 * @mixer: The #GstMixer (a #GstElement) that owns the track.
 * @track: the #GstMixerTrack to operate on.
 * @record: a boolean value that indicates whether to turn on
 *          or off recording.
 *
 * Enables or disables recording on the given track. Note that
 * this is only possible on input tracks, not on output tracks
 * (see GST_MIXER_TRACK_HAS_FLAG () and the GST_MIXER_TRACK_INPUT
 * flag).
 */

Ronald S. Bultje's avatar
Ronald S. Bultje committed
265
void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
266
gst_mixer_set_record (GstMixer * mixer, GstMixerTrack * track, gboolean record)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
267
268
269
270
{
  GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer);

  if (klass->set_record) {
271
    klass->set_record (mixer, track, record);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
272
273
  }
}
274

275
276
277
278
279
280
281
282
283
284
285
286
/**
 * gst_mixer_set_option:
 * @mixer: The #GstMixer (a #GstElement) that owns the optionlist.
 * @opts: The #GstMixerOptions that we operate on.
 * @value: The requested new option value.
 *
 * Sets a name/value option in the mixer to the requested value.
 */

void
gst_mixer_set_option (GstMixer * mixer, GstMixerOptions * opts, gchar * value)
{
287
288
289
290
291
292
  GstMixerClass *klass;

  g_return_if_fail (mixer != NULL);
  g_return_if_fail (opts != NULL);

  klass = GST_MIXER_GET_CLASS (mixer);
293
294
295
296
297
298
299

  if (klass->set_option) {
    klass->set_option (mixer, opts, value);
  }
}

/**
300
 * gst_mixer_get_option:
301
302
303
304
305
306
307
308
309
310
311
 * @mixer: The #GstMixer (a #GstElement) that owns the optionlist.
 * @opts: The #GstMixerOptions that we operate on.
 *
 * Get the current value of a name/value option in the mixer.
 *
 * Returns: current value of the name/value option.
 */

const gchar *
gst_mixer_get_option (GstMixer * mixer, GstMixerOptions * opts)
{
312
313
314
315
316
317
  GstMixerClass *klass;

  g_return_val_if_fail (mixer != NULL, NULL);
  g_return_val_if_fail (opts != NULL, NULL);

  klass = GST_MIXER_GET_CLASS (mixer);
318
319
320
321
322
323
324
325

  if (klass->get_option) {
    return klass->get_option (mixer, opts);
  }

  return NULL;
}

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/**
 * gst_mixer_get_mixer_flags:
 * @mixer: The #GstMixer implementation
 *
 * Get the set of supported flags for this mixer implementation.
 *
 * Returns: A set of or-ed GstMixerFlags for supported features.
 */
GstMixerFlags
gst_mixer_get_mixer_flags (GstMixer * mixer)
{
  GstMixerClass *klass;

  g_return_val_if_fail (mixer != NULL, FALSE);
  klass = GST_MIXER_GET_CLASS (mixer);

  if (klass->get_mixer_flags) {
    return klass->get_mixer_flags (mixer);
  }
  return GST_MIXER_FLAG_NONE;
}

/**
 * gst_mixer_mute_toggled:
 * @mixer: the #GstMixer (a #GstElement) that owns the track
 * @track: the GstMixerTrack that has change mute state.
 * @mute: the new state of the mute flag on the track
 *
 * This function is called by the mixer implementation to produce
 * a notification message on the bus indicating that the given track
 * has changed mute state.
 *
 * This function only works for GstElements that are implementing the
 * GstMixer interface, and the element needs to have been provided a bus.
 */
361
void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
362
gst_mixer_mute_toggled (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
363
{
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
364
365
366
  GstStructure *s;
  GstMessage *m;

367
  g_return_if_fail (mixer != NULL);
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
368
  g_return_if_fail (GST_IS_ELEMENT (mixer));
369
370
  g_return_if_fail (track != NULL);

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
371
372
373
  s = gst_structure_new (GST_MIXER_MESSAGE_NAME,
      "type", G_TYPE_STRING, "mute-toggled",
      "track", GST_TYPE_MIXER_TRACK, track, "mute", G_TYPE_BOOLEAN, mute, NULL);
374

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
375
376
377
378
  m = gst_message_new_element (GST_OBJECT (mixer), s);
  if (gst_element_post_message (GST_ELEMENT (mixer), m) == FALSE) {
    GST_WARNING ("This element has no bus, therefore no message sent!");
  }
379
380
}

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
381
382
383
384
385
386
387
388
389
390
391
392
393
/**
 * gst_mixer_record_toggled:
 * @mixer: the #GstMixer (a #GstElement) that owns the track
 * @track: the GstMixerTrack that has changed recording state.
 * @record: the new state of the record flag on the track
 *
 * This function is called by the mixer implementation to produce
 * a notification message on the bus indicating that the given track
 * has changed recording state.
 *
 * This function only works for GstElements that are implementing the
 * GstMixer interface, and the element needs to have been provided a bus.
 */
394
void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
395
396
gst_mixer_record_toggled (GstMixer * mixer,
    GstMixerTrack * track, gboolean record)
397
{
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
398
399
400
  GstStructure *s;
  GstMessage *m;

401
  g_return_if_fail (mixer != NULL);
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
402
  g_return_if_fail (GST_IS_ELEMENT (mixer));
403
404
  g_return_if_fail (track != NULL);

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
405
406
407
408
  s = gst_structure_new (GST_MIXER_MESSAGE_NAME,
      "type", G_TYPE_STRING, "record-toggled",
      "track", GST_TYPE_MIXER_TRACK, track,
      "record", G_TYPE_BOOLEAN, record, NULL);
409

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
410
411
412
413
  m = gst_message_new_element (GST_OBJECT (mixer), s);
  if (gst_element_post_message (GST_ELEMENT (mixer), m) == FALSE) {
    GST_WARNING ("This element has no bus, therefore no message sent!");
  }
414
415
}

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
416
417
418
419
420
421
422
423
424
425
426
427
428
/**
 * gst_mixer_volume_changed:
 * @mixer: the #GstMixer (a #GstElement) that owns the track
 * @track: the GstMixerTrack that has changed.
 * @volumes: Array of volume values, one per channel on the mixer track.
 *
 * This function is called by the mixer implementation to produce
 * a notification message on the bus indicating that the volume(s) for the
 * given track have changed.
 *
 * This function only works for GstElements that are implementing the
 * GstMixer interface, and the element needs to have been provided a bus.
 */
429
void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
430
gst_mixer_volume_changed (GstMixer * mixer,
431
    GstMixerTrack * track, gint * volumes)
432
{
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
433
434
435
436
437
438
  GstStructure *s;
  GstMessage *m;
  GValue l = { 0, };
  GValue v = { 0, };
  gint i;

439
  g_return_if_fail (mixer != NULL);
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
440
  g_return_if_fail (GST_IS_ELEMENT (mixer));
441
442
  g_return_if_fail (track != NULL);

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
443
444
445
  s = gst_structure_new (GST_MIXER_MESSAGE_NAME,
      "type", G_TYPE_STRING, "volume-changed",
      "track", GST_TYPE_MIXER_TRACK, track, NULL);
446

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
  g_value_init (&l, GST_TYPE_ARRAY);

  g_value_init (&v, G_TYPE_INT);

  /* FIXME 0.11: pass track->num_channels to the function */
  for (i = 0; i < track->num_channels; ++i) {
    g_value_set_int (&v, volumes[i]);
    gst_value_array_append_value (&l, &v);
  }
  g_value_unset (&v);

  gst_structure_set_value (s, "volumes", &l);
  g_value_unset (&l);

  m = gst_message_new_element (GST_OBJECT (mixer), s);
  if (gst_element_post_message (GST_ELEMENT (mixer), m) == FALSE) {
    GST_WARNING ("This element has no bus, therefore no message sent!");
  }
465
}
466

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
467
468
469
470
471
472
473
474
475
476
477
478
479
/**
 * gst_mixer_option_changed:
 * @mixer: the #GstMixer (a #GstElement) that owns the options 
 * @opts: the GstMixerOptions that has changed value.
 * @value: the new value of the GstMixerOptions.
 *
 * This function is called by the mixer implementation to produce
 * a notification message on the bus indicating that the given options
 * object has changed state. 
 *
 * This function only works for GstElements that are implementing the
 * GstMixer interface, and the element needs to have been provided a bus.
 */
480
481
void
gst_mixer_option_changed (GstMixer * mixer,
482
    GstMixerOptions * opts, gchar * value)
483
{
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
484
485
486
  GstStructure *s;
  GstMessage *m;

487
  g_return_if_fail (mixer != NULL);
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
488
  g_return_if_fail (GST_IS_ELEMENT (mixer));
489
490
  g_return_if_fail (opts != NULL);

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
491
492
493
494
495
496
497
498
499
500
501
  s = gst_structure_new (GST_MIXER_MESSAGE_NAME,
      "type", G_TYPE_STRING, "option-changed",
      "options", GST_TYPE_MIXER_OPTIONS, opts,
      "value", G_TYPE_STRING, value, NULL);

  m = gst_message_new_element (GST_OBJECT (mixer), s);
  if (gst_element_post_message (GST_ELEMENT (mixer), m) == FALSE) {
    GST_WARNING ("This element has no bus, therefore no message sent!");
  }
}

502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
/**
 * gst_mixer_options_list_changed:
 * @mixer: the #GstMixer (a #GstElement) that owns the options 
 * @opts: the GstMixerOptions whose list of values has changed
 *
 * This function is called by the mixer implementation to produce
 * a notification message on the bus indicating that the list of possible
 * options of a given options object has changed.
 *
 * The new options are not contained in the message on purpose. Applications
 * should call gst_mixer_option_get_values() on @opts to make @opts update
 * its internal state and obtain the new list of values.
 *
 * This function only works for GstElements that are implementing the
 * GstMixer interface, and the element needs to have been provided a bus
 * for this to work.
 *
 * Since: 0.10.18
 */
void
gst_mixer_options_list_changed (GstMixer * mixer, GstMixerOptions * opts)
{
  GstStructure *s;
  GstMessage *m;

  g_return_if_fail (mixer != NULL);
  g_return_if_fail (GST_IS_ELEMENT (mixer));
  g_return_if_fail (opts != NULL);
  g_return_if_fail (GST_IS_MIXER_OPTIONS (opts));

  /* we do not include the new list here on purpose, so that the application
   * has to use gst_mixer_options_get_values() to get the new list, which then
   * allows the mixer options object to update the internal GList in a somewhat
   * thread-safe way at least */
  s = gst_structure_new (GST_MIXER_MESSAGE_NAME,
      "type", G_TYPE_STRING, "options-list-changed",
      "options", GST_TYPE_MIXER_OPTIONS, opts, NULL);

  m = gst_message_new_element (GST_OBJECT (mixer), s);
  if (gst_element_post_message (GST_ELEMENT (mixer), m) == FALSE) {
    GST_WARNING ("This element has no bus, therefore no message sent!");
  }
}

/**
 * gst_mixer_mixer_changed:
 * @mixer: the #GstMixer (a #GstElement) which has changed
 *
 * This function is called by the mixer implementation to produce
 * a notification message on the bus indicating that the list of available
 * mixer tracks for a given mixer object has changed. Applications should
 * rebuild their interface when they receive this message.
 *
 * This function only works for GstElements that are implementing the
 * GstMixer interface, and the element needs to have been provided a bus.
 *
 * Since: 0.10.18
 */
void
gst_mixer_mixer_changed (GstMixer * mixer)
{
  GstStructure *s;
  GstMessage *m;

  g_return_if_fail (mixer != NULL);
  g_return_if_fail (GST_IS_ELEMENT (mixer));

  s = gst_structure_new (GST_MIXER_MESSAGE_NAME,
      "type", G_TYPE_STRING, "mixer-changed", NULL);

  m = gst_message_new_element (GST_OBJECT (mixer), s);
  if (gst_element_post_message (GST_ELEMENT (mixer), m) == FALSE) {
    GST_WARNING ("This element has no bus, therefore no message sent!");
  }
}

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
static gboolean
gst_mixer_message_is_mixer_message (GstMessage * message)
{
  const GstStructure *s;

  if (message == NULL)
    return FALSE;
  if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
    return FALSE;

  s = gst_message_get_structure (message);
  return gst_structure_has_name (s, GST_MIXER_MESSAGE_NAME);
}

/**
 * gst_mixer_message_get_type:
 * @message: A GstMessage to inspect.
 *
 * Check a bus message to see if it is a GstMixer notification
 * message and return the GstMixerMessageType identifying which
 * type of notification it is.
 *
600
 * Returns: The type of the GstMixerMessage, or GST_MIXER_MESSAGE_INVALID
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
 * if the message is not a GstMixer notification.
 *
 * Since: 0.10.14
 */
GstMixerMessageType
gst_mixer_message_get_type (GstMessage * message)
{
  const GstStructure *s;
  const gchar *m_type;

  if (!gst_mixer_message_is_mixer_message (message))
    return GST_MIXER_MESSAGE_INVALID;

  s = gst_message_get_structure (message);
  m_type = gst_structure_get_string (s, "type");
  g_return_val_if_fail (m_type != NULL, GST_MIXER_MESSAGE_INVALID);

  if (g_str_equal (m_type, "mute-toggled"))
    return GST_MIXER_MESSAGE_MUTE_TOGGLED;
  else if (g_str_equal (m_type, "record-toggled"))
    return GST_MIXER_MESSAGE_RECORD_TOGGLED;
  else if (g_str_equal (m_type, "volume-changed"))
    return GST_MIXER_MESSAGE_VOLUME_CHANGED;
  else if (g_str_equal (m_type, "option-changed"))
    return GST_MIXER_MESSAGE_OPTION_CHANGED;
626
627
628
629
  else if (g_str_equal (m_type, "options-list-changed"))
    return GST_MIXER_MESSAGE_OPTIONS_LIST_CHANGED;
  else if (g_str_equal (m_type, "mixer-changed"))
    return GST_MIXER_MESSAGE_MIXER_CHANGED;
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
630
631
632
633

  return GST_MIXER_MESSAGE_INVALID;
}

634
635
636
#define GST_MIXER_MESSAGE_HAS_TYPE(msg,msg_type) \
(gst_mixer_message_get_type (msg) == GST_MIXER_MESSAGE_ ## msg_type)

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
/**
 * gst_mixer_message_parse_mute_toggled:
 * @message: A mute-toggled change notification message.
 * @track: Pointer to hold a GstMixerTrack object, or NULL.
 * @mute: A pointer to a gboolean variable, or NULL.
 *
 * Extracts the contents of a mute-toggled bus message. Reads
 * the GstMixerTrack that has changed, and the new value of the mute
 * flag.
 *
 * The GstMixerTrack remains valid until the message is freed.
 *
 * Since: 0.10.14
 */
void
gst_mixer_message_parse_mute_toggled (GstMessage * message,
    GstMixerTrack ** track, gboolean * mute)
{
  const GstStructure *s;

  g_return_if_fail (gst_mixer_message_is_mixer_message (message));
658
  g_return_if_fail (GST_MIXER_MESSAGE_HAS_TYPE (message, MUTE_TOGGLED));
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
659

660
  s = gst_message_get_structure (message);
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694

  if (track) {
    const GValue *v = gst_structure_get_value (s, "track");

    g_return_if_fail (v != NULL);
    *track = (GstMixerTrack *) g_value_get_object (v);
    g_return_if_fail (GST_IS_MIXER_TRACK (*track));
  }

  if (mute)
    g_return_if_fail (gst_structure_get_boolean (s, "mute", mute));
}

/**
 * gst_mixer_message_parse_record_toggled:
 * @message: A record-toggled change notification message.
 * @track: Pointer to hold a GstMixerTrack object, or NULL.
 * @record: A pointer to a gboolean variable, or NULL.
 *
 * Extracts the contents of a record-toggled bus message. Reads
 * the GstMixerTrack that has changed, and the new value of the 
 * recording flag.
 *
 * The GstMixerTrack remains valid until the message is freed.
 *
 * Since: 0.10.14
 */
void
gst_mixer_message_parse_record_toggled (GstMessage * message,
    GstMixerTrack ** track, gboolean * record)
{
  const GstStructure *s;

  g_return_if_fail (gst_mixer_message_is_mixer_message (message));
695
  g_return_if_fail (GST_MIXER_MESSAGE_HAS_TYPE (message, RECORD_TOGGLED));
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
696

697
  s = gst_message_get_structure (message);
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734

  if (track) {
    const GValue *v = gst_structure_get_value (s, "track");

    g_return_if_fail (v != NULL);
    *track = (GstMixerTrack *) g_value_get_object (v);
    g_return_if_fail (GST_IS_MIXER_TRACK (*track));
  }

  if (record)
    g_return_if_fail (gst_structure_get_boolean (s, "record", record));
}

/**
 * gst_mixer_message_parse_volume_changed:
 * @message: A volume-changed change notification message.
 * @track: Pointer to hold a GstMixerTrack object, or NULL.
 * @volumes: A pointer to receive an array of gint values, or NULL.
 * @num_channels: Result location to receive the number of channels, or NULL.
 *
 * Parses a volume-changed notification message and extracts the track object
 * it refers to, as well as an array of volumes and the size of the volumes array.
 *
 * The track object remains valid until the message is freed.
 *
 * The caller must free the array returned in the volumes parameter using g_free
 * when they are done with it.
 *
 * Since: 0.10.14
 */
void
gst_mixer_message_parse_volume_changed (GstMessage * message,
    GstMixerTrack ** track, gint ** volumes, gint * num_channels)
{
  const GstStructure *s;

  g_return_if_fail (gst_mixer_message_is_mixer_message (message));
735
  g_return_if_fail (GST_MIXER_MESSAGE_HAS_TYPE (message, VOLUME_CHANGED));
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
736

737
  s = gst_message_get_structure (message);
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789

  if (track) {
    const GValue *v = gst_structure_get_value (s, "track");

    g_return_if_fail (v != NULL);
    *track = (GstMixerTrack *) g_value_get_object (v);
    g_return_if_fail (GST_IS_MIXER_TRACK (*track));
  }

  if (volumes || num_channels) {
    gint n_chans, i;
    const GValue *v = gst_structure_get_value (s, "volumes");

    g_return_if_fail (v != NULL);
    g_return_if_fail (GST_VALUE_HOLDS_ARRAY (v));

    n_chans = gst_value_array_get_size (v);
    if (num_channels)
      *num_channels = n_chans;

    if (volumes) {
      *volumes = g_new (gint, n_chans);
      for (i = 0; i < n_chans; i++) {
        const GValue *e = gst_value_array_get_value (v, i);

        g_return_if_fail (e != NULL && G_VALUE_HOLDS_INT (e));
        (*volumes)[i] = g_value_get_int (e);
      }
    }
  }
}

/**
 * gst_mixer_message_parse_option_changed:
 * @message: A volume-changed change notification message.
 * @options: Pointer to hold a GstMixerOptions object, or NULL.
 * @value: Result location to receive the new options value, or NULL.
 *
 * Extracts the GstMixerOptions and new value from a option-changed bus notification
 * message.
 *
 * The options and value returned remain valid until the message is freed.
 *
 * Since: 0.10.14
 */
void
gst_mixer_message_parse_option_changed (GstMessage * message,
    GstMixerOptions ** options, const gchar ** value)
{
  const GstStructure *s;

  g_return_if_fail (gst_mixer_message_is_mixer_message (message));
790
  g_return_if_fail (GST_MIXER_MESSAGE_HAS_TYPE (message, OPTION_CHANGED));
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
791

792
  s = gst_message_get_structure (message);
Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
793
794
795
796
797
798
799
800

  if (options) {
    const GValue *v = gst_structure_get_value (s, "options");

    g_return_if_fail (v != NULL);
    *options = (GstMixerOptions *) g_value_get_object (v);
    g_return_if_fail (GST_IS_MIXER_OPTIONS (*options));
  }
801

Marc-Andre Lureau's avatar
Marc-Andre Lureau committed
802
803
  if (value)
    *value = gst_structure_get_string (s, "value");
804
}
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837

/**
 * gst_mixer_message_parse_options_list_changed:
 * @message: A volume-changed change notification message.
 * @options: Pointer to hold a GstMixerOptions object, or NULL.
 *
 * Extracts the GstMixerOptions whose value list has changed from an
 * options-list-changed bus notification message.
 *
 * The options object returned remains valid until the message is freed. You
 * do not need to unref it.
 *
 * Since: 0.10.18
 */
void
gst_mixer_message_parse_options_list_changed (GstMessage * message,
    GstMixerOptions ** options)
{
  const GstStructure *s;

  g_return_if_fail (gst_mixer_message_is_mixer_message (message));
  g_return_if_fail (GST_MIXER_MESSAGE_HAS_TYPE (message, OPTIONS_LIST_CHANGED));

  s = gst_message_get_structure (message);

  if (options) {
    const GValue *v = gst_structure_get_value (s, "options");

    g_return_if_fail (v != NULL);
    *options = (GstMixerOptions *) g_value_get_object (v);
    g_return_if_fail (GST_IS_MIXER_OPTIONS (*options));
  }
}