File: module-mixer-api.c

package info (click to toggle)
wireplumber 0.5.12-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,244 kB
  • sloc: ansic: 41,043; python: 391; sh: 62; makefile: 57; xml: 23
file content (634 lines) | stat: -rw-r--r-- 19,193 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
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
626
627
628
629
630
631
632
633
634
/* WirePlumber
 *
 * Copyright © 2021 Collabora Ltd.
 *    @author George Kiagiadakis <george.kiagiadakis@collabora.com>
 *
 * SPDX-License-Identifier: MIT
 */

#include <wp/wp.h>
#include <math.h>
#include <pipewire/pipewire.h>
#include <spa/pod/iter.h>
#include <spa/param/audio/raw.h>

WP_DEFINE_LOCAL_LOG_TOPIC ("m-mixer-api")

struct volume {
  uint8_t channels;
  float values[SPA_AUDIO_MAX_CHANNELS];
};

struct channel_map {
  uint8_t channels;
  uint32_t map[SPA_AUDIO_MAX_CHANNELS];
};

struct node_info {
  guint32 seq;

  guint32 device_id;
  gint32 route_index;
  gint32 route_device;

  struct volume volume;
  struct volume monitorVolume;
  struct channel_map map;
  gboolean mute;
  gboolean monitorMute;
  float svolume;
  float base;
  float step;
};

struct _WpMixerApi
{
  WpPlugin parent;
  WpObjectManager *om;
  GHashTable *node_infos;
  guint32 seq;

  /* properties */
  gint scale;
};

enum {
  ACTION_SET_VOLUME,
  ACTION_GET_VOLUME,
  SIGNAL_CHANGED,
  N_SIGNALS
};

enum {
  PROP_0,
  PROP_SCALE,
};

static guint signals[N_SIGNALS] = {0};

G_DECLARE_FINAL_TYPE (WpMixerApi, wp_mixer_api, WP, MIXER_API, WpPlugin)
G_DEFINE_TYPE (WpMixerApi, wp_mixer_api, WP_TYPE_PLUGIN)

enum {
  SCALE_LINEAR,
  SCALE_CUBIC,
};

static GType
wp_mixer_api_volume_scale_enum_get_type (void)
{
  static gsize gtype_id = 0;
  static const GEnumValue values[] = {
    { (gint) SCALE_LINEAR, "SCALE_LINEAR", "linear" },
    { (gint) SCALE_CUBIC, "SCALE_CUBIC", "cubic" },
    { 0, NULL, NULL }
  };
  if (g_once_init_enter (&gtype_id)) {
    GType new_type = g_enum_register_static (
        g_intern_static_string ("WpMixerApiVolumeScale"), values);
    g_once_init_leave (&gtype_id, new_type);
  }
  return (GType) gtype_id;
}

static void
wp_mixer_api_init (WpMixerApi * self)
{
}

static void
wp_mixer_api_get_property (GObject * object, guint property_id,
    GValue * value, GParamSpec * pspec)
{
  WpMixerApi *self = WP_MIXER_API (object);

  switch (property_id) {
  case PROP_SCALE:
    g_value_set_enum (value, self->scale);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
wp_mixer_api_set_property (GObject * object, guint property_id,
    const GValue * value, GParamSpec * pspec)
{
  WpMixerApi *self = WP_MIXER_API (object);

  switch (property_id) {
  case PROP_SCALE:
    self->scale = g_value_get_enum (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static gboolean
node_info_fill (struct node_info * info, WpSpaPod * props)
{
  g_autoptr (WpSpaPod) channelVolumes = NULL;
  g_autoptr (WpSpaPod) channelMap = NULL;
  g_autoptr (WpSpaPod) monitorVolumes = NULL;

  if (!wp_spa_pod_get_object (props, NULL,
          "mute", "b", &info->mute,
          "channelVolumes", "P", &channelVolumes,
          NULL))
    return FALSE;

  /* default values */
  info->svolume = 1.0;
  info->base = 1.0;
  info->step = 1.0 / 65536.0;

  wp_spa_pod_get_object (props, NULL,
      "channelMap", "?P", &channelMap,
      "volumeBase", "?f", &info->base,
      "volumeStep", "?f", &info->step,
      "volume",     "?f", &info->svolume,
      "monitorVolumes", "?P", &monitorVolumes,
      "monitorMute", "?b", &info->monitorMute,
      NULL);

  info->volume.channels = spa_pod_copy_array (
      wp_spa_pod_get_spa_pod (channelVolumes), SPA_TYPE_Float,
      info->volume.values, SPA_AUDIO_MAX_CHANNELS);

  if (channelMap)
    info->map.channels = spa_pod_copy_array (
        wp_spa_pod_get_spa_pod (channelMap), SPA_TYPE_Id,
        info->map.map, SPA_AUDIO_MAX_CHANNELS);

  if (monitorVolumes)
    info->monitorVolume.channels = spa_pod_copy_array (
        wp_spa_pod_get_spa_pod (monitorVolumes), SPA_TYPE_Float,
        info->monitorVolume.values, SPA_AUDIO_MAX_CHANNELS);

  return TRUE;
}

static void
collect_node_info (WpMixerApi * self, struct node_info *info,
    WpPipewireObject * node)
{
  g_autoptr (WpPipewireObject) dev = NULL;
  const gchar *str = NULL;
  gboolean have_volume = FALSE;

  info->device_id = SPA_ID_INVALID;
  info->route_index = -1;
  info->route_device = -1;

  if ((str = wp_pipewire_object_get_property (node, PW_KEY_DEVICE_ID))) {
    dev = wp_object_manager_lookup (self->om, WP_TYPE_DEVICE,
        WP_CONSTRAINT_TYPE_G_PROPERTY, "bound-id", "=s", str, NULL);
  }

  if (dev && (str = wp_pipewire_object_get_property (node, "card.profile.device"))) {
    gint32 p_device = atoi (str);
    g_autoptr (WpIterator) it = NULL;
    g_auto (GValue) val = G_VALUE_INIT;

    it = wp_pipewire_object_enum_params_sync (dev, "Route", NULL);
    for (; it && wp_iterator_next (it, &val); g_value_unset (&val)) {
      WpSpaPod *param = g_value_get_boxed (&val);
      gint32 r_index = -1, r_device = -1;
      g_autoptr (WpSpaPod) props = NULL;

      if (!wp_spa_pod_get_object (param, NULL,
              "index", "i", &r_index,
              "device", "i", &r_device,
              "props", "P", &props,
              NULL))
        continue;
      if (r_device != p_device)
        continue;

      if (props && node_info_fill (info, props)) {
        info->device_id = wp_proxy_get_bound_id (WP_PROXY (dev));
        info->route_index = r_index;
        info->route_device = r_device;
        have_volume = TRUE;
        g_value_unset (&val);
        break;
      }
    }
  }

  if (!have_volume) {
    g_autoptr (WpIterator) it = NULL;
    g_auto (GValue) val = G_VALUE_INIT;

    it = wp_pipewire_object_enum_params_sync (node, "Props", NULL);
    for (; it && wp_iterator_next (it, &val); g_value_unset (&val)) {
      WpSpaPod *param = g_value_get_boxed (&val);
      if (node_info_fill (info, param)) {
        g_value_unset (&val);
        break;
      }
    }
  }
}

static void on_objects_changed (WpObjectManager * om, WpMixerApi * self);

static void
on_sync_done (WpCore * core, GAsyncResult * res, WpMixerApi * self)
{
  g_autoptr (GError) error = NULL;
  if (!wp_core_sync_finish (core, res, &error))
    wp_warning_object (core, "sync error: %s", error->message);
  if (self->om) {
    on_objects_changed (self->om, self);
  }
}

static void
on_params_changed (WpPipewireObject * obj, const gchar * param_name,
    WpMixerApi * self)
{
  if ((WP_IS_NODE (obj) && !g_strcmp0 (param_name, "Props")) ||
      (WP_IS_DEVICE (obj) && !g_strcmp0 (param_name, "Route"))) {
    g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self));
    wp_core_sync (core, NULL, (GAsyncReadyCallback) on_sync_done, self);
  }
}

static void
on_objects_changed (WpObjectManager * om, WpMixerApi * self)
{
  g_autoptr (WpIterator) it =
      wp_object_manager_new_filtered_iterator (om, WP_TYPE_NODE, NULL);
  g_auto (GValue) val = G_VALUE_INIT;
  GHashTableIter infos_it;
  struct node_info *info;
  struct node_info old;

  self->seq++;

  for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
    WpPipewireObject *node = g_value_get_object (&val);
    guint id = wp_proxy_get_bound_id (WP_PROXY (node));

    info = g_hash_table_lookup (self->node_infos, GUINT_TO_POINTER (id));
    if (!info) {
      info = g_slice_new0 (struct node_info);
      g_hash_table_insert (self->node_infos, GUINT_TO_POINTER (id), info);
    }
    info->seq = self->seq;

    old = *info;
    collect_node_info (self, info, node);
    if (memcmp (&old, info, sizeof (struct node_info)) != 0) {
      wp_debug_object (self, "node %u changed volume props", id);
      g_signal_emit (self, signals[SIGNAL_CHANGED], 0, id);
    }
  }

  /* remove node_info of nodes that were removed from the object manager */
  g_hash_table_iter_init (&infos_it, self->node_infos);
  while (g_hash_table_iter_next (&infos_it, NULL, (gpointer *) &info)) {
    if (info->seq != self->seq)
      g_hash_table_iter_remove (&infos_it);
  }
}

static void
on_object_added (WpObjectManager * om, WpProxy * obj, WpMixerApi * self)
{
  g_signal_connect (obj, "params-changed", G_CALLBACK (on_params_changed), self);
}

static void
on_object_removed (WpObjectManager * om, WpProxy * obj, WpMixerApi * self)
{
  g_signal_handlers_disconnect_by_func (obj, G_CALLBACK (on_params_changed), self);
}

static void
node_info_free (gpointer info)
{
  g_slice_free (struct node_info, info);
}

static void
on_om_installed (WpObjectManager * om, WpMixerApi * self)
{
  wp_object_update_features (WP_OBJECT (self), WP_PLUGIN_FEATURE_ENABLED, 0);
}

static void
wp_mixer_api_enable (WpPlugin * plugin, WpTransition * transition)
{
  WpMixerApi * self = WP_MIXER_API (plugin);
  g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (plugin));
  g_return_if_fail (core);

  self->node_infos = g_hash_table_new_full (g_direct_hash, g_direct_equal,
      NULL, node_info_free);

  self->om = wp_object_manager_new ();
  wp_object_manager_add_interest (self->om, WP_TYPE_NODE,
      WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "media.class", "#s", "*Audio*",
      NULL);
  wp_object_manager_add_interest (self->om, WP_TYPE_DEVICE,
      WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "media.class", "=s", "Audio/Device",
      NULL);
  wp_object_manager_request_object_features (self->om,
      WP_TYPE_GLOBAL_PROXY, WP_OBJECT_FEATURES_ALL);
  g_signal_connect_object (self->om, "objects-changed",
      G_CALLBACK (on_objects_changed), self, 0);
  g_signal_connect_object (self->om, "object-added",
      G_CALLBACK (on_object_added), self, 0);
  g_signal_connect_object (self->om, "object-removed",
      G_CALLBACK (on_object_removed), self, 0);
  g_signal_connect_object (self->om, "installed",
      G_CALLBACK (on_om_installed), self, 0);
  wp_core_install_object_manager (core, self->om);
}

static void
wp_mixer_api_disable (WpPlugin * plugin)
{
  WpMixerApi * self = WP_MIXER_API (plugin);

  {
    g_autoptr (WpIterator) it = wp_object_manager_new_iterator (self->om);
    g_auto (GValue) val = G_VALUE_INIT;

    for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
      WpProxy *obj = g_value_get_object (&val);
      on_object_removed (self->om, obj, self);
    }
  }

  g_clear_object (&self->om);
  g_clear_pointer (&self->node_infos, g_hash_table_unref);
}

static inline gdouble
volume_from_linear (float vol, gint scale)
{
  if (vol <= 0.0f)
    return 0.0;
  else if (scale == SCALE_CUBIC)
    return cbrt(vol);
  else
    return vol;
}

static inline float
volume_to_linear (gdouble vol, gint scale)
{
  if (vol <= 0.0f)
    return 0.0;
  else if (scale == SCALE_CUBIC)
    return vol * vol * vol;
  else
    return vol;
}

static gboolean
wp_mixer_api_set_volume (WpMixerApi * self, guint32 id, GVariant * vvolume)
{
  struct node_info *info = self->node_infos ?
      g_hash_table_lookup (self->node_infos, GUINT_TO_POINTER (id)) : NULL;
  struct volume new_volume = {0};
  struct volume new_monVolume = {0};
  gboolean has_mute = FALSE;
  gboolean has_monitorMute = FALSE;
  gboolean mute = FALSE;
  gboolean monitorMute = FALSE;
  WpSpaIdTable t_audioChannel =
      wp_spa_id_table_from_name ("Spa:Enum:AudioChannel");

  if (!info || !vvolume)
    return FALSE;

  if (g_variant_is_of_type (vvolume, G_VARIANT_TYPE_DOUBLE)) {
    gdouble val = g_variant_get_double (vvolume);
    new_volume = info->volume;
    for (uint i = 0; i < new_volume.channels; i++)
      new_volume.values[i] = volume_to_linear (val, self->scale);
  }
  else if (g_variant_is_of_type (vvolume, G_VARIANT_TYPE_VARDICT)) {
    GVariantIter *iter;
    const gchar *idx_str;
    GVariant *v;
    gdouble val;

    has_mute = g_variant_lookup (vvolume, "mute", "b", &mute);
    has_monitorMute = g_variant_lookup (vvolume, "monitorMute", "b", &monitorMute);

    if (g_variant_lookup (vvolume, "volume", "d", &val)) {
      new_volume = info->volume;
      for (uint i = 0; i < new_volume.channels; i++)
        new_volume.values[i] = volume_to_linear (val, self->scale);
    }

    if (g_variant_lookup (vvolume, "monitorVolume", "d", &val)) {
      new_monVolume = info->monitorVolume;
      for (uint i = 0; i < new_monVolume.channels; i++)
        new_monVolume.values[i] = volume_to_linear (val, self->scale);
    }

    if (g_variant_lookup (vvolume, "channelVolumes", "a{sv}", &iter)) {
      /* keep the existing volume values for unspecified channels */
      new_volume = info->volume;
      new_monVolume = info->monitorVolume;

      while (g_variant_iter_loop (iter, "{&sv}", &idx_str, &v)) {
        guint index = atoi (idx_str);
        const gchar *channel_str = NULL;
        WpSpaIdValue channel = NULL;

        if (g_variant_lookup (v, "channel", "&s", &channel_str)) {
          channel = wp_spa_id_table_find_value_from_short_name (
              t_audioChannel, channel_str);
          if (!channel)
            wp_notice_object (self, "invalid channel: %s", channel_str);
        }

        if (channel) {
          for (uint i = 0; i < info->map.channels; i++)
            if (info->map.map[i] == wp_spa_id_value_number (channel)) {
              index = i;
              break;
            }
        }

        if (index >= MIN(new_volume.channels, SPA_AUDIO_MAX_CHANNELS)) {
          wp_notice_object (self, "invalid channel index: %u", index);
          continue;
        }

        if (g_variant_lookup (v, "volume", "d", &val)) {
          new_volume.values[index] = volume_to_linear (val, self->scale);
        }
        if (g_variant_lookup (v, "monitorVolume", "d", &val)) {
          new_monVolume.values[index] = volume_to_linear (val, self->scale);
        }
      }
      g_variant_iter_free (iter);
    }
  } else {
    return FALSE;
  }

  /* set param */
  g_autoptr (WpSpaPod) props = NULL;
  g_autoptr (WpSpaPodBuilder) b =
      wp_spa_pod_builder_new_object ("Spa:Pod:Object:Param:Props", "Props");

  if (new_volume.channels > 0)
    wp_spa_pod_builder_add (b, "channelVolumes", "a",
        sizeof(float), SPA_TYPE_Float,
        new_volume.channels, new_volume.values, NULL);
  if (new_monVolume.channels > 0)
    wp_spa_pod_builder_add (b, "monitorVolumes", "a",
        sizeof(float), SPA_TYPE_Float,
        new_monVolume.channels, new_monVolume.values, NULL);
  if (has_mute)
    wp_spa_pod_builder_add (b, "mute", "b", mute, NULL);
  if (has_monitorMute)
    wp_spa_pod_builder_add (b, "monitorMute", "b", monitorMute, NULL);

  props = wp_spa_pod_builder_end (b);

  if (info->device_id != SPA_ID_INVALID) {
    g_autoptr (WpPipewireObject) device = wp_object_manager_lookup (self->om,
        WP_TYPE_DEVICE, WP_CONSTRAINT_TYPE_G_PROPERTY,
        "bound-id", "=u", info->device_id, NULL);
    g_return_val_if_fail (device != NULL, FALSE);

    wp_pipewire_object_set_param (device, "Route", 0, wp_spa_pod_new_object (
        "Spa:Pod:Object:Param:Route", "Route",
        "index", "i", info->route_index,
        "device", "i", info->route_device,
        "props", "P", props,
        "save", "b", true,
        NULL));
  } else {
    g_autoptr (WpPipewireObject) node = wp_object_manager_lookup (self->om,
        WP_TYPE_NODE, WP_CONSTRAINT_TYPE_G_PROPERTY,
        "bound-id", "=u", id, NULL);
    g_return_val_if_fail (node != NULL, FALSE);

    wp_pipewire_object_set_param (node, "Props", 0, g_steal_pointer (&props));
  }

  return TRUE;
}

static GVariant *
wp_mixer_api_get_volume (WpMixerApi * self, guint32 id)
{
  struct node_info *info = self->node_infos ?
      g_hash_table_lookup (self->node_infos, GUINT_TO_POINTER (id)) : NULL;
  g_auto (GVariantBuilder) b =
      G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
  g_auto (GVariantBuilder) b_vol =
      G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
  WpSpaIdTable t_audioChannel =
      wp_spa_id_table_from_name ("Spa:Enum:AudioChannel");

  if (!info)
    return NULL;

  g_variant_builder_add (&b, "{sv}", "id", g_variant_new_uint32 (id));
  g_variant_builder_add (&b, "{sv}", "mute", g_variant_new_boolean (info->mute));
  g_variant_builder_add (&b, "{sv}", "base", g_variant_new_double (info->base));
  g_variant_builder_add (&b, "{sv}", "step", g_variant_new_double (info->step));
  g_variant_builder_add (&b, "{sv}", "volume", g_variant_new_double (
          volume_from_linear ((info->volume.channels > 0) ?
              info->volume.values[0] : info->svolume, self->scale)));
  if (info->monitorVolume.channels > 0) {
    g_variant_builder_add (&b, "{sv}", "monitorVolume", g_variant_new_double (
          volume_from_linear (info->monitorVolume.values[0], self->scale)));
  }
  g_variant_builder_add (&b, "{sv}", "monitorMute", g_variant_new_boolean (info->monitorMute));

  for (guint i = 0; i < info->volume.channels; i++) {
    gchar index_str[10];
    g_auto (GVariantBuilder) b_vol_nested =
        G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);

    g_variant_builder_add (&b_vol_nested, "{sv}",
        "volume", g_variant_new_double (
            volume_from_linear (info->volume.values[i], self->scale)));

    if (i < info->map.channels) {
      WpSpaIdValue v =
          wp_spa_id_table_find_value (t_audioChannel, info->map.map[i]);
      if (v) {
        const gchar *channel_str = wp_spa_id_value_short_name (v);
        g_variant_builder_add (&b_vol_nested, "{sv}",
          "channel", g_variant_new_string (channel_str));
      }
    }

    if (i < info->monitorVolume.channels) {
      g_variant_builder_add (&b_vol_nested, "{sv}",
          "monitorVolume", g_variant_new_double (
              volume_from_linear (info->monitorVolume.values[i], self->scale)));
    }

    g_snprintf (index_str, 10, "%u", i);
    g_variant_builder_add (&b_vol, "{sv}", index_str,
        g_variant_builder_end (&b_vol_nested));
  }

  g_variant_builder_add (&b, "{sv}",
      "channelVolumes", g_variant_builder_end (&b_vol));
  return g_variant_builder_end (&b);
}

static void
wp_mixer_api_class_init (WpMixerApiClass * klass)
{
  GObjectClass *object_class = (GObjectClass *) klass;
  WpPluginClass *plugin_class = (WpPluginClass *) klass;

  object_class->set_property = wp_mixer_api_set_property;
  object_class->get_property = wp_mixer_api_get_property;

  plugin_class->enable = wp_mixer_api_enable;
  plugin_class->disable = wp_mixer_api_disable;

  g_object_class_install_property (object_class, PROP_SCALE,
      g_param_spec_enum ("scale", "scale", "scale",
          wp_mixer_api_volume_scale_enum_get_type (),
          SCALE_LINEAR, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

  signals[ACTION_SET_VOLUME] = g_signal_new_class_handler (
      "set-volume", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
      (GCallback) wp_mixer_api_set_volume,
      NULL, NULL, NULL,
      G_TYPE_BOOLEAN, 2, G_TYPE_UINT, G_TYPE_VARIANT);

  signals[ACTION_GET_VOLUME] = g_signal_new_class_handler (
      "get-volume", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
      (GCallback) wp_mixer_api_get_volume,
      NULL, NULL, NULL,
      G_TYPE_VARIANT, 1, G_TYPE_UINT);

  signals[SIGNAL_CHANGED] = g_signal_new (
      "changed", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT);
}

WP_PLUGIN_EXPORT GObject *
wireplumber__module_init (WpCore * core, WpSpaJson * args, GError ** error)
{
  return G_OBJECT (g_object_new (wp_mixer_api_get_type (),
      "name", "mixer-api",
      "core", core,
      NULL));
}