video-overlay-composition.h 12 KB

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