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"
68 #include "empathy-camera-menu.h"
70 #define CONTENT_HBOX_BORDER_WIDTH 6
71 #define CONTENT_HBOX_SPACING 3
72 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
74 #define SELF_VIDEO_SECTION_WIDTH 120
75 #define SELF_VIDEO_SECTION_HEIGHT 90
76 #define SELF_VIDEO_SECTION_MARGIN 10
78 #define FLOATING_TOOLBAR_OPACITY 192
79 #define FLOATING_TOOLBAR_WIDTH 280
80 #define FLOATING_TOOLBAR_HEIGHT 36
81 #define FLOATING_TOOLBAR_SPACING 20
83 /* The avatar's default width and height are set to the same value because we
84 want a square icon. */
85 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
86 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
87 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
89 #define SMALL_TOOLBAR_SIZE 36
91 /* If an video input error occurs, the error message will start with "v4l" */
92 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
94 /* The time interval in milliseconds between 2 outgoing rings */
95 #define MS_BETWEEN_RING 500
97 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
100 PROP_CALL_HANDLER = 1,
112 CAMERA_STATE_OFF = 0,
118 PREVIEW_POS_TOP_LEFT,
119 PREVIEW_POS_TOP_RIGHT,
120 PREVIEW_POS_BOTTOM_LEFT,
121 PREVIEW_POS_BOTTOM_RIGHT,
124 struct _EmpathyCallWindowPriv
126 gboolean dispose_has_run;
127 EmpathyCallHandler *handler;
129 EmpathyContact *contact;
131 EmpathyCameraMonitor *camera_monitor;
136 GtkUIManager *ui_manager;
137 GtkWidget *errors_vbox;
138 /* widget displays the video received from the remote user. This widget is
139 * alive only during call. */
140 ClutterActor *video_output;
141 ClutterActor *video_preview;
142 ClutterActor *preview_hidden_button;
143 ClutterActor *preview_rectangle1;
144 ClutterActor *preview_rectangle2;
145 ClutterActor *preview_rectangle3;
146 ClutterActor *preview_rectangle4;
147 ClutterActor *preview_rectangle_box1;
148 ClutterActor *preview_rectangle_box2;
149 ClutterActor *preview_rectangle_box3;
150 ClutterActor *preview_rectangle_box4;
151 GtkWidget *video_container;
152 GtkWidget *remote_user_avatar_widget;
153 GtkWidget *remote_user_avatar_toolbar;
154 GtkWidget *remote_user_name_toolbar;
155 GtkWidget *status_label;
156 GtkWidget *hangup_button;
157 GtkWidget *audio_call_button;
158 GtkWidget *video_call_button;
159 GtkWidget *mic_button;
160 GtkWidget *camera_button;
161 GtkWidget *dialpad_button;
163 GtkWidget *bottom_toolbar;
164 ClutterActor *floating_toolbar;
166 GtkAction *menu_fullscreen;
167 GtkAction *menu_swap_camera;
169 ClutterState *transitions;
171 /* The box that contains self and remote avatar and video
172 input/output. When we redial, we destroy and re-create the box */
173 ClutterActor *video_box;
174 ClutterLayoutManager *video_layout;
176 /* Coordinates of the preview drag event's start. */
177 PreviewPosition preview_pos;
179 /* We keep a reference on the hbox which contains the main content so we can
180 easilly repack everything when toggling fullscreen */
181 GtkWidget *content_hbox;
183 gulong video_output_motion_handler_id;
184 guint bus_message_source_id;
188 GtkWidget *dtmf_panel;
191 GtkWidget *details_vbox;
192 GtkWidget *vcodec_encoding_label;
193 GtkWidget *acodec_encoding_label;
194 GtkWidget *vcodec_decoding_label;
195 GtkWidget *acodec_decoding_label;
197 GtkWidget *audio_remote_candidate_label;
198 GtkWidget *audio_local_candidate_label;
199 GtkWidget *video_remote_candidate_label;
200 GtkWidget *video_local_candidate_label;
201 GtkWidget *video_remote_candidate_info_img;
202 GtkWidget *video_local_candidate_info_img;
203 GtkWidget *audio_remote_candidate_info_img;
204 GtkWidget *audio_local_candidate_info_img;
206 GstElement *video_input;
207 GstElement *video_preview_sink;
208 GstElement *video_output_sink;
209 GstElement *audio_input;
210 GstElement *audio_output;
211 GstElement *pipeline;
212 GstElement *video_tee;
222 gboolean call_started;
223 gboolean sending_video;
224 CameraState camera_state;
226 EmpathyCallWindowFullscreen *fullscreen;
227 gboolean is_fullscreen;
232 guint inactivity_src;
234 /* Those fields represent the state of the window before it actually was in
236 gboolean dialpad_was_visible_before_fs;
237 gint original_width_before_fs;
238 gint original_height_before_fs;
240 gint x, y, w, h, dialpad_width;
243 /* TRUE if the call should be started when the pipeline is playing */
244 gboolean start_call_when_playing;
245 /* TRUE if we requested to set the pipeline in the playing state */
246 gboolean pipeline_playing;
248 EmpathySoundManager *sound_mgr;
251 EmpathyMicMenu *mic_menu;
252 EmpathyCameraMenu *camera_menu;
255 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
257 static void empathy_call_window_realized_cb (GtkWidget *widget,
258 EmpathyCallWindow *window);
260 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
261 GdkEvent *event, EmpathyCallWindow *window);
263 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
264 GdkEventWindowState *event, EmpathyCallWindow *window);
266 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
269 static void empathy_call_window_mic_toggled_cb (
270 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
272 static void empathy_call_window_hangup_cb (gpointer object,
273 EmpathyCallWindow *window);
275 static void empathy_call_window_fullscreen_cb (gpointer object,
276 EmpathyCallWindow *window);
278 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
280 static gboolean empathy_call_window_video_button_press_cb (
281 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
283 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
284 GdkEventKey *event, EmpathyCallWindow *window);
286 static gboolean empathy_call_window_video_output_motion_notify (
287 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
289 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
292 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
293 EmpathyCallWindow *window);
295 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
297 static void empathy_call_window_status_message (EmpathyCallWindow *window,
300 static gboolean empathy_call_window_bus_message (GstBus *bus,
301 GstMessage *message, gpointer user_data);
304 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
305 gdouble value, EmpathyCallWindow *window);
308 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
311 gtk_widget_set_visible (self->priv->hangup_button, show);
312 gtk_widget_set_visible (self->priv->audio_call_button, !show);
313 gtk_widget_set_visible (self->priv->video_call_button, !show);
317 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
318 EmpathyCallWindow *self)
320 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
321 empathy_call_window_restart_call (self);
325 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
326 EmpathyCallWindow *self)
328 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
329 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
330 empathy_call_window_restart_call (self);
334 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
336 EmpathyCallWindowPriv *priv = GET_PRIV (window);
337 TpyCallChannel *call;
341 g_object_get (priv->handler, "call-channel", &call, NULL);
343 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
344 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
347 tpy_call_channel_dtmf_start_tone (call, event);
349 g_object_unref (call);
353 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
355 EmpathyCallWindowPriv *priv = GET_PRIV (window);
356 TpyCallChannel *call;
358 g_object_get (priv->handler, "call-channel", &call, NULL);
360 tpy_call_channel_dtmf_stop_tone (call);
362 g_object_unref (call);
366 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
368 EmpathyCallWindowPriv *priv = GET_PRIV (self);
371 volume = g_settings_get_double (priv->settings,
372 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
374 /* Don't store the volume because of muting */
375 if (volume > 0 || gtk_toggle_tool_button_get_active (
376 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
377 priv->volume = volume;
379 /* Ensure that the toggle button is active if the volume is > 0 and inactive
380 * if it's smaller than 0 */
381 if ((volume > 0) != gtk_toggle_tool_button_get_active (
382 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
383 gtk_toggle_tool_button_set_active (
384 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
386 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
391 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
393 EmpathyCallWindow *self)
395 empathy_call_window_mic_volume_changed (self);
399 empathy_call_window_raise_actors (EmpathyCallWindow *self)
401 clutter_actor_raise_top (self->priv->floating_toolbar);
403 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
404 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
405 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
406 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
410 empathy_call_window_show_video_output (EmpathyCallWindow *self,
413 if (self->priv->video_output != NULL)
414 g_object_set (self->priv->video_output, "visible", show, NULL);
416 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
418 empathy_call_window_raise_actors (self);
422 create_video_output_widget (EmpathyCallWindow *self)
424 EmpathyCallWindowPriv *priv = GET_PRIV (self);
426 g_assert (priv->video_output == NULL);
427 g_assert (priv->pipeline != NULL);
429 priv->video_output = clutter_texture_new ();
431 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
434 priv->video_output_sink = clutter_gst_video_sink_new (
435 CLUTTER_TEXTURE (priv->video_output));
437 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
440 gtk_widget_add_events (priv->video_container,
441 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
442 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
443 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
447 create_video_input (EmpathyCallWindow *self)
449 EmpathyCallWindowPriv *priv = GET_PRIV (self);
451 g_assert (priv->video_input == NULL);
452 priv->video_input = empathy_video_src_new ();
453 gst_object_ref (priv->video_input);
454 gst_object_sink (priv->video_input);
458 create_audio_input (EmpathyCallWindow *self)
460 EmpathyCallWindowPriv *priv = GET_PRIV (self);
462 g_assert (priv->audio_input == NULL);
463 priv->audio_input = empathy_audio_src_new ();
464 gst_object_ref (priv->audio_input);
465 gst_object_sink (priv->audio_input);
469 add_video_preview_to_pipeline (EmpathyCallWindow *self)
471 EmpathyCallWindowPriv *priv = GET_PRIV (self);
474 g_assert (priv->video_preview != NULL);
475 g_assert (priv->pipeline != NULL);
476 g_assert (priv->video_input != NULL);
477 g_assert (priv->video_tee != NULL);
479 preview = priv->video_preview_sink;
481 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
483 g_warning ("Could not add video input to pipeline");
487 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
489 g_warning ("Could not add video preview to pipeline");
493 if (!gst_element_link (priv->video_input, priv->video_tee))
495 g_warning ("Could not link video input to video tee");
499 if (!gst_element_link (priv->video_tee, preview))
501 g_warning ("Could not link video tee to video preview");
507 empathy_call_window_disable_camera_cb (GtkAction *action,
508 EmpathyCallWindow *self)
510 clutter_actor_destroy (self->priv->preview_hidden_button);
512 gtk_toggle_tool_button_set_active (
513 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
517 empathy_call_window_minimise_camera_cb (GtkAction *action,
518 EmpathyCallWindow *self)
520 clutter_actor_hide (self->priv->video_preview);
521 clutter_actor_show (self->priv->preview_hidden_button);
525 empathy_call_window_maximise_camera_cb (GtkAction *action,
526 EmpathyCallWindow *self)
528 clutter_actor_show (self->priv->video_preview);
529 clutter_actor_hide (self->priv->preview_hidden_button);
533 empathy_call_window_swap_camera_cb (GtkAction *action,
534 EmpathyCallWindow *self)
536 const GList *cameras, *l;
539 DEBUG ("Swapping the camera");
541 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
542 current_cam = empathy_video_src_dup_device (
543 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
545 for (l = cameras; l != NULL; l = l->next)
547 EmpathyCamera *camera = l->data;
549 if (!tp_strdiff (camera->device, current_cam))
554 next = l->next->data;
556 next = cameras->data;
558 /* EmpathyCameraMenu will update itself and do the actual change
560 g_settings_set_string (self->priv->settings,
561 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
568 g_free (current_cam);
572 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
573 EmpathyCamera *camera,
574 EmpathyCallWindow *self)
576 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
578 gtk_action_set_visible (self->priv->menu_swap_camera,
579 g_list_length ((GList *) cameras) >= 2);
583 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
584 EmpathyCamera *camera,
585 EmpathyCallWindow *self)
587 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
589 gtk_action_set_visible (self->priv->menu_swap_camera,
590 g_list_length ((GList *) cameras) >= 2);
594 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
595 EmpathyCallWindow *self)
599 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
601 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
602 0, gtk_get_current_event_time ());
603 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
607 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
608 EmpathyCallWindow *self)
612 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
613 "/preview-hidden-menu");
614 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
615 0, gtk_get_current_event_time ());
616 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
619 static ClutterActor *
620 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
622 ClutterBinAlignment x,
623 ClutterBinAlignment y)
625 ClutterLayoutManager *layout1, *layout2;
626 ClutterActor *rectangle;
627 ClutterActor *box1, *box2;
629 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
630 CLUTTER_BIN_ALIGNMENT_START);
632 box1 = clutter_box_new (layout1);
636 rectangle = clutter_rectangle_new_with_color (
637 CLUTTER_COLOR_Transparent);
639 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
642 clutter_actor_set_size (box1,
643 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
644 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
645 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
647 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
648 CLUTTER_BIN_ALIGNMENT_CENTER);
650 /* We have a box with the margins and the video in the middle inside
651 * a bigger box with an extra bottom margin so we're not on top of
652 * the floating toolbar. */
653 box2 = clutter_box_new (layout2);
655 clutter_actor_set_size (box2,
656 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
657 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
659 clutter_actor_set_size (rectangle,
660 SELF_VIDEO_SECTION_WIDTH + 5, SELF_VIDEO_SECTION_HEIGHT + 5);
662 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
663 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
665 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
668 clutter_actor_hide (rectangle);
674 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
676 self->priv->preview_rectangle1 =
677 empathy_call_window_create_preview_rectangle (self,
678 &self->priv->preview_rectangle_box1,
679 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
680 self->priv->preview_rectangle2 =
681 empathy_call_window_create_preview_rectangle (self,
682 &self->priv->preview_rectangle_box2,
683 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
684 self->priv->preview_rectangle3 =
685 empathy_call_window_create_preview_rectangle (self,
686 &self->priv->preview_rectangle_box3,
687 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
688 self->priv->preview_rectangle4 =
689 empathy_call_window_create_preview_rectangle (self,
690 &self->priv->preview_rectangle_box4,
691 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
695 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
698 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
699 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
700 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
701 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
704 static PreviewPosition
705 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
710 PreviewPosition pos = PREVIEW_POS_NONE;
712 g_return_val_if_fail (clutter_actor_has_allocation (self->priv->video_box),
715 clutter_actor_get_geometry (self->priv->video_box, &box);
717 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
718 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
719 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
720 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
722 pos = PREVIEW_POS_TOP_LEFT;
724 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
725 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
726 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
727 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
729 pos = PREVIEW_POS_TOP_RIGHT;
731 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
732 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
733 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
734 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
736 pos = PREVIEW_POS_BOTTOM_LEFT;
738 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
739 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
740 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
741 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
743 pos = PREVIEW_POS_BOTTOM_RIGHT;
749 static ClutterActor *
750 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
753 ClutterActor *rectangle;
757 case PREVIEW_POS_TOP_LEFT:
758 rectangle = self->priv->preview_rectangle1;
760 case PREVIEW_POS_TOP_RIGHT:
761 rectangle = self->priv->preview_rectangle3;
763 case PREVIEW_POS_BOTTOM_LEFT:
764 rectangle = self->priv->preview_rectangle2;
766 case PREVIEW_POS_BOTTOM_RIGHT:
767 rectangle = self->priv->preview_rectangle4;
777 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
780 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
782 DEBUG ("moving the video preview to %d", pos);
784 self->priv->preview_pos = pos;
788 case PREVIEW_POS_TOP_LEFT:
789 clutter_bin_layout_set_alignment (layout,
790 self->priv->video_preview,
791 CLUTTER_BIN_ALIGNMENT_START,
792 CLUTTER_BIN_ALIGNMENT_START);
794 case PREVIEW_POS_TOP_RIGHT:
795 clutter_bin_layout_set_alignment (layout,
796 self->priv->video_preview,
797 CLUTTER_BIN_ALIGNMENT_END,
798 CLUTTER_BIN_ALIGNMENT_START);
800 case PREVIEW_POS_BOTTOM_LEFT:
801 clutter_bin_layout_set_alignment (layout,
802 self->priv->video_preview,
803 CLUTTER_BIN_ALIGNMENT_START,
804 CLUTTER_BIN_ALIGNMENT_END);
806 case PREVIEW_POS_BOTTOM_RIGHT:
807 clutter_bin_layout_set_alignment (layout,
808 self->priv->video_preview,
809 CLUTTER_BIN_ALIGNMENT_END,
810 CLUTTER_BIN_ALIGNMENT_END);
813 g_warn_if_reached ();
818 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
821 ClutterActor *rectangle;
823 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
825 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
826 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
831 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
832 ClutterActor *rectangle)
834 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
835 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
836 CLUTTER_COLOR_Black);
840 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
842 ClutterActor *rectangle;
844 rectangle = empathy_call_window_get_preview_rectangle (self,
845 self->priv->preview_pos);
847 /* We don't want to darken the rectangle where the preview
850 if (self->priv->preview_rectangle1 != rectangle)
851 empathy_call_window_darken_preview_rectangle (self,
852 self->priv->preview_rectangle1);
854 if (self->priv->preview_rectangle2 != rectangle)
855 empathy_call_window_darken_preview_rectangle (self,
856 self->priv->preview_rectangle2);
858 if (self->priv->preview_rectangle3 != rectangle)
859 empathy_call_window_darken_preview_rectangle (self,
860 self->priv->preview_rectangle3);
862 if (self->priv->preview_rectangle4 != rectangle)
863 empathy_call_window_darken_preview_rectangle (self,
864 self->priv->preview_rectangle4);
868 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
872 ClutterModifierType modifiers,
873 EmpathyCallWindow *self)
875 ClutterActor *stage = clutter_actor_get_stage (actor);
876 ClutterActor *preview = clutter_clone_new (actor);
879 /* Flip the video preview */
880 /* FIXME: disabled because it makes the drag handle to go away! */
881 clutter_actor_set_rotation (preview,
884 SELF_VIDEO_SECTION_WIDTH * 0.5,
889 clutter_container_add_actor (CLUTTER_CONTAINER (stage), preview);
890 clutter_actor_set_position (preview, event_x, event_y);
892 clutter_drag_action_set_drag_handle (action, preview);
894 clutter_actor_set_opacity (actor, 0);
896 empathy_call_window_show_preview_rectangles (self, TRUE);
897 empathy_call_window_darken_preview_rectangles (self);
901 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
905 ClutterModifierType modifiers,
906 EmpathyCallWindow *self)
908 ClutterActor *preview = clutter_drag_action_get_drag_handle (action);
911 /* Get the position before destroying the drag actor, otherwise the
912 * preview_box allocation won't be valid and we won't be able to
913 * calculate the position. */
914 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
916 /* Destroy the video preview copy that we were dragging */
917 clutter_actor_destroy (preview);
919 clutter_actor_set_opacity (actor, 255);
921 if (pos != PREVIEW_POS_NONE)
922 empathy_call_window_move_video_preview (self, pos);
924 empathy_call_window_show_preview_rectangles (self, FALSE);
928 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
932 EmpathyCallWindow *self)
935 gfloat event_x, event_y;
937 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
939 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
941 if (pos != PREVIEW_POS_NONE)
942 empathy_call_window_highlight_preview_rectangle (self, pos);
944 empathy_call_window_darken_preview_rectangles (self);
948 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
949 ClutterCrossingEvent *event,
950 EmpathyCallWindow *self)
952 ClutterActor *rectangle;
954 rectangle = empathy_call_window_get_preview_rectangle (self,
955 self->priv->preview_pos);
957 empathy_call_window_highlight_preview_rectangle (self,
958 self->priv->preview_pos);
960 clutter_actor_show (rectangle);
966 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
967 ClutterCrossingEvent *event,
968 EmpathyCallWindow *self)
970 ClutterActor *rectangle;
972 rectangle = empathy_call_window_get_preview_rectangle (self,
973 self->priv->preview_pos);
975 empathy_call_window_darken_preview_rectangle (self, rectangle);
977 clutter_actor_hide (rectangle);
983 create_video_preview (EmpathyCallWindow *self)
985 EmpathyCallWindowPriv *priv = GET_PRIV (self);
986 ClutterLayoutManager *layout, *layout_center, *layout_end;
987 ClutterActor *preview;
990 ClutterAction *action;
993 g_assert (priv->video_preview == NULL);
995 preview = clutter_texture_new ();
996 clutter_actor_set_size (preview,
997 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
998 priv->video_preview_sink = clutter_gst_video_sink_new (
999 CLUTTER_TEXTURE (preview));
1001 /* Flip the video preview */
1002 clutter_actor_set_rotation (preview,
1005 SELF_VIDEO_SECTION_WIDTH * 0.5,
1009 /* Add a little offset to the video preview */
1010 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1011 CLUTTER_BIN_ALIGNMENT_START);
1012 priv->video_preview = clutter_box_new (layout);
1013 clutter_actor_set_size (priv->video_preview,
1014 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1015 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1016 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1018 /* We have a box with the margins and the video in the middle inside
1019 * a bigger box with an extra bottom margin so we're not on top of
1020 * the floating toolbar. */
1021 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1022 CLUTTER_BIN_ALIGNMENT_CENTER);
1023 box = clutter_box_new (layout_center);
1024 clutter_actor_set_size (box,
1025 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1026 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1028 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1029 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1031 g_object_set (priv->video_preview_sink,
1036 /* Translators: this is an "Info" label. It should be as short
1038 button = gtk_button_new_with_label (_("i"));
1039 b = gtk_clutter_actor_new_with_contents (button);
1041 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1042 CLUTTER_BIN_ALIGNMENT_END);
1043 box = clutter_box_new (layout_end);
1044 clutter_actor_set_size (box,
1045 SELF_VIDEO_SECTION_WIDTH,
1046 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1048 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1049 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1051 g_signal_connect (button, "clicked",
1052 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1055 /* Translators: this is an "Info" label. It should be as short
1057 button = gtk_button_new_with_label (_("i"));
1058 priv->preview_hidden_button =
1059 gtk_clutter_actor_new_with_contents (button);
1061 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1062 priv->preview_hidden_button,
1063 CLUTTER_BIN_ALIGNMENT_START,
1064 CLUTTER_BIN_ALIGNMENT_END);
1066 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1068 clutter_actor_hide (priv->preview_hidden_button);
1070 g_signal_connect (button, "clicked",
1071 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1074 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1075 priv->video_preview,
1076 CLUTTER_BIN_ALIGNMENT_START,
1077 CLUTTER_BIN_ALIGNMENT_END);
1079 action = clutter_drag_action_new ();
1080 g_signal_connect (action, "drag-begin",
1081 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1082 g_signal_connect (action, "drag-end",
1083 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1084 g_signal_connect (action, "drag-motion",
1085 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1087 g_signal_connect (preview, "enter-event",
1088 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1089 g_signal_connect (preview, "leave-event",
1090 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1092 clutter_actor_add_action (preview, action);
1093 clutter_actor_set_reactive (preview, TRUE);
1097 play_camera (EmpathyCallWindow *window,
1100 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1101 GstElement *preview;
1104 if (priv->video_preview == NULL)
1106 create_video_preview (window);
1107 add_video_preview_to_pipeline (window);
1111 state = GST_STATE_PLAYING;
1113 state = GST_STATE_NULL;
1115 preview = priv->video_preview_sink;
1117 gst_element_set_state (preview, state);
1118 gst_element_set_state (priv->video_input, state);
1119 gst_element_set_state (priv->video_tee, state);
1123 display_video_preview (EmpathyCallWindow *self,
1126 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1130 /* Display the video preview */
1131 DEBUG ("Show video preview");
1133 play_camera (self, TRUE);
1134 clutter_actor_show (priv->video_preview);
1135 clutter_actor_raise_top (priv->floating_toolbar);
1139 /* Hide the video preview */
1140 DEBUG ("Hide video preview");
1142 if (priv->video_preview != NULL)
1144 clutter_actor_hide (priv->video_preview);
1145 play_camera (self, FALSE);
1151 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1153 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1155 empathy_call_window_status_message (window, _("Connecting…"));
1156 priv->call_state = CONNECTING;
1159 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1160 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1164 disable_camera (EmpathyCallWindow *self)
1166 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1168 if (priv->camera_state == CAMERA_STATE_OFF)
1171 DEBUG ("Disable camera");
1173 display_video_preview (self, FALSE);
1175 if (priv->camera_state == CAMERA_STATE_ON)
1176 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1178 priv->camera_state = CAMERA_STATE_OFF;
1182 enable_camera (EmpathyCallWindow *self)
1184 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1186 if (priv->camera_state == CAMERA_STATE_ON)
1189 if (priv->video_input == NULL)
1191 DEBUG ("Can't enable camera, no input");
1195 DEBUG ("Enable camera");
1197 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1199 priv->camera_state = CAMERA_STATE_ON;
1203 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1204 EmpathyCallWindow *self)
1206 if (gtk_toggle_tool_button_get_active (toggle))
1207 enable_camera (self);
1209 disable_camera (self);
1213 create_pipeline (EmpathyCallWindow *self)
1215 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1218 g_assert (priv->pipeline == NULL);
1220 priv->pipeline = gst_pipeline_new (NULL);
1221 priv->pipeline_playing = FALSE;
1223 priv->video_tee = gst_element_factory_make ("tee", NULL);
1224 gst_object_ref (priv->video_tee);
1225 gst_object_sink (priv->video_tee);
1227 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1229 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1230 priv->bus_message_source_id = gst_bus_add_watch (bus,
1231 empathy_call_window_bus_message, self);
1233 g_object_unref (bus);
1237 empathy_call_window_settings_cb (GtkAction *action,
1238 EmpathyCallWindow *self)
1240 gchar *args = g_strdup_printf ("-p %s",
1241 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1243 empathy_launch_program (BIN_DIR, "empathy", args);
1249 empathy_call_window_contents_cb (GtkAction *action,
1250 EmpathyCallWindow *self)
1252 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1256 empathy_call_window_debug_cb (GtkAction *action,
1257 EmpathyCallWindow *self)
1259 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1263 empathy_call_window_about_cb (GtkAction *action,
1264 EmpathyCallWindow *self)
1266 empathy_about_dialog_new (GTK_WINDOW (self));
1270 empathy_call_window_toolbar_timeout (gpointer data)
1272 EmpathyCallWindow *self = data;
1274 clutter_state_set_state (self->priv->transitions, "fade-out");
1280 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1282 EmpathyCallWindow *self)
1284 clutter_state_set_state (self->priv->transitions, "fade-in");
1286 if (self->priv->inactivity_src > 0)
1287 g_source_remove (self->priv->inactivity_src);
1289 self->priv->inactivity_src = g_timeout_add_seconds (3,
1290 empathy_call_window_toolbar_timeout, self);
1296 empathy_call_window_configure_event_cb (GtkWidget *widget,
1298 EmpathyCallWindow *self)
1300 GdkWindow *gdk_window;
1301 GdkWindowState window_state;
1303 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1304 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1306 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1307 &self->priv->dialpad_width, NULL);
1309 gdk_window = gtk_widget_get_window (widget);
1310 window_state = gdk_window_get_state (gdk_window);
1311 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1317 empathy_call_window_destroyed_cb (GtkWidget *object,
1318 EmpathyCallWindow *self)
1320 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1322 /* Save the geometry as if the dialpad was hidden. */
1323 empathy_geometry_save_values (GTK_WINDOW (self),
1324 self->priv->x, self->priv->y,
1325 self->priv->w - self->priv->dialpad_width, self->priv->h,
1326 self->priv->maximized);
1331 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1333 ClutterBindConstraint *constraint)
1335 ClutterActorBox allocation;
1337 clutter_actor_get_allocation_box (stage, &allocation);
1339 clutter_bind_constraint_set_offset (constraint,
1340 allocation.y2 - allocation.y1 -
1341 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1345 empathy_call_window_init (EmpathyCallWindow *self)
1347 EmpathyCallWindowPriv *priv;
1349 GtkWidget *top_vbox;
1351 ClutterConstraint *constraint;
1352 ClutterActor *remote_avatar;
1353 GtkStyleContext *context;
1357 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1358 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1360 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1361 gui = empathy_builder_get_file (filename,
1362 "call_window_vbox", &top_vbox,
1363 "errors_vbox", &priv->errors_vbox,
1364 "pane", &priv->pane,
1365 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1366 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1367 "status_label", &priv->status_label,
1368 "audiocall", &priv->audio_call_button,
1369 "videocall", &priv->video_call_button,
1370 "microphone", &priv->mic_button,
1371 "camera", &priv->camera_button,
1372 "hangup", &priv->hangup_button,
1373 "dialpad", &priv->dialpad_button,
1374 "toolbar", &priv->toolbar,
1375 "bottom_toolbar", &priv->bottom_toolbar,
1376 "ui_manager", &priv->ui_manager,
1377 "menufullscreen", &priv->menu_fullscreen,
1378 "menupreviewswap", &priv->menu_swap_camera,
1379 "details_vbox", &priv->details_vbox,
1380 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1381 "acodec_encoding_label", &priv->acodec_encoding_label,
1382 "acodec_decoding_label", &priv->acodec_decoding_label,
1383 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1384 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1385 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1386 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1387 "video_local_candidate_label", &priv->video_local_candidate_label,
1388 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1389 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1390 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1391 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1395 empathy_builder_connect (gui, self,
1396 "hangup", "clicked", empathy_call_window_hangup_cb,
1397 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1398 "videocall", "clicked", empathy_call_window_video_call_cb,
1399 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1400 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1401 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1402 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1403 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1404 "menusettings", "activate", empathy_call_window_settings_cb,
1405 "menucontents", "activate", empathy_call_window_contents_cb,
1406 "menudebug", "activate", empathy_call_window_debug_cb,
1407 "menuabout", "activate", empathy_call_window_about_cb,
1408 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1409 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1410 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1411 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1414 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1416 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1418 g_object_bind_property (priv->camera_monitor, "available",
1419 priv->camera_button, "sensitive",
1420 G_BINDING_SYNC_CREATE);
1422 g_signal_connect (priv->camera_monitor, "added",
1423 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1424 g_signal_connect (priv->camera_monitor, "removed",
1425 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1427 priv->lock = g_mutex_new ();
1429 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1431 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1432 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1433 CONTENT_HBOX_BORDER_WIDTH);
1434 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1437 /* avatar/video box */
1438 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1439 CLUTTER_BIN_ALIGNMENT_CENTER);
1441 priv->video_box = clutter_box_new (priv->video_layout);
1443 priv->video_container = gtk_clutter_embed_new ();
1445 /* Set the background color to that of the rest of the window */
1446 context = gtk_widget_get_style_context (priv->content_hbox);
1447 gtk_style_context_get_background_color (context,
1448 GTK_STATE_FLAG_NORMAL, &rgba);
1449 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1450 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1451 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1452 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1453 clutter_stage_set_color (
1454 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1455 GTK_CLUTTER_EMBED (priv->video_container))),
1458 clutter_container_add (
1459 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1460 GTK_CLUTTER_EMBED (priv->video_container))),
1464 constraint = clutter_bind_constraint_new (
1465 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1466 CLUTTER_BIND_SIZE, 0);
1467 clutter_actor_add_constraint (priv->video_box, constraint);
1469 priv->remote_user_avatar_widget = gtk_image_new ();
1470 remote_avatar = gtk_clutter_actor_new_with_contents (
1471 priv->remote_user_avatar_widget);
1473 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1476 empathy_call_window_create_preview_rectangles (self);
1478 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1479 priv->video_container, TRUE, TRUE,
1480 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1482 create_pipeline (self);
1483 create_video_output_widget (self);
1484 create_audio_input (self);
1485 create_video_input (self);
1487 priv->floating_toolbar = empathy_rounded_actor_new ();
1489 gtk_widget_reparent (priv->bottom_toolbar,
1490 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1492 constraint = clutter_bind_constraint_new (
1493 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1496 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1499 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1500 "notify::allocation",
1501 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1504 clutter_actor_set_size (priv->floating_toolbar,
1505 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1506 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1508 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1509 priv->floating_toolbar,
1510 CLUTTER_BIN_ALIGNMENT_CENTER,
1511 CLUTTER_BIN_ALIGNMENT_END);
1513 clutter_actor_raise_top (priv->floating_toolbar);
1515 /* Transitions for the floating toolbar */
1516 priv->transitions = clutter_state_new ();
1518 /* all transitions last for 2s */
1519 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1521 /* transition from any state to "fade-out" state */
1522 clutter_state_set (priv->transitions, NULL, "fade-out",
1523 priv->floating_toolbar,
1524 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1527 /* transition from any state to "fade-in" state */
1528 clutter_state_set (priv->transitions, NULL, "fade-in",
1529 priv->floating_toolbar,
1530 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1533 /* put the actor into the "fade-in" state with no animation */
1534 clutter_state_warp_to_state (priv->transitions, "fade-in");
1536 /* The call will be started as soon the pipeline is playing */
1537 priv->start_call_when_playing = TRUE;
1539 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1540 G_CALLBACK (dtmf_button_pressed_cb),
1541 G_CALLBACK (dtmf_button_released_cb));
1543 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1546 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1549 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1551 gtk_widget_show_all (top_vbox);
1553 gtk_widget_hide (priv->dtmf_panel);
1554 gtk_widget_hide (priv->details_vbox);
1556 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1558 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1559 priv->video_container);
1561 /* We hide the bottom toolbar after 3s of inactivity and show it
1562 * again on mouse movement */
1563 priv->inactivity_src = g_timeout_add_seconds (3,
1564 empathy_call_window_toolbar_timeout, self);
1566 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1567 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1569 g_signal_connect (G_OBJECT (self), "realize",
1570 G_CALLBACK (empathy_call_window_realized_cb), self);
1572 g_signal_connect (G_OBJECT (self), "delete-event",
1573 G_CALLBACK (empathy_call_window_delete_cb), self);
1575 g_signal_connect (G_OBJECT (self), "window-state-event",
1576 G_CALLBACK (empathy_call_window_state_event_cb), self);
1578 g_signal_connect (G_OBJECT (self), "key-press-event",
1579 G_CALLBACK (empathy_call_window_key_press_cb), self);
1581 g_signal_connect (self, "motion-notify-event",
1582 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1584 priv->timer = g_timer_new ();
1586 g_object_ref (priv->ui_manager);
1587 g_object_unref (gui);
1589 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1590 priv->mic_menu = empathy_mic_menu_new (self);
1591 priv->camera_menu = empathy_camera_menu_new (self);
1593 empathy_call_window_show_hangup_button (self, TRUE);
1595 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1597 /* Retrieve initial volume */
1598 priv->volume = g_settings_get_double (priv->settings,
1599 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1601 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1602 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1604 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1605 /* These signals are used to track the window position and save it
1606 * when the window is destroyed. We need to do this as we don't want
1607 * the window geometry to be saved with the dialpad taken into account. */
1608 g_signal_connect (self, "destroy",
1609 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1610 g_signal_connect (self, "configure-event",
1611 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1612 g_signal_connect (self, "window-state-event",
1613 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1615 /* Don't display labels in both toolbars */
1616 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1619 /* Instead of specifying a width and a height, we specify only one size. That's
1620 because we want a square avatar icon. */
1622 init_contact_avatar_with_size (EmpathyContact *contact,
1623 GtkWidget *image_widget,
1626 GdkPixbuf *pixbuf_avatar = NULL;
1628 if (contact != NULL)
1630 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1634 if (pixbuf_avatar == NULL)
1636 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1637 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1640 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1642 if (pixbuf_avatar != NULL)
1643 g_object_unref (pixbuf_avatar);
1647 set_window_title (EmpathyCallWindow *self)
1649 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1652 if (priv->contact != NULL)
1654 /* translators: Call is a noun and %s is the contact name. This string
1655 * is used in the window title */
1656 tmp = g_strdup_printf (_("Call with %s"),
1657 empathy_contact_get_alias (priv->contact));
1658 gtk_window_set_title (GTK_WINDOW (self), tmp);
1663 g_warning ("Unknown remote contact!");
1668 set_remote_user_name (EmpathyCallWindow *self,
1669 EmpathyContact *contact)
1671 const gchar *alias = empathy_contact_get_alias (contact);
1672 const gchar *status = empathy_contact_get_status (contact);
1675 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1676 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1682 contact_name_changed_cb (EmpathyContact *contact,
1684 EmpathyCallWindow *self)
1686 set_window_title (self);
1687 set_remote_user_name (self, contact);
1691 contact_presence_changed_cb (EmpathyContact *contact,
1693 EmpathyCallWindow *self)
1695 set_remote_user_name (self, contact);
1699 contact_avatar_changed_cb (EmpathyContact *contact,
1701 EmpathyCallWindow *self)
1704 GtkAllocation allocation;
1705 GtkWidget *avatar_widget;
1707 avatar_widget = self->priv->remote_user_avatar_widget;
1709 gtk_widget_get_allocation (avatar_widget, &allocation);
1710 size = allocation.height;
1714 /* the widget is not allocated yet, set a default size */
1715 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1716 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1719 init_contact_avatar_with_size (contact, avatar_widget, size);
1721 avatar_widget = self->priv->remote_user_avatar_toolbar;
1723 gtk_widget_get_allocation (avatar_widget, &allocation);
1724 size = allocation.height;
1728 /* the widget is not allocated yet, set a default size */
1729 size = SMALL_TOOLBAR_SIZE;
1732 init_contact_avatar_with_size (contact, avatar_widget, size);
1736 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1737 EmpathyCallHandler *handler)
1739 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1741 tp_g_signal_connect_object (priv->contact, "notify::name",
1742 G_CALLBACK (contact_name_changed_cb), self, 0);
1743 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1744 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1745 tp_g_signal_connect_object (priv->contact, "notify::presence",
1746 G_CALLBACK (contact_presence_changed_cb), self, 0);
1748 set_window_title (self);
1749 set_remote_user_name (self, priv->contact);
1751 init_contact_avatar_with_size (priv->contact,
1752 priv->remote_user_avatar_widget,
1753 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1754 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1756 init_contact_avatar_with_size (priv->contact,
1757 priv->remote_user_avatar_toolbar,
1758 SMALL_TOOLBAR_SIZE);
1760 /* The remote avatar is shown by default and will be hidden when we receive
1761 video from the remote side. */
1762 clutter_actor_hide (priv->video_output);
1763 gtk_widget_show (priv->remote_user_avatar_widget);
1767 update_send_codec (EmpathyCallWindow *self,
1770 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1777 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1778 widget = priv->acodec_encoding_label;
1782 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1783 widget = priv->vcodec_encoding_label;
1789 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1790 gtk_label_set_text (GTK_LABEL (widget), tmp);
1795 send_audio_codec_notify_cb (GObject *object,
1799 EmpathyCallWindow *self = user_data;
1801 update_send_codec (self, TRUE);
1805 send_video_codec_notify_cb (GObject *object,
1809 EmpathyCallWindow *self = user_data;
1811 update_send_codec (self, FALSE);
1815 update_recv_codec (EmpathyCallWindow *self,
1818 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1821 GString *str = NULL;
1825 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1826 widget = priv->acodec_decoding_label;
1830 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1831 widget = priv->vcodec_decoding_label;
1837 for (l = codecs; l != NULL; l = g_list_next (l))
1839 FsCodec *codec = l->data;
1842 str = g_string_new (NULL);
1844 g_string_append (str, ", ");
1846 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1850 gtk_label_set_text (GTK_LABEL (widget), str->str);
1851 g_string_free (str, TRUE);
1855 recv_audio_codecs_notify_cb (GObject *object,
1859 EmpathyCallWindow *self = user_data;
1861 update_recv_codec (self, TRUE);
1865 recv_video_codecs_notify_cb (GObject *object,
1869 EmpathyCallWindow *self = user_data;
1871 update_recv_codec (self, FALSE);
1874 static const gchar *
1875 candidate_type_to_str (FsCandidate *candidate)
1877 switch (candidate->type)
1879 case FS_CANDIDATE_TYPE_HOST:
1881 case FS_CANDIDATE_TYPE_SRFLX:
1882 return "server reflexive";
1883 case FS_CANDIDATE_TYPE_PRFLX:
1884 return "peer reflexive";
1885 case FS_CANDIDATE_TYPE_RELAY:
1887 case FS_CANDIDATE_TYPE_MULTICAST:
1894 static const gchar *
1895 candidate_type_to_desc (FsCandidate *candidate)
1897 switch (candidate->type)
1899 case FS_CANDIDATE_TYPE_HOST:
1900 return _("The IP address as seen by the machine");
1901 case FS_CANDIDATE_TYPE_SRFLX:
1902 return _("The IP address as seen by a server on the Internet");
1903 case FS_CANDIDATE_TYPE_PRFLX:
1904 return _("The IP address of the peer as seen by the other side");
1905 case FS_CANDIDATE_TYPE_RELAY:
1906 return _("The IP address of a relay server");
1907 case FS_CANDIDATE_TYPE_MULTICAST:
1908 return _("The IP address of the multicast group");
1915 update_candidat_widget (EmpathyCallWindow *self,
1918 FsCandidate *candidate)
1922 g_assert (candidate != NULL);
1923 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1924 candidate->port, candidate_type_to_str (candidate));
1926 gtk_label_set_text (GTK_LABEL (label), str);
1927 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1933 candidates_changed_cb (GObject *object,
1935 EmpathyCallWindow *self)
1937 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1938 FsCandidate *candidate = NULL;
1940 if (type == FS_MEDIA_TYPE_VIDEO)
1942 /* Update remote candidate */
1943 candidate = empathy_call_handler_get_video_remote_candidate (
1946 update_candidat_widget (self, priv->video_remote_candidate_label,
1947 priv->video_remote_candidate_info_img, candidate);
1949 /* Update local candidate */
1950 candidate = empathy_call_handler_get_video_local_candidate (
1953 update_candidat_widget (self, priv->video_local_candidate_label,
1954 priv->video_local_candidate_info_img, candidate);
1958 /* Update remote candidate */
1959 candidate = empathy_call_handler_get_audio_remote_candidate (
1962 update_candidat_widget (self, priv->audio_remote_candidate_label,
1963 priv->audio_remote_candidate_info_img, candidate);
1965 /* Update local candidate */
1966 candidate = empathy_call_handler_get_audio_local_candidate (
1969 update_candidat_widget (self, priv->audio_local_candidate_label,
1970 priv->audio_local_candidate_info_img, candidate);
1975 empathy_call_window_constructed (GObject *object)
1977 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1978 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1979 TpyCallChannel *call;
1981 g_assert (priv->handler != NULL);
1983 g_object_get (priv->handler, "call-channel", &call, NULL);
1984 priv->outgoing = (call == NULL);
1986 g_object_unref (call);
1988 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1989 g_assert (priv->contact != NULL);
1991 empathy_call_window_setup_avatars (self, priv->handler);
1992 empathy_call_window_set_state_connecting (self);
1994 if (!empathy_call_handler_has_initial_video (priv->handler))
1996 gtk_toggle_tool_button_set_active (
1997 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1999 /* If call has InitialVideo, the preview will be started once the call has
2000 * been started (start_call()). */
2002 update_send_codec (self, TRUE);
2003 update_send_codec (self, FALSE);
2004 update_recv_codec (self, TRUE);
2005 update_recv_codec (self, FALSE);
2007 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2008 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2009 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2010 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2011 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2012 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2013 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2014 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2016 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2017 G_CALLBACK (candidates_changed_cb), self, 0);
2020 static void empathy_call_window_dispose (GObject *object);
2021 static void empathy_call_window_finalize (GObject *object);
2024 empathy_call_window_set_property (GObject *object,
2025 guint property_id, const GValue *value, GParamSpec *pspec)
2027 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2029 switch (property_id)
2031 case PROP_CALL_HANDLER:
2032 priv->handler = g_value_dup_object (value);
2035 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2040 empathy_call_window_get_property (GObject *object,
2041 guint property_id, GValue *value, GParamSpec *pspec)
2043 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2045 switch (property_id)
2047 case PROP_CALL_HANDLER:
2048 g_value_set_object (value, priv->handler);
2051 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2056 empathy_call_window_class_init (
2057 EmpathyCallWindowClass *empathy_call_window_class)
2059 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2060 GParamSpec *param_spec;
2062 g_type_class_add_private (empathy_call_window_class,
2063 sizeof (EmpathyCallWindowPriv));
2065 object_class->constructed = empathy_call_window_constructed;
2066 object_class->set_property = empathy_call_window_set_property;
2067 object_class->get_property = empathy_call_window_get_property;
2069 object_class->dispose = empathy_call_window_dispose;
2070 object_class->finalize = empathy_call_window_finalize;
2072 param_spec = g_param_spec_object ("handler",
2073 "handler", "The call handler",
2074 EMPATHY_TYPE_CALL_HANDLER,
2075 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2076 g_object_class_install_property (object_class,
2077 PROP_CALL_HANDLER, param_spec);
2081 empathy_call_window_dispose (GObject *object)
2083 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2084 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2086 if (priv->dispose_has_run)
2089 priv->dispose_has_run = TRUE;
2091 if (priv->handler != NULL)
2093 empathy_call_handler_stop_call (priv->handler);
2094 tp_clear_object (&priv->handler);
2097 if (priv->bus_message_source_id != 0)
2099 g_source_remove (priv->bus_message_source_id);
2100 priv->bus_message_source_id = 0;
2103 if (priv->got_video_src > 0)
2105 g_source_remove (priv->got_video_src);
2106 priv->got_video_src = 0;
2109 if (priv->inactivity_src > 0)
2111 g_source_remove (priv->inactivity_src);
2112 priv->inactivity_src = 0;
2115 tp_clear_object (&priv->pipeline);
2116 tp_clear_object (&priv->video_input);
2117 tp_clear_object (&priv->audio_input);
2118 tp_clear_object (&priv->video_tee);
2119 tp_clear_object (&priv->ui_manager);
2120 tp_clear_object (&priv->fullscreen);
2121 tp_clear_object (&priv->camera_monitor);
2122 tp_clear_object (&priv->settings);
2123 tp_clear_object (&priv->sound_mgr);
2124 tp_clear_object (&priv->mic_menu);
2125 tp_clear_object (&priv->camera_menu);
2127 g_list_free_full (priv->notifiers, g_object_unref);
2129 if (priv->timer_id != 0)
2130 g_source_remove (priv->timer_id);
2133 if (priv->contact != NULL)
2135 g_signal_handlers_disconnect_by_func (priv->contact,
2136 contact_name_changed_cb, self);
2137 priv->contact = NULL;
2140 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2144 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2146 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2148 if (priv->video_output_motion_handler_id != 0)
2150 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2151 priv->video_output_motion_handler_id);
2152 priv->video_output_motion_handler_id = 0;
2157 empathy_call_window_finalize (GObject *object)
2159 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2160 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2162 disconnect_video_output_motion_handler (self);
2164 /* free any data held directly by the object here */
2165 g_mutex_free (priv->lock);
2167 g_timer_destroy (priv->timer);
2169 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2174 empathy_call_window_new (EmpathyCallHandler *handler)
2176 return EMPATHY_CALL_WINDOW (
2177 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2181 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2182 GstElement *conference, gpointer user_data)
2184 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2185 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2186 FsElementAddedNotifier *notifier;
2189 DEBUG ("Conference added");
2191 /* Add notifier to set the various element properties as needed */
2192 notifier = fs_element_added_notifier_new ();
2193 keyfile = fs_utils_get_default_element_properties (conference);
2195 if (keyfile != NULL)
2196 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2198 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2200 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2202 gst_bin_add (GST_BIN (priv->pipeline), conference);
2203 gst_element_set_state (conference, GST_STATE_PLAYING);
2207 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2208 GstElement *conference, gpointer user_data)
2210 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2211 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2213 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2214 gst_element_set_state (conference, GST_STATE_NULL);
2218 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2220 GstStateChangeReturn state_change_return;
2221 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2223 if (priv->pipeline == NULL)
2226 if (priv->bus_message_source_id != 0)
2228 g_source_remove (priv->bus_message_source_id);
2229 priv->bus_message_source_id = 0;
2232 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2234 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2235 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2237 if (priv->pipeline != NULL)
2238 g_object_unref (priv->pipeline);
2239 priv->pipeline = NULL;
2241 if (priv->audio_output != NULL)
2242 g_object_unref (priv->audio_output);
2243 priv->audio_output = NULL;
2245 if (priv->video_tee != NULL)
2246 g_object_unref (priv->video_tee);
2247 priv->video_tee = NULL;
2249 if (priv->video_preview != NULL)
2250 clutter_actor_destroy (priv->video_preview);
2251 priv->video_preview = NULL;
2253 priv->funnel = NULL;
2255 create_pipeline (self);
2256 /* Call will be started when user will hit the 'redial' button */
2257 priv->start_call_when_playing = FALSE;
2258 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2264 g_message ("Error: could not destroy pipeline. Closing call window");
2265 gtk_widget_destroy (GTK_WIDGET (self));
2272 reset_details_pane (EmpathyCallWindow *self)
2274 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2276 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2277 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2278 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2279 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2283 empathy_call_window_disconnected (EmpathyCallWindow *self,
2286 gboolean could_disconnect = FALSE;
2287 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2288 gboolean could_reset_pipeline;
2290 /* Leave full screen mode if needed */
2291 gtk_window_unfullscreen (GTK_WINDOW (self));
2293 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2294 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2296 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2298 if (priv->call_state == CONNECTING)
2299 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2301 if (priv->call_state != REDIALING)
2302 priv->call_state = DISCONNECTED;
2304 if (could_reset_pipeline)
2306 g_mutex_lock (priv->lock);
2308 g_timer_stop (priv->timer);
2310 if (priv->timer_id != 0)
2311 g_source_remove (priv->timer_id);
2314 g_mutex_unlock (priv->lock);
2317 /* We are about to destroy the window, no need to update it or create
2318 * a video preview */
2321 empathy_call_window_status_message (self, _("Disconnected"));
2323 empathy_call_window_show_hangup_button (self, FALSE);
2325 /* Unsensitive the camera and mic button */
2326 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2327 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2329 /* Be sure that the mic button is enabled */
2330 gtk_toggle_tool_button_set_active (
2331 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2333 if (priv->camera_state == CAMERA_STATE_ON)
2335 /* Restart the preview with the new pipeline. */
2336 display_video_preview (self, TRUE);
2339 /* destroy the video output; it will be recreated when we'll redial */
2340 disconnect_video_output_motion_handler (self);
2341 if (priv->video_output != NULL)
2342 clutter_actor_destroy (priv->video_output);
2343 priv->video_output = NULL;
2344 if (priv->got_video_src > 0)
2346 g_source_remove (priv->got_video_src);
2347 priv->got_video_src = 0;
2350 gtk_widget_show (priv->remote_user_avatar_widget);
2352 reset_details_pane (self);
2354 priv->sending_video = FALSE;
2355 priv->call_started = FALSE;
2357 could_disconnect = TRUE;
2359 /* TODO: display the self avatar of the preview (depends if the "Always
2360 * Show Video Preview" is enabled or not) */
2363 return could_disconnect;
2368 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2371 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2372 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2374 if (empathy_call_window_disconnected (self, TRUE) &&
2375 priv->call_state == REDIALING)
2376 empathy_call_window_restart_call (self);
2380 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2382 FsMediaType media_type,
2383 EmpathyCallWindow *self)
2385 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2387 DEBUG ("removing content");
2390 * This assumes that there is only one video stream per channel...
2393 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2395 if (priv->funnel != NULL)
2399 output = priv->video_output_sink;
2401 gst_element_set_state (output, GST_STATE_NULL);
2402 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2404 gst_bin_remove (GST_BIN (priv->pipeline), output);
2405 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2406 priv->funnel = NULL;
2410 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2412 if (priv->audio_output != NULL)
2414 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2416 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2417 priv->audio_output = NULL;
2425 /* Called with global lock held */
2427 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2429 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2433 if (priv->funnel == NULL)
2435 output = priv->video_output_sink;
2437 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2441 g_warning ("Could not create fsfunnel");
2445 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2447 gst_object_unref (priv->funnel);
2448 priv->funnel = NULL;
2449 g_warning ("Could not add funnel to pipeline");
2453 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2455 g_warning ("Could not add the video output widget to the pipeline");
2459 if (!gst_element_link (priv->funnel, output))
2461 g_warning ("Could not link output sink to funnel");
2462 goto error_output_added;
2465 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2467 g_warning ("Could not start video sink");
2468 goto error_output_added;
2471 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2473 g_warning ("Could not start funnel");
2474 goto error_output_added;
2478 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2481 g_warning ("Could not get request pad from funnel");
2488 gst_element_set_locked_state (priv->funnel, TRUE);
2489 gst_element_set_locked_state (output, TRUE);
2491 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2492 gst_element_set_state (output, GST_STATE_NULL);
2494 gst_bin_remove (GST_BIN (priv->pipeline), output);
2495 gst_element_set_locked_state (output, FALSE);
2499 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2500 priv->funnel = NULL;
2505 /* Called with global lock held */
2507 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2509 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2511 GstPadTemplate *template;
2513 if (priv->audio_output == NULL)
2515 priv->audio_output = empathy_audio_sink_new ();
2516 g_object_ref_sink (priv->audio_output);
2518 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2520 g_warning ("Could not add audio sink to pipeline");
2521 g_object_unref (priv->audio_output);
2522 goto error_add_output;
2525 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2527 g_warning ("Could not start audio sink");
2532 template = gst_element_class_get_pad_template (
2533 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2535 pad = gst_element_request_pad (priv->audio_output,
2536 template, NULL, NULL);
2540 g_warning ("Could not get sink pad from sink");
2547 gst_element_set_locked_state (priv->audio_output, TRUE);
2548 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2549 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2550 priv->audio_output = NULL;
2558 empathy_call_window_update_timer (gpointer user_data)
2560 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2561 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2562 const gchar *status;
2566 time_ = g_timer_elapsed (priv->timer, NULL);
2568 if (priv->call_state == HELD)
2569 status = _("On hold");
2570 else if (!gtk_toggle_tool_button_get_active (
2571 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2574 status = _("Duration");
2576 /* Translators: 'status - minutes:seconds' the caller has been connected */
2577 str = g_strdup_printf (_("%s — %d:%02dm"),
2579 (int) time_ / 60, (int) time_ % 60);
2580 empathy_call_window_status_message (self, str);
2588 display_error (EmpathyCallWindow *self,
2589 TpyCallChannel *call,
2593 const gchar *details)
2595 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2596 GtkWidget *info_bar;
2597 GtkWidget *content_area;
2604 /* Create info bar */
2605 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2608 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2610 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2612 /* hbox containing the image and the messages vbox */
2613 hbox = gtk_hbox_new (FALSE, 3);
2614 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2617 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2618 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2620 /* vbox containing the main message and the details expander */
2621 vbox = gtk_vbox_new (FALSE, 3);
2622 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2625 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2627 label = gtk_label_new (NULL);
2628 gtk_label_set_markup (GTK_LABEL (label), txt);
2629 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2630 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2633 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2636 if (details != NULL)
2638 GtkWidget *expander;
2640 expander = gtk_expander_new (_("Technical Details"));
2642 txt = g_strdup_printf ("<i>%s</i>", details);
2644 label = gtk_label_new (NULL);
2645 gtk_label_set_markup (GTK_LABEL (label), txt);
2646 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2647 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2650 gtk_container_add (GTK_CONTAINER (expander), label);
2651 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2654 g_signal_connect (info_bar, "response",
2655 G_CALLBACK (gtk_widget_destroy), NULL);
2657 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2658 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2659 gtk_widget_show_all (info_bar);
2663 media_stream_error_to_txt (EmpathyCallWindow *self,
2664 TpyCallChannel *call,
2666 TpMediaStreamError error)
2668 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2669 const gchar *cm = NULL;
2675 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2677 return g_strdup_printf (
2678 _("%s's software does not understand any of the audio formats "
2679 "supported by your computer"),
2680 empathy_contact_get_alias (priv->contact));
2682 return g_strdup_printf (
2683 _("%s's software does not understand any of the video formats "
2684 "supported by your computer"),
2685 empathy_contact_get_alias (priv->contact));
2687 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2688 return g_strdup_printf (
2689 _("Can't establish a connection to %s. "
2690 "One of you might be on a network that does not allow "
2691 "direct connections."),
2692 empathy_contact_get_alias (priv->contact));
2694 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2695 return g_strdup (_("There was a failure on the network"));
2697 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2699 return g_strdup (_("The audio formats necessary for this call "
2700 "are not installed on your computer"));
2702 return g_strdup (_("The video formats necessary for this call "
2703 "are not installed on your computer"));
2705 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2706 tp_connection_parse_object_path (
2707 tp_channel_borrow_connection (TP_CHANNEL (call)),
2710 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2711 "product=Telepathy&component=%s", cm);
2713 result = g_strdup_printf (
2714 _("Something unexpected happened in a Telepathy component. "
2715 "Please <a href=\"%s\">report this bug</a> and attach "
2716 "logs gathered from the 'Debug' window in the Help menu."), url);
2722 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2723 return g_strdup (_("There was a failure in the call engine"));
2725 case TP_MEDIA_STREAM_ERROR_EOS:
2726 return g_strdup (_("The end of the stream was reached"));
2728 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2735 empathy_call_window_stream_error (EmpathyCallWindow *self,
2736 TpyCallChannel *call,
2745 desc = media_stream_error_to_txt (self, call, audio, code);
2748 /* No description, use the error message. That's not great as it's not
2749 * localized but it's better than nothing. */
2750 display_error (self, call, icon, title, msg, NULL);
2754 display_error (self, call, icon, title, desc, msg);
2760 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2763 EmpathyCallWindow *self)
2765 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2766 "gnome-stock-mic", _("Can't establish audio stream"));
2770 empathy_call_window_video_stream_error (TpyCallChannel *call,
2773 EmpathyCallWindow *self)
2775 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2776 "camera-web", _("Can't establish video stream"));
2781 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2783 EmpathyCallWindow *self)
2785 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2786 TpyCallChannel *call;
2787 gboolean can_send_video;
2789 if (state != TPY_CALL_STATE_ACCEPTED)
2792 if (priv->call_state == CONNECTED)
2795 g_timer_start (priv->timer);
2796 priv->call_state = CONNECTED;
2798 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2800 can_send_video = priv->video_input != NULL &&
2801 empathy_contact_can_voip_video (priv->contact) &&
2802 empathy_camera_monitor_get_available (priv->camera_monitor);
2804 g_object_get (priv->handler, "call-channel", &call, NULL);
2806 if (tpy_call_channel_has_dtmf (call))
2807 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2809 if (priv->video_input == NULL)
2810 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2812 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2814 empathy_call_window_show_hangup_button (self, TRUE);
2816 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2818 clutter_actor_hide (priv->video_output);
2819 gtk_widget_show (priv->remote_user_avatar_widget);
2821 g_object_unref (call);
2823 g_mutex_lock (priv->lock);
2825 priv->timer_id = g_timeout_add_seconds (1,
2826 empathy_call_window_update_timer, self);
2828 g_mutex_unlock (priv->lock);
2830 empathy_call_window_update_timer (self);
2832 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2836 empathy_call_window_show_video_output_cb (gpointer user_data)
2838 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2840 if (self->priv->video_output != NULL)
2842 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2843 clutter_actor_show (self->priv->video_output);
2844 empathy_call_window_raise_actors (self);
2851 empathy_call_window_check_video_cb (gpointer data)
2853 EmpathyCallWindow *self = data;
2855 if (self->priv->got_video)
2857 self->priv->got_video = FALSE;
2861 /* No video in the last N seconds, display the remote avatar */
2862 empathy_call_window_show_video_output (self, FALSE);
2867 /* Called from the streaming thread */
2869 empathy_call_window_video_probe_cb (GstPad *pad,
2870 GstMiniObject *mini_obj,
2871 EmpathyCallWindow *self)
2874 if (GST_IS_EVENT (mini_obj))
2877 if (G_UNLIKELY (!self->priv->got_video))
2879 /* show the remote video */
2880 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2881 empathy_call_window_show_video_output_cb,
2882 g_object_ref (self), g_object_unref);
2884 self->priv->got_video = TRUE;
2890 /* Called from the streaming thread */
2892 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2893 GstPad *src, guint media_type, gpointer user_data)
2895 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2896 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2897 gboolean retval = FALSE;
2901 g_mutex_lock (priv->lock);
2905 case TP_MEDIA_STREAM_TYPE_AUDIO:
2906 pad = empathy_call_window_get_audio_sink_pad (self);
2908 case TP_MEDIA_STREAM_TYPE_VIDEO:
2909 g_idle_add (empathy_call_window_show_video_output_cb, self);
2910 pad = empathy_call_window_get_video_sink_pad (self);
2912 gst_pad_add_data_probe (src,
2913 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2914 if (priv->got_video_src > 0)
2915 g_source_remove (priv->got_video_src);
2916 priv->got_video_src = g_timeout_add_seconds (5,
2917 empathy_call_window_check_video_cb, self);
2920 g_assert_not_reached ();
2926 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2927 g_warning ("Could not link %s sink pad",
2928 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2932 gst_object_unref (pad);
2936 /* If no sink could be linked, try to add fakesink to prevent the whole call
2941 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2943 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2945 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2946 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2947 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2949 gst_element_set_locked_state (fakesink, TRUE);
2950 gst_element_set_state (fakesink, GST_STATE_NULL);
2951 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2955 DEBUG ("Could not link real sink, linked fakesink instead");
2957 gst_object_unref (sinkpad);
2961 gst_object_unref (fakesink);
2966 g_mutex_unlock (priv->lock);
2972 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2973 GstPad *sink, FsMediaType media_type, gpointer user_data)
2975 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2976 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2978 gboolean retval = FALSE;
2982 case FS_MEDIA_TYPE_AUDIO:
2983 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2985 g_warning ("Could not add audio source to pipeline");
2989 pad = gst_element_get_static_pad (priv->audio_input, "src");
2992 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2993 g_warning ("Could not get source pad from audio source");
2997 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2999 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3000 g_warning ("Could not link audio source to farsight");
3004 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3006 g_warning ("Could not start audio source");
3007 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3008 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3014 case FS_MEDIA_TYPE_VIDEO:
3015 if (priv->video_tee != NULL)
3017 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3018 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3020 g_warning ("Could not link video source input pipeline");
3023 gst_object_unref (pad);
3029 g_assert_not_reached ();
3036 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3038 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3039 GstElement *preview;
3041 disable_camera (self);
3043 DEBUG ("remove video input");
3044 preview = priv->video_preview_sink;
3046 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3047 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3048 gst_element_set_state (preview, GST_STATE_NULL);
3050 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3053 g_object_unref (priv->video_input);
3054 priv->video_input = NULL;
3055 g_object_unref (priv->video_tee);
3056 priv->video_tee = NULL;
3057 clutter_actor_destroy (priv->video_preview);
3058 priv->video_preview = NULL;
3060 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3064 start_call (EmpathyCallWindow *self)
3066 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3068 priv->call_started = TRUE;
3069 empathy_call_handler_start_call (priv->handler,
3070 gtk_get_current_event_time ());
3072 if (empathy_call_handler_has_initial_video (priv->handler))
3074 TpyCallChannel *call;
3077 g_object_get (priv->handler, "call-channel", &call, NULL);
3078 s = tpy_call_channel_get_video_state (call);
3080 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3081 s == TPY_SENDING_STATE_SENDING)
3083 /* Enable 'send video' buttons and display the preview */
3084 gtk_toggle_tool_button_set_active (
3085 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3089 gtk_toggle_tool_button_set_active (
3090 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3092 if (priv->video_preview == NULL)
3094 create_video_preview (self);
3095 add_video_preview_to_pipeline (self);
3099 g_object_unref (call);
3104 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3107 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3108 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3111 empathy_call_handler_bus_message (priv->handler, bus, message);
3113 switch (GST_MESSAGE_TYPE (message))
3115 case GST_MESSAGE_STATE_CHANGED:
3116 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3118 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3120 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3121 !priv->call_started)
3123 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3124 if (newstate == GST_STATE_PAUSED)
3126 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3127 priv->pipeline_playing = TRUE;
3129 if (priv->start_call_when_playing)
3134 case GST_MESSAGE_ERROR:
3136 GError *error = NULL;
3137 GstElement *gst_error;
3140 gst_message_parse_error (message, &error, &debug);
3141 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3143 g_message ("Element error: %s -- %s\n", error->message, debug);
3145 if (g_str_has_prefix (gst_element_get_name (gst_error),
3146 VIDEO_INPUT_ERROR_PREFIX))
3148 /* Remove the video input and continue */
3149 if (priv->video_input != NULL)
3150 empathy_call_window_remove_video_input (self);
3151 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3155 empathy_call_window_disconnected (self, TRUE);
3157 g_error_free (error);
3160 case GST_MESSAGE_UNKNOWN:
3161 case GST_MESSAGE_EOS:
3162 case GST_MESSAGE_WARNING:
3163 case GST_MESSAGE_INFO:
3164 case GST_MESSAGE_TAG:
3165 case GST_MESSAGE_BUFFERING:
3166 case GST_MESSAGE_STATE_DIRTY:
3167 case GST_MESSAGE_STEP_DONE:
3168 case GST_MESSAGE_CLOCK_PROVIDE:
3169 case GST_MESSAGE_CLOCK_LOST:
3170 case GST_MESSAGE_NEW_CLOCK:
3171 case GST_MESSAGE_STRUCTURE_CHANGE:
3172 case GST_MESSAGE_STREAM_STATUS:
3173 case GST_MESSAGE_APPLICATION:
3174 case GST_MESSAGE_ELEMENT:
3175 case GST_MESSAGE_SEGMENT_START:
3176 case GST_MESSAGE_SEGMENT_DONE:
3177 case GST_MESSAGE_DURATION:
3178 case GST_MESSAGE_ANY:
3187 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3188 GHashTable *members,
3189 EmpathyCallWindow *self)
3191 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3192 GHashTableIter iter;
3193 gpointer key, value;
3194 gboolean held = FALSE;
3196 g_hash_table_iter_init (&iter, members);
3197 while (g_hash_table_iter_next (&iter, &key, &value))
3199 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3201 /* This assumes this is a 1-1 call, otherwise one participant
3202 * putting the call on hold wouldn't mean the call is on hold
3210 priv->call_state = HELD;
3211 else if (priv->call_state == HELD)
3212 priv->call_state = CONNECTED;
3216 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3218 EmpathyCallWindow *self)
3220 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3221 TpyCallChannel *call;
3223 g_object_get (priv->handler, "call-channel", &call, NULL);
3228 tp_g_signal_connect_object (call, "audio-stream-error",
3229 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3230 tp_g_signal_connect_object (call, "video-stream-error",
3231 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3234 tp_g_signal_connect_object (call, "members-changed",
3235 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3237 g_object_unref (call);
3241 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3243 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3244 TpyCallChannel *call;
3247 /* Make the hangup button twice as wide */
3248 width = gtk_widget_get_allocated_width (priv->hangup_button);
3249 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3251 g_signal_connect (priv->handler, "state-changed",
3252 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3253 g_signal_connect (priv->handler, "conference-added",
3254 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3255 g_signal_connect (priv->handler, "conference-removed",
3256 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3257 g_signal_connect (priv->handler, "closed",
3258 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3259 g_signal_connect (priv->handler, "src-pad-added",
3260 G_CALLBACK (empathy_call_window_src_added_cb), window);
3261 g_signal_connect (priv->handler, "sink-pad-added",
3262 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3263 g_signal_connect (priv->handler, "sink-pad-removed",
3264 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3266 g_object_get (priv->handler, "call-channel", &call, NULL);
3269 call_handler_notify_call_cb (priv->handler, NULL, window);
3270 g_object_unref (call);
3274 /* call-channel doesn't exist yet, we'll connect signals once it has been
3276 g_signal_connect (priv->handler, "notify::call-channel",
3277 G_CALLBACK (call_handler_notify_call_cb), window);
3280 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3284 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3285 EmpathyCallWindow *window)
3287 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3289 if (priv->pipeline != NULL)
3291 if (priv->bus_message_source_id != 0)
3293 g_source_remove (priv->bus_message_source_id);
3294 priv->bus_message_source_id = 0;
3297 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3300 if (priv->call_state == CONNECTING)
3301 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3307 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3310 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3312 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3317 gtk_widget_hide (priv->dtmf_panel);
3318 gtk_widget_hide (menu);
3319 gtk_widget_hide (priv->toolbar);
3323 if (priv->dialpad_was_visible_before_fs)
3324 gtk_widget_show (priv->dtmf_panel);
3326 gtk_widget_show (menu);
3327 gtk_widget_show (priv->toolbar);
3329 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3330 priv->original_height_before_fs);
3335 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3337 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3339 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3340 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3341 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3342 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3344 if (priv->video_output != NULL)
3347 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3348 priv->video_output, TRUE, TRUE,
3349 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3356 empathy_call_window_state_event_cb (GtkWidget *widget,
3357 GdkEventWindowState *event, EmpathyCallWindow *window)
3359 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3361 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3362 gboolean set_fullscreen = event->new_window_state &
3363 GDK_WINDOW_STATE_FULLSCREEN;
3367 gboolean dialpad_was_visible;
3368 GtkAllocation allocation;
3369 gint original_width, original_height;
3371 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3372 original_width = allocation.width;
3373 original_height = allocation.height;
3375 g_object_get (priv->dtmf_panel,
3376 "visible", &dialpad_was_visible,
3379 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3380 priv->original_width_before_fs = original_width;
3381 priv->original_height_before_fs = original_height;
3383 if (priv->video_output_motion_handler_id == 0 &&
3384 priv->video_output != NULL)
3386 priv->video_output_motion_handler_id = g_signal_connect (
3387 G_OBJECT (priv->video_container), "motion-notify-event",
3388 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3394 disconnect_video_output_motion_handler (window);
3397 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3399 show_controls (window, set_fullscreen);
3400 show_borders (window, set_fullscreen);
3401 gtk_action_set_stock_id (priv->menu_fullscreen,
3402 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3403 priv->is_fullscreen = set_fullscreen;
3410 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3413 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3414 int w, h, dialpad_width;
3415 GtkAllocation allocation;
3417 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3418 w = allocation.width;
3419 h = allocation.height;
3421 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3425 gtk_widget_show (priv->dtmf_panel);
3431 gtk_widget_hide (priv->dtmf_panel);
3435 gtk_window_resize (GTK_WINDOW (window), w, h);
3439 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3442 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3443 TpyCallChannel *call;
3445 priv->sending_video = (state == CAMERA_STATE_ON);
3447 if (state == CAMERA_STATE_ON)
3449 /* When we start sending video, we want to show the video preview by
3451 display_video_preview (window, TRUE);
3455 display_video_preview (window, FALSE);
3458 if (priv->call_state != CONNECTED)
3461 g_object_get (priv->handler, "call-channel", &call, NULL);
3462 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3463 tpy_call_channel_send_video (call, priv->sending_video);
3464 g_object_unref (call);
3468 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3469 EmpathyCallWindow *self)
3471 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3474 active = (gtk_toggle_tool_button_get_active (toggle));
3476 /* We don't want the settings callback to react to this change to avoid
3478 g_signal_handlers_block_by_func (priv->settings,
3479 empathy_call_window_prefs_volume_changed_cb, self);
3483 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3484 priv->volume * 100);
3488 /* TODO, Instead of setting the input volume to 0 we should probably
3489 * stop sending but this would cause the audio call to drop if both
3490 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3491 * in the future. GNOME #574574
3493 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3497 g_signal_handlers_unblock_by_func (priv->settings,
3498 empathy_call_window_prefs_volume_changed_cb, self);
3502 empathy_call_window_hangup_cb (gpointer object,
3503 EmpathyCallWindow *self)
3505 empathy_call_handler_stop_call (self->priv->handler);
3507 empathy_call_window_disconnected (self, TRUE);
3511 empathy_call_window_restart_call (EmpathyCallWindow *window)
3513 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3515 /* Remove error info bars */
3516 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3517 (GtkCallback) gtk_widget_destroy, NULL);
3519 create_video_output_widget (window);
3521 /* While the call was disconnected, the input volume might have changed.
3522 * However, since the audio_input source was destroyed, its volume has not
3523 * been updated during that time. That's why we manually update it here */
3524 empathy_call_window_mic_volume_changed (window);
3526 priv->outgoing = TRUE;
3527 empathy_call_window_set_state_connecting (window);
3529 if (priv->pipeline_playing)
3530 start_call (window);
3532 /* call will be started when the pipeline is ready */
3533 priv->start_call_when_playing = TRUE;
3535 empathy_call_window_setup_avatars (window, priv->handler);
3537 empathy_call_window_show_hangup_button (window, TRUE);
3541 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3542 EmpathyCallWindow *window)
3546 active = gtk_toggle_tool_button_get_active (button);
3548 empathy_call_window_show_dialpad (window, active);
3552 empathy_call_window_fullscreen_cb (gpointer object,
3553 EmpathyCallWindow *window)
3555 empathy_call_window_fullscreen_toggle (window);
3559 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3561 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3563 if (priv->is_fullscreen)
3564 gtk_window_unfullscreen (GTK_WINDOW (window));
3566 gtk_window_fullscreen (GTK_WINDOW (window));
3570 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3571 GdkEventButton *event, EmpathyCallWindow *window)
3573 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3575 empathy_call_window_video_menu_popup (window, event->button);
3583 empathy_call_window_key_press_cb (GtkWidget *video_output,
3584 GdkEventKey *event, EmpathyCallWindow *window)
3586 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3588 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3590 /* Since we are in fullscreen mode, toggling will bring us back to
3592 empathy_call_window_fullscreen_toggle (window);
3600 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3601 GdkEventMotion *event, EmpathyCallWindow *window)
3603 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3605 if (priv->is_fullscreen)
3607 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3609 /* Show the bottom toolbar */
3610 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3617 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3621 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3623 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3625 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3626 button, gtk_get_current_event_time ());
3627 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3631 empathy_call_window_status_message (EmpathyCallWindow *self,
3634 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3638 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3639 gdouble value, EmpathyCallWindow *window)
3641 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3643 if (priv->audio_output == NULL)
3646 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3651 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3653 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3655 return priv->ui_manager;
3658 EmpathyGstAudioSrc *
3659 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3661 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3663 return (EmpathyGstAudioSrc *) priv->audio_input;
3666 EmpathyGstVideoSrc *
3667 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3669 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);