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)
779 gtk_widget_hide (priv->video_preview);
780 play_camera (self, FALSE);
782 gtk_widget_show (priv->self_user_avatar_widget);
787 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
789 EmpathyCallWindowPriv *priv = GET_PRIV (window);
791 empathy_call_window_status_message (window, _("Connecting…"));
792 priv->call_state = CONNECTING;
795 empathy_sound_start_playing (GTK_WIDGET (window),
796 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
800 disable_camera (EmpathyCallWindow *self)
802 EmpathyCallWindowPriv *priv = GET_PRIV (self);
804 if (priv->camera_state == CAMERA_STATE_OFF)
807 DEBUG ("Disable camera");
809 display_video_preview (self, FALSE);
811 if (priv->camera_state == CAMERA_STATE_ON)
812 empathy_call_window_set_send_video (self, FALSE);
814 block_camera_control_signals (self);
815 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
816 priv->tool_button_camera_on), FALSE);
817 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
818 priv->tool_button_camera_preview), FALSE);
820 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
821 priv->tool_button_camera_off), TRUE);
822 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
824 unblock_camera_control_signals (self);
826 priv->camera_state = CAMERA_STATE_OFF;
830 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
831 EmpathyCallWindow *self)
833 EmpathyCallWindowPriv *priv = GET_PRIV (self);
835 if (!gtk_toggle_tool_button_get_active (toggle))
837 if (priv->camera_state == CAMERA_STATE_OFF)
839 /* We can't change the state by disabling the button */
840 block_camera_control_signals (self);
841 gtk_toggle_tool_button_set_active (toggle, TRUE);
842 unblock_camera_control_signals (self);
848 disable_camera (self);
852 enable_preview (EmpathyCallWindow *self)
854 EmpathyCallWindowPriv *priv = GET_PRIV (self);
856 if (priv->camera_state == CAMERA_STATE_PREVIEW)
859 DEBUG ("Enable preview");
861 if (priv->camera_state == CAMERA_STATE_ON)
862 /* preview is already displayed so we just have to stop sending */
863 empathy_call_window_set_send_video (self, FALSE);
865 display_video_preview (self, TRUE);
867 block_camera_control_signals (self);
868 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
869 priv->tool_button_camera_off), FALSE);
870 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
871 priv->tool_button_camera_on), FALSE);
873 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
874 priv->tool_button_camera_preview), TRUE);
875 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
876 CAMERA_STATE_PREVIEW);
877 unblock_camera_control_signals (self);
879 priv->camera_state = CAMERA_STATE_PREVIEW;
883 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
884 EmpathyCallWindow *self)
886 EmpathyCallWindowPriv *priv = GET_PRIV (self);
888 if (!gtk_toggle_tool_button_get_active (toggle))
890 if (priv->camera_state == CAMERA_STATE_PREVIEW)
892 /* We can't change the state by disabling the button */
893 block_camera_control_signals (self);
894 gtk_toggle_tool_button_set_active (toggle, TRUE);
895 unblock_camera_control_signals (self);
901 enable_preview (self);
905 enable_camera (EmpathyCallWindow *self)
907 EmpathyCallWindowPriv *priv = GET_PRIV (self);
909 if (priv->camera_state == CAMERA_STATE_ON)
912 if (priv->video_input == NULL)
914 DEBUG ("Can't enable camera, no input");
919 DEBUG ("Enable camera");
921 empathy_call_window_set_send_video (self, TRUE);
923 block_camera_control_signals (self);
924 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
925 priv->tool_button_camera_off), FALSE);
926 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
927 priv->tool_button_camera_preview), FALSE);
929 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
930 priv->tool_button_camera_on), TRUE);
931 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
933 unblock_camera_control_signals (self);
935 priv->camera_state = CAMERA_STATE_ON;
939 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
940 EmpathyCallWindow *self)
942 EmpathyCallWindowPriv *priv = GET_PRIV (self);
944 if (!gtk_toggle_tool_button_get_active (toggle))
946 if (priv->camera_state == CAMERA_STATE_ON)
948 /* We can't change the state by disabling the button */
949 block_camera_control_signals (self);
950 gtk_toggle_tool_button_set_active (toggle, TRUE);
951 unblock_camera_control_signals (self);
957 enable_camera (self);
961 action_camera_change_cb (GtkRadioAction *action,
962 GtkRadioAction *current,
963 EmpathyCallWindow *self)
967 state = gtk_radio_action_get_current_value (current);
971 case CAMERA_STATE_OFF:
972 disable_camera (self);
975 case CAMERA_STATE_PREVIEW:
976 enable_preview (self);
979 case CAMERA_STATE_ON:
980 enable_camera (self);
984 g_assert_not_reached ();
989 create_pipeline (EmpathyCallWindow *self)
991 EmpathyCallWindowPriv *priv = GET_PRIV (self);
994 g_assert (priv->pipeline == NULL);
996 priv->pipeline = gst_pipeline_new (NULL);
997 priv->pipeline_playing = FALSE;
999 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1000 priv->bus_message_source_id = gst_bus_add_watch (bus,
1001 empathy_call_window_bus_message, self);
1003 g_object_unref (bus);
1008 empathy_call_window_init (EmpathyCallWindow *self)
1010 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1012 GtkWidget *top_vbox;
1018 GError *error = NULL;
1020 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1021 gui = empathy_builder_get_file (filename,
1022 "call_window_vbox", &top_vbox,
1023 "errors_vbox", &priv->errors_vbox,
1024 "pane", &priv->pane,
1025 "statusbar", &priv->statusbar,
1026 "redial", &priv->redial_button,
1027 "microphone", &priv->mic_button,
1028 "toolbar", &priv->toolbar,
1029 "menuredial", &priv->redial,
1030 "ui_manager", &priv->ui_manager,
1031 "menufullscreen", &priv->menu_fullscreen,
1032 "camera_off", &priv->tool_button_camera_off,
1033 "camera_preview", &priv->tool_button_camera_preview,
1034 "camera_on", &priv->tool_button_camera_on,
1035 "action_camera_off", &priv->action_camera,
1036 "action_camera_preview", &priv->action_camera_preview,
1040 empathy_builder_connect (gui, self,
1041 "menuhangup", "activate", empathy_call_window_hangup_cb,
1042 "hangup", "clicked", empathy_call_window_hangup_cb,
1043 "menuredial", "activate", empathy_call_window_redial_cb,
1044 "redial", "clicked", empathy_call_window_redial_cb,
1045 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1046 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1047 "camera_off", "toggled", tool_button_camera_off_toggled_cb,
1048 "camera_preview", "toggled", tool_button_camera_preview_toggled_cb,
1049 "camera_on", "toggled", tool_button_camera_on_toggled_cb,
1050 "action_camera_off", "changed", action_camera_change_cb,
1053 priv->lock = g_mutex_new ();
1055 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1057 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1058 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1059 CONTENT_HBOX_BORDER_WIDTH);
1060 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1062 /* remote user output frame */
1063 priv->remote_user_output_frame = gtk_frame_new (NULL);
1064 gtk_widget_set_size_request (priv->remote_user_output_frame,
1065 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1066 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1067 priv->remote_user_output_frame, TRUE, TRUE,
1068 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1070 priv->remote_user_output_hbox = gtk_hbox_new (FALSE, 0);
1072 priv->remote_user_avatar_widget = gtk_image_new ();
1074 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1075 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1077 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1078 priv->remote_user_output_hbox);
1080 /* self user output frame */
1081 priv->self_user_output_frame = gtk_frame_new (NULL);
1082 gtk_widget_set_size_request (priv->self_user_output_frame,
1083 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1085 priv->self_user_output_hbox = gtk_hbox_new (FALSE, 0);
1087 priv->self_user_avatar_widget = gtk_image_new ();
1088 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1089 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1091 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1092 priv->self_user_output_hbox);
1094 create_pipeline (self);
1095 create_video_output_widget (self);
1096 create_audio_input (self);
1097 create_audio_output (self);
1098 create_video_input (self);
1100 priv->fsnotifier = fs_element_added_notifier_new ();
1101 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1103 /* The call will be started as soon the pipeline is playing */
1104 priv->start_call_when_playing = TRUE;
1106 keyfile = g_key_file_new ();
1107 filename = empathy_file_lookup ("element-properties", "data");
1108 if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error))
1110 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1115 g_warning ("Could not load element-properties file: %s", error->message);
1116 g_key_file_free (keyfile);
1117 g_clear_error (&error);
1121 priv->vbox = gtk_vbox_new (FALSE, 3);
1122 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1123 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1124 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1127 empathy_call_window_setup_toolbar (self);
1129 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1130 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1131 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1132 G_CALLBACK (empathy_call_window_sidebar_toggled_cb), self);
1134 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1136 h = gtk_hbox_new (FALSE, 3);
1137 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1138 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1140 priv->sidebar = empathy_sidebar_new ();
1141 g_signal_connect (G_OBJECT (priv->sidebar),
1142 "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb), self);
1143 g_signal_connect (G_OBJECT (priv->sidebar),
1144 "show", G_CALLBACK (empathy_call_window_sidebar_shown_cb), self);
1145 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1147 page = empathy_call_window_create_audio_input (self);
1148 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Audio input"),
1151 page = empathy_call_window_create_video_input (self);
1152 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Video input"),
1155 priv->dtmf_panel = empathy_call_window_create_dtmf (self);
1156 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Dialpad"),
1159 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1162 gtk_widget_show_all (top_vbox);
1164 gtk_widget_hide (priv->sidebar);
1166 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1167 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1168 priv->video_output);
1169 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1170 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1172 g_signal_connect (G_OBJECT (self), "realize",
1173 G_CALLBACK (empathy_call_window_realized_cb), self);
1175 g_signal_connect (G_OBJECT (self), "delete-event",
1176 G_CALLBACK (empathy_call_window_delete_cb), self);
1178 g_signal_connect (G_OBJECT (self), "window-state-event",
1179 G_CALLBACK (empathy_call_window_state_event_cb), self);
1181 g_signal_connect (G_OBJECT (self), "key-press-event",
1182 G_CALLBACK (empathy_call_window_key_press_cb), self);
1184 priv->timer = g_timer_new ();
1186 g_object_ref (priv->ui_manager);
1187 g_object_unref (gui);
1189 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1192 /* Instead of specifying a width and a height, we specify only one size. That's
1193 because we want a square avatar icon. */
1195 init_contact_avatar_with_size (EmpathyContact *contact,
1196 GtkWidget *image_widget,
1199 GdkPixbuf *pixbuf_avatar = NULL;
1201 if (contact != NULL)
1203 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1207 if (pixbuf_avatar == NULL)
1209 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized ("stock_person",
1213 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1215 if (pixbuf_avatar != NULL)
1216 g_object_unref (pixbuf_avatar);
1220 set_window_title (EmpathyCallWindow *self)
1222 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1225 /* translators: Call is a noun and %s is the contact name. This string
1226 * is used in the window title */
1227 tmp = g_strdup_printf (_("Call with %s"),
1228 empathy_contact_get_name (priv->contact));
1229 gtk_window_set_title (GTK_WINDOW (self), tmp);
1234 contact_name_changed_cb (EmpathyContact *contact,
1235 GParamSpec *pspec, EmpathyCallWindow *self)
1237 set_window_title (self);
1241 contact_avatar_changed_cb (EmpathyContact *contact,
1242 GParamSpec *pspec, GtkWidget *avatar_widget)
1246 size = avatar_widget->allocation.height;
1250 /* the widget is not allocated yet, set a default size */
1251 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1252 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1255 init_contact_avatar_with_size (contact, avatar_widget, size);
1259 empathy_call_window_got_self_contact_cb (EmpathyTpContactFactory *factory,
1260 EmpathyContact *contact, const GError *error, gpointer user_data,
1261 GObject *weak_object)
1263 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1264 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1266 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1267 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1269 g_signal_connect (contact, "notify::avatar",
1270 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1274 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1275 EmpathyCallHandler *handler)
1277 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1279 g_object_get (handler, "contact", &(priv->contact), NULL);
1281 if (priv->contact != NULL)
1283 TpConnection *connection;
1284 EmpathyTpContactFactory *factory;
1286 set_window_title (self);
1288 g_signal_connect (priv->contact, "notify::name",
1289 G_CALLBACK (contact_name_changed_cb), self);
1290 g_signal_connect (priv->contact, "notify::avatar",
1291 G_CALLBACK (contact_avatar_changed_cb),
1292 priv->remote_user_avatar_widget);
1294 /* Retreiving the self avatar */
1295 connection = empathy_contact_get_connection (priv->contact);
1296 factory = empathy_tp_contact_factory_dup_singleton (connection);
1297 empathy_tp_contact_factory_get_from_handle (factory,
1298 tp_connection_get_self_handle (connection),
1299 empathy_call_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1301 g_object_unref (factory);
1305 g_warning ("call handler doesn't have a contact");
1306 /* translators: Call is a noun. This string is used in the window
1308 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1310 /* Since we can't access the remote contact, we can't get a connection
1311 to it and can't get the self contact (and its avatar). This means
1312 that we have to manually set the self avatar. */
1313 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1314 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1317 init_contact_avatar_with_size (priv->contact,
1318 priv->remote_user_avatar_widget,
1319 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1320 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1322 /* The remote avatar is shown by default and will be hidden when we receive
1323 video from the remote side. */
1324 gtk_widget_hide (priv->video_output);
1325 gtk_widget_show (priv->remote_user_avatar_widget);
1329 empathy_call_window_constructed (GObject *object)
1331 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1332 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1333 EmpathyTpCall *call;
1335 g_assert (priv->handler != NULL);
1337 g_object_get (priv->handler, "tp-call", &call, NULL);
1338 priv->outgoing = (call == NULL);
1340 g_object_unref (call);
1342 empathy_call_window_setup_avatars (self, priv->handler);
1343 empathy_call_window_set_state_connecting (self);
1345 if (!empathy_call_handler_has_initial_video (priv->handler))
1347 gtk_toggle_tool_button_set_active (
1348 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1350 /* If call has InitialVideo, the preview will be started once the call has
1351 * been started (start_call()). */
1354 static void empathy_call_window_dispose (GObject *object);
1355 static void empathy_call_window_finalize (GObject *object);
1358 empathy_call_window_set_property (GObject *object,
1359 guint property_id, const GValue *value, GParamSpec *pspec)
1361 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1363 switch (property_id)
1365 case PROP_CALL_HANDLER:
1366 priv->handler = g_value_dup_object (value);
1369 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1374 empathy_call_window_get_property (GObject *object,
1375 guint property_id, GValue *value, GParamSpec *pspec)
1377 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1379 switch (property_id)
1381 case PROP_CALL_HANDLER:
1382 g_value_set_object (value, priv->handler);
1385 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1390 empathy_call_window_class_init (
1391 EmpathyCallWindowClass *empathy_call_window_class)
1393 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1394 GParamSpec *param_spec;
1396 g_type_class_add_private (empathy_call_window_class,
1397 sizeof (EmpathyCallWindowPriv));
1399 object_class->constructed = empathy_call_window_constructed;
1400 object_class->set_property = empathy_call_window_set_property;
1401 object_class->get_property = empathy_call_window_get_property;
1403 object_class->dispose = empathy_call_window_dispose;
1404 object_class->finalize = empathy_call_window_finalize;
1406 param_spec = g_param_spec_object ("handler",
1407 "handler", "The call handler",
1408 EMPATHY_TYPE_CALL_HANDLER,
1409 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1410 g_object_class_install_property (object_class,
1411 PROP_CALL_HANDLER, param_spec);
1415 empathy_call_window_video_stream_changed_cb (EmpathyTpCall *call,
1416 GParamSpec *property, EmpathyCallWindow *self)
1418 DEBUG ("video stream changed");
1419 empathy_call_window_update_avatars_visibility (call, self);
1423 empathy_call_window_dispose (GObject *object)
1425 EmpathyTpCall *call;
1426 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1427 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1429 if (priv->dispose_has_run)
1432 priv->dispose_has_run = TRUE;
1434 g_object_get (priv->handler, "tp-call", &call, NULL);
1438 g_object_unref (call);
1441 if (priv->handler != NULL)
1443 empathy_call_handler_stop_call (priv->handler);
1444 g_object_unref (priv->handler);
1446 priv->handler = NULL;
1448 if (priv->bus_message_source_id != 0)
1450 g_source_remove (priv->bus_message_source_id);
1451 priv->bus_message_source_id = 0;
1454 if (priv->pipeline != NULL)
1455 g_object_unref (priv->pipeline);
1456 priv->pipeline = NULL;
1458 if (priv->video_input != NULL)
1459 g_object_unref (priv->video_input);
1460 priv->video_input = NULL;
1462 if (priv->audio_input != NULL)
1463 g_object_unref (priv->audio_input);
1464 priv->audio_input = NULL;
1466 if (priv->audio_output != NULL)
1467 g_object_unref (priv->audio_output);
1468 priv->audio_output = NULL;
1470 if (priv->video_tee != NULL)
1471 g_object_unref (priv->video_tee);
1472 priv->video_tee = NULL;
1474 if (priv->liveadder != NULL)
1475 gst_object_unref (priv->liveadder);
1476 priv->liveadder = NULL;
1478 if (priv->fsnotifier != NULL)
1479 g_object_unref (priv->fsnotifier);
1480 priv->fsnotifier = NULL;
1482 if (priv->timer_id != 0)
1483 g_source_remove (priv->timer_id);
1486 if (priv->ui_manager != NULL)
1487 g_object_unref (priv->ui_manager);
1488 priv->ui_manager = NULL;
1490 if (priv->fullscreen != NULL)
1491 g_object_unref (priv->fullscreen);
1492 priv->fullscreen = NULL;
1494 if (priv->contact != NULL)
1496 g_signal_handlers_disconnect_by_func (priv->contact,
1497 contact_name_changed_cb, self);
1498 g_object_unref (priv->contact);
1499 priv->contact = NULL;
1502 /* release any references held by the object here */
1503 if (G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose)
1504 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1508 empathy_call_window_finalize (GObject *object)
1510 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1511 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1513 if (priv->video_output_motion_handler_id != 0)
1515 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1516 priv->video_output_motion_handler_id);
1517 priv->video_output_motion_handler_id = 0;
1520 /* free any data held directly by the object here */
1521 g_mutex_free (priv->lock);
1523 g_timer_destroy (priv->timer);
1525 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1530 empathy_call_window_new (EmpathyCallHandler *handler)
1532 return EMPATHY_CALL_WINDOW (
1533 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1537 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1538 GstElement *conference, gpointer user_data)
1540 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1541 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1543 gst_bin_add (GST_BIN (priv->pipeline), conference);
1545 gst_element_set_state (conference, GST_STATE_PLAYING);
1549 empathy_call_window_request_resource_cb (EmpathyCallHandler *handler,
1550 FsMediaType type, FsStreamDirection direction, gpointer user_data)
1552 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1553 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1555 if (type != FS_MEDIA_TYPE_VIDEO)
1558 if (direction == FS_DIRECTION_RECV)
1561 /* video and direction is send */
1562 return priv->video_input != NULL;
1566 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1568 GstStateChangeReturn state_change_return;
1569 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1571 if (priv->pipeline == NULL)
1574 if (priv->bus_message_source_id != 0)
1576 g_source_remove (priv->bus_message_source_id);
1577 priv->bus_message_source_id = 0;
1580 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1582 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1583 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1585 if (priv->pipeline != NULL)
1586 g_object_unref (priv->pipeline);
1587 priv->pipeline = NULL;
1589 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1590 empathy_call_window_mic_volume_changed_cb, self);
1592 if (priv->video_tee != NULL)
1593 g_object_unref (priv->video_tee);
1594 priv->video_tee = NULL;
1596 if (priv->video_preview != NULL)
1597 gtk_widget_destroy (priv->video_preview);
1598 priv->video_preview = NULL;
1600 priv->liveadder = NULL;
1601 priv->funnel = NULL;
1603 create_pipeline (self);
1604 /* Call will be started when user will hit the 'redial' button */
1605 priv->start_call_when_playing = FALSE;
1606 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1612 g_message ("Error: could not destroy pipeline. Closing call window");
1613 gtk_widget_destroy (GTK_WIDGET (self));
1620 empathy_call_window_disconnected (EmpathyCallWindow *self,
1623 gboolean could_disconnect = FALSE;
1624 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1625 gboolean could_reset_pipeline;
1627 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1629 if (priv->call_state == CONNECTING)
1630 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
1632 if (priv->call_state != REDIALING)
1633 priv->call_state = DISCONNECTED;
1635 if (could_reset_pipeline)
1637 g_mutex_lock (priv->lock);
1639 g_timer_stop (priv->timer);
1641 if (priv->timer_id != 0)
1642 g_source_remove (priv->timer_id);
1645 g_mutex_unlock (priv->lock);
1648 /* We are about to destroy the window, no need to update it or create
1649 * a video preview */
1652 empathy_call_window_status_message (self, _("Disconnected"));
1654 gtk_action_set_sensitive (priv->redial, TRUE);
1655 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1657 /* Unsensitive the camera and mic button */
1658 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1659 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1661 /* Be sure that the mic button is enabled */
1662 gtk_toggle_tool_button_set_active (
1663 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1665 if (priv->camera_state == CAMERA_STATE_ON)
1667 /* Enable the 'preview' button as we are not sending atm. */
1668 gtk_toggle_tool_button_set_active (
1669 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_preview), TRUE);
1671 else if (priv->camera_state == CAMERA_STATE_PREVIEW)
1673 /* Restart the preview with the new pipeline. */
1674 display_video_preview (self, TRUE);
1677 gtk_progress_bar_set_fraction (
1678 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1680 /* destroy the video output; it will be recreated when we'll redial */
1681 gtk_widget_destroy (priv->video_output);
1682 priv->video_output = NULL;
1684 gtk_widget_show (priv->remote_user_avatar_widget);
1686 priv->sending_video = FALSE;
1687 priv->call_started = FALSE;
1689 could_disconnect = TRUE;
1691 /* TODO: display the self avatar of the preview (depends if the "Always
1692 * Show Video Preview" is enabled or not) */
1695 return could_disconnect;
1700 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1703 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1704 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1706 if (empathy_call_window_disconnected (self, TRUE) &&
1707 priv->call_state == REDIALING)
1708 empathy_call_window_restart_call (self);
1713 empathy_call_window_channel_stream_closed_cb (EmpathyCallHandler *handler,
1714 TfStream *stream, gpointer user_data)
1716 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1717 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1720 g_object_get (stream, "media-type", &media_type, NULL);
1723 * This assumes that there is only one video stream per channel...
1726 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
1728 if (priv->funnel != NULL)
1732 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1733 (priv->video_output));
1735 gst_element_set_state (output, GST_STATE_NULL);
1736 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1738 gst_bin_remove (GST_BIN (priv->pipeline), output);
1739 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1740 priv->funnel = NULL;
1743 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
1745 if (priv->liveadder != NULL)
1747 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1748 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
1750 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1751 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
1752 priv->liveadder = NULL;
1757 /* Called with global lock held */
1759 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1761 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1765 if (priv->funnel == NULL)
1767 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1768 (priv->video_output));
1770 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1774 g_warning ("Could not create fsfunnel");
1778 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1780 gst_object_unref (priv->funnel);
1781 priv->funnel = NULL;
1782 g_warning ("Could not add funnel to pipeline");
1786 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1788 g_warning ("Could not add the video output widget to the pipeline");
1792 if (!gst_element_link (priv->funnel, output))
1794 g_warning ("Could not link output sink to funnel");
1795 goto error_output_added;
1798 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1800 g_warning ("Could not start video sink");
1801 goto error_output_added;
1804 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1806 g_warning ("Could not start funnel");
1807 goto error_output_added;
1811 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1814 g_warning ("Could not get request pad from funnel");
1821 gst_element_set_locked_state (priv->funnel, TRUE);
1822 gst_element_set_locked_state (output, TRUE);
1824 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1825 gst_element_set_state (output, GST_STATE_NULL);
1827 gst_bin_remove (GST_BIN (priv->pipeline), output);
1828 gst_element_set_locked_state (output, FALSE);
1832 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1833 priv->funnel = NULL;
1838 /* Called with global lock held */
1840 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1842 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1845 GError *gerror = NULL;
1847 if (priv->liveadder == NULL)
1849 priv->liveadder = gst_element_factory_make ("liveadder", NULL);
1851 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->liveadder))
1853 g_warning ("Could not add liveadder to the pipeline");
1854 goto error_add_liveadder;
1856 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1858 g_warning ("Could not add audio sink to pipeline");
1859 goto error_add_output;
1862 if (gst_element_set_state (priv->liveadder, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1864 g_warning ("Could not start liveadder");
1868 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1870 g_warning ("Could not start audio sink");
1874 if (GST_PAD_LINK_FAILED (
1875 gst_element_link (priv->liveadder, priv->audio_output)))
1877 g_warning ("Could not link liveadder to audio output");
1882 filter = gst_parse_bin_from_description (
1883 "audioconvert ! audioresample ! audioconvert", TRUE, &gerror);
1886 g_warning ("Could not make audio conversion filter: %s", gerror->message);
1887 g_clear_error (&gerror);
1891 if (!gst_bin_add (GST_BIN (priv->pipeline), filter))
1893 g_warning ("Could not add audio conversion filter to pipeline");
1894 gst_object_unref (filter);
1898 if (gst_element_set_state (filter, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1900 g_warning ("Could not start audio conversion filter");
1904 if (!gst_element_link (filter, priv->liveadder))
1906 g_warning ("Could not link audio conversion filter to liveadder");
1910 pad = gst_element_get_static_pad (filter, "sink");
1914 g_warning ("Could not get sink pad from filter");
1922 gst_element_set_locked_state (filter, TRUE);
1923 gst_element_set_state (filter, GST_STATE_NULL);
1924 gst_bin_remove (GST_BIN (priv->pipeline), filter);
1928 gst_element_set_locked_state (priv->liveadder, TRUE);
1929 gst_element_set_locked_state (priv->audio_output, TRUE);
1931 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
1932 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1934 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1938 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
1940 gst_element_set_locked_state (priv->liveadder, FALSE);
1941 gst_element_set_locked_state (priv->audio_output, FALSE);
1943 error_add_liveadder:
1945 if (priv->liveadder != NULL)
1947 gst_object_unref (priv->liveadder);
1948 priv->liveadder = NULL;
1955 empathy_call_window_update_timer (gpointer user_data)
1957 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1958 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1962 time_ = g_timer_elapsed (priv->timer, NULL);
1964 /* Translators: number of minutes:seconds the caller has been connected */
1965 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
1967 empathy_call_window_status_message (self, str);
1974 display_error (EmpathyCallWindow *self,
1975 EmpathyTpCall *call,
1979 const gchar *details)
1981 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1982 GtkWidget *info_bar;
1983 GtkWidget *content_area;
1990 /* Create info bar */
1991 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1994 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
1996 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
1998 /* hbox containing the image and the messages vbox */
1999 hbox = gtk_hbox_new (FALSE, 3);
2000 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2003 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2004 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2006 /* vbox containing the main message and the details expander */
2007 vbox = gtk_vbox_new (FALSE, 3);
2008 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2011 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2013 label = gtk_label_new (NULL);
2014 gtk_label_set_markup (GTK_LABEL (label), txt);
2015 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2016 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2019 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2022 if (details != NULL)
2024 GtkWidget *expander;
2026 expander = gtk_expander_new (_("Technical Details"));
2028 txt = g_strdup_printf ("<i>%s</i>", details);
2030 label = gtk_label_new (NULL);
2031 gtk_label_set_markup (GTK_LABEL (label), txt);
2032 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2033 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2036 gtk_container_add (GTK_CONTAINER (expander), label);
2037 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2040 g_signal_connect (info_bar, "response",
2041 G_CALLBACK (gtk_widget_destroy), NULL);
2043 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2044 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2045 gtk_widget_show_all (info_bar);
2049 media_stream_error_to_txt (EmpathyCallWindow *self,
2050 EmpathyTpCall *call,
2052 TpMediaStreamError error)
2054 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2061 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2063 return g_strdup_printf (
2064 _("%s's software does not understand any of the audio formats "
2065 "supported by your computer"),
2066 empathy_contact_get_name (priv->contact));
2068 return g_strdup_printf (
2069 _("%s's software does not understand any of the video formats "
2070 "supported by your computer"),
2071 empathy_contact_get_name (priv->contact));
2073 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2074 return g_strdup_printf (
2075 _("Can't establish a connection to %s. "
2076 "One of you might be on a network that does not allow "
2077 "direct connections."),
2078 empathy_contact_get_name (priv->contact));
2080 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2081 return g_strdup (_("There was a failure on the network"));
2083 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2085 return g_strdup (_("The audio formats necessary for this call "
2086 "are not installed on your computer"));
2088 return g_strdup (_("The video formats necessary for this call "
2089 "are not installed on your computer"));
2091 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2092 cm = empathy_tp_call_get_connection_manager (call);
2094 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2095 "product=Telepathy&component=%s", cm);
2097 result = g_strdup_printf (
2098 _("Something unexpected happened in a Telepathy component. "
2099 "Please <a href=\"%s\">report this bug</a> and attach "
2100 "logs gathered from the 'Debug' window in the Help menu."), url);
2105 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2106 return g_strdup (_("There was a failure in the call engine"));
2114 empathy_call_window_stream_error (EmpathyCallWindow *self,
2115 EmpathyTpCall *call,
2124 desc = media_stream_error_to_txt (self, call, audio, code);
2127 /* No description, use the error message. That's not great as it's not
2128 * localized but it's better than nothing. */
2129 display_error (self, call, icon, title, msg, NULL);
2133 display_error (self, call, icon, title, desc, msg);
2139 empathy_call_window_audio_stream_error (EmpathyTpCall *call,
2142 EmpathyCallWindow *self)
2144 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2145 "gnome-stock-mic", _("Can't establish audio stream"));
2149 empathy_call_window_video_stream_error (EmpathyTpCall *call,
2152 EmpathyCallWindow *self)
2154 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2155 "camera-web", _("Can't establish video stream"));
2159 empathy_call_window_connected (gpointer user_data)
2161 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2162 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2163 EmpathyTpCall *call;
2164 gboolean can_send_video;
2166 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
2168 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2169 empathy_contact_can_voip_video (priv->contact);
2171 g_object_get (priv->handler, "tp-call", &call, NULL);
2173 tp_g_signal_connect_object (call, "notify::video-stream",
2174 G_CALLBACK (empathy_call_window_video_stream_changed_cb),
2177 if (empathy_tp_call_has_dtmf (call))
2178 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2180 if (priv->video_input == NULL)
2181 empathy_call_window_set_send_video (self, FALSE);
2183 priv->sending_video = can_send_video ?
2184 empathy_tp_call_is_sending_video (call) : FALSE;
2186 gtk_toggle_tool_button_set_active (
2187 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2188 priv->sending_video && priv->video_input != NULL);
2189 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2191 gtk_action_set_sensitive (priv->redial, FALSE);
2192 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2194 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2196 empathy_call_window_update_avatars_visibility (call, self);
2198 g_object_unref (call);
2200 g_mutex_lock (priv->lock);
2202 priv->timer_id = g_timeout_add_seconds (1,
2203 empathy_call_window_update_timer, self);
2205 g_mutex_unlock (priv->lock);
2207 empathy_call_window_update_timer (self);
2213 /* Called from the streaming thread */
2215 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2216 GstPad *src, guint media_type, gpointer user_data)
2218 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2219 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2220 gboolean retval = FALSE;
2224 g_mutex_lock (priv->lock);
2226 if (priv->call_state != CONNECTED)
2228 g_timer_start (priv->timer);
2229 priv->timer_id = g_idle_add (empathy_call_window_connected, self);
2230 priv->call_state = CONNECTED;
2235 case TP_MEDIA_STREAM_TYPE_AUDIO:
2236 pad = empathy_call_window_get_audio_sink_pad (self);
2238 case TP_MEDIA_STREAM_TYPE_VIDEO:
2239 gtk_widget_hide (priv->remote_user_avatar_widget);
2240 gtk_widget_show (priv->video_output);
2241 pad = empathy_call_window_get_video_sink_pad (self);
2244 g_assert_not_reached ();
2250 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2251 g_warning ("Could not link %s sink pad",
2252 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2256 gst_object_unref (pad);
2260 /* If no sink could be linked, try to add fakesink to prevent the whole call
2265 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2267 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2269 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2270 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2271 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2273 gst_element_set_locked_state (fakesink, TRUE);
2274 gst_element_set_state (fakesink, GST_STATE_NULL);
2275 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2279 g_debug ("Could not link real sink, linked fakesink instead");
2281 gst_object_unref (sinkpad);
2285 gst_object_unref (fakesink);
2290 g_mutex_unlock (priv->lock);
2296 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2297 GstPad *sink, guint media_type, gpointer user_data)
2299 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2300 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2302 gboolean retval = FALSE;
2306 case TP_MEDIA_STREAM_TYPE_AUDIO:
2307 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2309 g_warning ("Could not add audio source to pipeline");
2313 pad = gst_element_get_static_pad (priv->audio_input, "src");
2316 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2317 g_warning ("Could not get source pad from audio source");
2321 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2323 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2324 g_warning ("Could not link audio source to farsight");
2328 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2330 g_warning ("Could not start audio source");
2331 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2332 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2338 case TP_MEDIA_STREAM_TYPE_VIDEO:
2339 if (priv->video_input != NULL)
2341 if (priv->video_tee != NULL)
2343 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2344 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2346 g_warning ("Could not link videp soure input pipeline");
2349 gst_object_unref (pad);
2356 g_assert_not_reached ();
2363 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2365 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2366 GstElement *preview;
2368 disable_camera (self);
2370 DEBUG ("remove video input");
2371 preview = empathy_video_widget_get_element (
2372 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2374 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2375 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2376 gst_element_set_state (preview, GST_STATE_NULL);
2378 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2379 priv->video_tee, preview, NULL);
2381 g_object_unref (priv->video_input);
2382 priv->video_input = NULL;
2383 g_object_unref (priv->video_tee);
2384 priv->video_tee = NULL;
2385 gtk_widget_destroy (priv->video_preview);
2386 priv->video_preview = NULL;
2388 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2389 gtk_widget_set_sensitive (priv->tool_button_camera_preview, FALSE);
2393 start_call (EmpathyCallWindow *self)
2395 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2397 priv->call_started = TRUE;
2398 empathy_call_handler_start_call (priv->handler,
2399 gtk_get_current_event_time ());
2401 if (empathy_call_handler_has_initial_video (priv->handler))
2403 /* Enable 'send video' buttons and display the preview */
2404 gtk_toggle_tool_button_set_active (
2405 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2410 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2413 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2414 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2417 empathy_call_handler_bus_message (priv->handler, bus, message);
2419 switch (GST_MESSAGE_TYPE (message))
2421 case GST_MESSAGE_STATE_CHANGED:
2422 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2424 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2425 if (newstate == GST_STATE_PAUSED)
2426 empathy_call_window_setup_video_input (self);
2428 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2429 !priv->call_started)
2431 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2432 if (newstate == GST_STATE_PAUSED)
2434 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2435 priv->pipeline_playing = TRUE;
2437 if (priv->start_call_when_playing)
2442 case GST_MESSAGE_ERROR:
2444 GError *error = NULL;
2445 GstElement *gst_error;
2448 gst_message_parse_error (message, &error, &debug);
2449 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2451 g_message ("Element error: %s -- %s\n", error->message, debug);
2453 if (g_str_has_prefix (gst_element_get_name (gst_error),
2454 VIDEO_INPUT_ERROR_PREFIX))
2456 /* Remove the video input and continue */
2457 if (priv->video_input != NULL)
2458 empathy_call_window_remove_video_input (self);
2459 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2463 empathy_call_window_disconnected (self, TRUE);
2465 g_error_free (error);
2476 empathy_call_window_update_avatars_visibility (EmpathyTpCall *call,
2477 EmpathyCallWindow *window)
2479 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2481 if (empathy_tp_call_is_receiving_video (call))
2483 gtk_widget_hide (priv->remote_user_avatar_widget);
2484 gtk_widget_show (priv->video_output);
2488 gtk_widget_hide (priv->video_output);
2489 gtk_widget_show (priv->remote_user_avatar_widget);
2494 call_handler_notify_tp_call_cb (EmpathyCallHandler *handler,
2496 EmpathyCallWindow *self)
2498 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2499 EmpathyTpCall *call;
2501 g_object_get (priv->handler, "tp-call", &call, NULL);
2505 tp_g_signal_connect_object (call, "audio-stream-error",
2506 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2507 tp_g_signal_connect_object (call, "video-stream-error",
2508 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2510 g_object_unref (call);
2514 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2516 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2517 EmpathyTpCall *call;
2519 g_signal_connect (priv->handler, "conference-added",
2520 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2521 g_signal_connect (priv->handler, "request-resource",
2522 G_CALLBACK (empathy_call_window_request_resource_cb), window);
2523 g_signal_connect (priv->handler, "closed",
2524 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2525 g_signal_connect (priv->handler, "src-pad-added",
2526 G_CALLBACK (empathy_call_window_src_added_cb), window);
2527 g_signal_connect (priv->handler, "sink-pad-added",
2528 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2529 g_signal_connect (priv->handler, "stream-closed",
2530 G_CALLBACK (empathy_call_window_channel_stream_closed_cb), window);
2532 g_object_get (priv->handler, "tp-call", &call, NULL);
2535 tp_g_signal_connect_object (call, "audio-stream-error",
2536 G_CALLBACK (empathy_call_window_audio_stream_error), window,
2538 tp_g_signal_connect_object (call, "video-stream-error",
2539 G_CALLBACK (empathy_call_window_video_stream_error), window,
2542 g_object_unref (call);
2546 /* tp-call doesn't exist yet, we'll connect signals once it has been
2548 g_signal_connect (priv->handler, "notify::tp-call",
2549 G_CALLBACK (call_handler_notify_tp_call_cb), window);
2552 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2556 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2557 EmpathyCallWindow *window)
2559 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2561 if (priv->pipeline != NULL)
2563 if (priv->bus_message_source_id != 0)
2565 g_source_remove (priv->bus_message_source_id);
2566 priv->bus_message_source_id = 0;
2569 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2572 if (priv->call_state == CONNECTING)
2573 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
2579 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2582 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2584 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2589 gtk_widget_hide (priv->sidebar);
2590 gtk_widget_hide (menu);
2591 gtk_widget_hide (priv->vbox);
2592 gtk_widget_hide (priv->statusbar);
2593 gtk_widget_hide (priv->toolbar);
2597 if (priv->sidebar_was_visible_before_fs)
2598 gtk_widget_show (priv->sidebar);
2600 gtk_widget_show (menu);
2601 gtk_widget_show (priv->vbox);
2602 gtk_widget_show (priv->statusbar);
2603 gtk_widget_show (priv->toolbar);
2605 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2606 priv->original_height_before_fs);
2611 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2613 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2615 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2616 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2617 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2618 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2619 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2620 priv->video_output, TRUE, TRUE,
2621 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2623 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2624 priv->vbox, TRUE, TRUE,
2625 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2630 empathy_call_window_state_event_cb (GtkWidget *widget,
2631 GdkEventWindowState *event, EmpathyCallWindow *window)
2633 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2635 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2636 gboolean set_fullscreen = event->new_window_state &
2637 GDK_WINDOW_STATE_FULLSCREEN;
2641 gboolean sidebar_was_visible;
2642 GtkAllocation allocation;
2643 gint original_width, original_height;
2645 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2646 original_width = allocation.width;
2647 original_height = allocation.height;
2649 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2651 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2652 priv->original_width_before_fs = original_width;
2653 priv->original_height_before_fs = original_height;
2655 if (priv->video_output_motion_handler_id == 0 &&
2656 priv->video_output != NULL)
2658 priv->video_output_motion_handler_id = g_signal_connect (
2659 G_OBJECT (priv->video_output), "motion-notify-event",
2660 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2666 if (priv->video_output_motion_handler_id != 0)
2668 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
2669 priv->video_output_motion_handler_id);
2670 priv->video_output_motion_handler_id = 0;
2674 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2676 show_controls (window, set_fullscreen);
2677 show_borders (window, set_fullscreen);
2678 gtk_action_set_stock_id (priv->menu_fullscreen,
2679 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2680 priv->is_fullscreen = set_fullscreen;
2687 empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
2688 EmpathyCallWindow *window)
2690 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2692 int w, h, handle_size;
2693 GtkAllocation allocation, sidebar_allocation;
2695 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2696 w = allocation.width;
2697 h = allocation.height;
2699 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2701 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
2702 if (gtk_toggle_button_get_active (toggle))
2704 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
2705 gtk_widget_show (priv->sidebar);
2706 w += sidebar_allocation.width + handle_size;
2710 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2711 w -= sidebar_allocation.width + handle_size;
2712 gtk_widget_hide (priv->sidebar);
2715 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
2718 gtk_window_resize (GTK_WINDOW (window), w, h);
2722 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2725 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2726 EmpathyTpCall *call;
2728 priv->sending_video = send;
2730 /* When we start sending video, we want to show the video preview by
2732 display_video_preview (window, send);
2734 if (priv->call_state != CONNECTED)
2737 g_object_get (priv->handler, "tp-call", &call, NULL);
2738 DEBUG ("%s sending video", send ? "start": "stop");
2739 empathy_tp_call_request_video_stream_direction (call, send);
2740 g_object_unref (call);
2744 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2745 EmpathyCallWindow *window)
2747 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2750 active = (gtk_toggle_tool_button_get_active (toggle));
2754 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2756 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
2760 /* TODO, Instead of setting the input volume to 0 we should probably
2761 * stop sending but this would cause the audio call to drop if both
2762 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2763 * in the future. GNOME #574574
2765 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2767 gtk_adjustment_set_value (priv->audio_input_adj, 0);
2772 empathy_call_window_sidebar_hidden_cb (EmpathySidebar *sidebar,
2773 EmpathyCallWindow *window)
2775 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2777 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2782 empathy_call_window_sidebar_shown_cb (EmpathySidebar *sidebar,
2783 EmpathyCallWindow *window)
2785 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2787 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2792 empathy_call_window_hangup_cb (gpointer object,
2793 EmpathyCallWindow *window)
2795 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2797 empathy_call_handler_stop_call (priv->handler);
2799 if (empathy_call_window_disconnected (window, FALSE))
2800 gtk_widget_destroy (GTK_WIDGET (window));
2804 empathy_call_window_restart_call (EmpathyCallWindow *window)
2806 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2808 create_video_output_widget (window);
2810 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
2811 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
2813 /* While the call was disconnected, the input volume might have changed.
2814 * However, since the audio_input source was destroyed, its volume has not
2815 * been updated during that time. That's why we manually update it here */
2816 empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
2818 priv->outgoing = TRUE;
2819 empathy_call_window_set_state_connecting (window);
2821 if (priv->pipeline_playing)
2822 start_call (window);
2824 /* call will be started when the pipeline is ready */
2825 priv->start_call_when_playing = TRUE;
2828 empathy_call_window_setup_avatars (window, priv->handler);
2830 gtk_action_set_sensitive (priv->redial, FALSE);
2831 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2835 empathy_call_window_redial_cb (gpointer object,
2836 EmpathyCallWindow *window)
2838 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2840 if (priv->call_state == CONNECTED)
2841 priv->call_state = REDIALING;
2843 empathy_call_handler_stop_call (priv->handler);
2845 if (priv->call_state != CONNECTED)
2846 empathy_call_window_restart_call (window);
2850 empathy_call_window_fullscreen_cb (gpointer object,
2851 EmpathyCallWindow *window)
2853 empathy_call_window_fullscreen_toggle (window);
2857 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2859 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2861 if (priv->is_fullscreen)
2862 gtk_window_unfullscreen (GTK_WINDOW (window));
2864 gtk_window_fullscreen (GTK_WINDOW (window));
2868 empathy_call_window_video_button_press_cb (GtkWidget *video_output,
2869 GdkEventButton *event, EmpathyCallWindow *window)
2871 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2873 empathy_call_window_video_menu_popup (window, event->button);
2881 empathy_call_window_key_press_cb (GtkWidget *video_output,
2882 GdkEventKey *event, EmpathyCallWindow *window)
2884 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2886 if (priv->is_fullscreen && event->keyval == GDK_Escape)
2888 /* Since we are in fullscreen mode, toggling will bring us back to
2890 empathy_call_window_fullscreen_toggle (window);
2898 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
2899 GdkEventMotion *event, EmpathyCallWindow *window)
2901 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2903 if (priv->is_fullscreen)
2905 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
2912 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
2916 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2918 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2920 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
2921 button, gtk_get_current_event_time ());
2922 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
2926 empathy_call_window_status_message (EmpathyCallWindow *window,
2929 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2931 if (priv->context_id == 0)
2933 priv->context_id = gtk_statusbar_get_context_id (
2934 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
2938 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
2941 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
2946 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
2947 gdouble value, EmpathyCallWindow *window)
2949 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2951 if (priv->audio_output == NULL)
2954 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
2958 /* block all the signals related to camera control widgets. This is useful
2959 * when we are manually updating the UI and so don't want to fire the
2962 block_camera_control_signals (EmpathyCallWindow *self)
2964 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2966 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
2967 tool_button_camera_off_toggled_cb, self);
2968 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
2969 tool_button_camera_preview_toggled_cb, self);
2970 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
2971 tool_button_camera_on_toggled_cb, self);
2972 g_signal_handlers_block_by_func (priv->action_camera,
2973 action_camera_change_cb, self);
2977 unblock_camera_control_signals (EmpathyCallWindow *self)
2979 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2981 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
2982 tool_button_camera_off_toggled_cb, self);
2983 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
2984 tool_button_camera_preview_toggled_cb, self);
2985 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
2986 tool_button_camera_on_toggled_cb, self);
2987 g_signal_handlers_unblock_by_func (priv->action_camera,
2988 action_camera_change_cb, self);