• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
27 G_BEGIN_DECLS
28 
29 typedef struct _GstVideoAggregator GstVideoAggregator;
30 typedef struct _GstVideoAggregatorClass GstVideoAggregatorClass;
31 typedef 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 
50 typedef struct _GstVideoAggregatorPad GstVideoAggregatorPad;
51 typedef struct _GstVideoAggregatorPadClass GstVideoAggregatorPadClass;
52 typedef struct _GstVideoAggregatorPadPrivate GstVideoAggregatorPadPrivate;
53 
54 /**
55  * GstVideoAggregatorPad:
56  * @info: The #GstVideoInfo currently set on the pad
57  *
58  * Since: 1.16
59  */
60 struct _GstVideoAggregatorPad
61 {
62   GstAggregatorPad              parent;
63 
64   /*< public >*/
65   /* read-only, with OBJECT_LOCK */
66   GstVideoInfo                  info;
67 
68   /* < private > */
69   GstVideoAggregatorPadPrivate *priv;
70 
71   gpointer                     _gst_reserved[GST_PADDING];
72 };
73 
74 /**
75  * GstVideoAggregatorPadClass:
76  * @update_conversion_info: Called when either the input or output formats
77  *                          have changed.
78  * @prepare_frame: Prepare the frame from the pad buffer and sets it to prepared_frame.
79  *      Implementations should always return TRUE.  Returning FALSE will cease
80  *      iteration over subsequent pads.
81  * @clean_frame:   clean the frame previously prepared in prepare_frame
82  *
83  * Since: 1.16
84  */
85 /**
86  * GstVideoAggregatorPadClass::prepare_frame_start:
87  * @pad: the #GstVideoAggregatorPad
88  * @videoaggregator: the parent #GstVideoAggregator
89  * @buffer: the input #GstBuffer to prepare
90  * @prepared_frame: the #GstVideoFrame to prepare into
91  *
92  * Begin preparing the frame from the pad buffer and sets it to prepared_frame.
93  *
94  * If overriden, `prepare_frame_finish` must also be overriden.
95  *
96  * Since: 1.20
97  */
98 /**
99  * GstVideoAggregatorPadClass::prepare_frame_finish:
100  * @pad: the #GstVideoAggregatorPad
101  * @videoaggregator: the parent #GstVideoAggregator
102  * @prepared_frame: the #GstVideoFrame to prepare into
103  *
104  * Finish preparing @prepared_frame.
105  *
106  * If overriden, `prepare_frame_start` must also be overriden.
107  *
108  * Since: 1.20
109  */
110 struct _GstVideoAggregatorPadClass
111 {
112   GstAggregatorPadClass parent_class;
113   void               (*update_conversion_info) (GstVideoAggregatorPad * pad);
114 
115   gboolean           (*prepare_frame)          (GstVideoAggregatorPad * pad,
116                                                 GstVideoAggregator    * videoaggregator,
117                                                 GstBuffer             * buffer,
118                                                 GstVideoFrame         * prepared_frame);
119 
120   void               (*clean_frame)            (GstVideoAggregatorPad * pad,
121                                                 GstVideoAggregator    * videoaggregator,
122                                                 GstVideoFrame         * prepared_frame);
123 
124   void               (*prepare_frame_start)    (GstVideoAggregatorPad * pad,
125                                                 GstVideoAggregator    * videoaggregator,
126                                                 GstBuffer             * buffer,
127                                                 GstVideoFrame         * prepared_frame);
128 
129   void               (*prepare_frame_finish)   (GstVideoAggregatorPad * pad,
130                                                 GstVideoAggregator    * videoaggregator,
131                                                 GstVideoFrame         * prepared_frame);
132 
133   gpointer          _gst_reserved[GST_PADDING_LARGE-2];
134 };
135 
136 GST_VIDEO_API
137 GType gst_video_aggregator_pad_get_type   (void);
138 
139 GST_VIDEO_API
140 gboolean gst_video_aggregator_pad_has_current_buffer (GstVideoAggregatorPad *pad);
141 
142 GST_VIDEO_API
143 GstBuffer * gst_video_aggregator_pad_get_current_buffer (GstVideoAggregatorPad *pad);
144 
145 GST_VIDEO_API
146 GstVideoFrame * gst_video_aggregator_pad_get_prepared_frame (GstVideoAggregatorPad *pad);
147 
148 GST_VIDEO_API
149 void gst_video_aggregator_pad_set_needs_alpha (GstVideoAggregatorPad *pad, gboolean needs_alpha);
150 
151 /********************************
152  * GstVideoAggregatorConvertPad *
153  *******************************/
154 
155 #define GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD            (gst_video_aggregator_convert_pad_get_type())
156 #define GST_VIDEO_AGGREGATOR_CONVERT_PAD(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD, GstVideoAggregatorConvertPad))
157 #define GST_VIDEO_AGGREGATOR_CONVERT_PAD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD, GstVideoAggregatorConvertPadClass))
158 #define GST_VIDEO_AGGREGATOR_CONVERT_PAD_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD, GstVideoAggregatorConvertPadClass))
159 #define GST_IS_VIDEO_AGGREGATOR_CONVERT_PAD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD))
160 #define GST_IS_VIDEO_AGGREGATOR_CONVERT_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD))
161 
162 typedef struct _GstVideoAggregatorConvertPad GstVideoAggregatorConvertPad;
163 typedef struct _GstVideoAggregatorConvertPadClass GstVideoAggregatorConvertPadClass;
164 typedef struct _GstVideoAggregatorConvertPadPrivate GstVideoAggregatorConvertPadPrivate;
165 
166 /**
167  * GstVideoAggregatorConvertPad:
168  *
169  * An implementation of GstPad that can be used with #GstVideoAggregator.
170  *
171  * See #GstVideoAggregator for more details.
172  *
173  * Since: 1.16
174  */
175 struct _GstVideoAggregatorConvertPad
176 {
177   /*< private >*/
178   GstVideoAggregatorPad                  parent;
179 
180   GstVideoAggregatorConvertPadPrivate   *priv;
181 
182   gpointer _gst_reserved[GST_PADDING];
183 };
184 
185 /**
186  * GstVideoAggregatorConvertPadClass:
187  *
188  * Since: 1.16
189  */
190 struct _GstVideoAggregatorConvertPadClass
191 {
192   GstVideoAggregatorPadClass   parent_class;
193 
194   void (*create_conversion_info) (GstVideoAggregatorConvertPad *pad, GstVideoAggregator *agg, GstVideoInfo *conversion_info);
195 
196   /*< private >*/
197   gpointer      _gst_reserved[GST_PADDING];
198 };
199 
200 GST_VIDEO_API
201 GType gst_video_aggregator_convert_pad_get_type           (void);
202 
203 GST_VIDEO_API
204 void gst_video_aggregator_convert_pad_update_conversion_info (GstVideoAggregatorConvertPad * pad);
205 
206 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoAggregatorConvertPad, gst_object_unref)
207 
208 /****************************************
209  * GstVideoAggregatorParallelConvertPad *
210  ****************************************/
211 
212 #define GST_TYPE_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD           (gst_video_aggregator_parallel_convert_pad_get_type())
213 GST_VIDEO_API
214 G_DECLARE_DERIVABLE_TYPE (GstVideoAggregatorParallelConvertPad, gst_video_aggregator_parallel_convert_pad, GST, VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD, GstVideoAggregatorConvertPad)
215 
216 #define GST_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD, GstVideoAggregatorParallelConvertPad))
217 #define GST_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD, GstVideoAggregatorConvertPadClass))
218 #define GST_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD, GstVideoAggregatorConvertPadClass))
219 #define GST_IS_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD))
220 #define GST_IS_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_AGGREGATOR_PARALLEL_CONVERT_PAD))
221 
222 /**
223  * GstVideoAggregatorParallelConvertPad:
224  *
225  * An implementation of GstPad that can be used with #GstVideoAggregator.
226  *
227  * See #GstVideoAggregator for more details.
228  *
229  * Since: 1.20
230  */
231 
232 /**
233  * GstVideoAggregatorParallelConvertPadClass:
234  *
235  * Since: 1.20
236  */
237 struct _GstVideoAggregatorParallelConvertPadClass
238 {
239   GstVideoAggregatorConvertPadClass   parent_class;
240 
241   /*< private >*/
242   gpointer      _gst_reserved[GST_PADDING];
243 };
244 
245 /**********************
246  * GstVideoAggregator *
247  *********************/
248 
249 #define GST_TYPE_VIDEO_AGGREGATOR (gst_video_aggregator_get_type())
250 #define GST_VIDEO_AGGREGATOR(obj) \
251         (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_AGGREGATOR, GstVideoAggregator))
252 #define GST_VIDEO_AGGREGATOR_CAST(obj) ((GstVideoAggregator *)(obj))
253 #define GST_VIDEO_AGGREGATOR_CLASS(klass) \
254         (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_AGGREGATOR, GstVideoAggregatorClass))
255 #define GST_IS_VIDEO_AGGREGATOR(obj) \
256         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_AGGREGATOR))
257 #define GST_IS_VIDEO_AGGREGATOR_CLASS(klass) \
258         (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_AGGREGATOR))
259 #define GST_VIDEO_AGGREGATOR_GET_CLASS(obj) \
260         (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_VIDEO_AGGREGATOR,GstVideoAggregatorClass))
261 
262 /**
263  * GstVideoAggregator:
264  * @info: The #GstVideoInfo representing the currently set
265  * srcpad caps.
266  *
267  * Since: 1.16
268  */
269 struct _GstVideoAggregator
270 {
271   GstAggregator              aggregator;
272 
273   /*< public >*/
274   /* Output caps */
275   GstVideoInfo               info;
276 
277   /* < private > */
278   GstVideoAggregatorPrivate *priv;
279   gpointer                  _gst_reserved[GST_PADDING_LARGE];
280 };
281 
282 /**
283  * GstVideoAggregatorClass:
284  * @update_caps:              Optional.
285  *                            Lets subclasses update the #GstCaps representing
286  *                            the src pad caps before usage.  Return %NULL to indicate failure.
287  * @aggregate_frames:         Lets subclasses aggregate frames that are ready. Subclasses
288  *                            should iterate the GstElement.sinkpads and use the already
289  *                            mapped #GstVideoFrame from gst_video_aggregator_pad_get_prepared_frame()
290  *                            or directly use the #GstBuffer from gst_video_aggregator_pad_get_current_buffer()
291  *                            if it needs to map the buffer in a special way. The result of the
292  *                            aggregation should land in @outbuffer.
293  * @create_output_buffer:     Optional.
294  *                            Lets subclasses provide a #GstBuffer to be used as @outbuffer of
295  *                            the #aggregate_frames vmethod.
296  * @find_best_format:         Optional.
297  *                            Lets subclasses decide of the best common format to use.
298  *
299  * Since: 1.16
300  **/
301 struct _GstVideoAggregatorClass
302 {
303   /*< private >*/
304   GstAggregatorClass parent_class;
305 
306   /*< public >*/
307   GstCaps *          (*update_caps)               (GstVideoAggregator *  videoaggregator,
308                                                    GstCaps            *  caps);
309   GstFlowReturn      (*aggregate_frames)          (GstVideoAggregator *  videoaggregator,
310                                                    GstBuffer          *  outbuffer);
311   GstFlowReturn      (*create_output_buffer)      (GstVideoAggregator *  videoaggregator,
312                                                    GstBuffer          ** outbuffer);
313   void               (*find_best_format)          (GstVideoAggregator *  vagg,
314                                                    GstCaps            *  downstream_caps,
315                                                    GstVideoInfo       *  best_info,
316                                                    gboolean           *  at_least_one_alpha);
317 
318   /* < private > */
319   gpointer            _gst_reserved[GST_PADDING_LARGE];
320 };
321 
322 GST_VIDEO_API
323 GType gst_video_aggregator_get_type       (void);
324 
325 GST_VIDEO_API
326 GstTaskPool * gst_video_aggregator_get_execution_task_pool (GstVideoAggregator * vagg);
327 
328 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoAggregator, gst_object_unref)
329 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoAggregatorPad, gst_object_unref)
330 
331 G_END_DECLS
332 #endif /* __GST_VIDEO_AGGREGATOR_H__ */
333