aggregator: make padding larger
[platform/upstream/gstreamer.git] / libs / gst / base / gstaggregator.h
1 /* GStreamer
2  * Copyright (C) 2014 Mathieu Duponchelle <mathieu.duponchelle@oencreed.com>
3  * Copyright (C) 2014 Thibault Saunier <tsaunier@gnome.org>
4  *
5  * gstaggregator.c:
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef __GST_AGGREGATOR_H__
24 #define __GST_AGGREGATOR_H__
25
26 #ifndef GST_USE_UNSTABLE_API
27 #warning "The Base library from gst-plugins-bad is unstable API and may change in future."
28 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
29 #endif
30
31 #include <gst/gst.h>
32
33 G_BEGIN_DECLS
34
35 /**************************
36  * GstAggregator Structs  *
37  *************************/
38
39 typedef struct _GstAggregator GstAggregator;
40 typedef struct _GstAggregatorPrivate GstAggregatorPrivate;
41 typedef struct _GstAggregatorClass GstAggregatorClass;
42
43 /************************
44  * GstAggregatorPad API *
45  ***********************/
46
47 #define GST_TYPE_AGGREGATOR_PAD            (gst_aggregator_pad_get_type())
48 #define GST_AGGREGATOR_PAD(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR_PAD, GstAggregatorPad))
49 #define GST_AGGREGATOR_PAD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGGREGATOR_PAD, GstAggregatorPadClass))
50 #define GST_AGGREGATOR_PAD_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AGGREGATOR_PAD, GstAggregatorPadClass))
51 #define GST_IS_AGGREGATOR_PAD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGGREGATOR_PAD))
52 #define GST_IS_AGGREGATOR_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGGREGATOR_PAD))
53
54 /****************************
55  * GstAggregatorPad Structs *
56  ***************************/
57
58 typedef struct _GstAggregatorPad GstAggregatorPad;
59 typedef struct _GstAggregatorPadClass GstAggregatorPadClass;
60 typedef struct _GstAggregatorPadPrivate GstAggregatorPadPrivate;
61
62 /**
63  * GstAggregatorPad:
64  * @buffer: currently queued buffer.
65  * @segment: last segment received.
66  *
67  * The implementation the GstPad to use with #GstAggregator
68  */
69 struct _GstAggregatorPad
70 {
71   GstPad                       parent;
72
73   GstBuffer                 *  buffer;
74   GstSegment                   segment;
75   gboolean                     eos;
76
77   /* < Private > */
78   GstAggregatorPadPrivate   *  priv;
79
80   gpointer _gst_reserved[GST_PADDING];
81 };
82
83 /**
84  * GstAggregatorPadClass:
85  * @flush:    Optional
86  *            Called when the pad has received a flush stop, this is the place
87  *            to flush any information specific to the pad, it allows for individual
88  *            pads to be flushed while others might not be.
89  *
90  */
91 struct _GstAggregatorPadClass
92 {
93   GstPadClass   parent_class;
94
95   GstFlowReturn (*flush)     (GstAggregatorPad * aggpad, GstAggregator * aggregator);
96
97   /*< private >*/
98   gpointer      _gst_reserved[GST_PADDING_LARGE];
99 };
100
101 GType gst_aggregator_pad_get_type           (void);
102
103 /****************************
104  * GstAggregatorPad methods *
105  ***************************/
106
107 GstBuffer * gst_aggregator_pad_steal_buffer (GstAggregatorPad *  pad);
108 GstBuffer * gst_aggregator_pad_get_buffer   (GstAggregatorPad *  pad);
109
110 /*********************
111  * GstAggregator API *
112  ********************/
113
114 #define GST_TYPE_AGGREGATOR            (gst_aggregator_get_type())
115 #define GST_AGGREGATOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR,GstAggregator))
116 #define GST_AGGREGATOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGGREGATOR,GstAggregatorClass))
117 #define GST_AGGREGATOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AGGREGATOR,GstAggregatorClass))
118 #define GST_IS_AGGREGATOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGGREGATOR))
119 #define GST_IS_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGGREGATOR))
120
121 #define GST_FLOW_CUSTOM_SUCCESS        GST_FLOW_NOT_HANDLED
122
123 /**
124  * GstAggregator:
125  * @aggregator_pads: #GList of #GstAggregatorPad managed by this #GstAggregator.
126  *
127  * Collectpads object.
128  */
129 struct _GstAggregator
130 {
131   GstElement               parent;
132
133   GstPad                *  srcpad;
134
135   GstSegment               segment;
136
137   /*< private >*/
138   GstAggregatorPrivate  *  priv;
139
140   GstClock              *  clock;
141
142   /* properties */
143   gint64                   latency;
144
145   gpointer                 _gst_reserved[GST_PADDING_LARGE];
146 };
147
148 /**
149  * GstAggregatorClass:
150  * @sinkpads_type:  Optional.
151  *                  The type of the pads that should be created when
152  *                  GstElement.request_new_pad is called.
153  * @flush:          Optional.
154  *                  Called after a succesful flushing seek, once all the flush
155  *                  stops have been received. Flush pad-specific data in
156  *                  #GstAggregatorPad->flush.
157  * @clip:           Optional.
158  *                  Called when a buffer is received on a sink pad, the task
159  *                  of clipping it and translating it to the current segment
160  *                  falls on the subclass.
161  * @sink_event:     Optional.
162  *                  Called when an event is received on a sink pad, the subclass
163  *                  should always chain up.
164  * @sink_query:     Optional.
165  *                  Called when a query is received on a sink pad, the subclass
166  *                  should always chain up.
167  * @src_event:      Optional.
168  *                  Called when an event is received on the src pad, the subclass
169  *                  should always chain up.
170  * @src_query:      Optional.
171  *                  Called when a query is received on the src pad, the subclass
172  *                  should always chain up.
173  * @src_activate:   Optional.
174  *                  Called when the src pad is activated, it will start/stop its
175  *                  pad task right after that call.
176  * @aggregate:      Mandatory.
177  *                  Called when buffers are queued on all sinkpads. Classes
178  *                  should iterate the GstElement->sinkpads and peek or steal
179  *                  buffers from the #GstAggregatorPads. If the subclass returns
180  *                  GST_FLOW_EOS, sending of the eos event will be taken care
181  *                  of. Once / if a buffer has been constructed from the
182  *                  aggregated buffers, the subclass should call _finish_buffer.
183  * @stop:           Optional.
184  *                  Should be linked up first. Called when the
185  *                  element goes from PAUSED to READY. The subclass should free
186  *                  all resources and reset its state.
187  * @start:          Optional.
188  *                  Should be linked up first. Called when the element goes from
189  *                  READY to PAUSED. The subclass should get ready to process
190  *                  aggregated buffers.
191  * @get_next_time:  Optional.
192  *                  Called when the element needs to know the time of the next
193  *                  rendered buffer for live pipelines. This causes deadline
194  *                  based aggregation to occur. Defaults to returning
195  *                  GST_CLOCK_TIME_NONE causing the element to wait for buffers
196  *                  on all sink pads before aggregating.
197  *
198  * The aggregator base class will handle in a thread-safe way all manners of
199  * concurrent flushes, seeks, pad additions and removals, leaving to the
200  * subclass the responsibility of clipping buffers, and aggregating buffers in
201  * the way the implementor sees fit.
202  *
203  * It will also take care of event ordering (stream-start, segment, eos).
204  *
205  * Basically, a basic implementation will override @aggregate, and call
206  * _finish_buffer from inside that function.
207  */
208 struct _GstAggregatorClass {
209   GstElementClass   parent_class;
210
211   GType             sinkpads_type;
212
213   GstFlowReturn     (*flush)          (GstAggregator    *  aggregator);
214
215   GstFlowReturn     (*clip)           (GstAggregator    *  agg,
216                                        GstAggregatorPad *  bpad,
217                                        GstBuffer        *  buf,
218                                        GstBuffer        ** outbuf);
219
220   /* sinkpads virtual methods */
221   gboolean          (*sink_event)     (GstAggregator    *  aggregate,
222                                        GstAggregatorPad *  bpad,
223                                        GstEvent         *  event);
224
225   gboolean          (*sink_query)     (GstAggregator    *  aggregate,
226                                        GstAggregatorPad *  bpad,
227                                        GstQuery         *  query);
228
229   /* srcpad virtual methods */
230   gboolean          (*src_event)      (GstAggregator    *  aggregate,
231                                        GstEvent         *  event);
232
233   gboolean          (*src_query)      (GstAggregator    *  aggregate,
234                                        GstQuery         *  query);
235
236   gboolean          (*src_activate)   (GstAggregator    *  aggregator,
237                                        GstPadMode          mode,
238                                        gboolean            active);
239
240   GstFlowReturn     (*aggregate)      (GstAggregator    *  aggregator,
241                                        gboolean            timeout);
242
243   gboolean          (*stop)           (GstAggregator    *  aggregator);
244
245   gboolean          (*start)          (GstAggregator    *  aggregator);
246
247   GstClockTime      (*get_next_time)  (GstAggregator    *  aggregator);
248
249   /*< private >*/
250   gpointer          _gst_reserved[GST_PADDING_LARGE];
251 };
252
253 /*************************
254  * GstAggregator methods *
255  ************************/
256
257 GstFlowReturn  gst_aggregator_finish_buffer         (GstAggregator                *  agg,
258                                                      GstBuffer                    *  buffer);
259 void           gst_aggregator_set_src_caps          (GstAggregator                *  agg,
260                                                      GstCaps                      *  caps);
261
262 void           gst_aggregator_set_latency           (GstAggregator                *  self,
263                                                      GstClockTime                    min_latency,
264                                                      GstClockTime                    max_latency);
265
266 GType gst_aggregator_get_type(void);
267
268 /* API that should eventually land in GstElement itself*/
269 typedef gboolean (*GstAggregatorPadForeachFunc)    (GstAggregator                 *  self,
270                                                     GstPad                        *  pad,
271                                                     gpointer                         user_data);
272 gboolean gst_aggregator_iterate_sinkpads           (GstAggregator                 *  self,
273                                                     GstAggregatorPadForeachFunc      func,
274                                                     gpointer                         user_data);
275
276 void     gst_aggregator_get_latency                (GstAggregator                 *  self,
277                                                     gboolean                      *  live,
278                                                     GstClockTime                  *  min,
279                                                     GstClockTime                  *  max);
280
281 G_END_DECLS
282
283 #endif /* __GST_AGGREGATOR_H__ */