Commit a0d4f104 authored by Julien Grossholtz's avatar Julien Grossholtz Committed by Stepan Salenikovich

video widget: Use sourcemodel from Media

Instead of using the former sourcemodel singleton, use the
sourcemodel attached to calls through media.
This allow the source checkbox to display correct data.

Change-Id: I589090f5a70807ce9e7018acf8ee75f4abcc559d
Tuleap: #264
parent 504f7728
......@@ -615,6 +615,12 @@ current_call_view_set_call_info(CurrentCallView *view, const QModelIndex& idx) {
}
);
/* handle video widget button click event */
g_signal_connect(priv->video_widget, "button-press-event", G_CALLBACK(video_widget_on_button_press_in_screen_event), priv->call);
/* handle video widget drag and drop*/
g_signal_connect(priv->video_widget, "drag-data-received", G_CALLBACK(video_widget_on_drag_data_received), priv->call);
/* catch double click to make full screen */
g_signal_connect(priv->video_widget, "button-press-event",
G_CALLBACK(on_button_press_in_video_event),
......
......@@ -35,16 +35,19 @@
#include <clutter-gtk/clutter-gtk.h>
#include <video/renderer.h>
#include <video/sourcemodel.h>
#include <media/video.h>
#include <video/devicemodel.h>
#include <QtCore/QUrl>
#include "../defines.h"
#include <stdlib.h>
#include <atomic>
#include <mutex>
#include <call.h>
#include "xrectsel.h"
static constexpr int VIDEO_LOCAL_SIZE = 150;
static constexpr int VIDEO_LOCAL_OPACITY_DEFAULT = 255; /* out of 255 */
static constexpr const char* JOIN_CALL_KEY = "call_data";
/* check video frame queues at this rate;
* use 30 ms (about 30 fps) since we don't expect to
......@@ -342,48 +345,52 @@ video_widget_init(VideoWidget *self)
self,
NULL);
/* handle button event */
g_signal_connect(GTK_WIDGET(self), "button-press-event", G_CALLBACK(on_button_press_in_screen_event), NULL);
/* drag & drop files as video sources */
gtk_drag_dest_set(GTK_WIDGET(self), GTK_DEST_DEFAULT_ALL, NULL, 0, (GdkDragAction)(GDK_ACTION_COPY | GDK_ACTION_PRIVATE));
gtk_drag_dest_add_uri_targets(GTK_WIDGET(self));
g_signal_connect(GTK_WIDGET(self), "drag-data-received", G_CALLBACK(on_drag_data_received), NULL);
}
/*
* on_drag_data_received()
* video_widget_on_drag_data_received()
*
* Handle dragged data in the video widget window.
* Dropping an image causes the client to switch the video input to that image.
*/
static void
on_drag_data_received(G_GNUC_UNUSED GtkWidget *self,
G_GNUC_UNUSED GdkDragContext *context,
G_GNUC_UNUSED gint x,
G_GNUC_UNUSED gint y,
GtkSelectionData *selection_data,
G_GNUC_UNUSED guint info,
G_GNUC_UNUSED guint32 time,
G_GNUC_UNUSED gpointer data)
void video_widget_on_drag_data_received(G_GNUC_UNUSED GtkWidget *self,
G_GNUC_UNUSED GdkDragContext *context,
G_GNUC_UNUSED gint x,
G_GNUC_UNUSED gint y,
GtkSelectionData *selection_data,
G_GNUC_UNUSED guint info,
G_GNUC_UNUSED guint32 time,
Call *call)
{
g_return_if_fail(call);
gchar **uris = gtk_selection_data_get_uris(selection_data);
/* only play the first selection */
if (uris && *uris)
Video::SourceModel::instance().setFile(QUrl(*uris));
if (uris && *uris){
if (auto out_media = call->firstMedia<Media::Video>(Media::Media::Direction::OUT))
out_media->sourceModel()->setFile(QUrl(*uris));
}
g_strfreev(uris);
}
static void
switch_video_input(G_GNUC_UNUSED GtkWidget *widget, Video::Device *device)
switch_video_input(GtkWidget *widget, Video::Device *device)
{
Video::SourceModel::instance().switchTo(device);
gpointer data = g_object_get_data(G_OBJECT(widget),JOIN_CALL_KEY );
g_return_if_fail(data);
Call *call = (Call*)data;
if (auto out_media = call->firstMedia<Media::Video>(Media::Media::Direction::OUT))
out_media->sourceModel()->switchTo(device);
}
static void
switch_video_input_screen(G_GNUC_UNUSED GtkWidget *item, G_GNUC_UNUSED gpointer user_data)
switch_video_input_screen(G_GNUC_UNUSED GtkWidget *item, Call* call)
{
unsigned x, y;
unsigned width, height;
......@@ -411,11 +418,12 @@ switch_video_input_screen(G_GNUC_UNUSED GtkWidget *item, G_GNUC_UNUSED gpointer
height = gdk_screen_height();
}
Video::SourceModel::instance().setDisplay(display, QRect(x,y,width,height));
if (auto out_media = call->firstMedia<Media::Video>(Media::Media::Direction::OUT))
out_media->sourceModel()->setDisplay(display, QRect(x,y,width,height));
}
static void
switch_video_input_file(G_GNUC_UNUSED GtkWidget *item, GtkWidget *parent)
switch_video_input_file(GtkWidget *item, GtkWidget *parent)
{
if (parent && GTK_IS_WIDGET(parent)) {
/* get parent window */
......@@ -432,24 +440,28 @@ switch_video_input_file(G_GNUC_UNUSED GtkWidget *item, GtkWidget *parent)
NULL);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
Call *call;
gpointer data = g_object_get_data(G_OBJECT(item),JOIN_CALL_KEY );
g_return_if_fail(data);
call = (Call*)data;
uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
Video::SourceModel::instance().setFile(QUrl(uri));
if (auto out_media = call->firstMedia<Media::Video>(Media::Media::Direction::OUT))
out_media->sourceModel()->setFile(QUrl(uri));
}
gtk_widget_destroy(dialog);
g_free(uri);
}
/*
* on_button_press_in_screen_event()
* video_widget_on_button_press_in_screen_event()
*
* Handle button event in the video screen.
*/
static gboolean
on_button_press_in_screen_event(GtkWidget *parent,
GdkEventButton *event,
G_GNUC_UNUSED gpointer data)
gboolean
video_widget_on_button_press_in_screen_event(GtkWidget *parent, GdkEventButton *event, Call* call)
{
/* check for right click */
if (event->button != BUTTON_RIGHT_CLICK || event->type != GDK_BUTTON_PRESS)
......@@ -458,7 +470,14 @@ on_button_press_in_screen_event(GtkWidget *parent,
/* create menu with available video sources */
GtkWidget *menu = gtk_menu_new();
auto active = Video::SourceModel::instance().activeIndex();
Video::SourceModel *sourcemodel = nullptr;
if (auto out_media = call->firstMedia<Media::Video>(Media::Media::Direction::OUT))
sourcemodel = out_media->sourceModel();
if(!sourcemodel)
return FALSE;
auto active = sourcemodel->activeIndex();
/* list available devices and check off the active device */
auto device_list = Video::DeviceModel::instance().devices();
......@@ -466,8 +485,9 @@ on_button_press_in_screen_event(GtkWidget *parent,
for( auto device: device_list) {
GtkWidget *item = gtk_check_menu_item_new_with_mnemonic(device->name().toLocal8Bit().constData());
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
auto device_idx = Video::SourceModel::instance().getDeviceIndex(device);
auto device_idx = sourcemodel->getDeviceIndex(device);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), device_idx == active);
g_object_set_data(G_OBJECT(item), JOIN_CALL_KEY,call);
g_signal_connect(item, "activate", G_CALLBACK(switch_video_input), device);
}
......@@ -478,12 +498,13 @@ on_button_press_in_screen_event(GtkWidget *parent,
GtkWidget *item = gtk_check_menu_item_new_with_mnemonic(_("Share screen area"));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), Video::SourceModel::ExtendedDeviceList::SCREEN == active);
g_signal_connect(item, "activate", G_CALLBACK(switch_video_input_screen), NULL);
g_signal_connect(item, "activate", G_CALLBACK(switch_video_input_screen), call);
/* add file as an input */
item = gtk_check_menu_item_new_with_mnemonic(_("Share file"));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), Video::SourceModel::ExtendedDeviceList::FILE == active);
g_object_set_data(G_OBJECT(item), JOIN_CALL_KEY, call);
g_signal_connect(item, "activate", G_CALLBACK(switch_video_input_file), parent);
/* show menu */
......
......@@ -34,6 +34,8 @@
#include <gtk/gtk.h>
#include <video/renderer.h>
class Call;
G_BEGIN_DECLS
#define VIDEO_WIDGET_TYPE (video_widget_get_type())
......@@ -56,6 +58,17 @@ GType video_widget_get_type (void) G_GNUC_CONST;
GtkWidget* video_widget_new (void);
void video_widget_push_new_renderer (VideoWidget *, Video::Renderer *, VideoRendererType);
void video_widget_pause_rendering (VideoWidget *self, gboolean pause);
void video_widget_on_drag_data_received (GtkWidget *self,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint32 time,
Call* call);
gboolean video_widget_on_button_press_in_screen_event (GtkWidget *parent,
GdkEventButton *event,
Call* call);
G_END_DECLS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment