mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
Add new gtkwaylandsink element
This is based on gtksink, but similar to waylandsink uses Wayland APIs directly instead of rendering with Gtk/Cairo primitives. Note that the long term plan is to move this into the existing extension in `-good`, which requires the Wayland library to move the as well. For this reason several files like `gstgtkutils.*` and `gtkgstbasewidget.*` are straight copies and should be kept in sync. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1515>
This commit is contained in:
parent
efb18ec300
commit
7e18fc1b1f
17 changed files with 2756 additions and 0 deletions
|
@ -28438,6 +28438,69 @@
|
|||
"tracers": {},
|
||||
"url": "Unknown package origin"
|
||||
},
|
||||
"gtkwayland": {
|
||||
"description": "Gtk+ wayland sink",
|
||||
"elements": {
|
||||
"gtkwaylandsink": {
|
||||
"author": "George Kiagiadakis <george.kiagiadakis@collabora.com>",
|
||||
"description": "A video sink that renders to a GtkWidget using Wayland API",
|
||||
"hierarchy": [
|
||||
"GstGtkWaylandSink",
|
||||
"GstVideoSink",
|
||||
"GstBaseSink",
|
||||
"GstElement",
|
||||
"GstObject",
|
||||
"GInitiallyUnowned",
|
||||
"GObject"
|
||||
],
|
||||
"interfaces": [
|
||||
"GstNavigation"
|
||||
],
|
||||
"klass": "Sink/Video",
|
||||
"long-name": "Gtk Wayland Video Sink",
|
||||
"pad-templates": {
|
||||
"sink": {
|
||||
"caps": "video/x-raw:\n format: { BGRx, BGRA, RGBx, xBGR, xRGB, RGBA, ABGR, ARGB, RGB, BGR, RGB16, BGR16, YUY2, YVYU, UYVY, AYUV, NV12, NV21, NV16, NV61, YUV9, YVU9, Y41B, I420, YV12, Y42B, v308 }\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n framerate: [ 0/1, 2147483647/1 ]\n\nvideo/x-raw(memory:DMABuf):\n format: { BGRx, BGRA, RGBx, xBGR, xRGB, RGBA, ABGR, ARGB, RGB, BGR, RGB16, BGR16, YUY2, YVYU, UYVY, AYUV, NV12, NV21, NV16, NV61, YUV9, YVU9, Y41B, I420, YV12, Y42B, v308 }\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n framerate: [ 0/1, 2147483647/1 ]\n",
|
||||
"direction": "sink",
|
||||
"presence": "always"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"rotate-method": {
|
||||
"blurb": "rotate method",
|
||||
"conditionally-available": false,
|
||||
"construct": false,
|
||||
"construct-only": false,
|
||||
"controllable": false,
|
||||
"default": "identity (0)",
|
||||
"mutable": "null",
|
||||
"readable": true,
|
||||
"type": "GstVideoOrientationMethod",
|
||||
"writable": true
|
||||
},
|
||||
"widget": {
|
||||
"blurb": "The GtkWidget to place in the widget hierarchy (must only be get from the GTK main thread)",
|
||||
"conditionally-available": false,
|
||||
"construct": false,
|
||||
"construct-only": false,
|
||||
"controllable": false,
|
||||
"mutable": "null",
|
||||
"readable": true,
|
||||
"type": "GtkWidget",
|
||||
"writable": false
|
||||
}
|
||||
},
|
||||
"rank": "marginal"
|
||||
}
|
||||
},
|
||||
"filename": "gstgtkwayland",
|
||||
"license": "LGPL",
|
||||
"other-types": {},
|
||||
"package": "GStreamer Bad Plug-ins",
|
||||
"source": "gst-plugins-bad",
|
||||
"tracers": {},
|
||||
"url": "Unknown package origin"
|
||||
},
|
||||
"hls": {
|
||||
"description": "HTTP Live Streaming (HLS)",
|
||||
"elements": {
|
||||
|
|
71
subprojects/gst-plugins-bad/ext/gtk/gstgtkutils.c
Normal file
71
subprojects/gst-plugins-bad/ext/gtk/gstgtkutils.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
||||
* Copyright (C) 2015 Thibault Saunier <tsaunier@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "gstgtkutils.h"
|
||||
|
||||
struct invoke_context
|
||||
{
|
||||
GThreadFunc func;
|
||||
gpointer data;
|
||||
GMutex lock;
|
||||
GCond cond;
|
||||
gboolean fired;
|
||||
|
||||
gpointer res;
|
||||
};
|
||||
|
||||
static gboolean
|
||||
gst_gtk_invoke_func (struct invoke_context *info)
|
||||
{
|
||||
g_mutex_lock (&info->lock);
|
||||
info->res = info->func (info->data);
|
||||
info->fired = TRUE;
|
||||
g_cond_signal (&info->cond);
|
||||
g_mutex_unlock (&info->lock);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
gpointer
|
||||
gst_gtk_invoke_on_main (GThreadFunc func, gpointer data)
|
||||
{
|
||||
GMainContext *main_context = g_main_context_default ();
|
||||
struct invoke_context info;
|
||||
|
||||
g_mutex_init (&info.lock);
|
||||
g_cond_init (&info.cond);
|
||||
info.fired = FALSE;
|
||||
info.func = func;
|
||||
info.data = data;
|
||||
|
||||
g_main_context_invoke (main_context, (GSourceFunc) gst_gtk_invoke_func,
|
||||
&info);
|
||||
|
||||
g_mutex_lock (&info.lock);
|
||||
while (!info.fired)
|
||||
g_cond_wait (&info.cond, &info.lock);
|
||||
g_mutex_unlock (&info.lock);
|
||||
|
||||
g_mutex_clear (&info.lock);
|
||||
g_cond_clear (&info.cond);
|
||||
|
||||
return info.res;
|
||||
}
|
29
subprojects/gst-plugins-bad/ext/gtk/gstgtkutils.h
Normal file
29
subprojects/gst-plugins-bad/ext/gtk/gstgtkutils.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
||||
* Copyright (C) 2015 Thibault Saunier <tsaunier@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GST_GTK_UTILS_H__
|
||||
#define __GST_GTK_UTILS_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
gpointer gst_gtk_invoke_on_main (GThreadFunc func, gpointer data);
|
||||
|
||||
#endif /* __GST_GTK_UTILS_H__ */
|
1247
subprojects/gst-plugins-bad/ext/gtk/gstgtkwaylandsink.c
Normal file
1247
subprojects/gst-plugins-bad/ext/gtk/gstgtkwaylandsink.c
Normal file
File diff suppressed because it is too large
Load diff
47
subprojects/gst-plugins-bad/ext/gtk/gstgtkwaylandsink.h
Normal file
47
subprojects/gst-plugins-bad/ext/gtk/gstgtkwaylandsink.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2021 Collabora Ltd.
|
||||
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_GTK_WAYLAND_SINK gst_gtk_wayland_sink_get_type ()
|
||||
G_DECLARE_FINAL_TYPE (GstGtkWaylandSink, gst_gtk_wayland_sink, GST, GTK_WAYLAND_SINK, GstVideoSink);
|
||||
|
||||
/**
|
||||
* GstGtkWaylandSink:
|
||||
*
|
||||
* Opaque #GstGtkWaylandSink object
|
||||
*
|
||||
* Since: 1.22
|
||||
*/
|
||||
struct _GstGtkWaylandSink
|
||||
{
|
||||
GstVideoSink parent;
|
||||
};
|
||||
|
||||
GST_ELEMENT_REGISTER_DECLARE (gtkwaylandsink);
|
||||
|
||||
G_END_DECLS
|
48
subprojects/gst-plugins-bad/ext/gtk/gstplugin.c
Normal file
48
subprojects/gst-plugins-bad/ext/gtk/gstplugin.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* plugin-gtkwayland:
|
||||
*
|
||||
* Since: 1.22
|
||||
*/
|
||||
|
||||
#include "gstgtkwaylandsink.h"
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
|
||||
ret |= GST_ELEMENT_REGISTER (gtkwaylandsink, plugin);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
gtkwayland,
|
||||
"Gtk+ wayland sink",
|
||||
plugin_init, PACKAGE_VERSION, GST_LICENSE, GST_PACKAGE_NAME,
|
||||
GST_PACKAGE_ORIGIN)
|
670
subprojects/gst-plugins-bad/ext/gtk/gtkgstbasewidget.c
Normal file
670
subprojects/gst-plugins-bad/ext/gtk/gtkgstbasewidget.c
Normal file
|
@ -0,0 +1,670 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "gtkgstbasewidget.h"
|
||||
|
||||
GST_DEBUG_CATEGORY (gst_debug_gtk_base_widget);
|
||||
#define GST_CAT_DEFAULT gst_debug_gtk_base_widget
|
||||
|
||||
#define DEFAULT_FORCE_ASPECT_RATIO TRUE
|
||||
#define DEFAULT_DISPLAY_PAR_N 0
|
||||
#define DEFAULT_DISPLAY_PAR_D 1
|
||||
#define DEFAULT_VIDEO_PAR_N 0
|
||||
#define DEFAULT_VIDEO_PAR_D 1
|
||||
#define DEFAULT_IGNORE_ALPHA TRUE
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_FORCE_ASPECT_RATIO,
|
||||
PROP_PIXEL_ASPECT_RATIO,
|
||||
PROP_IGNORE_ALPHA,
|
||||
PROP_VIDEO_ASPECT_RATIO_OVERRIDE,
|
||||
};
|
||||
|
||||
static gboolean
|
||||
_calculate_par (GtkGstBaseWidget * widget, GstVideoInfo * info)
|
||||
{
|
||||
gboolean ok;
|
||||
gint width, height;
|
||||
gint par_n, par_d;
|
||||
gint display_par_n, display_par_d;
|
||||
|
||||
width = GST_VIDEO_INFO_WIDTH (info);
|
||||
height = GST_VIDEO_INFO_HEIGHT (info);
|
||||
if (width == 0 || height == 0)
|
||||
return FALSE;
|
||||
|
||||
/* get video's PAR */
|
||||
if (widget->video_par_n != 0 && widget->video_par_d != 0) {
|
||||
par_n = widget->video_par_n;
|
||||
par_d = widget->video_par_d;
|
||||
} else {
|
||||
par_n = GST_VIDEO_INFO_PAR_N (info);
|
||||
par_d = GST_VIDEO_INFO_PAR_D (info);
|
||||
}
|
||||
|
||||
if (!par_n)
|
||||
par_n = 1;
|
||||
|
||||
/* get display's PAR */
|
||||
if (widget->par_n != 0 && widget->par_d != 0) {
|
||||
display_par_n = widget->par_n;
|
||||
display_par_d = widget->par_d;
|
||||
} else {
|
||||
display_par_n = 1;
|
||||
display_par_d = 1;
|
||||
}
|
||||
|
||||
|
||||
ok = gst_video_calculate_display_ratio (&widget->display_ratio_num,
|
||||
&widget->display_ratio_den, width, height, par_n, par_d, display_par_n,
|
||||
display_par_d);
|
||||
|
||||
if (ok) {
|
||||
GST_LOG ("PAR: %u/%u DAR:%u/%u", par_n, par_d, display_par_n,
|
||||
display_par_d);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
_apply_par (GtkGstBaseWidget * widget)
|
||||
{
|
||||
guint display_ratio_num, display_ratio_den;
|
||||
gint width, height;
|
||||
|
||||
width = GST_VIDEO_INFO_WIDTH (&widget->v_info);
|
||||
height = GST_VIDEO_INFO_HEIGHT (&widget->v_info);
|
||||
|
||||
if (!width || !height)
|
||||
return;
|
||||
|
||||
display_ratio_num = widget->display_ratio_num;
|
||||
display_ratio_den = widget->display_ratio_den;
|
||||
|
||||
if (height % display_ratio_den == 0) {
|
||||
GST_DEBUG ("keeping video height");
|
||||
widget->display_width = (guint)
|
||||
gst_util_uint64_scale_int (height, display_ratio_num,
|
||||
display_ratio_den);
|
||||
widget->display_height = height;
|
||||
} else if (width % display_ratio_num == 0) {
|
||||
GST_DEBUG ("keeping video width");
|
||||
widget->display_width = width;
|
||||
widget->display_height = (guint)
|
||||
gst_util_uint64_scale_int (width, display_ratio_den, display_ratio_num);
|
||||
} else {
|
||||
GST_DEBUG ("approximating while keeping video height");
|
||||
widget->display_width = (guint)
|
||||
gst_util_uint64_scale_int (height, display_ratio_num,
|
||||
display_ratio_den);
|
||||
widget->display_height = height;
|
||||
}
|
||||
|
||||
GST_DEBUG ("scaling to %dx%d", widget->display_width, widget->display_height);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_queue_draw (GtkGstBaseWidget * widget)
|
||||
{
|
||||
GTK_GST_BASE_WIDGET_LOCK (widget);
|
||||
widget->draw_id = 0;
|
||||
|
||||
if (widget->pending_resize) {
|
||||
widget->pending_resize = FALSE;
|
||||
|
||||
widget->v_info = widget->pending_v_info;
|
||||
widget->negotiated = TRUE;
|
||||
|
||||
_apply_par (widget);
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (widget));
|
||||
} else {
|
||||
gtk_widget_queue_draw (GTK_WIDGET (widget));
|
||||
}
|
||||
|
||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
_update_par (GtkGstBaseWidget * widget)
|
||||
{
|
||||
GTK_GST_BASE_WIDGET_LOCK (widget);
|
||||
if (widget->pending_resize) {
|
||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_calculate_par (widget, &widget->v_info)) {
|
||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||
return;
|
||||
}
|
||||
|
||||
widget->pending_resize = TRUE;
|
||||
if (!widget->draw_id) {
|
||||
widget->draw_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10,
|
||||
(GSourceFunc) _queue_draw, widget, NULL);
|
||||
}
|
||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_gst_base_widget_get_preferred_width (GtkWidget * widget, gint * min,
|
||||
gint * natural)
|
||||
{
|
||||
GtkGstBaseWidget *gst_widget = (GtkGstBaseWidget *) widget;
|
||||
gint video_width = gst_widget->display_width;
|
||||
|
||||
if (!gst_widget->negotiated)
|
||||
video_width = 10;
|
||||
|
||||
if (min)
|
||||
*min = 1;
|
||||
if (natural)
|
||||
*natural = video_width;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_gst_base_widget_get_preferred_height (GtkWidget * widget, gint * min,
|
||||
gint * natural)
|
||||
{
|
||||
GtkGstBaseWidget *gst_widget = (GtkGstBaseWidget *) widget;
|
||||
gint video_height = gst_widget->display_height;
|
||||
|
||||
if (!gst_widget->negotiated)
|
||||
video_height = 10;
|
||||
|
||||
if (min)
|
||||
*min = 1;
|
||||
if (natural)
|
||||
*natural = video_height;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_gst_base_widget_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GtkGstBaseWidget *gtk_widget = GTK_GST_BASE_WIDGET (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_FORCE_ASPECT_RATIO:
|
||||
gtk_widget->force_aspect_ratio = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_PIXEL_ASPECT_RATIO:
|
||||
gtk_widget->par_n = gst_value_get_fraction_numerator (value);
|
||||
gtk_widget->par_d = gst_value_get_fraction_denominator (value);
|
||||
_update_par (gtk_widget);
|
||||
break;
|
||||
case PROP_VIDEO_ASPECT_RATIO_OVERRIDE:
|
||||
gtk_widget->video_par_n = gst_value_get_fraction_numerator (value);
|
||||
gtk_widget->video_par_d = gst_value_get_fraction_denominator (value);
|
||||
_update_par (gtk_widget);
|
||||
break;
|
||||
case PROP_IGNORE_ALPHA:
|
||||
gtk_widget->ignore_alpha = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_gst_base_widget_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GtkGstBaseWidget *gtk_widget = GTK_GST_BASE_WIDGET (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_FORCE_ASPECT_RATIO:
|
||||
g_value_set_boolean (value, gtk_widget->force_aspect_ratio);
|
||||
break;
|
||||
case PROP_PIXEL_ASPECT_RATIO:
|
||||
gst_value_set_fraction (value, gtk_widget->par_n, gtk_widget->par_d);
|
||||
break;
|
||||
case PROP_VIDEO_ASPECT_RATIO_OVERRIDE:
|
||||
gst_value_set_fraction (value, gtk_widget->video_par_n,
|
||||
gtk_widget->video_par_d);
|
||||
break;
|
||||
case PROP_IGNORE_ALPHA:
|
||||
g_value_set_boolean (value, gtk_widget->ignore_alpha);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
_gdk_key_to_navigation_string (guint keyval)
|
||||
{
|
||||
/* TODO: expand */
|
||||
switch (keyval) {
|
||||
#define KEY(key) case GDK_KEY_ ## key: return G_STRINGIFY(key)
|
||||
KEY (Up);
|
||||
KEY (Down);
|
||||
KEY (Left);
|
||||
KEY (Right);
|
||||
KEY (Home);
|
||||
KEY (End);
|
||||
#undef KEY
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_gst_base_widget_key_event (GtkWidget * widget, GdkEventKey * event)
|
||||
{
|
||||
GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget);
|
||||
GstElement *element;
|
||||
|
||||
if ((element = g_weak_ref_get (&base_widget->element))) {
|
||||
if (GST_IS_NAVIGATION (element)) {
|
||||
const gchar *str = _gdk_key_to_navigation_string (event->keyval);
|
||||
|
||||
if (!str)
|
||||
str = event->string;
|
||||
|
||||
gst_navigation_send_event_simple (GST_NAVIGATION (element),
|
||||
(event->type == GDK_KEY_PRESS) ?
|
||||
gst_navigation_event_new_key_press (str, event->state) :
|
||||
gst_navigation_event_new_key_release (str, event->state));
|
||||
}
|
||||
g_object_unref (element);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
_fit_stream_to_allocated_size (GtkGstBaseWidget * base_widget,
|
||||
GtkAllocation * allocation, GstVideoRectangle * result)
|
||||
{
|
||||
if (base_widget->force_aspect_ratio) {
|
||||
GstVideoRectangle src, dst;
|
||||
|
||||
src.x = 0;
|
||||
src.y = 0;
|
||||
src.w = base_widget->display_width;
|
||||
src.h = base_widget->display_height;
|
||||
|
||||
dst.x = 0;
|
||||
dst.y = 0;
|
||||
dst.w = allocation->width;
|
||||
dst.h = allocation->height;
|
||||
|
||||
gst_video_sink_center_rect (src, dst, result, TRUE);
|
||||
} else {
|
||||
result->x = 0;
|
||||
result->y = 0;
|
||||
result->w = allocation->width;
|
||||
result->h = allocation->height;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_gst_base_widget_display_size_to_stream_size (GtkGstBaseWidget * base_widget,
|
||||
gdouble x, gdouble y, gdouble * stream_x, gdouble * stream_y)
|
||||
{
|
||||
gdouble stream_width, stream_height;
|
||||
GtkAllocation allocation;
|
||||
GstVideoRectangle result;
|
||||
|
||||
gtk_widget_get_allocation (GTK_WIDGET (base_widget), &allocation);
|
||||
_fit_stream_to_allocated_size (base_widget, &allocation, &result);
|
||||
|
||||
stream_width = (gdouble) GST_VIDEO_INFO_WIDTH (&base_widget->v_info);
|
||||
stream_height = (gdouble) GST_VIDEO_INFO_HEIGHT (&base_widget->v_info);
|
||||
|
||||
/* from display coordinates to stream coordinates */
|
||||
if (result.w > 0)
|
||||
*stream_x = (x - result.x) / result.w * stream_width;
|
||||
else
|
||||
*stream_x = 0.;
|
||||
|
||||
/* clip to stream size */
|
||||
if (*stream_x < 0.)
|
||||
*stream_x = 0.;
|
||||
if (*stream_x > GST_VIDEO_INFO_WIDTH (&base_widget->v_info))
|
||||
*stream_x = GST_VIDEO_INFO_WIDTH (&base_widget->v_info);
|
||||
|
||||
/* same for y-axis */
|
||||
if (result.h > 0)
|
||||
*stream_y = (y - result.y) / result.h * stream_height;
|
||||
else
|
||||
*stream_y = 0.;
|
||||
|
||||
if (*stream_y < 0.)
|
||||
*stream_y = 0.;
|
||||
if (*stream_y > GST_VIDEO_INFO_HEIGHT (&base_widget->v_info))
|
||||
*stream_y = GST_VIDEO_INFO_HEIGHT (&base_widget->v_info);
|
||||
|
||||
GST_TRACE ("transform %fx%f into %fx%f", x, y, *stream_x, *stream_y);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_gst_base_widget_button_event (GtkWidget * widget, GdkEventButton * event)
|
||||
{
|
||||
GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget);
|
||||
GstElement *element;
|
||||
|
||||
if ((element = g_weak_ref_get (&base_widget->element))) {
|
||||
if (GST_IS_NAVIGATION (element)) {
|
||||
gst_navigation_send_event_simple (GST_NAVIGATION (element),
|
||||
(event->type == GDK_BUTTON_PRESS) ?
|
||||
gst_navigation_event_new_mouse_button_press (event->button,
|
||||
event->x, event->y, event->state) :
|
||||
gst_navigation_event_new_mouse_button_release (event->button,
|
||||
event->x, event->y, event->state));
|
||||
}
|
||||
g_object_unref (element);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_gst_base_widget_motion_event (GtkWidget * widget, GdkEventMotion * event)
|
||||
{
|
||||
GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget);
|
||||
GstElement *element;
|
||||
|
||||
if ((element = g_weak_ref_get (&base_widget->element))) {
|
||||
if (GST_IS_NAVIGATION (element)) {
|
||||
gst_navigation_send_event_simple (GST_NAVIGATION (element),
|
||||
gst_navigation_event_new_mouse_move (event->x, event->y,
|
||||
event->state));
|
||||
}
|
||||
g_object_unref (element);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_gst_base_widget_scroll_event (GtkWidget * widget, GdkEventScroll * event)
|
||||
{
|
||||
GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget);
|
||||
GstElement *element;
|
||||
|
||||
if ((element = g_weak_ref_get (&base_widget->element))) {
|
||||
if (GST_IS_NAVIGATION (element)) {
|
||||
gdouble x, y, delta_x, delta_y;
|
||||
|
||||
gtk_gst_base_widget_display_size_to_stream_size (base_widget, event->x,
|
||||
event->y, &x, &y);
|
||||
|
||||
if (!gdk_event_get_scroll_deltas ((GdkEvent *) event, &delta_x, &delta_y)) {
|
||||
gdouble offset = 20;
|
||||
|
||||
delta_x = event->delta_x;
|
||||
delta_y = event->delta_y;
|
||||
|
||||
switch (event->direction) {
|
||||
case GDK_SCROLL_UP:
|
||||
delta_y = offset;
|
||||
break;
|
||||
case GDK_SCROLL_DOWN:
|
||||
delta_y = -offset;
|
||||
break;
|
||||
case GDK_SCROLL_LEFT:
|
||||
delta_x = -offset;
|
||||
break;
|
||||
case GDK_SCROLL_RIGHT:
|
||||
delta_x = offset;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
gst_navigation_send_event_simple (GST_NAVIGATION (element),
|
||||
gst_navigation_event_new_mouse_scroll (x, y, delta_x, delta_y,
|
||||
event->state));
|
||||
}
|
||||
g_object_unref (element);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_gst_base_widget_touch_event (GtkWidget * widget, GdkEventTouch * event)
|
||||
{
|
||||
GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget);
|
||||
GstElement *element;
|
||||
|
||||
if ((element = g_weak_ref_get (&base_widget->element))) {
|
||||
if (GST_IS_NAVIGATION (element)) {
|
||||
GstEvent *nav_event;
|
||||
gdouble x, y, p;
|
||||
guint id, i;
|
||||
|
||||
id = GPOINTER_TO_UINT (event->sequence);
|
||||
gtk_gst_base_widget_display_size_to_stream_size (base_widget, event->x,
|
||||
event->y, &x, &y);
|
||||
|
||||
p = NAN;
|
||||
for (i = 0; i < gdk_device_get_n_axes (event->device); i++) {
|
||||
if (gdk_device_get_axis_use (event->device, i) == GDK_AXIS_PRESSURE) {
|
||||
p = event->axes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (event->type) {
|
||||
case GDK_TOUCH_BEGIN:
|
||||
nav_event =
|
||||
gst_navigation_event_new_touch_down (id, x, y, p, event->state);
|
||||
break;
|
||||
case GDK_TOUCH_UPDATE:
|
||||
nav_event =
|
||||
gst_navigation_event_new_touch_motion (id, x, y, p, event->state);
|
||||
break;
|
||||
case GDK_TOUCH_END:
|
||||
case GDK_TOUCH_CANCEL:
|
||||
nav_event =
|
||||
gst_navigation_event_new_touch_up (id, x, y, event->state);
|
||||
break;
|
||||
default:
|
||||
nav_event = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (nav_event)
|
||||
gst_navigation_send_event_simple (GST_NAVIGATION (element), nav_event);
|
||||
}
|
||||
g_object_unref (element);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gtk_gst_base_widget_class_init (GtkGstBaseWidgetClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_klass = (GObjectClass *) klass;
|
||||
GtkWidgetClass *widget_klass = (GtkWidgetClass *) klass;
|
||||
|
||||
gobject_klass->set_property = gtk_gst_base_widget_set_property;
|
||||
gobject_klass->get_property = gtk_gst_base_widget_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_klass, PROP_FORCE_ASPECT_RATIO,
|
||||
g_param_spec_boolean ("force-aspect-ratio",
|
||||
"Force aspect ratio",
|
||||
"When enabled, scaling will respect original aspect ratio",
|
||||
DEFAULT_FORCE_ASPECT_RATIO,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||
GST_PARAM_MUTABLE_PLAYING));
|
||||
|
||||
g_object_class_install_property (gobject_klass, PROP_PIXEL_ASPECT_RATIO,
|
||||
gst_param_spec_fraction ("pixel-aspect-ratio", "Pixel Aspect Ratio",
|
||||
"The pixel aspect ratio of the device",
|
||||
0, 1, G_MAXINT, G_MAXINT, DEFAULT_DISPLAY_PAR_N,
|
||||
DEFAULT_DISPLAY_PAR_D, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||
GST_PARAM_MUTABLE_PLAYING));
|
||||
|
||||
g_object_class_install_property (gobject_klass,
|
||||
PROP_VIDEO_ASPECT_RATIO_OVERRIDE,
|
||||
gst_param_spec_fraction ("video-aspect-ratio-override",
|
||||
"Video Pixel Aspect Ratio",
|
||||
"The pixel aspect ratio of the video (0/1 = follow stream)", 0,
|
||||
G_MAXINT, G_MAXINT, 1, DEFAULT_VIDEO_PAR_N, DEFAULT_VIDEO_PAR_D,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||
GST_PARAM_MUTABLE_PLAYING));
|
||||
|
||||
g_object_class_install_property (gobject_klass, PROP_IGNORE_ALPHA,
|
||||
g_param_spec_boolean ("ignore-alpha", "Ignore Alpha",
|
||||
"When enabled, alpha will be ignored and converted to black",
|
||||
DEFAULT_IGNORE_ALPHA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
widget_klass->get_preferred_width = gtk_gst_base_widget_get_preferred_width;
|
||||
widget_klass->get_preferred_height = gtk_gst_base_widget_get_preferred_height;
|
||||
widget_klass->key_press_event = gtk_gst_base_widget_key_event;
|
||||
widget_klass->key_release_event = gtk_gst_base_widget_key_event;
|
||||
widget_klass->button_press_event = gtk_gst_base_widget_button_event;
|
||||
widget_klass->button_release_event = gtk_gst_base_widget_button_event;
|
||||
widget_klass->motion_notify_event = gtk_gst_base_widget_motion_event;
|
||||
widget_klass->scroll_event = gtk_gst_base_widget_scroll_event;
|
||||
widget_klass->touch_event = gtk_gst_base_widget_touch_event;
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (gst_debug_gtk_base_widget, "gtkbasewidget", 0,
|
||||
"Gtk Video Base Widget");
|
||||
}
|
||||
|
||||
void
|
||||
gtk_gst_base_widget_init (GtkGstBaseWidget * widget)
|
||||
{
|
||||
int event_mask;
|
||||
|
||||
widget->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO;
|
||||
widget->par_n = DEFAULT_DISPLAY_PAR_N;
|
||||
widget->par_d = DEFAULT_DISPLAY_PAR_D;
|
||||
widget->video_par_n = DEFAULT_VIDEO_PAR_N;
|
||||
widget->video_par_d = DEFAULT_VIDEO_PAR_D;
|
||||
widget->ignore_alpha = DEFAULT_IGNORE_ALPHA;
|
||||
|
||||
gst_video_info_init (&widget->v_info);
|
||||
gst_video_info_init (&widget->pending_v_info);
|
||||
|
||||
g_weak_ref_init (&widget->element, NULL);
|
||||
g_mutex_init (&widget->lock);
|
||||
|
||||
gtk_widget_set_can_focus (GTK_WIDGET (widget), TRUE);
|
||||
event_mask = gtk_widget_get_events (GTK_WIDGET (widget));
|
||||
event_mask |= GDK_KEY_PRESS_MASK
|
||||
| GDK_KEY_RELEASE_MASK
|
||||
| GDK_BUTTON_PRESS_MASK
|
||||
| GDK_BUTTON_RELEASE_MASK
|
||||
| GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_SCROLL_MASK
|
||||
| GDK_TOUCH_MASK;
|
||||
gtk_widget_set_events (GTK_WIDGET (widget), event_mask);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_gst_base_widget_finalize (GObject * object)
|
||||
{
|
||||
GtkGstBaseWidget *widget = GTK_GST_BASE_WIDGET (object);
|
||||
|
||||
gst_buffer_replace (&widget->pending_buffer, NULL);
|
||||
gst_buffer_replace (&widget->buffer, NULL);
|
||||
g_mutex_clear (&widget->lock);
|
||||
g_weak_ref_clear (&widget->element);
|
||||
|
||||
if (widget->draw_id)
|
||||
g_source_remove (widget->draw_id);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_gst_base_widget_set_element (GtkGstBaseWidget * widget,
|
||||
GstElement * element)
|
||||
{
|
||||
g_weak_ref_set (&widget->element, element);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_gst_base_widget_set_format (GtkGstBaseWidget * widget,
|
||||
GstVideoInfo * v_info)
|
||||
{
|
||||
GTK_GST_BASE_WIDGET_LOCK (widget);
|
||||
|
||||
if (gst_video_info_is_equal (&widget->pending_v_info, v_info)) {
|
||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!_calculate_par (widget, v_info)) {
|
||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
widget->pending_resize = TRUE;
|
||||
widget->pending_v_info = *v_info;
|
||||
|
||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_gst_base_widget_set_buffer (GtkGstBaseWidget * widget, GstBuffer * buffer)
|
||||
{
|
||||
/* As we have no type, this is better then no check */
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
|
||||
GTK_GST_BASE_WIDGET_LOCK (widget);
|
||||
|
||||
gst_buffer_replace (&widget->pending_buffer, buffer);
|
||||
|
||||
if (!widget->draw_id) {
|
||||
widget->draw_id = g_idle_add_full (G_PRIORITY_DEFAULT,
|
||||
(GSourceFunc) _queue_draw, widget, NULL);
|
||||
}
|
||||
|
||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_gst_base_widget_queue_draw (GtkGstBaseWidget * widget)
|
||||
{
|
||||
/* As we have no type, this is better then no check */
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
|
||||
GTK_GST_BASE_WIDGET_LOCK (widget);
|
||||
|
||||
if (!widget->draw_id) {
|
||||
widget->draw_id = g_idle_add_full (G_PRIORITY_DEFAULT,
|
||||
(GSourceFunc) _queue_draw, widget, NULL);
|
||||
}
|
||||
|
||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||
}
|
102
subprojects/gst-plugins-bad/ext/gtk/gtkgstbasewidget.h
Normal file
102
subprojects/gst-plugins-bad/ext/gtk/gtkgstbasewidget.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_GST_BASE_WIDGET_H__
|
||||
#define __GTK_GST_BASE_WIDGET_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#define GTK_GST_BASE_WIDGET(w) ((GtkGstBaseWidget *)(w))
|
||||
#define GTK_GST_BASE_WIDGET_CLASS(k) ((GtkGstBaseWidgetClass *)(k))
|
||||
#define GTK_GST_BASE_WIDGET_LOCK(w) g_mutex_lock(&((GtkGstBaseWidget*)(w))->lock)
|
||||
#define GTK_GST_BASE_WIDGET_UNLOCK(w) g_mutex_unlock(&((GtkGstBaseWidget*)(w))->lock)
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GtkGstBaseWidget GtkGstBaseWidget;
|
||||
typedef struct _GtkGstBaseWidgetClass GtkGstBaseWidgetClass;
|
||||
|
||||
struct _GtkGstBaseWidget
|
||||
{
|
||||
union {
|
||||
GtkDrawingArea drawing_area;
|
||||
#if GTK_CHECK_VERSION(3, 15, 0)
|
||||
GtkGLArea gl_area;
|
||||
#endif
|
||||
} parent;
|
||||
|
||||
/* properties */
|
||||
gboolean force_aspect_ratio;
|
||||
gint par_n, par_d;
|
||||
gint video_par_n, video_par_d;
|
||||
gboolean ignore_alpha;
|
||||
|
||||
gint display_width;
|
||||
gint display_height;
|
||||
|
||||
gboolean negotiated;
|
||||
GstBuffer *pending_buffer;
|
||||
GstBuffer *buffer;
|
||||
GstVideoInfo v_info;
|
||||
|
||||
/* resize */
|
||||
gboolean pending_resize;
|
||||
GstVideoInfo pending_v_info;
|
||||
guint display_ratio_num;
|
||||
guint display_ratio_den;
|
||||
|
||||
/*< private >*/
|
||||
GMutex lock;
|
||||
GWeakRef element;
|
||||
|
||||
/* Pending draw idles callback */
|
||||
guint draw_id;
|
||||
};
|
||||
|
||||
struct _GtkGstBaseWidgetClass
|
||||
{
|
||||
union {
|
||||
GtkDrawingAreaClass drawing_area_class;
|
||||
#if GTK_CHECK_VERSION(3, 15, 0)
|
||||
GtkGLAreaClass gl_area_class;
|
||||
#endif
|
||||
} parent_class;
|
||||
};
|
||||
|
||||
/* For implementer */
|
||||
void gtk_gst_base_widget_class_init (GtkGstBaseWidgetClass * klass);
|
||||
void gtk_gst_base_widget_init (GtkGstBaseWidget * widget);
|
||||
|
||||
void gtk_gst_base_widget_finalize (GObject * object);
|
||||
|
||||
/* API */
|
||||
gboolean gtk_gst_base_widget_set_format (GtkGstBaseWidget * widget, GstVideoInfo * v_info);
|
||||
void gtk_gst_base_widget_set_buffer (GtkGstBaseWidget * widget, GstBuffer * buffer);
|
||||
void gtk_gst_base_widget_queue_draw (GtkGstBaseWidget * widget);
|
||||
void gtk_gst_base_widget_set_element (GtkGstBaseWidget * widget, GstElement * element);
|
||||
void gtk_gst_base_widget_display_size_to_stream_size (GtkGstBaseWidget * base_widget,
|
||||
gdouble x, gdouble y,
|
||||
gdouble * stream_x, gdouble * stream_y);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_GST_BASE_WIDGET_H__ */
|
66
subprojects/gst-plugins-bad/ext/gtk/gtkgstwaylandwidget.c
Normal file
66
subprojects/gst-plugins-bad/ext/gtk/gtkgstwaylandwidget.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gtkgstwaylandwidget.h"
|
||||
|
||||
/**
|
||||
* SECTION:gtkgstwidget
|
||||
* @title: GtkGstWaylandWidget
|
||||
* @short_description: a #GtkWidget that renders GStreamer video #GstBuffers
|
||||
* @see_also: #GtkDrawingArea, #GstBuffer
|
||||
*
|
||||
* #GtkGstWaylandWidget is an #GtkWidget that renders GStreamer video buffers.
|
||||
*/
|
||||
|
||||
G_DEFINE_TYPE (GtkGstWaylandWidget, gtk_gst_wayland_widget,
|
||||
GTK_TYPE_DRAWING_AREA);
|
||||
|
||||
static void
|
||||
gtk_gst_wayland_widget_finalize (GObject * object)
|
||||
{
|
||||
gtk_gst_base_widget_finalize (object);
|
||||
|
||||
G_OBJECT_CLASS (gtk_gst_wayland_widget_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_gst_wayland_widget_class_init (GtkGstWaylandWidgetClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_klass = (GObjectClass *) klass;
|
||||
|
||||
gtk_gst_base_widget_class_init (GTK_GST_BASE_WIDGET_CLASS (klass));
|
||||
gobject_klass->finalize = gtk_gst_wayland_widget_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_gst_wayland_widget_init (GtkGstWaylandWidget * widget)
|
||||
{
|
||||
gtk_gst_base_widget_init (GTK_GST_BASE_WIDGET (widget));
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gtk_gst_wayland_widget_new (void)
|
||||
{
|
||||
return (GtkWidget *) g_object_new (GTK_TYPE_GST_WAYLAND_WIDGET, NULL);
|
||||
}
|
46
subprojects/gst-plugins-bad/ext/gtk/gtkgstwaylandwidget.h
Normal file
46
subprojects/gst-plugins-bad/ext/gtk/gtkgstwaylandwidget.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include "gtkgstbasewidget.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_GST_WAYLAND_WIDGET gtk_gst_wayland_widget_get_type ()
|
||||
G_DECLARE_FINAL_TYPE (GtkGstWaylandWidget, gtk_gst_wayland_widget, GTK, GST_WAYLAND_WIDGET, GtkDrawingArea);
|
||||
|
||||
/**
|
||||
* GtkGstWaylandWidget:
|
||||
*
|
||||
* Opaque #GtkGstWaylandWidget object
|
||||
*/
|
||||
struct _GtkGstWaylandWidget
|
||||
{
|
||||
/* <private> */
|
||||
GtkGstBaseWidget parent;
|
||||
};
|
||||
|
||||
GtkWidget * gtk_gst_wayland_widget_new (void);
|
||||
|
||||
G_END_DECLS
|
23
subprojects/gst-plugins-bad/ext/gtk/meson.build
Normal file
23
subprojects/gst-plugins-bad/ext/gtk/meson.build
Normal file
|
@ -0,0 +1,23 @@
|
|||
gtkwayland_sources = [
|
||||
'gstplugin.c',
|
||||
'gstgtkutils.c',
|
||||
'gstgtkwaylandsink.c',
|
||||
'gtkgstbasewidget.c',
|
||||
'gtkgstwaylandwidget.c',
|
||||
]
|
||||
|
||||
gtk_dep = dependency('gtk+-3.0', required : get_option('gtk3'))
|
||||
gtk_wayland_dep = dependency('gtk+-wayland-3.0', required : get_option('gtk3'))
|
||||
|
||||
if gtk_dep.found() and gtk_wayland_dep.found() and use_wayland
|
||||
gstgtkwayland = library('gstgtkwayland',
|
||||
gtkwayland_sources,
|
||||
c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API'],
|
||||
include_directories : [configinc],
|
||||
dependencies : [gtk_dep, gstvideo_dep, gstwayland_dep],
|
||||
install : true,
|
||||
install_dir : plugins_install_dir,
|
||||
)
|
||||
pkgconfig.generate(gstgtkwayland, install_dir : plugins_pkgconfig_install_dir)
|
||||
plugins += [gstgtkwayland]
|
||||
endif
|
|
@ -21,6 +21,7 @@ subdir('fluidsynth')
|
|||
subdir('gme')
|
||||
subdir('gs')
|
||||
subdir('gsm')
|
||||
subdir('gtk')
|
||||
subdir('hls')
|
||||
subdir('iqa')
|
||||
subdir('isac')
|
||||
|
|
|
@ -114,6 +114,7 @@ option('gl', type : 'feature', value : 'auto', description : 'GStreamer OpenGL i
|
|||
option('gme', type : 'feature', value : 'auto', description : 'libgme gaming console music file decoder plugin')
|
||||
option('gs', type : 'feature', value : 'auto', description : 'Google Cloud Storage source and sink plugin')
|
||||
option('gsm', type : 'feature', value : 'auto', description : 'GSM encoder/decoder plugin')
|
||||
option('gtk3', type : 'feature', value : 'auto', description : 'GTK+ video sink plugin')
|
||||
option('ipcpipeline', type : 'feature', value : 'auto', description : 'Inter-process communication plugin')
|
||||
option('iqa', type : 'feature', value : 'auto', description : 'Image quality assessment plugin (AGPL - only built if gpl option is also enabled!)')
|
||||
option('kate', type : 'feature', value : 'auto', description : 'Kate subtitle parser, tagger, and codec plugin')
|
||||
|
|
247
subprojects/gst-plugins-bad/tests/examples/gtk/gtkwaylandsink.c
Normal file
247
subprojects/gst-plugins-bad/tests/examples/gtk/gtkwaylandsink.c
Normal file
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2021 Collabora Ltd.
|
||||
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static gboolean live = FALSE;
|
||||
static gboolean scrollable = FALSE;
|
||||
|
||||
static GOptionEntry entries[] = {
|
||||
{"live", 'l', 0, G_OPTION_ARG_NONE, &live, "Use a live source", NULL},
|
||||
{"scrollable", 's', 0, G_OPTION_ARG_NONE, &scrollable,
|
||||
"Put the GtkWaylandSink into a GtkScrolledWindow ", NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GtkWidget *app_widget;
|
||||
|
||||
GstElement *pipeline;
|
||||
|
||||
gchar **argv;
|
||||
gint current_uri; /* index for argv */
|
||||
|
||||
gboolean is_fullscreen;
|
||||
} DemoApp;
|
||||
|
||||
static void
|
||||
on_about_to_finish (GstElement * playbin, DemoApp * d)
|
||||
{
|
||||
if (d->argv[++d->current_uri] == NULL)
|
||||
d->current_uri = 1;
|
||||
|
||||
g_print ("Now playing %s\n", d->argv[d->current_uri]);
|
||||
g_object_set (playbin, "uri", d->argv[d->current_uri], NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
error_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
|
||||
{
|
||||
DemoApp *d = user_data;
|
||||
gchar *debug = NULL;
|
||||
GError *err = NULL;
|
||||
|
||||
gst_message_parse_error (msg, &err, &debug);
|
||||
|
||||
g_print ("Error: %s\n", err->message);
|
||||
g_error_free (err);
|
||||
|
||||
if (debug) {
|
||||
g_print ("Debug details: %s\n", debug);
|
||||
g_free (debug);
|
||||
}
|
||||
|
||||
gst_element_set_state (d->pipeline, GST_STATE_NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
video_widget_button_pressed_cb (GtkWidget * widget,
|
||||
GdkEventButton * eventButton, DemoApp * d)
|
||||
{
|
||||
if (eventButton->type == GDK_2BUTTON_PRESS) {
|
||||
if (d->is_fullscreen) {
|
||||
gtk_window_unfullscreen (GTK_WINDOW (d->app_widget));
|
||||
d->is_fullscreen = FALSE;
|
||||
} else {
|
||||
gtk_window_fullscreen (GTK_WINDOW (d->app_widget));
|
||||
d->is_fullscreen = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
playing_clicked_cb (GtkButton * button, DemoApp * d)
|
||||
{
|
||||
gst_element_set_state (d->pipeline, GST_STATE_PLAYING);
|
||||
}
|
||||
|
||||
static void
|
||||
paused_clicked_cb (GtkButton * button, DemoApp * d)
|
||||
{
|
||||
gst_element_set_state (d->pipeline, GST_STATE_PAUSED);
|
||||
}
|
||||
|
||||
static void
|
||||
ready_clicked_cb (GtkButton * button, DemoApp * d)
|
||||
{
|
||||
gst_element_set_state (d->pipeline, GST_STATE_READY);
|
||||
}
|
||||
|
||||
static void
|
||||
null_clicked_cb (GtkButton * button, DemoApp * d)
|
||||
{
|
||||
gst_element_set_state (d->pipeline, GST_STATE_NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
build_window (DemoApp * d)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GstElement *sink;
|
||||
GtkWidget *box;
|
||||
GtkWidget *widget;
|
||||
GError *error = NULL;
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
if (!gtk_builder_add_from_file (builder, "window.ui", &error)) {
|
||||
g_error ("Failed to load window.ui: %s", error->message);
|
||||
g_error_free (error);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
d->app_widget = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
||||
g_object_ref (d->app_widget);
|
||||
g_signal_connect (d->app_widget, "destroy", G_CALLBACK (gtk_main_quit), NULL);
|
||||
|
||||
box = GTK_WIDGET (gtk_builder_get_object (builder, "box"));
|
||||
sink = gst_bin_get_by_name (GST_BIN (d->pipeline), "vsink");
|
||||
if (!sink && !g_strcmp0 (G_OBJECT_TYPE_NAME (d->pipeline), "GstPlayBin")) {
|
||||
g_object_get (d->pipeline, "video-sink", &sink, NULL);
|
||||
if (sink && g_strcmp0 (G_OBJECT_TYPE_NAME (sink), "GstGtkWaylandSink") != 0
|
||||
&& GST_IS_BIN (sink)) {
|
||||
GstBin *sinkbin = GST_BIN (sink);
|
||||
sink = gst_bin_get_by_name (sinkbin, "vsink");
|
||||
gst_object_unref (sinkbin);
|
||||
}
|
||||
}
|
||||
g_assert (sink);
|
||||
|
||||
g_object_get (sink, "widget", &widget, NULL);
|
||||
if (scrollable) {
|
||||
GtkWidget *scrollable;
|
||||
scrollable = gtk_scrolled_window_new (NULL, NULL);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (scrollable), widget);
|
||||
g_object_unref (widget);
|
||||
widget = scrollable;
|
||||
}
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (box), widget, TRUE, TRUE, 0);
|
||||
gtk_box_reorder_child (GTK_BOX (box), widget, 0);
|
||||
|
||||
g_signal_connect (widget, "button-press-event",
|
||||
G_CALLBACK (video_widget_button_pressed_cb), d);
|
||||
if (!scrollable)
|
||||
g_object_unref (widget);
|
||||
g_object_unref (sink);
|
||||
|
||||
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_playing"));
|
||||
g_signal_connect (widget, "clicked", G_CALLBACK (playing_clicked_cb), d);
|
||||
|
||||
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_paused"));
|
||||
g_signal_connect (widget, "clicked", G_CALLBACK (paused_clicked_cb), d);
|
||||
|
||||
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_ready"));
|
||||
g_signal_connect (widget, "clicked", G_CALLBACK (ready_clicked_cb), d);
|
||||
|
||||
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_null"));
|
||||
g_signal_connect (widget, "clicked", G_CALLBACK (null_clicked_cb), d);
|
||||
|
||||
gtk_widget_show_all (d->app_widget);
|
||||
|
||||
exit:
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
DemoApp *d;
|
||||
GOptionContext *context;
|
||||
GstBus *bus;
|
||||
GError *error = NULL;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
context = g_option_context_new ("- gtkwaylandsink demo");
|
||||
g_option_context_add_main_entries (context, entries, NULL);
|
||||
if (!g_option_context_parse (context, &argc, &argv, &error)) {
|
||||
g_printerr ("option parsing failed: %s\n", error->message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
d = g_slice_new0 (DemoApp);
|
||||
|
||||
if (argc > 1) {
|
||||
d->argv = argv;
|
||||
d->current_uri = 1;
|
||||
|
||||
d->pipeline =
|
||||
gst_parse_launch ("playbin video-sink=\"gtkwaylandsink name=vsink\"",
|
||||
NULL);
|
||||
g_object_set (d->pipeline, "uri", argv[d->current_uri], NULL);
|
||||
|
||||
/* enable looping */
|
||||
g_signal_connect (d->pipeline, "about-to-finish",
|
||||
G_CALLBACK (on_about_to_finish), d);
|
||||
} else {
|
||||
if (live) {
|
||||
d->pipeline = gst_parse_launch ("videotestsrc pattern=18 "
|
||||
"background-color=0xFF0062FF is-live=true ! "
|
||||
"gtkwaylandsink name=vsink", NULL);
|
||||
} else {
|
||||
d->pipeline = gst_parse_launch ("videotestsrc pattern=18 "
|
||||
"background-color=0xFF0062FF ! gtkwaylandsink name=vsink", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
build_window (d);
|
||||
|
||||
bus = gst_pipeline_get_bus (GST_PIPELINE (d->pipeline));
|
||||
gst_bus_add_signal_watch (bus);
|
||||
g_signal_connect (bus, "message::error", G_CALLBACK (error_cb), d);
|
||||
gst_object_unref (bus);
|
||||
|
||||
gst_element_set_state (d->pipeline, GST_STATE_PLAYING);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
gst_element_set_state (d->pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (d->pipeline);
|
||||
g_object_unref (d->app_widget);
|
||||
g_slice_free (DemoApp, d);
|
||||
|
||||
return 0;
|
||||
}
|
10
subprojects/gst-plugins-bad/tests/examples/gtk/meson.build
Normal file
10
subprojects/gst-plugins-bad/tests/examples/gtk/meson.build
Normal file
|
@ -0,0 +1,10 @@
|
|||
if gtk_dep.found() and gtk_wayland_dep.found() and use_wayland
|
||||
executable('gtkwaylandsink',
|
||||
'gtkwaylandsink.c',
|
||||
extra_files: ['window.ui'],
|
||||
install: false,
|
||||
include_directories : [configinc],
|
||||
dependencies : [gtk_dep, gst_dep],
|
||||
c_args : gst_plugins_bad_args,
|
||||
)
|
||||
endif
|
84
subprojects/gst-plugins-bad/tests/examples/gtk/window.ui
Normal file
84
subprojects/gst-plugins-bad/tests/examples/gtk/window.ui
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.38.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.0"/>
|
||||
<object class="GtkWindow" id="window">
|
||||
<property name="can-focus">False</property>
|
||||
<property name="title" translatable="yes">GStreamer Wayland GTK Demo</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="box">
|
||||
<property name="height-request">300</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButtonBox" id="buttonbox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="layout-style">center</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="button_playing">
|
||||
<property name="label" translatable="yes">PLAYING</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button_paused">
|
||||
<property name="label" translatable="yes">PAUSED</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button_ready">
|
||||
<property name="label" translatable="yes">READY</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button_null">
|
||||
<property name="label" translatable="yes">NULL</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
|
@ -4,6 +4,7 @@ subdir('camerabin2')
|
|||
subdir('codecparsers')
|
||||
subdir('d3d11')
|
||||
subdir('directfb')
|
||||
subdir('gtk')
|
||||
subdir('ipcpipeline')
|
||||
subdir('mediafoundation')
|
||||
subdir('mpegts')
|
||||
|
|
Loading…
Reference in a new issue