2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 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 <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-ui-utils.h>
50 #include <libempathy-gtk/empathy-sound-manager.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-images.h>
54 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
55 #include <libempathy/empathy-debug.h>
57 #include "empathy-call-window.h"
58 #include "empathy-call-window-fullscreen.h"
59 #include "empathy-call-factory.h"
60 #include "empathy-video-widget.h"
61 #include "empathy-about-dialog.h"
62 #include "empathy-audio-src.h"
63 #include "empathy-audio-sink.h"
64 #include "empathy-video-src.h"
65 #include "empathy-mic-menu.h"
66 #include "empathy-preferences.h"
67 #include "empathy-rounded-actor.h"
69 #define CONTENT_HBOX_BORDER_WIDTH 6
70 #define CONTENT_HBOX_SPACING 3
71 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
73 #define SELF_VIDEO_SECTION_WIDTH 120
74 #define SELF_VIDEO_SECTION_HEIGTH 90
75 #define SELF_VIDEO_SECTION_MARGIN 10
77 #define FLOATING_TOOLBAR_OPACITY 192
78 #define FLOATING_TOOLBAR_WIDTH 280
79 #define FLOATING_TOOLBAR_HEIGHT 36
80 #define FLOATING_TOOLBAR_SPACING 20
82 #define SELF_VIDEO_MARGIN 10
84 /* The avatar's default width and height are set to the same value because we
85 want a square icon. */
86 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
88 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
90 #define SMALL_TOOLBAR_SIZE 36
92 /* If an video input error occurs, the error message will start with "v4l" */
93 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
95 /* The time interval in milliseconds between 2 outgoing rings */
96 #define MS_BETWEEN_RING 500
98 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
101 PROP_CALL_HANDLER = 1,
113 CAMERA_STATE_OFF = 0,
119 PREVIEW_POS_TOP_LEFT,
120 PREVIEW_POS_TOP_RIGHT,
121 PREVIEW_POS_BOTTOM_LEFT,
122 PREVIEW_POS_BOTTOM_RIGHT,
125 struct _EmpathyCallWindowPriv
127 gboolean dispose_has_run;
128 EmpathyCallHandler *handler;
130 EmpathyContact *contact;
132 EmpathyCameraMonitor *camera_monitor;
137 GtkUIManager *ui_manager;
138 GtkWidget *errors_vbox;
139 /* widget displays the video received from the remote user. This widget is
140 * alive only during call. */
141 ClutterActor *video_output;
142 ClutterActor *video_preview;
143 ClutterActor *preview_hidden_button;
144 ClutterActor *preview_rectangle1;
145 ClutterActor *preview_rectangle2;
146 ClutterActor *preview_rectangle3;
147 ClutterActor *preview_rectangle4;
148 GtkWidget *video_container;
149 GtkWidget *remote_user_avatar_widget;
150 GtkWidget *remote_user_avatar_toolbar;
151 GtkWidget *remote_user_name_toolbar;
152 GtkWidget *status_label;
153 GtkWidget *hangup_button;
154 GtkWidget *audio_call_button;
155 GtkWidget *video_call_button;
156 GtkWidget *mic_button;
157 GtkWidget *camera_button;
158 GtkWidget *dialpad_button;
160 GtkWidget *bottom_toolbar;
161 ClutterActor *floating_toolbar;
163 GtkAction *menu_fullscreen;
165 ClutterState *transitions;
167 /* The box that contains self and remote avatar and video
168 input/output. When we redial, we destroy and re-create the box */
169 ClutterActor *video_box;
170 ClutterLayoutManager *video_layout;
172 /* We keep a reference on the hbox which contains the main content so we can
173 easilly repack everything when toggling fullscreen */
174 GtkWidget *content_hbox;
176 gulong video_output_motion_handler_id;
177 guint bus_message_source_id;
181 GtkWidget *dtmf_panel;
184 GtkWidget *details_vbox;
185 GtkWidget *vcodec_encoding_label;
186 GtkWidget *acodec_encoding_label;
187 GtkWidget *vcodec_decoding_label;
188 GtkWidget *acodec_decoding_label;
190 GtkWidget *audio_remote_candidate_label;
191 GtkWidget *audio_local_candidate_label;
192 GtkWidget *video_remote_candidate_label;
193 GtkWidget *video_local_candidate_label;
194 GtkWidget *video_remote_candidate_info_img;
195 GtkWidget *video_local_candidate_info_img;
196 GtkWidget *audio_remote_candidate_info_img;
197 GtkWidget *audio_local_candidate_info_img;
199 GstElement *video_input;
200 GstElement *video_preview_sink;
201 GstElement *video_output_sink;
202 GstElement *audio_input;
203 GstElement *audio_output;
204 GstElement *pipeline;
205 GstElement *video_tee;
215 gboolean call_started;
216 gboolean sending_video;
217 CameraState camera_state;
219 EmpathyCallWindowFullscreen *fullscreen;
220 gboolean is_fullscreen;
225 guint inactivity_src;
227 /* Those fields represent the state of the window before it actually was in
229 gboolean dialpad_was_visible_before_fs;
230 gint original_width_before_fs;
231 gint original_height_before_fs;
233 gint x, y, w, h, dialpad_width;
236 /* TRUE if the call should be started when the pipeline is playing */
237 gboolean start_call_when_playing;
238 /* TRUE if we requested to set the pipeline in the playing state */
239 gboolean pipeline_playing;
241 EmpathySoundManager *sound_mgr;
244 EmpathyMicMenu *mic_menu;
247 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
249 static void empathy_call_window_realized_cb (GtkWidget *widget,
250 EmpathyCallWindow *window);
252 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
253 GdkEvent *event, EmpathyCallWindow *window);
255 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
256 GdkEventWindowState *event, EmpathyCallWindow *window);
258 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
261 static void empathy_call_window_mic_toggled_cb (
262 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
264 static void empathy_call_window_hangup_cb (gpointer object,
265 EmpathyCallWindow *window);
267 static void empathy_call_window_fullscreen_cb (gpointer object,
268 EmpathyCallWindow *window);
270 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
272 static gboolean empathy_call_window_video_button_press_cb (
273 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
275 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
276 GdkEventKey *event, EmpathyCallWindow *window);
278 static gboolean empathy_call_window_video_output_motion_notify (
279 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
281 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
284 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
285 EmpathyCallWindow *window);
287 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
289 static void empathy_call_window_status_message (EmpathyCallWindow *window,
292 static gboolean empathy_call_window_bus_message (GstBus *bus,
293 GstMessage *message, gpointer user_data);
296 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
297 gdouble value, EmpathyCallWindow *window);
300 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
303 gtk_widget_set_visible (self->priv->hangup_button, show);
304 gtk_widget_set_visible (self->priv->audio_call_button, !show);
305 gtk_widget_set_visible (self->priv->video_call_button, !show);
309 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
310 EmpathyCallWindow *self)
312 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
313 empathy_call_window_restart_call (self);
317 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
318 EmpathyCallWindow *self)
320 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
321 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
322 empathy_call_window_restart_call (self);
326 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
328 EmpathyCallWindowPriv *priv = GET_PRIV (window);
329 TpyCallChannel *call;
333 g_object_get (priv->handler, "call-channel", &call, NULL);
335 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
336 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
339 tpy_call_channel_dtmf_start_tone (call, event);
341 g_object_unref (call);
345 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
347 EmpathyCallWindowPriv *priv = GET_PRIV (window);
348 TpyCallChannel *call;
350 g_object_get (priv->handler, "call-channel", &call, NULL);
352 tpy_call_channel_dtmf_stop_tone (call);
354 g_object_unref (call);
358 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
360 EmpathyCallWindowPriv *priv = GET_PRIV (self);
363 volume = g_settings_get_double (priv->settings,
364 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
366 /* Don't store the volume because of muting */
367 if (volume > 0 || gtk_toggle_tool_button_get_active (
368 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
369 priv->volume = volume;
371 /* Ensure that the toggle button is active if the volume is > 0 and inactive
372 * if it's smaller than 0 */
373 if ((volume > 0) != gtk_toggle_tool_button_get_active (
374 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
375 gtk_toggle_tool_button_set_active (
376 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
378 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
383 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
385 EmpathyCallWindow *self)
387 empathy_call_window_mic_volume_changed (self);
391 empathy_call_window_show_video_output (EmpathyCallWindow *self,
394 if (self->priv->video_output != NULL)
395 g_object_set (self->priv->video_output, "visible", show, NULL);
397 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
399 clutter_actor_raise_top (self->priv->floating_toolbar);
403 create_video_output_widget (EmpathyCallWindow *self)
405 EmpathyCallWindowPriv *priv = GET_PRIV (self);
407 g_assert (priv->video_output == NULL);
408 g_assert (priv->pipeline != NULL);
410 priv->video_output = clutter_texture_new ();
412 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
415 priv->video_output_sink = clutter_gst_video_sink_new (
416 CLUTTER_TEXTURE (priv->video_output));
418 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
421 gtk_widget_add_events (priv->video_container,
422 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
423 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
424 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
428 create_video_input (EmpathyCallWindow *self)
430 EmpathyCallWindowPriv *priv = GET_PRIV (self);
432 g_assert (priv->video_input == NULL);
433 priv->video_input = empathy_video_src_new ();
434 gst_object_ref (priv->video_input);
435 gst_object_sink (priv->video_input);
439 create_audio_input (EmpathyCallWindow *self)
441 EmpathyCallWindowPriv *priv = GET_PRIV (self);
443 g_assert (priv->audio_input == NULL);
444 priv->audio_input = empathy_audio_src_new ();
445 gst_object_ref (priv->audio_input);
446 gst_object_sink (priv->audio_input);
450 add_video_preview_to_pipeline (EmpathyCallWindow *self)
452 EmpathyCallWindowPriv *priv = GET_PRIV (self);
455 g_assert (priv->video_preview != NULL);
456 g_assert (priv->pipeline != NULL);
457 g_assert (priv->video_input != NULL);
458 g_assert (priv->video_tee != NULL);
460 preview = priv->video_preview_sink;
462 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
464 g_warning ("Could not add video input to pipeline");
468 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
470 g_warning ("Could not add video preview to pipeline");
474 if (!gst_element_link (priv->video_input, priv->video_tee))
476 g_warning ("Could not link video input to video tee");
480 if (!gst_element_link (priv->video_tee, preview))
482 g_warning ("Could not link video tee to video preview");
488 empathy_call_window_disable_camera_cb (GtkAction *action,
489 EmpathyCallWindow *self)
491 clutter_actor_destroy (self->priv->preview_hidden_button);
493 gtk_toggle_tool_button_set_active (
494 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
498 empathy_call_window_minimise_camera_cb (GtkAction *action,
499 EmpathyCallWindow *self)
501 clutter_actor_hide (self->priv->video_preview);
502 clutter_actor_show (self->priv->preview_hidden_button);
506 empathy_call_window_maximise_camera_cb (GtkAction *action,
507 EmpathyCallWindow *self)
509 clutter_actor_show (self->priv->video_preview);
510 clutter_actor_hide (self->priv->preview_hidden_button);
514 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
515 EmpathyCallWindow *self)
519 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
521 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
522 0, gtk_get_current_event_time ());
523 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
527 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
528 EmpathyCallWindow *self)
532 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
533 "/preview-hidden-menu");
534 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
535 0, gtk_get_current_event_time ());
536 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
539 static ClutterActor *
540 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
541 ClutterBinAlignment x,
542 ClutterBinAlignment y)
544 ClutterLayoutManager *layout;
545 ClutterActor *rectangle;
548 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
549 CLUTTER_BIN_ALIGNMENT_CENTER);
551 box = clutter_box_new (layout);
553 rectangle = clutter_rectangle_new_with_color (
554 CLUTTER_COLOR_Transparent);
556 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
559 clutter_actor_set_size (box,
560 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_MARGIN,
561 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_MARGIN);
563 clutter_actor_set_size (rectangle,
564 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
566 clutter_container_add_actor (CLUTTER_CONTAINER (box), rectangle);
568 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
571 clutter_actor_hide (rectangle);
577 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
579 self->priv->preview_rectangle1 =
580 empathy_call_window_create_preview_rectangle (self,
581 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
582 self->priv->preview_rectangle2 =
583 empathy_call_window_create_preview_rectangle (self,
584 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
585 self->priv->preview_rectangle3 =
586 empathy_call_window_create_preview_rectangle (self,
587 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
588 self->priv->preview_rectangle4 =
589 empathy_call_window_create_preview_rectangle (self,
590 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
594 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
597 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
598 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
599 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
600 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
604 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
607 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
609 DEBUG ("moving the video preview to %d", pos);
613 case PREVIEW_POS_TOP_LEFT:
614 clutter_bin_layout_set_alignment (layout,
615 self->priv->video_preview,
616 CLUTTER_BIN_ALIGNMENT_START,
617 CLUTTER_BIN_ALIGNMENT_START);
619 case PREVIEW_POS_TOP_RIGHT:
620 clutter_bin_layout_set_alignment (layout,
621 self->priv->video_preview,
622 CLUTTER_BIN_ALIGNMENT_END,
623 CLUTTER_BIN_ALIGNMENT_START);
625 case PREVIEW_POS_BOTTOM_LEFT:
626 clutter_bin_layout_set_alignment (layout,
627 self->priv->video_preview,
628 CLUTTER_BIN_ALIGNMENT_START,
629 CLUTTER_BIN_ALIGNMENT_END);
631 case PREVIEW_POS_BOTTOM_RIGHT:
632 clutter_bin_layout_set_alignment (layout,
633 self->priv->video_preview,
634 CLUTTER_BIN_ALIGNMENT_END,
635 CLUTTER_BIN_ALIGNMENT_END);
638 g_warn_if_reached ();
643 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
647 ClutterModifierType modifiers,
648 EmpathyCallWindow *self)
650 empathy_call_window_show_preview_rectangles (self, TRUE);
654 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
658 ClutterModifierType modifiers,
659 EmpathyCallWindow *self)
662 PreviewPosition pos = PREVIEW_POS_NONE;
664 clutter_actor_get_geometry (self->priv->video_box, &box);
666 if (0 + SELF_VIDEO_MARGIN <= event_x &&
667 event_x <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
668 0 + SELF_VIDEO_MARGIN <= event_y &&
669 event_y <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
671 pos = PREVIEW_POS_TOP_LEFT;
673 else if (box.width - SELF_VIDEO_MARGIN >= event_x &&
674 event_x >= (box.width - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
675 0 + SELF_VIDEO_MARGIN <= event_y &&
676 event_y <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
678 pos = PREVIEW_POS_TOP_RIGHT;
680 else if (0 + SELF_VIDEO_MARGIN <= event_x &&
681 event_x <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
682 box.height - SELF_VIDEO_MARGIN >= event_y &&
683 event_y >= (box.height - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGTH))
685 pos = PREVIEW_POS_BOTTOM_LEFT;
687 else if (box.width - SELF_VIDEO_MARGIN >= event_x &&
688 event_x >= (box.width - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
689 box.height - SELF_VIDEO_MARGIN >= event_y &&
690 event_y >= (box.height - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGTH))
692 pos = PREVIEW_POS_BOTTOM_RIGHT;
695 if (pos != PREVIEW_POS_NONE)
696 empathy_call_window_move_video_preview (self, pos);
698 empathy_call_window_show_preview_rectangles (self, FALSE);
702 create_video_preview (EmpathyCallWindow *self)
704 EmpathyCallWindowPriv *priv = GET_PRIV (self);
705 ClutterLayoutManager *layout, *layout_center;
706 ClutterActor *preview;
709 ClutterAction *action;
712 g_assert (priv->video_preview == NULL);
714 preview = clutter_texture_new ();
715 clutter_actor_set_size (preview,
716 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
717 priv->video_preview_sink = clutter_gst_video_sink_new (
718 CLUTTER_TEXTURE (preview));
720 /* Flip the video preview */
721 clutter_actor_set_rotation (preview,
724 SELF_VIDEO_SECTION_WIDTH * 0.5,
728 /* Add a little offset to the video preview */
729 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
730 CLUTTER_BIN_ALIGNMENT_CENTER);
731 priv->video_preview = clutter_box_new (layout);
732 clutter_actor_set_size (priv->video_preview,
733 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
734 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
735 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
737 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
738 CLUTTER_BIN_ALIGNMENT_CENTER);
739 box = clutter_box_new (layout_center);
740 clutter_actor_set_size (box,
741 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
743 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
744 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
746 g_object_set (priv->video_preview_sink,
751 /* Translators: this is an "Info" label. It should be as short
753 button = gtk_button_new_with_label (_("i"));
754 b = gtk_clutter_actor_new_with_contents (button);
756 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
758 CLUTTER_BIN_ALIGNMENT_END,
759 CLUTTER_BIN_ALIGNMENT_END);
761 g_signal_connect (button, "clicked",
762 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
765 /* Translators: this is an "Info" label. It should be as short
767 button = gtk_button_new_with_label (_("i"));
768 priv->preview_hidden_button =
769 gtk_clutter_actor_new_with_contents (button);
771 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
772 priv->preview_hidden_button,
773 CLUTTER_BIN_ALIGNMENT_START,
774 CLUTTER_BIN_ALIGNMENT_END);
776 clutter_actor_hide (priv->preview_hidden_button);
778 g_signal_connect (button, "clicked",
779 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
782 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
784 CLUTTER_BIN_ALIGNMENT_START,
785 CLUTTER_BIN_ALIGNMENT_END);
787 action = clutter_drag_action_new ();
788 g_signal_connect (action, "drag-begin",
789 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
790 g_signal_connect (action, "drag-end",
791 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
793 clutter_actor_add_action (preview, action);
794 clutter_actor_set_reactive (preview, TRUE);
798 play_camera (EmpathyCallWindow *window,
801 EmpathyCallWindowPriv *priv = GET_PRIV (window);
805 if (priv->video_preview == NULL)
807 create_video_preview (window);
808 add_video_preview_to_pipeline (window);
812 state = GST_STATE_PLAYING;
814 state = GST_STATE_NULL;
816 preview = priv->video_preview_sink;
818 gst_element_set_state (preview, state);
819 gst_element_set_state (priv->video_input, state);
820 gst_element_set_state (priv->video_tee, state);
824 display_video_preview (EmpathyCallWindow *self,
827 EmpathyCallWindowPriv *priv = GET_PRIV (self);
831 /* Display the video preview */
832 DEBUG ("Show video preview");
834 play_camera (self, TRUE);
835 clutter_actor_show (priv->video_preview);
836 clutter_actor_raise_top (priv->floating_toolbar);
840 /* Hide the video preview */
841 DEBUG ("Hide video preview");
843 if (priv->video_preview != NULL)
845 clutter_actor_hide (priv->video_preview);
846 play_camera (self, FALSE);
852 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
854 EmpathyCallWindowPriv *priv = GET_PRIV (window);
856 empathy_call_window_status_message (window, _("Connecting…"));
857 priv->call_state = CONNECTING;
860 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
861 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
865 disable_camera (EmpathyCallWindow *self)
867 EmpathyCallWindowPriv *priv = GET_PRIV (self);
869 if (priv->camera_state == CAMERA_STATE_OFF)
872 DEBUG ("Disable camera");
874 display_video_preview (self, FALSE);
876 if (priv->camera_state == CAMERA_STATE_ON)
877 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
879 priv->camera_state = CAMERA_STATE_OFF;
883 enable_camera (EmpathyCallWindow *self)
885 EmpathyCallWindowPriv *priv = GET_PRIV (self);
887 if (priv->camera_state == CAMERA_STATE_ON)
890 if (priv->video_input == NULL)
892 DEBUG ("Can't enable camera, no input");
896 DEBUG ("Enable camera");
898 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
900 priv->camera_state = CAMERA_STATE_ON;
904 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
905 EmpathyCallWindow *self)
907 if (gtk_toggle_tool_button_get_active (toggle))
908 enable_camera (self);
910 disable_camera (self);
914 create_pipeline (EmpathyCallWindow *self)
916 EmpathyCallWindowPriv *priv = GET_PRIV (self);
919 g_assert (priv->pipeline == NULL);
921 priv->pipeline = gst_pipeline_new (NULL);
922 priv->pipeline_playing = FALSE;
924 priv->video_tee = gst_element_factory_make ("tee", NULL);
925 gst_object_ref (priv->video_tee);
926 gst_object_sink (priv->video_tee);
928 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
930 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
931 priv->bus_message_source_id = gst_bus_add_watch (bus,
932 empathy_call_window_bus_message, self);
934 g_object_unref (bus);
938 empathy_call_window_settings_cb (GtkAction *action,
939 EmpathyCallWindow *self)
941 gchar *args = g_strdup_printf ("-p %s",
942 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
944 empathy_launch_program (BIN_DIR, "empathy", args);
950 empathy_call_window_contents_cb (GtkAction *action,
951 EmpathyCallWindow *self)
953 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
957 empathy_call_window_debug_cb (GtkAction *action,
958 EmpathyCallWindow *self)
960 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
964 empathy_call_window_about_cb (GtkAction *action,
965 EmpathyCallWindow *self)
967 empathy_about_dialog_new (GTK_WINDOW (self));
971 empathy_call_window_toolbar_timeout (gpointer data)
973 EmpathyCallWindow *self = data;
975 clutter_state_set_state (self->priv->transitions, "fade-out");
981 empathy_call_window_motion_notify_cb (GtkWidget *widget,
983 EmpathyCallWindow *self)
985 clutter_state_set_state (self->priv->transitions, "fade-in");
987 if (self->priv->inactivity_src > 0)
988 g_source_remove (self->priv->inactivity_src);
990 self->priv->inactivity_src = g_timeout_add_seconds (3,
991 empathy_call_window_toolbar_timeout, self);
997 empathy_call_window_configure_event_cb (GtkWidget *widget,
999 EmpathyCallWindow *self)
1001 GdkWindow *gdk_window;
1002 GdkWindowState window_state;
1004 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1005 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1007 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1008 &self->priv->dialpad_width, NULL);
1010 gdk_window = gtk_widget_get_window (widget);
1011 window_state = gdk_window_get_state (gdk_window);
1012 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1018 empathy_call_window_destroyed_cb (GtkWidget *object,
1019 EmpathyCallWindow *self)
1021 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1023 /* Save the geometry as if the dialpad was hidden. */
1024 empathy_geometry_save_values (GTK_WINDOW (self),
1025 self->priv->x, self->priv->y,
1026 self->priv->w - self->priv->dialpad_width, self->priv->h,
1027 self->priv->maximized);
1032 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1034 ClutterBindConstraint *constraint)
1036 ClutterActorBox allocation;
1038 clutter_actor_get_allocation_box (stage, &allocation);
1040 clutter_bind_constraint_set_offset (constraint,
1041 allocation.y2 - allocation.y1 -
1042 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1046 empathy_call_window_init (EmpathyCallWindow *self)
1048 EmpathyCallWindowPriv *priv;
1050 GtkWidget *top_vbox;
1052 ClutterConstraint *constraint;
1053 ClutterActor *remote_avatar;
1054 GtkStyleContext *context;
1058 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1059 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1061 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1062 gui = empathy_builder_get_file (filename,
1063 "call_window_vbox", &top_vbox,
1064 "errors_vbox", &priv->errors_vbox,
1065 "pane", &priv->pane,
1066 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1067 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1068 "status_label", &priv->status_label,
1069 "audiocall", &priv->audio_call_button,
1070 "videocall", &priv->video_call_button,
1071 "microphone", &priv->mic_button,
1072 "camera", &priv->camera_button,
1073 "hangup", &priv->hangup_button,
1074 "dialpad", &priv->dialpad_button,
1075 "toolbar", &priv->toolbar,
1076 "bottom_toolbar", &priv->bottom_toolbar,
1077 "ui_manager", &priv->ui_manager,
1078 "menufullscreen", &priv->menu_fullscreen,
1079 "details_vbox", &priv->details_vbox,
1080 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1081 "acodec_encoding_label", &priv->acodec_encoding_label,
1082 "acodec_decoding_label", &priv->acodec_decoding_label,
1083 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1084 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1085 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1086 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1087 "video_local_candidate_label", &priv->video_local_candidate_label,
1088 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1089 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1090 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1091 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1095 empathy_builder_connect (gui, self,
1096 "hangup", "clicked", empathy_call_window_hangup_cb,
1097 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1098 "videocall", "clicked", empathy_call_window_video_call_cb,
1099 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1100 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1101 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1102 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1103 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1104 "menusettings", "activate", empathy_call_window_settings_cb,
1105 "menucontents", "activate", empathy_call_window_contents_cb,
1106 "menudebug", "activate", empathy_call_window_debug_cb,
1107 "menuabout", "activate", empathy_call_window_about_cb,
1108 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1109 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1110 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1113 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1115 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1117 g_object_bind_property (priv->camera_monitor, "available",
1118 priv->camera_button, "sensitive",
1119 G_BINDING_SYNC_CREATE);
1121 priv->lock = g_mutex_new ();
1123 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1125 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1126 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1127 CONTENT_HBOX_BORDER_WIDTH);
1128 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1131 /* avatar/video box */
1132 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1133 CLUTTER_BIN_ALIGNMENT_CENTER);
1135 priv->video_box = clutter_box_new (priv->video_layout);
1137 empathy_call_window_create_preview_rectangles (self);
1139 priv->video_container = gtk_clutter_embed_new ();
1141 /* Set the background color to that of the rest of the window */
1142 context = gtk_widget_get_style_context (priv->content_hbox);
1143 gtk_style_context_get_background_color (context,
1144 GTK_STATE_FLAG_NORMAL, &rgba);
1145 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1146 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1147 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1148 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1149 clutter_stage_set_color (
1150 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1151 GTK_CLUTTER_EMBED (priv->video_container))),
1154 clutter_container_add (
1155 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1156 GTK_CLUTTER_EMBED (priv->video_container))),
1160 constraint = clutter_bind_constraint_new (
1161 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1162 CLUTTER_BIND_SIZE, 0);
1163 clutter_actor_add_constraint (priv->video_box, constraint);
1165 priv->remote_user_avatar_widget = gtk_image_new ();
1166 remote_avatar = gtk_clutter_actor_new_with_contents (
1167 priv->remote_user_avatar_widget);
1169 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1172 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1173 priv->video_container, TRUE, TRUE,
1174 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1176 create_pipeline (self);
1177 create_video_output_widget (self);
1178 create_audio_input (self);
1179 create_video_input (self);
1181 priv->floating_toolbar = empathy_rounded_actor_new ();
1183 gtk_widget_reparent (priv->bottom_toolbar,
1184 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1186 constraint = clutter_bind_constraint_new (
1187 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1190 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1193 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1194 "notify::allocation",
1195 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1198 clutter_actor_set_size (priv->floating_toolbar,
1199 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1200 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1202 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1203 priv->floating_toolbar,
1204 CLUTTER_BIN_ALIGNMENT_CENTER,
1205 CLUTTER_BIN_ALIGNMENT_END);
1207 clutter_actor_raise_top (priv->floating_toolbar);
1209 /* Transitions for the floating toolbar */
1210 priv->transitions = clutter_state_new ();
1212 /* all transitions last for 2s */
1213 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1215 /* transition from any state to "fade-out" state */
1216 clutter_state_set (priv->transitions, NULL, "fade-out",
1217 priv->floating_toolbar,
1218 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1221 /* transition from any state to "fade-in" state */
1222 clutter_state_set (priv->transitions, NULL, "fade-in",
1223 priv->floating_toolbar,
1224 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1227 /* put the actor into the "fade-in" state with no animation */
1228 clutter_state_warp_to_state (priv->transitions, "fade-in");
1230 /* The call will be started as soon the pipeline is playing */
1231 priv->start_call_when_playing = TRUE;
1233 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1234 G_CALLBACK (dtmf_button_pressed_cb),
1235 G_CALLBACK (dtmf_button_released_cb));
1237 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1240 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1243 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1245 gtk_widget_show_all (top_vbox);
1247 gtk_widget_hide (priv->dtmf_panel);
1248 gtk_widget_hide (priv->details_vbox);
1250 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1252 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1253 priv->video_container);
1255 /* We hide the bottom toolbar after 3s of inactivity and show it
1256 * again on mouse movement */
1257 priv->inactivity_src = g_timeout_add_seconds (3,
1258 empathy_call_window_toolbar_timeout, self);
1260 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1261 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1263 g_signal_connect (G_OBJECT (self), "realize",
1264 G_CALLBACK (empathy_call_window_realized_cb), self);
1266 g_signal_connect (G_OBJECT (self), "delete-event",
1267 G_CALLBACK (empathy_call_window_delete_cb), self);
1269 g_signal_connect (G_OBJECT (self), "window-state-event",
1270 G_CALLBACK (empathy_call_window_state_event_cb), self);
1272 g_signal_connect (G_OBJECT (self), "key-press-event",
1273 G_CALLBACK (empathy_call_window_key_press_cb), self);
1275 g_signal_connect (self, "motion-notify-event",
1276 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1278 priv->timer = g_timer_new ();
1280 g_object_ref (priv->ui_manager);
1281 g_object_unref (gui);
1283 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1284 priv->mic_menu = empathy_mic_menu_new (self);
1286 empathy_call_window_show_hangup_button (self, TRUE);
1288 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1290 /* Retrieve initial volume */
1291 priv->volume = g_settings_get_double (priv->settings,
1292 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1294 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1295 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1297 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1298 /* These signals are used to track the window position and save it
1299 * when the window is destroyed. We need to do this as we don't want
1300 * the window geometry to be saved with the dialpad taken into account. */
1301 g_signal_connect (self, "destroy",
1302 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1303 g_signal_connect (self, "configure-event",
1304 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1305 g_signal_connect (self, "window-state-event",
1306 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1308 /* Don't display labels in both toolbars */
1309 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1312 /* Instead of specifying a width and a height, we specify only one size. That's
1313 because we want a square avatar icon. */
1315 init_contact_avatar_with_size (EmpathyContact *contact,
1316 GtkWidget *image_widget,
1319 GdkPixbuf *pixbuf_avatar = NULL;
1321 if (contact != NULL)
1323 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1327 if (pixbuf_avatar == NULL)
1329 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1330 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1333 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1335 if (pixbuf_avatar != NULL)
1336 g_object_unref (pixbuf_avatar);
1340 set_window_title (EmpathyCallWindow *self)
1342 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1345 if (priv->contact != NULL)
1347 /* translators: Call is a noun and %s is the contact name. This string
1348 * is used in the window title */
1349 tmp = g_strdup_printf (_("Call with %s"),
1350 empathy_contact_get_alias (priv->contact));
1351 gtk_window_set_title (GTK_WINDOW (self), tmp);
1356 g_warning ("Unknown remote contact!");
1361 set_remote_user_name (EmpathyCallWindow *self,
1362 EmpathyContact *contact)
1364 const gchar *alias = empathy_contact_get_alias (contact);
1365 const gchar *status = empathy_contact_get_status (contact);
1368 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1369 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1375 contact_name_changed_cb (EmpathyContact *contact,
1377 EmpathyCallWindow *self)
1379 set_window_title (self);
1380 set_remote_user_name (self, contact);
1384 contact_presence_changed_cb (EmpathyContact *contact,
1386 EmpathyCallWindow *self)
1388 set_remote_user_name (self, contact);
1392 contact_avatar_changed_cb (EmpathyContact *contact,
1394 EmpathyCallWindow *self)
1397 GtkAllocation allocation;
1398 GtkWidget *avatar_widget;
1400 avatar_widget = self->priv->remote_user_avatar_widget;
1402 gtk_widget_get_allocation (avatar_widget, &allocation);
1403 size = allocation.height;
1407 /* the widget is not allocated yet, set a default size */
1408 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1409 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1412 init_contact_avatar_with_size (contact, avatar_widget, size);
1414 avatar_widget = self->priv->remote_user_avatar_toolbar;
1416 gtk_widget_get_allocation (avatar_widget, &allocation);
1417 size = allocation.height;
1421 /* the widget is not allocated yet, set a default size */
1422 size = SMALL_TOOLBAR_SIZE;
1425 init_contact_avatar_with_size (contact, avatar_widget, size);
1429 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1430 EmpathyCallHandler *handler)
1432 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1434 tp_g_signal_connect_object (priv->contact, "notify::name",
1435 G_CALLBACK (contact_name_changed_cb), self, 0);
1436 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1437 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1438 tp_g_signal_connect_object (priv->contact, "notify::presence",
1439 G_CALLBACK (contact_presence_changed_cb), self, 0);
1441 set_window_title (self);
1442 set_remote_user_name (self, priv->contact);
1444 init_contact_avatar_with_size (priv->contact,
1445 priv->remote_user_avatar_widget,
1446 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1447 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1449 init_contact_avatar_with_size (priv->contact,
1450 priv->remote_user_avatar_toolbar,
1451 SMALL_TOOLBAR_SIZE);
1453 /* The remote avatar is shown by default and will be hidden when we receive
1454 video from the remote side. */
1455 clutter_actor_hide (priv->video_output);
1456 gtk_widget_show (priv->remote_user_avatar_widget);
1460 update_send_codec (EmpathyCallWindow *self,
1463 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1470 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1471 widget = priv->acodec_encoding_label;
1475 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1476 widget = priv->vcodec_encoding_label;
1482 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1483 gtk_label_set_text (GTK_LABEL (widget), tmp);
1488 send_audio_codec_notify_cb (GObject *object,
1492 EmpathyCallWindow *self = user_data;
1494 update_send_codec (self, TRUE);
1498 send_video_codec_notify_cb (GObject *object,
1502 EmpathyCallWindow *self = user_data;
1504 update_send_codec (self, FALSE);
1508 update_recv_codec (EmpathyCallWindow *self,
1511 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1514 GString *str = NULL;
1518 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1519 widget = priv->acodec_decoding_label;
1523 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1524 widget = priv->vcodec_decoding_label;
1530 for (l = codecs; l != NULL; l = g_list_next (l))
1532 FsCodec *codec = l->data;
1535 str = g_string_new (NULL);
1537 g_string_append (str, ", ");
1539 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1543 gtk_label_set_text (GTK_LABEL (widget), str->str);
1544 g_string_free (str, TRUE);
1548 recv_audio_codecs_notify_cb (GObject *object,
1552 EmpathyCallWindow *self = user_data;
1554 update_recv_codec (self, TRUE);
1558 recv_video_codecs_notify_cb (GObject *object,
1562 EmpathyCallWindow *self = user_data;
1564 update_recv_codec (self, FALSE);
1567 static const gchar *
1568 candidate_type_to_str (FsCandidate *candidate)
1570 switch (candidate->type)
1572 case FS_CANDIDATE_TYPE_HOST:
1574 case FS_CANDIDATE_TYPE_SRFLX:
1575 return "server reflexive";
1576 case FS_CANDIDATE_TYPE_PRFLX:
1577 return "peer reflexive";
1578 case FS_CANDIDATE_TYPE_RELAY:
1580 case FS_CANDIDATE_TYPE_MULTICAST:
1587 static const gchar *
1588 candidate_type_to_desc (FsCandidate *candidate)
1590 switch (candidate->type)
1592 case FS_CANDIDATE_TYPE_HOST:
1593 return _("The IP address as seen by the machine");
1594 case FS_CANDIDATE_TYPE_SRFLX:
1595 return _("The IP address as seen by a server on the Internet");
1596 case FS_CANDIDATE_TYPE_PRFLX:
1597 return _("The IP address of the peer as seen by the other side");
1598 case FS_CANDIDATE_TYPE_RELAY:
1599 return _("The IP address of a relay server");
1600 case FS_CANDIDATE_TYPE_MULTICAST:
1601 return _("The IP address of the multicast group");
1608 update_candidat_widget (EmpathyCallWindow *self,
1611 FsCandidate *candidate)
1615 g_assert (candidate != NULL);
1616 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1617 candidate->port, candidate_type_to_str (candidate));
1619 gtk_label_set_text (GTK_LABEL (label), str);
1620 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1626 candidates_changed_cb (GObject *object,
1628 EmpathyCallWindow *self)
1630 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1631 FsCandidate *candidate = NULL;
1633 if (type == FS_MEDIA_TYPE_VIDEO)
1635 /* Update remote candidate */
1636 candidate = empathy_call_handler_get_video_remote_candidate (
1639 update_candidat_widget (self, priv->video_remote_candidate_label,
1640 priv->video_remote_candidate_info_img, candidate);
1642 /* Update local candidate */
1643 candidate = empathy_call_handler_get_video_local_candidate (
1646 update_candidat_widget (self, priv->video_local_candidate_label,
1647 priv->video_local_candidate_info_img, candidate);
1651 /* Update remote candidate */
1652 candidate = empathy_call_handler_get_audio_remote_candidate (
1655 update_candidat_widget (self, priv->audio_remote_candidate_label,
1656 priv->audio_remote_candidate_info_img, candidate);
1658 /* Update local candidate */
1659 candidate = empathy_call_handler_get_audio_local_candidate (
1662 update_candidat_widget (self, priv->audio_local_candidate_label,
1663 priv->audio_local_candidate_info_img, candidate);
1668 empathy_call_window_constructed (GObject *object)
1670 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1671 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1672 TpyCallChannel *call;
1674 g_assert (priv->handler != NULL);
1676 g_object_get (priv->handler, "call-channel", &call, NULL);
1677 priv->outgoing = (call == NULL);
1679 g_object_unref (call);
1681 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1682 g_assert (priv->contact != NULL);
1684 empathy_call_window_setup_avatars (self, priv->handler);
1685 empathy_call_window_set_state_connecting (self);
1687 if (!empathy_call_handler_has_initial_video (priv->handler))
1689 gtk_toggle_tool_button_set_active (
1690 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1692 /* If call has InitialVideo, the preview will be started once the call has
1693 * been started (start_call()). */
1695 update_send_codec (self, TRUE);
1696 update_send_codec (self, FALSE);
1697 update_recv_codec (self, TRUE);
1698 update_recv_codec (self, FALSE);
1700 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1701 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1702 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1703 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1704 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1705 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1706 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1707 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1709 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1710 G_CALLBACK (candidates_changed_cb), self, 0);
1713 static void empathy_call_window_dispose (GObject *object);
1714 static void empathy_call_window_finalize (GObject *object);
1717 empathy_call_window_set_property (GObject *object,
1718 guint property_id, const GValue *value, GParamSpec *pspec)
1720 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1722 switch (property_id)
1724 case PROP_CALL_HANDLER:
1725 priv->handler = g_value_dup_object (value);
1728 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1733 empathy_call_window_get_property (GObject *object,
1734 guint property_id, GValue *value, GParamSpec *pspec)
1736 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1738 switch (property_id)
1740 case PROP_CALL_HANDLER:
1741 g_value_set_object (value, priv->handler);
1744 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1749 empathy_call_window_class_init (
1750 EmpathyCallWindowClass *empathy_call_window_class)
1752 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1753 GParamSpec *param_spec;
1755 g_type_class_add_private (empathy_call_window_class,
1756 sizeof (EmpathyCallWindowPriv));
1758 object_class->constructed = empathy_call_window_constructed;
1759 object_class->set_property = empathy_call_window_set_property;
1760 object_class->get_property = empathy_call_window_get_property;
1762 object_class->dispose = empathy_call_window_dispose;
1763 object_class->finalize = empathy_call_window_finalize;
1765 param_spec = g_param_spec_object ("handler",
1766 "handler", "The call handler",
1767 EMPATHY_TYPE_CALL_HANDLER,
1768 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1769 g_object_class_install_property (object_class,
1770 PROP_CALL_HANDLER, param_spec);
1774 empathy_call_window_dispose (GObject *object)
1776 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1777 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1779 if (priv->dispose_has_run)
1782 priv->dispose_has_run = TRUE;
1784 if (priv->handler != NULL)
1786 empathy_call_handler_stop_call (priv->handler);
1787 tp_clear_object (&priv->handler);
1790 if (priv->bus_message_source_id != 0)
1792 g_source_remove (priv->bus_message_source_id);
1793 priv->bus_message_source_id = 0;
1796 if (priv->got_video_src > 0)
1798 g_source_remove (priv->got_video_src);
1799 priv->got_video_src = 0;
1802 if (priv->inactivity_src > 0)
1804 g_source_remove (priv->inactivity_src);
1805 priv->inactivity_src = 0;
1808 tp_clear_object (&priv->pipeline);
1809 tp_clear_object (&priv->video_input);
1810 tp_clear_object (&priv->audio_input);
1811 tp_clear_object (&priv->video_tee);
1812 tp_clear_object (&priv->ui_manager);
1813 tp_clear_object (&priv->fullscreen);
1814 tp_clear_object (&priv->camera_monitor);
1815 tp_clear_object (&priv->settings);
1816 tp_clear_object (&priv->transitions);
1818 g_list_free_full (priv->notifiers, g_object_unref);
1820 if (priv->timer_id != 0)
1821 g_source_remove (priv->timer_id);
1824 if (priv->contact != NULL)
1826 g_signal_handlers_disconnect_by_func (priv->contact,
1827 contact_name_changed_cb, self);
1828 priv->contact = NULL;
1832 tp_clear_object (&priv->sound_mgr);
1834 tp_clear_object (&priv->mic_menu);
1836 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1840 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1842 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1844 if (priv->video_output_motion_handler_id != 0)
1846 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1847 priv->video_output_motion_handler_id);
1848 priv->video_output_motion_handler_id = 0;
1853 empathy_call_window_finalize (GObject *object)
1855 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1856 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1858 disconnect_video_output_motion_handler (self);
1860 /* free any data held directly by the object here */
1861 g_mutex_free (priv->lock);
1863 g_timer_destroy (priv->timer);
1865 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1870 empathy_call_window_new (EmpathyCallHandler *handler)
1872 return EMPATHY_CALL_WINDOW (
1873 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1877 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1878 GstElement *conference, gpointer user_data)
1880 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1881 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1882 FsElementAddedNotifier *notifier;
1885 DEBUG ("Conference added");
1887 /* Add notifier to set the various element properties as needed */
1888 notifier = fs_element_added_notifier_new ();
1889 keyfile = fs_utils_get_default_element_properties (conference);
1891 if (keyfile != NULL)
1892 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1894 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1896 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1898 gst_bin_add (GST_BIN (priv->pipeline), conference);
1899 gst_element_set_state (conference, GST_STATE_PLAYING);
1903 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1904 GstElement *conference, gpointer user_data)
1906 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1907 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1909 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1910 gst_element_set_state (conference, GST_STATE_NULL);
1914 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1916 GstStateChangeReturn state_change_return;
1917 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1919 if (priv->pipeline == NULL)
1922 if (priv->bus_message_source_id != 0)
1924 g_source_remove (priv->bus_message_source_id);
1925 priv->bus_message_source_id = 0;
1928 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1930 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1931 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1933 if (priv->pipeline != NULL)
1934 g_object_unref (priv->pipeline);
1935 priv->pipeline = NULL;
1937 if (priv->audio_output != NULL)
1938 g_object_unref (priv->audio_output);
1939 priv->audio_output = NULL;
1941 if (priv->video_tee != NULL)
1942 g_object_unref (priv->video_tee);
1943 priv->video_tee = NULL;
1945 if (priv->video_preview != NULL)
1946 clutter_actor_destroy (priv->video_preview);
1947 priv->video_preview = NULL;
1949 priv->funnel = NULL;
1951 create_pipeline (self);
1952 /* Call will be started when user will hit the 'redial' button */
1953 priv->start_call_when_playing = FALSE;
1954 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1960 g_message ("Error: could not destroy pipeline. Closing call window");
1961 gtk_widget_destroy (GTK_WIDGET (self));
1968 reset_details_pane (EmpathyCallWindow *self)
1970 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1972 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1973 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1974 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1975 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1979 empathy_call_window_disconnected (EmpathyCallWindow *self,
1982 gboolean could_disconnect = FALSE;
1983 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1984 gboolean could_reset_pipeline;
1986 /* Leave full screen mode if needed */
1987 gtk_window_unfullscreen (GTK_WINDOW (self));
1989 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1990 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1992 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1994 if (priv->call_state == CONNECTING)
1995 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1997 if (priv->call_state != REDIALING)
1998 priv->call_state = DISCONNECTED;
2000 if (could_reset_pipeline)
2002 g_mutex_lock (priv->lock);
2004 g_timer_stop (priv->timer);
2006 if (priv->timer_id != 0)
2007 g_source_remove (priv->timer_id);
2010 g_mutex_unlock (priv->lock);
2013 /* We are about to destroy the window, no need to update it or create
2014 * a video preview */
2017 empathy_call_window_status_message (self, _("Disconnected"));
2019 empathy_call_window_show_hangup_button (self, FALSE);
2021 /* Unsensitive the camera and mic button */
2022 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2023 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2025 /* Be sure that the mic button is enabled */
2026 gtk_toggle_tool_button_set_active (
2027 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2029 if (priv->camera_state == CAMERA_STATE_ON)
2031 /* Restart the preview with the new pipeline. */
2032 display_video_preview (self, TRUE);
2035 /* destroy the video output; it will be recreated when we'll redial */
2036 disconnect_video_output_motion_handler (self);
2037 if (priv->video_output != NULL)
2038 clutter_actor_destroy (priv->video_output);
2039 priv->video_output = NULL;
2040 if (priv->got_video_src > 0)
2042 g_source_remove (priv->got_video_src);
2043 priv->got_video_src = 0;
2046 gtk_widget_show (priv->remote_user_avatar_widget);
2048 reset_details_pane (self);
2050 priv->sending_video = FALSE;
2051 priv->call_started = FALSE;
2053 could_disconnect = TRUE;
2055 /* TODO: display the self avatar of the preview (depends if the "Always
2056 * Show Video Preview" is enabled or not) */
2059 return could_disconnect;
2064 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2067 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2068 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2070 if (empathy_call_window_disconnected (self, TRUE) &&
2071 priv->call_state == REDIALING)
2072 empathy_call_window_restart_call (self);
2076 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2078 FsMediaType media_type,
2079 EmpathyCallWindow *self)
2081 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2083 DEBUG ("removing content");
2086 * This assumes that there is only one video stream per channel...
2089 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2091 if (priv->funnel != NULL)
2095 output = priv->video_output_sink;
2097 gst_element_set_state (output, GST_STATE_NULL);
2098 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2100 gst_bin_remove (GST_BIN (priv->pipeline), output);
2101 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2102 priv->funnel = NULL;
2106 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2108 if (priv->audio_output != NULL)
2110 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2112 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2113 priv->audio_output = NULL;
2121 /* Called with global lock held */
2123 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2125 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2129 if (priv->funnel == NULL)
2131 output = priv->video_output_sink;
2133 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2137 g_warning ("Could not create fsfunnel");
2141 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2143 gst_object_unref (priv->funnel);
2144 priv->funnel = NULL;
2145 g_warning ("Could not add funnel to pipeline");
2149 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2151 g_warning ("Could not add the video output widget to the pipeline");
2155 if (!gst_element_link (priv->funnel, output))
2157 g_warning ("Could not link output sink to funnel");
2158 goto error_output_added;
2161 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2163 g_warning ("Could not start video sink");
2164 goto error_output_added;
2167 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2169 g_warning ("Could not start funnel");
2170 goto error_output_added;
2174 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2177 g_warning ("Could not get request pad from funnel");
2184 gst_element_set_locked_state (priv->funnel, TRUE);
2185 gst_element_set_locked_state (output, TRUE);
2187 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2188 gst_element_set_state (output, GST_STATE_NULL);
2190 gst_bin_remove (GST_BIN (priv->pipeline), output);
2191 gst_element_set_locked_state (output, FALSE);
2195 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2196 priv->funnel = NULL;
2201 /* Called with global lock held */
2203 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2205 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2207 GstPadTemplate *template;
2209 if (priv->audio_output == NULL)
2211 priv->audio_output = empathy_audio_sink_new ();
2212 g_object_ref_sink (priv->audio_output);
2214 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2216 g_warning ("Could not add audio sink to pipeline");
2217 g_object_unref (priv->audio_output);
2218 goto error_add_output;
2221 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2223 g_warning ("Could not start audio sink");
2228 template = gst_element_class_get_pad_template (
2229 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2231 pad = gst_element_request_pad (priv->audio_output,
2232 template, NULL, NULL);
2236 g_warning ("Could not get sink pad from sink");
2243 gst_element_set_locked_state (priv->audio_output, TRUE);
2244 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2245 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2246 priv->audio_output = NULL;
2254 empathy_call_window_update_timer (gpointer user_data)
2256 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2257 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2258 const gchar *status;
2262 time_ = g_timer_elapsed (priv->timer, NULL);
2264 if (priv->call_state == HELD)
2265 status = _("On hold");
2266 else if (!gtk_toggle_tool_button_get_active (
2267 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2270 status = _("Duration");
2272 /* Translators: 'status - minutes:seconds' the caller has been connected */
2273 str = g_strdup_printf (_("%s — %d:%02dm"),
2275 (int) time_ / 60, (int) time_ % 60);
2276 empathy_call_window_status_message (self, str);
2284 display_error (EmpathyCallWindow *self,
2285 TpyCallChannel *call,
2289 const gchar *details)
2291 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2292 GtkWidget *info_bar;
2293 GtkWidget *content_area;
2300 /* Create info bar */
2301 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2304 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2306 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2308 /* hbox containing the image and the messages vbox */
2309 hbox = gtk_hbox_new (FALSE, 3);
2310 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2313 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2314 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2316 /* vbox containing the main message and the details expander */
2317 vbox = gtk_vbox_new (FALSE, 3);
2318 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2321 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2323 label = gtk_label_new (NULL);
2324 gtk_label_set_markup (GTK_LABEL (label), txt);
2325 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2326 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2329 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2332 if (details != NULL)
2334 GtkWidget *expander;
2336 expander = gtk_expander_new (_("Technical Details"));
2338 txt = g_strdup_printf ("<i>%s</i>", details);
2340 label = gtk_label_new (NULL);
2341 gtk_label_set_markup (GTK_LABEL (label), txt);
2342 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2343 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2346 gtk_container_add (GTK_CONTAINER (expander), label);
2347 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2350 g_signal_connect (info_bar, "response",
2351 G_CALLBACK (gtk_widget_destroy), NULL);
2353 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2354 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2355 gtk_widget_show_all (info_bar);
2359 media_stream_error_to_txt (EmpathyCallWindow *self,
2360 TpyCallChannel *call,
2362 TpMediaStreamError error)
2364 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2365 const gchar *cm = NULL;
2371 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2373 return g_strdup_printf (
2374 _("%s's software does not understand any of the audio formats "
2375 "supported by your computer"),
2376 empathy_contact_get_alias (priv->contact));
2378 return g_strdup_printf (
2379 _("%s's software does not understand any of the video formats "
2380 "supported by your computer"),
2381 empathy_contact_get_alias (priv->contact));
2383 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2384 return g_strdup_printf (
2385 _("Can't establish a connection to %s. "
2386 "One of you might be on a network that does not allow "
2387 "direct connections."),
2388 empathy_contact_get_alias (priv->contact));
2390 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2391 return g_strdup (_("There was a failure on the network"));
2393 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2395 return g_strdup (_("The audio formats necessary for this call "
2396 "are not installed on your computer"));
2398 return g_strdup (_("The video formats necessary for this call "
2399 "are not installed on your computer"));
2401 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2402 tp_connection_parse_object_path (
2403 tp_channel_borrow_connection (TP_CHANNEL (call)),
2406 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2407 "product=Telepathy&component=%s", cm);
2409 result = g_strdup_printf (
2410 _("Something unexpected happened in a Telepathy component. "
2411 "Please <a href=\"%s\">report this bug</a> and attach "
2412 "logs gathered from the 'Debug' window in the Help menu."), url);
2418 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2419 return g_strdup (_("There was a failure in the call engine"));
2421 case TP_MEDIA_STREAM_ERROR_EOS:
2422 return g_strdup (_("The end of the stream was reached"));
2424 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2431 empathy_call_window_stream_error (EmpathyCallWindow *self,
2432 TpyCallChannel *call,
2441 desc = media_stream_error_to_txt (self, call, audio, code);
2444 /* No description, use the error message. That's not great as it's not
2445 * localized but it's better than nothing. */
2446 display_error (self, call, icon, title, msg, NULL);
2450 display_error (self, call, icon, title, desc, msg);
2456 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2459 EmpathyCallWindow *self)
2461 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2462 "gnome-stock-mic", _("Can't establish audio stream"));
2466 empathy_call_window_video_stream_error (TpyCallChannel *call,
2469 EmpathyCallWindow *self)
2471 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2472 "camera-web", _("Can't establish video stream"));
2477 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2479 EmpathyCallWindow *self)
2481 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2482 TpyCallChannel *call;
2483 gboolean can_send_video;
2485 if (state != TPY_CALL_STATE_ACCEPTED)
2488 if (priv->call_state == CONNECTED)
2491 g_timer_start (priv->timer);
2492 priv->call_state = CONNECTED;
2494 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2496 can_send_video = priv->video_input != NULL &&
2497 empathy_contact_can_voip_video (priv->contact) &&
2498 empathy_camera_monitor_get_available (priv->camera_monitor);
2500 g_object_get (priv->handler, "call-channel", &call, NULL);
2502 if (tpy_call_channel_has_dtmf (call))
2503 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2505 if (priv->video_input == NULL)
2506 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2508 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2510 empathy_call_window_show_hangup_button (self, TRUE);
2512 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2514 clutter_actor_hide (priv->video_output);
2515 gtk_widget_show (priv->remote_user_avatar_widget);
2517 g_object_unref (call);
2519 g_mutex_lock (priv->lock);
2521 priv->timer_id = g_timeout_add_seconds (1,
2522 empathy_call_window_update_timer, self);
2524 g_mutex_unlock (priv->lock);
2526 empathy_call_window_update_timer (self);
2528 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2532 empathy_call_window_show_video_output_cb (gpointer user_data)
2534 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2536 if (self->priv->video_output != NULL)
2538 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2539 clutter_actor_show (self->priv->video_output);
2540 clutter_actor_raise_top (self->priv->floating_toolbar);
2547 empathy_call_window_check_video_cb (gpointer data)
2549 EmpathyCallWindow *self = data;
2551 if (self->priv->got_video)
2553 self->priv->got_video = FALSE;
2557 /* No video in the last N seconds, display the remote avatar */
2558 empathy_call_window_show_video_output (self, FALSE);
2563 /* Called from the streaming thread */
2565 empathy_call_window_video_probe_cb (GstPad *pad,
2566 GstMiniObject *mini_obj,
2567 EmpathyCallWindow *self)
2570 if (GST_IS_EVENT (mini_obj))
2573 if (G_UNLIKELY (!self->priv->got_video))
2575 /* show the remote video */
2576 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2577 empathy_call_window_show_video_output_cb,
2578 g_object_ref (self), g_object_unref);
2580 self->priv->got_video = TRUE;
2586 /* Called from the streaming thread */
2588 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2589 GstPad *src, guint media_type, gpointer user_data)
2591 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2592 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2593 gboolean retval = FALSE;
2597 g_mutex_lock (priv->lock);
2601 case TP_MEDIA_STREAM_TYPE_AUDIO:
2602 pad = empathy_call_window_get_audio_sink_pad (self);
2604 case TP_MEDIA_STREAM_TYPE_VIDEO:
2605 g_idle_add (empathy_call_window_show_video_output_cb, self);
2606 pad = empathy_call_window_get_video_sink_pad (self);
2608 gst_pad_add_data_probe (src,
2609 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2610 if (priv->got_video_src > 0)
2611 g_source_remove (priv->got_video_src);
2612 priv->got_video_src = g_timeout_add_seconds (5,
2613 empathy_call_window_check_video_cb, self);
2616 g_assert_not_reached ();
2622 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2623 g_warning ("Could not link %s sink pad",
2624 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2628 gst_object_unref (pad);
2632 /* If no sink could be linked, try to add fakesink to prevent the whole call
2637 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2639 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2641 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2642 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2643 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2645 gst_element_set_locked_state (fakesink, TRUE);
2646 gst_element_set_state (fakesink, GST_STATE_NULL);
2647 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2651 DEBUG ("Could not link real sink, linked fakesink instead");
2653 gst_object_unref (sinkpad);
2657 gst_object_unref (fakesink);
2662 g_mutex_unlock (priv->lock);
2668 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2669 GstPad *sink, FsMediaType media_type, gpointer user_data)
2671 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2672 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2674 gboolean retval = FALSE;
2678 case FS_MEDIA_TYPE_AUDIO:
2679 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2681 g_warning ("Could not add audio source to pipeline");
2685 pad = gst_element_get_static_pad (priv->audio_input, "src");
2688 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2689 g_warning ("Could not get source pad from audio source");
2693 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2695 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2696 g_warning ("Could not link audio source to farsight");
2700 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2702 g_warning ("Could not start audio source");
2703 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2704 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2710 case FS_MEDIA_TYPE_VIDEO:
2711 if (priv->video_tee != NULL)
2713 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2714 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2716 g_warning ("Could not link video source input pipeline");
2719 gst_object_unref (pad);
2725 g_assert_not_reached ();
2732 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2734 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2735 GstElement *preview;
2737 disable_camera (self);
2739 DEBUG ("remove video input");
2740 preview = priv->video_preview_sink;
2742 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2743 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2744 gst_element_set_state (preview, GST_STATE_NULL);
2746 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2749 g_object_unref (priv->video_input);
2750 priv->video_input = NULL;
2751 g_object_unref (priv->video_tee);
2752 priv->video_tee = NULL;
2753 clutter_actor_destroy (priv->video_preview);
2754 priv->video_preview = NULL;
2756 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2760 start_call (EmpathyCallWindow *self)
2762 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2764 priv->call_started = TRUE;
2765 empathy_call_handler_start_call (priv->handler,
2766 gtk_get_current_event_time ());
2768 if (empathy_call_handler_has_initial_video (priv->handler))
2770 TpyCallChannel *call;
2773 g_object_get (priv->handler, "call-channel", &call, NULL);
2774 s = tpy_call_channel_get_video_state (call);
2776 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2777 s == TPY_SENDING_STATE_SENDING)
2779 /* Enable 'send video' buttons and display the preview */
2780 gtk_toggle_tool_button_set_active (
2781 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2785 gtk_toggle_tool_button_set_active (
2786 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2788 if (priv->video_preview == NULL)
2790 create_video_preview (self);
2791 add_video_preview_to_pipeline (self);
2795 g_object_unref (call);
2800 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2803 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2804 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2807 empathy_call_handler_bus_message (priv->handler, bus, message);
2809 switch (GST_MESSAGE_TYPE (message))
2811 case GST_MESSAGE_STATE_CHANGED:
2812 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2814 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2816 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2817 !priv->call_started)
2819 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2820 if (newstate == GST_STATE_PAUSED)
2822 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2823 priv->pipeline_playing = TRUE;
2825 if (priv->start_call_when_playing)
2830 case GST_MESSAGE_ERROR:
2832 GError *error = NULL;
2833 GstElement *gst_error;
2836 gst_message_parse_error (message, &error, &debug);
2837 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2839 g_message ("Element error: %s -- %s\n", error->message, debug);
2841 if (g_str_has_prefix (gst_element_get_name (gst_error),
2842 VIDEO_INPUT_ERROR_PREFIX))
2844 /* Remove the video input and continue */
2845 if (priv->video_input != NULL)
2846 empathy_call_window_remove_video_input (self);
2847 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2851 empathy_call_window_disconnected (self, TRUE);
2853 g_error_free (error);
2856 case GST_MESSAGE_UNKNOWN:
2857 case GST_MESSAGE_EOS:
2858 case GST_MESSAGE_WARNING:
2859 case GST_MESSAGE_INFO:
2860 case GST_MESSAGE_TAG:
2861 case GST_MESSAGE_BUFFERING:
2862 case GST_MESSAGE_STATE_DIRTY:
2863 case GST_MESSAGE_STEP_DONE:
2864 case GST_MESSAGE_CLOCK_PROVIDE:
2865 case GST_MESSAGE_CLOCK_LOST:
2866 case GST_MESSAGE_NEW_CLOCK:
2867 case GST_MESSAGE_STRUCTURE_CHANGE:
2868 case GST_MESSAGE_STREAM_STATUS:
2869 case GST_MESSAGE_APPLICATION:
2870 case GST_MESSAGE_ELEMENT:
2871 case GST_MESSAGE_SEGMENT_START:
2872 case GST_MESSAGE_SEGMENT_DONE:
2873 case GST_MESSAGE_DURATION:
2874 case GST_MESSAGE_ANY:
2883 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2884 GHashTable *members,
2885 EmpathyCallWindow *self)
2887 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2888 GHashTableIter iter;
2889 gpointer key, value;
2890 gboolean held = FALSE;
2892 g_hash_table_iter_init (&iter, members);
2893 while (g_hash_table_iter_next (&iter, &key, &value))
2895 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2897 /* This assumes this is a 1-1 call, otherwise one participant
2898 * putting the call on hold wouldn't mean the call is on hold
2906 priv->call_state = HELD;
2907 else if (priv->call_state == HELD)
2908 priv->call_state = CONNECTED;
2912 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2914 EmpathyCallWindow *self)
2916 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2917 TpyCallChannel *call;
2919 g_object_get (priv->handler, "call-channel", &call, NULL);
2924 tp_g_signal_connect_object (call, "audio-stream-error",
2925 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2926 tp_g_signal_connect_object (call, "video-stream-error",
2927 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2930 tp_g_signal_connect_object (call, "members-changed",
2931 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2933 g_object_unref (call);
2937 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2939 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2940 TpyCallChannel *call;
2943 /* Make the hangup button twice as wide */
2944 width = gtk_widget_get_allocated_width (priv->hangup_button);
2945 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2947 g_signal_connect (priv->handler, "state-changed",
2948 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2949 g_signal_connect (priv->handler, "conference-added",
2950 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2951 g_signal_connect (priv->handler, "conference-removed",
2952 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2953 g_signal_connect (priv->handler, "closed",
2954 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2955 g_signal_connect (priv->handler, "src-pad-added",
2956 G_CALLBACK (empathy_call_window_src_added_cb), window);
2957 g_signal_connect (priv->handler, "sink-pad-added",
2958 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2959 g_signal_connect (priv->handler, "sink-pad-removed",
2960 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2962 g_object_get (priv->handler, "call-channel", &call, NULL);
2965 call_handler_notify_call_cb (priv->handler, NULL, window);
2966 g_object_unref (call);
2970 /* call-channel doesn't exist yet, we'll connect signals once it has been
2972 g_signal_connect (priv->handler, "notify::call-channel",
2973 G_CALLBACK (call_handler_notify_call_cb), window);
2976 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2980 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2981 EmpathyCallWindow *window)
2983 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2985 if (priv->pipeline != NULL)
2987 if (priv->bus_message_source_id != 0)
2989 g_source_remove (priv->bus_message_source_id);
2990 priv->bus_message_source_id = 0;
2993 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2996 if (priv->call_state == CONNECTING)
2997 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3003 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3006 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3008 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3013 gtk_widget_hide (priv->dtmf_panel);
3014 gtk_widget_hide (menu);
3015 gtk_widget_hide (priv->toolbar);
3019 if (priv->dialpad_was_visible_before_fs)
3020 gtk_widget_show (priv->dtmf_panel);
3022 gtk_widget_show (menu);
3023 gtk_widget_show (priv->toolbar);
3025 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3026 priv->original_height_before_fs);
3031 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3033 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3035 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3036 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3037 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3038 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3040 if (priv->video_output != NULL)
3043 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3044 priv->video_output, TRUE, TRUE,
3045 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3052 empathy_call_window_state_event_cb (GtkWidget *widget,
3053 GdkEventWindowState *event, EmpathyCallWindow *window)
3055 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3057 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3058 gboolean set_fullscreen = event->new_window_state &
3059 GDK_WINDOW_STATE_FULLSCREEN;
3063 gboolean dialpad_was_visible;
3064 GtkAllocation allocation;
3065 gint original_width, original_height;
3067 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3068 original_width = allocation.width;
3069 original_height = allocation.height;
3071 g_object_get (priv->dtmf_panel,
3072 "visible", &dialpad_was_visible,
3075 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3076 priv->original_width_before_fs = original_width;
3077 priv->original_height_before_fs = original_height;
3079 if (priv->video_output_motion_handler_id == 0 &&
3080 priv->video_output != NULL)
3082 priv->video_output_motion_handler_id = g_signal_connect (
3083 G_OBJECT (priv->video_container), "motion-notify-event",
3084 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3090 disconnect_video_output_motion_handler (window);
3093 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3095 show_controls (window, set_fullscreen);
3096 show_borders (window, set_fullscreen);
3097 gtk_action_set_stock_id (priv->menu_fullscreen,
3098 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3099 priv->is_fullscreen = set_fullscreen;
3106 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3109 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3110 int w, h, dialpad_width;
3111 GtkAllocation allocation;
3113 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3114 w = allocation.width;
3115 h = allocation.height;
3117 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3121 gtk_widget_show (priv->dtmf_panel);
3127 gtk_widget_hide (priv->dtmf_panel);
3131 gtk_window_resize (GTK_WINDOW (window), w, h);
3135 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3138 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3139 TpyCallChannel *call;
3141 priv->sending_video = (state == CAMERA_STATE_ON);
3143 if (state == CAMERA_STATE_ON)
3145 /* When we start sending video, we want to show the video preview by
3147 display_video_preview (window, TRUE);
3151 display_video_preview (window, FALSE);
3154 if (priv->call_state != CONNECTED)
3157 g_object_get (priv->handler, "call-channel", &call, NULL);
3158 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3159 tpy_call_channel_send_video (call, priv->sending_video);
3160 g_object_unref (call);
3164 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3165 EmpathyCallWindow *self)
3167 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3170 active = (gtk_toggle_tool_button_get_active (toggle));
3172 /* We don't want the settings callback to react to this change to avoid
3174 g_signal_handlers_block_by_func (priv->settings,
3175 empathy_call_window_prefs_volume_changed_cb, self);
3179 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3180 priv->volume * 100);
3184 /* TODO, Instead of setting the input volume to 0 we should probably
3185 * stop sending but this would cause the audio call to drop if both
3186 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3187 * in the future. GNOME #574574
3189 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3193 g_signal_handlers_unblock_by_func (priv->settings,
3194 empathy_call_window_prefs_volume_changed_cb, self);
3198 empathy_call_window_hangup_cb (gpointer object,
3199 EmpathyCallWindow *self)
3201 empathy_call_handler_stop_call (self->priv->handler);
3203 empathy_call_window_disconnected (self, TRUE);
3207 empathy_call_window_restart_call (EmpathyCallWindow *window)
3209 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3211 /* Remove error info bars */
3212 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3213 (GtkCallback) gtk_widget_destroy, NULL);
3215 create_video_output_widget (window);
3217 /* While the call was disconnected, the input volume might have changed.
3218 * However, since the audio_input source was destroyed, its volume has not
3219 * been updated during that time. That's why we manually update it here */
3220 empathy_call_window_mic_volume_changed (window);
3222 priv->outgoing = TRUE;
3223 empathy_call_window_set_state_connecting (window);
3225 if (priv->pipeline_playing)
3226 start_call (window);
3228 /* call will be started when the pipeline is ready */
3229 priv->start_call_when_playing = TRUE;
3231 empathy_call_window_setup_avatars (window, priv->handler);
3233 empathy_call_window_show_hangup_button (window, TRUE);
3237 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3238 EmpathyCallWindow *window)
3242 active = gtk_toggle_tool_button_get_active (button);
3244 empathy_call_window_show_dialpad (window, active);
3248 empathy_call_window_fullscreen_cb (gpointer object,
3249 EmpathyCallWindow *window)
3251 empathy_call_window_fullscreen_toggle (window);
3255 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3257 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3259 if (priv->is_fullscreen)
3260 gtk_window_unfullscreen (GTK_WINDOW (window));
3262 gtk_window_fullscreen (GTK_WINDOW (window));
3266 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3267 GdkEventButton *event, EmpathyCallWindow *window)
3269 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3271 empathy_call_window_video_menu_popup (window, event->button);
3279 empathy_call_window_key_press_cb (GtkWidget *video_output,
3280 GdkEventKey *event, EmpathyCallWindow *window)
3282 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3284 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3286 /* Since we are in fullscreen mode, toggling will bring us back to
3288 empathy_call_window_fullscreen_toggle (window);
3296 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3297 GdkEventMotion *event, EmpathyCallWindow *window)
3299 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3301 if (priv->is_fullscreen)
3303 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3305 /* Show the bottom toolbar */
3306 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3313 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3317 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3319 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3321 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3322 button, gtk_get_current_event_time ());
3323 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3327 empathy_call_window_status_message (EmpathyCallWindow *self,
3330 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3334 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3335 gdouble value, EmpathyCallWindow *window)
3337 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3339 if (priv->audio_output == NULL)
3342 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3347 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3349 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3351 return priv->ui_manager;
3354 EmpathyGstAudioSrc *
3355 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3357 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3359 return (EmpathyGstAudioSrc *) priv->audio_input;