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
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <telepathy-glib/util.h>
35 #include <telepathy-farstream/telepathy-farstream.h>
37 #include <farstream/fs-element-added-notifier.h>
38 #include <farstream/fs-utils.h>
40 #include <libempathy/empathy-tp-contact-factory.h>
41 #include <libempathy/empathy-utils.h>
42 #include <libempathy-gtk/empathy-avatar-image.h>
43 #include <libempathy-gtk/empathy-dialpad-widget.h>
44 #include <libempathy-gtk/empathy-ui-utils.h>
45 #include <libempathy-gtk/empathy-sound-manager.h>
46 #include <libempathy-gtk/empathy-geometry.h>
47 #include <libempathy-gtk/empathy-images.h>
49 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
50 #include <libempathy/empathy-debug.h>
52 #include "empathy-streamed-media-window.h"
53 #include "empathy-streamed-media-window-fullscreen.h"
54 #include "empathy-video-widget.h"
55 #include "empathy-audio-src.h"
56 #include "empathy-audio-sink.h"
57 #include "empathy-video-src.h"
58 #include "ev-sidebar.h"
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(EmpathyStreamedMediaWindow, empathy_streamed_media_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 _EmpathyStreamedMediaWindowPriv EmpathyStreamedMediaWindowPriv;
111 struct _EmpathyStreamedMediaWindowPriv
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;
193 FsElementAddedNotifier *fsnotifier;
200 GtkWidget *video_contrast;
201 GtkWidget *video_brightness;
202 GtkWidget *video_gamma;
205 gboolean call_started;
206 gboolean sending_video;
207 CameraState camera_state;
209 EmpathyStreamedMediaWindowFullscreen *fullscreen;
210 gboolean is_fullscreen;
212 /* Those fields represent the state of the window before it actually was in
214 gboolean sidebar_was_visible_before_fs;
215 gint original_width_before_fs;
216 gint original_height_before_fs;
218 /* TRUE if the call should be started when the pipeline is playing */
219 gboolean start_call_when_playing;
220 /* TRUE if we requested to set the pipeline in the playing state */
221 gboolean pipeline_playing;
223 EmpathySoundManager *sound_mgr;
226 #define GET_PRIV(o) \
227 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_STREAMED_MEDIA_WINDOW, \
228 EmpathyStreamedMediaWindowPriv))
230 static void empathy_streamed_media_window_realized_cb (GtkWidget *widget,
231 EmpathyStreamedMediaWindow *window);
233 static gboolean empathy_streamed_media_window_delete_cb (GtkWidget *widget,
234 GdkEvent *event, EmpathyStreamedMediaWindow *window);
236 static gboolean empathy_streamed_media_window_state_event_cb (GtkWidget *widget,
237 GdkEventWindowState *event, EmpathyStreamedMediaWindow *window);
239 static void empathy_streamed_media_window_sidebar_toggled_cb (GtkToggleButton *toggle,
240 EmpathyStreamedMediaWindow *window);
242 static void empathy_streamed_media_window_set_send_video (EmpathyStreamedMediaWindow *window,
245 static void empathy_streamed_media_window_mic_toggled_cb (
246 GtkToggleToolButton *toggle, EmpathyStreamedMediaWindow *window);
248 static void empathy_streamed_media_window_sidebar_hidden_cb (EvSidebar *sidebar,
249 EmpathyStreamedMediaWindow *window);
251 static void empathy_streamed_media_window_sidebar_shown_cb (EvSidebar *sidebar,
252 EmpathyStreamedMediaWindow *window);
254 static void empathy_streamed_media_window_hangup_cb (gpointer object,
255 EmpathyStreamedMediaWindow *window);
257 static void empathy_streamed_media_window_fullscreen_cb (gpointer object,
258 EmpathyStreamedMediaWindow *window);
260 static void empathy_streamed_media_window_fullscreen_toggle (EmpathyStreamedMediaWindow *window);
262 static gboolean empathy_streamed_media_window_video_button_press_cb (
263 GtkWidget *video_output, GdkEventButton *event, EmpathyStreamedMediaWindow *window);
265 static gboolean empathy_streamed_media_window_key_press_cb (GtkWidget *video_output,
266 GdkEventKey *event, EmpathyStreamedMediaWindow *window);
268 static gboolean empathy_streamed_media_window_video_output_motion_notify (
269 GtkWidget *widget, GdkEventMotion *event, EmpathyStreamedMediaWindow *window);
271 static void empathy_streamed_media_window_video_menu_popup (EmpathyStreamedMediaWindow *window,
274 static void empathy_streamed_media_window_redial_cb (gpointer object,
275 EmpathyStreamedMediaWindow *window);
277 static void empathy_streamed_media_window_restart_call (EmpathyStreamedMediaWindow *window);
279 static void empathy_streamed_media_window_status_message (EmpathyStreamedMediaWindow *window,
282 static void empathy_streamed_media_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
283 EmpathyStreamedMediaWindow *window);
285 static gboolean empathy_streamed_media_window_bus_message (GstBus *bus,
286 GstMessage *message, gpointer user_data);
289 empathy_streamed_media_window_volume_changed_cb (GtkScaleButton *button,
290 gdouble value, EmpathyStreamedMediaWindow *window);
292 static void block_camera_control_signals (EmpathyStreamedMediaWindow *self);
293 static void unblock_camera_control_signals (EmpathyStreamedMediaWindow *self);
296 empathy_streamed_media_window_setup_toolbar (EmpathyStreamedMediaWindow *self)
298 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
299 GtkToolItem *tool_item;
300 GtkWidget *camera_off_icon;
301 GdkPixbuf *pixbuf, *modded_pixbuf;
303 /* set the icon of the 'camera off' button by greying off the webcam icon */
304 pixbuf = empathy_pixbuf_from_icon_name ("camera-web",
305 GTK_ICON_SIZE_SMALL_TOOLBAR);
307 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
308 gdk_pixbuf_get_width (pixbuf),
309 gdk_pixbuf_get_height (pixbuf));
311 gdk_pixbuf_saturate_and_pixelate (pixbuf, modded_pixbuf, 1.0, TRUE);
312 g_object_unref (pixbuf);
314 camera_off_icon = gtk_image_new_from_pixbuf (modded_pixbuf);
315 g_object_unref (modded_pixbuf);
316 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (
317 priv->tool_button_camera_off), camera_off_icon);
319 /* Add an empty expanded GtkToolItem so the volume button is at the end of
321 tool_item = gtk_tool_item_new ();
322 gtk_tool_item_set_expand (tool_item, TRUE);
323 gtk_widget_show (GTK_WIDGET (tool_item));
324 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
326 priv->volume_button = gtk_volume_button_new ();
327 /* FIXME listen to the audiosinks signals and update the button according to
328 * that, for now starting out at 1.0 and assuming only the app changes the
330 gtk_scale_button_set_value (GTK_SCALE_BUTTON (priv->volume_button), 1.0);
331 g_signal_connect (G_OBJECT (priv->volume_button), "value-changed",
332 G_CALLBACK (empathy_streamed_media_window_volume_changed_cb), self);
334 tool_item = gtk_tool_item_new ();
335 gtk_container_add (GTK_CONTAINER (tool_item), priv->volume_button);
336 gtk_widget_show_all (GTK_WIDGET (tool_item));
337 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
341 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
343 EmpathyStreamedMediaWindow *window)
345 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
346 EmpathyTpStreamedMedia *call;
348 g_object_get (priv->handler, "tp-call", &call, NULL);
350 empathy_tp_streamed_media_start_tone (call, event);
352 g_object_unref (call);
356 dtmf_stop_tone_cb (EmpathyDialpadWidget *self,
358 EmpathyStreamedMediaWindow *window)
360 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
361 EmpathyTpStreamedMedia *call;
363 g_object_get (priv->handler, "tp-call", &call, NULL);
365 empathy_tp_streamed_media_stop_tone (call);
367 g_object_unref (call);
371 empathy_streamed_media_window_create_video_input_add_slider (EmpathyStreamedMediaWindow *self,
372 gchar *label_text, GtkWidget *bin)
374 GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
375 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
376 GtkWidget *label = gtk_label_new (label_text);
378 gtk_widget_set_sensitive (scale, FALSE);
380 gtk_container_add (GTK_CONTAINER (bin), vbox);
382 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
383 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
384 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
390 empathy_streamed_media_window_video_contrast_changed_cb (GtkAdjustment *adj,
391 EmpathyStreamedMediaWindow *self)
394 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
396 empathy_video_src_set_channel (priv->video_input,
397 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
401 empathy_streamed_media_window_video_brightness_changed_cb (GtkAdjustment *adj,
402 EmpathyStreamedMediaWindow *self)
405 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
407 empathy_video_src_set_channel (priv->video_input,
408 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
412 empathy_streamed_media_window_video_gamma_changed_cb (GtkAdjustment *adj,
413 EmpathyStreamedMediaWindow *self)
416 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
418 empathy_video_src_set_channel (priv->video_input,
419 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
424 empathy_streamed_media_window_create_video_input (EmpathyStreamedMediaWindow *self)
426 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
429 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
430 gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
432 priv->video_contrast = empathy_streamed_media_window_create_video_input_add_slider (
433 self, _("Contrast"), hbox);
435 priv->video_brightness = empathy_streamed_media_window_create_video_input_add_slider (
436 self, _("Brightness"), hbox);
438 priv->video_gamma = empathy_streamed_media_window_create_video_input_add_slider (
439 self, _("Gamma"), hbox);
445 empathy_streamed_media_window_setup_video_input (EmpathyStreamedMediaWindow *self)
447 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
451 supported = empathy_video_src_get_supported_channels (priv->video_input);
453 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
455 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
457 gtk_adjustment_set_value (adj,
458 empathy_video_src_get_channel (priv->video_input,
459 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
461 g_signal_connect (G_OBJECT (adj), "value-changed",
462 G_CALLBACK (empathy_streamed_media_window_video_contrast_changed_cb), self);
464 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
467 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
469 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
471 gtk_adjustment_set_value (adj,
472 empathy_video_src_get_channel (priv->video_input,
473 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
475 g_signal_connect (G_OBJECT (adj), "value-changed",
476 G_CALLBACK (empathy_streamed_media_window_video_brightness_changed_cb), self);
477 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
480 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
482 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
484 gtk_adjustment_set_value (adj,
485 empathy_video_src_get_channel (priv->video_input,
486 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
488 g_signal_connect (G_OBJECT (adj), "value-changed",
489 G_CALLBACK (empathy_streamed_media_window_video_gamma_changed_cb), self);
490 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
495 empathy_streamed_media_window_mic_volume_changed_cb (GtkAdjustment *adj,
496 EmpathyStreamedMediaWindow *self)
498 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
501 volume = gtk_adjustment_get_value (adj)/100.0;
503 /* Don't store the volume because of muting */
504 if (volume > 0 || gtk_toggle_tool_button_get_active (
505 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
506 priv->volume = volume;
508 /* Ensure that the toggle button is active if the volume is > 0 and inactive
509 * if it's smaller than 0 */
510 if ((volume > 0) != gtk_toggle_tool_button_get_active (
511 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
512 gtk_toggle_tool_button_set_active (
513 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
515 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
520 empathy_streamed_media_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
521 gdouble level, EmpathyStreamedMediaWindow *window)
524 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
526 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
527 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
532 empathy_streamed_media_window_create_audio_input (EmpathyStreamedMediaWindow *self)
534 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
535 GtkWidget *hbox, *vbox, *label;
537 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
538 gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
540 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
541 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
543 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
544 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
545 label = gtk_label_new (_("Volume"));
547 priv->audio_input_adj = gtk_range_get_adjustment (
548 GTK_RANGE (priv->volume_scale));
549 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
550 (priv->audio_input));
551 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
553 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
554 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), self);
556 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
557 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
559 priv->volume_progress_bar = gtk_progress_bar_new ();
561 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
562 GTK_ORIENTATION_VERTICAL);
564 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
567 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
574 create_video_output_widget (EmpathyStreamedMediaWindow *self)
576 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
579 g_assert (priv->video_output == NULL);
580 g_assert (priv->pipeline != NULL);
582 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
583 priv->video_output = empathy_video_widget_new (bus);
585 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
586 priv->video_output, TRUE, TRUE, 0);
588 gtk_widget_add_events (priv->video_output,
589 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
590 g_signal_connect (G_OBJECT (priv->video_output), "button-press-event",
591 G_CALLBACK (empathy_streamed_media_window_video_button_press_cb), self);
593 g_object_unref (bus);
597 create_video_input (EmpathyStreamedMediaWindow *self)
599 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
601 g_assert (priv->video_input == NULL);
602 priv->video_input = empathy_video_src_new ();
603 gst_object_ref (priv->video_input);
604 gst_object_sink (priv->video_input);
608 create_audio_input (EmpathyStreamedMediaWindow *self)
610 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
612 g_assert (priv->audio_input == NULL);
613 priv->audio_input = empathy_audio_src_new ();
614 gst_object_ref (priv->audio_input);
615 gst_object_sink (priv->audio_input);
617 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
618 G_CALLBACK (empathy_streamed_media_window_audio_input_level_changed_cb),
623 add_video_preview_to_pipeline (EmpathyStreamedMediaWindow *self)
625 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
628 g_assert (priv->video_preview != NULL);
629 g_assert (priv->pipeline != NULL);
630 g_assert (priv->video_input != NULL);
631 g_assert (priv->video_tee != NULL);
633 preview = empathy_video_widget_get_element (
634 EMPATHY_VIDEO_WIDGET (priv->video_preview));
636 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
638 g_warning ("Could not add video input to pipeline");
642 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee))
644 g_warning ("Could not add video tee to pipeline");
648 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
650 g_warning ("Could not add video preview to pipeline");
654 if (!gst_element_link (priv->video_input, priv->video_tee))
656 g_warning ("Could not link video input to video tee");
660 if (!gst_element_link (priv->video_tee, preview))
662 g_warning ("Could not link video tee to video preview");
668 create_video_preview (EmpathyStreamedMediaWindow *self)
670 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
673 g_assert (priv->video_preview == NULL);
674 g_assert (priv->video_tee == NULL);
676 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
678 priv->video_preview = empathy_video_widget_new_with_size (bus,
679 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
680 g_object_set (priv->video_preview,
686 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
687 priv->video_preview, TRUE, TRUE, 0);
689 priv->video_tee = gst_element_factory_make ("tee", NULL);
690 gst_object_ref (priv->video_tee);
691 gst_object_sink (priv->video_tee);
693 g_object_unref (bus);
697 play_camera (EmpathyStreamedMediaWindow *window,
700 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
704 if (priv->video_preview == NULL)
706 create_video_preview (window);
707 add_video_preview_to_pipeline (window);
711 state = GST_STATE_PLAYING;
713 state = GST_STATE_NULL;
715 preview = empathy_video_widget_get_element (
716 EMPATHY_VIDEO_WIDGET (priv->video_preview));
718 gst_element_set_state (preview, state);
719 gst_element_set_state (priv->video_input, state);
720 gst_element_set_state (priv->video_tee, state);
724 display_video_preview (EmpathyStreamedMediaWindow *self,
727 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
731 /* Display the preview and hide the self avatar */
732 DEBUG ("Show video preview");
734 play_camera (self, TRUE);
735 gtk_widget_show (priv->video_preview);
736 gtk_widget_hide (priv->self_user_avatar_widget);
740 /* Display the self avatar and hide the preview */
741 DEBUG ("Show self avatar");
743 if (priv->video_preview != NULL)
745 gtk_widget_hide (priv->video_preview);
746 play_camera (self, FALSE);
748 gtk_widget_show (priv->self_user_avatar_widget);
753 empathy_streamed_media_window_set_state_connecting (EmpathyStreamedMediaWindow *window)
755 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
757 empathy_streamed_media_window_status_message (window, _("Connecting…"));
758 priv->call_state = CONNECTING;
761 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
762 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
766 disable_camera (EmpathyStreamedMediaWindow *self)
768 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
770 if (priv->camera_state == CAMERA_STATE_OFF)
773 DEBUG ("Disable camera");
775 display_video_preview (self, FALSE);
777 if (priv->camera_state == CAMERA_STATE_ON)
778 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
780 block_camera_control_signals (self);
781 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
782 priv->tool_button_camera_on), FALSE);
783 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
784 priv->tool_button_camera_preview), FALSE);
786 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
787 priv->tool_button_camera_off), TRUE);
788 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
790 unblock_camera_control_signals (self);
792 priv->camera_state = CAMERA_STATE_OFF;
796 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
797 EmpathyStreamedMediaWindow *self)
799 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
801 if (!gtk_toggle_tool_button_get_active (toggle))
803 if (priv->camera_state == CAMERA_STATE_OFF)
805 /* We can't change the state by disabling the button */
806 block_camera_control_signals (self);
807 gtk_toggle_tool_button_set_active (toggle, TRUE);
808 unblock_camera_control_signals (self);
814 disable_camera (self);
818 enable_preview (EmpathyStreamedMediaWindow *self)
820 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
822 if (priv->camera_state == CAMERA_STATE_PREVIEW)
825 DEBUG ("Enable preview");
827 if (priv->camera_state == CAMERA_STATE_ON)
829 /* preview is already displayed so we just have to stop sending */
830 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_PREVIEW);
834 display_video_preview (self, TRUE);
837 block_camera_control_signals (self);
838 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
839 priv->tool_button_camera_off), FALSE);
840 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
841 priv->tool_button_camera_on), FALSE);
843 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
844 priv->tool_button_camera_preview), TRUE);
845 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
846 CAMERA_STATE_PREVIEW);
847 unblock_camera_control_signals (self);
849 priv->camera_state = CAMERA_STATE_PREVIEW;
853 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
854 EmpathyStreamedMediaWindow *self)
856 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
858 if (!gtk_toggle_tool_button_get_active (toggle))
860 if (priv->camera_state == CAMERA_STATE_PREVIEW)
862 /* We can't change the state by disabling the button */
863 block_camera_control_signals (self);
864 gtk_toggle_tool_button_set_active (toggle, TRUE);
865 unblock_camera_control_signals (self);
871 enable_preview (self);
875 enable_camera (EmpathyStreamedMediaWindow *self)
877 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
879 if (priv->camera_state == CAMERA_STATE_ON)
882 if (priv->video_input == NULL)
884 DEBUG ("Can't enable camera, no input");
889 DEBUG ("Enable camera");
891 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_ON);
893 block_camera_control_signals (self);
894 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
895 priv->tool_button_camera_off), FALSE);
896 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
897 priv->tool_button_camera_preview), FALSE);
899 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
900 priv->tool_button_camera_on), TRUE);
901 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
903 unblock_camera_control_signals (self);
905 priv->camera_state = CAMERA_STATE_ON;
909 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
910 EmpathyStreamedMediaWindow *self)
912 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
914 if (!gtk_toggle_tool_button_get_active (toggle))
916 if (priv->camera_state == CAMERA_STATE_ON)
918 /* We can't change the state by disabling the button */
919 block_camera_control_signals (self);
920 gtk_toggle_tool_button_set_active (toggle, TRUE);
921 unblock_camera_control_signals (self);
927 enable_camera (self);
931 action_camera_change_cb (GtkRadioAction *action,
932 GtkRadioAction *current,
933 EmpathyStreamedMediaWindow *self)
937 state = gtk_radio_action_get_current_value (current);
941 case CAMERA_STATE_OFF:
942 disable_camera (self);
945 case CAMERA_STATE_PREVIEW:
946 enable_preview (self);
949 case CAMERA_STATE_ON:
950 enable_camera (self);
954 g_assert_not_reached ();
959 create_pipeline (EmpathyStreamedMediaWindow *self)
961 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
964 g_assert (priv->pipeline == NULL);
966 priv->pipeline = gst_pipeline_new (NULL);
967 priv->pipeline_playing = FALSE;
969 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
970 priv->bus_message_source_id = gst_bus_add_watch (bus,
971 empathy_streamed_media_window_bus_message, self);
973 g_object_unref (bus);
978 empathy_streamed_media_window_init (EmpathyStreamedMediaWindow *self)
980 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
989 filename = empathy_file_lookup ("empathy-streamed-media-window.ui", "src");
990 gui = empathy_builder_get_file (filename,
991 "call_window_vbox", &top_vbox,
992 "errors_vbox", &priv->errors_vbox,
994 "statusbar", &priv->statusbar,
995 "redial", &priv->redial_button,
996 "microphone", &priv->mic_button,
997 "toolbar", &priv->toolbar,
998 "menuredial", &priv->redial,
999 "ui_manager", &priv->ui_manager,
1000 "menufullscreen", &priv->menu_fullscreen,
1001 "camera_off", &priv->tool_button_camera_off,
1002 "camera_preview", &priv->tool_button_camera_preview,
1003 "camera_on", &priv->tool_button_camera_on,
1004 "action_camera_on", &priv->action_camera_on,
1005 "details_vbox", &priv->details_vbox,
1006 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1007 "acodec_encoding_label", &priv->acodec_encoding_label,
1008 "acodec_decoding_label", &priv->acodec_decoding_label,
1009 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1010 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1011 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1012 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1013 "video_local_candidate_label", &priv->video_local_candidate_label,
1014 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1015 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1016 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1017 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1021 empathy_builder_connect (gui, self,
1022 "menuhangup", "activate", empathy_streamed_media_window_hangup_cb,
1023 "hangup", "clicked", empathy_streamed_media_window_hangup_cb,
1024 "menuredial", "activate", empathy_streamed_media_window_redial_cb,
1025 "redial", "clicked", empathy_streamed_media_window_redial_cb,
1026 "microphone", "toggled", empathy_streamed_media_window_mic_toggled_cb,
1027 "menufullscreen", "activate", empathy_streamed_media_window_fullscreen_cb,
1028 "camera_off", "toggled", tool_button_camera_off_toggled_cb,
1029 "camera_preview", "toggled", tool_button_camera_preview_toggled_cb,
1030 "camera_on", "toggled", tool_button_camera_on_toggled_cb,
1031 "action_camera_on", "changed", action_camera_change_cb,
1034 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1036 priv->lock = g_mutex_new ();
1038 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1040 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1041 CONTENT_HBOX_SPACING);
1042 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1043 CONTENT_HBOX_BORDER_WIDTH);
1044 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1046 /* remote user output frame */
1047 priv->remote_user_output_frame = gtk_frame_new (NULL);
1048 gtk_widget_set_size_request (priv->remote_user_output_frame,
1049 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1050 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1051 priv->remote_user_output_frame, TRUE, TRUE,
1052 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1054 priv->remote_user_output_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
1056 priv->remote_user_avatar_widget = gtk_image_new ();
1058 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1059 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1061 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1062 priv->remote_user_output_hbox);
1064 /* self user output frame */
1065 priv->self_user_output_frame = gtk_frame_new (NULL);
1066 gtk_widget_set_size_request (priv->self_user_output_frame,
1067 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1069 priv->self_user_output_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
1071 priv->self_user_avatar_widget = gtk_image_new ();
1072 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1073 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1075 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1076 priv->self_user_output_hbox);
1078 create_pipeline (self);
1079 create_video_output_widget (self);
1080 create_audio_input (self);
1081 create_video_input (self);
1083 priv->fsnotifier = fs_element_added_notifier_new ();
1084 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1086 /* The call will be started as soon the pipeline is playing */
1087 priv->start_call_when_playing = TRUE;
1089 priv->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
1090 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1091 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1092 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1095 empathy_streamed_media_window_setup_toolbar (self);
1097 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1098 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1099 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1100 G_CALLBACK (empathy_streamed_media_window_sidebar_toggled_cb), self);
1102 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1104 h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
1105 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1106 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1108 priv->sidebar = ev_sidebar_new ();
1109 g_signal_connect (G_OBJECT (priv->sidebar),
1110 "hide", G_CALLBACK (empathy_streamed_media_window_sidebar_hidden_cb), self);
1111 g_signal_connect (G_OBJECT (priv->sidebar),
1112 "show", G_CALLBACK (empathy_streamed_media_window_sidebar_shown_cb), self);
1113 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1115 page = empathy_streamed_media_window_create_audio_input (self);
1116 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1117 _("Audio input"), page);
1119 page = empathy_streamed_media_window_create_video_input (self);
1120 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1121 _("Video input"), page);
1123 priv->dtmf_panel = empathy_dialpad_widget_new ();
1124 g_signal_connect (priv->dtmf_panel, "start-tone",
1125 G_CALLBACK (dtmf_start_tone_cb), self);
1126 g_signal_connect (priv->dtmf_panel, "stop-tone",
1127 G_CALLBACK (dtmf_stop_tone_cb), self);
1128 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1129 _("Dialpad"), priv->dtmf_panel);
1131 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1133 /* Put the details vbox in a scroll window as it can require a lot of
1134 * horizontal space. */
1135 scroll = gtk_scrolled_window_new (NULL, NULL);
1136 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll),
1137 priv->details_vbox);
1139 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details",
1140 _("Details"), scroll);
1142 gtk_widget_show_all (top_vbox);
1144 gtk_widget_hide (priv->sidebar);
1146 priv->fullscreen = empathy_streamed_media_window_fullscreen_new (self);
1147 empathy_streamed_media_window_fullscreen_set_video_widget (priv->fullscreen,
1148 priv->video_output);
1149 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1150 "clicked", G_CALLBACK (empathy_streamed_media_window_fullscreen_cb), self);
1152 g_signal_connect (G_OBJECT (self), "realize",
1153 G_CALLBACK (empathy_streamed_media_window_realized_cb), self);
1155 g_signal_connect (G_OBJECT (self), "delete-event",
1156 G_CALLBACK (empathy_streamed_media_window_delete_cb), self);
1158 g_signal_connect (G_OBJECT (self), "window-state-event",
1159 G_CALLBACK (empathy_streamed_media_window_state_event_cb), self);
1161 g_signal_connect (G_OBJECT (self), "key-press-event",
1162 G_CALLBACK (empathy_streamed_media_window_key_press_cb), self);
1164 priv->timer = g_timer_new ();
1166 g_object_ref (priv->ui_manager);
1167 g_object_unref (gui);
1169 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1171 empathy_geometry_bind (GTK_WINDOW (self), "av-window");
1174 /* Instead of specifying a width and a height, we specify only one size. That's
1175 because we want a square avatar icon. */
1177 init_contact_avatar_with_size (EmpathyContact *contact,
1178 GtkWidget *image_widget,
1181 GdkPixbuf *pixbuf_avatar = NULL;
1183 if (contact != NULL)
1185 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1189 if (pixbuf_avatar == NULL)
1191 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1192 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1195 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1197 if (pixbuf_avatar != NULL)
1198 g_object_unref (pixbuf_avatar);
1202 set_window_title (EmpathyStreamedMediaWindow *self)
1204 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1207 /* translators: Call is a noun and %s is the contact name. This string
1208 * is used in the window title */
1209 tmp = g_strdup_printf (_("Call with %s"),
1210 empathy_contact_get_alias (priv->contact));
1211 gtk_window_set_title (GTK_WINDOW (self), tmp);
1216 contact_name_changed_cb (EmpathyContact *contact,
1217 GParamSpec *pspec, EmpathyStreamedMediaWindow *self)
1219 set_window_title (self);
1223 contact_avatar_changed_cb (EmpathyContact *contact,
1224 GParamSpec *pspec, GtkWidget *avatar_widget)
1227 GtkAllocation allocation;
1229 gtk_widget_get_allocation (avatar_widget, &allocation);
1230 size = allocation.height;
1234 /* the widget is not allocated yet, set a default size */
1235 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1236 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1239 init_contact_avatar_with_size (contact, avatar_widget, size);
1243 empathy_streamed_media_window_got_self_contact_cb (TpConnection *connection,
1244 EmpathyContact *contact, const GError *error, gpointer user_data,
1245 GObject *weak_object)
1247 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1248 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1250 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1251 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1253 g_signal_connect (contact, "notify::avatar",
1254 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1258 empathy_streamed_media_window_setup_avatars (EmpathyStreamedMediaWindow *self,
1259 EmpathyStreamedMediaHandler *handler)
1261 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1263 g_object_get (handler, "contact", &(priv->contact), NULL);
1265 if (priv->contact != NULL)
1267 TpConnection *connection;
1269 set_window_title (self);
1271 g_signal_connect (priv->contact, "notify::name",
1272 G_CALLBACK (contact_name_changed_cb), self);
1273 g_signal_connect (priv->contact, "notify::avatar",
1274 G_CALLBACK (contact_avatar_changed_cb),
1275 priv->remote_user_avatar_widget);
1277 /* Retreiving the self avatar */
1278 connection = empathy_contact_get_connection (priv->contact);
1279 empathy_tp_contact_factory_get_from_handle (connection,
1280 tp_connection_get_self_handle (connection),
1281 empathy_streamed_media_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1285 g_warning ("call handler doesn't have a contact");
1286 /* translators: Call is a noun. This string is used in the window
1288 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1290 /* Since we can't access the remote contact, we can't get a connection
1291 to it and can't get the self contact (and its avatar). This means
1292 that we have to manually set the self avatar. */
1293 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1294 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1297 init_contact_avatar_with_size (priv->contact,
1298 priv->remote_user_avatar_widget,
1299 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1300 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1302 /* The remote avatar is shown by default and will be hidden when we receive
1303 video from the remote side. */
1304 gtk_widget_hide (priv->video_output);
1305 gtk_widget_show (priv->remote_user_avatar_widget);
1309 update_send_codec (EmpathyStreamedMediaWindow *self,
1312 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1319 codec = empathy_streamed_media_handler_get_send_audio_codec (priv->handler);
1320 widget = priv->acodec_encoding_label;
1324 codec = empathy_streamed_media_handler_get_send_video_codec (priv->handler);
1325 widget = priv->vcodec_encoding_label;
1331 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1332 gtk_label_set_text (GTK_LABEL (widget), tmp);
1337 send_audio_codec_notify_cb (GObject *object,
1341 EmpathyStreamedMediaWindow *self = user_data;
1343 update_send_codec (self, TRUE);
1347 send_video_codec_notify_cb (GObject *object,
1351 EmpathyStreamedMediaWindow *self = user_data;
1353 update_send_codec (self, FALSE);
1357 update_recv_codec (EmpathyStreamedMediaWindow *self,
1360 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1363 GString *str = NULL;
1367 codecs = empathy_streamed_media_handler_get_recv_audio_codecs (priv->handler);
1368 widget = priv->acodec_decoding_label;
1372 codecs = empathy_streamed_media_handler_get_recv_video_codecs (priv->handler);
1373 widget = priv->vcodec_decoding_label;
1379 for (l = codecs; l != NULL; l = g_list_next (l))
1381 FsCodec *codec = l->data;
1384 str = g_string_new (NULL);
1386 g_string_append (str, ", ");
1388 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1392 gtk_label_set_text (GTK_LABEL (widget), str->str);
1393 g_string_free (str, TRUE);
1397 recv_audio_codecs_notify_cb (GObject *object,
1401 EmpathyStreamedMediaWindow *self = user_data;
1403 update_recv_codec (self, TRUE);
1407 recv_video_codecs_notify_cb (GObject *object,
1411 EmpathyStreamedMediaWindow *self = user_data;
1413 update_recv_codec (self, FALSE);
1416 static const gchar *
1417 candidate_type_to_str (FsCandidate *candidate)
1419 switch (candidate->type)
1421 case FS_CANDIDATE_TYPE_HOST:
1423 case FS_CANDIDATE_TYPE_SRFLX:
1424 return "server reflexive";
1425 case FS_CANDIDATE_TYPE_PRFLX:
1426 return "peer reflexive";
1427 case FS_CANDIDATE_TYPE_RELAY:
1429 case FS_CANDIDATE_TYPE_MULTICAST:
1436 static const gchar *
1437 candidate_type_to_desc (FsCandidate *candidate)
1439 switch (candidate->type)
1441 case FS_CANDIDATE_TYPE_HOST:
1442 return _("The IP address as seen by the machine");
1443 case FS_CANDIDATE_TYPE_SRFLX:
1444 return _("The IP address as seen by a server on the Internet");
1445 case FS_CANDIDATE_TYPE_PRFLX:
1446 return _("The IP address of the peer as seen by the other side");
1447 case FS_CANDIDATE_TYPE_RELAY:
1448 return _("The IP address of a relay server");
1449 case FS_CANDIDATE_TYPE_MULTICAST:
1450 return _("The IP address of the multicast group");
1457 update_candidat_widget (EmpathyStreamedMediaWindow *self,
1460 FsCandidate *candidate)
1464 g_assert (candidate != NULL);
1465 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1466 candidate->port, candidate_type_to_str (candidate));
1468 gtk_label_set_text (GTK_LABEL (label), str);
1469 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1475 candidates_changed_cb (GObject *object,
1477 EmpathyStreamedMediaWindow *self)
1479 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1480 FsCandidate *candidate = NULL;
1482 if (type == FS_MEDIA_TYPE_VIDEO)
1484 /* Update remote candidate */
1485 candidate = empathy_streamed_media_handler_get_video_remote_candidate (
1488 update_candidat_widget (self, priv->video_remote_candidate_label,
1489 priv->video_remote_candidate_info_img, candidate);
1491 /* Update local candidate */
1492 candidate = empathy_streamed_media_handler_get_video_local_candidate (
1495 update_candidat_widget (self, priv->video_local_candidate_label,
1496 priv->video_local_candidate_info_img, candidate);
1500 /* Update remote candidate */
1501 candidate = empathy_streamed_media_handler_get_audio_remote_candidate (
1504 update_candidat_widget (self, priv->audio_remote_candidate_label,
1505 priv->audio_remote_candidate_info_img, candidate);
1507 /* Update local candidate */
1508 candidate = empathy_streamed_media_handler_get_audio_local_candidate (
1511 update_candidat_widget (self, priv->audio_local_candidate_label,
1512 priv->audio_local_candidate_info_img, candidate);
1517 empathy_streamed_media_window_constructed (GObject *object)
1519 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1520 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1521 EmpathyTpStreamedMedia *call;
1523 g_assert (priv->handler != NULL);
1525 g_object_get (priv->handler, "tp-call", &call, NULL);
1526 priv->outgoing = (call == NULL);
1528 g_object_unref (call);
1530 empathy_streamed_media_window_setup_avatars (self, priv->handler);
1531 empathy_streamed_media_window_set_state_connecting (self);
1533 if (!empathy_streamed_media_handler_has_initial_video (priv->handler))
1535 gtk_toggle_tool_button_set_active (
1536 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1538 /* If call has InitialVideo, the preview will be started once the call has
1539 * been started (start_call()). */
1541 update_send_codec (self, TRUE);
1542 update_send_codec (self, FALSE);
1543 update_recv_codec (self, TRUE);
1544 update_recv_codec (self, FALSE);
1546 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1547 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1548 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1549 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1550 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1551 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1552 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1553 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1555 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1556 G_CALLBACK (candidates_changed_cb), self, 0);
1559 static void empathy_streamed_media_window_dispose (GObject *object);
1560 static void empathy_streamed_media_window_finalize (GObject *object);
1563 empathy_streamed_media_window_set_property (GObject *object,
1564 guint property_id, const GValue *value, GParamSpec *pspec)
1566 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1568 switch (property_id)
1570 case PROP_STREAMED_MEDIA_HANDLER:
1571 priv->handler = g_value_dup_object (value);
1574 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1579 empathy_streamed_media_window_get_property (GObject *object,
1580 guint property_id, GValue *value, GParamSpec *pspec)
1582 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1584 switch (property_id)
1586 case PROP_STREAMED_MEDIA_HANDLER:
1587 g_value_set_object (value, priv->handler);
1590 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1595 empathy_streamed_media_window_class_init (
1596 EmpathyStreamedMediaWindowClass *empathy_streamed_media_window_class)
1598 GObjectClass *object_class = G_OBJECT_CLASS (empathy_streamed_media_window_class);
1599 GParamSpec *param_spec;
1601 g_type_class_add_private (empathy_streamed_media_window_class,
1602 sizeof (EmpathyStreamedMediaWindowPriv));
1604 object_class->constructed = empathy_streamed_media_window_constructed;
1605 object_class->set_property = empathy_streamed_media_window_set_property;
1606 object_class->get_property = empathy_streamed_media_window_get_property;
1608 object_class->dispose = empathy_streamed_media_window_dispose;
1609 object_class->finalize = empathy_streamed_media_window_finalize;
1611 param_spec = g_param_spec_object ("handler",
1612 "handler", "The call handler",
1613 EMPATHY_TYPE_STREAMED_MEDIA_HANDLER,
1614 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1615 g_object_class_install_property (object_class,
1616 PROP_STREAMED_MEDIA_HANDLER, param_spec);
1620 empathy_streamed_media_window_video_stream_changed_cb (EmpathyTpStreamedMedia *call,
1621 GParamSpec *property, EmpathyStreamedMediaWindow *self)
1623 DEBUG ("video stream changed");
1624 empathy_streamed_media_window_update_avatars_visibility (call, self);
1628 empathy_streamed_media_window_dispose (GObject *object)
1630 EmpathyTpStreamedMedia *call;
1631 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1632 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1634 if (priv->dispose_has_run)
1637 priv->dispose_has_run = TRUE;
1639 g_object_get (priv->handler, "tp-call", &call, NULL);
1643 g_object_unref (call);
1646 if (priv->handler != NULL)
1648 empathy_streamed_media_handler_stop_call (priv->handler);
1649 g_object_unref (priv->handler);
1651 priv->handler = NULL;
1653 if (priv->bus_message_source_id != 0)
1655 g_source_remove (priv->bus_message_source_id);
1656 priv->bus_message_source_id = 0;
1659 if (priv->pipeline != NULL)
1660 g_object_unref (priv->pipeline);
1661 priv->pipeline = NULL;
1663 if (priv->video_input != NULL)
1664 g_object_unref (priv->video_input);
1665 priv->video_input = NULL;
1667 if (priv->audio_input != NULL)
1668 g_object_unref (priv->audio_input);
1669 priv->audio_input = NULL;
1671 if (priv->video_tee != NULL)
1672 g_object_unref (priv->video_tee);
1673 priv->video_tee = NULL;
1675 if (priv->fsnotifier != NULL)
1676 g_object_unref (priv->fsnotifier);
1677 priv->fsnotifier = NULL;
1679 if (priv->timer_id != 0)
1680 g_source_remove (priv->timer_id);
1683 if (priv->ui_manager != NULL)
1684 g_object_unref (priv->ui_manager);
1685 priv->ui_manager = NULL;
1687 if (priv->fullscreen != NULL)
1688 g_object_unref (priv->fullscreen);
1689 priv->fullscreen = NULL;
1691 if (priv->contact != NULL)
1693 g_signal_handlers_disconnect_by_func (priv->contact,
1694 contact_name_changed_cb, self);
1695 g_object_unref (priv->contact);
1696 priv->contact = NULL;
1699 tp_clear_object (&priv->sound_mgr);
1701 /* release any references held by the object here */
1702 if (G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose)
1703 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose (object);
1707 disconnect_video_output_motion_handler (EmpathyStreamedMediaWindow *self)
1709 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1711 if (priv->video_output_motion_handler_id != 0)
1713 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1714 priv->video_output_motion_handler_id);
1715 priv->video_output_motion_handler_id = 0;
1720 empathy_streamed_media_window_finalize (GObject *object)
1722 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1723 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1725 disconnect_video_output_motion_handler (self);
1727 /* free any data held directly by the object here */
1728 g_mutex_free (priv->lock);
1730 g_timer_destroy (priv->timer);
1732 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->finalize (object);
1736 EmpathyStreamedMediaWindow *
1737 empathy_streamed_media_window_new (EmpathyStreamedMediaHandler *handler)
1739 return EMPATHY_STREAMED_MEDIA_WINDOW (
1740 g_object_new (EMPATHY_TYPE_STREAMED_MEDIA_WINDOW, "handler", handler, NULL));
1744 empathy_streamed_media_window_conference_added_cb (EmpathyStreamedMediaHandler *handler,
1745 GstElement *conference, gpointer user_data)
1747 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1748 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1751 keyfile = fs_utils_get_default_element_properties (conference);
1752 if (keyfile != NULL)
1753 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1756 gst_bin_add (GST_BIN (priv->pipeline), conference);
1758 gst_element_set_state (conference, GST_STATE_PLAYING);
1762 empathy_streamed_media_window_start_receiving_cb (EmpathyStreamedMediaHandler *handler,
1763 FsMediaType type,gpointer user_data)
1765 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1766 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1768 if (type != FS_MEDIA_TYPE_VIDEO)
1771 /* video and direction is send */
1772 return priv->video_input != NULL;
1776 empathy_streamed_media_window_reset_pipeline (EmpathyStreamedMediaWindow *self)
1778 GstStateChangeReturn state_change_return;
1779 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1781 if (priv->pipeline == NULL)
1784 if (priv->bus_message_source_id != 0)
1786 g_source_remove (priv->bus_message_source_id);
1787 priv->bus_message_source_id = 0;
1790 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1792 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1793 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1795 if (priv->pipeline != NULL)
1796 g_object_unref (priv->pipeline);
1797 priv->pipeline = NULL;
1799 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1800 empathy_streamed_media_window_mic_volume_changed_cb, self);
1802 if (priv->video_tee != NULL)
1803 g_object_unref (priv->video_tee);
1804 priv->video_tee = NULL;
1806 if (priv->video_preview != NULL)
1807 gtk_widget_destroy (priv->video_preview);
1808 priv->video_preview = NULL;
1810 priv->funnel = NULL;
1812 create_pipeline (self);
1813 /* Call will be started when user will hit the 'redial' button */
1814 priv->start_call_when_playing = FALSE;
1815 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1821 g_message ("Error: could not destroy pipeline. Closing call window");
1822 gtk_widget_destroy (GTK_WIDGET (self));
1829 reset_details_pane (EmpathyStreamedMediaWindow *self)
1831 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1833 /* translators: encoding video codec is unknown */
1834 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label),
1835 C_("codec", "Unknown"));
1836 /* translators: encoding audio codec is unknown */
1837 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label),
1838 C_("codec", "Unknown"));
1839 /* translators: decoding video codec is unknown */
1840 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label),
1841 C_("codec", "Unknown"));
1842 /* translators: decoding audio codec is unknown */
1843 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label),
1844 C_("codec", "Unknown"));
1848 empathy_streamed_media_window_disconnected (EmpathyStreamedMediaWindow *self,
1851 gboolean could_disconnect = FALSE;
1852 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1853 gboolean could_reset_pipeline;
1855 /* Leave full screen mode if needed */
1856 gtk_window_unfullscreen (GTK_WINDOW (self));
1858 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1860 could_reset_pipeline = empathy_streamed_media_window_reset_pipeline (self);
1862 if (priv->call_state == CONNECTING)
1863 empathy_sound_manager_stop (priv->sound_mgr,
1864 EMPATHY_SOUND_PHONE_OUTGOING);
1866 if (priv->call_state != REDIALING)
1867 priv->call_state = DISCONNECTED;
1869 if (could_reset_pipeline)
1871 g_mutex_lock (priv->lock);
1873 g_timer_stop (priv->timer);
1875 if (priv->timer_id != 0)
1876 g_source_remove (priv->timer_id);
1879 g_mutex_unlock (priv->lock);
1882 /* We are about to destroy the window, no need to update it or create
1883 * a video preview */
1886 empathy_streamed_media_window_status_message (self, _("Disconnected"));
1888 gtk_action_set_sensitive (priv->redial, TRUE);
1889 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1891 /* Unsensitive the camera and mic button */
1892 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1893 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
1894 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1896 /* Be sure that the mic button is enabled */
1897 gtk_toggle_tool_button_set_active (
1898 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1900 if (priv->camera_state == CAMERA_STATE_ON)
1902 /* Enable the 'preview' button as we are not sending atm. */
1903 gtk_toggle_tool_button_set_active (
1904 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_preview), TRUE);
1906 else if (priv->camera_state == CAMERA_STATE_PREVIEW)
1908 /* Restart the preview with the new pipeline. */
1909 display_video_preview (self, TRUE);
1912 gtk_progress_bar_set_fraction (
1913 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1915 /* destroy the video output; it will be recreated when we'll redial */
1916 disconnect_video_output_motion_handler (self);
1917 gtk_widget_destroy (priv->video_output);
1918 priv->video_output = NULL;
1920 gtk_widget_show (priv->remote_user_avatar_widget);
1922 reset_details_pane (self);
1924 priv->sending_video = FALSE;
1925 priv->call_started = FALSE;
1927 could_disconnect = TRUE;
1929 /* TODO: display the self avatar of the preview (depends if the "Always
1930 * Show Video Preview" is enabled or not) */
1933 return could_disconnect;
1938 empathy_streamed_media_window_channel_closed_cb (EmpathyStreamedMediaHandler *handler,
1941 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1942 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1944 if (empathy_streamed_media_window_disconnected (self, TRUE) &&
1945 priv->call_state == REDIALING)
1946 empathy_streamed_media_window_restart_call (self);
1951 empathy_streamed_media_window_channel_stream_closed_cb (EmpathyStreamedMediaHandler *handler,
1952 TfContent *content, gpointer user_data)
1954 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1955 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1958 g_object_get (content, "media-type", &media_type, NULL);
1961 * This assumes that there is only one video stream per channel...
1964 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
1966 if (priv->funnel != NULL)
1970 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1971 (priv->video_output));
1973 gst_element_set_state (output, GST_STATE_NULL);
1974 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1976 gst_bin_remove (GST_BIN (priv->pipeline), output);
1977 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1978 priv->funnel = NULL;
1981 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
1983 if (priv->audio_output != NULL)
1985 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1987 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1988 priv->audio_output = NULL;
1993 /* Called with global lock held */
1995 empathy_streamed_media_window_get_video_sink_pad (EmpathyStreamedMediaWindow *self)
1997 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2001 if (priv->funnel == NULL)
2003 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
2004 (priv->video_output));
2006 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2010 g_warning ("Could not create fsfunnel");
2014 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2016 gst_object_unref (priv->funnel);
2017 priv->funnel = NULL;
2018 g_warning ("Could not add funnel to pipeline");
2022 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2024 g_warning ("Could not add the video output widget to the pipeline");
2028 if (!gst_element_link (priv->funnel, output))
2030 g_warning ("Could not link output sink to funnel");
2031 goto error_output_added;
2034 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2036 g_warning ("Could not start video sink");
2037 goto error_output_added;
2040 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2042 g_warning ("Could not start funnel");
2043 goto error_output_added;
2047 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2050 g_warning ("Could not get request pad from funnel");
2057 gst_element_set_locked_state (priv->funnel, TRUE);
2058 gst_element_set_locked_state (output, TRUE);
2060 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2061 gst_element_set_state (output, GST_STATE_NULL);
2063 gst_bin_remove (GST_BIN (priv->pipeline), output);
2064 gst_element_set_locked_state (output, FALSE);
2068 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2069 priv->funnel = NULL;
2074 /* Called with global lock held */
2076 empathy_streamed_media_window_get_audio_sink_pad (EmpathyStreamedMediaWindow *self)
2078 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2080 GstPadTemplate *template;
2082 if (priv->audio_output == NULL)
2084 priv->audio_output = empathy_audio_sink_new ();
2086 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2088 g_warning ("Could not add audio sink to pipeline");
2089 g_object_unref (priv->audio_output);
2090 goto error_add_output;
2093 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2095 g_warning ("Could not start audio sink");
2100 template = gst_element_class_get_pad_template (
2101 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2103 pad = gst_element_request_pad (priv->audio_output,
2104 template, NULL, NULL);
2108 g_warning ("Could not get sink pad from sink");
2115 gst_element_set_locked_state (priv->audio_output, TRUE);
2116 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2117 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2118 priv->audio_output = NULL;
2126 empathy_streamed_media_window_update_timer (gpointer user_data)
2128 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2129 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2133 time_ = g_timer_elapsed (priv->timer, NULL);
2135 /* Translators: number of minutes:seconds the caller has been connected */
2136 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
2138 empathy_streamed_media_window_status_message (self, str);
2145 display_error (EmpathyStreamedMediaWindow *self,
2146 EmpathyTpStreamedMedia *call,
2150 const gchar *details)
2152 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2153 GtkWidget *info_bar;
2154 GtkWidget *content_area;
2161 /* Create info bar */
2162 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2165 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2167 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2169 /* hbox containing the image and the messages vbox */
2170 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2171 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2174 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2175 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2177 /* vbox containing the main message and the details expander */
2178 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2179 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2182 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2184 label = gtk_label_new (NULL);
2185 gtk_label_set_markup (GTK_LABEL (label), txt);
2186 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2187 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2190 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2193 if (details != NULL)
2195 GtkWidget *expander;
2197 expander = gtk_expander_new (_("Technical Details"));
2199 txt = g_strdup_printf ("<i>%s</i>", details);
2201 label = gtk_label_new (NULL);
2202 gtk_label_set_markup (GTK_LABEL (label), txt);
2203 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2204 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2207 gtk_container_add (GTK_CONTAINER (expander), label);
2208 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2211 g_signal_connect (info_bar, "response",
2212 G_CALLBACK (gtk_widget_destroy), NULL);
2214 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2215 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2216 gtk_widget_show_all (info_bar);
2220 media_stream_error_to_txt (EmpathyStreamedMediaWindow *self,
2221 EmpathyTpStreamedMedia *call,
2223 TpMediaStreamError error)
2225 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2232 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2234 return g_strdup_printf (
2235 _("%s's software does not understand any of the audio formats "
2236 "supported by your computer"),
2237 empathy_contact_get_alias (priv->contact));
2239 return g_strdup_printf (
2240 _("%s's software does not understand any of the video formats "
2241 "supported by your computer"),
2242 empathy_contact_get_alias (priv->contact));
2244 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2245 return g_strdup_printf (
2246 _("Can't establish a connection to %s. "
2247 "One of you might be on a network that does not allow "
2248 "direct connections."),
2249 empathy_contact_get_alias (priv->contact));
2251 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2252 return g_strdup (_("There was a failure on the network"));
2254 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2256 return g_strdup (_("The audio formats necessary for this call "
2257 "are not installed on your computer"));
2259 return g_strdup (_("The video formats necessary for this call "
2260 "are not installed on your computer"));
2262 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2263 cm = empathy_tp_streamed_media_get_connection_manager (call);
2265 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2266 "product=Telepathy&component=%s", cm);
2268 result = g_strdup_printf (
2269 _("Something unexpected happened in a Telepathy component. "
2270 "Please <a href=\"%s\">report this bug</a> and attach "
2271 "logs gathered from the 'Debug' window in the Help menu."), url);
2276 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2277 return g_strdup (_("There was a failure in the call engine"));
2279 case TP_MEDIA_STREAM_ERROR_EOS:
2280 return g_strdup (_("The end of the stream was reached"));
2282 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2289 empathy_streamed_media_window_stream_error (EmpathyStreamedMediaWindow *self,
2290 EmpathyTpStreamedMedia *call,
2299 desc = media_stream_error_to_txt (self, call, audio, code);
2302 /* No description, use the error message. That's not great as it's not
2303 * localized but it's better than nothing. */
2304 display_error (self, call, icon, title, msg, NULL);
2308 display_error (self, call, icon, title, desc, msg);
2314 empathy_streamed_media_window_audio_stream_error (EmpathyTpStreamedMedia *call,
2317 EmpathyStreamedMediaWindow *self)
2319 empathy_streamed_media_window_stream_error (self, call, TRUE, code, msg,
2320 "gnome-stock-mic", _("Can't establish audio stream"));
2324 empathy_streamed_media_window_video_stream_error (EmpathyTpStreamedMedia *call,
2327 EmpathyStreamedMediaWindow *self)
2329 empathy_streamed_media_window_stream_error (self, call, FALSE, code, msg,
2330 "camera-web", _("Can't establish video stream"));
2334 empathy_streamed_media_window_connected (gpointer user_data)
2336 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2337 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2338 EmpathyTpStreamedMedia *call;
2339 gboolean can_send_video;
2341 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2343 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2344 empathy_contact_can_voip_video (priv->contact);
2346 g_object_get (priv->handler, "tp-call", &call, NULL);
2348 tp_g_signal_connect_object (call, "notify::video-stream",
2349 G_CALLBACK (empathy_streamed_media_window_video_stream_changed_cb),
2352 if (empathy_tp_streamed_media_has_dtmf (call))
2353 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2355 if (priv->video_input == NULL)
2356 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
2358 priv->sending_video = can_send_video ?
2359 empathy_tp_streamed_media_is_sending_video (call) : FALSE;
2361 gtk_toggle_tool_button_set_active (
2362 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2363 priv->sending_video && priv->video_input != NULL);
2364 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2365 gtk_action_set_sensitive (priv->action_camera_on, can_send_video);
2367 gtk_action_set_sensitive (priv->redial, FALSE);
2368 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2370 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2372 empathy_streamed_media_window_update_avatars_visibility (call, self);
2374 g_object_unref (call);
2376 g_mutex_lock (priv->lock);
2378 priv->timer_id = g_timeout_add_seconds (1,
2379 empathy_streamed_media_window_update_timer, self);
2381 g_mutex_unlock (priv->lock);
2383 empathy_streamed_media_window_update_timer (self);
2385 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2391 /* Called from the streaming thread */
2393 empathy_streamed_media_window_src_added_cb (EmpathyStreamedMediaHandler *handler,
2394 GstPad *src, guint media_type, gpointer user_data)
2396 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2397 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2398 gboolean retval = FALSE;
2402 g_mutex_lock (priv->lock);
2404 if (priv->call_state != CONNECTED)
2406 g_timer_start (priv->timer);
2407 priv->timer_id = g_idle_add (empathy_streamed_media_window_connected, self);
2408 priv->call_state = CONNECTED;
2413 case TP_MEDIA_STREAM_TYPE_AUDIO:
2414 pad = empathy_streamed_media_window_get_audio_sink_pad (self);
2416 case TP_MEDIA_STREAM_TYPE_VIDEO:
2417 gtk_widget_hide (priv->remote_user_avatar_widget);
2418 gtk_widget_show (priv->video_output);
2419 pad = empathy_streamed_media_window_get_video_sink_pad (self);
2422 g_assert_not_reached ();
2428 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2429 g_warning ("Could not link %s sink pad",
2430 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2434 gst_object_unref (pad);
2438 /* If no sink could be linked, try to add fakesink to prevent the whole call
2443 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2445 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2447 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2448 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2449 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2451 gst_element_set_locked_state (fakesink, TRUE);
2452 gst_element_set_state (fakesink, GST_STATE_NULL);
2453 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2457 DEBUG ("Could not link real sink, linked fakesink instead");
2459 gst_object_unref (sinkpad);
2463 gst_object_unref (fakesink);
2468 g_mutex_unlock (priv->lock);
2474 empathy_streamed_media_window_sink_added_cb (EmpathyStreamedMediaHandler *handler,
2475 GstPad *sink, guint media_type, gpointer user_data)
2477 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2478 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2480 gboolean retval = FALSE;
2484 case TP_MEDIA_STREAM_TYPE_AUDIO:
2485 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2487 g_warning ("Could not add audio source to pipeline");
2491 pad = gst_element_get_static_pad (priv->audio_input, "src");
2494 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2495 g_warning ("Could not get source pad from audio source");
2499 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2501 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2502 g_warning ("Could not link audio source to farsight");
2506 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2508 g_warning ("Could not start audio source");
2509 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2510 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2516 case TP_MEDIA_STREAM_TYPE_VIDEO:
2517 if (priv->video_input != NULL)
2519 if (priv->video_tee != NULL)
2521 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2522 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2524 g_warning ("Could not link videp soure input pipeline");
2527 gst_object_unref (pad);
2534 g_assert_not_reached ();
2541 empathy_streamed_media_window_remove_video_input (EmpathyStreamedMediaWindow *self)
2543 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2544 GstElement *preview;
2546 disable_camera (self);
2548 DEBUG ("remove video input");
2549 preview = empathy_video_widget_get_element (
2550 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2552 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2553 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2554 gst_element_set_state (preview, GST_STATE_NULL);
2556 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2557 priv->video_tee, preview, NULL);
2559 g_object_unref (priv->video_input);
2560 priv->video_input = NULL;
2561 g_object_unref (priv->video_tee);
2562 priv->video_tee = NULL;
2563 gtk_widget_destroy (priv->video_preview);
2564 priv->video_preview = NULL;
2566 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2567 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
2568 gtk_widget_set_sensitive (priv->tool_button_camera_preview, FALSE);
2572 start_call (EmpathyStreamedMediaWindow *self)
2574 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2576 priv->call_started = TRUE;
2577 empathy_streamed_media_handler_start_call (priv->handler,
2578 empathy_get_current_action_time ());
2580 if (empathy_streamed_media_handler_has_initial_video (priv->handler))
2582 /* Enable 'send video' buttons and display the preview */
2583 gtk_toggle_tool_button_set_active (
2584 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2589 empathy_streamed_media_window_bus_message (GstBus *bus, GstMessage *message,
2592 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2593 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2596 empathy_streamed_media_handler_bus_message (priv->handler, bus, message);
2598 switch (GST_MESSAGE_TYPE (message))
2600 case GST_MESSAGE_STATE_CHANGED:
2601 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2603 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2604 if (newstate == GST_STATE_PAUSED)
2605 empathy_streamed_media_window_setup_video_input (self);
2607 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2608 !priv->call_started)
2610 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2611 if (newstate == GST_STATE_PAUSED)
2613 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2614 priv->pipeline_playing = TRUE;
2616 if (priv->start_call_when_playing)
2621 case GST_MESSAGE_ERROR:
2623 GError *error = NULL;
2624 GstElement *gst_error;
2627 gst_message_parse_error (message, &error, &debug);
2628 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2630 g_message ("Element error: %s -- %s\n", error->message, debug);
2632 if (g_str_has_prefix (gst_element_get_name (gst_error),
2633 VIDEO_INPUT_ERROR_PREFIX))
2635 /* Remove the video input and continue */
2636 if (priv->video_input != NULL)
2637 empathy_streamed_media_window_remove_video_input (self);
2638 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2642 empathy_streamed_media_window_disconnected (self, TRUE);
2644 g_error_free (error);
2647 case GST_MESSAGE_UNKNOWN:
2648 case GST_MESSAGE_EOS:
2649 case GST_MESSAGE_WARNING:
2650 case GST_MESSAGE_INFO:
2651 case GST_MESSAGE_TAG:
2652 case GST_MESSAGE_BUFFERING:
2653 case GST_MESSAGE_STATE_DIRTY:
2654 case GST_MESSAGE_STEP_DONE:
2655 case GST_MESSAGE_CLOCK_PROVIDE:
2656 case GST_MESSAGE_CLOCK_LOST:
2657 case GST_MESSAGE_NEW_CLOCK:
2658 case GST_MESSAGE_STRUCTURE_CHANGE:
2659 case GST_MESSAGE_STREAM_STATUS:
2660 case GST_MESSAGE_APPLICATION:
2661 case GST_MESSAGE_ELEMENT:
2662 case GST_MESSAGE_SEGMENT_START:
2663 case GST_MESSAGE_SEGMENT_DONE:
2664 case GST_MESSAGE_DURATION:
2665 case GST_MESSAGE_ANY:
2674 empathy_streamed_media_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
2675 EmpathyStreamedMediaWindow *window)
2677 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2679 if (empathy_tp_streamed_media_is_receiving_video (call))
2681 gtk_widget_hide (priv->remote_user_avatar_widget);
2682 gtk_widget_show (priv->video_output);
2686 gtk_widget_hide (priv->video_output);
2687 gtk_widget_show (priv->remote_user_avatar_widget);
2692 call_handler_notify_tp_streamed_media_cb (EmpathyStreamedMediaHandler *handler,
2694 EmpathyStreamedMediaWindow *self)
2696 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2697 EmpathyTpStreamedMedia *call;
2699 g_object_get (priv->handler, "tp-call", &call, NULL);
2703 tp_g_signal_connect_object (call, "audio-stream-error",
2704 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), self, 0);
2705 tp_g_signal_connect_object (call, "video-stream-error",
2706 G_CALLBACK (empathy_streamed_media_window_video_stream_error), self, 0);
2708 g_object_unref (call);
2712 empathy_streamed_media_window_realized_cb (GtkWidget *widget, EmpathyStreamedMediaWindow *window)
2714 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2715 EmpathyTpStreamedMedia *call;
2717 g_signal_connect (priv->handler, "conference-added",
2718 G_CALLBACK (empathy_streamed_media_window_conference_added_cb), window);
2719 g_signal_connect (priv->handler, "start-receiving",
2720 G_CALLBACK (empathy_streamed_media_window_start_receiving_cb), window);
2721 g_signal_connect (priv->handler, "closed",
2722 G_CALLBACK (empathy_streamed_media_window_channel_closed_cb), window);
2723 g_signal_connect (priv->handler, "src-pad-added",
2724 G_CALLBACK (empathy_streamed_media_window_src_added_cb), window);
2725 g_signal_connect (priv->handler, "sink-pad-added",
2726 G_CALLBACK (empathy_streamed_media_window_sink_added_cb), window);
2727 g_signal_connect (priv->handler, "stream-closed",
2728 G_CALLBACK (empathy_streamed_media_window_channel_stream_closed_cb), window);
2730 g_object_get (priv->handler, "tp-call", &call, NULL);
2733 tp_g_signal_connect_object (call, "audio-stream-error",
2734 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), window,
2736 tp_g_signal_connect_object (call, "video-stream-error",
2737 G_CALLBACK (empathy_streamed_media_window_video_stream_error), window,
2740 g_object_unref (call);
2744 /* tp-call doesn't exist yet, we'll connect signals once it has been
2746 g_signal_connect (priv->handler, "notify::tp-call",
2747 G_CALLBACK (call_handler_notify_tp_streamed_media_cb), window);
2750 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2754 empathy_streamed_media_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2755 EmpathyStreamedMediaWindow *window)
2757 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2759 if (priv->pipeline != NULL)
2761 if (priv->bus_message_source_id != 0)
2763 g_source_remove (priv->bus_message_source_id);
2764 priv->bus_message_source_id = 0;
2767 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2770 if (priv->call_state == CONNECTING)
2771 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2777 show_controls (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2780 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2782 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2787 gtk_widget_hide (priv->sidebar);
2788 gtk_widget_hide (menu);
2789 gtk_widget_hide (priv->vbox);
2790 gtk_widget_hide (priv->statusbar);
2791 gtk_widget_hide (priv->toolbar);
2795 if (priv->sidebar_was_visible_before_fs)
2796 gtk_widget_show (priv->sidebar);
2798 gtk_widget_show (menu);
2799 gtk_widget_show (priv->vbox);
2800 gtk_widget_show (priv->statusbar);
2801 gtk_widget_show (priv->toolbar);
2803 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2804 priv->original_height_before_fs);
2809 show_borders (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2811 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2813 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2814 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2815 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2816 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2818 if (priv->video_output != NULL)
2820 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2821 priv->video_output, TRUE, TRUE,
2822 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2826 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2827 priv->vbox, TRUE, TRUE,
2828 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2833 empathy_streamed_media_window_state_event_cb (GtkWidget *widget,
2834 GdkEventWindowState *event, EmpathyStreamedMediaWindow *window)
2836 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2838 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2839 gboolean set_fullscreen = event->new_window_state &
2840 GDK_WINDOW_STATE_FULLSCREEN;
2844 gboolean sidebar_was_visible;
2845 GtkAllocation allocation;
2846 gint original_width, original_height;
2848 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2849 original_width = allocation.width;
2850 original_height = allocation.height;
2852 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2854 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2855 priv->original_width_before_fs = original_width;
2856 priv->original_height_before_fs = original_height;
2858 if (priv->video_output_motion_handler_id == 0 &&
2859 priv->video_output != NULL)
2861 priv->video_output_motion_handler_id = g_signal_connect (
2862 G_OBJECT (priv->video_output), "motion-notify-event",
2863 G_CALLBACK (empathy_streamed_media_window_video_output_motion_notify),
2869 disconnect_video_output_motion_handler (window);
2872 empathy_streamed_media_window_fullscreen_set_fullscreen (priv->fullscreen,
2874 show_controls (window, set_fullscreen);
2875 show_borders (window, set_fullscreen);
2876 gtk_action_set_stock_id (priv->menu_fullscreen,
2877 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2878 priv->is_fullscreen = set_fullscreen;
2885 empathy_streamed_media_window_sidebar_toggled_cb (GtkToggleButton *toggle,
2886 EmpathyStreamedMediaWindow *window)
2888 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2890 int w, h, handle_size;
2891 GtkAllocation allocation, sidebar_allocation;
2893 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2894 w = allocation.width;
2895 h = allocation.height;
2897 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2899 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
2900 if (gtk_toggle_button_get_active (toggle))
2902 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
2903 gtk_widget_show (priv->sidebar);
2904 w += sidebar_allocation.width + handle_size;
2908 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2909 w -= sidebar_allocation.width + handle_size;
2910 gtk_widget_hide (priv->sidebar);
2913 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
2916 gtk_window_resize (GTK_WINDOW (window), w, h);
2920 empathy_streamed_media_window_set_send_video (EmpathyStreamedMediaWindow *window,
2923 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2924 EmpathyTpStreamedMedia *call;
2926 priv->sending_video = (state == CAMERA_STATE_ON);
2928 if (state == CAMERA_STATE_PREVIEW ||
2929 state == CAMERA_STATE_ON)
2931 /* When we start sending video, we want to show the video preview by
2933 display_video_preview (window, TRUE);
2937 display_video_preview (window, FALSE);
2940 if (priv->call_state != CONNECTED)
2943 g_object_get (priv->handler, "tp-call", &call, NULL);
2944 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2945 empathy_tp_streamed_media_request_video_stream_direction (call, priv->sending_video);
2946 g_object_unref (call);
2950 empathy_streamed_media_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2951 EmpathyStreamedMediaWindow *window)
2953 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2956 active = (gtk_toggle_tool_button_get_active (toggle));
2960 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2962 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
2966 /* TODO, Instead of setting the input volume to 0 we should probably
2967 * stop sending but this would cause the audio call to drop if both
2968 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2969 * in the future. GNOME #574574
2971 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2973 gtk_adjustment_set_value (priv->audio_input_adj, 0);
2978 empathy_streamed_media_window_sidebar_hidden_cb (EvSidebar *sidebar,
2979 EmpathyStreamedMediaWindow *window)
2981 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2983 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2988 empathy_streamed_media_window_sidebar_shown_cb (EvSidebar *sidebar,
2989 EmpathyStreamedMediaWindow *window)
2991 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2993 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2998 empathy_streamed_media_window_hangup_cb (gpointer object,
2999 EmpathyStreamedMediaWindow *window)
3001 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3003 empathy_streamed_media_handler_stop_call (priv->handler);
3005 if (empathy_streamed_media_window_disconnected (window, FALSE))
3006 gtk_widget_destroy (GTK_WIDGET (window));
3010 empathy_streamed_media_window_restart_call (EmpathyStreamedMediaWindow *window)
3012 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3014 /* Remove error info bars */
3015 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3016 (GtkCallback) gtk_widget_destroy, NULL);
3018 create_video_output_widget (window);
3020 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3021 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), window);
3023 /* While the call was disconnected, the input volume might have changed.
3024 * However, since the audio_input source was destroyed, its volume has not
3025 * been updated during that time. That's why we manually update it here */
3026 empathy_streamed_media_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3028 priv->outgoing = TRUE;
3029 empathy_streamed_media_window_set_state_connecting (window);
3031 if (priv->pipeline_playing)
3032 start_call (window);
3034 /* call will be started when the pipeline is ready */
3035 priv->start_call_when_playing = TRUE;
3038 empathy_streamed_media_window_setup_avatars (window, priv->handler);
3040 gtk_action_set_sensitive (priv->redial, FALSE);
3041 gtk_widget_set_sensitive (priv->redial_button, FALSE);
3045 empathy_streamed_media_window_redial_cb (gpointer object,
3046 EmpathyStreamedMediaWindow *window)
3048 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3050 if (priv->call_state == CONNECTED)
3051 priv->call_state = REDIALING;
3053 empathy_streamed_media_handler_stop_call (priv->handler);
3055 if (priv->call_state != CONNECTED)
3056 empathy_streamed_media_window_restart_call (window);
3060 empathy_streamed_media_window_fullscreen_cb (gpointer object,
3061 EmpathyStreamedMediaWindow *window)
3063 empathy_streamed_media_window_fullscreen_toggle (window);
3067 empathy_streamed_media_window_fullscreen_toggle (EmpathyStreamedMediaWindow *window)
3069 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3071 if (priv->is_fullscreen)
3072 gtk_window_unfullscreen (GTK_WINDOW (window));
3074 gtk_window_fullscreen (GTK_WINDOW (window));
3078 empathy_streamed_media_window_video_button_press_cb (GtkWidget *video_output,
3079 GdkEventButton *event, EmpathyStreamedMediaWindow *window)
3081 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3083 empathy_streamed_media_window_video_menu_popup (window, event->button);
3091 empathy_streamed_media_window_key_press_cb (GtkWidget *video_output,
3092 GdkEventKey *event, EmpathyStreamedMediaWindow *window)
3094 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3096 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3098 /* Since we are in fullscreen mode, toggling will bring us back to
3100 empathy_streamed_media_window_fullscreen_toggle (window);
3108 empathy_streamed_media_window_video_output_motion_notify (GtkWidget *widget,
3109 GdkEventMotion *event, EmpathyStreamedMediaWindow *window)
3111 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3113 if (priv->is_fullscreen)
3115 empathy_streamed_media_window_fullscreen_show_popup (priv->fullscreen);
3122 empathy_streamed_media_window_video_menu_popup (EmpathyStreamedMediaWindow *window,
3126 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3128 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3130 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3131 button, gtk_get_current_event_time ());
3132 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3136 empathy_streamed_media_window_status_message (EmpathyStreamedMediaWindow *window,
3139 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3141 if (priv->context_id == 0)
3143 priv->context_id = gtk_statusbar_get_context_id (
3144 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
3148 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
3151 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
3156 empathy_streamed_media_window_volume_changed_cb (GtkScaleButton *button,
3157 gdouble value, EmpathyStreamedMediaWindow *window)
3159 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3161 if (priv->audio_output == NULL)
3164 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3168 /* block all the signals related to camera control widgets. This is useful
3169 * when we are manually updating the UI and so don't want to fire the
3172 block_camera_control_signals (EmpathyStreamedMediaWindow *self)
3174 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3176 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
3177 tool_button_camera_off_toggled_cb, self);
3178 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
3179 tool_button_camera_preview_toggled_cb, self);
3180 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
3181 tool_button_camera_on_toggled_cb, self);
3182 g_signal_handlers_block_by_func (priv->action_camera_on,
3183 action_camera_change_cb, self);
3187 unblock_camera_control_signals (EmpathyStreamedMediaWindow *self)
3189 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3191 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
3192 tool_button_camera_off_toggled_cb, self);
3193 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
3194 tool_button_camera_preview_toggled_cb, self);
3195 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
3196 tool_button_camera_on_toggled_cb, self);
3197 g_signal_handlers_unblock_by_func (priv->action_camera_on,
3198 action_camera_change_cb, self);