From 0d4d3f1a8c6ac172d7944e33c55e02eaa3f74155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Wed, 16 Jun 2021 09:43:55 +0200 Subject: [PATCH] sink: Avoid props code duplication --- lib/gst/clapper/gtk4/gstclapperglsink.c | 27 ++------------- lib/gst/clapper/gtk4/gstgtkutils.c | 17 ++++++++++ lib/gst/clapper/gtk4/gstgtkutils.h | 15 +++++++++ lib/gst/clapper/gtk4/gtkclapperglwidget.c | 41 ++++++----------------- 4 files changed, 44 insertions(+), 56 deletions(-) diff --git a/lib/gst/clapper/gtk4/gstclapperglsink.c b/lib/gst/clapper/gtk4/gstclapperglsink.c index d7f6e31b..73ef41dc 100644 --- a/lib/gst/clapper/gtk4/gstclapperglsink.c +++ b/lib/gst/clapper/gtk4/gstclapperglsink.c @@ -37,10 +37,6 @@ GST_DEBUG_CATEGORY (gst_debug_clapper_gl_sink); #define GST_CAT_DEFAULT gst_debug_clapper_gl_sink -#define DEFAULT_FORCE_ASPECT_RATIO TRUE -#define DEFAULT_PAR_N 0 -#define DEFAULT_PAR_D 1 - static GstStaticPadTemplate gst_clapper_gl_sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, @@ -79,14 +75,6 @@ static GstFlowReturn gst_clapper_gl_sink_show_frame (GstVideoSink * bsink, static void gst_clapper_gl_sink_navigation_interface_init (GstNavigationInterface * iface); -enum -{ - PROP_0, - PROP_WIDGET, - PROP_FORCE_ASPECT_RATIO, - PROP_PIXEL_ASPECT_RATIO, -}; - #define gst_clapper_gl_sink_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstClapperGLSink, gst_clapper_gl_sink, GST_TYPE_VIDEO_SINK, @@ -112,6 +100,7 @@ gst_clapper_gl_sink_class_init (GstClapperGLSinkClass * klass) gobject_class->set_property = gst_clapper_gl_sink_set_property; gobject_class->get_property = gst_clapper_gl_sink_get_property; + gobject_class->finalize = gst_clapper_gl_sink_finalize; g_object_class_install_property (gobject_class, PROP_WIDGET, g_param_spec_object ("widget", "GTK Widget", @@ -119,19 +108,7 @@ gst_clapper_gl_sink_class_init (GstClapperGLSinkClass * klass) "(must only be get from the GTK main thread)", GTK_TYPE_WIDGET, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (gobject_class, 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)); - - g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO, - gst_param_spec_fraction ("pixel-aspect-ratio", "Pixel Aspect Ratio", - "The pixel aspect ratio of the device", DEFAULT_PAR_N, DEFAULT_PAR_D, - G_MAXINT, 1, 1, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - gobject_class->finalize = gst_clapper_gl_sink_finalize; + gst_gtk_install_shared_properties (gobject_class); gstelement_class->change_state = gst_clapper_gl_sink_change_state; diff --git a/lib/gst/clapper/gtk4/gstgtkutils.c b/lib/gst/clapper/gtk4/gstgtkutils.c index c730f018..c658a3eb 100644 --- a/lib/gst/clapper/gtk4/gstgtkutils.c +++ b/lib/gst/clapper/gtk4/gstgtkutils.c @@ -19,6 +19,7 @@ * Boston, MA 02110-1301, USA. */ +#include #include "gstgtkutils.h" struct invoke_context @@ -69,3 +70,19 @@ gst_gtk_invoke_on_main (GThreadFunc func, gpointer data) return info.res; } + +void +gst_gtk_install_shared_properties (GObjectClass *gobject_class) +{ + g_object_class_install_property (gobject_class, 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)); + + g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO, + gst_param_spec_fraction ("pixel-aspect-ratio", "Pixel Aspect Ratio", + "The pixel aspect ratio of the device", DEFAULT_PAR_N, DEFAULT_PAR_D, + G_MAXINT, 1, 1, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +} diff --git a/lib/gst/clapper/gtk4/gstgtkutils.h b/lib/gst/clapper/gtk4/gstgtkutils.h index 7584ae2c..4fce7449 100644 --- a/lib/gst/clapper/gtk4/gstgtkutils.h +++ b/lib/gst/clapper/gtk4/gstgtkutils.h @@ -22,8 +22,23 @@ #ifndef __GST_GTK_UTILS_H__ #define __GST_GTK_UTILS_H__ +#define DEFAULT_FORCE_ASPECT_RATIO TRUE +#define DEFAULT_PAR_N 0 +#define DEFAULT_PAR_D 1 + #include +#include + +enum +{ + PROP_0, + PROP_WIDGET, + PROP_FORCE_ASPECT_RATIO, + PROP_PIXEL_ASPECT_RATIO, +}; gpointer gst_gtk_invoke_on_main (GThreadFunc func, gpointer data); +void gst_gtk_install_shared_properties (GObjectClass *gobject_class); + #endif /* __GST_GTK_UTILS_H__ */ diff --git a/lib/gst/clapper/gtk4/gtkclapperglwidget.c b/lib/gst/clapper/gtk4/gtkclapperglwidget.c index 39612dea..ff25433b 100644 --- a/lib/gst/clapper/gtk4/gtkclapperglwidget.c +++ b/lib/gst/clapper/gtk4/gtkclapperglwidget.c @@ -57,10 +57,6 @@ GST_DEBUG_CATEGORY (gst_debug_clapper_gl_widget); #define GST_CAT_DEFAULT gst_debug_clapper_gl_widget -#define DEFAULT_FORCE_ASPECT_RATIO TRUE -#define DEFAULT_PAR_N 0 -#define DEFAULT_PAR_D 1 - struct _GtkClapperGLWidgetPrivate { gboolean initiated; @@ -94,13 +90,6 @@ G_DEFINE_TYPE_WITH_CODE (GtkClapperGLWidget, gtk_clapper_gl_widget, GTK_TYPE_GL_ GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "gtkclapperglwidget", 0, "GTK Clapper GL Widget")); -enum -{ - PROP_0, - PROP_FORCE_ASPECT_RATIO, - PROP_PIXEL_ASPECT_RATIO, -}; - static void gtk_clapper_gl_widget_get_preferred_width (GtkWidget * widget, gint * min, gint * natural) @@ -909,30 +898,20 @@ _get_gl_context (GtkClapperGLWidget * clapper_widget) static void gtk_clapper_gl_widget_class_init (GtkClapperGLWidgetClass * klass) { - GObjectClass *gobject_klass = (GObjectClass *) klass; - GtkWidgetClass *widget_klass = (GtkWidgetClass *) klass; - GtkGLAreaClass *gl_area_klass = (GtkGLAreaClass *) klass; + GObjectClass *gobject_class = (GObjectClass *) klass; + GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; + GtkGLAreaClass *gl_area_class = (GtkGLAreaClass *) klass; - gobject_klass->set_property = gtk_clapper_gl_widget_set_property; - gobject_klass->get_property = gtk_clapper_gl_widget_get_property; - gobject_klass->finalize = gtk_clapper_gl_widget_finalize; + gobject_class->set_property = gtk_clapper_gl_widget_set_property; + gobject_class->get_property = gtk_clapper_gl_widget_get_property; + gobject_class->finalize = gtk_clapper_gl_widget_finalize; - 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_gtk_install_shared_properties (gobject_class); - 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", DEFAULT_PAR_N, DEFAULT_PAR_D, - G_MAXINT, 1, 1, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + widget_class->measure = gtk_clapper_gl_widget_measure; + widget_class->size_allocate = gtk_clapper_gl_widget_size_allocate; - widget_klass->measure = gtk_clapper_gl_widget_measure; - widget_klass->size_allocate = gtk_clapper_gl_widget_size_allocate; - - gl_area_klass->render = gtk_clapper_gl_widget_render; + gl_area_class->render = gtk_clapper_gl_widget_render; } static void