/** * gst_element_register: * @plugin: (allow-none): #GstPlugin to register the element with, or %NULL for * a static element. * @name: name of elements of this type * @rank: rank of element (higher rank means more importance when autoplugging) * @type: GType of element to register * * Create a new elementfactory capable of instantiating objects of the * @type and add the factory to @plugin. * * Returns: %TRUE, if the registering succeeded, %FALSE on error */ gboolean gst_element_register (GstPlugin * plugin, const gchar * name, guint rank, GType type) { GstPluginFeature *existing_feature; GstRegistry *registry; GstElementFactory *factory; GType *interfaces; guint n_interfaces, i; GstElementClass *klass; GList *item; g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (g_type_is_a (type, GST_TYPE_ELEMENT), FALSE); registry = gst_registry_get (); /* check if feature already exists, if it exists there is no need to update it * when the registry is getting updated, outdated plugins and all their * features are removed and readded. */ existing_feature = gst_registry_lookup_feature (registry, name); if (existing_feature) { GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)", existing_feature, name); factory = GST_ELEMENT_FACTORY_CAST (existing_feature); factory->type = type; existing_feature->loaded = TRUE; g_type_set_qdata (type, __gst_elementclass_factory, factory); gst_object_unref (existing_feature); return TRUE; } factory = g_object_new (GST_TYPE_ELEMENT_FACTORY, NULL); gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name); GST_LOG_OBJECT (factory, "Created new elementfactory for type %s", g_type_name (type)); /* provide info needed during class structure setup */ g_type_set_qdata (type, __gst_elementclass_factory, factory); klass = GST_ELEMENT_CLASS (g_type_class_ref (type)); CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_LONGNAME); CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_KLASS); CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_DESCRIPTION); CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_AUTHOR); factory->type = type; factory->metadata = gst_structure_copy ((GstStructure *) klass->metadata); for (item = klass->padtemplates; item; item = item->next) { GstPadTemplate *templ = item->data; GstStaticPadTemplate *newt; gchar *caps_string = gst_caps_to_string (templ->caps); newt = g_slice_new (GstStaticPadTemplate); newt->name_template = g_intern_string (templ->name_template); newt->direction = templ->direction; newt->presence = templ->presence; newt->static_caps.caps = NULL; newt->static_caps.string = g_intern_string (caps_string); factory->staticpadtemplates = g_list_append (factory->staticpadtemplates, newt); g_free (caps_string); } factory->numpadtemplates = klass->numpadtemplates; /* special stuff for URI handling */ if (g_type_is_a (type, GST_TYPE_URI_HANDLER)) { GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_type_interface_peek (klass, GST_TYPE_URI_HANDLER); if (!iface || !iface->get_type || !iface->get_protocols) goto urierror; if (iface->get_type) factory->uri_type = iface->get_type (factory->type); if (!GST_URI_TYPE_IS_VALID (factory->uri_type)) goto urierror; if (iface->get_protocols) { const gchar *const *protocols; protocols = iface->get_protocols (factory->type); factory->uri_protocols = g_strdupv ((gchar **) protocols); } if (!factory->uri_protocols) goto urierror; } interfaces = g_type_interfaces (type, &n_interfaces); for (i = 0; i < n_interfaces; i++) { __gst_element_factory_add_interface (factory, g_type_name (interfaces[i])); } g_free (interfaces); if (plugin && plugin->desc.name) { GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name; GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin; g_object_add_weak_pointer ((GObject *) plugin, (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin); } else { GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL"; GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL; } gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank); GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE; gst_registry_add_feature (registry, GST_PLUGIN_FEATURE_CAST (factory)); return TRUE; /* ERRORS */ urierror: { GST_WARNING_OBJECT (factory, "error with uri handler!"); gst_element_factory_cleanup (factory); return FALSE; } detailserror: { gst_element_factory_cleanup (factory); return FALSE; } }
/** * gst_device_provider_register: * @plugin: (allow-none): #GstPlugin to register the device provider with, or %NULL for * a static device provider. * @name: name of device providers of this type * @rank: rank of device provider (higher rank means more importance when autoplugging) * @type: GType of device provider to register * * Create a new device providerfactory capable of instantiating objects of the * @type and add the factory to @plugin. * * Returns: %TRUE, if the registering succeeded, %FALSE on error * * Since: 1.4 */ gboolean gst_device_provider_register (GstPlugin * plugin, const gchar * name, guint rank, GType type) { GstPluginFeature *existing_feature; GstRegistry *registry; GstDeviceProviderFactory *factory; GstDeviceProviderClass *klass; g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (g_type_is_a (type, GST_TYPE_DEVICE_PROVIDER), FALSE); registry = gst_registry_get (); /* check if feature already exists, if it exists there is no need to update it * when the registry is getting updated, outdated plugins and all their * features are removed and readded. */ existing_feature = gst_registry_lookup_feature (registry, name); if (existing_feature) { GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)", existing_feature, name); factory = GST_DEVICE_PROVIDER_FACTORY_CAST (existing_feature); factory->type = type; existing_feature->loaded = TRUE; g_type_set_qdata (type, __gst_deviceproviderclass_factory, factory); gst_object_unref (existing_feature); return TRUE; } factory = GST_DEVICE_PROVIDER_FACTORY_CAST (g_object_newv (GST_TYPE_DEVICE_PROVIDER_FACTORY, 0, NULL)); gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name); GST_LOG_OBJECT (factory, "Created new device providerfactory for type %s", g_type_name (type)); /* provide info needed during class structure setup */ g_type_set_qdata (type, __gst_deviceproviderclass_factory, factory); klass = GST_DEVICE_PROVIDER_CLASS (g_type_class_ref (type)); CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_LONGNAME); CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_KLASS); CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_DESCRIPTION); CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_AUTHOR); factory->type = type; factory->metadata = gst_structure_copy ((GstStructure *) klass->metadata); if (plugin && plugin->desc.name) { GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name; GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin; g_object_add_weak_pointer ((GObject *) plugin, (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin); } else { GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL"; GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL; } gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank); GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE; gst_registry_add_feature (registry, GST_PLUGIN_FEATURE_CAST (factory)); return TRUE; /* ERRORS */ detailserror: { gst_device_provider_factory_cleanup (factory); return FALSE; } }