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 GtkWidget *video_container;
148 GtkWidget *remote_user_avatar_widget;
149 GtkWidget *remote_user_avatar_toolbar;
150 GtkWidget *remote_user_name_toolbar;
151 GtkWidget *status_label;
152 GtkWidget *hangup_button;
153 GtkWidget *audio_call_button;
154 GtkWidget *video_call_button;
155 GtkWidget *mic_button;
156 GtkWidget *camera_button;
157 GtkWidget *dialpad_button;
159 GtkWidget *bottom_toolbar;
160 ClutterActor *floating_toolbar;
162 GtkAction *menu_fullscreen;
163 GtkAction *menu_swap_camera;
165 ClutterState *transitions;
167 /* The box that contains self and remote avatar and video
168 input/output. When we redial, we destroy and re-create the box */
169 ClutterActor *video_box;
170 ClutterLayoutManager *video_layout;
172 /* Coordinates of the preview drag event's start. */
173 PreviewPosition preview_pos;
177 /* We keep a reference on the hbox which contains the main content so we can
178 easilly repack everything when toggling fullscreen */
179 GtkWidget *content_hbox;
181 gulong video_output_motion_handler_id;
182 guint bus_message_source_id;
186 GtkWidget *dtmf_panel;
189 GtkWidget *details_vbox;
190 GtkWidget *vcodec_encoding_label;
191 GtkWidget *acodec_encoding_label;
192 GtkWidget *vcodec_decoding_label;
193 GtkWidget *acodec_decoding_label;
195 GtkWidget *audio_remote_candidate_label;
196 GtkWidget *audio_local_candidate_label;
197 GtkWidget *video_remote_candidate_label;
198 GtkWidget *video_local_candidate_label;
199 GtkWidget *video_remote_candidate_info_img;
200 GtkWidget *video_local_candidate_info_img;
201 GtkWidget *audio_remote_candidate_info_img;
202 GtkWidget *audio_local_candidate_info_img;
204 GstElement *video_input;
205 GstElement *video_preview_sink;
206 GstElement *video_output_sink;
207 GstElement *audio_input;
208 GstElement *audio_output;
209 GstElement *pipeline;
210 GstElement *video_tee;
220 gboolean call_started;
221 gboolean sending_video;
222 CameraState camera_state;
224 EmpathyCallWindowFullscreen *fullscreen;
225 gboolean is_fullscreen;
230 guint inactivity_src;
232 /* Those fields represent the state of the window before it actually was in
234 gboolean dialpad_was_visible_before_fs;
235 gint original_width_before_fs;
236 gint original_height_before_fs;
238 gint x, y, w, h, dialpad_width;
241 /* TRUE if the call should be started when the pipeline is playing */
242 gboolean start_call_when_playing;
243 /* TRUE if we requested to set the pipeline in the playing state */
244 gboolean pipeline_playing;
246 EmpathySoundManager *sound_mgr;
249 EmpathyMicMenu *mic_menu;
250 EmpathyCameraMenu *camera_menu;
253 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
255 static void empathy_call_window_realized_cb (GtkWidget *widget,
256 EmpathyCallWindow *window);
258 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
259 GdkEvent *event, EmpathyCallWindow *window);
261 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
262 GdkEventWindowState *event, EmpathyCallWindow *window);
264 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
267 static void empathy_call_window_mic_toggled_cb (
268 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
270 static void empathy_call_window_hangup_cb (gpointer object,
271 EmpathyCallWindow *window);
273 static void empathy_call_window_fullscreen_cb (gpointer object,
274 EmpathyCallWindow *window);
276 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
278 static gboolean empathy_call_window_video_button_press_cb (
279 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
281 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
282 GdkEventKey *event, EmpathyCallWindow *window);
284 static gboolean empathy_call_window_video_output_motion_notify (
285 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
287 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
290 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
291 EmpathyCallWindow *window);
293 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
295 static void empathy_call_window_status_message (EmpathyCallWindow *window,
298 static gboolean empathy_call_window_bus_message (GstBus *bus,
299 GstMessage *message, gpointer user_data);
302 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
303 gdouble value, EmpathyCallWindow *window);
306 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
309 gtk_widget_set_visible (self->priv->hangup_button, show);
310 gtk_widget_set_visible (self->priv->audio_call_button, !show);
311 gtk_widget_set_visible (self->priv->video_call_button, !show);
315 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
316 EmpathyCallWindow *self)
318 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
319 empathy_call_window_restart_call (self);
323 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
324 EmpathyCallWindow *self)
326 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
327 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
328 empathy_call_window_restart_call (self);
332 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
334 EmpathyCallWindowPriv *priv = GET_PRIV (window);
335 TpyCallChannel *call;
339 g_object_get (priv->handler, "call-channel", &call, NULL);
341 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
342 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
345 tpy_call_channel_dtmf_start_tone (call, event);
347 g_object_unref (call);
351 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
353 EmpathyCallWindowPriv *priv = GET_PRIV (window);
354 TpyCallChannel *call;
356 g_object_get (priv->handler, "call-channel", &call, NULL);
358 tpy_call_channel_dtmf_stop_tone (call);
360 g_object_unref (call);
364 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
366 EmpathyCallWindowPriv *priv = GET_PRIV (self);
369 volume = g_settings_get_double (priv->settings,
370 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
372 /* Don't store the volume because of muting */
373 if (volume > 0 || gtk_toggle_tool_button_get_active (
374 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
375 priv->volume = volume;
377 /* Ensure that the toggle button is active if the volume is > 0 and inactive
378 * if it's smaller than 0 */
379 if ((volume > 0) != gtk_toggle_tool_button_get_active (
380 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
381 gtk_toggle_tool_button_set_active (
382 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
384 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
389 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
391 EmpathyCallWindow *self)
393 empathy_call_window_mic_volume_changed (self);
397 empathy_call_window_show_video_output (EmpathyCallWindow *self,
400 if (self->priv->video_output != NULL)
401 g_object_set (self->priv->video_output, "visible", show, NULL);
403 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
405 clutter_actor_raise_top (self->priv->floating_toolbar);
409 create_video_output_widget (EmpathyCallWindow *self)
411 EmpathyCallWindowPriv *priv = GET_PRIV (self);
413 g_assert (priv->video_output == NULL);
414 g_assert (priv->pipeline != NULL);
416 priv->video_output = clutter_texture_new ();
418 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
421 priv->video_output_sink = clutter_gst_video_sink_new (
422 CLUTTER_TEXTURE (priv->video_output));
424 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
427 gtk_widget_add_events (priv->video_container,
428 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
429 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
430 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
434 create_video_input (EmpathyCallWindow *self)
436 EmpathyCallWindowPriv *priv = GET_PRIV (self);
438 g_assert (priv->video_input == NULL);
439 priv->video_input = empathy_video_src_new ();
440 gst_object_ref (priv->video_input);
441 gst_object_sink (priv->video_input);
445 create_audio_input (EmpathyCallWindow *self)
447 EmpathyCallWindowPriv *priv = GET_PRIV (self);
449 g_assert (priv->audio_input == NULL);
450 priv->audio_input = empathy_audio_src_new ();
451 gst_object_ref (priv->audio_input);
452 gst_object_sink (priv->audio_input);
456 add_video_preview_to_pipeline (EmpathyCallWindow *self)
458 EmpathyCallWindowPriv *priv = GET_PRIV (self);
461 g_assert (priv->video_preview != NULL);
462 g_assert (priv->pipeline != NULL);
463 g_assert (priv->video_input != NULL);
464 g_assert (priv->video_tee != NULL);
466 preview = priv->video_preview_sink;
468 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
470 g_warning ("Could not add video input to pipeline");
474 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
476 g_warning ("Could not add video preview to pipeline");
480 if (!gst_element_link (priv->video_input, priv->video_tee))
482 g_warning ("Could not link video input to video tee");
486 if (!gst_element_link (priv->video_tee, preview))
488 g_warning ("Could not link video tee to video preview");
494 empathy_call_window_disable_camera_cb (GtkAction *action,
495 EmpathyCallWindow *self)
497 clutter_actor_destroy (self->priv->preview_hidden_button);
499 gtk_toggle_tool_button_set_active (
500 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
504 empathy_call_window_minimise_camera_cb (GtkAction *action,
505 EmpathyCallWindow *self)
507 clutter_actor_hide (self->priv->video_preview);
508 clutter_actor_show (self->priv->preview_hidden_button);
512 empathy_call_window_maximise_camera_cb (GtkAction *action,
513 EmpathyCallWindow *self)
515 clutter_actor_show (self->priv->video_preview);
516 clutter_actor_hide (self->priv->preview_hidden_button);
520 empathy_call_window_swap_camera_cb (GtkAction *action,
521 EmpathyCallWindow *self)
523 const GList *cameras, *l;
526 DEBUG ("Swapping the camera");
528 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
529 current_cam = empathy_video_src_dup_device (
530 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
532 for (l = cameras; l != NULL; l = l->next)
534 EmpathyCamera *camera = l->data;
536 if (!tp_strdiff (camera->device, current_cam))
541 next = l->next->data;
543 next = cameras->data;
545 /* EmpathyCameraMenu will update itself and do the actual change
547 g_settings_set_string (self->priv->settings,
548 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
555 g_free (current_cam);
559 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
560 EmpathyCamera *camera,
561 EmpathyCallWindow *self)
563 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
565 gtk_action_set_visible (self->priv->menu_swap_camera,
566 g_list_length ((GList *) cameras) >= 2);
570 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
571 EmpathyCamera *camera,
572 EmpathyCallWindow *self)
574 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
576 gtk_action_set_visible (self->priv->menu_swap_camera,
577 g_list_length ((GList *) cameras) >= 2);
581 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
582 EmpathyCallWindow *self)
586 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
588 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
589 0, gtk_get_current_event_time ());
590 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
594 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
595 EmpathyCallWindow *self)
599 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
600 "/preview-hidden-menu");
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);
606 static ClutterActor *
607 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
608 ClutterBinAlignment x,
609 ClutterBinAlignment y)
611 ClutterLayoutManager *layout1, *layout2;
612 ClutterActor *rectangle;
613 ClutterActor *box1, *box2;
615 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
616 CLUTTER_BIN_ALIGNMENT_START);
618 box1 = clutter_box_new (layout1);
620 rectangle = clutter_rectangle_new_with_color (
621 CLUTTER_COLOR_Transparent);
623 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
626 clutter_actor_set_size (box1,
627 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
628 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
629 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
631 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
632 CLUTTER_BIN_ALIGNMENT_CENTER);
634 /* We have a box with the margins and the video in the middle inside
635 * a bigger box with an extra bottom margin so we're not on top of
636 * the floating toolbar. */
637 box2 = clutter_box_new (layout2);
639 clutter_actor_set_size (box2,
640 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
641 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
643 clutter_actor_set_size (rectangle,
644 SELF_VIDEO_SECTION_WIDTH + 5, SELF_VIDEO_SECTION_HEIGHT + 5);
646 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
647 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
649 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
652 clutter_actor_hide (rectangle);
658 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
660 self->priv->preview_rectangle1 =
661 empathy_call_window_create_preview_rectangle (self,
662 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
663 self->priv->preview_rectangle2 =
664 empathy_call_window_create_preview_rectangle (self,
665 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
666 self->priv->preview_rectangle3 =
667 empathy_call_window_create_preview_rectangle (self,
668 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
669 self->priv->preview_rectangle4 =
670 empathy_call_window_create_preview_rectangle (self,
671 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
675 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
678 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
679 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
680 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
681 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
684 static PreviewPosition
685 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
690 PreviewPosition pos = PREVIEW_POS_NONE;
692 clutter_actor_get_geometry (self->priv->video_box, &box);
694 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
695 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
696 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
697 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
699 pos = PREVIEW_POS_TOP_LEFT;
701 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
702 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
703 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
704 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
706 pos = PREVIEW_POS_TOP_RIGHT;
708 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
709 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
710 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
711 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
713 pos = PREVIEW_POS_BOTTOM_LEFT;
715 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
716 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
717 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
718 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
720 pos = PREVIEW_POS_BOTTOM_RIGHT;
726 static ClutterActor *
727 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
730 ClutterActor *rectangle;
734 case PREVIEW_POS_TOP_LEFT:
735 rectangle = self->priv->preview_rectangle1;
737 case PREVIEW_POS_TOP_RIGHT:
738 rectangle = self->priv->preview_rectangle3;
740 case PREVIEW_POS_BOTTOM_LEFT:
741 rectangle = self->priv->preview_rectangle2;
743 case PREVIEW_POS_BOTTOM_RIGHT:
744 rectangle = self->priv->preview_rectangle4;
754 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
757 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
759 DEBUG ("moving the video preview to %d", pos);
761 self->priv->preview_pos = pos;
765 case PREVIEW_POS_TOP_LEFT:
766 clutter_bin_layout_set_alignment (layout,
767 self->priv->video_preview,
768 CLUTTER_BIN_ALIGNMENT_START,
769 CLUTTER_BIN_ALIGNMENT_START);
771 case PREVIEW_POS_TOP_RIGHT:
772 clutter_bin_layout_set_alignment (layout,
773 self->priv->video_preview,
774 CLUTTER_BIN_ALIGNMENT_END,
775 CLUTTER_BIN_ALIGNMENT_START);
777 case PREVIEW_POS_BOTTOM_LEFT:
778 clutter_bin_layout_set_alignment (layout,
779 self->priv->video_preview,
780 CLUTTER_BIN_ALIGNMENT_START,
781 CLUTTER_BIN_ALIGNMENT_END);
783 case PREVIEW_POS_BOTTOM_RIGHT:
784 clutter_bin_layout_set_alignment (layout,
785 self->priv->video_preview,
786 CLUTTER_BIN_ALIGNMENT_END,
787 CLUTTER_BIN_ALIGNMENT_END);
790 g_warn_if_reached ();
795 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
798 ClutterActor *rectangle;
800 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
802 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
803 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
808 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
809 ClutterActor *rectangle)
811 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
812 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
813 CLUTTER_COLOR_Black);
817 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
819 ClutterActor *rectangle;
821 rectangle = empathy_call_window_get_preview_rectangle (self,
822 self->priv->preview_pos);
824 /* We don't want to darken the rectangle where the preview
827 if (self->priv->preview_rectangle1 != rectangle)
828 empathy_call_window_darken_preview_rectangle (self,
829 self->priv->preview_rectangle1);
831 if (self->priv->preview_rectangle2 != rectangle)
832 empathy_call_window_darken_preview_rectangle (self,
833 self->priv->preview_rectangle2);
835 if (self->priv->preview_rectangle3 != rectangle)
836 empathy_call_window_darken_preview_rectangle (self,
837 self->priv->preview_rectangle3);
839 if (self->priv->preview_rectangle4 != rectangle)
840 empathy_call_window_darken_preview_rectangle (self,
841 self->priv->preview_rectangle4);
845 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
849 ClutterModifierType modifiers,
850 EmpathyCallWindow *self)
852 empathy_call_window_show_preview_rectangles (self, TRUE);
853 empathy_call_window_darken_preview_rectangles (self);
855 self->priv->event_x = event_x;
856 self->priv->event_y = event_y;
860 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
864 ClutterModifierType modifiers,
865 EmpathyCallWindow *self)
869 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
871 if (pos != PREVIEW_POS_NONE)
872 empathy_call_window_move_video_preview (self, pos);
874 empathy_call_window_show_preview_rectangles (self, FALSE);
878 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
882 EmpathyCallWindow *self)
886 pos = empathy_call_window_get_preview_position (self,
887 self->priv->event_x - delta_x, self->priv->event_y + delta_y);
889 if (pos != PREVIEW_POS_NONE)
890 empathy_call_window_highlight_preview_rectangle (self, pos);
892 empathy_call_window_darken_preview_rectangles (self);
896 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
897 ClutterCrossingEvent *event,
898 EmpathyCallWindow *self)
900 ClutterActor *rectangle;
902 rectangle = empathy_call_window_get_preview_rectangle (self,
903 self->priv->preview_pos);
905 empathy_call_window_highlight_preview_rectangle (self,
906 self->priv->preview_pos);
908 clutter_actor_show (rectangle);
914 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
915 ClutterCrossingEvent *event,
916 EmpathyCallWindow *self)
918 ClutterActor *rectangle;
920 rectangle = empathy_call_window_get_preview_rectangle (self,
921 self->priv->preview_pos);
923 empathy_call_window_darken_preview_rectangle (self, rectangle);
925 clutter_actor_hide (rectangle);
931 create_video_preview (EmpathyCallWindow *self)
933 EmpathyCallWindowPriv *priv = GET_PRIV (self);
934 ClutterLayoutManager *layout, *layout_center, *layout_end;
935 ClutterActor *preview;
938 ClutterAction *action;
941 g_assert (priv->video_preview == NULL);
943 preview = clutter_texture_new ();
944 clutter_actor_set_size (preview,
945 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
946 priv->video_preview_sink = clutter_gst_video_sink_new (
947 CLUTTER_TEXTURE (preview));
949 /* Flip the video preview */
950 clutter_actor_set_rotation (preview,
953 SELF_VIDEO_SECTION_WIDTH * 0.5,
957 /* Add a little offset to the video preview */
958 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
959 CLUTTER_BIN_ALIGNMENT_START);
960 priv->video_preview = clutter_box_new (layout);
961 clutter_actor_set_size (priv->video_preview,
962 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
963 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
964 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
966 /* We have a box with the margins and the video in the middle inside
967 * a bigger box with an extra bottom margin so we're not on top of
968 * the floating toolbar. */
969 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
970 CLUTTER_BIN_ALIGNMENT_CENTER);
971 box = clutter_box_new (layout_center);
972 clutter_actor_set_size (box,
973 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
974 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
976 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
977 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
979 g_object_set (priv->video_preview_sink,
984 /* Translators: this is an "Info" label. It should be as short
986 button = gtk_button_new_with_label (_("i"));
987 b = gtk_clutter_actor_new_with_contents (button);
989 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
990 CLUTTER_BIN_ALIGNMENT_END);
991 box = clutter_box_new (layout_end);
992 clutter_actor_set_size (box,
993 SELF_VIDEO_SECTION_WIDTH,
994 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
996 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
997 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
999 g_signal_connect (button, "clicked",
1000 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1003 /* Translators: this is an "Info" label. It should be as short
1005 button = gtk_button_new_with_label (_("i"));
1006 priv->preview_hidden_button =
1007 gtk_clutter_actor_new_with_contents (button);
1009 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1010 priv->preview_hidden_button,
1011 CLUTTER_BIN_ALIGNMENT_START,
1012 CLUTTER_BIN_ALIGNMENT_END);
1014 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1016 clutter_actor_hide (priv->preview_hidden_button);
1018 g_signal_connect (button, "clicked",
1019 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1022 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1023 priv->video_preview,
1024 CLUTTER_BIN_ALIGNMENT_START,
1025 CLUTTER_BIN_ALIGNMENT_END);
1027 action = clutter_drag_action_new ();
1028 g_signal_connect (action, "drag-begin",
1029 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1030 g_signal_connect (action, "drag-end",
1031 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1032 g_signal_connect (action, "drag-motion",
1033 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1035 g_signal_connect (preview, "enter-event",
1036 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1037 g_signal_connect (preview, "leave-event",
1038 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1040 clutter_actor_add_action (preview, action);
1041 clutter_actor_set_reactive (preview, TRUE);
1045 play_camera (EmpathyCallWindow *window,
1048 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1049 GstElement *preview;
1052 if (priv->video_preview == NULL)
1054 create_video_preview (window);
1055 add_video_preview_to_pipeline (window);
1059 state = GST_STATE_PLAYING;
1061 state = GST_STATE_NULL;
1063 preview = priv->video_preview_sink;
1065 gst_element_set_state (preview, state);
1066 gst_element_set_state (priv->video_input, state);
1067 gst_element_set_state (priv->video_tee, state);
1071 display_video_preview (EmpathyCallWindow *self,
1074 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1078 /* Display the video preview */
1079 DEBUG ("Show video preview");
1081 play_camera (self, TRUE);
1082 clutter_actor_show (priv->video_preview);
1083 clutter_actor_raise_top (priv->floating_toolbar);
1087 /* Hide the video preview */
1088 DEBUG ("Hide video preview");
1090 if (priv->video_preview != NULL)
1092 clutter_actor_hide (priv->video_preview);
1093 play_camera (self, FALSE);
1099 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1101 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1103 empathy_call_window_status_message (window, _("Connecting…"));
1104 priv->call_state = CONNECTING;
1107 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1108 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1112 disable_camera (EmpathyCallWindow *self)
1114 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1116 if (priv->camera_state == CAMERA_STATE_OFF)
1119 DEBUG ("Disable camera");
1121 display_video_preview (self, FALSE);
1123 if (priv->camera_state == CAMERA_STATE_ON)
1124 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1126 priv->camera_state = CAMERA_STATE_OFF;
1130 enable_camera (EmpathyCallWindow *self)
1132 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1134 if (priv->camera_state == CAMERA_STATE_ON)
1137 if (priv->video_input == NULL)
1139 DEBUG ("Can't enable camera, no input");
1143 DEBUG ("Enable camera");
1145 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1147 priv->camera_state = CAMERA_STATE_ON;
1151 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1152 EmpathyCallWindow *self)
1154 if (gtk_toggle_tool_button_get_active (toggle))
1155 enable_camera (self);
1157 disable_camera (self);
1161 create_pipeline (EmpathyCallWindow *self)
1163 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1166 g_assert (priv->pipeline == NULL);
1168 priv->pipeline = gst_pipeline_new (NULL);
1169 priv->pipeline_playing = FALSE;
1171 priv->video_tee = gst_element_factory_make ("tee", NULL);
1172 gst_object_ref (priv->video_tee);
1173 gst_object_sink (priv->video_tee);
1175 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1177 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1178 priv->bus_message_source_id = gst_bus_add_watch (bus,
1179 empathy_call_window_bus_message, self);
1181 g_object_unref (bus);
1185 empathy_call_window_settings_cb (GtkAction *action,
1186 EmpathyCallWindow *self)
1188 gchar *args = g_strdup_printf ("-p %s",
1189 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1191 empathy_launch_program (BIN_DIR, "empathy", args);
1197 empathy_call_window_contents_cb (GtkAction *action,
1198 EmpathyCallWindow *self)
1200 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1204 empathy_call_window_debug_cb (GtkAction *action,
1205 EmpathyCallWindow *self)
1207 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1211 empathy_call_window_about_cb (GtkAction *action,
1212 EmpathyCallWindow *self)
1214 empathy_about_dialog_new (GTK_WINDOW (self));
1218 empathy_call_window_toolbar_timeout (gpointer data)
1220 EmpathyCallWindow *self = data;
1222 clutter_state_set_state (self->priv->transitions, "fade-out");
1228 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1230 EmpathyCallWindow *self)
1232 clutter_state_set_state (self->priv->transitions, "fade-in");
1234 if (self->priv->inactivity_src > 0)
1235 g_source_remove (self->priv->inactivity_src);
1237 self->priv->inactivity_src = g_timeout_add_seconds (3,
1238 empathy_call_window_toolbar_timeout, self);
1244 empathy_call_window_configure_event_cb (GtkWidget *widget,
1246 EmpathyCallWindow *self)
1248 GdkWindow *gdk_window;
1249 GdkWindowState window_state;
1251 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1252 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1254 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1255 &self->priv->dialpad_width, NULL);
1257 gdk_window = gtk_widget_get_window (widget);
1258 window_state = gdk_window_get_state (gdk_window);
1259 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1265 empathy_call_window_destroyed_cb (GtkWidget *object,
1266 EmpathyCallWindow *self)
1268 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1270 /* Save the geometry as if the dialpad was hidden. */
1271 empathy_geometry_save_values (GTK_WINDOW (self),
1272 self->priv->x, self->priv->y,
1273 self->priv->w - self->priv->dialpad_width, self->priv->h,
1274 self->priv->maximized);
1279 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1281 ClutterBindConstraint *constraint)
1283 ClutterActorBox allocation;
1285 clutter_actor_get_allocation_box (stage, &allocation);
1287 clutter_bind_constraint_set_offset (constraint,
1288 allocation.y2 - allocation.y1 -
1289 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1293 empathy_call_window_init (EmpathyCallWindow *self)
1295 EmpathyCallWindowPriv *priv;
1297 GtkWidget *top_vbox;
1299 ClutterConstraint *constraint;
1300 ClutterActor *remote_avatar;
1301 GtkStyleContext *context;
1305 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1306 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1308 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1309 gui = empathy_builder_get_file (filename,
1310 "call_window_vbox", &top_vbox,
1311 "errors_vbox", &priv->errors_vbox,
1312 "pane", &priv->pane,
1313 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1314 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1315 "status_label", &priv->status_label,
1316 "audiocall", &priv->audio_call_button,
1317 "videocall", &priv->video_call_button,
1318 "microphone", &priv->mic_button,
1319 "camera", &priv->camera_button,
1320 "hangup", &priv->hangup_button,
1321 "dialpad", &priv->dialpad_button,
1322 "toolbar", &priv->toolbar,
1323 "bottom_toolbar", &priv->bottom_toolbar,
1324 "ui_manager", &priv->ui_manager,
1325 "menufullscreen", &priv->menu_fullscreen,
1326 "menupreviewswap", &priv->menu_swap_camera,
1327 "details_vbox", &priv->details_vbox,
1328 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1329 "acodec_encoding_label", &priv->acodec_encoding_label,
1330 "acodec_decoding_label", &priv->acodec_decoding_label,
1331 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1332 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1333 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1334 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1335 "video_local_candidate_label", &priv->video_local_candidate_label,
1336 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1337 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1338 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1339 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1343 empathy_builder_connect (gui, self,
1344 "hangup", "clicked", empathy_call_window_hangup_cb,
1345 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1346 "videocall", "clicked", empathy_call_window_video_call_cb,
1347 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1348 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1349 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1350 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1351 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1352 "menusettings", "activate", empathy_call_window_settings_cb,
1353 "menucontents", "activate", empathy_call_window_contents_cb,
1354 "menudebug", "activate", empathy_call_window_debug_cb,
1355 "menuabout", "activate", empathy_call_window_about_cb,
1356 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1357 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1358 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1359 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1362 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1364 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1366 g_object_bind_property (priv->camera_monitor, "available",
1367 priv->camera_button, "sensitive",
1368 G_BINDING_SYNC_CREATE);
1370 g_signal_connect (priv->camera_monitor, "added",
1371 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1372 g_signal_connect (priv->camera_monitor, "removed",
1373 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1375 priv->lock = g_mutex_new ();
1377 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1379 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1380 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1381 CONTENT_HBOX_BORDER_WIDTH);
1382 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1385 /* avatar/video box */
1386 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1387 CLUTTER_BIN_ALIGNMENT_CENTER);
1389 priv->video_box = clutter_box_new (priv->video_layout);
1391 priv->video_container = gtk_clutter_embed_new ();
1393 /* Set the background color to that of the rest of the window */
1394 context = gtk_widget_get_style_context (priv->content_hbox);
1395 gtk_style_context_get_background_color (context,
1396 GTK_STATE_FLAG_NORMAL, &rgba);
1397 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1398 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1399 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1400 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1401 clutter_stage_set_color (
1402 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1403 GTK_CLUTTER_EMBED (priv->video_container))),
1406 clutter_container_add (
1407 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1408 GTK_CLUTTER_EMBED (priv->video_container))),
1412 constraint = clutter_bind_constraint_new (
1413 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1414 CLUTTER_BIND_SIZE, 0);
1415 clutter_actor_add_constraint (priv->video_box, constraint);
1417 priv->remote_user_avatar_widget = gtk_image_new ();
1418 remote_avatar = gtk_clutter_actor_new_with_contents (
1419 priv->remote_user_avatar_widget);
1421 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1424 empathy_call_window_create_preview_rectangles (self);
1426 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1427 priv->video_container, TRUE, TRUE,
1428 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1430 create_pipeline (self);
1431 create_video_output_widget (self);
1432 create_audio_input (self);
1433 create_video_input (self);
1435 priv->floating_toolbar = empathy_rounded_actor_new ();
1437 gtk_widget_reparent (priv->bottom_toolbar,
1438 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1440 constraint = clutter_bind_constraint_new (
1441 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1444 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1447 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1448 "notify::allocation",
1449 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1452 clutter_actor_set_size (priv->floating_toolbar,
1453 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1454 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1456 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1457 priv->floating_toolbar,
1458 CLUTTER_BIN_ALIGNMENT_CENTER,
1459 CLUTTER_BIN_ALIGNMENT_END);
1461 clutter_actor_raise_top (priv->floating_toolbar);
1463 /* Transitions for the floating toolbar */
1464 priv->transitions = clutter_state_new ();
1466 /* all transitions last for 2s */
1467 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1469 /* transition from any state to "fade-out" state */
1470 clutter_state_set (priv->transitions, NULL, "fade-out",
1471 priv->floating_toolbar,
1472 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1475 /* transition from any state to "fade-in" state */
1476 clutter_state_set (priv->transitions, NULL, "fade-in",
1477 priv->floating_toolbar,
1478 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1481 /* put the actor into the "fade-in" state with no animation */
1482 clutter_state_warp_to_state (priv->transitions, "fade-in");
1484 /* The call will be started as soon the pipeline is playing */
1485 priv->start_call_when_playing = TRUE;
1487 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1488 G_CALLBACK (dtmf_button_pressed_cb),
1489 G_CALLBACK (dtmf_button_released_cb));
1491 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1494 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1497 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1499 gtk_widget_show_all (top_vbox);
1501 gtk_widget_hide (priv->dtmf_panel);
1502 gtk_widget_hide (priv->details_vbox);
1504 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1506 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1507 priv->video_container);
1509 /* We hide the bottom toolbar after 3s of inactivity and show it
1510 * again on mouse movement */
1511 priv->inactivity_src = g_timeout_add_seconds (3,
1512 empathy_call_window_toolbar_timeout, self);
1514 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1515 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1517 g_signal_connect (G_OBJECT (self), "realize",
1518 G_CALLBACK (empathy_call_window_realized_cb), self);
1520 g_signal_connect (G_OBJECT (self), "delete-event",
1521 G_CALLBACK (empathy_call_window_delete_cb), self);
1523 g_signal_connect (G_OBJECT (self), "window-state-event",
1524 G_CALLBACK (empathy_call_window_state_event_cb), self);
1526 g_signal_connect (G_OBJECT (self), "key-press-event",
1527 G_CALLBACK (empathy_call_window_key_press_cb), self);
1529 g_signal_connect (self, "motion-notify-event",
1530 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1532 priv->timer = g_timer_new ();
1534 g_object_ref (priv->ui_manager);
1535 g_object_unref (gui);
1537 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1538 priv->mic_menu = empathy_mic_menu_new (self);
1539 priv->camera_menu = empathy_camera_menu_new (self);
1541 empathy_call_window_show_hangup_button (self, TRUE);
1543 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1545 /* Retrieve initial volume */
1546 priv->volume = g_settings_get_double (priv->settings,
1547 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1549 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1550 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1552 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1553 /* These signals are used to track the window position and save it
1554 * when the window is destroyed. We need to do this as we don't want
1555 * the window geometry to be saved with the dialpad taken into account. */
1556 g_signal_connect (self, "destroy",
1557 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1558 g_signal_connect (self, "configure-event",
1559 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1560 g_signal_connect (self, "window-state-event",
1561 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1563 /* Don't display labels in both toolbars */
1564 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1567 /* Instead of specifying a width and a height, we specify only one size. That's
1568 because we want a square avatar icon. */
1570 init_contact_avatar_with_size (EmpathyContact *contact,
1571 GtkWidget *image_widget,
1574 GdkPixbuf *pixbuf_avatar = NULL;
1576 if (contact != NULL)
1578 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1582 if (pixbuf_avatar == NULL)
1584 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1585 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1588 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1590 if (pixbuf_avatar != NULL)
1591 g_object_unref (pixbuf_avatar);
1595 set_window_title (EmpathyCallWindow *self)
1597 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1600 if (priv->contact != NULL)
1602 /* translators: Call is a noun and %s is the contact name. This string
1603 * is used in the window title */
1604 tmp = g_strdup_printf (_("Call with %s"),
1605 empathy_contact_get_alias (priv->contact));
1606 gtk_window_set_title (GTK_WINDOW (self), tmp);
1611 g_warning ("Unknown remote contact!");
1616 set_remote_user_name (EmpathyCallWindow *self,
1617 EmpathyContact *contact)
1619 const gchar *alias = empathy_contact_get_alias (contact);
1620 const gchar *status = empathy_contact_get_status (contact);
1623 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1624 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1630 contact_name_changed_cb (EmpathyContact *contact,
1632 EmpathyCallWindow *self)
1634 set_window_title (self);
1635 set_remote_user_name (self, contact);
1639 contact_presence_changed_cb (EmpathyContact *contact,
1641 EmpathyCallWindow *self)
1643 set_remote_user_name (self, contact);
1647 contact_avatar_changed_cb (EmpathyContact *contact,
1649 EmpathyCallWindow *self)
1652 GtkAllocation allocation;
1653 GtkWidget *avatar_widget;
1655 avatar_widget = self->priv->remote_user_avatar_widget;
1657 gtk_widget_get_allocation (avatar_widget, &allocation);
1658 size = allocation.height;
1662 /* the widget is not allocated yet, set a default size */
1663 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1664 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1667 init_contact_avatar_with_size (contact, avatar_widget, size);
1669 avatar_widget = self->priv->remote_user_avatar_toolbar;
1671 gtk_widget_get_allocation (avatar_widget, &allocation);
1672 size = allocation.height;
1676 /* the widget is not allocated yet, set a default size */
1677 size = SMALL_TOOLBAR_SIZE;
1680 init_contact_avatar_with_size (contact, avatar_widget, size);
1684 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1685 EmpathyCallHandler *handler)
1687 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1689 tp_g_signal_connect_object (priv->contact, "notify::name",
1690 G_CALLBACK (contact_name_changed_cb), self, 0);
1691 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1692 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1693 tp_g_signal_connect_object (priv->contact, "notify::presence",
1694 G_CALLBACK (contact_presence_changed_cb), self, 0);
1696 set_window_title (self);
1697 set_remote_user_name (self, priv->contact);
1699 init_contact_avatar_with_size (priv->contact,
1700 priv->remote_user_avatar_widget,
1701 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1702 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1704 init_contact_avatar_with_size (priv->contact,
1705 priv->remote_user_avatar_toolbar,
1706 SMALL_TOOLBAR_SIZE);
1708 /* The remote avatar is shown by default and will be hidden when we receive
1709 video from the remote side. */
1710 clutter_actor_hide (priv->video_output);
1711 gtk_widget_show (priv->remote_user_avatar_widget);
1715 update_send_codec (EmpathyCallWindow *self,
1718 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1725 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1726 widget = priv->acodec_encoding_label;
1730 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1731 widget = priv->vcodec_encoding_label;
1737 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1738 gtk_label_set_text (GTK_LABEL (widget), tmp);
1743 send_audio_codec_notify_cb (GObject *object,
1747 EmpathyCallWindow *self = user_data;
1749 update_send_codec (self, TRUE);
1753 send_video_codec_notify_cb (GObject *object,
1757 EmpathyCallWindow *self = user_data;
1759 update_send_codec (self, FALSE);
1763 update_recv_codec (EmpathyCallWindow *self,
1766 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1769 GString *str = NULL;
1773 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1774 widget = priv->acodec_decoding_label;
1778 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1779 widget = priv->vcodec_decoding_label;
1785 for (l = codecs; l != NULL; l = g_list_next (l))
1787 FsCodec *codec = l->data;
1790 str = g_string_new (NULL);
1792 g_string_append (str, ", ");
1794 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1798 gtk_label_set_text (GTK_LABEL (widget), str->str);
1799 g_string_free (str, TRUE);
1803 recv_audio_codecs_notify_cb (GObject *object,
1807 EmpathyCallWindow *self = user_data;
1809 update_recv_codec (self, TRUE);
1813 recv_video_codecs_notify_cb (GObject *object,
1817 EmpathyCallWindow *self = user_data;
1819 update_recv_codec (self, FALSE);
1822 static const gchar *
1823 candidate_type_to_str (FsCandidate *candidate)
1825 switch (candidate->type)
1827 case FS_CANDIDATE_TYPE_HOST:
1829 case FS_CANDIDATE_TYPE_SRFLX:
1830 return "server reflexive";
1831 case FS_CANDIDATE_TYPE_PRFLX:
1832 return "peer reflexive";
1833 case FS_CANDIDATE_TYPE_RELAY:
1835 case FS_CANDIDATE_TYPE_MULTICAST:
1842 static const gchar *
1843 candidate_type_to_desc (FsCandidate *candidate)
1845 switch (candidate->type)
1847 case FS_CANDIDATE_TYPE_HOST:
1848 return _("The IP address as seen by the machine");
1849 case FS_CANDIDATE_TYPE_SRFLX:
1850 return _("The IP address as seen by a server on the Internet");
1851 case FS_CANDIDATE_TYPE_PRFLX:
1852 return _("The IP address of the peer as seen by the other side");
1853 case FS_CANDIDATE_TYPE_RELAY:
1854 return _("The IP address of a relay server");
1855 case FS_CANDIDATE_TYPE_MULTICAST:
1856 return _("The IP address of the multicast group");
1863 update_candidat_widget (EmpathyCallWindow *self,
1866 FsCandidate *candidate)
1870 g_assert (candidate != NULL);
1871 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1872 candidate->port, candidate_type_to_str (candidate));
1874 gtk_label_set_text (GTK_LABEL (label), str);
1875 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1881 candidates_changed_cb (GObject *object,
1883 EmpathyCallWindow *self)
1885 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1886 FsCandidate *candidate = NULL;
1888 if (type == FS_MEDIA_TYPE_VIDEO)
1890 /* Update remote candidate */
1891 candidate = empathy_call_handler_get_video_remote_candidate (
1894 update_candidat_widget (self, priv->video_remote_candidate_label,
1895 priv->video_remote_candidate_info_img, candidate);
1897 /* Update local candidate */
1898 candidate = empathy_call_handler_get_video_local_candidate (
1901 update_candidat_widget (self, priv->video_local_candidate_label,
1902 priv->video_local_candidate_info_img, candidate);
1906 /* Update remote candidate */
1907 candidate = empathy_call_handler_get_audio_remote_candidate (
1910 update_candidat_widget (self, priv->audio_remote_candidate_label,
1911 priv->audio_remote_candidate_info_img, candidate);
1913 /* Update local candidate */
1914 candidate = empathy_call_handler_get_audio_local_candidate (
1917 update_candidat_widget (self, priv->audio_local_candidate_label,
1918 priv->audio_local_candidate_info_img, candidate);
1923 empathy_call_window_constructed (GObject *object)
1925 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1926 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1927 TpyCallChannel *call;
1929 g_assert (priv->handler != NULL);
1931 g_object_get (priv->handler, "call-channel", &call, NULL);
1932 priv->outgoing = (call == NULL);
1934 g_object_unref (call);
1936 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1937 g_assert (priv->contact != NULL);
1939 empathy_call_window_setup_avatars (self, priv->handler);
1940 empathy_call_window_set_state_connecting (self);
1942 if (!empathy_call_handler_has_initial_video (priv->handler))
1944 gtk_toggle_tool_button_set_active (
1945 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1947 /* If call has InitialVideo, the preview will be started once the call has
1948 * been started (start_call()). */
1950 update_send_codec (self, TRUE);
1951 update_send_codec (self, FALSE);
1952 update_recv_codec (self, TRUE);
1953 update_recv_codec (self, FALSE);
1955 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1956 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1957 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1958 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1959 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1960 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1961 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1962 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1964 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1965 G_CALLBACK (candidates_changed_cb), self, 0);
1968 static void empathy_call_window_dispose (GObject *object);
1969 static void empathy_call_window_finalize (GObject *object);
1972 empathy_call_window_set_property (GObject *object,
1973 guint property_id, const GValue *value, GParamSpec *pspec)
1975 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1977 switch (property_id)
1979 case PROP_CALL_HANDLER:
1980 priv->handler = g_value_dup_object (value);
1983 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1988 empathy_call_window_get_property (GObject *object,
1989 guint property_id, GValue *value, GParamSpec *pspec)
1991 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1993 switch (property_id)
1995 case PROP_CALL_HANDLER:
1996 g_value_set_object (value, priv->handler);
1999 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2004 empathy_call_window_class_init (
2005 EmpathyCallWindowClass *empathy_call_window_class)
2007 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2008 GParamSpec *param_spec;
2010 g_type_class_add_private (empathy_call_window_class,
2011 sizeof (EmpathyCallWindowPriv));
2013 object_class->constructed = empathy_call_window_constructed;
2014 object_class->set_property = empathy_call_window_set_property;
2015 object_class->get_property = empathy_call_window_get_property;
2017 object_class->dispose = empathy_call_window_dispose;
2018 object_class->finalize = empathy_call_window_finalize;
2020 param_spec = g_param_spec_object ("handler",
2021 "handler", "The call handler",
2022 EMPATHY_TYPE_CALL_HANDLER,
2023 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2024 g_object_class_install_property (object_class,
2025 PROP_CALL_HANDLER, param_spec);
2029 empathy_call_window_dispose (GObject *object)
2031 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2032 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2034 if (priv->dispose_has_run)
2037 priv->dispose_has_run = TRUE;
2039 if (priv->handler != NULL)
2041 empathy_call_handler_stop_call (priv->handler);
2042 tp_clear_object (&priv->handler);
2045 if (priv->bus_message_source_id != 0)
2047 g_source_remove (priv->bus_message_source_id);
2048 priv->bus_message_source_id = 0;
2051 if (priv->got_video_src > 0)
2053 g_source_remove (priv->got_video_src);
2054 priv->got_video_src = 0;
2057 if (priv->inactivity_src > 0)
2059 g_source_remove (priv->inactivity_src);
2060 priv->inactivity_src = 0;
2063 tp_clear_object (&priv->pipeline);
2064 tp_clear_object (&priv->video_input);
2065 tp_clear_object (&priv->audio_input);
2066 tp_clear_object (&priv->video_tee);
2067 tp_clear_object (&priv->ui_manager);
2068 tp_clear_object (&priv->fullscreen);
2069 tp_clear_object (&priv->camera_monitor);
2070 tp_clear_object (&priv->settings);
2071 tp_clear_object (&priv->sound_mgr);
2072 tp_clear_object (&priv->mic_menu);
2073 tp_clear_object (&priv->camera_menu);
2075 g_list_free_full (priv->notifiers, g_object_unref);
2077 if (priv->timer_id != 0)
2078 g_source_remove (priv->timer_id);
2081 if (priv->contact != NULL)
2083 g_signal_handlers_disconnect_by_func (priv->contact,
2084 contact_name_changed_cb, self);
2085 priv->contact = NULL;
2088 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2092 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2094 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2096 if (priv->video_output_motion_handler_id != 0)
2098 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2099 priv->video_output_motion_handler_id);
2100 priv->video_output_motion_handler_id = 0;
2105 empathy_call_window_finalize (GObject *object)
2107 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2108 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2110 disconnect_video_output_motion_handler (self);
2112 /* free any data held directly by the object here */
2113 g_mutex_free (priv->lock);
2115 g_timer_destroy (priv->timer);
2117 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2122 empathy_call_window_new (EmpathyCallHandler *handler)
2124 return EMPATHY_CALL_WINDOW (
2125 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2129 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2130 GstElement *conference, gpointer user_data)
2132 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2133 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2134 FsElementAddedNotifier *notifier;
2137 DEBUG ("Conference added");
2139 /* Add notifier to set the various element properties as needed */
2140 notifier = fs_element_added_notifier_new ();
2141 keyfile = fs_utils_get_default_element_properties (conference);
2143 if (keyfile != NULL)
2144 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2146 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2148 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2150 gst_bin_add (GST_BIN (priv->pipeline), conference);
2151 gst_element_set_state (conference, GST_STATE_PLAYING);
2155 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2156 GstElement *conference, gpointer user_data)
2158 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2159 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2161 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2162 gst_element_set_state (conference, GST_STATE_NULL);
2166 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2168 GstStateChangeReturn state_change_return;
2169 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2171 if (priv->pipeline == NULL)
2174 if (priv->bus_message_source_id != 0)
2176 g_source_remove (priv->bus_message_source_id);
2177 priv->bus_message_source_id = 0;
2180 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2182 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2183 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2185 if (priv->pipeline != NULL)
2186 g_object_unref (priv->pipeline);
2187 priv->pipeline = NULL;
2189 if (priv->audio_output != NULL)
2190 g_object_unref (priv->audio_output);
2191 priv->audio_output = NULL;
2193 if (priv->video_tee != NULL)
2194 g_object_unref (priv->video_tee);
2195 priv->video_tee = NULL;
2197 if (priv->video_preview != NULL)
2198 clutter_actor_destroy (priv->video_preview);
2199 priv->video_preview = NULL;
2201 priv->funnel = NULL;
2203 create_pipeline (self);
2204 /* Call will be started when user will hit the 'redial' button */
2205 priv->start_call_when_playing = FALSE;
2206 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2212 g_message ("Error: could not destroy pipeline. Closing call window");
2213 gtk_widget_destroy (GTK_WIDGET (self));
2220 reset_details_pane (EmpathyCallWindow *self)
2222 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2224 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2225 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2226 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2227 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2231 empathy_call_window_disconnected (EmpathyCallWindow *self,
2234 gboolean could_disconnect = FALSE;
2235 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2236 gboolean could_reset_pipeline;
2238 /* Leave full screen mode if needed */
2239 gtk_window_unfullscreen (GTK_WINDOW (self));
2241 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2242 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2244 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2246 if (priv->call_state == CONNECTING)
2247 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2249 if (priv->call_state != REDIALING)
2250 priv->call_state = DISCONNECTED;
2252 if (could_reset_pipeline)
2254 g_mutex_lock (priv->lock);
2256 g_timer_stop (priv->timer);
2258 if (priv->timer_id != 0)
2259 g_source_remove (priv->timer_id);
2262 g_mutex_unlock (priv->lock);
2265 /* We are about to destroy the window, no need to update it or create
2266 * a video preview */
2269 empathy_call_window_status_message (self, _("Disconnected"));
2271 empathy_call_window_show_hangup_button (self, FALSE);
2273 /* Unsensitive the camera and mic button */
2274 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2275 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2277 /* Be sure that the mic button is enabled */
2278 gtk_toggle_tool_button_set_active (
2279 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2281 if (priv->camera_state == CAMERA_STATE_ON)
2283 /* Restart the preview with the new pipeline. */
2284 display_video_preview (self, TRUE);
2287 /* destroy the video output; it will be recreated when we'll redial */
2288 disconnect_video_output_motion_handler (self);
2289 if (priv->video_output != NULL)
2290 clutter_actor_destroy (priv->video_output);
2291 priv->video_output = NULL;
2292 if (priv->got_video_src > 0)
2294 g_source_remove (priv->got_video_src);
2295 priv->got_video_src = 0;
2298 gtk_widget_show (priv->remote_user_avatar_widget);
2300 reset_details_pane (self);
2302 priv->sending_video = FALSE;
2303 priv->call_started = FALSE;
2305 could_disconnect = TRUE;
2307 /* TODO: display the self avatar of the preview (depends if the "Always
2308 * Show Video Preview" is enabled or not) */
2311 return could_disconnect;
2316 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2319 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2320 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2322 if (empathy_call_window_disconnected (self, TRUE) &&
2323 priv->call_state == REDIALING)
2324 empathy_call_window_restart_call (self);
2328 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2330 FsMediaType media_type,
2331 EmpathyCallWindow *self)
2333 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2335 DEBUG ("removing content");
2338 * This assumes that there is only one video stream per channel...
2341 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2343 if (priv->funnel != NULL)
2347 output = priv->video_output_sink;
2349 gst_element_set_state (output, GST_STATE_NULL);
2350 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2352 gst_bin_remove (GST_BIN (priv->pipeline), output);
2353 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2354 priv->funnel = NULL;
2358 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2360 if (priv->audio_output != NULL)
2362 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2364 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2365 priv->audio_output = NULL;
2373 /* Called with global lock held */
2375 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2377 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2381 if (priv->funnel == NULL)
2383 output = priv->video_output_sink;
2385 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2389 g_warning ("Could not create fsfunnel");
2393 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2395 gst_object_unref (priv->funnel);
2396 priv->funnel = NULL;
2397 g_warning ("Could not add funnel to pipeline");
2401 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2403 g_warning ("Could not add the video output widget to the pipeline");
2407 if (!gst_element_link (priv->funnel, output))
2409 g_warning ("Could not link output sink to funnel");
2410 goto error_output_added;
2413 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2415 g_warning ("Could not start video sink");
2416 goto error_output_added;
2419 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2421 g_warning ("Could not start funnel");
2422 goto error_output_added;
2426 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2429 g_warning ("Could not get request pad from funnel");
2436 gst_element_set_locked_state (priv->funnel, TRUE);
2437 gst_element_set_locked_state (output, TRUE);
2439 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2440 gst_element_set_state (output, GST_STATE_NULL);
2442 gst_bin_remove (GST_BIN (priv->pipeline), output);
2443 gst_element_set_locked_state (output, FALSE);
2447 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2448 priv->funnel = NULL;
2453 /* Called with global lock held */
2455 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2457 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2459 GstPadTemplate *template;
2461 if (priv->audio_output == NULL)
2463 priv->audio_output = empathy_audio_sink_new ();
2464 g_object_ref_sink (priv->audio_output);
2466 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2468 g_warning ("Could not add audio sink to pipeline");
2469 g_object_unref (priv->audio_output);
2470 goto error_add_output;
2473 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2475 g_warning ("Could not start audio sink");
2480 template = gst_element_class_get_pad_template (
2481 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2483 pad = gst_element_request_pad (priv->audio_output,
2484 template, NULL, NULL);
2488 g_warning ("Could not get sink pad from sink");
2495 gst_element_set_locked_state (priv->audio_output, TRUE);
2496 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2497 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2498 priv->audio_output = NULL;
2506 empathy_call_window_update_timer (gpointer user_data)
2508 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2509 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2510 const gchar *status;
2514 time_ = g_timer_elapsed (priv->timer, NULL);
2516 if (priv->call_state == HELD)
2517 status = _("On hold");
2518 else if (!gtk_toggle_tool_button_get_active (
2519 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2522 status = _("Duration");
2524 /* Translators: 'status - minutes:seconds' the caller has been connected */
2525 str = g_strdup_printf (_("%s — %d:%02dm"),
2527 (int) time_ / 60, (int) time_ % 60);
2528 empathy_call_window_status_message (self, str);
2536 display_error (EmpathyCallWindow *self,
2537 TpyCallChannel *call,
2541 const gchar *details)
2543 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2544 GtkWidget *info_bar;
2545 GtkWidget *content_area;
2552 /* Create info bar */
2553 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2556 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2558 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2560 /* hbox containing the image and the messages vbox */
2561 hbox = gtk_hbox_new (FALSE, 3);
2562 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2565 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2566 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2568 /* vbox containing the main message and the details expander */
2569 vbox = gtk_vbox_new (FALSE, 3);
2570 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2573 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2575 label = gtk_label_new (NULL);
2576 gtk_label_set_markup (GTK_LABEL (label), txt);
2577 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2578 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2581 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2584 if (details != NULL)
2586 GtkWidget *expander;
2588 expander = gtk_expander_new (_("Technical Details"));
2590 txt = g_strdup_printf ("<i>%s</i>", details);
2592 label = gtk_label_new (NULL);
2593 gtk_label_set_markup (GTK_LABEL (label), txt);
2594 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2595 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2598 gtk_container_add (GTK_CONTAINER (expander), label);
2599 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2602 g_signal_connect (info_bar, "response",
2603 G_CALLBACK (gtk_widget_destroy), NULL);
2605 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2606 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2607 gtk_widget_show_all (info_bar);
2611 media_stream_error_to_txt (EmpathyCallWindow *self,
2612 TpyCallChannel *call,
2614 TpMediaStreamError error)
2616 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2617 const gchar *cm = NULL;
2623 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2625 return g_strdup_printf (
2626 _("%s's software does not understand any of the audio formats "
2627 "supported by your computer"),
2628 empathy_contact_get_alias (priv->contact));
2630 return g_strdup_printf (
2631 _("%s's software does not understand any of the video formats "
2632 "supported by your computer"),
2633 empathy_contact_get_alias (priv->contact));
2635 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2636 return g_strdup_printf (
2637 _("Can't establish a connection to %s. "
2638 "One of you might be on a network that does not allow "
2639 "direct connections."),
2640 empathy_contact_get_alias (priv->contact));
2642 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2643 return g_strdup (_("There was a failure on the network"));
2645 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2647 return g_strdup (_("The audio formats necessary for this call "
2648 "are not installed on your computer"));
2650 return g_strdup (_("The video formats necessary for this call "
2651 "are not installed on your computer"));
2653 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2654 tp_connection_parse_object_path (
2655 tp_channel_borrow_connection (TP_CHANNEL (call)),
2658 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2659 "product=Telepathy&component=%s", cm);
2661 result = g_strdup_printf (
2662 _("Something unexpected happened in a Telepathy component. "
2663 "Please <a href=\"%s\">report this bug</a> and attach "
2664 "logs gathered from the 'Debug' window in the Help menu."), url);
2670 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2671 return g_strdup (_("There was a failure in the call engine"));
2673 case TP_MEDIA_STREAM_ERROR_EOS:
2674 return g_strdup (_("The end of the stream was reached"));
2676 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2683 empathy_call_window_stream_error (EmpathyCallWindow *self,
2684 TpyCallChannel *call,
2693 desc = media_stream_error_to_txt (self, call, audio, code);
2696 /* No description, use the error message. That's not great as it's not
2697 * localized but it's better than nothing. */
2698 display_error (self, call, icon, title, msg, NULL);
2702 display_error (self, call, icon, title, desc, msg);
2708 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2711 EmpathyCallWindow *self)
2713 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2714 "gnome-stock-mic", _("Can't establish audio stream"));
2718 empathy_call_window_video_stream_error (TpyCallChannel *call,
2721 EmpathyCallWindow *self)
2723 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2724 "camera-web", _("Can't establish video stream"));
2729 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2731 EmpathyCallWindow *self)
2733 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2734 TpyCallChannel *call;
2735 gboolean can_send_video;
2737 if (state != TPY_CALL_STATE_ACCEPTED)
2740 if (priv->call_state == CONNECTED)
2743 g_timer_start (priv->timer);
2744 priv->call_state = CONNECTED;
2746 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2748 can_send_video = priv->video_input != NULL &&
2749 empathy_contact_can_voip_video (priv->contact) &&
2750 empathy_camera_monitor_get_available (priv->camera_monitor);
2752 g_object_get (priv->handler, "call-channel", &call, NULL);
2754 if (tpy_call_channel_has_dtmf (call))
2755 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2757 if (priv->video_input == NULL)
2758 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2760 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2762 empathy_call_window_show_hangup_button (self, TRUE);
2764 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2766 clutter_actor_hide (priv->video_output);
2767 gtk_widget_show (priv->remote_user_avatar_widget);
2769 g_object_unref (call);
2771 g_mutex_lock (priv->lock);
2773 priv->timer_id = g_timeout_add_seconds (1,
2774 empathy_call_window_update_timer, self);
2776 g_mutex_unlock (priv->lock);
2778 empathy_call_window_update_timer (self);
2780 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2784 empathy_call_window_show_video_output_cb (gpointer user_data)
2786 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2788 if (self->priv->video_output != NULL)
2790 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2791 clutter_actor_show (self->priv->video_output);
2792 clutter_actor_raise_top (self->priv->floating_toolbar);
2799 empathy_call_window_check_video_cb (gpointer data)
2801 EmpathyCallWindow *self = data;
2803 if (self->priv->got_video)
2805 self->priv->got_video = FALSE;
2809 /* No video in the last N seconds, display the remote avatar */
2810 empathy_call_window_show_video_output (self, FALSE);
2815 /* Called from the streaming thread */
2817 empathy_call_window_video_probe_cb (GstPad *pad,
2818 GstMiniObject *mini_obj,
2819 EmpathyCallWindow *self)
2822 if (GST_IS_EVENT (mini_obj))
2825 if (G_UNLIKELY (!self->priv->got_video))
2827 /* show the remote video */
2828 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2829 empathy_call_window_show_video_output_cb,
2830 g_object_ref (self), g_object_unref);
2832 self->priv->got_video = TRUE;
2838 /* Called from the streaming thread */
2840 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2841 GstPad *src, guint media_type, gpointer user_data)
2843 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2844 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2845 gboolean retval = FALSE;
2849 g_mutex_lock (priv->lock);
2853 case TP_MEDIA_STREAM_TYPE_AUDIO:
2854 pad = empathy_call_window_get_audio_sink_pad (self);
2856 case TP_MEDIA_STREAM_TYPE_VIDEO:
2857 g_idle_add (empathy_call_window_show_video_output_cb, self);
2858 pad = empathy_call_window_get_video_sink_pad (self);
2860 gst_pad_add_data_probe (src,
2861 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2862 if (priv->got_video_src > 0)
2863 g_source_remove (priv->got_video_src);
2864 priv->got_video_src = g_timeout_add_seconds (5,
2865 empathy_call_window_check_video_cb, self);
2868 g_assert_not_reached ();
2874 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2875 g_warning ("Could not link %s sink pad",
2876 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2880 gst_object_unref (pad);
2884 /* If no sink could be linked, try to add fakesink to prevent the whole call
2889 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2891 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2893 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2894 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2895 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2897 gst_element_set_locked_state (fakesink, TRUE);
2898 gst_element_set_state (fakesink, GST_STATE_NULL);
2899 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2903 DEBUG ("Could not link real sink, linked fakesink instead");
2905 gst_object_unref (sinkpad);
2909 gst_object_unref (fakesink);
2914 g_mutex_unlock (priv->lock);
2920 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2921 GstPad *sink, FsMediaType media_type, gpointer user_data)
2923 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2924 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2926 gboolean retval = FALSE;
2930 case FS_MEDIA_TYPE_AUDIO:
2931 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2933 g_warning ("Could not add audio source to pipeline");
2937 pad = gst_element_get_static_pad (priv->audio_input, "src");
2940 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2941 g_warning ("Could not get source pad from audio source");
2945 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2947 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2948 g_warning ("Could not link audio source to farsight");
2952 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2954 g_warning ("Could not start audio source");
2955 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2956 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2962 case FS_MEDIA_TYPE_VIDEO:
2963 if (priv->video_tee != NULL)
2965 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2966 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2968 g_warning ("Could not link video source input pipeline");
2971 gst_object_unref (pad);
2977 g_assert_not_reached ();
2984 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2986 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2987 GstElement *preview;
2989 disable_camera (self);
2991 DEBUG ("remove video input");
2992 preview = priv->video_preview_sink;
2994 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2995 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2996 gst_element_set_state (preview, GST_STATE_NULL);
2998 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3001 g_object_unref (priv->video_input);
3002 priv->video_input = NULL;
3003 g_object_unref (priv->video_tee);
3004 priv->video_tee = NULL;
3005 clutter_actor_destroy (priv->video_preview);
3006 priv->video_preview = NULL;
3008 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3012 start_call (EmpathyCallWindow *self)
3014 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3016 priv->call_started = TRUE;
3017 empathy_call_handler_start_call (priv->handler,
3018 gtk_get_current_event_time ());
3020 if (empathy_call_handler_has_initial_video (priv->handler))
3022 TpyCallChannel *call;
3025 g_object_get (priv->handler, "call-channel", &call, NULL);
3026 s = tpy_call_channel_get_video_state (call);
3028 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3029 s == TPY_SENDING_STATE_SENDING)
3031 /* Enable 'send video' buttons and display the preview */
3032 gtk_toggle_tool_button_set_active (
3033 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3037 gtk_toggle_tool_button_set_active (
3038 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3040 if (priv->video_preview == NULL)
3042 create_video_preview (self);
3043 add_video_preview_to_pipeline (self);
3047 g_object_unref (call);
3052 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3055 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3056 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3059 empathy_call_handler_bus_message (priv->handler, bus, message);
3061 switch (GST_MESSAGE_TYPE (message))
3063 case GST_MESSAGE_STATE_CHANGED:
3064 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3066 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3068 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3069 !priv->call_started)
3071 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3072 if (newstate == GST_STATE_PAUSED)
3074 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3075 priv->pipeline_playing = TRUE;
3077 if (priv->start_call_when_playing)
3082 case GST_MESSAGE_ERROR:
3084 GError *error = NULL;
3085 GstElement *gst_error;
3088 gst_message_parse_error (message, &error, &debug);
3089 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3091 g_message ("Element error: %s -- %s\n", error->message, debug);
3093 if (g_str_has_prefix (gst_element_get_name (gst_error),
3094 VIDEO_INPUT_ERROR_PREFIX))
3096 /* Remove the video input and continue */
3097 if (priv->video_input != NULL)
3098 empathy_call_window_remove_video_input (self);
3099 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3103 empathy_call_window_disconnected (self, TRUE);
3105 g_error_free (error);
3108 case GST_MESSAGE_UNKNOWN:
3109 case GST_MESSAGE_EOS:
3110 case GST_MESSAGE_WARNING:
3111 case GST_MESSAGE_INFO:
3112 case GST_MESSAGE_TAG:
3113 case GST_MESSAGE_BUFFERING:
3114 case GST_MESSAGE_STATE_DIRTY:
3115 case GST_MESSAGE_STEP_DONE:
3116 case GST_MESSAGE_CLOCK_PROVIDE:
3117 case GST_MESSAGE_CLOCK_LOST:
3118 case GST_MESSAGE_NEW_CLOCK:
3119 case GST_MESSAGE_STRUCTURE_CHANGE:
3120 case GST_MESSAGE_STREAM_STATUS:
3121 case GST_MESSAGE_APPLICATION:
3122 case GST_MESSAGE_ELEMENT:
3123 case GST_MESSAGE_SEGMENT_START:
3124 case GST_MESSAGE_SEGMENT_DONE:
3125 case GST_MESSAGE_DURATION:
3126 case GST_MESSAGE_ANY:
3135 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3136 GHashTable *members,
3137 EmpathyCallWindow *self)
3139 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3140 GHashTableIter iter;
3141 gpointer key, value;
3142 gboolean held = FALSE;
3144 g_hash_table_iter_init (&iter, members);
3145 while (g_hash_table_iter_next (&iter, &key, &value))
3147 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3149 /* This assumes this is a 1-1 call, otherwise one participant
3150 * putting the call on hold wouldn't mean the call is on hold
3158 priv->call_state = HELD;
3159 else if (priv->call_state == HELD)
3160 priv->call_state = CONNECTED;
3164 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3166 EmpathyCallWindow *self)
3168 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3169 TpyCallChannel *call;
3171 g_object_get (priv->handler, "call-channel", &call, NULL);
3176 tp_g_signal_connect_object (call, "audio-stream-error",
3177 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3178 tp_g_signal_connect_object (call, "video-stream-error",
3179 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3182 tp_g_signal_connect_object (call, "members-changed",
3183 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3185 g_object_unref (call);
3189 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3191 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3192 TpyCallChannel *call;
3195 /* Make the hangup button twice as wide */
3196 width = gtk_widget_get_allocated_width (priv->hangup_button);
3197 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3199 g_signal_connect (priv->handler, "state-changed",
3200 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3201 g_signal_connect (priv->handler, "conference-added",
3202 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3203 g_signal_connect (priv->handler, "conference-removed",
3204 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3205 g_signal_connect (priv->handler, "closed",
3206 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3207 g_signal_connect (priv->handler, "src-pad-added",
3208 G_CALLBACK (empathy_call_window_src_added_cb), window);
3209 g_signal_connect (priv->handler, "sink-pad-added",
3210 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3211 g_signal_connect (priv->handler, "sink-pad-removed",
3212 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3214 g_object_get (priv->handler, "call-channel", &call, NULL);
3217 call_handler_notify_call_cb (priv->handler, NULL, window);
3218 g_object_unref (call);
3222 /* call-channel doesn't exist yet, we'll connect signals once it has been
3224 g_signal_connect (priv->handler, "notify::call-channel",
3225 G_CALLBACK (call_handler_notify_call_cb), window);
3228 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3232 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3233 EmpathyCallWindow *window)
3235 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3237 if (priv->pipeline != NULL)
3239 if (priv->bus_message_source_id != 0)
3241 g_source_remove (priv->bus_message_source_id);
3242 priv->bus_message_source_id = 0;
3245 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3248 if (priv->call_state == CONNECTING)
3249 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3255 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3258 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3260 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3265 gtk_widget_hide (priv->dtmf_panel);
3266 gtk_widget_hide (menu);
3267 gtk_widget_hide (priv->toolbar);
3271 if (priv->dialpad_was_visible_before_fs)
3272 gtk_widget_show (priv->dtmf_panel);
3274 gtk_widget_show (menu);
3275 gtk_widget_show (priv->toolbar);
3277 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3278 priv->original_height_before_fs);
3283 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3285 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3287 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3288 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3289 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3290 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3292 if (priv->video_output != NULL)
3295 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3296 priv->video_output, TRUE, TRUE,
3297 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3304 empathy_call_window_state_event_cb (GtkWidget *widget,
3305 GdkEventWindowState *event, EmpathyCallWindow *window)
3307 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3309 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3310 gboolean set_fullscreen = event->new_window_state &
3311 GDK_WINDOW_STATE_FULLSCREEN;
3315 gboolean dialpad_was_visible;
3316 GtkAllocation allocation;
3317 gint original_width, original_height;
3319 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3320 original_width = allocation.width;
3321 original_height = allocation.height;
3323 g_object_get (priv->dtmf_panel,
3324 "visible", &dialpad_was_visible,
3327 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3328 priv->original_width_before_fs = original_width;
3329 priv->original_height_before_fs = original_height;
3331 if (priv->video_output_motion_handler_id == 0 &&
3332 priv->video_output != NULL)
3334 priv->video_output_motion_handler_id = g_signal_connect (
3335 G_OBJECT (priv->video_container), "motion-notify-event",
3336 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3342 disconnect_video_output_motion_handler (window);
3345 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3347 show_controls (window, set_fullscreen);
3348 show_borders (window, set_fullscreen);
3349 gtk_action_set_stock_id (priv->menu_fullscreen,
3350 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3351 priv->is_fullscreen = set_fullscreen;
3358 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3361 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3362 int w, h, dialpad_width;
3363 GtkAllocation allocation;
3365 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3366 w = allocation.width;
3367 h = allocation.height;
3369 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3373 gtk_widget_show (priv->dtmf_panel);
3379 gtk_widget_hide (priv->dtmf_panel);
3383 gtk_window_resize (GTK_WINDOW (window), w, h);
3387 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3390 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3391 TpyCallChannel *call;
3393 priv->sending_video = (state == CAMERA_STATE_ON);
3395 if (state == CAMERA_STATE_ON)
3397 /* When we start sending video, we want to show the video preview by
3399 display_video_preview (window, TRUE);
3403 display_video_preview (window, FALSE);
3406 if (priv->call_state != CONNECTED)
3409 g_object_get (priv->handler, "call-channel", &call, NULL);
3410 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3411 tpy_call_channel_send_video (call, priv->sending_video);
3412 g_object_unref (call);
3416 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3417 EmpathyCallWindow *self)
3419 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3422 active = (gtk_toggle_tool_button_get_active (toggle));
3424 /* We don't want the settings callback to react to this change to avoid
3426 g_signal_handlers_block_by_func (priv->settings,
3427 empathy_call_window_prefs_volume_changed_cb, self);
3431 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3432 priv->volume * 100);
3436 /* TODO, Instead of setting the input volume to 0 we should probably
3437 * stop sending but this would cause the audio call to drop if both
3438 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3439 * in the future. GNOME #574574
3441 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3445 g_signal_handlers_unblock_by_func (priv->settings,
3446 empathy_call_window_prefs_volume_changed_cb, self);
3450 empathy_call_window_hangup_cb (gpointer object,
3451 EmpathyCallWindow *self)
3453 empathy_call_handler_stop_call (self->priv->handler);
3455 empathy_call_window_disconnected (self, TRUE);
3459 empathy_call_window_restart_call (EmpathyCallWindow *window)
3461 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3463 /* Remove error info bars */
3464 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3465 (GtkCallback) gtk_widget_destroy, NULL);
3467 create_video_output_widget (window);
3469 /* While the call was disconnected, the input volume might have changed.
3470 * However, since the audio_input source was destroyed, its volume has not
3471 * been updated during that time. That's why we manually update it here */
3472 empathy_call_window_mic_volume_changed (window);
3474 priv->outgoing = TRUE;
3475 empathy_call_window_set_state_connecting (window);
3477 if (priv->pipeline_playing)
3478 start_call (window);
3480 /* call will be started when the pipeline is ready */
3481 priv->start_call_when_playing = TRUE;
3483 empathy_call_window_setup_avatars (window, priv->handler);
3485 empathy_call_window_show_hangup_button (window, TRUE);
3489 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3490 EmpathyCallWindow *window)
3494 active = gtk_toggle_tool_button_get_active (button);
3496 empathy_call_window_show_dialpad (window, active);
3500 empathy_call_window_fullscreen_cb (gpointer object,
3501 EmpathyCallWindow *window)
3503 empathy_call_window_fullscreen_toggle (window);
3507 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3509 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3511 if (priv->is_fullscreen)
3512 gtk_window_unfullscreen (GTK_WINDOW (window));
3514 gtk_window_fullscreen (GTK_WINDOW (window));
3518 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3519 GdkEventButton *event, EmpathyCallWindow *window)
3521 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3523 empathy_call_window_video_menu_popup (window, event->button);
3531 empathy_call_window_key_press_cb (GtkWidget *video_output,
3532 GdkEventKey *event, EmpathyCallWindow *window)
3534 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3536 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3538 /* Since we are in fullscreen mode, toggling will bring us back to
3540 empathy_call_window_fullscreen_toggle (window);
3548 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3549 GdkEventMotion *event, EmpathyCallWindow *window)
3551 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3553 if (priv->is_fullscreen)
3555 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3557 /* Show the bottom toolbar */
3558 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3565 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3569 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3571 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3573 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3574 button, gtk_get_current_event_time ());
3575 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3579 empathy_call_window_status_message (EmpathyCallWindow *self,
3582 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3586 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3587 gdouble value, EmpathyCallWindow *window)
3589 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3591 if (priv->audio_output == NULL)
3594 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3599 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3601 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3603 return priv->ui_manager;
3606 EmpathyGstAudioSrc *
3607 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3609 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3611 return (EmpathyGstAudioSrc *) priv->audio_input;
3614 EmpathyGstVideoSrc *
3615 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3617 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);