gstvideometa.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* GStreamer
  2. * Copyright (C) <2011> Wim Taymans <[email protected]>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __GST_VIDEO_META_H__
  20. #define __GST_VIDEO_META_H__
  21. #include <gst/gst.h>
  22. #include <gst/video/video.h>
  23. G_BEGIN_DECLS
  24. #define GST_VIDEO_META_API_TYPE (gst_video_meta_api_get_type())
  25. #define GST_VIDEO_META_INFO (gst_video_meta_get_info())
  26. typedef struct _GstVideoMeta GstVideoMeta;
  27. #define GST_CAPS_FEATURE_META_GST_VIDEO_META "meta:GstVideoMeta"
  28. #define GST_VIDEO_CROP_META_API_TYPE (gst_video_crop_meta_api_get_type())
  29. #define GST_VIDEO_CROP_META_INFO (gst_video_crop_meta_get_info())
  30. typedef struct _GstVideoCropMeta GstVideoCropMeta;
  31. /**
  32. * GstVideoMeta:
  33. * @meta: parent #GstMeta
  34. * @buffer: the buffer this metadata belongs to
  35. * @flags: additional video flags
  36. * @format: the video format
  37. * @id: identifier of the frame
  38. * @width: the video width
  39. * @height: the video height
  40. * @n_planes: the number of planes in the image
  41. * @offset: array of offsets for the planes. This field might not always be
  42. * valid, it is used by the default implementation of @map.
  43. * @stride: array of strides for the planes. This field might not always be
  44. * valid, it is used by the default implementation of @map.
  45. * @map: map the memory of a plane
  46. * @unmap: unmap the memory of a plane
  47. *
  48. * Extra buffer metadata describing image properties
  49. */
  50. struct _GstVideoMeta {
  51. GstMeta meta;
  52. GstBuffer *buffer;
  53. GstVideoFrameFlags flags;
  54. GstVideoFormat format;
  55. gint id;
  56. guint width;
  57. guint height;
  58. guint n_planes;
  59. gsize offset[GST_VIDEO_MAX_PLANES];
  60. gint stride[GST_VIDEO_MAX_PLANES];
  61. gboolean (*map) (GstVideoMeta *meta, guint plane, GstMapInfo *info,
  62. gpointer *data, gint * stride, GstMapFlags flags);
  63. gboolean (*unmap) (GstVideoMeta *meta, guint plane, GstMapInfo *info);
  64. };
  65. GType gst_video_meta_api_get_type (void);
  66. const GstMetaInfo * gst_video_meta_get_info (void);
  67. #define gst_buffer_get_video_meta(b) ((GstVideoMeta*)gst_buffer_get_meta((b),GST_VIDEO_META_API_TYPE))
  68. GstVideoMeta * gst_buffer_get_video_meta_id (GstBuffer *buffer, gint id);
  69. GstVideoMeta * gst_buffer_add_video_meta (GstBuffer *buffer, GstVideoFrameFlags flags,
  70. GstVideoFormat format, guint width, guint height);
  71. GstVideoMeta * gst_buffer_add_video_meta_full (GstBuffer *buffer, GstVideoFrameFlags flags,
  72. GstVideoFormat format, guint width, guint height,
  73. guint n_planes, gsize offset[GST_VIDEO_MAX_PLANES],
  74. gint stride[GST_VIDEO_MAX_PLANES]);
  75. gboolean gst_video_meta_map (GstVideoMeta *meta, guint plane, GstMapInfo *info,
  76. gpointer *data, gint *stride, GstMapFlags flags);
  77. gboolean gst_video_meta_unmap (GstVideoMeta *meta, guint plane, GstMapInfo *info);
  78. /**
  79. * GstVideoCropMeta:
  80. * @meta: parent #GstMeta
  81. * @x: the horizontal offset
  82. * @y: the vertical offset
  83. * @width: the cropped width
  84. * @height: the cropped height
  85. *
  86. * Extra buffer metadata describing image cropping.
  87. */
  88. struct _GstVideoCropMeta {
  89. GstMeta meta;
  90. guint x;
  91. guint y;
  92. guint width;
  93. guint height;
  94. };
  95. GType gst_video_crop_meta_api_get_type (void);
  96. const GstMetaInfo * gst_video_crop_meta_get_info (void);
  97. #define gst_buffer_get_video_crop_meta(b) ((GstVideoCropMeta*)gst_buffer_get_meta((b),GST_VIDEO_CROP_META_API_TYPE))
  98. #define gst_buffer_add_video_crop_meta(b) ((GstVideoCropMeta*)gst_buffer_add_meta((b),GST_VIDEO_CROP_META_INFO, NULL))
  99. /* video metadata transforms */
  100. GQuark gst_video_meta_transform_scale_get_quark (void);
  101. /**
  102. * gst_video_meta_transform_scale:
  103. *
  104. * GQuark for the video "gst-video-scale" transform.
  105. */
  106. #define GST_VIDEO_META_TRANSFORM_IS_SCALE(type) ((type) == gst_video_meta_transform_scale_get_quark())
  107. /**
  108. * GstVideoMetaTransform:
  109. * @in_info: the input #GstVideoInfo
  110. * @out_info: the output #GstVideoInfo
  111. *
  112. * Extra data passed to a video transform #GstMetaTransformFunction such as:
  113. * "gst-video-scale".
  114. */
  115. typedef struct {
  116. GstVideoInfo *in_info;
  117. GstVideoInfo *out_info;
  118. } GstVideoMetaTransform;
  119. /**
  120. * GstVideoGLTextureType:
  121. * @GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE: Luminance texture, GL_LUMINANCE
  122. * @GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA: Luminance-alpha texture, GL_LUMINANCE_ALPHA
  123. * @GST_VIDEO_GL_TEXTURE_TYPE_RGB16: RGB 565 texture, GL_RGB
  124. * @GST_VIDEO_GL_TEXTURE_TYPE_RGB: RGB texture, GL_RGB
  125. * @GST_VIDEO_GL_TEXTURE_TYPE_RGBA: RGBA texture, GL_RGBA
  126. * @GST_VIDEO_GL_TEXTURE_TYPE_R: R texture, GL_RED_EXT
  127. * @GST_VIDEO_GL_TEXTURE_TYPE_RG: RG texture, GL_RG_EXT
  128. *
  129. * The GL texture type.
  130. */
  131. typedef enum
  132. {
  133. GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE,
  134. GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA,
  135. GST_VIDEO_GL_TEXTURE_TYPE_RGB16,
  136. GST_VIDEO_GL_TEXTURE_TYPE_RGB,
  137. GST_VIDEO_GL_TEXTURE_TYPE_RGBA,
  138. GST_VIDEO_GL_TEXTURE_TYPE_R,
  139. GST_VIDEO_GL_TEXTURE_TYPE_RG
  140. } GstVideoGLTextureType;
  141. /**
  142. * GstVideoGLTextureOrientation:
  143. * @GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL: Top line first in memory, left row first
  144. * @GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_FLIP: Bottom line first in memory, left row first
  145. * @GST_VIDEO_GL_TEXTURE_ORIENTATION_X_FLIP_Y_NORMAL: Top line first in memory, right row first
  146. * @GST_VIDEO_GL_TEXTURE_ORIENTATION_X_FLIP_Y_FLIP: Bottom line first in memory, right row first
  147. *
  148. * The orientation of the GL texture.
  149. */
  150. typedef enum
  151. {
  152. GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL,
  153. GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_FLIP,
  154. GST_VIDEO_GL_TEXTURE_ORIENTATION_X_FLIP_Y_NORMAL,
  155. GST_VIDEO_GL_TEXTURE_ORIENTATION_X_FLIP_Y_FLIP
  156. } GstVideoGLTextureOrientation;
  157. #define GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE (gst_video_gl_texture_upload_meta_api_get_type())
  158. #define GST_VIDEO_GL_TEXTURE_UPLOAD_META_INFO (gst_video_gl_texture_upload_meta_get_info())
  159. typedef struct _GstVideoGLTextureUploadMeta GstVideoGLTextureUploadMeta;
  160. typedef gboolean (*GstVideoGLTextureUpload) (GstVideoGLTextureUploadMeta *meta, guint texture_id[4]);
  161. #define GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META "meta:GstVideoGLTextureUploadMeta"
  162. /**
  163. * GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META:
  164. *
  165. * An option that can be activated on a bufferpool to request gl texture upload
  166. * meta on buffers from the pool.
  167. *
  168. * When this option is enabled on the bufferpool,
  169. * @GST_BUFFER_POOL_OPTION_VIDEO_META should also be enabled.
  170. *
  171. * Since: 1.2.2
  172. */
  173. #define GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META "GstBufferPoolOptionVideoGLTextureUploadMeta"
  174. /**
  175. * GstVideoGLTextureUploadMeta:
  176. * @meta: parent #GstMeta
  177. * @texture_orientation: Orientation of the textures
  178. * @n_textures: Number of textures that are generated
  179. * @texture_type: Type of each texture
  180. *
  181. * Extra buffer metadata for uploading a buffer to an OpenGL texture
  182. * ID. The caller of gst_video_gl_texture_upload_meta_upload() must
  183. * have OpenGL set up and call this from a thread where it is valid
  184. * to upload something to an OpenGL texture.
  185. */
  186. struct _GstVideoGLTextureUploadMeta {
  187. GstMeta meta;
  188. GstVideoGLTextureOrientation texture_orientation;
  189. guint n_textures;
  190. GstVideoGLTextureType texture_type[4];
  191. /* <private> */
  192. GstBuffer *buffer;
  193. GstVideoGLTextureUpload upload;
  194. gpointer user_data;
  195. GBoxedCopyFunc user_data_copy;
  196. GBoxedFreeFunc user_data_free;
  197. };
  198. GType gst_video_gl_texture_upload_meta_api_get_type (void);
  199. const GstMetaInfo * gst_video_gl_texture_upload_meta_get_info (void);
  200. #define gst_buffer_get_video_gl_texture_upload_meta(b) ((GstVideoGLTextureUploadMeta*)gst_buffer_get_meta((b),GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE))
  201. GstVideoGLTextureUploadMeta *
  202. gst_buffer_add_video_gl_texture_upload_meta (GstBuffer *buffer,
  203. GstVideoGLTextureOrientation texture_orientation,
  204. guint n_textures,
  205. GstVideoGLTextureType texture_type[4],
  206. GstVideoGLTextureUpload upload,
  207. gpointer user_data,
  208. GBoxedCopyFunc user_data_copy,
  209. GBoxedFreeFunc user_data_free);
  210. gboolean gst_video_gl_texture_upload_meta_upload (GstVideoGLTextureUploadMeta *meta,
  211. guint texture_id[4]);
  212. /**
  213. * GstVideoRegionOfInterestMeta:
  214. * @meta: parent #GstMeta
  215. * @roi_type: GQuark describing the semantic of the Roi (f.i. a face, a pedestrian)
  216. * @id: identifier of this particular ROI
  217. * @parent_id: identifier of its parent ROI, used f.i. for ROI hierarchisation.
  218. * @x: x component of upper-left corner
  219. * @y: y component of upper-left corner
  220. * @width: bounding box width
  221. * @height: bounding box height
  222. *
  223. * Extra buffer metadata describing an image region of interest
  224. */
  225. typedef struct {
  226. GstMeta meta;
  227. GQuark roi_type;
  228. gint id;
  229. gint parent_id;
  230. guint x;
  231. guint y;
  232. guint w;
  233. guint h;
  234. } GstVideoRegionOfInterestMeta;
  235. GType gst_video_region_of_interest_meta_api_get_type (void);
  236. #define GST_VIDEO_REGION_OF_INTEREST_META_API_TYPE (gst_video_region_of_interest_meta_api_get_type())
  237. const GstMetaInfo *gst_video_region_of_interest_meta_get_info (void);
  238. #define GST_VIDEO_REGION_OF_INTEREST_META_INFO (gst_video_region_of_interest_meta_get_info())
  239. #define gst_buffer_get_video_region_of_interest_meta(b) \
  240. ((GstVideoRegionOfInterestMeta*)gst_buffer_get_meta((b),GST_VIDEO_REGION_OF_INTEREST_META_API_TYPE))
  241. GstVideoRegionOfInterestMeta *gst_buffer_get_video_region_of_interest_meta_id (GstBuffer * buffer,
  242. gint id);
  243. GstVideoRegionOfInterestMeta *gst_buffer_add_video_region_of_interest_meta (GstBuffer * buffer,
  244. const gchar * roi_type,
  245. guint x,
  246. guint y,
  247. guint w,
  248. guint h);
  249. GstVideoRegionOfInterestMeta *gst_buffer_add_video_region_of_interest_meta_id (GstBuffer * buffer,
  250. GQuark roi_type,
  251. guint x,
  252. guint y,
  253. guint w,
  254. guint h);
  255. G_END_DECLS
  256. #endif /* __GST_VIDEO_META_H__ */