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_rectangles (EmpathyCallWindow *self)
731 clutter_rectangle_set_border_width (
732 CLUTTER_RECTANGLE (self->priv->preview_rectangle1), 1);
733 clutter_rectangle_set_border_color (
734 CLUTTER_RECTANGLE (self->priv->preview_rectangle1),
735 CLUTTER_COLOR_Black);
737 clutter_rectangle_set_border_width (
738 CLUTTER_RECTANGLE (self->priv->preview_rectangle2), 1);
739 clutter_rectangle_set_border_color (
740 CLUTTER_RECTANGLE (self->priv->preview_rectangle2),
741 CLUTTER_COLOR_Black);
743 clutter_rectangle_set_border_width (
744 CLUTTER_RECTANGLE (self->priv->preview_rectangle3), 1);
745 clutter_rectangle_set_border_color (
746 CLUTTER_RECTANGLE (self->priv->preview_rectangle3),
747 CLUTTER_COLOR_Black);
749 clutter_rectangle_set_border_width (
750 CLUTTER_RECTANGLE (self->priv->preview_rectangle4), 1);
751 clutter_rectangle_set_border_color (
752 CLUTTER_RECTANGLE (self->priv->preview_rectangle4),
753 CLUTTER_COLOR_Black);
757 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
761 ClutterModifierType modifiers,
762 EmpathyCallWindow *self)
764 empathy_call_window_show_preview_rectangles (self, TRUE);
766 self->priv->event_x = event_x;
767 self->priv->event_y = event_y;
771 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
775 ClutterModifierType modifiers,
776 EmpathyCallWindow *self)
780 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
782 if (pos != PREVIEW_POS_NONE)
783 empathy_call_window_move_video_preview (self, pos);
785 empathy_call_window_show_preview_rectangles (self, FALSE);
789 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
793 EmpathyCallWindow *self)
797 pos = empathy_call_window_get_preview_position (self,
798 self->priv->event_x - delta_x, self->priv->event_y + delta_y);
800 if (pos != PREVIEW_POS_NONE)
801 empathy_call_window_highlight_preview_rectangle (self, pos);
803 empathy_call_window_darken_preview_rectangles (self);
807 create_video_preview (EmpathyCallWindow *self)
809 EmpathyCallWindowPriv *priv = GET_PRIV (self);
810 ClutterLayoutManager *layout, *layout_center;
811 ClutterActor *preview;
814 ClutterAction *action;
817 g_assert (priv->video_preview == NULL);
819 preview = clutter_texture_new ();
820 clutter_actor_set_size (preview,
821 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
822 priv->video_preview_sink = clutter_gst_video_sink_new (
823 CLUTTER_TEXTURE (preview));
825 /* Flip the video preview */
826 clutter_actor_set_rotation (preview,
829 SELF_VIDEO_SECTION_WIDTH * 0.5,
833 /* Add a little offset to the video preview */
834 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
835 CLUTTER_BIN_ALIGNMENT_CENTER);
836 priv->video_preview = clutter_box_new (layout);
837 clutter_actor_set_size (priv->video_preview,
838 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
839 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
840 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
842 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
843 CLUTTER_BIN_ALIGNMENT_CENTER);
844 box = clutter_box_new (layout_center);
845 clutter_actor_set_size (box,
846 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
848 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
849 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
851 g_object_set (priv->video_preview_sink,
856 /* Translators: this is an "Info" label. It should be as short
858 button = gtk_button_new_with_label (_("i"));
859 b = gtk_clutter_actor_new_with_contents (button);
861 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
863 CLUTTER_BIN_ALIGNMENT_END,
864 CLUTTER_BIN_ALIGNMENT_END);
866 g_signal_connect (button, "clicked",
867 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
870 /* Translators: this is an "Info" label. It should be as short
872 button = gtk_button_new_with_label (_("i"));
873 priv->preview_hidden_button =
874 gtk_clutter_actor_new_with_contents (button);
876 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
877 priv->preview_hidden_button,
878 CLUTTER_BIN_ALIGNMENT_START,
879 CLUTTER_BIN_ALIGNMENT_END);
881 clutter_actor_hide (priv->preview_hidden_button);
883 g_signal_connect (button, "clicked",
884 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
887 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
889 CLUTTER_BIN_ALIGNMENT_START,
890 CLUTTER_BIN_ALIGNMENT_END);
892 action = clutter_drag_action_new ();
893 g_signal_connect (action, "drag-begin",
894 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
895 g_signal_connect (action, "drag-end",
896 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
897 g_signal_connect (action, "drag-motion",
898 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
900 clutter_actor_add_action (preview, action);
901 clutter_actor_set_reactive (preview, TRUE);
905 play_camera (EmpathyCallWindow *window,
908 EmpathyCallWindowPriv *priv = GET_PRIV (window);
912 if (priv->video_preview == NULL)
914 create_video_preview (window);
915 add_video_preview_to_pipeline (window);
919 state = GST_STATE_PLAYING;
921 state = GST_STATE_NULL;
923 preview = priv->video_preview_sink;
925 gst_element_set_state (preview, state);
926 gst_element_set_state (priv->video_input, state);
927 gst_element_set_state (priv->video_tee, state);
931 display_video_preview (EmpathyCallWindow *self,
934 EmpathyCallWindowPriv *priv = GET_PRIV (self);
938 /* Display the video preview */
939 DEBUG ("Show video preview");
941 play_camera (self, TRUE);
942 clutter_actor_show (priv->video_preview);
943 clutter_actor_raise_top (priv->floating_toolbar);
947 /* Hide the video preview */
948 DEBUG ("Hide video preview");
950 if (priv->video_preview != NULL)
952 clutter_actor_hide (priv->video_preview);
953 play_camera (self, FALSE);
959 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
961 EmpathyCallWindowPriv *priv = GET_PRIV (window);
963 empathy_call_window_status_message (window, _("Connecting…"));
964 priv->call_state = CONNECTING;
967 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
968 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
972 disable_camera (EmpathyCallWindow *self)
974 EmpathyCallWindowPriv *priv = GET_PRIV (self);
976 if (priv->camera_state == CAMERA_STATE_OFF)
979 DEBUG ("Disable camera");
981 display_video_preview (self, FALSE);
983 if (priv->camera_state == CAMERA_STATE_ON)
984 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
986 priv->camera_state = CAMERA_STATE_OFF;
990 enable_camera (EmpathyCallWindow *self)
992 EmpathyCallWindowPriv *priv = GET_PRIV (self);
994 if (priv->camera_state == CAMERA_STATE_ON)
997 if (priv->video_input == NULL)
999 DEBUG ("Can't enable camera, no input");
1003 DEBUG ("Enable camera");
1005 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1007 priv->camera_state = CAMERA_STATE_ON;
1011 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1012 EmpathyCallWindow *self)
1014 if (gtk_toggle_tool_button_get_active (toggle))
1015 enable_camera (self);
1017 disable_camera (self);
1021 create_pipeline (EmpathyCallWindow *self)
1023 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1026 g_assert (priv->pipeline == NULL);
1028 priv->pipeline = gst_pipeline_new (NULL);
1029 priv->pipeline_playing = FALSE;
1031 priv->video_tee = gst_element_factory_make ("tee", NULL);
1032 gst_object_ref (priv->video_tee);
1033 gst_object_sink (priv->video_tee);
1035 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1037 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1038 priv->bus_message_source_id = gst_bus_add_watch (bus,
1039 empathy_call_window_bus_message, self);
1041 g_object_unref (bus);
1045 empathy_call_window_settings_cb (GtkAction *action,
1046 EmpathyCallWindow *self)
1048 gchar *args = g_strdup_printf ("-p %s",
1049 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1051 empathy_launch_program (BIN_DIR, "empathy", args);
1057 empathy_call_window_contents_cb (GtkAction *action,
1058 EmpathyCallWindow *self)
1060 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1064 empathy_call_window_debug_cb (GtkAction *action,
1065 EmpathyCallWindow *self)
1067 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1071 empathy_call_window_about_cb (GtkAction *action,
1072 EmpathyCallWindow *self)
1074 empathy_about_dialog_new (GTK_WINDOW (self));
1078 empathy_call_window_toolbar_timeout (gpointer data)
1080 EmpathyCallWindow *self = data;
1082 clutter_state_set_state (self->priv->transitions, "fade-out");
1088 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1090 EmpathyCallWindow *self)
1092 clutter_state_set_state (self->priv->transitions, "fade-in");
1094 if (self->priv->inactivity_src > 0)
1095 g_source_remove (self->priv->inactivity_src);
1097 self->priv->inactivity_src = g_timeout_add_seconds (3,
1098 empathy_call_window_toolbar_timeout, self);
1104 empathy_call_window_configure_event_cb (GtkWidget *widget,
1106 EmpathyCallWindow *self)
1108 GdkWindow *gdk_window;
1109 GdkWindowState window_state;
1111 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1112 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1114 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1115 &self->priv->dialpad_width, NULL);
1117 gdk_window = gtk_widget_get_window (widget);
1118 window_state = gdk_window_get_state (gdk_window);
1119 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1125 empathy_call_window_destroyed_cb (GtkWidget *object,
1126 EmpathyCallWindow *self)
1128 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1130 /* Save the geometry as if the dialpad was hidden. */
1131 empathy_geometry_save_values (GTK_WINDOW (self),
1132 self->priv->x, self->priv->y,
1133 self->priv->w - self->priv->dialpad_width, self->priv->h,
1134 self->priv->maximized);
1139 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1141 ClutterBindConstraint *constraint)
1143 ClutterActorBox allocation;
1145 clutter_actor_get_allocation_box (stage, &allocation);
1147 clutter_bind_constraint_set_offset (constraint,
1148 allocation.y2 - allocation.y1 -
1149 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1153 empathy_call_window_init (EmpathyCallWindow *self)
1155 EmpathyCallWindowPriv *priv;
1157 GtkWidget *top_vbox;
1159 ClutterConstraint *constraint;
1160 ClutterActor *remote_avatar;
1161 GtkStyleContext *context;
1165 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1166 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1168 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1169 gui = empathy_builder_get_file (filename,
1170 "call_window_vbox", &top_vbox,
1171 "errors_vbox", &priv->errors_vbox,
1172 "pane", &priv->pane,
1173 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1174 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1175 "status_label", &priv->status_label,
1176 "audiocall", &priv->audio_call_button,
1177 "videocall", &priv->video_call_button,
1178 "microphone", &priv->mic_button,
1179 "camera", &priv->camera_button,
1180 "hangup", &priv->hangup_button,
1181 "dialpad", &priv->dialpad_button,
1182 "toolbar", &priv->toolbar,
1183 "bottom_toolbar", &priv->bottom_toolbar,
1184 "ui_manager", &priv->ui_manager,
1185 "menufullscreen", &priv->menu_fullscreen,
1186 "details_vbox", &priv->details_vbox,
1187 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1188 "acodec_encoding_label", &priv->acodec_encoding_label,
1189 "acodec_decoding_label", &priv->acodec_decoding_label,
1190 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1191 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1192 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1193 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1194 "video_local_candidate_label", &priv->video_local_candidate_label,
1195 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1196 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1197 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1198 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1202 empathy_builder_connect (gui, self,
1203 "hangup", "clicked", empathy_call_window_hangup_cb,
1204 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1205 "videocall", "clicked", empathy_call_window_video_call_cb,
1206 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1207 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1208 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1209 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1210 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1211 "menusettings", "activate", empathy_call_window_settings_cb,
1212 "menucontents", "activate", empathy_call_window_contents_cb,
1213 "menudebug", "activate", empathy_call_window_debug_cb,
1214 "menuabout", "activate", empathy_call_window_about_cb,
1215 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1216 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1217 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1220 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1222 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1224 g_object_bind_property (priv->camera_monitor, "available",
1225 priv->camera_button, "sensitive",
1226 G_BINDING_SYNC_CREATE);
1228 priv->lock = g_mutex_new ();
1230 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1232 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1233 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1234 CONTENT_HBOX_BORDER_WIDTH);
1235 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1238 /* avatar/video box */
1239 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1240 CLUTTER_BIN_ALIGNMENT_CENTER);
1242 priv->video_box = clutter_box_new (priv->video_layout);
1244 empathy_call_window_create_preview_rectangles (self);
1246 priv->video_container = gtk_clutter_embed_new ();
1248 /* Set the background color to that of the rest of the window */
1249 context = gtk_widget_get_style_context (priv->content_hbox);
1250 gtk_style_context_get_background_color (context,
1251 GTK_STATE_FLAG_NORMAL, &rgba);
1252 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1253 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1254 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1255 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1256 clutter_stage_set_color (
1257 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1258 GTK_CLUTTER_EMBED (priv->video_container))),
1261 clutter_container_add (
1262 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1263 GTK_CLUTTER_EMBED (priv->video_container))),
1267 constraint = clutter_bind_constraint_new (
1268 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1269 CLUTTER_BIND_SIZE, 0);
1270 clutter_actor_add_constraint (priv->video_box, constraint);
1272 priv->remote_user_avatar_widget = gtk_image_new ();
1273 remote_avatar = gtk_clutter_actor_new_with_contents (
1274 priv->remote_user_avatar_widget);
1276 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1279 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1280 priv->video_container, TRUE, TRUE,
1281 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1283 create_pipeline (self);
1284 create_video_output_widget (self);
1285 create_audio_input (self);
1286 create_video_input (self);
1288 priv->floating_toolbar = empathy_rounded_actor_new ();
1290 gtk_widget_reparent (priv->bottom_toolbar,
1291 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1293 constraint = clutter_bind_constraint_new (
1294 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1297 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1300 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1301 "notify::allocation",
1302 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1305 clutter_actor_set_size (priv->floating_toolbar,
1306 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1307 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1309 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1310 priv->floating_toolbar,
1311 CLUTTER_BIN_ALIGNMENT_CENTER,
1312 CLUTTER_BIN_ALIGNMENT_END);
1314 clutter_actor_raise_top (priv->floating_toolbar);
1316 /* Transitions for the floating toolbar */
1317 priv->transitions = clutter_state_new ();
1319 /* all transitions last for 2s */
1320 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1322 /* transition from any state to "fade-out" state */
1323 clutter_state_set (priv->transitions, NULL, "fade-out",
1324 priv->floating_toolbar,
1325 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1328 /* transition from any state to "fade-in" state */
1329 clutter_state_set (priv->transitions, NULL, "fade-in",
1330 priv->floating_toolbar,
1331 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1334 /* put the actor into the "fade-in" state with no animation */
1335 clutter_state_warp_to_state (priv->transitions, "fade-in");
1337 /* The call will be started as soon the pipeline is playing */
1338 priv->start_call_when_playing = TRUE;
1340 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1341 G_CALLBACK (dtmf_button_pressed_cb),
1342 G_CALLBACK (dtmf_button_released_cb));
1344 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1347 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1350 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1352 gtk_widget_show_all (top_vbox);
1354 gtk_widget_hide (priv->dtmf_panel);
1355 gtk_widget_hide (priv->details_vbox);
1357 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1359 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1360 priv->video_container);
1362 /* We hide the bottom toolbar after 3s of inactivity and show it
1363 * again on mouse movement */
1364 priv->inactivity_src = g_timeout_add_seconds (3,
1365 empathy_call_window_toolbar_timeout, self);
1367 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1368 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1370 g_signal_connect (G_OBJECT (self), "realize",
1371 G_CALLBACK (empathy_call_window_realized_cb), self);
1373 g_signal_connect (G_OBJECT (self), "delete-event",
1374 G_CALLBACK (empathy_call_window_delete_cb), self);
1376 g_signal_connect (G_OBJECT (self), "window-state-event",
1377 G_CALLBACK (empathy_call_window_state_event_cb), self);
1379 g_signal_connect (G_OBJECT (self), "key-press-event",
1380 G_CALLBACK (empathy_call_window_key_press_cb), self);
1382 g_signal_connect (self, "motion-notify-event",
1383 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1385 priv->timer = g_timer_new ();
1387 g_object_ref (priv->ui_manager);
1388 g_object_unref (gui);
1390 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1391 priv->mic_menu = empathy_mic_menu_new (self);
1393 empathy_call_window_show_hangup_button (self, TRUE);
1395 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1397 /* Retrieve initial volume */
1398 priv->volume = g_settings_get_double (priv->settings,
1399 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1401 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1402 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1404 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1405 /* These signals are used to track the window position and save it
1406 * when the window is destroyed. We need to do this as we don't want
1407 * the window geometry to be saved with the dialpad taken into account. */
1408 g_signal_connect (self, "destroy",
1409 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1410 g_signal_connect (self, "configure-event",
1411 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1412 g_signal_connect (self, "window-state-event",
1413 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1415 /* Don't display labels in both toolbars */
1416 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1419 /* Instead of specifying a width and a height, we specify only one size. That's
1420 because we want a square avatar icon. */
1422 init_contact_avatar_with_size (EmpathyContact *contact,
1423 GtkWidget *image_widget,
1426 GdkPixbuf *pixbuf_avatar = NULL;
1428 if (contact != NULL)
1430 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1434 if (pixbuf_avatar == NULL)
1436 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1437 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1440 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1442 if (pixbuf_avatar != NULL)
1443 g_object_unref (pixbuf_avatar);
1447 set_window_title (EmpathyCallWindow *self)
1449 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1452 if (priv->contact != NULL)
1454 /* translators: Call is a noun and %s is the contact name. This string
1455 * is used in the window title */
1456 tmp = g_strdup_printf (_("Call with %s"),
1457 empathy_contact_get_alias (priv->contact));
1458 gtk_window_set_title (GTK_WINDOW (self), tmp);
1463 g_warning ("Unknown remote contact!");
1468 set_remote_user_name (EmpathyCallWindow *self,
1469 EmpathyContact *contact)
1471 const gchar *alias = empathy_contact_get_alias (contact);
1472 const gchar *status = empathy_contact_get_status (contact);
1475 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1476 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1482 contact_name_changed_cb (EmpathyContact *contact,
1484 EmpathyCallWindow *self)
1486 set_window_title (self);
1487 set_remote_user_name (self, contact);
1491 contact_presence_changed_cb (EmpathyContact *contact,
1493 EmpathyCallWindow *self)
1495 set_remote_user_name (self, contact);
1499 contact_avatar_changed_cb (EmpathyContact *contact,
1501 EmpathyCallWindow *self)
1504 GtkAllocation allocation;
1505 GtkWidget *avatar_widget;
1507 avatar_widget = self->priv->remote_user_avatar_widget;
1509 gtk_widget_get_allocation (avatar_widget, &allocation);
1510 size = allocation.height;
1514 /* the widget is not allocated yet, set a default size */
1515 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1516 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1519 init_contact_avatar_with_size (contact, avatar_widget, size);
1521 avatar_widget = self->priv->remote_user_avatar_toolbar;
1523 gtk_widget_get_allocation (avatar_widget, &allocation);
1524 size = allocation.height;
1528 /* the widget is not allocated yet, set a default size */
1529 size = SMALL_TOOLBAR_SIZE;
1532 init_contact_avatar_with_size (contact, avatar_widget, size);
1536 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1537 EmpathyCallHandler *handler)
1539 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1541 tp_g_signal_connect_object (priv->contact, "notify::name",
1542 G_CALLBACK (contact_name_changed_cb), self, 0);
1543 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1544 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1545 tp_g_signal_connect_object (priv->contact, "notify::presence",
1546 G_CALLBACK (contact_presence_changed_cb), self, 0);
1548 set_window_title (self);
1549 set_remote_user_name (self, priv->contact);
1551 init_contact_avatar_with_size (priv->contact,
1552 priv->remote_user_avatar_widget,
1553 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1554 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1556 init_contact_avatar_with_size (priv->contact,
1557 priv->remote_user_avatar_toolbar,
1558 SMALL_TOOLBAR_SIZE);
1560 /* The remote avatar is shown by default and will be hidden when we receive
1561 video from the remote side. */
1562 clutter_actor_hide (priv->video_output);
1563 gtk_widget_show (priv->remote_user_avatar_widget);
1567 update_send_codec (EmpathyCallWindow *self,
1570 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1577 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1578 widget = priv->acodec_encoding_label;
1582 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1583 widget = priv->vcodec_encoding_label;
1589 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1590 gtk_label_set_text (GTK_LABEL (widget), tmp);
1595 send_audio_codec_notify_cb (GObject *object,
1599 EmpathyCallWindow *self = user_data;
1601 update_send_codec (self, TRUE);
1605 send_video_codec_notify_cb (GObject *object,
1609 EmpathyCallWindow *self = user_data;
1611 update_send_codec (self, FALSE);
1615 update_recv_codec (EmpathyCallWindow *self,
1618 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1621 GString *str = NULL;
1625 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1626 widget = priv->acodec_decoding_label;
1630 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1631 widget = priv->vcodec_decoding_label;
1637 for (l = codecs; l != NULL; l = g_list_next (l))
1639 FsCodec *codec = l->data;
1642 str = g_string_new (NULL);
1644 g_string_append (str, ", ");
1646 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1650 gtk_label_set_text (GTK_LABEL (widget), str->str);
1651 g_string_free (str, TRUE);
1655 recv_audio_codecs_notify_cb (GObject *object,
1659 EmpathyCallWindow *self = user_data;
1661 update_recv_codec (self, TRUE);
1665 recv_video_codecs_notify_cb (GObject *object,
1669 EmpathyCallWindow *self = user_data;
1671 update_recv_codec (self, FALSE);
1674 static const gchar *
1675 candidate_type_to_str (FsCandidate *candidate)
1677 switch (candidate->type)
1679 case FS_CANDIDATE_TYPE_HOST:
1681 case FS_CANDIDATE_TYPE_SRFLX:
1682 return "server reflexive";
1683 case FS_CANDIDATE_TYPE_PRFLX:
1684 return "peer reflexive";
1685 case FS_CANDIDATE_TYPE_RELAY:
1687 case FS_CANDIDATE_TYPE_MULTICAST:
1694 static const gchar *
1695 candidate_type_to_desc (FsCandidate *candidate)
1697 switch (candidate->type)
1699 case FS_CANDIDATE_TYPE_HOST:
1700 return _("The IP address as seen by the machine");
1701 case FS_CANDIDATE_TYPE_SRFLX:
1702 return _("The IP address as seen by a server on the Internet");
1703 case FS_CANDIDATE_TYPE_PRFLX:
1704 return _("The IP address of the peer as seen by the other side");
1705 case FS_CANDIDATE_TYPE_RELAY:
1706 return _("The IP address of a relay server");
1707 case FS_CANDIDATE_TYPE_MULTICAST:
1708 return _("The IP address of the multicast group");
1715 update_candidat_widget (EmpathyCallWindow *self,
1718 FsCandidate *candidate)
1722 g_assert (candidate != NULL);
1723 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1724 candidate->port, candidate_type_to_str (candidate));
1726 gtk_label_set_text (GTK_LABEL (label), str);
1727 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1733 candidates_changed_cb (GObject *object,
1735 EmpathyCallWindow *self)
1737 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1738 FsCandidate *candidate = NULL;
1740 if (type == FS_MEDIA_TYPE_VIDEO)
1742 /* Update remote candidate */
1743 candidate = empathy_call_handler_get_video_remote_candidate (
1746 update_candidat_widget (self, priv->video_remote_candidate_label,
1747 priv->video_remote_candidate_info_img, candidate);
1749 /* Update local candidate */
1750 candidate = empathy_call_handler_get_video_local_candidate (
1753 update_candidat_widget (self, priv->video_local_candidate_label,
1754 priv->video_local_candidate_info_img, candidate);
1758 /* Update remote candidate */
1759 candidate = empathy_call_handler_get_audio_remote_candidate (
1762 update_candidat_widget (self, priv->audio_remote_candidate_label,
1763 priv->audio_remote_candidate_info_img, candidate);
1765 /* Update local candidate */
1766 candidate = empathy_call_handler_get_audio_local_candidate (
1769 update_candidat_widget (self, priv->audio_local_candidate_label,
1770 priv->audio_local_candidate_info_img, candidate);
1775 empathy_call_window_constructed (GObject *object)
1777 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1778 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1779 TpyCallChannel *call;
1781 g_assert (priv->handler != NULL);
1783 g_object_get (priv->handler, "call-channel", &call, NULL);
1784 priv->outgoing = (call == NULL);
1786 g_object_unref (call);
1788 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1789 g_assert (priv->contact != NULL);
1791 empathy_call_window_setup_avatars (self, priv->handler);
1792 empathy_call_window_set_state_connecting (self);
1794 if (!empathy_call_handler_has_initial_video (priv->handler))
1796 gtk_toggle_tool_button_set_active (
1797 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1799 /* If call has InitialVideo, the preview will be started once the call has
1800 * been started (start_call()). */
1802 update_send_codec (self, TRUE);
1803 update_send_codec (self, FALSE);
1804 update_recv_codec (self, TRUE);
1805 update_recv_codec (self, FALSE);
1807 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1808 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1809 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1810 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1811 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1812 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1813 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1814 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1816 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1817 G_CALLBACK (candidates_changed_cb), self, 0);
1820 static void empathy_call_window_dispose (GObject *object);
1821 static void empathy_call_window_finalize (GObject *object);
1824 empathy_call_window_set_property (GObject *object,
1825 guint property_id, const GValue *value, GParamSpec *pspec)
1827 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1829 switch (property_id)
1831 case PROP_CALL_HANDLER:
1832 priv->handler = g_value_dup_object (value);
1835 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1840 empathy_call_window_get_property (GObject *object,
1841 guint property_id, GValue *value, GParamSpec *pspec)
1843 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1845 switch (property_id)
1847 case PROP_CALL_HANDLER:
1848 g_value_set_object (value, priv->handler);
1851 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1856 empathy_call_window_class_init (
1857 EmpathyCallWindowClass *empathy_call_window_class)
1859 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1860 GParamSpec *param_spec;
1862 g_type_class_add_private (empathy_call_window_class,
1863 sizeof (EmpathyCallWindowPriv));
1865 object_class->constructed = empathy_call_window_constructed;
1866 object_class->set_property = empathy_call_window_set_property;
1867 object_class->get_property = empathy_call_window_get_property;
1869 object_class->dispose = empathy_call_window_dispose;
1870 object_class->finalize = empathy_call_window_finalize;
1872 param_spec = g_param_spec_object ("handler",
1873 "handler", "The call handler",
1874 EMPATHY_TYPE_CALL_HANDLER,
1875 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1876 g_object_class_install_property (object_class,
1877 PROP_CALL_HANDLER, param_spec);
1881 empathy_call_window_dispose (GObject *object)
1883 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1884 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1886 if (priv->dispose_has_run)
1889 priv->dispose_has_run = TRUE;
1891 if (priv->handler != NULL)
1893 empathy_call_handler_stop_call (priv->handler);
1894 tp_clear_object (&priv->handler);
1897 if (priv->bus_message_source_id != 0)
1899 g_source_remove (priv->bus_message_source_id);
1900 priv->bus_message_source_id = 0;
1903 if (priv->got_video_src > 0)
1905 g_source_remove (priv->got_video_src);
1906 priv->got_video_src = 0;
1909 if (priv->inactivity_src > 0)
1911 g_source_remove (priv->inactivity_src);
1912 priv->inactivity_src = 0;
1915 tp_clear_object (&priv->pipeline);
1916 tp_clear_object (&priv->video_input);
1917 tp_clear_object (&priv->audio_input);
1918 tp_clear_object (&priv->video_tee);
1919 tp_clear_object (&priv->ui_manager);
1920 tp_clear_object (&priv->fullscreen);
1921 tp_clear_object (&priv->camera_monitor);
1922 tp_clear_object (&priv->settings);
1923 tp_clear_object (&priv->transitions);
1925 g_list_free_full (priv->notifiers, g_object_unref);
1927 if (priv->timer_id != 0)
1928 g_source_remove (priv->timer_id);
1931 if (priv->contact != NULL)
1933 g_signal_handlers_disconnect_by_func (priv->contact,
1934 contact_name_changed_cb, self);
1935 priv->contact = NULL;
1939 tp_clear_object (&priv->sound_mgr);
1941 tp_clear_object (&priv->mic_menu);
1943 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1947 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1949 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1951 if (priv->video_output_motion_handler_id != 0)
1953 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1954 priv->video_output_motion_handler_id);
1955 priv->video_output_motion_handler_id = 0;
1960 empathy_call_window_finalize (GObject *object)
1962 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1963 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1965 disconnect_video_output_motion_handler (self);
1967 /* free any data held directly by the object here */
1968 g_mutex_free (priv->lock);
1970 g_timer_destroy (priv->timer);
1972 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1977 empathy_call_window_new (EmpathyCallHandler *handler)
1979 return EMPATHY_CALL_WINDOW (
1980 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1984 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1985 GstElement *conference, gpointer user_data)
1987 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1988 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1989 FsElementAddedNotifier *notifier;
1992 DEBUG ("Conference added");
1994 /* Add notifier to set the various element properties as needed */
1995 notifier = fs_element_added_notifier_new ();
1996 keyfile = fs_utils_get_default_element_properties (conference);
1998 if (keyfile != NULL)
1999 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2001 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2003 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2005 gst_bin_add (GST_BIN (priv->pipeline), conference);
2006 gst_element_set_state (conference, GST_STATE_PLAYING);
2010 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2011 GstElement *conference, gpointer user_data)
2013 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2014 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2016 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2017 gst_element_set_state (conference, GST_STATE_NULL);
2021 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2023 GstStateChangeReturn state_change_return;
2024 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2026 if (priv->pipeline == NULL)
2029 if (priv->bus_message_source_id != 0)
2031 g_source_remove (priv->bus_message_source_id);
2032 priv->bus_message_source_id = 0;
2035 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2037 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2038 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2040 if (priv->pipeline != NULL)
2041 g_object_unref (priv->pipeline);
2042 priv->pipeline = NULL;
2044 if (priv->audio_output != NULL)
2045 g_object_unref (priv->audio_output);
2046 priv->audio_output = NULL;
2048 if (priv->video_tee != NULL)
2049 g_object_unref (priv->video_tee);
2050 priv->video_tee = NULL;
2052 if (priv->video_preview != NULL)
2053 clutter_actor_destroy (priv->video_preview);
2054 priv->video_preview = NULL;
2056 priv->funnel = NULL;
2058 create_pipeline (self);
2059 /* Call will be started when user will hit the 'redial' button */
2060 priv->start_call_when_playing = FALSE;
2061 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2067 g_message ("Error: could not destroy pipeline. Closing call window");
2068 gtk_widget_destroy (GTK_WIDGET (self));
2075 reset_details_pane (EmpathyCallWindow *self)
2077 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2079 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2080 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2081 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2082 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2086 empathy_call_window_disconnected (EmpathyCallWindow *self,
2089 gboolean could_disconnect = FALSE;
2090 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2091 gboolean could_reset_pipeline;
2093 /* Leave full screen mode if needed */
2094 gtk_window_unfullscreen (GTK_WINDOW (self));
2096 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2097 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2099 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2101 if (priv->call_state == CONNECTING)
2102 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2104 if (priv->call_state != REDIALING)
2105 priv->call_state = DISCONNECTED;
2107 if (could_reset_pipeline)
2109 g_mutex_lock (priv->lock);
2111 g_timer_stop (priv->timer);
2113 if (priv->timer_id != 0)
2114 g_source_remove (priv->timer_id);
2117 g_mutex_unlock (priv->lock);
2120 /* We are about to destroy the window, no need to update it or create
2121 * a video preview */
2124 empathy_call_window_status_message (self, _("Disconnected"));
2126 empathy_call_window_show_hangup_button (self, FALSE);
2128 /* Unsensitive the camera and mic button */
2129 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2130 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2132 /* Be sure that the mic button is enabled */
2133 gtk_toggle_tool_button_set_active (
2134 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2136 if (priv->camera_state == CAMERA_STATE_ON)
2138 /* Restart the preview with the new pipeline. */
2139 display_video_preview (self, TRUE);
2142 /* destroy the video output; it will be recreated when we'll redial */
2143 disconnect_video_output_motion_handler (self);
2144 if (priv->video_output != NULL)
2145 clutter_actor_destroy (priv->video_output);
2146 priv->video_output = NULL;
2147 if (priv->got_video_src > 0)
2149 g_source_remove (priv->got_video_src);
2150 priv->got_video_src = 0;
2153 gtk_widget_show (priv->remote_user_avatar_widget);
2155 reset_details_pane (self);
2157 priv->sending_video = FALSE;
2158 priv->call_started = FALSE;
2160 could_disconnect = TRUE;
2162 /* TODO: display the self avatar of the preview (depends if the "Always
2163 * Show Video Preview" is enabled or not) */
2166 return could_disconnect;
2171 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2174 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2175 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2177 if (empathy_call_window_disconnected (self, TRUE) &&
2178 priv->call_state == REDIALING)
2179 empathy_call_window_restart_call (self);
2183 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2185 FsMediaType media_type,
2186 EmpathyCallWindow *self)
2188 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2190 DEBUG ("removing content");
2193 * This assumes that there is only one video stream per channel...
2196 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2198 if (priv->funnel != NULL)
2202 output = priv->video_output_sink;
2204 gst_element_set_state (output, GST_STATE_NULL);
2205 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2207 gst_bin_remove (GST_BIN (priv->pipeline), output);
2208 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2209 priv->funnel = NULL;
2213 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2215 if (priv->audio_output != NULL)
2217 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2219 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2220 priv->audio_output = NULL;
2228 /* Called with global lock held */
2230 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2232 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2236 if (priv->funnel == NULL)
2238 output = priv->video_output_sink;
2240 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2244 g_warning ("Could not create fsfunnel");
2248 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2250 gst_object_unref (priv->funnel);
2251 priv->funnel = NULL;
2252 g_warning ("Could not add funnel to pipeline");
2256 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2258 g_warning ("Could not add the video output widget to the pipeline");
2262 if (!gst_element_link (priv->funnel, output))
2264 g_warning ("Could not link output sink to funnel");
2265 goto error_output_added;
2268 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2270 g_warning ("Could not start video sink");
2271 goto error_output_added;
2274 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2276 g_warning ("Could not start funnel");
2277 goto error_output_added;
2281 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2284 g_warning ("Could not get request pad from funnel");
2291 gst_element_set_locked_state (priv->funnel, TRUE);
2292 gst_element_set_locked_state (output, TRUE);
2294 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2295 gst_element_set_state (output, GST_STATE_NULL);
2297 gst_bin_remove (GST_BIN (priv->pipeline), output);
2298 gst_element_set_locked_state (output, FALSE);
2302 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2303 priv->funnel = NULL;
2308 /* Called with global lock held */
2310 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2312 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2314 GstPadTemplate *template;
2316 if (priv->audio_output == NULL)
2318 priv->audio_output = empathy_audio_sink_new ();
2319 g_object_ref_sink (priv->audio_output);
2321 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2323 g_warning ("Could not add audio sink to pipeline");
2324 g_object_unref (priv->audio_output);
2325 goto error_add_output;
2328 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2330 g_warning ("Could not start audio sink");
2335 template = gst_element_class_get_pad_template (
2336 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2338 pad = gst_element_request_pad (priv->audio_output,
2339 template, NULL, NULL);
2343 g_warning ("Could not get sink pad from sink");
2350 gst_element_set_locked_state (priv->audio_output, TRUE);
2351 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2352 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2353 priv->audio_output = NULL;
2361 empathy_call_window_update_timer (gpointer user_data)
2363 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2364 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2365 const gchar *status;
2369 time_ = g_timer_elapsed (priv->timer, NULL);
2371 if (priv->call_state == HELD)
2372 status = _("On hold");
2373 else if (!gtk_toggle_tool_button_get_active (
2374 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2377 status = _("Duration");
2379 /* Translators: 'status - minutes:seconds' the caller has been connected */
2380 str = g_strdup_printf (_("%s — %d:%02dm"),
2382 (int) time_ / 60, (int) time_ % 60);
2383 empathy_call_window_status_message (self, str);
2391 display_error (EmpathyCallWindow *self,
2392 TpyCallChannel *call,
2396 const gchar *details)
2398 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2399 GtkWidget *info_bar;
2400 GtkWidget *content_area;
2407 /* Create info bar */
2408 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2411 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2413 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2415 /* hbox containing the image and the messages vbox */
2416 hbox = gtk_hbox_new (FALSE, 3);
2417 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2420 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2421 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2423 /* vbox containing the main message and the details expander */
2424 vbox = gtk_vbox_new (FALSE, 3);
2425 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2428 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2430 label = gtk_label_new (NULL);
2431 gtk_label_set_markup (GTK_LABEL (label), txt);
2432 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2433 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2436 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2439 if (details != NULL)
2441 GtkWidget *expander;
2443 expander = gtk_expander_new (_("Technical Details"));
2445 txt = g_strdup_printf ("<i>%s</i>", details);
2447 label = gtk_label_new (NULL);
2448 gtk_label_set_markup (GTK_LABEL (label), txt);
2449 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2450 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2453 gtk_container_add (GTK_CONTAINER (expander), label);
2454 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2457 g_signal_connect (info_bar, "response",
2458 G_CALLBACK (gtk_widget_destroy), NULL);
2460 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2461 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2462 gtk_widget_show_all (info_bar);
2466 media_stream_error_to_txt (EmpathyCallWindow *self,
2467 TpyCallChannel *call,
2469 TpMediaStreamError error)
2471 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2472 const gchar *cm = NULL;
2478 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2480 return g_strdup_printf (
2481 _("%s's software does not understand any of the audio formats "
2482 "supported by your computer"),
2483 empathy_contact_get_alias (priv->contact));
2485 return g_strdup_printf (
2486 _("%s's software does not understand any of the video formats "
2487 "supported by your computer"),
2488 empathy_contact_get_alias (priv->contact));
2490 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2491 return g_strdup_printf (
2492 _("Can't establish a connection to %s. "
2493 "One of you might be on a network that does not allow "
2494 "direct connections."),
2495 empathy_contact_get_alias (priv->contact));
2497 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2498 return g_strdup (_("There was a failure on the network"));
2500 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2502 return g_strdup (_("The audio formats necessary for this call "
2503 "are not installed on your computer"));
2505 return g_strdup (_("The video formats necessary for this call "
2506 "are not installed on your computer"));
2508 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2509 tp_connection_parse_object_path (
2510 tp_channel_borrow_connection (TP_CHANNEL (call)),
2513 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2514 "product=Telepathy&component=%s", cm);
2516 result = g_strdup_printf (
2517 _("Something unexpected happened in a Telepathy component. "
2518 "Please <a href=\"%s\">report this bug</a> and attach "
2519 "logs gathered from the 'Debug' window in the Help menu."), url);
2525 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2526 return g_strdup (_("There was a failure in the call engine"));
2528 case TP_MEDIA_STREAM_ERROR_EOS:
2529 return g_strdup (_("The end of the stream was reached"));
2531 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2538 empathy_call_window_stream_error (EmpathyCallWindow *self,
2539 TpyCallChannel *call,
2548 desc = media_stream_error_to_txt (self, call, audio, code);
2551 /* No description, use the error message. That's not great as it's not
2552 * localized but it's better than nothing. */
2553 display_error (self, call, icon, title, msg, NULL);
2557 display_error (self, call, icon, title, desc, msg);
2563 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2566 EmpathyCallWindow *self)
2568 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2569 "gnome-stock-mic", _("Can't establish audio stream"));
2573 empathy_call_window_video_stream_error (TpyCallChannel *call,
2576 EmpathyCallWindow *self)
2578 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2579 "camera-web", _("Can't establish video stream"));
2584 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2586 EmpathyCallWindow *self)
2588 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2589 TpyCallChannel *call;
2590 gboolean can_send_video;
2592 if (state != TPY_CALL_STATE_ACCEPTED)
2595 if (priv->call_state == CONNECTED)
2598 g_timer_start (priv->timer);
2599 priv->call_state = CONNECTED;
2601 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2603 can_send_video = priv->video_input != NULL &&
2604 empathy_contact_can_voip_video (priv->contact) &&
2605 empathy_camera_monitor_get_available (priv->camera_monitor);
2607 g_object_get (priv->handler, "call-channel", &call, NULL);
2609 if (tpy_call_channel_has_dtmf (call))
2610 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2612 if (priv->video_input == NULL)
2613 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2615 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2617 empathy_call_window_show_hangup_button (self, TRUE);
2619 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2621 clutter_actor_hide (priv->video_output);
2622 gtk_widget_show (priv->remote_user_avatar_widget);
2624 g_object_unref (call);
2626 g_mutex_lock (priv->lock);
2628 priv->timer_id = g_timeout_add_seconds (1,
2629 empathy_call_window_update_timer, self);
2631 g_mutex_unlock (priv->lock);
2633 empathy_call_window_update_timer (self);
2635 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2639 empathy_call_window_show_video_output_cb (gpointer user_data)
2641 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2643 if (self->priv->video_output != NULL)
2645 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2646 clutter_actor_show (self->priv->video_output);
2647 clutter_actor_raise_top (self->priv->floating_toolbar);
2654 empathy_call_window_check_video_cb (gpointer data)
2656 EmpathyCallWindow *self = data;
2658 if (self->priv->got_video)
2660 self->priv->got_video = FALSE;
2664 /* No video in the last N seconds, display the remote avatar */
2665 empathy_call_window_show_video_output (self, FALSE);
2670 /* Called from the streaming thread */
2672 empathy_call_window_video_probe_cb (GstPad *pad,
2673 GstMiniObject *mini_obj,
2674 EmpathyCallWindow *self)
2677 if (GST_IS_EVENT (mini_obj))
2680 if (G_UNLIKELY (!self->priv->got_video))
2682 /* show the remote video */
2683 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2684 empathy_call_window_show_video_output_cb,
2685 g_object_ref (self), g_object_unref);
2687 self->priv->got_video = TRUE;
2693 /* Called from the streaming thread */
2695 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2696 GstPad *src, guint media_type, gpointer user_data)
2698 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2699 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2700 gboolean retval = FALSE;
2704 g_mutex_lock (priv->lock);
2708 case TP_MEDIA_STREAM_TYPE_AUDIO:
2709 pad = empathy_call_window_get_audio_sink_pad (self);
2711 case TP_MEDIA_STREAM_TYPE_VIDEO:
2712 g_idle_add (empathy_call_window_show_video_output_cb, self);
2713 pad = empathy_call_window_get_video_sink_pad (self);
2715 gst_pad_add_data_probe (src,
2716 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2717 if (priv->got_video_src > 0)
2718 g_source_remove (priv->got_video_src);
2719 priv->got_video_src = g_timeout_add_seconds (5,
2720 empathy_call_window_check_video_cb, self);
2723 g_assert_not_reached ();
2729 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2730 g_warning ("Could not link %s sink pad",
2731 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2735 gst_object_unref (pad);
2739 /* If no sink could be linked, try to add fakesink to prevent the whole call
2744 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2746 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2748 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2749 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2750 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2752 gst_element_set_locked_state (fakesink, TRUE);
2753 gst_element_set_state (fakesink, GST_STATE_NULL);
2754 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2758 DEBUG ("Could not link real sink, linked fakesink instead");
2760 gst_object_unref (sinkpad);
2764 gst_object_unref (fakesink);
2769 g_mutex_unlock (priv->lock);
2775 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2776 GstPad *sink, FsMediaType media_type, gpointer user_data)
2778 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2779 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2781 gboolean retval = FALSE;
2785 case FS_MEDIA_TYPE_AUDIO:
2786 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2788 g_warning ("Could not add audio source to pipeline");
2792 pad = gst_element_get_static_pad (priv->audio_input, "src");
2795 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2796 g_warning ("Could not get source pad from audio source");
2800 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2802 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2803 g_warning ("Could not link audio source to farsight");
2807 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2809 g_warning ("Could not start audio source");
2810 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2811 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2817 case FS_MEDIA_TYPE_VIDEO:
2818 if (priv->video_tee != NULL)
2820 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2821 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2823 g_warning ("Could not link video source input pipeline");
2826 gst_object_unref (pad);
2832 g_assert_not_reached ();
2839 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2841 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2842 GstElement *preview;
2844 disable_camera (self);
2846 DEBUG ("remove video input");
2847 preview = priv->video_preview_sink;
2849 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2850 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2851 gst_element_set_state (preview, GST_STATE_NULL);
2853 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2856 g_object_unref (priv->video_input);
2857 priv->video_input = NULL;
2858 g_object_unref (priv->video_tee);
2859 priv->video_tee = NULL;
2860 clutter_actor_destroy (priv->video_preview);
2861 priv->video_preview = NULL;
2863 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2867 start_call (EmpathyCallWindow *self)
2869 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2871 priv->call_started = TRUE;
2872 empathy_call_handler_start_call (priv->handler,
2873 gtk_get_current_event_time ());
2875 if (empathy_call_handler_has_initial_video (priv->handler))
2877 TpyCallChannel *call;
2880 g_object_get (priv->handler, "call-channel", &call, NULL);
2881 s = tpy_call_channel_get_video_state (call);
2883 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2884 s == TPY_SENDING_STATE_SENDING)
2886 /* Enable 'send video' buttons and display the preview */
2887 gtk_toggle_tool_button_set_active (
2888 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2892 gtk_toggle_tool_button_set_active (
2893 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2895 if (priv->video_preview == NULL)
2897 create_video_preview (self);
2898 add_video_preview_to_pipeline (self);
2902 g_object_unref (call);
2907 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2910 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2911 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2914 empathy_call_handler_bus_message (priv->handler, bus, message);
2916 switch (GST_MESSAGE_TYPE (message))
2918 case GST_MESSAGE_STATE_CHANGED:
2919 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2921 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2923 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2924 !priv->call_started)
2926 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2927 if (newstate == GST_STATE_PAUSED)
2929 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2930 priv->pipeline_playing = TRUE;
2932 if (priv->start_call_when_playing)
2937 case GST_MESSAGE_ERROR:
2939 GError *error = NULL;
2940 GstElement *gst_error;
2943 gst_message_parse_error (message, &error, &debug);
2944 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2946 g_message ("Element error: %s -- %s\n", error->message, debug);
2948 if (g_str_has_prefix (gst_element_get_name (gst_error),
2949 VIDEO_INPUT_ERROR_PREFIX))
2951 /* Remove the video input and continue */
2952 if (priv->video_input != NULL)
2953 empathy_call_window_remove_video_input (self);
2954 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2958 empathy_call_window_disconnected (self, TRUE);
2960 g_error_free (error);
2963 case GST_MESSAGE_UNKNOWN:
2964 case GST_MESSAGE_EOS:
2965 case GST_MESSAGE_WARNING:
2966 case GST_MESSAGE_INFO:
2967 case GST_MESSAGE_TAG:
2968 case GST_MESSAGE_BUFFERING:
2969 case GST_MESSAGE_STATE_DIRTY:
2970 case GST_MESSAGE_STEP_DONE:
2971 case GST_MESSAGE_CLOCK_PROVIDE:
2972 case GST_MESSAGE_CLOCK_LOST:
2973 case GST_MESSAGE_NEW_CLOCK:
2974 case GST_MESSAGE_STRUCTURE_CHANGE:
2975 case GST_MESSAGE_STREAM_STATUS:
2976 case GST_MESSAGE_APPLICATION:
2977 case GST_MESSAGE_ELEMENT:
2978 case GST_MESSAGE_SEGMENT_START:
2979 case GST_MESSAGE_SEGMENT_DONE:
2980 case GST_MESSAGE_DURATION:
2981 case GST_MESSAGE_ANY:
2990 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2991 GHashTable *members,
2992 EmpathyCallWindow *self)
2994 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2995 GHashTableIter iter;
2996 gpointer key, value;
2997 gboolean held = FALSE;
2999 g_hash_table_iter_init (&iter, members);
3000 while (g_hash_table_iter_next (&iter, &key, &value))
3002 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3004 /* This assumes this is a 1-1 call, otherwise one participant
3005 * putting the call on hold wouldn't mean the call is on hold
3013 priv->call_state = HELD;
3014 else if (priv->call_state == HELD)
3015 priv->call_state = CONNECTED;
3019 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3021 EmpathyCallWindow *self)
3023 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3024 TpyCallChannel *call;
3026 g_object_get (priv->handler, "call-channel", &call, NULL);
3031 tp_g_signal_connect_object (call, "audio-stream-error",
3032 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3033 tp_g_signal_connect_object (call, "video-stream-error",
3034 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3037 tp_g_signal_connect_object (call, "members-changed",
3038 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3040 g_object_unref (call);
3044 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3046 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3047 TpyCallChannel *call;
3050 /* Make the hangup button twice as wide */
3051 width = gtk_widget_get_allocated_width (priv->hangup_button);
3052 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3054 g_signal_connect (priv->handler, "state-changed",
3055 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3056 g_signal_connect (priv->handler, "conference-added",
3057 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3058 g_signal_connect (priv->handler, "conference-removed",
3059 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3060 g_signal_connect (priv->handler, "closed",
3061 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3062 g_signal_connect (priv->handler, "src-pad-added",
3063 G_CALLBACK (empathy_call_window_src_added_cb), window);
3064 g_signal_connect (priv->handler, "sink-pad-added",
3065 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3066 g_signal_connect (priv->handler, "sink-pad-removed",
3067 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3069 g_object_get (priv->handler, "call-channel", &call, NULL);
3072 call_handler_notify_call_cb (priv->handler, NULL, window);
3073 g_object_unref (call);
3077 /* call-channel doesn't exist yet, we'll connect signals once it has been
3079 g_signal_connect (priv->handler, "notify::call-channel",
3080 G_CALLBACK (call_handler_notify_call_cb), window);
3083 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3087 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3088 EmpathyCallWindow *window)
3090 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3092 if (priv->pipeline != NULL)
3094 if (priv->bus_message_source_id != 0)
3096 g_source_remove (priv->bus_message_source_id);
3097 priv->bus_message_source_id = 0;
3100 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3103 if (priv->call_state == CONNECTING)
3104 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3110 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3113 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3115 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3120 gtk_widget_hide (priv->dtmf_panel);
3121 gtk_widget_hide (menu);
3122 gtk_widget_hide (priv->toolbar);
3126 if (priv->dialpad_was_visible_before_fs)
3127 gtk_widget_show (priv->dtmf_panel);
3129 gtk_widget_show (menu);
3130 gtk_widget_show (priv->toolbar);
3132 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3133 priv->original_height_before_fs);
3138 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3140 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3142 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3143 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3144 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3145 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3147 if (priv->video_output != NULL)
3150 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3151 priv->video_output, TRUE, TRUE,
3152 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3159 empathy_call_window_state_event_cb (GtkWidget *widget,
3160 GdkEventWindowState *event, EmpathyCallWindow *window)
3162 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3164 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3165 gboolean set_fullscreen = event->new_window_state &
3166 GDK_WINDOW_STATE_FULLSCREEN;
3170 gboolean dialpad_was_visible;
3171 GtkAllocation allocation;
3172 gint original_width, original_height;
3174 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3175 original_width = allocation.width;
3176 original_height = allocation.height;
3178 g_object_get (priv->dtmf_panel,
3179 "visible", &dialpad_was_visible,
3182 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3183 priv->original_width_before_fs = original_width;
3184 priv->original_height_before_fs = original_height;
3186 if (priv->video_output_motion_handler_id == 0 &&
3187 priv->video_output != NULL)
3189 priv->video_output_motion_handler_id = g_signal_connect (
3190 G_OBJECT (priv->video_container), "motion-notify-event",
3191 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3197 disconnect_video_output_motion_handler (window);
3200 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3202 show_controls (window, set_fullscreen);
3203 show_borders (window, set_fullscreen);
3204 gtk_action_set_stock_id (priv->menu_fullscreen,
3205 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3206 priv->is_fullscreen = set_fullscreen;
3213 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3216 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3217 int w, h, dialpad_width;
3218 GtkAllocation allocation;
3220 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3221 w = allocation.width;
3222 h = allocation.height;
3224 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3228 gtk_widget_show (priv->dtmf_panel);
3234 gtk_widget_hide (priv->dtmf_panel);
3238 gtk_window_resize (GTK_WINDOW (window), w, h);
3242 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3245 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3246 TpyCallChannel *call;
3248 priv->sending_video = (state == CAMERA_STATE_ON);
3250 if (state == CAMERA_STATE_ON)
3252 /* When we start sending video, we want to show the video preview by
3254 display_video_preview (window, TRUE);
3258 display_video_preview (window, FALSE);
3261 if (priv->call_state != CONNECTED)
3264 g_object_get (priv->handler, "call-channel", &call, NULL);
3265 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3266 tpy_call_channel_send_video (call, priv->sending_video);
3267 g_object_unref (call);
3271 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3272 EmpathyCallWindow *self)
3274 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3277 active = (gtk_toggle_tool_button_get_active (toggle));
3279 /* We don't want the settings callback to react to this change to avoid
3281 g_signal_handlers_block_by_func (priv->settings,
3282 empathy_call_window_prefs_volume_changed_cb, self);
3286 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3287 priv->volume * 100);
3291 /* TODO, Instead of setting the input volume to 0 we should probably
3292 * stop sending but this would cause the audio call to drop if both
3293 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3294 * in the future. GNOME #574574
3296 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3300 g_signal_handlers_unblock_by_func (priv->settings,
3301 empathy_call_window_prefs_volume_changed_cb, self);
3305 empathy_call_window_hangup_cb (gpointer object,
3306 EmpathyCallWindow *self)
3308 empathy_call_handler_stop_call (self->priv->handler);
3310 empathy_call_window_disconnected (self, TRUE);
3314 empathy_call_window_restart_call (EmpathyCallWindow *window)
3316 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3318 /* Remove error info bars */
3319 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3320 (GtkCallback) gtk_widget_destroy, NULL);
3322 create_video_output_widget (window);
3324 /* While the call was disconnected, the input volume might have changed.
3325 * However, since the audio_input source was destroyed, its volume has not
3326 * been updated during that time. That's why we manually update it here */
3327 empathy_call_window_mic_volume_changed (window);
3329 priv->outgoing = TRUE;
3330 empathy_call_window_set_state_connecting (window);
3332 if (priv->pipeline_playing)
3333 start_call (window);
3335 /* call will be started when the pipeline is ready */
3336 priv->start_call_when_playing = TRUE;
3338 empathy_call_window_setup_avatars (window, priv->handler);
3340 empathy_call_window_show_hangup_button (window, TRUE);
3344 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3345 EmpathyCallWindow *window)
3349 active = gtk_toggle_tool_button_get_active (button);
3351 empathy_call_window_show_dialpad (window, active);
3355 empathy_call_window_fullscreen_cb (gpointer object,
3356 EmpathyCallWindow *window)
3358 empathy_call_window_fullscreen_toggle (window);
3362 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3364 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3366 if (priv->is_fullscreen)
3367 gtk_window_unfullscreen (GTK_WINDOW (window));
3369 gtk_window_fullscreen (GTK_WINDOW (window));
3373 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3374 GdkEventButton *event, EmpathyCallWindow *window)
3376 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3378 empathy_call_window_video_menu_popup (window, event->button);
3386 empathy_call_window_key_press_cb (GtkWidget *video_output,
3387 GdkEventKey *event, EmpathyCallWindow *window)
3389 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3391 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3393 /* Since we are in fullscreen mode, toggling will bring us back to
3395 empathy_call_window_fullscreen_toggle (window);
3403 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3404 GdkEventMotion *event, EmpathyCallWindow *window)
3406 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3408 if (priv->is_fullscreen)
3410 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3412 /* Show the bottom toolbar */
3413 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3420 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3424 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3426 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3428 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3429 button, gtk_get_current_event_time ());
3430 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3434 empathy_call_window_status_message (EmpathyCallWindow *self,
3437 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3441 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3442 gdouble value, EmpathyCallWindow *window)
3444 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3446 if (priv->audio_output == NULL)
3449 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3454 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3456 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3458 return priv->ui_manager;
3461 EmpathyGstAudioSrc *
3462 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3464 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3466 return (EmpathyGstAudioSrc *) priv->audio_input;