]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-audio-sink.c
de.po: Updated German translation
[empathy.git] / libempathy-gtk / empathy-audio-sink.c
1 /*
2  * empathy-gst-audio-sink.c - Source for EmpathyGstAudioSink
3  * Copyright (C) 2008 Collabora Ltd.
4  * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include <gst/farsight/fs-element-added-notifier.h>
26
27 #include "empathy-audio-sink.h"
28
29
30 G_DEFINE_TYPE(EmpathyGstAudioSink, empathy_audio_sink, GST_TYPE_BIN)
31
32 /* signal enum */
33 #if 0
34 enum
35 {
36     LAST_SIGNAL
37 };
38
39 static guint signals[LAST_SIGNAL] = {0};
40 #endif
41
42 enum {
43   PROP_VOLUME = 1,
44 };
45
46 /* private structure */
47 typedef struct _EmpathyGstAudioSinkPrivate EmpathyGstAudioSinkPrivate;
48
49 struct _EmpathyGstAudioSinkPrivate
50 {
51   gboolean dispose_has_run;
52   GstElement *sink;
53   GstElement *volume;
54   FsElementAddedNotifier *notifier;
55 };
56
57 #define EMPATHY_GST_AUDIO_SINK_GET_PRIVATE(o) \
58   (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_GST_AUDIO_SINK, \
59   EmpathyGstAudioSinkPrivate))
60
61 static void
62 empathy_audio_sink_element_added_cb (FsElementAddedNotifier *notifier,
63   GstBin *bin, GstElement *element, EmpathyGstAudioSink *self)
64 {
65   EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
66
67   if (g_object_class_find_property (G_OBJECT_GET_CLASS (element), "volume"))
68     {
69       gdouble volume;
70
71       volume = empathy_audio_sink_get_volume (self);
72       empathy_audio_sink_set_volume (self, 1.0);
73
74       if (priv->volume != NULL)
75         g_object_unref (priv->volume);
76       priv->volume = g_object_ref (element);
77
78       if (volume != 1.0)
79         empathy_audio_sink_set_volume (self, volume);
80     }
81 }
82
83 static void
84 empathy_audio_sink_init (EmpathyGstAudioSink *obj)
85 {
86   EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (obj);
87   GstElement *resample;
88   GstPad *ghost, *sink;
89
90   priv->notifier = fs_element_added_notifier_new ();
91   g_signal_connect (priv->notifier, "element-added",
92     G_CALLBACK (empathy_audio_sink_element_added_cb), obj);
93
94   resample = gst_element_factory_make ("audioresample", NULL);
95
96   priv->volume = gst_element_factory_make ("volume", NULL);
97   g_object_ref (priv->volume);
98
99   priv->sink = gst_element_factory_make ("gconfaudiosink", NULL);
100
101   fs_element_added_notifier_add (priv->notifier, GST_BIN (priv->sink));
102
103
104   gst_bin_add_many (GST_BIN (obj), resample, priv->volume, priv->sink, NULL);
105   gst_element_link_many (resample, priv->volume, priv->sink, NULL);
106
107   sink = gst_element_get_static_pad (resample, "sink");
108
109   ghost = gst_ghost_pad_new ("sink", sink);
110   gst_element_add_pad (GST_ELEMENT (obj), ghost);
111
112   gst_object_unref (G_OBJECT (sink));
113 }
114
115 static void empathy_audio_sink_dispose (GObject *object);
116 static void empathy_audio_sink_finalize (GObject *object);
117
118 static void
119 empathy_audio_sink_set_property (GObject *object,
120   guint property_id, const GValue *value, GParamSpec *pspec)
121 {
122   switch (property_id)
123     {
124       case PROP_VOLUME:
125         empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (object),
126           g_value_get_double (value));
127         break;
128       default:
129         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
130     }
131 }
132
133 static void
134 empathy_audio_sink_get_property (GObject *object,
135   guint property_id, GValue *value, GParamSpec *pspec)
136 {
137   switch (property_id)
138     {
139       case PROP_VOLUME:
140         g_value_set_double (value,
141           empathy_audio_sink_get_volume (EMPATHY_GST_AUDIO_SINK (object)));
142         break;
143       default:
144         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
145     }
146 }
147
148
149
150 static void
151 empathy_audio_sink_class_init (EmpathyGstAudioSinkClass
152   *empathy_audio_sink_class)
153 {
154   GObjectClass *object_class = G_OBJECT_CLASS (empathy_audio_sink_class);
155   GParamSpec *param_spec;
156
157   g_type_class_add_private (empathy_audio_sink_class,
158     sizeof (EmpathyGstAudioSinkPrivate));
159
160   object_class->dispose = empathy_audio_sink_dispose;
161   object_class->finalize = empathy_audio_sink_finalize;
162
163   object_class->set_property = empathy_audio_sink_set_property;
164   object_class->get_property = empathy_audio_sink_get_property;
165
166   param_spec = g_param_spec_double ("volume", "Volume", "volume factory",
167     0.0, 5.0, 1.0,
168     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
169   g_object_class_install_property (object_class, PROP_VOLUME, param_spec);
170 }
171
172 void
173 empathy_audio_sink_dispose (GObject *object)
174 {
175   EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (object);
176   EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
177
178   if (priv->dispose_has_run)
179     return;
180
181   priv->dispose_has_run = TRUE;
182
183   if (priv->notifier != NULL)
184     g_object_unref (priv->notifier);
185   priv->notifier = NULL;
186
187   if (priv->volume != NULL)
188     g_object_unref (priv->volume);
189   priv->volume = NULL;
190
191   if (G_OBJECT_CLASS (empathy_audio_sink_parent_class)->dispose)
192     G_OBJECT_CLASS (empathy_audio_sink_parent_class)->dispose (object);
193 }
194
195 void
196 empathy_audio_sink_finalize (GObject *object)
197 {
198   //EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (object);
199   //EmpathyGstAudioSinkPrivate *priv =
200   //  EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
201
202   /* free any data held directly by the object here */
203
204   G_OBJECT_CLASS (empathy_audio_sink_parent_class)->finalize (object);
205 }
206
207 GstElement *
208 empathy_audio_sink_new (void)
209 {
210   return GST_ELEMENT (g_object_new (EMPATHY_TYPE_GST_AUDIO_SINK, NULL));
211 }
212
213 void
214 empathy_audio_sink_set_volume (EmpathyGstAudioSink *sink, gdouble volume)
215 {
216   EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (sink);
217
218   g_object_set (G_OBJECT (priv->volume), "volume", volume, NULL);
219 }
220
221 gdouble
222 empathy_audio_sink_get_volume (EmpathyGstAudioSink *sink)
223 {
224   EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (sink);
225   gdouble volume;
226
227   g_object_get (G_OBJECT (priv->volume), "volume", &volume, NULL);
228
229   return volume;
230 }