1/* Generic video aggregator plugin
2 * Copyright (C) 2008 Wim Taymans <wim@fluendo.com>
3 * Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef __GST_VIDEO_AGGREGATOR_H__
22#define __GST_VIDEO_AGGREGATOR_H__
23
24#include <gst/video/video.h>
25#include <gst/base/gstaggregator.h>
26
27G_BEGIN_DECLS
28
29typedef struct _GstVideoAggregator GstVideoAggregator;
30typedef struct _GstVideoAggregatorClass GstVideoAggregatorClass;
31typedef struct _GstVideoAggregatorPrivate GstVideoAggregatorPrivate;
32
33/*************************
34 * GstVideoAggregatorPad *
35 *************************/
36
37#define GST_TYPE_VIDEO_AGGREGATOR_PAD (gst_video_aggregator_pad_get_type())
38#define GST_VIDEO_AGGREGATOR_PAD(obj) \
39 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_AGGREGATOR_PAD, GstVideoAggregatorPad))
40#define GST_VIDEO_AGGREGATOR_PAD_CAST(obj) ((GstVideoAggregatorPad *)(obj))
41#define GST_VIDEO_AGGREGATOR_PAD_CLASS(klass) \
42 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_AGGREGATOR_PAD, GstVideoAggregatorPadClass))
43#define GST_IS_VIDEO_AGGREGATOR_PAD(obj) \
44 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_AGGREGATOR_PAD))
45#define GST_IS_VIDEO_AGGREGATOR_PAD_CLASS(klass) \
46 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_AGGREGATOR_PAD))
47#define GST_VIDEO_AGGREGATOR_PAD_GET_CLASS(obj) \
48 (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_VIDEO_AGGREGATOR_PAD,GstVideoAggregatorPadClass))
49
50typedef struct _GstVideoAggregatorPad GstVideoAggregatorPad;
51typedef struct _GstVideoAggregatorPadClass GstVideoAggregatorPadClass;
52typedef struct _GstVideoAggregatorPadPrivate GstVideoAggregatorPadPrivate;
53
54/**
55 * GstVideoAggregatorPad:
56 * @info: The #GstVideoInfo currently set on the pad
57 */
58struct _GstVideoAggregatorPad
59{
60 GstAggregatorPad parent;
61
62 /*< public >*/
63 /* read-only, with OBJECT_LOCK */
64 GstVideoInfo info;
65
66 /* < private > */
67 GstVideoAggregatorPadPrivate *priv;
68
69 gpointer _gst_reserved[GST_PADDING];
70};
71
72/**
73 * GstVideoAggregatorPadClass:
74 * @update_conversion_info: Called when either the input or output formats
75 * have changed.
76 * @prepare_frame: Prepare the frame from the pad buffer and sets it to prepared_frame
77 * @clean_frame: clean the frame previously prepared in prepare_frame
78 */
79struct _GstVideoAggregatorPadClass
80{
81 GstAggregatorPadClass parent_class;
82 void (*update_conversion_info) (GstVideoAggregatorPad * pad);
83
84 gboolean (*prepare_frame) (GstVideoAggregatorPad * pad,
85 GstVideoAggregator * videoaggregator,
86 GstBuffer * buffer,
87 GstVideoFrame * prepared_frame);
88
89 void (*clean_frame) (GstVideoAggregatorPad * pad,
90 GstVideoAggregator * videoaggregator,
91 GstVideoFrame * prepared_frame);
92
93 gpointer _gst_reserved[GST_PADDING_LARGE];
94};
95
96GST_VIDEO_API
97GType gst_video_aggregator_pad_get_type (void);
98
99GST_VIDEO_API
100gboolean gst_video_aggregator_pad_has_current_buffer (GstVideoAggregatorPad *pad);
101
102GST_VIDEO_API
103GstBuffer * gst_video_aggregator_pad_get_current_buffer (GstVideoAggregatorPad *pad);
104
105GST_VIDEO_API
106GstVideoFrame * gst_video_aggregator_pad_get_prepared_frame (GstVideoAggregatorPad *pad);
107
108GST_VIDEO_API
109void gst_video_aggregator_pad_set_needs_alpha (GstVideoAggregatorPad *pad, gboolean needs_alpha);
110
111/********************************
112 * GstVideoAggregatorConvertPad *
113 *******************************/
114
115#define GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD (gst_video_aggregator_convert_pad_get_type())
116#define GST_VIDEO_AGGREGATOR_CONVERT_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD, GstVideoAggregatorConvertPad))
117#define GST_VIDEO_AGGREGATOR_CONVERT_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD, GstVideoAggregatorConvertPadClass))
118#define GST_VIDEO_AGGREGATOR_CONVERT_PAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD, GstVideoAggregatorConvertPadClass))
119#define GST_IS_VIDEO_AGGREGATOR_CONVERT_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD))
120#define GST_IS_VIDEO_AGGREGATOR_CONVERT_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD))
121
122typedef struct _GstVideoAggregatorConvertPad GstVideoAggregatorConvertPad;
123typedef struct _GstVideoAggregatorConvertPadClass GstVideoAggregatorConvertPadClass;
124typedef struct _GstVideoAggregatorConvertPadPrivate GstVideoAggregatorConvertPadPrivate;
125
126/**
127 * GstVideoAggregatorConvertPad:
128 *
129 * An implementation of GstPad that can be used with #GstVideoAggregator.
130 *
131 * See #GstVideoAggregator for more details.
132 */
133struct _GstVideoAggregatorConvertPad
134{
135 /*< private >*/
136 GstVideoAggregatorPad parent;
137
138 GstVideoAggregatorConvertPadPrivate *priv;
139
140 gpointer _gst_reserved[GST_PADDING];
141};
142
143/**
144 * GstVideoAggregatorConvertPadClass:
145 *
146 */
147struct _GstVideoAggregatorConvertPadClass
148{
149 GstVideoAggregatorPadClass parent_class;
150
151 void (*create_conversion_info) (GstVideoAggregatorConvertPad *pad, GstVideoAggregator *agg, GstVideoInfo *conversion_info);
152
153 /*< private >*/
154 gpointer _gst_reserved[GST_PADDING];
155};
156
157GST_VIDEO_API
158GType gst_video_aggregator_convert_pad_get_type (void);
159
160GST_VIDEO_API
161void gst_video_aggregator_convert_pad_update_conversion_info (GstVideoAggregatorConvertPad * pad);
162
163/**********************
164 * GstVideoAggregator *
165 *********************/
166
167#define GST_TYPE_VIDEO_AGGREGATOR (gst_video_aggregator_get_type())
168#define GST_VIDEO_AGGREGATOR(obj) \
169 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_AGGREGATOR, GstVideoAggregator))
170#define GST_VIDEO_AGGREGATOR_CAST(obj) ((GstVideoAggregator *)(obj))
171#define GST_VIDEO_AGGREGATOR_CLASS(klass) \
172 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_AGGREGATOR, GstVideoAggregatorClass))
173#define GST_IS_VIDEO_AGGREGATOR(obj) \
174 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_AGGREGATOR))
175#define GST_IS_VIDEO_AGGREGATOR_CLASS(klass) \
176 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_AGGREGATOR))
177#define GST_VIDEO_AGGREGATOR_GET_CLASS(obj) \
178 (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_VIDEO_AGGREGATOR,GstVideoAggregatorClass))
179
180/**
181 * GstVideoAggregator:
182 * @info: The #GstVideoInfo representing the currently set
183 * srcpad caps.
184 */
185struct _GstVideoAggregator
186{
187 GstAggregator aggregator;
188
189 /*< public >*/
190 /* Output caps */
191 GstVideoInfo info;
192
193 /* < private > */
194 GstVideoAggregatorPrivate *priv;
195 gpointer _gst_reserved[GST_PADDING_LARGE];
196};
197
198/**
199 * GstVideoAggregatorClass:
200 * @update_caps: Optional.
201 * Lets subclasses update the #GstCaps representing
202 * the src pad caps before usage. Return %NULL to indicate failure.
203 * @aggregate_frames: Lets subclasses aggregate frames that are ready. Subclasses
204 * should iterate the GstElement.sinkpads and use the already
205 * mapped #GstVideoFrame from gst_video_aggregator_pad_get_prepared_frame()
206 * or directly use the #GstBuffer from gst_video_aggregator_pad_get_current_buffer()
207 * if it needs to map the buffer in a special way. The result of the
208 * aggregation should land in @outbuffer.
209 * @create_output_buffer: Optional.
210 * Lets subclasses provide a #GstBuffer to be used as @outbuffer of
211 * the #aggregate_frames vmethod.
212 * @find_best_format: Optional.
213 * Lets subclasses decide of the best common format to use.
214 **/
215struct _GstVideoAggregatorClass
216{
217 /*< private >*/
218 GstAggregatorClass parent_class;
219
220 /*< public >*/
221 GstCaps * (*update_caps) (GstVideoAggregator * videoaggregator,
222 GstCaps * caps);
223 GstFlowReturn (*aggregate_frames) (GstVideoAggregator * videoaggregator,
224 GstBuffer * outbuffer);
225 GstFlowReturn (*create_output_buffer) (GstVideoAggregator * videoaggregator,
226 GstBuffer ** outbuffer);
227 void (*find_best_format) (GstVideoAggregator * vagg,
228 GstCaps * downstream_caps,
229 GstVideoInfo * best_info,
230 gboolean * at_least_one_alpha);
231
232 /* < private > */
233 gpointer _gst_reserved[GST_PADDING_LARGE];
234};
235
236GST_VIDEO_API
237GType gst_video_aggregator_get_type (void);
238
239G_END_DECLS
240#endif /* __GST_VIDEO_AGGREGATOR_H__ */
241