gstmeta.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* GStreamer
  2. * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
  3. *
  4. * gstmeta.h: Header for Metadata structures
  5. *
  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.
  10. *
  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.
  15. *
  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.
  20. */
  21. #ifndef __GST_META_H__
  22. #define __GST_META_H__
  23. #include <glib.h>
  24. #include <gst/gstbuffer.h>
  25. G_BEGIN_DECLS
  26. typedef struct _GstMeta GstMeta;
  27. typedef struct _GstMetaInfo GstMetaInfo;
  28. #define GST_META_CAST(meta) ((GstMeta *)(meta))
  29. /**
  30. * GstMetaFlags:
  31. * @GST_META_FLAG_NONE: no flags
  32. * @GST_META_FLAG_READONLY: metadata should not be modified
  33. * @GST_META_FLAG_POOLED: metadata is managed by a bufferpool
  34. * @GST_META_FLAG_LOCKED: metadata should not be removed
  35. * @GST_META_FLAG_LAST: additional flags can be added starting from this flag.
  36. *
  37. * Extra metadata flags.
  38. */
  39. typedef enum {
  40. GST_META_FLAG_NONE = 0,
  41. GST_META_FLAG_READONLY = (1 << 0),
  42. GST_META_FLAG_POOLED = (1 << 1),
  43. GST_META_FLAG_LOCKED = (1 << 2),
  44. GST_META_FLAG_LAST = (1 << 16)
  45. } GstMetaFlags;
  46. /**
  47. * GST_META_FLAGS:
  48. * @meta: a #GstMeta.
  49. *
  50. * A flags word containing #GstMetaFlags flags set on @meta
  51. */
  52. #define GST_META_FLAGS(meta) (GST_META_CAST (meta)->flags)
  53. /**
  54. * GST_META_FLAG_IS_SET:
  55. * @meta: a #GstMeta.
  56. * @flag: the #GstMetaFlags to check.
  57. *
  58. * Gives the status of a specific flag on a metadata.
  59. */
  60. #define GST_META_FLAG_IS_SET(meta,flag) !!(GST_META_FLAGS (meta) & (flag))
  61. /**
  62. * GST_META_FLAG_SET:
  63. * @meta: a #GstMeta.
  64. * @flag: the #GstMetaFlags to set.
  65. *
  66. * Sets a metadata flag on a metadata.
  67. */
  68. #define GST_META_FLAG_SET(meta,flag) (GST_META_FLAGS (meta) |= (flag))
  69. /**
  70. * GST_META_FLAG_UNSET:
  71. * @meta: a #GstMeta.
  72. * @flag: the #GstMetaFlags to clear.
  73. *
  74. * Clears a metadata flag.
  75. */
  76. #define GST_META_FLAG_UNSET(meta,flag) (GST_META_FLAGS (meta) &= ~(flag))
  77. /**
  78. * GST_META_TAG_MEMORY_STR:
  79. *
  80. * This metadata stays relevant as long as memory layout is unchanged.
  81. *
  82. * Since: 1.2
  83. */
  84. #define GST_META_TAG_MEMORY_STR "memory"
  85. /**
  86. * GstMeta:
  87. * @flags: extra flags for the metadata
  88. * @info: pointer to the #GstMetaInfo
  89. *
  90. * Base structure for metadata. Custom metadata will put this structure
  91. * as the first member of their structure.
  92. */
  93. struct _GstMeta {
  94. GstMetaFlags flags;
  95. const GstMetaInfo *info;
  96. };
  97. /**
  98. * GstMetaInitFunction:
  99. * @meta: a #GstMeta
  100. * @params: parameters passed to the init function
  101. * @buffer: a #GstBuffer
  102. *
  103. * Function called when @meta is initialized in @buffer.
  104. */
  105. typedef gboolean (*GstMetaInitFunction) (GstMeta *meta, gpointer params, GstBuffer *buffer);
  106. /**
  107. * GstMetaFreeFunction:
  108. * @meta: a #GstMeta
  109. * @buffer: a #GstBuffer
  110. *
  111. * Function called when @meta is freed in @buffer.
  112. */
  113. typedef void (*GstMetaFreeFunction) (GstMeta *meta, GstBuffer *buffer);
  114. /**
  115. * gst_meta_transform_copy:
  116. *
  117. * GQuark for the "gst-copy" transform.
  118. */
  119. GST_EXPORT GQuark _gst_meta_transform_copy;
  120. /**
  121. * GST_META_TRANSFORM_IS_COPY:
  122. * @type: a transform type
  123. *
  124. * Check if the transform type is a copy transform
  125. */
  126. #define GST_META_TRANSFORM_IS_COPY(type) ((type) == _gst_meta_transform_copy)
  127. /**
  128. * GstMetaTransformCopy:
  129. * @region: %TRUE if only region is copied
  130. * @offset: the offset to copy, 0 if @region is %FALSE, otherwise > 0
  131. * @size: the size to copy, -1 or the buffer size when @region is %FALSE
  132. *
  133. * Extra data passed to a "gst-copy" transform #GstMetaTransformFunction.
  134. */
  135. typedef struct {
  136. gboolean region;
  137. gsize offset;
  138. gsize size;
  139. } GstMetaTransformCopy;
  140. /**
  141. * GstMetaTransformFunction:
  142. * @transbuf: a #GstBuffer
  143. * @meta: a #GstMeta
  144. * @buffer: a #GstBuffer
  145. * @type: the transform type
  146. * @data: transform specific data.
  147. *
  148. * Function called for each @meta in @buffer as a result of performing a
  149. * transformation on @transbuf. Additional @type specific transform data
  150. * is passed to the function as @data.
  151. *
  152. * Implementations should check the @type of the transform and parse
  153. * additional type specific fields in @data that should be used to update
  154. * the metadata on @transbuf.
  155. *
  156. * Returns: %TRUE if the transform could be performed
  157. */
  158. typedef gboolean (*GstMetaTransformFunction) (GstBuffer *transbuf,
  159. GstMeta *meta, GstBuffer *buffer,
  160. GQuark type, gpointer data);
  161. /**
  162. * GstMetaInfo:
  163. * @api: tag identifying the metadata structure and api
  164. * @type: type identifying the implementor of the api
  165. * @size: size of the metadata
  166. * @init_func: function for initializing the metadata
  167. * @free_func: function for freeing the metadata
  168. * @transform_func: function for transforming the metadata
  169. *
  170. * The #GstMetaInfo provides information about a specific metadata
  171. * structure.
  172. */
  173. struct _GstMetaInfo {
  174. GType api;
  175. GType type;
  176. gsize size;
  177. GstMetaInitFunction init_func;
  178. GstMetaFreeFunction free_func;
  179. GstMetaTransformFunction transform_func;
  180. /*< private >*/
  181. gpointer _gst_reserved[GST_PADDING];
  182. };
  183. GType gst_meta_api_type_register (const gchar *api,
  184. const gchar **tags);
  185. gboolean gst_meta_api_type_has_tag (GType api, GQuark tag);
  186. const GstMetaInfo * gst_meta_register (GType api, const gchar *impl,
  187. gsize size,
  188. GstMetaInitFunction init_func,
  189. GstMetaFreeFunction free_func,
  190. GstMetaTransformFunction transform_func);
  191. const GstMetaInfo * gst_meta_get_info (const gchar * impl);
  192. const gchar* const* gst_meta_api_type_get_tags (GType api);
  193. /* some default tags */
  194. GST_EXPORT GQuark _gst_meta_tag_memory;
  195. /**
  196. * GST_META_TAG_MEMORY:
  197. *
  198. * Metadata tagged with this tag depends on the particular memory
  199. * or buffer that it is on.
  200. *
  201. * Deprecated: The GQuarks are not exported by any public API, use
  202. * GST_META_TAG_MEMORY_STR instead.
  203. */
  204. #ifndef GST_DISABLE_DEPRECATED
  205. #define GST_META_TAG_MEMORY (_gst_meta_tag_memory)
  206. #endif
  207. G_END_DECLS
  208. #endif /* __GST_META_H__ */