2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-ui-utils.h>
50 #include <libempathy-gtk/empathy-sound-manager.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-images.h>
54 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
55 #include <libempathy/empathy-debug.h>
57 #include "empathy-call-window.h"
58 #include "empathy-call-window-fullscreen.h"
59 #include "empathy-call-factory.h"
60 #include "empathy-video-widget.h"
61 #include "empathy-about-dialog.h"
62 #include "empathy-audio-src.h"
63 #include "empathy-audio-sink.h"
64 #include "empathy-video-src.h"
65 #include "empathy-mic-menu.h"
66 #include "empathy-preferences.h"
67 #include "empathy-rounded-actor.h"
69 #define CONTENT_HBOX_BORDER_WIDTH 6
70 #define CONTENT_HBOX_SPACING 3
71 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
73 #define SELF_VIDEO_SECTION_WIDTH 120
74 #define SELF_VIDEO_SECTION_HEIGTH 90
75 #define SELF_VIDEO_SECTION_MARGIN 10
77 #define FLOATING_TOOLBAR_OPACITY 192
78 #define FLOATING_TOOLBAR_WIDTH 280
79 #define FLOATING_TOOLBAR_HEIGHT 36
80 #define FLOATING_TOOLBAR_SPACING 20
82 #define SELF_VIDEO_MARGIN 10
84 /* The avatar's default width and height are set to the same value because we
85 want a square icon. */
86 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
88 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
90 #define SMALL_TOOLBAR_SIZE 36
92 /* If an video input error occurs, the error message will start with "v4l" */
93 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
95 /* The time interval in milliseconds between 2 outgoing rings */
96 #define MS_BETWEEN_RING 500
98 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
101 PROP_CALL_HANDLER = 1,
113 CAMERA_STATE_OFF = 0,
119 PREVIEW_POS_TOP_LEFT,
120 PREVIEW_POS_TOP_RIGHT,
121 PREVIEW_POS_BOTTOM_LEFT,
122 PREVIEW_POS_BOTTOM_RIGHT,
125 struct _EmpathyCallWindowPriv
127 gboolean dispose_has_run;
128 EmpathyCallHandler *handler;
130 EmpathyContact *contact;
132 EmpathyCameraMonitor *camera_monitor;
137 GtkUIManager *ui_manager;
138 GtkWidget *errors_vbox;
139 /* widget displays the video received from the remote user. This widget is
140 * alive only during call. */
141 ClutterActor *video_output;
142 ClutterActor *video_preview;
143 ClutterActor *preview_hidden_button;
144 ClutterActor *preview_rectangle1;
145 ClutterActor *preview_rectangle2;
146 ClutterActor *preview_rectangle3;
147 ClutterActor *preview_rectangle4;
148 GtkWidget *video_container;
149 GtkWidget *remote_user_avatar_widget;
150 GtkWidget *remote_user_avatar_toolbar;
151 GtkWidget *remote_user_name_toolbar;
152 GtkWidget *status_label;
153 GtkWidget *hangup_button;
154 GtkWidget *audio_call_button;
155 GtkWidget *video_call_button;
156 GtkWidget *mic_button;
157 GtkWidget *camera_button;
158 GtkWidget *dialpad_button;
160 GtkWidget *bottom_toolbar;
161 ClutterActor *floating_toolbar;
163 GtkAction *menu_fullscreen;
165 ClutterState *transitions;
167 /* The box that contains self and remote avatar and video
168 input/output. When we redial, we destroy and re-create the box */
169 ClutterActor *video_box;
170 ClutterLayoutManager *video_layout;
172 /* Coordinates of the preview drag event's start. */
176 /* We keep a reference on the hbox which contains the main content so we can
177 easilly repack everything when toggling fullscreen */
178 GtkWidget *content_hbox;
180 gulong video_output_motion_handler_id;
181 guint bus_message_source_id;
185 GtkWidget *dtmf_panel;
188 GtkWidget *details_vbox;
189 GtkWidget *vcodec_encoding_label;
190 GtkWidget *acodec_encoding_label;
191 GtkWidget *vcodec_decoding_label;
192 GtkWidget *acodec_decoding_label;
194 GtkWidget *audio_remote_candidate_label;
195 GtkWidget *audio_local_candidate_label;
196 GtkWidget *video_remote_candidate_label;
197 GtkWidget *video_local_candidate_label;
198 GtkWidget *video_remote_candidate_info_img;
199 GtkWidget *video_local_candidate_info_img;
200 GtkWidget *audio_remote_candidate_info_img;
201 GtkWidget *audio_local_candidate_info_img;
203 GstElement *video_input;
204 GstElement *video_preview_sink;
205 GstElement *video_output_sink;
206 GstElement *audio_input;
207 GstElement *audio_output;
208 GstElement *pipeline;
209 GstElement *video_tee;
219 gboolean call_started;
220 gboolean sending_video;
221 CameraState camera_state;
223 EmpathyCallWindowFullscreen *fullscreen;
224 gboolean is_fullscreen;
229 guint inactivity_src;
231 /* Those fields represent the state of the window before it actually was in
233 gboolean dialpad_was_visible_before_fs;
234 gint original_width_before_fs;
235 gint original_height_before_fs;
237 gint x, y, w, h, dialpad_width;
240 /* TRUE if the call should be started when the pipeline is playing */
241 gboolean start_call_when_playing;
242 /* TRUE if we requested to set the pipeline in the playing state */
243 gboolean pipeline_playing;
245 EmpathySoundManager *sound_mgr;
248 EmpathyMicMenu *mic_menu;
251 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
253 static void empathy_call_window_realized_cb (GtkWidget *widget,
254 EmpathyCallWindow *window);
256 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
257 GdkEvent *event, EmpathyCallWindow *window);
259 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
260 GdkEventWindowState *event, EmpathyCallWindow *window);
262 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
265 static void empathy_call_window_mic_toggled_cb (
266 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
268 static void empathy_call_window_hangup_cb (gpointer object,
269 EmpathyCallWindow *window);
271 static void empathy_call_window_fullscreen_cb (gpointer object,
272 EmpathyCallWindow *window);
274 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
276 static gboolean empathy_call_window_video_button_press_cb (
277 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
279 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
280 GdkEventKey *event, EmpathyCallWindow *window);
282 static gboolean empathy_call_window_video_output_motion_notify (
283 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
285 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
288 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
289 EmpathyCallWindow *window);
291 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
293 static void empathy_call_window_status_message (EmpathyCallWindow *window,
296 static gboolean empathy_call_window_bus_message (GstBus *bus,
297 GstMessage *message, gpointer user_data);
300 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
301 gdouble value, EmpathyCallWindow *window);
304 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
307 gtk_widget_set_visible (self->priv->hangup_button, show);
308 gtk_widget_set_visible (self->priv->audio_call_button, !show);
309 gtk_widget_set_visible (self->priv->video_call_button, !show);
313 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
314 EmpathyCallWindow *self)
316 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
317 empathy_call_window_restart_call (self);
321 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
322 EmpathyCallWindow *self)
324 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
325 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
326 empathy_call_window_restart_call (self);
330 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
332 EmpathyCallWindowPriv *priv = GET_PRIV (window);
333 TpyCallChannel *call;
337 g_object_get (priv->handler, "call-channel", &call, NULL);
339 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
340 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
343 tpy_call_channel_dtmf_start_tone (call, event);
345 g_object_unref (call);
349 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
351 EmpathyCallWindowPriv *priv = GET_PRIV (window);
352 TpyCallChannel *call;
354 g_object_get (priv->handler, "call-channel", &call, NULL);
356 tpy_call_channel_dtmf_stop_tone (call);
358 g_object_unref (call);
362 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
364 EmpathyCallWindowPriv *priv = GET_PRIV (self);
367 volume = g_settings_get_double (priv->settings,
368 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
370 /* Don't store the volume because of muting */
371 if (volume > 0 || gtk_toggle_tool_button_get_active (
372 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
373 priv->volume = volume;
375 /* Ensure that the toggle button is active if the volume is > 0 and inactive
376 * if it's smaller than 0 */
377 if ((volume > 0) != gtk_toggle_tool_button_get_active (
378 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
379 gtk_toggle_tool_button_set_active (
380 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
382 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
387 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
389 EmpathyCallWindow *self)
391 empathy_call_window_mic_volume_changed (self);
395 empathy_call_window_show_video_output (EmpathyCallWindow *self,
398 if (self->priv->video_output != NULL)
399 g_object_set (self->priv->video_output, "visible", show, NULL);
401 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
403 clutter_actor_raise_top (self->priv->floating_toolbar);
407 create_video_output_widget (EmpathyCallWindow *self)
409 EmpathyCallWindowPriv *priv = GET_PRIV (self);
411 g_assert (priv->video_output == NULL);
412 g_assert (priv->pipeline != NULL);
414 priv->video_output = clutter_texture_new ();
416 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
419 priv->video_output_sink = clutter_gst_video_sink_new (
420 CLUTTER_TEXTURE (priv->video_output));
422 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
425 gtk_widget_add_events (priv->video_container,
426 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
427 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
428 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
432 create_video_input (EmpathyCallWindow *self)
434 EmpathyCallWindowPriv *priv = GET_PRIV (self);
436 g_assert (priv->video_input == NULL);
437 priv->video_input = empathy_video_src_new ();
438 gst_object_ref (priv->video_input);
439 gst_object_sink (priv->video_input);
443 create_audio_input (EmpathyCallWindow *self)
445 EmpathyCallWindowPriv *priv = GET_PRIV (self);
447 g_assert (priv->audio_input == NULL);
448 priv->audio_input = empathy_audio_src_new ();
449 gst_object_ref (priv->audio_input);
450 gst_object_sink (priv->audio_input);
454 add_video_preview_to_pipeline (EmpathyCallWindow *self)
456 EmpathyCallWindowPriv *priv = GET_PRIV (self);
459 g_assert (priv->video_preview != NULL);
460 g_assert (priv->pipeline != NULL);
461 g_assert (priv->video_input != NULL);
462 g_assert (priv->video_tee != NULL);
464 preview = priv->video_preview_sink;
466 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
468 g_warning ("Could not add video input to pipeline");
472 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
474 g_warning ("Could not add video preview to pipeline");
478 if (!gst_element_link (priv->video_input, priv->video_tee))
480 g_warning ("Could not link video input to video tee");
484 if (!gst_element_link (priv->video_tee, preview))
486 g_warning ("Could not link video tee to video preview");
492 empathy_call_window_disable_camera_cb (GtkAction *action,
493 EmpathyCallWindow *self)
495 clutter_actor_destroy (self->priv->preview_hidden_button);
497 gtk_toggle_tool_button_set_active (
498 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
502 empathy_call_window_minimise_camera_cb (GtkAction *action,
503 EmpathyCallWindow *self)
505 clutter_actor_hide (self->priv->video_preview);
506 clutter_actor_show (self->priv->preview_hidden_button);
510 empathy_call_window_maximise_camera_cb (GtkAction *action,
511 EmpathyCallWindow *self)
513 clutter_actor_show (self->priv->video_preview);
514 clutter_actor_hide (self->priv->preview_hidden_button);
518 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
519 EmpathyCallWindow *self)
523 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
525 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
526 0, gtk_get_current_event_time ());
527 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
531 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
532 EmpathyCallWindow *self)
536 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
537 "/preview-hidden-menu");
538 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
539 0, gtk_get_current_event_time ());
540 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
543 static ClutterActor *
544 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
545 ClutterBinAlignment x,
546 ClutterBinAlignment y)
548 ClutterLayoutManager *layout;
549 ClutterActor *rectangle;
552 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
553 CLUTTER_BIN_ALIGNMENT_CENTER);
555 box = clutter_box_new (layout);
557 rectangle = clutter_rectangle_new_with_color (
558 CLUTTER_COLOR_Transparent);
560 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
563 clutter_actor_set_size (box,
564 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_MARGIN,
565 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_MARGIN);
567 clutter_actor_set_size (rectangle,
568 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
570 clutter_container_add_actor (CLUTTER_CONTAINER (box), rectangle);
572 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
575 clutter_actor_hide (rectangle);
581 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
583 self->priv->preview_rectangle1 =
584 empathy_call_window_create_preview_rectangle (self,
585 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
586 self->priv->preview_rectangle2 =
587 empathy_call_window_create_preview_rectangle (self,
588 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
589 self->priv->preview_rectangle3 =
590 empathy_call_window_create_preview_rectangle (self,
591 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
592 self->priv->preview_rectangle4 =
593 empathy_call_window_create_preview_rectangle (self,
594 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
598 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
601 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
602 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
603 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
604 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
607 static PreviewPosition
608 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
613 PreviewPosition pos = PREVIEW_POS_NONE;
615 clutter_actor_get_geometry (self->priv->video_box, &box);
617 if (0 + SELF_VIDEO_MARGIN <= event_x &&
618 event_x <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
619 0 + SELF_VIDEO_MARGIN <= event_y &&
620 event_y <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
622 pos = PREVIEW_POS_TOP_LEFT;
624 else if (box.width - SELF_VIDEO_MARGIN >= event_x &&
625 event_x >= (box.width - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
626 0 + SELF_VIDEO_MARGIN <= event_y &&
627 event_y <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
629 pos = PREVIEW_POS_TOP_RIGHT;
631 else if (0 + SELF_VIDEO_MARGIN <= event_x &&
632 event_x <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
633 box.height - SELF_VIDEO_MARGIN >= event_y &&
634 event_y >= (box.height - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGTH))
636 pos = PREVIEW_POS_BOTTOM_LEFT;
638 else if (box.width - SELF_VIDEO_MARGIN >= event_x &&
639 event_x >= (box.width - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
640 box.height - SELF_VIDEO_MARGIN >= event_y &&
641 event_y >= (box.height - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGTH))
643 pos = PREVIEW_POS_BOTTOM_RIGHT;
649 static ClutterActor *
650 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
653 ClutterActor *rectangle;
657 case PREVIEW_POS_TOP_LEFT:
658 rectangle = self->priv->preview_rectangle1;
660 case PREVIEW_POS_TOP_RIGHT:
661 rectangle = self->priv->preview_rectangle3;
663 case PREVIEW_POS_BOTTOM_LEFT:
664 rectangle = self->priv->preview_rectangle2;
666 case PREVIEW_POS_BOTTOM_RIGHT:
667 rectangle = self->priv->preview_rectangle4;
677 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
680 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
682 DEBUG ("moving the video preview to %d", pos);
686 case PREVIEW_POS_TOP_LEFT:
687 clutter_bin_layout_set_alignment (layout,
688 self->priv->video_preview,
689 CLUTTER_BIN_ALIGNMENT_START,
690 CLUTTER_BIN_ALIGNMENT_START);
692 case PREVIEW_POS_TOP_RIGHT:
693 clutter_bin_layout_set_alignment (layout,
694 self->priv->video_preview,
695 CLUTTER_BIN_ALIGNMENT_END,
696 CLUTTER_BIN_ALIGNMENT_START);
698 case PREVIEW_POS_BOTTOM_LEFT:
699 clutter_bin_layout_set_alignment (layout,
700 self->priv->video_preview,
701 CLUTTER_BIN_ALIGNMENT_START,
702 CLUTTER_BIN_ALIGNMENT_END);
704 case PREVIEW_POS_BOTTOM_RIGHT:
705 clutter_bin_layout_set_alignment (layout,
706 self->priv->video_preview,
707 CLUTTER_BIN_ALIGNMENT_END,
708 CLUTTER_BIN_ALIGNMENT_END);
711 g_warn_if_reached ();
716 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
719 ClutterActor *rectangle;
721 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
723 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
724 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
729 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
730 ClutterActor *rectangle)
732 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
733 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
734 CLUTTER_COLOR_Black);
738 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
740 empathy_call_window_darken_preview_rectangle (self,
741 self->priv->preview_rectangle1);
743 empathy_call_window_darken_preview_rectangle (self,
744 self->priv->preview_rectangle2);
746 empathy_call_window_darken_preview_rectangle (self,
747 self->priv->preview_rectangle3);
749 empathy_call_window_darken_preview_rectangle (self,
750 self->priv->preview_rectangle4);
754 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
758 ClutterModifierType modifiers,
759 EmpathyCallWindow *self)
761 empathy_call_window_show_preview_rectangles (self, TRUE);
763 self->priv->event_x = event_x;
764 self->priv->event_y = event_y;
768 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
772 ClutterModifierType modifiers,
773 EmpathyCallWindow *self)
777 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
779 if (pos != PREVIEW_POS_NONE)
780 empathy_call_window_move_video_preview (self, pos);
782 empathy_call_window_show_preview_rectangles (self, FALSE);
786 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
790 EmpathyCallWindow *self)
794 pos = empathy_call_window_get_preview_position (self,
795 self->priv->event_x - delta_x, self->priv->event_y + delta_y);
797 if (pos != PREVIEW_POS_NONE)
798 empathy_call_window_highlight_preview_rectangle (self, pos);
800 empathy_call_window_darken_preview_rectangles (self);
804 create_video_preview (EmpathyCallWindow *self)
806 EmpathyCallWindowPriv *priv = GET_PRIV (self);
807 ClutterLayoutManager *layout, *layout_center;
808 ClutterActor *preview;
811 ClutterAction *action;
814 g_assert (priv->video_preview == NULL);
816 preview = clutter_texture_new ();
817 clutter_actor_set_size (preview,
818 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
819 priv->video_preview_sink = clutter_gst_video_sink_new (
820 CLUTTER_TEXTURE (preview));
822 /* Flip the video preview */
823 clutter_actor_set_rotation (preview,
826 SELF_VIDEO_SECTION_WIDTH * 0.5,
830 /* Add a little offset to the video preview */
831 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
832 CLUTTER_BIN_ALIGNMENT_CENTER);
833 priv->video_preview = clutter_box_new (layout);
834 clutter_actor_set_size (priv->video_preview,
835 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
836 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
837 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
839 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
840 CLUTTER_BIN_ALIGNMENT_CENTER);
841 box = clutter_box_new (layout_center);
842 clutter_actor_set_size (box,
843 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
845 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
846 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
848 g_object_set (priv->video_preview_sink,
853 /* Translators: this is an "Info" label. It should be as short
855 button = gtk_button_new_with_label (_("i"));
856 b = gtk_clutter_actor_new_with_contents (button);
858 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
860 CLUTTER_BIN_ALIGNMENT_END,
861 CLUTTER_BIN_ALIGNMENT_END);
863 g_signal_connect (button, "clicked",
864 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
867 /* Translators: this is an "Info" label. It should be as short
869 button = gtk_button_new_with_label (_("i"));
870 priv->preview_hidden_button =
871 gtk_clutter_actor_new_with_contents (button);
873 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
874 priv->preview_hidden_button,
875 CLUTTER_BIN_ALIGNMENT_START,
876 CLUTTER_BIN_ALIGNMENT_END);
878 clutter_actor_hide (priv->preview_hidden_button);
880 g_signal_connect (button, "clicked",
881 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
884 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
886 CLUTTER_BIN_ALIGNMENT_START,
887 CLUTTER_BIN_ALIGNMENT_END);
889 action = clutter_drag_action_new ();
890 g_signal_connect (action, "drag-begin",
891 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
892 g_signal_connect (action, "drag-end",
893 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
894 g_signal_connect (action, "drag-motion",
895 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
897 clutter_actor_add_action (preview, action);
898 clutter_actor_set_reactive (preview, TRUE);
902 play_camera (EmpathyCallWindow *window,
905 EmpathyCallWindowPriv *priv = GET_PRIV (window);
909 if (priv->video_preview == NULL)
911 create_video_preview (window);
912 add_video_preview_to_pipeline (window);
916 state = GST_STATE_PLAYING;
918 state = GST_STATE_NULL;
920 preview = priv->video_preview_sink;
922 gst_element_set_state (preview, state);
923 gst_element_set_state (priv->video_input, state);
924 gst_element_set_state (priv->video_tee, state);
928 display_video_preview (EmpathyCallWindow *self,
931 EmpathyCallWindowPriv *priv = GET_PRIV (self);
935 /* Display the video preview */
936 DEBUG ("Show video preview");
938 play_camera (self, TRUE);
939 clutter_actor_show (priv->video_preview);
940 clutter_actor_raise_top (priv->floating_toolbar);
944 /* Hide the video preview */
945 DEBUG ("Hide video preview");
947 if (priv->video_preview != NULL)
949 clutter_actor_hide (priv->video_preview);
950 play_camera (self, FALSE);
956 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
958 EmpathyCallWindowPriv *priv = GET_PRIV (window);
960 empathy_call_window_status_message (window, _("Connecting…"));
961 priv->call_state = CONNECTING;
964 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
965 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
969 disable_camera (EmpathyCallWindow *self)
971 EmpathyCallWindowPriv *priv = GET_PRIV (self);
973 if (priv->camera_state == CAMERA_STATE_OFF)
976 DEBUG ("Disable camera");
978 display_video_preview (self, FALSE);
980 if (priv->camera_state == CAMERA_STATE_ON)
981 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
983 priv->camera_state = CAMERA_STATE_OFF;
987 enable_camera (EmpathyCallWindow *self)
989 EmpathyCallWindowPriv *priv = GET_PRIV (self);
991 if (priv->camera_state == CAMERA_STATE_ON)
994 if (priv->video_input == NULL)
996 DEBUG ("Can't enable camera, no input");
1000 DEBUG ("Enable camera");
1002 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1004 priv->camera_state = CAMERA_STATE_ON;
1008 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1009 EmpathyCallWindow *self)
1011 if (gtk_toggle_tool_button_get_active (toggle))
1012 enable_camera (self);
1014 disable_camera (self);
1018 create_pipeline (EmpathyCallWindow *self)
1020 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1023 g_assert (priv->pipeline == NULL);
1025 priv->pipeline = gst_pipeline_new (NULL);
1026 priv->pipeline_playing = FALSE;
1028 priv->video_tee = gst_element_factory_make ("tee", NULL);
1029 gst_object_ref (priv->video_tee);
1030 gst_object_sink (priv->video_tee);
1032 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1034 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1035 priv->bus_message_source_id = gst_bus_add_watch (bus,
1036 empathy_call_window_bus_message, self);
1038 g_object_unref (bus);
1042 empathy_call_window_settings_cb (GtkAction *action,
1043 EmpathyCallWindow *self)
1045 gchar *args = g_strdup_printf ("-p %s",
1046 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1048 empathy_launch_program (BIN_DIR, "empathy", args);
1054 empathy_call_window_contents_cb (GtkAction *action,
1055 EmpathyCallWindow *self)
1057 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1061 empathy_call_window_debug_cb (GtkAction *action,
1062 EmpathyCallWindow *self)
1064 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1068 empathy_call_window_about_cb (GtkAction *action,
1069 EmpathyCallWindow *self)
1071 empathy_about_dialog_new (GTK_WINDOW (self));
1075 empathy_call_window_toolbar_timeout (gpointer data)
1077 EmpathyCallWindow *self = data;
1079 clutter_state_set_state (self->priv->transitions, "fade-out");
1085 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1087 EmpathyCallWindow *self)
1089 clutter_state_set_state (self->priv->transitions, "fade-in");
1091 if (self->priv->inactivity_src > 0)
1092 g_source_remove (self->priv->inactivity_src);
1094 self->priv->inactivity_src = g_timeout_add_seconds (3,
1095 empathy_call_window_toolbar_timeout, self);
1101 empathy_call_window_configure_event_cb (GtkWidget *widget,
1103 EmpathyCallWindow *self)
1105 GdkWindow *gdk_window;
1106 GdkWindowState window_state;
1108 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1109 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1111 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1112 &self->priv->dialpad_width, NULL);
1114 gdk_window = gtk_widget_get_window (widget);
1115 window_state = gdk_window_get_state (gdk_window);
1116 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1122 empathy_call_window_destroyed_cb (GtkWidget *object,
1123 EmpathyCallWindow *self)
1125 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1127 /* Save the geometry as if the dialpad was hidden. */
1128 empathy_geometry_save_values (GTK_WINDOW (self),
1129 self->priv->x, self->priv->y,
1130 self->priv->w - self->priv->dialpad_width, self->priv->h,
1131 self->priv->maximized);
1136 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1138 ClutterBindConstraint *constraint)
1140 ClutterActorBox allocation;
1142 clutter_actor_get_allocation_box (stage, &allocation);
1144 clutter_bind_constraint_set_offset (constraint,
1145 allocation.y2 - allocation.y1 -
1146 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1150 empathy_call_window_init (EmpathyCallWindow *self)
1152 EmpathyCallWindowPriv *priv;
1154 GtkWidget *top_vbox;
1156 ClutterConstraint *constraint;
1157 ClutterActor *remote_avatar;
1158 GtkStyleContext *context;
1162 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1163 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1165 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1166 gui = empathy_builder_get_file (filename,
1167 "call_window_vbox", &top_vbox,
1168 "errors_vbox", &priv->errors_vbox,
1169 "pane", &priv->pane,
1170 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1171 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1172 "status_label", &priv->status_label,
1173 "audiocall", &priv->audio_call_button,
1174 "videocall", &priv->video_call_button,
1175 "microphone", &priv->mic_button,
1176 "camera", &priv->camera_button,
1177 "hangup", &priv->hangup_button,
1178 "dialpad", &priv->dialpad_button,
1179 "toolbar", &priv->toolbar,
1180 "bottom_toolbar", &priv->bottom_toolbar,
1181 "ui_manager", &priv->ui_manager,
1182 "menufullscreen", &priv->menu_fullscreen,
1183 "details_vbox", &priv->details_vbox,
1184 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1185 "acodec_encoding_label", &priv->acodec_encoding_label,
1186 "acodec_decoding_label", &priv->acodec_decoding_label,
1187 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1188 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1189 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1190 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1191 "video_local_candidate_label", &priv->video_local_candidate_label,
1192 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1193 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1194 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1195 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1199 empathy_builder_connect (gui, self,
1200 "hangup", "clicked", empathy_call_window_hangup_cb,
1201 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1202 "videocall", "clicked", empathy_call_window_video_call_cb,
1203 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1204 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1205 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1206 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1207 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1208 "menusettings", "activate", empathy_call_window_settings_cb,
1209 "menucontents", "activate", empathy_call_window_contents_cb,
1210 "menudebug", "activate", empathy_call_window_debug_cb,
1211 "menuabout", "activate", empathy_call_window_about_cb,
1212 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1213 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1214 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1217 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1219 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1221 g_object_bind_property (priv->camera_monitor, "available",
1222 priv->camera_button, "sensitive",
1223 G_BINDING_SYNC_CREATE);
1225 priv->lock = g_mutex_new ();
1227 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1229 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1230 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1231 CONTENT_HBOX_BORDER_WIDTH);
1232 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1235 /* avatar/video box */
1236 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1237 CLUTTER_BIN_ALIGNMENT_CENTER);
1239 priv->video_box = clutter_box_new (priv->video_layout);
1241 empathy_call_window_create_preview_rectangles (self);
1243 priv->video_container = gtk_clutter_embed_new ();
1245 /* Set the background color to that of the rest of the window */
1246 context = gtk_widget_get_style_context (priv->content_hbox);
1247 gtk_style_context_get_background_color (context,
1248 GTK_STATE_FLAG_NORMAL, &rgba);
1249 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1250 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1251 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1252 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1253 clutter_stage_set_color (
1254 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1255 GTK_CLUTTER_EMBED (priv->video_container))),
1258 clutter_container_add (
1259 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1260 GTK_CLUTTER_EMBED (priv->video_container))),
1264 constraint = clutter_bind_constraint_new (
1265 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1266 CLUTTER_BIND_SIZE, 0);
1267 clutter_actor_add_constraint (priv->video_box, constraint);
1269 priv->remote_user_avatar_widget = gtk_image_new ();
1270 remote_avatar = gtk_clutter_actor_new_with_contents (
1271 priv->remote_user_avatar_widget);
1273 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1276 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1277 priv->video_container, TRUE, TRUE,
1278 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1280 create_pipeline (self);
1281 create_video_output_widget (self);
1282 create_audio_input (self);
1283 create_video_input (self);
1285 priv->floating_toolbar = empathy_rounded_actor_new ();
1287 gtk_widget_reparent (priv->bottom_toolbar,
1288 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1290 constraint = clutter_bind_constraint_new (
1291 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1294 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1297 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1298 "notify::allocation",
1299 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1302 clutter_actor_set_size (priv->floating_toolbar,
1303 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1304 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1306 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1307 priv->floating_toolbar,
1308 CLUTTER_BIN_ALIGNMENT_CENTER,
1309 CLUTTER_BIN_ALIGNMENT_END);
1311 clutter_actor_raise_top (priv->floating_toolbar);
1313 /* Transitions for the floating toolbar */
1314 priv->transitions = clutter_state_new ();
1316 /* all transitions last for 2s */
1317 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1319 /* transition from any state to "fade-out" state */
1320 clutter_state_set (priv->transitions, NULL, "fade-out",
1321 priv->floating_toolbar,
1322 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1325 /* transition from any state to "fade-in" state */
1326 clutter_state_set (priv->transitions, NULL, "fade-in",
1327 priv->floating_toolbar,
1328 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1331 /* put the actor into the "fade-in" state with no animation */
1332 clutter_state_warp_to_state (priv->transitions, "fade-in");
1334 /* The call will be started as soon the pipeline is playing */
1335 priv->start_call_when_playing = TRUE;
1337 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1338 G_CALLBACK (dtmf_button_pressed_cb),
1339 G_CALLBACK (dtmf_button_released_cb));
1341 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1344 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1347 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1349 gtk_widget_show_all (top_vbox);
1351 gtk_widget_hide (priv->dtmf_panel);
1352 gtk_widget_hide (priv->details_vbox);
1354 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1356 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1357 priv->video_container);
1359 /* We hide the bottom toolbar after 3s of inactivity and show it
1360 * again on mouse movement */
1361 priv->inactivity_src = g_timeout_add_seconds (3,
1362 empathy_call_window_toolbar_timeout, self);
1364 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1365 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1367 g_signal_connect (G_OBJECT (self), "realize",
1368 G_CALLBACK (empathy_call_window_realized_cb), self);
1370 g_signal_connect (G_OBJECT (self), "delete-event",
1371 G_CALLBACK (empathy_call_window_delete_cb), self);
1373 g_signal_connect (G_OBJECT (self), "window-state-event",
1374 G_CALLBACK (empathy_call_window_state_event_cb), self);
1376 g_signal_connect (G_OBJECT (self), "key-press-event",
1377 G_CALLBACK (empathy_call_window_key_press_cb), self);
1379 g_signal_connect (self, "motion-notify-event",
1380 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1382 priv->timer = g_timer_new ();
1384 g_object_ref (priv->ui_manager);
1385 g_object_unref (gui);
1387 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1388 priv->mic_menu = empathy_mic_menu_new (self);
1390 empathy_call_window_show_hangup_button (self, TRUE);
1392 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1394 /* Retrieve initial volume */
1395 priv->volume = g_settings_get_double (priv->settings,
1396 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1398 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1399 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1401 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1402 /* These signals are used to track the window position and save it
1403 * when the window is destroyed. We need to do this as we don't want
1404 * the window geometry to be saved with the dialpad taken into account. */
1405 g_signal_connect (self, "destroy",
1406 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1407 g_signal_connect (self, "configure-event",
1408 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1409 g_signal_connect (self, "window-state-event",
1410 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1412 /* Don't display labels in both toolbars */
1413 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1416 /* Instead of specifying a width and a height, we specify only one size. That's
1417 because we want a square avatar icon. */
1419 init_contact_avatar_with_size (EmpathyContact *contact,
1420 GtkWidget *image_widget,
1423 GdkPixbuf *pixbuf_avatar = NULL;
1425 if (contact != NULL)
1427 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1431 if (pixbuf_avatar == NULL)
1433 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1434 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1437 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1439 if (pixbuf_avatar != NULL)
1440 g_object_unref (pixbuf_avatar);
1444 set_window_title (EmpathyCallWindow *self)
1446 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1449 if (priv->contact != NULL)
1451 /* translators: Call is a noun and %s is the contact name. This string
1452 * is used in the window title */
1453 tmp = g_strdup_printf (_("Call with %s"),
1454 empathy_contact_get_alias (priv->contact));
1455 gtk_window_set_title (GTK_WINDOW (self), tmp);
1460 g_warning ("Unknown remote contact!");
1465 set_remote_user_name (EmpathyCallWindow *self,
1466 EmpathyContact *contact)
1468 const gchar *alias = empathy_contact_get_alias (contact);
1469 const gchar *status = empathy_contact_get_status (contact);
1472 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1473 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1479 contact_name_changed_cb (EmpathyContact *contact,
1481 EmpathyCallWindow *self)
1483 set_window_title (self);
1484 set_remote_user_name (self, contact);
1488 contact_presence_changed_cb (EmpathyContact *contact,
1490 EmpathyCallWindow *self)
1492 set_remote_user_name (self, contact);
1496 contact_avatar_changed_cb (EmpathyContact *contact,
1498 EmpathyCallWindow *self)
1501 GtkAllocation allocation;
1502 GtkWidget *avatar_widget;
1504 avatar_widget = self->priv->remote_user_avatar_widget;
1506 gtk_widget_get_allocation (avatar_widget, &allocation);
1507 size = allocation.height;
1511 /* the widget is not allocated yet, set a default size */
1512 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1513 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1516 init_contact_avatar_with_size (contact, avatar_widget, size);
1518 avatar_widget = self->priv->remote_user_avatar_toolbar;
1520 gtk_widget_get_allocation (avatar_widget, &allocation);
1521 size = allocation.height;
1525 /* the widget is not allocated yet, set a default size */
1526 size = SMALL_TOOLBAR_SIZE;
1529 init_contact_avatar_with_size (contact, avatar_widget, size);
1533 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1534 EmpathyCallHandler *handler)
1536 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1538 tp_g_signal_connect_object (priv->contact, "notify::name",
1539 G_CALLBACK (contact_name_changed_cb), self, 0);
1540 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1541 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1542 tp_g_signal_connect_object (priv->contact, "notify::presence",
1543 G_CALLBACK (contact_presence_changed_cb), self, 0);
1545 set_window_title (self);
1546 set_remote_user_name (self, priv->contact);
1548 init_contact_avatar_with_size (priv->contact,
1549 priv->remote_user_avatar_widget,
1550 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1551 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1553 init_contact_avatar_with_size (priv->contact,
1554 priv->remote_user_avatar_toolbar,
1555 SMALL_TOOLBAR_SIZE);
1557 /* The remote avatar is shown by default and will be hidden when we receive
1558 video from the remote side. */
1559 clutter_actor_hide (priv->video_output);
1560 gtk_widget_show (priv->remote_user_avatar_widget);
1564 update_send_codec (EmpathyCallWindow *self,
1567 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1574 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1575 widget = priv->acodec_encoding_label;
1579 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1580 widget = priv->vcodec_encoding_label;
1586 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1587 gtk_label_set_text (GTK_LABEL (widget), tmp);
1592 send_audio_codec_notify_cb (GObject *object,
1596 EmpathyCallWindow *self = user_data;
1598 update_send_codec (self, TRUE);
1602 send_video_codec_notify_cb (GObject *object,
1606 EmpathyCallWindow *self = user_data;
1608 update_send_codec (self, FALSE);
1612 update_recv_codec (EmpathyCallWindow *self,
1615 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1618 GString *str = NULL;
1622 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1623 widget = priv->acodec_decoding_label;
1627 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1628 widget = priv->vcodec_decoding_label;
1634 for (l = codecs; l != NULL; l = g_list_next (l))
1636 FsCodec *codec = l->data;
1639 str = g_string_new (NULL);
1641 g_string_append (str, ", ");
1643 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1647 gtk_label_set_text (GTK_LABEL (widget), str->str);
1648 g_string_free (str, TRUE);
1652 recv_audio_codecs_notify_cb (GObject *object,
1656 EmpathyCallWindow *self = user_data;
1658 update_recv_codec (self, TRUE);
1662 recv_video_codecs_notify_cb (GObject *object,
1666 EmpathyCallWindow *self = user_data;
1668 update_recv_codec (self, FALSE);
1671 static const gchar *
1672 candidate_type_to_str (FsCandidate *candidate)
1674 switch (candidate->type)
1676 case FS_CANDIDATE_TYPE_HOST:
1678 case FS_CANDIDATE_TYPE_SRFLX:
1679 return "server reflexive";
1680 case FS_CANDIDATE_TYPE_PRFLX:
1681 return "peer reflexive";
1682 case FS_CANDIDATE_TYPE_RELAY:
1684 case FS_CANDIDATE_TYPE_MULTICAST:
1691 static const gchar *
1692 candidate_type_to_desc (FsCandidate *candidate)
1694 switch (candidate->type)
1696 case FS_CANDIDATE_TYPE_HOST:
1697 return _("The IP address as seen by the machine");
1698 case FS_CANDIDATE_TYPE_SRFLX:
1699 return _("The IP address as seen by a server on the Internet");
1700 case FS_CANDIDATE_TYPE_PRFLX:
1701 return _("The IP address of the peer as seen by the other side");
1702 case FS_CANDIDATE_TYPE_RELAY:
1703 return _("The IP address of a relay server");
1704 case FS_CANDIDATE_TYPE_MULTICAST:
1705 return _("The IP address of the multicast group");
1712 update_candidat_widget (EmpathyCallWindow *self,
1715 FsCandidate *candidate)
1719 g_assert (candidate != NULL);
1720 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1721 candidate->port, candidate_type_to_str (candidate));
1723 gtk_label_set_text (GTK_LABEL (label), str);
1724 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1730 candidates_changed_cb (GObject *object,
1732 EmpathyCallWindow *self)
1734 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1735 FsCandidate *candidate = NULL;
1737 if (type == FS_MEDIA_TYPE_VIDEO)
1739 /* Update remote candidate */
1740 candidate = empathy_call_handler_get_video_remote_candidate (
1743 update_candidat_widget (self, priv->video_remote_candidate_label,
1744 priv->video_remote_candidate_info_img, candidate);
1746 /* Update local candidate */
1747 candidate = empathy_call_handler_get_video_local_candidate (
1750 update_candidat_widget (self, priv->video_local_candidate_label,
1751 priv->video_local_candidate_info_img, candidate);
1755 /* Update remote candidate */
1756 candidate = empathy_call_handler_get_audio_remote_candidate (
1759 update_candidat_widget (self, priv->audio_remote_candidate_label,
1760 priv->audio_remote_candidate_info_img, candidate);
1762 /* Update local candidate */
1763 candidate = empathy_call_handler_get_audio_local_candidate (
1766 update_candidat_widget (self, priv->audio_local_candidate_label,
1767 priv->audio_local_candidate_info_img, candidate);
1772 empathy_call_window_constructed (GObject *object)
1774 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1775 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1776 TpyCallChannel *call;
1778 g_assert (priv->handler != NULL);
1780 g_object_get (priv->handler, "call-channel", &call, NULL);
1781 priv->outgoing = (call == NULL);
1783 g_object_unref (call);
1785 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1786 g_assert (priv->contact != NULL);
1788 empathy_call_window_setup_avatars (self, priv->handler);
1789 empathy_call_window_set_state_connecting (self);
1791 if (!empathy_call_handler_has_initial_video (priv->handler))
1793 gtk_toggle_tool_button_set_active (
1794 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1796 /* If call has InitialVideo, the preview will be started once the call has
1797 * been started (start_call()). */
1799 update_send_codec (self, TRUE);
1800 update_send_codec (self, FALSE);
1801 update_recv_codec (self, TRUE);
1802 update_recv_codec (self, FALSE);
1804 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1805 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1806 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1807 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1808 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1809 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1810 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1811 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1813 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1814 G_CALLBACK (candidates_changed_cb), self, 0);
1817 static void empathy_call_window_dispose (GObject *object);
1818 static void empathy_call_window_finalize (GObject *object);
1821 empathy_call_window_set_property (GObject *object,
1822 guint property_id, const GValue *value, GParamSpec *pspec)
1824 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1826 switch (property_id)
1828 case PROP_CALL_HANDLER:
1829 priv->handler = g_value_dup_object (value);
1832 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1837 empathy_call_window_get_property (GObject *object,
1838 guint property_id, GValue *value, GParamSpec *pspec)
1840 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1842 switch (property_id)
1844 case PROP_CALL_HANDLER:
1845 g_value_set_object (value, priv->handler);
1848 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1853 empathy_call_window_class_init (
1854 EmpathyCallWindowClass *empathy_call_window_class)
1856 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1857 GParamSpec *param_spec;
1859 g_type_class_add_private (empathy_call_window_class,
1860 sizeof (EmpathyCallWindowPriv));
1862 object_class->constructed = empathy_call_window_constructed;
1863 object_class->set_property = empathy_call_window_set_property;
1864 object_class->get_property = empathy_call_window_get_property;
1866 object_class->dispose = empathy_call_window_dispose;
1867 object_class->finalize = empathy_call_window_finalize;
1869 param_spec = g_param_spec_object ("handler",
1870 "handler", "The call handler",
1871 EMPATHY_TYPE_CALL_HANDLER,
1872 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1873 g_object_class_install_property (object_class,
1874 PROP_CALL_HANDLER, param_spec);
1878 empathy_call_window_dispose (GObject *object)
1880 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1881 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1883 if (priv->dispose_has_run)
1886 priv->dispose_has_run = TRUE;
1888 if (priv->handler != NULL)
1890 empathy_call_handler_stop_call (priv->handler);
1891 tp_clear_object (&priv->handler);
1894 if (priv->bus_message_source_id != 0)
1896 g_source_remove (priv->bus_message_source_id);
1897 priv->bus_message_source_id = 0;
1900 if (priv->got_video_src > 0)
1902 g_source_remove (priv->got_video_src);
1903 priv->got_video_src = 0;
1906 if (priv->inactivity_src > 0)
1908 g_source_remove (priv->inactivity_src);
1909 priv->inactivity_src = 0;
1912 tp_clear_object (&priv->pipeline);
1913 tp_clear_object (&priv->video_input);
1914 tp_clear_object (&priv->audio_input);
1915 tp_clear_object (&priv->video_tee);
1916 tp_clear_object (&priv->ui_manager);
1917 tp_clear_object (&priv->fullscreen);
1918 tp_clear_object (&priv->camera_monitor);
1919 tp_clear_object (&priv->settings);
1920 tp_clear_object (&priv->transitions);
1922 g_list_free_full (priv->notifiers, g_object_unref);
1924 if (priv->timer_id != 0)
1925 g_source_remove (priv->timer_id);
1928 if (priv->contact != NULL)
1930 g_signal_handlers_disconnect_by_func (priv->contact,
1931 contact_name_changed_cb, self);
1932 priv->contact = NULL;
1936 tp_clear_object (&priv->sound_mgr);
1938 tp_clear_object (&priv->mic_menu);
1940 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1944 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1946 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1948 if (priv->video_output_motion_handler_id != 0)
1950 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1951 priv->video_output_motion_handler_id);
1952 priv->video_output_motion_handler_id = 0;
1957 empathy_call_window_finalize (GObject *object)
1959 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1960 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1962 disconnect_video_output_motion_handler (self);
1964 /* free any data held directly by the object here */
1965 g_mutex_free (priv->lock);
1967 g_timer_destroy (priv->timer);
1969 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1974 empathy_call_window_new (EmpathyCallHandler *handler)
1976 return EMPATHY_CALL_WINDOW (
1977 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1981 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1982 GstElement *conference, gpointer user_data)
1984 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1985 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1986 FsElementAddedNotifier *notifier;
1989 DEBUG ("Conference added");
1991 /* Add notifier to set the various element properties as needed */
1992 notifier = fs_element_added_notifier_new ();
1993 keyfile = fs_utils_get_default_element_properties (conference);
1995 if (keyfile != NULL)
1996 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1998 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2000 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2002 gst_bin_add (GST_BIN (priv->pipeline), conference);
2003 gst_element_set_state (conference, GST_STATE_PLAYING);
2007 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2008 GstElement *conference, gpointer user_data)
2010 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2011 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2013 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2014 gst_element_set_state (conference, GST_STATE_NULL);
2018 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2020 GstStateChangeReturn state_change_return;
2021 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2023 if (priv->pipeline == NULL)
2026 if (priv->bus_message_source_id != 0)
2028 g_source_remove (priv->bus_message_source_id);
2029 priv->bus_message_source_id = 0;
2032 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2034 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2035 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2037 if (priv->pipeline != NULL)
2038 g_object_unref (priv->pipeline);
2039 priv->pipeline = NULL;
2041 if (priv->audio_output != NULL)
2042 g_object_unref (priv->audio_output);
2043 priv->audio_output = NULL;
2045 if (priv->video_tee != NULL)
2046 g_object_unref (priv->video_tee);
2047 priv->video_tee = NULL;
2049 if (priv->video_preview != NULL)
2050 clutter_actor_destroy (priv->video_preview);
2051 priv->video_preview = NULL;
2053 priv->funnel = NULL;
2055 create_pipeline (self);
2056 /* Call will be started when user will hit the 'redial' button */
2057 priv->start_call_when_playing = FALSE;
2058 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2064 g_message ("Error: could not destroy pipeline. Closing call window");
2065 gtk_widget_destroy (GTK_WIDGET (self));
2072 reset_details_pane (EmpathyCallWindow *self)
2074 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2076 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2077 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2078 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2079 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2083 empathy_call_window_disconnected (EmpathyCallWindow *self,
2086 gboolean could_disconnect = FALSE;
2087 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2088 gboolean could_reset_pipeline;
2090 /* Leave full screen mode if needed */
2091 gtk_window_unfullscreen (GTK_WINDOW (self));
2093 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2094 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2096 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2098 if (priv->call_state == CONNECTING)
2099 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2101 if (priv->call_state != REDIALING)
2102 priv->call_state = DISCONNECTED;
2104 if (could_reset_pipeline)
2106 g_mutex_lock (priv->lock);
2108 g_timer_stop (priv->timer);
2110 if (priv->timer_id != 0)
2111 g_source_remove (priv->timer_id);
2114 g_mutex_unlock (priv->lock);
2117 /* We are about to destroy the window, no need to update it or create
2118 * a video preview */
2121 empathy_call_window_status_message (self, _("Disconnected"));
2123 empathy_call_window_show_hangup_button (self, FALSE);
2125 /* Unsensitive the camera and mic button */
2126 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2127 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2129 /* Be sure that the mic button is enabled */
2130 gtk_toggle_tool_button_set_active (
2131 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2133 if (priv->camera_state == CAMERA_STATE_ON)
2135 /* Restart the preview with the new pipeline. */
2136 display_video_preview (self, TRUE);
2139 /* destroy the video output; it will be recreated when we'll redial */
2140 disconnect_video_output_motion_handler (self);
2141 if (priv->video_output != NULL)
2142 clutter_actor_destroy (priv->video_output);
2143 priv->video_output = NULL;
2144 if (priv->got_video_src > 0)
2146 g_source_remove (priv->got_video_src);
2147 priv->got_video_src = 0;
2150 gtk_widget_show (priv->remote_user_avatar_widget);
2152 reset_details_pane (self);
2154 priv->sending_video = FALSE;
2155 priv->call_started = FALSE;
2157 could_disconnect = TRUE;
2159 /* TODO: display the self avatar of the preview (depends if the "Always
2160 * Show Video Preview" is enabled or not) */
2163 return could_disconnect;
2168 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2171 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2172 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2174 if (empathy_call_window_disconnected (self, TRUE) &&
2175 priv->call_state == REDIALING)
2176 empathy_call_window_restart_call (self);
2180 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2182 FsMediaType media_type,
2183 EmpathyCallWindow *self)
2185 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2187 DEBUG ("removing content");
2190 * This assumes that there is only one video stream per channel...
2193 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2195 if (priv->funnel != NULL)
2199 output = priv->video_output_sink;
2201 gst_element_set_state (output, GST_STATE_NULL);
2202 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2204 gst_bin_remove (GST_BIN (priv->pipeline), output);
2205 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2206 priv->funnel = NULL;
2210 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2212 if (priv->audio_output != NULL)
2214 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2216 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2217 priv->audio_output = NULL;
2225 /* Called with global lock held */
2227 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2229 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2233 if (priv->funnel == NULL)
2235 output = priv->video_output_sink;
2237 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2241 g_warning ("Could not create fsfunnel");
2245 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2247 gst_object_unref (priv->funnel);
2248 priv->funnel = NULL;
2249 g_warning ("Could not add funnel to pipeline");
2253 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2255 g_warning ("Could not add the video output widget to the pipeline");
2259 if (!gst_element_link (priv->funnel, output))
2261 g_warning ("Could not link output sink to funnel");
2262 goto error_output_added;
2265 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2267 g_warning ("Could not start video sink");
2268 goto error_output_added;
2271 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2273 g_warning ("Could not start funnel");
2274 goto error_output_added;
2278 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2281 g_warning ("Could not get request pad from funnel");
2288 gst_element_set_locked_state (priv->funnel, TRUE);
2289 gst_element_set_locked_state (output, TRUE);
2291 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2292 gst_element_set_state (output, GST_STATE_NULL);
2294 gst_bin_remove (GST_BIN (priv->pipeline), output);
2295 gst_element_set_locked_state (output, FALSE);
2299 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2300 priv->funnel = NULL;
2305 /* Called with global lock held */
2307 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2309 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2311 GstPadTemplate *template;
2313 if (priv->audio_output == NULL)
2315 priv->audio_output = empathy_audio_sink_new ();
2316 g_object_ref_sink (priv->audio_output);
2318 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2320 g_warning ("Could not add audio sink to pipeline");
2321 g_object_unref (priv->audio_output);
2322 goto error_add_output;
2325 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2327 g_warning ("Could not start audio sink");
2332 template = gst_element_class_get_pad_template (
2333 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2335 pad = gst_element_request_pad (priv->audio_output,
2336 template, NULL, NULL);
2340 g_warning ("Could not get sink pad from sink");
2347 gst_element_set_locked_state (priv->audio_output, TRUE);
2348 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2349 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2350 priv->audio_output = NULL;
2358 empathy_call_window_update_timer (gpointer user_data)
2360 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2361 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2362 const gchar *status;
2366 time_ = g_timer_elapsed (priv->timer, NULL);
2368 if (priv->call_state == HELD)
2369 status = _("On hold");
2370 else if (!gtk_toggle_tool_button_get_active (
2371 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2374 status = _("Duration");
2376 /* Translators: 'status - minutes:seconds' the caller has been connected */
2377 str = g_strdup_printf (_("%s — %d:%02dm"),
2379 (int) time_ / 60, (int) time_ % 60);
2380 empathy_call_window_status_message (self, str);
2388 display_error (EmpathyCallWindow *self,
2389 TpyCallChannel *call,
2393 const gchar *details)
2395 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2396 GtkWidget *info_bar;
2397 GtkWidget *content_area;
2404 /* Create info bar */
2405 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2408 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2410 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2412 /* hbox containing the image and the messages vbox */
2413 hbox = gtk_hbox_new (FALSE, 3);
2414 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2417 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2418 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2420 /* vbox containing the main message and the details expander */
2421 vbox = gtk_vbox_new (FALSE, 3);
2422 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2425 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2427 label = gtk_label_new (NULL);
2428 gtk_label_set_markup (GTK_LABEL (label), txt);
2429 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2430 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2433 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2436 if (details != NULL)
2438 GtkWidget *expander;
2440 expander = gtk_expander_new (_("Technical Details"));
2442 txt = g_strdup_printf ("<i>%s</i>", details);
2444 label = gtk_label_new (NULL);
2445 gtk_label_set_markup (GTK_LABEL (label), txt);
2446 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2447 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2450 gtk_container_add (GTK_CONTAINER (expander), label);
2451 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2454 g_signal_connect (info_bar, "response",
2455 G_CALLBACK (gtk_widget_destroy), NULL);
2457 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2458 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2459 gtk_widget_show_all (info_bar);
2463 media_stream_error_to_txt (EmpathyCallWindow *self,
2464 TpyCallChannel *call,
2466 TpMediaStreamError error)
2468 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2469 const gchar *cm = NULL;
2475 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2477 return g_strdup_printf (
2478 _("%s's software does not understand any of the audio formats "
2479 "supported by your computer"),
2480 empathy_contact_get_alias (priv->contact));
2482 return g_strdup_printf (
2483 _("%s's software does not understand any of the video formats "
2484 "supported by your computer"),
2485 empathy_contact_get_alias (priv->contact));
2487 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2488 return g_strdup_printf (
2489 _("Can't establish a connection to %s. "
2490 "One of you might be on a network that does not allow "
2491 "direct connections."),
2492 empathy_contact_get_alias (priv->contact));
2494 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2495 return g_strdup (_("There was a failure on the network"));
2497 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2499 return g_strdup (_("The audio formats necessary for this call "
2500 "are not installed on your computer"));
2502 return g_strdup (_("The video formats necessary for this call "
2503 "are not installed on your computer"));
2505 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2506 tp_connection_parse_object_path (
2507 tp_channel_borrow_connection (TP_CHANNEL (call)),
2510 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2511 "product=Telepathy&component=%s", cm);
2513 result = g_strdup_printf (
2514 _("Something unexpected happened in a Telepathy component. "
2515 "Please <a href=\"%s\">report this bug</a> and attach "
2516 "logs gathered from the 'Debug' window in the Help menu."), url);
2522 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2523 return g_strdup (_("There was a failure in the call engine"));
2525 case TP_MEDIA_STREAM_ERROR_EOS:
2526 return g_strdup (_("The end of the stream was reached"));
2528 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2535 empathy_call_window_stream_error (EmpathyCallWindow *self,
2536 TpyCallChannel *call,
2545 desc = media_stream_error_to_txt (self, call, audio, code);
2548 /* No description, use the error message. That's not great as it's not
2549 * localized but it's better than nothing. */
2550 display_error (self, call, icon, title, msg, NULL);
2554 display_error (self, call, icon, title, desc, msg);
2560 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2563 EmpathyCallWindow *self)
2565 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2566 "gnome-stock-mic", _("Can't establish audio stream"));
2570 empathy_call_window_video_stream_error (TpyCallChannel *call,
2573 EmpathyCallWindow *self)
2575 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2576 "camera-web", _("Can't establish video stream"));
2581 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2583 EmpathyCallWindow *self)
2585 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2586 TpyCallChannel *call;
2587 gboolean can_send_video;
2589 if (state != TPY_CALL_STATE_ACCEPTED)
2592 if (priv->call_state == CONNECTED)
2595 g_timer_start (priv->timer);
2596 priv->call_state = CONNECTED;
2598 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2600 can_send_video = priv->video_input != NULL &&
2601 empathy_contact_can_voip_video (priv->contact) &&
2602 empathy_camera_monitor_get_available (priv->camera_monitor);
2604 g_object_get (priv->handler, "call-channel", &call, NULL);
2606 if (tpy_call_channel_has_dtmf (call))
2607 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2609 if (priv->video_input == NULL)
2610 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2612 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2614 empathy_call_window_show_hangup_button (self, TRUE);
2616 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2618 clutter_actor_hide (priv->video_output);
2619 gtk_widget_show (priv->remote_user_avatar_widget);
2621 g_object_unref (call);
2623 g_mutex_lock (priv->lock);
2625 priv->timer_id = g_timeout_add_seconds (1,
2626 empathy_call_window_update_timer, self);
2628 g_mutex_unlock (priv->lock);
2630 empathy_call_window_update_timer (self);
2632 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2636 empathy_call_window_show_video_output_cb (gpointer user_data)
2638 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2640 if (self->priv->video_output != NULL)
2642 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2643 clutter_actor_show (self->priv->video_output);
2644 clutter_actor_raise_top (self->priv->floating_toolbar);
2651 empathy_call_window_check_video_cb (gpointer data)
2653 EmpathyCallWindow *self = data;
2655 if (self->priv->got_video)
2657 self->priv->got_video = FALSE;
2661 /* No video in the last N seconds, display the remote avatar */
2662 empathy_call_window_show_video_output (self, FALSE);
2667 /* Called from the streaming thread */
2669 empathy_call_window_video_probe_cb (GstPad *pad,
2670 GstMiniObject *mini_obj,
2671 EmpathyCallWindow *self)
2674 if (GST_IS_EVENT (mini_obj))
2677 if (G_UNLIKELY (!self->priv->got_video))
2679 /* show the remote video */
2680 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2681 empathy_call_window_show_video_output_cb,
2682 g_object_ref (self), g_object_unref);
2684 self->priv->got_video = TRUE;
2690 /* Called from the streaming thread */
2692 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2693 GstPad *src, guint media_type, gpointer user_data)
2695 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2696 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2697 gboolean retval = FALSE;
2701 g_mutex_lock (priv->lock);
2705 case TP_MEDIA_STREAM_TYPE_AUDIO:
2706 pad = empathy_call_window_get_audio_sink_pad (self);
2708 case TP_MEDIA_STREAM_TYPE_VIDEO:
2709 g_idle_add (empathy_call_window_show_video_output_cb, self);
2710 pad = empathy_call_window_get_video_sink_pad (self);
2712 gst_pad_add_data_probe (src,
2713 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2714 if (priv->got_video_src > 0)
2715 g_source_remove (priv->got_video_src);
2716 priv->got_video_src = g_timeout_add_seconds (5,
2717 empathy_call_window_check_video_cb, self);
2720 g_assert_not_reached ();
2726 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2727 g_warning ("Could not link %s sink pad",
2728 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2732 gst_object_unref (pad);
2736 /* If no sink could be linked, try to add fakesink to prevent the whole call
2741 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2743 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2745 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2746 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2747 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2749 gst_element_set_locked_state (fakesink, TRUE);
2750 gst_element_set_state (fakesink, GST_STATE_NULL);
2751 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2755 DEBUG ("Could not link real sink, linked fakesink instead");
2757 gst_object_unref (sinkpad);
2761 gst_object_unref (fakesink);
2766 g_mutex_unlock (priv->lock);
2772 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2773 GstPad *sink, FsMediaType media_type, gpointer user_data)
2775 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2776 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2778 gboolean retval = FALSE;
2782 case FS_MEDIA_TYPE_AUDIO:
2783 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2785 g_warning ("Could not add audio source to pipeline");
2789 pad = gst_element_get_static_pad (priv->audio_input, "src");
2792 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2793 g_warning ("Could not get source pad from audio source");
2797 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2799 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2800 g_warning ("Could not link audio source to farsight");
2804 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2806 g_warning ("Could not start audio source");
2807 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2808 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2814 case FS_MEDIA_TYPE_VIDEO:
2815 if (priv->video_tee != NULL)
2817 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2818 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2820 g_warning ("Could not link video source input pipeline");
2823 gst_object_unref (pad);
2829 g_assert_not_reached ();
2836 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2838 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2839 GstElement *preview;
2841 disable_camera (self);
2843 DEBUG ("remove video input");
2844 preview = priv->video_preview_sink;
2846 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2847 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2848 gst_element_set_state (preview, GST_STATE_NULL);
2850 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2853 g_object_unref (priv->video_input);
2854 priv->video_input = NULL;
2855 g_object_unref (priv->video_tee);
2856 priv->video_tee = NULL;
2857 clutter_actor_destroy (priv->video_preview);
2858 priv->video_preview = NULL;
2860 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2864 start_call (EmpathyCallWindow *self)
2866 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2868 priv->call_started = TRUE;
2869 empathy_call_handler_start_call (priv->handler,
2870 gtk_get_current_event_time ());
2872 if (empathy_call_handler_has_initial_video (priv->handler))
2874 TpyCallChannel *call;
2877 g_object_get (priv->handler, "call-channel", &call, NULL);
2878 s = tpy_call_channel_get_video_state (call);
2880 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2881 s == TPY_SENDING_STATE_SENDING)
2883 /* Enable 'send video' buttons and display the preview */
2884 gtk_toggle_tool_button_set_active (
2885 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2889 gtk_toggle_tool_button_set_active (
2890 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2892 if (priv->video_preview == NULL)
2894 create_video_preview (self);
2895 add_video_preview_to_pipeline (self);
2899 g_object_unref (call);
2904 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2907 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2908 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2911 empathy_call_handler_bus_message (priv->handler, bus, message);
2913 switch (GST_MESSAGE_TYPE (message))
2915 case GST_MESSAGE_STATE_CHANGED:
2916 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2918 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2920 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2921 !priv->call_started)
2923 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2924 if (newstate == GST_STATE_PAUSED)
2926 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2927 priv->pipeline_playing = TRUE;
2929 if (priv->start_call_when_playing)
2934 case GST_MESSAGE_ERROR:
2936 GError *error = NULL;
2937 GstElement *gst_error;
2940 gst_message_parse_error (message, &error, &debug);
2941 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2943 g_message ("Element error: %s -- %s\n", error->message, debug);
2945 if (g_str_has_prefix (gst_element_get_name (gst_error),
2946 VIDEO_INPUT_ERROR_PREFIX))
2948 /* Remove the video input and continue */
2949 if (priv->video_input != NULL)
2950 empathy_call_window_remove_video_input (self);
2951 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2955 empathy_call_window_disconnected (self, TRUE);
2957 g_error_free (error);
2960 case GST_MESSAGE_UNKNOWN:
2961 case GST_MESSAGE_EOS:
2962 case GST_MESSAGE_WARNING:
2963 case GST_MESSAGE_INFO:
2964 case GST_MESSAGE_TAG:
2965 case GST_MESSAGE_BUFFERING:
2966 case GST_MESSAGE_STATE_DIRTY:
2967 case GST_MESSAGE_STEP_DONE:
2968 case GST_MESSAGE_CLOCK_PROVIDE:
2969 case GST_MESSAGE_CLOCK_LOST:
2970 case GST_MESSAGE_NEW_CLOCK:
2971 case GST_MESSAGE_STRUCTURE_CHANGE:
2972 case GST_MESSAGE_STREAM_STATUS:
2973 case GST_MESSAGE_APPLICATION:
2974 case GST_MESSAGE_ELEMENT:
2975 case GST_MESSAGE_SEGMENT_START:
2976 case GST_MESSAGE_SEGMENT_DONE:
2977 case GST_MESSAGE_DURATION:
2978 case GST_MESSAGE_ANY:
2987 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2988 GHashTable *members,
2989 EmpathyCallWindow *self)
2991 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2992 GHashTableIter iter;
2993 gpointer key, value;
2994 gboolean held = FALSE;
2996 g_hash_table_iter_init (&iter, members);
2997 while (g_hash_table_iter_next (&iter, &key, &value))
2999 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3001 /* This assumes this is a 1-1 call, otherwise one participant
3002 * putting the call on hold wouldn't mean the call is on hold
3010 priv->call_state = HELD;
3011 else if (priv->call_state == HELD)
3012 priv->call_state = CONNECTED;
3016 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3018 EmpathyCallWindow *self)
3020 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3021 TpyCallChannel *call;
3023 g_object_get (priv->handler, "call-channel", &call, NULL);
3028 tp_g_signal_connect_object (call, "audio-stream-error",
3029 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3030 tp_g_signal_connect_object (call, "video-stream-error",
3031 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3034 tp_g_signal_connect_object (call, "members-changed",
3035 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3037 g_object_unref (call);
3041 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3043 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3044 TpyCallChannel *call;
3047 /* Make the hangup button twice as wide */
3048 width = gtk_widget_get_allocated_width (priv->hangup_button);
3049 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3051 g_signal_connect (priv->handler, "state-changed",
3052 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3053 g_signal_connect (priv->handler, "conference-added",
3054 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3055 g_signal_connect (priv->handler, "conference-removed",
3056 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3057 g_signal_connect (priv->handler, "closed",
3058 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3059 g_signal_connect (priv->handler, "src-pad-added",
3060 G_CALLBACK (empathy_call_window_src_added_cb), window);
3061 g_signal_connect (priv->handler, "sink-pad-added",
3062 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3063 g_signal_connect (priv->handler, "sink-pad-removed",
3064 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3066 g_object_get (priv->handler, "call-channel", &call, NULL);
3069 call_handler_notify_call_cb (priv->handler, NULL, window);
3070 g_object_unref (call);
3074 /* call-channel doesn't exist yet, we'll connect signals once it has been
3076 g_signal_connect (priv->handler, "notify::call-channel",
3077 G_CALLBACK (call_handler_notify_call_cb), window);
3080 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3084 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3085 EmpathyCallWindow *window)
3087 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3089 if (priv->pipeline != NULL)
3091 if (priv->bus_message_source_id != 0)
3093 g_source_remove (priv->bus_message_source_id);
3094 priv->bus_message_source_id = 0;
3097 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3100 if (priv->call_state == CONNECTING)
3101 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3107 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3110 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3112 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3117 gtk_widget_hide (priv->dtmf_panel);
3118 gtk_widget_hide (menu);
3119 gtk_widget_hide (priv->toolbar);
3123 if (priv->dialpad_was_visible_before_fs)
3124 gtk_widget_show (priv->dtmf_panel);
3126 gtk_widget_show (menu);
3127 gtk_widget_show (priv->toolbar);
3129 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3130 priv->original_height_before_fs);
3135 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3137 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3139 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3140 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3141 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3142 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3144 if (priv->video_output != NULL)
3147 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3148 priv->video_output, TRUE, TRUE,
3149 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3156 empathy_call_window_state_event_cb (GtkWidget *widget,
3157 GdkEventWindowState *event, EmpathyCallWindow *window)
3159 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3161 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3162 gboolean set_fullscreen = event->new_window_state &
3163 GDK_WINDOW_STATE_FULLSCREEN;
3167 gboolean dialpad_was_visible;
3168 GtkAllocation allocation;
3169 gint original_width, original_height;
3171 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3172 original_width = allocation.width;
3173 original_height = allocation.height;
3175 g_object_get (priv->dtmf_panel,
3176 "visible", &dialpad_was_visible,
3179 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3180 priv->original_width_before_fs = original_width;
3181 priv->original_height_before_fs = original_height;
3183 if (priv->video_output_motion_handler_id == 0 &&
3184 priv->video_output != NULL)
3186 priv->video_output_motion_handler_id = g_signal_connect (
3187 G_OBJECT (priv->video_container), "motion-notify-event",
3188 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3194 disconnect_video_output_motion_handler (window);
3197 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3199 show_controls (window, set_fullscreen);
3200 show_borders (window, set_fullscreen);
3201 gtk_action_set_stock_id (priv->menu_fullscreen,
3202 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3203 priv->is_fullscreen = set_fullscreen;
3210 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3213 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3214 int w, h, dialpad_width;
3215 GtkAllocation allocation;
3217 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3218 w = allocation.width;
3219 h = allocation.height;
3221 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3225 gtk_widget_show (priv->dtmf_panel);
3231 gtk_widget_hide (priv->dtmf_panel);
3235 gtk_window_resize (GTK_WINDOW (window), w, h);
3239 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3242 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3243 TpyCallChannel *call;
3245 priv->sending_video = (state == CAMERA_STATE_ON);
3247 if (state == CAMERA_STATE_ON)
3249 /* When we start sending video, we want to show the video preview by
3251 display_video_preview (window, TRUE);
3255 display_video_preview (window, FALSE);
3258 if (priv->call_state != CONNECTED)
3261 g_object_get (priv->handler, "call-channel", &call, NULL);
3262 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3263 tpy_call_channel_send_video (call, priv->sending_video);
3264 g_object_unref (call);
3268 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3269 EmpathyCallWindow *self)
3271 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3274 active = (gtk_toggle_tool_button_get_active (toggle));
3276 /* We don't want the settings callback to react to this change to avoid
3278 g_signal_handlers_block_by_func (priv->settings,
3279 empathy_call_window_prefs_volume_changed_cb, self);
3283 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3284 priv->volume * 100);
3288 /* TODO, Instead of setting the input volume to 0 we should probably
3289 * stop sending but this would cause the audio call to drop if both
3290 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3291 * in the future. GNOME #574574
3293 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3297 g_signal_handlers_unblock_by_func (priv->settings,
3298 empathy_call_window_prefs_volume_changed_cb, self);
3302 empathy_call_window_hangup_cb (gpointer object,
3303 EmpathyCallWindow *self)
3305 empathy_call_handler_stop_call (self->priv->handler);
3307 empathy_call_window_disconnected (self, TRUE);
3311 empathy_call_window_restart_call (EmpathyCallWindow *window)
3313 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3315 /* Remove error info bars */
3316 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3317 (GtkCallback) gtk_widget_destroy, NULL);
3319 create_video_output_widget (window);
3321 /* While the call was disconnected, the input volume might have changed.
3322 * However, since the audio_input source was destroyed, its volume has not
3323 * been updated during that time. That's why we manually update it here */
3324 empathy_call_window_mic_volume_changed (window);
3326 priv->outgoing = TRUE;
3327 empathy_call_window_set_state_connecting (window);
3329 if (priv->pipeline_playing)
3330 start_call (window);
3332 /* call will be started when the pipeline is ready */
3333 priv->start_call_when_playing = TRUE;
3335 empathy_call_window_setup_avatars (window, priv->handler);
3337 empathy_call_window_show_hangup_button (window, TRUE);
3341 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3342 EmpathyCallWindow *window)
3346 active = gtk_toggle_tool_button_get_active (button);
3348 empathy_call_window_show_dialpad (window, active);
3352 empathy_call_window_fullscreen_cb (gpointer object,
3353 EmpathyCallWindow *window)
3355 empathy_call_window_fullscreen_toggle (window);
3359 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3361 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3363 if (priv->is_fullscreen)
3364 gtk_window_unfullscreen (GTK_WINDOW (window));
3366 gtk_window_fullscreen (GTK_WINDOW (window));
3370 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3371 GdkEventButton *event, EmpathyCallWindow *window)
3373 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3375 empathy_call_window_video_menu_popup (window, event->button);
3383 empathy_call_window_key_press_cb (GtkWidget *video_output,
3384 GdkEventKey *event, EmpathyCallWindow *window)
3386 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3388 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3390 /* Since we are in fullscreen mode, toggling will bring us back to
3392 empathy_call_window_fullscreen_toggle (window);
3400 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3401 GdkEventMotion *event, EmpathyCallWindow *window)
3403 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3405 if (priv->is_fullscreen)
3407 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3409 /* Show the bottom toolbar */
3410 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3417 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3421 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3423 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3425 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3426 button, gtk_get_current_event_time ());
3427 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3431 empathy_call_window_status_message (EmpathyCallWindow *self,
3434 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3438 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3439 gdouble value, EmpathyCallWindow *window)
3441 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3443 if (priv->audio_output == NULL)
3446 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3451 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3453 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3455 return priv->ui_manager;
3458 EmpathyGstAudioSrc *
3459 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3461 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3463 return (EmpathyGstAudioSrc *) priv->audio_input;