From a4aa2af291ca493cc79d764f54e1b9db71fbd857 Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Fri, 23 Jul 2021 09:36:10 +0100 Subject: [PATCH] debugutils: De-duplicate proxy_properties function to a new utils module Part-of: --- gst/debugutils/gstfakeaudiosink.c | 94 +---------------------- gst/debugutils/gstfakesinkutils.c | 109 ++++++++++++++++++++++++++ gst/debugutils/gstfakesinkutils.h | 33 ++++++++ gst/debugutils/gstfakevideosink.c | 123 ++++-------------------------- gst/debugutils/meson.build | 1 + 5 files changed, 161 insertions(+), 199 deletions(-) create mode 100644 gst/debugutils/gstfakesinkutils.c create mode 100644 gst/debugutils/gstfakesinkutils.h diff --git a/gst/debugutils/gstfakeaudiosink.c b/gst/debugutils/gstfakeaudiosink.c index 89553456f6..ef736eb243 100644 --- a/gst/debugutils/gstfakeaudiosink.c +++ b/gst/debugutils/gstfakeaudiosink.c @@ -39,6 +39,7 @@ #include "gstdebugutilsbadelements.h" #include "gstfakeaudiosink.h" +#include "gstfakesinkutils.h" #include @@ -61,97 +62,6 @@ G_DEFINE_TYPE_WITH_CODE (GstFakeAudioSink, gst_fake_audio_sink, GST_TYPE_BIN, GST_ELEMENT_REGISTER_DEFINE (fakeaudiosink, "fakeaudiosink", GST_RANK_NONE, gst_fake_audio_sink_get_type ()); -/* TODO complete the types and make this an utility */ -static void -gst_fake_audio_sink_proxy_properties (GstFakeAudioSink * self, - GstElement * child) -{ - static gsize initialized = 0; - - if (g_once_init_enter (&initialized)) { - GObjectClass *object_class; - GParamSpec **properties; - guint n_properties, i; - - object_class = G_OBJECT_CLASS (GST_FAKE_AUDIO_SINK_GET_CLASS (self)); - properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (child), - &n_properties); - - for (i = 0; i < n_properties; i++) { - guint property_id = i + PROP_LAST; - - if (properties[i]->owner_type != G_OBJECT_TYPE (child) && - properties[i]->owner_type != GST_TYPE_BASE_SINK) - continue; - - if (G_IS_PARAM_SPEC_BOOLEAN (properties[i])) { - GParamSpecBoolean *prop = G_PARAM_SPEC_BOOLEAN (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_boolean (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->default_value, properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_INT (properties[i])) { - GParamSpecInt *prop = G_PARAM_SPEC_INT (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_int (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->minimum, prop->maximum, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_UINT (properties[i])) { - GParamSpecUInt *prop = G_PARAM_SPEC_UINT (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_uint (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->minimum, prop->maximum, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_INT64 (properties[i])) { - GParamSpecInt64 *prop = G_PARAM_SPEC_INT64 (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_int64 (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->minimum, prop->maximum, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_UINT64 (properties[i])) { - GParamSpecUInt64 *prop = G_PARAM_SPEC_UINT64 (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_uint64 (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->minimum, prop->maximum, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_ENUM (properties[i])) { - GParamSpecEnum *prop = G_PARAM_SPEC_ENUM (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_enum (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - properties[i]->value_type, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_STRING (properties[i])) { - GParamSpecString *prop = G_PARAM_SPEC_STRING (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_string (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->default_value, properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_BOXED (properties[i])) { - g_object_class_install_property (object_class, property_id, - g_param_spec_boxed (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - properties[i]->value_type, properties[i]->flags)); - } - } - - g_free (properties); - g_once_init_leave (&initialized, 1); - } -} - static void gst_fake_audio_sink_init (GstFakeAudioSink * self) { @@ -179,7 +89,7 @@ gst_fake_audio_sink_init (GstFakeAudioSink * self) self->child = child; - gst_fake_audio_sink_proxy_properties (self, child); + gst_fake_sink_proxy_properties (GST_ELEMENT_CAST (self), child, PROP_LAST); } else { g_warning ("Check your GStreamer installation, " "core element 'fakesink' is missing."); diff --git a/gst/debugutils/gstfakesinkutils.c b/gst/debugutils/gstfakesinkutils.c new file mode 100644 index 0000000000..46ac9830f4 --- /dev/null +++ b/gst/debugutils/gstfakesinkutils.c @@ -0,0 +1,109 @@ +/* + * GStreamer + * Copyright (C) 2017 Collabora Inc. + * Author: Nicolas Dufresne + * + * 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 "gstfakesinkutils.h" +#include + +/* TODO complete the types */ +void +gst_fake_sink_proxy_properties (GstElement * self, + GstElement * child, guint property_id_offset) +{ + GObjectClass *object_class; + GParamSpec **properties; + guint n_properties, i; + + object_class = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (self)); + properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (child), + &n_properties); + + for (i = 0; i < n_properties; i++) { + guint property_id = i + property_id_offset; + + if (properties[i]->owner_type != G_OBJECT_TYPE (child) && + properties[i]->owner_type != GST_TYPE_BASE_SINK) + continue; + + if (G_IS_PARAM_SPEC_BOOLEAN (properties[i])) { + GParamSpecBoolean *prop = G_PARAM_SPEC_BOOLEAN (properties[i]); + g_object_class_install_property (object_class, property_id, + g_param_spec_boolean (g_param_spec_get_name (properties[i]), + g_param_spec_get_nick (properties[i]), + g_param_spec_get_blurb (properties[i]), + prop->default_value, properties[i]->flags)); + } else if (G_IS_PARAM_SPEC_INT (properties[i])) { + GParamSpecInt *prop = G_PARAM_SPEC_INT (properties[i]); + g_object_class_install_property (object_class, property_id, + g_param_spec_int (g_param_spec_get_name (properties[i]), + g_param_spec_get_nick (properties[i]), + g_param_spec_get_blurb (properties[i]), + prop->minimum, prop->maximum, prop->default_value, + properties[i]->flags)); + } else if (G_IS_PARAM_SPEC_UINT (properties[i])) { + GParamSpecUInt *prop = G_PARAM_SPEC_UINT (properties[i]); + g_object_class_install_property (object_class, property_id, + g_param_spec_uint (g_param_spec_get_name (properties[i]), + g_param_spec_get_nick (properties[i]), + g_param_spec_get_blurb (properties[i]), + prop->minimum, prop->maximum, prop->default_value, + properties[i]->flags)); + } else if (G_IS_PARAM_SPEC_INT64 (properties[i])) { + GParamSpecInt64 *prop = G_PARAM_SPEC_INT64 (properties[i]); + g_object_class_install_property (object_class, property_id, + g_param_spec_int64 (g_param_spec_get_name (properties[i]), + g_param_spec_get_nick (properties[i]), + g_param_spec_get_blurb (properties[i]), + prop->minimum, prop->maximum, prop->default_value, + properties[i]->flags)); + } else if (G_IS_PARAM_SPEC_UINT64 (properties[i])) { + GParamSpecUInt64 *prop = G_PARAM_SPEC_UINT64 (properties[i]); + g_object_class_install_property (object_class, property_id, + g_param_spec_uint64 (g_param_spec_get_name (properties[i]), + g_param_spec_get_nick (properties[i]), + g_param_spec_get_blurb (properties[i]), + prop->minimum, prop->maximum, prop->default_value, + properties[i]->flags)); + } else if (G_IS_PARAM_SPEC_ENUM (properties[i])) { + GParamSpecEnum *prop = G_PARAM_SPEC_ENUM (properties[i]); + g_object_class_install_property (object_class, property_id, + g_param_spec_enum (g_param_spec_get_name (properties[i]), + g_param_spec_get_nick (properties[i]), + g_param_spec_get_blurb (properties[i]), + properties[i]->value_type, prop->default_value, + properties[i]->flags)); + } else if (G_IS_PARAM_SPEC_STRING (properties[i])) { + GParamSpecString *prop = G_PARAM_SPEC_STRING (properties[i]); + g_object_class_install_property (object_class, property_id, + g_param_spec_string (g_param_spec_get_name (properties[i]), + g_param_spec_get_nick (properties[i]), + g_param_spec_get_blurb (properties[i]), + prop->default_value, properties[i]->flags)); + } else if (G_IS_PARAM_SPEC_BOXED (properties[i])) { + g_object_class_install_property (object_class, property_id, + g_param_spec_boxed (g_param_spec_get_name (properties[i]), + g_param_spec_get_nick (properties[i]), + g_param_spec_get_blurb (properties[i]), + properties[i]->value_type, properties[i]->flags)); + } + } + + g_free (properties); +} diff --git a/gst/debugutils/gstfakesinkutils.h b/gst/debugutils/gstfakesinkutils.h new file mode 100644 index 0000000000..ca8231f314 --- /dev/null +++ b/gst/debugutils/gstfakesinkutils.h @@ -0,0 +1,33 @@ +/* + * GStreamer + * Copyright (C) 2017 Collabora Inc. + * Author: Nicolas Dufresne + * + * 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_FAKE_SINK_UTILS_H__ +#define __GST_FAKE_SINK_UTILS_H__ + +#include + +G_BEGIN_DECLS + +void gst_fake_sink_proxy_properties (GstElement * self, GstElement * child, guint property_id_offset); + +G_END_DECLS + +#endif diff --git a/gst/debugutils/gstfakevideosink.c b/gst/debugutils/gstfakevideosink.c index c524ccfe63..837a765845 100644 --- a/gst/debugutils/gstfakevideosink.c +++ b/gst/debugutils/gstfakevideosink.c @@ -39,6 +39,7 @@ #include "gstdebugutilsbadelements.h" #include "gstfakevideosink.h" +#include "gstfakesinkutils.h" #include @@ -126,112 +127,6 @@ gst_fake_video_sink_query (GstPad * pad, GstObject * parent, GstQuery * query) return TRUE; } -/* TODO complete the types and make this an utility */ -static void -gst_fake_video_sink_proxy_properties (GstFakeVideoSink * self, - GstElement * child) -{ - static gsize initialized = 0; - - if (g_once_init_enter (&initialized)) { - GObjectClass *object_class; - GParamSpec **properties; - guint n_properties, i; - - object_class = G_OBJECT_CLASS (GST_FAKE_VIDEO_SINK_GET_CLASS (self)); - properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (child), - &n_properties); - - /** - * GstFakeVideoSink:allocation-meta-flags - * - * Control the behaviour of the sink allocation query handler. - * - * Since: 1.18 - */ - g_object_class_install_property (object_class, PROP_ALLOCATION_META_FLAGS, - g_param_spec_flags ("allocation-meta-flags", "Flags", - "Flags to control behaviour", - GST_TYPE_FAKE_VIDEO_SINK_ALLOCATION_META_FLAGS, - ALLOCATION_META_DEFAULT_FLAGS, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - - for (i = 0; i < n_properties; i++) { - guint property_id = i + PROP_LAST; - - if (properties[i]->owner_type != G_OBJECT_TYPE (child) && - properties[i]->owner_type != GST_TYPE_BASE_SINK) - continue; - - if (G_IS_PARAM_SPEC_BOOLEAN (properties[i])) { - GParamSpecBoolean *prop = G_PARAM_SPEC_BOOLEAN (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_boolean (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->default_value, properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_INT (properties[i])) { - GParamSpecInt *prop = G_PARAM_SPEC_INT (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_int (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->minimum, prop->maximum, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_UINT (properties[i])) { - GParamSpecUInt *prop = G_PARAM_SPEC_UINT (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_uint (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->minimum, prop->maximum, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_INT64 (properties[i])) { - GParamSpecInt64 *prop = G_PARAM_SPEC_INT64 (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_int64 (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->minimum, prop->maximum, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_UINT64 (properties[i])) { - GParamSpecUInt64 *prop = G_PARAM_SPEC_UINT64 (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_uint64 (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->minimum, prop->maximum, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_ENUM (properties[i])) { - GParamSpecEnum *prop = G_PARAM_SPEC_ENUM (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_enum (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - properties[i]->value_type, prop->default_value, - properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_STRING (properties[i])) { - GParamSpecString *prop = G_PARAM_SPEC_STRING (properties[i]); - g_object_class_install_property (object_class, property_id, - g_param_spec_string (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - prop->default_value, properties[i]->flags)); - } else if (G_IS_PARAM_SPEC_BOXED (properties[i])) { - g_object_class_install_property (object_class, property_id, - g_param_spec_boxed (g_param_spec_get_name (properties[i]), - g_param_spec_get_nick (properties[i]), - g_param_spec_get_blurb (properties[i]), - properties[i]->value_type, properties[i]->flags)); - } - } - - g_free (properties); - g_once_init_leave (&initialized, 1); - } -} - static void gst_fake_video_sink_init (GstFakeVideoSink * self) { @@ -262,7 +157,7 @@ gst_fake_video_sink_init (GstFakeVideoSink * self) self->child = child; - gst_fake_video_sink_proxy_properties (self, child); + gst_fake_sink_proxy_properties (GST_ELEMENT_CAST (self), child, PROP_LAST); } else { g_warning ("Check your GStreamer installation, " "core element 'fakesink' is missing."); @@ -319,6 +214,20 @@ gst_fake_video_sink_class_init (GstFakeVideoSinkClass * klass) "Video/Sink", "Fake video display that allows zero-copy", "Nicolas Dufresne "); + /** + * GstFakeVideoSink:allocation-meta-flags + * + * Control the behaviour of the sink allocation query handler. + * + * Since: 1.18 + */ + g_object_class_install_property (object_class, PROP_ALLOCATION_META_FLAGS, + g_param_spec_flags ("allocation-meta-flags", "Flags", + "Flags to control behaviour", + GST_TYPE_FAKE_VIDEO_SINK_ALLOCATION_META_FLAGS, + ALLOCATION_META_DEFAULT_FLAGS, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gst_type_mark_as_plugin_api (GST_TYPE_FAKE_VIDEO_SINK_ALLOCATION_META_FLAGS, 0); } diff --git a/gst/debugutils/meson.build b/gst/debugutils/meson.build index 9af3578cdd..fc31f104c5 100644 --- a/gst/debugutils/meson.build +++ b/gst/debugutils/meson.build @@ -8,6 +8,7 @@ debugutilsbad_sources = [ 'gstdebugspy.c', 'gsterrorignore.c', 'gstfakeaudiosink.c', + 'gstfakesinkutils.c', 'gstfakevideosink.c', 'gsttestsrcbin.c', 'gstvideocodectestsink.c',