debugutils: De-duplicate proxy_properties function to a new utils module
authorPhilippe Normand <philn@igalia.com>
Fri, 23 Jul 2021 08:36:10 +0000 (09:36 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 26 Jul 2021 15:36:48 +0000 (15:36 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2426>

gst/debugutils/gstfakeaudiosink.c
gst/debugutils/gstfakesinkutils.c [new file with mode: 0644]
gst/debugutils/gstfakesinkutils.h [new file with mode: 0644]
gst/debugutils/gstfakevideosink.c
gst/debugutils/meson.build

index 8955345..ef736eb 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "gstdebugutilsbadelements.h"
 #include "gstfakeaudiosink.h"
+#include "gstfakesinkutils.h"
 
 #include <gst/audio/audio.h>
 
@@ -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 (file)
index 0000000..46ac983
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * GStreamer
+ * Copyright (C) 2017 Collabora Inc.
+ *   Author: Nicolas Dufresne <nicolas.dufresne@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 "gstfakesinkutils.h"
+#include <gst/base/gstbasesink.h>
+
+/* 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 (file)
index 0000000..ca8231f
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * GStreamer
+ * Copyright (C) 2017 Collabora Inc.
+ *   Author: Nicolas Dufresne <nicolas.dufresne@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.
+ */
+
+#ifndef __GST_FAKE_SINK_UTILS_H__
+#define __GST_FAKE_SINK_UTILS_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+void gst_fake_sink_proxy_properties (GstElement * self, GstElement * child, guint property_id_offset);
+
+G_END_DECLS
+
+#endif
index c524ccf..837a765 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "gstdebugutilsbadelements.h"
 #include "gstfakevideosink.h"
+#include "gstfakesinkutils.h"
 
 #include <gst/video/video.h>
 
@@ -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 <nicolas.dufresne@collabora.com>");
 
+  /**
+   * 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);
 }
index 9af3578..fc31f10 100644 (file)
@@ -8,6 +8,7 @@ debugutilsbad_sources = [
   'gstdebugspy.c',
   'gsterrorignore.c',
   'gstfakeaudiosink.c',
+  'gstfakesinkutils.c',
   'gstfakevideosink.c',
   'gsttestsrcbin.c',
   'gstvideocodectestsink.c',