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"
67 #define CONTENT_HBOX_BORDER_WIDTH 6
68 #define CONTENT_HBOX_SPACING 3
69 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
71 #define SELF_VIDEO_SECTION_WIDTH 120
72 #define SELF_VIDEO_SECTION_HEIGTH 90
74 /* The avatar's default width and height are set to the same value because we
75 want a square icon. */
76 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
77 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
78 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
80 #define SMALL_TOOLBAR_SIZE 36
82 /* If an video input error occurs, the error message will start with "v4l" */
83 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
85 /* The time interval in milliseconds between 2 outgoing rings */
86 #define MS_BETWEEN_RING 500
88 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
91 PROP_CALL_HANDLER = 1,
103 CAMERA_STATE_OFF = 0,
107 struct _EmpathyCallWindowPriv
109 gboolean dispose_has_run;
110 EmpathyCallHandler *handler;
112 EmpathyContact *contact;
114 EmpathyCameraMonitor *camera_monitor;
119 GtkUIManager *ui_manager;
120 GtkWidget *errors_vbox;
121 /* widget displays the video received from the remote user. This widget is
122 * alive only during call. */
123 ClutterActor *video_output;
124 ClutterActor *video_preview;
125 ClutterActor *preview_hidden_button;
126 GtkWidget *video_container;
127 GtkWidget *remote_user_avatar_widget;
128 GtkWidget *remote_user_avatar_toolbar;
129 GtkWidget *remote_user_name_toolbar;
130 GtkWidget *status_label;
131 GtkWidget *hangup_button;
132 GtkWidget *audio_call_button;
133 GtkWidget *video_call_button;
134 GtkWidget *mic_button;
135 GtkWidget *camera_button;
136 GtkWidget *dialpad_button;
138 GtkWidget *bottom_toolbar;
140 GtkAction *menu_fullscreen;
142 /* The box that contains self and remote avatar and video
143 input/output. When we redial, we destroy and re-create the box */
144 ClutterActor *video_box;
145 ClutterLayoutManager *video_layout;
147 /* We keep a reference on the hbox which contains the main content so we can
148 easilly repack everything when toggling fullscreen */
149 GtkWidget *content_hbox;
151 gulong video_output_motion_handler_id;
152 guint bus_message_source_id;
156 GtkWidget *dtmf_panel;
159 GtkWidget *details_vbox;
160 GtkWidget *vcodec_encoding_label;
161 GtkWidget *acodec_encoding_label;
162 GtkWidget *vcodec_decoding_label;
163 GtkWidget *acodec_decoding_label;
165 GtkWidget *audio_remote_candidate_label;
166 GtkWidget *audio_local_candidate_label;
167 GtkWidget *video_remote_candidate_label;
168 GtkWidget *video_local_candidate_label;
169 GtkWidget *video_remote_candidate_info_img;
170 GtkWidget *video_local_candidate_info_img;
171 GtkWidget *audio_remote_candidate_info_img;
172 GtkWidget *audio_local_candidate_info_img;
174 GstElement *video_input;
175 GstElement *video_preview_sink;
176 GstElement *video_output_sink;
177 GstElement *audio_input;
178 GstElement *audio_output;
179 GstElement *pipeline;
180 GstElement *video_tee;
190 gboolean call_started;
191 gboolean sending_video;
192 CameraState camera_state;
194 EmpathyCallWindowFullscreen *fullscreen;
195 gboolean is_fullscreen;
200 /* Those fields represent the state of the window before it actually was in
202 gboolean dialpad_was_visible_before_fs;
203 gint original_width_before_fs;
204 gint original_height_before_fs;
206 gint x, y, w, h, dialpad_width;
209 /* TRUE if the call should be started when the pipeline is playing */
210 gboolean start_call_when_playing;
211 /* TRUE if we requested to set the pipeline in the playing state */
212 gboolean pipeline_playing;
214 EmpathySoundManager *sound_mgr;
217 EmpathyMicMenu *mic_menu;
220 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
222 static void empathy_call_window_realized_cb (GtkWidget *widget,
223 EmpathyCallWindow *window);
225 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
226 GdkEvent *event, EmpathyCallWindow *window);
228 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
229 GdkEventWindowState *event, EmpathyCallWindow *window);
231 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
234 static void empathy_call_window_mic_toggled_cb (
235 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
237 static void empathy_call_window_hangup_cb (gpointer object,
238 EmpathyCallWindow *window);
240 static void empathy_call_window_fullscreen_cb (gpointer object,
241 EmpathyCallWindow *window);
243 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
245 static gboolean empathy_call_window_video_button_press_cb (
246 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
248 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
249 GdkEventKey *event, EmpathyCallWindow *window);
251 static gboolean empathy_call_window_video_output_motion_notify (
252 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
254 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
257 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
258 EmpathyCallWindow *window);
260 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
262 static void empathy_call_window_status_message (EmpathyCallWindow *window,
265 static gboolean empathy_call_window_bus_message (GstBus *bus,
266 GstMessage *message, gpointer user_data);
269 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
270 gdouble value, EmpathyCallWindow *window);
273 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
276 gtk_widget_set_visible (self->priv->hangup_button, show);
277 gtk_widget_set_visible (self->priv->audio_call_button, !show);
278 gtk_widget_set_visible (self->priv->video_call_button, !show);
282 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
283 EmpathyCallWindow *self)
285 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
286 empathy_call_window_restart_call (self);
290 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
291 EmpathyCallWindow *self)
293 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
294 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
295 empathy_call_window_restart_call (self);
299 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
301 EmpathyCallWindowPriv *priv = GET_PRIV (window);
302 TpyCallChannel *call;
306 g_object_get (priv->handler, "call-channel", &call, NULL);
308 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
309 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
312 tpy_call_channel_dtmf_start_tone (call, event);
314 g_object_unref (call);
318 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
320 EmpathyCallWindowPriv *priv = GET_PRIV (window);
321 TpyCallChannel *call;
323 g_object_get (priv->handler, "call-channel", &call, NULL);
325 tpy_call_channel_dtmf_stop_tone (call);
327 g_object_unref (call);
331 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
333 EmpathyCallWindowPriv *priv = GET_PRIV (self);
336 volume = g_settings_get_double (priv->settings,
337 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
339 /* Don't store the volume because of muting */
340 if (volume > 0 || gtk_toggle_tool_button_get_active (
341 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
342 priv->volume = volume;
344 /* Ensure that the toggle button is active if the volume is > 0 and inactive
345 * if it's smaller than 0 */
346 if ((volume > 0) != gtk_toggle_tool_button_get_active (
347 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
348 gtk_toggle_tool_button_set_active (
349 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
351 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
356 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
358 EmpathyCallWindow *self)
360 empathy_call_window_mic_volume_changed (self);
364 empathy_call_window_show_video_output (EmpathyCallWindow *self,
367 if (self->priv->video_output != NULL)
368 g_object_set (self->priv->video_output, "visible", show, NULL);
370 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
374 create_video_output_widget (EmpathyCallWindow *self)
376 EmpathyCallWindowPriv *priv = GET_PRIV (self);
378 g_assert (priv->video_output == NULL);
379 g_assert (priv->pipeline != NULL);
381 priv->video_output = clutter_texture_new ();
383 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
386 priv->video_output_sink = clutter_gst_video_sink_new (
387 CLUTTER_TEXTURE (priv->video_output));
389 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
392 gtk_widget_add_events (priv->video_container,
393 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
394 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
395 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
399 create_video_input (EmpathyCallWindow *self)
401 EmpathyCallWindowPriv *priv = GET_PRIV (self);
403 g_assert (priv->video_input == NULL);
404 priv->video_input = empathy_video_src_new ();
405 gst_object_ref (priv->video_input);
406 gst_object_sink (priv->video_input);
410 create_audio_input (EmpathyCallWindow *self)
412 EmpathyCallWindowPriv *priv = GET_PRIV (self);
414 g_assert (priv->audio_input == NULL);
415 priv->audio_input = empathy_audio_src_new ();
416 gst_object_ref (priv->audio_input);
417 gst_object_sink (priv->audio_input);
421 add_video_preview_to_pipeline (EmpathyCallWindow *self)
423 EmpathyCallWindowPriv *priv = GET_PRIV (self);
426 g_assert (priv->video_preview != NULL);
427 g_assert (priv->pipeline != NULL);
428 g_assert (priv->video_input != NULL);
429 g_assert (priv->video_tee != NULL);
431 preview = priv->video_preview_sink;
433 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
435 g_warning ("Could not add video input to pipeline");
439 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
441 g_warning ("Could not add video preview to pipeline");
445 if (!gst_element_link (priv->video_input, priv->video_tee))
447 g_warning ("Could not link video input to video tee");
451 if (!gst_element_link (priv->video_tee, preview))
453 g_warning ("Could not link video tee to video preview");
459 empathy_call_window_disable_camera_cb (GtkAction *action,
460 EmpathyCallWindow *self)
462 clutter_actor_destroy (self->priv->preview_hidden_button);
464 gtk_toggle_tool_button_set_active (
465 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
469 empathy_call_window_minimise_camera_cb (GtkAction *action,
470 EmpathyCallWindow *self)
472 clutter_actor_hide (self->priv->video_preview);
473 clutter_actor_show (self->priv->preview_hidden_button);
477 empathy_call_window_maximise_camera_cb (GtkAction *action,
478 EmpathyCallWindow *self)
480 clutter_actor_show (self->priv->video_preview);
481 clutter_actor_hide (self->priv->preview_hidden_button);
485 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
486 EmpathyCallWindow *self)
490 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
492 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
493 0, gtk_get_current_event_time ());
494 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
498 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
499 EmpathyCallWindow *self)
503 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
504 "/preview-hidden-menu");
505 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
506 0, gtk_get_current_event_time ());
507 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
511 create_video_preview (EmpathyCallWindow *self)
513 EmpathyCallWindowPriv *priv = GET_PRIV (self);
514 ClutterLayoutManager *layout, *layout_center;
515 ClutterActor *preview;
520 g_assert (priv->video_preview == NULL);
522 preview = clutter_texture_new ();
523 clutter_actor_set_size (preview,
524 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
525 priv->video_preview_sink = clutter_gst_video_sink_new (
526 CLUTTER_TEXTURE (preview));
528 /* Flip the video preview */
529 clutter_actor_set_rotation (preview,
532 SELF_VIDEO_SECTION_WIDTH * 0.5,
536 /* Add a little offset to the video preview */
537 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
538 CLUTTER_BIN_ALIGNMENT_START);
539 priv->video_preview = clutter_box_new (layout);
540 clutter_actor_set_size (priv->video_preview,
541 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
543 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
544 CLUTTER_BIN_ALIGNMENT_CENTER);
545 box = clutter_box_new (layout_center);
546 clutter_actor_set_size (box,
547 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
549 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
550 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
552 g_object_set (priv->video_preview_sink,
557 /* Translators: this is an "Info" label. It should be as short
559 button = gtk_button_new_with_label (_("i"));
560 b = gtk_clutter_actor_new_with_contents (button);
562 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
564 CLUTTER_BIN_ALIGNMENT_END,
565 CLUTTER_BIN_ALIGNMENT_END);
567 g_signal_connect (button, "clicked",
568 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
571 /* Translators: this is an "Info" label. It should be as short
573 button = gtk_button_new_with_label (_("i"));
574 priv->preview_hidden_button =
575 gtk_clutter_actor_new_with_contents (button);
577 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
578 priv->preview_hidden_button,
579 CLUTTER_BIN_ALIGNMENT_START,
580 CLUTTER_BIN_ALIGNMENT_END);
582 clutter_actor_hide (priv->preview_hidden_button);
584 g_signal_connect (button, "clicked",
585 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
588 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
590 CLUTTER_BIN_ALIGNMENT_START,
591 CLUTTER_BIN_ALIGNMENT_END);
595 play_camera (EmpathyCallWindow *window,
598 EmpathyCallWindowPriv *priv = GET_PRIV (window);
602 if (priv->video_preview == NULL)
604 create_video_preview (window);
605 add_video_preview_to_pipeline (window);
609 state = GST_STATE_PLAYING;
611 state = GST_STATE_NULL;
613 preview = priv->video_preview_sink;
615 gst_element_set_state (preview, state);
616 gst_element_set_state (priv->video_input, state);
617 gst_element_set_state (priv->video_tee, state);
621 display_video_preview (EmpathyCallWindow *self,
624 EmpathyCallWindowPriv *priv = GET_PRIV (self);
628 /* Display the video preview */
629 DEBUG ("Show video preview");
631 play_camera (self, TRUE);
632 clutter_actor_show (priv->video_preview);
636 /* Hide the video preview */
637 DEBUG ("Hide video preview");
639 if (priv->video_preview != NULL)
641 clutter_actor_hide (priv->video_preview);
642 play_camera (self, FALSE);
648 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
650 EmpathyCallWindowPriv *priv = GET_PRIV (window);
652 empathy_call_window_status_message (window, _("Connecting…"));
653 priv->call_state = CONNECTING;
656 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
657 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
661 disable_camera (EmpathyCallWindow *self)
663 EmpathyCallWindowPriv *priv = GET_PRIV (self);
665 if (priv->camera_state == CAMERA_STATE_OFF)
668 DEBUG ("Disable camera");
670 display_video_preview (self, FALSE);
672 if (priv->camera_state == CAMERA_STATE_ON)
673 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
675 priv->camera_state = CAMERA_STATE_OFF;
679 enable_camera (EmpathyCallWindow *self)
681 EmpathyCallWindowPriv *priv = GET_PRIV (self);
683 if (priv->camera_state == CAMERA_STATE_ON)
686 if (priv->video_input == NULL)
688 DEBUG ("Can't enable camera, no input");
692 DEBUG ("Enable camera");
694 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
696 priv->camera_state = CAMERA_STATE_ON;
700 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
701 EmpathyCallWindow *self)
703 if (gtk_toggle_tool_button_get_active (toggle))
704 enable_camera (self);
706 disable_camera (self);
710 create_pipeline (EmpathyCallWindow *self)
712 EmpathyCallWindowPriv *priv = GET_PRIV (self);
715 g_assert (priv->pipeline == NULL);
717 priv->pipeline = gst_pipeline_new (NULL);
718 priv->pipeline_playing = FALSE;
720 priv->video_tee = gst_element_factory_make ("tee", NULL);
721 gst_object_ref (priv->video_tee);
722 gst_object_sink (priv->video_tee);
724 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
726 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
727 priv->bus_message_source_id = gst_bus_add_watch (bus,
728 empathy_call_window_bus_message, self);
730 g_object_unref (bus);
734 empathy_call_window_contents_cb (GtkAction *action,
735 EmpathyCallWindow *self)
737 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
741 empathy_call_window_about_cb (GtkAction *action,
742 EmpathyCallWindow *self)
744 empathy_about_dialog_new (GTK_WINDOW (self));
748 empathy_call_window_configure_event_cb (GtkWidget *widget,
750 EmpathyCallWindow *self)
752 GdkWindow *gdk_window;
753 GdkWindowState window_state;
755 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
756 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
758 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
759 &self->priv->dialpad_width, NULL);
761 gdk_window = gtk_widget_get_window (widget);
762 window_state = gdk_window_get_state (gdk_window);
763 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
769 empathy_call_window_destroyed_cb (GtkWidget *object,
770 EmpathyCallWindow *self)
772 if (gtk_widget_get_visible (self->priv->dtmf_panel))
774 /* Save the geometry as if the dialpad was hidden. */
775 empathy_geometry_save_values (GTK_WINDOW (self),
776 self->priv->x, self->priv->y,
777 self->priv->w - self->priv->dialpad_width, self->priv->h,
778 self->priv->maximized);
783 empathy_call_window_init (EmpathyCallWindow *self)
785 EmpathyCallWindowPriv *priv;
789 ClutterConstraint *size_constraint;
790 ClutterActor *remote_avatar;
791 GtkStyleContext *context;
795 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
796 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
798 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
799 gui = empathy_builder_get_file (filename,
800 "call_window_vbox", &top_vbox,
801 "errors_vbox", &priv->errors_vbox,
803 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
804 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
805 "status_label", &priv->status_label,
806 "audiocall", &priv->audio_call_button,
807 "videocall", &priv->video_call_button,
808 "microphone", &priv->mic_button,
809 "camera", &priv->camera_button,
810 "hangup", &priv->hangup_button,
811 "dialpad", &priv->dialpad_button,
812 "toolbar", &priv->toolbar,
813 "bottom_toolbar", &priv->bottom_toolbar,
814 "ui_manager", &priv->ui_manager,
815 "menufullscreen", &priv->menu_fullscreen,
816 "details_vbox", &priv->details_vbox,
817 "vcodec_encoding_label", &priv->vcodec_encoding_label,
818 "acodec_encoding_label", &priv->acodec_encoding_label,
819 "acodec_decoding_label", &priv->acodec_decoding_label,
820 "vcodec_decoding_label", &priv->vcodec_decoding_label,
821 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
822 "audio_local_candidate_label", &priv->audio_local_candidate_label,
823 "video_remote_candidate_label", &priv->video_remote_candidate_label,
824 "video_local_candidate_label", &priv->video_local_candidate_label,
825 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
826 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
827 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
828 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
832 empathy_builder_connect (gui, self,
833 "hangup", "clicked", empathy_call_window_hangup_cb,
834 "audiocall", "clicked", empathy_call_window_audio_call_cb,
835 "videocall", "clicked", empathy_call_window_video_call_cb,
836 "volume", "value-changed", empathy_call_window_volume_changed_cb,
837 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
838 "camera", "toggled", empathy_call_window_camera_toggled_cb,
839 "dialpad", "toggled", empathy_call_window_dialpad_cb,
840 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
841 "menucontents", "activate", empathy_call_window_contents_cb,
842 "menuabout", "activate", empathy_call_window_about_cb,
843 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
844 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
845 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
848 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
850 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
852 g_object_bind_property (priv->camera_monitor, "available",
853 priv->camera_button, "sensitive",
854 G_BINDING_SYNC_CREATE);
856 priv->lock = g_mutex_new ();
858 gtk_container_add (GTK_CONTAINER (self), top_vbox);
860 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
861 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
862 CONTENT_HBOX_BORDER_WIDTH);
863 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
866 /* avatar/video box */
867 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
868 CLUTTER_BIN_ALIGNMENT_CENTER);
870 priv->video_box = clutter_box_new (priv->video_layout);
872 priv->video_container = gtk_clutter_embed_new ();
874 /* Set the background color to that of the rest of the window */
875 context = gtk_widget_get_style_context (priv->content_hbox);
876 gtk_style_context_get_background_color (context,
877 GTK_STATE_FLAG_NORMAL, &rgba);
878 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
879 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
880 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
881 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
882 clutter_stage_set_color (
883 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
884 GTK_CLUTTER_EMBED (priv->video_container))),
887 clutter_container_add (
888 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
889 GTK_CLUTTER_EMBED (priv->video_container))),
893 size_constraint = clutter_bind_constraint_new (
894 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
895 CLUTTER_BIND_SIZE, 0);
896 clutter_actor_add_constraint (priv->video_box, size_constraint);
898 priv->remote_user_avatar_widget = gtk_image_new ();
899 remote_avatar = gtk_clutter_actor_new_with_contents (
900 priv->remote_user_avatar_widget);
902 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
905 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
906 priv->video_container, TRUE, TRUE,
907 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
909 create_pipeline (self);
910 create_video_output_widget (self);
911 create_audio_input (self);
912 create_video_input (self);
914 /* The call will be started as soon the pipeline is playing */
915 priv->start_call_when_playing = TRUE;
917 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
918 G_CALLBACK (dtmf_button_pressed_cb),
919 G_CALLBACK (dtmf_button_released_cb));
921 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
924 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
927 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
929 gtk_widget_show_all (top_vbox);
931 gtk_widget_hide (priv->dtmf_panel);
932 gtk_widget_hide (priv->details_vbox);
934 priv->fullscreen = empathy_call_window_fullscreen_new (self);
936 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
937 priv->video_container);
939 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
940 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
942 g_signal_connect (G_OBJECT (self), "realize",
943 G_CALLBACK (empathy_call_window_realized_cb), self);
945 g_signal_connect (G_OBJECT (self), "delete-event",
946 G_CALLBACK (empathy_call_window_delete_cb), self);
948 g_signal_connect (G_OBJECT (self), "window-state-event",
949 G_CALLBACK (empathy_call_window_state_event_cb), self);
951 g_signal_connect (G_OBJECT (self), "key-press-event",
952 G_CALLBACK (empathy_call_window_key_press_cb), self);
954 priv->timer = g_timer_new ();
956 g_object_ref (priv->ui_manager);
957 g_object_unref (gui);
959 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
960 priv->mic_menu = empathy_mic_menu_new (self);
962 empathy_call_window_show_hangup_button (self, TRUE);
964 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
965 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
966 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
968 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
969 /* These signals are used to track the window position and save it
970 * when the window is destroyed. We need to do this as we don't want
971 * the window geometry to be saved with the dialpad taken into account. */
972 g_signal_connect (self, "destroy",
973 G_CALLBACK (empathy_call_window_destroyed_cb), self);
974 g_signal_connect (self, "configure-event",
975 G_CALLBACK (empathy_call_window_configure_event_cb), self);
976 g_signal_connect (self, "window-state-event",
977 G_CALLBACK (empathy_call_window_configure_event_cb), self);
979 /* Don't display labels in both toolbars */
980 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
981 gtk_toolbar_set_style (GTK_TOOLBAR (priv->bottom_toolbar), GTK_TOOLBAR_ICONS);
984 /* Instead of specifying a width and a height, we specify only one size. That's
985 because we want a square avatar icon. */
987 init_contact_avatar_with_size (EmpathyContact *contact,
988 GtkWidget *image_widget,
991 GdkPixbuf *pixbuf_avatar = NULL;
995 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
999 if (pixbuf_avatar == NULL)
1001 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1002 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1005 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1007 if (pixbuf_avatar != NULL)
1008 g_object_unref (pixbuf_avatar);
1012 set_window_title (EmpathyCallWindow *self)
1014 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1017 if (priv->contact != NULL)
1019 /* translators: Call is a noun and %s is the contact name. This string
1020 * is used in the window title */
1021 tmp = g_strdup_printf (_("Call with %s"),
1022 empathy_contact_get_alias (priv->contact));
1023 gtk_window_set_title (GTK_WINDOW (self), tmp);
1028 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1033 set_remote_user_name (EmpathyCallWindow *self,
1034 EmpathyContact *contact)
1036 const gchar *alias = empathy_contact_get_alias (contact);
1037 const gchar *status = empathy_contact_get_status (contact);
1040 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1041 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1047 contact_name_changed_cb (EmpathyContact *contact,
1049 EmpathyCallWindow *self)
1051 set_window_title (self);
1052 set_remote_user_name (self, contact);
1056 contact_presence_changed_cb (EmpathyContact *contact,
1058 EmpathyCallWindow *self)
1060 set_remote_user_name (self, contact);
1064 contact_avatar_changed_cb (EmpathyContact *contact,
1066 EmpathyCallWindow *self)
1069 GtkAllocation allocation;
1070 GtkWidget *avatar_widget;
1072 avatar_widget = self->priv->remote_user_avatar_widget;
1074 gtk_widget_get_allocation (avatar_widget, &allocation);
1075 size = allocation.height;
1079 /* the widget is not allocated yet, set a default size */
1080 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1081 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1084 init_contact_avatar_with_size (contact, avatar_widget, size);
1086 avatar_widget = self->priv->remote_user_avatar_toolbar;
1088 gtk_widget_get_allocation (avatar_widget, &allocation);
1089 size = allocation.height;
1093 /* the widget is not allocated yet, set a default size */
1094 size = SMALL_TOOLBAR_SIZE;
1097 init_contact_avatar_with_size (contact, avatar_widget, size);
1101 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1102 EmpathyCallHandler *handler)
1104 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1106 tp_g_signal_connect_object (priv->contact, "notify::name",
1107 G_CALLBACK (contact_name_changed_cb), self, 0);
1108 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1109 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1110 tp_g_signal_connect_object (priv->contact, "notify::presence",
1111 G_CALLBACK (contact_presence_changed_cb), self, 0);
1113 set_window_title (self);
1114 set_remote_user_name (self, priv->contact);
1116 init_contact_avatar_with_size (priv->contact,
1117 priv->remote_user_avatar_widget,
1118 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1119 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1121 init_contact_avatar_with_size (priv->contact,
1122 priv->remote_user_avatar_toolbar,
1123 SMALL_TOOLBAR_SIZE);
1125 /* The remote avatar is shown by default and will be hidden when we receive
1126 video from the remote side. */
1127 clutter_actor_hide (priv->video_output);
1128 gtk_widget_show (priv->remote_user_avatar_widget);
1132 update_send_codec (EmpathyCallWindow *self,
1135 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1142 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1143 widget = priv->acodec_encoding_label;
1147 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1148 widget = priv->vcodec_encoding_label;
1154 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1155 gtk_label_set_text (GTK_LABEL (widget), tmp);
1160 send_audio_codec_notify_cb (GObject *object,
1164 EmpathyCallWindow *self = user_data;
1166 update_send_codec (self, TRUE);
1170 send_video_codec_notify_cb (GObject *object,
1174 EmpathyCallWindow *self = user_data;
1176 update_send_codec (self, FALSE);
1180 update_recv_codec (EmpathyCallWindow *self,
1183 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1186 GString *str = NULL;
1190 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1191 widget = priv->acodec_decoding_label;
1195 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1196 widget = priv->vcodec_decoding_label;
1202 for (l = codecs; l != NULL; l = g_list_next (l))
1204 FsCodec *codec = l->data;
1207 str = g_string_new (NULL);
1209 g_string_append (str, ", ");
1211 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1215 gtk_label_set_text (GTK_LABEL (widget), str->str);
1216 g_string_free (str, TRUE);
1220 recv_audio_codecs_notify_cb (GObject *object,
1224 EmpathyCallWindow *self = user_data;
1226 update_recv_codec (self, TRUE);
1230 recv_video_codecs_notify_cb (GObject *object,
1234 EmpathyCallWindow *self = user_data;
1236 update_recv_codec (self, FALSE);
1239 static const gchar *
1240 candidate_type_to_str (FsCandidate *candidate)
1242 switch (candidate->type)
1244 case FS_CANDIDATE_TYPE_HOST:
1246 case FS_CANDIDATE_TYPE_SRFLX:
1247 return "server reflexive";
1248 case FS_CANDIDATE_TYPE_PRFLX:
1249 return "peer reflexive";
1250 case FS_CANDIDATE_TYPE_RELAY:
1252 case FS_CANDIDATE_TYPE_MULTICAST:
1259 static const gchar *
1260 candidate_type_to_desc (FsCandidate *candidate)
1262 switch (candidate->type)
1264 case FS_CANDIDATE_TYPE_HOST:
1265 return _("The IP address as seen by the machine");
1266 case FS_CANDIDATE_TYPE_SRFLX:
1267 return _("The IP address as seen by a server on the Internet");
1268 case FS_CANDIDATE_TYPE_PRFLX:
1269 return _("The IP address of the peer as seen by the other side");
1270 case FS_CANDIDATE_TYPE_RELAY:
1271 return _("The IP address of a relay server");
1272 case FS_CANDIDATE_TYPE_MULTICAST:
1273 return _("The IP address of the multicast group");
1280 update_candidat_widget (EmpathyCallWindow *self,
1283 FsCandidate *candidate)
1287 g_assert (candidate != NULL);
1288 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1289 candidate->port, candidate_type_to_str (candidate));
1291 gtk_label_set_text (GTK_LABEL (label), str);
1292 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1298 candidates_changed_cb (GObject *object,
1300 EmpathyCallWindow *self)
1302 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1303 FsCandidate *candidate = NULL;
1305 if (type == FS_MEDIA_TYPE_VIDEO)
1307 /* Update remote candidate */
1308 candidate = empathy_call_handler_get_video_remote_candidate (
1311 update_candidat_widget (self, priv->video_remote_candidate_label,
1312 priv->video_remote_candidate_info_img, candidate);
1314 /* Update local candidate */
1315 candidate = empathy_call_handler_get_video_local_candidate (
1318 update_candidat_widget (self, priv->video_local_candidate_label,
1319 priv->video_local_candidate_info_img, candidate);
1323 /* Update remote candidate */
1324 candidate = empathy_call_handler_get_audio_remote_candidate (
1327 update_candidat_widget (self, priv->audio_remote_candidate_label,
1328 priv->audio_remote_candidate_info_img, candidate);
1330 /* Update local candidate */
1331 candidate = empathy_call_handler_get_audio_local_candidate (
1334 update_candidat_widget (self, priv->audio_local_candidate_label,
1335 priv->audio_local_candidate_info_img, candidate);
1340 empathy_call_window_constructed (GObject *object)
1342 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1343 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1344 TpyCallChannel *call;
1346 g_assert (priv->handler != NULL);
1348 g_object_get (priv->handler, "call-channel", &call, NULL);
1349 priv->outgoing = (call == NULL);
1351 g_object_unref (call);
1353 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1354 g_assert (priv->contact != NULL);
1356 empathy_call_window_setup_avatars (self, priv->handler);
1357 empathy_call_window_set_state_connecting (self);
1359 if (!empathy_call_handler_has_initial_video (priv->handler))
1361 gtk_toggle_tool_button_set_active (
1362 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1364 /* If call has InitialVideo, the preview will be started once the call has
1365 * been started (start_call()). */
1367 update_send_codec (self, TRUE);
1368 update_send_codec (self, FALSE);
1369 update_recv_codec (self, TRUE);
1370 update_recv_codec (self, FALSE);
1372 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1373 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1374 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1375 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1376 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1377 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1378 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1379 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1381 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1382 G_CALLBACK (candidates_changed_cb), self, 0);
1385 static void empathy_call_window_dispose (GObject *object);
1386 static void empathy_call_window_finalize (GObject *object);
1389 empathy_call_window_set_property (GObject *object,
1390 guint property_id, const GValue *value, GParamSpec *pspec)
1392 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1394 switch (property_id)
1396 case PROP_CALL_HANDLER:
1397 priv->handler = g_value_dup_object (value);
1400 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1405 empathy_call_window_get_property (GObject *object,
1406 guint property_id, GValue *value, GParamSpec *pspec)
1408 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1410 switch (property_id)
1412 case PROP_CALL_HANDLER:
1413 g_value_set_object (value, priv->handler);
1416 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1421 empathy_call_window_class_init (
1422 EmpathyCallWindowClass *empathy_call_window_class)
1424 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1425 GParamSpec *param_spec;
1427 g_type_class_add_private (empathy_call_window_class,
1428 sizeof (EmpathyCallWindowPriv));
1430 object_class->constructed = empathy_call_window_constructed;
1431 object_class->set_property = empathy_call_window_set_property;
1432 object_class->get_property = empathy_call_window_get_property;
1434 object_class->dispose = empathy_call_window_dispose;
1435 object_class->finalize = empathy_call_window_finalize;
1437 param_spec = g_param_spec_object ("handler",
1438 "handler", "The call handler",
1439 EMPATHY_TYPE_CALL_HANDLER,
1440 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1441 g_object_class_install_property (object_class,
1442 PROP_CALL_HANDLER, param_spec);
1446 empathy_call_window_dispose (GObject *object)
1448 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1449 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1451 if (priv->dispose_has_run)
1454 priv->dispose_has_run = TRUE;
1456 if (priv->handler != NULL)
1458 empathy_call_handler_stop_call (priv->handler);
1459 tp_clear_object (&priv->handler);
1462 if (priv->bus_message_source_id != 0)
1464 g_source_remove (priv->bus_message_source_id);
1465 priv->bus_message_source_id = 0;
1468 if (priv->got_video_src > 0)
1470 g_source_remove (priv->got_video_src);
1471 priv->got_video_src = 0;
1474 tp_clear_object (&priv->pipeline);
1475 tp_clear_object (&priv->video_input);
1476 tp_clear_object (&priv->audio_input);
1477 tp_clear_object (&priv->video_tee);
1478 tp_clear_object (&priv->ui_manager);
1479 tp_clear_object (&priv->fullscreen);
1480 tp_clear_object (&priv->camera_monitor);
1481 tp_clear_object (&priv->settings);
1483 g_list_free_full (priv->notifiers, g_object_unref);
1485 if (priv->timer_id != 0)
1486 g_source_remove (priv->timer_id);
1489 if (priv->contact != NULL)
1491 g_signal_handlers_disconnect_by_func (priv->contact,
1492 contact_name_changed_cb, self);
1493 priv->contact = NULL;
1497 tp_clear_object (&priv->sound_mgr);
1499 tp_clear_object (&priv->mic_menu);
1501 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1505 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1507 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1509 if (priv->video_output_motion_handler_id != 0)
1511 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1512 priv->video_output_motion_handler_id);
1513 priv->video_output_motion_handler_id = 0;
1518 empathy_call_window_finalize (GObject *object)
1520 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1521 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1523 disconnect_video_output_motion_handler (self);
1525 /* free any data held directly by the object here */
1526 g_mutex_free (priv->lock);
1528 g_timer_destroy (priv->timer);
1530 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1535 empathy_call_window_new (EmpathyCallHandler *handler)
1537 return EMPATHY_CALL_WINDOW (
1538 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1542 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1543 GstElement *conference, gpointer user_data)
1545 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1546 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1547 FsElementAddedNotifier *notifier;
1550 DEBUG ("Conference added");
1552 /* Add notifier to set the various element properties as needed */
1553 notifier = fs_element_added_notifier_new ();
1554 keyfile = fs_utils_get_default_element_properties (conference);
1556 if (keyfile != NULL)
1557 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1559 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1561 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1563 gst_bin_add (GST_BIN (priv->pipeline), conference);
1564 gst_element_set_state (conference, GST_STATE_PLAYING);
1568 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1569 GstElement *conference, gpointer user_data)
1571 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1572 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1574 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1575 gst_element_set_state (conference, GST_STATE_NULL);
1579 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1581 GstStateChangeReturn state_change_return;
1582 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1584 if (priv->pipeline == NULL)
1587 if (priv->bus_message_source_id != 0)
1589 g_source_remove (priv->bus_message_source_id);
1590 priv->bus_message_source_id = 0;
1593 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1595 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1596 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1598 if (priv->pipeline != NULL)
1599 g_object_unref (priv->pipeline);
1600 priv->pipeline = NULL;
1602 if (priv->audio_output != NULL)
1603 g_object_unref (priv->audio_output);
1604 priv->audio_output = NULL;
1606 if (priv->video_tee != NULL)
1607 g_object_unref (priv->video_tee);
1608 priv->video_tee = NULL;
1610 if (priv->video_preview != NULL)
1611 clutter_actor_destroy (priv->video_preview);
1612 priv->video_preview = NULL;
1614 priv->funnel = NULL;
1616 create_pipeline (self);
1617 /* Call will be started when user will hit the 'redial' button */
1618 priv->start_call_when_playing = FALSE;
1619 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1625 g_message ("Error: could not destroy pipeline. Closing call window");
1626 gtk_widget_destroy (GTK_WIDGET (self));
1633 reset_details_pane (EmpathyCallWindow *self)
1635 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1637 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1638 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1639 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1640 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1644 empathy_call_window_disconnected (EmpathyCallWindow *self,
1647 gboolean could_disconnect = FALSE;
1648 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1649 gboolean could_reset_pipeline;
1651 /* Leave full screen mode if needed */
1652 gtk_window_unfullscreen (GTK_WINDOW (self));
1654 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1655 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1657 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1659 if (priv->call_state == CONNECTING)
1660 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1662 if (priv->call_state != REDIALING)
1663 priv->call_state = DISCONNECTED;
1665 if (could_reset_pipeline)
1667 g_mutex_lock (priv->lock);
1669 g_timer_stop (priv->timer);
1671 if (priv->timer_id != 0)
1672 g_source_remove (priv->timer_id);
1675 g_mutex_unlock (priv->lock);
1678 /* We are about to destroy the window, no need to update it or create
1679 * a video preview */
1682 empathy_call_window_status_message (self, _("Disconnected"));
1684 empathy_call_window_show_hangup_button (self, FALSE);
1686 /* Unsensitive the camera and mic button */
1687 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1688 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1690 /* Be sure that the mic button is enabled */
1691 gtk_toggle_tool_button_set_active (
1692 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1694 if (priv->camera_state == CAMERA_STATE_ON)
1696 /* Restart the preview with the new pipeline. */
1697 display_video_preview (self, TRUE);
1700 /* destroy the video output; it will be recreated when we'll redial */
1701 disconnect_video_output_motion_handler (self);
1702 if (priv->video_output != NULL)
1703 clutter_actor_destroy (priv->video_output);
1704 priv->video_output = NULL;
1705 if (priv->got_video_src > 0)
1707 g_source_remove (priv->got_video_src);
1708 priv->got_video_src = 0;
1711 gtk_widget_show (priv->remote_user_avatar_widget);
1713 reset_details_pane (self);
1715 priv->sending_video = FALSE;
1716 priv->call_started = FALSE;
1718 could_disconnect = TRUE;
1720 /* TODO: display the self avatar of the preview (depends if the "Always
1721 * Show Video Preview" is enabled or not) */
1724 return could_disconnect;
1729 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1732 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1733 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1735 if (empathy_call_window_disconnected (self, TRUE) &&
1736 priv->call_state == REDIALING)
1737 empathy_call_window_restart_call (self);
1741 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1743 FsMediaType media_type,
1744 EmpathyCallWindow *self)
1746 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1748 DEBUG ("removing content");
1751 * This assumes that there is only one video stream per channel...
1754 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1756 if (priv->funnel != NULL)
1760 output = priv->video_output_sink;
1762 gst_element_set_state (output, GST_STATE_NULL);
1763 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1765 gst_bin_remove (GST_BIN (priv->pipeline), output);
1766 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1767 priv->funnel = NULL;
1771 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1773 if (priv->audio_output != NULL)
1775 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1777 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1778 priv->audio_output = NULL;
1786 /* Called with global lock held */
1788 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1790 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1794 if (priv->funnel == NULL)
1796 output = priv->video_output_sink;
1798 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1802 g_warning ("Could not create fsfunnel");
1806 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1808 gst_object_unref (priv->funnel);
1809 priv->funnel = NULL;
1810 g_warning ("Could not add funnel to pipeline");
1814 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1816 g_warning ("Could not add the video output widget to the pipeline");
1820 if (!gst_element_link (priv->funnel, output))
1822 g_warning ("Could not link output sink to funnel");
1823 goto error_output_added;
1826 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1828 g_warning ("Could not start video sink");
1829 goto error_output_added;
1832 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1834 g_warning ("Could not start funnel");
1835 goto error_output_added;
1839 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1842 g_warning ("Could not get request pad from funnel");
1849 gst_element_set_locked_state (priv->funnel, TRUE);
1850 gst_element_set_locked_state (output, TRUE);
1852 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1853 gst_element_set_state (output, GST_STATE_NULL);
1855 gst_bin_remove (GST_BIN (priv->pipeline), output);
1856 gst_element_set_locked_state (output, FALSE);
1860 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1861 priv->funnel = NULL;
1866 /* Called with global lock held */
1868 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1870 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1872 GstPadTemplate *template;
1874 if (priv->audio_output == NULL)
1876 priv->audio_output = empathy_audio_sink_new ();
1877 g_object_ref_sink (priv->audio_output);
1879 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1881 g_warning ("Could not add audio sink to pipeline");
1882 g_object_unref (priv->audio_output);
1883 goto error_add_output;
1886 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1888 g_warning ("Could not start audio sink");
1893 template = gst_element_class_get_pad_template (
1894 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
1896 pad = gst_element_request_pad (priv->audio_output,
1897 template, NULL, NULL);
1901 g_warning ("Could not get sink pad from sink");
1908 gst_element_set_locked_state (priv->audio_output, TRUE);
1909 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1910 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1911 priv->audio_output = NULL;
1919 empathy_call_window_update_timer (gpointer user_data)
1921 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1922 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1923 const gchar *status;
1927 time_ = g_timer_elapsed (priv->timer, NULL);
1929 if (priv->call_state == HELD)
1930 status = _("On hold");
1931 else if (!gtk_toggle_tool_button_get_active (
1932 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
1935 status = _("Duration");
1937 /* Translators: 'status - minutes:seconds' the caller has been connected */
1938 str = g_strdup_printf (_("%s — %d:%02dm"),
1940 (int) time_ / 60, (int) time_ % 60);
1941 empathy_call_window_status_message (self, str);
1949 display_error (EmpathyCallWindow *self,
1950 TpyCallChannel *call,
1954 const gchar *details)
1956 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1957 GtkWidget *info_bar;
1958 GtkWidget *content_area;
1965 /* Create info bar */
1966 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1969 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
1971 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
1973 /* hbox containing the image and the messages vbox */
1974 hbox = gtk_hbox_new (FALSE, 3);
1975 gtk_container_add (GTK_CONTAINER (content_area), hbox);
1978 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
1979 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1981 /* vbox containing the main message and the details expander */
1982 vbox = gtk_vbox_new (FALSE, 3);
1983 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
1986 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
1988 label = gtk_label_new (NULL);
1989 gtk_label_set_markup (GTK_LABEL (label), txt);
1990 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1991 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1994 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
1997 if (details != NULL)
1999 GtkWidget *expander;
2001 expander = gtk_expander_new (_("Technical Details"));
2003 txt = g_strdup_printf ("<i>%s</i>", details);
2005 label = gtk_label_new (NULL);
2006 gtk_label_set_markup (GTK_LABEL (label), txt);
2007 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2008 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2011 gtk_container_add (GTK_CONTAINER (expander), label);
2012 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2015 g_signal_connect (info_bar, "response",
2016 G_CALLBACK (gtk_widget_destroy), NULL);
2018 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2019 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2020 gtk_widget_show_all (info_bar);
2024 media_stream_error_to_txt (EmpathyCallWindow *self,
2025 TpyCallChannel *call,
2027 TpMediaStreamError error)
2029 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2030 const gchar *cm = NULL;
2036 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2038 return g_strdup_printf (
2039 _("%s's software does not understand any of the audio formats "
2040 "supported by your computer"),
2041 empathy_contact_get_alias (priv->contact));
2043 return g_strdup_printf (
2044 _("%s's software does not understand any of the video formats "
2045 "supported by your computer"),
2046 empathy_contact_get_alias (priv->contact));
2048 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2049 return g_strdup_printf (
2050 _("Can't establish a connection to %s. "
2051 "One of you might be on a network that does not allow "
2052 "direct connections."),
2053 empathy_contact_get_alias (priv->contact));
2055 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2056 return g_strdup (_("There was a failure on the network"));
2058 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2060 return g_strdup (_("The audio formats necessary for this call "
2061 "are not installed on your computer"));
2063 return g_strdup (_("The video formats necessary for this call "
2064 "are not installed on your computer"));
2066 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2067 tp_connection_parse_object_path (
2068 tp_channel_borrow_connection (TP_CHANNEL (call)),
2071 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2072 "product=Telepathy&component=%s", cm);
2074 result = g_strdup_printf (
2075 _("Something unexpected happened in a Telepathy component. "
2076 "Please <a href=\"%s\">report this bug</a> and attach "
2077 "logs gathered from the 'Debug' window in the Help menu."), url);
2083 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2084 return g_strdup (_("There was a failure in the call engine"));
2086 case TP_MEDIA_STREAM_ERROR_EOS:
2087 return g_strdup (_("The end of the stream was reached"));
2089 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2096 empathy_call_window_stream_error (EmpathyCallWindow *self,
2097 TpyCallChannel *call,
2106 desc = media_stream_error_to_txt (self, call, audio, code);
2109 /* No description, use the error message. That's not great as it's not
2110 * localized but it's better than nothing. */
2111 display_error (self, call, icon, title, msg, NULL);
2115 display_error (self, call, icon, title, desc, msg);
2121 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2124 EmpathyCallWindow *self)
2126 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2127 "gnome-stock-mic", _("Can't establish audio stream"));
2131 empathy_call_window_video_stream_error (TpyCallChannel *call,
2134 EmpathyCallWindow *self)
2136 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2137 "camera-web", _("Can't establish video stream"));
2142 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2144 EmpathyCallWindow *self)
2146 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2147 TpyCallChannel *call;
2148 gboolean can_send_video;
2150 if (state != TPY_CALL_STATE_ACCEPTED)
2153 if (priv->call_state == CONNECTED)
2156 g_timer_start (priv->timer);
2157 priv->call_state = CONNECTED;
2159 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2161 can_send_video = priv->video_input != NULL &&
2162 empathy_contact_can_voip_video (priv->contact) &&
2163 empathy_camera_monitor_get_available (priv->camera_monitor);
2165 g_object_get (priv->handler, "call-channel", &call, NULL);
2167 if (tpy_call_channel_has_dtmf (call))
2168 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2170 if (priv->video_input == NULL)
2171 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2173 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2175 empathy_call_window_show_hangup_button (self, TRUE);
2177 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2179 clutter_actor_hide (priv->video_output);
2180 gtk_widget_show (priv->remote_user_avatar_widget);
2182 g_object_unref (call);
2184 g_mutex_lock (priv->lock);
2186 priv->timer_id = g_timeout_add_seconds (1,
2187 empathy_call_window_update_timer, self);
2189 g_mutex_unlock (priv->lock);
2191 empathy_call_window_update_timer (self);
2193 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2197 empathy_call_window_show_video_output_cb (gpointer user_data)
2199 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2201 if (self->priv->video_output != NULL)
2203 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2204 clutter_actor_show (self->priv->video_output);
2211 empathy_call_window_check_video_cb (gpointer data)
2213 EmpathyCallWindow *self = data;
2215 if (self->priv->got_video)
2217 self->priv->got_video = FALSE;
2221 /* No video in the last N seconds, display the remote avatar */
2222 empathy_call_window_show_video_output (self, FALSE);
2227 /* Called from the streaming thread */
2229 empathy_call_window_video_probe_cb (GstPad *pad,
2230 GstMiniObject *mini_obj,
2231 EmpathyCallWindow *self)
2234 if (GST_IS_EVENT (mini_obj))
2237 if (G_UNLIKELY (!self->priv->got_video))
2239 /* show the remote video */
2240 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2241 empathy_call_window_show_video_output_cb,
2242 g_object_ref (self), g_object_unref);
2244 self->priv->got_video = TRUE;
2250 /* Called from the streaming thread */
2252 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2253 GstPad *src, guint media_type, gpointer user_data)
2255 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2256 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2257 gboolean retval = FALSE;
2261 g_mutex_lock (priv->lock);
2265 case TP_MEDIA_STREAM_TYPE_AUDIO:
2266 pad = empathy_call_window_get_audio_sink_pad (self);
2268 case TP_MEDIA_STREAM_TYPE_VIDEO:
2269 g_idle_add (empathy_call_window_show_video_output_cb, self);
2270 pad = empathy_call_window_get_video_sink_pad (self);
2272 gst_pad_add_data_probe (src,
2273 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2274 if (priv->got_video_src > 0)
2275 g_source_remove (priv->got_video_src);
2276 priv->got_video_src = g_timeout_add_seconds (5,
2277 empathy_call_window_check_video_cb, self);
2280 g_assert_not_reached ();
2286 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2287 g_warning ("Could not link %s sink pad",
2288 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2292 gst_object_unref (pad);
2296 /* If no sink could be linked, try to add fakesink to prevent the whole call
2301 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2303 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2305 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2306 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2307 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2309 gst_element_set_locked_state (fakesink, TRUE);
2310 gst_element_set_state (fakesink, GST_STATE_NULL);
2311 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2315 DEBUG ("Could not link real sink, linked fakesink instead");
2317 gst_object_unref (sinkpad);
2321 gst_object_unref (fakesink);
2326 g_mutex_unlock (priv->lock);
2332 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2333 GstPad *sink, FsMediaType media_type, gpointer user_data)
2335 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2336 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2338 gboolean retval = FALSE;
2342 case FS_MEDIA_TYPE_AUDIO:
2343 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2345 g_warning ("Could not add audio source to pipeline");
2349 pad = gst_element_get_static_pad (priv->audio_input, "src");
2352 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2353 g_warning ("Could not get source pad from audio source");
2357 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2359 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2360 g_warning ("Could not link audio source to farsight");
2364 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2366 g_warning ("Could not start audio source");
2367 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2368 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2374 case FS_MEDIA_TYPE_VIDEO:
2375 if (priv->video_tee != NULL)
2377 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2378 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2380 g_warning ("Could not link video source input pipeline");
2383 gst_object_unref (pad);
2389 g_assert_not_reached ();
2396 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2398 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2399 GstElement *preview;
2401 disable_camera (self);
2403 DEBUG ("remove video input");
2404 preview = priv->video_preview_sink;
2406 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2407 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2408 gst_element_set_state (preview, GST_STATE_NULL);
2410 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2413 g_object_unref (priv->video_input);
2414 priv->video_input = NULL;
2415 g_object_unref (priv->video_tee);
2416 priv->video_tee = NULL;
2417 clutter_actor_destroy (priv->video_preview);
2418 priv->video_preview = NULL;
2420 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2424 start_call (EmpathyCallWindow *self)
2426 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2428 priv->call_started = TRUE;
2429 empathy_call_handler_start_call (priv->handler,
2430 gtk_get_current_event_time ());
2432 if (empathy_call_handler_has_initial_video (priv->handler))
2434 TpyCallChannel *call;
2437 g_object_get (priv->handler, "call-channel", &call, NULL);
2438 s = tpy_call_channel_get_video_state (call);
2440 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2441 s == TPY_SENDING_STATE_SENDING)
2443 /* Enable 'send video' buttons and display the preview */
2444 gtk_toggle_tool_button_set_active (
2445 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2449 gtk_toggle_tool_button_set_active (
2450 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2452 if (priv->video_preview == NULL)
2454 create_video_preview (self);
2455 add_video_preview_to_pipeline (self);
2459 g_object_unref (call);
2464 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2467 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2468 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2471 empathy_call_handler_bus_message (priv->handler, bus, message);
2473 switch (GST_MESSAGE_TYPE (message))
2475 case GST_MESSAGE_STATE_CHANGED:
2476 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2478 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2480 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2481 !priv->call_started)
2483 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2484 if (newstate == GST_STATE_PAUSED)
2486 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2487 priv->pipeline_playing = TRUE;
2489 if (priv->start_call_when_playing)
2494 case GST_MESSAGE_ERROR:
2496 GError *error = NULL;
2497 GstElement *gst_error;
2500 gst_message_parse_error (message, &error, &debug);
2501 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2503 g_message ("Element error: %s -- %s\n", error->message, debug);
2505 if (g_str_has_prefix (gst_element_get_name (gst_error),
2506 VIDEO_INPUT_ERROR_PREFIX))
2508 /* Remove the video input and continue */
2509 if (priv->video_input != NULL)
2510 empathy_call_window_remove_video_input (self);
2511 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2515 empathy_call_window_disconnected (self, TRUE);
2517 g_error_free (error);
2520 case GST_MESSAGE_UNKNOWN:
2521 case GST_MESSAGE_EOS:
2522 case GST_MESSAGE_WARNING:
2523 case GST_MESSAGE_INFO:
2524 case GST_MESSAGE_TAG:
2525 case GST_MESSAGE_BUFFERING:
2526 case GST_MESSAGE_STATE_DIRTY:
2527 case GST_MESSAGE_STEP_DONE:
2528 case GST_MESSAGE_CLOCK_PROVIDE:
2529 case GST_MESSAGE_CLOCK_LOST:
2530 case GST_MESSAGE_NEW_CLOCK:
2531 case GST_MESSAGE_STRUCTURE_CHANGE:
2532 case GST_MESSAGE_STREAM_STATUS:
2533 case GST_MESSAGE_APPLICATION:
2534 case GST_MESSAGE_ELEMENT:
2535 case GST_MESSAGE_SEGMENT_START:
2536 case GST_MESSAGE_SEGMENT_DONE:
2537 case GST_MESSAGE_DURATION:
2538 case GST_MESSAGE_ANY:
2547 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2548 GHashTable *members,
2549 EmpathyCallWindow *self)
2551 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2552 GHashTableIter iter;
2553 gpointer key, value;
2554 gboolean held = FALSE;
2556 g_hash_table_iter_init (&iter, members);
2557 while (g_hash_table_iter_next (&iter, &key, &value))
2559 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2561 /* This assumes this is a 1-1 call, otherwise one participant
2562 * putting the call on hold wouldn't mean the call is on hold
2570 priv->call_state = HELD;
2571 else if (priv->call_state == HELD)
2572 priv->call_state = CONNECTED;
2576 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2578 EmpathyCallWindow *self)
2580 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2581 TpyCallChannel *call;
2583 g_object_get (priv->handler, "call-channel", &call, NULL);
2588 tp_g_signal_connect_object (call, "audio-stream-error",
2589 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2590 tp_g_signal_connect_object (call, "video-stream-error",
2591 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2594 tp_g_signal_connect_object (call, "members-changed",
2595 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2597 g_object_unref (call);
2601 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2603 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2604 TpyCallChannel *call;
2607 /* Make the hangup button twice as wide */
2608 width = gtk_widget_get_allocated_width (priv->hangup_button);
2609 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2611 g_signal_connect (priv->handler, "state-changed",
2612 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2613 g_signal_connect (priv->handler, "conference-added",
2614 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2615 g_signal_connect (priv->handler, "conference-removed",
2616 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2617 g_signal_connect (priv->handler, "closed",
2618 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2619 g_signal_connect (priv->handler, "src-pad-added",
2620 G_CALLBACK (empathy_call_window_src_added_cb), window);
2621 g_signal_connect (priv->handler, "sink-pad-added",
2622 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2623 g_signal_connect (priv->handler, "sink-pad-removed",
2624 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2626 g_object_get (priv->handler, "call-channel", &call, NULL);
2629 call_handler_notify_call_cb (priv->handler, NULL, window);
2630 g_object_unref (call);
2634 /* call-channel doesn't exist yet, we'll connect signals once it has been
2636 g_signal_connect (priv->handler, "notify::call-channel",
2637 G_CALLBACK (call_handler_notify_call_cb), window);
2640 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2644 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2645 EmpathyCallWindow *window)
2647 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2649 if (priv->pipeline != NULL)
2651 if (priv->bus_message_source_id != 0)
2653 g_source_remove (priv->bus_message_source_id);
2654 priv->bus_message_source_id = 0;
2657 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2660 if (priv->call_state == CONNECTING)
2661 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2667 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2670 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2672 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2677 gtk_widget_hide (priv->dtmf_panel);
2678 gtk_widget_hide (menu);
2679 gtk_widget_hide (priv->toolbar);
2683 if (priv->dialpad_was_visible_before_fs)
2684 gtk_widget_show (priv->dtmf_panel);
2686 gtk_widget_show (menu);
2687 gtk_widget_show (priv->toolbar);
2689 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2690 priv->original_height_before_fs);
2695 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2697 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2699 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2700 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2701 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2702 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2704 if (priv->video_output != NULL)
2707 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2708 priv->video_output, TRUE, TRUE,
2709 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2716 empathy_call_window_state_event_cb (GtkWidget *widget,
2717 GdkEventWindowState *event, EmpathyCallWindow *window)
2719 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2721 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2722 gboolean set_fullscreen = event->new_window_state &
2723 GDK_WINDOW_STATE_FULLSCREEN;
2727 gboolean dialpad_was_visible;
2728 GtkAllocation allocation;
2729 gint original_width, original_height;
2731 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2732 original_width = allocation.width;
2733 original_height = allocation.height;
2735 g_object_get (priv->dtmf_panel,
2736 "visible", &dialpad_was_visible,
2739 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2740 priv->original_width_before_fs = original_width;
2741 priv->original_height_before_fs = original_height;
2743 if (priv->video_output_motion_handler_id == 0 &&
2744 priv->video_output != NULL)
2746 priv->video_output_motion_handler_id = g_signal_connect (
2747 G_OBJECT (priv->video_container), "motion-notify-event",
2748 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2754 disconnect_video_output_motion_handler (window);
2757 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2759 show_controls (window, set_fullscreen);
2760 show_borders (window, set_fullscreen);
2761 gtk_action_set_stock_id (priv->menu_fullscreen,
2762 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2763 priv->is_fullscreen = set_fullscreen;
2770 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2773 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2774 int w, h, dialpad_width;
2775 GtkAllocation allocation;
2777 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2778 w = allocation.width;
2779 h = allocation.height;
2781 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2785 gtk_widget_show (priv->dtmf_panel);
2791 gtk_widget_hide (priv->dtmf_panel);
2795 gtk_window_resize (GTK_WINDOW (window), w, h);
2799 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2802 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2803 TpyCallChannel *call;
2805 priv->sending_video = (state == CAMERA_STATE_ON);
2807 if (state == CAMERA_STATE_ON)
2809 /* When we start sending video, we want to show the video preview by
2811 display_video_preview (window, TRUE);
2815 display_video_preview (window, FALSE);
2818 if (priv->call_state != CONNECTED)
2821 g_object_get (priv->handler, "call-channel", &call, NULL);
2822 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2823 tpy_call_channel_send_video (call, priv->sending_video);
2824 g_object_unref (call);
2828 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2829 EmpathyCallWindow *window)
2831 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2834 active = (gtk_toggle_tool_button_get_active (toggle));
2838 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2839 priv->volume * 100);
2843 /* TODO, Instead of setting the input volume to 0 we should probably
2844 * stop sending but this would cause the audio call to drop if both
2845 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2846 * in the future. GNOME #574574
2848 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2854 empathy_call_window_hangup_cb (gpointer object,
2855 EmpathyCallWindow *self)
2857 empathy_call_handler_stop_call (self->priv->handler);
2859 empathy_call_window_disconnected (self, TRUE);
2863 empathy_call_window_restart_call (EmpathyCallWindow *window)
2865 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2867 /* Remove error info bars */
2868 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
2869 (GtkCallback) gtk_widget_destroy, NULL);
2871 create_video_output_widget (window);
2873 /* While the call was disconnected, the input volume might have changed.
2874 * However, since the audio_input source was destroyed, its volume has not
2875 * been updated during that time. That's why we manually update it here */
2876 empathy_call_window_mic_volume_changed (window);
2878 priv->outgoing = TRUE;
2879 empathy_call_window_set_state_connecting (window);
2881 if (priv->pipeline_playing)
2882 start_call (window);
2884 /* call will be started when the pipeline is ready */
2885 priv->start_call_when_playing = TRUE;
2887 empathy_call_window_setup_avatars (window, priv->handler);
2889 empathy_call_window_show_hangup_button (window, TRUE);
2893 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
2894 EmpathyCallWindow *window)
2898 active = gtk_toggle_tool_button_get_active (button);
2900 empathy_call_window_show_dialpad (window, active);
2904 empathy_call_window_fullscreen_cb (gpointer object,
2905 EmpathyCallWindow *window)
2907 empathy_call_window_fullscreen_toggle (window);
2911 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2913 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2915 if (priv->is_fullscreen)
2916 gtk_window_unfullscreen (GTK_WINDOW (window));
2918 gtk_window_fullscreen (GTK_WINDOW (window));
2922 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
2923 GdkEventButton *event, EmpathyCallWindow *window)
2925 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2927 empathy_call_window_video_menu_popup (window, event->button);
2935 empathy_call_window_key_press_cb (GtkWidget *video_output,
2936 GdkEventKey *event, EmpathyCallWindow *window)
2938 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2940 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
2942 /* Since we are in fullscreen mode, toggling will bring us back to
2944 empathy_call_window_fullscreen_toggle (window);
2952 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
2953 GdkEventMotion *event, EmpathyCallWindow *window)
2955 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2957 if (priv->is_fullscreen)
2959 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
2966 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
2970 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2972 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2974 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
2975 button, gtk_get_current_event_time ());
2976 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
2980 empathy_call_window_status_message (EmpathyCallWindow *self,
2983 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
2987 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
2988 gdouble value, EmpathyCallWindow *window)
2990 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2992 if (priv->audio_output == NULL)
2995 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3000 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3002 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3004 return priv->ui_manager;
3007 EmpathyGstAudioSrc *
3008 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3010 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3012 return (EmpathyGstAudioSrc *) priv->audio_input;