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
28G_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
45typedef 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 */
61static inline GstVideoOverlayRectangle *
62gst_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 */
74static inline void
75gst_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 */
88typedef 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 GST_VIDEO_FORMATS_ALL
123
124GST_VIDEO_API
125GType gst_video_overlay_rectangle_get_type (void);
126
127GST_VIDEO_API
128GstVideoOverlayRectangle * gst_video_overlay_rectangle_new_raw (GstBuffer * pixels,
129 gint render_x, gint render_y,
130 guint render_width, guint render_height,
131 GstVideoOverlayFormatFlags flags);
132
133GST_VIDEO_API
134GstVideoOverlayRectangle * gst_video_overlay_rectangle_copy (GstVideoOverlayRectangle * rectangle);
135
136GST_VIDEO_API
137guint gst_video_overlay_rectangle_get_seqnum (GstVideoOverlayRectangle * rectangle);
138
139GST_VIDEO_API
140void gst_video_overlay_rectangle_set_render_rectangle (GstVideoOverlayRectangle * rectangle,
141 gint render_x,
142 gint render_y,
143 guint render_width,
144 guint render_height);
145
146GST_VIDEO_API
147gboolean gst_video_overlay_rectangle_get_render_rectangle (GstVideoOverlayRectangle * rectangle,
148 gint * render_x,
149 gint * render_y,
150 guint * render_width,
151 guint * render_height);
152
153GST_VIDEO_API
154GstBuffer * gst_video_overlay_rectangle_get_pixels_raw (GstVideoOverlayRectangle * rectangle,
155 GstVideoOverlayFormatFlags flags);
156
157GST_VIDEO_API
158GstBuffer * gst_video_overlay_rectangle_get_pixels_argb (GstVideoOverlayRectangle * rectangle,
159 GstVideoOverlayFormatFlags flags);
160
161GST_VIDEO_API
162GstBuffer * gst_video_overlay_rectangle_get_pixels_ayuv (GstVideoOverlayRectangle * rectangle,
163 GstVideoOverlayFormatFlags flags);
164
165GST_VIDEO_API
166GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_raw (GstVideoOverlayRectangle * rectangle,
167 GstVideoOverlayFormatFlags flags);
168
169GST_VIDEO_API
170GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_argb (GstVideoOverlayRectangle * rectangle,
171 GstVideoOverlayFormatFlags flags);
172
173GST_VIDEO_API
174GstBuffer * gst_video_overlay_rectangle_get_pixels_unscaled_ayuv (GstVideoOverlayRectangle * rectangle,
175 GstVideoOverlayFormatFlags flags);
176
177GST_VIDEO_API
178GstVideoOverlayFormatFlags gst_video_overlay_rectangle_get_flags (GstVideoOverlayRectangle * rectangle);
179
180GST_VIDEO_API
181gfloat gst_video_overlay_rectangle_get_global_alpha (GstVideoOverlayRectangle * rectangle);
182
183GST_VIDEO_API
184void gst_video_overlay_rectangle_set_global_alpha (GstVideoOverlayRectangle * rectangle,
185 gfloat global_alpha);
186
187/**
188 * GstVideoOverlayComposition:
189 *
190 * An opaque video overlay composition object. A composition contains
191 * multiple overlay rectangles.
192 */
193#define GST_TYPE_VIDEO_OVERLAY_COMPOSITION \
194 (gst_video_overlay_composition_get_type ())
195#define GST_VIDEO_OVERLAY_COMPOSITION_CAST(obj) \
196 ((GstVideoOverlayComposition *)(obj))
197#define GST_VIDEO_OVERLAY_COMPOSITION(obj) \
198 (GST_VIDEO_OVERLAY_COMPOSITION_CAST(obj))
199#define GST_IS_VIDEO_OVERLAY_COMPOSITION(obj) \
200 (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_VIDEO_OVERLAY_COMPOSITION))
201
202typedef struct _GstVideoOverlayComposition GstVideoOverlayComposition;
203
204/**
205 * gst_video_overlay_composition_ref:
206 * @comp: a a #GstVideoOverlayComposition.
207 *
208 * Increases the refcount of the given composition by one.
209 *
210 * Note that the refcount affects the writeability
211 * of @comp, use gst_video_overlay_composition_make_writable() to ensure
212 * a composition and its rectangles can be modified.
213 *
214 * Returns: (transfer full): @comp
215 */
216static inline GstVideoOverlayComposition *
217gst_video_overlay_composition_ref (GstVideoOverlayComposition * comp)
218{
219 return (GstVideoOverlayComposition *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (comp));
220}
221
222/**
223 * gst_video_overlay_composition_unref:
224 * @comp: (transfer full): a #GstVideoOverlayComposition.
225 *
226 * Decreases the refcount of the composition. If the refcount reaches 0, the
227 * composition will be freed.
228 */
229static inline void
230gst_video_overlay_composition_unref (GstVideoOverlayComposition * comp)
231{
232 gst_mini_object_unref (GST_MINI_OBJECT_CAST (comp));
233}
234
235GST_VIDEO_API
236GType gst_video_overlay_composition_get_type (void);
237
238GST_VIDEO_API
239GstVideoOverlayComposition * gst_video_overlay_composition_copy (GstVideoOverlayComposition * comp);
240
241GST_VIDEO_API
242GstVideoOverlayComposition * gst_video_overlay_composition_make_writable (GstVideoOverlayComposition * comp);
243
244GST_VIDEO_API
245GstVideoOverlayComposition * gst_video_overlay_composition_new (GstVideoOverlayRectangle * rectangle);
246
247GST_VIDEO_API
248void gst_video_overlay_composition_add_rectangle (GstVideoOverlayComposition * comp,
249 GstVideoOverlayRectangle * rectangle);
250
251GST_VIDEO_API
252guint gst_video_overlay_composition_n_rectangles (GstVideoOverlayComposition * comp);
253
254GST_VIDEO_API
255GstVideoOverlayRectangle * gst_video_overlay_composition_get_rectangle (GstVideoOverlayComposition * comp, guint n);
256
257GST_VIDEO_API
258guint gst_video_overlay_composition_get_seqnum (GstVideoOverlayComposition * comp);
259
260/* blend composition onto raw video buffer */
261
262GST_VIDEO_API
263gboolean gst_video_overlay_composition_blend (GstVideoOverlayComposition * comp,
264 GstVideoFrame * video_buf);
265
266/* attach/retrieve composition from buffers */
267
268#define GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE \
269 (gst_video_overlay_composition_meta_api_get_type())
270#define GST_VIDEO_OVERLAY_COMPOSITION_META_INFO \
271 (gst_video_overlay_composition_meta_get_info())
272
273typedef struct _GstVideoOverlayCompositionMeta GstVideoOverlayCompositionMeta;
274
275/**
276 * GstVideoOverlayCompositionMeta:
277 * @meta: parent #GstMeta
278 * @overlay: the attached #GstVideoOverlayComposition
279 *
280 * Extra buffer metadata describing image overlay data.
281 */
282struct _GstVideoOverlayCompositionMeta
283{
284 GstMeta meta;
285
286 GstVideoOverlayComposition *overlay;
287};
288
289GST_VIDEO_API
290GType gst_video_overlay_composition_meta_api_get_type (void);
291
292GST_VIDEO_API
293const GstMetaInfo *gst_video_overlay_composition_meta_get_info (void);
294
295GST_VIDEO_API
296GstVideoOverlayCompositionMeta * gst_buffer_add_video_overlay_composition_meta (GstBuffer * buf,
297 GstVideoOverlayComposition * comp);
298
299#define gst_buffer_get_video_overlay_composition_meta(b) \
300 ((GstVideoOverlayCompositionMeta*)gst_buffer_get_meta((b),GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE))
301#define gst_buffer_remove_video_overlay_composition_meta(b,m) \
302 gst_buffer_remove_meta((b),((GstMeta *) m))
303
304G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoOverlayComposition, gst_video_overlay_composition_unref)
305
306G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoOverlayRectangle, gst_video_overlay_rectangle_unref)
307
308G_END_DECLS
309
310#endif /* __GST_VIDEO_OVERLAY_COMPOSITION_H__ */
311

source code of include/gstreamer-1.0/gst/video/video-overlay-composition.h