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-farsight/channel.h>
34 #include <gst/farsight/fs-element-added-notifier.h>
36 #include <libempathy/empathy-tp-contact-factory.h>
37 #include <libempathy/empathy-call-factory.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy-gtk/empathy-avatar-image.h>
40 #include <libempathy-gtk/empathy-video-widget.h>
41 #include <libempathy-gtk/empathy-audio-src.h>
42 #include <libempathy-gtk/empathy-audio-sink.h>
43 #include <libempathy-gtk/empathy-video-src.h>
44 #include <libempathy-gtk/empathy-ui-utils.h>
45 #include <libempathy-gtk/empathy-sound.h>
46 #include <libempathy-gtk/empathy-geometry.h>
48 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
49 #include <libempathy/empathy-debug.h>
51 #include "empathy-call-window.h"
52 #include "empathy-call-window-fullscreen.h"
53 #include "empathy-sidebar.h"
55 #define BUTTON_ID "empathy-call-dtmf-button-id"
57 #define CONTENT_HBOX_BORDER_WIDTH 6
58 #define CONTENT_HBOX_SPACING 3
59 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
61 #define SELF_VIDEO_SECTION_WIDTH 160
62 #define SELF_VIDEO_SECTION_HEIGTH 120
64 /* The avatar's default width and height are set to the same value because we
65 want a square icon. */
66 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
67 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
68 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
70 /* If an video input error occurs, the error message will start with "v4l" */
71 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
73 /* The time interval in milliseconds between 2 outgoing rings */
74 #define MS_BETWEEN_RING 500
76 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
85 static guint signals[LAST_SIGNAL] = {0};
89 PROP_CALL_HANDLER = 1,
100 CAMERA_STATE_OFF = 0,
101 CAMERA_STATE_PREVIEW,
105 /* private structure */
106 typedef struct _EmpathyCallWindowPriv EmpathyCallWindowPriv;
108 struct _EmpathyCallWindowPriv
110 gboolean dispose_has_run;
111 EmpathyCallHandler *handler;
112 EmpathyContact *contact;
117 GtkUIManager *ui_manager;
118 GtkWidget *errors_vbox;
119 /* widget displays the video received from the remote user. This widget is
120 * alive only during call. */
121 GtkWidget *video_output;
122 GtkWidget *video_preview;
123 GtkWidget *remote_user_avatar_widget;
124 GtkWidget *self_user_avatar_widget;
126 GtkWidget *sidebar_button;
127 GtkWidget *statusbar;
128 GtkWidget *volume_button;
129 GtkWidget *redial_button;
130 GtkWidget *mic_button;
134 GtkAction *menu_fullscreen;
135 GtkAction *action_camera;
136 GtkAction *action_camera_preview;
137 GtkWidget *tool_button_camera_off;
138 GtkWidget *tool_button_camera_preview;
139 GtkWidget *tool_button_camera_on;
141 /* The frames and boxes that contain self and remote avatar and video
142 input/output. When we redial, we destroy and re-create the boxes */
143 GtkWidget *remote_user_output_frame;
144 GtkWidget *self_user_output_frame;
145 GtkWidget *remote_user_output_hbox;
146 GtkWidget *self_user_output_hbox;
148 /* We keep a reference on the hbox which contains the main content so we can
149 easilly repack everything when toggling fullscreen */
150 GtkWidget *content_hbox;
152 /* This vbox is contained in the content_hbox and it contains the
153 self_user_output_frame and the sidebar button. When toggling fullscreen,
154 it needs to be repacked. We keep a reference on it for easier access. */
157 gulong video_output_motion_handler_id;
158 guint bus_message_source_id;
161 GtkWidget *volume_scale;
162 GtkWidget *volume_progress_bar;
163 GtkAdjustment *audio_input_adj;
165 GtkWidget *dtmf_panel;
167 GstElement *video_input;
168 GstElement *audio_input;
169 GstElement *audio_output;
170 GstElement *pipeline;
171 GstElement *video_tee;
174 GstElement *liveadder;
176 FsElementAddedNotifier *fsnotifier;
183 GtkWidget *video_contrast;
184 GtkWidget *video_brightness;
185 GtkWidget *video_gamma;
188 gboolean call_started;
189 gboolean sending_video;
190 CameraState camera_state;
192 EmpathyCallWindowFullscreen *fullscreen;
193 gboolean is_fullscreen;
195 /* Those fields represent the state of the window before it actually was in
197 gboolean sidebar_was_visible_before_fs;
198 gint original_width_before_fs;
199 gint original_height_before_fs;
202 #define GET_PRIV(o) \
203 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CALL_WINDOW, \
204 EmpathyCallWindowPriv))
206 static void empathy_call_window_realized_cb (GtkWidget *widget,
207 EmpathyCallWindow *window);
209 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
210 GdkEvent *event, EmpathyCallWindow *window);
212 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
213 GdkEventWindowState *event, EmpathyCallWindow *window);
215 static void empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
216 EmpathyCallWindow *window);
218 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
221 static void empathy_call_window_mic_toggled_cb (
222 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
224 static void empathy_call_window_sidebar_hidden_cb (EmpathySidebar *sidebar,
225 EmpathyCallWindow *window);
227 static void empathy_call_window_sidebar_shown_cb (EmpathySidebar *sidebar,
228 EmpathyCallWindow *window);
230 static void empathy_call_window_hangup_cb (gpointer object,
231 EmpathyCallWindow *window);
233 static void empathy_call_window_fullscreen_cb (gpointer object,
234 EmpathyCallWindow *window);
236 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
238 static gboolean empathy_call_window_video_button_press_cb (
239 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
241 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
242 GdkEventKey *event, EmpathyCallWindow *window);
244 static gboolean empathy_call_window_video_output_motion_notify (
245 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
247 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
250 static void empathy_call_window_redial_cb (gpointer object,
251 EmpathyCallWindow *window);
253 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
255 static void empathy_call_window_status_message (EmpathyCallWindow *window,
258 static void empathy_call_window_update_avatars_visibility (EmpathyTpCall *call,
259 EmpathyCallWindow *window);
261 static gboolean empathy_call_window_bus_message (GstBus *bus,
262 GstMessage *message, gpointer user_data);
265 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
266 gdouble value, EmpathyCallWindow *window);
268 static void block_camera_control_signals (EmpathyCallWindow *self);
269 static void unblock_camera_control_signals (EmpathyCallWindow *self);
272 empathy_call_window_setup_toolbar (EmpathyCallWindow *self)
274 EmpathyCallWindowPriv *priv = GET_PRIV (self);
275 GtkToolItem *tool_item;
276 GtkWidget *camera_off_icon;
277 GdkPixbuf *pixbuf, *modded_pixbuf;
279 /* set the icon of the 'camera off' button by greying off the webcam icon */
280 pixbuf = empathy_pixbuf_from_icon_name ("camera-web",
281 GTK_ICON_SIZE_SMALL_TOOLBAR);
283 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
284 gdk_pixbuf_get_width (pixbuf),
285 gdk_pixbuf_get_height (pixbuf));
287 gdk_pixbuf_saturate_and_pixelate (pixbuf, modded_pixbuf, 1.0, TRUE);
288 g_object_unref (pixbuf);
290 camera_off_icon = gtk_image_new_from_pixbuf (modded_pixbuf);
291 g_object_unref (modded_pixbuf);
292 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (
293 priv->tool_button_camera_off), camera_off_icon);
295 /* Add an empty expanded GtkToolItem so the volume button is at the end of
297 tool_item = gtk_tool_item_new ();
298 gtk_tool_item_set_expand (tool_item, TRUE);
299 gtk_widget_show (GTK_WIDGET (tool_item));
300 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
302 priv->volume_button = gtk_volume_button_new ();
303 /* FIXME listen to the audiosinks signals and update the button according to
304 * that, for now starting out at 1.0 and assuming only the app changes the
306 gtk_scale_button_set_value (GTK_SCALE_BUTTON (priv->volume_button), 1.0);
307 g_signal_connect (G_OBJECT (priv->volume_button), "value-changed",
308 G_CALLBACK (empathy_call_window_volume_changed_cb), self);
310 tool_item = gtk_tool_item_new ();
311 gtk_container_add (GTK_CONTAINER (tool_item), priv->volume_button);
312 gtk_widget_show_all (GTK_WIDGET (tool_item));
313 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
317 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
319 EmpathyCallWindowPriv *priv = GET_PRIV (window);
324 g_object_get (priv->handler, "tp-call", &call, NULL);
326 button_quark = g_quark_from_static_string (BUTTON_ID);
327 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
330 empathy_tp_call_start_tone (call, event);
332 g_object_unref (call);
336 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
338 EmpathyCallWindowPriv *priv = GET_PRIV (window);
341 g_object_get (priv->handler, "tp-call", &call, NULL);
343 empathy_tp_call_stop_tone (call);
345 g_object_unref (call);
349 empathy_call_window_create_dtmf (EmpathyCallWindow *self)
357 } dtmfbuttons[] = { { "1", TP_DTMF_EVENT_DIGIT_1 },
358 { "2", TP_DTMF_EVENT_DIGIT_2 },
359 { "3", TP_DTMF_EVENT_DIGIT_3 },
360 { "4", TP_DTMF_EVENT_DIGIT_4 },
361 { "5", TP_DTMF_EVENT_DIGIT_5 },
362 { "6", TP_DTMF_EVENT_DIGIT_6 },
363 { "7", TP_DTMF_EVENT_DIGIT_7 },
364 { "8", TP_DTMF_EVENT_DIGIT_8 },
365 { "9", TP_DTMF_EVENT_DIGIT_9 },
366 { "#", TP_DTMF_EVENT_HASH },
367 { "0", TP_DTMF_EVENT_DIGIT_0 },
368 { "*", TP_DTMF_EVENT_ASTERISK },
371 button_quark = g_quark_from_static_string (BUTTON_ID);
373 table = gtk_table_new (4, 3, TRUE);
375 for (i = 0; dtmfbuttons[i].label != NULL; i++)
377 GtkWidget *button = gtk_button_new_with_label (dtmfbuttons[i].label);
378 gtk_table_attach (GTK_TABLE (table), button, i % 3, i % 3 + 1,
379 i/3, i/3 + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1);
381 g_object_set_qdata (G_OBJECT (button), button_quark,
382 GUINT_TO_POINTER (dtmfbuttons[i].event));
384 g_signal_connect (G_OBJECT (button), "pressed",
385 G_CALLBACK (dtmf_button_pressed_cb), self);
386 g_signal_connect (G_OBJECT (button), "released",
387 G_CALLBACK (dtmf_button_released_cb), self);
394 empathy_call_window_create_video_input_add_slider (EmpathyCallWindow *self,
395 gchar *label_text, GtkWidget *bin)
397 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
398 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
399 GtkWidget *label = gtk_label_new (label_text);
401 gtk_widget_set_sensitive (scale, FALSE);
403 gtk_container_add (GTK_CONTAINER (bin), vbox);
405 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
406 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
407 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
413 empathy_call_window_video_contrast_changed_cb (GtkAdjustment *adj,
414 EmpathyCallWindow *self)
417 EmpathyCallWindowPriv *priv = GET_PRIV (self);
419 empathy_video_src_set_channel (priv->video_input,
420 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
424 empathy_call_window_video_brightness_changed_cb (GtkAdjustment *adj,
425 EmpathyCallWindow *self)
428 EmpathyCallWindowPriv *priv = GET_PRIV (self);
430 empathy_video_src_set_channel (priv->video_input,
431 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
435 empathy_call_window_video_gamma_changed_cb (GtkAdjustment *adj,
436 EmpathyCallWindow *self)
439 EmpathyCallWindowPriv *priv = GET_PRIV (self);
441 empathy_video_src_set_channel (priv->video_input,
442 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
447 empathy_call_window_create_video_input (EmpathyCallWindow *self)
449 EmpathyCallWindowPriv *priv = GET_PRIV (self);
452 hbox = gtk_hbox_new (TRUE, 3);
454 priv->video_contrast = empathy_call_window_create_video_input_add_slider (
455 self, _("Contrast"), hbox);
457 priv->video_brightness = empathy_call_window_create_video_input_add_slider (
458 self, _("Brightness"), hbox);
460 priv->video_gamma = empathy_call_window_create_video_input_add_slider (
461 self, _("Gamma"), hbox);
467 empathy_call_window_setup_video_input (EmpathyCallWindow *self)
469 EmpathyCallWindowPriv *priv = GET_PRIV (self);
473 supported = empathy_video_src_get_supported_channels (priv->video_input);
475 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
477 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
479 gtk_adjustment_set_value (adj,
480 empathy_video_src_get_channel (priv->video_input,
481 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
483 g_signal_connect (G_OBJECT (adj), "value-changed",
484 G_CALLBACK (empathy_call_window_video_contrast_changed_cb), self);
486 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
489 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
491 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
493 gtk_adjustment_set_value (adj,
494 empathy_video_src_get_channel (priv->video_input,
495 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
497 g_signal_connect (G_OBJECT (adj), "value-changed",
498 G_CALLBACK (empathy_call_window_video_brightness_changed_cb), self);
499 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
502 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
504 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
506 gtk_adjustment_set_value (adj,
507 empathy_video_src_get_channel (priv->video_input,
508 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
510 g_signal_connect (G_OBJECT (adj), "value-changed",
511 G_CALLBACK (empathy_call_window_video_gamma_changed_cb), self);
512 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
517 empathy_call_window_mic_volume_changed_cb (GtkAdjustment *adj,
518 EmpathyCallWindow *self)
520 EmpathyCallWindowPriv *priv = GET_PRIV (self);
523 volume = gtk_adjustment_get_value (adj)/100.0;
525 /* Don't store the volume because of muting */
526 if (volume > 0 || gtk_toggle_tool_button_get_active (
527 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
528 priv->volume = volume;
530 /* Ensure that the toggle button is active if the volume is > 0 and inactive
531 * if it's smaller than 0 */
532 if ((volume > 0) != gtk_toggle_tool_button_get_active (
533 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
534 gtk_toggle_tool_button_set_active (
535 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
537 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
542 empathy_call_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
543 gdouble level, EmpathyCallWindow *window)
546 EmpathyCallWindowPriv *priv = GET_PRIV (window);
548 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
549 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
554 empathy_call_window_create_audio_input (EmpathyCallWindow *self)
556 EmpathyCallWindowPriv *priv = GET_PRIV (self);
557 GtkWidget *hbox, *vbox, *label;
559 hbox = gtk_hbox_new (TRUE, 3);
561 vbox = gtk_vbox_new (FALSE, 3);
562 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
564 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
565 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
566 label = gtk_label_new (_("Volume"));
568 priv->audio_input_adj = gtk_range_get_adjustment (
569 GTK_RANGE (priv->volume_scale));
570 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
571 (priv->audio_input));
572 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
574 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
575 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), self);
577 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
578 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
580 priv->volume_progress_bar = gtk_progress_bar_new ();
581 gtk_progress_bar_set_orientation (
582 GTK_PROGRESS_BAR (priv->volume_progress_bar),
583 GTK_PROGRESS_BOTTOM_TO_TOP);
584 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
587 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
594 create_video_output_widget (EmpathyCallWindow *self)
596 EmpathyCallWindowPriv *priv = GET_PRIV (self);
599 g_assert (priv->video_output == NULL);
600 g_assert (priv->pipeline != NULL);
602 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
603 priv->video_output = empathy_video_widget_new (bus);
605 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
606 priv->video_output, TRUE, TRUE, 0);
608 gtk_widget_add_events (priv->video_output,
609 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
610 g_signal_connect (G_OBJECT (priv->video_output), "button-press-event",
611 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
613 g_object_unref (bus);
617 create_audio_output (EmpathyCallWindow *self)
619 EmpathyCallWindowPriv *priv = GET_PRIV (self);
621 g_assert (priv->audio_output == NULL);
622 priv->audio_output = empathy_audio_sink_new ();
623 gst_object_ref (priv->audio_output);
624 gst_object_sink (priv->audio_output);
628 create_video_input (EmpathyCallWindow *self)
630 EmpathyCallWindowPriv *priv = GET_PRIV (self);
632 g_assert (priv->video_input == NULL);
633 priv->video_input = empathy_video_src_new ();
634 gst_object_ref (priv->video_input);
635 gst_object_sink (priv->video_input);
639 create_audio_input (EmpathyCallWindow *self)
641 EmpathyCallWindowPriv *priv = GET_PRIV (self);
643 g_assert (priv->audio_input == NULL);
644 priv->audio_input = empathy_audio_src_new ();
645 gst_object_ref (priv->audio_input);
646 gst_object_sink (priv->audio_input);
648 empathy_signal_connect_weak (priv->audio_input, "peak-level-changed",
649 G_CALLBACK (empathy_call_window_audio_input_level_changed_cb),
654 add_video_preview_to_pipeline (EmpathyCallWindow *self)
656 EmpathyCallWindowPriv *priv = GET_PRIV (self);
659 g_assert (priv->video_preview != NULL);
660 g_assert (priv->pipeline != NULL);
661 g_assert (priv->video_input != NULL);
662 g_assert (priv->video_tee != NULL);
664 preview = empathy_video_widget_get_element (
665 EMPATHY_VIDEO_WIDGET (priv->video_preview));
666 gst_bin_add_many (GST_BIN (priv->pipeline), priv->video_input,
667 priv->video_tee, preview, NULL);
668 gst_element_link_many (priv->video_input, priv->video_tee,
673 create_video_preview (EmpathyCallWindow *self)
675 EmpathyCallWindowPriv *priv = GET_PRIV (self);
678 g_assert (priv->video_preview == NULL);
679 g_assert (priv->video_tee == NULL);
681 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
683 priv->video_preview = empathy_video_widget_new_with_size (bus,
684 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
685 g_object_set (priv->video_preview, "sync", FALSE, "async", TRUE, NULL);
687 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
688 priv->video_preview, TRUE, TRUE, 0);
690 priv->video_tee = gst_element_factory_make ("tee", NULL);
691 gst_object_ref (priv->video_tee);
692 gst_object_sink (priv->video_tee);
694 g_object_unref (bus);
698 play_camera (EmpathyCallWindow *window,
701 EmpathyCallWindowPriv *priv = GET_PRIV (window);
705 if (priv->video_preview == NULL)
707 create_video_preview (window);
708 add_video_preview_to_pipeline (window);
712 state = GST_STATE_PLAYING;
714 state = GST_STATE_NULL;
716 preview = empathy_video_widget_get_element (
717 EMPATHY_VIDEO_WIDGET (priv->video_preview));
719 gst_element_set_state (preview, state);
720 gst_element_set_state (priv->video_input, state);
721 gst_element_set_state (priv->video_tee, state);
725 display_video_preview (EmpathyCallWindow *self,
728 EmpathyCallWindowPriv *priv = GET_PRIV (self);
732 /* Display the preview and hide the self avatar */
733 DEBUG ("Show video preview");
735 play_camera (self, TRUE);
736 gtk_widget_show (priv->video_preview);
737 gtk_widget_hide (priv->self_user_avatar_widget);
741 /* Display the self avatar and hide the preview */
742 DEBUG ("Show self avatar");
744 if (priv->video_preview != NULL)
745 gtk_widget_hide (priv->video_preview);
746 play_camera (self, FALSE);
747 gtk_widget_show (priv->self_user_avatar_widget);
752 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
754 EmpathyCallWindowPriv *priv = GET_PRIV (window);
756 empathy_call_window_status_message (window, _("Connecting…"));
757 priv->call_state = CONNECTING;
760 empathy_sound_start_playing (GTK_WIDGET (window),
761 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
765 disable_camera (EmpathyCallWindow *self)
767 EmpathyCallWindowPriv *priv = GET_PRIV (self);
769 if (priv->camera_state == CAMERA_STATE_OFF)
772 DEBUG ("Disable camera");
774 display_video_preview (self, FALSE);
776 if (priv->camera_state == CAMERA_STATE_ON)
777 empathy_call_window_set_send_video (self, FALSE);
779 block_camera_control_signals (self);
780 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
781 priv->tool_button_camera_on), FALSE);
782 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
783 priv->tool_button_camera_preview), FALSE);
785 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
786 priv->tool_button_camera_off), TRUE);
787 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
789 unblock_camera_control_signals (self);
791 priv->camera_state = CAMERA_STATE_OFF;
795 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
796 EmpathyCallWindow *self)
798 EmpathyCallWindowPriv *priv = GET_PRIV (self);
800 if (!gtk_toggle_tool_button_get_active (toggle))
802 if (priv->camera_state == CAMERA_STATE_OFF)
804 /* We can't change the state by disabling the button */
805 block_camera_control_signals (self);
806 gtk_toggle_tool_button_set_active (toggle, TRUE);
807 unblock_camera_control_signals (self);
813 disable_camera (self);
817 enable_preview (EmpathyCallWindow *self)
819 EmpathyCallWindowPriv *priv = GET_PRIV (self);
821 if (priv->camera_state == CAMERA_STATE_PREVIEW)
824 DEBUG ("Enable preview");
826 if (priv->camera_state == CAMERA_STATE_ON)
827 /* preview is already displayed so we just have to stop sending */
828 empathy_call_window_set_send_video (self, FALSE);
830 display_video_preview (self, TRUE);
832 block_camera_control_signals (self);
833 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
834 priv->tool_button_camera_off), FALSE);
835 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
836 priv->tool_button_camera_on), FALSE);
838 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
839 priv->tool_button_camera_preview), TRUE);
840 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
841 CAMERA_STATE_PREVIEW);
842 unblock_camera_control_signals (self);
844 priv->camera_state = CAMERA_STATE_PREVIEW;
848 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
849 EmpathyCallWindow *self)
851 EmpathyCallWindowPriv *priv = GET_PRIV (self);
853 if (!gtk_toggle_tool_button_get_active (toggle))
855 if (priv->camera_state == CAMERA_STATE_PREVIEW)
857 /* We can't change the state by disabling the button */
858 block_camera_control_signals (self);
859 gtk_toggle_tool_button_set_active (toggle, TRUE);
860 unblock_camera_control_signals (self);
866 enable_preview (self);
870 enable_camera (EmpathyCallWindow *self)
872 EmpathyCallWindowPriv *priv = GET_PRIV (self);
874 if (priv->camera_state == CAMERA_STATE_ON)
877 DEBUG ("Enable camera");
879 empathy_call_window_set_send_video (self, TRUE);
881 block_camera_control_signals (self);
882 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
883 priv->tool_button_camera_off), FALSE);
884 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
885 priv->tool_button_camera_preview), FALSE);
887 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
888 priv->tool_button_camera_on), TRUE);
889 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera),
891 unblock_camera_control_signals (self);
893 priv->camera_state = CAMERA_STATE_ON;
897 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
898 EmpathyCallWindow *self)
900 EmpathyCallWindowPriv *priv = GET_PRIV (self);
902 if (!gtk_toggle_tool_button_get_active (toggle))
904 if (priv->camera_state == CAMERA_STATE_ON)
906 /* We can't change the state by disabling the button */
907 block_camera_control_signals (self);
908 gtk_toggle_tool_button_set_active (toggle, TRUE);
909 unblock_camera_control_signals (self);
915 enable_camera (self);
919 action_camera_change_cb (GtkRadioAction *action,
920 GtkRadioAction *current,
921 EmpathyCallWindow *self)
925 state = gtk_radio_action_get_current_value (current);
929 case CAMERA_STATE_OFF:
930 disable_camera (self);
933 case CAMERA_STATE_PREVIEW:
934 enable_preview (self);
937 case CAMERA_STATE_ON:
938 enable_camera (self);
942 g_assert_not_reached ();
947 create_pipeline (EmpathyCallWindow *self)
949 EmpathyCallWindowPriv *priv = GET_PRIV (self);
952 g_assert (priv->pipeline == NULL);
954 priv->pipeline = gst_pipeline_new (NULL);
955 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
956 priv->bus_message_source_id = gst_bus_add_watch (bus,
957 empathy_call_window_bus_message, self);
959 g_object_unref (bus);
964 empathy_call_window_init (EmpathyCallWindow *self)
966 EmpathyCallWindowPriv *priv = GET_PRIV (self);
974 GError *error = NULL;
976 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
977 gui = empathy_builder_get_file (filename,
978 "call_window_vbox", &top_vbox,
979 "errors_vbox", &priv->errors_vbox,
981 "statusbar", &priv->statusbar,
982 "redial", &priv->redial_button,
983 "microphone", &priv->mic_button,
984 "toolbar", &priv->toolbar,
985 "menuredial", &priv->redial,
986 "ui_manager", &priv->ui_manager,
987 "menufullscreen", &priv->menu_fullscreen,
988 "camera_off", &priv->tool_button_camera_off,
989 "camera_preview", &priv->tool_button_camera_preview,
990 "camera_on", &priv->tool_button_camera_on,
991 "action_camera_off", &priv->action_camera,
992 "action_camera_preview", &priv->action_camera_preview,
996 empathy_builder_connect (gui, self,
997 "menuhangup", "activate", empathy_call_window_hangup_cb,
998 "hangup", "clicked", empathy_call_window_hangup_cb,
999 "menuredial", "activate", empathy_call_window_redial_cb,
1000 "redial", "clicked", empathy_call_window_redial_cb,
1001 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1002 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1003 "camera_off", "toggled", tool_button_camera_off_toggled_cb,
1004 "camera_preview", "toggled", tool_button_camera_preview_toggled_cb,
1005 "camera_on", "toggled", tool_button_camera_on_toggled_cb,
1006 "action_camera_off", "changed", action_camera_change_cb,
1009 priv->lock = g_mutex_new ();
1011 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1013 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1014 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1015 CONTENT_HBOX_BORDER_WIDTH);
1016 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1018 /* remote user output frame */
1019 priv->remote_user_output_frame = gtk_frame_new (NULL);
1020 gtk_widget_set_size_request (priv->remote_user_output_frame,
1021 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1022 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1023 priv->remote_user_output_frame, TRUE, TRUE,
1024 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1026 priv->remote_user_output_hbox = gtk_hbox_new (FALSE, 0);
1028 priv->remote_user_avatar_widget = gtk_image_new ();
1030 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1031 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1033 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1034 priv->remote_user_output_hbox);
1036 /* self user output frame */
1037 priv->self_user_output_frame = gtk_frame_new (NULL);
1038 gtk_widget_set_size_request (priv->self_user_output_frame,
1039 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1041 priv->self_user_output_hbox = gtk_hbox_new (FALSE, 0);
1043 priv->self_user_avatar_widget = gtk_image_new ();
1044 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1045 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1047 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1048 priv->self_user_output_hbox);
1050 create_pipeline (self);
1051 create_video_output_widget (self);
1052 create_audio_input (self);
1053 create_audio_output (self);
1054 create_video_input (self);
1056 priv->fsnotifier = fs_element_added_notifier_new ();
1057 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1059 keyfile = g_key_file_new ();
1060 filename = empathy_file_lookup ("element-properties", "data");
1061 if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error))
1063 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1068 g_warning ("Could not load element-properties file: %s", error->message);
1069 g_key_file_free (keyfile);
1070 g_clear_error (&error);
1074 priv->vbox = gtk_vbox_new (FALSE, 3);
1075 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1076 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1077 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1080 empathy_call_window_setup_toolbar (self);
1082 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1083 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1084 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1085 G_CALLBACK (empathy_call_window_sidebar_toggled_cb), self);
1087 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1089 h = gtk_hbox_new (FALSE, 3);
1090 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1091 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1093 priv->sidebar = empathy_sidebar_new ();
1094 g_signal_connect (G_OBJECT (priv->sidebar),
1095 "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb), self);
1096 g_signal_connect (G_OBJECT (priv->sidebar),
1097 "show", G_CALLBACK (empathy_call_window_sidebar_shown_cb), self);
1098 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1100 page = empathy_call_window_create_audio_input (self);
1101 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Audio input"),
1104 page = empathy_call_window_create_video_input (self);
1105 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Video input"),
1108 priv->dtmf_panel = empathy_call_window_create_dtmf (self);
1109 empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Dialpad"),
1112 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1115 gtk_widget_show_all (top_vbox);
1117 gtk_widget_hide (priv->sidebar);
1119 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1120 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1121 priv->video_output);
1122 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1123 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1125 g_signal_connect (G_OBJECT (self), "realize",
1126 G_CALLBACK (empathy_call_window_realized_cb), self);
1128 g_signal_connect (G_OBJECT (self), "delete-event",
1129 G_CALLBACK (empathy_call_window_delete_cb), self);
1131 g_signal_connect (G_OBJECT (self), "window-state-event",
1132 G_CALLBACK (empathy_call_window_state_event_cb), self);
1134 g_signal_connect (G_OBJECT (self), "key-press-event",
1135 G_CALLBACK (empathy_call_window_key_press_cb), self);
1137 priv->timer = g_timer_new ();
1139 g_object_ref (priv->ui_manager);
1140 g_object_unref (gui);
1142 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1145 /* Instead of specifying a width and a height, we specify only one size. That's
1146 because we want a square avatar icon. */
1148 init_contact_avatar_with_size (EmpathyContact *contact,
1149 GtkWidget *image_widget,
1152 GdkPixbuf *pixbuf_avatar = NULL;
1154 if (contact != NULL)
1156 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1160 if (pixbuf_avatar == NULL)
1162 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized ("stock_person",
1166 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1170 set_window_title (EmpathyCallWindow *self)
1172 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1175 /* translators: Call is a noun and %s is the contact name. This string
1176 * is used in the window title */
1177 tmp = g_strdup_printf (_("Call with %s"),
1178 empathy_contact_get_name (priv->contact));
1179 gtk_window_set_title (GTK_WINDOW (self), tmp);
1184 contact_name_changed_cb (EmpathyContact *contact,
1185 GParamSpec *pspec, EmpathyCallWindow *self)
1187 set_window_title (self);
1191 contact_avatar_changed_cb (EmpathyContact *contact,
1192 GParamSpec *pspec, GtkWidget *avatar_widget)
1196 size = avatar_widget->allocation.height;
1200 /* the widget is not allocated yet, set a default size */
1201 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1202 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1205 init_contact_avatar_with_size (contact, avatar_widget, size);
1209 empathy_call_window_got_self_contact_cb (EmpathyTpContactFactory *factory,
1210 EmpathyContact *contact, const GError *error, gpointer user_data,
1211 GObject *weak_object)
1213 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1214 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1216 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1217 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1219 g_signal_connect (contact, "notify::avatar",
1220 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1224 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1225 EmpathyCallHandler *handler)
1227 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1229 g_object_get (handler, "contact", &(priv->contact), NULL);
1231 if (priv->contact != NULL)
1233 TpConnection *connection;
1234 EmpathyTpContactFactory *factory;
1236 set_window_title (self);
1238 g_signal_connect (priv->contact, "notify::name",
1239 G_CALLBACK (contact_name_changed_cb), self);
1240 g_signal_connect (priv->contact, "notify::avatar",
1241 G_CALLBACK (contact_avatar_changed_cb),
1242 priv->remote_user_avatar_widget);
1244 /* Retreiving the self avatar */
1245 connection = empathy_contact_get_connection (priv->contact);
1246 factory = empathy_tp_contact_factory_dup_singleton (connection);
1247 empathy_tp_contact_factory_get_from_handle (factory,
1248 tp_connection_get_self_handle (connection),
1249 empathy_call_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1251 g_object_unref (factory);
1255 g_warning ("call handler doesn't have a contact");
1256 /* translators: Call is a noun. This string is used in the window
1258 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1260 /* Since we can't access the remote contact, we can't get a connection
1261 to it and can't get the self contact (and its avatar). This means
1262 that we have to manually set the self avatar. */
1263 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1264 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1267 init_contact_avatar_with_size (priv->contact,
1268 priv->remote_user_avatar_widget,
1269 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1270 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1272 /* The remote avatar is shown by default and will be hidden when we receive
1273 video from the remote side. */
1274 gtk_widget_hide (priv->video_output);
1275 gtk_widget_show (priv->remote_user_avatar_widget);
1279 empathy_call_window_constructed (GObject *object)
1281 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1282 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1283 EmpathyTpCall *call;
1285 g_assert (priv->handler != NULL);
1287 g_object_get (priv->handler, "tp-call", &call, NULL);
1288 priv->outgoing = (call == NULL);
1290 g_object_unref (call);
1292 empathy_call_window_setup_avatars (self, priv->handler);
1293 empathy_call_window_set_state_connecting (self);
1295 if (!empathy_call_handler_has_initial_video (priv->handler))
1297 gtk_toggle_tool_button_set_active (
1298 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1300 /* If call has InitialVideo, the preview will be started once the call has
1301 * been started (start_call()). */
1304 static void empathy_call_window_dispose (GObject *object);
1305 static void empathy_call_window_finalize (GObject *object);
1308 empathy_call_window_set_property (GObject *object,
1309 guint property_id, const GValue *value, GParamSpec *pspec)
1311 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1313 switch (property_id)
1315 case PROP_CALL_HANDLER:
1316 priv->handler = g_value_dup_object (value);
1319 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1324 empathy_call_window_get_property (GObject *object,
1325 guint property_id, GValue *value, GParamSpec *pspec)
1327 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1329 switch (property_id)
1331 case PROP_CALL_HANDLER:
1332 g_value_set_object (value, priv->handler);
1335 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1340 empathy_call_window_class_init (
1341 EmpathyCallWindowClass *empathy_call_window_class)
1343 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1344 GParamSpec *param_spec;
1346 g_type_class_add_private (empathy_call_window_class,
1347 sizeof (EmpathyCallWindowPriv));
1349 object_class->constructed = empathy_call_window_constructed;
1350 object_class->set_property = empathy_call_window_set_property;
1351 object_class->get_property = empathy_call_window_get_property;
1353 object_class->dispose = empathy_call_window_dispose;
1354 object_class->finalize = empathy_call_window_finalize;
1356 param_spec = g_param_spec_object ("handler",
1357 "handler", "The call handler",
1358 EMPATHY_TYPE_CALL_HANDLER,
1359 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1360 g_object_class_install_property (object_class,
1361 PROP_CALL_HANDLER, param_spec);
1365 empathy_call_window_video_stream_changed_cb (EmpathyTpCall *call,
1366 GParamSpec *property, EmpathyCallWindow *self)
1368 DEBUG ("video stream changed");
1369 empathy_call_window_update_avatars_visibility (call, self);
1373 empathy_call_window_dispose (GObject *object)
1375 EmpathyTpCall *call;
1376 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1377 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1379 if (priv->dispose_has_run)
1382 priv->dispose_has_run = TRUE;
1384 g_object_get (priv->handler, "tp-call", &call, NULL);
1388 g_signal_handlers_disconnect_by_func (call,
1389 empathy_call_window_video_stream_changed_cb, object);
1390 g_object_unref (call);
1393 if (priv->handler != NULL)
1395 empathy_call_handler_stop_call (priv->handler);
1396 g_object_unref (priv->handler);
1398 priv->handler = NULL;
1400 if (priv->pipeline != NULL)
1401 g_object_unref (priv->pipeline);
1402 priv->pipeline = NULL;
1404 if (priv->video_input != NULL)
1405 g_object_unref (priv->video_input);
1406 priv->video_input = NULL;
1408 if (priv->audio_input != NULL)
1409 g_object_unref (priv->audio_input);
1410 priv->audio_input = NULL;
1412 if (priv->audio_output != NULL)
1413 g_object_unref (priv->audio_output);
1414 priv->audio_output = NULL;
1416 if (priv->video_tee != NULL)
1417 g_object_unref (priv->video_tee);
1418 priv->video_tee = NULL;
1420 if (priv->fsnotifier != NULL)
1421 g_object_unref (priv->fsnotifier);
1422 priv->fsnotifier = NULL;
1424 if (priv->timer_id != 0)
1425 g_source_remove (priv->timer_id);
1428 if (priv->ui_manager != NULL)
1429 g_object_unref (priv->ui_manager);
1430 priv->ui_manager = NULL;
1432 if (priv->contact != NULL)
1434 g_signal_handlers_disconnect_by_func (priv->contact,
1435 contact_name_changed_cb, self);
1436 g_object_unref (priv->contact);
1437 priv->contact = NULL;
1440 /* release any references held by the object here */
1441 if (G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose)
1442 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1446 empathy_call_window_finalize (GObject *object)
1448 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1449 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1451 if (priv->video_output_motion_handler_id != 0)
1453 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1454 priv->video_output_motion_handler_id);
1455 priv->video_output_motion_handler_id = 0;
1458 if (priv->bus_message_source_id != 0)
1460 g_source_remove (priv->bus_message_source_id);
1461 priv->bus_message_source_id = 0;
1464 /* free any data held directly by the object here */
1465 g_mutex_free (priv->lock);
1467 g_timer_destroy (priv->timer);
1469 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1474 empathy_call_window_new (EmpathyCallHandler *handler)
1476 return EMPATHY_CALL_WINDOW (
1477 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1481 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1482 GstElement *conference, gpointer user_data)
1484 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1485 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1487 gst_bin_add (GST_BIN (priv->pipeline), conference);
1489 gst_element_set_state (conference, GST_STATE_PLAYING);
1493 empathy_call_window_request_resource_cb (EmpathyCallHandler *handler,
1494 FsMediaType type, FsStreamDirection direction, gpointer user_data)
1496 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1497 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1499 if (type != FS_MEDIA_TYPE_VIDEO)
1502 if (direction == FS_DIRECTION_RECV)
1505 /* video and direction is send */
1506 return priv->video_input != NULL;
1510 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1512 GstStateChangeReturn state_change_return;
1513 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1515 if (priv->pipeline == NULL)
1518 if (priv->bus_message_source_id != 0)
1520 g_source_remove (priv->bus_message_source_id);
1521 priv->bus_message_source_id = 0;
1524 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1526 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1527 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1529 if (priv->pipeline != NULL)
1530 g_object_unref (priv->pipeline);
1531 priv->pipeline = NULL;
1533 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1534 empathy_call_window_mic_volume_changed_cb, self);
1536 if (priv->video_tee != NULL)
1537 g_object_unref (priv->video_tee);
1538 priv->video_tee = NULL;
1540 if (priv->video_preview != NULL)
1541 gtk_widget_destroy (priv->video_preview);
1542 priv->video_preview = NULL;
1544 priv->liveadder = NULL;
1545 priv->funnel = NULL;
1547 create_pipeline (self);
1553 g_message ("Error: could not destroy pipeline. Closing call window");
1554 gtk_widget_destroy (GTK_WIDGET (self));
1561 empathy_call_window_disconnected (EmpathyCallWindow *self)
1563 gboolean could_disconnect = FALSE;
1564 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1565 gboolean could_reset_pipeline;
1567 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1569 if (priv->call_state == CONNECTING)
1570 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
1572 if (priv->call_state != REDIALING)
1573 priv->call_state = DISCONNECTED;
1575 if (could_reset_pipeline)
1577 g_mutex_lock (priv->lock);
1579 g_timer_stop (priv->timer);
1581 if (priv->timer_id != 0)
1582 g_source_remove (priv->timer_id);
1585 g_mutex_unlock (priv->lock);
1587 empathy_call_window_status_message (self, _("Disconnected"));
1589 gtk_action_set_sensitive (priv->redial, TRUE);
1590 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1592 /* Reseting the send_video, camera_buton and mic_button to their
1594 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1595 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1596 gtk_toggle_tool_button_set_active (
1597 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1598 gtk_toggle_tool_button_set_active (
1599 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1601 gtk_progress_bar_set_fraction (
1602 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1604 /* destroy the video output; it will be recreated when we'll redial */
1605 gtk_widget_destroy (priv->video_output);
1606 priv->video_output = NULL;
1608 gtk_widget_show (priv->remote_user_avatar_widget);
1610 priv->sending_video = FALSE;
1611 priv->call_started = FALSE;
1613 could_disconnect = TRUE;
1615 /* TODO: display the self avatar of the preview (depends if the "Always
1616 * Show Video Preview" is enabled or not) */
1619 return could_disconnect;
1624 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1627 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1628 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1630 if (empathy_call_window_disconnected (self) && priv->call_state == REDIALING)
1631 empathy_call_window_restart_call (self);
1636 empathy_call_window_channel_stream_closed_cb (EmpathyCallHandler *handler,
1637 TfStream *stream, gpointer user_data)
1639 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1640 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1643 g_object_get (stream, "media-type", &media_type, NULL);
1646 * This assumes that there is only one video stream per channel...
1649 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
1651 if (priv->funnel != NULL)
1655 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1656 (priv->video_output));
1658 gst_element_set_state (output, GST_STATE_NULL);
1659 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1661 gst_bin_remove (GST_BIN (priv->pipeline), output);
1662 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1663 priv->funnel = NULL;
1666 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
1668 if (priv->liveadder != NULL)
1670 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1671 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
1673 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1674 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
1675 priv->liveadder = NULL;
1680 /* Called with global lock held */
1682 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1684 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1688 if (priv->funnel == NULL)
1690 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1691 (priv->video_output));
1693 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1697 g_warning ("Could not create fsfunnel");
1701 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1703 gst_object_unref (priv->funnel);
1704 priv->funnel = NULL;
1705 g_warning ("Could not add funnel to pipeline");
1709 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1711 g_warning ("Could not add the video output widget to the pipeline");
1715 if (!gst_element_link (priv->funnel, output))
1717 g_warning ("Could not link output sink to funnel");
1718 goto error_output_added;
1721 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1723 g_warning ("Could not start video sink");
1724 goto error_output_added;
1727 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1729 g_warning ("Could not start funnel");
1730 goto error_output_added;
1734 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1737 g_warning ("Could not get request pad from funnel");
1744 gst_element_set_locked_state (priv->funnel, TRUE);
1745 gst_element_set_locked_state (output, TRUE);
1747 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1748 gst_element_set_state (output, GST_STATE_NULL);
1750 gst_bin_remove (GST_BIN (priv->pipeline), output);
1751 gst_element_set_locked_state (output, FALSE);
1755 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1756 priv->funnel = NULL;
1761 /* Called with global lock held */
1763 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1765 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1768 GError *gerror = NULL;
1770 if (priv->liveadder == NULL)
1772 priv->liveadder = gst_element_factory_make ("liveadder", NULL);
1774 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->liveadder))
1776 g_warning ("Could not add liveadder to the pipeline");
1777 goto error_add_liveadder;
1779 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1781 g_warning ("Could not add audio sink to pipeline");
1782 goto error_add_output;
1785 if (gst_element_set_state (priv->liveadder, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1787 g_warning ("Could not start liveadder");
1791 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1793 g_warning ("Could not start audio sink");
1797 if (GST_PAD_LINK_FAILED (
1798 gst_element_link (priv->liveadder, priv->audio_output)))
1800 g_warning ("Could not link liveadder to audio output");
1805 filter = gst_parse_bin_from_description (
1806 "audioconvert ! audioresample ! audioconvert", TRUE, &gerror);
1809 g_warning ("Could not make audio conversion filter: %s", gerror->message);
1810 g_clear_error (&gerror);
1814 if (!gst_bin_add (GST_BIN (priv->pipeline), filter))
1816 g_warning ("Could not add audio conversion filter to pipeline");
1817 gst_object_unref (filter);
1821 if (gst_element_set_state (filter, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1823 g_warning ("Could not start audio conversion filter");
1827 if (!gst_element_link (filter, priv->liveadder))
1829 g_warning ("Could not link audio conversion filter to liveadder");
1833 pad = gst_element_get_static_pad (filter, "sink");
1837 g_warning ("Could not get sink pad from filter");
1845 gst_element_set_locked_state (filter, TRUE);
1846 gst_element_set_state (filter, GST_STATE_NULL);
1847 gst_bin_remove (GST_BIN (priv->pipeline), filter);
1851 gst_element_set_locked_state (priv->liveadder, TRUE);
1852 gst_element_set_locked_state (priv->audio_output, TRUE);
1854 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
1855 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1857 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1861 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
1863 gst_element_set_locked_state (priv->liveadder, FALSE);
1864 gst_element_set_locked_state (priv->audio_output, FALSE);
1866 error_add_liveadder:
1868 if (priv->liveadder != NULL)
1870 gst_object_unref (priv->liveadder);
1871 priv->liveadder = NULL;
1878 empathy_call_window_update_timer (gpointer user_data)
1880 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1881 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1885 time_ = g_timer_elapsed (priv->timer, NULL);
1887 /* Translators: number of minutes:seconds the caller has been connected */
1888 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
1890 empathy_call_window_status_message (self, str);
1897 display_error (EmpathyCallWindow *self,
1898 EmpathyTpCall *call,
1902 const gchar *details)
1904 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1905 GtkWidget *info_bar;
1906 GtkWidget *content_area;
1913 /* Create info bar */
1914 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1917 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
1919 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
1921 /* hbox containing the image and the messages vbox */
1922 hbox = gtk_hbox_new (FALSE, 3);
1923 gtk_container_add (GTK_CONTAINER (content_area), hbox);
1926 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
1927 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1929 /* vbox containing the main message and the details expander */
1930 vbox = gtk_vbox_new (FALSE, 3);
1931 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
1934 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
1936 label = gtk_label_new (NULL);
1937 gtk_label_set_markup (GTK_LABEL (label), txt);
1938 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1939 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1942 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
1945 if (details != NULL)
1947 GtkWidget *expander;
1949 expander = gtk_expander_new (_("Technical Details"));
1951 txt = g_strdup_printf ("<i>%s</i>", details);
1953 label = gtk_label_new (NULL);
1954 gtk_label_set_markup (GTK_LABEL (label), txt);
1955 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1956 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1959 gtk_container_add (GTK_CONTAINER (expander), label);
1960 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
1963 g_signal_connect (info_bar, "response",
1964 G_CALLBACK (gtk_widget_destroy), NULL);
1966 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
1967 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1968 gtk_widget_show_all (info_bar);
1972 media_stream_error_to_txt (EmpathyCallWindow *self,
1973 EmpathyTpCall *call,
1975 TpMediaStreamError error)
1977 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1984 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
1986 return g_strdup_printf (
1987 _("%s's software does not understand any of the audio formats "
1988 "supported by your computer"),
1989 empathy_contact_get_name (priv->contact));
1991 return g_strdup_printf (
1992 _("%s's software does not understand any of the video formats "
1993 "supported by your computer"),
1994 empathy_contact_get_name (priv->contact));
1996 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
1997 return g_strdup_printf (
1998 _("Can't establish a connection to %s. "
1999 "One of you might be on a network that does not allow "
2000 "direct connections."),
2001 empathy_contact_get_name (priv->contact));
2003 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2004 return g_strdup (_("There was a failure on the network"));
2006 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2008 return g_strdup (_("The audio formats necessary for this call "
2009 "are not installed on your computer"));
2011 return g_strdup (_("The video formats necessary for this call "
2012 "are not installed on your computer"));
2014 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2015 cm = empathy_tp_call_get_connection_manager (call);
2017 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2018 "product=Telepathy&component=%s", cm);
2020 result = g_strdup_printf (
2021 _("Something unexpected happened in a Telepathy component. "
2022 "Please <a href=\"%s\">report this bug</a> and attach "
2023 "logs gathered from the 'Debug' window in the Help menu."), url);
2028 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2029 return g_strdup (_("There was a failure in the call engine"));
2037 empathy_call_window_stream_error (EmpathyCallWindow *self,
2038 EmpathyTpCall *call,
2047 desc = media_stream_error_to_txt (self, call, audio, code);
2050 /* No description, use the error message. That's not great as it's not
2051 * localized but it's better than nothing. */
2052 display_error (self, call, icon, title, msg, NULL);
2056 display_error (self, call, icon, title, desc, msg);
2062 empathy_call_window_audio_stream_error (EmpathyTpCall *call,
2065 EmpathyCallWindow *self)
2067 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2068 "gnome-stock-mic", _("Can't establish audio stream"));
2072 empathy_call_window_video_stream_error (EmpathyTpCall *call,
2075 EmpathyCallWindow *self)
2077 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2078 "camera-web", _("Can't establish video stream"));
2082 empathy_call_window_connected (gpointer user_data)
2084 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2085 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2086 EmpathyTpCall *call;
2087 gboolean can_send_video;
2089 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
2091 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2092 empathy_contact_can_voip_video (priv->contact);
2094 g_object_get (priv->handler, "tp-call", &call, NULL);
2096 g_signal_connect (call, "notify::video-stream",
2097 G_CALLBACK (empathy_call_window_video_stream_changed_cb), self);
2099 if (empathy_tp_call_has_dtmf (call))
2100 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2102 if (priv->video_input == NULL)
2103 empathy_call_window_set_send_video (self, FALSE);
2105 priv->sending_video = can_send_video ?
2106 empathy_tp_call_is_sending_video (call) : FALSE;
2108 gtk_toggle_tool_button_set_active (
2109 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2110 priv->sending_video && priv->video_input != NULL);
2111 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2113 gtk_action_set_sensitive (priv->redial, FALSE);
2114 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2116 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2118 empathy_call_window_update_avatars_visibility (call, self);
2120 g_object_unref (call);
2122 g_mutex_lock (priv->lock);
2124 priv->timer_id = g_timeout_add_seconds (1,
2125 empathy_call_window_update_timer, self);
2127 g_mutex_unlock (priv->lock);
2129 empathy_call_window_update_timer (self);
2135 /* Called from the streaming thread */
2137 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2138 GstPad *src, guint media_type, gpointer user_data)
2140 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2141 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2142 gboolean retval = FALSE;
2146 g_mutex_lock (priv->lock);
2148 if (priv->call_state != CONNECTED)
2150 g_timer_start (priv->timer);
2151 priv->timer_id = g_idle_add (empathy_call_window_connected, self);
2152 priv->call_state = CONNECTED;
2157 case TP_MEDIA_STREAM_TYPE_AUDIO:
2158 pad = empathy_call_window_get_audio_sink_pad (self);
2160 case TP_MEDIA_STREAM_TYPE_VIDEO:
2161 gtk_widget_hide (priv->remote_user_avatar_widget);
2162 gtk_widget_show (priv->video_output);
2163 pad = empathy_call_window_get_video_sink_pad (self);
2166 g_assert_not_reached ();
2172 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2173 g_warning ("Could not link %s sink pad",
2174 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2178 gst_object_unref (pad);
2182 /* If no sink could be linked, try to add fakesink to prevent the whole call
2187 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2189 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2191 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2192 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2193 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2195 gst_element_set_locked_state (fakesink, TRUE);
2196 gst_element_set_state (fakesink, GST_STATE_NULL);
2197 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2201 g_debug ("Could not link real sink, linked fakesink instead");
2203 gst_object_unref (sinkpad);
2207 gst_object_unref (fakesink);
2212 g_mutex_unlock (priv->lock);
2218 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2219 GstPad *sink, guint media_type, gpointer user_data)
2221 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2222 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2224 gboolean retval = FALSE;
2228 case TP_MEDIA_STREAM_TYPE_AUDIO:
2229 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2231 g_warning ("Could not add audio source to pipeline");
2235 pad = gst_element_get_static_pad (priv->audio_input, "src");
2238 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2239 g_warning ("Could not get source pad from audio source");
2243 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2245 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2246 g_warning ("Could not link audio source to farsight");
2250 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2252 g_warning ("Could not start audio source");
2253 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2254 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2260 case TP_MEDIA_STREAM_TYPE_VIDEO:
2261 if (priv->video_input != NULL)
2263 if (priv->video_tee != NULL)
2265 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2266 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2268 g_warning ("Could not link videp soure input pipeline");
2277 g_assert_not_reached ();
2284 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2286 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2287 GstElement *preview;
2289 DEBUG ("remove video input");
2290 preview = empathy_video_widget_get_element (
2291 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2293 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2294 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2295 gst_element_set_state (preview, GST_STATE_NULL);
2297 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2298 priv->video_tee, preview, NULL);
2300 g_object_unref (priv->video_input);
2301 priv->video_input = NULL;
2302 g_object_unref (priv->video_tee);
2303 priv->video_tee = NULL;
2304 gtk_widget_destroy (priv->video_preview);
2305 priv->video_preview = NULL;
2307 gtk_toggle_tool_button_set_active (
2308 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), FALSE);
2309 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2311 gtk_widget_show (priv->self_user_avatar_widget);
2315 start_call (EmpathyCallWindow *self)
2317 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2319 priv->call_started = TRUE;
2320 empathy_call_handler_start_call (priv->handler);
2321 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2323 if (empathy_call_handler_has_initial_video (priv->handler))
2325 /* Enable 'send video' buttons and display the preview */
2326 gtk_toggle_tool_button_set_active (
2327 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2332 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2335 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2336 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2339 empathy_call_handler_bus_message (priv->handler, bus, message);
2341 switch (GST_MESSAGE_TYPE (message))
2343 case GST_MESSAGE_STATE_CHANGED:
2344 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2346 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2347 if (newstate == GST_STATE_PAUSED)
2348 empathy_call_window_setup_video_input (self);
2350 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2351 !priv->call_started)
2353 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2354 if (newstate == GST_STATE_PAUSED)
2360 case GST_MESSAGE_ERROR:
2362 GError *error = NULL;
2363 GstElement *gst_error;
2366 gst_message_parse_error (message, &error, &debug);
2367 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2369 g_message ("Element error: %s -- %s\n", error->message, debug);
2371 if (g_str_has_prefix (gst_element_get_name (gst_error),
2372 VIDEO_INPUT_ERROR_PREFIX))
2374 /* Remove the video input and continue */
2375 if (priv->video_input != NULL)
2376 empathy_call_window_remove_video_input (self);
2377 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2381 empathy_call_window_disconnected (self);
2383 g_error_free (error);
2394 empathy_call_window_update_avatars_visibility (EmpathyTpCall *call,
2395 EmpathyCallWindow *window)
2397 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2399 if (empathy_tp_call_is_receiving_video (call))
2401 gtk_widget_hide (priv->remote_user_avatar_widget);
2402 gtk_widget_show (priv->video_output);
2406 gtk_widget_hide (priv->video_output);
2407 gtk_widget_show (priv->remote_user_avatar_widget);
2412 call_handler_notify_tp_call_cb (EmpathyCallHandler *handler,
2414 EmpathyCallWindow *self)
2416 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2417 EmpathyTpCall *call;
2419 g_object_get (priv->handler, "tp-call", &call, NULL);
2423 empathy_signal_connect_weak (call, "audio-stream-error",
2424 G_CALLBACK (empathy_call_window_audio_stream_error), G_OBJECT (self));
2425 empathy_signal_connect_weak (call, "video-stream-error",
2426 G_CALLBACK (empathy_call_window_video_stream_error), G_OBJECT (self));
2428 g_object_unref (call);
2432 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2434 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2435 EmpathyTpCall *call;
2437 g_signal_connect (priv->handler, "conference-added",
2438 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2439 g_signal_connect (priv->handler, "request-resource",
2440 G_CALLBACK (empathy_call_window_request_resource_cb), window);
2441 g_signal_connect (priv->handler, "closed",
2442 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2443 g_signal_connect (priv->handler, "src-pad-added",
2444 G_CALLBACK (empathy_call_window_src_added_cb), window);
2445 g_signal_connect (priv->handler, "sink-pad-added",
2446 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2447 g_signal_connect (priv->handler, "stream-closed",
2448 G_CALLBACK (empathy_call_window_channel_stream_closed_cb), window);
2450 g_object_get (priv->handler, "tp-call", &call, NULL);
2453 empathy_signal_connect_weak (call, "audio-stream-error",
2454 G_CALLBACK (empathy_call_window_audio_stream_error), G_OBJECT (window));
2455 empathy_signal_connect_weak (call, "video-stream-error",
2456 G_CALLBACK (empathy_call_window_video_stream_error), G_OBJECT (window));
2458 g_object_unref (call);
2462 /* tp-call doesn't exist yet, we'll connect signals once it has been
2464 g_signal_connect (priv->handler, "notify::tp-call",
2465 G_CALLBACK (call_handler_notify_tp_call_cb), window);
2468 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2472 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2473 EmpathyCallWindow *window)
2475 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2477 if (priv->pipeline != NULL)
2479 if (priv->bus_message_source_id != 0)
2481 g_source_remove (priv->bus_message_source_id);
2482 priv->bus_message_source_id = 0;
2485 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2488 if (priv->call_state == CONNECTING)
2489 empathy_sound_stop (EMPATHY_SOUND_PHONE_OUTGOING);
2495 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2498 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2500 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2505 gtk_widget_hide (priv->sidebar);
2506 gtk_widget_hide (menu);
2507 gtk_widget_hide (priv->vbox);
2508 gtk_widget_hide (priv->statusbar);
2509 gtk_widget_hide (priv->toolbar);
2513 if (priv->sidebar_was_visible_before_fs)
2514 gtk_widget_show (priv->sidebar);
2516 gtk_widget_show (menu);
2517 gtk_widget_show (priv->vbox);
2518 gtk_widget_show (priv->statusbar);
2519 gtk_widget_show (priv->toolbar);
2521 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2522 priv->original_height_before_fs);
2527 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2529 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2531 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2532 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2533 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2534 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2535 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2536 priv->video_output, TRUE, TRUE,
2537 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2539 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2540 priv->vbox, TRUE, TRUE,
2541 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2546 empathy_call_window_state_event_cb (GtkWidget *widget,
2547 GdkEventWindowState *event, EmpathyCallWindow *window)
2549 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2551 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2552 gboolean set_fullscreen = event->new_window_state &
2553 GDK_WINDOW_STATE_FULLSCREEN;
2557 gboolean sidebar_was_visible;
2558 GtkAllocation allocation;
2559 gint original_width, original_height;
2561 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2562 original_width = allocation.width;
2563 original_height = allocation.height;
2565 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2567 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2568 priv->original_width_before_fs = original_width;
2569 priv->original_height_before_fs = original_height;
2571 if (priv->video_output_motion_handler_id == 0 &&
2572 priv->video_output != NULL)
2574 priv->video_output_motion_handler_id = g_signal_connect (
2575 G_OBJECT (priv->video_output), "motion-notify-event",
2576 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2582 if (priv->video_output_motion_handler_id != 0)
2584 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
2585 priv->video_output_motion_handler_id);
2586 priv->video_output_motion_handler_id = 0;
2590 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2592 show_controls (window, set_fullscreen);
2593 show_borders (window, set_fullscreen);
2594 gtk_action_set_stock_id (priv->menu_fullscreen,
2595 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2596 priv->is_fullscreen = set_fullscreen;
2603 empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
2604 EmpathyCallWindow *window)
2606 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2608 int w, h, handle_size;
2609 GtkAllocation allocation, sidebar_allocation;
2611 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2612 w = allocation.width;
2613 h = allocation.height;
2615 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2617 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
2618 if (gtk_toggle_button_get_active (toggle))
2620 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
2621 gtk_widget_show (priv->sidebar);
2622 w += sidebar_allocation.width + handle_size;
2626 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2627 w -= sidebar_allocation.width + handle_size;
2628 gtk_widget_hide (priv->sidebar);
2631 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
2634 gtk_window_resize (GTK_WINDOW (window), w, h);
2638 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2641 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2642 EmpathyTpCall *call;
2644 priv->sending_video = send;
2646 /* When we start sending video, we want to show the video preview by
2648 display_video_preview (window, send);
2650 if (priv->call_state != CONNECTED)
2653 g_object_get (priv->handler, "tp-call", &call, NULL);
2654 DEBUG ("%s sending video", send ? "start": "stop");
2655 empathy_tp_call_request_video_stream_direction (call, send);
2656 g_object_unref (call);
2660 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2661 EmpathyCallWindow *window)
2663 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2666 active = (gtk_toggle_tool_button_get_active (toggle));
2670 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2672 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
2676 /* TODO, Instead of setting the input volume to 0 we should probably
2677 * stop sending but this would cause the audio call to drop if both
2678 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2679 * in the future. GNOME #574574
2681 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2683 gtk_adjustment_set_value (priv->audio_input_adj, 0);
2688 empathy_call_window_sidebar_hidden_cb (EmpathySidebar *sidebar,
2689 EmpathyCallWindow *window)
2691 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2693 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2698 empathy_call_window_sidebar_shown_cb (EmpathySidebar *sidebar,
2699 EmpathyCallWindow *window)
2701 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2703 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2708 empathy_call_window_hangup_cb (gpointer object,
2709 EmpathyCallWindow *window)
2711 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2713 empathy_call_handler_stop_call (priv->handler);
2715 if (empathy_call_window_disconnected (window))
2716 gtk_widget_destroy (GTK_WIDGET (window));
2720 empathy_call_window_restart_call (EmpathyCallWindow *window)
2722 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2724 create_video_output_widget (window);
2726 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
2727 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
2729 /* While the call was disconnected, the input volume might have changed.
2730 * However, since the audio_input source was destroyed, its volume has not
2731 * been updated during that time. That's why we manually update it here */
2732 empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
2734 gtk_widget_show_all (priv->content_hbox);
2736 priv->outgoing = TRUE;
2737 empathy_call_window_set_state_connecting (window);
2739 start_call (window);
2740 empathy_call_window_setup_avatars (window, priv->handler);
2742 gtk_action_set_sensitive (priv->redial, FALSE);
2743 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2747 empathy_call_window_redial_cb (gpointer object,
2748 EmpathyCallWindow *window)
2750 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2752 if (priv->call_state == CONNECTED)
2753 priv->call_state = REDIALING;
2755 empathy_call_handler_stop_call (priv->handler);
2757 if (priv->call_state != CONNECTED)
2758 empathy_call_window_restart_call (window);
2762 empathy_call_window_fullscreen_cb (gpointer object,
2763 EmpathyCallWindow *window)
2765 empathy_call_window_fullscreen_toggle (window);
2769 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2771 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2773 if (priv->is_fullscreen)
2774 gtk_window_unfullscreen (GTK_WINDOW (window));
2776 gtk_window_fullscreen (GTK_WINDOW (window));
2780 empathy_call_window_video_button_press_cb (GtkWidget *video_output,
2781 GdkEventButton *event, EmpathyCallWindow *window)
2783 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2785 empathy_call_window_video_menu_popup (window, event->button);
2793 empathy_call_window_key_press_cb (GtkWidget *video_output,
2794 GdkEventKey *event, EmpathyCallWindow *window)
2796 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2798 if (priv->is_fullscreen && event->keyval == GDK_Escape)
2800 /* Since we are in fullscreen mode, toggling will bring us back to
2802 empathy_call_window_fullscreen_toggle (window);
2810 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
2811 GdkEventMotion *event, EmpathyCallWindow *window)
2813 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2815 if (priv->is_fullscreen)
2817 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
2824 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
2828 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2830 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2832 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
2833 button, gtk_get_current_event_time ());
2834 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
2838 empathy_call_window_status_message (EmpathyCallWindow *window,
2841 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2843 if (priv->context_id == 0)
2845 priv->context_id = gtk_statusbar_get_context_id (
2846 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
2850 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
2853 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
2858 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
2859 gdouble value, EmpathyCallWindow *window)
2861 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2863 if (priv->audio_output == NULL)
2866 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
2870 /* block all the signals related to camera control widgets. This is useful
2871 * when we are manually updating the UI and so don't want to fire the
2874 block_camera_control_signals (EmpathyCallWindow *self)
2876 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2878 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
2879 tool_button_camera_off_toggled_cb, self);
2880 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
2881 tool_button_camera_preview_toggled_cb, self);
2882 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
2883 tool_button_camera_on_toggled_cb, self);
2884 g_signal_handlers_block_by_func (priv->action_camera,
2885 action_camera_change_cb, self);
2889 unblock_camera_control_signals (EmpathyCallWindow *self)
2891 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2893 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
2894 tool_button_camera_off_toggled_cb, self);
2895 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
2896 tool_button_camera_preview_toggled_cb, self);
2897 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
2898 tool_button_camera_on_toggled_cb, self);
2899 g_signal_handlers_unblock_by_func (priv->action_camera,
2900 action_camera_change_cb, self);