aggregator: Document that get_next_time() should return running time
[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 #ifndef GST_USE_UNSTABLE_API
25 #warning "The Base library from gst-plugins-bad is unstable API and may change in future."
26 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
27 #endif
28
29 #include <gst/gst.h>
30
31 G_BEGIN_DECLS
32
33 /**************************
34  * GstAggregator Structs  *
35  *************************/
36
37 typedef struct _GstAggregator GstAggregator;
38 typedef struct _GstAggregatorPrivate GstAggregatorPrivate;
39 typedef struct _GstAggregatorClass GstAggregatorClass;
40
41 /************************
42  * GstAggregatorPad API *
43  ***********************/
44
45 #define GST_TYPE_AGGREGATOR_PAD            (gst_aggregator_pad_get_type())
46 #define GST_AGGREGATOR_PAD(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR_PAD, GstAggregatorPad))
47 #define GST_AGGREGATOR_PAD_CAST(obj)       ((GstAggregatorPad *)(obj))
48 #define GST_AGGREGATOR_PAD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGGREGATOR_PAD, GstAggregatorPadClass))
49 #define GST_AGGREGATOR_PAD_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AGGREGATOR_PAD, GstAggregatorPadClass))
50 #define GST_IS_AGGREGATOR_PAD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGGREGATOR_PAD))
51 #define GST_IS_AGGREGATOR_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGGREGATOR_PAD))
52
53 /****************************
54  * GstAggregatorPad Structs *
55  ***************************/
56
57 typedef struct _GstAggregatorPad GstAggregatorPad;
58 typedef struct _GstAggregatorPadClass GstAggregatorPadClass;
59 typedef struct _GstAggregatorPadPrivate GstAggregatorPadPrivate;
60
61 /**
62  * GstAggregatorPad:
63  * @buffer: currently queued buffer.
64  * @segment: last segment received.
65  *
66  * The implementation the GstPad to use with #GstAggregator
67  */
68 struct _GstAggregatorPad
69 {
70   GstPad                       parent;
71
72   /* Protected by the OBJECT_LOCK */
73   GstSegment segment;
74   /* Segment to use in the clip function, before the queue */
75   GstSegment clip_segment;
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 gboolean    gst_aggregator_pad_drop_buffer  (GstAggregatorPad *  pad);
110 gboolean    gst_aggregator_pad_is_eos       (GstAggregatorPad *  pad);
111
112 /*********************
113  * GstAggregator API *
114  ********************/
115
116 #define GST_TYPE_AGGREGATOR            (gst_aggregator_get_type())
117 #define GST_AGGREGATOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR,GstAggregator))
118 #define GST_AGGREGATOR_CAST(obj)       ((GstAggregator *)(obj))
119 #define GST_AGGREGATOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGGREGATOR,GstAggregatorClass))
120 #define GST_AGGREGATOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AGGREGATOR,GstAggregatorClass))
121 #define GST_IS_AGGREGATOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGGREGATOR))
122 #define GST_IS_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGGREGATOR))
123
124 #define GST_FLOW_NOT_HANDLED           GST_FLOW_CUSTOM_SUCCESS
125
126 /**
127  * GstAggregator:
128  * @srcpad: the aggregator's source pad
129  * @segment: the output segment
130  *
131  * Aggregator base class object structure.
132  */
133 struct _GstAggregator
134 {
135   GstElement               parent;
136
137   GstPad                *  srcpad;
138
139   /* Only access with the object lock held */
140   GstSegment               segment;
141
142   /*< private >*/
143   GstAggregatorPrivate  *  priv;
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  *                  Called when the element goes from PAUSED to READY.
185  *                  The subclass should free all resources and reset its state.
186  * @start:          Optional.
187  *                  Called when the element goes from READY to PAUSED.
188  *                  The subclass should get ready to process
189  *                  aggregated buffers.
190  * @get_next_time:  Optional.
191  *                  Called when the element needs to know the running time of the next
192  *                  rendered buffer for live pipelines. This causes deadline
193  *                  based aggregation to occur. Defaults to returning
194  *                  GST_CLOCK_TIME_NONE causing the element to wait for buffers
195  *                  on all sink pads before aggregating.
196  *
197  * The aggregator base class will handle in a thread-safe way all manners of
198  * concurrent flushes, seeks, pad additions and removals, leaving to the
199  * subclass the responsibility of clipping buffers, and aggregating buffers in
200  * the way the implementor sees fit.
201  *
202  * It will also take care of event ordering (stream-start, segment, eos).
203  *
204  * Basically, a basic implementation will override @aggregate, and call
205  * _finish_buffer from inside that function.
206  */
207 struct _GstAggregatorClass {
208   GstElementClass   parent_class;
209
210   GType             sinkpads_type;
211
212   GstFlowReturn     (*flush)          (GstAggregator    *  aggregator);
213
214   GstFlowReturn     (*clip)           (GstAggregator    *  aggregator,
215                                        GstAggregatorPad *  aggregator_pad,
216                                        GstBuffer        *  buf,
217                                        GstBuffer        ** outbuf);
218
219   /* sinkpads virtual methods */
220   gboolean          (*sink_event)     (GstAggregator    *  aggregator,
221                                        GstAggregatorPad *  aggregator_pad,
222                                        GstEvent         *  event);
223
224   gboolean          (*sink_query)     (GstAggregator    *  aggregator,
225                                        GstAggregatorPad *  aggregator_pad,
226                                        GstQuery         *  query);
227
228   /* srcpad virtual methods */
229   gboolean          (*src_event)      (GstAggregator    *  aggregator,
230                                        GstEvent         *  event);
231
232   gboolean          (*src_query)      (GstAggregator    *  aggregator,
233                                        GstQuery         *  query);
234
235   gboolean          (*src_activate)   (GstAggregator    *  aggregator,
236                                        GstPadMode          mode,
237                                        gboolean            active);
238
239   GstFlowReturn     (*aggregate)      (GstAggregator    *  aggregator,
240                                        gboolean            timeout);
241
242   gboolean          (*stop)           (GstAggregator    *  aggregator);
243
244   gboolean          (*start)          (GstAggregator    *  aggregator);
245
246   GstClockTime      (*get_next_time)  (GstAggregator    *  aggregator);
247
248   /*< private >*/
249   gpointer          _gst_reserved[GST_PADDING_LARGE];
250 };
251
252 /************************************
253  * GstAggregator convenience macros *
254  ***********************************/
255
256 /**
257  * GST_AGGREGATOR_SRC_PAD:
258  * @agg: a #GstAggregator
259  *
260  * Convenience macro to access the source pad of #GstAggregator
261  *
262  * Since: 1.6
263  */
264 #define GST_AGGREGATOR_SRC_PAD(agg) (((GstAggregator *)(agg))->srcpad)
265
266 /*************************
267  * GstAggregator methods *
268  ************************/
269
270 GstFlowReturn  gst_aggregator_finish_buffer         (GstAggregator                *  agg,
271                                                      GstBuffer                    *  buffer);
272 void           gst_aggregator_set_src_caps          (GstAggregator                *  agg,
273                                                      GstCaps                      *  caps);
274
275 void           gst_aggregator_set_latency           (GstAggregator                *  self,
276                                                      GstClockTime                    min_latency,
277                                                      GstClockTime                    max_latency);
278
279 GType gst_aggregator_get_type(void);
280
281 /* API that should eventually land in GstElement itself (FIXME) */
282 typedef gboolean (*GstAggregatorPadForeachFunc)    (GstAggregator                 *  aggregator,
283                                                     GstAggregatorPad              *  aggregator_pad,
284                                                     gpointer                         user_data);
285
286 gboolean gst_aggregator_iterate_sinkpads           (GstAggregator                 *  self,
287                                                     GstAggregatorPadForeachFunc      func,
288                                                     gpointer                         user_data);
289
290 GstClockTime  gst_aggregator_get_latency           (GstAggregator                 *  self);
291
292 G_END_DECLS
293
294 #endif /* __GST_AGGREGATOR_H__ */