|
Packit Service |
963350 |
/* GStreamer
|
|
Packit Service |
963350 |
* Copyright (C) 2015 Jan Schmidt <jan@centricular.com>
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* gstdynamictypefactory.c: Implementation of GstDynamicTypeFactory
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
963350 |
* modify it under the terms of the GNU Library General Public
|
|
Packit Service |
963350 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
963350 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
963350 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
963350 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
963350 |
* Library General Public License for more details.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* You should have received a copy of the GNU Library General Public
|
|
Packit Service |
963350 |
* License along with this library; if not, write to the
|
|
Packit Service |
963350 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit Service |
963350 |
* Boston, MA 02110-1301, USA.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* SECTION:gstdynamictypefactory
|
|
Packit Service |
963350 |
* @title: GstDynamicTypeFactory
|
|
Packit Service |
963350 |
* @short_description: Represents a registered dynamically loadable GType
|
|
Packit Service |
963350 |
* @see_also: #GstPlugin, #GstPluginFeature.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* #GstDynamicTypeFactory is used to represent a type that can be
|
|
Packit Service |
963350 |
* automatically loaded the first time it is used. For example,
|
|
Packit Service |
963350 |
* a non-standard type for use in caps fields.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* In general, applications and plugins don't need to use the factory
|
|
Packit Service |
963350 |
* beyond registering the type in a plugin init function. Once that is
|
|
Packit Service |
963350 |
* done, the type is stored in the registry, and ready as soon as the
|
|
Packit Service |
963350 |
* registry is loaded.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* ## Registering a type for dynamic loading
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* |[
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* static gboolean
|
|
Packit Service |
963350 |
* plugin_init (GstPlugin * plugin)
|
|
Packit Service |
963350 |
* {
|
|
Packit Service |
963350 |
* return gst_dynamic_type_register (plugin, GST_TYPE_CUSTOM_CAPS_FIELD);
|
|
Packit Service |
963350 |
* }
|
|
Packit Service |
963350 |
* ]|
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
963350 |
#include "config.h"
|
|
Packit Service |
963350 |
#endif
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#include "gst_private.h"
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#include <glib-object.h>
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#include "gst.h"
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#include "glib-compat-private.h"
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GST_DEBUG_CATEGORY_STATIC (dynamic_type_factory_debug);
|
|
Packit Service |
963350 |
#define GST_CAT_DEFAULT dynamic_type_factory_debug
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#define _do_init \
|
|
Packit Service |
963350 |
{ \
|
|
Packit Service |
963350 |
GST_DEBUG_CATEGORY_INIT (dynamic_type_factory_debug, \
|
|
Packit Service |
963350 |
"GST_DYNAMIC_TYPE_FACTORY", GST_DEBUG_BOLD, \
|
|
Packit Service |
963350 |
"dynamic type factories allow automatically loading a type from a plugin"); \
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
G_DEFINE_TYPE_WITH_CODE (GstDynamicTypeFactory, gst_dynamic_type_factory,
|
|
Packit Service |
963350 |
GST_TYPE_PLUGIN_FEATURE, _do_init);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_dynamic_type_factory_class_init (GstDynamicTypeFactoryClass * klass)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_dynamic_type_factory_init (GstDynamicTypeFactory * factory)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static GstDynamicTypeFactory *
|
|
Packit Service |
963350 |
gst_dynamic_type_factory_find (const gchar * name)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstPluginFeature *feature;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
g_return_val_if_fail (name != NULL, NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
feature = gst_registry_find_feature (gst_registry_get (), name,
|
|
Packit Service |
963350 |
GST_TYPE_DYNAMIC_TYPE_FACTORY);
|
|
Packit Service |
963350 |
if (feature)
|
|
Packit Service |
963350 |
return GST_DYNAMIC_TYPE_FACTORY (feature);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return NULL;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GType
|
|
Packit Service |
963350 |
gst_dynamic_type_factory_load (const gchar * factoryname)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstDynamicTypeFactory *factory = gst_dynamic_type_factory_find (factoryname);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* Called with a non-dynamic or unregistered type? */
|
|
Packit Service |
963350 |
if (factory == NULL)
|
|
Packit Service |
963350 |
return FALSE;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
factory =
|
|
Packit Service |
963350 |
GST_DYNAMIC_TYPE_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
|
|
Packit Service |
963350 |
(factory)));
|
|
Packit Service |
963350 |
if (factory == NULL)
|
|
Packit Service |
963350 |
return 0;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GST_DEBUG_OBJECT (factory, "Loaded type %s", factoryname);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return factory->type;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static GstDynamicTypeFactory *
|
|
Packit Service |
963350 |
gst_dynamic_type_factory_create (GstRegistry * registry,
|
|
Packit Service |
963350 |
GstPlugin * plugin, const gchar * name)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstDynamicTypeFactory *factory;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
factory = g_object_new (GST_TYPE_DYNAMIC_TYPE_FACTORY, NULL);
|
|
Packit Service |
963350 |
gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
|
|
Packit Service |
963350 |
GST_LOG_OBJECT (factory, "Created new dynamictypefactory for type %s", name);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (plugin && plugin->desc.name) {
|
|
Packit Service |
963350 |
GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name;
|
|
Packit Service |
963350 |
GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
|
|
Packit Service |
963350 |
g_object_add_weak_pointer ((GObject *) plugin,
|
|
Packit Service |
963350 |
(gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
|
|
Packit Service |
963350 |
} else {
|
|
Packit Service |
963350 |
GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
|
|
Packit Service |
963350 |
GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return factory;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
gboolean
|
|
Packit Service |
963350 |
gst_dynamic_type_register (GstPlugin * plugin, GType dyn_type)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstDynamicTypeFactory *factory;
|
|
Packit Service |
963350 |
const gchar *name;
|
|
Packit Service |
963350 |
GstPluginFeature *existing_feature;
|
|
Packit Service |
963350 |
GstRegistry *registry;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
name = g_type_name (dyn_type);
|
|
Packit Service |
963350 |
g_return_val_if_fail (name != NULL, FALSE);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
registry = gst_registry_get ();
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* check if feature already exists, if it exists there is no need to
|
|
Packit Service |
963350 |
* update it for this method of dynamic type */
|
|
Packit Service |
963350 |
existing_feature = gst_registry_lookup_feature (registry, name);
|
|
Packit Service |
963350 |
if (existing_feature) {
|
|
Packit Service |
963350 |
GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)",
|
|
Packit Service |
963350 |
existing_feature, name);
|
|
Packit Service |
963350 |
existing_feature->loaded = TRUE;
|
|
Packit Service |
963350 |
GST_DYNAMIC_TYPE_FACTORY (existing_feature)->type = dyn_type;
|
|
Packit Service |
963350 |
gst_object_unref (existing_feature);
|
|
Packit Service |
963350 |
return TRUE;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
factory = gst_dynamic_type_factory_create (registry, plugin, name);
|
|
Packit Service |
963350 |
factory->type = dyn_type;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
gst_registry_add_feature (registry, GST_PLUGIN_FEATURE_CAST (factory));
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return TRUE;
|
|
Packit Service |
963350 |
}
|