diff --git a/gnome/src/actions.c b/gnome/src/actions.c index 26cf76d00735da6c3adddf6cf9c4c226291f4c21..877407261c8f7001220a1680cc4383285fd55c16 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -1014,30 +1014,42 @@ sflphone_call_state_changed(callable_obj_t * c, const gchar * description, const } #ifdef SFL_VIDEO -char * +gchar * sflphone_get_display(void) { int width = gdk_screen_width(); int height = gdk_screen_height(); char *display = getenv("DISPLAY"); - char resource[256]; - sprintf(resource, "display://%s %dx%d", display, width, height); - return g_strdup(resource); + return g_strdup_printf("display://%s %dx%d", display, width, height); +} + +gchar * +sflphone_get_active_video(void) +{ + gchar *device = dbus_get_active_video_device(); + gchar *resource = g_strconcat("v4l2://", device, NULL); + g_free(device); + + return resource; +} + +gchar * +sflphone_get_video_none(void) +{ + return g_strconcat("file://", ICONS_DIR, "/sflphone.png", NULL); } void sflphone_toggle_screenshare(void) { static gboolean screenshare = TRUE; - gchar *resource; + gchar *resource = NULL; if (screenshare) { resource = sflphone_get_display(); } else { - gchar *device = dbus_get_active_video_device(); - resource = g_strconcat("v4l2://", device, NULL); - g_free(device); + resource = sflphone_get_active_video(); } if (dbus_switch_video_input(resource)) { @@ -1049,4 +1061,27 @@ sflphone_toggle_screenshare(void) g_free(resource); } + +void +sflphone_toggle_camera(void) +{ + static gboolean camera_toggle = TRUE; + gchar *resource = NULL; + + if (camera_toggle) { + resource = sflphone_get_video_none(); + } else { + resource = sflphone_get_active_video(); + } + + if (dbus_switch_video_input(resource)) { + g_debug("switched video input to '%s'", resource); + camera_toggle = !camera_toggle; + } else { + g_error("failed to switch to resource '%s'\n", resource); + } + + g_free(resource); + +} #endif diff --git a/gnome/src/actions.h b/gnome/src/actions.h index 0c6fb59e12c52f61952f8523ab98033959e68aaf..d0eed595a8da1b7d46f06b038cc459b9023395bc 100644 --- a/gnome/src/actions.h +++ b/gnome/src/actions.h @@ -261,8 +261,14 @@ void sflphone_srtp_sdes_off(callable_obj_t * c, SFLPhoneClient *client); void sflphone_fill_conference_list(SFLPhoneClient *client); -char *sflphone_get_display(void); +gchar * sflphone_get_display(void); + +gchar * sflphone_get_active_video(void); + +gchar * sflphone_get_video_none(void); void sflphone_toggle_screenshare(void); +void sflphone_toggle_camera(void); + #endif diff --git a/gnome/src/uimanager.c b/gnome/src/uimanager.c index 2e0417d714421e686627eb051494ff268b4b28a4..4e28ac01024857fcb0159cb310bd2874c2d8c11a 100644 --- a/gnome/src/uimanager.c +++ b/gnome/src/uimanager.c @@ -691,23 +691,20 @@ call_screenshare(G_GNUC_UNUSED GtkAction *action, G_GNUC_UNUSED SFLPhoneClient * static void call_switch_video_input(G_GNUC_UNUSED GtkWidget *widget, gchar *device) { - gboolean switched; - gchar *resource; + gchar *resource = NULL; if (g_strcmp0(device, "None") == 0) { - resource = g_strconcat("file://", ICONS_DIR "/sflphone.png", NULL); - switched = dbus_switch_video_input(resource); + resource = sflphone_get_video_none(); } else if (g_strcmp0(device, "Screen") == 0) { resource = sflphone_get_display(); - switched = dbus_switch_video_input(resource); } else { dbus_set_active_video_device(device); - resource = g_strconcat("v4l2://", device, NULL); - switched = dbus_switch_video_input(resource); + resource = g_strconcat("v4l2://", device, NULL); } - if (!switched) - g_warning("Failed to switch to '%s' (MRL '%s')\n", device, resource); + if (!dbus_switch_video_input(resource)) + g_error("failed to switch to '%s' (MRL '%s')\n", device, resource); + g_free(resource); } #endif