2 * empathy-call-window.c - Source for EmpathyCallWindow
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
27 #include <libempathy-gtk/empathy-video-widget.h>
28 #include <libempathy-gtk/empathy-audio-src.h>
29 #include <libempathy-gtk/empathy-audio-sink.h>
30 #include <libempathy-gtk/empathy-video-src.h>
32 #include "empathy-call-window.h"
34 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
43 static guint signals[LAST_SIGNAL] = {0};
47 PROP_CALL_HANDLER = 1,
50 /* private structure */
51 typedef struct _EmpathyCallWindowPriv EmpathyCallWindowPriv;
53 struct _EmpathyCallWindowPriv
55 gboolean dispose_has_run;
56 EmpathyCallHandler *handler;
57 GtkWidget *video_output;
58 GtkWidget *video_preview;
59 GstElement *video_input;
60 GstElement *audio_input;
61 GstElement *audio_output;
63 GstElement *video_tee;
67 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CALL_WINDOW, \
68 EmpathyCallWindowPriv))
70 static void empathy_call_window_realized_cb (GtkWidget *widget,
71 EmpathyCallWindow *window);
73 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
74 GdkEvent*event, EmpathyCallWindow *window);
77 empathy_call_window_init (EmpathyCallWindow *self)
79 EmpathyCallWindowPriv *priv = GET_PRIV (self);
83 priv->pipeline = gst_pipeline_new (NULL);
85 hbox = gtk_hbox_new (TRUE, 3);
86 gtk_container_add (GTK_CONTAINER (self), hbox);
88 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
90 priv->video_output = empathy_video_widget_new (bus);
92 priv->video_tee = gst_element_factory_make ("tee", NULL);
93 gst_object_ref (priv->video_tee);
94 gst_object_sink (priv->video_tee);
96 priv->video_preview = empathy_video_widget_new (bus);
98 priv->video_input = empathy_video_src_new ();
99 gst_object_ref (priv->video_input);
100 gst_object_sink (priv->video_input);
102 priv->audio_input = empathy_audio_src_new ();
103 gst_object_ref (priv->audio_input);
104 gst_object_sink (priv->audio_input);
106 priv->audio_output = empathy_audio_sink_new ();
107 gst_object_ref (priv->audio_output);
108 gst_object_sink (priv->audio_output);
110 g_object_unref (bus);
112 gtk_box_pack_start (GTK_BOX (hbox), priv->video_preview, TRUE, TRUE, 3);
113 gtk_box_pack_start (GTK_BOX (hbox), priv->video_output, TRUE, TRUE, 3);
115 gtk_widget_show_all (hbox);
117 g_signal_connect (G_OBJECT (self), "realize",
118 G_CALLBACK (empathy_call_window_realized_cb), self);
120 g_signal_connect (G_OBJECT (self), "delete-event",
121 G_CALLBACK (empathy_call_window_delete_cb), self);
124 static void empathy_call_window_dispose (GObject *object);
125 static void empathy_call_window_finalize (GObject *object);
128 empathy_call_window_set_property (GObject *object,
129 guint property_id, const GValue *value, GParamSpec *pspec)
131 EmpathyCallWindowPriv *priv = GET_PRIV (object);
135 case PROP_CALL_HANDLER:
136 priv->handler = g_value_dup_object (value);
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
144 empathy_call_window_get_property (GObject *object,
145 guint property_id, GValue *value, GParamSpec *pspec)
147 EmpathyCallWindowPriv *priv = GET_PRIV (object);
151 case PROP_CALL_HANDLER:
152 g_value_set_object (value, priv->handler);
155 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
160 empathy_call_window_class_init (
161 EmpathyCallWindowClass *empathy_call_window_class)
163 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
164 GParamSpec *param_spec;
166 g_type_class_add_private (empathy_call_window_class,
167 sizeof (EmpathyCallWindowPriv));
169 object_class->set_property = empathy_call_window_set_property;
170 object_class->get_property = empathy_call_window_get_property;
172 object_class->dispose = empathy_call_window_dispose;
173 object_class->finalize = empathy_call_window_finalize;
175 param_spec = g_param_spec_object ("handler",
176 "handler", "The call handler",
177 EMPATHY_TYPE_CALL_HANDLER,
178 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
179 g_object_class_install_property (object_class,
180 PROP_CALL_HANDLER, param_spec);
185 empathy_call_window_dispose (GObject *object)
187 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
188 EmpathyCallWindowPriv *priv = GET_PRIV (self);
190 if (priv->dispose_has_run)
193 priv->dispose_has_run = TRUE;
195 if (priv->handler != NULL)
196 g_object_unref (priv->handler);
198 priv->handler = NULL;
200 if (priv->pipeline != NULL)
201 g_object_unref (priv->pipeline);
202 priv->pipeline = NULL;
204 if (priv->video_input != NULL)
205 g_object_unref (priv->video_input);
206 priv->video_input = NULL;
208 if (priv->audio_input != NULL)
209 g_object_unref (priv->audio_input);
210 priv->audio_input = NULL;
212 if (priv->audio_output != NULL)
213 g_object_unref (priv->audio_output);
214 priv->audio_output = NULL;
216 if (priv->video_tee != NULL)
217 g_object_unref (priv->video_tee);
218 priv->video_tee = NULL;
220 /* release any references held by the object here */
221 if (G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose)
222 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
226 empathy_call_window_finalize (GObject *object)
228 //EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
229 //EmpathyCallWindowPriv *priv = GET_PRIV (self);
231 /* free any data held directly by the object here */
233 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
238 empathy_call_window_new (EmpathyCallHandler *handler)
240 return EMPATHY_CALL_WINDOW (
241 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
245 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
246 GstElement *conference, gpointer user_data)
248 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
249 EmpathyCallWindowPriv *priv = GET_PRIV (self);
251 gst_bin_add (GST_BIN (priv->pipeline), conference);
253 gst_element_set_state (conference, GST_STATE_PLAYING);
255 printf ("ADDING CONFERENCE\n");
259 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
260 GstPad *src, guint media_type, gpointer user_data)
262 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
263 EmpathyCallWindowPriv *priv = GET_PRIV (self);
268 printf ("ADDING SRC PAD %d\n", media_type);
272 case TP_MEDIA_STREAM_TYPE_AUDIO:
273 element = priv->audio_output;
274 g_object_ref (element);
276 case TP_MEDIA_STREAM_TYPE_VIDEO:
278 empathy_video_widget_get_element (
279 EMPATHY_VIDEO_WIDGET (priv->video_output));
282 g_assert_not_reached ();
285 gst_bin_add (GST_BIN (priv->pipeline), element);
287 pad = gst_element_get_static_pad (element, "sink");
288 gst_element_set_state (element, GST_STATE_PLAYING);
290 gst_pad_link (src, pad);
294 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
295 GstPad *sink, guint media_type, gpointer user_data)
297 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
298 EmpathyCallWindowPriv *priv = GET_PRIV (self);
301 printf ("ADDING SINK PAD %d\n", media_type);
305 case TP_MEDIA_STREAM_TYPE_AUDIO:
306 gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input);
307 gst_element_set_state (priv->audio_input, GST_STATE_PLAYING);
309 pad = gst_element_get_static_pad (priv->audio_input, "src");
310 gst_pad_link (pad, sink);
312 case TP_MEDIA_STREAM_TYPE_VIDEO:
313 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
314 gst_pad_link (pad, sink);
317 g_assert_not_reached ();
323 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
325 EmpathyCallWindowPriv *priv = GET_PRIV (window);
329 g_signal_connect (priv->handler, "conference-added",
330 G_CALLBACK (empathy_call_window_conference_added_cb), window);
331 g_signal_connect (priv->handler, "src-pad-added",
332 G_CALLBACK (empathy_call_window_src_added_cb), window);
333 g_signal_connect (priv->handler, "sink-pad-added",
334 G_CALLBACK (empathy_call_window_sink_added_cb), window);
336 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
337 empathy_call_handler_set_bus (priv->handler, bus);
338 empathy_call_handler_start_call (priv->handler);
340 preview = empathy_video_widget_get_element (
341 EMPATHY_VIDEO_WIDGET (priv->video_preview));
343 gst_bin_add_many (GST_BIN (priv->pipeline), priv->video_input,
344 priv->video_tee, preview, NULL);
345 gst_element_link_many (priv->video_input, priv->video_tee,
348 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
350 g_object_unref (bus);
354 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
355 EmpathyCallWindow *window)
357 EmpathyCallWindowPriv *priv = GET_PRIV (window);
359 gst_element_set_state (priv->pipeline, GST_STATE_NULL);