2 * empathy-gst-audio-sink.c - Source for EmpathyGstAudioSink
3 * Copyright (C) 2008 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
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.
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.
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
25 #include <gst/farsight/fs-element-added-notifier.h>
27 #include "empathy-audio-sink.h"
30 G_DEFINE_TYPE(EmpathyGstAudioSink, empathy_audio_sink, GST_TYPE_BIN)
39 static guint signals[LAST_SIGNAL] = {0};
46 /* private structure */
47 typedef struct _EmpathyGstAudioSinkPrivate EmpathyGstAudioSinkPrivate;
49 struct _EmpathyGstAudioSinkPrivate
51 gboolean dispose_has_run;
54 FsElementAddedNotifier *notifier;
57 #define EMPATHY_GST_AUDIO_SINK_GET_PRIVATE(o) \
58 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_GST_AUDIO_SINK, \
59 EmpathyGstAudioSinkPrivate))
62 empathy_audio_sink_element_added_cb (FsElementAddedNotifier *notifier,
63 GstBin *bin, GstElement *element, EmpathyGstAudioSink *self)
65 EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
67 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element), "volume"))
71 volume = empathy_audio_sink_get_volume (self);
72 empathy_audio_sink_set_volume (self, 1.0);
74 if (priv->volume != NULL)
75 g_object_unref (priv->volume);
76 priv->volume = g_object_ref (element);
79 empathy_audio_sink_set_volume (self, volume);
84 empathy_audio_sink_init (EmpathyGstAudioSink *obj)
86 EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (obj);
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);
94 resample = gst_element_factory_make ("audioresample", NULL);
96 priv->volume = gst_element_factory_make ("volume", NULL);
97 g_object_ref (priv->volume);
99 priv->sink = gst_element_factory_make ("gconfaudiosink", NULL);
101 fs_element_added_notifier_add (priv->notifier, GST_BIN (priv->sink));
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);
107 sink = gst_element_get_static_pad (resample, "sink");
109 ghost = gst_ghost_pad_new ("sink", sink);
110 gst_element_add_pad (GST_ELEMENT (obj), ghost);
112 gst_object_unref (G_OBJECT (sink));
115 static void empathy_audio_sink_dispose (GObject *object);
116 static void empathy_audio_sink_finalize (GObject *object);
119 empathy_audio_sink_set_property (GObject *object,
120 guint property_id, const GValue *value, GParamSpec *pspec)
125 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (object),
126 g_value_get_double (value));
129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
134 empathy_audio_sink_get_property (GObject *object,
135 guint property_id, GValue *value, GParamSpec *pspec)
140 g_value_set_double (value,
141 empathy_audio_sink_get_volume (EMPATHY_GST_AUDIO_SINK (object)));
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
151 empathy_audio_sink_class_init (EmpathyGstAudioSinkClass
152 *empathy_audio_sink_class)
154 GObjectClass *object_class = G_OBJECT_CLASS (empathy_audio_sink_class);
155 GParamSpec *param_spec;
157 g_type_class_add_private (empathy_audio_sink_class,
158 sizeof (EmpathyGstAudioSinkPrivate));
160 object_class->dispose = empathy_audio_sink_dispose;
161 object_class->finalize = empathy_audio_sink_finalize;
163 object_class->set_property = empathy_audio_sink_set_property;
164 object_class->get_property = empathy_audio_sink_get_property;
166 param_spec = g_param_spec_double ("volume", "Volume", "volume factory",
168 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
169 g_object_class_install_property (object_class, PROP_VOLUME, param_spec);
173 empathy_audio_sink_dispose (GObject *object)
175 EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (object);
176 EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
178 if (priv->dispose_has_run)
181 priv->dispose_has_run = TRUE;
183 if (priv->notifier != NULL)
184 g_object_unref (priv->notifier);
185 priv->notifier = NULL;
187 if (priv->volume != NULL)
188 g_object_unref (priv->volume);
191 if (G_OBJECT_CLASS (empathy_audio_sink_parent_class)->dispose)
192 G_OBJECT_CLASS (empathy_audio_sink_parent_class)->dispose (object);
196 empathy_audio_sink_finalize (GObject *object)
198 //EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (object);
199 //EmpathyGstAudioSinkPrivate *priv =
200 // EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
202 /* free any data held directly by the object here */
204 G_OBJECT_CLASS (empathy_audio_sink_parent_class)->finalize (object);
208 empathy_audio_sink_new (void)
210 return GST_ELEMENT (g_object_new (EMPATHY_TYPE_GST_AUDIO_SINK, NULL));
214 empathy_audio_sink_set_volume (EmpathyGstAudioSink *sink, gdouble volume)
216 EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (sink);
218 g_object_set (G_OBJECT (priv->volume), "volume", volume, NULL);
222 empathy_audio_sink_get_volume (EmpathyGstAudioSink *sink)
224 EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (sink);
227 g_object_get (G_OBJECT (priv->volume), "volume", &volume, NULL);