2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2009 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 <telepathy-glib/util.h>
33 #include <telepathy-farsight/channel.h>
34 #include <telepathy-glib/util.h>
36 #include <gst/farsight/fs-element-added-notifier.h>
38 #include <libempathy/empathy-tp-contact-factory.h>
39 #include <libempathy/empathy-call-factory.h>
40 #include <libempathy/empathy-utils.h>
41 #include <libempathy-gtk/empathy-avatar-image.h>
42 #include <libempathy-gtk/empathy-video-widget.h>
43 #include <libempathy-gtk/empathy-audio-src.h>
44 #include <libempathy-gtk/empathy-audio-sink.h>
45 #include <libempathy-gtk/empathy-video-src.h>
46 #include <libempathy-gtk/empathy-ui-utils.h>
47 #include <libempathy-gtk/empathy-sound-manager.h>
48 #include <libempathy-gtk/empathy-geometry.h>
49 #include <libempathy-gtk/empathy-images.h>
51 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
52 #include <libempathy/empathy-debug.h>
54 #include "empathy-call-window.h"
55 #include "empathy-call-window-fullscreen.h"
56 #include "ev-sidebar.h"
58 #define BUTTON_ID "empathy-call-dtmf-button-id"
60 #define CONTENT_HBOX_BORDER_WIDTH 6
61 #define CONTENT_HBOX_SPACING 3
62 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
64 #define SELF_VIDEO_SECTION_WIDTH 160
65 #define SELF_VIDEO_SECTION_HEIGTH 120
67 /* The avatar's default width and height are set to the same value because we
68 want a square icon. */
69 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
70 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
71 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
73 /* If an video input error occurs, the error message will start with "v4l" */
74 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
76 /* The time interval in milliseconds between 2 outgoing rings */
77 #define MS_BETWEEN_RING 500
79 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
88 static guint signals[LAST_SIGNAL] = {0};
92 PROP_STREAMED_MEDIA_HANDLER = 1,
103 CAMERA_STATE_OFF = 0,
104 CAMERA_STATE_PREVIEW,
108 /* private structure */
109 typedef struct _EmpathyCallWindowPriv EmpathyCallWindowPriv;
111 struct _EmpathyCallWindowPriv
113 gboolean dispose_has_run;
114 EmpathyStreamedMediaHandler *handler;
115 EmpathyContact *contact;
120 GtkUIManager *ui_manager;
121 GtkWidget *errors_vbox;
122 /* widget displays the video received from the remote user. This widget is
123 * alive only during call. */
124 GtkWidget *video_output;
125 GtkWidget *video_preview;
126 GtkWidget *remote_user_avatar_widget;
127 GtkWidget *self_user_avatar_widget;
129 GtkWidget *sidebar_button;
130 GtkWidget *statusbar;
131 GtkWidget *volume_button;
132 GtkWidget *redial_button;
133 GtkWidget *mic_button;
137 GtkAction *menu_fullscreen;
138 GtkAction *action_camera_on;
139 GtkWidget *tool_button_camera_off;
140 GtkWidget *tool_button_camera_preview;
141 GtkWidget *tool_button_camera_on;
143 /* The frames and boxes that contain self and remote avatar and video
144 input/output. When we redial, we destroy and re-create the boxes */
145 GtkWidget *remote_user_output_frame;
146 GtkWidget *self_user_output_frame;
147 GtkWidget *remote_user_output_hbox;
148 GtkWidget *self_user_output_hbox;
150 /* We keep a reference on the hbox which contains the main content so we can
151 easilly repack everything when toggling fullscreen */
152 GtkWidget *content_hbox;
154 /* This vbox is contained in the content_hbox and it contains the
155 self_user_output_frame and the sidebar button. When toggling fullscreen,
156 it needs to be repacked. We keep a reference on it for easier access. */
159 gulong video_output_motion_handler_id;
160 guint bus_message_source_id;
163 GtkWidget *volume_scale;
164 GtkWidget *volume_progress_bar;
165 GtkAdjustment *audio_input_adj;
167 GtkWidget *dtmf_panel;
170 GtkWidget *details_vbox;
171 GtkWidget *vcodec_encoding_label;
172 GtkWidget *acodec_encoding_label;
173 GtkWidget *vcodec_decoding_label;
174 GtkWidget *acodec_decoding_label;
176 GtkWidget *audio_remote_candidate_label;
177 GtkWidget *audio_local_candidate_label;
178 GtkWidget *video_remote_candidate_label;
179 GtkWidget *video_local_candidate_label;
180 GtkWidget *video_remote_candidate_info_img;
181 GtkWidget *video_local_candidate_info_img;
182 GtkWidget *audio_remote_candidate_info_img;
183 GtkWidget *audio_local_candidate_info_img;
185 GstElement *video_input;
186 GstElement *audio_input;
187 GstElement *audio_output;
188 GstElement *pipeline;
189 GstElement *video_tee;
192 GstElement *liveadder;
194 FsElementAddedNotifier *fsnotifier;
201 GtkWidget *video_contrast;
202 GtkWidget *video_brightness;
203 GtkWidget *video_gamma;
206 gboolean call_started;
207 gboolean sending_video;
208 CameraState camera_state;
210 EmpathyCallWindowFullscreen *fullscreen;
211 gboolean is_fullscreen;
213 /* Those fields represent the state of the window before it actually was in
215 gboolean sidebar_was_visible_before_fs;
216 gint original_width_before_fs;
217 gint original_height_before_fs;
219 /* TRUE if the call should be started when the pipeline is playing */
220 gboolean start_call_when_playing;
221 /* TRUE if we requested to set the pipeline in the playing state */
222 gboolean pipeline_playing;
224 EmpathySoundManager *sound_mgr;
227 #define GET_PRIV(o) \
228 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CALL_WINDOW, \
229 EmpathyCallWindowPriv))
231 static void empathy_call_window_realized_cb (GtkWidget *widget,
232 EmpathyCallWindow *window);
234 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
235 GdkEvent *event, EmpathyCallWindow *window);
237 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
238 GdkEventWindowState *event, EmpathyCallWindow *window);
240 static void empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
241 EmpathyCallWindow *window);
243 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
246 static void empathy_call_window_mic_toggled_cb (
247 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
249 static void empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
250 EmpathyCallWindow *window);
252 static void empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
253 EmpathyCallWindow *window);
255 static void empathy_call_window_hangup_cb (gpointer object,
256 EmpathyCallWindow *window);
258 static void empathy_call_window_fullscreen_cb (gpointer object,
259 EmpathyCallWindow *window);
261 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
263 static gboolean empathy_call_window_video_button_press_cb (
264 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
266 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
267 GdkEventKey *event, EmpathyCallWindow *window);
269 static gboolean empathy_call_window_video_output_motion_notify (
270 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
272 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
275 static void empathy_call_window_redial_cb (gpointer object,
276 EmpathyCallWindow *window);
278 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
280 static void empathy_call_window_status_message (EmpathyCallWindow *window,
283 static void empathy_call_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
284 EmpathyCallWindow *window);
286 static gboolean empathy_call_window_bus_message (GstBus *bus,
287 GstMessage *message, gpointer user_data);
290 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
291 gdouble value, EmpathyCallWindow *window);
293 static void block_camera_control_signals (EmpathyCallWindow *self);
294 static void unblock_camera_control_signals (EmpathyCallWindow *self);
297 empathy_call_window_setup_toolbar (EmpathyCallWindow *self)
299 EmpathyCallWindowPriv *priv = GET_PRIV (self);
300 GtkToolItem *tool_item;
301 GtkWidget *camera_off_icon;
302 GdkPixbuf *pixbuf, *modded_pixbuf;
304 /* set the icon of the 'camera off' button by greying off the webcam icon */
305 pixbuf = empathy_pixbuf_from_icon_name ("camera-web",
306 GTK_ICON_SIZE_SMALL_TOOLBAR);
308 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
309 gdk_pixbuf_get_width (pixbuf),
310 gdk_pixbuf_get_height (pixbuf));
312 gdk_pixbuf_saturate_and_pixelate (pixbuf, modded_pixbuf, 1.0, TRUE);
313 g_object_unref (pixbuf);
315 camera_off_icon = gtk_image_new_from_pixbuf (modded_pixbuf);
316 g_object_unref (modded_pixbuf);
317 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (
318 priv->tool_button_camera_off), camera_off_icon);
320 /* Add an empty expanded GtkToolItem so the volume button is at the end of
322 tool_item = gtk_tool_item_new ();
323 gtk_tool_item_set_expand (tool_item, TRUE);
324 gtk_widget_show (GTK_WIDGET (tool_item));
325 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
327 priv->volume_button = gtk_volume_button_new ();
328 /* FIXME listen to the audiosinks signals and update the button according to
329 * that, for now starting out at 1.0 and assuming only the app changes the
331 gtk_scale_button_set_value (GTK_SCALE_BUTTON (priv->volume_button), 1.0);
332 g_signal_connect (G_OBJECT (priv->volume_button), "value-changed",
333 G_CALLBACK (empathy_call_window_volume_changed_cb), self);
335 tool_item = gtk_tool_item_new ();
336 gtk_container_add (GTK_CONTAINER (tool_item), priv->volume_button);
337 gtk_widget_show_all (GTK_WIDGET (tool_item));
338 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
342 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
344 EmpathyCallWindowPriv *priv = GET_PRIV (window);
345 EmpathyTpStreamedMedia *call;
349 g_object_get (priv->handler, "tp-call", &call, NULL);
351 button_quark = g_quark_from_static_string (BUTTON_ID);
352 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
355 empathy_tp_streamed_media_start_tone (call, event);
357 g_object_unref (call);
361 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
363 EmpathyCallWindowPriv *priv = GET_PRIV (window);
364 EmpathyTpStreamedMedia *call;
366 g_object_get (priv->handler, "tp-call", &call, NULL);
368 empathy_tp_streamed_media_stop_tone (call);
370 g_object_unref (call);
374 empathy_call_window_create_dtmf (EmpathyCallWindow *self)
382 } dtmfbuttons[] = { { "1", TP_DTMF_EVENT_DIGIT_1 },
383 { "2", TP_DTMF_EVENT_DIGIT_2 },
384 { "3", TP_DTMF_EVENT_DIGIT_3 },
385 { "4", TP_DTMF_EVENT_DIGIT_4 },
386 { "5", TP_DTMF_EVENT_DIGIT_5 },
387 { "6", TP_DTMF_EVENT_DIGIT_6 },
388 { "7", TP_DTMF_EVENT_DIGIT_7 },
389 { "8", TP_DTMF_EVENT_DIGIT_8 },
390 { "9", TP_DTMF_EVENT_DIGIT_9 },
391 { "#", TP_DTMF_EVENT_HASH },
392 { "0", TP_DTMF_EVENT_DIGIT_0 },
393 { "*", TP_DTMF_EVENT_ASTERISK },
396 button_quark = g_quark_from_static_string (BUTTON_ID);
398 table = gtk_table_new (4, 3, TRUE);
400 for (i = 0; dtmfbuttons[i].label != NULL; i++)
402 GtkWidget *button = gtk_button_new_with_label (dtmfbuttons[i].label);
403 gtk_table_attach (GTK_TABLE (table), button, i % 3, i % 3 + 1,
404 i/3, i/3 + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1);
406 g_object_set_qdata (G_OBJECT (button), button_quark,
407 GUINT_TO_POINTER (dtmfbuttons[i].event));
409 g_signal_connect (G_OBJECT (button), "pressed",
410 G_CALLBACK (dtmf_button_pressed_cb), self);
411 g_signal_connect (G_OBJECT (button), "released",
412 G_CALLBACK (dtmf_button_released_cb), self);
419 empathy_call_window_create_video_input_add_slider (EmpathyCallWindow *self,
420 gchar *label_text, GtkWidget *bin)
422 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
423 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
424 GtkWidget *label = gtk_label_new (label_text);
426 gtk_widget_set_sensitive (scale, FALSE);
428 gtk_container_add (GTK_CONTAINER (bin), vbox);
430 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
431 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
432 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
438 empathy_call_window_video_contrast_changed_cb (GtkAdjustment *adj,
439 EmpathyCallWindow *self)
442 EmpathyCallWindowPriv *priv = GET_PRIV (self);
444 empathy_video_src_set_channel (priv->video_input,
445 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
449 empathy_call_window_video_brightness_changed_cb (GtkAdjustment *adj,
450 EmpathyCallWindow *self)
453 EmpathyCallWindowPriv *priv = GET_PRIV (self);
455 empathy_video_src_set_channel (priv->video_input,
456 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
460 empathy_call_window_video_gamma_changed_cb (GtkAdjustment *adj,
461 EmpathyCallWindow *self)
464 EmpathyCallWindowPriv *priv = GET_PRIV (self);
466 empathy_video_src_set_channel (priv->video_input,
467 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
472 empathy_call_window_create_video_input (EmpathyCallWindow *self)
474 EmpathyCallWindowPriv *priv = GET_PRIV (self);
477 hbox = gtk_hbox_new (TRUE, 3);
479 priv->video_contrast = empathy_call_window_create_video_input_add_slider (
480 self, _("Contrast"), hbox);
482 priv->video_brightness = empathy_call_window_create_video_input_add_slider (
483 self, _("Brightness"), hbox);
485 priv->video_gamma = empathy_call_window_create_video_input_add_slider (
486 self, _("Gamma"), hbox);
492 empathy_call_window_setup_video_input (EmpathyCallWindow *self)
494 EmpathyCallWindowPriv *priv = GET_PRIV (self);
498 supported = empathy_video_src_get_supported_channels (priv->video_input);
500 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
502 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
504 gtk_adjustment_set_value (adj,
505 empathy_video_src_get_channel (priv->video_input,
506 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
508 g_signal_connect (G_OBJECT (adj), "value-changed",
509 G_CALLBACK (empathy_call_window_video_contrast_changed_cb), self);
511 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
514 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
516 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
518 gtk_adjustment_set_value (adj,
519 empathy_video_src_get_channel (priv->video_input,
520 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
522 g_signal_connect (G_OBJECT (adj), "value-changed",
523 G_CALLBACK (empathy_call_window_video_brightness_changed_cb), self);
524 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
527 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
529 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
531 gtk_adjustment_set_value (adj,
532 empathy_video_src_get_channel (priv->video_input,
533 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
535 g_signal_connect (G_OBJECT (adj), "value-changed",
536 G_CALLBACK (empathy_call_window_video_gamma_changed_cb), self);
537 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
542 empathy_call_window_mic_volume_changed_cb (GtkAdjustment *adj,
543 EmpathyCallWindow *self)
545 EmpathyCallWindowPriv *priv = GET_PRIV (self);
548 volume = gtk_adjustment_get_value (adj)/100.0;
550 /* Don't store the volume because of muting */
551 if (volume > 0 || gtk_toggle_tool_button_get_active (
552 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
553 priv->volume = volume;
555 /* Ensure that the toggle button is active if the volume is > 0 and inactive
556 * if it's smaller than 0 */
557 if ((volume > 0) != gtk_toggle_tool_button_get_active (
558 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
559 gtk_toggle_tool_button_set_active (
560 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
562 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
567 empathy_call_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
568 gdouble level, EmpathyCallWindow *window)
571 EmpathyCallWindowPriv *priv = GET_PRIV (window);
573 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
574 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
579 empathy_call_window_create_audio_input (EmpathyCallWindow *self)
581 EmpathyCallWindowPriv *priv = GET_PRIV (self);
582 GtkWidget *hbox, *vbox, *label;
584 hbox = gtk_hbox_new (TRUE, 3);
586 vbox = gtk_vbox_new (FALSE, 3);
587 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
589 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
590 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
591 label = gtk_label_new (_("Volume"));
593 priv->audio_input_adj = gtk_range_get_adjustment (
594 GTK_RANGE (priv->volume_scale));
595 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
596 (priv->audio_input));
597 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
599 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
600 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), self);
602 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
603 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
605 priv->volume_progress_bar = gtk_progress_bar_new ();
607 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
608 GTK_ORIENTATION_VERTICAL);
610 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
613 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
620 create_video_output_widget (EmpathyCallWindow *self)
622 EmpathyCallWindowPriv *priv = GET_PRIV (self);
625 g_assert (priv->video_output == NULL);
626 g_assert (priv->pipeline != NULL);
628 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
629 priv->video_output = empathy_video_widget_new (bus);
631 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
632 priv->video_output, TRUE, TRUE, 0);
634 gtk_widget_add_events (priv->video_output,
635 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
636 g_signal_connect (G_OBJECT (priv->video_output), "button-press-event",
637 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
639 g_object_unref (bus);
643 create_audio_output (EmpathyCallWindow *self)
645 EmpathyCallWindowPriv *priv = GET_PRIV (self);
647 g_assert (priv->audio_output == NULL);
648 priv->audio_output = empathy_audio_sink_new ();
649 gst_object_ref (priv->audio_output);
650 gst_object_sink (priv->audio_output);
654 create_video_input (EmpathyCallWindow *self)
656 EmpathyCallWindowPriv *priv = GET_PRIV (self);
658 g_assert (priv->video_input == NULL);
659 priv->video_input = empathy_video_src_new ();
660 gst_object_ref (priv->video_input);
661 gst_object_sink (priv->video_input);
665 create_audio_input (EmpathyCallWindow *self)
667 EmpathyCallWindowPriv *priv = GET_PRIV (self);
669 g_assert (priv->audio_input == NULL);
670 priv->audio_input = empathy_audio_src_new ();
671 gst_object_ref (priv->audio_input);
672 gst_object_sink (priv->audio_input);
674 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
675 G_CALLBACK (empathy_call_window_audio_input_level_changed_cb),
680 add_video_preview_to_pipeline (EmpathyCallWindow *self)
682 EmpathyCallWindowPriv *priv = GET_PRIV (self);
685 g_assert (priv->video_preview != NULL);
686 g_assert (priv->pipeline != NULL);
687 g_assert (priv->video_input != NULL);
688 g_assert (priv->video_tee != NULL);
690 preview = empathy_video_widget_get_element (
691 EMPATHY_VIDEO_WIDGET (priv->video_preview));
693 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
695 g_warning ("Could not add video input to pipeline");
699 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee))
701 g_warning ("Could not add video tee to pipeline");
705 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
707 g_warning ("Could not add video preview to pipeline");
711 if (!gst_element_link (priv->video_input, priv->video_tee))
713 g_warning ("Could not link video input to video tee");
717 if (!gst_element_link (priv->video_tee, preview))
719 g_warning ("Could not link video tee to video preview");
725 create_video_preview (EmpathyCallWindow *self)
727 EmpathyCallWindowPriv *priv = GET_PRIV (self);
730 g_assert (priv->video_preview == NULL);
731 g_assert (priv->video_tee == NULL);
733 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
735 priv->video_preview = empathy_video_widget_new_with_size (bus,
736 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
737 g_object_set (priv->video_preview, "sync", FALSE, "async", TRUE, NULL);
739 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
740 priv->video_preview, TRUE, TRUE, 0);
742 priv->video_tee = gst_element_factory_make ("tee", NULL);
743 gst_object_ref (priv->video_tee);
744 gst_object_sink (priv->video_tee);
746 g_object_unref (bus);
750 play_camera (EmpathyCallWindow *window,
753 EmpathyCallWindowPriv *priv = GET_PRIV (window);
757 if (priv->video_preview == NULL)
759 create_video_preview (window);
760 add_video_preview_to_pipeline (window);
764 state = GST_STATE_PLAYING;
766 state = GST_STATE_NULL;
768 preview = empathy_video_widget_get_element (
769 EMPATHY_VIDEO_WIDGET (priv->video_preview));
771 gst_element_set_state (preview, state);
772 gst_element_set_state (priv->video_input, state);
773 gst_element_set_state (priv->video_tee, state);
777 display_video_preview (EmpathyCallWindow *self,
780 EmpathyCallWindowPriv *priv = GET_PRIV (self);
784 /* Display the preview and hide the self avatar */
785 DEBUG ("Show video preview");
787 play_camera (self, TRUE);
788 gtk_widget_show (priv->video_preview);
789 gtk_widget_hide (priv->self_user_avatar_widget);
793 /* Display the self avatar and hide the preview */
794 DEBUG ("Show self avatar");
796 if (priv->video_preview != NULL)
798 gtk_widget_hide (priv->video_preview);
799 play_camera (self, FALSE);
801 gtk_widget_show (priv->self_user_avatar_widget);
806 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
808 EmpathyCallWindowPriv *priv = GET_PRIV (window);
810 empathy_call_window_status_message (window, _("Connecting…"));
811 priv->call_state = CONNECTING;
814 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
815 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
819 disable_camera (EmpathyCallWindow *self)
821 EmpathyCallWindowPriv *priv = GET_PRIV (self);
823 if (priv->camera_state == CAMERA_STATE_OFF)
826 DEBUG ("Disable camera");
828 display_video_preview (self, FALSE);
830 if (priv->camera_state == CAMERA_STATE_ON)
831 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
833 block_camera_control_signals (self);
834 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
835 priv->tool_button_camera_on), FALSE);
836 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
837 priv->tool_button_camera_preview), FALSE);
839 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
840 priv->tool_button_camera_off), TRUE);
841 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
843 unblock_camera_control_signals (self);
845 priv->camera_state = CAMERA_STATE_OFF;
849 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
850 EmpathyCallWindow *self)
852 EmpathyCallWindowPriv *priv = GET_PRIV (self);
854 if (!gtk_toggle_tool_button_get_active (toggle))
856 if (priv->camera_state == CAMERA_STATE_OFF)
858 /* We can't change the state by disabling the button */
859 block_camera_control_signals (self);
860 gtk_toggle_tool_button_set_active (toggle, TRUE);
861 unblock_camera_control_signals (self);
867 disable_camera (self);
871 enable_preview (EmpathyCallWindow *self)
873 EmpathyCallWindowPriv *priv = GET_PRIV (self);
875 if (priv->camera_state == CAMERA_STATE_PREVIEW)
878 DEBUG ("Enable preview");
880 if (priv->camera_state == CAMERA_STATE_ON)
882 /* preview is already displayed so we just have to stop sending */
883 empathy_call_window_set_send_video (self, CAMERA_STATE_PREVIEW);
887 display_video_preview (self, TRUE);
890 block_camera_control_signals (self);
891 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
892 priv->tool_button_camera_off), FALSE);
893 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
894 priv->tool_button_camera_on), FALSE);
896 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
897 priv->tool_button_camera_preview), TRUE);
898 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
899 CAMERA_STATE_PREVIEW);
900 unblock_camera_control_signals (self);
902 priv->camera_state = CAMERA_STATE_PREVIEW;
906 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
907 EmpathyCallWindow *self)
909 EmpathyCallWindowPriv *priv = GET_PRIV (self);
911 if (!gtk_toggle_tool_button_get_active (toggle))
913 if (priv->camera_state == CAMERA_STATE_PREVIEW)
915 /* We can't change the state by disabling the button */
916 block_camera_control_signals (self);
917 gtk_toggle_tool_button_set_active (toggle, TRUE);
918 unblock_camera_control_signals (self);
924 enable_preview (self);
928 enable_camera (EmpathyCallWindow *self)
930 EmpathyCallWindowPriv *priv = GET_PRIV (self);
932 if (priv->camera_state == CAMERA_STATE_ON)
935 if (priv->video_input == NULL)
937 DEBUG ("Can't enable camera, no input");
942 DEBUG ("Enable camera");
944 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
946 block_camera_control_signals (self);
947 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
948 priv->tool_button_camera_off), FALSE);
949 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
950 priv->tool_button_camera_preview), FALSE);
952 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
953 priv->tool_button_camera_on), TRUE);
954 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
956 unblock_camera_control_signals (self);
958 priv->camera_state = CAMERA_STATE_ON;
962 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
963 EmpathyCallWindow *self)
965 EmpathyCallWindowPriv *priv = GET_PRIV (self);
967 if (!gtk_toggle_tool_button_get_active (toggle))
969 if (priv->camera_state == CAMERA_STATE_ON)
971 /* We can't change the state by disabling the button */
972 block_camera_control_signals (self);
973 gtk_toggle_tool_button_set_active (toggle, TRUE);
974 unblock_camera_control_signals (self);
980 enable_camera (self);
984 action_camera_change_cb (GtkRadioAction *action,
985 GtkRadioAction *current,
986 EmpathyCallWindow *self)
990 state = gtk_radio_action_get_current_value (current);
994 case CAMERA_STATE_OFF:
995 disable_camera (self);
998 case CAMERA_STATE_PREVIEW:
999 enable_preview (self);
1002 case CAMERA_STATE_ON:
1003 enable_camera (self);
1007 g_assert_not_reached ();
1012 create_pipeline (EmpathyCallWindow *self)
1014 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1017 g_assert (priv->pipeline == NULL);
1019 priv->pipeline = gst_pipeline_new (NULL);
1020 priv->pipeline_playing = FALSE;
1022 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1023 priv->bus_message_source_id = gst_bus_add_watch (bus,
1024 empathy_call_window_bus_message, self);
1026 g_object_unref (bus);
1031 empathy_call_window_init (EmpathyCallWindow *self)
1033 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1035 GtkWidget *top_vbox;
1041 GError *error = NULL;
1043 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1044 gui = empathy_builder_get_file (filename,
1045 "call_window_vbox", &top_vbox,
1046 "errors_vbox", &priv->errors_vbox,
1047 "pane", &priv->pane,
1048 "statusbar", &priv->statusbar,
1049 "redial", &priv->redial_button,
1050 "microphone", &priv->mic_button,
1051 "toolbar", &priv->toolbar,
1052 "menuredial", &priv->redial,
1053 "ui_manager", &priv->ui_manager,
1054 "menufullscreen", &priv->menu_fullscreen,
1055 "camera_off", &priv->tool_button_camera_off,
1056 "camera_preview", &priv->tool_button_camera_preview,
1057 "camera_on", &priv->tool_button_camera_on,
1058 "action_camera_on", &priv->action_camera_on,
1059 "details_vbox", &priv->details_vbox,
1060 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1061 "acodec_encoding_label", &priv->acodec_encoding_label,
1062 "acodec_decoding_label", &priv->acodec_decoding_label,
1063 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1064 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1065 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1066 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1067 "video_local_candidate_label", &priv->video_local_candidate_label,
1068 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1069 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1070 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1071 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1075 empathy_builder_connect (gui, self,
1076 "menuhangup", "activate", empathy_call_window_hangup_cb,
1077 "hangup", "clicked", empathy_call_window_hangup_cb,
1078 "menuredial", "activate", empathy_call_window_redial_cb,
1079 "redial", "clicked", empathy_call_window_redial_cb,
1080 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1081 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1082 "camera_off", "toggled", tool_button_camera_off_toggled_cb,
1083 "camera_preview", "toggled", tool_button_camera_preview_toggled_cb,
1084 "camera_on", "toggled", tool_button_camera_on_toggled_cb,
1085 "action_camera_on", "changed", action_camera_change_cb,
1088 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1090 priv->lock = g_mutex_new ();
1092 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1094 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1095 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1096 CONTENT_HBOX_BORDER_WIDTH);
1097 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1099 /* remote user output frame */
1100 priv->remote_user_output_frame = gtk_frame_new (NULL);
1101 gtk_widget_set_size_request (priv->remote_user_output_frame,
1102 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1103 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1104 priv->remote_user_output_frame, TRUE, TRUE,
1105 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1107 priv->remote_user_output_hbox = gtk_hbox_new (FALSE, 0);
1109 priv->remote_user_avatar_widget = gtk_image_new ();
1111 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1112 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1114 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1115 priv->remote_user_output_hbox);
1117 /* self user output frame */
1118 priv->self_user_output_frame = gtk_frame_new (NULL);
1119 gtk_widget_set_size_request (priv->self_user_output_frame,
1120 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1122 priv->self_user_output_hbox = gtk_hbox_new (FALSE, 0);
1124 priv->self_user_avatar_widget = gtk_image_new ();
1125 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1126 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1128 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1129 priv->self_user_output_hbox);
1131 create_pipeline (self);
1132 create_video_output_widget (self);
1133 create_audio_input (self);
1134 create_audio_output (self);
1135 create_video_input (self);
1137 priv->fsnotifier = fs_element_added_notifier_new ();
1138 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1140 /* The call will be started as soon the pipeline is playing */
1141 priv->start_call_when_playing = TRUE;
1143 keyfile = g_key_file_new ();
1144 filename = empathy_file_lookup ("element-properties", "data");
1145 if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error))
1147 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1152 g_warning ("Could not load element-properties file: %s", error->message);
1153 g_key_file_free (keyfile);
1154 g_clear_error (&error);
1158 priv->vbox = gtk_vbox_new (FALSE, 3);
1159 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1160 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1161 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1164 empathy_call_window_setup_toolbar (self);
1166 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1167 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1168 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1169 G_CALLBACK (empathy_call_window_sidebar_toggled_cb), self);
1171 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1173 h = gtk_hbox_new (FALSE, 3);
1174 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1175 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1177 priv->sidebar = ev_sidebar_new ();
1178 g_signal_connect (G_OBJECT (priv->sidebar),
1179 "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb), self);
1180 g_signal_connect (G_OBJECT (priv->sidebar),
1181 "show", G_CALLBACK (empathy_call_window_sidebar_shown_cb), self);
1182 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1184 page = empathy_call_window_create_audio_input (self);
1185 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1186 _("Audio input"), page);
1188 page = empathy_call_window_create_video_input (self);
1189 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1190 _("Video input"), page);
1192 priv->dtmf_panel = empathy_call_window_create_dtmf (self);
1193 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1194 _("Dialpad"), priv->dtmf_panel);
1196 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1198 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details",
1199 _("Details"), priv->details_vbox);
1201 gtk_widget_show_all (top_vbox);
1203 gtk_widget_hide (priv->sidebar);
1205 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1206 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1207 priv->video_output);
1208 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1209 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1211 g_signal_connect (G_OBJECT (self), "realize",
1212 G_CALLBACK (empathy_call_window_realized_cb), self);
1214 g_signal_connect (G_OBJECT (self), "delete-event",
1215 G_CALLBACK (empathy_call_window_delete_cb), self);
1217 g_signal_connect (G_OBJECT (self), "window-state-event",
1218 G_CALLBACK (empathy_call_window_state_event_cb), self);
1220 g_signal_connect (G_OBJECT (self), "key-press-event",
1221 G_CALLBACK (empathy_call_window_key_press_cb), self);
1223 priv->timer = g_timer_new ();
1225 g_object_ref (priv->ui_manager);
1226 g_object_unref (gui);
1228 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1230 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1233 /* Instead of specifying a width and a height, we specify only one size. That's
1234 because we want a square avatar icon. */
1236 init_contact_avatar_with_size (EmpathyContact *contact,
1237 GtkWidget *image_widget,
1240 GdkPixbuf *pixbuf_avatar = NULL;
1242 if (contact != NULL)
1244 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1248 if (pixbuf_avatar == NULL)
1250 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1251 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1254 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1256 if (pixbuf_avatar != NULL)
1257 g_object_unref (pixbuf_avatar);
1261 set_window_title (EmpathyCallWindow *self)
1263 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1266 /* translators: Call is a noun and %s is the contact name. This string
1267 * is used in the window title */
1268 tmp = g_strdup_printf (_("Call with %s"),
1269 empathy_contact_get_alias (priv->contact));
1270 gtk_window_set_title (GTK_WINDOW (self), tmp);
1275 contact_name_changed_cb (EmpathyContact *contact,
1276 GParamSpec *pspec, EmpathyCallWindow *self)
1278 set_window_title (self);
1282 contact_avatar_changed_cb (EmpathyContact *contact,
1283 GParamSpec *pspec, GtkWidget *avatar_widget)
1286 GtkAllocation allocation;
1288 gtk_widget_get_allocation (avatar_widget, &allocation);
1289 size = allocation.height;
1293 /* the widget is not allocated yet, set a default size */
1294 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1295 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1298 init_contact_avatar_with_size (contact, avatar_widget, size);
1302 empathy_call_window_got_self_contact_cb (TpConnection *connection,
1303 EmpathyContact *contact, const GError *error, gpointer user_data,
1304 GObject *weak_object)
1306 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1307 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1309 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1310 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1312 g_signal_connect (contact, "notify::avatar",
1313 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1317 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1318 EmpathyStreamedMediaHandler *handler)
1320 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1322 g_object_get (handler, "contact", &(priv->contact), NULL);
1324 if (priv->contact != NULL)
1326 TpConnection *connection;
1328 set_window_title (self);
1330 g_signal_connect (priv->contact, "notify::name",
1331 G_CALLBACK (contact_name_changed_cb), self);
1332 g_signal_connect (priv->contact, "notify::avatar",
1333 G_CALLBACK (contact_avatar_changed_cb),
1334 priv->remote_user_avatar_widget);
1336 /* Retreiving the self avatar */
1337 connection = empathy_contact_get_connection (priv->contact);
1338 empathy_tp_contact_factory_get_from_handle (connection,
1339 tp_connection_get_self_handle (connection),
1340 empathy_call_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1344 g_warning ("call handler doesn't have a contact");
1345 /* translators: Call is a noun. This string is used in the window
1347 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1349 /* Since we can't access the remote contact, we can't get a connection
1350 to it and can't get the self contact (and its avatar). This means
1351 that we have to manually set the self avatar. */
1352 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1353 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1356 init_contact_avatar_with_size (priv->contact,
1357 priv->remote_user_avatar_widget,
1358 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1359 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1361 /* The remote avatar is shown by default and will be hidden when we receive
1362 video from the remote side. */
1363 gtk_widget_hide (priv->video_output);
1364 gtk_widget_show (priv->remote_user_avatar_widget);
1368 update_send_codec (EmpathyCallWindow *self,
1371 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1378 codec = empathy_streamed_media_handler_get_send_audio_codec (priv->handler);
1379 widget = priv->acodec_encoding_label;
1383 codec = empathy_streamed_media_handler_get_send_video_codec (priv->handler);
1384 widget = priv->vcodec_encoding_label;
1390 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1391 gtk_label_set_text (GTK_LABEL (widget), tmp);
1396 send_audio_codec_notify_cb (GObject *object,
1400 EmpathyCallWindow *self = user_data;
1402 update_send_codec (self, TRUE);
1406 send_video_codec_notify_cb (GObject *object,
1410 EmpathyCallWindow *self = user_data;
1412 update_send_codec (self, FALSE);
1416 update_recv_codec (EmpathyCallWindow *self,
1419 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1422 GString *str = NULL;
1426 codecs = empathy_streamed_media_handler_get_recv_audio_codecs (priv->handler);
1427 widget = priv->acodec_decoding_label;
1431 codecs = empathy_streamed_media_handler_get_recv_video_codecs (priv->handler);
1432 widget = priv->vcodec_decoding_label;
1438 for (l = codecs; l != NULL; l = g_list_next (l))
1440 FsCodec *codec = l->data;
1443 str = g_string_new (NULL);
1445 g_string_append (str, ", ");
1447 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1451 gtk_label_set_text (GTK_LABEL (widget), str->str);
1452 g_string_free (str, TRUE);
1456 recv_audio_codecs_notify_cb (GObject *object,
1460 EmpathyCallWindow *self = user_data;
1462 update_recv_codec (self, TRUE);
1466 recv_video_codecs_notify_cb (GObject *object,
1470 EmpathyCallWindow *self = user_data;
1472 update_recv_codec (self, FALSE);
1475 static const gchar *
1476 candidate_type_to_str (FsCandidate *candidate)
1478 switch (candidate->type)
1480 case FS_CANDIDATE_TYPE_HOST:
1482 case FS_CANDIDATE_TYPE_SRFLX:
1483 return "server reflexive";
1484 case FS_CANDIDATE_TYPE_PRFLX:
1485 return "peer reflexive";
1486 case FS_CANDIDATE_TYPE_RELAY:
1488 case FS_CANDIDATE_TYPE_MULTICAST:
1495 static const gchar *
1496 candidate_type_to_desc (FsCandidate *candidate)
1498 switch (candidate->type)
1500 case FS_CANDIDATE_TYPE_HOST:
1501 return _("The IP address as seen by the machine");
1502 case FS_CANDIDATE_TYPE_SRFLX:
1503 return _("The IP address as seen by a server on the Internet");
1504 case FS_CANDIDATE_TYPE_PRFLX:
1505 return _("The IP address of the peer as seen by the other side");
1506 case FS_CANDIDATE_TYPE_RELAY:
1507 return _("The IP address of a relay server");
1508 case FS_CANDIDATE_TYPE_MULTICAST:
1509 return _("The IP address of the multicast group");
1516 update_candidat_widget (EmpathyCallWindow *self,
1519 FsCandidate *candidate)
1523 g_assert (candidate != NULL);
1524 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1525 candidate->port, candidate_type_to_str (candidate));
1527 gtk_label_set_text (GTK_LABEL (label), str);
1528 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1534 candidates_changed_cb (GObject *object,
1536 EmpathyCallWindow *self)
1538 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1539 FsCandidate *candidate = NULL;
1541 if (type == FS_MEDIA_TYPE_VIDEO)
1543 /* Update remote candidate */
1544 candidate = empathy_streamed_media_handler_get_video_remote_candidate (
1547 update_candidat_widget (self, priv->video_remote_candidate_label,
1548 priv->video_remote_candidate_info_img, candidate);
1550 /* Update local candidate */
1551 candidate = empathy_streamed_media_handler_get_video_local_candidate (
1554 update_candidat_widget (self, priv->video_local_candidate_label,
1555 priv->video_local_candidate_info_img, candidate);
1559 /* Update remote candidate */
1560 candidate = empathy_streamed_media_handler_get_audio_remote_candidate (
1563 update_candidat_widget (self, priv->audio_remote_candidate_label,
1564 priv->audio_remote_candidate_info_img, candidate);
1566 /* Update local candidate */
1567 candidate = empathy_streamed_media_handler_get_audio_local_candidate (
1570 update_candidat_widget (self, priv->audio_local_candidate_label,
1571 priv->audio_local_candidate_info_img, candidate);
1576 empathy_call_window_constructed (GObject *object)
1578 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1579 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1580 EmpathyTpStreamedMedia *call;
1582 g_assert (priv->handler != NULL);
1584 g_object_get (priv->handler, "tp-call", &call, NULL);
1585 priv->outgoing = (call == NULL);
1587 g_object_unref (call);
1589 empathy_call_window_setup_avatars (self, priv->handler);
1590 empathy_call_window_set_state_connecting (self);
1592 if (!empathy_streamed_media_handler_has_initial_video (priv->handler))
1594 gtk_toggle_tool_button_set_active (
1595 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1597 /* If call has InitialVideo, the preview will be started once the call has
1598 * been started (start_call()). */
1600 update_send_codec (self, TRUE);
1601 update_send_codec (self, FALSE);
1602 update_recv_codec (self, TRUE);
1603 update_recv_codec (self, FALSE);
1605 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1606 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1607 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1608 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1609 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1610 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1611 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1612 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1614 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1615 G_CALLBACK (candidates_changed_cb), self, 0);
1618 static void empathy_call_window_dispose (GObject *object);
1619 static void empathy_call_window_finalize (GObject *object);
1622 empathy_call_window_set_property (GObject *object,
1623 guint property_id, const GValue *value, GParamSpec *pspec)
1625 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1627 switch (property_id)
1629 case PROP_STREAMED_MEDIA_HANDLER:
1630 priv->handler = g_value_dup_object (value);
1633 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1638 empathy_call_window_get_property (GObject *object,
1639 guint property_id, GValue *value, GParamSpec *pspec)
1641 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1643 switch (property_id)
1645 case PROP_STREAMED_MEDIA_HANDLER:
1646 g_value_set_object (value, priv->handler);
1649 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1654 empathy_call_window_class_init (
1655 EmpathyCallWindowClass *empathy_call_window_class)
1657 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1658 GParamSpec *param_spec;
1660 g_type_class_add_private (empathy_call_window_class,
1661 sizeof (EmpathyCallWindowPriv));
1663 object_class->constructed = empathy_call_window_constructed;
1664 object_class->set_property = empathy_call_window_set_property;
1665 object_class->get_property = empathy_call_window_get_property;
1667 object_class->dispose = empathy_call_window_dispose;
1668 object_class->finalize = empathy_call_window_finalize;
1670 param_spec = g_param_spec_object ("handler",
1671 "handler", "The call handler",
1672 EMPATHY_TYPE_STREAMED_MEDIA_HANDLER,
1673 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1674 g_object_class_install_property (object_class,
1675 PROP_STREAMED_MEDIA_HANDLER, param_spec);
1679 empathy_call_window_video_stream_changed_cb (EmpathyTpStreamedMedia *call,
1680 GParamSpec *property, EmpathyCallWindow *self)
1682 DEBUG ("video stream changed");
1683 empathy_call_window_update_avatars_visibility (call, self);
1687 empathy_call_window_dispose (GObject *object)
1689 EmpathyTpStreamedMedia *call;
1690 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1691 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1693 if (priv->dispose_has_run)
1696 priv->dispose_has_run = TRUE;
1698 g_object_get (priv->handler, "tp-call", &call, NULL);
1702 g_object_unref (call);
1705 if (priv->handler != NULL)
1707 empathy_streamed_media_handler_stop_call (priv->handler);
1708 g_object_unref (priv->handler);
1710 priv->handler = NULL;
1712 if (priv->bus_message_source_id != 0)
1714 g_source_remove (priv->bus_message_source_id);
1715 priv->bus_message_source_id = 0;
1718 if (priv->pipeline != NULL)
1719 g_object_unref (priv->pipeline);
1720 priv->pipeline = NULL;
1722 if (priv->video_input != NULL)
1723 g_object_unref (priv->video_input);
1724 priv->video_input = NULL;
1726 if (priv->audio_input != NULL)
1727 g_object_unref (priv->audio_input);
1728 priv->audio_input = NULL;
1730 if (priv->audio_output != NULL)
1731 g_object_unref (priv->audio_output);
1732 priv->audio_output = NULL;
1734 if (priv->video_tee != NULL)
1735 g_object_unref (priv->video_tee);
1736 priv->video_tee = NULL;
1738 if (priv->liveadder != NULL)
1739 gst_object_unref (priv->liveadder);
1740 priv->liveadder = NULL;
1742 if (priv->fsnotifier != NULL)
1743 g_object_unref (priv->fsnotifier);
1744 priv->fsnotifier = NULL;
1746 if (priv->timer_id != 0)
1747 g_source_remove (priv->timer_id);
1750 if (priv->ui_manager != NULL)
1751 g_object_unref (priv->ui_manager);
1752 priv->ui_manager = NULL;
1754 if (priv->fullscreen != NULL)
1755 g_object_unref (priv->fullscreen);
1756 priv->fullscreen = NULL;
1758 if (priv->contact != NULL)
1760 g_signal_handlers_disconnect_by_func (priv->contact,
1761 contact_name_changed_cb, self);
1762 g_object_unref (priv->contact);
1763 priv->contact = NULL;
1766 tp_clear_object (&priv->sound_mgr);
1768 /* release any references held by the object here */
1769 if (G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose)
1770 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1774 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1776 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1778 if (priv->video_output_motion_handler_id != 0)
1780 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1781 priv->video_output_motion_handler_id);
1782 priv->video_output_motion_handler_id = 0;
1787 empathy_call_window_finalize (GObject *object)
1789 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1790 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1792 disconnect_video_output_motion_handler (self);
1794 /* free any data held directly by the object here */
1795 g_mutex_free (priv->lock);
1797 g_timer_destroy (priv->timer);
1799 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1804 empathy_call_window_new (EmpathyStreamedMediaHandler *handler)
1806 return EMPATHY_CALL_WINDOW (
1807 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1811 empathy_call_window_conference_added_cb (EmpathyStreamedMediaHandler *handler,
1812 GstElement *conference, gpointer user_data)
1814 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1815 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1817 gst_bin_add (GST_BIN (priv->pipeline), conference);
1819 gst_element_set_state (conference, GST_STATE_PLAYING);
1823 empathy_call_window_request_resource_cb (EmpathyStreamedMediaHandler *handler,
1824 FsMediaType type, FsStreamDirection direction, gpointer user_data)
1826 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1827 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1829 if (type != FS_MEDIA_TYPE_VIDEO)
1832 if (direction == FS_DIRECTION_RECV)
1835 /* video and direction is send */
1836 return priv->video_input != NULL;
1840 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1842 GstStateChangeReturn state_change_return;
1843 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1845 if (priv->pipeline == NULL)
1848 if (priv->bus_message_source_id != 0)
1850 g_source_remove (priv->bus_message_source_id);
1851 priv->bus_message_source_id = 0;
1854 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1856 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1857 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1859 if (priv->pipeline != NULL)
1860 g_object_unref (priv->pipeline);
1861 priv->pipeline = NULL;
1863 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1864 empathy_call_window_mic_volume_changed_cb, self);
1866 if (priv->video_tee != NULL)
1867 g_object_unref (priv->video_tee);
1868 priv->video_tee = NULL;
1870 if (priv->video_preview != NULL)
1871 gtk_widget_destroy (priv->video_preview);
1872 priv->video_preview = NULL;
1874 priv->liveadder = NULL;
1875 priv->funnel = NULL;
1877 create_pipeline (self);
1878 /* Call will be started when user will hit the 'redial' button */
1879 priv->start_call_when_playing = FALSE;
1880 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1886 g_message ("Error: could not destroy pipeline. Closing call window");
1887 gtk_widget_destroy (GTK_WIDGET (self));
1894 reset_details_pane (EmpathyCallWindow *self)
1896 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1898 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1899 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1900 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1901 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1905 empathy_call_window_disconnected (EmpathyCallWindow *self,
1908 gboolean could_disconnect = FALSE;
1909 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1910 gboolean could_reset_pipeline;
1912 /* Leave full screen mode if needed */
1913 gtk_window_unfullscreen (GTK_WINDOW (self));
1915 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1917 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1919 if (priv->call_state == CONNECTING)
1920 empathy_sound_manager_stop (priv->sound_mgr,
1921 EMPATHY_SOUND_PHONE_OUTGOING);
1923 if (priv->call_state != REDIALING)
1924 priv->call_state = DISCONNECTED;
1926 if (could_reset_pipeline)
1928 g_mutex_lock (priv->lock);
1930 g_timer_stop (priv->timer);
1932 if (priv->timer_id != 0)
1933 g_source_remove (priv->timer_id);
1936 g_mutex_unlock (priv->lock);
1939 /* We are about to destroy the window, no need to update it or create
1940 * a video preview */
1943 empathy_call_window_status_message (self, _("Disconnected"));
1945 gtk_action_set_sensitive (priv->redial, TRUE);
1946 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1948 /* Unsensitive the camera and mic button */
1949 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1950 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
1951 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1953 /* Be sure that the mic button is enabled */
1954 gtk_toggle_tool_button_set_active (
1955 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1957 if (priv->camera_state == CAMERA_STATE_ON)
1959 /* Enable the 'preview' button as we are not sending atm. */
1960 gtk_toggle_tool_button_set_active (
1961 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_preview), TRUE);
1963 else if (priv->camera_state == CAMERA_STATE_PREVIEW)
1965 /* Restart the preview with the new pipeline. */
1966 display_video_preview (self, TRUE);
1969 gtk_progress_bar_set_fraction (
1970 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1972 /* destroy the video output; it will be recreated when we'll redial */
1973 disconnect_video_output_motion_handler (self);
1974 gtk_widget_destroy (priv->video_output);
1975 priv->video_output = NULL;
1977 gtk_widget_show (priv->remote_user_avatar_widget);
1979 reset_details_pane (self);
1981 priv->sending_video = FALSE;
1982 priv->call_started = FALSE;
1984 could_disconnect = TRUE;
1986 /* TODO: display the self avatar of the preview (depends if the "Always
1987 * Show Video Preview" is enabled or not) */
1990 return could_disconnect;
1995 empathy_call_window_channel_closed_cb (EmpathyStreamedMediaHandler *handler,
1998 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1999 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2001 if (empathy_call_window_disconnected (self, TRUE) &&
2002 priv->call_state == REDIALING)
2003 empathy_call_window_restart_call (self);
2008 empathy_call_window_channel_stream_closed_cb (EmpathyStreamedMediaHandler *handler,
2009 TfStream *stream, gpointer user_data)
2011 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2012 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2015 g_object_get (stream, "media-type", &media_type, NULL);
2018 * This assumes that there is only one video stream per channel...
2021 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
2023 if (priv->funnel != NULL)
2027 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
2028 (priv->video_output));
2030 gst_element_set_state (output, GST_STATE_NULL);
2031 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2033 gst_bin_remove (GST_BIN (priv->pipeline), output);
2034 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2035 priv->funnel = NULL;
2038 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
2040 if (priv->liveadder != NULL)
2042 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2043 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
2045 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2046 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
2047 priv->liveadder = NULL;
2052 /* Called with global lock held */
2054 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2056 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2060 if (priv->funnel == NULL)
2062 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
2063 (priv->video_output));
2065 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2069 g_warning ("Could not create fsfunnel");
2073 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2075 gst_object_unref (priv->funnel);
2076 priv->funnel = NULL;
2077 g_warning ("Could not add funnel to pipeline");
2081 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2083 g_warning ("Could not add the video output widget to the pipeline");
2087 if (!gst_element_link (priv->funnel, output))
2089 g_warning ("Could not link output sink to funnel");
2090 goto error_output_added;
2093 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2095 g_warning ("Could not start video sink");
2096 goto error_output_added;
2099 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2101 g_warning ("Could not start funnel");
2102 goto error_output_added;
2106 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2109 g_warning ("Could not get request pad from funnel");
2116 gst_element_set_locked_state (priv->funnel, TRUE);
2117 gst_element_set_locked_state (output, TRUE);
2119 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2120 gst_element_set_state (output, GST_STATE_NULL);
2122 gst_bin_remove (GST_BIN (priv->pipeline), output);
2123 gst_element_set_locked_state (output, FALSE);
2127 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2128 priv->funnel = NULL;
2133 /* Called with global lock held */
2135 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2137 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2140 GError *gerror = NULL;
2142 if (priv->liveadder == NULL)
2144 priv->liveadder = gst_element_factory_make ("liveadder", NULL);
2146 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->liveadder))
2148 g_warning ("Could not add liveadder to the pipeline");
2149 goto error_add_liveadder;
2151 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2153 g_warning ("Could not add audio sink to pipeline");
2154 goto error_add_output;
2157 if (gst_element_set_state (priv->liveadder, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2159 g_warning ("Could not start liveadder");
2163 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2165 g_warning ("Could not start audio sink");
2169 if (GST_PAD_LINK_FAILED (
2170 gst_element_link (priv->liveadder, priv->audio_output)))
2172 g_warning ("Could not link liveadder to audio output");
2177 filter = gst_parse_bin_from_description (
2178 "audioconvert ! audioresample ! audioconvert", TRUE, &gerror);
2181 g_warning ("Could not make audio conversion filter: %s", gerror->message);
2182 g_clear_error (&gerror);
2186 if (!gst_bin_add (GST_BIN (priv->pipeline), filter))
2188 g_warning ("Could not add audio conversion filter to pipeline");
2189 gst_object_unref (filter);
2193 if (gst_element_set_state (filter, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2195 g_warning ("Could not start audio conversion filter");
2199 if (!gst_element_link (filter, priv->liveadder))
2201 g_warning ("Could not link audio conversion filter to liveadder");
2205 pad = gst_element_get_static_pad (filter, "sink");
2209 g_warning ("Could not get sink pad from filter");
2217 gst_element_set_locked_state (filter, TRUE);
2218 gst_element_set_state (filter, GST_STATE_NULL);
2219 gst_bin_remove (GST_BIN (priv->pipeline), filter);
2223 gst_element_set_locked_state (priv->liveadder, TRUE);
2224 gst_element_set_locked_state (priv->audio_output, TRUE);
2226 gst_element_set_state (priv->liveadder, GST_STATE_NULL);
2227 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2229 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2233 gst_bin_remove (GST_BIN (priv->pipeline), priv->liveadder);
2235 gst_element_set_locked_state (priv->liveadder, FALSE);
2236 gst_element_set_locked_state (priv->audio_output, FALSE);
2238 error_add_liveadder:
2240 if (priv->liveadder != NULL)
2242 gst_object_unref (priv->liveadder);
2243 priv->liveadder = NULL;
2250 empathy_call_window_update_timer (gpointer user_data)
2252 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2253 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2257 time_ = g_timer_elapsed (priv->timer, NULL);
2259 /* Translators: number of minutes:seconds the caller has been connected */
2260 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
2262 empathy_call_window_status_message (self, str);
2269 display_error (EmpathyCallWindow *self,
2270 EmpathyTpStreamedMedia *call,
2274 const gchar *details)
2276 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2277 GtkWidget *info_bar;
2278 GtkWidget *content_area;
2285 /* Create info bar */
2286 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2289 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2291 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2293 /* hbox containing the image and the messages vbox */
2294 hbox = gtk_hbox_new (FALSE, 3);
2295 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2298 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2299 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2301 /* vbox containing the main message and the details expander */
2302 vbox = gtk_vbox_new (FALSE, 3);
2303 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2306 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2308 label = gtk_label_new (NULL);
2309 gtk_label_set_markup (GTK_LABEL (label), txt);
2310 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2311 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2314 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2317 if (details != NULL)
2319 GtkWidget *expander;
2321 expander = gtk_expander_new (_("Technical Details"));
2323 txt = g_strdup_printf ("<i>%s</i>", details);
2325 label = gtk_label_new (NULL);
2326 gtk_label_set_markup (GTK_LABEL (label), txt);
2327 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2328 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2331 gtk_container_add (GTK_CONTAINER (expander), label);
2332 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2335 g_signal_connect (info_bar, "response",
2336 G_CALLBACK (gtk_widget_destroy), NULL);
2338 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2339 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2340 gtk_widget_show_all (info_bar);
2344 media_stream_error_to_txt (EmpathyCallWindow *self,
2345 EmpathyTpStreamedMedia *call,
2347 TpMediaStreamError error)
2349 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2356 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2358 return g_strdup_printf (
2359 _("%s's software does not understand any of the audio formats "
2360 "supported by your computer"),
2361 empathy_contact_get_alias (priv->contact));
2363 return g_strdup_printf (
2364 _("%s's software does not understand any of the video formats "
2365 "supported by your computer"),
2366 empathy_contact_get_alias (priv->contact));
2368 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2369 return g_strdup_printf (
2370 _("Can't establish a connection to %s. "
2371 "One of you might be on a network that does not allow "
2372 "direct connections."),
2373 empathy_contact_get_alias (priv->contact));
2375 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2376 return g_strdup (_("There was a failure on the network"));
2378 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2380 return g_strdup (_("The audio formats necessary for this call "
2381 "are not installed on your computer"));
2383 return g_strdup (_("The video formats necessary for this call "
2384 "are not installed on your computer"));
2386 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2387 cm = empathy_tp_streamed_media_get_connection_manager (call);
2389 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2390 "product=Telepathy&component=%s", cm);
2392 result = g_strdup_printf (
2393 _("Something unexpected happened in a Telepathy component. "
2394 "Please <a href=\"%s\">report this bug</a> and attach "
2395 "logs gathered from the 'Debug' window in the Help menu."), url);
2400 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2401 return g_strdup (_("There was a failure in the call engine"));
2403 case TP_MEDIA_STREAM_ERROR_EOS:
2404 return g_strdup (_("The end of the stream was reached"));
2406 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2413 empathy_call_window_stream_error (EmpathyCallWindow *self,
2414 EmpathyTpStreamedMedia *call,
2423 desc = media_stream_error_to_txt (self, call, audio, code);
2426 /* No description, use the error message. That's not great as it's not
2427 * localized but it's better than nothing. */
2428 display_error (self, call, icon, title, msg, NULL);
2432 display_error (self, call, icon, title, desc, msg);
2438 empathy_call_window_audio_stream_error (EmpathyTpStreamedMedia *call,
2441 EmpathyCallWindow *self)
2443 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2444 "gnome-stock-mic", _("Can't establish audio stream"));
2448 empathy_call_window_video_stream_error (EmpathyTpStreamedMedia *call,
2451 EmpathyCallWindow *self)
2453 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2454 "camera-web", _("Can't establish video stream"));
2458 empathy_call_window_connected (gpointer user_data)
2460 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2461 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2462 EmpathyTpStreamedMedia *call;
2463 gboolean can_send_video;
2465 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2467 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2468 empathy_contact_can_voip_video (priv->contact);
2470 g_object_get (priv->handler, "tp-call", &call, NULL);
2472 tp_g_signal_connect_object (call, "notify::video-stream",
2473 G_CALLBACK (empathy_call_window_video_stream_changed_cb),
2476 if (empathy_tp_streamed_media_has_dtmf (call))
2477 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2479 if (priv->video_input == NULL)
2480 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2482 priv->sending_video = can_send_video ?
2483 empathy_tp_streamed_media_is_sending_video (call) : FALSE;
2485 gtk_toggle_tool_button_set_active (
2486 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2487 priv->sending_video && priv->video_input != NULL);
2488 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2489 gtk_action_set_sensitive (priv->action_camera_on, can_send_video);
2491 gtk_action_set_sensitive (priv->redial, FALSE);
2492 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2494 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2496 empathy_call_window_update_avatars_visibility (call, self);
2498 g_object_unref (call);
2500 g_mutex_lock (priv->lock);
2502 priv->timer_id = g_timeout_add_seconds (1,
2503 empathy_call_window_update_timer, self);
2505 g_mutex_unlock (priv->lock);
2507 empathy_call_window_update_timer (self);
2509 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2515 /* Called from the streaming thread */
2517 empathy_call_window_src_added_cb (EmpathyStreamedMediaHandler *handler,
2518 GstPad *src, guint media_type, gpointer user_data)
2520 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2521 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2522 gboolean retval = FALSE;
2526 g_mutex_lock (priv->lock);
2528 if (priv->call_state != CONNECTED)
2530 g_timer_start (priv->timer);
2531 priv->timer_id = g_idle_add (empathy_call_window_connected, self);
2532 priv->call_state = CONNECTED;
2537 case TP_MEDIA_STREAM_TYPE_AUDIO:
2538 pad = empathy_call_window_get_audio_sink_pad (self);
2540 case TP_MEDIA_STREAM_TYPE_VIDEO:
2541 gtk_widget_hide (priv->remote_user_avatar_widget);
2542 gtk_widget_show (priv->video_output);
2543 pad = empathy_call_window_get_video_sink_pad (self);
2546 g_assert_not_reached ();
2552 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2553 g_warning ("Could not link %s sink pad",
2554 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2558 gst_object_unref (pad);
2562 /* If no sink could be linked, try to add fakesink to prevent the whole call
2567 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2569 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2571 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2572 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2573 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2575 gst_element_set_locked_state (fakesink, TRUE);
2576 gst_element_set_state (fakesink, GST_STATE_NULL);
2577 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2581 g_debug ("Could not link real sink, linked fakesink instead");
2583 gst_object_unref (sinkpad);
2587 gst_object_unref (fakesink);
2592 g_mutex_unlock (priv->lock);
2598 empathy_call_window_sink_added_cb (EmpathyStreamedMediaHandler *handler,
2599 GstPad *sink, guint media_type, gpointer user_data)
2601 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2602 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2604 gboolean retval = FALSE;
2608 case TP_MEDIA_STREAM_TYPE_AUDIO:
2609 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2611 g_warning ("Could not add audio source to pipeline");
2615 pad = gst_element_get_static_pad (priv->audio_input, "src");
2618 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2619 g_warning ("Could not get source pad from audio source");
2623 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2625 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2626 g_warning ("Could not link audio source to farsight");
2630 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2632 g_warning ("Could not start audio source");
2633 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2634 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2640 case TP_MEDIA_STREAM_TYPE_VIDEO:
2641 if (priv->video_input != NULL)
2643 if (priv->video_tee != NULL)
2645 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2646 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2648 g_warning ("Could not link videp soure input pipeline");
2651 gst_object_unref (pad);
2658 g_assert_not_reached ();
2665 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2667 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2668 GstElement *preview;
2670 disable_camera (self);
2672 DEBUG ("remove video input");
2673 preview = empathy_video_widget_get_element (
2674 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2676 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2677 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2678 gst_element_set_state (preview, GST_STATE_NULL);
2680 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2681 priv->video_tee, preview, NULL);
2683 g_object_unref (priv->video_input);
2684 priv->video_input = NULL;
2685 g_object_unref (priv->video_tee);
2686 priv->video_tee = NULL;
2687 gtk_widget_destroy (priv->video_preview);
2688 priv->video_preview = NULL;
2690 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2691 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
2692 gtk_widget_set_sensitive (priv->tool_button_camera_preview, FALSE);
2696 start_call (EmpathyCallWindow *self)
2698 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2700 priv->call_started = TRUE;
2701 empathy_streamed_media_handler_start_call (priv->handler,
2702 gtk_get_current_event_time ());
2704 if (empathy_streamed_media_handler_has_initial_video (priv->handler))
2706 /* Enable 'send video' buttons and display the preview */
2707 gtk_toggle_tool_button_set_active (
2708 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2713 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2716 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2717 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2720 empathy_streamed_media_handler_bus_message (priv->handler, bus, message);
2722 switch (GST_MESSAGE_TYPE (message))
2724 case GST_MESSAGE_STATE_CHANGED:
2725 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2727 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2728 if (newstate == GST_STATE_PAUSED)
2729 empathy_call_window_setup_video_input (self);
2731 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2732 !priv->call_started)
2734 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2735 if (newstate == GST_STATE_PAUSED)
2737 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2738 priv->pipeline_playing = TRUE;
2740 if (priv->start_call_when_playing)
2745 case GST_MESSAGE_ERROR:
2747 GError *error = NULL;
2748 GstElement *gst_error;
2751 gst_message_parse_error (message, &error, &debug);
2752 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2754 g_message ("Element error: %s -- %s\n", error->message, debug);
2756 if (g_str_has_prefix (gst_element_get_name (gst_error),
2757 VIDEO_INPUT_ERROR_PREFIX))
2759 /* Remove the video input and continue */
2760 if (priv->video_input != NULL)
2761 empathy_call_window_remove_video_input (self);
2762 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2766 empathy_call_window_disconnected (self, TRUE);
2768 g_error_free (error);
2771 case GST_MESSAGE_UNKNOWN:
2772 case GST_MESSAGE_EOS:
2773 case GST_MESSAGE_WARNING:
2774 case GST_MESSAGE_INFO:
2775 case GST_MESSAGE_TAG:
2776 case GST_MESSAGE_BUFFERING:
2777 case GST_MESSAGE_STATE_DIRTY:
2778 case GST_MESSAGE_STEP_DONE:
2779 case GST_MESSAGE_CLOCK_PROVIDE:
2780 case GST_MESSAGE_CLOCK_LOST:
2781 case GST_MESSAGE_NEW_CLOCK:
2782 case GST_MESSAGE_STRUCTURE_CHANGE:
2783 case GST_MESSAGE_STREAM_STATUS:
2784 case GST_MESSAGE_APPLICATION:
2785 case GST_MESSAGE_ELEMENT:
2786 case GST_MESSAGE_SEGMENT_START:
2787 case GST_MESSAGE_SEGMENT_DONE:
2788 case GST_MESSAGE_DURATION:
2789 case GST_MESSAGE_ANY:
2798 empathy_call_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
2799 EmpathyCallWindow *window)
2801 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2803 if (empathy_tp_streamed_media_is_receiving_video (call))
2805 gtk_widget_hide (priv->remote_user_avatar_widget);
2806 gtk_widget_show (priv->video_output);
2810 gtk_widget_hide (priv->video_output);
2811 gtk_widget_show (priv->remote_user_avatar_widget);
2816 call_handler_notify_tp_streamed_media_cb (EmpathyStreamedMediaHandler *handler,
2818 EmpathyCallWindow *self)
2820 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2821 EmpathyTpStreamedMedia *call;
2823 g_object_get (priv->handler, "tp-call", &call, NULL);
2827 tp_g_signal_connect_object (call, "audio-stream-error",
2828 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2829 tp_g_signal_connect_object (call, "video-stream-error",
2830 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2832 g_object_unref (call);
2836 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2838 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2839 EmpathyTpStreamedMedia *call;
2841 g_signal_connect (priv->handler, "conference-added",
2842 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2843 g_signal_connect (priv->handler, "request-resource",
2844 G_CALLBACK (empathy_call_window_request_resource_cb), window);
2845 g_signal_connect (priv->handler, "closed",
2846 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2847 g_signal_connect (priv->handler, "src-pad-added",
2848 G_CALLBACK (empathy_call_window_src_added_cb), window);
2849 g_signal_connect (priv->handler, "sink-pad-added",
2850 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2851 g_signal_connect (priv->handler, "stream-closed",
2852 G_CALLBACK (empathy_call_window_channel_stream_closed_cb), window);
2854 g_object_get (priv->handler, "tp-call", &call, NULL);
2857 tp_g_signal_connect_object (call, "audio-stream-error",
2858 G_CALLBACK (empathy_call_window_audio_stream_error), window,
2860 tp_g_signal_connect_object (call, "video-stream-error",
2861 G_CALLBACK (empathy_call_window_video_stream_error), window,
2864 g_object_unref (call);
2868 /* tp-call doesn't exist yet, we'll connect signals once it has been
2870 g_signal_connect (priv->handler, "notify::tp-call",
2871 G_CALLBACK (call_handler_notify_tp_streamed_media_cb), window);
2874 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2878 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2879 EmpathyCallWindow *window)
2881 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2883 if (priv->pipeline != NULL)
2885 if (priv->bus_message_source_id != 0)
2887 g_source_remove (priv->bus_message_source_id);
2888 priv->bus_message_source_id = 0;
2891 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2894 if (priv->call_state == CONNECTING)
2895 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2901 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2904 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2906 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2911 gtk_widget_hide (priv->sidebar);
2912 gtk_widget_hide (menu);
2913 gtk_widget_hide (priv->vbox);
2914 gtk_widget_hide (priv->statusbar);
2915 gtk_widget_hide (priv->toolbar);
2919 if (priv->sidebar_was_visible_before_fs)
2920 gtk_widget_show (priv->sidebar);
2922 gtk_widget_show (menu);
2923 gtk_widget_show (priv->vbox);
2924 gtk_widget_show (priv->statusbar);
2925 gtk_widget_show (priv->toolbar);
2927 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2928 priv->original_height_before_fs);
2933 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2935 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2937 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2938 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2939 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2940 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2942 if (priv->video_output != NULL)
2944 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2945 priv->video_output, TRUE, TRUE,
2946 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2950 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2951 priv->vbox, TRUE, TRUE,
2952 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2957 empathy_call_window_state_event_cb (GtkWidget *widget,
2958 GdkEventWindowState *event, EmpathyCallWindow *window)
2960 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2962 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2963 gboolean set_fullscreen = event->new_window_state &
2964 GDK_WINDOW_STATE_FULLSCREEN;
2968 gboolean sidebar_was_visible;
2969 GtkAllocation allocation;
2970 gint original_width, original_height;
2972 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2973 original_width = allocation.width;
2974 original_height = allocation.height;
2976 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2978 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2979 priv->original_width_before_fs = original_width;
2980 priv->original_height_before_fs = original_height;
2982 if (priv->video_output_motion_handler_id == 0 &&
2983 priv->video_output != NULL)
2985 priv->video_output_motion_handler_id = g_signal_connect (
2986 G_OBJECT (priv->video_output), "motion-notify-event",
2987 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2993 disconnect_video_output_motion_handler (window);
2996 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2998 show_controls (window, set_fullscreen);
2999 show_borders (window, set_fullscreen);
3000 gtk_action_set_stock_id (priv->menu_fullscreen,
3001 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3002 priv->is_fullscreen = set_fullscreen;
3009 empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
3010 EmpathyCallWindow *window)
3012 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3014 int w, h, handle_size;
3015 GtkAllocation allocation, sidebar_allocation;
3017 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3018 w = allocation.width;
3019 h = allocation.height;
3021 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
3023 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
3024 if (gtk_toggle_button_get_active (toggle))
3026 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
3027 gtk_widget_show (priv->sidebar);
3028 w += sidebar_allocation.width + handle_size;
3032 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
3033 w -= sidebar_allocation.width + handle_size;
3034 gtk_widget_hide (priv->sidebar);
3037 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
3040 gtk_window_resize (GTK_WINDOW (window), w, h);
3044 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3047 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3048 EmpathyTpStreamedMedia *call;
3050 priv->sending_video = (state == CAMERA_STATE_ON);
3052 if (state == CAMERA_STATE_PREVIEW ||
3053 state == CAMERA_STATE_ON)
3055 /* When we start sending video, we want to show the video preview by
3057 display_video_preview (window, TRUE);
3061 display_video_preview (window, FALSE);
3064 if (priv->call_state != CONNECTED)
3067 g_object_get (priv->handler, "tp-call", &call, NULL);
3068 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3069 empathy_tp_streamed_media_request_video_stream_direction (call, priv->sending_video);
3070 g_object_unref (call);
3074 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3075 EmpathyCallWindow *window)
3077 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3080 active = (gtk_toggle_tool_button_get_active (toggle));
3084 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3086 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
3090 /* TODO, Instead of setting the input volume to 0 we should probably
3091 * stop sending but this would cause the audio call to drop if both
3092 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3093 * in the future. GNOME #574574
3095 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3097 gtk_adjustment_set_value (priv->audio_input_adj, 0);
3102 empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
3103 EmpathyCallWindow *window)
3105 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3107 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
3112 empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
3113 EmpathyCallWindow *window)
3115 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3117 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
3122 empathy_call_window_hangup_cb (gpointer object,
3123 EmpathyCallWindow *window)
3125 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3127 empathy_streamed_media_handler_stop_call (priv->handler);
3129 if (empathy_call_window_disconnected (window, FALSE))
3130 gtk_widget_destroy (GTK_WIDGET (window));
3134 empathy_call_window_restart_call (EmpathyCallWindow *window)
3136 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3138 /* Remove error info bars */
3139 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3140 (GtkCallback) gtk_widget_destroy, NULL);
3142 create_video_output_widget (window);
3144 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3145 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
3147 /* While the call was disconnected, the input volume might have changed.
3148 * However, since the audio_input source was destroyed, its volume has not
3149 * been updated during that time. That's why we manually update it here */
3150 empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3152 priv->outgoing = TRUE;
3153 empathy_call_window_set_state_connecting (window);
3155 if (priv->pipeline_playing)
3156 start_call (window);
3158 /* call will be started when the pipeline is ready */
3159 priv->start_call_when_playing = TRUE;
3162 empathy_call_window_setup_avatars (window, priv->handler);
3164 gtk_action_set_sensitive (priv->redial, FALSE);
3165 gtk_widget_set_sensitive (priv->redial_button, FALSE);
3169 empathy_call_window_redial_cb (gpointer object,
3170 EmpathyCallWindow *window)
3172 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3174 if (priv->call_state == CONNECTED)
3175 priv->call_state = REDIALING;
3177 empathy_streamed_media_handler_stop_call (priv->handler);
3179 if (priv->call_state != CONNECTED)
3180 empathy_call_window_restart_call (window);
3184 empathy_call_window_fullscreen_cb (gpointer object,
3185 EmpathyCallWindow *window)
3187 empathy_call_window_fullscreen_toggle (window);
3191 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3193 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3195 if (priv->is_fullscreen)
3196 gtk_window_unfullscreen (GTK_WINDOW (window));
3198 gtk_window_fullscreen (GTK_WINDOW (window));
3202 empathy_call_window_video_button_press_cb (GtkWidget *video_output,
3203 GdkEventButton *event, EmpathyCallWindow *window)
3205 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3207 empathy_call_window_video_menu_popup (window, event->button);
3215 empathy_call_window_key_press_cb (GtkWidget *video_output,
3216 GdkEventKey *event, EmpathyCallWindow *window)
3218 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3220 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3222 /* Since we are in fullscreen mode, toggling will bring us back to
3224 empathy_call_window_fullscreen_toggle (window);
3232 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3233 GdkEventMotion *event, EmpathyCallWindow *window)
3235 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3237 if (priv->is_fullscreen)
3239 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3246 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3250 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3252 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3254 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3255 button, gtk_get_current_event_time ());
3256 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3260 empathy_call_window_status_message (EmpathyCallWindow *window,
3263 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3265 if (priv->context_id == 0)
3267 priv->context_id = gtk_statusbar_get_context_id (
3268 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
3272 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
3275 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
3280 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3281 gdouble value, EmpathyCallWindow *window)
3283 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3285 if (priv->audio_output == NULL)
3288 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3292 /* block all the signals related to camera control widgets. This is useful
3293 * when we are manually updating the UI and so don't want to fire the
3296 block_camera_control_signals (EmpathyCallWindow *self)
3298 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3300 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
3301 tool_button_camera_off_toggled_cb, self);
3302 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
3303 tool_button_camera_preview_toggled_cb, self);
3304 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
3305 tool_button_camera_on_toggled_cb, self);
3306 g_signal_handlers_block_by_func (priv->action_camera_on,
3307 action_camera_change_cb, self);
3311 unblock_camera_control_signals (EmpathyCallWindow *self)
3313 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3315 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
3316 tool_button_camera_off_toggled_cb, self);
3317 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
3318 tool_button_camera_preview_toggled_cb, self);
3319 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
3320 tool_button_camera_on_toggled_cb, self);
3321 g_signal_handlers_unblock_by_func (priv->action_camera_on,
3322 action_camera_change_cb, self);