Display a context menu when clicking on audio/video icons (#590051)
[empathy-mirror.git] / libempathy-gtk / empathy-audio-sink.c
blob1d2169593f73739dad371b861164a48239a6f575
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>
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
22 #include <stdio.h>
23 #include <stdlib.h>
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)
32 /* signal enum */
33 #if 0
34 enum
36 LAST_SIGNAL
39 static guint signals[LAST_SIGNAL] = {0};
40 #endif
42 enum {
43 PROP_VOLUME = 1,
46 /* private structure */
47 typedef struct _EmpathyGstAudioSinkPrivate EmpathyGstAudioSinkPrivate;
49 struct _EmpathyGstAudioSinkPrivate
51 gboolean dispose_has_run;
52 GstElement *sink;
53 GstElement *volume;
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))
61 static void
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"))
69 gdouble 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);
78 if (volume != 1.0)
79 empathy_audio_sink_set_volume (self, volume);
83 static void
84 empathy_audio_sink_init (EmpathyGstAudioSink *obj)
86 EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (obj);
87 GstElement *resample;
88 GstPad *ghost, *sink;
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);
117 static void
118 empathy_audio_sink_set_property (GObject *object,
119 guint property_id, const GValue *value, GParamSpec *pspec)
121 switch (property_id)
123 case PROP_VOLUME:
124 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (object),
125 g_value_get_double (value));
126 break;
127 default:
128 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
132 static void
133 empathy_audio_sink_get_property (GObject *object,
134 guint property_id, GValue *value, GParamSpec *pspec)
136 switch (property_id)
138 case PROP_VOLUME:
139 g_value_set_double (value,
140 empathy_audio_sink_get_volume (EMPATHY_GST_AUDIO_SINK (object)));
141 break;
142 default:
143 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
147 static void
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",
164 0.0, 5.0, 1.0,
165 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
166 g_object_class_install_property (object_class, PROP_VOLUME, param_spec);
169 void
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)
176 return;
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);
186 priv->volume = NULL;
188 if (G_OBJECT_CLASS (empathy_audio_sink_parent_class)->dispose)
189 G_OBJECT_CLASS (empathy_audio_sink_parent_class)->dispose (object);
192 void
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);
204 GstElement *
205 empathy_audio_sink_new (void)
207 static gboolean registered = FALSE;
209 if (!registered) {
210 if (!gst_element_register (NULL, "empathyaudiosink",
211 GST_RANK_NONE, EMPATHY_TYPE_GST_AUDIO_SINK))
212 return NULL;
213 registered = TRUE;
215 return gst_element_factory_make ("empathyaudiosink", NULL);
218 void
219 empathy_audio_sink_set_volume (EmpathyGstAudioSink *sink, gdouble volume)
221 EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (sink);
223 g_object_set (G_OBJECT (priv->volume), "volume", volume, NULL);
226 gdouble
227 empathy_audio_sink_get_volume (EmpathyGstAudioSink *sink)
229 EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (sink);
230 gdouble volume;
232 g_object_get (G_OBJECT (priv->volume), "volume", &volume, NULL);
234 return volume;