1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2008 William Jon McCann
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
#include <glib/gi18n.h>
30
#include <pulse/pulseaudio.h>
32
#include "gvc-mixer-sink.h"
34
#define GVC_MIXER_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SINK, GvcMixerSinkPrivate))
36
struct GvcMixerSinkPrivate
41
static void gvc_mixer_sink_class_init (GvcMixerSinkClass *klass);
42
static void gvc_mixer_sink_init (GvcMixerSink *mixer_sink);
43
static void gvc_mixer_sink_finalize (GObject *object);
45
G_DEFINE_TYPE (GvcMixerSink, gvc_mixer_sink, GVC_TYPE_MIXER_STREAM)
48
gvc_mixer_sink_change_volume (GvcMixerStream *stream,
60
index = gvc_mixer_stream_get_index (stream);
63
map = gvc_mixer_stream_get_channel_map (stream);
64
num_channels = gvc_channel_map_get_num_channels (map);
65
gains = gvc_channel_map_get_gains (map);
67
g_debug ("Changing volume for sink: n=%d vol=%u", num_channels, (guint)volume);
69
/* set all values to nominal level */
70
pa_cvolume_set (&cv, num_channels, (pa_volume_t)volume);
72
/* apply channel gain mapping */
73
for (i = 0; i < num_channels; i++) {
75
v = (double) volume * gains[i];
76
g_debug ("Channel %d v=%u", i, v);
80
context = gvc_mixer_stream_get_pa_context (stream);
82
o = pa_context_set_sink_volume_by_index (context,
89
g_warning ("pa_context_set_sink_volume_by_index() failed");
93
pa_operation_unref(o);
99
gvc_mixer_sink_change_is_muted (GvcMixerStream *stream,
106
index = gvc_mixer_stream_get_index (stream);
107
context = gvc_mixer_stream_get_pa_context (stream);
109
o = pa_context_set_sink_mute_by_index (context,
116
g_warning ("pa_context_set_sink_mute_by_index() failed");
120
pa_operation_unref(o);
126
gvc_mixer_sink_constructor (GType type,
127
guint n_construct_properties,
128
GObjectConstructParam *construct_params)
133
object = G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->constructor (type, n_construct_properties, construct_params);
135
self = GVC_MIXER_SINK (object);
141
gvc_mixer_sink_class_init (GvcMixerSinkClass *klass)
143
GObjectClass *object_class = G_OBJECT_CLASS (klass);
144
GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
146
object_class->constructor = gvc_mixer_sink_constructor;
147
object_class->finalize = gvc_mixer_sink_finalize;
149
stream_class->change_volume = gvc_mixer_sink_change_volume;
150
stream_class->change_is_muted = gvc_mixer_sink_change_is_muted;
152
g_type_class_add_private (klass, sizeof (GvcMixerSinkPrivate));
156
gvc_mixer_sink_init (GvcMixerSink *sink)
158
sink->priv = GVC_MIXER_SINK_GET_PRIVATE (sink);
163
gvc_mixer_sink_finalize (GObject *object)
165
GvcMixerSink *mixer_sink;
167
g_return_if_fail (object != NULL);
168
g_return_if_fail (GVC_IS_MIXER_SINK (object));
170
mixer_sink = GVC_MIXER_SINK (object);
172
g_return_if_fail (mixer_sink->priv != NULL);
173
G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->finalize (object);
177
gvc_mixer_sink_new (pa_context *context,
179
GvcChannelMap *channel_map)
184
object = g_object_new (GVC_TYPE_MIXER_SINK,
185
"pa-context", context,
187
"channel-map", channel_map,
190
return GVC_MIXER_STREAM (object);