2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2009 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 <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <telepathy-glib/util.h>
33 #include <telepathy-farsight/channel.h>
34 #include <telepathy-glib/util.h>
36 #include <gst/farsight/fs-element-added-notifier.h>
38 #include <libempathy/empathy-tp-contact-factory.h>
39 #include <libempathy/empathy-call-factory.h>
40 #include <libempathy/empathy-utils.h>
41 #include <libempathy-gtk/empathy-avatar-image.h>
42 #include <libempathy-gtk/empathy-video-widget.h>
43 #include <libempathy-gtk/empathy-audio-src.h>
44 #include <libempathy-gtk/empathy-audio-sink.h>
45 #include <libempathy-gtk/empathy-video-src.h>
46 #include <libempathy-gtk/empathy-ui-utils.h>
47 #include <libempathy-gtk/empathy-sound.h>
48 #include <libempathy-gtk/empathy-geometry.h>
50 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
51 #include <libempathy/empathy-debug.h>
53 #include "empathy-call-window.h"
54 #include "empathy-call-window-fullscreen.h"
55 #include "empathy-sidebar.h"
57 #define BUTTON_ID "empathy-call-dtmf-button-id"
59 #define CONTENT_HBOX_BORDER_WIDTH 6
60 #define CONTENT_HBOX_SPACING 3
61 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
63 #define SELF_VIDEO_SECTION_WIDTH 160
64 #define SELF_VIDEO_SECTION_HEIGTH 120
66 /* The avatar's default width and height are set to the same value because we
67 want a square icon. */
68 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
69 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
70 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
72 /* If an video input error occurs, the error message will start with "v4l" */
73 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
75 /* The time interval in milliseconds between 2 outgoing rings */
76 #define MS_BETWEEN_RING 500
78 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
87 static guint signals[LAST_SIGNAL] = {0};
91 PROP_CALL_HANDLER = 1,
102 CAMERA_STATE_OFF = 0,
103 CAMERA_STATE_PREVIEW,
107 /* private structure */
108 typedef struct _EmpathyCallWindowPriv EmpathyCallWindowPriv;
110 struct _EmpathyCallWindowPriv
112 gboolean dispose_has_run;
113 EmpathyCallHandler *handler;
114 EmpathyContact *contact;
119 GtkUIManager *ui_manager;
120 GtkWidget *errors_vbox;
121 /* widget displays the video received from the remote user. This widget is
122 * alive only during call. */
123 GtkWidget *video_output;
124 GtkWidget *video_preview;
125 GtkWidget *remote_user_avatar_widget;
126 GtkWidget *self_user_avatar_widget;
128 GtkWidget *sidebar_button;
129 GtkWidget *statusbar;
130 GtkWidget *volume_button;
131 GtkWidget *redial_button;
132 GtkWidget *mic_button;
136 GtkAction *menu_fullscreen;
137 GtkAction *action_camera;
138 GtkAction *action_camera_preview;
139 GtkWidget *tool_button_camera_off;
140 GtkWidget *tool_button_camera_preview;
141 GtkWidget *tool_button_camera_on;
143 /* The frames and boxes that contain self and remote avatar and video
144 input/output. When we redial, we destroy and re-create the boxes */
145 GtkWidget *remote_user_output_frame;
146 GtkWidget *self_user_output_frame;
147 GtkWidget *remote_user_output_hbox;
148 GtkWidget *self_user_output_hbox;
150 /* We keep a reference on the hbox which contains the main content so we can
151 easilly repack everything when toggling fullscreen */
152 GtkWidget *content_hbox;
154 /* This vbox is contained in the content_hbox and it contains the
155 self_user_output_frame and the sidebar button. When toggling fullscreen,
156 it needs to be repacked. We keep a reference on it for easier access. */
159 gulong video_output_motion_handler_id;
160 guint bus_message_source_id;
163 GtkWidget *volume_scale;
164 GtkWidget *volume_progress_bar;
165 GtkAdjustment *audio_input_adj;
167 GtkWidget *dtmf_panel;
169 GstElement *video_input;
170 GstElement *audio_input;
171 GstElement *audio_output;
172 GstElement *pipeline;
173 GstElement *video_tee;
176 GstElement *liveadder;
178 FsElementAddedNotifier *fsnotifier;
185 GtkWidget *video_contrast;
186 GtkWidget *video_brightness;
187 GtkWidget *video_gamma;
190 gboolean call_started;
191 gboolean sending_video;
192 CameraState camera_state;
194 EmpathyCallWindowFullscreen *fullscreen;
195 gboolean is_fullscreen;
197 /* Those fields represent the state of the window before it actually was in
199 gboolean sidebar_was_visible_before_fs;
200 gint original_width_before_fs;
201 gint original_height_before_fs;
203 /* TRUE if the call should be started when the pipeline is playing */
204 gboolean start_call_when_playing;
205 /* TRUE if we requested to set the pipeline in the playing state */
206 gboolean pipeline_playing;
209 #define GET_PRIV(o) \
210 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CALL_WINDOW, \
211 EmpathyCallWindowPriv))
213 static void empathy_call_window_realized_cb (GtkWidget *widget,
214 EmpathyCallWindow *window);
216 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
217 GdkEvent *event, EmpathyCallWindow *window);
219 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
220 GdkEventWindowState *event, EmpathyCallWindow *window);
222 static void empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
223 EmpathyCallWindow *window);
225 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
228 static void empathy_call_window_mic_toggled_cb (
229 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
231 static void empathy_call_window_sidebar_hidden_cb (EmpathySidebar *sidebar,
232 EmpathyCallWindow *window);
234 static void empathy_call_window_sidebar_shown_cb (EmpathySidebar *sidebar,
235 EmpathyCallWindow *window);
237 static void empathy_call_window_hangup_cb (gpointer object,
238 EmpathyCallWindow *window);
240 static void empathy_call_window_fullscreen_cb (gpointer object,
241 EmpathyCallWindow *window);
243 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
245 static gboolean empathy_call_window_video_button_press_cb (
246 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
248 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
249 GdkEventKey *event, EmpathyCallWindow *window);
251 static gboolean empathy_call_window_video_output_motion_notify (
252 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
254 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
257 static void empathy_call_window_redial_cb (gpointer object,
258 EmpathyCallWindow *window);
260 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
262 static void empathy_call_window_status_message (EmpathyCallWindow *window,
265 static void empathy_call_window_update_avatars_visibility (EmpathyTpCall *call,
266 EmpathyCallWindow *window);
268 static gboolean empathy_call_window_bus_message (GstBus *bus,
269 GstMessage *message, gpointer user_data);
272 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
273 gdouble value, EmpathyCallWindow *window);
275 static void block_camera_control_signals (EmpathyCallWindow *self);
276 static void unblock_camera_control_signals (EmpathyCallWindow *self);
279 empathy_call_window_setup_toolbar (EmpathyCallWindow *self)
281 EmpathyCallWindowPriv *priv = GET_PRIV (self);
282 GtkToolItem *tool_item;
283 GtkWidget *camera_off_icon;
284 GdkPixbuf *pixbuf, *modded_pixbuf;
286 /* set the icon of the 'camera off' button by greying off the webcam icon */
287 pixbuf = empathy_pixbuf_from_icon_name ("camera-web",
288 GTK_ICON_SIZE_SMALL_TOOLBAR);
290 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
291 gdk_pixbuf_get_width (pixbuf),
292 gdk_pixbuf_get_height (pixbuf));
294 gdk_pixbuf_saturate_and_pixelate (pixbuf, modded_pixbuf, 1.0, TRUE);
295 g_object_unref (pixbuf);
297 camera_off_icon = gtk_image_new_from_pixbuf (modded_pixbuf);
298 g_object_unref (modded_pixbuf);
299 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (
300 priv->tool_button_camera_off), camera_off_icon);
302 /* Add an empty expanded GtkToolItem so the volume button is at the end of
304 tool_item = gtk_tool_item_new ();
305 gtk_tool_item_set_expand (tool_item, TRUE);
306 gtk_widget_show (GTK_WIDGET (tool_item));
307 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
309 priv->volume_button = gtk_volume_button_new ();
310 /* FIXME listen to the audiosinks signals and update the button according to
311 * that, for now starting out at 1.0 and assuming only the app changes the
313 gtk_scale_button_set_value (GTK_SCALE_BUTTON (priv->volume_button), 1.0);
314 g_signal_connect (G_OBJECT (priv->volume_button), "value-changed",
315 G_CALLBACK (empathy_call_window_volume_changed_cb), self);
317 tool_item = gtk_tool_item_new ();
318 gtk_container_add (GTK_CONTAINER (tool_item), priv->volume_button);
319 gtk_widget_show_all (GTK_WIDGET (tool_item));
320 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
324 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
326 EmpathyCallWindowPriv *priv = GET_PRIV (window);
331 g_object_get (priv->handler, "tp-call", &call, NULL);
333 button_quark = g_quark_from_static_string (BUTTON_ID);
334 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
337 empathy_tp_call_start_tone (call, event);
339 g_object_unref (call);
343 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
345 EmpathyCallWindowPriv *priv = GET_PRIV (window);
348 g_object_get (priv->handler, "tp-call", &call, NULL);
350 empathy_tp_call_stop_tone (call);
352 g_object_unref (call);
356 empathy_call_window_create_dtmf (EmpathyCallWindow *self)
364 } dtmfbuttons[] = { { "1", TP_DTMF_EVENT_DIGIT_1 },
365 { "2", TP_DTMF_EVENT_DIGIT_2 },
366 { "3", TP_DTMF_EVENT_DIGIT_3 },
367 { "4", TP_DTMF_EVENT_DIGIT_4 },
368 { "5", TP_DTMF_EVENT_DIGIT_5 },
369 { "6", TP_DTMF_EVENT_DIGIT_6 },
370 { "7", TP_DTMF_EVENT_DIGIT_7 },
371 { "8", TP_DTMF_EVENT_DIGIT_8 },
372 { "9", TP_DTMF_EVENT_DIGIT_9 },
373 { "#", TP_DTMF_EVENT_HASH },
374 { "0", TP_DTMF_EVENT_DIGIT_0 },
375 { "*", TP_DTMF_EVENT_ASTERISK },
378 button_quark = g_quark_from_static_string (BUTTON_ID);
380 table = gtk_table_new (4, 3, TRUE);
382 for (i = 0; dtmfbuttons[i].label != NULL; i++)
384 GtkWidget *button = gtk_button_new_with_label (dtmfbuttons[i].label);
385 gtk_table_attach (GTK_TABLE (table), button, i % 3, i % 3 + 1,
386 i/3, i/3 + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1);
388 g_object_set_qdata (G_OBJECT (button), button_quark,
389 GUINT_TO_POINTER (dtmfbuttons[i].event));
391 g_signal_connect (G_OBJECT (button), "pressed",
392 G_CALLBACK (dtmf_button_pressed_cb), self);
393 g_signal_connect (G_OBJECT (button), "released",
394 G_CALLBACK (dtmf_button_released_cb), self);
401 empathy_call_window_create_video_input_add_slider (EmpathyCallWindow *self,
402 gchar *label_text, GtkWidget *bin)
404 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
405 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
406 GtkWidget *label = gtk_label_new (label_text);
408 gtk_widget_set_sensitive (scale, FALSE);
410 gtk_container_add (GTK_CONTAINER (bin), vbox);
412 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
413 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
414 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
420 empathy_call_window_video_contrast_changed_cb (GtkAdjustment *adj,
421 EmpathyCallWindow *self)
424 EmpathyCallWindowPriv *priv = GET_PRIV (self);
426 empathy_video_src_set_channel (priv->video_input,
427 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
431 empathy_call_window_video_brightness_changed_cb (GtkAdjustment *adj,
432 EmpathyCallWindow *self)
435 EmpathyCallWindowPriv *priv = GET_PRIV (self);
437 empathy_video_src_set_channel (priv->video_input,
438 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
442 empathy_call_window_video_gamma_changed_cb (GtkAdjustment *adj,
443 EmpathyCallWindow *self)
446 EmpathyCallWindowPriv *priv = GET_PRIV (self);
448 empathy_video_src_set_channel (priv->video_input,
449 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
454 empathy_call_window_create_video_input (EmpathyCallWindow *self)
456 EmpathyCallWindowPriv *priv = GET_PRIV (self);
459 hbox = gtk_hbox_new (TRUE, 3);
461 priv->video_contrast = empathy_call_window_create_video_input_add_slider (
462 self, _("Contrast"), hbox);
464 priv->video_brightness = empathy_call_window_create_video_input_add_slider (
465 self, _("Brightness"), hbox);
467 priv->video_gamma = empathy_call_window_create_video_input_add_slider (
468 self, _("Gamma"), hbox);
474 empathy_call_window_setup_video_input (EmpathyCallWindow *self)
476 EmpathyCallWindowPriv *priv = GET_PRIV (self);
480 supported = empathy_video_src_get_supported_channels (priv->video_input);
482 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
484 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
486 gtk_adjustment_set_value (adj,
487 empathy_video_src_get_channel (priv->video_input,
488 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
490 g_signal_connect (G_OBJECT (adj), "value-changed",
491 G_CALLBACK (empathy_call_window_video_contrast_changed_cb), self);
493 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
496 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
498 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
500 gtk_adjustment_set_value (adj,
501 empathy_video_src_get_channel (priv->video_input,
502 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
504 g_signal_connect (G_OBJECT (adj), "value-changed",
505 G_CALLBACK (empathy_call_window_video_brightness_changed_cb), self);
506 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
509 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
511 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
513 gtk_adjustment_set_value (adj,
514 empathy_video_src_get_channel (priv->video_input,
515 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
517 g_signal_connect (G_OBJECT (adj), "value-changed",
518 G_CALLBACK (empathy_call_window_video_gamma_changed_cb), self);
519 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
524 empathy_call_window_mic_volume_changed_cb (GtkAdjustment *adj,
525 EmpathyCallWindow *self)
527 EmpathyCallWindowPriv *priv = GET_PRIV (self);
530 volume = gtk_adjustment_get_value (adj)/100.0;
532 /* Don't store the volume because of muting */
533 if (volume > 0 || gtk_toggle_tool_button_get_active (
534 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
535 priv->volume = volume;
537 /* Ensure that the toggle button is active if the volume is > 0 and inactive
538 * if it's smaller than 0 */
539 if ((volume > 0) != gtk_toggle_tool_button_get_active (
540 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
541 gtk_toggle_tool_button_set_active (
542 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
544 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
549 empathy_call_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
550 gdouble level, EmpathyCallWindow *window)
553 EmpathyCallWindowPriv *priv = GET_PRIV (window);
555 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
556 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
561 empathy_call_window_create_audio_input (EmpathyCallWindow *self)
563 EmpathyCallWindowPriv *priv = GET_PRIV (self);
564 GtkWidget *hbox, *vbox, *label;
566 hbox = gtk_hbox_new (TRUE, 3);
568 vbox = gtk_vbox_new (FALSE, 3);
569 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
571 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
572 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
573 label = gtk_label_new (_("Volume"));
575 priv->audio_input_adj = gtk_range_get_adjustment (
576 GTK_RANGE (priv->volume_scale));
577 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
578 (priv->audio_input));
579 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
581 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
582 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), self);
584 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
585 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
587 priv->volume_progress_bar = gtk_progress_bar_new ();
588 gtk_progress_bar_set_orientation (
589 GTK_PROGRESS_BAR (priv->volume_progress_bar),
590 GTK_PROGRESS_BOTTOM_TO_TOP);
591 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
594 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
601 create_video_output_widget (EmpathyCallWindow *self)
603 EmpathyCallWindowPriv *priv = GET_PRIV (self);
606 g_assert (priv->video_output == NULL);
607 g_assert (priv->pipeline != NULL);
609 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
610 priv->video_output = empathy_video_widget_new (bus);
612 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
613 priv->video_output, TRUE, TRUE, 0);
615 gtk_widget_add_events (priv->video_output,
616 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
617 g_signal_connect (G_OBJECT (priv->video_output), "button-press-event",
618 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
620 g_object_unref (bus);
624 create_audio_output (EmpathyCallWindow *self)
626 EmpathyCallWindowPriv *priv = GET_PRIV (self);
628 g_assert (priv->audio_output == NULL);
629 priv->audio_output = empathy_audio_sink_new ();
630 gst_object_ref (priv->audio_output);
631 gst_object_sink (priv->audio_output);
635 create_video_input (EmpathyCallWindow *self)
637 EmpathyCallWindowPriv *priv = GET_PRIV (self);
639 g_assert (priv->video_input == NULL);
640 priv->video_input = empathy_video_src_new ();
641 gst_object_ref (priv->video_input);
642 gst_object_sink (priv->video_input);
646 create_audio_input (EmpathyCallWindow *self)
648 EmpathyCallWindowPriv *priv = GET_PRIV (self);
650 g_assert (priv->audio_input == NULL);
651 priv->audio_input = empathy_audio_src_new ();
652 gst_object_ref (priv->audio_input);
653 gst_object_sink (priv->audio_input);
655 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
656 G_CALLBACK (empathy_call_window_audio_input_level_changed_cb),
661 add_video_preview_to_pipeline (EmpathyCallWindow *self)
663 EmpathyCallWindowPriv *priv = GET_PRIV (self);
666 g_assert (priv->video_preview != NULL);
667 g_assert (priv->pipeline != NULL);
668 g_assert (priv->video_input != NULL);
669 g_assert (priv->video_tee != NULL);
671 preview = empathy_video_widget_get_element (
672 EMPATHY_VIDEO_WIDGET (priv->video_preview));
674 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
676 g_warning ("Could not add video input to pipeline");
680 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee))
682 g_warning ("Could not add video tee to pipeline");
686 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
688 g_warning ("Could not add video preview to pipeline");
692 if (!gst_element_link (priv->video_input, priv->video_tee))
694 g_warning ("Could not link video input to video tee");
698 if (!gst_element_link (priv->video_tee, preview))
700 g_warning ("Could not link video tee to video preview");
706 create_video_preview (EmpathyCallWindow *self)
708 EmpathyCallWindowPriv *priv = GET_PRIV (self);
711 g_assert (priv->video_preview == NULL);
712 g_assert (priv->video_tee == NULL);
714 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
716 priv->video_preview = empathy_video_widget_new_with_size (bus,
717 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
718 g_object_set (priv->video_preview, "sync", FALSE, "async", TRUE, NULL);
720 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
721 priv->video_preview, TRUE, TRUE, 0);
723 priv->video_tee = gst_element_factory_make ("tee", NULL);
724 gst_object_ref (priv->video_tee);
725 gst_object_sink (priv->video_tee);
727 g_object_unref (bus);
731 play_camera (EmpathyCallWindow *window,
734 EmpathyCallWindowPriv *priv = GET_PRIV (window);
738 if (priv->video_preview == NULL)
740 create_video_preview (window);
741 add_video_preview_to_pipeline (window);
745 state = GST_STATE_PLAYING;
747 state = GST_STATE_NULL;
749 preview = empathy_video_widget_get_element (
750 EMPATHY_VIDEO_WIDGET (priv->video_preview));
752 gst_element_set_state (preview, state);
753 gst_element_set_state (priv->video_input, state);
754 gst_element_set_state (priv->video_tee, state);
758 display_video_preview (EmpathyCallWindow *self,
761 EmpathyCallWindowPriv *priv = GET_PRIV (self);
765 /* Display the preview and hide the self avatar */
766 DEBUG ("Show video preview");
768 play_camera (self, TRUE);
769 gtk_widget_show (priv->video_preview);
770 gtk_widget_hide (priv->self_user_avatar_widget);
774 /* Display the self avatar and hide the preview */
775 DEBUG ("Show self avatar");
777 if (priv->video_preview != NULL)
778 gtk_widget_hide (priv->video_preview);
779 play_camera (self, FALSE);
780 gtk_widget_show (priv->self_user_avatar_widget);
785 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
787 EmpathyCallWindowPriv *priv = GET_PRIV (window);
789 empathy_call_window_status_message (window, _("Connecting…"));
790 priv->call_state = CONNECTING;
793 empathy_sound_start_playing (GTK_WIDGET (window),
794 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
798 disable_camera (EmpathyCallWindow *self)
800 EmpathyCallWindowPriv *priv = GET_PRIV (self);
802 if (priv->camera_state == CAMERA_STATE_OFF)
805 DEBUG ("Disable camera");
807 display_video_preview (self, FALSE);
809 if (priv->camera_state == CAMERA_STATE_ON)
810 empathy_call_window_set_send_video (self, FALSE);
812 block_camera_control_signals (self);
813 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
814 priv->tool_button_camera_on), FALSE);
815 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
816 priv->tool_button_camera_preview), FALSE);
818 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
819 priv->tool_button_camera_off), TRUE);
820 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
822 unblock_camera_control_signals (self);
824 priv->camera_state = CAMERA_STATE_OFF;
828 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
829 EmpathyCallWindow *self)
831 EmpathyCallWindowPriv *priv = GET_PRIV (self);
833 if (!gtk_toggle_tool_button_get_active (toggle))
835 if (priv->camera_state == CAMERA_STATE_OFF)
837 /* We can't change the state by disabling the button */
838 block_camera_control_signals (self);
839 gtk_toggle_tool_button_set_active (toggle, TRUE);
840 unblock_camera_control_signals (self);
846 disable_camera (self);
850 enable_preview (EmpathyCallWindow *self)
852 EmpathyCallWindowPriv *priv = GET_PRIV (self);
854 if (priv->camera_state == CAMERA_STATE_PREVIEW)
857 DEBUG ("Enable preview");
859 if (priv->camera_state == CAMERA_STATE_ON)
860 /* preview is already displayed so we just have to stop sending */
861 empathy_call_window_set_send_video (self, FALSE);
863 display_video_preview (self, TRUE);
865 block_camera_control_signals (self);
866 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
867 priv->tool_button_camera_off), FALSE);
868 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
869 priv->tool_button_camera_on), FALSE);
871 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
872 priv->tool_button_camera_preview), TRUE);
873 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
874 CAMERA_STATE_PREVIEW);
875 unblock_camera_control_signals (self);
877 priv->camera_state = CAMERA_STATE_PREVIEW;
881 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
882 EmpathyCallWindow *self)
884 EmpathyCallWindowPriv *priv = GET_PRIV (self);
886 if (!gtk_toggle_tool_button_get_active (toggle))
888 if (priv->camera_state == CAMERA_STATE_PREVIEW)
890 /* We can't change the state by disabling the button */
891 block_camera_control_signals (self);
892 gtk_toggle_tool_button_set_active (toggle, TRUE);
893 unblock_camera_control_signals (self);
899 enable_preview (self);
903 enable_camera (EmpathyCallWindow *self)
905 EmpathyCallWindowPriv *priv = GET_PRIV (self);
907 if (priv->camera_state == CAMERA_STATE_ON)
910 DEBUG ("Enable camera");
912 empathy_call_window_set_send_video (self, TRUE);
914 block_camera_control_signals (self);
915 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
916 priv->tool_button_camera_off), FALSE);
917 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
918 priv->tool_button_camera_preview), FALSE);
920 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
921 priv->tool_button_camera_on), TRUE);
922 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
924 unblock_camera_control_signals (self);
926 priv->camera_state = CAMERA_STATE_ON;
930 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
931 EmpathyCallWindow *self)
933 EmpathyCallWindowPriv *priv = GET_PRIV (self);
935 if (!gtk_toggle_tool_button_get_active (toggle))
937 if (priv->camera_state == CAMERA_STATE_ON)
939 /* We can't change the state by disabling the button */
940 block_camera_control_signals (self);
941 gtk_toggle_tool_button_set_active (toggle, TRUE);
942 unblock_camera_control_signals (self);
948 enable_camera (self);
952 action_camera_change_cb (GtkRadioAction *action,
953 GtkRadioAction *current,
954 EmpathyCallWindow *self)
958 state = gtk_radio_action_get_current_value (current);
962 case CAMERA_STATE_OFF:
963 disable_camera (self);
966 case CAMERA_STATE_PREVIEW:
967 enable_preview (self);
970 case CAMERA_STATE_ON:
971 enable_camera (self);
975 g_assert_not_reached ();
980 create_pipeline (EmpathyCallWindow *self)
982 EmpathyCallWindowPriv *priv = GET_PRIV (self);
985 g_assert (priv->pipeline == NULL);
987 priv->pipeline = gst_pipeline_new (NULL);
988 priv->pipeline_playing = FALSE;
990 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
991 priv->bus_message_source_id = gst_bus_add_watch (bus,
992 empathy_call_window_bus_message, self);
994 g_object_unref (bus);
999 empathy_call_window_init (EmpathyCallWindow *self)
1001 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1003 GtkWidget *top_vbox;
1009 GError *error = NULL;
1011 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1012 gui = empathy_builder_get_file (filename,
1013 "call_window_vbox", &top_vbox,
1014 "errors_vbox", &priv->errors_vbox,
1015 "pane", &priv->pane,
1016 "statusbar", &priv->statusbar,
1017 "redial", &priv->redial_button,
1018 "microphone", &priv->mic_button,
1019 "toolbar", &priv->toolbar,
1020 "menuredial", &priv->redial,
1021 "ui_manager", &priv->ui_manager,
1022 "menufullscreen", &priv->menu_fullscreen,
1023 "camera_off", &priv->tool_button_camera_off,
1024 "camera_preview", &priv->tool_button_camera_preview,
1025 "camera_on", &priv->tool_button_camera_on,
1026 "action_camera_off", &priv->action_camera,
1027 "action_camera_preview", &priv->action_camera_preview,
1031 empathy_builder_connect (gui, self,
1032 "menuhangup", "activate", empathy_call_window_hangup_cb,
1033 "hangup", "clicked", empathy_call_window_hangup_cb,
1034 "menuredial", "activate", empathy_call_window_redial_cb,
1035 "redial", "clicked", empathy_call_window_redial_cb,
1036 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1037 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1038 "camera_off", "toggled", tool_button_camera_off_toggled_cb,
1039 "camera_preview", "toggled", tool_button_camera_preview_toggled_cb,
1040 "camera_on", "toggled", tool_button_camera_on_toggled_cb,
1041 "action_camera_off", "changed", action_camera_change_cb,
1044 priv->lock = g_mutex_new ();
1046 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1048 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1049 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1050 CONTENT_HBOX_BORDER_WIDTH);
1051 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1053 /* remote user output frame */
1054 priv->remote_user_output_frame = gtk_frame_new (NULL);
1055 gtk_widget_set_size_request (priv->remote_user_output_frame,
1056 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1057 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1058 priv->remote_user_output_frame, TRUE, TRUE,
1059 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1061 priv->remote_user_output_hbox = gtk_hbox_new (FALSE, 0);
1063 priv->remote_user_avatar_widget = gtk_image_new ();
1065 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1066 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1068 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1069 priv->remote_user_output_hbox);
1071 /* self user output frame */
1072 priv->self_user_output_frame = gtk_frame_new (NULL);
1073 gtk_widget_set_size_request (priv->self_user_output_frame,
1074 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1076 priv->self_user_output_hbox = gtk_hbox_new (FALSE, 0);
1078 priv->self_user_avatar_widget = gtk_image_new ();
1079 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1080 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1082 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1083 priv->self_user_output_hbox);
1085 create_pipeline (self);
1086 create_video_output_widget (self);
1087 create_audio_input (self);
1088 create_audio_output (self);
1089 create_video_input (self);
1091 priv->fsnotifier = fs_element_added_notifier_new ();
1092 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1094 /* The call will be started as soon the pipeline is playing */
1095 priv->start_call_when_playing = TRUE;
1097 keyfile = g_key_file_new ();
1098 filename = empathy_file_lookup ("element-properties", "data");
1099 if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error))
1101 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1106 g_warning ("Could not load element-properties file: %s", error->message);
1107 g_key_file_free (keyfile);
1108 g_clear_error (&error);
1112 priv->vbox = gtk_vbox_new (FALSE, 3);
1113 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1114 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1115 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1118 empathy_call_window_setup_toolbar (self);
1120 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1121 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1122 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1123 G_CALLBACK (empathy_call_window_sidebar_toggled_cb), self);
1125 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1127 h = gtk_hbox_new (FALSE, 3);
1128 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1129 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1131 priv->sidebar = empathy_sidebar_new ();
1132 g_signal_connect (G_OBJECT (priv->sidebar),
1133 "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb), self);
1134 g_signal_connect (G_OBJECT (priv->sidebar),
1135 "show", G_CALLBACK (empathy_call_window_sidebar_shown_cb), self);
1136 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1138 page = empathy_call_window_create_audio_input (self);
1139 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Audio input"),
1142 page = empathy_call_window_create_video_input (self);
1143 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Video input"),
1146 priv->dtmf_panel = empathy_call_window_create_dtmf (self);
1147 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Dialpad"),
1150 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1153 gtk_widget_show_all (top_vbox);
1155 gtk_widget_hide (priv->sidebar);
1157 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1158 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1159 priv->video_output);
1160 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1161 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1163 g_signal_connect (G_OBJECT (self), "realize",
1164 G_CALLBACK (empathy_call_window_realized_cb), self);
1166 g_signal_connect (G_OBJECT (self), "delete-event",
1167 G_CALLBACK (empathy_call_window_delete_cb), self);
1169 g_signal_connect (G_OBJECT (self), "window-state-event",
1170 G_CALLBACK (empathy_call_window_state_event_cb), self);
1172 g_signal_connect (G_OBJECT (self), "key-press-event",
1173 G_CALLBACK (empathy_call_window_key_press_cb), self);
1175 priv->timer = g_timer_new ();
1177 g_object_ref (priv->ui_manager);
1178 g_object_unref (gui);
1180 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1183 /* Instead of specifying a width and a height, we specify only one size. That's
1184 because we want a square avatar icon. */
1186 init_contact_avatar_with_size (EmpathyContact *contact,
1187 GtkWidget *image_widget,
1190 GdkPixbuf *pixbuf_avatar = NULL;
1192 if (contact != NULL)
1194 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1198 if (pixbuf_avatar == NULL)
1200 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized ("stock_person",
1204 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1206 if (pixbuf_avatar != NULL)
1207 g_object_unref (pixbuf_avatar);
1211 set_window_title (EmpathyCallWindow *self)
1213 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1216 /* translators: Call is a noun and %s is the contact name. This string
1217 * is used in the window title */
1218 tmp = g_strdup_printf (_("Call with %s"),
1219 empathy_contact_get_name (priv->contact));
1220 gtk_window_set_title (GTK_WINDOW (self), tmp);
1225 contact_name_changed_cb (EmpathyContact *contact,
1226 GParamSpec *pspec, EmpathyCallWindow *self)
1228 set_window_title (self);
1232 contact_avatar_changed_cb (EmpathyContact *contact,
1233 GParamSpec *pspec, GtkWidget *avatar_widget)
1237 size = avatar_widget->allocation.height;
1241 /* the widget is not allocated yet, set a default size */
1242 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1243 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1246 init_contact_avatar_with_size (contact, avatar_widget, size);
1250 empathy_call_window_got_self_contact_cb (EmpathyTpContactFactory *factory,
1251 EmpathyContact *contact, const GError *error, gpointer user_data,
1252 GObject *weak_object)
1254 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1255 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1257 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1258 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1260 g_signal_connect (contact, "notify::avatar",
1261 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1265 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1266 EmpathyCallHandler *handler)
1268 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1270 g_object_get (handler, "contact", &(priv->contact), NULL);
1272 if (priv->contact != NULL)
1274 TpConnection *connection;
1275 EmpathyTpContactFactory *factory;
1277 set_window_title (self);
1279 g_signal_connect (priv->contact, "notify::name",
1280 G_CALLBACK (contact_name_changed_cb), self);
1281 g_signal_connect (priv->contact, "notify::avatar",
1282 G_CALLBACK (contact_avatar_changed_cb),
1283 priv->remote_user_avatar_widget);
1285 /* Retreiving the self avatar */
1286 connection = empathy_contact_get_connection (priv->contact);
1287 factory = empathy_tp_contact_factory_dup_singleton (connection);
1288 empathy_tp_contact_factory_get_from_handle (factory,
1289 tp_connection_get_self_handle (connection),
1290 empathy_call_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1292 g_object_unref (factory);
1296 g_warning ("call handler doesn't have a contact");
1297 /* translators: Call is a noun. This string is used in the window
1299 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1301 /* Since we can't access the remote contact, we can't get a connection
1302 to it and can't get the self contact (and its avatar). This means
1303 that we have to manually set the self avatar. */
1304 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1305 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1308 init_contact_avatar_with_size (priv->contact,
1309 priv->remote_user_avatar_widget,
1310 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1311 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1313 /* The remote avatar is shown by default and will be hidden when we receive
1314 video from the remote side. */
1315 gtk_widget_hide (priv->video_output);
1316 gtk_widget_show (priv->remote_user_avatar_widget);
1320 empathy_call_window_constructed (GObject *object)
1322 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1323 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1324 EmpathyTpCall *call;
1326 g_assert (priv->handler != NULL);
1328 g_object_get (priv->handler, "tp-call", &call, NULL);
1329 priv->outgoing = (call == NULL);
1331 g_object_unref (call);
1333 empathy_call_window_setup_avatars (self, priv->handler);
1334 empathy_call_window_set_state_connecting (self);
1336 if (!empathy_call_handler_has_initial_video (priv->handler))
1338 gtk_toggle_tool_button_set_active (
1339 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1341 /* If call has InitialVideo, the preview will be started once the call has
1342 * been started (start_call()). */
1345 static void empathy_call_window_dispose (GObject *object);
1346 static void empathy_call_window_finalize (GObject *object);
1349 empathy_call_window_set_property (GObject *object,
1350 guint property_id, const GValue *value, GParamSpec *pspec)
1352 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1354 switch (property_id)
1356 case PROP_CALL_HANDLER:
1357 priv->handler = g_value_dup_object (value);
1360 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1365 empathy_call_window_get_property (GObject *object,
1366 guint property_id, GValue *value, GParamSpec *pspec)
1368 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1370 switch (property_id)
1372 case PROP_CALL_HANDLER:
1373 g_value_set_object (value, priv->handler);
1376 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1381 empathy_call_window_class_init (
1382 EmpathyCallWindowClass *empathy_call_window_class)
1384 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1385 GParamSpec *param_spec;
1387 g_type_class_add_private (empathy_call_window_class,
1388 sizeof (EmpathyCallWindowPriv));
1390 object_class->constructed = empathy_call_window_constructed;
1391 object_class->set_property = empathy_call_window_set_property;
1392 object_class->get_property = empathy_call_window_get_property;
1394 object_class->dispose = empathy_call_window_dispose;
1395 object_class->finalize = empathy_call_window_finalize;
1397 param_spec = g_param_spec_object ("handler",
1398 "handler", "The call handler",
1399 EMPATHY_TYPE_CALL_HANDLER,
1400 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1401 g_object_class_install_property (object_class,
1402 PROP_CALL_HANDLER, param_spec);
1406 empathy_call_window_video_stream_changed_cb (EmpathyTpCall *call,
1407 GParamSpec *property, EmpathyCallWindow *self)
1409 DEBUG ("video stream changed");
1410 empathy_call_window_update_avatars_visibility (call, self);
1414 empathy_call_window_dispose (GObject *object)
1416 EmpathyTpCall *call;
1417 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1418 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1420 if (priv->dispose_has_run)
1423 priv->dispose_has_run = TRUE;
1425 g_object_get (priv->handler, "tp-call", &call, NULL);
1429 g_object_unref (call);
1432 if (priv->handler != NULL)
1434 empathy_call_handler_stop_call (priv->handler);
1435 g_object_unref (priv->handler);
1437 priv->handler = NULL;
1439 if (priv->bus_message_source_id != 0)
1441 g_source_remove (priv->bus_message_source_id);
1442 priv->bus_message_source_id = 0;
1445 if (priv->pipeline != NULL)
1446 g_object_unref (priv->pipeline);
1447 priv->pipeline = NULL;
1449 if (priv->video_input != NULL)
1450 g_object_unref (priv->video_input);
1451 priv->video_input = NULL;
1453 if (priv->audio_input != NULL)
1454 g_object_unref (priv->audio_input);
1455 priv->audio_input = NULL;
1457 if (priv->audio_output != NULL)
1458 g_object_unref (priv->audio_output);
1459 priv->audio_output = NULL;
1461 if (priv->video_tee != NULL)
1462 g_object_unref (priv->video_tee);
1463 priv->video_tee = NULL;
1465 if (priv->liveadder != NULL)
1466 gst_object_unref (priv->liveadder);
1467 priv->liveadder = NULL;
1469 if (priv->fsnotifier != NULL)
1470 g_object_unref (priv->fsnotifier);
1471 priv->fsnotifier = NULL;
1473 if (priv->timer_id != 0)
1474 g_source_remove (priv->timer_id);
1477 if (priv->ui_manager != NULL)
1478 g_object_unref (priv->ui_manager);
1479 priv->ui_manager = NULL;
1481 if (priv->fullscreen != NULL)
1482 g_object_unref (priv->fullscreen);
1483 priv->fullscreen = NULL;
1485 if (priv->contact != NULL)
1487 g_signal_handlers_disconnect_by_func (priv->contact,
1488 contact_name_changed_cb, self);
1489 g_object_unref (priv->contact);
1490 priv->contact = NULL;
1493 /* release any references held by the object here */
1494 if (G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose)
1495 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1499 empathy_call_window_finalize (GObject *object)
1501 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1502 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1504 if (priv->video_output_motion_handler_id != 0)
1506 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1507 priv->video_output_motion_handler_id);
1508 priv->video_output_motion_handler_id = 0;
1511 /* free any data held directly by the object here */
1512 g_mutex_free (priv->lock);
1514 g_timer_destroy (priv->timer);
1516 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1521 empathy_call_window_new (EmpathyCallHandler *handler)
1523 return EMPATHY_CALL_WINDOW (
1524 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1528 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1529 GstElement *conference, gpointer user_data)
1531 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1532 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1534 gst_bin_add (GST_BIN (priv->pipeline), conference);
1536 gst_element_set_state (conference, GST_STATE_PLAYING);
1540 empathy_call_window_request_resource_cb (EmpathyCallHandler *handler,
1541 FsMediaType type, FsStreamDirection direction, gpointer user_data)
1543 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1544 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1546 if (type != FS_MEDIA_TYPE_VIDEO)
1549 if (direction == FS_DIRECTION_RECV)
1552 /* video and direction is send */
1553 return priv->video_input != NULL;
1557 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1559 GstStateChangeReturn state_change_return;
1560 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1562 if (priv->pipeline == NULL)
1565 if (priv->bus_message_source_id != 0)
1567 g_source_remove (priv->bus_message_source_id);
1568 priv->bus_message_source_id = 0;
1571 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1573 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1574 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1576 if (priv->pipeline != NULL)
1577 g_object_unref (priv->pipeline);
1578 priv->pipeline = NULL;
1580 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1581 empathy_call_window_mic_volume_changed_cb, self);
1583 if (priv->video_tee != NULL)
1584 g_object_unref (priv->video_tee);
1585 priv->video_tee = NULL;
1587 if (priv->video_preview != NULL)
1588 gtk_widget_destroy (priv->video_preview);
1589 priv->video_preview = NULL;
1591 priv->liveadder = NULL;
1592 priv->funnel = NULL;
1594 create_pipeline (self);
1595 /* Call will be started when user will hit the 'redial' button */
1596 priv->start_call_when_playing = FALSE;
1597 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1603 g_message ("Error: could not destroy pipeline. Closing call window");
1604 gtk_widget_destroy (GTK_WIDGET (self));
1611 empathy_call_window_disconnected (EmpathyCallWindow *self,
1614 gboolean could_disconnect = FALSE;
1615 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1616 gboolean could_reset_pipeline;
1618 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1620 if (priv->call_state == CONNECTING)
1621 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
1623 if (priv->call_state != REDIALING)
1624 priv->call_state = DISCONNECTED;
1626 if (could_reset_pipeline)
1628 g_mutex_lock (priv->lock);
1630 g_timer_stop (priv->timer);
1632 if (priv->timer_id != 0)
1633 g_source_remove (priv->timer_id);
1636 g_mutex_unlock (priv->lock);
1639 /* We are about to destroy the window, no need to update it or create
1640 * a video preview */
1643 empathy_call_window_status_message (self, _("Disconnected"));
1645 gtk_action_set_sensitive (priv->redial, TRUE);
1646 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1648 /* Unsensitive the camera and mic button */
1649 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1650 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1652 /* Be sure that the mic button is enabled */
1653 gtk_toggle_tool_button_set_active (
1654 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1656 if (priv->camera_state == CAMERA_STATE_ON)
1658 /* Enable the 'preview' button as we are not sending atm. */
1659 gtk_toggle_tool_button_set_active (
1660 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_preview), TRUE);
1662 else if (priv->camera_state == CAMERA_STATE_PREVIEW)
1664 /* Restart the preview with the new pipeline. */
1665 display_video_preview (self, TRUE);
1668 gtk_progress_bar_set_fraction (
1669 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1671 /* destroy the video output; it will be recreated when we'll redial */
1672 gtk_widget_destroy (priv->video_output);
1673 priv->video_output = NULL;
1675 gtk_widget_show (priv->remote_user_avatar_widget);
1677 priv->sending_video = FALSE;
1678 priv->call_started = FALSE;
1680 could_disconnect = TRUE;
1682 /* TODO: display the self avatar of the preview (depends if the "Always
1683 * Show Video Preview" is enabled or not) */
1686 return could_disconnect;
1691 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1694 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1695 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1697 if (empathy_call_window_disconnected (self, TRUE) &&
1698 priv->call_state == REDIALING)
1699 empathy_call_window_restart_call (self);
1704 empathy_call_window_channel_stream_closed_cb (EmpathyCallHandler *handler,
1705 TfStream *stream, gpointer user_data)
1707 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1708 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1711 g_object_get (stream, "media-type", &media_type, NULL);
1714 * This assumes that there is only one video stream per channel...
1717 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
1719 if (priv->funnel != NULL)
1723 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1724 (priv->video_output));
1726 gst_element_set_state (output, GST_STATE_NULL);
1727 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1729 gst_bin_remove (GST_BIN (priv->pipeline), output);
1730 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1731 priv->funnel = NULL;
1734 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
1736 if (priv->liveadder != NULL)
1738 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1739 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
1741 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1742 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
1743 priv->liveadder = NULL;
1748 /* Called with global lock held */
1750 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1752 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1756 if (priv->funnel == NULL)
1758 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1759 (priv->video_output));
1761 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1765 g_warning ("Could not create fsfunnel");
1769 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1771 gst_object_unref (priv->funnel);
1772 priv->funnel = NULL;
1773 g_warning ("Could not add funnel to pipeline");
1777 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1779 g_warning ("Could not add the video output widget to the pipeline");
1783 if (!gst_element_link (priv->funnel, output))
1785 g_warning ("Could not link output sink to funnel");
1786 goto error_output_added;
1789 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1791 g_warning ("Could not start video sink");
1792 goto error_output_added;
1795 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1797 g_warning ("Could not start funnel");
1798 goto error_output_added;
1802 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1805 g_warning ("Could not get request pad from funnel");
1812 gst_element_set_locked_state (priv->funnel, TRUE);
1813 gst_element_set_locked_state (output, TRUE);
1815 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1816 gst_element_set_state (output, GST_STATE_NULL);
1818 gst_bin_remove (GST_BIN (priv->pipeline), output);
1819 gst_element_set_locked_state (output, FALSE);
1823 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1824 priv->funnel = NULL;
1829 /* Called with global lock held */
1831 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1833 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1836 GError *gerror = NULL;
1838 if (priv->liveadder == NULL)
1840 priv->liveadder = gst_element_factory_make ("liveadder", NULL);
1842 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->liveadder))
1844 g_warning ("Could not add liveadder to the pipeline");
1845 goto error_add_liveadder;
1847 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1849 g_warning ("Could not add audio sink to pipeline");
1850 goto error_add_output;
1853 if (gst_element_set_state (priv->liveadder, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1855 g_warning ("Could not start liveadder");
1859 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1861 g_warning ("Could not start audio sink");
1865 if (GST_PAD_LINK_FAILED (
1866 gst_element_link (priv->liveadder, priv->audio_output)))
1868 g_warning ("Could not link liveadder to audio output");
1873 filter = gst_parse_bin_from_description (
1874 "audioconvert ! audioresample ! audioconvert", TRUE, &gerror);
1877 g_warning ("Could not make audio conversion filter: %s", gerror->message);
1878 g_clear_error (&gerror);
1882 if (!gst_bin_add (GST_BIN (priv->pipeline), filter))
1884 g_warning ("Could not add audio conversion filter to pipeline");
1885 gst_object_unref (filter);
1889 if (gst_element_set_state (filter, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1891 g_warning ("Could not start audio conversion filter");
1895 if (!gst_element_link (filter, priv->liveadder))
1897 g_warning ("Could not link audio conversion filter to liveadder");
1901 pad = gst_element_get_static_pad (filter, "sink");
1905 g_warning ("Could not get sink pad from filter");
1913 gst_element_set_locked_state (filter, TRUE);
1914 gst_element_set_state (filter, GST_STATE_NULL);
1915 gst_bin_remove (GST_BIN (priv->pipeline), filter);
1919 gst_element_set_locked_state (priv->liveadder, TRUE);
1920 gst_element_set_locked_state (priv->audio_output, TRUE);
1922 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
1923 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1925 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1929 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
1931 gst_element_set_locked_state (priv->liveadder, FALSE);
1932 gst_element_set_locked_state (priv->audio_output, FALSE);
1934 error_add_liveadder:
1936 if (priv->liveadder != NULL)
1938 gst_object_unref (priv->liveadder);
1939 priv->liveadder = NULL;
1946 empathy_call_window_update_timer (gpointer user_data)
1948 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1949 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1953 time_ = g_timer_elapsed (priv->timer, NULL);
1955 /* Translators: number of minutes:seconds the caller has been connected */
1956 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
1958 empathy_call_window_status_message (self, str);
1965 display_error (EmpathyCallWindow *self,
1966 EmpathyTpCall *call,
1970 const gchar *details)
1972 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1973 GtkWidget *info_bar;
1974 GtkWidget *content_area;
1981 /* Create info bar */
1982 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1985 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
1987 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
1989 /* hbox containing the image and the messages vbox */
1990 hbox = gtk_hbox_new (FALSE, 3);
1991 gtk_container_add (GTK_CONTAINER (content_area), hbox);
1994 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
1995 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1997 /* vbox containing the main message and the details expander */
1998 vbox = gtk_vbox_new (FALSE, 3);
1999 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2002 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2004 label = gtk_label_new (NULL);
2005 gtk_label_set_markup (GTK_LABEL (label), txt);
2006 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2007 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2010 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2013 if (details != NULL)
2015 GtkWidget *expander;
2017 expander = gtk_expander_new (_("Technical Details"));
2019 txt = g_strdup_printf ("<i>%s</i>", details);
2021 label = gtk_label_new (NULL);
2022 gtk_label_set_markup (GTK_LABEL (label), txt);
2023 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2024 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2027 gtk_container_add (GTK_CONTAINER (expander), label);
2028 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2031 g_signal_connect (info_bar, "response",
2032 G_CALLBACK (gtk_widget_destroy), NULL);
2034 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2035 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2036 gtk_widget_show_all (info_bar);
2040 media_stream_error_to_txt (EmpathyCallWindow *self,
2041 EmpathyTpCall *call,
2043 TpMediaStreamError error)
2045 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2052 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2054 return g_strdup_printf (
2055 _("%s's software does not understand any of the audio formats "
2056 "supported by your computer"),
2057 empathy_contact_get_name (priv->contact));
2059 return g_strdup_printf (
2060 _("%s's software does not understand any of the video formats "
2061 "supported by your computer"),
2062 empathy_contact_get_name (priv->contact));
2064 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2065 return g_strdup_printf (
2066 _("Can't establish a connection to %s. "
2067 "One of you might be on a network that does not allow "
2068 "direct connections."),
2069 empathy_contact_get_name (priv->contact));
2071 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2072 return g_strdup (_("There was a failure on the network"));
2074 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2076 return g_strdup (_("The audio formats necessary for this call "
2077 "are not installed on your computer"));
2079 return g_strdup (_("The video formats necessary for this call "
2080 "are not installed on your computer"));
2082 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2083 cm = empathy_tp_call_get_connection_manager (call);
2085 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2086 "product=Telepathy&component=%s", cm);
2088 result = g_strdup_printf (
2089 _("Something unexpected happened in a Telepathy component. "
2090 "Please <a href=\"%s\">report this bug</a> and attach "
2091 "logs gathered from the 'Debug' window in the Help menu."), url);
2096 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2097 return g_strdup (_("There was a failure in the call engine"));
2105 empathy_call_window_stream_error (EmpathyCallWindow *self,
2106 EmpathyTpCall *call,
2115 desc = media_stream_error_to_txt (self, call, audio, code);
2118 /* No description, use the error message. That's not great as it's not
2119 * localized but it's better than nothing. */
2120 display_error (self, call, icon, title, msg, NULL);
2124 display_error (self, call, icon, title, desc, msg);
2130 empathy_call_window_audio_stream_error (EmpathyTpCall *call,
2133 EmpathyCallWindow *self)
2135 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2136 "gnome-stock-mic", _("Can't establish audio stream"));
2140 empathy_call_window_video_stream_error (EmpathyTpCall *call,
2143 EmpathyCallWindow *self)
2145 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2146 "camera-web", _("Can't establish video stream"));
2150 empathy_call_window_connected (gpointer user_data)
2152 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2153 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2154 EmpathyTpCall *call;
2155 gboolean can_send_video;
2157 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
2159 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2160 empathy_contact_can_voip_video (priv->contact);
2162 g_object_get (priv->handler, "tp-call", &call, NULL);
2164 tp_g_signal_connect_object (call, "notify::video-stream",
2165 G_CALLBACK (empathy_call_window_video_stream_changed_cb),
2168 if (empathy_tp_call_has_dtmf (call))
2169 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2171 if (priv->video_input == NULL)
2172 empathy_call_window_set_send_video (self, FALSE);
2174 priv->sending_video = can_send_video ?
2175 empathy_tp_call_is_sending_video (call) : FALSE;
2177 gtk_toggle_tool_button_set_active (
2178 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2179 priv->sending_video && priv->video_input != NULL);
2180 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2182 gtk_action_set_sensitive (priv->redial, FALSE);
2183 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2185 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2187 empathy_call_window_update_avatars_visibility (call, self);
2189 g_object_unref (call);
2191 g_mutex_lock (priv->lock);
2193 priv->timer_id = g_timeout_add_seconds (1,
2194 empathy_call_window_update_timer, self);
2196 g_mutex_unlock (priv->lock);
2198 empathy_call_window_update_timer (self);
2204 /* Called from the streaming thread */
2206 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2207 GstPad *src, guint media_type, gpointer user_data)
2209 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2210 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2211 gboolean retval = FALSE;
2215 g_mutex_lock (priv->lock);
2217 if (priv->call_state != CONNECTED)
2219 g_timer_start (priv->timer);
2220 priv->timer_id = g_idle_add (empathy_call_window_connected, self);
2221 priv->call_state = CONNECTED;
2226 case TP_MEDIA_STREAM_TYPE_AUDIO:
2227 pad = empathy_call_window_get_audio_sink_pad (self);
2229 case TP_MEDIA_STREAM_TYPE_VIDEO:
2230 gtk_widget_hide (priv->remote_user_avatar_widget);
2231 gtk_widget_show (priv->video_output);
2232 pad = empathy_call_window_get_video_sink_pad (self);
2235 g_assert_not_reached ();
2241 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2242 g_warning ("Could not link %s sink pad",
2243 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2247 gst_object_unref (pad);
2251 /* If no sink could be linked, try to add fakesink to prevent the whole call
2256 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2258 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2260 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2261 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2262 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2264 gst_element_set_locked_state (fakesink, TRUE);
2265 gst_element_set_state (fakesink, GST_STATE_NULL);
2266 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2270 g_debug ("Could not link real sink, linked fakesink instead");
2272 gst_object_unref (sinkpad);
2276 gst_object_unref (fakesink);
2281 g_mutex_unlock (priv->lock);
2287 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2288 GstPad *sink, guint media_type, gpointer user_data)
2290 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2291 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2293 gboolean retval = FALSE;
2297 case TP_MEDIA_STREAM_TYPE_AUDIO:
2298 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2300 g_warning ("Could not add audio source to pipeline");
2304 pad = gst_element_get_static_pad (priv->audio_input, "src");
2307 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2308 g_warning ("Could not get source pad from audio source");
2312 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2314 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2315 g_warning ("Could not link audio source to farsight");
2319 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2321 g_warning ("Could not start audio source");
2322 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2323 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2329 case TP_MEDIA_STREAM_TYPE_VIDEO:
2330 if (priv->video_input != NULL)
2332 if (priv->video_tee != NULL)
2334 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2335 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2337 g_warning ("Could not link videp soure input pipeline");
2340 gst_object_unref (pad);
2347 g_assert_not_reached ();
2354 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2356 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2357 GstElement *preview;
2359 DEBUG ("remove video input");
2360 preview = empathy_video_widget_get_element (
2361 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2363 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2364 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2365 gst_element_set_state (preview, GST_STATE_NULL);
2367 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2368 priv->video_tee, preview, NULL);
2370 g_object_unref (priv->video_input);
2371 priv->video_input = NULL;
2372 g_object_unref (priv->video_tee);
2373 priv->video_tee = NULL;
2374 gtk_widget_destroy (priv->video_preview);
2375 priv->video_preview = NULL;
2377 gtk_toggle_tool_button_set_active (
2378 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), FALSE);
2379 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2381 gtk_widget_show (priv->self_user_avatar_widget);
2385 start_call (EmpathyCallWindow *self)
2387 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2389 priv->call_started = TRUE;
2390 empathy_call_handler_start_call (priv->handler,
2391 gtk_get_current_event_time ());
2393 if (empathy_call_handler_has_initial_video (priv->handler))
2395 /* Enable 'send video' buttons and display the preview */
2396 gtk_toggle_tool_button_set_active (
2397 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2402 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2405 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2406 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2409 empathy_call_handler_bus_message (priv->handler, bus, message);
2411 switch (GST_MESSAGE_TYPE (message))
2413 case GST_MESSAGE_STATE_CHANGED:
2414 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2416 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2417 if (newstate == GST_STATE_PAUSED)
2418 empathy_call_window_setup_video_input (self);
2420 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2421 !priv->call_started)
2423 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2424 if (newstate == GST_STATE_PAUSED)
2426 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2427 priv->pipeline_playing = TRUE;
2429 if (priv->start_call_when_playing)
2434 case GST_MESSAGE_ERROR:
2436 GError *error = NULL;
2437 GstElement *gst_error;
2440 gst_message_parse_error (message, &error, &debug);
2441 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2443 g_message ("Element error: %s -- %s\n", error->message, debug);
2445 if (g_str_has_prefix (gst_element_get_name (gst_error),
2446 VIDEO_INPUT_ERROR_PREFIX))
2448 /* Remove the video input and continue */
2449 if (priv->video_input != NULL)
2450 empathy_call_window_remove_video_input (self);
2451 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2455 empathy_call_window_disconnected (self, TRUE);
2457 g_error_free (error);
2468 empathy_call_window_update_avatars_visibility (EmpathyTpCall *call,
2469 EmpathyCallWindow *window)
2471 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2473 if (empathy_tp_call_is_receiving_video (call))
2475 gtk_widget_hide (priv->remote_user_avatar_widget);
2476 gtk_widget_show (priv->video_output);
2480 gtk_widget_hide (priv->video_output);
2481 gtk_widget_show (priv->remote_user_avatar_widget);
2486 call_handler_notify_tp_call_cb (EmpathyCallHandler *handler,
2488 EmpathyCallWindow *self)
2490 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2491 EmpathyTpCall *call;
2493 g_object_get (priv->handler, "tp-call", &call, NULL);
2497 tp_g_signal_connect_object (call, "audio-stream-error",
2498 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2499 tp_g_signal_connect_object (call, "video-stream-error",
2500 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2502 g_object_unref (call);
2506 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2508 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2509 EmpathyTpCall *call;
2511 g_signal_connect (priv->handler, "conference-added",
2512 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2513 g_signal_connect (priv->handler, "request-resource",
2514 G_CALLBACK (empathy_call_window_request_resource_cb), window);
2515 g_signal_connect (priv->handler, "closed",
2516 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2517 g_signal_connect (priv->handler, "src-pad-added",
2518 G_CALLBACK (empathy_call_window_src_added_cb), window);
2519 g_signal_connect (priv->handler, "sink-pad-added",
2520 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2521 g_signal_connect (priv->handler, "stream-closed",
2522 G_CALLBACK (empathy_call_window_channel_stream_closed_cb), window);
2524 g_object_get (priv->handler, "tp-call", &call, NULL);
2527 tp_g_signal_connect_object (call, "audio-stream-error",
2528 G_CALLBACK (empathy_call_window_audio_stream_error), window,
2530 tp_g_signal_connect_object (call, "video-stream-error",
2531 G_CALLBACK (empathy_call_window_video_stream_error), window,
2534 g_object_unref (call);
2538 /* tp-call doesn't exist yet, we'll connect signals once it has been
2540 g_signal_connect (priv->handler, "notify::tp-call",
2541 G_CALLBACK (call_handler_notify_tp_call_cb), window);
2544 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2548 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2549 EmpathyCallWindow *window)
2551 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2553 if (priv->pipeline != NULL)
2555 if (priv->bus_message_source_id != 0)
2557 g_source_remove (priv->bus_message_source_id);
2558 priv->bus_message_source_id = 0;
2561 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2564 if (priv->call_state == CONNECTING)
2565 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
2571 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2574 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2576 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2581 gtk_widget_hide (priv->sidebar);
2582 gtk_widget_hide (menu);
2583 gtk_widget_hide (priv->vbox);
2584 gtk_widget_hide (priv->statusbar);
2585 gtk_widget_hide (priv->toolbar);
2589 if (priv->sidebar_was_visible_before_fs)
2590 gtk_widget_show (priv->sidebar);
2592 gtk_widget_show (menu);
2593 gtk_widget_show (priv->vbox);
2594 gtk_widget_show (priv->statusbar);
2595 gtk_widget_show (priv->toolbar);
2597 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2598 priv->original_height_before_fs);
2603 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2605 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2607 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2608 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2609 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2610 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2611 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2612 priv->video_output, TRUE, TRUE,
2613 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2615 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2616 priv->vbox, TRUE, TRUE,
2617 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2622 empathy_call_window_state_event_cb (GtkWidget *widget,
2623 GdkEventWindowState *event, EmpathyCallWindow *window)
2625 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2627 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2628 gboolean set_fullscreen = event->new_window_state &
2629 GDK_WINDOW_STATE_FULLSCREEN;
2633 gboolean sidebar_was_visible;
2634 GtkAllocation allocation;
2635 gint original_width, original_height;
2637 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2638 original_width = allocation.width;
2639 original_height = allocation.height;
2641 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2643 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2644 priv->original_width_before_fs = original_width;
2645 priv->original_height_before_fs = original_height;
2647 if (priv->video_output_motion_handler_id == 0 &&
2648 priv->video_output != NULL)
2650 priv->video_output_motion_handler_id = g_signal_connect (
2651 G_OBJECT (priv->video_output), "motion-notify-event",
2652 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2658 if (priv->video_output_motion_handler_id != 0)
2660 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
2661 priv->video_output_motion_handler_id);
2662 priv->video_output_motion_handler_id = 0;
2666 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2668 show_controls (window, set_fullscreen);
2669 show_borders (window, set_fullscreen);
2670 gtk_action_set_stock_id (priv->menu_fullscreen,
2671 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2672 priv->is_fullscreen = set_fullscreen;
2679 empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
2680 EmpathyCallWindow *window)
2682 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2684 int w, h, handle_size;
2685 GtkAllocation allocation, sidebar_allocation;
2687 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2688 w = allocation.width;
2689 h = allocation.height;
2691 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2693 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
2694 if (gtk_toggle_button_get_active (toggle))
2696 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
2697 gtk_widget_show (priv->sidebar);
2698 w += sidebar_allocation.width + handle_size;
2702 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2703 w -= sidebar_allocation.width + handle_size;
2704 gtk_widget_hide (priv->sidebar);
2707 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
2710 gtk_window_resize (GTK_WINDOW (window), w, h);
2714 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2717 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2718 EmpathyTpCall *call;
2720 priv->sending_video = send;
2722 /* When we start sending video, we want to show the video preview by
2724 display_video_preview (window, send);
2726 if (priv->call_state != CONNECTED)
2729 g_object_get (priv->handler, "tp-call", &call, NULL);
2730 DEBUG ("%s sending video", send ? "start": "stop");
2731 empathy_tp_call_request_video_stream_direction (call, send);
2732 g_object_unref (call);
2736 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2737 EmpathyCallWindow *window)
2739 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2742 active = (gtk_toggle_tool_button_get_active (toggle));
2746 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2748 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
2752 /* TODO, Instead of setting the input volume to 0 we should probably
2753 * stop sending but this would cause the audio call to drop if both
2754 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2755 * in the future. GNOME #574574
2757 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2759 gtk_adjustment_set_value (priv->audio_input_adj, 0);
2764 empathy_call_window_sidebar_hidden_cb (EmpathySidebar *sidebar,
2765 EmpathyCallWindow *window)
2767 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2769 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2774 empathy_call_window_sidebar_shown_cb (EmpathySidebar *sidebar,
2775 EmpathyCallWindow *window)
2777 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2779 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2784 empathy_call_window_hangup_cb (gpointer object,
2785 EmpathyCallWindow *window)
2787 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2789 empathy_call_handler_stop_call (priv->handler);
2791 if (empathy_call_window_disconnected (window, FALSE))
2792 gtk_widget_destroy (GTK_WIDGET (window));
2796 empathy_call_window_restart_call (EmpathyCallWindow *window)
2798 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2800 create_video_output_widget (window);
2802 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
2803 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
2805 /* While the call was disconnected, the input volume might have changed.
2806 * However, since the audio_input source was destroyed, its volume has not
2807 * been updated during that time. That's why we manually update it here */
2808 empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
2810 priv->outgoing = TRUE;
2811 empathy_call_window_set_state_connecting (window);
2813 if (priv->pipeline_playing)
2814 start_call (window);
2816 /* call will be started when the pipeline is ready */
2817 priv->start_call_when_playing = TRUE;
2820 empathy_call_window_setup_avatars (window, priv->handler);
2822 gtk_action_set_sensitive (priv->redial, FALSE);
2823 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2827 empathy_call_window_redial_cb (gpointer object,
2828 EmpathyCallWindow *window)
2830 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2832 if (priv->call_state == CONNECTED)
2833 priv->call_state = REDIALING;
2835 empathy_call_handler_stop_call (priv->handler);
2837 if (priv->call_state != CONNECTED)
2838 empathy_call_window_restart_call (window);
2842 empathy_call_window_fullscreen_cb (gpointer object,
2843 EmpathyCallWindow *window)
2845 empathy_call_window_fullscreen_toggle (window);
2849 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2851 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2853 if (priv->is_fullscreen)
2854 gtk_window_unfullscreen (GTK_WINDOW (window));
2856 gtk_window_fullscreen (GTK_WINDOW (window));
2860 empathy_call_window_video_button_press_cb (GtkWidget *video_output,
2861 GdkEventButton *event, EmpathyCallWindow *window)
2863 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2865 empathy_call_window_video_menu_popup (window, event->button);
2873 empathy_call_window_key_press_cb (GtkWidget *video_output,
2874 GdkEventKey *event, EmpathyCallWindow *window)
2876 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2878 if (priv->is_fullscreen && event->keyval == GDK_Escape)
2880 /* Since we are in fullscreen mode, toggling will bring us back to
2882 empathy_call_window_fullscreen_toggle (window);
2890 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
2891 GdkEventMotion *event, EmpathyCallWindow *window)
2893 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2895 if (priv->is_fullscreen)
2897 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
2904 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
2908 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2910 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2912 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
2913 button, gtk_get_current_event_time ());
2914 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
2918 empathy_call_window_status_message (EmpathyCallWindow *window,
2921 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2923 if (priv->context_id == 0)
2925 priv->context_id = gtk_statusbar_get_context_id (
2926 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
2930 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
2933 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
2938 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
2939 gdouble value, EmpathyCallWindow *window)
2941 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2943 if (priv->audio_output == NULL)
2946 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
2950 /* block all the signals related to camera control widgets. This is useful
2951 * when we are manually updating the UI and so don't want to fire the
2954 block_camera_control_signals (EmpathyCallWindow *self)
2956 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2958 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
2959 tool_button_camera_off_toggled_cb, self);
2960 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
2961 tool_button_camera_preview_toggled_cb, self);
2962 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
2963 tool_button_camera_on_toggled_cb, self);
2964 g_signal_handlers_block_by_func (priv->action_camera,
2965 action_camera_change_cb, self);
2969 unblock_camera_control_signals (EmpathyCallWindow *self)
2971 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2973 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
2974 tool_button_camera_off_toggled_cb, self);
2975 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
2976 tool_button_camera_preview_toggled_cb, self);
2977 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
2978 tool_button_camera_on_toggled_cb, self);
2979 g_signal_handlers_unblock_by_func (priv->action_camera,
2980 action_camera_change_cb, self);