video-overlay-composition.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* GStreamer Video Overlay Composition
  2. * Copyright (C) 2011 Intel Corporation
  3. * Copyright (C) 2011 Collabora Ltd.
  4. * Copyright (C) 2011 Tim-Philipp Müller <tim centricular net>
  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_VIDEO_OVERLAY_COMPOSITION_H__
  22. #define __GST_VIDEO_OVERLAY_COMPOSITION_H__
  23. #include <gst/gst.h>
  24. #include <gst/video/video.h>
  25. G_BEGIN_DECLS
  26. /**
  27. * GstVideoOverlayRectangle:
  28. *
  29. * An opaque video overlay rectangle object. A rectangle contains a single
  30. * overlay rectangle which can be added to a composition.
  31. */
  32. #define GST_TYPE_VIDEO_OVERLAY_RECTANGLE \
  33. (gst_video_overlay_rectangle_get_type ())
  34. #define GST_VIDEO_OVERLAY_RECTANGLE_CAST(obj) \
  35. ((GstVideoOverlayRectangle *)(obj)
  36. #define GST_VIDEO_OVERLAY_RECTANGLE(obj) \
  37. (GST_VIDEO_OVERLAY_RECTANGLE_CAST(obj))
  38. #define GST_IS_VIDEO_OVERLAY_RECTANGLE(obj) \
  39. (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_VIDEO_OVERLAY_RECTANGLE))
  40. typedef struct _GstVideoOverlayRectangle GstVideoOverlayRectangle;
  41. /**
  42. * gst_video_overlay_rectangle_ref:
  43. * @comp: a a #GstVideoOverlayRectangle.
  44. *
  45. * Increases the refcount of the given rectangle by one.
  46. *
  47. * Note that the refcount affects the writeability
  48. * of @comp, use gst_video_overlay_rectangle_copy() to ensure a rectangle can
  49. * be modified (there is no gst_video_overlay_rectangle_make_writable() because
  50. * it is unlikely that someone will hold the single reference to the rectangle
  51. * and not know that that's the case).
  52. *
  53. * Returns: (transfer full): @comp
  54. */
  55. #ifdef _FOOL_GTK_DOC_
  56. G_INLINE_FUNC GstVideoOverlayRectangle *
  57. gst_video_overlay_rectangle_ref (GstVideoOverlayRectangle * comp);
  58. #endif
  59. static inline GstVideoOverlayRectangle *
  60. gst_video_overlay_rectangle_ref (GstVideoOverlayRectangle * comp)
  61. {
  62. return (GstVideoOverlayRectangle *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (comp));
  63. }
  64. /**
  65. * gst_video_overlay_rectangle_unref:
  66. * @comp: (transfer full): a #GstVideoOverlayRectangle.
  67. *
  68. * Decreases the refcount of the rectangle. If the refcount reaches 0, the
  69. * rectangle will be freed.
  70. */
  71. #ifdef _FOOL_GTK_DOC_
  72. G_INLINE_FUNC void
  73. gst_video_overlay_rectangle_unref (GstVideoOverlayRectangle * comp);
  74. #endif
  75. static inline void
  76. gst_video_overlay_rectangle_unref (GstVideoOverlayRectangle * comp)
  77. {
  78. gst_mini_object_unref (GST_MINI_OBJECT_CAST (comp));
  79. }
  80. /**
  81. * GstVideoOverlayFormatFlags:
  82. * @GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE: no flags
  83. * @GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA: RGB are premultiplied by A/255.
  84. * @GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA: a global-alpha value != 1 is set.
  85. *
  86. * Overlay format flags.
  87. */
  88. typedef enum {
  89. GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE = 0,
  90. GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA = 1,
  91. GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA = 2
  92. } GstVideoOverlayFormatFlags;
  93. #define GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION "meta:GstVideoOverlayComposition"
  94. /**
  95. * GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB:
  96. *
  97. * Supported RGB overlay video format.
  98. */
  99. #if G_BYTE_ORDER == G_LITTLE_ENDIAN
  100. #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB GST_VIDEO_FORMAT_BGRA
  101. #else
  102. #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB GST_VIDEO_FORMAT_ARGB
  103. #endif
  104. /**
  105. * GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV:
  106. *
  107. * Supported YUV overlay video format.
  108. */
  109. #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV GST_VIDEO_FORMAT_AYUV
  110. /**
  111. * GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS:
  112. *
  113. * Video formats supported by gst_video_overlay_composition_blend(), for
  114. * use in overlay elements' pad template caps.
  115. *
  116. * Since: 1.2
  117. */
  118. #define GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS \
  119. "{ BGRx, RGBx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR," \
  120. " I420, YV12, AYUV, YUY2, UYVY, v308, Y41B, Y42B, Y444," \
  121. " NV12, NV21, A420, YUV9, YVU9, IYU1, GRAY8 }"
  122. GType gst_video_overlay_rectangle_get_type (void);
  123. GstVideoOverlayRectangle * gst_video_overlay_rectangle_new_raw (GstBuffer * pixels,
  124. gint render_x, gint render_y,
  125. guint render_width, guint render_height,
  126. GstVideoOverlayFormatFlags flags);
  127. GstVideoOverlayRectangle * gst_video_overlay_rectangle_copy (GstVideoOverlayRectangle * rectangle);
  128. guint gst_video_overlay_rectangle_get_seqnum (GstVideoOverlayRectangle * rectangle);
  129. void gst_video_overlay_rectangle_set_render_rectangle (GstVideoOverlayRectangle * rectangle,
  130. gint render_x,
  131. gint render_y,
  132. guint render_width,
  133. guint render_height);
  134. gboolean gst_video_overlay_rectangle_get_render_rectangle (GstVideoOverlayRectangle * rectangle,
  135. gint * render_x,
  136. gint * render_y,
  137. guint * render_width,
  138. guint * render_height);
  139. GstBuffer * gst_video_overlay_rectangle_get_pixels_raw (GstVideoOverlayRectangle * rectangle,
  140. GstVideoOverlayFormatFlags flags);
  141. GstBuffer * gst_video_overlay_rectangle_get_pixels_argb (GstVideoOverlayRectangle * rectangle,
  142. GstVideoOverlayFormatFlags flags);
  143. GstBuffer * gst_video_overlay_rectangle_get_pixels_ayuv (GstVideoOverlayRectangle * rectangle,
  144. GstVideoOverlayFormatFlags flags);
  145. GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_raw (GstVideoOverlayRectangle * rectangle,
  146. GstVideoOverlayFormatFlags flags);
  147. GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_argb (GstVideoOverlayRectangle * rectangle,
  148. GstVideoOverlayFormatFlags flags);
  149. GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_ayuv (GstVideoOverlayRectangle * rectangle,
  150. GstVideoOverlayFormatFlags flags);
  151. GstVideoOverlayFormatFlags gst_video_overlay_rectangle_get_flags (GstVideoOverlayRectangle * rectangle);
  152. gfloat gst_video_overlay_rectangle_get_global_alpha (GstVideoOverlayRectangle * rectangle);
  153. void gst_video_overlay_rectangle_set_global_alpha (GstVideoOverlayRectangle * rectangle,
  154. gfloat global_alpha);
  155. /**
  156. * GstVideoOverlayComposition:
  157. *
  158. * An opaque video overlay composition object. A composition contains
  159. * multiple overlay rectangles.
  160. */
  161. #define GST_TYPE_VIDEO_OVERLAY_COMPOSITION \
  162. (gst_video_overlay_composition_get_type ())
  163. #define GST_VIDEO_OVERLAY_COMPOSITION_CAST(obj) \
  164. ((GstVideoOverlayComposition *)(obj)
  165. #define GST_VIDEO_OVERLAY_COMPOSITION(obj) \
  166. (GST_VIDEO_OVERLAY_COMPOSITION_CAST(obj))
  167. #define GST_IS_VIDEO_OVERLAY_COMPOSITION(obj) \
  168. (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_VIDEO_OVERLAY_COMPOSITION))
  169. typedef struct _GstVideoOverlayComposition GstVideoOverlayComposition;
  170. /**
  171. * gst_video_overlay_composition_ref:
  172. * @comp: a a #GstVideoOverlayComposition.
  173. *
  174. * Increases the refcount of the given composition by one.
  175. *
  176. * Note that the refcount affects the writeability
  177. * of @comp, use gst_video_overlay_composition_make_writable() to ensure
  178. * a composition and its rectangles can be modified.
  179. *
  180. * Returns: (transfer full): @comp
  181. */
  182. #ifdef _FOOL_GTK_DOC_
  183. G_INLINE_FUNC GstVideoOverlayComposition *
  184. gst_video_overlay_composition_ref (GstVideoOverlayComposition * comp);
  185. #endif
  186. static inline GstVideoOverlayComposition *
  187. gst_video_overlay_composition_ref (GstVideoOverlayComposition * comp)
  188. {
  189. return (GstVideoOverlayComposition *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (comp));
  190. }
  191. /**
  192. * gst_video_overlay_composition_unref:
  193. * @comp: (transfer full): a #GstVideoOverlayComposition.
  194. *
  195. * Decreases the refcount of the composition. If the refcount reaches 0, the
  196. * composition will be freed.
  197. */
  198. #ifdef _FOOL_GTK_DOC_
  199. G_INLINE_FUNC void
  200. gst_video_overlay_composition_unref (GstVideoOverlayComposition * comp);
  201. #endif
  202. static inline void
  203. gst_video_overlay_composition_unref (GstVideoOverlayComposition * comp)
  204. {
  205. gst_mini_object_unref (GST_MINI_OBJECT_CAST (comp));
  206. }
  207. GType gst_video_overlay_composition_get_type (void);
  208. GstVideoOverlayComposition * gst_video_overlay_composition_copy (GstVideoOverlayComposition * comp);
  209. GstVideoOverlayComposition * gst_video_overlay_composition_make_writable (GstVideoOverlayComposition * comp);
  210. GstVideoOverlayComposition * gst_video_overlay_composition_new (GstVideoOverlayRectangle * rectangle);
  211. void gst_video_overlay_composition_add_rectangle (GstVideoOverlayComposition * comp,
  212. GstVideoOverlayRectangle * rectangle);
  213. guint gst_video_overlay_composition_n_rectangles (GstVideoOverlayComposition * comp);
  214. GstVideoOverlayRectangle * gst_video_overlay_composition_get_rectangle (GstVideoOverlayComposition * comp, guint n);
  215. guint gst_video_overlay_composition_get_seqnum (GstVideoOverlayComposition * comp);
  216. /* blend composition onto raw video buffer */
  217. gboolean gst_video_overlay_composition_blend (GstVideoOverlayComposition * comp,
  218. GstVideoFrame * video_buf);
  219. /* attach/retrieve composition from buffers */
  220. #define GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE \
  221. (gst_video_overlay_composition_meta_api_get_type())
  222. #define GST_VIDEO_OVERLAY_COMPOSITION_META_INFO \
  223. (gst_video_overlay_composition_meta_get_info())
  224. typedef struct _GstVideoOverlayCompositionMeta GstVideoOverlayCompositionMeta;
  225. /**
  226. * GstVideoOverlayCompositionMeta:
  227. * @meta: parent #GstMeta
  228. * @overlay: the attached #GstVideoOverlayComposition
  229. *
  230. * Extra buffer metadata describing image overlay data.
  231. */
  232. struct _GstVideoOverlayCompositionMeta
  233. {
  234. GstMeta meta;
  235. GstVideoOverlayComposition *overlay;
  236. };
  237. GType gst_video_overlay_composition_meta_api_get_type (void);
  238. const GstMetaInfo *gst_video_overlay_composition_meta_get_info (void);
  239. GstVideoOverlayCompositionMeta * gst_buffer_add_video_overlay_composition_meta (GstBuffer * buf,
  240. GstVideoOverlayComposition * comp);
  241. #define gst_buffer_get_video_overlay_composition_meta(b) \
  242. ((GstVideoOverlayCompositionMeta*)gst_buffer_get_meta((b),GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE))
  243. #define gst_buffer_remove_video_overlay_composition_meta(b,m) \
  244. gst_buffer_remove_meta((b),((GstMeta *) m))
  245. G_END_DECLS
  246. #endif /* __GST_VIDEO_OVERLAY_COMPOSITION_H__ */