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 | |
22 | #ifndef __GST_VIDEO_OVERLAY_COMPOSITION_H__ |
23 | #define __GST_VIDEO_OVERLAY_COMPOSITION_H__ |
24 | |
25 | #include <gst/gst.h> |
26 | #include <gst/video/video.h> |
27 | |
28 | G_BEGIN_DECLS |
29 | |
30 | /** |
31 | * GstVideoOverlayRectangle: |
32 | * |
33 | * An opaque video overlay rectangle object. A rectangle contains a single |
34 | * overlay rectangle which can be added to a composition. |
35 | */ |
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)) |
44 | |
45 | typedef struct _GstVideoOverlayRectangle GstVideoOverlayRectangle; |
46 | |
47 | /** |
48 | * gst_video_overlay_rectangle_ref: |
49 | * @comp: a a #GstVideoOverlayRectangle. |
50 | * |
51 | * Increases the refcount of the given rectangle by one. |
52 | * |
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). |
58 | * |
59 | * Returns: (transfer full): @comp |
60 | */ |
61 | static inline GstVideoOverlayRectangle * |
62 | gst_video_overlay_rectangle_ref (GstVideoOverlayRectangle * comp) |
63 | { |
64 | return (GstVideoOverlayRectangle *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (comp)); |
65 | } |
66 | |
67 | /** |
68 | * gst_video_overlay_rectangle_unref: |
69 | * @comp: (transfer full): a #GstVideoOverlayRectangle. |
70 | * |
71 | * Decreases the refcount of the rectangle. If the refcount reaches 0, the |
72 | * rectangle will be freed. |
73 | */ |
74 | static inline void |
75 | gst_video_overlay_rectangle_unref (GstVideoOverlayRectangle * comp) |
76 | { |
77 | gst_mini_object_unref (GST_MINI_OBJECT_CAST (comp)); |
78 | } |
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<<0), |
91 | GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA = (1<<1) |
92 | } GstVideoOverlayFormatFlags; |
93 | |
94 | #define GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION "meta:GstVideoOverlayComposition" |
95 | |
96 | /** |
97 | * GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB: |
98 | * |
99 | * Supported RGB overlay video format. |
100 | */ |
101 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
102 | #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB GST_VIDEO_FORMAT_BGRA |
103 | #else |
104 | #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB GST_VIDEO_FORMAT_ARGB |
105 | #endif |
106 | |
107 | /** |
108 | * GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV: |
109 | * |
110 | * Supported YUV overlay video format. |
111 | */ |
112 | #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV GST_VIDEO_FORMAT_AYUV |
113 | |
114 | /** |
115 | * GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS: |
116 | * |
117 | * Video formats supported by gst_video_overlay_composition_blend(), for |
118 | * use in overlay elements' pad template caps. |
119 | * |
120 | * Since: 1.2 |
121 | */ |
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 }" |
126 | |
127 | GST_VIDEO_API |
128 | GType gst_video_overlay_rectangle_get_type (void); |
129 | |
130 | GST_VIDEO_API |
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); |
135 | |
136 | GST_VIDEO_API |
137 | GstVideoOverlayRectangle * gst_video_overlay_rectangle_copy (GstVideoOverlayRectangle * rectangle); |
138 | |
139 | GST_VIDEO_API |
140 | guint gst_video_overlay_rectangle_get_seqnum (GstVideoOverlayRectangle * rectangle); |
141 | |
142 | GST_VIDEO_API |
143 | void gst_video_overlay_rectangle_set_render_rectangle (GstVideoOverlayRectangle * rectangle, |
144 | gint render_x, |
145 | gint render_y, |
146 | guint render_width, |
147 | guint render_height); |
148 | |
149 | GST_VIDEO_API |
150 | gboolean gst_video_overlay_rectangle_get_render_rectangle (GstVideoOverlayRectangle * rectangle, |
151 | gint * render_x, |
152 | gint * render_y, |
153 | guint * render_width, |
154 | guint * render_height); |
155 | |
156 | GST_VIDEO_API |
157 | GstBuffer * gst_video_overlay_rectangle_get_pixels_raw (GstVideoOverlayRectangle * rectangle, |
158 | GstVideoOverlayFormatFlags flags); |
159 | |
160 | GST_VIDEO_API |
161 | GstBuffer * gst_video_overlay_rectangle_get_pixels_argb (GstVideoOverlayRectangle * rectangle, |
162 | GstVideoOverlayFormatFlags flags); |
163 | |
164 | GST_VIDEO_API |
165 | GstBuffer * gst_video_overlay_rectangle_get_pixels_ayuv (GstVideoOverlayRectangle * rectangle, |
166 | GstVideoOverlayFormatFlags flags); |
167 | |
168 | GST_VIDEO_API |
169 | GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_raw (GstVideoOverlayRectangle * rectangle, |
170 | GstVideoOverlayFormatFlags flags); |
171 | |
172 | GST_VIDEO_API |
173 | GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_argb (GstVideoOverlayRectangle * rectangle, |
174 | GstVideoOverlayFormatFlags flags); |
175 | |
176 | GST_VIDEO_API |
177 | GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_ayuv (GstVideoOverlayRectangle * rectangle, |
178 | GstVideoOverlayFormatFlags flags); |
179 | |
180 | GST_VIDEO_API |
181 | GstVideoOverlayFormatFlags gst_video_overlay_rectangle_get_flags (GstVideoOverlayRectangle * rectangle); |
182 | |
183 | GST_VIDEO_API |
184 | gfloat gst_video_overlay_rectangle_get_global_alpha (GstVideoOverlayRectangle * rectangle); |
185 | |
186 | GST_VIDEO_API |
187 | void gst_video_overlay_rectangle_set_global_alpha (GstVideoOverlayRectangle * rectangle, |
188 | gfloat global_alpha); |
189 | |
190 | /** |
191 | * GstVideoOverlayComposition: |
192 | * |
193 | * An opaque video overlay composition object. A composition contains |
194 | * multiple overlay rectangles. |
195 | */ |
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)) |
204 | |
205 | typedef struct _GstVideoOverlayComposition GstVideoOverlayComposition; |
206 | |
207 | /** |
208 | * gst_video_overlay_composition_ref: |
209 | * @comp: a a #GstVideoOverlayComposition. |
210 | * |
211 | * Increases the refcount of the given composition by one. |
212 | * |
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. |
216 | * |
217 | * Returns: (transfer full): @comp |
218 | */ |
219 | static inline GstVideoOverlayComposition * |
220 | gst_video_overlay_composition_ref (GstVideoOverlayComposition * comp) |
221 | { |
222 | return (GstVideoOverlayComposition *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (comp)); |
223 | } |
224 | |
225 | /** |
226 | * gst_video_overlay_composition_unref: |
227 | * @comp: (transfer full): a #GstVideoOverlayComposition. |
228 | * |
229 | * Decreases the refcount of the composition. If the refcount reaches 0, the |
230 | * composition will be freed. |
231 | */ |
232 | static inline void |
233 | gst_video_overlay_composition_unref (GstVideoOverlayComposition * comp) |
234 | { |
235 | gst_mini_object_unref (GST_MINI_OBJECT_CAST (comp)); |
236 | } |
237 | |
238 | GST_VIDEO_API |
239 | GType gst_video_overlay_composition_get_type (void); |
240 | |
241 | GST_VIDEO_API |
242 | GstVideoOverlayComposition * gst_video_overlay_composition_copy (GstVideoOverlayComposition * comp); |
243 | |
244 | GST_VIDEO_API |
245 | GstVideoOverlayComposition * gst_video_overlay_composition_make_writable (GstVideoOverlayComposition * comp); |
246 | |
247 | GST_VIDEO_API |
248 | GstVideoOverlayComposition * gst_video_overlay_composition_new (GstVideoOverlayRectangle * rectangle); |
249 | |
250 | GST_VIDEO_API |
251 | void gst_video_overlay_composition_add_rectangle (GstVideoOverlayComposition * comp, |
252 | GstVideoOverlayRectangle * rectangle); |
253 | |
254 | GST_VIDEO_API |
255 | guint gst_video_overlay_composition_n_rectangles (GstVideoOverlayComposition * comp); |
256 | |
257 | GST_VIDEO_API |
258 | GstVideoOverlayRectangle * gst_video_overlay_composition_get_rectangle (GstVideoOverlayComposition * comp, guint n); |
259 | |
260 | GST_VIDEO_API |
261 | guint gst_video_overlay_composition_get_seqnum (GstVideoOverlayComposition * comp); |
262 | |
263 | /* blend composition onto raw video buffer */ |
264 | |
265 | GST_VIDEO_API |
266 | gboolean gst_video_overlay_composition_blend (GstVideoOverlayComposition * comp, |
267 | GstVideoFrame * video_buf); |
268 | |
269 | /* attach/retrieve composition from buffers */ |
270 | |
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()) |
275 | |
276 | typedef struct _GstVideoOverlayCompositionMeta GstVideoOverlayCompositionMeta; |
277 | |
278 | /** |
279 | * GstVideoOverlayCompositionMeta: |
280 | * @meta: parent #GstMeta |
281 | * @overlay: the attached #GstVideoOverlayComposition |
282 | * |
283 | * Extra buffer metadata describing image overlay data. |
284 | */ |
285 | struct _GstVideoOverlayCompositionMeta |
286 | { |
287 | GstMeta meta; |
288 | |
289 | GstVideoOverlayComposition *overlay; |
290 | }; |
291 | |
292 | GST_VIDEO_API |
293 | GType gst_video_overlay_composition_meta_api_get_type (void); |
294 | |
295 | GST_VIDEO_API |
296 | const GstMetaInfo *gst_video_overlay_composition_meta_get_info (void); |
297 | |
298 | GST_VIDEO_API |
299 | GstVideoOverlayCompositionMeta * gst_buffer_add_video_overlay_composition_meta (GstBuffer * buf, |
300 | GstVideoOverlayComposition * comp); |
301 | |
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)) |
306 | |
307 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC |
308 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoOverlayComposition, gst_video_overlay_composition_unref) |
309 | #endif |
310 | |
311 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC |
312 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoOverlayRectangle, gst_video_overlay_rectangle_unref) |
313 | #endif |
314 | |
315 | G_END_DECLS |
316 | |
317 | #endif /* __GST_VIDEO_OVERLAY_COMPOSITION_H__ */ |
318 | |