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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
|
/*
* Copyright (C) 2014 Michal Ratajsky <michal.ratajsky@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the licence, 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <libmatemixer/matemixer.h>
#include <libmatemixer/matemixer-private.h>
#include <pulse/pulseaudio.h>
#include <pulse/ext-stream-restore.h>
#include "pulse-connection.h"
#include "pulse-ext-stream.h"
#include "pulse-helpers.h"
#include "pulse-stream.h"
#include "pulse-stream-control.h"
struct _PulseExtStreamPrivate
{
guint volume;
pa_cvolume cvolume;
pa_channel_map channel_map;
MateMixerAppInfo *app_info;
PulseConnection *connection;
};
enum {
PROP_0,
PROP_CONNECTION,
PROP_APP_INFO,
N_PROPERTIES
};
static GParamSpec *properties[N_PROPERTIES] = { NULL, };
static void pulse_ext_stream_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
static void pulse_ext_stream_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static void pulse_ext_stream_dispose (GObject *object);
static void pulse_ext_stream_finalize (GObject *object);
G_DEFINE_TYPE_WITH_PRIVATE (PulseExtStream, pulse_ext_stream, MATE_MIXER_TYPE_STORED_CONTROL)
static MateMixerAppInfo * pulse_ext_stream_get_app_info (MateMixerStreamControl *mmsc);
static gboolean pulse_ext_stream_set_stream (MateMixerStreamControl *mmsc,
MateMixerStream *mms);
static gboolean pulse_ext_stream_set_mute (MateMixerStreamControl *mmsc,
gboolean mute);
static guint pulse_ext_stream_get_num_channels (MateMixerStreamControl *mmsc);
static guint pulse_ext_stream_get_volume (MateMixerStreamControl *mmsc);
static gboolean pulse_ext_stream_set_volume (MateMixerStreamControl *mmsc,
guint volume);
static guint pulse_ext_stream_get_channel_volume (MateMixerStreamControl *mmsc,
guint channel);
static gboolean pulse_ext_stream_set_channel_volume (MateMixerStreamControl *mmsc,
guint channel,
guint volume);
static MateMixerChannelPosition pulse_ext_stream_get_channel_position (MateMixerStreamControl *mmsc,
guint channel);
static gboolean pulse_ext_stream_has_channel_position (MateMixerStreamControl *mmsc,
MateMixerChannelPosition position);
static gboolean pulse_ext_stream_set_balance (MateMixerStreamControl *mmsc,
gfloat balance);
static gboolean pulse_ext_stream_set_fade (MateMixerStreamControl *mmsc,
gfloat fade);
static guint pulse_ext_stream_get_min_volume (MateMixerStreamControl *mmsc);
static guint pulse_ext_stream_get_max_volume (MateMixerStreamControl *mmsc);
static guint pulse_ext_stream_get_normal_volume (MateMixerStreamControl *mmsc);
static guint pulse_ext_stream_get_base_volume (MateMixerStreamControl *mmsc);
static void fill_ext_stream_restore_info (PulseExtStream *ext,
pa_ext_stream_restore_info *info);
static gboolean write_cvolume (PulseExtStream *ext,
const pa_cvolume *cvolume);
static void store_cvolume (PulseExtStream *ext,
const pa_cvolume *cvolume);
static void
pulse_ext_stream_class_init (PulseExtStreamClass *klass)
{
GObjectClass *object_class;
MateMixerStreamControlClass *control_class;
object_class = G_OBJECT_CLASS (klass);
object_class->dispose = pulse_ext_stream_dispose;
object_class->finalize = pulse_ext_stream_finalize;
object_class->get_property = pulse_ext_stream_get_property;
object_class->set_property = pulse_ext_stream_set_property;
control_class = MATE_MIXER_STREAM_CONTROL_CLASS (klass);
control_class->get_app_info = pulse_ext_stream_get_app_info;
control_class->set_stream = pulse_ext_stream_set_stream;
control_class->set_mute = pulse_ext_stream_set_mute;
control_class->get_num_channels = pulse_ext_stream_get_num_channels;
control_class->get_volume = pulse_ext_stream_get_volume;
control_class->set_volume = pulse_ext_stream_set_volume;
control_class->get_channel_volume = pulse_ext_stream_get_channel_volume;
control_class->set_channel_volume = pulse_ext_stream_set_channel_volume;
control_class->get_channel_position = pulse_ext_stream_get_channel_position;
control_class->has_channel_position = pulse_ext_stream_has_channel_position;
control_class->set_balance = pulse_ext_stream_set_balance;
control_class->set_fade = pulse_ext_stream_set_fade;
control_class->get_min_volume = pulse_ext_stream_get_min_volume;
control_class->get_max_volume = pulse_ext_stream_get_max_volume;
control_class->get_normal_volume = pulse_ext_stream_get_normal_volume;
control_class->get_base_volume = pulse_ext_stream_get_base_volume;
properties[PROP_CONNECTION] =
g_param_spec_object ("connection",
"Connection",
"PulseAudio connection",
PULSE_TYPE_CONNECTION,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
properties[PROP_APP_INFO] =
g_param_spec_boxed ("app-info",
"Application information",
"Application information",
MATE_MIXER_TYPE_APP_INFO,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
static void
pulse_ext_stream_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
PulseExtStream *ext;
ext = PULSE_EXT_STREAM (object);
switch (param_id) {
case PROP_CONNECTION:
g_value_set_object (value, ext->priv->connection);
break;
case PROP_APP_INFO:
g_value_set_boxed (value, ext->priv->app_info);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
pulse_ext_stream_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
PulseExtStream *ext;
ext = PULSE_EXT_STREAM (object);
switch (param_id) {
case PROP_CONNECTION:
/* Construct-only object */
ext->priv->connection = g_value_dup_object (value);
break;
case PROP_APP_INFO:
/* Construct-only boxed */
ext->priv->app_info = g_value_dup_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
pulse_ext_stream_init (PulseExtStream *ext)
{
ext->priv = pulse_ext_stream_get_instance_private (ext);
}
static void
pulse_ext_stream_dispose (GObject *object)
{
PulseExtStream *ext;
ext = PULSE_EXT_STREAM (object);
g_clear_object (&ext->priv->connection);
G_OBJECT_CLASS (pulse_ext_stream_parent_class)->dispose (object);
}
static void
pulse_ext_stream_finalize (GObject *object)
{
PulseExtStream *ext;
ext = PULSE_EXT_STREAM (object);
if (ext->priv->app_info != NULL)
_mate_mixer_app_info_free (ext->priv->app_info);
G_OBJECT_CLASS (pulse_ext_stream_parent_class)->finalize (object);
}
PulseExtStream *
pulse_ext_stream_new (PulseConnection *connection,
const pa_ext_stream_restore_info *info,
PulseStream *parent)
{
PulseExtStream *ext;
gchar *suffix;
MateMixerAppInfo *app_info = NULL;
MateMixerDirection direction;
MateMixerStreamControlFlags flags = MATE_MIXER_STREAM_CONTROL_MUTE_READABLE |
MATE_MIXER_STREAM_CONTROL_MUTE_WRITABLE |
MATE_MIXER_STREAM_CONTROL_MOVABLE |
MATE_MIXER_STREAM_CONTROL_STORED;
MateMixerStreamControlRole role = MATE_MIXER_STREAM_CONTROL_ROLE_UNKNOWN;
MateMixerStreamControlMediaRole media_role =
MATE_MIXER_STREAM_CONTROL_MEDIA_ROLE_UNKNOWN;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (info != NULL, NULL);
/* The name of an ext-stream is in one of the following formats:
* sink-input-by-media-role: ...
* sink-input-by-application-name: ...
* sink-input-by-application-id: ...
* sink-input-by-media-name: ...
* source-output-by-media-role: ...
* source-output-by-application-name: ...
* source-output-by-application-id: ...
* source-output-by-media-name: ...
*/
if (g_str_has_prefix (info->name, "sink-input"))
direction = MATE_MIXER_DIRECTION_OUTPUT;
else if (g_str_has_prefix (info->name, "source-output"))
direction = MATE_MIXER_DIRECTION_INPUT;
else
direction = MATE_MIXER_DIRECTION_UNKNOWN;
suffix = strchr (info->name, ':');
if (suffix != NULL)
suffix++;
if (strstr (info->name, "-by-media-role:")) {
if G_LIKELY (suffix != NULL)
media_role = pulse_convert_media_role_name (suffix);
}
else if (strstr (info->name, "-by-application-name:")) {
role = MATE_MIXER_STREAM_CONTROL_ROLE_APPLICATION;
/* Make sure an application ext-stream always has a MateMixerAppInfo
* structure available, even in the case no application info is
* available */
if (app_info == NULL)
app_info = _mate_mixer_app_info_new ();
if G_LIKELY (suffix != NULL)
_mate_mixer_app_info_set_name (app_info, suffix);
}
else if (strstr (info->name, "-by-application-id:")) {
role = MATE_MIXER_STREAM_CONTROL_ROLE_APPLICATION;
/* Make sure an application ext-stream always has a MateMixerAppInfo
* structure available, even in the case no application info is
* available */
if (app_info == NULL)
app_info = _mate_mixer_app_info_new ();
if G_LIKELY (suffix != NULL)
_mate_mixer_app_info_set_id (app_info, suffix);
}
ext = g_object_new (PULSE_TYPE_EXT_STREAM,
"flags", flags,
"role", role,
"media-role", media_role,
"name", info->name,
"direction", direction,
"stream", parent,
"connection", connection,
"app-info", app_info,
NULL);
if (app_info != NULL)
_mate_mixer_app_info_free (app_info);
/* Store values which are expected to be changed */
pulse_ext_stream_update (ext, info, parent);
return ext;
}
void
pulse_ext_stream_update (PulseExtStream *ext,
const pa_ext_stream_restore_info *info,
PulseStream *parent)
{
MateMixerStreamControlFlags flags;
gboolean volume_changed = FALSE;
g_return_if_fail (PULSE_IS_EXT_STREAM (ext));
g_return_if_fail (info != NULL);
/* Let all the information update before emitting notify signals */
g_object_freeze_notify (G_OBJECT (ext));
_mate_mixer_stream_control_set_mute (MATE_MIXER_STREAM_CONTROL (ext),
info->mute ? TRUE : FALSE);
flags = mate_mixer_stream_control_get_flags (MATE_MIXER_STREAM_CONTROL (ext));
if (pa_channel_map_valid (&info->channel_map) != 0) {
if (pa_channel_map_can_balance (&info->channel_map) != 0)
flags |= MATE_MIXER_STREAM_CONTROL_CAN_BALANCE;
else
flags &= ~MATE_MIXER_STREAM_CONTROL_CAN_BALANCE;
if (pa_channel_map_can_fade (&info->channel_map) != 0)
flags |= MATE_MIXER_STREAM_CONTROL_CAN_FADE;
else
flags &= ~MATE_MIXER_STREAM_CONTROL_CAN_FADE;
ext->priv->channel_map = info->channel_map;
} else {
flags &= ~(MATE_MIXER_STREAM_CONTROL_CAN_BALANCE | MATE_MIXER_STREAM_CONTROL_CAN_FADE);
/* If the channel map is not valid, create an empty channel map, which
* also won't validate, but at least we know what it is */
pa_channel_map_init (&ext->priv->channel_map);
}
if (pa_cvolume_valid (&info->volume) != 0) {
flags |= MATE_MIXER_STREAM_CONTROL_VOLUME_READABLE |
MATE_MIXER_STREAM_CONTROL_VOLUME_WRITABLE;
if (pa_cvolume_equal (&ext->priv->cvolume, &info->volume) == 0)
volume_changed = TRUE;
} else {
flags &= ~(MATE_MIXER_STREAM_CONTROL_VOLUME_READABLE |
MATE_MIXER_STREAM_CONTROL_VOLUME_WRITABLE);
if (ext->priv->volume != (guint) PA_VOLUME_MUTED)
volume_changed = TRUE;
}
if (volume_changed == TRUE)
store_cvolume (ext, &info->volume);
_mate_mixer_stream_control_set_flags (MATE_MIXER_STREAM_CONTROL (ext), flags);
/* Also set initially, but may change at any time */
if (parent != NULL)
_mate_mixer_stream_control_set_stream (MATE_MIXER_STREAM_CONTROL (ext),
MATE_MIXER_STREAM (parent));
else
_mate_mixer_stream_control_set_stream (MATE_MIXER_STREAM_CONTROL (ext),
NULL);
g_object_thaw_notify (G_OBJECT (ext));
}
static MateMixerAppInfo *
pulse_ext_stream_get_app_info (MateMixerStreamControl *mmsc)
{
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), NULL);
return PULSE_EXT_STREAM (mmsc)->priv->app_info;
}
static gboolean
pulse_ext_stream_set_stream (MateMixerStreamControl *mmsc, MateMixerStream *mms)
{
PulseExtStream *ext;
pa_ext_stream_restore_info info;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), FALSE);
g_return_val_if_fail (mms == NULL || PULSE_IS_STREAM (mms), FALSE);
ext = PULSE_EXT_STREAM (mmsc);
fill_ext_stream_restore_info (ext, &info);
if (mms != NULL)
info.device = mate_mixer_stream_get_name (mms);
else
info.device = NULL;
return pulse_connection_write_ext_stream (ext->priv->connection, &info);
}
static gboolean
pulse_ext_stream_set_mute (MateMixerStreamControl *mmsc, gboolean mute)
{
PulseExtStream *ext;
pa_ext_stream_restore_info info;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), FALSE);
ext = PULSE_EXT_STREAM (mmsc);
fill_ext_stream_restore_info (ext, &info);
info.mute = mute;
return pulse_connection_write_ext_stream (ext->priv->connection, &info);
}
static guint
pulse_ext_stream_get_num_channels (MateMixerStreamControl *mmsc)
{
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), 0);
return PULSE_EXT_STREAM (mmsc)->priv->channel_map.channels;
}
static guint
pulse_ext_stream_get_volume (MateMixerStreamControl *mmsc)
{
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), (guint) PA_VOLUME_MUTED);
return PULSE_EXT_STREAM (mmsc)->priv->volume;
}
static gboolean
pulse_ext_stream_set_volume (MateMixerStreamControl *mmsc, guint volume)
{
PulseExtStream *ext;
pa_cvolume cvolume;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), FALSE);
ext = PULSE_EXT_STREAM (mmsc);
cvolume = ext->priv->cvolume;
/* Modify a temporary cvolume structure as the change may be irreversible */
if (pa_cvolume_scale (&cvolume, (pa_volume_t) volume) == NULL)
return FALSE;
return write_cvolume (ext, &cvolume);
}
static guint
pulse_ext_stream_get_channel_volume (MateMixerStreamControl *mmsc, guint channel)
{
PulseExtStream *ext;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), (guint) PA_VOLUME_MUTED);
ext = PULSE_EXT_STREAM (mmsc);
if (channel >= ext->priv->cvolume.channels)
return (guint) PA_VOLUME_MUTED;
return (guint) ext->priv->cvolume.values[channel];
}
static gboolean
pulse_ext_stream_set_channel_volume (MateMixerStreamControl *mmsc, guint channel, guint volume)
{
PulseExtStream *ext;
pa_cvolume cvolume;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), FALSE);
ext = PULSE_EXT_STREAM (mmsc);
if (channel >= ext->priv->cvolume.channels)
return FALSE;
/* Modify a temporary cvolume structure as the change may be irreversible */
cvolume = ext->priv->cvolume;
cvolume.values[channel] = (pa_volume_t) volume;
return write_cvolume (ext, &cvolume);
}
static MateMixerChannelPosition
pulse_ext_stream_get_channel_position (MateMixerStreamControl *mmsc, guint channel)
{
PulseExtStream *ext;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), MATE_MIXER_CHANNEL_UNKNOWN);
ext = PULSE_EXT_STREAM (mmsc);
if (channel >= ext->priv->channel_map.channels)
return MATE_MIXER_CHANNEL_UNKNOWN;
if (ext->priv->channel_map.map[channel] == PA_CHANNEL_POSITION_INVALID)
return MATE_MIXER_CHANNEL_UNKNOWN;
return pulse_channel_map_from[ext->priv->channel_map.map[channel]];
}
static gboolean
pulse_ext_stream_has_channel_position (MateMixerStreamControl *mmsc,
MateMixerChannelPosition position)
{
PulseExtStream *ext;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), FALSE);
ext = PULSE_EXT_STREAM (mmsc);
/* Handle invalid position as a special case, otherwise this function would
* return TRUE for e.g. unknown index in a default channel map */
if (pulse_channel_map_to[position] == PA_CHANNEL_POSITION_INVALID)
return FALSE;
if (pa_channel_map_has_position (&ext->priv->channel_map,
pulse_channel_map_to[position]) != 0)
return TRUE;
else
return FALSE;
}
static gboolean
pulse_ext_stream_set_balance (MateMixerStreamControl *mmsc, gfloat balance)
{
PulseExtStream *ext;
pa_cvolume cvolume;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), FALSE);
ext = PULSE_EXT_STREAM (mmsc);
cvolume = ext->priv->cvolume;
/* Modify a temporary cvolume structure as the change may be irreversible */
if (pa_cvolume_set_balance (&cvolume, &ext->priv->channel_map, balance) == NULL)
return FALSE;
return write_cvolume (ext, &cvolume);
}
static gboolean
pulse_ext_stream_set_fade (MateMixerStreamControl *mmsc, gfloat fade)
{
PulseExtStream *ext;
pa_cvolume cvolume;
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), FALSE);
ext = PULSE_EXT_STREAM (mmsc);
cvolume = ext->priv->cvolume;
/* Modify a temporary cvolume structure as the change may be irreversible */
if (pa_cvolume_set_fade (&cvolume, &ext->priv->channel_map, fade) == NULL)
return FALSE;
return write_cvolume (ext, &cvolume);
}
static guint
pulse_ext_stream_get_min_volume (MateMixerStreamControl *mmsc)
{
return (guint) PA_VOLUME_MUTED;
}
static guint
pulse_ext_stream_get_max_volume (MateMixerStreamControl *mmsc)
{
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), (guint) PA_VOLUME_MUTED);
return (guint) PA_VOLUME_NORM;
}
static guint
pulse_ext_stream_get_normal_volume (MateMixerStreamControl *mmsc)
{
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), (guint) PA_VOLUME_MUTED);
return (guint) PA_VOLUME_NORM;
}
static guint
pulse_ext_stream_get_base_volume (MateMixerStreamControl *mmsc)
{
g_return_val_if_fail (PULSE_IS_EXT_STREAM (mmsc), (guint) PA_VOLUME_MUTED);
/* Base volume is not supported/used in ext-streams */
return (guint) PA_VOLUME_NORM;
}
static void
fill_ext_stream_restore_info (PulseExtStream *ext,
pa_ext_stream_restore_info *info)
{
MateMixerStream *mms;
MateMixerStreamControl *mmsc;
mmsc = MATE_MIXER_STREAM_CONTROL (ext);
info->name = mate_mixer_stream_control_get_name (mmsc);
info->mute = mate_mixer_stream_control_get_mute (mmsc);
info->volume = ext->priv->cvolume;
info->channel_map = ext->priv->channel_map;
mms = mate_mixer_stream_control_get_stream (mmsc);
if (mms != NULL)
info->device = mate_mixer_stream_get_name (mms);
else
info->device = NULL;
}
static gboolean
write_cvolume (PulseExtStream *ext, const pa_cvolume *cvolume)
{
pa_ext_stream_restore_info info;
/* Make sure to only store a valid and modified volume */
if (pa_cvolume_valid (cvolume) == 0)
return FALSE;
if (pa_cvolume_equal (cvolume, &ext->priv->cvolume) != 0)
return TRUE;
fill_ext_stream_restore_info (ext, &info);
info.volume = *cvolume;
if (pulse_connection_write_ext_stream (ext->priv->connection, &info) == FALSE)
return FALSE;
store_cvolume (ext, cvolume);
return TRUE;
}
static void
store_cvolume (PulseExtStream *ext, const pa_cvolume *cvolume)
{
gfloat value;
/* Avoid validating whether the volume has changed, it should be done by
* the caller */
ext->priv->cvolume = *cvolume;
ext->priv->volume = (guint) pa_cvolume_max (cvolume);
g_object_notify (G_OBJECT (ext), "volume");
/* PulseAudio returns the default 0.0f value on error, so skip checking validity
* of the channel map and cvolume */
value = pa_cvolume_get_balance (&ext->priv->cvolume,
&ext->priv->channel_map);
_mate_mixer_stream_control_set_balance (MATE_MIXER_STREAM_CONTROL (ext), value);
value = pa_cvolume_get_fade (&ext->priv->cvolume,
&ext->priv->channel_map);
_mate_mixer_stream_control_set_fade (MATE_MIXER_STREAM_CONTROL (ext), value);
}
|