~ubuntu-branches/ubuntu/wily/mate-settings-daemon/wily

« back to all changes in this revision

Viewing changes to plugins/media-keys/cut-n-paste/gvc-mixer-sink.c

  • Committer: Package Import Robot
  • Author(s): John Paul Adrian Glaubitz, Martin Wimpress, John Paul Adrian Glaubitz
  • Date: 2015-08-16 16:35:32 UTC
  • mfrom: (10.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20150816163532-34zcev57w1c1bbv6
Tags: 1.10.1-1
[ Martin Wimpress ]
* debian/rules:
  + Remove obsolete build options.

[ John Paul Adrian Glaubitz ]
* Fix minor typo in debian/control (missing hyphen).
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2
 
 *
3
 
 * Copyright (C) 2008 William Jon McCann
4
 
 *
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.
9
 
 *
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.
14
 
 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
 *
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
 
23
 
#include <stdlib.h>
24
 
#include <stdio.h>
25
 
#include <unistd.h>
26
 
 
27
 
#include <glib.h>
28
 
#include <glib/gi18n-lib.h>
29
 
 
30
 
#include <pulse/pulseaudio.h>
31
 
 
32
 
#include "gvc-mixer-sink.h"
33
 
 
34
 
#define GVC_MIXER_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SINK, GvcMixerSinkPrivate))
35
 
 
36
 
struct GvcMixerSinkPrivate
37
 
{
38
 
        gpointer dummy;
39
 
};
40
 
 
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);
44
 
static void     gvc_mixer_sink_dispose    (GObject           *object);
45
 
 
46
 
G_DEFINE_TYPE (GvcMixerSink, gvc_mixer_sink, GVC_TYPE_MIXER_STREAM)
47
 
 
48
 
static gboolean
49
 
gvc_mixer_sink_push_volume (GvcMixerStream *stream, gpointer *op)
50
 
{
51
 
        pa_operation        *o;
52
 
        guint                index;
53
 
        const GvcChannelMap *map;
54
 
        pa_context          *context;
55
 
        const pa_cvolume    *cv;
56
 
 
57
 
        index = gvc_mixer_stream_get_index (stream);
58
 
 
59
 
        map = gvc_mixer_stream_get_channel_map (stream);
60
 
 
61
 
        /* set the volume */
62
 
        cv = gvc_channel_map_get_cvolume(map);
63
 
 
64
 
        context = gvc_mixer_stream_get_pa_context (stream);
65
 
 
66
 
        o = pa_context_set_sink_volume_by_index (context,
67
 
                                                 index,
68
 
                                                 cv,
69
 
                                                 NULL,
70
 
                                                 NULL);
71
 
 
72
 
        if (o == NULL) {
73
 
                g_warning ("pa_context_set_sink_volume_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
74
 
                return FALSE;
75
 
        }
76
 
 
77
 
        *op = o;
78
 
 
79
 
        return TRUE;
80
 
}
81
 
 
82
 
static gboolean
83
 
gvc_mixer_sink_change_is_muted (GvcMixerStream *stream,
84
 
                                gboolean        is_muted)
85
 
{
86
 
        pa_operation *o;
87
 
        guint         index;
88
 
        pa_context   *context;
89
 
 
90
 
        index = gvc_mixer_stream_get_index (stream);
91
 
        context = gvc_mixer_stream_get_pa_context (stream);
92
 
 
93
 
        o = pa_context_set_sink_mute_by_index (context,
94
 
                                               index,
95
 
                                               is_muted,
96
 
                                               NULL,
97
 
                                               NULL);
98
 
 
99
 
        if (o == NULL) {
100
 
                g_warning ("pa_context_set_sink_mute_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
101
 
                return FALSE;
102
 
        }
103
 
 
104
 
        pa_operation_unref(o);
105
 
 
106
 
        return TRUE;
107
 
}
108
 
 
109
 
static gboolean
110
 
gvc_mixer_sink_change_port (GvcMixerStream *stream,
111
 
                            const char     *port)
112
 
{
113
 
#if PA_MICRO > 15
114
 
        pa_operation *o;
115
 
        guint         index;
116
 
        pa_context   *context;
117
 
 
118
 
        index = gvc_mixer_stream_get_index (stream);
119
 
        context = gvc_mixer_stream_get_pa_context (stream);
120
 
 
121
 
        o = pa_context_set_sink_port_by_index (context,
122
 
                                               index,
123
 
                                               port,
124
 
                                               NULL,
125
 
                                               NULL);
126
 
 
127
 
        if (o == NULL) {
128
 
                g_warning ("pa_context_set_sink_port_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
129
 
                return FALSE;
130
 
        }
131
 
 
132
 
        pa_operation_unref(o);
133
 
 
134
 
        return TRUE;
135
 
#else
136
 
        return FALSE;
137
 
#endif /* PA_MICRO > 15 */
138
 
}
139
 
 
140
 
static GObject *
141
 
gvc_mixer_sink_constructor (GType                  type,
142
 
                            guint                  n_construct_properties,
143
 
                            GObjectConstructParam *construct_params)
144
 
{
145
 
        GObject      *object;
146
 
        GvcMixerSink *self;
147
 
 
148
 
        object = G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->constructor (type, n_construct_properties, construct_params);
149
 
 
150
 
        self = GVC_MIXER_SINK (object);
151
 
 
152
 
        return object;
153
 
}
154
 
 
155
 
static void
156
 
gvc_mixer_sink_class_init (GvcMixerSinkClass *klass)
157
 
{
158
 
        GObjectClass        *object_class = G_OBJECT_CLASS (klass);
159
 
        GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
160
 
 
161
 
        object_class->constructor = gvc_mixer_sink_constructor;
162
 
        object_class->dispose = gvc_mixer_sink_dispose;
163
 
        object_class->finalize = gvc_mixer_sink_finalize;
164
 
 
165
 
        stream_class->push_volume = gvc_mixer_sink_push_volume;
166
 
        stream_class->change_port = gvc_mixer_sink_change_port;
167
 
        stream_class->change_is_muted = gvc_mixer_sink_change_is_muted;
168
 
 
169
 
        g_type_class_add_private (klass, sizeof (GvcMixerSinkPrivate));
170
 
}
171
 
 
172
 
static void
173
 
gvc_mixer_sink_init (GvcMixerSink *sink)
174
 
{
175
 
        sink->priv = GVC_MIXER_SINK_GET_PRIVATE (sink);
176
 
}
177
 
 
178
 
static void
179
 
gvc_mixer_sink_dispose (GObject *object)
180
 
{
181
 
        GvcMixerSink *mixer_sink;
182
 
 
183
 
        g_return_if_fail (object != NULL);
184
 
        g_return_if_fail (GVC_IS_MIXER_SINK (object));
185
 
 
186
 
        mixer_sink = GVC_MIXER_SINK (object);
187
 
 
188
 
        G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->dispose (object);
189
 
}
190
 
 
191
 
static void
192
 
gvc_mixer_sink_finalize (GObject *object)
193
 
{
194
 
        GvcMixerSink *mixer_sink;
195
 
 
196
 
        g_return_if_fail (object != NULL);
197
 
        g_return_if_fail (GVC_IS_MIXER_SINK (object));
198
 
 
199
 
        mixer_sink = GVC_MIXER_SINK (object);
200
 
 
201
 
        g_return_if_fail (mixer_sink->priv != NULL);
202
 
        G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->finalize (object);
203
 
}
204
 
 
205
 
GvcMixerStream *
206
 
gvc_mixer_sink_new (pa_context    *context,
207
 
                    guint          index,
208
 
                    GvcChannelMap *channel_map)
209
 
 
210
 
{
211
 
        GObject *object;
212
 
 
213
 
        object = g_object_new (GVC_TYPE_MIXER_SINK,
214
 
                               "pa-context", context,
215
 
                               "index", index,
216
 
                               "channel-map", channel_map,
217
 
                               NULL);
218
 
 
219
 
        return GVC_MIXER_STREAM (object);
220
 
}