meta: transform docs
[platform/upstream/gstreamer.git] / gst / gstmeta.c
index 078aef1..8a0978a 100644 (file)
 #include "gstutils.h"
 
 static GHashTable *metainfo = NULL;
-static GStaticRWLock lock = G_STATIC_RW_LOCK_INIT;
+static GRWLock lock;
+
+GQuark _gst_meta_transform_copy;
+GQuark _gst_meta_tag_memory;
 
 void
 _priv_gst_meta_initialize (void)
 {
+  g_rw_lock_init (&lock);
   metainfo = g_hash_table_new (g_str_hash, g_str_equal);
+
+  _gst_meta_transform_copy = g_quark_from_static_string ("gst-copy");
+  _gst_meta_tag_memory = g_quark_from_static_string ("memory");
+}
+
+/**
+ * gst_meta_api_type_register:
+ * @api: an API to register
+ * @tags: tags for @api
+ *
+ * Register and return a GType for the @api and associate it with
+ * @tags.
+ *
+ * Returns: a unique GType for @api.
+ */
+GType
+gst_meta_api_type_register (const gchar * api, const gchar ** tags)
+{
+  GType type;
+
+  g_return_val_if_fail (api != NULL, 0);
+  g_return_val_if_fail (tags != NULL, 0);
+
+  GST_CAT_DEBUG (GST_CAT_META, "register API \"%s\"", api);
+  type = g_pointer_type_register_static (api);
+
+  if (type != 0) {
+    gint i;
+
+    for (i = 0; tags[i]; i++) {
+      GST_CAT_DEBUG (GST_CAT_META, "  adding tag \"%s\"", tags[i]);
+      g_type_set_qdata (type, g_quark_from_string (tags[i]),
+          GINT_TO_POINTER (TRUE));
+    }
+  }
+  return type;
+}
+
+/**
+ * gst_meta_api_type_has_tag:
+ * @api: an API
+ * @tag: the tag to check
+ *
+ * Check if @api was registered with @tag.
+ *
+ * Returns: %TRUE if @api was registered with @tag.
+ */
+gboolean
+gst_meta_api_type_has_tag (GType api, GQuark tag)
+{
+  g_return_val_if_fail (api != 0, FALSE);
+  g_return_val_if_fail (tag != 0, FALSE);
+
+  return g_type_get_qdata (api, tag) != NULL;
 }
 
 /**
- * gst_meta_register_info:
- * @info: a #GstMetaInfo
+ * gst_meta_register:
+ * @api: the type of the #GstMeta API
+ * @impl: the name of the #GstMeta implementation
+ * @size: the size of the #GstMeta structure
+ * @init_func: a #GstMetaInitFunction
+ * @free_func: a #GstMetaFreeFunction
+ * @transform_func: a #GstMetaTransformFunction
+ * @tags: a NULL terminated array of strings describing what the metadata
+ *        contains info about.
+ *
+ * Register a new #GstMeta implementation.
  *
- * Register a #GstMetaInfo. The same @info can be retrieved later with
- * gst_meta_get_info() by using @impl as the key.
+ * The same @info can be retrieved later with gst_meta_get_info() by using
+ * @impl as the key.
  *
- * Returns: a #GstMetaInfo that can be used to access metadata.
+ * Returns: (transfer none): a #GstMetaInfo that can be used to access metadata.
  */
 
 const GstMetaInfo *
-gst_meta_register (const gchar * api, const gchar * impl, gsize size,
+gst_meta_register (GType api, const gchar * impl, gsize size,
     GstMetaInitFunction init_func, GstMetaFreeFunction free_func,
-    GstMetaCopyFunction copy_func, GstMetaTransformFunction transform_func)
+    GstMetaTransformFunction transform_func)
 {
   GstMetaInfo *info;
 
-  g_return_val_if_fail (api != NULL, NULL);
+  g_return_val_if_fail (api != 0, NULL);
   g_return_val_if_fail (impl != NULL, NULL);
   g_return_val_if_fail (size != 0, NULL);
 
   info = g_slice_new (GstMetaInfo);
-  info->api = g_quark_from_string (api);
+  info->api = api;
   info->type = g_pointer_type_register_static (impl);
   info->size = size;
   info->init_func = init_func;
   info->free_func = free_func;
-  info->copy_func = copy_func;
   info->transform_func = transform_func;
 
-  GST_DEBUG ("register \"%s\" implementing \"%s\" of size %" G_GSIZE_FORMAT,
-      api, impl, size);
+  GST_CAT_DEBUG (GST_CAT_META,
+      "register \"%s\" implementing \"%s\" of size %" G_GSIZE_FORMAT, impl,
+      g_type_name (api), size);
 
-  g_static_rw_lock_writer_lock (&lock);
+  g_rw_lock_writer_lock (&lock);
   g_hash_table_insert (metainfo, (gpointer) impl, (gpointer) info);
-  g_static_rw_lock_writer_unlock (&lock);
+  g_rw_lock_writer_unlock (&lock);
 
   return info;
 }
@@ -85,11 +152,11 @@ gst_meta_register (const gchar * api, const gchar * impl, gsize size,
  * gst_meta_get_info:
  * @impl: the name
  *
- * Lookup a previously registered meta info structure by its implementor name
+ * Lookup a previously registered meta info structure by its implementation name
  * @impl.
  *
- * Returns: a #GstMetaInfo with @impl or #NULL when no such metainfo
- * exists.
+ * Returns: (transfer none): a #GstMetaInfo with @impl, or #NULL when no such
+ * metainfo exists.
  */
 const GstMetaInfo *
 gst_meta_get_info (const gchar * impl)
@@ -98,56 +165,9 @@ gst_meta_get_info (const gchar * impl)
 
   g_return_val_if_fail (impl != NULL, NULL);
 
-  g_static_rw_lock_reader_lock (&lock);
+  g_rw_lock_reader_lock (&lock);
   info = g_hash_table_lookup (metainfo, impl);
-  g_static_rw_lock_reader_unlock (&lock);
+  g_rw_lock_reader_unlock (&lock);
 
   return info;
 }
-
-/* Timing metadata */
-static void
-meta_timing_copy (GstBuffer * copybuf, GstMetaTiming * meta,
-    GstBuffer * buffer, gsize offset, gsize size)
-{
-  GstMetaTiming *timing;
-
-  GST_DEBUG ("trans called from buffer %p to %p, meta %p,"
-      "offset %" G_GSIZE_FORMAT ", size %" G_GSIZE_FORMAT, buffer,
-      copybuf, meta, offset, size);
-
-  timing = gst_buffer_add_meta_timing (copybuf);
-  if (offset == 0) {
-    /* same offset, copy timestamps */
-    timing->pts = meta->pts;
-    timing->dts = meta->dts;
-    if (size == gst_buffer_get_size (buffer)) {
-      /* same size, copy duration */
-      timing->duration = meta->duration;
-    } else {
-      /* else clear */
-      timing->duration = GST_CLOCK_TIME_NONE;
-    }
-  } else {
-    timing->pts = -1;
-    timing->dts = -1;
-    timing->duration = -1;
-  }
-  timing->clock_rate = meta->clock_rate;
-}
-
-const GstMetaInfo *
-gst_meta_timing_get_info (void)
-{
-  static const GstMetaInfo *meta_info = NULL;
-
-  if (meta_info == NULL) {
-    meta_info = gst_meta_register ("GstMetaTiming", "GstMetaTiming",
-        sizeof (GstMetaTiming),
-        (GstMetaInitFunction) NULL,
-        (GstMetaFreeFunction) NULL,
-        (GstMetaCopyFunction) meta_timing_copy,
-        (GstMetaTransformFunction) NULL);
-  }
-  return meta_info;
-}