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"
64 #include "empathy-mic-menu.h"
66 #define CONTENT_HBOX_BORDER_WIDTH 6
67 #define CONTENT_HBOX_SPACING 3
68 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
70 #define SELF_VIDEO_SECTION_WIDTH 120
71 #define SELF_VIDEO_SECTION_HEIGTH 90
73 /* The avatar's default width and height are set to the same value because we
74 want a square icon. */
75 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
76 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
77 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
79 #define SMALL_TOOLBAR_SIZE 36
81 /* If an video input error occurs, the error message will start with "v4l" */
82 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
84 /* The time interval in milliseconds between 2 outgoing rings */
85 #define MS_BETWEEN_RING 500
87 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
90 PROP_CALL_HANDLER = 1,
102 CAMERA_STATE_OFF = 0,
106 struct _EmpathyCallWindowPriv
108 gboolean dispose_has_run;
109 EmpathyCallHandler *handler;
111 EmpathyContact *contact;
113 EmpathyCameraMonitor *camera_monitor;
118 GtkUIManager *ui_manager;
119 GtkWidget *errors_vbox;
120 /* widget displays the video received from the remote user. This widget is
121 * alive only during call. */
122 ClutterActor *video_output;
123 ClutterActor *video_preview;
124 ClutterActor *preview_hidden_button;
125 GtkWidget *video_container;
126 GtkWidget *remote_user_avatar_widget;
127 GtkWidget *remote_user_avatar_toolbar;
128 GtkWidget *remote_user_name_toolbar;
129 GtkWidget *status_label;
130 GtkWidget *hangup_button;
131 GtkWidget *audio_call_button;
132 GtkWidget *video_call_button;
133 GtkWidget *mic_button;
134 GtkWidget *camera_button;
135 GtkWidget *dialpad_button;
137 GtkWidget *bottom_toolbar;
139 GtkAction *menu_fullscreen;
141 /* The box that contains self and remote avatar and video
142 input/output. When we redial, we destroy and re-create the box */
143 ClutterActor *video_box;
144 ClutterLayoutManager *video_layout;
146 /* We keep a reference on the hbox which contains the main content so we can
147 easilly repack everything when toggling fullscreen */
148 GtkWidget *content_hbox;
150 gulong video_output_motion_handler_id;
151 guint bus_message_source_id;
155 GtkWidget *dtmf_panel;
158 GtkWidget *details_vbox;
159 GtkWidget *vcodec_encoding_label;
160 GtkWidget *acodec_encoding_label;
161 GtkWidget *vcodec_decoding_label;
162 GtkWidget *acodec_decoding_label;
164 GtkWidget *audio_remote_candidate_label;
165 GtkWidget *audio_local_candidate_label;
166 GtkWidget *video_remote_candidate_label;
167 GtkWidget *video_local_candidate_label;
168 GtkWidget *video_remote_candidate_info_img;
169 GtkWidget *video_local_candidate_info_img;
170 GtkWidget *audio_remote_candidate_info_img;
171 GtkWidget *audio_local_candidate_info_img;
173 GstElement *video_input;
174 GstElement *video_preview_sink;
175 GstElement *video_output_sink;
176 GstElement *audio_input;
177 GstElement *audio_output;
178 GstElement *pipeline;
179 GstElement *video_tee;
189 gboolean call_started;
190 gboolean sending_video;
191 CameraState camera_state;
193 EmpathyCallWindowFullscreen *fullscreen;
194 gboolean is_fullscreen;
199 /* Those fields represent the state of the window before it actually was in
201 gboolean dialpad_was_visible_before_fs;
202 gint original_width_before_fs;
203 gint original_height_before_fs;
205 gint x, y, w, h, dialpad_width;
208 /* TRUE if the call should be started when the pipeline is playing */
209 gboolean start_call_when_playing;
210 /* TRUE if we requested to set the pipeline in the playing state */
211 gboolean pipeline_playing;
213 EmpathySoundManager *sound_mgr;
216 EmpathyMicMenu *mic_menu;
219 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
221 static void empathy_call_window_realized_cb (GtkWidget *widget,
222 EmpathyCallWindow *window);
224 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
225 GdkEvent *event, EmpathyCallWindow *window);
227 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
228 GdkEventWindowState *event, EmpathyCallWindow *window);
230 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
233 static void empathy_call_window_mic_toggled_cb (
234 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
236 static void empathy_call_window_hangup_cb (gpointer object,
237 EmpathyCallWindow *window);
239 static void empathy_call_window_fullscreen_cb (gpointer object,
240 EmpathyCallWindow *window);
242 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
244 static gboolean empathy_call_window_video_button_press_cb (
245 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
247 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
248 GdkEventKey *event, EmpathyCallWindow *window);
250 static gboolean empathy_call_window_video_output_motion_notify (
251 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
253 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
256 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
257 EmpathyCallWindow *window);
259 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
261 static void empathy_call_window_status_message (EmpathyCallWindow *window,
264 static gboolean empathy_call_window_bus_message (GstBus *bus,
265 GstMessage *message, gpointer user_data);
268 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
269 gdouble value, EmpathyCallWindow *window);
272 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
275 gtk_widget_set_visible (self->priv->hangup_button, show);
276 gtk_widget_set_visible (self->priv->audio_call_button, !show);
277 gtk_widget_set_visible (self->priv->video_call_button, !show);
281 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
282 EmpathyCallWindow *self)
284 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
285 empathy_call_window_restart_call (self);
289 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
290 EmpathyCallWindow *self)
292 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
293 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
294 empathy_call_window_restart_call (self);
298 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
300 EmpathyCallWindowPriv *priv = GET_PRIV (window);
301 TpyCallChannel *call;
305 g_object_get (priv->handler, "call-channel", &call, NULL);
307 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
308 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
311 tpy_call_channel_dtmf_start_tone (call, event);
313 g_object_unref (call);
317 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
319 EmpathyCallWindowPriv *priv = GET_PRIV (window);
320 TpyCallChannel *call;
322 g_object_get (priv->handler, "call-channel", &call, NULL);
324 tpy_call_channel_dtmf_stop_tone (call);
326 g_object_unref (call);
330 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
332 EmpathyCallWindowPriv *priv = GET_PRIV (self);
335 volume = g_settings_get_double (priv->settings,
336 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
338 /* Don't store the volume because of muting */
339 if (volume > 0 || gtk_toggle_tool_button_get_active (
340 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
341 priv->volume = volume;
343 /* Ensure that the toggle button is active if the volume is > 0 and inactive
344 * if it's smaller than 0 */
345 if ((volume > 0) != gtk_toggle_tool_button_get_active (
346 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
347 gtk_toggle_tool_button_set_active (
348 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
350 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
355 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
357 EmpathyCallWindow *self)
359 empathy_call_window_mic_volume_changed (self);
363 empathy_call_window_show_video_output (EmpathyCallWindow *self,
366 if (self->priv->video_output != NULL)
367 g_object_set (self->priv->video_output, "visible", show, NULL);
369 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
373 create_video_output_widget (EmpathyCallWindow *self)
375 EmpathyCallWindowPriv *priv = GET_PRIV (self);
377 g_assert (priv->video_output == NULL);
378 g_assert (priv->pipeline != NULL);
380 priv->video_output = clutter_texture_new ();
382 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
385 priv->video_output_sink = clutter_gst_video_sink_new (
386 CLUTTER_TEXTURE (priv->video_output));
388 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
391 gtk_widget_add_events (priv->video_container,
392 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
393 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
394 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
398 create_video_input (EmpathyCallWindow *self)
400 EmpathyCallWindowPriv *priv = GET_PRIV (self);
402 g_assert (priv->video_input == NULL);
403 priv->video_input = empathy_video_src_new ();
404 gst_object_ref (priv->video_input);
405 gst_object_sink (priv->video_input);
409 create_audio_input (EmpathyCallWindow *self)
411 EmpathyCallWindowPriv *priv = GET_PRIV (self);
413 g_assert (priv->audio_input == NULL);
414 priv->audio_input = empathy_audio_src_new ();
415 gst_object_ref (priv->audio_input);
416 gst_object_sink (priv->audio_input);
420 add_video_preview_to_pipeline (EmpathyCallWindow *self)
422 EmpathyCallWindowPriv *priv = GET_PRIV (self);
425 g_assert (priv->video_preview != NULL);
426 g_assert (priv->pipeline != NULL);
427 g_assert (priv->video_input != NULL);
428 g_assert (priv->video_tee != NULL);
430 preview = priv->video_preview_sink;
432 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
434 g_warning ("Could not add video input to pipeline");
438 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
440 g_warning ("Could not add video preview to pipeline");
444 if (!gst_element_link (priv->video_input, priv->video_tee))
446 g_warning ("Could not link video input to video tee");
450 if (!gst_element_link (priv->video_tee, preview))
452 g_warning ("Could not link video tee to video preview");
458 empathy_call_window_disable_camera_cb (GtkAction *action,
459 EmpathyCallWindow *self)
461 clutter_actor_destroy (self->priv->preview_hidden_button);
463 gtk_toggle_tool_button_set_active (
464 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
468 empathy_call_window_minimise_camera_cb (GtkAction *action,
469 EmpathyCallWindow *self)
471 clutter_actor_hide (self->priv->video_preview);
472 clutter_actor_show (self->priv->preview_hidden_button);
476 empathy_call_window_maximise_camera_cb (GtkAction *action,
477 EmpathyCallWindow *self)
479 clutter_actor_show (self->priv->video_preview);
480 clutter_actor_hide (self->priv->preview_hidden_button);
484 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
485 EmpathyCallWindow *self)
489 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
491 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
492 0, gtk_get_current_event_time ());
493 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
497 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
498 EmpathyCallWindow *self)
502 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
503 "/preview-hidden-menu");
504 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
505 0, gtk_get_current_event_time ());
506 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
510 create_video_preview (EmpathyCallWindow *self)
512 EmpathyCallWindowPriv *priv = GET_PRIV (self);
513 ClutterLayoutManager *layout, *layout_center;
514 ClutterActor *preview;
519 g_assert (priv->video_preview == NULL);
521 preview = clutter_texture_new ();
522 clutter_actor_set_size (preview,
523 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
524 priv->video_preview_sink = clutter_gst_video_sink_new (
525 CLUTTER_TEXTURE (preview));
527 /* Flip the video preview */
528 clutter_actor_set_rotation (preview,
531 SELF_VIDEO_SECTION_WIDTH * 0.5,
535 /* Add a little offset to the video preview */
536 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
537 CLUTTER_BIN_ALIGNMENT_START);
538 priv->video_preview = clutter_box_new (layout);
539 clutter_actor_set_size (priv->video_preview,
540 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
542 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
543 CLUTTER_BIN_ALIGNMENT_CENTER);
544 box = clutter_box_new (layout_center);
545 clutter_actor_set_size (box,
546 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
548 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
549 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
551 g_object_set (priv->video_preview_sink,
556 /* Translators: this is an "Info" label. It should be as short
558 button = gtk_button_new_with_label (_("i"));
559 b = gtk_clutter_actor_new_with_contents (button);
561 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
563 CLUTTER_BIN_ALIGNMENT_END,
564 CLUTTER_BIN_ALIGNMENT_END);
566 g_signal_connect (button, "clicked",
567 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
570 /* Translators: this is an "Info" label. It should be as short
572 button = gtk_button_new_with_label (_("i"));
573 priv->preview_hidden_button =
574 gtk_clutter_actor_new_with_contents (button);
576 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
577 priv->preview_hidden_button,
578 CLUTTER_BIN_ALIGNMENT_START,
579 CLUTTER_BIN_ALIGNMENT_END);
581 clutter_actor_hide (priv->preview_hidden_button);
583 g_signal_connect (button, "clicked",
584 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
587 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
589 CLUTTER_BIN_ALIGNMENT_START,
590 CLUTTER_BIN_ALIGNMENT_END);
594 play_camera (EmpathyCallWindow *window,
597 EmpathyCallWindowPriv *priv = GET_PRIV (window);
601 if (priv->video_preview == NULL)
603 create_video_preview (window);
604 add_video_preview_to_pipeline (window);
608 state = GST_STATE_PLAYING;
610 state = GST_STATE_NULL;
612 preview = priv->video_preview_sink;
614 gst_element_set_state (preview, state);
615 gst_element_set_state (priv->video_input, state);
616 gst_element_set_state (priv->video_tee, state);
620 display_video_preview (EmpathyCallWindow *self,
623 EmpathyCallWindowPriv *priv = GET_PRIV (self);
627 /* Display the video preview */
628 DEBUG ("Show video preview");
630 play_camera (self, TRUE);
631 clutter_actor_show (priv->video_preview);
635 /* Hide the video preview */
636 DEBUG ("Hide video preview");
638 if (priv->video_preview != NULL)
640 clutter_actor_hide (priv->video_preview);
641 play_camera (self, FALSE);
647 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
649 EmpathyCallWindowPriv *priv = GET_PRIV (window);
651 empathy_call_window_status_message (window, _("Connecting…"));
652 priv->call_state = CONNECTING;
655 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
656 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
660 disable_camera (EmpathyCallWindow *self)
662 EmpathyCallWindowPriv *priv = GET_PRIV (self);
664 if (priv->camera_state == CAMERA_STATE_OFF)
667 DEBUG ("Disable camera");
669 display_video_preview (self, FALSE);
671 if (priv->camera_state == CAMERA_STATE_ON)
672 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
674 priv->camera_state = CAMERA_STATE_OFF;
678 enable_camera (EmpathyCallWindow *self)
680 EmpathyCallWindowPriv *priv = GET_PRIV (self);
682 if (priv->camera_state == CAMERA_STATE_ON)
685 if (priv->video_input == NULL)
687 DEBUG ("Can't enable camera, no input");
691 DEBUG ("Enable camera");
693 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
695 priv->camera_state = CAMERA_STATE_ON;
699 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
700 EmpathyCallWindow *self)
702 if (gtk_toggle_tool_button_get_active (toggle))
703 enable_camera (self);
705 disable_camera (self);
709 create_pipeline (EmpathyCallWindow *self)
711 EmpathyCallWindowPriv *priv = GET_PRIV (self);
714 g_assert (priv->pipeline == NULL);
716 priv->pipeline = gst_pipeline_new (NULL);
717 priv->pipeline_playing = FALSE;
719 priv->video_tee = gst_element_factory_make ("tee", NULL);
720 gst_object_ref (priv->video_tee);
721 gst_object_sink (priv->video_tee);
723 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
725 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
726 priv->bus_message_source_id = gst_bus_add_watch (bus,
727 empathy_call_window_bus_message, self);
729 g_object_unref (bus);
733 empathy_call_window_configure_event_cb (GtkWidget *widget,
735 EmpathyCallWindow *self)
737 GdkWindow *gdk_window;
738 GdkWindowState window_state;
740 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
741 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
743 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
744 &self->priv->dialpad_width, NULL);
746 gdk_window = gtk_widget_get_window (widget);
747 window_state = gdk_window_get_state (gdk_window);
748 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
754 empathy_call_window_destroyed_cb (GtkWidget *object,
755 EmpathyCallWindow *self)
757 if (gtk_widget_get_visible (self->priv->dtmf_panel))
759 /* Save the geometry as if the dialpad was hidden. */
760 empathy_geometry_save_values (GTK_WINDOW (self),
761 self->priv->x, self->priv->y,
762 self->priv->w - self->priv->dialpad_width, self->priv->h,
763 self->priv->maximized);
768 empathy_call_window_init (EmpathyCallWindow *self)
770 EmpathyCallWindowPriv *priv;
774 ClutterConstraint *size_constraint;
775 ClutterActor *remote_avatar;
776 GtkStyleContext *context;
780 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
781 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
783 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
784 gui = empathy_builder_get_file (filename,
785 "call_window_vbox", &top_vbox,
786 "errors_vbox", &priv->errors_vbox,
788 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
789 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
790 "status_label", &priv->status_label,
791 "audiocall", &priv->audio_call_button,
792 "videocall", &priv->video_call_button,
793 "microphone", &priv->mic_button,
794 "camera", &priv->camera_button,
795 "hangup", &priv->hangup_button,
796 "dialpad", &priv->dialpad_button,
797 "toolbar", &priv->toolbar,
798 "bottom_toolbar", &priv->bottom_toolbar,
799 "ui_manager", &priv->ui_manager,
800 "menufullscreen", &priv->menu_fullscreen,
801 "details_vbox", &priv->details_vbox,
802 "vcodec_encoding_label", &priv->vcodec_encoding_label,
803 "acodec_encoding_label", &priv->acodec_encoding_label,
804 "acodec_decoding_label", &priv->acodec_decoding_label,
805 "vcodec_decoding_label", &priv->vcodec_decoding_label,
806 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
807 "audio_local_candidate_label", &priv->audio_local_candidate_label,
808 "video_remote_candidate_label", &priv->video_remote_candidate_label,
809 "video_local_candidate_label", &priv->video_local_candidate_label,
810 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
811 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
812 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
813 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
817 empathy_builder_connect (gui, self,
818 "hangup", "clicked", empathy_call_window_hangup_cb,
819 "audiocall", "clicked", empathy_call_window_audio_call_cb,
820 "videocall", "clicked", empathy_call_window_video_call_cb,
821 "volume", "value-changed", empathy_call_window_volume_changed_cb,
822 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
823 "camera", "toggled", empathy_call_window_camera_toggled_cb,
824 "dialpad", "toggled", empathy_call_window_dialpad_cb,
825 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
826 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
827 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
828 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
831 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
833 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
835 g_object_bind_property (priv->camera_monitor, "available",
836 priv->camera_button, "sensitive",
837 G_BINDING_SYNC_CREATE);
839 priv->lock = g_mutex_new ();
841 gtk_container_add (GTK_CONTAINER (self), top_vbox);
843 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
844 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
845 CONTENT_HBOX_BORDER_WIDTH);
846 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
849 /* avatar/video box */
850 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
851 CLUTTER_BIN_ALIGNMENT_CENTER);
853 priv->video_box = clutter_box_new (priv->video_layout);
855 priv->video_container = gtk_clutter_embed_new ();
857 /* Set the background color to that of the rest of the window */
858 context = gtk_widget_get_style_context (priv->content_hbox);
859 gtk_style_context_get_background_color (context,
860 GTK_STATE_FLAG_NORMAL, &rgba);
861 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
862 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
863 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
864 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
865 clutter_stage_set_color (
866 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
867 GTK_CLUTTER_EMBED (priv->video_container))),
870 clutter_container_add (
871 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
872 GTK_CLUTTER_EMBED (priv->video_container))),
876 size_constraint = clutter_bind_constraint_new (
877 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
878 CLUTTER_BIND_SIZE, 0);
879 clutter_actor_add_constraint (priv->video_box, size_constraint);
881 priv->remote_user_avatar_widget = gtk_image_new ();
882 remote_avatar = gtk_clutter_actor_new_with_contents (
883 priv->remote_user_avatar_widget);
885 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
888 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
889 priv->video_container, TRUE, TRUE,
890 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
892 create_pipeline (self);
893 create_video_output_widget (self);
894 create_audio_input (self);
895 create_video_input (self);
897 /* The call will be started as soon the pipeline is playing */
898 priv->start_call_when_playing = TRUE;
900 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
901 G_CALLBACK (dtmf_button_pressed_cb),
902 G_CALLBACK (dtmf_button_released_cb));
904 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
907 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
910 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
912 gtk_widget_show_all (top_vbox);
914 gtk_widget_hide (priv->dtmf_panel);
915 gtk_widget_hide (priv->details_vbox);
917 priv->fullscreen = empathy_call_window_fullscreen_new (self);
919 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
920 priv->video_container);
922 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
923 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
925 g_signal_connect (G_OBJECT (self), "realize",
926 G_CALLBACK (empathy_call_window_realized_cb), self);
928 g_signal_connect (G_OBJECT (self), "delete-event",
929 G_CALLBACK (empathy_call_window_delete_cb), self);
931 g_signal_connect (G_OBJECT (self), "window-state-event",
932 G_CALLBACK (empathy_call_window_state_event_cb), self);
934 g_signal_connect (G_OBJECT (self), "key-press-event",
935 G_CALLBACK (empathy_call_window_key_press_cb), self);
937 priv->timer = g_timer_new ();
939 g_object_ref (priv->ui_manager);
940 g_object_unref (gui);
942 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
943 priv->mic_menu = empathy_mic_menu_new (self);
945 empathy_call_window_show_hangup_button (self, TRUE);
947 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
948 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
949 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
951 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
952 /* These signals are used to track the window position and save it
953 * when the window is destroyed. We need to do this as we don't want
954 * the window geometry to be saved with the dialpad taken into account. */
955 g_signal_connect (self, "destroy",
956 G_CALLBACK (empathy_call_window_destroyed_cb), self);
957 g_signal_connect (self, "configure-event",
958 G_CALLBACK (empathy_call_window_configure_event_cb), self);
959 g_signal_connect (self, "window-state-event",
960 G_CALLBACK (empathy_call_window_configure_event_cb), self);
962 /* Don't display labels in both toolbars */
963 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
964 gtk_toolbar_set_style (GTK_TOOLBAR (priv->bottom_toolbar), GTK_TOOLBAR_ICONS);
967 /* Instead of specifying a width and a height, we specify only one size. That's
968 because we want a square avatar icon. */
970 init_contact_avatar_with_size (EmpathyContact *contact,
971 GtkWidget *image_widget,
974 GdkPixbuf *pixbuf_avatar = NULL;
978 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
982 if (pixbuf_avatar == NULL)
984 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
985 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
988 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
990 if (pixbuf_avatar != NULL)
991 g_object_unref (pixbuf_avatar);
995 set_window_title (EmpathyCallWindow *self)
997 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1000 if (priv->contact != NULL)
1002 /* translators: Call is a noun and %s is the contact name. This string
1003 * is used in the window title */
1004 tmp = g_strdup_printf (_("Call with %s"),
1005 empathy_contact_get_alias (priv->contact));
1006 gtk_window_set_title (GTK_WINDOW (self), tmp);
1011 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1016 set_remote_user_name (EmpathyCallWindow *self,
1017 EmpathyContact *contact)
1019 const gchar *alias = empathy_contact_get_alias (contact);
1020 const gchar *status = empathy_contact_get_status (contact);
1023 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1024 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1030 contact_name_changed_cb (EmpathyContact *contact,
1032 EmpathyCallWindow *self)
1034 set_window_title (self);
1035 set_remote_user_name (self, contact);
1039 contact_presence_changed_cb (EmpathyContact *contact,
1041 EmpathyCallWindow *self)
1043 set_remote_user_name (self, contact);
1047 contact_avatar_changed_cb (EmpathyContact *contact,
1049 EmpathyCallWindow *self)
1052 GtkAllocation allocation;
1053 GtkWidget *avatar_widget;
1055 avatar_widget = self->priv->remote_user_avatar_widget;
1057 gtk_widget_get_allocation (avatar_widget, &allocation);
1058 size = allocation.height;
1062 /* the widget is not allocated yet, set a default size */
1063 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1064 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1067 init_contact_avatar_with_size (contact, avatar_widget, size);
1069 avatar_widget = self->priv->remote_user_avatar_toolbar;
1071 gtk_widget_get_allocation (avatar_widget, &allocation);
1072 size = allocation.height;
1076 /* the widget is not allocated yet, set a default size */
1077 size = SMALL_TOOLBAR_SIZE;
1080 init_contact_avatar_with_size (contact, avatar_widget, size);
1084 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1085 EmpathyCallHandler *handler)
1087 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1089 tp_g_signal_connect_object (priv->contact, "notify::name",
1090 G_CALLBACK (contact_name_changed_cb), self, 0);
1091 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1092 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1093 tp_g_signal_connect_object (priv->contact, "notify::presence",
1094 G_CALLBACK (contact_presence_changed_cb), self, 0);
1096 set_window_title (self);
1097 set_remote_user_name (self, priv->contact);
1099 init_contact_avatar_with_size (priv->contact,
1100 priv->remote_user_avatar_widget,
1101 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1102 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1104 init_contact_avatar_with_size (priv->contact,
1105 priv->remote_user_avatar_toolbar,
1106 SMALL_TOOLBAR_SIZE);
1108 /* The remote avatar is shown by default and will be hidden when we receive
1109 video from the remote side. */
1110 clutter_actor_hide (priv->video_output);
1111 gtk_widget_show (priv->remote_user_avatar_widget);
1115 update_send_codec (EmpathyCallWindow *self,
1118 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1125 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1126 widget = priv->acodec_encoding_label;
1130 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1131 widget = priv->vcodec_encoding_label;
1137 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1138 gtk_label_set_text (GTK_LABEL (widget), tmp);
1143 send_audio_codec_notify_cb (GObject *object,
1147 EmpathyCallWindow *self = user_data;
1149 update_send_codec (self, TRUE);
1153 send_video_codec_notify_cb (GObject *object,
1157 EmpathyCallWindow *self = user_data;
1159 update_send_codec (self, FALSE);
1163 update_recv_codec (EmpathyCallWindow *self,
1166 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1169 GString *str = NULL;
1173 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1174 widget = priv->acodec_decoding_label;
1178 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1179 widget = priv->vcodec_decoding_label;
1185 for (l = codecs; l != NULL; l = g_list_next (l))
1187 FsCodec *codec = l->data;
1190 str = g_string_new (NULL);
1192 g_string_append (str, ", ");
1194 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1198 gtk_label_set_text (GTK_LABEL (widget), str->str);
1199 g_string_free (str, TRUE);
1203 recv_audio_codecs_notify_cb (GObject *object,
1207 EmpathyCallWindow *self = user_data;
1209 update_recv_codec (self, TRUE);
1213 recv_video_codecs_notify_cb (GObject *object,
1217 EmpathyCallWindow *self = user_data;
1219 update_recv_codec (self, FALSE);
1222 static const gchar *
1223 candidate_type_to_str (FsCandidate *candidate)
1225 switch (candidate->type)
1227 case FS_CANDIDATE_TYPE_HOST:
1229 case FS_CANDIDATE_TYPE_SRFLX:
1230 return "server reflexive";
1231 case FS_CANDIDATE_TYPE_PRFLX:
1232 return "peer reflexive";
1233 case FS_CANDIDATE_TYPE_RELAY:
1235 case FS_CANDIDATE_TYPE_MULTICAST:
1242 static const gchar *
1243 candidate_type_to_desc (FsCandidate *candidate)
1245 switch (candidate->type)
1247 case FS_CANDIDATE_TYPE_HOST:
1248 return _("The IP address as seen by the machine");
1249 case FS_CANDIDATE_TYPE_SRFLX:
1250 return _("The IP address as seen by a server on the Internet");
1251 case FS_CANDIDATE_TYPE_PRFLX:
1252 return _("The IP address of the peer as seen by the other side");
1253 case FS_CANDIDATE_TYPE_RELAY:
1254 return _("The IP address of a relay server");
1255 case FS_CANDIDATE_TYPE_MULTICAST:
1256 return _("The IP address of the multicast group");
1263 update_candidat_widget (EmpathyCallWindow *self,
1266 FsCandidate *candidate)
1270 g_assert (candidate != NULL);
1271 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1272 candidate->port, candidate_type_to_str (candidate));
1274 gtk_label_set_text (GTK_LABEL (label), str);
1275 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1281 candidates_changed_cb (GObject *object,
1283 EmpathyCallWindow *self)
1285 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1286 FsCandidate *candidate = NULL;
1288 if (type == FS_MEDIA_TYPE_VIDEO)
1290 /* Update remote candidate */
1291 candidate = empathy_call_handler_get_video_remote_candidate (
1294 update_candidat_widget (self, priv->video_remote_candidate_label,
1295 priv->video_remote_candidate_info_img, candidate);
1297 /* Update local candidate */
1298 candidate = empathy_call_handler_get_video_local_candidate (
1301 update_candidat_widget (self, priv->video_local_candidate_label,
1302 priv->video_local_candidate_info_img, candidate);
1306 /* Update remote candidate */
1307 candidate = empathy_call_handler_get_audio_remote_candidate (
1310 update_candidat_widget (self, priv->audio_remote_candidate_label,
1311 priv->audio_remote_candidate_info_img, candidate);
1313 /* Update local candidate */
1314 candidate = empathy_call_handler_get_audio_local_candidate (
1317 update_candidat_widget (self, priv->audio_local_candidate_label,
1318 priv->audio_local_candidate_info_img, candidate);
1323 empathy_call_window_constructed (GObject *object)
1325 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1326 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1327 TpyCallChannel *call;
1329 g_assert (priv->handler != NULL);
1331 g_object_get (priv->handler, "call-channel", &call, NULL);
1332 priv->outgoing = (call == NULL);
1334 g_object_unref (call);
1336 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1337 g_assert (priv->contact != NULL);
1339 empathy_call_window_setup_avatars (self, priv->handler);
1340 empathy_call_window_set_state_connecting (self);
1342 if (!empathy_call_handler_has_initial_video (priv->handler))
1344 gtk_toggle_tool_button_set_active (
1345 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1347 /* If call has InitialVideo, the preview will be started once the call has
1348 * been started (start_call()). */
1350 update_send_codec (self, TRUE);
1351 update_send_codec (self, FALSE);
1352 update_recv_codec (self, TRUE);
1353 update_recv_codec (self, FALSE);
1355 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1356 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1357 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1358 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1359 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1360 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1361 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1362 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1364 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1365 G_CALLBACK (candidates_changed_cb), self, 0);
1368 static void empathy_call_window_dispose (GObject *object);
1369 static void empathy_call_window_finalize (GObject *object);
1372 empathy_call_window_set_property (GObject *object,
1373 guint property_id, const GValue *value, GParamSpec *pspec)
1375 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1377 switch (property_id)
1379 case PROP_CALL_HANDLER:
1380 priv->handler = g_value_dup_object (value);
1383 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1388 empathy_call_window_get_property (GObject *object,
1389 guint property_id, GValue *value, GParamSpec *pspec)
1391 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1393 switch (property_id)
1395 case PROP_CALL_HANDLER:
1396 g_value_set_object (value, priv->handler);
1399 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1404 empathy_call_window_class_init (
1405 EmpathyCallWindowClass *empathy_call_window_class)
1407 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1408 GParamSpec *param_spec;
1410 g_type_class_add_private (empathy_call_window_class,
1411 sizeof (EmpathyCallWindowPriv));
1413 object_class->constructed = empathy_call_window_constructed;
1414 object_class->set_property = empathy_call_window_set_property;
1415 object_class->get_property = empathy_call_window_get_property;
1417 object_class->dispose = empathy_call_window_dispose;
1418 object_class->finalize = empathy_call_window_finalize;
1420 param_spec = g_param_spec_object ("handler",
1421 "handler", "The call handler",
1422 EMPATHY_TYPE_CALL_HANDLER,
1423 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1424 g_object_class_install_property (object_class,
1425 PROP_CALL_HANDLER, param_spec);
1429 empathy_call_window_dispose (GObject *object)
1431 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1432 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1434 if (priv->dispose_has_run)
1437 priv->dispose_has_run = TRUE;
1439 if (priv->handler != NULL)
1441 empathy_call_handler_stop_call (priv->handler);
1442 tp_clear_object (&priv->handler);
1445 if (priv->bus_message_source_id != 0)
1447 g_source_remove (priv->bus_message_source_id);
1448 priv->bus_message_source_id = 0;
1451 if (priv->got_video_src > 0)
1453 g_source_remove (priv->got_video_src);
1454 priv->got_video_src = 0;
1457 tp_clear_object (&priv->pipeline);
1458 tp_clear_object (&priv->video_input);
1459 tp_clear_object (&priv->audio_input);
1460 tp_clear_object (&priv->video_tee);
1461 tp_clear_object (&priv->ui_manager);
1462 tp_clear_object (&priv->fullscreen);
1463 tp_clear_object (&priv->camera_monitor);
1464 tp_clear_object (&priv->settings);
1466 g_list_free_full (priv->notifiers, g_object_unref);
1468 if (priv->timer_id != 0)
1469 g_source_remove (priv->timer_id);
1472 if (priv->contact != NULL)
1474 g_signal_handlers_disconnect_by_func (priv->contact,
1475 contact_name_changed_cb, self);
1476 priv->contact = NULL;
1480 tp_clear_object (&priv->sound_mgr);
1482 tp_clear_object (&priv->mic_menu);
1484 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1488 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1490 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1492 if (priv->video_output_motion_handler_id != 0)
1494 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1495 priv->video_output_motion_handler_id);
1496 priv->video_output_motion_handler_id = 0;
1501 empathy_call_window_finalize (GObject *object)
1503 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1504 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1506 disconnect_video_output_motion_handler (self);
1508 /* free any data held directly by the object here */
1509 g_mutex_free (priv->lock);
1511 g_timer_destroy (priv->timer);
1513 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1518 empathy_call_window_new (EmpathyCallHandler *handler)
1520 return EMPATHY_CALL_WINDOW (
1521 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1525 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1526 GstElement *conference, gpointer user_data)
1528 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1529 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1530 FsElementAddedNotifier *notifier;
1533 DEBUG ("Conference added");
1535 /* Add notifier to set the various element properties as needed */
1536 notifier = fs_element_added_notifier_new ();
1537 keyfile = fs_utils_get_default_element_properties (conference);
1539 if (keyfile != NULL)
1540 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1542 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1544 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1546 gst_bin_add (GST_BIN (priv->pipeline), conference);
1547 gst_element_set_state (conference, GST_STATE_PLAYING);
1551 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1552 GstElement *conference, gpointer user_data)
1554 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1555 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1557 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1558 gst_element_set_state (conference, GST_STATE_NULL);
1562 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1564 GstStateChangeReturn state_change_return;
1565 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1567 if (priv->pipeline == NULL)
1570 if (priv->bus_message_source_id != 0)
1572 g_source_remove (priv->bus_message_source_id);
1573 priv->bus_message_source_id = 0;
1576 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1578 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1579 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1581 if (priv->pipeline != NULL)
1582 g_object_unref (priv->pipeline);
1583 priv->pipeline = NULL;
1585 if (priv->audio_output != NULL)
1586 g_object_unref (priv->audio_output);
1587 priv->audio_output = NULL;
1589 if (priv->video_tee != NULL)
1590 g_object_unref (priv->video_tee);
1591 priv->video_tee = NULL;
1593 if (priv->video_preview != NULL)
1594 clutter_actor_destroy (priv->video_preview);
1595 priv->video_preview = NULL;
1597 priv->funnel = NULL;
1599 create_pipeline (self);
1600 /* Call will be started when user will hit the 'redial' button */
1601 priv->start_call_when_playing = FALSE;
1602 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1608 g_message ("Error: could not destroy pipeline. Closing call window");
1609 gtk_widget_destroy (GTK_WIDGET (self));
1616 reset_details_pane (EmpathyCallWindow *self)
1618 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1620 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1621 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1622 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1623 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1627 empathy_call_window_disconnected (EmpathyCallWindow *self,
1630 gboolean could_disconnect = FALSE;
1631 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1632 gboolean could_reset_pipeline;
1634 /* Leave full screen mode if needed */
1635 gtk_window_unfullscreen (GTK_WINDOW (self));
1637 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1638 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1640 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1642 if (priv->call_state == CONNECTING)
1643 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1645 if (priv->call_state != REDIALING)
1646 priv->call_state = DISCONNECTED;
1648 if (could_reset_pipeline)
1650 g_mutex_lock (priv->lock);
1652 g_timer_stop (priv->timer);
1654 if (priv->timer_id != 0)
1655 g_source_remove (priv->timer_id);
1658 g_mutex_unlock (priv->lock);
1661 /* We are about to destroy the window, no need to update it or create
1662 * a video preview */
1665 empathy_call_window_status_message (self, _("Disconnected"));
1667 empathy_call_window_show_hangup_button (self, FALSE);
1669 /* Unsensitive the camera and mic button */
1670 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1671 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1673 /* Be sure that the mic button is enabled */
1674 gtk_toggle_tool_button_set_active (
1675 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1677 if (priv->camera_state == CAMERA_STATE_ON)
1679 /* Restart the preview with the new pipeline. */
1680 display_video_preview (self, TRUE);
1683 /* destroy the video output; it will be recreated when we'll redial */
1684 disconnect_video_output_motion_handler (self);
1685 if (priv->video_output != NULL)
1686 clutter_actor_destroy (priv->video_output);
1687 priv->video_output = NULL;
1688 if (priv->got_video_src > 0)
1690 g_source_remove (priv->got_video_src);
1691 priv->got_video_src = 0;
1694 gtk_widget_show (priv->remote_user_avatar_widget);
1696 reset_details_pane (self);
1698 priv->sending_video = FALSE;
1699 priv->call_started = FALSE;
1701 could_disconnect = TRUE;
1703 /* TODO: display the self avatar of the preview (depends if the "Always
1704 * Show Video Preview" is enabled or not) */
1707 return could_disconnect;
1712 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1715 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1716 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1718 if (empathy_call_window_disconnected (self, TRUE) &&
1719 priv->call_state == REDIALING)
1720 empathy_call_window_restart_call (self);
1724 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1726 FsMediaType media_type,
1727 EmpathyCallWindow *self)
1729 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1731 DEBUG ("removing content");
1734 * This assumes that there is only one video stream per channel...
1737 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1739 if (priv->funnel != NULL)
1743 output = priv->video_output_sink;
1745 gst_element_set_state (output, GST_STATE_NULL);
1746 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1748 gst_bin_remove (GST_BIN (priv->pipeline), output);
1749 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1750 priv->funnel = NULL;
1754 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1756 if (priv->audio_output != NULL)
1758 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1760 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1761 priv->audio_output = NULL;
1769 /* Called with global lock held */
1771 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1773 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1777 if (priv->funnel == NULL)
1779 output = priv->video_output_sink;
1781 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1785 g_warning ("Could not create fsfunnel");
1789 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1791 gst_object_unref (priv->funnel);
1792 priv->funnel = NULL;
1793 g_warning ("Could not add funnel to pipeline");
1797 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1799 g_warning ("Could not add the video output widget to the pipeline");
1803 if (!gst_element_link (priv->funnel, output))
1805 g_warning ("Could not link output sink to funnel");
1806 goto error_output_added;
1809 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1811 g_warning ("Could not start video sink");
1812 goto error_output_added;
1815 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1817 g_warning ("Could not start funnel");
1818 goto error_output_added;
1822 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1825 g_warning ("Could not get request pad from funnel");
1832 gst_element_set_locked_state (priv->funnel, TRUE);
1833 gst_element_set_locked_state (output, TRUE);
1835 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1836 gst_element_set_state (output, GST_STATE_NULL);
1838 gst_bin_remove (GST_BIN (priv->pipeline), output);
1839 gst_element_set_locked_state (output, FALSE);
1843 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1844 priv->funnel = NULL;
1849 /* Called with global lock held */
1851 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1853 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1855 GstPadTemplate *template;
1857 if (priv->audio_output == NULL)
1859 priv->audio_output = empathy_audio_sink_new ();
1860 g_object_ref_sink (priv->audio_output);
1862 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1864 g_warning ("Could not add audio sink to pipeline");
1865 g_object_unref (priv->audio_output);
1866 goto error_add_output;
1869 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1871 g_warning ("Could not start audio sink");
1876 template = gst_element_class_get_pad_template (
1877 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
1879 pad = gst_element_request_pad (priv->audio_output,
1880 template, NULL, NULL);
1884 g_warning ("Could not get sink pad from sink");
1891 gst_element_set_locked_state (priv->audio_output, TRUE);
1892 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1893 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1894 priv->audio_output = NULL;
1902 empathy_call_window_update_timer (gpointer user_data)
1904 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1905 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1906 const gchar *status;
1910 time_ = g_timer_elapsed (priv->timer, NULL);
1912 if (priv->call_state == HELD)
1913 status = _("On hold");
1914 else if (!gtk_toggle_tool_button_get_active (
1915 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
1918 status = _("Duration");
1920 /* Translators: 'status - minutes:seconds' the caller has been connected */
1921 str = g_strdup_printf (_("%s — %d:%02dm"),
1923 (int) time_ / 60, (int) time_ % 60);
1924 empathy_call_window_status_message (self, str);
1932 display_error (EmpathyCallWindow *self,
1933 TpyCallChannel *call,
1937 const gchar *details)
1939 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1940 GtkWidget *info_bar;
1941 GtkWidget *content_area;
1948 /* Create info bar */
1949 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1952 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
1954 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
1956 /* hbox containing the image and the messages vbox */
1957 hbox = gtk_hbox_new (FALSE, 3);
1958 gtk_container_add (GTK_CONTAINER (content_area), hbox);
1961 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
1962 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1964 /* vbox containing the main message and the details expander */
1965 vbox = gtk_vbox_new (FALSE, 3);
1966 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
1969 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
1971 label = gtk_label_new (NULL);
1972 gtk_label_set_markup (GTK_LABEL (label), txt);
1973 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1974 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1977 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
1980 if (details != NULL)
1982 GtkWidget *expander;
1984 expander = gtk_expander_new (_("Technical Details"));
1986 txt = g_strdup_printf ("<i>%s</i>", details);
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_container_add (GTK_CONTAINER (expander), label);
1995 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
1998 g_signal_connect (info_bar, "response",
1999 G_CALLBACK (gtk_widget_destroy), NULL);
2001 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2002 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2003 gtk_widget_show_all (info_bar);
2007 media_stream_error_to_txt (EmpathyCallWindow *self,
2008 TpyCallChannel *call,
2010 TpMediaStreamError error)
2012 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2013 const gchar *cm = NULL;
2019 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2021 return g_strdup_printf (
2022 _("%s's software does not understand any of the audio formats "
2023 "supported by your computer"),
2024 empathy_contact_get_alias (priv->contact));
2026 return g_strdup_printf (
2027 _("%s's software does not understand any of the video formats "
2028 "supported by your computer"),
2029 empathy_contact_get_alias (priv->contact));
2031 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2032 return g_strdup_printf (
2033 _("Can't establish a connection to %s. "
2034 "One of you might be on a network that does not allow "
2035 "direct connections."),
2036 empathy_contact_get_alias (priv->contact));
2038 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2039 return g_strdup (_("There was a failure on the network"));
2041 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2043 return g_strdup (_("The audio formats necessary for this call "
2044 "are not installed on your computer"));
2046 return g_strdup (_("The video formats necessary for this call "
2047 "are not installed on your computer"));
2049 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2050 tp_connection_parse_object_path (
2051 tp_channel_borrow_connection (TP_CHANNEL (call)),
2054 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2055 "product=Telepathy&component=%s", cm);
2057 result = g_strdup_printf (
2058 _("Something unexpected happened in a Telepathy component. "
2059 "Please <a href=\"%s\">report this bug</a> and attach "
2060 "logs gathered from the 'Debug' window in the Help menu."), url);
2066 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2067 return g_strdup (_("There was a failure in the call engine"));
2069 case TP_MEDIA_STREAM_ERROR_EOS:
2070 return g_strdup (_("The end of the stream was reached"));
2072 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2079 empathy_call_window_stream_error (EmpathyCallWindow *self,
2080 TpyCallChannel *call,
2089 desc = media_stream_error_to_txt (self, call, audio, code);
2092 /* No description, use the error message. That's not great as it's not
2093 * localized but it's better than nothing. */
2094 display_error (self, call, icon, title, msg, NULL);
2098 display_error (self, call, icon, title, desc, msg);
2104 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2107 EmpathyCallWindow *self)
2109 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2110 "gnome-stock-mic", _("Can't establish audio stream"));
2114 empathy_call_window_video_stream_error (TpyCallChannel *call,
2117 EmpathyCallWindow *self)
2119 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2120 "camera-web", _("Can't establish video stream"));
2125 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2127 EmpathyCallWindow *self)
2129 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2130 TpyCallChannel *call;
2131 gboolean can_send_video;
2133 if (state != TPY_CALL_STATE_ACCEPTED)
2136 if (priv->call_state == CONNECTED)
2139 g_timer_start (priv->timer);
2140 priv->call_state = CONNECTED;
2142 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2144 can_send_video = priv->video_input != NULL &&
2145 empathy_contact_can_voip_video (priv->contact) &&
2146 empathy_camera_monitor_get_available (priv->camera_monitor);
2148 g_object_get (priv->handler, "call-channel", &call, NULL);
2150 if (tpy_call_channel_has_dtmf (call))
2151 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2153 if (priv->video_input == NULL)
2154 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2156 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2158 empathy_call_window_show_hangup_button (self, TRUE);
2160 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2162 clutter_actor_hide (priv->video_output);
2163 gtk_widget_show (priv->remote_user_avatar_widget);
2165 g_object_unref (call);
2167 g_mutex_lock (priv->lock);
2169 priv->timer_id = g_timeout_add_seconds (1,
2170 empathy_call_window_update_timer, self);
2172 g_mutex_unlock (priv->lock);
2174 empathy_call_window_update_timer (self);
2176 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2180 empathy_call_window_show_video_output_cb (gpointer user_data)
2182 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2184 if (self->priv->video_output != NULL)
2186 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2187 clutter_actor_show (self->priv->video_output);
2194 empathy_call_window_check_video_cb (gpointer data)
2196 EmpathyCallWindow *self = data;
2198 if (self->priv->got_video)
2200 self->priv->got_video = FALSE;
2204 /* No video in the last N seconds, display the remote avatar */
2205 empathy_call_window_show_video_output (self, FALSE);
2210 /* Called from the streaming thread */
2212 empathy_call_window_video_probe_cb (GstPad *pad,
2213 GstMiniObject *mini_obj,
2214 EmpathyCallWindow *self)
2217 if (GST_IS_EVENT (mini_obj))
2220 if (G_UNLIKELY (!self->priv->got_video))
2222 /* show the remote video */
2223 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2224 empathy_call_window_show_video_output_cb,
2225 g_object_ref (self), g_object_unref);
2227 self->priv->got_video = TRUE;
2233 /* Called from the streaming thread */
2235 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2236 GstPad *src, guint media_type, gpointer user_data)
2238 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2239 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2240 gboolean retval = FALSE;
2244 g_mutex_lock (priv->lock);
2248 case TP_MEDIA_STREAM_TYPE_AUDIO:
2249 pad = empathy_call_window_get_audio_sink_pad (self);
2251 case TP_MEDIA_STREAM_TYPE_VIDEO:
2252 g_idle_add (empathy_call_window_show_video_output_cb, self);
2253 pad = empathy_call_window_get_video_sink_pad (self);
2255 gst_pad_add_data_probe (src,
2256 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2257 if (priv->got_video_src > 0)
2258 g_source_remove (priv->got_video_src);
2259 priv->got_video_src = g_timeout_add_seconds (5,
2260 empathy_call_window_check_video_cb, self);
2263 g_assert_not_reached ();
2269 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2270 g_warning ("Could not link %s sink pad",
2271 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2275 gst_object_unref (pad);
2279 /* If no sink could be linked, try to add fakesink to prevent the whole call
2284 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2286 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2288 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2289 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2290 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2292 gst_element_set_locked_state (fakesink, TRUE);
2293 gst_element_set_state (fakesink, GST_STATE_NULL);
2294 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2298 DEBUG ("Could not link real sink, linked fakesink instead");
2300 gst_object_unref (sinkpad);
2304 gst_object_unref (fakesink);
2309 g_mutex_unlock (priv->lock);
2315 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2316 GstPad *sink, FsMediaType media_type, gpointer user_data)
2318 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2319 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2321 gboolean retval = FALSE;
2325 case FS_MEDIA_TYPE_AUDIO:
2326 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2328 g_warning ("Could not add audio source to pipeline");
2332 pad = gst_element_get_static_pad (priv->audio_input, "src");
2335 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2336 g_warning ("Could not get source pad from audio source");
2340 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2342 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2343 g_warning ("Could not link audio source to farsight");
2347 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2349 g_warning ("Could not start audio source");
2350 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2351 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2357 case FS_MEDIA_TYPE_VIDEO:
2358 if (priv->video_tee != NULL)
2360 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2361 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2363 g_warning ("Could not link video source input pipeline");
2366 gst_object_unref (pad);
2372 g_assert_not_reached ();
2379 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2381 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2382 GstElement *preview;
2384 disable_camera (self);
2386 DEBUG ("remove video input");
2387 preview = priv->video_preview_sink;
2389 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2390 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2391 gst_element_set_state (preview, GST_STATE_NULL);
2393 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2396 g_object_unref (priv->video_input);
2397 priv->video_input = NULL;
2398 g_object_unref (priv->video_tee);
2399 priv->video_tee = NULL;
2400 clutter_actor_destroy (priv->video_preview);
2401 priv->video_preview = NULL;
2403 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2407 start_call (EmpathyCallWindow *self)
2409 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2411 priv->call_started = TRUE;
2412 empathy_call_handler_start_call (priv->handler,
2413 gtk_get_current_event_time ());
2415 if (empathy_call_handler_has_initial_video (priv->handler))
2417 TpyCallChannel *call;
2420 g_object_get (priv->handler, "call-channel", &call, NULL);
2421 s = tpy_call_channel_get_video_state (call);
2423 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2424 s == TPY_SENDING_STATE_SENDING)
2426 /* Enable 'send video' buttons and display the preview */
2427 gtk_toggle_tool_button_set_active (
2428 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2432 gtk_toggle_tool_button_set_active (
2433 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2435 if (priv->video_preview == NULL)
2437 create_video_preview (self);
2438 add_video_preview_to_pipeline (self);
2442 g_object_unref (call);
2447 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2450 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2451 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2454 empathy_call_handler_bus_message (priv->handler, bus, message);
2456 switch (GST_MESSAGE_TYPE (message))
2458 case GST_MESSAGE_STATE_CHANGED:
2459 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2461 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2463 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2464 !priv->call_started)
2466 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2467 if (newstate == GST_STATE_PAUSED)
2469 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2470 priv->pipeline_playing = TRUE;
2472 if (priv->start_call_when_playing)
2477 case GST_MESSAGE_ERROR:
2479 GError *error = NULL;
2480 GstElement *gst_error;
2483 gst_message_parse_error (message, &error, &debug);
2484 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2486 g_message ("Element error: %s -- %s\n", error->message, debug);
2488 if (g_str_has_prefix (gst_element_get_name (gst_error),
2489 VIDEO_INPUT_ERROR_PREFIX))
2491 /* Remove the video input and continue */
2492 if (priv->video_input != NULL)
2493 empathy_call_window_remove_video_input (self);
2494 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2498 empathy_call_window_disconnected (self, TRUE);
2500 g_error_free (error);
2503 case GST_MESSAGE_UNKNOWN:
2504 case GST_MESSAGE_EOS:
2505 case GST_MESSAGE_WARNING:
2506 case GST_MESSAGE_INFO:
2507 case GST_MESSAGE_TAG:
2508 case GST_MESSAGE_BUFFERING:
2509 case GST_MESSAGE_STATE_DIRTY:
2510 case GST_MESSAGE_STEP_DONE:
2511 case GST_MESSAGE_CLOCK_PROVIDE:
2512 case GST_MESSAGE_CLOCK_LOST:
2513 case GST_MESSAGE_NEW_CLOCK:
2514 case GST_MESSAGE_STRUCTURE_CHANGE:
2515 case GST_MESSAGE_STREAM_STATUS:
2516 case GST_MESSAGE_APPLICATION:
2517 case GST_MESSAGE_ELEMENT:
2518 case GST_MESSAGE_SEGMENT_START:
2519 case GST_MESSAGE_SEGMENT_DONE:
2520 case GST_MESSAGE_DURATION:
2521 case GST_MESSAGE_ANY:
2530 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2531 GHashTable *members,
2532 EmpathyCallWindow *self)
2534 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2535 GHashTableIter iter;
2536 gpointer key, value;
2537 gboolean held = FALSE;
2539 g_hash_table_iter_init (&iter, members);
2540 while (g_hash_table_iter_next (&iter, &key, &value))
2542 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2544 /* This assumes this is a 1-1 call, otherwise one participant
2545 * putting the call on hold wouldn't mean the call is on hold
2553 priv->call_state = HELD;
2554 else if (priv->call_state == HELD)
2555 priv->call_state = CONNECTED;
2559 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2561 EmpathyCallWindow *self)
2563 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2564 TpyCallChannel *call;
2566 g_object_get (priv->handler, "call-channel", &call, NULL);
2571 tp_g_signal_connect_object (call, "audio-stream-error",
2572 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2573 tp_g_signal_connect_object (call, "video-stream-error",
2574 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2577 tp_g_signal_connect_object (call, "members-changed",
2578 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2580 g_object_unref (call);
2584 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2586 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2587 TpyCallChannel *call;
2590 /* Make the hangup button twice as wide */
2591 width = gtk_widget_get_allocated_width (priv->hangup_button);
2592 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2594 g_signal_connect (priv->handler, "state-changed",
2595 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2596 g_signal_connect (priv->handler, "conference-added",
2597 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2598 g_signal_connect (priv->handler, "conference-removed",
2599 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2600 g_signal_connect (priv->handler, "closed",
2601 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2602 g_signal_connect (priv->handler, "src-pad-added",
2603 G_CALLBACK (empathy_call_window_src_added_cb), window);
2604 g_signal_connect (priv->handler, "sink-pad-added",
2605 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2606 g_signal_connect (priv->handler, "sink-pad-removed",
2607 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2609 g_object_get (priv->handler, "call-channel", &call, NULL);
2612 call_handler_notify_call_cb (priv->handler, NULL, window);
2613 g_object_unref (call);
2617 /* call-channel doesn't exist yet, we'll connect signals once it has been
2619 g_signal_connect (priv->handler, "notify::call-channel",
2620 G_CALLBACK (call_handler_notify_call_cb), window);
2623 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2627 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2628 EmpathyCallWindow *window)
2630 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2632 if (priv->pipeline != NULL)
2634 if (priv->bus_message_source_id != 0)
2636 g_source_remove (priv->bus_message_source_id);
2637 priv->bus_message_source_id = 0;
2640 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2643 if (priv->call_state == CONNECTING)
2644 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2650 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2653 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2655 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2660 gtk_widget_hide (priv->dtmf_panel);
2661 gtk_widget_hide (menu);
2662 gtk_widget_hide (priv->toolbar);
2666 if (priv->dialpad_was_visible_before_fs)
2667 gtk_widget_show (priv->dtmf_panel);
2669 gtk_widget_show (menu);
2670 gtk_widget_show (priv->toolbar);
2672 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2673 priv->original_height_before_fs);
2678 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2680 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2682 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2683 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2684 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2685 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2687 if (priv->video_output != NULL)
2690 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2691 priv->video_output, TRUE, TRUE,
2692 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2699 empathy_call_window_state_event_cb (GtkWidget *widget,
2700 GdkEventWindowState *event, EmpathyCallWindow *window)
2702 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2704 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2705 gboolean set_fullscreen = event->new_window_state &
2706 GDK_WINDOW_STATE_FULLSCREEN;
2710 gboolean dialpad_was_visible;
2711 GtkAllocation allocation;
2712 gint original_width, original_height;
2714 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2715 original_width = allocation.width;
2716 original_height = allocation.height;
2718 g_object_get (priv->dtmf_panel,
2719 "visible", &dialpad_was_visible,
2722 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2723 priv->original_width_before_fs = original_width;
2724 priv->original_height_before_fs = original_height;
2726 if (priv->video_output_motion_handler_id == 0 &&
2727 priv->video_output != NULL)
2729 priv->video_output_motion_handler_id = g_signal_connect (
2730 G_OBJECT (priv->video_container), "motion-notify-event",
2731 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2737 disconnect_video_output_motion_handler (window);
2740 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2742 show_controls (window, set_fullscreen);
2743 show_borders (window, set_fullscreen);
2744 gtk_action_set_stock_id (priv->menu_fullscreen,
2745 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2746 priv->is_fullscreen = set_fullscreen;
2753 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2756 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2757 int w, h, dialpad_width;
2758 GtkAllocation allocation;
2760 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2761 w = allocation.width;
2762 h = allocation.height;
2764 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2768 gtk_widget_show (priv->dtmf_panel);
2774 gtk_widget_hide (priv->dtmf_panel);
2778 gtk_window_resize (GTK_WINDOW (window), w, h);
2782 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2785 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2786 TpyCallChannel *call;
2788 priv->sending_video = (state == CAMERA_STATE_ON);
2790 if (state == CAMERA_STATE_ON)
2792 /* When we start sending video, we want to show the video preview by
2794 display_video_preview (window, TRUE);
2798 display_video_preview (window, FALSE);
2801 if (priv->call_state != CONNECTED)
2804 g_object_get (priv->handler, "call-channel", &call, NULL);
2805 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2806 tpy_call_channel_send_video (call, priv->sending_video);
2807 g_object_unref (call);
2811 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2812 EmpathyCallWindow *window)
2814 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2817 active = (gtk_toggle_tool_button_get_active (toggle));
2821 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2822 priv->volume * 100);
2826 /* TODO, Instead of setting the input volume to 0 we should probably
2827 * stop sending but this would cause the audio call to drop if both
2828 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2829 * in the future. GNOME #574574
2831 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2837 empathy_call_window_hangup_cb (gpointer object,
2838 EmpathyCallWindow *self)
2840 empathy_call_handler_stop_call (self->priv->handler);
2842 empathy_call_window_disconnected (self, TRUE);
2846 empathy_call_window_restart_call (EmpathyCallWindow *window)
2848 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2850 /* Remove error info bars */
2851 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
2852 (GtkCallback) gtk_widget_destroy, NULL);
2854 create_video_output_widget (window);
2856 /* While the call was disconnected, the input volume might have changed.
2857 * However, since the audio_input source was destroyed, its volume has not
2858 * been updated during that time. That's why we manually update it here */
2859 empathy_call_window_mic_volume_changed (window);
2861 priv->outgoing = TRUE;
2862 empathy_call_window_set_state_connecting (window);
2864 if (priv->pipeline_playing)
2865 start_call (window);
2867 /* call will be started when the pipeline is ready */
2868 priv->start_call_when_playing = TRUE;
2870 empathy_call_window_setup_avatars (window, priv->handler);
2872 empathy_call_window_show_hangup_button (window, TRUE);
2876 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
2877 EmpathyCallWindow *window)
2881 active = gtk_toggle_tool_button_get_active (button);
2883 empathy_call_window_show_dialpad (window, active);
2887 empathy_call_window_fullscreen_cb (gpointer object,
2888 EmpathyCallWindow *window)
2890 empathy_call_window_fullscreen_toggle (window);
2894 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2896 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2898 if (priv->is_fullscreen)
2899 gtk_window_unfullscreen (GTK_WINDOW (window));
2901 gtk_window_fullscreen (GTK_WINDOW (window));
2905 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
2906 GdkEventButton *event, EmpathyCallWindow *window)
2908 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2910 empathy_call_window_video_menu_popup (window, event->button);
2918 empathy_call_window_key_press_cb (GtkWidget *video_output,
2919 GdkEventKey *event, EmpathyCallWindow *window)
2921 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2923 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
2925 /* Since we are in fullscreen mode, toggling will bring us back to
2927 empathy_call_window_fullscreen_toggle (window);
2935 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
2936 GdkEventMotion *event, EmpathyCallWindow *window)
2938 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2940 if (priv->is_fullscreen)
2942 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
2949 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
2953 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2955 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2957 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
2958 button, gtk_get_current_event_time ());
2959 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
2963 empathy_call_window_status_message (EmpathyCallWindow *self,
2966 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
2970 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
2971 gdouble value, EmpathyCallWindow *window)
2973 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2975 if (priv->audio_output == NULL)
2978 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
2983 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
2985 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2987 return priv->ui_manager;
2990 EmpathyGstAudioSrc *
2991 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
2993 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2995 return (EmpathyGstAudioSrc *) priv->audio_input;