gstaggregator: pads must inherit from #GstAggregatorPad
[platform/upstream/gstreamer.git] / libs / gst / base / gstaggregator.h
1 /* GStreamer aggregator base class
2  * Copyright (C) 2014 Mathieu Duponchelle <mathieu.duponchelle@oencreed.com>
3  * Copyright (C) 2014 Thibault Saunier <tsaunier@gnome.org>
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_AGGREGATOR_H__
22 #define __GST_AGGREGATOR_H__
23
24 #include <gst/gst.h>
25
26 G_BEGIN_DECLS
27
28 /**************************
29  * GstAggregator Structs  *
30  *************************/
31
32 typedef struct _GstAggregator GstAggregator;
33 typedef struct _GstAggregatorPrivate GstAggregatorPrivate;
34 typedef struct _GstAggregatorClass GstAggregatorClass;
35
36 /************************
37  * GstAggregatorPad API *
38  ***********************/
39
40 #define GST_TYPE_AGGREGATOR_PAD            (gst_aggregator_pad_get_type())
41 #define GST_AGGREGATOR_PAD(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR_PAD, GstAggregatorPad))
42 #define GST_AGGREGATOR_PAD_CAST(obj)       ((GstAggregatorPad *)(obj))
43 #define GST_AGGREGATOR_PAD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGGREGATOR_PAD, GstAggregatorPadClass))
44 #define GST_AGGREGATOR_PAD_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AGGREGATOR_PAD, GstAggregatorPadClass))
45 #define GST_IS_AGGREGATOR_PAD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGGREGATOR_PAD))
46 #define GST_IS_AGGREGATOR_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGGREGATOR_PAD))
47
48 /****************************
49  * GstAggregatorPad Structs *
50  ***************************/
51
52 typedef struct _GstAggregatorPad GstAggregatorPad;
53 typedef struct _GstAggregatorPadClass GstAggregatorPadClass;
54 typedef struct _GstAggregatorPadPrivate GstAggregatorPadPrivate;
55
56 /**
57  * GstAggregatorPad:
58  * @segment: last segment received.
59  *
60  * The implementation the GstPad to use with #GstAggregator
61  */
62 struct _GstAggregatorPad
63 {
64   GstPad                       parent;
65
66   /* Protected by the OBJECT_LOCK */
67   GstSegment segment;
68
69   /* < Private > */
70   GstAggregatorPadPrivate   *  priv;
71
72   gpointer _gst_reserved[GST_PADDING];
73 };
74
75 /**
76  * GstAggregatorPadClass:
77  * @flush:       Optional
78  *               Called when the pad has received a flush stop, this is the place
79  *               to flush any information specific to the pad, it allows for individual
80  *               pads to be flushed while others might not be.
81  * @skip_buffer: Optional
82  *               Called before input buffers are queued in the pad, return %TRUE
83  *               if the buffer should be skipped.
84  *
85  */
86 struct _GstAggregatorPadClass
87 {
88   GstPadClass   parent_class;
89
90   GstFlowReturn (*flush)       (GstAggregatorPad * aggpad, GstAggregator * aggregator);
91   gboolean      (*skip_buffer) (GstAggregatorPad * aggpad, GstAggregator * aggregator, GstBuffer * buffer);
92
93   /*< private >*/
94   gpointer      _gst_reserved[GST_PADDING_LARGE];
95 };
96
97 GST_EXPORT
98 GType gst_aggregator_pad_get_type           (void);
99
100 /****************************
101  * GstAggregatorPad methods *
102  ***************************/
103
104 GST_EXPORT
105 GstBuffer * gst_aggregator_pad_pop_buffer   (GstAggregatorPad *  pad);
106
107 GST_EXPORT
108 GstBuffer * gst_aggregator_pad_peek_buffer  (GstAggregatorPad *  pad);
109
110 GST_EXPORT
111 gboolean    gst_aggregator_pad_drop_buffer  (GstAggregatorPad *  pad);
112
113 GST_EXPORT
114 gboolean    gst_aggregator_pad_is_eos       (GstAggregatorPad *  pad);
115
116 /*********************
117  * GstAggregator API *
118  ********************/
119
120 #define GST_TYPE_AGGREGATOR            (gst_aggregator_get_type())
121 #define GST_AGGREGATOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR,GstAggregator))
122 #define GST_AGGREGATOR_CAST(obj)       ((GstAggregator *)(obj))
123 #define GST_AGGREGATOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGGREGATOR,GstAggregatorClass))
124 #define GST_AGGREGATOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AGGREGATOR,GstAggregatorClass))
125 #define GST_IS_AGGREGATOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGGREGATOR))
126 #define GST_IS_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGGREGATOR))
127
128 #define GST_AGGREGATOR_FLOW_NEED_DATA             GST_FLOW_CUSTOM_ERROR
129
130 /**
131  * GstAggregator:
132  * @srcpad: the aggregator's source pad
133  * @segment: the output segment
134  *
135  * Aggregator base class object structure.
136  */
137 struct _GstAggregator
138 {
139   GstElement               parent;
140
141   GstPad                *  srcpad;
142
143   /*< private >*/
144   GstAggregatorPrivate  *  priv;
145
146   gpointer                 _gst_reserved[GST_PADDING_LARGE];
147 };
148
149 /**
150  * GstAggregatorClass:
151  * @flush:          Optional.
152  *                  Called after a successful flushing seek, once all the flush
153  *                  stops have been received. Flush pad-specific data in
154  *                  #GstAggregatorPad->flush.
155  * @clip:           Optional.
156  *                  Called when a buffer is received on a sink pad, the task of
157  *                  clipping it and translating it to the current segment falls
158  *                  on the subclass. The function should use the segment of data
159  *                  and the negotiated media type on the pad to perform
160  *                  clipping of input buffer. This function takes ownership of
161  *                  buf and should output a buffer or return NULL in
162  *                  if the buffer should be dropped.
163  * @finish_buffer:  Optional.
164  *                  Called when a subclass calls gst_aggregator_finish_buffer()
165  *                  from their aggregate function to push out a buffer.
166  *                  Subclasses can override this to modify or decorate buffers
167  *                  before they get pushed out. This function takes ownership
168  *                  of the buffer passed. Subclasses that override this method
169  *                  should always chain up to the parent class virtual method.
170  * @sink_event:     Optional.
171  *                  Called when an event is received on a sink pad, the subclass
172  *                  should always chain up.
173  * @sink_query:     Optional.
174  *                  Called when a query is received on a sink pad, the subclass
175  *                  should always chain up.
176  * @src_event:      Optional.
177  *                  Called when an event is received on the src pad, the subclass
178  *                  should always chain up.
179  * @src_query:      Optional.
180  *                  Called when a query is received on the src pad, the subclass
181  *                  should always chain up.
182  * @src_activate:   Optional.
183  *                  Called when the src pad is activated, it will start/stop its
184  *                  pad task right after that call.
185  * @aggregate:      Mandatory.
186  *                  Called when buffers are queued on all sinkpads. Classes
187  *                  should iterate the GstElement->sinkpads and peek or steal
188  *                  buffers from the #GstAggregatorPads. If the subclass returns
189  *                  GST_FLOW_EOS, sending of the eos event will be taken care
190  *                  of. Once / if a buffer has been constructed from the
191  *                  aggregated buffers, the subclass should call _finish_buffer.
192  * @stop:           Optional.
193  *                  Called when the element goes from PAUSED to READY.
194  *                  The subclass should free all resources and reset its state.
195  * @start:          Optional.
196  *                  Called when the element goes from READY to PAUSED.
197  *                  The subclass should get ready to process
198  *                  aggregated buffers.
199  * @get_next_time:  Optional.
200  *                  Called when the element needs to know the running time of the next
201  *                  rendered buffer for live pipelines. This causes deadline
202  *                  based aggregation to occur. Defaults to returning
203  *                  GST_CLOCK_TIME_NONE causing the element to wait for buffers
204  *                  on all sink pads before aggregating.
205  * @update_src_caps: Lets subclasses update the #GstCaps representing
206  *                   the src pad caps before usage.  The result should end up
207  *                   in @ret. Return %GST_AGGREGATOR_FLOW_NEED_DATA to indicate that the
208  *                   element needs more information (caps, a buffer, etc) to
209  *                   choose the correct caps. Should return ANY caps if the
210  *                   stream has not caps at all.
211  * @fixate_src_caps: Optional.
212  *                   Fixate and return the src pad caps provided.  The function takes
213  *                   ownership of @caps and returns a fixated version of
214  *                   @caps. @caps is not guaranteed to be writable.
215  * @negotiated_src_caps: Optional.
216  *                       Notifies subclasses what caps format has been negotiated
217  * @decide_allocation: Optional.
218  *                     Allows the subclass to influence the allocation choices.
219  *                     Setup the allocation parameters for allocating output
220  *                     buffers. The passed in query contains the result of the
221  *                     downstream allocation query.
222  *
223  * The aggregator base class will handle in a thread-safe way all manners of
224  * concurrent flushes, seeks, pad additions and removals, leaving to the
225  * subclass the responsibility of clipping buffers, and aggregating buffers in
226  * the way the implementor sees fit.
227  *
228  * It will also take care of event ordering (stream-start, segment, eos).
229  *
230  * Basically, a simple implementation will override @aggregate, and call
231  * _finish_buffer from inside that function.
232  */
233 struct _GstAggregatorClass {
234   GstElementClass   parent_class;
235
236   GstFlowReturn     (*flush)          (GstAggregator    *  aggregator);
237
238   GstBuffer *       (*clip)           (GstAggregator    *  aggregator,
239                                        GstAggregatorPad *  aggregator_pad,
240                                        GstBuffer        *  buf);
241
242   GstFlowReturn     (*finish_buffer)  (GstAggregator    * aggregator,
243                                        GstBuffer        * buffer);
244
245   /* sinkpads virtual methods */
246   gboolean          (*sink_event)     (GstAggregator    *  aggregator,
247                                        GstAggregatorPad *  aggregator_pad,
248                                        GstEvent         *  event);
249
250   gboolean          (*sink_query)     (GstAggregator    *  aggregator,
251                                        GstAggregatorPad *  aggregator_pad,
252                                        GstQuery         *  query);
253
254   /* srcpad virtual methods */
255   gboolean          (*src_event)      (GstAggregator    *  aggregator,
256                                        GstEvent         *  event);
257
258   gboolean          (*src_query)      (GstAggregator    *  aggregator,
259                                        GstQuery         *  query);
260
261   gboolean          (*src_activate)   (GstAggregator    *  aggregator,
262                                        GstPadMode          mode,
263                                        gboolean            active);
264
265   GstFlowReturn     (*aggregate)      (GstAggregator    *  aggregator,
266                                        gboolean            timeout);
267
268   gboolean          (*stop)           (GstAggregator    *  aggregator);
269
270   gboolean          (*start)          (GstAggregator    *  aggregator);
271
272   GstClockTime      (*get_next_time)  (GstAggregator    *  aggregator);
273
274   GstAggregatorPad * (*create_new_pad) (GstAggregator  * self,
275                                         GstPadTemplate * templ,
276                                         const gchar    * req_name,
277                                         const GstCaps  * caps);
278   GstFlowReturn     (*update_src_caps) (GstAggregator *  self,
279                                         GstCaps       *  caps,
280                                         GstCaps       ** ret);
281   GstCaps *         (*fixate_src_caps) (GstAggregator *  self,
282                                         GstCaps       *  caps);
283   gboolean          (*negotiated_src_caps) (GstAggregator *  self,
284                                             GstCaps      *  caps);
285   gboolean          (*decide_allocation) (GstAggregator * self,
286                                           GstQuery * query);
287   gboolean          (*propose_allocation) (GstAggregator * self,
288                                            GstAggregatorPad * pad,
289                                            GstQuery * decide_query,
290                                            GstQuery * query);
291   /*< private >*/
292   gpointer          _gst_reserved[GST_PADDING_LARGE];
293 };
294
295 /************************************
296  * GstAggregator convenience macros *
297  ***********************************/
298
299 /**
300  * GST_AGGREGATOR_SRC_PAD:
301  * @agg: a #GstAggregator
302  *
303  * Convenience macro to access the source pad of #GstAggregator
304  *
305  * Since: 1.6
306  */
307 #define GST_AGGREGATOR_SRC_PAD(agg) (((GstAggregator *)(agg))->srcpad)
308
309 /*************************
310  * GstAggregator methods *
311  ************************/
312
313 GST_EXPORT
314 GstFlowReturn  gst_aggregator_finish_buffer         (GstAggregator                *  aggregator,
315                                                      GstBuffer                    *  buffer);
316
317 GST_EXPORT
318 void           gst_aggregator_set_src_caps          (GstAggregator                *  self,
319                                                      GstCaps                      *  caps);
320
321 GST_EXPORT
322 void           gst_aggregator_set_latency           (GstAggregator                *  self,
323                                                      GstClockTime                    min_latency,
324                                                      GstClockTime                    max_latency);
325
326 GST_EXPORT
327 GType gst_aggregator_get_type(void);
328
329 GST_EXPORT
330 GstClockTime  gst_aggregator_get_latency           (GstAggregator                 *  self);
331
332 GST_EXPORT
333 GstBufferPool * gst_aggregator_get_buffer_pool     (GstAggregator                 * self);
334
335 GST_EXPORT
336 void            gst_aggregator_get_allocator       (GstAggregator                 * self,
337                                                     GstAllocator                 ** allocator,
338                                                     GstAllocationParams           * params);
339
340 G_END_DECLS
341
342 #endif /* __GST_AGGREGATOR_H__ */