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
));
103 gst_bin_add_many (GST_BIN (obj
), resample
, priv
->volume
, priv
->sink
, NULL
);
104 gst_element_link_many (resample
, priv
->volume
, priv
->sink
, NULL
);
106 sink
= gst_element_get_static_pad (resample
, "sink");
108 ghost
= gst_ghost_pad_new ("sink", sink
);
109 gst_element_add_pad (GST_ELEMENT (obj
), ghost
);
111 gst_object_unref (G_OBJECT (sink
));
114 static void empathy_audio_sink_dispose (GObject
*object
);
115 static void empathy_audio_sink_finalize (GObject
*object
);
118 empathy_audio_sink_set_property (GObject
*object
,
119 guint property_id
, const GValue
*value
, GParamSpec
*pspec
)
124 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (object
),
125 g_value_get_double (value
));
128 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
133 empathy_audio_sink_get_property (GObject
*object
,
134 guint property_id
, GValue
*value
, GParamSpec
*pspec
)
139 g_value_set_double (value
,
140 empathy_audio_sink_get_volume (EMPATHY_GST_AUDIO_SINK (object
)));
143 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
148 empathy_audio_sink_class_init (EmpathyGstAudioSinkClass
149 *empathy_audio_sink_class
)
151 GObjectClass
*object_class
= G_OBJECT_CLASS (empathy_audio_sink_class
);
152 GParamSpec
*param_spec
;
154 g_type_class_add_private (empathy_audio_sink_class
,
155 sizeof (EmpathyGstAudioSinkPrivate
));
157 object_class
->dispose
= empathy_audio_sink_dispose
;
158 object_class
->finalize
= empathy_audio_sink_finalize
;
160 object_class
->set_property
= empathy_audio_sink_set_property
;
161 object_class
->get_property
= empathy_audio_sink_get_property
;
163 param_spec
= g_param_spec_double ("volume", "Volume", "volume control",
165 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
166 g_object_class_install_property (object_class
, PROP_VOLUME
, param_spec
);
170 empathy_audio_sink_dispose (GObject
*object
)
172 EmpathyGstAudioSink
*self
= EMPATHY_GST_AUDIO_SINK (object
);
173 EmpathyGstAudioSinkPrivate
*priv
= EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self
);
175 if (priv
->dispose_has_run
)
178 priv
->dispose_has_run
= TRUE
;
180 if (priv
->notifier
!= NULL
)
181 g_object_unref (priv
->notifier
);
182 priv
->notifier
= NULL
;
184 if (priv
->volume
!= NULL
)
185 g_object_unref (priv
->volume
);
188 if (G_OBJECT_CLASS (empathy_audio_sink_parent_class
)->dispose
)
189 G_OBJECT_CLASS (empathy_audio_sink_parent_class
)->dispose (object
);
193 empathy_audio_sink_finalize (GObject
*object
)
195 //EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (object);
196 //EmpathyGstAudioSinkPrivate *priv =
197 // EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
199 /* free any data held directly by the object here */
201 G_OBJECT_CLASS (empathy_audio_sink_parent_class
)->finalize (object
);
205 empathy_audio_sink_new (void)
207 return GST_ELEMENT (g_object_new (EMPATHY_TYPE_GST_AUDIO_SINK
, NULL
));
211 empathy_audio_sink_set_volume (EmpathyGstAudioSink
*sink
, gdouble volume
)
213 EmpathyGstAudioSinkPrivate
*priv
= EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (sink
);
215 g_object_set (G_OBJECT (priv
->volume
), "volume", volume
, NULL
);
219 empathy_audio_sink_get_volume (EmpathyGstAudioSink
*sink
)
221 EmpathyGstAudioSinkPrivate
*priv
= EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (sink
);
224 g_object_get (G_OBJECT (priv
->volume
), "volume", &volume
, NULL
);