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-audio-src.h"
62 #include "empathy-audio-sink.h"
63 #include "empathy-video-src.h"
65 #define CONTENT_HBOX_BORDER_WIDTH 6
66 #define CONTENT_HBOX_SPACING 3
67 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
69 #define SELF_VIDEO_SECTION_WIDTH 120
70 #define SELF_VIDEO_SECTION_HEIGTH 90
72 /* The avatar's default width and height are set to the same value because we
73 want a square icon. */
74 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
75 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
76 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
78 #define SMALL_TOOLBAR_SIZE 36
80 /* If an video input error occurs, the error message will start with "v4l" */
81 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
83 /* The time interval in milliseconds between 2 outgoing rings */
84 #define MS_BETWEEN_RING 500
86 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
89 PROP_CALL_HANDLER = 1,
101 CAMERA_STATE_OFF = 0,
105 struct _EmpathyCallWindowPriv
107 gboolean dispose_has_run;
108 EmpathyCallHandler *handler;
110 EmpathyContact *contact;
112 EmpathyCameraMonitor *camera_monitor;
117 GtkUIManager *ui_manager;
118 GtkWidget *errors_vbox;
119 /* widget displays the video received from the remote user. This widget is
120 * alive only during call. */
121 ClutterActor *video_output;
122 ClutterActor *video_preview;
123 ClutterActor *preview_hidden_button;
124 GtkWidget *video_container;
125 GtkWidget *remote_user_avatar_widget;
126 GtkWidget *remote_user_avatar_toolbar;
127 GtkWidget *remote_user_name_toolbar;
128 GtkWidget *status_label;
129 GtkWidget *hangup_button;
130 GtkWidget *audio_call_button;
131 GtkWidget *video_call_button;
132 GtkWidget *mic_button;
133 GtkWidget *camera_button;
134 GtkWidget *dialpad_button;
136 GtkWidget *bottom_toolbar;
138 GtkAction *menu_fullscreen;
140 /* The box that contains self and remote avatar and video
141 input/output. When we redial, we destroy and re-create the box */
142 ClutterActor *video_box;
143 ClutterLayoutManager *video_layout;
145 /* We keep a reference on the hbox which contains the main content so we can
146 easilly repack everything when toggling fullscreen */
147 GtkWidget *content_hbox;
149 gulong video_output_motion_handler_id;
150 guint bus_message_source_id;
154 GtkWidget *dtmf_panel;
157 GtkWidget *details_vbox;
158 GtkWidget *vcodec_encoding_label;
159 GtkWidget *acodec_encoding_label;
160 GtkWidget *vcodec_decoding_label;
161 GtkWidget *acodec_decoding_label;
163 GtkWidget *audio_remote_candidate_label;
164 GtkWidget *audio_local_candidate_label;
165 GtkWidget *video_remote_candidate_label;
166 GtkWidget *video_local_candidate_label;
167 GtkWidget *video_remote_candidate_info_img;
168 GtkWidget *video_local_candidate_info_img;
169 GtkWidget *audio_remote_candidate_info_img;
170 GtkWidget *audio_local_candidate_info_img;
172 GstElement *video_input;
173 GstElement *video_preview_sink;
174 GstElement *video_output_sink;
175 GstElement *audio_input;
176 GstElement *audio_output;
177 GstElement *pipeline;
178 GstElement *video_tee;
188 gboolean call_started;
189 gboolean sending_video;
190 CameraState camera_state;
192 EmpathyCallWindowFullscreen *fullscreen;
193 gboolean is_fullscreen;
198 /* Those fields represent the state of the window before it actually was in
200 gboolean dialpad_was_visible_before_fs;
201 gint original_width_before_fs;
202 gint original_height_before_fs;
204 gint x, y, w, h, dialpad_width;
207 /* TRUE if the call should be started when the pipeline is playing */
208 gboolean start_call_when_playing;
209 /* TRUE if we requested to set the pipeline in the playing state */
210 gboolean pipeline_playing;
212 EmpathySoundManager *sound_mgr;
217 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
219 static void empathy_call_window_realized_cb (GtkWidget *widget,
220 EmpathyCallWindow *window);
222 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
223 GdkEvent *event, EmpathyCallWindow *window);
225 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
226 GdkEventWindowState *event, EmpathyCallWindow *window);
228 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
231 static void empathy_call_window_mic_toggled_cb (
232 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
234 static void empathy_call_window_hangup_cb (gpointer object,
235 EmpathyCallWindow *window);
237 static void empathy_call_window_fullscreen_cb (gpointer object,
238 EmpathyCallWindow *window);
240 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
242 static gboolean empathy_call_window_video_button_press_cb (
243 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
245 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
246 GdkEventKey *event, EmpathyCallWindow *window);
248 static gboolean empathy_call_window_video_output_motion_notify (
249 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
251 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
254 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
255 EmpathyCallWindow *window);
257 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
259 static void empathy_call_window_status_message (EmpathyCallWindow *window,
262 static gboolean empathy_call_window_bus_message (GstBus *bus,
263 GstMessage *message, gpointer user_data);
266 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
267 gdouble value, EmpathyCallWindow *window);
270 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
273 gtk_widget_set_visible (self->priv->hangup_button, show);
274 gtk_widget_set_visible (self->priv->audio_call_button, !show);
275 gtk_widget_set_visible (self->priv->video_call_button, !show);
279 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
280 EmpathyCallWindow *self)
282 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
283 empathy_call_window_restart_call (self);
287 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
288 EmpathyCallWindow *self)
290 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
291 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
292 empathy_call_window_restart_call (self);
296 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
298 EmpathyCallWindowPriv *priv = GET_PRIV (window);
299 TpyCallChannel *call;
303 g_object_get (priv->handler, "call-channel", &call, NULL);
305 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
306 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
309 tpy_call_channel_dtmf_start_tone (call, event);
311 g_object_unref (call);
315 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
317 EmpathyCallWindowPriv *priv = GET_PRIV (window);
318 TpyCallChannel *call;
320 g_object_get (priv->handler, "call-channel", &call, NULL);
322 tpy_call_channel_dtmf_stop_tone (call);
324 g_object_unref (call);
328 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
330 EmpathyCallWindowPriv *priv = GET_PRIV (self);
333 volume = g_settings_get_double (priv->settings,
334 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
336 /* Don't store the volume because of muting */
337 if (volume > 0 || gtk_toggle_tool_button_get_active (
338 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
339 priv->volume = volume;
341 /* Ensure that the toggle button is active if the volume is > 0 and inactive
342 * if it's smaller than 0 */
343 if ((volume > 0) != gtk_toggle_tool_button_get_active (
344 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
345 gtk_toggle_tool_button_set_active (
346 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
348 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
353 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
355 EmpathyCallWindow *self)
357 empathy_call_window_mic_volume_changed (self);
361 empathy_call_window_show_video_output (EmpathyCallWindow *self,
364 if (self->priv->video_output != NULL)
365 g_object_set (self->priv->video_output, "visible", show, NULL);
367 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
371 create_video_output_widget (EmpathyCallWindow *self)
373 EmpathyCallWindowPriv *priv = GET_PRIV (self);
375 g_assert (priv->video_output == NULL);
376 g_assert (priv->pipeline != NULL);
378 priv->video_output = clutter_texture_new ();
380 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
383 priv->video_output_sink = clutter_gst_video_sink_new (
384 CLUTTER_TEXTURE (priv->video_output));
386 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
389 gtk_widget_add_events (priv->video_container,
390 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
391 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
392 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
396 create_video_input (EmpathyCallWindow *self)
398 EmpathyCallWindowPriv *priv = GET_PRIV (self);
400 g_assert (priv->video_input == NULL);
401 priv->video_input = empathy_video_src_new ();
402 gst_object_ref (priv->video_input);
403 gst_object_sink (priv->video_input);
407 create_audio_input (EmpathyCallWindow *self)
409 EmpathyCallWindowPriv *priv = GET_PRIV (self);
411 g_assert (priv->audio_input == NULL);
412 priv->audio_input = empathy_audio_src_new ();
413 gst_object_ref (priv->audio_input);
414 gst_object_sink (priv->audio_input);
418 add_video_preview_to_pipeline (EmpathyCallWindow *self)
420 EmpathyCallWindowPriv *priv = GET_PRIV (self);
423 g_assert (priv->video_preview != NULL);
424 g_assert (priv->pipeline != NULL);
425 g_assert (priv->video_input != NULL);
426 g_assert (priv->video_tee != NULL);
428 preview = priv->video_preview_sink;
430 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
432 g_warning ("Could not add video input to pipeline");
436 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
438 g_warning ("Could not add video preview to pipeline");
442 if (!gst_element_link (priv->video_input, priv->video_tee))
444 g_warning ("Could not link video input to video tee");
448 if (!gst_element_link (priv->video_tee, preview))
450 g_warning ("Could not link video tee to video preview");
456 empathy_call_window_disable_camera_cb (GtkAction *action,
457 EmpathyCallWindow *self)
459 clutter_actor_destroy (self->priv->preview_hidden_button);
461 gtk_toggle_tool_button_set_active (
462 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
466 empathy_call_window_minimise_camera_cb (GtkAction *action,
467 EmpathyCallWindow *self)
469 clutter_actor_hide (self->priv->video_preview);
470 clutter_actor_show (self->priv->preview_hidden_button);
474 empathy_call_window_maximise_camera_cb (GtkAction *action,
475 EmpathyCallWindow *self)
477 clutter_actor_show (self->priv->video_preview);
478 clutter_actor_hide (self->priv->preview_hidden_button);
482 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
483 EmpathyCallWindow *self)
487 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
489 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
490 0, gtk_get_current_event_time ());
491 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
495 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
496 EmpathyCallWindow *self)
500 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
501 "/preview-hidden-menu");
502 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
503 0, gtk_get_current_event_time ());
504 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
508 create_video_preview (EmpathyCallWindow *self)
510 EmpathyCallWindowPriv *priv = GET_PRIV (self);
511 ClutterLayoutManager *layout, *layout_center;
512 ClutterActor *preview;
517 g_assert (priv->video_preview == NULL);
519 preview = clutter_texture_new ();
520 clutter_actor_set_size (preview,
521 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
522 priv->video_preview_sink = clutter_gst_video_sink_new (
523 CLUTTER_TEXTURE (preview));
525 /* Flip the video preview */
526 clutter_actor_set_rotation (preview,
529 SELF_VIDEO_SECTION_WIDTH * 0.5,
533 /* Add a little offset to the video preview */
534 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
535 CLUTTER_BIN_ALIGNMENT_START);
536 priv->video_preview = clutter_box_new (layout);
537 clutter_actor_set_size (priv->video_preview,
538 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
540 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
541 CLUTTER_BIN_ALIGNMENT_CENTER);
542 box = clutter_box_new (layout_center);
543 clutter_actor_set_size (box,
544 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
546 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
547 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
549 g_object_set (priv->video_preview_sink,
554 /* Translators: this is an "Info" label. It should be as short
556 button = gtk_button_new_with_label (_("i"));
557 b = gtk_clutter_actor_new_with_contents (button);
559 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
561 CLUTTER_BIN_ALIGNMENT_END,
562 CLUTTER_BIN_ALIGNMENT_END);
564 g_signal_connect (button, "clicked",
565 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
568 /* Translators: this is an "Info" label. It should be as short
570 button = gtk_button_new_with_label (_("i"));
571 priv->preview_hidden_button =
572 gtk_clutter_actor_new_with_contents (button);
574 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
575 priv->preview_hidden_button,
576 CLUTTER_BIN_ALIGNMENT_START,
577 CLUTTER_BIN_ALIGNMENT_END);
579 clutter_actor_hide (priv->preview_hidden_button);
581 g_signal_connect (button, "clicked",
582 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
585 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
587 CLUTTER_BIN_ALIGNMENT_START,
588 CLUTTER_BIN_ALIGNMENT_END);
592 play_camera (EmpathyCallWindow *window,
595 EmpathyCallWindowPriv *priv = GET_PRIV (window);
599 if (priv->video_preview == NULL)
601 create_video_preview (window);
602 add_video_preview_to_pipeline (window);
606 state = GST_STATE_PLAYING;
608 state = GST_STATE_NULL;
610 preview = priv->video_preview_sink;
612 gst_element_set_state (preview, state);
613 gst_element_set_state (priv->video_input, state);
614 gst_element_set_state (priv->video_tee, state);
618 display_video_preview (EmpathyCallWindow *self,
621 EmpathyCallWindowPriv *priv = GET_PRIV (self);
625 /* Display the video preview */
626 DEBUG ("Show video preview");
628 play_camera (self, TRUE);
629 clutter_actor_show (priv->video_preview);
633 /* Hide the video preview */
634 DEBUG ("Hide video preview");
636 if (priv->video_preview != NULL)
638 clutter_actor_hide (priv->video_preview);
639 play_camera (self, FALSE);
645 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
647 EmpathyCallWindowPriv *priv = GET_PRIV (window);
649 empathy_call_window_status_message (window, _("Connecting…"));
650 priv->call_state = CONNECTING;
653 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
654 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
658 disable_camera (EmpathyCallWindow *self)
660 EmpathyCallWindowPriv *priv = GET_PRIV (self);
662 if (priv->camera_state == CAMERA_STATE_OFF)
665 DEBUG ("Disable camera");
667 display_video_preview (self, FALSE);
669 if (priv->camera_state == CAMERA_STATE_ON)
670 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
672 priv->camera_state = CAMERA_STATE_OFF;
676 enable_camera (EmpathyCallWindow *self)
678 EmpathyCallWindowPriv *priv = GET_PRIV (self);
680 if (priv->camera_state == CAMERA_STATE_ON)
683 if (priv->video_input == NULL)
685 DEBUG ("Can't enable camera, no input");
689 DEBUG ("Enable camera");
691 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
693 priv->camera_state = CAMERA_STATE_ON;
697 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
698 EmpathyCallWindow *self)
700 if (gtk_toggle_tool_button_get_active (toggle))
701 enable_camera (self);
703 disable_camera (self);
707 create_pipeline (EmpathyCallWindow *self)
709 EmpathyCallWindowPriv *priv = GET_PRIV (self);
712 g_assert (priv->pipeline == NULL);
714 priv->pipeline = gst_pipeline_new (NULL);
715 priv->pipeline_playing = FALSE;
717 priv->video_tee = gst_element_factory_make ("tee", NULL);
718 gst_object_ref (priv->video_tee);
719 gst_object_sink (priv->video_tee);
721 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
723 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
724 priv->bus_message_source_id = gst_bus_add_watch (bus,
725 empathy_call_window_bus_message, self);
727 g_object_unref (bus);
731 empathy_call_window_configure_event_cb (GtkWidget *widget,
733 EmpathyCallWindow *self)
735 GdkWindow *gdk_window;
736 GdkWindowState window_state;
738 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
739 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
741 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
742 &self->priv->dialpad_width, NULL);
744 gdk_window = gtk_widget_get_window (widget);
745 window_state = gdk_window_get_state (gdk_window);
746 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
752 empathy_call_window_destroyed_cb (GtkWidget *object,
753 EmpathyCallWindow *self)
755 if (gtk_widget_get_visible (self->priv->dtmf_panel))
757 /* Save the geometry as if the dialpad was hidden. */
758 empathy_geometry_save_values (GTK_WINDOW (self),
759 self->priv->x, self->priv->y,
760 self->priv->w - self->priv->dialpad_width, self->priv->h,
761 self->priv->maximized);
766 empathy_call_window_init (EmpathyCallWindow *self)
768 EmpathyCallWindowPriv *priv;
772 ClutterConstraint *size_constraint;
773 ClutterActor *remote_avatar;
774 GtkStyleContext *context;
778 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
779 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
781 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
782 gui = empathy_builder_get_file (filename,
783 "call_window_vbox", &top_vbox,
784 "errors_vbox", &priv->errors_vbox,
786 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
787 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
788 "status_label", &priv->status_label,
789 "audiocall", &priv->audio_call_button,
790 "videocall", &priv->video_call_button,
791 "microphone", &priv->mic_button,
792 "camera", &priv->camera_button,
793 "hangup", &priv->hangup_button,
794 "dialpad", &priv->dialpad_button,
795 "toolbar", &priv->toolbar,
796 "bottom_toolbar", &priv->bottom_toolbar,
797 "ui_manager", &priv->ui_manager,
798 "menufullscreen", &priv->menu_fullscreen,
799 "details_vbox", &priv->details_vbox,
800 "vcodec_encoding_label", &priv->vcodec_encoding_label,
801 "acodec_encoding_label", &priv->acodec_encoding_label,
802 "acodec_decoding_label", &priv->acodec_decoding_label,
803 "vcodec_decoding_label", &priv->vcodec_decoding_label,
804 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
805 "audio_local_candidate_label", &priv->audio_local_candidate_label,
806 "video_remote_candidate_label", &priv->video_remote_candidate_label,
807 "video_local_candidate_label", &priv->video_local_candidate_label,
808 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
809 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
810 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
811 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
815 empathy_builder_connect (gui, self,
816 "menuhangup", "activate", empathy_call_window_hangup_cb,
817 "hangup", "clicked", empathy_call_window_hangup_cb,
818 "audiocall", "clicked", empathy_call_window_audio_call_cb,
819 "videocall", "clicked", empathy_call_window_video_call_cb,
820 "volume", "value-changed", empathy_call_window_volume_changed_cb,
821 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
822 "camera", "toggled", empathy_call_window_camera_toggled_cb,
823 "dialpad", "toggled", empathy_call_window_dialpad_cb,
824 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
825 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
826 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
827 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
830 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
832 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
834 g_object_bind_property (priv->camera_monitor, "available",
835 priv->camera_button, "sensitive",
836 G_BINDING_SYNC_CREATE);
838 priv->lock = g_mutex_new ();
840 gtk_container_add (GTK_CONTAINER (self), top_vbox);
842 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
843 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
844 CONTENT_HBOX_BORDER_WIDTH);
845 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
848 /* avatar/video box */
849 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
850 CLUTTER_BIN_ALIGNMENT_CENTER);
852 priv->video_box = clutter_box_new (priv->video_layout);
854 priv->video_container = gtk_clutter_embed_new ();
856 /* Set the background color to that of the rest of the window */
857 context = gtk_widget_get_style_context (priv->content_hbox);
858 gtk_style_context_get_background_color (context,
859 GTK_STATE_FLAG_NORMAL, &rgba);
860 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
861 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
862 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
863 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
864 clutter_stage_set_color (
865 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
866 GTK_CLUTTER_EMBED (priv->video_container))),
869 clutter_container_add (
870 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
871 GTK_CLUTTER_EMBED (priv->video_container))),
875 size_constraint = clutter_bind_constraint_new (
876 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
877 CLUTTER_BIND_SIZE, 0);
878 clutter_actor_add_constraint (priv->video_box, size_constraint);
880 priv->remote_user_avatar_widget = gtk_image_new ();
881 remote_avatar = gtk_clutter_actor_new_with_contents (
882 priv->remote_user_avatar_widget);
884 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
887 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
888 priv->video_container, TRUE, TRUE,
889 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
891 create_pipeline (self);
892 create_video_output_widget (self);
893 create_audio_input (self);
894 create_video_input (self);
896 /* The call will be started as soon the pipeline is playing */
897 priv->start_call_when_playing = TRUE;
899 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
900 G_CALLBACK (dtmf_button_pressed_cb),
901 G_CALLBACK (dtmf_button_released_cb));
903 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
906 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
908 gtk_widget_show_all (top_vbox);
910 gtk_widget_hide (priv->dtmf_panel);
912 priv->fullscreen = empathy_call_window_fullscreen_new (self);
914 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
915 priv->video_container);
917 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
918 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
920 g_signal_connect (G_OBJECT (self), "realize",
921 G_CALLBACK (empathy_call_window_realized_cb), self);
923 g_signal_connect (G_OBJECT (self), "delete-event",
924 G_CALLBACK (empathy_call_window_delete_cb), self);
926 g_signal_connect (G_OBJECT (self), "window-state-event",
927 G_CALLBACK (empathy_call_window_state_event_cb), self);
929 g_signal_connect (G_OBJECT (self), "key-press-event",
930 G_CALLBACK (empathy_call_window_key_press_cb), self);
932 priv->timer = g_timer_new ();
934 g_object_ref (priv->ui_manager);
935 g_object_unref (gui);
937 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
939 empathy_call_window_show_hangup_button (self, TRUE);
941 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
942 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
943 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
945 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
946 /* These signals are used to track the window position and save it
947 * when the window is destroyed. We need to do this as we don't want
948 * the window geometry to be saved with the dialpad taken into account. */
949 g_signal_connect (self, "destroy",
950 G_CALLBACK (empathy_call_window_destroyed_cb), self);
951 g_signal_connect (self, "configure-event",
952 G_CALLBACK (empathy_call_window_configure_event_cb), self);
953 g_signal_connect (self, "window-state-event",
954 G_CALLBACK (empathy_call_window_configure_event_cb), self);
957 /* Instead of specifying a width and a height, we specify only one size. That's
958 because we want a square avatar icon. */
960 init_contact_avatar_with_size (EmpathyContact *contact,
961 GtkWidget *image_widget,
964 GdkPixbuf *pixbuf_avatar = NULL;
968 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
972 if (pixbuf_avatar == NULL)
974 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
975 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
978 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
980 if (pixbuf_avatar != NULL)
981 g_object_unref (pixbuf_avatar);
985 set_window_title (EmpathyCallWindow *self)
987 EmpathyCallWindowPriv *priv = GET_PRIV (self);
990 if (priv->contact != NULL)
992 /* translators: Call is a noun and %s is the contact name. This string
993 * is used in the window title */
994 tmp = g_strdup_printf (_("Call with %s"),
995 empathy_contact_get_alias (priv->contact));
996 gtk_window_set_title (GTK_WINDOW (self), tmp);
1001 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1006 set_remote_user_name (EmpathyCallWindow *self,
1007 EmpathyContact *contact)
1009 const gchar *alias = empathy_contact_get_alias (contact);
1010 const gchar *status = empathy_contact_get_status (contact);
1013 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1014 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1020 contact_name_changed_cb (EmpathyContact *contact,
1022 EmpathyCallWindow *self)
1024 set_window_title (self);
1025 set_remote_user_name (self, contact);
1029 contact_presence_changed_cb (EmpathyContact *contact,
1031 EmpathyCallWindow *self)
1033 set_remote_user_name (self, contact);
1037 contact_avatar_changed_cb (EmpathyContact *contact,
1039 EmpathyCallWindow *self)
1042 GtkAllocation allocation;
1043 GtkWidget *avatar_widget;
1045 avatar_widget = self->priv->remote_user_avatar_widget;
1047 gtk_widget_get_allocation (avatar_widget, &allocation);
1048 size = allocation.height;
1052 /* the widget is not allocated yet, set a default size */
1053 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1054 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1057 init_contact_avatar_with_size (contact, avatar_widget, size);
1059 avatar_widget = self->priv->remote_user_avatar_toolbar;
1061 gtk_widget_get_allocation (avatar_widget, &allocation);
1062 size = allocation.height;
1066 /* the widget is not allocated yet, set a default size */
1067 size = SMALL_TOOLBAR_SIZE;
1070 init_contact_avatar_with_size (contact, avatar_widget, size);
1074 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1075 EmpathyCallHandler *handler)
1077 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1079 tp_g_signal_connect_object (priv->contact, "notify::name",
1080 G_CALLBACK (contact_name_changed_cb), self, 0);
1081 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1082 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1083 tp_g_signal_connect_object (priv->contact, "notify::presence",
1084 G_CALLBACK (contact_presence_changed_cb), self, 0);
1086 set_window_title (self);
1087 set_remote_user_name (self, priv->contact);
1089 init_contact_avatar_with_size (priv->contact,
1090 priv->remote_user_avatar_widget,
1091 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1092 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1094 init_contact_avatar_with_size (priv->contact,
1095 priv->remote_user_avatar_toolbar,
1096 SMALL_TOOLBAR_SIZE);
1098 /* The remote avatar is shown by default and will be hidden when we receive
1099 video from the remote side. */
1100 clutter_actor_hide (priv->video_output);
1101 gtk_widget_show (priv->remote_user_avatar_widget);
1105 update_send_codec (EmpathyCallWindow *self,
1108 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1115 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1116 widget = priv->acodec_encoding_label;
1120 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1121 widget = priv->vcodec_encoding_label;
1127 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1128 gtk_label_set_text (GTK_LABEL (widget), tmp);
1133 send_audio_codec_notify_cb (GObject *object,
1137 EmpathyCallWindow *self = user_data;
1139 update_send_codec (self, TRUE);
1143 send_video_codec_notify_cb (GObject *object,
1147 EmpathyCallWindow *self = user_data;
1149 update_send_codec (self, FALSE);
1153 update_recv_codec (EmpathyCallWindow *self,
1156 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1159 GString *str = NULL;
1163 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1164 widget = priv->acodec_decoding_label;
1168 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1169 widget = priv->vcodec_decoding_label;
1175 for (l = codecs; l != NULL; l = g_list_next (l))
1177 FsCodec *codec = l->data;
1180 str = g_string_new (NULL);
1182 g_string_append (str, ", ");
1184 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1188 gtk_label_set_text (GTK_LABEL (widget), str->str);
1189 g_string_free (str, TRUE);
1193 recv_audio_codecs_notify_cb (GObject *object,
1197 EmpathyCallWindow *self = user_data;
1199 update_recv_codec (self, TRUE);
1203 recv_video_codecs_notify_cb (GObject *object,
1207 EmpathyCallWindow *self = user_data;
1209 update_recv_codec (self, FALSE);
1212 static const gchar *
1213 candidate_type_to_str (FsCandidate *candidate)
1215 switch (candidate->type)
1217 case FS_CANDIDATE_TYPE_HOST:
1219 case FS_CANDIDATE_TYPE_SRFLX:
1220 return "server reflexive";
1221 case FS_CANDIDATE_TYPE_PRFLX:
1222 return "peer reflexive";
1223 case FS_CANDIDATE_TYPE_RELAY:
1225 case FS_CANDIDATE_TYPE_MULTICAST:
1232 static const gchar *
1233 candidate_type_to_desc (FsCandidate *candidate)
1235 switch (candidate->type)
1237 case FS_CANDIDATE_TYPE_HOST:
1238 return _("The IP address as seen by the machine");
1239 case FS_CANDIDATE_TYPE_SRFLX:
1240 return _("The IP address as seen by a server on the Internet");
1241 case FS_CANDIDATE_TYPE_PRFLX:
1242 return _("The IP address of the peer as seen by the other side");
1243 case FS_CANDIDATE_TYPE_RELAY:
1244 return _("The IP address of a relay server");
1245 case FS_CANDIDATE_TYPE_MULTICAST:
1246 return _("The IP address of the multicast group");
1253 update_candidat_widget (EmpathyCallWindow *self,
1256 FsCandidate *candidate)
1260 g_assert (candidate != NULL);
1261 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1262 candidate->port, candidate_type_to_str (candidate));
1264 gtk_label_set_text (GTK_LABEL (label), str);
1265 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1271 candidates_changed_cb (GObject *object,
1273 EmpathyCallWindow *self)
1275 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1276 FsCandidate *candidate = NULL;
1278 if (type == FS_MEDIA_TYPE_VIDEO)
1280 /* Update remote candidate */
1281 candidate = empathy_call_handler_get_video_remote_candidate (
1284 update_candidat_widget (self, priv->video_remote_candidate_label,
1285 priv->video_remote_candidate_info_img, candidate);
1287 /* Update local candidate */
1288 candidate = empathy_call_handler_get_video_local_candidate (
1291 update_candidat_widget (self, priv->video_local_candidate_label,
1292 priv->video_local_candidate_info_img, candidate);
1296 /* Update remote candidate */
1297 candidate = empathy_call_handler_get_audio_remote_candidate (
1300 update_candidat_widget (self, priv->audio_remote_candidate_label,
1301 priv->audio_remote_candidate_info_img, candidate);
1303 /* Update local candidate */
1304 candidate = empathy_call_handler_get_audio_local_candidate (
1307 update_candidat_widget (self, priv->audio_local_candidate_label,
1308 priv->audio_local_candidate_info_img, candidate);
1313 empathy_call_window_constructed (GObject *object)
1315 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1316 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1317 TpyCallChannel *call;
1319 g_assert (priv->handler != NULL);
1321 g_object_get (priv->handler, "call-channel", &call, NULL);
1322 priv->outgoing = (call == NULL);
1324 g_object_unref (call);
1326 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1327 g_assert (priv->contact != NULL);
1329 empathy_call_window_setup_avatars (self, priv->handler);
1330 empathy_call_window_set_state_connecting (self);
1332 if (!empathy_call_handler_has_initial_video (priv->handler))
1334 gtk_toggle_tool_button_set_active (
1335 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1337 /* If call has InitialVideo, the preview will be started once the call has
1338 * been started (start_call()). */
1340 update_send_codec (self, TRUE);
1341 update_send_codec (self, FALSE);
1342 update_recv_codec (self, TRUE);
1343 update_recv_codec (self, FALSE);
1345 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1346 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1347 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1348 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1349 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1350 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1351 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1352 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1354 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1355 G_CALLBACK (candidates_changed_cb), self, 0);
1358 static void empathy_call_window_dispose (GObject *object);
1359 static void empathy_call_window_finalize (GObject *object);
1362 empathy_call_window_set_property (GObject *object,
1363 guint property_id, const GValue *value, GParamSpec *pspec)
1365 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1367 switch (property_id)
1369 case PROP_CALL_HANDLER:
1370 priv->handler = g_value_dup_object (value);
1373 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1378 empathy_call_window_get_property (GObject *object,
1379 guint property_id, GValue *value, GParamSpec *pspec)
1381 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1383 switch (property_id)
1385 case PROP_CALL_HANDLER:
1386 g_value_set_object (value, priv->handler);
1389 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1394 empathy_call_window_class_init (
1395 EmpathyCallWindowClass *empathy_call_window_class)
1397 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1398 GParamSpec *param_spec;
1400 g_type_class_add_private (empathy_call_window_class,
1401 sizeof (EmpathyCallWindowPriv));
1403 object_class->constructed = empathy_call_window_constructed;
1404 object_class->set_property = empathy_call_window_set_property;
1405 object_class->get_property = empathy_call_window_get_property;
1407 object_class->dispose = empathy_call_window_dispose;
1408 object_class->finalize = empathy_call_window_finalize;
1410 param_spec = g_param_spec_object ("handler",
1411 "handler", "The call handler",
1412 EMPATHY_TYPE_CALL_HANDLER,
1413 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1414 g_object_class_install_property (object_class,
1415 PROP_CALL_HANDLER, param_spec);
1419 empathy_call_window_dispose (GObject *object)
1421 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1422 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1424 if (priv->dispose_has_run)
1427 priv->dispose_has_run = TRUE;
1429 if (priv->handler != NULL)
1431 empathy_call_handler_stop_call (priv->handler);
1432 tp_clear_object (&priv->handler);
1435 if (priv->bus_message_source_id != 0)
1437 g_source_remove (priv->bus_message_source_id);
1438 priv->bus_message_source_id = 0;
1441 if (priv->got_video_src > 0)
1443 g_source_remove (priv->got_video_src);
1444 priv->got_video_src = 0;
1447 tp_clear_object (&priv->pipeline);
1448 tp_clear_object (&priv->video_input);
1449 tp_clear_object (&priv->audio_input);
1450 tp_clear_object (&priv->video_tee);
1451 tp_clear_object (&priv->ui_manager);
1452 tp_clear_object (&priv->fullscreen);
1453 tp_clear_object (&priv->camera_monitor);
1454 tp_clear_object (&priv->settings);
1456 g_list_free_full (priv->notifiers, g_object_unref);
1458 if (priv->timer_id != 0)
1459 g_source_remove (priv->timer_id);
1462 if (priv->contact != NULL)
1464 g_signal_handlers_disconnect_by_func (priv->contact,
1465 contact_name_changed_cb, self);
1466 priv->contact = NULL;
1470 tp_clear_object (&priv->sound_mgr);
1472 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1476 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1478 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1480 if (priv->video_output_motion_handler_id != 0)
1482 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1483 priv->video_output_motion_handler_id);
1484 priv->video_output_motion_handler_id = 0;
1489 empathy_call_window_finalize (GObject *object)
1491 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1492 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1494 disconnect_video_output_motion_handler (self);
1496 /* free any data held directly by the object here */
1497 g_mutex_free (priv->lock);
1499 g_timer_destroy (priv->timer);
1501 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1506 empathy_call_window_new (EmpathyCallHandler *handler)
1508 return EMPATHY_CALL_WINDOW (
1509 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1513 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1514 GstElement *conference, gpointer user_data)
1516 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1517 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1518 FsElementAddedNotifier *notifier;
1521 DEBUG ("Conference added");
1523 /* Add notifier to set the various element properties as needed */
1524 notifier = fs_element_added_notifier_new ();
1525 keyfile = fs_utils_get_default_element_properties (conference);
1527 if (keyfile != NULL)
1528 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1530 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1532 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1534 gst_bin_add (GST_BIN (priv->pipeline), conference);
1535 gst_element_set_state (conference, GST_STATE_PLAYING);
1539 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1540 GstElement *conference, gpointer user_data)
1542 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1543 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1545 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1546 gst_element_set_state (conference, GST_STATE_NULL);
1550 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1552 GstStateChangeReturn state_change_return;
1553 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1555 if (priv->pipeline == NULL)
1558 if (priv->bus_message_source_id != 0)
1560 g_source_remove (priv->bus_message_source_id);
1561 priv->bus_message_source_id = 0;
1564 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1566 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1567 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1569 if (priv->pipeline != NULL)
1570 g_object_unref (priv->pipeline);
1571 priv->pipeline = NULL;
1573 if (priv->audio_output != NULL)
1574 g_object_unref (priv->audio_output);
1575 priv->audio_output = NULL;
1577 if (priv->video_tee != NULL)
1578 g_object_unref (priv->video_tee);
1579 priv->video_tee = NULL;
1581 if (priv->video_preview != NULL)
1582 clutter_actor_destroy (priv->video_preview);
1583 priv->video_preview = NULL;
1585 priv->funnel = NULL;
1587 create_pipeline (self);
1588 /* Call will be started when user will hit the 'redial' button */
1589 priv->start_call_when_playing = FALSE;
1590 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1596 g_message ("Error: could not destroy pipeline. Closing call window");
1597 gtk_widget_destroy (GTK_WIDGET (self));
1604 reset_details_pane (EmpathyCallWindow *self)
1606 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1608 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1609 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1610 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1611 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1615 empathy_call_window_disconnected (EmpathyCallWindow *self,
1618 gboolean could_disconnect = FALSE;
1619 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1620 gboolean could_reset_pipeline;
1622 /* Leave full screen mode if needed */
1623 gtk_window_unfullscreen (GTK_WINDOW (self));
1625 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1626 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1628 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1630 if (priv->call_state == CONNECTING)
1631 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1633 if (priv->call_state != REDIALING)
1634 priv->call_state = DISCONNECTED;
1636 if (could_reset_pipeline)
1638 g_mutex_lock (priv->lock);
1640 g_timer_stop (priv->timer);
1642 if (priv->timer_id != 0)
1643 g_source_remove (priv->timer_id);
1646 g_mutex_unlock (priv->lock);
1649 /* We are about to destroy the window, no need to update it or create
1650 * a video preview */
1653 empathy_call_window_status_message (self, _("Disconnected"));
1655 empathy_call_window_show_hangup_button (self, FALSE);
1657 /* Unsensitive the camera and mic button */
1658 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1659 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1661 /* Be sure that the mic button is enabled */
1662 gtk_toggle_tool_button_set_active (
1663 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1665 if (priv->camera_state == CAMERA_STATE_ON)
1667 /* Restart the preview with the new pipeline. */
1668 display_video_preview (self, TRUE);
1671 /* destroy the video output; it will be recreated when we'll redial */
1672 disconnect_video_output_motion_handler (self);
1673 if (priv->video_output != NULL)
1674 clutter_actor_destroy (priv->video_output);
1675 priv->video_output = NULL;
1676 if (priv->got_video_src > 0)
1678 g_source_remove (priv->got_video_src);
1679 priv->got_video_src = 0;
1682 gtk_widget_show (priv->remote_user_avatar_widget);
1684 reset_details_pane (self);
1686 priv->sending_video = FALSE;
1687 priv->call_started = FALSE;
1689 could_disconnect = TRUE;
1691 /* TODO: display the self avatar of the preview (depends if the "Always
1692 * Show Video Preview" is enabled or not) */
1695 return could_disconnect;
1700 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1703 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1704 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1706 if (empathy_call_window_disconnected (self, TRUE) &&
1707 priv->call_state == REDIALING)
1708 empathy_call_window_restart_call (self);
1712 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1714 FsMediaType media_type,
1715 EmpathyCallWindow *self)
1717 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1719 DEBUG ("removing content");
1722 * This assumes that there is only one video stream per channel...
1725 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1727 if (priv->funnel != NULL)
1731 output = priv->video_output_sink;
1733 gst_element_set_state (output, GST_STATE_NULL);
1734 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1736 gst_bin_remove (GST_BIN (priv->pipeline), output);
1737 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1738 priv->funnel = NULL;
1742 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1744 if (priv->audio_output != NULL)
1746 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1748 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1749 priv->audio_output = NULL;
1757 /* Called with global lock held */
1759 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1761 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1765 if (priv->funnel == NULL)
1767 output = priv->video_output_sink;
1769 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1773 g_warning ("Could not create fsfunnel");
1777 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1779 gst_object_unref (priv->funnel);
1780 priv->funnel = NULL;
1781 g_warning ("Could not add funnel to pipeline");
1785 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1787 g_warning ("Could not add the video output widget to the pipeline");
1791 if (!gst_element_link (priv->funnel, output))
1793 g_warning ("Could not link output sink to funnel");
1794 goto error_output_added;
1797 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1799 g_warning ("Could not start video sink");
1800 goto error_output_added;
1803 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1805 g_warning ("Could not start funnel");
1806 goto error_output_added;
1810 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1813 g_warning ("Could not get request pad from funnel");
1820 gst_element_set_locked_state (priv->funnel, TRUE);
1821 gst_element_set_locked_state (output, TRUE);
1823 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1824 gst_element_set_state (output, GST_STATE_NULL);
1826 gst_bin_remove (GST_BIN (priv->pipeline), output);
1827 gst_element_set_locked_state (output, FALSE);
1831 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1832 priv->funnel = NULL;
1837 /* Called with global lock held */
1839 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1841 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1843 GstPadTemplate *template;
1845 if (priv->audio_output == NULL)
1847 priv->audio_output = empathy_audio_sink_new ();
1848 g_object_ref_sink (priv->audio_output);
1850 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1852 g_warning ("Could not add audio sink to pipeline");
1853 g_object_unref (priv->audio_output);
1854 goto error_add_output;
1857 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1859 g_warning ("Could not start audio sink");
1864 template = gst_element_class_get_pad_template (
1865 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
1867 pad = gst_element_request_pad (priv->audio_output,
1868 template, NULL, NULL);
1872 g_warning ("Could not get sink pad from sink");
1879 gst_element_set_locked_state (priv->audio_output, TRUE);
1880 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1881 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1882 priv->audio_output = NULL;
1890 empathy_call_window_update_timer (gpointer user_data)
1892 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1893 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1897 time_ = g_timer_elapsed (priv->timer, NULL);
1899 /* Translators: 'status - minutes:seconds' the caller has been connected */
1900 str = g_strdup_printf (_("%s — %d:%02dm"),
1901 priv->call_state == HELD ? _("On hold") : _("Connected"),
1902 (int) time_ / 60, (int) time_ % 60);
1903 empathy_call_window_status_message (self, str);
1911 display_error (EmpathyCallWindow *self,
1912 TpyCallChannel *call,
1916 const gchar *details)
1918 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1919 GtkWidget *info_bar;
1920 GtkWidget *content_area;
1927 /* Create info bar */
1928 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1931 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
1933 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
1935 /* hbox containing the image and the messages vbox */
1936 hbox = gtk_hbox_new (FALSE, 3);
1937 gtk_container_add (GTK_CONTAINER (content_area), hbox);
1940 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
1941 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1943 /* vbox containing the main message and the details expander */
1944 vbox = gtk_vbox_new (FALSE, 3);
1945 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
1948 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
1950 label = gtk_label_new (NULL);
1951 gtk_label_set_markup (GTK_LABEL (label), txt);
1952 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1953 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1956 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
1959 if (details != NULL)
1961 GtkWidget *expander;
1963 expander = gtk_expander_new (_("Technical Details"));
1965 txt = g_strdup_printf ("<i>%s</i>", details);
1967 label = gtk_label_new (NULL);
1968 gtk_label_set_markup (GTK_LABEL (label), txt);
1969 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1970 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1973 gtk_container_add (GTK_CONTAINER (expander), label);
1974 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
1977 g_signal_connect (info_bar, "response",
1978 G_CALLBACK (gtk_widget_destroy), NULL);
1980 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
1981 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1982 gtk_widget_show_all (info_bar);
1986 media_stream_error_to_txt (EmpathyCallWindow *self,
1987 TpyCallChannel *call,
1989 TpMediaStreamError error)
1991 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1992 const gchar *cm = NULL;
1998 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2000 return g_strdup_printf (
2001 _("%s's software does not understand any of the audio formats "
2002 "supported by your computer"),
2003 empathy_contact_get_alias (priv->contact));
2005 return g_strdup_printf (
2006 _("%s's software does not understand any of the video formats "
2007 "supported by your computer"),
2008 empathy_contact_get_alias (priv->contact));
2010 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2011 return g_strdup_printf (
2012 _("Can't establish a connection to %s. "
2013 "One of you might be on a network that does not allow "
2014 "direct connections."),
2015 empathy_contact_get_alias (priv->contact));
2017 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2018 return g_strdup (_("There was a failure on the network"));
2020 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2022 return g_strdup (_("The audio formats necessary for this call "
2023 "are not installed on your computer"));
2025 return g_strdup (_("The video formats necessary for this call "
2026 "are not installed on your computer"));
2028 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2029 tp_connection_parse_object_path (
2030 tp_channel_borrow_connection (TP_CHANNEL (call)),
2033 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2034 "product=Telepathy&component=%s", cm);
2036 result = g_strdup_printf (
2037 _("Something unexpected happened in a Telepathy component. "
2038 "Please <a href=\"%s\">report this bug</a> and attach "
2039 "logs gathered from the 'Debug' window in the Help menu."), url);
2045 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2046 return g_strdup (_("There was a failure in the call engine"));
2048 case TP_MEDIA_STREAM_ERROR_EOS:
2049 return g_strdup (_("The end of the stream was reached"));
2051 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2058 empathy_call_window_stream_error (EmpathyCallWindow *self,
2059 TpyCallChannel *call,
2068 desc = media_stream_error_to_txt (self, call, audio, code);
2071 /* No description, use the error message. That's not great as it's not
2072 * localized but it's better than nothing. */
2073 display_error (self, call, icon, title, msg, NULL);
2077 display_error (self, call, icon, title, desc, msg);
2083 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2086 EmpathyCallWindow *self)
2088 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2089 "gnome-stock-mic", _("Can't establish audio stream"));
2093 empathy_call_window_video_stream_error (TpyCallChannel *call,
2096 EmpathyCallWindow *self)
2098 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2099 "camera-web", _("Can't establish video stream"));
2104 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2106 EmpathyCallWindow *self)
2108 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2109 TpyCallChannel *call;
2110 gboolean can_send_video;
2112 if (state != TPY_CALL_STATE_ACCEPTED)
2115 if (priv->call_state == CONNECTED)
2118 g_timer_start (priv->timer);
2119 priv->call_state = CONNECTED;
2121 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2123 can_send_video = priv->video_input != NULL &&
2124 empathy_contact_can_voip_video (priv->contact) &&
2125 empathy_camera_monitor_get_available (priv->camera_monitor);
2127 g_object_get (priv->handler, "call-channel", &call, NULL);
2129 if (tpy_call_channel_has_dtmf (call))
2130 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2132 if (priv->video_input == NULL)
2133 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2135 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2137 empathy_call_window_show_hangup_button (self, TRUE);
2139 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2141 clutter_actor_hide (priv->video_output);
2142 gtk_widget_show (priv->remote_user_avatar_widget);
2144 g_object_unref (call);
2146 g_mutex_lock (priv->lock);
2148 priv->timer_id = g_timeout_add_seconds (1,
2149 empathy_call_window_update_timer, self);
2151 g_mutex_unlock (priv->lock);
2153 empathy_call_window_update_timer (self);
2155 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2159 empathy_call_window_show_video_output_cb (gpointer user_data)
2161 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2163 if (self->priv->video_output != NULL)
2165 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2166 clutter_actor_show (self->priv->video_output);
2173 empathy_call_window_check_video_cb (gpointer data)
2175 EmpathyCallWindow *self = data;
2177 if (self->priv->got_video)
2179 self->priv->got_video = FALSE;
2183 /* No video in the last N seconds, display the remote avatar */
2184 empathy_call_window_show_video_output (self, FALSE);
2189 /* Called from the streaming thread */
2191 empathy_call_window_video_probe_cb (GstPad *pad,
2192 GstMiniObject *mini_obj,
2193 EmpathyCallWindow *self)
2196 if (GST_IS_EVENT (mini_obj))
2199 if (G_UNLIKELY (!self->priv->got_video))
2201 /* show the remote video */
2202 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2203 empathy_call_window_show_video_output_cb,
2204 g_object_ref (self), g_object_unref);
2206 self->priv->got_video = TRUE;
2212 /* Called from the streaming thread */
2214 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2215 GstPad *src, guint media_type, gpointer user_data)
2217 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2218 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2219 gboolean retval = FALSE;
2223 g_mutex_lock (priv->lock);
2227 case TP_MEDIA_STREAM_TYPE_AUDIO:
2228 pad = empathy_call_window_get_audio_sink_pad (self);
2230 case TP_MEDIA_STREAM_TYPE_VIDEO:
2231 g_idle_add (empathy_call_window_show_video_output_cb, self);
2232 pad = empathy_call_window_get_video_sink_pad (self);
2234 gst_pad_add_data_probe (src,
2235 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2236 if (priv->got_video_src > 0)
2237 g_source_remove (priv->got_video_src);
2238 priv->got_video_src = g_timeout_add_seconds (5,
2239 empathy_call_window_check_video_cb, self);
2242 g_assert_not_reached ();
2248 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2249 g_warning ("Could not link %s sink pad",
2250 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2254 gst_object_unref (pad);
2258 /* If no sink could be linked, try to add fakesink to prevent the whole call
2263 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2265 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2267 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2268 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2269 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2271 gst_element_set_locked_state (fakesink, TRUE);
2272 gst_element_set_state (fakesink, GST_STATE_NULL);
2273 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2277 DEBUG ("Could not link real sink, linked fakesink instead");
2279 gst_object_unref (sinkpad);
2283 gst_object_unref (fakesink);
2288 g_mutex_unlock (priv->lock);
2294 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2295 GstPad *sink, FsMediaType media_type, gpointer user_data)
2297 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2298 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2300 gboolean retval = FALSE;
2304 case FS_MEDIA_TYPE_AUDIO:
2305 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2307 g_warning ("Could not add audio source to pipeline");
2311 pad = gst_element_get_static_pad (priv->audio_input, "src");
2314 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2315 g_warning ("Could not get source pad from audio source");
2319 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2321 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2322 g_warning ("Could not link audio source to farsight");
2326 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2328 g_warning ("Could not start audio source");
2329 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2330 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2336 case FS_MEDIA_TYPE_VIDEO:
2337 if (priv->video_tee != NULL)
2339 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2340 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2342 g_warning ("Could not link video source input pipeline");
2345 gst_object_unref (pad);
2351 g_assert_not_reached ();
2358 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2360 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2361 GstElement *preview;
2363 disable_camera (self);
2365 DEBUG ("remove video input");
2366 preview = priv->video_preview_sink;
2368 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2369 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2370 gst_element_set_state (preview, GST_STATE_NULL);
2372 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2375 g_object_unref (priv->video_input);
2376 priv->video_input = NULL;
2377 g_object_unref (priv->video_tee);
2378 priv->video_tee = NULL;
2379 clutter_actor_destroy (priv->video_preview);
2380 priv->video_preview = NULL;
2382 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2386 start_call (EmpathyCallWindow *self)
2388 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2390 priv->call_started = TRUE;
2391 empathy_call_handler_start_call (priv->handler,
2392 gtk_get_current_event_time ());
2394 if (empathy_call_handler_has_initial_video (priv->handler))
2396 TpyCallChannel *call;
2399 g_object_get (priv->handler, "call-channel", &call, NULL);
2400 s = tpy_call_channel_get_video_state (call);
2402 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2403 s == TPY_SENDING_STATE_SENDING)
2405 /* Enable 'send video' buttons and display the preview */
2406 gtk_toggle_tool_button_set_active (
2407 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2411 gtk_toggle_tool_button_set_active (
2412 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2414 if (priv->video_preview == NULL)
2416 create_video_preview (self);
2417 add_video_preview_to_pipeline (self);
2421 g_object_unref (call);
2426 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2429 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2430 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2433 empathy_call_handler_bus_message (priv->handler, bus, message);
2435 switch (GST_MESSAGE_TYPE (message))
2437 case GST_MESSAGE_STATE_CHANGED:
2438 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2440 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2442 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2443 !priv->call_started)
2445 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2446 if (newstate == GST_STATE_PAUSED)
2448 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2449 priv->pipeline_playing = TRUE;
2451 if (priv->start_call_when_playing)
2456 case GST_MESSAGE_ERROR:
2458 GError *error = NULL;
2459 GstElement *gst_error;
2462 gst_message_parse_error (message, &error, &debug);
2463 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2465 g_message ("Element error: %s -- %s\n", error->message, debug);
2467 if (g_str_has_prefix (gst_element_get_name (gst_error),
2468 VIDEO_INPUT_ERROR_PREFIX))
2470 /* Remove the video input and continue */
2471 if (priv->video_input != NULL)
2472 empathy_call_window_remove_video_input (self);
2473 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2477 empathy_call_window_disconnected (self, TRUE);
2479 g_error_free (error);
2482 case GST_MESSAGE_UNKNOWN:
2483 case GST_MESSAGE_EOS:
2484 case GST_MESSAGE_WARNING:
2485 case GST_MESSAGE_INFO:
2486 case GST_MESSAGE_TAG:
2487 case GST_MESSAGE_BUFFERING:
2488 case GST_MESSAGE_STATE_DIRTY:
2489 case GST_MESSAGE_STEP_DONE:
2490 case GST_MESSAGE_CLOCK_PROVIDE:
2491 case GST_MESSAGE_CLOCK_LOST:
2492 case GST_MESSAGE_NEW_CLOCK:
2493 case GST_MESSAGE_STRUCTURE_CHANGE:
2494 case GST_MESSAGE_STREAM_STATUS:
2495 case GST_MESSAGE_APPLICATION:
2496 case GST_MESSAGE_ELEMENT:
2497 case GST_MESSAGE_SEGMENT_START:
2498 case GST_MESSAGE_SEGMENT_DONE:
2499 case GST_MESSAGE_DURATION:
2500 case GST_MESSAGE_ANY:
2509 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2510 GHashTable *members,
2511 EmpathyCallWindow *self)
2513 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2514 GHashTableIter iter;
2515 gpointer key, value;
2516 gboolean held = FALSE;
2518 g_hash_table_iter_init (&iter, members);
2519 while (g_hash_table_iter_next (&iter, &key, &value))
2521 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2523 /* This assumes this is a 1-1 call, otherwise one participant
2524 * putting the call on hold wouldn't mean the call is on hold
2532 priv->call_state = HELD;
2533 else if (priv->call_state == HELD)
2534 priv->call_state = CONNECTED;
2538 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2540 EmpathyCallWindow *self)
2542 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2543 TpyCallChannel *call;
2545 g_object_get (priv->handler, "call-channel", &call, NULL);
2550 tp_g_signal_connect_object (call, "audio-stream-error",
2551 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2552 tp_g_signal_connect_object (call, "video-stream-error",
2553 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2556 tp_g_signal_connect_object (call, "members-changed",
2557 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2559 g_object_unref (call);
2563 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2565 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2566 TpyCallChannel *call;
2569 /* Make the hangup button twice as wide */
2570 width = gtk_widget_get_allocated_width (priv->hangup_button);
2571 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2573 g_signal_connect (priv->handler, "state-changed",
2574 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2575 g_signal_connect (priv->handler, "conference-added",
2576 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2577 g_signal_connect (priv->handler, "conference-removed",
2578 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2579 g_signal_connect (priv->handler, "closed",
2580 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2581 g_signal_connect (priv->handler, "src-pad-added",
2582 G_CALLBACK (empathy_call_window_src_added_cb), window);
2583 g_signal_connect (priv->handler, "sink-pad-added",
2584 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2585 g_signal_connect (priv->handler, "sink-pad-removed",
2586 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2588 g_object_get (priv->handler, "call-channel", &call, NULL);
2591 call_handler_notify_call_cb (priv->handler, NULL, window);
2592 g_object_unref (call);
2596 /* call-channel doesn't exist yet, we'll connect signals once it has been
2598 g_signal_connect (priv->handler, "notify::call-channel",
2599 G_CALLBACK (call_handler_notify_call_cb), window);
2602 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2606 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2607 EmpathyCallWindow *window)
2609 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2611 if (priv->pipeline != NULL)
2613 if (priv->bus_message_source_id != 0)
2615 g_source_remove (priv->bus_message_source_id);
2616 priv->bus_message_source_id = 0;
2619 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2622 if (priv->call_state == CONNECTING)
2623 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2629 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2632 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2634 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2639 gtk_widget_hide (priv->dtmf_panel);
2640 gtk_widget_hide (menu);
2641 gtk_widget_hide (priv->toolbar);
2645 if (priv->dialpad_was_visible_before_fs)
2646 gtk_widget_show (priv->dtmf_panel);
2648 gtk_widget_show (menu);
2649 gtk_widget_show (priv->toolbar);
2651 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2652 priv->original_height_before_fs);
2657 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2659 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2661 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2662 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2663 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2664 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2666 if (priv->video_output != NULL)
2669 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2670 priv->video_output, TRUE, TRUE,
2671 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2678 empathy_call_window_state_event_cb (GtkWidget *widget,
2679 GdkEventWindowState *event, EmpathyCallWindow *window)
2681 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2683 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2684 gboolean set_fullscreen = event->new_window_state &
2685 GDK_WINDOW_STATE_FULLSCREEN;
2689 gboolean dialpad_was_visible;
2690 GtkAllocation allocation;
2691 gint original_width, original_height;
2693 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2694 original_width = allocation.width;
2695 original_height = allocation.height;
2697 g_object_get (priv->dtmf_panel,
2698 "visible", &dialpad_was_visible,
2701 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2702 priv->original_width_before_fs = original_width;
2703 priv->original_height_before_fs = original_height;
2705 if (priv->video_output_motion_handler_id == 0 &&
2706 priv->video_output != NULL)
2708 priv->video_output_motion_handler_id = g_signal_connect (
2709 G_OBJECT (priv->video_container), "motion-notify-event",
2710 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2716 disconnect_video_output_motion_handler (window);
2719 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2721 show_controls (window, set_fullscreen);
2722 show_borders (window, set_fullscreen);
2723 gtk_action_set_stock_id (priv->menu_fullscreen,
2724 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2725 priv->is_fullscreen = set_fullscreen;
2732 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2735 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2736 int w, h, dialpad_width;
2737 GtkAllocation allocation;
2739 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2740 w = allocation.width;
2741 h = allocation.height;
2743 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2747 gtk_widget_show (priv->dtmf_panel);
2753 gtk_widget_hide (priv->dtmf_panel);
2757 gtk_window_resize (GTK_WINDOW (window), w, h);
2761 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2764 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2765 TpyCallChannel *call;
2767 priv->sending_video = (state == CAMERA_STATE_ON);
2769 if (state == CAMERA_STATE_ON)
2771 /* When we start sending video, we want to show the video preview by
2773 display_video_preview (window, TRUE);
2777 display_video_preview (window, FALSE);
2780 if (priv->call_state != CONNECTED)
2783 g_object_get (priv->handler, "call-channel", &call, NULL);
2784 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2785 tpy_call_channel_send_video (call, priv->sending_video);
2786 g_object_unref (call);
2790 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2791 EmpathyCallWindow *window)
2793 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2796 active = (gtk_toggle_tool_button_get_active (toggle));
2800 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2801 priv->volume * 100);
2805 /* TODO, Instead of setting the input volume to 0 we should probably
2806 * stop sending but this would cause the audio call to drop if both
2807 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2808 * in the future. GNOME #574574
2810 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2816 empathy_call_window_hangup_cb (gpointer object,
2817 EmpathyCallWindow *window)
2819 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2821 empathy_call_handler_stop_call (priv->handler);
2823 if (empathy_call_window_disconnected (window, FALSE))
2824 gtk_widget_destroy (GTK_WIDGET (window));
2828 empathy_call_window_restart_call (EmpathyCallWindow *window)
2830 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2832 /* Remove error info bars */
2833 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
2834 (GtkCallback) gtk_widget_destroy, NULL);
2836 create_video_output_widget (window);
2838 /* While the call was disconnected, the input volume might have changed.
2839 * However, since the audio_input source was destroyed, its volume has not
2840 * been updated during that time. That's why we manually update it here */
2841 empathy_call_window_mic_volume_changed (window);
2843 priv->outgoing = TRUE;
2844 empathy_call_window_set_state_connecting (window);
2846 if (priv->pipeline_playing)
2847 start_call (window);
2849 /* call will be started when the pipeline is ready */
2850 priv->start_call_when_playing = TRUE;
2852 empathy_call_window_setup_avatars (window, priv->handler);
2854 empathy_call_window_show_hangup_button (window, TRUE);
2858 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
2859 EmpathyCallWindow *window)
2863 active = gtk_toggle_tool_button_get_active (button);
2865 empathy_call_window_show_dialpad (window, active);
2869 empathy_call_window_fullscreen_cb (gpointer object,
2870 EmpathyCallWindow *window)
2872 empathy_call_window_fullscreen_toggle (window);
2876 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2878 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2880 if (priv->is_fullscreen)
2881 gtk_window_unfullscreen (GTK_WINDOW (window));
2883 gtk_window_fullscreen (GTK_WINDOW (window));
2887 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
2888 GdkEventButton *event, EmpathyCallWindow *window)
2890 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2892 empathy_call_window_video_menu_popup (window, event->button);
2900 empathy_call_window_key_press_cb (GtkWidget *video_output,
2901 GdkEventKey *event, EmpathyCallWindow *window)
2903 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2905 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
2907 /* Since we are in fullscreen mode, toggling will bring us back to
2909 empathy_call_window_fullscreen_toggle (window);
2917 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
2918 GdkEventMotion *event, EmpathyCallWindow *window)
2920 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2922 if (priv->is_fullscreen)
2924 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
2931 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
2935 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2937 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2939 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
2940 button, gtk_get_current_event_time ());
2941 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
2945 empathy_call_window_status_message (EmpathyCallWindow *self,
2948 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
2952 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
2953 gdouble value, EmpathyCallWindow *window)
2955 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2957 if (priv->audio_output == NULL)
2960 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),