feature: use object name

Remove the name property from the plugin feature and port code to use the object
name instead.
This commit is contained in:
Wim Taymans 2011-05-24 18:17:24 +02:00
parent 65b427bf8e
commit 2c221a5729
10 changed files with 72 additions and 98 deletions

View file

@ -370,9 +370,9 @@ gst_element_factory_create (GstElementFactory * factory, const gchar * name)
if (name)
GST_INFO ("creating element \"%s\" named \"%s\"",
GST_PLUGIN_FEATURE_NAME (factory), GST_STR_NULL (name));
GST_OBJECT_NAME (factory), GST_STR_NULL (name));
else
GST_INFO ("creating element \"%s\"", GST_PLUGIN_FEATURE_NAME (factory));
GST_INFO ("creating element \"%s\"", GST_OBJECT_NAME (factory));
if (factory->type == 0)
goto no_type;
@ -398,7 +398,7 @@ gst_element_factory_create (GstElementFactory * factory, const gchar * name)
(gpointer) & oclass->elementfactory, NULL, factory))
gst_object_unref (factory);
GST_DEBUG ("created element \"%s\"", GST_PLUGIN_FEATURE_NAME (factory));
GST_DEBUG ("created element \"%s\"", GST_OBJECT_NAME (factory));
return element;

View file

@ -86,9 +86,11 @@ gst_index_factory_new (const gchar * name, const gchar * longdesc, GType type)
GstIndexFactory *factory;
g_return_val_if_fail (name != NULL, NULL);
factory = GST_INDEX_FACTORY (g_object_newv (GST_TYPE_INDEX_FACTORY, 0, NULL));
GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (name);
factory =
GST_INDEX_FACTORY (g_object_new (GST_TYPE_INDEX_FACTORY, "name", name,
NULL));
if (factory->longdesc)
g_free (factory->longdesc);
factory->longdesc = g_strdup (longdesc);

View file

@ -63,8 +63,7 @@ gst_plugin_feature_finalize (GObject * object)
{
GstPluginFeature *feature = GST_PLUGIN_FEATURE_CAST (object);
GST_DEBUG ("finalizing feature %p: '%s'", feature,
GST_PLUGIN_FEATURE_NAME (feature));
GST_DEBUG ("finalizing feature %p: '%s'", feature, GST_OBJECT_NAME (feature));
if (feature->plugin != NULL) {
g_object_remove_weak_pointer ((GObject *) feature->plugin,
@ -103,7 +102,7 @@ gst_plugin_feature_load (GstPluginFeature * feature)
g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
GST_DEBUG ("loading plugin for feature %p; '%s'", feature,
GST_PLUGIN_FEATURE_NAME (feature));
GST_OBJECT_NAME (feature));
if (feature->loaded)
return gst_object_ref (feature);
@ -116,7 +115,8 @@ gst_plugin_feature_load (GstPluginFeature * feature)
gst_object_unref (plugin);
real_feature =
gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
gst_registry_lookup_feature (gst_registry_get_default (),
GST_OBJECT_NAME (feature));
if (real_feature == NULL)
goto disappeared;
@ -129,20 +129,20 @@ gst_plugin_feature_load (GstPluginFeature * feature)
load_failed:
{
GST_WARNING ("Failed to load plugin containing feature '%s'.",
GST_PLUGIN_FEATURE_NAME (feature));
GST_OBJECT_NAME (feature));
return NULL;
}
disappeared:
{
GST_INFO
("Loaded plugin containing feature '%s', but feature disappeared.",
feature->name);
GST_OBJECT_NAME (feature));
return NULL;
}
not_found:
{
GST_INFO ("Tried to load plugin containing feature '%s', but feature was "
"not found.", real_feature->name);
"not found.", GST_OBJECT_NAME (real_feature));
return NULL;
}
}
@ -163,48 +163,7 @@ gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
(data->name == NULL
|| !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
}
/**
* gst_plugin_feature_set_name:
* @feature: a feature
* @name: the name to set
*
* Sets the name of a plugin feature. The name uniquely identifies a feature
* within all features of the same type. Renaming a plugin feature is not
* allowed. A copy is made of the name so you should free the supplied @name
* after calling this function.
*/
void
gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
{
g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
g_return_if_fail (name != NULL);
if (G_UNLIKELY (feature->name)) {
g_return_if_fail (strcmp (feature->name, name) == 0);
} else {
gst_object_set_name (GST_OBJECT (feature), name);
feature->name = GST_OBJECT_NAME (GST_OBJECT (feature));
}
}
/**
* gst_plugin_feature_get_name:
* @feature: a feature
*
* Gets the name of a plugin feature.
*
* Returns: the name
*/
G_CONST_RETURN gchar *
gst_plugin_feature_get_name (GstPluginFeature * feature)
{
g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
return feature->name;
(data->name == NULL || !strcmp (data->name, GST_OBJECT_NAME (feature))));
}
/**
@ -345,7 +304,7 @@ gst_plugin_feature_check_version (GstPluginFeature * feature,
g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
GST_DEBUG ("Looking up plugin '%s' containing plugin feature '%s'",
feature->plugin_name, feature->name);
feature->plugin_name, GST_OBJECT_NAME (feature));
registry = gst_registry_get_default ();
plugin = gst_registry_find_plugin (registry, feature->plugin_name);
@ -422,7 +381,7 @@ gst_plugin_feature_rank_compare_func (gconstpointer p1, gconstpointer p2)
if (diff != 0)
return diff;
diff = strcmp (f2->name, f1->name);
diff = strcmp (GST_OBJECT_NAME (f2), GST_OBJECT_NAME (f1));
return diff;
}

View file

@ -38,14 +38,6 @@ G_BEGIN_DECLS
#define GST_PLUGIN_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PLUGIN_FEATURE, GstPluginFeatureClass))
#define GST_PLUGIN_FEATURE_CAST(obj) ((GstPluginFeature*)(obj))
/**
* GST_PLUGIN_FEATURE_NAME:
* @feature: The feature to query
*
* Get the name of the feature
*/
#define GST_PLUGIN_FEATURE_NAME(feature) (GST_PLUGIN_FEATURE (feature)->name)
typedef struct _GstPluginFeature GstPluginFeature;
typedef struct _GstPluginFeatureClass GstPluginFeatureClass;
@ -71,6 +63,29 @@ typedef enum {
GST_RANK_PRIMARY = 256
} GstRank;
/**
* gst_plugin_feature_get_name:
* @feature: a #GstPluginFeature to get the name of @feature.
*
* Returns a copy of the name of @feature.
* Caller should g_free() the return value after usage.
* For a nameless plugin feature, this returns NULL, which you can safely g_free()
* as well.
*
* Returns: (transfer full): the name of @feature. g_free() after usage. MT safe.
*
*/
#define gst_plugin_feature_get_name(feature) gst_object_get_name(GST_OBJECT_CAST(feature))
/**
* gst_plugin_feature_set_name:
* @feature: a #GstPluginFeature to set the name of.
* @name: the new name
*
* Sets the name of the plugin feature, getting rid of the old name if there was one.
*/
#define gst_plugin_feature_set_name(feature,name) gst_object_set_name(GST_OBJECT_CAST(feature),name)
/**
* GstPluginFeature:
*
@ -81,7 +96,6 @@ struct _GstPluginFeature {
/*< private >*/
gboolean loaded;
gchar *name; /* FIXME-0.11: remove variable, we use GstObject:name */
guint rank;
const gchar *plugin_name;
@ -134,9 +148,7 @@ gboolean gst_plugin_feature_type_name_filter (GstPluginFeature *featu
GstTypeNameData *data);
void gst_plugin_feature_set_rank (GstPluginFeature *feature, guint rank);
void gst_plugin_feature_set_name (GstPluginFeature *feature, const gchar *name);
guint gst_plugin_feature_get_rank (GstPluginFeature *feature);
G_CONST_RETURN gchar *gst_plugin_feature_get_name (GstPluginFeature *feature);
void gst_plugin_feature_list_free (GList *list);
GList *gst_plugin_feature_list_copy (GList *list);

View file

@ -484,7 +484,7 @@ gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
plugin->desc.name);
registry->features = g_list_delete_link (registry->features, f);
g_hash_table_remove (registry->feature_hash, feature->name);
g_hash_table_remove (registry->feature_hash, GST_OBJECT_NAME (feature));
gst_object_unparent (GST_OBJECT_CAST (feature));
}
f = next;
@ -538,25 +538,27 @@ gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
g_return_val_if_fail (feature->name != NULL, FALSE);
g_return_val_if_fail (GST_OBJECT_NAME (feature) != NULL, FALSE);
g_return_val_if_fail (feature->plugin_name != NULL, FALSE);
GST_OBJECT_LOCK (registry);
existing_feature = gst_registry_lookup_feature_locked (registry,
feature->name);
GST_OBJECT_NAME (feature));
if (G_UNLIKELY (existing_feature)) {
GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
existing_feature, feature->name);
existing_feature, GST_OBJECT_NAME (feature));
/* Remove the existing feature from the list now, before we insert the new
* one, but don't unref yet because the hash is still storing a reference to
* it. */
registry->features = g_list_remove (registry->features, existing_feature);
}
GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature, feature->name);
GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature,
GST_OBJECT_NAME (feature));
registry->features = g_list_prepend (registry->features, feature);
g_hash_table_replace (registry->feature_hash, feature->name, feature);
g_hash_table_replace (registry->feature_hash, GST_OBJECT_NAME (feature),
feature);
if (G_UNLIKELY (existing_feature)) {
/* We unref now. No need to remove the feature name from the hash table, it
@ -569,7 +571,8 @@ gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
registry->priv->cookie++;
GST_OBJECT_UNLOCK (registry);
GST_LOG_OBJECT (registry, "emitting feature-added for %s", feature->name);
GST_LOG_OBJECT (registry, "emitting feature-added for %s",
GST_OBJECT_NAME (feature));
g_signal_emit (registry, gst_registry_signals[FEATURE_ADDED], 0, feature);
return TRUE;
@ -595,7 +598,7 @@ gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
GST_OBJECT_LOCK (registry);
registry->features = g_list_remove (registry->features, feature);
g_hash_table_remove (registry->feature_hash, feature->name);
g_hash_table_remove (registry->feature_hash, GST_OBJECT_NAME (feature));
registry->priv->cookie++;
GST_OBJECT_UNLOCK (registry);
@ -678,7 +681,7 @@ type_find_factory_rank_cmp (const GstPluginFeature * fac1,
/* to make the order in which things happen more deterministic,
* sort by name when the ranks are the same. */
return strcmp (fac1->name, fac2->name);
return strcmp (GST_OBJECT_NAME (fac1), GST_OBJECT_NAME (fac2));
}
static GList *

View file

@ -247,7 +247,7 @@ gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
gst_registry_chunks_save_const_string (list, (gchar *) walk->data);
}
GST_DEBUG ("Feature %s: saved %d interfaces %d pad templates",
feature->name, ef->ninterfaces, ef->npadtemplates);
GST_OBJECT_NAME (feature), ef->ninterfaces, ef->npadtemplates);
/* save uritypes */
if (GST_URI_TYPE_IS_VALID (factory->uri_type)) {
@ -269,7 +269,7 @@ gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
GST_DEBUG ("Saved %d UriTypes", ef->nuriprotocols);
} else {
g_warning ("GStreamer feature '%s' is URI handler but does not provide"
" any protocols it can handle", feature->name);
" any protocols it can handle", GST_OBJECT_NAME (feature));
}
}
@ -341,7 +341,7 @@ gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
*list = g_list_prepend (*list, chk);
/* pack plugin feature strings */
gst_registry_chunks_save_const_string (list, feature->name);
gst_registry_chunks_save_const_string (list, GST_OBJECT_NAME (feature));
gst_registry_chunks_save_const_string (list, (gchar *) type_name);
return TRUE;
@ -674,8 +674,8 @@ gst_registry_chunks_load_feature (GstRegistry * registry, gchar ** in,
(gpointer *) & feature->plugin);
gst_registry_add_feature (registry, feature);
GST_DEBUG ("Added feature %s, plugin %p %s", feature->name, plugin,
plugin_name);
GST_DEBUG ("Added feature %s, plugin %p %s", GST_OBJECT_NAME (feature),
plugin, plugin_name);
return TRUE;

View file

@ -86,7 +86,7 @@ helper_find_peek (gpointer data, gint64 offset, guint size)
helper = (GstTypeFindHelper *) data;
GST_LOG_OBJECT (helper->obj, "'%s' called peek (%" G_GINT64_FORMAT
", %u)", GST_PLUGIN_FEATURE_NAME (helper->factory), offset, size);
", %u)", GST_OBJECT_NAME (helper->factory), offset, size);
if (size == 0)
return NULL;
@ -202,7 +202,7 @@ helper_find_suggest (gpointer data, guint probability, const GstCaps * caps)
GST_LOG_OBJECT (helper->obj,
"'%s' called called suggest (%u, %" GST_PTR_FORMAT ")",
GST_PLUGIN_FEATURE_NAME (helper->factory), probability, caps);
GST_OBJECT_NAME (helper->factory), probability, caps);
if (probability > helper->best_probability) {
GstCaps *copy = gst_caps_copy (caps);
@ -219,8 +219,7 @@ helper_find_get_length (gpointer data)
GstTypeFindHelper *helper = (GstTypeFindHelper *) data;
GST_LOG_OBJECT (helper->obj, "'%s' called called get_length, returning %"
G_GUINT64_FORMAT, GST_PLUGIN_FEATURE_NAME (helper->factory),
helper->size);
G_GUINT64_FORMAT, GST_OBJECT_NAME (helper->factory), helper->size);
return helper->size;
}
@ -313,7 +312,7 @@ gst_type_find_helper_get_range_ext (GstObject * obj,
continue;
GST_LOG_OBJECT (obj, "testing factory %s for extension %s",
GST_PLUGIN_FEATURE_NAME (factory), extension);
GST_OBJECT_NAME (factory), extension);
for (i = 0; ext[i]; i++) {
if (strcmp (ext[i], extension) == 0) {
@ -443,14 +442,14 @@ buf_helper_find_peek (gpointer data, gint64 off, guint size)
helper = (GstTypeFindBufHelper *) data;
GST_LOG_OBJECT (helper->obj, "'%s' called peek (%" G_GINT64_FORMAT ", %u)",
GST_PLUGIN_FEATURE_NAME (helper->factory), off, size);
GST_OBJECT_NAME (helper->factory), off, size);
if (size == 0)
return NULL;
if (off < 0) {
GST_LOG_OBJECT (helper->obj, "'%s' wanted to peek at end; not supported",
GST_PLUGIN_FEATURE_NAME (helper->factory));
GST_OBJECT_NAME (helper->factory));
return NULL;
}
@ -475,7 +474,7 @@ buf_helper_find_suggest (gpointer data, guint probability, const GstCaps * caps)
GST_LOG_OBJECT (helper->obj,
"'%s' called called suggest (%u, %" GST_PTR_FORMAT ")",
GST_PLUGIN_FEATURE_NAME (helper->factory), probability, caps);
GST_OBJECT_NAME (helper->factory), probability, caps);
/* Note: not >= as we call typefinders in order of rank, highest first */
if (probability > helper->best_probability) {

View file

@ -68,7 +68,7 @@ GST_START_TEST (test_registry)
fail_if (GST_OBJECT_REFCOUNT_VALUE (feature) != 1,
"Feature in registry should have refcount of 1");
GST_DEBUG ("refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (feature),
feature->name);
GST_OBJECT_NAME (feature));
}
}

View file

@ -1070,7 +1070,7 @@ print_element_list (gboolean print_all)
print_element_info (factory, TRUE);
else
g_print ("%s: %s: %s\n", plugin->desc.name,
GST_PLUGIN_FEATURE_NAME (factory),
GST_OBJECT_NAME (factory),
gst_element_factory_get_longname (factory));
} else if (GST_IS_INDEX_FACTORY (feature)) {
GstIndexFactory *factory;
@ -1078,7 +1078,7 @@ print_element_list (gboolean print_all)
factory = GST_INDEX_FACTORY (feature);
if (!print_all)
g_print ("%s: %s: %s\n", plugin->desc.name,
GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
GST_OBJECT_NAME (factory), factory->longdesc);
} else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
GstTypeFindFactory *factory;
@ -1103,8 +1103,7 @@ print_element_list (gboolean print_all)
} else {
if (!print_all)
n_print ("%s: %s (%s)\n", plugin->desc.name,
GST_PLUGIN_FEATURE_NAME (feature),
g_type_name (G_OBJECT_TYPE (feature)));
GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
}
next:
@ -1262,7 +1261,7 @@ print_plugin_features (GstPlugin * plugin)
GstElementFactory *factory;
factory = GST_ELEMENT_FACTORY (feature);
n_print (" %s: %s\n", GST_PLUGIN_FEATURE_NAME (factory),
n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
gst_element_factory_get_longname (factory));
num_elements++;
} else if (GST_IS_INDEX_FACTORY (feature)) {
@ -1356,7 +1355,7 @@ print_element_info (GstElementFactory * factory, gboolean print_names)
}
if (print_names)
_name = g_strdup_printf ("%s: ", GST_PLUGIN_FEATURE (factory)->name);
_name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
else
_name = NULL;
@ -1434,7 +1433,7 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
if (caps == NULL) {
g_printerr ("Couldn't find static pad template for %s '%s'\n",
type_name, GST_PLUGIN_FEATURE_NAME (factory));
type_name, GST_OBJECT_NAME (factory));
return;
}

View file

@ -462,7 +462,7 @@ print_element_info (GstElementFactory * factory)
return -1;
}
PUT_START_TAG (0, "element");
PUT_ESCAPED (1, "name", GST_PLUGIN_FEATURE_NAME (factory));
PUT_ESCAPED (1, "name", GST_OBJECT_NAME (factory));
gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));