debugutils: De-duplicate proxy_properties function to a new utils module

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2426>
This commit is contained in:
Philippe Normand 2021-07-23 09:36:10 +01:00 committed by GStreamer Marge Bot
parent dc787434bc
commit a4aa2af291
5 changed files with 161 additions and 199 deletions

View file

@ -39,6 +39,7 @@
#include "gstdebugutilsbadelements.h" #include "gstdebugutilsbadelements.h"
#include "gstfakeaudiosink.h" #include "gstfakeaudiosink.h"
#include "gstfakesinkutils.h"
#include <gst/audio/audio.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_ELEMENT_REGISTER_DEFINE (fakeaudiosink, "fakeaudiosink",
GST_RANK_NONE, gst_fake_audio_sink_get_type ()); 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 static void
gst_fake_audio_sink_init (GstFakeAudioSink * self) gst_fake_audio_sink_init (GstFakeAudioSink * self)
{ {
@ -179,7 +89,7 @@ gst_fake_audio_sink_init (GstFakeAudioSink * self)
self->child = child; self->child = child;
gst_fake_audio_sink_proxy_properties (self, child); gst_fake_sink_proxy_properties (GST_ELEMENT_CAST (self), child, PROP_LAST);
} else { } else {
g_warning ("Check your GStreamer installation, " g_warning ("Check your GStreamer installation, "
"core element 'fakesink' is missing."); "core element 'fakesink' is missing.");

View file

@ -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);
}

View file

@ -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

View file

@ -39,6 +39,7 @@
#include "gstdebugutilsbadelements.h" #include "gstdebugutilsbadelements.h"
#include "gstfakevideosink.h" #include "gstfakevideosink.h"
#include "gstfakesinkutils.h"
#include <gst/video/video.h> #include <gst/video/video.h>
@ -126,112 +127,6 @@ gst_fake_video_sink_query (GstPad * pad, GstObject * parent, GstQuery * query)
return TRUE; 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 static void
gst_fake_video_sink_init (GstFakeVideoSink * self) gst_fake_video_sink_init (GstFakeVideoSink * self)
{ {
@ -262,7 +157,7 @@ gst_fake_video_sink_init (GstFakeVideoSink * self)
self->child = child; self->child = child;
gst_fake_video_sink_proxy_properties (self, child); gst_fake_sink_proxy_properties (GST_ELEMENT_CAST (self), child, PROP_LAST);
} else { } else {
g_warning ("Check your GStreamer installation, " g_warning ("Check your GStreamer installation, "
"core element 'fakesink' is missing."); "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", "Video/Sink", "Fake video display that allows zero-copy",
"Nicolas Dufresne <nicolas.dufresne@collabora.com>"); "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, gst_type_mark_as_plugin_api (GST_TYPE_FAKE_VIDEO_SINK_ALLOCATION_META_FLAGS,
0); 0);
} }

View file

@ -8,6 +8,7 @@ debugutilsbad_sources = [
'gstdebugspy.c', 'gstdebugspy.c',
'gsterrorignore.c', 'gsterrorignore.c',
'gstfakeaudiosink.c', 'gstfakeaudiosink.c',
'gstfakesinkutils.c',
'gstfakevideosink.c', 'gstfakevideosink.c',
'gsttestsrcbin.c', 'gsttestsrcbin.c',
'gstvideocodectestsink.c', 'gstvideocodectestsink.c',