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
76 #define FLOATING_TOOLBAR_OPACITY 192
77 #define FLOATING_TOOLBAR_WIDTH 280
78 #define FLOATING_TOOLBAR_HEIGHT 36
79 #define FLOATING_TOOLBAR_SPACING 20
81 /* The avatar's default width and height are set to the same value because we
82 want a square icon. */
83 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
84 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
85 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
87 #define SMALL_TOOLBAR_SIZE 36
89 /* If an video input error occurs, the error message will start with "v4l" */
90 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
92 /* The time interval in milliseconds between 2 outgoing rings */
93 #define MS_BETWEEN_RING 500
95 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
98 PROP_CALL_HANDLER = 1,
110 CAMERA_STATE_OFF = 0,
114 struct _EmpathyCallWindowPriv
116 gboolean dispose_has_run;
117 EmpathyCallHandler *handler;
119 EmpathyContact *contact;
121 EmpathyCameraMonitor *camera_monitor;
126 GtkUIManager *ui_manager;
127 GtkWidget *errors_vbox;
128 /* widget displays the video received from the remote user. This widget is
129 * alive only during call. */
130 ClutterActor *video_output;
131 ClutterActor *video_preview;
132 ClutterActor *preview_hidden_button;
133 GtkWidget *video_container;
134 GtkWidget *remote_user_avatar_widget;
135 GtkWidget *remote_user_avatar_toolbar;
136 GtkWidget *remote_user_name_toolbar;
137 GtkWidget *status_label;
138 GtkWidget *hangup_button;
139 GtkWidget *audio_call_button;
140 GtkWidget *video_call_button;
141 GtkWidget *mic_button;
142 GtkWidget *camera_button;
143 GtkWidget *dialpad_button;
145 GtkWidget *bottom_toolbar;
146 ClutterActor *floating_toolbar;
148 GtkAction *menu_fullscreen;
150 ClutterState *transitions;
152 /* The box that contains self and remote avatar and video
153 input/output. When we redial, we destroy and re-create the box */
154 ClutterActor *video_box;
155 ClutterLayoutManager *video_layout;
157 /* We keep a reference on the hbox which contains the main content so we can
158 easilly repack everything when toggling fullscreen */
159 GtkWidget *content_hbox;
161 gulong video_output_motion_handler_id;
162 guint bus_message_source_id;
166 GtkWidget *dtmf_panel;
169 GtkWidget *details_vbox;
170 GtkWidget *vcodec_encoding_label;
171 GtkWidget *acodec_encoding_label;
172 GtkWidget *vcodec_decoding_label;
173 GtkWidget *acodec_decoding_label;
175 GtkWidget *audio_remote_candidate_label;
176 GtkWidget *audio_local_candidate_label;
177 GtkWidget *video_remote_candidate_label;
178 GtkWidget *video_local_candidate_label;
179 GtkWidget *video_remote_candidate_info_img;
180 GtkWidget *video_local_candidate_info_img;
181 GtkWidget *audio_remote_candidate_info_img;
182 GtkWidget *audio_local_candidate_info_img;
184 GstElement *video_input;
185 GstElement *video_preview_sink;
186 GstElement *video_output_sink;
187 GstElement *audio_input;
188 GstElement *audio_output;
189 GstElement *pipeline;
190 GstElement *video_tee;
200 gboolean call_started;
201 gboolean sending_video;
202 CameraState camera_state;
204 EmpathyCallWindowFullscreen *fullscreen;
205 gboolean is_fullscreen;
210 guint inactivity_src;
212 /* Those fields represent the state of the window before it actually was in
214 gboolean dialpad_was_visible_before_fs;
215 gint original_width_before_fs;
216 gint original_height_before_fs;
218 gint x, y, w, h, dialpad_width;
221 /* TRUE if the call should be started when the pipeline is playing */
222 gboolean start_call_when_playing;
223 /* TRUE if we requested to set the pipeline in the playing state */
224 gboolean pipeline_playing;
226 EmpathySoundManager *sound_mgr;
229 EmpathyMicMenu *mic_menu;
232 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
234 static void empathy_call_window_realized_cb (GtkWidget *widget,
235 EmpathyCallWindow *window);
237 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
238 GdkEvent *event, EmpathyCallWindow *window);
240 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
241 GdkEventWindowState *event, EmpathyCallWindow *window);
243 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
246 static void empathy_call_window_mic_toggled_cb (
247 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
249 static void empathy_call_window_hangup_cb (gpointer object,
250 EmpathyCallWindow *window);
252 static void empathy_call_window_fullscreen_cb (gpointer object,
253 EmpathyCallWindow *window);
255 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
257 static gboolean empathy_call_window_video_button_press_cb (
258 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
260 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
261 GdkEventKey *event, EmpathyCallWindow *window);
263 static gboolean empathy_call_window_video_output_motion_notify (
264 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
266 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
269 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
270 EmpathyCallWindow *window);
272 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
274 static void empathy_call_window_status_message (EmpathyCallWindow *window,
277 static gboolean empathy_call_window_bus_message (GstBus *bus,
278 GstMessage *message, gpointer user_data);
281 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
282 gdouble value, EmpathyCallWindow *window);
285 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
288 gtk_widget_set_visible (self->priv->hangup_button, show);
289 gtk_widget_set_visible (self->priv->audio_call_button, !show);
290 gtk_widget_set_visible (self->priv->video_call_button, !show);
294 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
295 EmpathyCallWindow *self)
297 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
298 empathy_call_window_restart_call (self);
302 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
303 EmpathyCallWindow *self)
305 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
306 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
307 empathy_call_window_restart_call (self);
311 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
313 EmpathyCallWindowPriv *priv = GET_PRIV (window);
314 TpyCallChannel *call;
318 g_object_get (priv->handler, "call-channel", &call, NULL);
320 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
321 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
324 tpy_call_channel_dtmf_start_tone (call, event);
326 g_object_unref (call);
330 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
332 EmpathyCallWindowPriv *priv = GET_PRIV (window);
333 TpyCallChannel *call;
335 g_object_get (priv->handler, "call-channel", &call, NULL);
337 tpy_call_channel_dtmf_stop_tone (call);
339 g_object_unref (call);
343 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
345 EmpathyCallWindowPriv *priv = GET_PRIV (self);
348 volume = g_settings_get_double (priv->settings,
349 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
351 /* Don't store the volume because of muting */
352 if (volume > 0 || gtk_toggle_tool_button_get_active (
353 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
354 priv->volume = volume;
356 /* Ensure that the toggle button is active if the volume is > 0 and inactive
357 * if it's smaller than 0 */
358 if ((volume > 0) != gtk_toggle_tool_button_get_active (
359 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
360 gtk_toggle_tool_button_set_active (
361 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
363 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
368 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
370 EmpathyCallWindow *self)
372 empathy_call_window_mic_volume_changed (self);
376 empathy_call_window_show_video_output (EmpathyCallWindow *self,
379 if (self->priv->video_output != NULL)
380 g_object_set (self->priv->video_output, "visible", show, NULL);
382 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
384 clutter_actor_raise_top (self->priv->floating_toolbar);
388 create_video_output_widget (EmpathyCallWindow *self)
390 EmpathyCallWindowPriv *priv = GET_PRIV (self);
392 g_assert (priv->video_output == NULL);
393 g_assert (priv->pipeline != NULL);
395 priv->video_output = clutter_texture_new ();
397 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
400 priv->video_output_sink = clutter_gst_video_sink_new (
401 CLUTTER_TEXTURE (priv->video_output));
403 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
406 gtk_widget_add_events (priv->video_container,
407 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
408 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
409 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
413 create_video_input (EmpathyCallWindow *self)
415 EmpathyCallWindowPriv *priv = GET_PRIV (self);
417 g_assert (priv->video_input == NULL);
418 priv->video_input = empathy_video_src_new ();
419 gst_object_ref (priv->video_input);
420 gst_object_sink (priv->video_input);
424 create_audio_input (EmpathyCallWindow *self)
426 EmpathyCallWindowPriv *priv = GET_PRIV (self);
428 g_assert (priv->audio_input == NULL);
429 priv->audio_input = empathy_audio_src_new ();
430 gst_object_ref (priv->audio_input);
431 gst_object_sink (priv->audio_input);
435 add_video_preview_to_pipeline (EmpathyCallWindow *self)
437 EmpathyCallWindowPriv *priv = GET_PRIV (self);
440 g_assert (priv->video_preview != NULL);
441 g_assert (priv->pipeline != NULL);
442 g_assert (priv->video_input != NULL);
443 g_assert (priv->video_tee != NULL);
445 preview = priv->video_preview_sink;
447 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
449 g_warning ("Could not add video input to pipeline");
453 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
455 g_warning ("Could not add video preview to pipeline");
459 if (!gst_element_link (priv->video_input, priv->video_tee))
461 g_warning ("Could not link video input to video tee");
465 if (!gst_element_link (priv->video_tee, preview))
467 g_warning ("Could not link video tee to video preview");
473 empathy_call_window_disable_camera_cb (GtkAction *action,
474 EmpathyCallWindow *self)
476 clutter_actor_destroy (self->priv->preview_hidden_button);
478 gtk_toggle_tool_button_set_active (
479 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
483 empathy_call_window_minimise_camera_cb (GtkAction *action,
484 EmpathyCallWindow *self)
486 clutter_actor_hide (self->priv->video_preview);
487 clutter_actor_show (self->priv->preview_hidden_button);
491 empathy_call_window_maximise_camera_cb (GtkAction *action,
492 EmpathyCallWindow *self)
494 clutter_actor_show (self->priv->video_preview);
495 clutter_actor_hide (self->priv->preview_hidden_button);
499 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
500 EmpathyCallWindow *self)
504 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
506 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
507 0, gtk_get_current_event_time ());
508 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
512 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
513 EmpathyCallWindow *self)
517 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
518 "/preview-hidden-menu");
519 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
520 0, gtk_get_current_event_time ());
521 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
525 create_video_preview (EmpathyCallWindow *self)
527 EmpathyCallWindowPriv *priv = GET_PRIV (self);
528 ClutterLayoutManager *layout, *layout_center;
529 ClutterActor *preview;
534 g_assert (priv->video_preview == NULL);
536 preview = clutter_texture_new ();
537 clutter_actor_set_size (preview,
538 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
539 priv->video_preview_sink = clutter_gst_video_sink_new (
540 CLUTTER_TEXTURE (preview));
542 /* Flip the video preview */
543 clutter_actor_set_rotation (preview,
546 SELF_VIDEO_SECTION_WIDTH * 0.5,
550 /* Add a little offset to the video preview */
551 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
552 CLUTTER_BIN_ALIGNMENT_START);
553 priv->video_preview = clutter_box_new (layout);
554 clutter_actor_set_size (priv->video_preview,
555 SELF_VIDEO_SECTION_WIDTH + 10,
556 SELF_VIDEO_SECTION_HEIGTH + 10 +
557 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
559 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
560 CLUTTER_BIN_ALIGNMENT_CENTER);
561 box = clutter_box_new (layout_center);
562 clutter_actor_set_size (box,
563 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
565 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
566 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
568 g_object_set (priv->video_preview_sink,
573 /* Translators: this is an "Info" label. It should be as short
575 button = gtk_button_new_with_label (_("i"));
576 b = gtk_clutter_actor_new_with_contents (button);
578 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
580 CLUTTER_BIN_ALIGNMENT_END,
581 CLUTTER_BIN_ALIGNMENT_END);
583 g_signal_connect (button, "clicked",
584 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
587 /* Translators: this is an "Info" label. It should be as short
589 button = gtk_button_new_with_label (_("i"));
590 priv->preview_hidden_button =
591 gtk_clutter_actor_new_with_contents (button);
593 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
594 priv->preview_hidden_button,
595 CLUTTER_BIN_ALIGNMENT_START,
596 CLUTTER_BIN_ALIGNMENT_END);
598 clutter_actor_hide (priv->preview_hidden_button);
600 g_signal_connect (button, "clicked",
601 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
604 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
606 CLUTTER_BIN_ALIGNMENT_START,
607 CLUTTER_BIN_ALIGNMENT_END);
611 play_camera (EmpathyCallWindow *window,
614 EmpathyCallWindowPriv *priv = GET_PRIV (window);
618 if (priv->video_preview == NULL)
620 create_video_preview (window);
621 add_video_preview_to_pipeline (window);
625 state = GST_STATE_PLAYING;
627 state = GST_STATE_NULL;
629 preview = priv->video_preview_sink;
631 gst_element_set_state (preview, state);
632 gst_element_set_state (priv->video_input, state);
633 gst_element_set_state (priv->video_tee, state);
637 display_video_preview (EmpathyCallWindow *self,
640 EmpathyCallWindowPriv *priv = GET_PRIV (self);
644 /* Display the video preview */
645 DEBUG ("Show video preview");
647 play_camera (self, TRUE);
648 clutter_actor_show (priv->video_preview);
652 /* Hide the video preview */
653 DEBUG ("Hide video preview");
655 if (priv->video_preview != NULL)
657 clutter_actor_hide (priv->video_preview);
658 play_camera (self, FALSE);
664 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
666 EmpathyCallWindowPriv *priv = GET_PRIV (window);
668 empathy_call_window_status_message (window, _("Connecting…"));
669 priv->call_state = CONNECTING;
672 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
673 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
677 disable_camera (EmpathyCallWindow *self)
679 EmpathyCallWindowPriv *priv = GET_PRIV (self);
681 if (priv->camera_state == CAMERA_STATE_OFF)
684 DEBUG ("Disable camera");
686 display_video_preview (self, FALSE);
688 if (priv->camera_state == CAMERA_STATE_ON)
689 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
691 priv->camera_state = CAMERA_STATE_OFF;
695 enable_camera (EmpathyCallWindow *self)
697 EmpathyCallWindowPriv *priv = GET_PRIV (self);
699 if (priv->camera_state == CAMERA_STATE_ON)
702 if (priv->video_input == NULL)
704 DEBUG ("Can't enable camera, no input");
708 DEBUG ("Enable camera");
710 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
712 priv->camera_state = CAMERA_STATE_ON;
716 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
717 EmpathyCallWindow *self)
719 if (gtk_toggle_tool_button_get_active (toggle))
720 enable_camera (self);
722 disable_camera (self);
726 create_pipeline (EmpathyCallWindow *self)
728 EmpathyCallWindowPriv *priv = GET_PRIV (self);
731 g_assert (priv->pipeline == NULL);
733 priv->pipeline = gst_pipeline_new (NULL);
734 priv->pipeline_playing = FALSE;
736 priv->video_tee = gst_element_factory_make ("tee", NULL);
737 gst_object_ref (priv->video_tee);
738 gst_object_sink (priv->video_tee);
740 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
742 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
743 priv->bus_message_source_id = gst_bus_add_watch (bus,
744 empathy_call_window_bus_message, self);
746 g_object_unref (bus);
750 empathy_call_window_settings_cb (GtkAction *action,
751 EmpathyCallWindow *self)
753 gchar *args = g_strdup_printf ("-p %s",
754 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
756 empathy_launch_program (BIN_DIR, "empathy", args);
762 empathy_call_window_contents_cb (GtkAction *action,
763 EmpathyCallWindow *self)
765 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
769 empathy_call_window_debug_cb (GtkAction *action,
770 EmpathyCallWindow *self)
772 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
776 empathy_call_window_about_cb (GtkAction *action,
777 EmpathyCallWindow *self)
779 empathy_about_dialog_new (GTK_WINDOW (self));
783 empathy_call_window_toolbar_timeout (gpointer data)
785 EmpathyCallWindow *self = data;
787 clutter_state_set_state (self->priv->transitions, "fade-out");
793 empathy_call_window_motion_notify_cb (GtkWidget *widget,
795 EmpathyCallWindow *self)
797 clutter_state_set_state (self->priv->transitions, "fade-in");
799 if (self->priv->inactivity_src > 0)
800 g_source_remove (self->priv->inactivity_src);
802 self->priv->inactivity_src = g_timeout_add_seconds (3,
803 empathy_call_window_toolbar_timeout, self);
809 empathy_call_window_configure_event_cb (GtkWidget *widget,
811 EmpathyCallWindow *self)
813 GdkWindow *gdk_window;
814 GdkWindowState window_state;
816 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
817 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
819 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
820 &self->priv->dialpad_width, NULL);
822 gdk_window = gtk_widget_get_window (widget);
823 window_state = gdk_window_get_state (gdk_window);
824 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
830 empathy_call_window_destroyed_cb (GtkWidget *object,
831 EmpathyCallWindow *self)
833 if (gtk_widget_get_visible (self->priv->dtmf_panel))
835 /* Save the geometry as if the dialpad was hidden. */
836 empathy_geometry_save_values (GTK_WINDOW (self),
837 self->priv->x, self->priv->y,
838 self->priv->w - self->priv->dialpad_width, self->priv->h,
839 self->priv->maximized);
844 empathy_call_window_video_box_allocation_changed_cb (ClutterActor *video_box,
846 ClutterBindConstraint *constraint)
848 ClutterActorBox allocation;
850 clutter_actor_get_allocation_box (video_box, &allocation);
852 clutter_bind_constraint_set_offset (constraint,
853 allocation.y2 - allocation.y1 -
854 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
858 empathy_call_window_init (EmpathyCallWindow *self)
860 EmpathyCallWindowPriv *priv;
864 ClutterConstraint *constraint;
865 ClutterActor *remote_avatar;
866 GtkStyleContext *context;
870 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
871 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
873 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
874 gui = empathy_builder_get_file (filename,
875 "call_window_vbox", &top_vbox,
876 "errors_vbox", &priv->errors_vbox,
878 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
879 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
880 "status_label", &priv->status_label,
881 "audiocall", &priv->audio_call_button,
882 "videocall", &priv->video_call_button,
883 "microphone", &priv->mic_button,
884 "camera", &priv->camera_button,
885 "hangup", &priv->hangup_button,
886 "dialpad", &priv->dialpad_button,
887 "toolbar", &priv->toolbar,
888 "bottom_toolbar", &priv->bottom_toolbar,
889 "ui_manager", &priv->ui_manager,
890 "menufullscreen", &priv->menu_fullscreen,
891 "details_vbox", &priv->details_vbox,
892 "vcodec_encoding_label", &priv->vcodec_encoding_label,
893 "acodec_encoding_label", &priv->acodec_encoding_label,
894 "acodec_decoding_label", &priv->acodec_decoding_label,
895 "vcodec_decoding_label", &priv->vcodec_decoding_label,
896 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
897 "audio_local_candidate_label", &priv->audio_local_candidate_label,
898 "video_remote_candidate_label", &priv->video_remote_candidate_label,
899 "video_local_candidate_label", &priv->video_local_candidate_label,
900 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
901 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
902 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
903 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
907 empathy_builder_connect (gui, self,
908 "hangup", "clicked", empathy_call_window_hangup_cb,
909 "audiocall", "clicked", empathy_call_window_audio_call_cb,
910 "videocall", "clicked", empathy_call_window_video_call_cb,
911 "volume", "value-changed", empathy_call_window_volume_changed_cb,
912 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
913 "camera", "toggled", empathy_call_window_camera_toggled_cb,
914 "dialpad", "toggled", empathy_call_window_dialpad_cb,
915 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
916 "menusettings", "activate", empathy_call_window_settings_cb,
917 "menucontents", "activate", empathy_call_window_contents_cb,
918 "menudebug", "activate", empathy_call_window_debug_cb,
919 "menuabout", "activate", empathy_call_window_about_cb,
920 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
921 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
922 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
925 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
927 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
929 g_object_bind_property (priv->camera_monitor, "available",
930 priv->camera_button, "sensitive",
931 G_BINDING_SYNC_CREATE);
933 priv->lock = g_mutex_new ();
935 gtk_container_add (GTK_CONTAINER (self), top_vbox);
937 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
938 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
939 CONTENT_HBOX_BORDER_WIDTH);
940 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
943 /* avatar/video box */
944 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
945 CLUTTER_BIN_ALIGNMENT_CENTER);
947 priv->video_box = clutter_box_new (priv->video_layout);
949 priv->video_container = gtk_clutter_embed_new ();
951 /* Set the background color to that of the rest of the window */
952 context = gtk_widget_get_style_context (priv->content_hbox);
953 gtk_style_context_get_background_color (context,
954 GTK_STATE_FLAG_NORMAL, &rgba);
955 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
956 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
957 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
958 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
959 clutter_stage_set_color (
960 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
961 GTK_CLUTTER_EMBED (priv->video_container))),
964 clutter_container_add (
965 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
966 GTK_CLUTTER_EMBED (priv->video_container))),
970 constraint = clutter_bind_constraint_new (
971 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
972 CLUTTER_BIND_SIZE, 0);
973 clutter_actor_add_constraint (priv->video_box, constraint);
975 priv->remote_user_avatar_widget = gtk_image_new ();
976 remote_avatar = gtk_clutter_actor_new_with_contents (
977 priv->remote_user_avatar_widget);
979 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
982 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
983 priv->video_container, TRUE, TRUE,
984 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
986 create_pipeline (self);
987 create_video_output_widget (self);
988 create_audio_input (self);
989 create_video_input (self);
991 priv->floating_toolbar = empathy_rounded_actor_new ();
993 gtk_widget_reparent (priv->bottom_toolbar,
994 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
996 constraint = clutter_bind_constraint_new (priv->video_box,
999 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1001 g_signal_connect (priv->video_box, "notify::allocation",
1002 G_CALLBACK (empathy_call_window_video_box_allocation_changed_cb),
1005 clutter_actor_set_size (priv->floating_toolbar,
1006 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1007 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1009 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1010 priv->floating_toolbar,
1011 CLUTTER_BIN_ALIGNMENT_CENTER,
1012 CLUTTER_BIN_ALIGNMENT_END);
1014 clutter_actor_raise_top (priv->floating_toolbar);
1016 /* Transitions for the floating toolbar */
1017 priv->transitions = clutter_state_new ();
1019 /* all transitions last for 2s */
1020 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1022 /* transition from any state to "fade-out" state */
1023 clutter_state_set (priv->transitions, NULL, "fade-out",
1024 priv->floating_toolbar,
1025 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1028 /* transition from any state to "fade-in" state */
1029 clutter_state_set (priv->transitions, NULL, "fade-in",
1030 priv->floating_toolbar,
1031 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1034 /* put the actor into the "fade-in" state with no animation */
1035 clutter_state_warp_to_state (priv->transitions, "fade-in");
1037 /* The call will be started as soon the pipeline is playing */
1038 priv->start_call_when_playing = TRUE;
1040 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1041 G_CALLBACK (dtmf_button_pressed_cb),
1042 G_CALLBACK (dtmf_button_released_cb));
1044 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1047 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1050 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1052 gtk_widget_show_all (top_vbox);
1054 gtk_widget_hide (priv->dtmf_panel);
1055 gtk_widget_hide (priv->details_vbox);
1057 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1059 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1060 priv->video_container);
1062 /* We hide the bottom toolbar after 3s of inactivity and show it
1063 * again on mouse movement */
1064 priv->inactivity_src = g_timeout_add_seconds (3,
1065 empathy_call_window_toolbar_timeout, self);
1067 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1068 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1070 g_signal_connect (G_OBJECT (self), "realize",
1071 G_CALLBACK (empathy_call_window_realized_cb), self);
1073 g_signal_connect (G_OBJECT (self), "delete-event",
1074 G_CALLBACK (empathy_call_window_delete_cb), self);
1076 g_signal_connect (G_OBJECT (self), "window-state-event",
1077 G_CALLBACK (empathy_call_window_state_event_cb), self);
1079 g_signal_connect (G_OBJECT (self), "key-press-event",
1080 G_CALLBACK (empathy_call_window_key_press_cb), self);
1082 g_signal_connect (self, "motion-notify-event",
1083 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1085 priv->timer = g_timer_new ();
1087 g_object_ref (priv->ui_manager);
1088 g_object_unref (gui);
1090 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1091 priv->mic_menu = empathy_mic_menu_new (self);
1093 empathy_call_window_show_hangup_button (self, TRUE);
1095 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1096 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1097 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1099 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1100 /* These signals are used to track the window position and save it
1101 * when the window is destroyed. We need to do this as we don't want
1102 * the window geometry to be saved with the dialpad taken into account. */
1103 g_signal_connect (self, "destroy",
1104 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1105 g_signal_connect (self, "configure-event",
1106 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1107 g_signal_connect (self, "window-state-event",
1108 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1110 /* Don't display labels in both toolbars */
1111 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1114 /* Instead of specifying a width and a height, we specify only one size. That's
1115 because we want a square avatar icon. */
1117 init_contact_avatar_with_size (EmpathyContact *contact,
1118 GtkWidget *image_widget,
1121 GdkPixbuf *pixbuf_avatar = NULL;
1123 if (contact != NULL)
1125 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1129 if (pixbuf_avatar == NULL)
1131 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1132 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1135 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1137 if (pixbuf_avatar != NULL)
1138 g_object_unref (pixbuf_avatar);
1142 set_window_title (EmpathyCallWindow *self)
1144 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1147 if (priv->contact != NULL)
1149 /* translators: Call is a noun and %s is the contact name. This string
1150 * is used in the window title */
1151 tmp = g_strdup_printf (_("Call with %s"),
1152 empathy_contact_get_alias (priv->contact));
1153 gtk_window_set_title (GTK_WINDOW (self), tmp);
1158 g_warning ("Unknown remote contact!");
1163 set_remote_user_name (EmpathyCallWindow *self,
1164 EmpathyContact *contact)
1166 const gchar *alias = empathy_contact_get_alias (contact);
1167 const gchar *status = empathy_contact_get_status (contact);
1170 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1171 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1177 contact_name_changed_cb (EmpathyContact *contact,
1179 EmpathyCallWindow *self)
1181 set_window_title (self);
1182 set_remote_user_name (self, contact);
1186 contact_presence_changed_cb (EmpathyContact *contact,
1188 EmpathyCallWindow *self)
1190 set_remote_user_name (self, contact);
1194 contact_avatar_changed_cb (EmpathyContact *contact,
1196 EmpathyCallWindow *self)
1199 GtkAllocation allocation;
1200 GtkWidget *avatar_widget;
1202 avatar_widget = self->priv->remote_user_avatar_widget;
1204 gtk_widget_get_allocation (avatar_widget, &allocation);
1205 size = allocation.height;
1209 /* the widget is not allocated yet, set a default size */
1210 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1211 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1214 init_contact_avatar_with_size (contact, avatar_widget, size);
1216 avatar_widget = self->priv->remote_user_avatar_toolbar;
1218 gtk_widget_get_allocation (avatar_widget, &allocation);
1219 size = allocation.height;
1223 /* the widget is not allocated yet, set a default size */
1224 size = SMALL_TOOLBAR_SIZE;
1227 init_contact_avatar_with_size (contact, avatar_widget, size);
1231 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1232 EmpathyCallHandler *handler)
1234 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1236 tp_g_signal_connect_object (priv->contact, "notify::name",
1237 G_CALLBACK (contact_name_changed_cb), self, 0);
1238 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1239 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1240 tp_g_signal_connect_object (priv->contact, "notify::presence",
1241 G_CALLBACK (contact_presence_changed_cb), self, 0);
1243 set_window_title (self);
1244 set_remote_user_name (self, priv->contact);
1246 init_contact_avatar_with_size (priv->contact,
1247 priv->remote_user_avatar_widget,
1248 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1249 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1251 init_contact_avatar_with_size (priv->contact,
1252 priv->remote_user_avatar_toolbar,
1253 SMALL_TOOLBAR_SIZE);
1255 /* The remote avatar is shown by default and will be hidden when we receive
1256 video from the remote side. */
1257 clutter_actor_hide (priv->video_output);
1258 gtk_widget_show (priv->remote_user_avatar_widget);
1262 update_send_codec (EmpathyCallWindow *self,
1265 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1272 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1273 widget = priv->acodec_encoding_label;
1277 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1278 widget = priv->vcodec_encoding_label;
1284 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1285 gtk_label_set_text (GTK_LABEL (widget), tmp);
1290 send_audio_codec_notify_cb (GObject *object,
1294 EmpathyCallWindow *self = user_data;
1296 update_send_codec (self, TRUE);
1300 send_video_codec_notify_cb (GObject *object,
1304 EmpathyCallWindow *self = user_data;
1306 update_send_codec (self, FALSE);
1310 update_recv_codec (EmpathyCallWindow *self,
1313 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1316 GString *str = NULL;
1320 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1321 widget = priv->acodec_decoding_label;
1325 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1326 widget = priv->vcodec_decoding_label;
1332 for (l = codecs; l != NULL; l = g_list_next (l))
1334 FsCodec *codec = l->data;
1337 str = g_string_new (NULL);
1339 g_string_append (str, ", ");
1341 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1345 gtk_label_set_text (GTK_LABEL (widget), str->str);
1346 g_string_free (str, TRUE);
1350 recv_audio_codecs_notify_cb (GObject *object,
1354 EmpathyCallWindow *self = user_data;
1356 update_recv_codec (self, TRUE);
1360 recv_video_codecs_notify_cb (GObject *object,
1364 EmpathyCallWindow *self = user_data;
1366 update_recv_codec (self, FALSE);
1369 static const gchar *
1370 candidate_type_to_str (FsCandidate *candidate)
1372 switch (candidate->type)
1374 case FS_CANDIDATE_TYPE_HOST:
1376 case FS_CANDIDATE_TYPE_SRFLX:
1377 return "server reflexive";
1378 case FS_CANDIDATE_TYPE_PRFLX:
1379 return "peer reflexive";
1380 case FS_CANDIDATE_TYPE_RELAY:
1382 case FS_CANDIDATE_TYPE_MULTICAST:
1389 static const gchar *
1390 candidate_type_to_desc (FsCandidate *candidate)
1392 switch (candidate->type)
1394 case FS_CANDIDATE_TYPE_HOST:
1395 return _("The IP address as seen by the machine");
1396 case FS_CANDIDATE_TYPE_SRFLX:
1397 return _("The IP address as seen by a server on the Internet");
1398 case FS_CANDIDATE_TYPE_PRFLX:
1399 return _("The IP address of the peer as seen by the other side");
1400 case FS_CANDIDATE_TYPE_RELAY:
1401 return _("The IP address of a relay server");
1402 case FS_CANDIDATE_TYPE_MULTICAST:
1403 return _("The IP address of the multicast group");
1410 update_candidat_widget (EmpathyCallWindow *self,
1413 FsCandidate *candidate)
1417 g_assert (candidate != NULL);
1418 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1419 candidate->port, candidate_type_to_str (candidate));
1421 gtk_label_set_text (GTK_LABEL (label), str);
1422 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1428 candidates_changed_cb (GObject *object,
1430 EmpathyCallWindow *self)
1432 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1433 FsCandidate *candidate = NULL;
1435 if (type == FS_MEDIA_TYPE_VIDEO)
1437 /* Update remote candidate */
1438 candidate = empathy_call_handler_get_video_remote_candidate (
1441 update_candidat_widget (self, priv->video_remote_candidate_label,
1442 priv->video_remote_candidate_info_img, candidate);
1444 /* Update local candidate */
1445 candidate = empathy_call_handler_get_video_local_candidate (
1448 update_candidat_widget (self, priv->video_local_candidate_label,
1449 priv->video_local_candidate_info_img, candidate);
1453 /* Update remote candidate */
1454 candidate = empathy_call_handler_get_audio_remote_candidate (
1457 update_candidat_widget (self, priv->audio_remote_candidate_label,
1458 priv->audio_remote_candidate_info_img, candidate);
1460 /* Update local candidate */
1461 candidate = empathy_call_handler_get_audio_local_candidate (
1464 update_candidat_widget (self, priv->audio_local_candidate_label,
1465 priv->audio_local_candidate_info_img, candidate);
1470 empathy_call_window_constructed (GObject *object)
1472 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1473 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1474 TpyCallChannel *call;
1476 g_assert (priv->handler != NULL);
1478 g_object_get (priv->handler, "call-channel", &call, NULL);
1479 priv->outgoing = (call == NULL);
1481 g_object_unref (call);
1483 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1484 g_assert (priv->contact != NULL);
1486 empathy_call_window_setup_avatars (self, priv->handler);
1487 empathy_call_window_set_state_connecting (self);
1489 if (!empathy_call_handler_has_initial_video (priv->handler))
1491 gtk_toggle_tool_button_set_active (
1492 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1494 /* If call has InitialVideo, the preview will be started once the call has
1495 * been started (start_call()). */
1497 update_send_codec (self, TRUE);
1498 update_send_codec (self, FALSE);
1499 update_recv_codec (self, TRUE);
1500 update_recv_codec (self, FALSE);
1502 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1503 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1504 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1505 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1506 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1507 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1508 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1509 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1511 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1512 G_CALLBACK (candidates_changed_cb), self, 0);
1515 static void empathy_call_window_dispose (GObject *object);
1516 static void empathy_call_window_finalize (GObject *object);
1519 empathy_call_window_set_property (GObject *object,
1520 guint property_id, const GValue *value, GParamSpec *pspec)
1522 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1524 switch (property_id)
1526 case PROP_CALL_HANDLER:
1527 priv->handler = g_value_dup_object (value);
1530 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1535 empathy_call_window_get_property (GObject *object,
1536 guint property_id, GValue *value, GParamSpec *pspec)
1538 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1540 switch (property_id)
1542 case PROP_CALL_HANDLER:
1543 g_value_set_object (value, priv->handler);
1546 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1551 empathy_call_window_class_init (
1552 EmpathyCallWindowClass *empathy_call_window_class)
1554 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1555 GParamSpec *param_spec;
1557 g_type_class_add_private (empathy_call_window_class,
1558 sizeof (EmpathyCallWindowPriv));
1560 object_class->constructed = empathy_call_window_constructed;
1561 object_class->set_property = empathy_call_window_set_property;
1562 object_class->get_property = empathy_call_window_get_property;
1564 object_class->dispose = empathy_call_window_dispose;
1565 object_class->finalize = empathy_call_window_finalize;
1567 param_spec = g_param_spec_object ("handler",
1568 "handler", "The call handler",
1569 EMPATHY_TYPE_CALL_HANDLER,
1570 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1571 g_object_class_install_property (object_class,
1572 PROP_CALL_HANDLER, param_spec);
1576 empathy_call_window_dispose (GObject *object)
1578 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1579 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1581 if (priv->dispose_has_run)
1584 priv->dispose_has_run = TRUE;
1586 if (priv->handler != NULL)
1588 empathy_call_handler_stop_call (priv->handler);
1589 tp_clear_object (&priv->handler);
1592 if (priv->bus_message_source_id != 0)
1594 g_source_remove (priv->bus_message_source_id);
1595 priv->bus_message_source_id = 0;
1598 if (priv->got_video_src > 0)
1600 g_source_remove (priv->got_video_src);
1601 priv->got_video_src = 0;
1604 if (priv->inactivity_src > 0)
1606 g_source_remove (priv->inactivity_src);
1607 priv->inactivity_src = 0;
1610 tp_clear_object (&priv->pipeline);
1611 tp_clear_object (&priv->video_input);
1612 tp_clear_object (&priv->audio_input);
1613 tp_clear_object (&priv->video_tee);
1614 tp_clear_object (&priv->ui_manager);
1615 tp_clear_object (&priv->fullscreen);
1616 tp_clear_object (&priv->camera_monitor);
1617 tp_clear_object (&priv->settings);
1618 tp_clear_object (&priv->transitions);
1620 g_list_free_full (priv->notifiers, g_object_unref);
1622 if (priv->timer_id != 0)
1623 g_source_remove (priv->timer_id);
1626 if (priv->contact != NULL)
1628 g_signal_handlers_disconnect_by_func (priv->contact,
1629 contact_name_changed_cb, self);
1630 priv->contact = NULL;
1634 tp_clear_object (&priv->sound_mgr);
1636 tp_clear_object (&priv->mic_menu);
1638 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1642 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1644 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1646 if (priv->video_output_motion_handler_id != 0)
1648 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1649 priv->video_output_motion_handler_id);
1650 priv->video_output_motion_handler_id = 0;
1655 empathy_call_window_finalize (GObject *object)
1657 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1658 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1660 disconnect_video_output_motion_handler (self);
1662 /* free any data held directly by the object here */
1663 g_mutex_free (priv->lock);
1665 g_timer_destroy (priv->timer);
1667 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1672 empathy_call_window_new (EmpathyCallHandler *handler)
1674 return EMPATHY_CALL_WINDOW (
1675 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1679 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1680 GstElement *conference, gpointer user_data)
1682 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1683 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1684 FsElementAddedNotifier *notifier;
1687 DEBUG ("Conference added");
1689 /* Add notifier to set the various element properties as needed */
1690 notifier = fs_element_added_notifier_new ();
1691 keyfile = fs_utils_get_default_element_properties (conference);
1693 if (keyfile != NULL)
1694 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1696 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1698 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1700 gst_bin_add (GST_BIN (priv->pipeline), conference);
1701 gst_element_set_state (conference, GST_STATE_PLAYING);
1705 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1706 GstElement *conference, gpointer user_data)
1708 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1709 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1711 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1712 gst_element_set_state (conference, GST_STATE_NULL);
1716 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1718 GstStateChangeReturn state_change_return;
1719 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1721 if (priv->pipeline == NULL)
1724 if (priv->bus_message_source_id != 0)
1726 g_source_remove (priv->bus_message_source_id);
1727 priv->bus_message_source_id = 0;
1730 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1732 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1733 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1735 if (priv->pipeline != NULL)
1736 g_object_unref (priv->pipeline);
1737 priv->pipeline = NULL;
1739 if (priv->audio_output != NULL)
1740 g_object_unref (priv->audio_output);
1741 priv->audio_output = NULL;
1743 if (priv->video_tee != NULL)
1744 g_object_unref (priv->video_tee);
1745 priv->video_tee = NULL;
1747 if (priv->video_preview != NULL)
1748 clutter_actor_destroy (priv->video_preview);
1749 priv->video_preview = NULL;
1751 priv->funnel = NULL;
1753 create_pipeline (self);
1754 /* Call will be started when user will hit the 'redial' button */
1755 priv->start_call_when_playing = FALSE;
1756 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1762 g_message ("Error: could not destroy pipeline. Closing call window");
1763 gtk_widget_destroy (GTK_WIDGET (self));
1770 reset_details_pane (EmpathyCallWindow *self)
1772 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1774 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1775 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1776 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1777 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1781 empathy_call_window_disconnected (EmpathyCallWindow *self,
1784 gboolean could_disconnect = FALSE;
1785 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1786 gboolean could_reset_pipeline;
1788 /* Leave full screen mode if needed */
1789 gtk_window_unfullscreen (GTK_WINDOW (self));
1791 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1792 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1794 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1796 if (priv->call_state == CONNECTING)
1797 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1799 if (priv->call_state != REDIALING)
1800 priv->call_state = DISCONNECTED;
1802 if (could_reset_pipeline)
1804 g_mutex_lock (priv->lock);
1806 g_timer_stop (priv->timer);
1808 if (priv->timer_id != 0)
1809 g_source_remove (priv->timer_id);
1812 g_mutex_unlock (priv->lock);
1815 /* We are about to destroy the window, no need to update it or create
1816 * a video preview */
1819 empathy_call_window_status_message (self, _("Disconnected"));
1821 empathy_call_window_show_hangup_button (self, FALSE);
1823 /* Unsensitive the camera and mic button */
1824 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1825 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1827 /* Be sure that the mic button is enabled */
1828 gtk_toggle_tool_button_set_active (
1829 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1831 if (priv->camera_state == CAMERA_STATE_ON)
1833 /* Restart the preview with the new pipeline. */
1834 display_video_preview (self, TRUE);
1837 /* destroy the video output; it will be recreated when we'll redial */
1838 disconnect_video_output_motion_handler (self);
1839 if (priv->video_output != NULL)
1840 clutter_actor_destroy (priv->video_output);
1841 priv->video_output = NULL;
1842 if (priv->got_video_src > 0)
1844 g_source_remove (priv->got_video_src);
1845 priv->got_video_src = 0;
1848 gtk_widget_show (priv->remote_user_avatar_widget);
1850 reset_details_pane (self);
1852 priv->sending_video = FALSE;
1853 priv->call_started = FALSE;
1855 could_disconnect = TRUE;
1857 /* TODO: display the self avatar of the preview (depends if the "Always
1858 * Show Video Preview" is enabled or not) */
1861 return could_disconnect;
1866 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1869 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1870 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1872 if (empathy_call_window_disconnected (self, TRUE) &&
1873 priv->call_state == REDIALING)
1874 empathy_call_window_restart_call (self);
1878 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1880 FsMediaType media_type,
1881 EmpathyCallWindow *self)
1883 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1885 DEBUG ("removing content");
1888 * This assumes that there is only one video stream per channel...
1891 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1893 if (priv->funnel != NULL)
1897 output = priv->video_output_sink;
1899 gst_element_set_state (output, GST_STATE_NULL);
1900 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1902 gst_bin_remove (GST_BIN (priv->pipeline), output);
1903 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1904 priv->funnel = NULL;
1908 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1910 if (priv->audio_output != NULL)
1912 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1914 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1915 priv->audio_output = NULL;
1923 /* Called with global lock held */
1925 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1927 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1931 if (priv->funnel == NULL)
1933 output = priv->video_output_sink;
1935 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1939 g_warning ("Could not create fsfunnel");
1943 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1945 gst_object_unref (priv->funnel);
1946 priv->funnel = NULL;
1947 g_warning ("Could not add funnel to pipeline");
1951 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1953 g_warning ("Could not add the video output widget to the pipeline");
1957 if (!gst_element_link (priv->funnel, output))
1959 g_warning ("Could not link output sink to funnel");
1960 goto error_output_added;
1963 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1965 g_warning ("Could not start video sink");
1966 goto error_output_added;
1969 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1971 g_warning ("Could not start funnel");
1972 goto error_output_added;
1976 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1979 g_warning ("Could not get request pad from funnel");
1986 gst_element_set_locked_state (priv->funnel, TRUE);
1987 gst_element_set_locked_state (output, TRUE);
1989 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1990 gst_element_set_state (output, GST_STATE_NULL);
1992 gst_bin_remove (GST_BIN (priv->pipeline), output);
1993 gst_element_set_locked_state (output, FALSE);
1997 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1998 priv->funnel = NULL;
2003 /* Called with global lock held */
2005 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2007 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2009 GstPadTemplate *template;
2011 if (priv->audio_output == NULL)
2013 priv->audio_output = empathy_audio_sink_new ();
2014 g_object_ref_sink (priv->audio_output);
2016 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2018 g_warning ("Could not add audio sink to pipeline");
2019 g_object_unref (priv->audio_output);
2020 goto error_add_output;
2023 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2025 g_warning ("Could not start audio sink");
2030 template = gst_element_class_get_pad_template (
2031 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2033 pad = gst_element_request_pad (priv->audio_output,
2034 template, NULL, NULL);
2038 g_warning ("Could not get sink pad from sink");
2045 gst_element_set_locked_state (priv->audio_output, TRUE);
2046 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2047 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2048 priv->audio_output = NULL;
2056 empathy_call_window_update_timer (gpointer user_data)
2058 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2059 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2060 const gchar *status;
2064 time_ = g_timer_elapsed (priv->timer, NULL);
2066 if (priv->call_state == HELD)
2067 status = _("On hold");
2068 else if (!gtk_toggle_tool_button_get_active (
2069 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2072 status = _("Duration");
2074 /* Translators: 'status - minutes:seconds' the caller has been connected */
2075 str = g_strdup_printf (_("%s — %d:%02dm"),
2077 (int) time_ / 60, (int) time_ % 60);
2078 empathy_call_window_status_message (self, str);
2086 display_error (EmpathyCallWindow *self,
2087 TpyCallChannel *call,
2091 const gchar *details)
2093 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2094 GtkWidget *info_bar;
2095 GtkWidget *content_area;
2102 /* Create info bar */
2103 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2106 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2108 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2110 /* hbox containing the image and the messages vbox */
2111 hbox = gtk_hbox_new (FALSE, 3);
2112 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2115 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2116 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2118 /* vbox containing the main message and the details expander */
2119 vbox = gtk_vbox_new (FALSE, 3);
2120 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2123 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2125 label = gtk_label_new (NULL);
2126 gtk_label_set_markup (GTK_LABEL (label), txt);
2127 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2128 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2131 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2134 if (details != NULL)
2136 GtkWidget *expander;
2138 expander = gtk_expander_new (_("Technical Details"));
2140 txt = g_strdup_printf ("<i>%s</i>", details);
2142 label = gtk_label_new (NULL);
2143 gtk_label_set_markup (GTK_LABEL (label), txt);
2144 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2145 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2148 gtk_container_add (GTK_CONTAINER (expander), label);
2149 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2152 g_signal_connect (info_bar, "response",
2153 G_CALLBACK (gtk_widget_destroy), NULL);
2155 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2156 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2157 gtk_widget_show_all (info_bar);
2161 media_stream_error_to_txt (EmpathyCallWindow *self,
2162 TpyCallChannel *call,
2164 TpMediaStreamError error)
2166 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2167 const gchar *cm = NULL;
2173 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2175 return g_strdup_printf (
2176 _("%s's software does not understand any of the audio formats "
2177 "supported by your computer"),
2178 empathy_contact_get_alias (priv->contact));
2180 return g_strdup_printf (
2181 _("%s's software does not understand any of the video formats "
2182 "supported by your computer"),
2183 empathy_contact_get_alias (priv->contact));
2185 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2186 return g_strdup_printf (
2187 _("Can't establish a connection to %s. "
2188 "One of you might be on a network that does not allow "
2189 "direct connections."),
2190 empathy_contact_get_alias (priv->contact));
2192 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2193 return g_strdup (_("There was a failure on the network"));
2195 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2197 return g_strdup (_("The audio formats necessary for this call "
2198 "are not installed on your computer"));
2200 return g_strdup (_("The video formats necessary for this call "
2201 "are not installed on your computer"));
2203 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2204 tp_connection_parse_object_path (
2205 tp_channel_borrow_connection (TP_CHANNEL (call)),
2208 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2209 "product=Telepathy&component=%s", cm);
2211 result = g_strdup_printf (
2212 _("Something unexpected happened in a Telepathy component. "
2213 "Please <a href=\"%s\">report this bug</a> and attach "
2214 "logs gathered from the 'Debug' window in the Help menu."), url);
2220 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2221 return g_strdup (_("There was a failure in the call engine"));
2223 case TP_MEDIA_STREAM_ERROR_EOS:
2224 return g_strdup (_("The end of the stream was reached"));
2226 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2233 empathy_call_window_stream_error (EmpathyCallWindow *self,
2234 TpyCallChannel *call,
2243 desc = media_stream_error_to_txt (self, call, audio, code);
2246 /* No description, use the error message. That's not great as it's not
2247 * localized but it's better than nothing. */
2248 display_error (self, call, icon, title, msg, NULL);
2252 display_error (self, call, icon, title, desc, msg);
2258 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2261 EmpathyCallWindow *self)
2263 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2264 "gnome-stock-mic", _("Can't establish audio stream"));
2268 empathy_call_window_video_stream_error (TpyCallChannel *call,
2271 EmpathyCallWindow *self)
2273 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2274 "camera-web", _("Can't establish video stream"));
2279 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2281 EmpathyCallWindow *self)
2283 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2284 TpyCallChannel *call;
2285 gboolean can_send_video;
2287 if (state != TPY_CALL_STATE_ACCEPTED)
2290 if (priv->call_state == CONNECTED)
2293 g_timer_start (priv->timer);
2294 priv->call_state = CONNECTED;
2296 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2298 can_send_video = priv->video_input != NULL &&
2299 empathy_contact_can_voip_video (priv->contact) &&
2300 empathy_camera_monitor_get_available (priv->camera_monitor);
2302 g_object_get (priv->handler, "call-channel", &call, NULL);
2304 if (tpy_call_channel_has_dtmf (call))
2305 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2307 if (priv->video_input == NULL)
2308 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2310 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2312 empathy_call_window_show_hangup_button (self, TRUE);
2314 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2316 clutter_actor_hide (priv->video_output);
2317 gtk_widget_show (priv->remote_user_avatar_widget);
2319 g_object_unref (call);
2321 g_mutex_lock (priv->lock);
2323 priv->timer_id = g_timeout_add_seconds (1,
2324 empathy_call_window_update_timer, self);
2326 g_mutex_unlock (priv->lock);
2328 empathy_call_window_update_timer (self);
2330 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2334 empathy_call_window_show_video_output_cb (gpointer user_data)
2336 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2338 if (self->priv->video_output != NULL)
2340 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2341 clutter_actor_show (self->priv->video_output);
2342 clutter_actor_raise_top (self->priv->floating_toolbar);
2349 empathy_call_window_check_video_cb (gpointer data)
2351 EmpathyCallWindow *self = data;
2353 if (self->priv->got_video)
2355 self->priv->got_video = FALSE;
2359 /* No video in the last N seconds, display the remote avatar */
2360 empathy_call_window_show_video_output (self, FALSE);
2365 /* Called from the streaming thread */
2367 empathy_call_window_video_probe_cb (GstPad *pad,
2368 GstMiniObject *mini_obj,
2369 EmpathyCallWindow *self)
2372 if (GST_IS_EVENT (mini_obj))
2375 if (G_UNLIKELY (!self->priv->got_video))
2377 /* show the remote video */
2378 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2379 empathy_call_window_show_video_output_cb,
2380 g_object_ref (self), g_object_unref);
2382 self->priv->got_video = TRUE;
2388 /* Called from the streaming thread */
2390 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2391 GstPad *src, guint media_type, gpointer user_data)
2393 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2394 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2395 gboolean retval = FALSE;
2399 g_mutex_lock (priv->lock);
2403 case TP_MEDIA_STREAM_TYPE_AUDIO:
2404 pad = empathy_call_window_get_audio_sink_pad (self);
2406 case TP_MEDIA_STREAM_TYPE_VIDEO:
2407 g_idle_add (empathy_call_window_show_video_output_cb, self);
2408 pad = empathy_call_window_get_video_sink_pad (self);
2410 gst_pad_add_data_probe (src,
2411 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2412 if (priv->got_video_src > 0)
2413 g_source_remove (priv->got_video_src);
2414 priv->got_video_src = g_timeout_add_seconds (5,
2415 empathy_call_window_check_video_cb, self);
2418 g_assert_not_reached ();
2424 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2425 g_warning ("Could not link %s sink pad",
2426 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2430 gst_object_unref (pad);
2434 /* If no sink could be linked, try to add fakesink to prevent the whole call
2439 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2441 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2443 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2444 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2445 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2447 gst_element_set_locked_state (fakesink, TRUE);
2448 gst_element_set_state (fakesink, GST_STATE_NULL);
2449 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2453 DEBUG ("Could not link real sink, linked fakesink instead");
2455 gst_object_unref (sinkpad);
2459 gst_object_unref (fakesink);
2464 g_mutex_unlock (priv->lock);
2470 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2471 GstPad *sink, FsMediaType media_type, gpointer user_data)
2473 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2474 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2476 gboolean retval = FALSE;
2480 case FS_MEDIA_TYPE_AUDIO:
2481 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2483 g_warning ("Could not add audio source to pipeline");
2487 pad = gst_element_get_static_pad (priv->audio_input, "src");
2490 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2491 g_warning ("Could not get source pad from audio source");
2495 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2497 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2498 g_warning ("Could not link audio source to farsight");
2502 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2504 g_warning ("Could not start audio source");
2505 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2506 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2512 case FS_MEDIA_TYPE_VIDEO:
2513 if (priv->video_tee != NULL)
2515 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2516 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2518 g_warning ("Could not link video source input pipeline");
2521 gst_object_unref (pad);
2527 g_assert_not_reached ();
2534 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2536 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2537 GstElement *preview;
2539 disable_camera (self);
2541 DEBUG ("remove video input");
2542 preview = priv->video_preview_sink;
2544 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2545 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2546 gst_element_set_state (preview, GST_STATE_NULL);
2548 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2551 g_object_unref (priv->video_input);
2552 priv->video_input = NULL;
2553 g_object_unref (priv->video_tee);
2554 priv->video_tee = NULL;
2555 clutter_actor_destroy (priv->video_preview);
2556 priv->video_preview = NULL;
2558 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2562 start_call (EmpathyCallWindow *self)
2564 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2566 priv->call_started = TRUE;
2567 empathy_call_handler_start_call (priv->handler,
2568 gtk_get_current_event_time ());
2570 if (empathy_call_handler_has_initial_video (priv->handler))
2572 TpyCallChannel *call;
2575 g_object_get (priv->handler, "call-channel", &call, NULL);
2576 s = tpy_call_channel_get_video_state (call);
2578 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2579 s == TPY_SENDING_STATE_SENDING)
2581 /* Enable 'send video' buttons and display the preview */
2582 gtk_toggle_tool_button_set_active (
2583 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2587 gtk_toggle_tool_button_set_active (
2588 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2590 if (priv->video_preview == NULL)
2592 create_video_preview (self);
2593 add_video_preview_to_pipeline (self);
2597 g_object_unref (call);
2602 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2605 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2606 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2609 empathy_call_handler_bus_message (priv->handler, bus, message);
2611 switch (GST_MESSAGE_TYPE (message))
2613 case GST_MESSAGE_STATE_CHANGED:
2614 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2616 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2618 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2619 !priv->call_started)
2621 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2622 if (newstate == GST_STATE_PAUSED)
2624 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2625 priv->pipeline_playing = TRUE;
2627 if (priv->start_call_when_playing)
2632 case GST_MESSAGE_ERROR:
2634 GError *error = NULL;
2635 GstElement *gst_error;
2638 gst_message_parse_error (message, &error, &debug);
2639 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2641 g_message ("Element error: %s -- %s\n", error->message, debug);
2643 if (g_str_has_prefix (gst_element_get_name (gst_error),
2644 VIDEO_INPUT_ERROR_PREFIX))
2646 /* Remove the video input and continue */
2647 if (priv->video_input != NULL)
2648 empathy_call_window_remove_video_input (self);
2649 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2653 empathy_call_window_disconnected (self, TRUE);
2655 g_error_free (error);
2658 case GST_MESSAGE_UNKNOWN:
2659 case GST_MESSAGE_EOS:
2660 case GST_MESSAGE_WARNING:
2661 case GST_MESSAGE_INFO:
2662 case GST_MESSAGE_TAG:
2663 case GST_MESSAGE_BUFFERING:
2664 case GST_MESSAGE_STATE_DIRTY:
2665 case GST_MESSAGE_STEP_DONE:
2666 case GST_MESSAGE_CLOCK_PROVIDE:
2667 case GST_MESSAGE_CLOCK_LOST:
2668 case GST_MESSAGE_NEW_CLOCK:
2669 case GST_MESSAGE_STRUCTURE_CHANGE:
2670 case GST_MESSAGE_STREAM_STATUS:
2671 case GST_MESSAGE_APPLICATION:
2672 case GST_MESSAGE_ELEMENT:
2673 case GST_MESSAGE_SEGMENT_START:
2674 case GST_MESSAGE_SEGMENT_DONE:
2675 case GST_MESSAGE_DURATION:
2676 case GST_MESSAGE_ANY:
2685 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2686 GHashTable *members,
2687 EmpathyCallWindow *self)
2689 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2690 GHashTableIter iter;
2691 gpointer key, value;
2692 gboolean held = FALSE;
2694 g_hash_table_iter_init (&iter, members);
2695 while (g_hash_table_iter_next (&iter, &key, &value))
2697 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2699 /* This assumes this is a 1-1 call, otherwise one participant
2700 * putting the call on hold wouldn't mean the call is on hold
2708 priv->call_state = HELD;
2709 else if (priv->call_state == HELD)
2710 priv->call_state = CONNECTED;
2714 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2716 EmpathyCallWindow *self)
2718 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2719 TpyCallChannel *call;
2721 g_object_get (priv->handler, "call-channel", &call, NULL);
2726 tp_g_signal_connect_object (call, "audio-stream-error",
2727 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2728 tp_g_signal_connect_object (call, "video-stream-error",
2729 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2732 tp_g_signal_connect_object (call, "members-changed",
2733 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2735 g_object_unref (call);
2739 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2741 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2742 TpyCallChannel *call;
2745 /* Make the hangup button twice as wide */
2746 width = gtk_widget_get_allocated_width (priv->hangup_button);
2747 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2749 g_signal_connect (priv->handler, "state-changed",
2750 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2751 g_signal_connect (priv->handler, "conference-added",
2752 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2753 g_signal_connect (priv->handler, "conference-removed",
2754 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2755 g_signal_connect (priv->handler, "closed",
2756 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2757 g_signal_connect (priv->handler, "src-pad-added",
2758 G_CALLBACK (empathy_call_window_src_added_cb), window);
2759 g_signal_connect (priv->handler, "sink-pad-added",
2760 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2761 g_signal_connect (priv->handler, "sink-pad-removed",
2762 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2764 g_object_get (priv->handler, "call-channel", &call, NULL);
2767 call_handler_notify_call_cb (priv->handler, NULL, window);
2768 g_object_unref (call);
2772 /* call-channel doesn't exist yet, we'll connect signals once it has been
2774 g_signal_connect (priv->handler, "notify::call-channel",
2775 G_CALLBACK (call_handler_notify_call_cb), window);
2778 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2782 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2783 EmpathyCallWindow *window)
2785 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2787 if (priv->pipeline != NULL)
2789 if (priv->bus_message_source_id != 0)
2791 g_source_remove (priv->bus_message_source_id);
2792 priv->bus_message_source_id = 0;
2795 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2798 if (priv->call_state == CONNECTING)
2799 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2805 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2808 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2810 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2815 gtk_widget_hide (priv->dtmf_panel);
2816 gtk_widget_hide (menu);
2817 gtk_widget_hide (priv->toolbar);
2821 if (priv->dialpad_was_visible_before_fs)
2822 gtk_widget_show (priv->dtmf_panel);
2824 gtk_widget_show (menu);
2825 gtk_widget_show (priv->toolbar);
2827 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2828 priv->original_height_before_fs);
2833 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2835 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2837 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2838 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2839 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2840 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2842 if (priv->video_output != NULL)
2845 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2846 priv->video_output, TRUE, TRUE,
2847 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2854 empathy_call_window_state_event_cb (GtkWidget *widget,
2855 GdkEventWindowState *event, EmpathyCallWindow *window)
2857 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2859 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2860 gboolean set_fullscreen = event->new_window_state &
2861 GDK_WINDOW_STATE_FULLSCREEN;
2865 gboolean dialpad_was_visible;
2866 GtkAllocation allocation;
2867 gint original_width, original_height;
2869 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2870 original_width = allocation.width;
2871 original_height = allocation.height;
2873 g_object_get (priv->dtmf_panel,
2874 "visible", &dialpad_was_visible,
2877 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2878 priv->original_width_before_fs = original_width;
2879 priv->original_height_before_fs = original_height;
2881 if (priv->video_output_motion_handler_id == 0 &&
2882 priv->video_output != NULL)
2884 priv->video_output_motion_handler_id = g_signal_connect (
2885 G_OBJECT (priv->video_container), "motion-notify-event",
2886 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2892 disconnect_video_output_motion_handler (window);
2895 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2897 show_controls (window, set_fullscreen);
2898 show_borders (window, set_fullscreen);
2899 gtk_action_set_stock_id (priv->menu_fullscreen,
2900 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2901 priv->is_fullscreen = set_fullscreen;
2908 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2911 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2912 int w, h, dialpad_width;
2913 GtkAllocation allocation;
2915 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2916 w = allocation.width;
2917 h = allocation.height;
2919 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2923 gtk_widget_show (priv->dtmf_panel);
2929 gtk_widget_hide (priv->dtmf_panel);
2933 gtk_window_resize (GTK_WINDOW (window), w, h);
2937 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2940 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2941 TpyCallChannel *call;
2943 priv->sending_video = (state == CAMERA_STATE_ON);
2945 if (state == CAMERA_STATE_ON)
2947 /* When we start sending video, we want to show the video preview by
2949 display_video_preview (window, TRUE);
2953 display_video_preview (window, FALSE);
2956 if (priv->call_state != CONNECTED)
2959 g_object_get (priv->handler, "call-channel", &call, NULL);
2960 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2961 tpy_call_channel_send_video (call, priv->sending_video);
2962 g_object_unref (call);
2966 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2967 EmpathyCallWindow *window)
2969 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2972 active = (gtk_toggle_tool_button_get_active (toggle));
2976 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2977 priv->volume * 100);
2981 /* TODO, Instead of setting the input volume to 0 we should probably
2982 * stop sending but this would cause the audio call to drop if both
2983 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2984 * in the future. GNOME #574574
2986 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2992 empathy_call_window_hangup_cb (gpointer object,
2993 EmpathyCallWindow *self)
2995 empathy_call_handler_stop_call (self->priv->handler);
2997 empathy_call_window_disconnected (self, TRUE);
3001 empathy_call_window_restart_call (EmpathyCallWindow *window)
3003 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3005 /* Remove error info bars */
3006 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3007 (GtkCallback) gtk_widget_destroy, NULL);
3009 create_video_output_widget (window);
3011 /* While the call was disconnected, the input volume might have changed.
3012 * However, since the audio_input source was destroyed, its volume has not
3013 * been updated during that time. That's why we manually update it here */
3014 empathy_call_window_mic_volume_changed (window);
3016 priv->outgoing = TRUE;
3017 empathy_call_window_set_state_connecting (window);
3019 if (priv->pipeline_playing)
3020 start_call (window);
3022 /* call will be started when the pipeline is ready */
3023 priv->start_call_when_playing = TRUE;
3025 empathy_call_window_setup_avatars (window, priv->handler);
3027 empathy_call_window_show_hangup_button (window, TRUE);
3031 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3032 EmpathyCallWindow *window)
3036 active = gtk_toggle_tool_button_get_active (button);
3038 empathy_call_window_show_dialpad (window, active);
3042 empathy_call_window_fullscreen_cb (gpointer object,
3043 EmpathyCallWindow *window)
3045 empathy_call_window_fullscreen_toggle (window);
3049 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3051 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3053 if (priv->is_fullscreen)
3054 gtk_window_unfullscreen (GTK_WINDOW (window));
3056 gtk_window_fullscreen (GTK_WINDOW (window));
3060 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3061 GdkEventButton *event, EmpathyCallWindow *window)
3063 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3065 empathy_call_window_video_menu_popup (window, event->button);
3073 empathy_call_window_key_press_cb (GtkWidget *video_output,
3074 GdkEventKey *event, EmpathyCallWindow *window)
3076 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3078 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3080 /* Since we are in fullscreen mode, toggling will bring us back to
3082 empathy_call_window_fullscreen_toggle (window);
3090 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3091 GdkEventMotion *event, EmpathyCallWindow *window)
3093 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3095 if (priv->is_fullscreen)
3097 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3099 /* Show the bottom toolbar */
3100 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3107 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3111 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3113 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3115 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3116 button, gtk_get_current_event_time ());
3117 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3121 empathy_call_window_status_message (EmpathyCallWindow *self,
3124 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3128 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3129 gdouble value, EmpathyCallWindow *window)
3131 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3133 if (priv->audio_output == NULL)
3136 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3141 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3143 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3145 return priv->ui_manager;
3148 EmpathyGstAudioSrc *
3149 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3151 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3153 return (EmpathyGstAudioSrc *) priv->audio_input;