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>
49 #include <libempathy-gtk/empathy-images.h>
51 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
52 #include <libempathy/empathy-debug.h>
54 #include "empathy-call-window.h"
55 #include "empathy-call-window-fullscreen.h"
56 #include "empathy-sidebar.h"
58 #define BUTTON_ID "empathy-call-dtmf-button-id"
60 #define CONTENT_HBOX_BORDER_WIDTH 6
61 #define CONTENT_HBOX_SPACING 3
62 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
64 #define SELF_VIDEO_SECTION_WIDTH 160
65 #define SELF_VIDEO_SECTION_HEIGTH 120
67 /* The avatar's default width and height are set to the same value because we
68 want a square icon. */
69 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
70 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
71 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
73 /* If an video input error occurs, the error message will start with "v4l" */
74 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
76 /* The time interval in milliseconds between 2 outgoing rings */
77 #define MS_BETWEEN_RING 500
79 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
88 static guint signals[LAST_SIGNAL] = {0};
92 PROP_CALL_HANDLER = 1,
103 CAMERA_STATE_OFF = 0,
104 CAMERA_STATE_PREVIEW,
108 /* private structure */
109 typedef struct _EmpathyCallWindowPriv EmpathyCallWindowPriv;
111 struct _EmpathyCallWindowPriv
113 gboolean dispose_has_run;
114 EmpathyCallHandler *handler;
115 EmpathyContact *contact;
120 GtkUIManager *ui_manager;
121 GtkWidget *errors_vbox;
122 /* widget displays the video received from the remote user. This widget is
123 * alive only during call. */
124 GtkWidget *video_output;
125 GtkWidget *video_preview;
126 GtkWidget *remote_user_avatar_widget;
127 GtkWidget *self_user_avatar_widget;
129 GtkWidget *sidebar_button;
130 GtkWidget *statusbar;
131 GtkWidget *volume_button;
132 GtkWidget *redial_button;
133 GtkWidget *mic_button;
137 GtkAction *menu_fullscreen;
138 GtkAction *action_camera;
139 GtkAction *action_camera_preview;
140 GtkWidget *tool_button_camera_off;
141 GtkWidget *tool_button_camera_preview;
142 GtkWidget *tool_button_camera_on;
144 /* The frames and boxes that contain self and remote avatar and video
145 input/output. When we redial, we destroy and re-create the boxes */
146 GtkWidget *remote_user_output_frame;
147 GtkWidget *self_user_output_frame;
148 GtkWidget *remote_user_output_hbox;
149 GtkWidget *self_user_output_hbox;
151 /* We keep a reference on the hbox which contains the main content so we can
152 easilly repack everything when toggling fullscreen */
153 GtkWidget *content_hbox;
155 /* This vbox is contained in the content_hbox and it contains the
156 self_user_output_frame and the sidebar button. When toggling fullscreen,
157 it needs to be repacked. We keep a reference on it for easier access. */
160 gulong video_output_motion_handler_id;
161 guint bus_message_source_id;
164 GtkWidget *volume_scale;
165 GtkWidget *volume_progress_bar;
166 GtkAdjustment *audio_input_adj;
168 GtkWidget *dtmf_panel;
170 GstElement *video_input;
171 GstElement *audio_input;
172 GstElement *audio_output;
173 GstElement *pipeline;
174 GstElement *video_tee;
177 GstElement *liveadder;
179 FsElementAddedNotifier *fsnotifier;
186 GtkWidget *video_contrast;
187 GtkWidget *video_brightness;
188 GtkWidget *video_gamma;
191 gboolean call_started;
192 gboolean sending_video;
193 CameraState camera_state;
195 EmpathyCallWindowFullscreen *fullscreen;
196 gboolean is_fullscreen;
198 /* Those fields represent the state of the window before it actually was in
200 gboolean sidebar_was_visible_before_fs;
201 gint original_width_before_fs;
202 gint original_height_before_fs;
204 /* TRUE if the call should be started when the pipeline is playing */
205 gboolean start_call_when_playing;
206 /* TRUE if we requested to set the pipeline in the playing state */
207 gboolean pipeline_playing;
210 #define GET_PRIV(o) \
211 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CALL_WINDOW, \
212 EmpathyCallWindowPriv))
214 static void empathy_call_window_realized_cb (GtkWidget *widget,
215 EmpathyCallWindow *window);
217 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
218 GdkEvent *event, EmpathyCallWindow *window);
220 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
221 GdkEventWindowState *event, EmpathyCallWindow *window);
223 static void empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
224 EmpathyCallWindow *window);
226 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
229 static void empathy_call_window_mic_toggled_cb (
230 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
232 static void empathy_call_window_sidebar_hidden_cb (EmpathySidebar *sidebar,
233 EmpathyCallWindow *window);
235 static void empathy_call_window_sidebar_shown_cb (EmpathySidebar *sidebar,
236 EmpathyCallWindow *window);
238 static void empathy_call_window_hangup_cb (gpointer object,
239 EmpathyCallWindow *window);
241 static void empathy_call_window_fullscreen_cb (gpointer object,
242 EmpathyCallWindow *window);
244 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
246 static gboolean empathy_call_window_video_button_press_cb (
247 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
249 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
250 GdkEventKey *event, EmpathyCallWindow *window);
252 static gboolean empathy_call_window_video_output_motion_notify (
253 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
255 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
258 static void empathy_call_window_redial_cb (gpointer object,
259 EmpathyCallWindow *window);
261 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
263 static void empathy_call_window_status_message (EmpathyCallWindow *window,
266 static void empathy_call_window_update_avatars_visibility (EmpathyTpCall *call,
267 EmpathyCallWindow *window);
269 static gboolean empathy_call_window_bus_message (GstBus *bus,
270 GstMessage *message, gpointer user_data);
273 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
274 gdouble value, EmpathyCallWindow *window);
276 static void block_camera_control_signals (EmpathyCallWindow *self);
277 static void unblock_camera_control_signals (EmpathyCallWindow *self);
280 empathy_call_window_setup_toolbar (EmpathyCallWindow *self)
282 EmpathyCallWindowPriv *priv = GET_PRIV (self);
283 GtkToolItem *tool_item;
284 GtkWidget *camera_off_icon;
285 GdkPixbuf *pixbuf, *modded_pixbuf;
287 /* set the icon of the 'camera off' button by greying off the webcam icon */
288 pixbuf = empathy_pixbuf_from_icon_name ("camera-web",
289 GTK_ICON_SIZE_SMALL_TOOLBAR);
291 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
292 gdk_pixbuf_get_width (pixbuf),
293 gdk_pixbuf_get_height (pixbuf));
295 gdk_pixbuf_saturate_and_pixelate (pixbuf, modded_pixbuf, 1.0, TRUE);
296 g_object_unref (pixbuf);
298 camera_off_icon = gtk_image_new_from_pixbuf (modded_pixbuf);
299 g_object_unref (modded_pixbuf);
300 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (
301 priv->tool_button_camera_off), camera_off_icon);
303 /* Add an empty expanded GtkToolItem so the volume button is at the end of
305 tool_item = gtk_tool_item_new ();
306 gtk_tool_item_set_expand (tool_item, TRUE);
307 gtk_widget_show (GTK_WIDGET (tool_item));
308 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
310 priv->volume_button = gtk_volume_button_new ();
311 /* FIXME listen to the audiosinks signals and update the button according to
312 * that, for now starting out at 1.0 and assuming only the app changes the
314 gtk_scale_button_set_value (GTK_SCALE_BUTTON (priv->volume_button), 1.0);
315 g_signal_connect (G_OBJECT (priv->volume_button), "value-changed",
316 G_CALLBACK (empathy_call_window_volume_changed_cb), self);
318 tool_item = gtk_tool_item_new ();
319 gtk_container_add (GTK_CONTAINER (tool_item), priv->volume_button);
320 gtk_widget_show_all (GTK_WIDGET (tool_item));
321 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
325 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
327 EmpathyCallWindowPriv *priv = GET_PRIV (window);
332 g_object_get (priv->handler, "tp-call", &call, NULL);
334 button_quark = g_quark_from_static_string (BUTTON_ID);
335 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
338 empathy_tp_call_start_tone (call, event);
340 g_object_unref (call);
344 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
346 EmpathyCallWindowPriv *priv = GET_PRIV (window);
349 g_object_get (priv->handler, "tp-call", &call, NULL);
351 empathy_tp_call_stop_tone (call);
353 g_object_unref (call);
357 empathy_call_window_create_dtmf (EmpathyCallWindow *self)
365 } dtmfbuttons[] = { { "1", TP_DTMF_EVENT_DIGIT_1 },
366 { "2", TP_DTMF_EVENT_DIGIT_2 },
367 { "3", TP_DTMF_EVENT_DIGIT_3 },
368 { "4", TP_DTMF_EVENT_DIGIT_4 },
369 { "5", TP_DTMF_EVENT_DIGIT_5 },
370 { "6", TP_DTMF_EVENT_DIGIT_6 },
371 { "7", TP_DTMF_EVENT_DIGIT_7 },
372 { "8", TP_DTMF_EVENT_DIGIT_8 },
373 { "9", TP_DTMF_EVENT_DIGIT_9 },
374 { "#", TP_DTMF_EVENT_HASH },
375 { "0", TP_DTMF_EVENT_DIGIT_0 },
376 { "*", TP_DTMF_EVENT_ASTERISK },
379 button_quark = g_quark_from_static_string (BUTTON_ID);
381 table = gtk_table_new (4, 3, TRUE);
383 for (i = 0; dtmfbuttons[i].label != NULL; i++)
385 GtkWidget *button = gtk_button_new_with_label (dtmfbuttons[i].label);
386 gtk_table_attach (GTK_TABLE (table), button, i % 3, i % 3 + 1,
387 i/3, i/3 + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1);
389 g_object_set_qdata (G_OBJECT (button), button_quark,
390 GUINT_TO_POINTER (dtmfbuttons[i].event));
392 g_signal_connect (G_OBJECT (button), "pressed",
393 G_CALLBACK (dtmf_button_pressed_cb), self);
394 g_signal_connect (G_OBJECT (button), "released",
395 G_CALLBACK (dtmf_button_released_cb), self);
402 empathy_call_window_create_video_input_add_slider (EmpathyCallWindow *self,
403 gchar *label_text, GtkWidget *bin)
405 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
406 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
407 GtkWidget *label = gtk_label_new (label_text);
409 gtk_widget_set_sensitive (scale, FALSE);
411 gtk_container_add (GTK_CONTAINER (bin), vbox);
413 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
414 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
415 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
421 empathy_call_window_video_contrast_changed_cb (GtkAdjustment *adj,
422 EmpathyCallWindow *self)
425 EmpathyCallWindowPriv *priv = GET_PRIV (self);
427 empathy_video_src_set_channel (priv->video_input,
428 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
432 empathy_call_window_video_brightness_changed_cb (GtkAdjustment *adj,
433 EmpathyCallWindow *self)
436 EmpathyCallWindowPriv *priv = GET_PRIV (self);
438 empathy_video_src_set_channel (priv->video_input,
439 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
443 empathy_call_window_video_gamma_changed_cb (GtkAdjustment *adj,
444 EmpathyCallWindow *self)
447 EmpathyCallWindowPriv *priv = GET_PRIV (self);
449 empathy_video_src_set_channel (priv->video_input,
450 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
455 empathy_call_window_create_video_input (EmpathyCallWindow *self)
457 EmpathyCallWindowPriv *priv = GET_PRIV (self);
460 hbox = gtk_hbox_new (TRUE, 3);
462 priv->video_contrast = empathy_call_window_create_video_input_add_slider (
463 self, _("Contrast"), hbox);
465 priv->video_brightness = empathy_call_window_create_video_input_add_slider (
466 self, _("Brightness"), hbox);
468 priv->video_gamma = empathy_call_window_create_video_input_add_slider (
469 self, _("Gamma"), hbox);
475 empathy_call_window_setup_video_input (EmpathyCallWindow *self)
477 EmpathyCallWindowPriv *priv = GET_PRIV (self);
481 supported = empathy_video_src_get_supported_channels (priv->video_input);
483 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
485 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
487 gtk_adjustment_set_value (adj,
488 empathy_video_src_get_channel (priv->video_input,
489 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
491 g_signal_connect (G_OBJECT (adj), "value-changed",
492 G_CALLBACK (empathy_call_window_video_contrast_changed_cb), self);
494 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
497 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
499 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
501 gtk_adjustment_set_value (adj,
502 empathy_video_src_get_channel (priv->video_input,
503 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
505 g_signal_connect (G_OBJECT (adj), "value-changed",
506 G_CALLBACK (empathy_call_window_video_brightness_changed_cb), self);
507 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
510 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
512 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
514 gtk_adjustment_set_value (adj,
515 empathy_video_src_get_channel (priv->video_input,
516 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
518 g_signal_connect (G_OBJECT (adj), "value-changed",
519 G_CALLBACK (empathy_call_window_video_gamma_changed_cb), self);
520 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
525 empathy_call_window_mic_volume_changed_cb (GtkAdjustment *adj,
526 EmpathyCallWindow *self)
528 EmpathyCallWindowPriv *priv = GET_PRIV (self);
531 volume = gtk_adjustment_get_value (adj)/100.0;
533 /* Don't store the volume because of muting */
534 if (volume > 0 || gtk_toggle_tool_button_get_active (
535 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
536 priv->volume = volume;
538 /* Ensure that the toggle button is active if the volume is > 0 and inactive
539 * if it's smaller than 0 */
540 if ((volume > 0) != gtk_toggle_tool_button_get_active (
541 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
542 gtk_toggle_tool_button_set_active (
543 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
545 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
550 empathy_call_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
551 gdouble level, EmpathyCallWindow *window)
554 EmpathyCallWindowPriv *priv = GET_PRIV (window);
556 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
557 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
562 empathy_call_window_create_audio_input (EmpathyCallWindow *self)
564 EmpathyCallWindowPriv *priv = GET_PRIV (self);
565 GtkWidget *hbox, *vbox, *label;
567 hbox = gtk_hbox_new (TRUE, 3);
569 vbox = gtk_vbox_new (FALSE, 3);
570 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
572 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
573 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
574 label = gtk_label_new (_("Volume"));
576 priv->audio_input_adj = gtk_range_get_adjustment (
577 GTK_RANGE (priv->volume_scale));
578 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
579 (priv->audio_input));
580 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
582 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
583 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), self);
585 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
586 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
588 priv->volume_progress_bar = gtk_progress_bar_new ();
589 gtk_progress_bar_set_orientation (
590 GTK_PROGRESS_BAR (priv->volume_progress_bar),
591 GTK_PROGRESS_BOTTOM_TO_TOP);
592 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
595 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
602 create_video_output_widget (EmpathyCallWindow *self)
604 EmpathyCallWindowPriv *priv = GET_PRIV (self);
607 g_assert (priv->video_output == NULL);
608 g_assert (priv->pipeline != NULL);
610 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
611 priv->video_output = empathy_video_widget_new (bus);
613 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
614 priv->video_output, TRUE, TRUE, 0);
616 gtk_widget_add_events (priv->video_output,
617 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
618 g_signal_connect (G_OBJECT (priv->video_output), "button-press-event",
619 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
621 g_object_unref (bus);
625 create_audio_output (EmpathyCallWindow *self)
627 EmpathyCallWindowPriv *priv = GET_PRIV (self);
629 g_assert (priv->audio_output == NULL);
630 priv->audio_output = empathy_audio_sink_new ();
631 gst_object_ref (priv->audio_output);
632 gst_object_sink (priv->audio_output);
636 create_video_input (EmpathyCallWindow *self)
638 EmpathyCallWindowPriv *priv = GET_PRIV (self);
640 g_assert (priv->video_input == NULL);
641 priv->video_input = empathy_video_src_new ();
642 gst_object_ref (priv->video_input);
643 gst_object_sink (priv->video_input);
647 create_audio_input (EmpathyCallWindow *self)
649 EmpathyCallWindowPriv *priv = GET_PRIV (self);
651 g_assert (priv->audio_input == NULL);
652 priv->audio_input = empathy_audio_src_new ();
653 gst_object_ref (priv->audio_input);
654 gst_object_sink (priv->audio_input);
656 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
657 G_CALLBACK (empathy_call_window_audio_input_level_changed_cb),
662 add_video_preview_to_pipeline (EmpathyCallWindow *self)
664 EmpathyCallWindowPriv *priv = GET_PRIV (self);
667 g_assert (priv->video_preview != NULL);
668 g_assert (priv->pipeline != NULL);
669 g_assert (priv->video_input != NULL);
670 g_assert (priv->video_tee != NULL);
672 preview = empathy_video_widget_get_element (
673 EMPATHY_VIDEO_WIDGET (priv->video_preview));
675 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
677 g_warning ("Could not add video input to pipeline");
681 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee))
683 g_warning ("Could not add video tee to pipeline");
687 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
689 g_warning ("Could not add video preview to pipeline");
693 if (!gst_element_link (priv->video_input, priv->video_tee))
695 g_warning ("Could not link video input to video tee");
699 if (!gst_element_link (priv->video_tee, preview))
701 g_warning ("Could not link video tee to video preview");
707 create_video_preview (EmpathyCallWindow *self)
709 EmpathyCallWindowPriv *priv = GET_PRIV (self);
712 g_assert (priv->video_preview == NULL);
713 g_assert (priv->video_tee == NULL);
715 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
717 priv->video_preview = empathy_video_widget_new_with_size (bus,
718 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
719 g_object_set (priv->video_preview, "sync", FALSE, "async", TRUE, NULL);
721 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
722 priv->video_preview, TRUE, TRUE, 0);
724 priv->video_tee = gst_element_factory_make ("tee", NULL);
725 gst_object_ref (priv->video_tee);
726 gst_object_sink (priv->video_tee);
728 g_object_unref (bus);
732 play_camera (EmpathyCallWindow *window,
735 EmpathyCallWindowPriv *priv = GET_PRIV (window);
739 if (priv->video_preview == NULL)
741 create_video_preview (window);
742 add_video_preview_to_pipeline (window);
746 state = GST_STATE_PLAYING;
748 state = GST_STATE_NULL;
750 preview = empathy_video_widget_get_element (
751 EMPATHY_VIDEO_WIDGET (priv->video_preview));
753 gst_element_set_state (preview, state);
754 gst_element_set_state (priv->video_input, state);
755 gst_element_set_state (priv->video_tee, state);
759 display_video_preview (EmpathyCallWindow *self,
762 EmpathyCallWindowPriv *priv = GET_PRIV (self);
766 /* Display the preview and hide the self avatar */
767 DEBUG ("Show video preview");
769 play_camera (self, TRUE);
770 gtk_widget_show (priv->video_preview);
771 gtk_widget_hide (priv->self_user_avatar_widget);
775 /* Display the self avatar and hide the preview */
776 DEBUG ("Show self avatar");
778 if (priv->video_preview != NULL)
780 gtk_widget_hide (priv->video_preview);
781 play_camera (self, FALSE);
783 gtk_widget_show (priv->self_user_avatar_widget);
788 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
790 EmpathyCallWindowPriv *priv = GET_PRIV (window);
792 empathy_call_window_status_message (window, _("Connecting…"));
793 priv->call_state = CONNECTING;
796 empathy_sound_start_playing (GTK_WIDGET (window),
797 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
801 disable_camera (EmpathyCallWindow *self)
803 EmpathyCallWindowPriv *priv = GET_PRIV (self);
805 if (priv->camera_state == CAMERA_STATE_OFF)
808 DEBUG ("Disable camera");
810 display_video_preview (self, FALSE);
812 if (priv->camera_state == CAMERA_STATE_ON)
813 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
815 block_camera_control_signals (self);
816 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
817 priv->tool_button_camera_on), FALSE);
818 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
819 priv->tool_button_camera_preview), FALSE);
821 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
822 priv->tool_button_camera_off), TRUE);
823 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
825 unblock_camera_control_signals (self);
827 priv->camera_state = CAMERA_STATE_OFF;
831 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
832 EmpathyCallWindow *self)
834 EmpathyCallWindowPriv *priv = GET_PRIV (self);
836 if (!gtk_toggle_tool_button_get_active (toggle))
838 if (priv->camera_state == CAMERA_STATE_OFF)
840 /* We can't change the state by disabling the button */
841 block_camera_control_signals (self);
842 gtk_toggle_tool_button_set_active (toggle, TRUE);
843 unblock_camera_control_signals (self);
849 disable_camera (self);
853 enable_preview (EmpathyCallWindow *self)
855 EmpathyCallWindowPriv *priv = GET_PRIV (self);
857 if (priv->camera_state == CAMERA_STATE_PREVIEW)
860 DEBUG ("Enable preview");
862 if (priv->camera_state == CAMERA_STATE_ON)
864 /* preview is already displayed so we just have to stop sending */
865 empathy_call_window_set_send_video (self, CAMERA_STATE_PREVIEW);
869 display_video_preview (self, TRUE);
872 block_camera_control_signals (self);
873 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
874 priv->tool_button_camera_off), FALSE);
875 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
876 priv->tool_button_camera_on), FALSE);
878 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
879 priv->tool_button_camera_preview), TRUE);
880 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
881 CAMERA_STATE_PREVIEW);
882 unblock_camera_control_signals (self);
884 priv->camera_state = CAMERA_STATE_PREVIEW;
888 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
889 EmpathyCallWindow *self)
891 EmpathyCallWindowPriv *priv = GET_PRIV (self);
893 if (!gtk_toggle_tool_button_get_active (toggle))
895 if (priv->camera_state == CAMERA_STATE_PREVIEW)
897 /* We can't change the state by disabling the button */
898 block_camera_control_signals (self);
899 gtk_toggle_tool_button_set_active (toggle, TRUE);
900 unblock_camera_control_signals (self);
906 enable_preview (self);
910 enable_camera (EmpathyCallWindow *self)
912 EmpathyCallWindowPriv *priv = GET_PRIV (self);
914 if (priv->camera_state == CAMERA_STATE_ON)
917 if (priv->video_input == NULL)
919 DEBUG ("Can't enable camera, no input");
924 DEBUG ("Enable camera");
926 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
928 block_camera_control_signals (self);
929 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
930 priv->tool_button_camera_off), FALSE);
931 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
932 priv->tool_button_camera_preview), FALSE);
934 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
935 priv->tool_button_camera_on), TRUE);
936 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
938 unblock_camera_control_signals (self);
940 priv->camera_state = CAMERA_STATE_ON;
944 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
945 EmpathyCallWindow *self)
947 EmpathyCallWindowPriv *priv = GET_PRIV (self);
949 if (!gtk_toggle_tool_button_get_active (toggle))
951 if (priv->camera_state == CAMERA_STATE_ON)
953 /* We can't change the state by disabling the button */
954 block_camera_control_signals (self);
955 gtk_toggle_tool_button_set_active (toggle, TRUE);
956 unblock_camera_control_signals (self);
962 enable_camera (self);
966 action_camera_change_cb (GtkRadioAction *action,
967 GtkRadioAction *current,
968 EmpathyCallWindow *self)
972 state = gtk_radio_action_get_current_value (current);
976 case CAMERA_STATE_OFF:
977 disable_camera (self);
980 case CAMERA_STATE_PREVIEW:
981 enable_preview (self);
984 case CAMERA_STATE_ON:
985 enable_camera (self);
989 g_assert_not_reached ();
994 create_pipeline (EmpathyCallWindow *self)
996 EmpathyCallWindowPriv *priv = GET_PRIV (self);
999 g_assert (priv->pipeline == NULL);
1001 priv->pipeline = gst_pipeline_new (NULL);
1002 priv->pipeline_playing = FALSE;
1004 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1005 priv->bus_message_source_id = gst_bus_add_watch (bus,
1006 empathy_call_window_bus_message, self);
1008 g_object_unref (bus);
1013 empathy_call_window_init (EmpathyCallWindow *self)
1015 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1017 GtkWidget *top_vbox;
1023 GError *error = NULL;
1025 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1026 gui = empathy_builder_get_file (filename,
1027 "call_window_vbox", &top_vbox,
1028 "errors_vbox", &priv->errors_vbox,
1029 "pane", &priv->pane,
1030 "statusbar", &priv->statusbar,
1031 "redial", &priv->redial_button,
1032 "microphone", &priv->mic_button,
1033 "toolbar", &priv->toolbar,
1034 "menuredial", &priv->redial,
1035 "ui_manager", &priv->ui_manager,
1036 "menufullscreen", &priv->menu_fullscreen,
1037 "camera_off", &priv->tool_button_camera_off,
1038 "camera_preview", &priv->tool_button_camera_preview,
1039 "camera_on", &priv->tool_button_camera_on,
1040 "action_camera_off", &priv->action_camera,
1041 "action_camera_preview", &priv->action_camera_preview,
1045 empathy_builder_connect (gui, self,
1046 "menuhangup", "activate", empathy_call_window_hangup_cb,
1047 "hangup", "clicked", empathy_call_window_hangup_cb,
1048 "menuredial", "activate", empathy_call_window_redial_cb,
1049 "redial", "clicked", empathy_call_window_redial_cb,
1050 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1051 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1052 "camera_off", "toggled", tool_button_camera_off_toggled_cb,
1053 "camera_preview", "toggled", tool_button_camera_preview_toggled_cb,
1054 "camera_on", "toggled", tool_button_camera_on_toggled_cb,
1055 "action_camera_off", "changed", action_camera_change_cb,
1058 priv->lock = g_mutex_new ();
1060 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1062 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1063 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1064 CONTENT_HBOX_BORDER_WIDTH);
1065 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1067 /* remote user output frame */
1068 priv->remote_user_output_frame = gtk_frame_new (NULL);
1069 gtk_widget_set_size_request (priv->remote_user_output_frame,
1070 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1071 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1072 priv->remote_user_output_frame, TRUE, TRUE,
1073 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1075 priv->remote_user_output_hbox = gtk_hbox_new (FALSE, 0);
1077 priv->remote_user_avatar_widget = gtk_image_new ();
1079 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1080 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1082 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1083 priv->remote_user_output_hbox);
1085 /* self user output frame */
1086 priv->self_user_output_frame = gtk_frame_new (NULL);
1087 gtk_widget_set_size_request (priv->self_user_output_frame,
1088 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1090 priv->self_user_output_hbox = gtk_hbox_new (FALSE, 0);
1092 priv->self_user_avatar_widget = gtk_image_new ();
1093 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1094 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1096 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1097 priv->self_user_output_hbox);
1099 create_pipeline (self);
1100 create_video_output_widget (self);
1101 create_audio_input (self);
1102 create_audio_output (self);
1103 create_video_input (self);
1105 priv->fsnotifier = fs_element_added_notifier_new ();
1106 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1108 /* The call will be started as soon the pipeline is playing */
1109 priv->start_call_when_playing = TRUE;
1111 keyfile = g_key_file_new ();
1112 filename = empathy_file_lookup ("element-properties", "data");
1113 if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error))
1115 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1120 g_warning ("Could not load element-properties file: %s", error->message);
1121 g_key_file_free (keyfile);
1122 g_clear_error (&error);
1126 priv->vbox = gtk_vbox_new (FALSE, 3);
1127 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1128 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1129 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1132 empathy_call_window_setup_toolbar (self);
1134 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1135 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1136 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1137 G_CALLBACK (empathy_call_window_sidebar_toggled_cb), self);
1139 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1141 h = gtk_hbox_new (FALSE, 3);
1142 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1143 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1145 priv->sidebar = empathy_sidebar_new ();
1146 g_signal_connect (G_OBJECT (priv->sidebar),
1147 "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb), self);
1148 g_signal_connect (G_OBJECT (priv->sidebar),
1149 "show", G_CALLBACK (empathy_call_window_sidebar_shown_cb), self);
1150 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1152 page = empathy_call_window_create_audio_input (self);
1153 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Audio input"),
1156 page = empathy_call_window_create_video_input (self);
1157 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Video input"),
1160 priv->dtmf_panel = empathy_call_window_create_dtmf (self);
1161 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Dialpad"),
1164 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1167 gtk_widget_show_all (top_vbox);
1169 gtk_widget_hide (priv->sidebar);
1171 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1172 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1173 priv->video_output);
1174 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1175 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1177 g_signal_connect (G_OBJECT (self), "realize",
1178 G_CALLBACK (empathy_call_window_realized_cb), self);
1180 g_signal_connect (G_OBJECT (self), "delete-event",
1181 G_CALLBACK (empathy_call_window_delete_cb), self);
1183 g_signal_connect (G_OBJECT (self), "window-state-event",
1184 G_CALLBACK (empathy_call_window_state_event_cb), self);
1186 g_signal_connect (G_OBJECT (self), "key-press-event",
1187 G_CALLBACK (empathy_call_window_key_press_cb), self);
1189 priv->timer = g_timer_new ();
1191 g_object_ref (priv->ui_manager);
1192 g_object_unref (gui);
1194 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1197 /* Instead of specifying a width and a height, we specify only one size. That's
1198 because we want a square avatar icon. */
1200 init_contact_avatar_with_size (EmpathyContact *contact,
1201 GtkWidget *image_widget,
1204 GdkPixbuf *pixbuf_avatar = NULL;
1206 if (contact != NULL)
1208 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1212 if (pixbuf_avatar == NULL)
1214 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1215 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1218 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1220 if (pixbuf_avatar != NULL)
1221 g_object_unref (pixbuf_avatar);
1225 set_window_title (EmpathyCallWindow *self)
1227 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1230 /* translators: Call is a noun and %s is the contact name. This string
1231 * is used in the window title */
1232 tmp = g_strdup_printf (_("Call with %s"),
1233 empathy_contact_get_name (priv->contact));
1234 gtk_window_set_title (GTK_WINDOW (self), tmp);
1239 contact_name_changed_cb (EmpathyContact *contact,
1240 GParamSpec *pspec, EmpathyCallWindow *self)
1242 set_window_title (self);
1246 contact_avatar_changed_cb (EmpathyContact *contact,
1247 GParamSpec *pspec, GtkWidget *avatar_widget)
1251 size = avatar_widget->allocation.height;
1255 /* the widget is not allocated yet, set a default size */
1256 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1257 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1260 init_contact_avatar_with_size (contact, avatar_widget, size);
1264 empathy_call_window_got_self_contact_cb (TpConnection *connection,
1265 EmpathyContact *contact, const GError *error, gpointer user_data,
1266 GObject *weak_object)
1268 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1269 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1271 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1272 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1274 g_signal_connect (contact, "notify::avatar",
1275 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1279 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1280 EmpathyCallHandler *handler)
1282 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1284 g_object_get (handler, "contact", &(priv->contact), NULL);
1286 if (priv->contact != NULL)
1288 TpConnection *connection;
1290 set_window_title (self);
1292 g_signal_connect (priv->contact, "notify::name",
1293 G_CALLBACK (contact_name_changed_cb), self);
1294 g_signal_connect (priv->contact, "notify::avatar",
1295 G_CALLBACK (contact_avatar_changed_cb),
1296 priv->remote_user_avatar_widget);
1298 /* Retreiving the self avatar */
1299 connection = empathy_contact_get_connection (priv->contact);
1300 empathy_tp_contact_factory_get_from_handle (connection,
1301 tp_connection_get_self_handle (connection),
1302 empathy_call_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1306 g_warning ("call handler doesn't have a contact");
1307 /* translators: Call is a noun. This string is used in the window
1309 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1311 /* Since we can't access the remote contact, we can't get a connection
1312 to it and can't get the self contact (and its avatar). This means
1313 that we have to manually set the self avatar. */
1314 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1315 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1318 init_contact_avatar_with_size (priv->contact,
1319 priv->remote_user_avatar_widget,
1320 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1321 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1323 /* The remote avatar is shown by default and will be hidden when we receive
1324 video from the remote side. */
1325 gtk_widget_hide (priv->video_output);
1326 gtk_widget_show (priv->remote_user_avatar_widget);
1330 empathy_call_window_constructed (GObject *object)
1332 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1333 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1334 EmpathyTpCall *call;
1336 g_assert (priv->handler != NULL);
1338 g_object_get (priv->handler, "tp-call", &call, NULL);
1339 priv->outgoing = (call == NULL);
1341 g_object_unref (call);
1343 empathy_call_window_setup_avatars (self, priv->handler);
1344 empathy_call_window_set_state_connecting (self);
1346 if (!empathy_call_handler_has_initial_video (priv->handler))
1348 gtk_toggle_tool_button_set_active (
1349 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1351 /* If call has InitialVideo, the preview will be started once the call has
1352 * been started (start_call()). */
1355 static void empathy_call_window_dispose (GObject *object);
1356 static void empathy_call_window_finalize (GObject *object);
1359 empathy_call_window_set_property (GObject *object,
1360 guint property_id, const GValue *value, GParamSpec *pspec)
1362 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1364 switch (property_id)
1366 case PROP_CALL_HANDLER:
1367 priv->handler = g_value_dup_object (value);
1370 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1375 empathy_call_window_get_property (GObject *object,
1376 guint property_id, GValue *value, GParamSpec *pspec)
1378 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1380 switch (property_id)
1382 case PROP_CALL_HANDLER:
1383 g_value_set_object (value, priv->handler);
1386 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1391 empathy_call_window_class_init (
1392 EmpathyCallWindowClass *empathy_call_window_class)
1394 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1395 GParamSpec *param_spec;
1397 g_type_class_add_private (empathy_call_window_class,
1398 sizeof (EmpathyCallWindowPriv));
1400 object_class->constructed = empathy_call_window_constructed;
1401 object_class->set_property = empathy_call_window_set_property;
1402 object_class->get_property = empathy_call_window_get_property;
1404 object_class->dispose = empathy_call_window_dispose;
1405 object_class->finalize = empathy_call_window_finalize;
1407 param_spec = g_param_spec_object ("handler",
1408 "handler", "The call handler",
1409 EMPATHY_TYPE_CALL_HANDLER,
1410 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1411 g_object_class_install_property (object_class,
1412 PROP_CALL_HANDLER, param_spec);
1416 empathy_call_window_video_stream_changed_cb (EmpathyTpCall *call,
1417 GParamSpec *property, EmpathyCallWindow *self)
1419 DEBUG ("video stream changed");
1420 empathy_call_window_update_avatars_visibility (call, self);
1424 empathy_call_window_dispose (GObject *object)
1426 EmpathyTpCall *call;
1427 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1428 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1430 if (priv->dispose_has_run)
1433 priv->dispose_has_run = TRUE;
1435 g_object_get (priv->handler, "tp-call", &call, NULL);
1439 g_object_unref (call);
1442 if (priv->handler != NULL)
1444 empathy_call_handler_stop_call (priv->handler);
1445 g_object_unref (priv->handler);
1447 priv->handler = NULL;
1449 if (priv->bus_message_source_id != 0)
1451 g_source_remove (priv->bus_message_source_id);
1452 priv->bus_message_source_id = 0;
1455 if (priv->pipeline != NULL)
1456 g_object_unref (priv->pipeline);
1457 priv->pipeline = NULL;
1459 if (priv->video_input != NULL)
1460 g_object_unref (priv->video_input);
1461 priv->video_input = NULL;
1463 if (priv->audio_input != NULL)
1464 g_object_unref (priv->audio_input);
1465 priv->audio_input = NULL;
1467 if (priv->audio_output != NULL)
1468 g_object_unref (priv->audio_output);
1469 priv->audio_output = NULL;
1471 if (priv->video_tee != NULL)
1472 g_object_unref (priv->video_tee);
1473 priv->video_tee = NULL;
1475 if (priv->liveadder != NULL)
1476 gst_object_unref (priv->liveadder);
1477 priv->liveadder = NULL;
1479 if (priv->fsnotifier != NULL)
1480 g_object_unref (priv->fsnotifier);
1481 priv->fsnotifier = NULL;
1483 if (priv->timer_id != 0)
1484 g_source_remove (priv->timer_id);
1487 if (priv->ui_manager != NULL)
1488 g_object_unref (priv->ui_manager);
1489 priv->ui_manager = NULL;
1491 if (priv->fullscreen != NULL)
1492 g_object_unref (priv->fullscreen);
1493 priv->fullscreen = NULL;
1495 if (priv->contact != NULL)
1497 g_signal_handlers_disconnect_by_func (priv->contact,
1498 contact_name_changed_cb, self);
1499 g_object_unref (priv->contact);
1500 priv->contact = NULL;
1503 /* release any references held by the object here */
1504 if (G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose)
1505 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1509 empathy_call_window_finalize (GObject *object)
1511 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1512 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1514 if (priv->video_output_motion_handler_id != 0)
1516 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1517 priv->video_output_motion_handler_id);
1518 priv->video_output_motion_handler_id = 0;
1521 /* free any data held directly by the object here */
1522 g_mutex_free (priv->lock);
1524 g_timer_destroy (priv->timer);
1526 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1531 empathy_call_window_new (EmpathyCallHandler *handler)
1533 return EMPATHY_CALL_WINDOW (
1534 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1538 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1539 GstElement *conference, gpointer user_data)
1541 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1542 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1544 gst_bin_add (GST_BIN (priv->pipeline), conference);
1546 gst_element_set_state (conference, GST_STATE_PLAYING);
1550 empathy_call_window_request_resource_cb (EmpathyCallHandler *handler,
1551 FsMediaType type, FsStreamDirection direction, gpointer user_data)
1553 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1554 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1556 if (type != FS_MEDIA_TYPE_VIDEO)
1559 if (direction == FS_DIRECTION_RECV)
1562 /* video and direction is send */
1563 return priv->video_input != NULL;
1567 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1569 GstStateChangeReturn state_change_return;
1570 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1572 if (priv->pipeline == NULL)
1575 if (priv->bus_message_source_id != 0)
1577 g_source_remove (priv->bus_message_source_id);
1578 priv->bus_message_source_id = 0;
1581 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1583 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1584 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1586 if (priv->pipeline != NULL)
1587 g_object_unref (priv->pipeline);
1588 priv->pipeline = NULL;
1590 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1591 empathy_call_window_mic_volume_changed_cb, self);
1593 if (priv->video_tee != NULL)
1594 g_object_unref (priv->video_tee);
1595 priv->video_tee = NULL;
1597 if (priv->video_preview != NULL)
1598 gtk_widget_destroy (priv->video_preview);
1599 priv->video_preview = NULL;
1601 priv->liveadder = NULL;
1602 priv->funnel = NULL;
1604 create_pipeline (self);
1605 /* Call will be started when user will hit the 'redial' button */
1606 priv->start_call_when_playing = FALSE;
1607 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1613 g_message ("Error: could not destroy pipeline. Closing call window");
1614 gtk_widget_destroy (GTK_WIDGET (self));
1621 empathy_call_window_disconnected (EmpathyCallWindow *self,
1624 gboolean could_disconnect = FALSE;
1625 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1626 gboolean could_reset_pipeline;
1628 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1630 if (priv->call_state == CONNECTING)
1631 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
1633 if (priv->call_state != REDIALING)
1634 priv->call_state = DISCONNECTED;
1636 if (could_reset_pipeline)
1638 g_mutex_lock (priv->lock);
1640 g_timer_stop (priv->timer);
1642 if (priv->timer_id != 0)
1643 g_source_remove (priv->timer_id);
1646 g_mutex_unlock (priv->lock);
1649 /* We are about to destroy the window, no need to update it or create
1650 * a video preview */
1653 empathy_call_window_status_message (self, _("Disconnected"));
1655 gtk_action_set_sensitive (priv->redial, TRUE);
1656 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1658 /* Unsensitive the camera and mic button */
1659 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1660 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1662 /* Be sure that the mic button is enabled */
1663 gtk_toggle_tool_button_set_active (
1664 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1666 if (priv->camera_state == CAMERA_STATE_ON)
1668 /* Enable the 'preview' button as we are not sending atm. */
1669 gtk_toggle_tool_button_set_active (
1670 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_preview), TRUE);
1672 else if (priv->camera_state == CAMERA_STATE_PREVIEW)
1674 /* Restart the preview with the new pipeline. */
1675 display_video_preview (self, TRUE);
1678 gtk_progress_bar_set_fraction (
1679 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1681 /* destroy the video output; it will be recreated when we'll redial */
1682 gtk_widget_destroy (priv->video_output);
1683 priv->video_output = NULL;
1685 gtk_widget_show (priv->remote_user_avatar_widget);
1687 priv->sending_video = FALSE;
1688 priv->call_started = FALSE;
1690 could_disconnect = TRUE;
1692 /* TODO: display the self avatar of the preview (depends if the "Always
1693 * Show Video Preview" is enabled or not) */
1696 return could_disconnect;
1701 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1704 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1705 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1707 if (empathy_call_window_disconnected (self, TRUE) &&
1708 priv->call_state == REDIALING)
1709 empathy_call_window_restart_call (self);
1714 empathy_call_window_channel_stream_closed_cb (EmpathyCallHandler *handler,
1715 TfStream *stream, gpointer user_data)
1717 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1718 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1721 g_object_get (stream, "media-type", &media_type, NULL);
1724 * This assumes that there is only one video stream per channel...
1727 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
1729 if (priv->funnel != NULL)
1733 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1734 (priv->video_output));
1736 gst_element_set_state (output, GST_STATE_NULL);
1737 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1739 gst_bin_remove (GST_BIN (priv->pipeline), output);
1740 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1741 priv->funnel = NULL;
1744 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
1746 if (priv->liveadder != NULL)
1748 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1749 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
1751 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1752 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
1753 priv->liveadder = NULL;
1758 /* Called with global lock held */
1760 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1762 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1766 if (priv->funnel == NULL)
1768 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1769 (priv->video_output));
1771 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1775 g_warning ("Could not create fsfunnel");
1779 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1781 gst_object_unref (priv->funnel);
1782 priv->funnel = NULL;
1783 g_warning ("Could not add funnel to pipeline");
1787 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1789 g_warning ("Could not add the video output widget to the pipeline");
1793 if (!gst_element_link (priv->funnel, output))
1795 g_warning ("Could not link output sink to funnel");
1796 goto error_output_added;
1799 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1801 g_warning ("Could not start video sink");
1802 goto error_output_added;
1805 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1807 g_warning ("Could not start funnel");
1808 goto error_output_added;
1812 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1815 g_warning ("Could not get request pad from funnel");
1822 gst_element_set_locked_state (priv->funnel, TRUE);
1823 gst_element_set_locked_state (output, TRUE);
1825 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1826 gst_element_set_state (output, GST_STATE_NULL);
1828 gst_bin_remove (GST_BIN (priv->pipeline), output);
1829 gst_element_set_locked_state (output, FALSE);
1833 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1834 priv->funnel = NULL;
1839 /* Called with global lock held */
1841 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1843 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1846 GError *gerror = NULL;
1848 if (priv->liveadder == NULL)
1850 priv->liveadder = gst_element_factory_make ("liveadder", NULL);
1852 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->liveadder))
1854 g_warning ("Could not add liveadder to the pipeline");
1855 goto error_add_liveadder;
1857 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1859 g_warning ("Could not add audio sink to pipeline");
1860 goto error_add_output;
1863 if (gst_element_set_state (priv->liveadder, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1865 g_warning ("Could not start liveadder");
1869 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1871 g_warning ("Could not start audio sink");
1875 if (GST_PAD_LINK_FAILED (
1876 gst_element_link (priv->liveadder, priv->audio_output)))
1878 g_warning ("Could not link liveadder to audio output");
1883 filter = gst_parse_bin_from_description (
1884 "audioconvert ! audioresample ! audioconvert", TRUE, &gerror);
1887 g_warning ("Could not make audio conversion filter: %s", gerror->message);
1888 g_clear_error (&gerror);
1892 if (!gst_bin_add (GST_BIN (priv->pipeline), filter))
1894 g_warning ("Could not add audio conversion filter to pipeline");
1895 gst_object_unref (filter);
1899 if (gst_element_set_state (filter, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1901 g_warning ("Could not start audio conversion filter");
1905 if (!gst_element_link (filter, priv->liveadder))
1907 g_warning ("Could not link audio conversion filter to liveadder");
1911 pad = gst_element_get_static_pad (filter, "sink");
1915 g_warning ("Could not get sink pad from filter");
1923 gst_element_set_locked_state (filter, TRUE);
1924 gst_element_set_state (filter, GST_STATE_NULL);
1925 gst_bin_remove (GST_BIN (priv->pipeline), filter);
1929 gst_element_set_locked_state (priv->liveadder, TRUE);
1930 gst_element_set_locked_state (priv->audio_output, TRUE);
1932 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
1933 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1935 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1939 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
1941 gst_element_set_locked_state (priv->liveadder, FALSE);
1942 gst_element_set_locked_state (priv->audio_output, FALSE);
1944 error_add_liveadder:
1946 if (priv->liveadder != NULL)
1948 gst_object_unref (priv->liveadder);
1949 priv->liveadder = NULL;
1956 empathy_call_window_update_timer (gpointer user_data)
1958 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1959 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1963 time_ = g_timer_elapsed (priv->timer, NULL);
1965 /* Translators: number of minutes:seconds the caller has been connected */
1966 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
1968 empathy_call_window_status_message (self, str);
1975 display_error (EmpathyCallWindow *self,
1976 EmpathyTpCall *call,
1980 const gchar *details)
1982 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1983 GtkWidget *info_bar;
1984 GtkWidget *content_area;
1991 /* Create info bar */
1992 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1995 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
1997 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
1999 /* hbox containing the image and the messages vbox */
2000 hbox = gtk_hbox_new (FALSE, 3);
2001 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2004 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2005 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2007 /* vbox containing the main message and the details expander */
2008 vbox = gtk_vbox_new (FALSE, 3);
2009 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2012 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2014 label = gtk_label_new (NULL);
2015 gtk_label_set_markup (GTK_LABEL (label), txt);
2016 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2017 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2020 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2023 if (details != NULL)
2025 GtkWidget *expander;
2027 expander = gtk_expander_new (_("Technical Details"));
2029 txt = g_strdup_printf ("<i>%s</i>", details);
2031 label = gtk_label_new (NULL);
2032 gtk_label_set_markup (GTK_LABEL (label), txt);
2033 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2034 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2037 gtk_container_add (GTK_CONTAINER (expander), label);
2038 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2041 g_signal_connect (info_bar, "response",
2042 G_CALLBACK (gtk_widget_destroy), NULL);
2044 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2045 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2046 gtk_widget_show_all (info_bar);
2050 media_stream_error_to_txt (EmpathyCallWindow *self,
2051 EmpathyTpCall *call,
2053 TpMediaStreamError error)
2055 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2062 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2064 return g_strdup_printf (
2065 _("%s's software does not understand any of the audio formats "
2066 "supported by your computer"),
2067 empathy_contact_get_name (priv->contact));
2069 return g_strdup_printf (
2070 _("%s's software does not understand any of the video formats "
2071 "supported by your computer"),
2072 empathy_contact_get_name (priv->contact));
2074 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2075 return g_strdup_printf (
2076 _("Can't establish a connection to %s. "
2077 "One of you might be on a network that does not allow "
2078 "direct connections."),
2079 empathy_contact_get_name (priv->contact));
2081 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2082 return g_strdup (_("There was a failure on the network"));
2084 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2086 return g_strdup (_("The audio formats necessary for this call "
2087 "are not installed on your computer"));
2089 return g_strdup (_("The video formats necessary for this call "
2090 "are not installed on your computer"));
2092 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2093 cm = empathy_tp_call_get_connection_manager (call);
2095 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2096 "product=Telepathy&component=%s", cm);
2098 result = g_strdup_printf (
2099 _("Something unexpected happened in a Telepathy component. "
2100 "Please <a href=\"%s\">report this bug</a> and attach "
2101 "logs gathered from the 'Debug' window in the Help menu."), url);
2106 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2107 return g_strdup (_("There was a failure in the call engine"));
2115 empathy_call_window_stream_error (EmpathyCallWindow *self,
2116 EmpathyTpCall *call,
2125 desc = media_stream_error_to_txt (self, call, audio, code);
2128 /* No description, use the error message. That's not great as it's not
2129 * localized but it's better than nothing. */
2130 display_error (self, call, icon, title, msg, NULL);
2134 display_error (self, call, icon, title, desc, msg);
2140 empathy_call_window_audio_stream_error (EmpathyTpCall *call,
2143 EmpathyCallWindow *self)
2145 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2146 "gnome-stock-mic", _("Can't establish audio stream"));
2150 empathy_call_window_video_stream_error (EmpathyTpCall *call,
2153 EmpathyCallWindow *self)
2155 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2156 "camera-web", _("Can't establish video stream"));
2160 empathy_call_window_connected (gpointer user_data)
2162 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2163 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2164 EmpathyTpCall *call;
2165 gboolean can_send_video;
2167 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
2169 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2170 empathy_contact_can_voip_video (priv->contact);
2172 g_object_get (priv->handler, "tp-call", &call, NULL);
2174 tp_g_signal_connect_object (call, "notify::video-stream",
2175 G_CALLBACK (empathy_call_window_video_stream_changed_cb),
2178 if (empathy_tp_call_has_dtmf (call))
2179 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2181 if (priv->video_input == NULL)
2182 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2184 priv->sending_video = can_send_video ?
2185 empathy_tp_call_is_sending_video (call) : FALSE;
2187 gtk_toggle_tool_button_set_active (
2188 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2189 priv->sending_video && priv->video_input != NULL);
2190 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2192 gtk_action_set_sensitive (priv->redial, FALSE);
2193 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2195 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2197 empathy_call_window_update_avatars_visibility (call, self);
2199 g_object_unref (call);
2201 g_mutex_lock (priv->lock);
2203 priv->timer_id = g_timeout_add_seconds (1,
2204 empathy_call_window_update_timer, self);
2206 g_mutex_unlock (priv->lock);
2208 empathy_call_window_update_timer (self);
2214 /* Called from the streaming thread */
2216 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2217 GstPad *src, guint media_type, gpointer user_data)
2219 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2220 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2221 gboolean retval = FALSE;
2225 g_mutex_lock (priv->lock);
2227 if (priv->call_state != CONNECTED)
2229 g_timer_start (priv->timer);
2230 priv->timer_id = g_idle_add (empathy_call_window_connected, self);
2231 priv->call_state = CONNECTED;
2236 case TP_MEDIA_STREAM_TYPE_AUDIO:
2237 pad = empathy_call_window_get_audio_sink_pad (self);
2239 case TP_MEDIA_STREAM_TYPE_VIDEO:
2240 gtk_widget_hide (priv->remote_user_avatar_widget);
2241 gtk_widget_show (priv->video_output);
2242 pad = empathy_call_window_get_video_sink_pad (self);
2245 g_assert_not_reached ();
2251 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2252 g_warning ("Could not link %s sink pad",
2253 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2257 gst_object_unref (pad);
2261 /* If no sink could be linked, try to add fakesink to prevent the whole call
2266 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2268 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2270 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2271 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2272 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2274 gst_element_set_locked_state (fakesink, TRUE);
2275 gst_element_set_state (fakesink, GST_STATE_NULL);
2276 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2280 g_debug ("Could not link real sink, linked fakesink instead");
2282 gst_object_unref (sinkpad);
2286 gst_object_unref (fakesink);
2291 g_mutex_unlock (priv->lock);
2297 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2298 GstPad *sink, guint media_type, gpointer user_data)
2300 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2301 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2303 gboolean retval = FALSE;
2307 case TP_MEDIA_STREAM_TYPE_AUDIO:
2308 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2310 g_warning ("Could not add audio source to pipeline");
2314 pad = gst_element_get_static_pad (priv->audio_input, "src");
2317 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2318 g_warning ("Could not get source pad from audio source");
2322 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2324 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2325 g_warning ("Could not link audio source to farsight");
2329 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2331 g_warning ("Could not start audio source");
2332 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2333 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2339 case TP_MEDIA_STREAM_TYPE_VIDEO:
2340 if (priv->video_input != NULL)
2342 if (priv->video_tee != NULL)
2344 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2345 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2347 g_warning ("Could not link videp soure input pipeline");
2350 gst_object_unref (pad);
2357 g_assert_not_reached ();
2364 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2366 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2367 GstElement *preview;
2369 disable_camera (self);
2371 DEBUG ("remove video input");
2372 preview = empathy_video_widget_get_element (
2373 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2375 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2376 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2377 gst_element_set_state (preview, GST_STATE_NULL);
2379 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2380 priv->video_tee, preview, NULL);
2382 g_object_unref (priv->video_input);
2383 priv->video_input = NULL;
2384 g_object_unref (priv->video_tee);
2385 priv->video_tee = NULL;
2386 gtk_widget_destroy (priv->video_preview);
2387 priv->video_preview = NULL;
2389 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2390 gtk_widget_set_sensitive (priv->tool_button_camera_preview, FALSE);
2394 start_call (EmpathyCallWindow *self)
2396 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2398 priv->call_started = TRUE;
2399 empathy_call_handler_start_call (priv->handler,
2400 gtk_get_current_event_time ());
2402 if (empathy_call_handler_has_initial_video (priv->handler))
2404 /* Enable 'send video' buttons and display the preview */
2405 gtk_toggle_tool_button_set_active (
2406 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2411 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2414 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2415 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2418 empathy_call_handler_bus_message (priv->handler, bus, message);
2420 switch (GST_MESSAGE_TYPE (message))
2422 case GST_MESSAGE_STATE_CHANGED:
2423 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2425 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2426 if (newstate == GST_STATE_PAUSED)
2427 empathy_call_window_setup_video_input (self);
2429 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2430 !priv->call_started)
2432 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2433 if (newstate == GST_STATE_PAUSED)
2435 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2436 priv->pipeline_playing = TRUE;
2438 if (priv->start_call_when_playing)
2443 case GST_MESSAGE_ERROR:
2445 GError *error = NULL;
2446 GstElement *gst_error;
2449 gst_message_parse_error (message, &error, &debug);
2450 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2452 g_message ("Element error: %s -- %s\n", error->message, debug);
2454 if (g_str_has_prefix (gst_element_get_name (gst_error),
2455 VIDEO_INPUT_ERROR_PREFIX))
2457 /* Remove the video input and continue */
2458 if (priv->video_input != NULL)
2459 empathy_call_window_remove_video_input (self);
2460 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2464 empathy_call_window_disconnected (self, TRUE);
2466 g_error_free (error);
2477 empathy_call_window_update_avatars_visibility (EmpathyTpCall *call,
2478 EmpathyCallWindow *window)
2480 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2482 if (empathy_tp_call_is_receiving_video (call))
2484 gtk_widget_hide (priv->remote_user_avatar_widget);
2485 gtk_widget_show (priv->video_output);
2489 gtk_widget_hide (priv->video_output);
2490 gtk_widget_show (priv->remote_user_avatar_widget);
2495 call_handler_notify_tp_call_cb (EmpathyCallHandler *handler,
2497 EmpathyCallWindow *self)
2499 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2500 EmpathyTpCall *call;
2502 g_object_get (priv->handler, "tp-call", &call, NULL);
2506 tp_g_signal_connect_object (call, "audio-stream-error",
2507 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2508 tp_g_signal_connect_object (call, "video-stream-error",
2509 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2511 g_object_unref (call);
2515 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2517 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2518 EmpathyTpCall *call;
2520 g_signal_connect (priv->handler, "conference-added",
2521 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2522 g_signal_connect (priv->handler, "request-resource",
2523 G_CALLBACK (empathy_call_window_request_resource_cb), window);
2524 g_signal_connect (priv->handler, "closed",
2525 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2526 g_signal_connect (priv->handler, "src-pad-added",
2527 G_CALLBACK (empathy_call_window_src_added_cb), window);
2528 g_signal_connect (priv->handler, "sink-pad-added",
2529 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2530 g_signal_connect (priv->handler, "stream-closed",
2531 G_CALLBACK (empathy_call_window_channel_stream_closed_cb), window);
2533 g_object_get (priv->handler, "tp-call", &call, NULL);
2536 tp_g_signal_connect_object (call, "audio-stream-error",
2537 G_CALLBACK (empathy_call_window_audio_stream_error), window,
2539 tp_g_signal_connect_object (call, "video-stream-error",
2540 G_CALLBACK (empathy_call_window_video_stream_error), window,
2543 g_object_unref (call);
2547 /* tp-call doesn't exist yet, we'll connect signals once it has been
2549 g_signal_connect (priv->handler, "notify::tp-call",
2550 G_CALLBACK (call_handler_notify_tp_call_cb), window);
2553 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2557 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2558 EmpathyCallWindow *window)
2560 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2562 if (priv->pipeline != NULL)
2564 if (priv->bus_message_source_id != 0)
2566 g_source_remove (priv->bus_message_source_id);
2567 priv->bus_message_source_id = 0;
2570 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2573 if (priv->call_state == CONNECTING)
2574 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
2580 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2583 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2585 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2590 gtk_widget_hide (priv->sidebar);
2591 gtk_widget_hide (menu);
2592 gtk_widget_hide (priv->vbox);
2593 gtk_widget_hide (priv->statusbar);
2594 gtk_widget_hide (priv->toolbar);
2598 if (priv->sidebar_was_visible_before_fs)
2599 gtk_widget_show (priv->sidebar);
2601 gtk_widget_show (menu);
2602 gtk_widget_show (priv->vbox);
2603 gtk_widget_show (priv->statusbar);
2604 gtk_widget_show (priv->toolbar);
2606 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2607 priv->original_height_before_fs);
2612 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2614 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2616 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2617 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2618 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2619 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2620 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2621 priv->video_output, TRUE, TRUE,
2622 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2624 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2625 priv->vbox, TRUE, TRUE,
2626 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2631 empathy_call_window_state_event_cb (GtkWidget *widget,
2632 GdkEventWindowState *event, EmpathyCallWindow *window)
2634 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2636 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2637 gboolean set_fullscreen = event->new_window_state &
2638 GDK_WINDOW_STATE_FULLSCREEN;
2642 gboolean sidebar_was_visible;
2643 GtkAllocation allocation;
2644 gint original_width, original_height;
2646 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2647 original_width = allocation.width;
2648 original_height = allocation.height;
2650 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2652 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2653 priv->original_width_before_fs = original_width;
2654 priv->original_height_before_fs = original_height;
2656 if (priv->video_output_motion_handler_id == 0 &&
2657 priv->video_output != NULL)
2659 priv->video_output_motion_handler_id = g_signal_connect (
2660 G_OBJECT (priv->video_output), "motion-notify-event",
2661 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2667 if (priv->video_output_motion_handler_id != 0)
2669 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
2670 priv->video_output_motion_handler_id);
2671 priv->video_output_motion_handler_id = 0;
2675 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2677 show_controls (window, set_fullscreen);
2678 show_borders (window, set_fullscreen);
2679 gtk_action_set_stock_id (priv->menu_fullscreen,
2680 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2681 priv->is_fullscreen = set_fullscreen;
2688 empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
2689 EmpathyCallWindow *window)
2691 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2693 int w, h, handle_size;
2694 GtkAllocation allocation, sidebar_allocation;
2696 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2697 w = allocation.width;
2698 h = allocation.height;
2700 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2702 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
2703 if (gtk_toggle_button_get_active (toggle))
2705 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
2706 gtk_widget_show (priv->sidebar);
2707 w += sidebar_allocation.width + handle_size;
2711 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2712 w -= sidebar_allocation.width + handle_size;
2713 gtk_widget_hide (priv->sidebar);
2716 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
2719 gtk_window_resize (GTK_WINDOW (window), w, h);
2723 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2726 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2727 EmpathyTpCall *call;
2729 priv->sending_video = (state == CAMERA_STATE_ON);
2731 if (state == CAMERA_STATE_PREVIEW ||
2732 state == CAMERA_STATE_ON)
2734 /* When we start sending video, we want to show the video preview by
2736 display_video_preview (window, TRUE);
2740 display_video_preview (window, FALSE);
2743 if (priv->call_state != CONNECTED)
2746 g_object_get (priv->handler, "tp-call", &call, NULL);
2747 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2748 empathy_tp_call_request_video_stream_direction (call, priv->sending_video);
2749 g_object_unref (call);
2753 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2754 EmpathyCallWindow *window)
2756 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2759 active = (gtk_toggle_tool_button_get_active (toggle));
2763 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2765 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
2769 /* TODO, Instead of setting the input volume to 0 we should probably
2770 * stop sending but this would cause the audio call to drop if both
2771 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2772 * in the future. GNOME #574574
2774 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2776 gtk_adjustment_set_value (priv->audio_input_adj, 0);
2781 empathy_call_window_sidebar_hidden_cb (EmpathySidebar *sidebar,
2782 EmpathyCallWindow *window)
2784 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2786 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2791 empathy_call_window_sidebar_shown_cb (EmpathySidebar *sidebar,
2792 EmpathyCallWindow *window)
2794 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2796 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2801 empathy_call_window_hangup_cb (gpointer object,
2802 EmpathyCallWindow *window)
2804 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2806 empathy_call_handler_stop_call (priv->handler);
2808 if (empathy_call_window_disconnected (window, FALSE))
2809 gtk_widget_destroy (GTK_WIDGET (window));
2813 empathy_call_window_restart_call (EmpathyCallWindow *window)
2815 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2817 create_video_output_widget (window);
2819 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
2820 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
2822 /* While the call was disconnected, the input volume might have changed.
2823 * However, since the audio_input source was destroyed, its volume has not
2824 * been updated during that time. That's why we manually update it here */
2825 empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
2827 priv->outgoing = TRUE;
2828 empathy_call_window_set_state_connecting (window);
2830 if (priv->pipeline_playing)
2831 start_call (window);
2833 /* call will be started when the pipeline is ready */
2834 priv->start_call_when_playing = TRUE;
2837 empathy_call_window_setup_avatars (window, priv->handler);
2839 gtk_action_set_sensitive (priv->redial, FALSE);
2840 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2844 empathy_call_window_redial_cb (gpointer object,
2845 EmpathyCallWindow *window)
2847 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2849 if (priv->call_state == CONNECTED)
2850 priv->call_state = REDIALING;
2852 empathy_call_handler_stop_call (priv->handler);
2854 if (priv->call_state != CONNECTED)
2855 empathy_call_window_restart_call (window);
2859 empathy_call_window_fullscreen_cb (gpointer object,
2860 EmpathyCallWindow *window)
2862 empathy_call_window_fullscreen_toggle (window);
2866 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2868 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2870 if (priv->is_fullscreen)
2871 gtk_window_unfullscreen (GTK_WINDOW (window));
2873 gtk_window_fullscreen (GTK_WINDOW (window));
2877 empathy_call_window_video_button_press_cb (GtkWidget *video_output,
2878 GdkEventButton *event, EmpathyCallWindow *window)
2880 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2882 empathy_call_window_video_menu_popup (window, event->button);
2890 empathy_call_window_key_press_cb (GtkWidget *video_output,
2891 GdkEventKey *event, EmpathyCallWindow *window)
2893 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2895 if (priv->is_fullscreen && event->keyval == GDK_Escape)
2897 /* Since we are in fullscreen mode, toggling will bring us back to
2899 empathy_call_window_fullscreen_toggle (window);
2907 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
2908 GdkEventMotion *event, EmpathyCallWindow *window)
2910 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2912 if (priv->is_fullscreen)
2914 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
2921 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
2925 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2927 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2929 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
2930 button, gtk_get_current_event_time ());
2931 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
2935 empathy_call_window_status_message (EmpathyCallWindow *window,
2938 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2940 if (priv->context_id == 0)
2942 priv->context_id = gtk_statusbar_get_context_id (
2943 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
2947 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
2950 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
2955 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
2956 gdouble value, EmpathyCallWindow *window)
2958 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2960 if (priv->audio_output == NULL)
2963 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
2967 /* block all the signals related to camera control widgets. This is useful
2968 * when we are manually updating the UI and so don't want to fire the
2971 block_camera_control_signals (EmpathyCallWindow *self)
2973 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2975 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
2976 tool_button_camera_off_toggled_cb, self);
2977 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
2978 tool_button_camera_preview_toggled_cb, self);
2979 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
2980 tool_button_camera_on_toggled_cb, self);
2981 g_signal_handlers_block_by_func (priv->action_camera,
2982 action_camera_change_cb, self);
2986 unblock_camera_control_signals (EmpathyCallWindow *self)
2988 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2990 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
2991 tool_button_camera_off_toggled_cb, self);
2992 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
2993 tool_button_camera_preview_toggled_cb, self);
2994 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
2995 tool_button_camera_on_toggled_cb, self);
2996 g_signal_handlers_unblock_by_func (priv->action_camera,
2997 action_camera_change_cb, self);