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>
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.
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.
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.
22 #ifndef __GST_VIDEO_OVERLAY_COMPOSITION_H__
23 #define __GST_VIDEO_OVERLAY_COMPOSITION_H__
26 #include <gst/video/video.h>
31 * GstVideoOverlayRectangle:
33 * An opaque video overlay rectangle object. A rectangle contains a single
34 * overlay rectangle which can be added to a composition.
36 #define GST_TYPE_VIDEO_OVERLAY_RECTANGLE \
37 (gst_video_overlay_rectangle_get_type ())
38 #define GST_VIDEO_OVERLAY_RECTANGLE_CAST(obj) \
39 ((GstVideoOverlayRectangle *)(obj))
40 #define GST_VIDEO_OVERLAY_RECTANGLE(obj) \
41 (GST_VIDEO_OVERLAY_RECTANGLE_CAST(obj))
42 #define GST_IS_VIDEO_OVERLAY_RECTANGLE(obj) \
43 (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_VIDEO_OVERLAY_RECTANGLE))
45 typedef struct _GstVideoOverlayRectangle GstVideoOverlayRectangle;
48 * gst_video_overlay_rectangle_ref:
49 * @comp: a a #GstVideoOverlayRectangle.
51 * Increases the refcount of the given rectangle by one.
53 * Note that the refcount affects the writeability
54 * of @comp, use gst_video_overlay_rectangle_copy() to ensure a rectangle can
55 * be modified (there is no gst_video_overlay_rectangle_make_writable() because
56 * it is unlikely that someone will hold the single reference to the rectangle
57 * and not know that that's the case).
59 * Returns: (transfer full): @comp
61 static inline GstVideoOverlayRectangle *
62 gst_video_overlay_rectangle_ref (GstVideoOverlayRectangle * comp)
64 return (GstVideoOverlayRectangle *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (comp));
68 * gst_video_overlay_rectangle_unref:
69 * @comp: (transfer full): a #GstVideoOverlayRectangle.
71 * Decreases the refcount of the rectangle. If the refcount reaches 0, the
72 * rectangle will be freed.
75 gst_video_overlay_rectangle_unref (GstVideoOverlayRectangle * comp)
77 gst_mini_object_unref (GST_MINI_OBJECT_CAST (comp));
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.
86 * Overlay format flags.
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;
94 #define GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION "meta:GstVideoOverlayComposition"
97 * GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB:
99 * Supported RGB overlay video format.
101 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
102 #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB GST_VIDEO_FORMAT_BGRA
104 #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB GST_VIDEO_FORMAT_ARGB
108 * GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV:
110 * Supported YUV overlay video format.
112 #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV GST_VIDEO_FORMAT_AYUV
115 * GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS:
117 * Video formats supported by gst_video_overlay_composition_blend(), for
118 * use in overlay elements' pad template caps.
122 #define GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS \
123 "{ BGRx, RGBx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR," \
124 " I420, YV12, AYUV, YUY2, UYVY, v308, Y41B, Y42B, Y444," \
125 " NV12, NV21, A420, YUV9, YVU9, IYU1, GRAY8 }"
128 GType gst_video_overlay_rectangle_get_type (void);
131 GstVideoOverlayRectangle * gst_video_overlay_rectangle_new_raw (GstBuffer * pixels,
132 gint render_x, gint render_y,
133 guint render_width, guint render_height,
134 GstVideoOverlayFormatFlags flags);
137 GstVideoOverlayRectangle * gst_video_overlay_rectangle_copy (GstVideoOverlayRectangle * rectangle);
140 guint gst_video_overlay_rectangle_get_seqnum (GstVideoOverlayRectangle * rectangle);
143 void gst_video_overlay_rectangle_set_render_rectangle (GstVideoOverlayRectangle * rectangle,
147 guint render_height);
150 gboolean gst_video_overlay_rectangle_get_render_rectangle (GstVideoOverlayRectangle * rectangle,
153 guint * render_width,
154 guint * render_height);
157 GstBuffer * gst_video_overlay_rectangle_get_pixels_raw (GstVideoOverlayRectangle * rectangle,
158 GstVideoOverlayFormatFlags flags);
161 GstBuffer * gst_video_overlay_rectangle_get_pixels_argb (GstVideoOverlayRectangle * rectangle,
162 GstVideoOverlayFormatFlags flags);
165 GstBuffer * gst_video_overlay_rectangle_get_pixels_ayuv (GstVideoOverlayRectangle * rectangle,
166 GstVideoOverlayFormatFlags flags);
169 GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_raw (GstVideoOverlayRectangle * rectangle,
170 GstVideoOverlayFormatFlags flags);
173 GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_argb (GstVideoOverlayRectangle * rectangle,
174 GstVideoOverlayFormatFlags flags);
177 GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_ayuv (GstVideoOverlayRectangle * rectangle,
178 GstVideoOverlayFormatFlags flags);
181 GstVideoOverlayFormatFlags gst_video_overlay_rectangle_get_flags (GstVideoOverlayRectangle * rectangle);
184 gfloat gst_video_overlay_rectangle_get_global_alpha (GstVideoOverlayRectangle * rectangle);
187 void gst_video_overlay_rectangle_set_global_alpha (GstVideoOverlayRectangle * rectangle,
188 gfloat global_alpha);
191 * GstVideoOverlayComposition:
193 * An opaque video overlay composition object. A composition contains
194 * multiple overlay rectangles.
196 #define GST_TYPE_VIDEO_OVERLAY_COMPOSITION \
197 (gst_video_overlay_composition_get_type ())
198 #define GST_VIDEO_OVERLAY_COMPOSITION_CAST(obj) \
199 ((GstVideoOverlayComposition *)(obj))
200 #define GST_VIDEO_OVERLAY_COMPOSITION(obj) \
201 (GST_VIDEO_OVERLAY_COMPOSITION_CAST(obj))
202 #define GST_IS_VIDEO_OVERLAY_COMPOSITION(obj) \
203 (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_VIDEO_OVERLAY_COMPOSITION))
205 typedef struct _GstVideoOverlayComposition GstVideoOverlayComposition;
208 * gst_video_overlay_composition_ref:
209 * @comp: a a #GstVideoOverlayComposition.
211 * Increases the refcount of the given composition by one.
213 * Note that the refcount affects the writeability
214 * of @comp, use gst_video_overlay_composition_make_writable() to ensure
215 * a composition and its rectangles can be modified.
217 * Returns: (transfer full): @comp
219 static inline GstVideoOverlayComposition *
220 gst_video_overlay_composition_ref (GstVideoOverlayComposition * comp)
222 return (GstVideoOverlayComposition *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (comp));
226 * gst_video_overlay_composition_unref:
227 * @comp: (transfer full): a #GstVideoOverlayComposition.
229 * Decreases the refcount of the composition. If the refcount reaches 0, the
230 * composition will be freed.
233 gst_video_overlay_composition_unref (GstVideoOverlayComposition * comp)
235 gst_mini_object_unref (GST_MINI_OBJECT_CAST (comp));
239 GType gst_video_overlay_composition_get_type (void);
242 GstVideoOverlayComposition * gst_video_overlay_composition_copy (GstVideoOverlayComposition * comp);
245 GstVideoOverlayComposition * gst_video_overlay_composition_make_writable (GstVideoOverlayComposition * comp);
248 GstVideoOverlayComposition * gst_video_overlay_composition_new (GstVideoOverlayRectangle * rectangle);
251 void gst_video_overlay_composition_add_rectangle (GstVideoOverlayComposition * comp,
252 GstVideoOverlayRectangle * rectangle);
255 guint gst_video_overlay_composition_n_rectangles (GstVideoOverlayComposition * comp);
258 GstVideoOverlayRectangle * gst_video_overlay_composition_get_rectangle (GstVideoOverlayComposition * comp, guint n);
261 guint gst_video_overlay_composition_get_seqnum (GstVideoOverlayComposition * comp);
263 /* blend composition onto raw video buffer */
266 gboolean gst_video_overlay_composition_blend (GstVideoOverlayComposition * comp,
267 GstVideoFrame * video_buf);
269 /* attach/retrieve composition from buffers */
271 #define GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE \
272 (gst_video_overlay_composition_meta_api_get_type())
273 #define GST_VIDEO_OVERLAY_COMPOSITION_META_INFO \
274 (gst_video_overlay_composition_meta_get_info())
276 typedef struct _GstVideoOverlayCompositionMeta GstVideoOverlayCompositionMeta;
279 * GstVideoOverlayCompositionMeta:
280 * @meta: parent #GstMeta
281 * @overlay: the attached #GstVideoOverlayComposition
283 * Extra buffer metadata describing image overlay data.
285 struct _GstVideoOverlayCompositionMeta
289 GstVideoOverlayComposition *overlay;
293 GType gst_video_overlay_composition_meta_api_get_type (void);
296 const GstMetaInfo *gst_video_overlay_composition_meta_get_info (void);
299 GstVideoOverlayCompositionMeta * gst_buffer_add_video_overlay_composition_meta (GstBuffer * buf,
300 GstVideoOverlayComposition * comp);
302 #define gst_buffer_get_video_overlay_composition_meta(b) \
303 ((GstVideoOverlayCompositionMeta*)gst_buffer_get_meta((b),GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE))
304 #define gst_buffer_remove_video_overlay_composition_meta(b,m) \
305 gst_buffer_remove_meta((b),((GstMeta *) m))
307 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
308 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoOverlayComposition, gst_video_overlay_composition_unref)
311 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
312 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoOverlayRectangle, gst_video_overlay_rectangle_unref)
317 #endif /* __GST_VIDEO_OVERLAY_COMPOSITION_H__ */