2 * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
4 * gsttracer.c: tracer base class
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
24 * @short_description: Tracing base class
26 * Tracing modules will subclass #GstTracer and register through
27 * gst_tracing_register(). Modules can attach to various hook-types - see
28 * gst_tracing_register_hook(). When invoked they receive hook specific
29 * contextual data, which they must not modify.
34 #define GST_USE_UNSTABLE_API
36 #include "gst_private.h"
37 #include "gstenumtypes.h"
38 #include "gsttracer.h"
39 #include "gsttracerfactory.h"
40 #include "gsttracerutils.h"
42 GST_DEBUG_CATEGORY_EXTERN (tracer_debug);
43 #define GST_CAT_DEFAULT tracer_debug
45 /* tracing plugins base class */
54 static GParamSpec *properties[PROP_LAST];
56 static void gst_tracer_set_property (GObject * object, guint prop_id,
57 const GValue * value, GParamSpec * pspec);
58 static void gst_tracer_get_property (GObject * object, guint prop_id,
59 GValue * value, GParamSpec * pspec);
61 struct _GstTracerPrivate
66 #define gst_tracer_parent_class parent_class
67 G_DEFINE_ABSTRACT_TYPE (GstTracer, gst_tracer, GST_TYPE_OBJECT);
70 gst_tracer_dispose (GObject * object)
72 GstTracer *tracer = GST_TRACER (object);
73 g_free (tracer->priv->params);
77 gst_tracer_class_init (GstTracerClass * klass)
79 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
81 gobject_class->set_property = gst_tracer_set_property;
82 gobject_class->get_property = gst_tracer_get_property;
83 gobject_class->dispose = gst_tracer_dispose;
85 properties[PROP_PARAMS] =
86 g_param_spec_string ("params", "Params", "Extra configuration parameters",
87 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
89 g_object_class_install_properties (gobject_class, PROP_LAST, properties);
90 g_type_class_add_private (klass, sizeof (GstTracerPrivate));
94 gst_tracer_init (GstTracer * tracer)
96 tracer->priv = G_TYPE_INSTANCE_GET_PRIVATE (tracer, GST_TYPE_TRACER,
101 gst_tracer_set_property (GObject * object, guint prop_id,
102 const GValue * value, GParamSpec * pspec)
104 GstTracer *self = GST_TRACER_CAST (object);
108 self->priv->params = g_value_dup_string (value);
111 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
117 gst_tracer_get_property (GObject * object, guint prop_id,
118 GValue * value, GParamSpec * pspec)
120 GstTracer *self = GST_TRACER_CAST (object);
124 g_value_set_string (value, self->priv->params);
127 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
132 /* tracing modules */
135 * gst_tracer_register:
136 * @plugin: (allow-none): A #GstPlugin, or %NULL for a static typefind function
137 * @name: The name for registering
138 * @type: GType of tracer to register
140 * Create a new tracer-factory capable of instantiating objects of the
141 * @type and add the factory to @plugin.
143 * Returns: %TRUE, if the registering succeeded, %FALSE on error
146 gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type)
148 GstPluginFeature *existing_feature;
149 GstRegistry *registry;
150 GstTracerFactory *factory;
152 g_return_val_if_fail (name != NULL, FALSE);
153 g_return_val_if_fail (g_type_is_a (type, GST_TYPE_TRACER), FALSE);
155 registry = gst_registry_get ();
156 /* check if feature already exists, if it exists there is no need to update it
157 * when the registry is getting updated, outdated plugins and all their
158 * features are removed and readded.
160 existing_feature = gst_registry_lookup_feature (registry, name);
161 if (existing_feature) {
162 GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)",
163 existing_feature, name);
164 factory = GST_TRACER_FACTORY_CAST (existing_feature);
165 factory->type = type;
166 existing_feature->loaded = TRUE;
167 gst_object_unref (existing_feature);
171 factory = g_object_newv (GST_TYPE_TRACER_FACTORY, 0, NULL);
172 GST_DEBUG_OBJECT (factory, "new tracer factory for %s", name);
174 gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
175 gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory),
178 factory->type = type;
179 GST_DEBUG_OBJECT (factory, "tracer factory for %u:%s",
180 (guint) type, g_type_name (type));
182 if (plugin && plugin->desc.name) {
183 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name; /* interned string */
184 GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
185 g_object_add_weak_pointer ((GObject *) plugin,
186 (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
188 GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
189 GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
191 GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;
193 gst_registry_add_feature (gst_registry_get (),
194 GST_PLUGIN_FEATURE_CAST (factory));