~elementary-os/ubuntu-package-imports/gnome-settings-daemon-bionic

« back to all changes in this revision

Viewing changes to subprojects/gvc/gvc-mixer-sink-input.c

  • Committer: RabbitBot
  • Date: 2018-03-05 16:57:46 UTC
  • Revision ID: rabbitbot@elementary.io-20180305165746-jzssepejk5kh8cty
updated to version 3.27.91-0ubuntu1

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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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-input.h"
 
33
#include "gvc-mixer-stream-private.h"
 
34
#include "gvc-channel-map-private.h"
 
35
 
 
36
#define GVC_MIXER_SINK_INPUT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SINK_INPUT, GvcMixerSinkInputPrivate))
 
37
 
 
38
struct GvcMixerSinkInputPrivate
 
39
{
 
40
        gpointer dummy;
 
41
};
 
42
 
 
43
static void     gvc_mixer_sink_input_finalize   (GObject                *object);
 
44
 
 
45
G_DEFINE_TYPE (GvcMixerSinkInput, gvc_mixer_sink_input, GVC_TYPE_MIXER_STREAM)
 
46
 
 
47
static gboolean
 
48
gvc_mixer_sink_input_push_volume (GvcMixerStream *stream, gpointer *op)
 
49
{
 
50
        pa_operation        *o;
 
51
        guint                index;
 
52
        const GvcChannelMap *map;
 
53
        pa_context          *context;
 
54
        const pa_cvolume    *cv;
 
55
 
 
56
        index = gvc_mixer_stream_get_index (stream);
 
57
 
 
58
        map = gvc_mixer_stream_get_channel_map (stream);
 
59
 
 
60
        cv = gvc_channel_map_get_cvolume(map);
 
61
 
 
62
        context = gvc_mixer_stream_get_pa_context (stream);
 
63
 
 
64
        o = pa_context_set_sink_input_volume (context,
 
65
                                              index,
 
66
                                              cv,
 
67
                                              NULL,
 
68
                                              NULL);
 
69
 
 
70
        if (o == NULL) {
 
71
                g_warning ("pa_context_set_sink_input_volume() failed");
 
72
                return FALSE;
 
73
        }
 
74
 
 
75
        *op = o;
 
76
 
 
77
        return TRUE;
 
78
}
 
79
 
 
80
static gboolean
 
81
gvc_mixer_sink_input_change_is_muted (GvcMixerStream *stream,
 
82
                                      gboolean        is_muted)
 
83
{
 
84
        pa_operation *o;
 
85
        guint         index;
 
86
        pa_context   *context;
 
87
 
 
88
        index = gvc_mixer_stream_get_index (stream);
 
89
        context = gvc_mixer_stream_get_pa_context (stream);
 
90
 
 
91
        o = pa_context_set_sink_input_mute (context,
 
92
                                            index,
 
93
                                            is_muted,
 
94
                                            NULL,
 
95
                                            NULL);
 
96
 
 
97
        if (o == NULL) {
 
98
                g_warning ("pa_context_set_sink_input_mute_by_index() failed");
 
99
                return FALSE;
 
100
        }
 
101
 
 
102
        pa_operation_unref(o);
 
103
 
 
104
        return TRUE;
 
105
}
 
106
 
 
107
static void
 
108
gvc_mixer_sink_input_class_init (GvcMixerSinkInputClass *klass)
 
109
{
 
110
        GObjectClass        *object_class = G_OBJECT_CLASS (klass);
 
111
        GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
 
112
 
 
113
        object_class->finalize = gvc_mixer_sink_input_finalize;
 
114
 
 
115
        stream_class->push_volume = gvc_mixer_sink_input_push_volume;
 
116
        stream_class->change_is_muted = gvc_mixer_sink_input_change_is_muted;
 
117
 
 
118
        g_type_class_add_private (klass, sizeof (GvcMixerSinkInputPrivate));
 
119
}
 
120
 
 
121
static void
 
122
gvc_mixer_sink_input_init (GvcMixerSinkInput *sink_input)
 
123
{
 
124
        sink_input->priv = GVC_MIXER_SINK_INPUT_GET_PRIVATE (sink_input);
 
125
}
 
126
 
 
127
static void
 
128
gvc_mixer_sink_input_finalize (GObject *object)
 
129
{
 
130
        GvcMixerSinkInput *mixer_sink_input;
 
131
 
 
132
        g_return_if_fail (object != NULL);
 
133
        g_return_if_fail (GVC_IS_MIXER_SINK_INPUT (object));
 
134
 
 
135
        mixer_sink_input = GVC_MIXER_SINK_INPUT (object);
 
136
 
 
137
        g_return_if_fail (mixer_sink_input->priv != NULL);
 
138
        G_OBJECT_CLASS (gvc_mixer_sink_input_parent_class)->finalize (object);
 
139
}
 
140
 
 
141
/**
 
142
 * gvc_mixer_sink_input_new: (skip)
 
143
 * @context:
 
144
 * @index:
 
145
 * @channel_map:
 
146
 *
 
147
 * Returns:
 
148
 */
 
149
GvcMixerStream *
 
150
gvc_mixer_sink_input_new (pa_context    *context,
 
151
                          guint          index,
 
152
                          GvcChannelMap *channel_map)
 
153
{
 
154
        GObject *object;
 
155
 
 
156
        object = g_object_new (GVC_TYPE_MIXER_SINK_INPUT,
 
157
                               "pa-context", context,
 
158
                               "index", index,
 
159
                               "channel-map", channel_map,
 
160
                               NULL);
 
161
 
 
162
        return GVC_MIXER_STREAM (object);
 
163
}