aggregator: add a timeout property determining buffer wait time
[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   gboolean                     unresponsive;
77
78   /* < Private > */
79   GstAggregatorPadPrivate   *  priv;
80
81   gpointer _gst_reserved[GST_PADDING];
82 };
83
84 /**
85  * GstAggregatorPadClass:
86  * @flush:    Optional
87  *            Called when the pad has received a flush stop, this is the place
88  *            to flush any information specific to the pad, it allows for individual
89  *            pads to be flushed while others might not be.
90  *
91  */
92 struct _GstAggregatorPadClass
93 {
94   GstPadClass   parent_class;
95
96   GstFlowReturn (*flush)     (GstAggregatorPad * aggpad, GstAggregator * aggregator);
97
98   /*< private >*/
99   gpointer      _gst_reserved[GST_PADDING];
100 };
101
102 GType gst_aggregator_pad_get_type           (void);
103
104 /****************************
105  * GstAggregatorPad methods *
106  ***************************/
107
108 GstBuffer * gst_aggregator_pad_steal_buffer (GstAggregatorPad *  pad);
109 GstBuffer * gst_aggregator_pad_get_buffer   (GstAggregatorPad *  pad);
110
111 /*********************
112  * GstAggregator API *
113  ********************/
114
115 #define GST_TYPE_AGGREGATOR            (gst_aggregator_get_type())
116 #define GST_AGGREGATOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR,GstAggregator))
117 #define GST_AGGREGATOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGGREGATOR,GstAggregatorClass))
118 #define GST_AGGREGATOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AGGREGATOR,GstAggregatorClass))
119 #define GST_IS_AGGREGATOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGGREGATOR))
120 #define GST_IS_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGGREGATOR))
121
122 #define GST_FLOW_CUSTOM_SUCCESS        GST_FLOW_NOT_HANDLED
123
124 /**
125  * GstAggregator:
126  * @aggregator_pads: #GList of #GstAggregatorPad managed by this #GstAggregator.
127  *
128  * Collectpads object.
129  */
130 struct _GstAggregator
131 {
132   GstElement               parent;
133
134   GstPad                *  srcpad;
135
136   GstSegment               segment;
137
138   /*< private >*/
139   GstAggregatorPrivate  *  priv;
140
141   GstClock              *  clock;
142
143   /* properties */
144   gint64                   timeout;
145
146   gpointer                 _gst_reserved[GST_PADDING];
147 };
148
149 /**
150  * GstAggregatorClass:
151  * @sinkpads_type:  Optional.
152  *                  The type of the pads that should be created when
153  *                  GstElement.request_new_pad is called.
154  * @flush:          Optional.
155  *                  Called after a succesful flushing seek, once all the flush
156  *                  stops have been received. Flush pad-specific data in
157  *                  #GstAggregatorPad->flush.
158  * @clip:           Optional.
159  *                  Called when a buffer is received on a sink pad, the task
160  *                  of clipping it and translating it to the current segment
161  *                  falls on the subclass.
162  * @sink_event:     Optional.
163  *                  Called when an event is received on a sink pad, the subclass
164  *                  should always chain up.
165  * @sink_query:     Optional.
166  *                  Called when a query is received on a sink pad, the subclass
167  *                  should always chain up.
168  * @src_event:      Optional.
169  *                  Called when an event is received on the src pad, the subclass
170  *                  should always chain up.
171  * @src_query:      Optional.
172  *                  Called when a query is received on the src pad, the subclass
173  *                  should always chain up.
174  * @src_activate:   Optional.
175  *                  Called when the src pad is activated, it will start/stop its
176  *                  pad task right after that call.
177  * @aggregate:      Mandatory.
178  *                  Called when buffers are queued on all sinkpads. Classes
179  *                  should iterate the GstElement->sinkpads and peek or steal
180  *                  buffers from the #GstAggregatorPads. If the subclass returns
181  *                  GST_FLOW_EOS, sending of the eos event will be taken care
182  *                  of. Once / if a buffer has been constructed from the
183  *                  aggregated buffers, the subclass should call _finish_buffer.
184  * @stop:           Optional.
185  *                  Should be linked up first. Called when the
186  *                  element goes from PAUSED to READY. The subclass should free
187  *                  all resources and reset its state.
188  * @start:          Optional.
189  *                  Should be linked up first. Called when the element goes from
190  *                  READY to PAUSED. The subclass should get ready to process
191  *                  aggregated buffers.
192  *
193  * The aggregator base class will handle in a thread-safe way all manners of
194  * concurrent flushes, seeks, pad additions and removals, leaving to the
195  * subclass the responsibility of clipping buffers, and aggregating buffers in
196  * the way the implementor sees fit.
197  *
198  * It will also take care of event ordering (stream-start, segment, eos).
199  *
200  * Basically, a basic implementation will override @aggregate, and call
201  * _finish_buffer from inside that function.
202  */
203 struct _GstAggregatorClass {
204   GstElementClass   parent_class;
205
206   GType             sinkpads_type;
207
208   GstFlowReturn     (*flush)          (GstAggregator    *  aggregator);
209
210   GstFlowReturn     (*clip)           (GstAggregator    *  agg,
211                                        GstAggregatorPad *  bpad,
212                                        GstBuffer        *  buf,
213                                        GstBuffer        ** outbuf);
214
215   /* sinkpads virtual methods */
216   gboolean          (*sink_event)     (GstAggregator    *  aggregate,
217                                        GstAggregatorPad *  bpad,
218                                        GstEvent         *  event);
219
220   gboolean          (*sink_query)     (GstAggregator    *  aggregate,
221                                        GstAggregatorPad *  bpad,
222                                        GstQuery         *  query);
223
224   /* srcpad virtual methods */
225   gboolean          (*src_event)      (GstAggregator    *  aggregate,
226                                        GstEvent         *  event);
227
228   gboolean          (*src_query)      (GstAggregator    *  aggregate,
229                                        GstQuery         *  query);
230
231   gboolean          (*src_activate)   (GstAggregator    *  aggregator,
232                                        GstPadMode          mode,
233                                        gboolean            active);
234
235   GstFlowReturn     (*aggregate)      (GstAggregator    *  aggregator);
236
237   gboolean          (*stop)           (GstAggregator    *  aggregator);
238
239   gboolean          (*start)          (GstAggregator    *  aggregator);
240
241   /*< private >*/
242   gpointer          _gst_reserved[GST_PADDING];
243 };
244
245 /*************************
246  * GstAggregator methods *
247  ************************/
248
249 GstFlowReturn  gst_aggregator_finish_buffer         (GstAggregator                *  agg,
250                                                      GstBuffer                    *  buffer);
251 void           gst_aggregator_set_src_caps          (GstAggregator                *  agg,
252                                                      GstCaps                      *  caps);
253
254 GType gst_aggregator_get_type(void);
255
256 /* API that should eventually land in GstElement itself*/
257 typedef gboolean (*GstAggregatorPadForeachFunc)    (GstAggregator                 *  self,
258                                                     GstPad                        *  pad,
259                                                     gpointer                         user_data);
260 gboolean gst_aggregator_iterate_sinkpads           (GstAggregator                 *  self,
261                                                     GstAggregatorPadForeachFunc      func,
262                                                     gpointer                         user_data);
263
264
265 G_END_DECLS
266
267 #endif /* __GST_AGGREGATOR_H__ */