2 * empathy-streamed-media-window.c - Source for EmpathyStreamedMediaWindow
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-utils.h>
40 #include <libempathy-gtk/empathy-avatar-image.h>
41 #include <libempathy-gtk/empathy-ui-utils.h>
42 #include <libempathy-gtk/empathy-sound-manager.h>
43 #include <libempathy-gtk/empathy-geometry.h>
44 #include <libempathy-gtk/empathy-images.h>
46 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
47 #include <libempathy/empathy-debug.h>
49 #include "empathy-streamed-media-window.h"
50 #include "empathy-streamed-media-window-fullscreen.h"
51 #include "empathy-video-widget.h"
52 #include "empathy-audio-src.h"
53 #include "empathy-audio-sink.h"
54 #include "empathy-video-src.h"
55 #include "ev-sidebar.h"
57 #define CONTENT_HBOX_BORDER_WIDTH 6
58 #define CONTENT_HBOX_SPACING 3
59 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
61 #define SELF_VIDEO_SECTION_WIDTH 160
62 #define SELF_VIDEO_SECTION_HEIGTH 120
64 /* The avatar's default width and height are set to the same value because we
65 want a square icon. */
66 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
67 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
68 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
70 /* If an video input error occurs, the error message will start with "v4l" */
71 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
73 /* The time interval in milliseconds between 2 outgoing rings */
74 #define MS_BETWEEN_RING 500
76 G_DEFINE_TYPE(EmpathyStreamedMediaWindow, empathy_streamed_media_window, GTK_TYPE_WINDOW)
85 static guint signals[LAST_SIGNAL] = {0};
89 PROP_STREAMED_MEDIA_HANDLER = 1,
100 CAMERA_STATE_OFF = 0,
101 CAMERA_STATE_PREVIEW,
105 /* private structure */
106 typedef struct _EmpathyStreamedMediaWindowPriv EmpathyStreamedMediaWindowPriv;
108 struct _EmpathyStreamedMediaWindowPriv
110 gboolean dispose_has_run;
111 EmpathyStreamedMediaHandler *handler;
112 EmpathyContact *contact;
117 GtkUIManager *ui_manager;
118 GtkWidget *errors_vbox;
119 /* widget displays the video received from the remote user. This widget is
120 * alive only during call. */
121 GtkWidget *video_output;
122 GtkWidget *video_preview;
123 GtkWidget *remote_user_avatar_widget;
124 GtkWidget *self_user_avatar_widget;
126 GtkWidget *sidebar_button;
127 GtkWidget *statusbar;
128 GtkWidget *volume_button;
129 GtkWidget *redial_button;
130 GtkWidget *mic_button;
134 GtkAction *menu_fullscreen;
135 GtkAction *action_camera_on;
136 GtkWidget *tool_button_camera_off;
137 GtkWidget *tool_button_camera_preview;
138 GtkWidget *tool_button_camera_on;
140 /* The frames and boxes that contain self and remote avatar and video
141 input/output. When we redial, we destroy and re-create the boxes */
142 GtkWidget *remote_user_output_frame;
143 GtkWidget *self_user_output_frame;
144 GtkWidget *remote_user_output_hbox;
145 GtkWidget *self_user_output_hbox;
147 /* We keep a reference on the hbox which contains the main content so we can
148 easilly repack everything when toggling fullscreen */
149 GtkWidget *content_hbox;
151 /* This vbox is contained in the content_hbox and it contains the
152 self_user_output_frame and the sidebar button. When toggling fullscreen,
153 it needs to be repacked. We keep a reference on it for easier access. */
156 gulong video_output_motion_handler_id;
157 guint bus_message_source_id;
160 GtkWidget *volume_scale;
161 GtkWidget *volume_progress_bar;
162 GtkAdjustment *audio_input_adj;
164 GtkWidget *dtmf_panel;
167 GtkWidget *details_vbox;
168 GtkWidget *vcodec_encoding_label;
169 GtkWidget *acodec_encoding_label;
170 GtkWidget *vcodec_decoding_label;
171 GtkWidget *acodec_decoding_label;
173 GtkWidget *audio_remote_candidate_label;
174 GtkWidget *audio_local_candidate_label;
175 GtkWidget *video_remote_candidate_label;
176 GtkWidget *video_local_candidate_label;
177 GtkWidget *video_remote_candidate_info_img;
178 GtkWidget *video_local_candidate_info_img;
179 GtkWidget *audio_remote_candidate_info_img;
180 GtkWidget *audio_local_candidate_info_img;
182 GstElement *video_input;
183 GstElement *audio_input;
184 GstElement *audio_output;
185 GstElement *pipeline;
186 GstElement *video_tee;
190 FsElementAddedNotifier *fsnotifier;
197 GtkWidget *video_contrast;
198 GtkWidget *video_brightness;
199 GtkWidget *video_gamma;
202 gboolean call_started;
203 gboolean sending_video;
204 CameraState camera_state;
206 EmpathyStreamedMediaWindowFullscreen *fullscreen;
207 gboolean is_fullscreen;
209 /* Those fields represent the state of the window before it actually was in
211 gboolean sidebar_was_visible_before_fs;
212 gint original_width_before_fs;
213 gint original_height_before_fs;
215 /* TRUE if the call should be started when the pipeline is playing */
216 gboolean start_call_when_playing;
217 /* TRUE if we requested to set the pipeline in the playing state */
218 gboolean pipeline_playing;
220 EmpathySoundManager *sound_mgr;
223 #define GET_PRIV(o) \
224 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_STREAMED_MEDIA_WINDOW, \
225 EmpathyStreamedMediaWindowPriv))
227 static void empathy_streamed_media_window_realized_cb (GtkWidget *widget,
228 EmpathyStreamedMediaWindow *window);
230 static gboolean empathy_streamed_media_window_delete_cb (GtkWidget *widget,
231 GdkEvent *event, EmpathyStreamedMediaWindow *window);
233 static gboolean empathy_streamed_media_window_state_event_cb (GtkWidget *widget,
234 GdkEventWindowState *event, EmpathyStreamedMediaWindow *window);
236 static void empathy_streamed_media_window_sidebar_toggled_cb (GtkToggleButton *toggle,
237 EmpathyStreamedMediaWindow *window);
239 static void empathy_streamed_media_window_set_send_video (EmpathyStreamedMediaWindow *window,
242 static void empathy_streamed_media_window_mic_toggled_cb (
243 GtkToggleToolButton *toggle, EmpathyStreamedMediaWindow *window);
245 static void empathy_streamed_media_window_sidebar_hidden_cb (EvSidebar *sidebar,
246 EmpathyStreamedMediaWindow *window);
248 static void empathy_streamed_media_window_sidebar_shown_cb (EvSidebar *sidebar,
249 EmpathyStreamedMediaWindow *window);
251 static void empathy_streamed_media_window_hangup_cb (gpointer object,
252 EmpathyStreamedMediaWindow *window);
254 static void empathy_streamed_media_window_fullscreen_cb (gpointer object,
255 EmpathyStreamedMediaWindow *window);
257 static void empathy_streamed_media_window_fullscreen_toggle (EmpathyStreamedMediaWindow *window);
259 static gboolean empathy_streamed_media_window_video_button_press_cb (
260 GtkWidget *video_output, GdkEventButton *event, EmpathyStreamedMediaWindow *window);
262 static gboolean empathy_streamed_media_window_key_press_cb (GtkWidget *video_output,
263 GdkEventKey *event, EmpathyStreamedMediaWindow *window);
265 static gboolean empathy_streamed_media_window_video_output_motion_notify (
266 GtkWidget *widget, GdkEventMotion *event, EmpathyStreamedMediaWindow *window);
268 static void empathy_streamed_media_window_video_menu_popup (EmpathyStreamedMediaWindow *window,
271 static void empathy_streamed_media_window_redial_cb (gpointer object,
272 EmpathyStreamedMediaWindow *window);
274 static void empathy_streamed_media_window_restart_call (EmpathyStreamedMediaWindow *window);
276 static void empathy_streamed_media_window_status_message (EmpathyStreamedMediaWindow *window,
279 static void empathy_streamed_media_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
280 EmpathyStreamedMediaWindow *window);
282 static gboolean empathy_streamed_media_window_bus_message (GstBus *bus,
283 GstMessage *message, gpointer user_data);
286 empathy_streamed_media_window_volume_changed_cb (GtkScaleButton *button,
287 gdouble value, EmpathyStreamedMediaWindow *window);
289 static void block_camera_control_signals (EmpathyStreamedMediaWindow *self);
290 static void unblock_camera_control_signals (EmpathyStreamedMediaWindow *self);
293 empathy_streamed_media_window_setup_toolbar (EmpathyStreamedMediaWindow *self)
295 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
296 GtkToolItem *tool_item;
297 GtkWidget *camera_off_icon;
298 GdkPixbuf *pixbuf, *modded_pixbuf;
300 /* set the icon of the 'camera off' button by greying off the webcam icon */
301 pixbuf = empathy_pixbuf_from_icon_name ("camera-web",
302 GTK_ICON_SIZE_SMALL_TOOLBAR);
304 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
305 gdk_pixbuf_get_width (pixbuf),
306 gdk_pixbuf_get_height (pixbuf));
308 gdk_pixbuf_saturate_and_pixelate (pixbuf, modded_pixbuf, 1.0, TRUE);
309 g_object_unref (pixbuf);
311 camera_off_icon = gtk_image_new_from_pixbuf (modded_pixbuf);
312 g_object_unref (modded_pixbuf);
313 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (
314 priv->tool_button_camera_off), camera_off_icon);
316 /* Add an empty expanded GtkToolItem so the volume button is at the end of
318 tool_item = gtk_tool_item_new ();
319 gtk_tool_item_set_expand (tool_item, TRUE);
320 gtk_widget_show (GTK_WIDGET (tool_item));
321 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
323 priv->volume_button = gtk_volume_button_new ();
324 /* FIXME listen to the audiosinks signals and update the button according to
325 * that, for now starting out at 1.0 and assuming only the app changes the
327 gtk_scale_button_set_value (GTK_SCALE_BUTTON (priv->volume_button), 1.0);
328 g_signal_connect (G_OBJECT (priv->volume_button), "value-changed",
329 G_CALLBACK (empathy_streamed_media_window_volume_changed_cb), self);
331 tool_item = gtk_tool_item_new ();
332 gtk_container_add (GTK_CONTAINER (tool_item), priv->volume_button);
333 gtk_widget_show_all (GTK_WIDGET (tool_item));
334 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
338 dtmf_button_pressed_cb (GtkButton *button, EmpathyStreamedMediaWindow *window)
340 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
341 EmpathyTpStreamedMedia *call;
345 g_object_get (priv->handler, "tp-call", &call, NULL);
347 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
348 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
351 empathy_tp_streamed_media_start_tone (call, event);
353 g_object_unref (call);
357 dtmf_button_released_cb (GtkButton *button, EmpathyStreamedMediaWindow *window)
359 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
360 EmpathyTpStreamedMedia *call;
362 g_object_get (priv->handler, "tp-call", &call, NULL);
364 empathy_tp_streamed_media_stop_tone (call);
366 g_object_unref (call);
370 empathy_streamed_media_window_create_video_input_add_slider (EmpathyStreamedMediaWindow *self,
371 gchar *label_text, GtkWidget *bin)
373 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
374 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
375 GtkWidget *label = gtk_label_new (label_text);
377 gtk_widget_set_sensitive (scale, FALSE);
379 gtk_container_add (GTK_CONTAINER (bin), vbox);
381 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
382 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
383 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
389 empathy_streamed_media_window_video_contrast_changed_cb (GtkAdjustment *adj,
390 EmpathyStreamedMediaWindow *self)
393 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
395 empathy_video_src_set_channel (priv->video_input,
396 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
400 empathy_streamed_media_window_video_brightness_changed_cb (GtkAdjustment *adj,
401 EmpathyStreamedMediaWindow *self)
404 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
406 empathy_video_src_set_channel (priv->video_input,
407 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
411 empathy_streamed_media_window_video_gamma_changed_cb (GtkAdjustment *adj,
412 EmpathyStreamedMediaWindow *self)
415 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
417 empathy_video_src_set_channel (priv->video_input,
418 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
423 empathy_streamed_media_window_create_video_input (EmpathyStreamedMediaWindow *self)
425 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
428 hbox = gtk_hbox_new (TRUE, 3);
430 priv->video_contrast = empathy_streamed_media_window_create_video_input_add_slider (
431 self, _("Contrast"), hbox);
433 priv->video_brightness = empathy_streamed_media_window_create_video_input_add_slider (
434 self, _("Brightness"), hbox);
436 priv->video_gamma = empathy_streamed_media_window_create_video_input_add_slider (
437 self, _("Gamma"), hbox);
443 empathy_streamed_media_window_setup_video_input (EmpathyStreamedMediaWindow *self)
445 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
449 supported = empathy_video_src_get_supported_channels (priv->video_input);
451 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
453 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
455 gtk_adjustment_set_value (adj,
456 empathy_video_src_get_channel (priv->video_input,
457 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
459 g_signal_connect (G_OBJECT (adj), "value-changed",
460 G_CALLBACK (empathy_streamed_media_window_video_contrast_changed_cb), self);
462 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
465 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
467 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
469 gtk_adjustment_set_value (adj,
470 empathy_video_src_get_channel (priv->video_input,
471 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
473 g_signal_connect (G_OBJECT (adj), "value-changed",
474 G_CALLBACK (empathy_streamed_media_window_video_brightness_changed_cb), self);
475 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
478 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
480 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
482 gtk_adjustment_set_value (adj,
483 empathy_video_src_get_channel (priv->video_input,
484 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
486 g_signal_connect (G_OBJECT (adj), "value-changed",
487 G_CALLBACK (empathy_streamed_media_window_video_gamma_changed_cb), self);
488 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
493 empathy_streamed_media_window_mic_volume_changed_cb (GtkAdjustment *adj,
494 EmpathyStreamedMediaWindow *self)
496 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
499 volume = gtk_adjustment_get_value (adj)/100.0;
501 /* Don't store the volume because of muting */
502 if (volume > 0 || gtk_toggle_tool_button_get_active (
503 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
504 priv->volume = volume;
506 /* Ensure that the toggle button is active if the volume is > 0 and inactive
507 * if it's smaller than 0 */
508 if ((volume > 0) != gtk_toggle_tool_button_get_active (
509 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
510 gtk_toggle_tool_button_set_active (
511 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
513 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
518 empathy_streamed_media_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
519 gdouble level, EmpathyStreamedMediaWindow *window)
522 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
524 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
525 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
530 empathy_streamed_media_window_create_audio_input (EmpathyStreamedMediaWindow *self)
532 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
533 GtkWidget *hbox, *vbox, *label;
535 hbox = gtk_hbox_new (TRUE, 3);
537 vbox = gtk_vbox_new (FALSE, 3);
538 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
540 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
541 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
542 label = gtk_label_new (_("Volume"));
544 priv->audio_input_adj = gtk_range_get_adjustment (
545 GTK_RANGE (priv->volume_scale));
546 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
547 (priv->audio_input));
548 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
550 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
551 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), self);
553 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
554 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
556 priv->volume_progress_bar = gtk_progress_bar_new ();
558 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
559 GTK_ORIENTATION_VERTICAL);
561 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
564 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
571 create_video_output_widget (EmpathyStreamedMediaWindow *self)
573 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
576 g_assert (priv->video_output == NULL);
577 g_assert (priv->pipeline != NULL);
579 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
580 priv->video_output = empathy_video_widget_new (bus);
582 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
583 priv->video_output, TRUE, TRUE, 0);
585 gtk_widget_add_events (priv->video_output,
586 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
587 g_signal_connect (G_OBJECT (priv->video_output), "button-press-event",
588 G_CALLBACK (empathy_streamed_media_window_video_button_press_cb), self);
590 g_object_unref (bus);
594 create_video_input (EmpathyStreamedMediaWindow *self)
596 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
598 g_assert (priv->video_input == NULL);
599 priv->video_input = empathy_video_src_new ();
600 gst_object_ref (priv->video_input);
601 gst_object_sink (priv->video_input);
605 create_audio_input (EmpathyStreamedMediaWindow *self)
607 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
609 g_assert (priv->audio_input == NULL);
610 priv->audio_input = empathy_audio_src_new ();
611 gst_object_ref (priv->audio_input);
612 gst_object_sink (priv->audio_input);
614 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
615 G_CALLBACK (empathy_streamed_media_window_audio_input_level_changed_cb),
620 add_video_preview_to_pipeline (EmpathyStreamedMediaWindow *self)
622 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
625 g_assert (priv->video_preview != NULL);
626 g_assert (priv->pipeline != NULL);
627 g_assert (priv->video_input != NULL);
628 g_assert (priv->video_tee != NULL);
630 preview = empathy_video_widget_get_element (
631 EMPATHY_VIDEO_WIDGET (priv->video_preview));
633 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
635 g_warning ("Could not add video input to pipeline");
639 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee))
641 g_warning ("Could not add video tee to pipeline");
645 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
647 g_warning ("Could not add video preview to pipeline");
651 if (!gst_element_link (priv->video_input, priv->video_tee))
653 g_warning ("Could not link video input to video tee");
657 if (!gst_element_link (priv->video_tee, preview))
659 g_warning ("Could not link video tee to video preview");
665 create_video_preview (EmpathyStreamedMediaWindow *self)
667 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
670 g_assert (priv->video_preview == NULL);
671 g_assert (priv->video_tee == NULL);
673 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
675 priv->video_preview = empathy_video_widget_new_with_size (bus,
676 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
677 g_object_set (priv->video_preview,
683 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
684 priv->video_preview, TRUE, TRUE, 0);
686 priv->video_tee = gst_element_factory_make ("tee", NULL);
687 gst_object_ref (priv->video_tee);
688 gst_object_sink (priv->video_tee);
690 g_object_unref (bus);
694 play_camera (EmpathyStreamedMediaWindow *window,
697 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
701 if (priv->video_preview == NULL)
703 create_video_preview (window);
704 add_video_preview_to_pipeline (window);
708 state = GST_STATE_PLAYING;
710 state = GST_STATE_NULL;
712 preview = empathy_video_widget_get_element (
713 EMPATHY_VIDEO_WIDGET (priv->video_preview));
715 gst_element_set_state (preview, state);
716 gst_element_set_state (priv->video_input, state);
717 gst_element_set_state (priv->video_tee, state);
721 display_video_preview (EmpathyStreamedMediaWindow *self,
724 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
728 /* Display the preview and hide the self avatar */
729 DEBUG ("Show video preview");
731 play_camera (self, TRUE);
732 gtk_widget_show (priv->video_preview);
733 gtk_widget_hide (priv->self_user_avatar_widget);
737 /* Display the self avatar and hide the preview */
738 DEBUG ("Show self avatar");
740 if (priv->video_preview != NULL)
742 gtk_widget_hide (priv->video_preview);
743 play_camera (self, FALSE);
745 gtk_widget_show (priv->self_user_avatar_widget);
750 empathy_streamed_media_window_set_state_connecting (EmpathyStreamedMediaWindow *window)
752 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
754 empathy_streamed_media_window_status_message (window, _("Connecting…"));
755 priv->call_state = CONNECTING;
758 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
759 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
763 disable_camera (EmpathyStreamedMediaWindow *self)
765 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
767 if (priv->camera_state == CAMERA_STATE_OFF)
770 DEBUG ("Disable camera");
772 display_video_preview (self, FALSE);
774 if (priv->camera_state == CAMERA_STATE_ON)
775 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
777 block_camera_control_signals (self);
778 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
779 priv->tool_button_camera_on), FALSE);
780 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
781 priv->tool_button_camera_preview), FALSE);
783 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
784 priv->tool_button_camera_off), TRUE);
785 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
787 unblock_camera_control_signals (self);
789 priv->camera_state = CAMERA_STATE_OFF;
793 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
794 EmpathyStreamedMediaWindow *self)
796 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
798 if (!gtk_toggle_tool_button_get_active (toggle))
800 if (priv->camera_state == CAMERA_STATE_OFF)
802 /* We can't change the state by disabling the button */
803 block_camera_control_signals (self);
804 gtk_toggle_tool_button_set_active (toggle, TRUE);
805 unblock_camera_control_signals (self);
811 disable_camera (self);
815 enable_preview (EmpathyStreamedMediaWindow *self)
817 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
819 if (priv->camera_state == CAMERA_STATE_PREVIEW)
822 DEBUG ("Enable preview");
824 if (priv->camera_state == CAMERA_STATE_ON)
826 /* preview is already displayed so we just have to stop sending */
827 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_PREVIEW);
831 display_video_preview (self, TRUE);
834 block_camera_control_signals (self);
835 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
836 priv->tool_button_camera_off), FALSE);
837 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
838 priv->tool_button_camera_on), FALSE);
840 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
841 priv->tool_button_camera_preview), TRUE);
842 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
843 CAMERA_STATE_PREVIEW);
844 unblock_camera_control_signals (self);
846 priv->camera_state = CAMERA_STATE_PREVIEW;
850 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
851 EmpathyStreamedMediaWindow *self)
853 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
855 if (!gtk_toggle_tool_button_get_active (toggle))
857 if (priv->camera_state == CAMERA_STATE_PREVIEW)
859 /* We can't change the state by disabling the button */
860 block_camera_control_signals (self);
861 gtk_toggle_tool_button_set_active (toggle, TRUE);
862 unblock_camera_control_signals (self);
868 enable_preview (self);
872 enable_camera (EmpathyStreamedMediaWindow *self)
874 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
876 if (priv->camera_state == CAMERA_STATE_ON)
879 if (priv->video_input == NULL)
881 DEBUG ("Can't enable camera, no input");
886 DEBUG ("Enable camera");
888 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_ON);
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_preview), FALSE);
896 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
897 priv->tool_button_camera_on), TRUE);
898 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
900 unblock_camera_control_signals (self);
902 priv->camera_state = CAMERA_STATE_ON;
906 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
907 EmpathyStreamedMediaWindow *self)
909 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
911 if (!gtk_toggle_tool_button_get_active (toggle))
913 if (priv->camera_state == CAMERA_STATE_ON)
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_camera (self);
928 action_camera_change_cb (GtkRadioAction *action,
929 GtkRadioAction *current,
930 EmpathyStreamedMediaWindow *self)
934 state = gtk_radio_action_get_current_value (current);
938 case CAMERA_STATE_OFF:
939 disable_camera (self);
942 case CAMERA_STATE_PREVIEW:
943 enable_preview (self);
946 case CAMERA_STATE_ON:
947 enable_camera (self);
951 g_assert_not_reached ();
956 create_pipeline (EmpathyStreamedMediaWindow *self)
958 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
961 g_assert (priv->pipeline == NULL);
963 priv->pipeline = gst_pipeline_new (NULL);
964 priv->pipeline_playing = FALSE;
966 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
967 priv->bus_message_source_id = gst_bus_add_watch (bus,
968 empathy_streamed_media_window_bus_message, self);
970 g_object_unref (bus);
975 empathy_streamed_media_window_init (EmpathyStreamedMediaWindow *self)
977 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
985 GError *error = NULL;
988 filename = empathy_file_lookup ("empathy-streamed-media-window.ui", "src");
989 gui = empathy_builder_get_file (filename,
990 "call_window_vbox", &top_vbox,
991 "errors_vbox", &priv->errors_vbox,
993 "statusbar", &priv->statusbar,
994 "redial", &priv->redial_button,
995 "microphone", &priv->mic_button,
996 "toolbar", &priv->toolbar,
997 "menuredial", &priv->redial,
998 "ui_manager", &priv->ui_manager,
999 "menufullscreen", &priv->menu_fullscreen,
1000 "camera_off", &priv->tool_button_camera_off,
1001 "camera_preview", &priv->tool_button_camera_preview,
1002 "camera_on", &priv->tool_button_camera_on,
1003 "action_camera_on", &priv->action_camera_on,
1004 "details_vbox", &priv->details_vbox,
1005 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1006 "acodec_encoding_label", &priv->acodec_encoding_label,
1007 "acodec_decoding_label", &priv->acodec_decoding_label,
1008 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1009 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1010 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1011 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1012 "video_local_candidate_label", &priv->video_local_candidate_label,
1013 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1014 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1015 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1016 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1020 empathy_builder_connect (gui, self,
1021 "menuhangup", "activate", empathy_streamed_media_window_hangup_cb,
1022 "hangup", "clicked", empathy_streamed_media_window_hangup_cb,
1023 "menuredial", "activate", empathy_streamed_media_window_redial_cb,
1024 "redial", "clicked", empathy_streamed_media_window_redial_cb,
1025 "microphone", "toggled", empathy_streamed_media_window_mic_toggled_cb,
1026 "menufullscreen", "activate", empathy_streamed_media_window_fullscreen_cb,
1027 "camera_off", "toggled", tool_button_camera_off_toggled_cb,
1028 "camera_preview", "toggled", tool_button_camera_preview_toggled_cb,
1029 "camera_on", "toggled", tool_button_camera_on_toggled_cb,
1030 "action_camera_on", "changed", action_camera_change_cb,
1033 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1035 priv->lock = g_mutex_new ();
1037 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1039 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1040 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1041 CONTENT_HBOX_BORDER_WIDTH);
1042 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1044 /* remote user output frame */
1045 priv->remote_user_output_frame = gtk_frame_new (NULL);
1046 gtk_widget_set_size_request (priv->remote_user_output_frame,
1047 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1048 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1049 priv->remote_user_output_frame, TRUE, TRUE,
1050 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1052 priv->remote_user_output_hbox = gtk_hbox_new (FALSE, 0);
1054 priv->remote_user_avatar_widget = gtk_image_new ();
1056 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1057 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1059 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1060 priv->remote_user_output_hbox);
1062 /* self user output frame */
1063 priv->self_user_output_frame = gtk_frame_new (NULL);
1064 gtk_widget_set_size_request (priv->self_user_output_frame,
1065 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1067 priv->self_user_output_hbox = gtk_hbox_new (FALSE, 0);
1069 priv->self_user_avatar_widget = gtk_image_new ();
1070 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1071 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1073 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1074 priv->self_user_output_hbox);
1076 create_pipeline (self);
1077 create_video_output_widget (self);
1078 create_audio_input (self);
1079 create_video_input (self);
1081 priv->fsnotifier = fs_element_added_notifier_new ();
1082 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1084 /* The call will be started as soon the pipeline is playing */
1085 priv->start_call_when_playing = TRUE;
1087 keyfile = g_key_file_new ();
1088 filename = empathy_file_lookup ("element-properties", "data");
1089 if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error))
1091 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1096 g_warning ("Could not load element-properties file: %s", error->message);
1097 g_key_file_free (keyfile);
1098 g_clear_error (&error);
1102 priv->vbox = gtk_vbox_new (FALSE, 3);
1103 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1104 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1105 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1108 empathy_streamed_media_window_setup_toolbar (self);
1110 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1111 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1112 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1113 G_CALLBACK (empathy_streamed_media_window_sidebar_toggled_cb), self);
1115 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1117 h = gtk_hbox_new (FALSE, 3);
1118 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1119 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1121 priv->sidebar = ev_sidebar_new ();
1122 g_signal_connect (G_OBJECT (priv->sidebar),
1123 "hide", G_CALLBACK (empathy_streamed_media_window_sidebar_hidden_cb), self);
1124 g_signal_connect (G_OBJECT (priv->sidebar),
1125 "show", G_CALLBACK (empathy_streamed_media_window_sidebar_shown_cb), self);
1126 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1128 page = empathy_streamed_media_window_create_audio_input (self);
1129 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1130 _("Audio input"), page);
1132 page = empathy_streamed_media_window_create_video_input (self);
1133 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1134 _("Video input"), page);
1136 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1137 G_CALLBACK (dtmf_button_pressed_cb),
1138 G_CALLBACK (dtmf_button_released_cb));
1139 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1140 _("Dialpad"), priv->dtmf_panel);
1142 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1144 /* Put the details vbox in a scroll window as it can require a lot of
1145 * horizontal space. */
1146 scroll = gtk_scrolled_window_new (NULL, NULL);
1147 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll),
1148 priv->details_vbox);
1150 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details",
1151 _("Details"), scroll);
1153 gtk_widget_show_all (top_vbox);
1155 gtk_widget_hide (priv->sidebar);
1157 priv->fullscreen = empathy_streamed_media_window_fullscreen_new (self);
1158 empathy_streamed_media_window_fullscreen_set_video_widget (priv->fullscreen,
1159 priv->video_output);
1160 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1161 "clicked", G_CALLBACK (empathy_streamed_media_window_fullscreen_cb), self);
1163 g_signal_connect (G_OBJECT (self), "realize",
1164 G_CALLBACK (empathy_streamed_media_window_realized_cb), self);
1166 g_signal_connect (G_OBJECT (self), "delete-event",
1167 G_CALLBACK (empathy_streamed_media_window_delete_cb), self);
1169 g_signal_connect (G_OBJECT (self), "window-state-event",
1170 G_CALLBACK (empathy_streamed_media_window_state_event_cb), self);
1172 g_signal_connect (G_OBJECT (self), "key-press-event",
1173 G_CALLBACK (empathy_streamed_media_window_key_press_cb), self);
1175 priv->timer = g_timer_new ();
1177 g_object_ref (priv->ui_manager);
1178 g_object_unref (gui);
1180 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1182 empathy_geometry_bind (GTK_WINDOW (self), "av-window");
1185 /* Instead of specifying a width and a height, we specify only one size. That's
1186 because we want a square avatar icon. */
1188 init_contact_avatar_with_size (EmpathyContact *contact,
1189 GtkWidget *image_widget,
1192 GdkPixbuf *pixbuf_avatar = NULL;
1194 if (contact != NULL)
1196 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1200 if (pixbuf_avatar == NULL)
1202 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1203 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1206 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1208 if (pixbuf_avatar != NULL)
1209 g_object_unref (pixbuf_avatar);
1213 set_window_title (EmpathyStreamedMediaWindow *self)
1215 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1218 /* translators: Call is a noun and %s is the contact name. This string
1219 * is used in the window title */
1220 tmp = g_strdup_printf (_("Call with %s"),
1221 empathy_contact_get_alias (priv->contact));
1222 gtk_window_set_title (GTK_WINDOW (self), tmp);
1227 contact_name_changed_cb (EmpathyContact *contact,
1228 GParamSpec *pspec, EmpathyStreamedMediaWindow *self)
1230 set_window_title (self);
1234 contact_avatar_changed_cb (EmpathyContact *contact,
1235 GParamSpec *pspec, GtkWidget *avatar_widget)
1238 GtkAllocation allocation;
1240 gtk_widget_get_allocation (avatar_widget, &allocation);
1241 size = allocation.height;
1245 /* the widget is not allocated yet, set a default size */
1246 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1247 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1250 init_contact_avatar_with_size (contact, avatar_widget, size);
1254 empathy_streamed_media_window_got_self_contact_cb (TpConnection *connection,
1255 EmpathyContact *contact, const GError *error, gpointer user_data,
1256 GObject *weak_object)
1258 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1259 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1261 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1262 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1264 g_signal_connect (contact, "notify::avatar",
1265 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1269 empathy_streamed_media_window_setup_avatars (EmpathyStreamedMediaWindow *self,
1270 EmpathyStreamedMediaHandler *handler)
1272 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1274 g_object_get (handler, "contact", &(priv->contact), NULL);
1276 if (priv->contact != NULL)
1278 TpConnection *connection;
1280 set_window_title (self);
1282 g_signal_connect (priv->contact, "notify::name",
1283 G_CALLBACK (contact_name_changed_cb), self);
1284 g_signal_connect (priv->contact, "notify::avatar",
1285 G_CALLBACK (contact_avatar_changed_cb),
1286 priv->remote_user_avatar_widget);
1288 /* Retreiving the self avatar */
1289 connection = empathy_contact_get_connection (priv->contact);
1290 empathy_tp_contact_factory_get_from_handle (connection,
1291 tp_connection_get_self_handle (connection),
1292 empathy_streamed_media_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1296 g_warning ("call handler doesn't have a contact");
1297 /* translators: Call is a noun. This string is used in the window
1299 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1301 /* Since we can't access the remote contact, we can't get a connection
1302 to it and can't get the self contact (and its avatar). This means
1303 that we have to manually set the self avatar. */
1304 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1305 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1308 init_contact_avatar_with_size (priv->contact,
1309 priv->remote_user_avatar_widget,
1310 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1311 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1313 /* The remote avatar is shown by default and will be hidden when we receive
1314 video from the remote side. */
1315 gtk_widget_hide (priv->video_output);
1316 gtk_widget_show (priv->remote_user_avatar_widget);
1320 update_send_codec (EmpathyStreamedMediaWindow *self,
1323 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1330 codec = empathy_streamed_media_handler_get_send_audio_codec (priv->handler);
1331 widget = priv->acodec_encoding_label;
1335 codec = empathy_streamed_media_handler_get_send_video_codec (priv->handler);
1336 widget = priv->vcodec_encoding_label;
1342 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1343 gtk_label_set_text (GTK_LABEL (widget), tmp);
1348 send_audio_codec_notify_cb (GObject *object,
1352 EmpathyStreamedMediaWindow *self = user_data;
1354 update_send_codec (self, TRUE);
1358 send_video_codec_notify_cb (GObject *object,
1362 EmpathyStreamedMediaWindow *self = user_data;
1364 update_send_codec (self, FALSE);
1368 update_recv_codec (EmpathyStreamedMediaWindow *self,
1371 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1374 GString *str = NULL;
1378 codecs = empathy_streamed_media_handler_get_recv_audio_codecs (priv->handler);
1379 widget = priv->acodec_decoding_label;
1383 codecs = empathy_streamed_media_handler_get_recv_video_codecs (priv->handler);
1384 widget = priv->vcodec_decoding_label;
1390 for (l = codecs; l != NULL; l = g_list_next (l))
1392 FsCodec *codec = l->data;
1395 str = g_string_new (NULL);
1397 g_string_append (str, ", ");
1399 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1403 gtk_label_set_text (GTK_LABEL (widget), str->str);
1404 g_string_free (str, TRUE);
1408 recv_audio_codecs_notify_cb (GObject *object,
1412 EmpathyStreamedMediaWindow *self = user_data;
1414 update_recv_codec (self, TRUE);
1418 recv_video_codecs_notify_cb (GObject *object,
1422 EmpathyStreamedMediaWindow *self = user_data;
1424 update_recv_codec (self, FALSE);
1427 static const gchar *
1428 candidate_type_to_str (FsCandidate *candidate)
1430 switch (candidate->type)
1432 case FS_CANDIDATE_TYPE_HOST:
1434 case FS_CANDIDATE_TYPE_SRFLX:
1435 return "server reflexive";
1436 case FS_CANDIDATE_TYPE_PRFLX:
1437 return "peer reflexive";
1438 case FS_CANDIDATE_TYPE_RELAY:
1440 case FS_CANDIDATE_TYPE_MULTICAST:
1447 static const gchar *
1448 candidate_type_to_desc (FsCandidate *candidate)
1450 switch (candidate->type)
1452 case FS_CANDIDATE_TYPE_HOST:
1453 return _("The IP address as seen by the machine");
1454 case FS_CANDIDATE_TYPE_SRFLX:
1455 return _("The IP address as seen by a server on the Internet");
1456 case FS_CANDIDATE_TYPE_PRFLX:
1457 return _("The IP address of the peer as seen by the other side");
1458 case FS_CANDIDATE_TYPE_RELAY:
1459 return _("The IP address of a relay server");
1460 case FS_CANDIDATE_TYPE_MULTICAST:
1461 return _("The IP address of the multicast group");
1468 update_candidat_widget (EmpathyStreamedMediaWindow *self,
1471 FsCandidate *candidate)
1475 g_assert (candidate != NULL);
1476 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1477 candidate->port, candidate_type_to_str (candidate));
1479 gtk_label_set_text (GTK_LABEL (label), str);
1480 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1486 candidates_changed_cb (GObject *object,
1488 EmpathyStreamedMediaWindow *self)
1490 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1491 FsCandidate *candidate = NULL;
1493 if (type == FS_MEDIA_TYPE_VIDEO)
1495 /* Update remote candidate */
1496 candidate = empathy_streamed_media_handler_get_video_remote_candidate (
1499 update_candidat_widget (self, priv->video_remote_candidate_label,
1500 priv->video_remote_candidate_info_img, candidate);
1502 /* Update local candidate */
1503 candidate = empathy_streamed_media_handler_get_video_local_candidate (
1506 update_candidat_widget (self, priv->video_local_candidate_label,
1507 priv->video_local_candidate_info_img, candidate);
1511 /* Update remote candidate */
1512 candidate = empathy_streamed_media_handler_get_audio_remote_candidate (
1515 update_candidat_widget (self, priv->audio_remote_candidate_label,
1516 priv->audio_remote_candidate_info_img, candidate);
1518 /* Update local candidate */
1519 candidate = empathy_streamed_media_handler_get_audio_local_candidate (
1522 update_candidat_widget (self, priv->audio_local_candidate_label,
1523 priv->audio_local_candidate_info_img, candidate);
1528 empathy_streamed_media_window_constructed (GObject *object)
1530 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1531 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1532 EmpathyTpStreamedMedia *call;
1534 g_assert (priv->handler != NULL);
1536 g_object_get (priv->handler, "tp-call", &call, NULL);
1537 priv->outgoing = (call == NULL);
1539 g_object_unref (call);
1541 empathy_streamed_media_window_setup_avatars (self, priv->handler);
1542 empathy_streamed_media_window_set_state_connecting (self);
1544 if (!empathy_streamed_media_handler_has_initial_video (priv->handler))
1546 gtk_toggle_tool_button_set_active (
1547 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1549 /* If call has InitialVideo, the preview will be started once the call has
1550 * been started (start_call()). */
1552 update_send_codec (self, TRUE);
1553 update_send_codec (self, FALSE);
1554 update_recv_codec (self, TRUE);
1555 update_recv_codec (self, FALSE);
1557 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1558 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1559 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1560 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1561 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1562 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1563 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1564 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1566 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1567 G_CALLBACK (candidates_changed_cb), self, 0);
1570 static void empathy_streamed_media_window_dispose (GObject *object);
1571 static void empathy_streamed_media_window_finalize (GObject *object);
1574 empathy_streamed_media_window_set_property (GObject *object,
1575 guint property_id, const GValue *value, GParamSpec *pspec)
1577 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1579 switch (property_id)
1581 case PROP_STREAMED_MEDIA_HANDLER:
1582 priv->handler = g_value_dup_object (value);
1585 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1590 empathy_streamed_media_window_get_property (GObject *object,
1591 guint property_id, GValue *value, GParamSpec *pspec)
1593 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1595 switch (property_id)
1597 case PROP_STREAMED_MEDIA_HANDLER:
1598 g_value_set_object (value, priv->handler);
1601 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1606 empathy_streamed_media_window_class_init (
1607 EmpathyStreamedMediaWindowClass *empathy_streamed_media_window_class)
1609 GObjectClass *object_class = G_OBJECT_CLASS (empathy_streamed_media_window_class);
1610 GParamSpec *param_spec;
1612 g_type_class_add_private (empathy_streamed_media_window_class,
1613 sizeof (EmpathyStreamedMediaWindowPriv));
1615 object_class->constructed = empathy_streamed_media_window_constructed;
1616 object_class->set_property = empathy_streamed_media_window_set_property;
1617 object_class->get_property = empathy_streamed_media_window_get_property;
1619 object_class->dispose = empathy_streamed_media_window_dispose;
1620 object_class->finalize = empathy_streamed_media_window_finalize;
1622 param_spec = g_param_spec_object ("handler",
1623 "handler", "The call handler",
1624 EMPATHY_TYPE_STREAMED_MEDIA_HANDLER,
1625 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1626 g_object_class_install_property (object_class,
1627 PROP_STREAMED_MEDIA_HANDLER, param_spec);
1631 empathy_streamed_media_window_video_stream_changed_cb (EmpathyTpStreamedMedia *call,
1632 GParamSpec *property, EmpathyStreamedMediaWindow *self)
1634 DEBUG ("video stream changed");
1635 empathy_streamed_media_window_update_avatars_visibility (call, self);
1639 empathy_streamed_media_window_dispose (GObject *object)
1641 EmpathyTpStreamedMedia *call;
1642 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1643 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1645 if (priv->dispose_has_run)
1648 priv->dispose_has_run = TRUE;
1650 g_object_get (priv->handler, "tp-call", &call, NULL);
1654 g_object_unref (call);
1657 if (priv->handler != NULL)
1659 empathy_streamed_media_handler_stop_call (priv->handler);
1660 g_object_unref (priv->handler);
1662 priv->handler = NULL;
1664 if (priv->bus_message_source_id != 0)
1666 g_source_remove (priv->bus_message_source_id);
1667 priv->bus_message_source_id = 0;
1670 if (priv->pipeline != NULL)
1671 g_object_unref (priv->pipeline);
1672 priv->pipeline = NULL;
1674 if (priv->video_input != NULL)
1675 g_object_unref (priv->video_input);
1676 priv->video_input = NULL;
1678 if (priv->audio_input != NULL)
1679 g_object_unref (priv->audio_input);
1680 priv->audio_input = NULL;
1682 if (priv->video_tee != NULL)
1683 g_object_unref (priv->video_tee);
1684 priv->video_tee = NULL;
1686 if (priv->fsnotifier != NULL)
1687 g_object_unref (priv->fsnotifier);
1688 priv->fsnotifier = NULL;
1690 if (priv->timer_id != 0)
1691 g_source_remove (priv->timer_id);
1694 if (priv->ui_manager != NULL)
1695 g_object_unref (priv->ui_manager);
1696 priv->ui_manager = NULL;
1698 if (priv->fullscreen != NULL)
1699 g_object_unref (priv->fullscreen);
1700 priv->fullscreen = NULL;
1702 if (priv->contact != NULL)
1704 g_signal_handlers_disconnect_by_func (priv->contact,
1705 contact_name_changed_cb, self);
1706 g_object_unref (priv->contact);
1707 priv->contact = NULL;
1710 tp_clear_object (&priv->sound_mgr);
1712 /* release any references held by the object here */
1713 if (G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose)
1714 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose (object);
1718 disconnect_video_output_motion_handler (EmpathyStreamedMediaWindow *self)
1720 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1722 if (priv->video_output_motion_handler_id != 0)
1724 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1725 priv->video_output_motion_handler_id);
1726 priv->video_output_motion_handler_id = 0;
1731 empathy_streamed_media_window_finalize (GObject *object)
1733 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1734 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1736 disconnect_video_output_motion_handler (self);
1738 /* free any data held directly by the object here */
1739 g_mutex_free (priv->lock);
1741 g_timer_destroy (priv->timer);
1743 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->finalize (object);
1747 EmpathyStreamedMediaWindow *
1748 empathy_streamed_media_window_new (EmpathyStreamedMediaHandler *handler)
1750 return EMPATHY_STREAMED_MEDIA_WINDOW (
1751 g_object_new (EMPATHY_TYPE_STREAMED_MEDIA_WINDOW, "handler", handler, NULL));
1755 empathy_streamed_media_window_conference_added_cb (EmpathyStreamedMediaHandler *handler,
1756 GstElement *conference, gpointer user_data)
1758 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1759 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1761 gst_bin_add (GST_BIN (priv->pipeline), conference);
1763 gst_element_set_state (conference, GST_STATE_PLAYING);
1767 empathy_streamed_media_window_request_resource_cb (EmpathyStreamedMediaHandler *handler,
1768 FsMediaType type, FsStreamDirection direction, gpointer user_data)
1770 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1771 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1773 if (type != FS_MEDIA_TYPE_VIDEO)
1776 if (direction == FS_DIRECTION_RECV)
1779 /* video and direction is send */
1780 return priv->video_input != NULL;
1784 empathy_streamed_media_window_reset_pipeline (EmpathyStreamedMediaWindow *self)
1786 GstStateChangeReturn state_change_return;
1787 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1789 if (priv->pipeline == NULL)
1792 if (priv->bus_message_source_id != 0)
1794 g_source_remove (priv->bus_message_source_id);
1795 priv->bus_message_source_id = 0;
1798 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1800 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1801 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1803 if (priv->pipeline != NULL)
1804 g_object_unref (priv->pipeline);
1805 priv->pipeline = NULL;
1807 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1808 empathy_streamed_media_window_mic_volume_changed_cb, self);
1810 if (priv->video_tee != NULL)
1811 g_object_unref (priv->video_tee);
1812 priv->video_tee = NULL;
1814 if (priv->video_preview != NULL)
1815 gtk_widget_destroy (priv->video_preview);
1816 priv->video_preview = NULL;
1818 priv->funnel = NULL;
1820 create_pipeline (self);
1821 /* Call will be started when user will hit the 'redial' button */
1822 priv->start_call_when_playing = FALSE;
1823 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1829 g_message ("Error: could not destroy pipeline. Closing call window");
1830 gtk_widget_destroy (GTK_WIDGET (self));
1837 reset_details_pane (EmpathyStreamedMediaWindow *self)
1839 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1841 /* translators: encoding video codec is unknown */
1842 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label),
1843 C_("codec", "Unknown"));
1844 /* translators: encoding audio codec is unknown */
1845 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label),
1846 C_("codec", "Unknown"));
1847 /* translators: decoding video codec is unknown */
1848 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label),
1849 C_("codec", "Unknown"));
1850 /* translators: decoding audio codec is unknown */
1851 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label),
1852 C_("codec", "Unknown"));
1856 empathy_streamed_media_window_disconnected (EmpathyStreamedMediaWindow *self,
1859 gboolean could_disconnect = FALSE;
1860 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1861 gboolean could_reset_pipeline;
1863 /* Leave full screen mode if needed */
1864 gtk_window_unfullscreen (GTK_WINDOW (self));
1866 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1868 could_reset_pipeline = empathy_streamed_media_window_reset_pipeline (self);
1870 if (priv->call_state == CONNECTING)
1871 empathy_sound_manager_stop (priv->sound_mgr,
1872 EMPATHY_SOUND_PHONE_OUTGOING);
1874 if (priv->call_state != REDIALING)
1875 priv->call_state = DISCONNECTED;
1877 if (could_reset_pipeline)
1879 g_mutex_lock (priv->lock);
1881 g_timer_stop (priv->timer);
1883 if (priv->timer_id != 0)
1884 g_source_remove (priv->timer_id);
1887 g_mutex_unlock (priv->lock);
1890 /* We are about to destroy the window, no need to update it or create
1891 * a video preview */
1894 empathy_streamed_media_window_status_message (self, _("Disconnected"));
1896 gtk_action_set_sensitive (priv->redial, TRUE);
1897 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1899 /* Unsensitive the camera and mic button */
1900 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1901 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
1902 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1904 /* Be sure that the mic button is enabled */
1905 gtk_toggle_tool_button_set_active (
1906 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1908 if (priv->camera_state == CAMERA_STATE_ON)
1910 /* Enable the 'preview' button as we are not sending atm. */
1911 gtk_toggle_tool_button_set_active (
1912 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_preview), TRUE);
1914 else if (priv->camera_state == CAMERA_STATE_PREVIEW)
1916 /* Restart the preview with the new pipeline. */
1917 display_video_preview (self, TRUE);
1920 gtk_progress_bar_set_fraction (
1921 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1923 /* destroy the video output; it will be recreated when we'll redial */
1924 disconnect_video_output_motion_handler (self);
1925 gtk_widget_destroy (priv->video_output);
1926 priv->video_output = NULL;
1928 gtk_widget_show (priv->remote_user_avatar_widget);
1930 reset_details_pane (self);
1932 priv->sending_video = FALSE;
1933 priv->call_started = FALSE;
1935 could_disconnect = TRUE;
1937 /* TODO: display the self avatar of the preview (depends if the "Always
1938 * Show Video Preview" is enabled or not) */
1941 return could_disconnect;
1946 empathy_streamed_media_window_channel_closed_cb (EmpathyStreamedMediaHandler *handler,
1949 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1950 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1952 if (empathy_streamed_media_window_disconnected (self, TRUE) &&
1953 priv->call_state == REDIALING)
1954 empathy_streamed_media_window_restart_call (self);
1959 empathy_streamed_media_window_channel_stream_closed_cb (EmpathyStreamedMediaHandler *handler,
1960 TfStream *stream, gpointer user_data)
1962 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1963 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1966 g_object_get (stream, "media-type", &media_type, NULL);
1969 * This assumes that there is only one video stream per channel...
1972 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
1974 if (priv->funnel != NULL)
1978 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1979 (priv->video_output));
1981 gst_element_set_state (output, GST_STATE_NULL);
1982 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1984 gst_bin_remove (GST_BIN (priv->pipeline), output);
1985 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1986 priv->funnel = NULL;
1989 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
1991 if (priv->audio_output != NULL)
1993 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1995 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1996 priv->audio_output = NULL;
2001 /* Called with global lock held */
2003 empathy_streamed_media_window_get_video_sink_pad (EmpathyStreamedMediaWindow *self)
2005 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2009 if (priv->funnel == NULL)
2011 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
2012 (priv->video_output));
2014 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2018 g_warning ("Could not create fsfunnel");
2022 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2024 gst_object_unref (priv->funnel);
2025 priv->funnel = NULL;
2026 g_warning ("Could not add funnel to pipeline");
2030 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2032 g_warning ("Could not add the video output widget to the pipeline");
2036 if (!gst_element_link (priv->funnel, output))
2038 g_warning ("Could not link output sink to funnel");
2039 goto error_output_added;
2042 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2044 g_warning ("Could not start video sink");
2045 goto error_output_added;
2048 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2050 g_warning ("Could not start funnel");
2051 goto error_output_added;
2055 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2058 g_warning ("Could not get request pad from funnel");
2065 gst_element_set_locked_state (priv->funnel, TRUE);
2066 gst_element_set_locked_state (output, TRUE);
2068 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2069 gst_element_set_state (output, GST_STATE_NULL);
2071 gst_bin_remove (GST_BIN (priv->pipeline), output);
2072 gst_element_set_locked_state (output, FALSE);
2076 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2077 priv->funnel = NULL;
2082 /* Called with global lock held */
2084 empathy_streamed_media_window_get_audio_sink_pad (EmpathyStreamedMediaWindow *self)
2086 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2088 GstPadTemplate *template;
2090 if (priv->audio_output == NULL)
2092 priv->audio_output = empathy_audio_sink_new ();
2094 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2096 g_warning ("Could not add audio sink to pipeline");
2097 g_object_unref (priv->audio_output);
2098 goto error_add_output;
2101 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2103 g_warning ("Could not start audio sink");
2108 template = gst_element_class_get_pad_template (
2109 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2111 pad = gst_element_request_pad (priv->audio_output,
2112 template, NULL, NULL);
2116 g_warning ("Could not get sink pad from sink");
2123 gst_element_set_locked_state (priv->audio_output, TRUE);
2124 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2125 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2126 priv->audio_output = NULL;
2134 empathy_streamed_media_window_update_timer (gpointer user_data)
2136 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2137 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2141 time_ = g_timer_elapsed (priv->timer, NULL);
2143 /* Translators: number of minutes:seconds the caller has been connected */
2144 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
2146 empathy_streamed_media_window_status_message (self, str);
2153 display_error (EmpathyStreamedMediaWindow *self,
2154 EmpathyTpStreamedMedia *call,
2158 const gchar *details)
2160 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2161 GtkWidget *info_bar;
2162 GtkWidget *content_area;
2169 /* Create info bar */
2170 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2173 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2175 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2177 /* hbox containing the image and the messages vbox */
2178 hbox = gtk_hbox_new (FALSE, 3);
2179 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2182 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2183 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2185 /* vbox containing the main message and the details expander */
2186 vbox = gtk_vbox_new (FALSE, 3);
2187 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2190 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2192 label = gtk_label_new (NULL);
2193 gtk_label_set_markup (GTK_LABEL (label), txt);
2194 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2195 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2198 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2201 if (details != NULL)
2203 GtkWidget *expander;
2205 expander = gtk_expander_new (_("Technical Details"));
2207 txt = g_strdup_printf ("<i>%s</i>", details);
2209 label = gtk_label_new (NULL);
2210 gtk_label_set_markup (GTK_LABEL (label), txt);
2211 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2212 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2215 gtk_container_add (GTK_CONTAINER (expander), label);
2216 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2219 g_signal_connect (info_bar, "response",
2220 G_CALLBACK (gtk_widget_destroy), NULL);
2222 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2223 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2224 gtk_widget_show_all (info_bar);
2228 media_stream_error_to_txt (EmpathyStreamedMediaWindow *self,
2229 EmpathyTpStreamedMedia *call,
2231 TpMediaStreamError error)
2233 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2240 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2242 return g_strdup_printf (
2243 _("%s's software does not understand any of the audio formats "
2244 "supported by your computer"),
2245 empathy_contact_get_alias (priv->contact));
2247 return g_strdup_printf (
2248 _("%s's software does not understand any of the video formats "
2249 "supported by your computer"),
2250 empathy_contact_get_alias (priv->contact));
2252 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2253 return g_strdup_printf (
2254 _("Can't establish a connection to %s. "
2255 "One of you might be on a network that does not allow "
2256 "direct connections."),
2257 empathy_contact_get_alias (priv->contact));
2259 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2260 return g_strdup (_("There was a failure on the network"));
2262 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2264 return g_strdup (_("The audio formats necessary for this call "
2265 "are not installed on your computer"));
2267 return g_strdup (_("The video formats necessary for this call "
2268 "are not installed on your computer"));
2270 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2271 cm = empathy_tp_streamed_media_get_connection_manager (call);
2273 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2274 "product=Telepathy&component=%s", cm);
2276 result = g_strdup_printf (
2277 _("Something unexpected happened in a Telepathy component. "
2278 "Please <a href=\"%s\">report this bug</a> and attach "
2279 "logs gathered from the 'Debug' window in the Help menu."), url);
2284 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2285 return g_strdup (_("There was a failure in the call engine"));
2287 case TP_MEDIA_STREAM_ERROR_EOS:
2288 return g_strdup (_("The end of the stream was reached"));
2290 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2297 empathy_streamed_media_window_stream_error (EmpathyStreamedMediaWindow *self,
2298 EmpathyTpStreamedMedia *call,
2307 desc = media_stream_error_to_txt (self, call, audio, code);
2310 /* No description, use the error message. That's not great as it's not
2311 * localized but it's better than nothing. */
2312 display_error (self, call, icon, title, msg, NULL);
2316 display_error (self, call, icon, title, desc, msg);
2322 empathy_streamed_media_window_audio_stream_error (EmpathyTpStreamedMedia *call,
2325 EmpathyStreamedMediaWindow *self)
2327 empathy_streamed_media_window_stream_error (self, call, TRUE, code, msg,
2328 "gnome-stock-mic", _("Can't establish audio stream"));
2332 empathy_streamed_media_window_video_stream_error (EmpathyTpStreamedMedia *call,
2335 EmpathyStreamedMediaWindow *self)
2337 empathy_streamed_media_window_stream_error (self, call, FALSE, code, msg,
2338 "camera-web", _("Can't establish video stream"));
2342 empathy_streamed_media_window_connected (gpointer user_data)
2344 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2345 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2346 EmpathyTpStreamedMedia *call;
2347 gboolean can_send_video;
2349 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2351 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2352 empathy_contact_can_voip_video (priv->contact);
2354 g_object_get (priv->handler, "tp-call", &call, NULL);
2356 tp_g_signal_connect_object (call, "notify::video-stream",
2357 G_CALLBACK (empathy_streamed_media_window_video_stream_changed_cb),
2360 if (empathy_tp_streamed_media_has_dtmf (call))
2361 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2363 if (priv->video_input == NULL)
2364 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
2366 priv->sending_video = can_send_video ?
2367 empathy_tp_streamed_media_is_sending_video (call) : FALSE;
2369 gtk_toggle_tool_button_set_active (
2370 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2371 priv->sending_video && priv->video_input != NULL);
2372 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2373 gtk_action_set_sensitive (priv->action_camera_on, can_send_video);
2375 gtk_action_set_sensitive (priv->redial, FALSE);
2376 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2378 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2380 empathy_streamed_media_window_update_avatars_visibility (call, self);
2382 g_object_unref (call);
2384 g_mutex_lock (priv->lock);
2386 priv->timer_id = g_timeout_add_seconds (1,
2387 empathy_streamed_media_window_update_timer, self);
2389 g_mutex_unlock (priv->lock);
2391 empathy_streamed_media_window_update_timer (self);
2393 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2399 /* Called from the streaming thread */
2401 empathy_streamed_media_window_src_added_cb (EmpathyStreamedMediaHandler *handler,
2402 GstPad *src, guint media_type, gpointer user_data)
2404 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2405 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2406 gboolean retval = FALSE;
2410 g_mutex_lock (priv->lock);
2412 if (priv->call_state != CONNECTED)
2414 g_timer_start (priv->timer);
2415 priv->timer_id = g_idle_add (empathy_streamed_media_window_connected, self);
2416 priv->call_state = CONNECTED;
2421 case TP_MEDIA_STREAM_TYPE_AUDIO:
2422 pad = empathy_streamed_media_window_get_audio_sink_pad (self);
2424 case TP_MEDIA_STREAM_TYPE_VIDEO:
2425 gtk_widget_hide (priv->remote_user_avatar_widget);
2426 gtk_widget_show (priv->video_output);
2427 pad = empathy_streamed_media_window_get_video_sink_pad (self);
2430 g_assert_not_reached ();
2436 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2437 g_warning ("Could not link %s sink pad",
2438 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2442 gst_object_unref (pad);
2446 /* If no sink could be linked, try to add fakesink to prevent the whole call
2451 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2453 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2455 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2456 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2457 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2459 gst_element_set_locked_state (fakesink, TRUE);
2460 gst_element_set_state (fakesink, GST_STATE_NULL);
2461 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2465 DEBUG ("Could not link real sink, linked fakesink instead");
2467 gst_object_unref (sinkpad);
2471 gst_object_unref (fakesink);
2476 g_mutex_unlock (priv->lock);
2482 empathy_streamed_media_window_sink_added_cb (EmpathyStreamedMediaHandler *handler,
2483 GstPad *sink, guint media_type, gpointer user_data)
2485 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2486 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2488 gboolean retval = FALSE;
2492 case TP_MEDIA_STREAM_TYPE_AUDIO:
2493 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2495 g_warning ("Could not add audio source to pipeline");
2499 pad = gst_element_get_static_pad (priv->audio_input, "src");
2502 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2503 g_warning ("Could not get source pad from audio source");
2507 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2509 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2510 g_warning ("Could not link audio source to farsight");
2514 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2516 g_warning ("Could not start audio source");
2517 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2518 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2524 case TP_MEDIA_STREAM_TYPE_VIDEO:
2525 if (priv->video_input != NULL)
2527 if (priv->video_tee != NULL)
2529 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2530 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2532 g_warning ("Could not link videp soure input pipeline");
2535 gst_object_unref (pad);
2542 g_assert_not_reached ();
2549 empathy_streamed_media_window_remove_video_input (EmpathyStreamedMediaWindow *self)
2551 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2552 GstElement *preview;
2554 disable_camera (self);
2556 DEBUG ("remove video input");
2557 preview = empathy_video_widget_get_element (
2558 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2560 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2561 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2562 gst_element_set_state (preview, GST_STATE_NULL);
2564 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2565 priv->video_tee, preview, NULL);
2567 g_object_unref (priv->video_input);
2568 priv->video_input = NULL;
2569 g_object_unref (priv->video_tee);
2570 priv->video_tee = NULL;
2571 gtk_widget_destroy (priv->video_preview);
2572 priv->video_preview = NULL;
2574 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2575 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
2576 gtk_widget_set_sensitive (priv->tool_button_camera_preview, FALSE);
2580 start_call (EmpathyStreamedMediaWindow *self)
2582 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2584 priv->call_started = TRUE;
2585 empathy_streamed_media_handler_start_call (priv->handler,
2586 empathy_get_current_action_time ());
2588 if (empathy_streamed_media_handler_has_initial_video (priv->handler))
2590 /* Enable 'send video' buttons and display the preview */
2591 gtk_toggle_tool_button_set_active (
2592 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2597 empathy_streamed_media_window_bus_message (GstBus *bus, GstMessage *message,
2600 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2601 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2604 empathy_streamed_media_handler_bus_message (priv->handler, bus, message);
2606 switch (GST_MESSAGE_TYPE (message))
2608 case GST_MESSAGE_STATE_CHANGED:
2609 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2611 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2612 if (newstate == GST_STATE_PAUSED)
2613 empathy_streamed_media_window_setup_video_input (self);
2615 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2616 !priv->call_started)
2618 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2619 if (newstate == GST_STATE_PAUSED)
2621 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2622 priv->pipeline_playing = TRUE;
2624 if (priv->start_call_when_playing)
2629 case GST_MESSAGE_ERROR:
2631 GError *error = NULL;
2632 GstElement *gst_error;
2635 gst_message_parse_error (message, &error, &debug);
2636 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2638 g_message ("Element error: %s -- %s\n", error->message, debug);
2640 if (g_str_has_prefix (gst_element_get_name (gst_error),
2641 VIDEO_INPUT_ERROR_PREFIX))
2643 /* Remove the video input and continue */
2644 if (priv->video_input != NULL)
2645 empathy_streamed_media_window_remove_video_input (self);
2646 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2650 empathy_streamed_media_window_disconnected (self, TRUE);
2652 g_error_free (error);
2655 case GST_MESSAGE_UNKNOWN:
2656 case GST_MESSAGE_EOS:
2657 case GST_MESSAGE_WARNING:
2658 case GST_MESSAGE_INFO:
2659 case GST_MESSAGE_TAG:
2660 case GST_MESSAGE_BUFFERING:
2661 case GST_MESSAGE_STATE_DIRTY:
2662 case GST_MESSAGE_STEP_DONE:
2663 case GST_MESSAGE_CLOCK_PROVIDE:
2664 case GST_MESSAGE_CLOCK_LOST:
2665 case GST_MESSAGE_NEW_CLOCK:
2666 case GST_MESSAGE_STRUCTURE_CHANGE:
2667 case GST_MESSAGE_STREAM_STATUS:
2668 case GST_MESSAGE_APPLICATION:
2669 case GST_MESSAGE_ELEMENT:
2670 case GST_MESSAGE_SEGMENT_START:
2671 case GST_MESSAGE_SEGMENT_DONE:
2672 case GST_MESSAGE_DURATION:
2673 case GST_MESSAGE_ANY:
2682 empathy_streamed_media_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
2683 EmpathyStreamedMediaWindow *window)
2685 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2687 if (empathy_tp_streamed_media_is_receiving_video (call))
2689 gtk_widget_hide (priv->remote_user_avatar_widget);
2690 gtk_widget_show (priv->video_output);
2694 gtk_widget_hide (priv->video_output);
2695 gtk_widget_show (priv->remote_user_avatar_widget);
2700 call_handler_notify_tp_streamed_media_cb (EmpathyStreamedMediaHandler *handler,
2702 EmpathyStreamedMediaWindow *self)
2704 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2705 EmpathyTpStreamedMedia *call;
2707 g_object_get (priv->handler, "tp-call", &call, NULL);
2711 tp_g_signal_connect_object (call, "audio-stream-error",
2712 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), self, 0);
2713 tp_g_signal_connect_object (call, "video-stream-error",
2714 G_CALLBACK (empathy_streamed_media_window_video_stream_error), self, 0);
2716 g_object_unref (call);
2720 empathy_streamed_media_window_realized_cb (GtkWidget *widget, EmpathyStreamedMediaWindow *window)
2722 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2723 EmpathyTpStreamedMedia *call;
2725 g_signal_connect (priv->handler, "conference-added",
2726 G_CALLBACK (empathy_streamed_media_window_conference_added_cb), window);
2727 g_signal_connect (priv->handler, "request-resource",
2728 G_CALLBACK (empathy_streamed_media_window_request_resource_cb), window);
2729 g_signal_connect (priv->handler, "closed",
2730 G_CALLBACK (empathy_streamed_media_window_channel_closed_cb), window);
2731 g_signal_connect (priv->handler, "src-pad-added",
2732 G_CALLBACK (empathy_streamed_media_window_src_added_cb), window);
2733 g_signal_connect (priv->handler, "sink-pad-added",
2734 G_CALLBACK (empathy_streamed_media_window_sink_added_cb), window);
2735 g_signal_connect (priv->handler, "stream-closed",
2736 G_CALLBACK (empathy_streamed_media_window_channel_stream_closed_cb), window);
2738 g_object_get (priv->handler, "tp-call", &call, NULL);
2741 tp_g_signal_connect_object (call, "audio-stream-error",
2742 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), window,
2744 tp_g_signal_connect_object (call, "video-stream-error",
2745 G_CALLBACK (empathy_streamed_media_window_video_stream_error), window,
2748 g_object_unref (call);
2752 /* tp-call doesn't exist yet, we'll connect signals once it has been
2754 g_signal_connect (priv->handler, "notify::tp-call",
2755 G_CALLBACK (call_handler_notify_tp_streamed_media_cb), window);
2758 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2762 empathy_streamed_media_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2763 EmpathyStreamedMediaWindow *window)
2765 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2767 if (priv->pipeline != NULL)
2769 if (priv->bus_message_source_id != 0)
2771 g_source_remove (priv->bus_message_source_id);
2772 priv->bus_message_source_id = 0;
2775 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2778 if (priv->call_state == CONNECTING)
2779 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2785 show_controls (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2788 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2790 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2795 gtk_widget_hide (priv->sidebar);
2796 gtk_widget_hide (menu);
2797 gtk_widget_hide (priv->vbox);
2798 gtk_widget_hide (priv->statusbar);
2799 gtk_widget_hide (priv->toolbar);
2803 if (priv->sidebar_was_visible_before_fs)
2804 gtk_widget_show (priv->sidebar);
2806 gtk_widget_show (menu);
2807 gtk_widget_show (priv->vbox);
2808 gtk_widget_show (priv->statusbar);
2809 gtk_widget_show (priv->toolbar);
2811 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2812 priv->original_height_before_fs);
2817 show_borders (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2819 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2821 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2822 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2823 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2824 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2826 if (priv->video_output != NULL)
2828 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2829 priv->video_output, TRUE, TRUE,
2830 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2834 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2835 priv->vbox, TRUE, TRUE,
2836 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2841 empathy_streamed_media_window_state_event_cb (GtkWidget *widget,
2842 GdkEventWindowState *event, EmpathyStreamedMediaWindow *window)
2844 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2846 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2847 gboolean set_fullscreen = event->new_window_state &
2848 GDK_WINDOW_STATE_FULLSCREEN;
2852 gboolean sidebar_was_visible;
2853 GtkAllocation allocation;
2854 gint original_width, original_height;
2856 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2857 original_width = allocation.width;
2858 original_height = allocation.height;
2860 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2862 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2863 priv->original_width_before_fs = original_width;
2864 priv->original_height_before_fs = original_height;
2866 if (priv->video_output_motion_handler_id == 0 &&
2867 priv->video_output != NULL)
2869 priv->video_output_motion_handler_id = g_signal_connect (
2870 G_OBJECT (priv->video_output), "motion-notify-event",
2871 G_CALLBACK (empathy_streamed_media_window_video_output_motion_notify),
2877 disconnect_video_output_motion_handler (window);
2880 empathy_streamed_media_window_fullscreen_set_fullscreen (priv->fullscreen,
2882 show_controls (window, set_fullscreen);
2883 show_borders (window, set_fullscreen);
2884 gtk_action_set_stock_id (priv->menu_fullscreen,
2885 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2886 priv->is_fullscreen = set_fullscreen;
2893 empathy_streamed_media_window_sidebar_toggled_cb (GtkToggleButton *toggle,
2894 EmpathyStreamedMediaWindow *window)
2896 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2898 int w, h, handle_size;
2899 GtkAllocation allocation, sidebar_allocation;
2901 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2902 w = allocation.width;
2903 h = allocation.height;
2905 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2907 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
2908 if (gtk_toggle_button_get_active (toggle))
2910 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
2911 gtk_widget_show (priv->sidebar);
2912 w += sidebar_allocation.width + handle_size;
2916 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2917 w -= sidebar_allocation.width + handle_size;
2918 gtk_widget_hide (priv->sidebar);
2921 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
2924 gtk_window_resize (GTK_WINDOW (window), w, h);
2928 empathy_streamed_media_window_set_send_video (EmpathyStreamedMediaWindow *window,
2931 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2932 EmpathyTpStreamedMedia *call;
2934 priv->sending_video = (state == CAMERA_STATE_ON);
2936 if (state == CAMERA_STATE_PREVIEW ||
2937 state == CAMERA_STATE_ON)
2939 /* When we start sending video, we want to show the video preview by
2941 display_video_preview (window, TRUE);
2945 display_video_preview (window, FALSE);
2948 if (priv->call_state != CONNECTED)
2951 g_object_get (priv->handler, "tp-call", &call, NULL);
2952 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2953 empathy_tp_streamed_media_request_video_stream_direction (call, priv->sending_video);
2954 g_object_unref (call);
2958 empathy_streamed_media_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2959 EmpathyStreamedMediaWindow *window)
2961 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2964 active = (gtk_toggle_tool_button_get_active (toggle));
2968 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2970 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
2974 /* TODO, Instead of setting the input volume to 0 we should probably
2975 * stop sending but this would cause the audio call to drop if both
2976 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2977 * in the future. GNOME #574574
2979 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2981 gtk_adjustment_set_value (priv->audio_input_adj, 0);
2986 empathy_streamed_media_window_sidebar_hidden_cb (EvSidebar *sidebar,
2987 EmpathyStreamedMediaWindow *window)
2989 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2991 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2996 empathy_streamed_media_window_sidebar_shown_cb (EvSidebar *sidebar,
2997 EmpathyStreamedMediaWindow *window)
2999 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3001 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
3006 empathy_streamed_media_window_hangup_cb (gpointer object,
3007 EmpathyStreamedMediaWindow *window)
3009 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3011 empathy_streamed_media_handler_stop_call (priv->handler);
3013 if (empathy_streamed_media_window_disconnected (window, FALSE))
3014 gtk_widget_destroy (GTK_WIDGET (window));
3018 empathy_streamed_media_window_restart_call (EmpathyStreamedMediaWindow *window)
3020 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3022 /* Remove error info bars */
3023 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3024 (GtkCallback) gtk_widget_destroy, NULL);
3026 create_video_output_widget (window);
3028 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3029 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), window);
3031 /* While the call was disconnected, the input volume might have changed.
3032 * However, since the audio_input source was destroyed, its volume has not
3033 * been updated during that time. That's why we manually update it here */
3034 empathy_streamed_media_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3036 priv->outgoing = TRUE;
3037 empathy_streamed_media_window_set_state_connecting (window);
3039 if (priv->pipeline_playing)
3040 start_call (window);
3042 /* call will be started when the pipeline is ready */
3043 priv->start_call_when_playing = TRUE;
3046 empathy_streamed_media_window_setup_avatars (window, priv->handler);
3048 gtk_action_set_sensitive (priv->redial, FALSE);
3049 gtk_widget_set_sensitive (priv->redial_button, FALSE);
3053 empathy_streamed_media_window_redial_cb (gpointer object,
3054 EmpathyStreamedMediaWindow *window)
3056 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3058 if (priv->call_state == CONNECTED)
3059 priv->call_state = REDIALING;
3061 empathy_streamed_media_handler_stop_call (priv->handler);
3063 if (priv->call_state != CONNECTED)
3064 empathy_streamed_media_window_restart_call (window);
3068 empathy_streamed_media_window_fullscreen_cb (gpointer object,
3069 EmpathyStreamedMediaWindow *window)
3071 empathy_streamed_media_window_fullscreen_toggle (window);
3075 empathy_streamed_media_window_fullscreen_toggle (EmpathyStreamedMediaWindow *window)
3077 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3079 if (priv->is_fullscreen)
3080 gtk_window_unfullscreen (GTK_WINDOW (window));
3082 gtk_window_fullscreen (GTK_WINDOW (window));
3086 empathy_streamed_media_window_video_button_press_cb (GtkWidget *video_output,
3087 GdkEventButton *event, EmpathyStreamedMediaWindow *window)
3089 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3091 empathy_streamed_media_window_video_menu_popup (window, event->button);
3099 empathy_streamed_media_window_key_press_cb (GtkWidget *video_output,
3100 GdkEventKey *event, EmpathyStreamedMediaWindow *window)
3102 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3104 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3106 /* Since we are in fullscreen mode, toggling will bring us back to
3108 empathy_streamed_media_window_fullscreen_toggle (window);
3116 empathy_streamed_media_window_video_output_motion_notify (GtkWidget *widget,
3117 GdkEventMotion *event, EmpathyStreamedMediaWindow *window)
3119 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3121 if (priv->is_fullscreen)
3123 empathy_streamed_media_window_fullscreen_show_popup (priv->fullscreen);
3130 empathy_streamed_media_window_video_menu_popup (EmpathyStreamedMediaWindow *window,
3134 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3136 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3138 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3139 button, gtk_get_current_event_time ());
3140 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3144 empathy_streamed_media_window_status_message (EmpathyStreamedMediaWindow *window,
3147 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3149 if (priv->context_id == 0)
3151 priv->context_id = gtk_statusbar_get_context_id (
3152 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
3156 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
3159 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
3164 empathy_streamed_media_window_volume_changed_cb (GtkScaleButton *button,
3165 gdouble value, EmpathyStreamedMediaWindow *window)
3167 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3169 if (priv->audio_output == NULL)
3172 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3176 /* block all the signals related to camera control widgets. This is useful
3177 * when we are manually updating the UI and so don't want to fire the
3180 block_camera_control_signals (EmpathyStreamedMediaWindow *self)
3182 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3184 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
3185 tool_button_camera_off_toggled_cb, self);
3186 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
3187 tool_button_camera_preview_toggled_cb, self);
3188 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
3189 tool_button_camera_on_toggled_cb, self);
3190 g_signal_handlers_block_by_func (priv->action_camera_on,
3191 action_camera_change_cb, self);
3195 unblock_camera_control_signals (EmpathyStreamedMediaWindow *self)
3197 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3199 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
3200 tool_button_camera_off_toggled_cb, self);
3201 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
3202 tool_button_camera_preview_toggled_cb, self);
3203 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
3204 tool_button_camera_on_toggled_cb, self);
3205 g_signal_handlers_unblock_by_func (priv->action_camera_on,
3206 action_camera_change_cb, self);