~ubuntu-branches/ubuntu/maverick/gnome-media/maverick

« back to all changes in this revision

Viewing changes to gnome-volume-control/src/gvc-mixer-sink.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette, Josselin Mouette, Luca Bruno
  • Date: 2009-05-28 00:05:41 UTC
  • mfrom: (0.1.28 upstream)
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: james.westby@ubuntu.com-20090528000541-s3h2g1jjw8sodkfi
Tags: 2.26.0-1
[ Josselin Mouette ]
* Set the team as primary maintainer. Closes: #523538.

[ Luca Bruno ]
* New upstream release. Closes: #526798.
  + Features a MP2 audio profile. Closes: #502059.
* debian/control.in:
  - Build-Depends:
    + Add libcanberra-gtk-dev 0.4.
    + Add libunique-dev.
    + Bump libglib2.0-dev to 2.18.2.
* debian/patches/01_vumeter_nodisplay.patch:
  - Remove, vu-meter isn't being built by default since 2.23.

[ Josselin Mouette ]
* Update build-dependencies, include libpulse.
* Explicitly enable the gst mixer.
* Install the autostart file in /usr/share/gnome/autostart.
* Install OMF and sound files.
* 10_applet_tryexec.patch: new patch. Only run 
  gnome-volume-control-applet when pulseaudio is installed.
* Split install targets for gnome-volume-control and gst-mixer. 
  Install selectively what comes from each of them.
* Install both gnome-volume-control.pulse and 
  gnome-volume-control.gstreamer. The real gnome-volume-control is now  
  a wrapper script.
* Depend on x11-utils for the wrapper script to work.
* Suggest pulseaudio.

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.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
 
 
45
G_DEFINE_TYPE (GvcMixerSink, gvc_mixer_sink, GVC_TYPE_MIXER_STREAM)
 
46
 
 
47
static gboolean
 
48
gvc_mixer_sink_change_volume (GvcMixerStream *stream,
 
49
                              guint           volume)
 
50
{
 
51
        pa_operation      *o;
 
52
        guint              index;
 
53
        GvcChannelMap     *map;
 
54
        pa_context        *context;
 
55
        pa_cvolume         cv;
 
56
        guint              i;
 
57
        guint              num_channels;
 
58
        gdouble           *gains;
 
59
 
 
60
        index = gvc_mixer_stream_get_index (stream);
 
61
 
 
62
 
 
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);
 
66
 
 
67
        g_debug ("Changing volume for sink: n=%d vol=%u", num_channels, (guint)volume);
 
68
 
 
69
        /* set all values to nominal level */
 
70
        pa_cvolume_set (&cv, num_channels, (pa_volume_t)volume);
 
71
 
 
72
        /* apply channel gain mapping */
 
73
        for (i = 0; i < num_channels; i++) {
 
74
                pa_volume_t v;
 
75
                v = (double) volume * gains[i];
 
76
                g_debug ("Channel %d v=%u", i, v);
 
77
                cv.values[i] = v;
 
78
        }
 
79
 
 
80
        context = gvc_mixer_stream_get_pa_context (stream);
 
81
 
 
82
        o = pa_context_set_sink_volume_by_index (context,
 
83
                                                 index,
 
84
                                                 &cv,
 
85
                                                 NULL,
 
86
                                                 NULL);
 
87
 
 
88
        if (o == NULL) {
 
89
                g_warning ("pa_context_set_sink_volume_by_index() failed");
 
90
                return FALSE;
 
91
        }
 
92
 
 
93
        pa_operation_unref(o);
 
94
 
 
95
        return TRUE;
 
96
}
 
97
 
 
98
static gboolean
 
99
gvc_mixer_sink_change_is_muted (GvcMixerStream *stream,
 
100
                                gboolean        is_muted)
 
101
{
 
102
        pa_operation *o;
 
103
        guint         index;
 
104
        pa_context   *context;
 
105
 
 
106
        index = gvc_mixer_stream_get_index (stream);
 
107
        context = gvc_mixer_stream_get_pa_context (stream);
 
108
 
 
109
        o = pa_context_set_sink_mute_by_index (context,
 
110
                                               index,
 
111
                                               is_muted,
 
112
                                               NULL,
 
113
                                               NULL);
 
114
 
 
115
        if (o == NULL) {
 
116
                g_warning ("pa_context_set_sink_mute_by_index() failed");
 
117
                return FALSE;
 
118
        }
 
119
 
 
120
        pa_operation_unref(o);
 
121
 
 
122
        return TRUE;
 
123
}
 
124
 
 
125
static GObject *
 
126
gvc_mixer_sink_constructor (GType                  type,
 
127
                            guint                  n_construct_properties,
 
128
                            GObjectConstructParam *construct_params)
 
129
{
 
130
        GObject       *object;
 
131
        GvcMixerSink *self;
 
132
 
 
133
        object = G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->constructor (type, n_construct_properties, construct_params);
 
134
 
 
135
        self = GVC_MIXER_SINK (object);
 
136
 
 
137
        return object;
 
138
}
 
139
 
 
140
static void
 
141
gvc_mixer_sink_class_init (GvcMixerSinkClass *klass)
 
142
{
 
143
        GObjectClass        *object_class = G_OBJECT_CLASS (klass);
 
144
        GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
 
145
 
 
146
        object_class->constructor = gvc_mixer_sink_constructor;
 
147
        object_class->finalize = gvc_mixer_sink_finalize;
 
148
 
 
149
        stream_class->change_volume = gvc_mixer_sink_change_volume;
 
150
        stream_class->change_is_muted = gvc_mixer_sink_change_is_muted;
 
151
 
 
152
        g_type_class_add_private (klass, sizeof (GvcMixerSinkPrivate));
 
153
}
 
154
 
 
155
static void
 
156
gvc_mixer_sink_init (GvcMixerSink *sink)
 
157
{
 
158
        sink->priv = GVC_MIXER_SINK_GET_PRIVATE (sink);
 
159
 
 
160
}
 
161
 
 
162
static void
 
163
gvc_mixer_sink_finalize (GObject *object)
 
164
{
 
165
        GvcMixerSink *mixer_sink;
 
166
 
 
167
        g_return_if_fail (object != NULL);
 
168
        g_return_if_fail (GVC_IS_MIXER_SINK (object));
 
169
 
 
170
        mixer_sink = GVC_MIXER_SINK (object);
 
171
 
 
172
        g_return_if_fail (mixer_sink->priv != NULL);
 
173
        G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->finalize (object);
 
174
}
 
175
 
 
176
GvcMixerStream *
 
177
gvc_mixer_sink_new (pa_context    *context,
 
178
                    guint          index,
 
179
                    GvcChannelMap *channel_map)
 
180
 
 
181
{
 
182
        GObject *object;
 
183
 
 
184
        object = g_object_new (GVC_TYPE_MIXER_SINK,
 
185
                               "pa-context", context,
 
186
                               "index", index,
 
187
                               "channel-map", channel_map,
 
188
                               NULL);
 
189
 
 
190
        return GVC_MIXER_STREAM (object);
 
191
}