aggregator: hook up to build system
[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  *
82  */
83 struct _GstAggregatorPadClass
84 {
85   GstPadClass   parent_class;
86
87   GstFlowReturn (*flush)     (GstAggregatorPad * aggpad, GstAggregator * aggregator);
88
89   /*< private >*/
90   gpointer      _gst_reserved[GST_PADDING_LARGE];
91 };
92
93 GST_EXPORT
94 GType gst_aggregator_pad_get_type           (void);
95
96 /****************************
97  * GstAggregatorPad methods *
98  ***************************/
99
100 GST_EXPORT
101 GstBuffer * gst_aggregator_pad_steal_buffer (GstAggregatorPad *  pad);
102
103 GST_EXPORT
104 GstBuffer * gst_aggregator_pad_get_buffer   (GstAggregatorPad *  pad);
105
106 GST_EXPORT
107 gboolean    gst_aggregator_pad_drop_buffer  (GstAggregatorPad *  pad);
108
109 GST_EXPORT
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_AGGREGATOR_FLOW_NEED_DATA             GST_FLOW_CUSTOM_ERROR
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  * @flush:          Optional.
151  *                  Called after a successful flushing seek, once all the flush
152  *                  stops have been received. Flush pad-specific data in
153  *                  #GstAggregatorPad->flush.
154  * @clip:           Optional.
155  *                  Called when a buffer is received on a sink pad, the task of
156  *                  clipping it and translating it to the current segment falls
157  *                  on the subclass. The function should use the segment of data
158  *                  and the negotiated media type on the pad to perform
159  *                  clipping of input buffer. This function takes ownership of
160  *                  buf and should output a buffer or return NULL in
161  *                  if the buffer should be dropped.
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  *                  Called when the element goes from PAUSED to READY.
186  *                  The subclass should free all resources and reset its state.
187  * @start:          Optional.
188  *                  Called when the element goes from READY to PAUSED.
189  *                  The subclass should get ready to process
190  *                  aggregated buffers.
191  * @get_next_time:  Optional.
192  *                  Called when the element needs to know the running 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  * @update_src_caps: Lets subclasses update the #GstCaps representing
198  *                   the src pad caps before usage.  The result should end up
199  *                   in @ret. Return %GST_AGGREGATOR_FLOW_NEED_DATA to indicate that the
200  *                   element needs more information (caps, a buffer, etc) to
201  *                   choose the correct caps. Should return ANY caps if the
202  *                   stream has not caps at all.
203  * @fixate_src_caps: Optional.
204  *                   Fixate and return the src pad caps provided.  The function takes
205  *                   ownership of @caps and returns a fixated version of
206  *                   @caps. @caps is not guaranteed to be writable.
207  * @negotiated_src_caps: Optional.
208  *                       Notifies subclasses what caps format has been negotiated
209  * @decide_allocation: Optional.
210  *                     Allows the subclass to influence the allocation choices.
211  *                     Setup the allocation parameters for allocating output
212  *                     buffers. The passed in query contains the result of the
213  *                     downstream allocation query.
214  *
215  * The aggregator base class will handle in a thread-safe way all manners of
216  * concurrent flushes, seeks, pad additions and removals, leaving to the
217  * subclass the responsibility of clipping buffers, and aggregating buffers in
218  * the way the implementor sees fit.
219  *
220  * It will also take care of event ordering (stream-start, segment, eos).
221  *
222  * Basically, a simple implementation will override @aggregate, and call
223  * _finish_buffer from inside that function.
224  */
225 struct _GstAggregatorClass {
226   GstElementClass   parent_class;
227
228   GstFlowReturn     (*flush)          (GstAggregator    *  aggregator);
229
230   GstBuffer *       (*clip)           (GstAggregator    *  aggregator,
231                                        GstAggregatorPad *  aggregator_pad,
232                                        GstBuffer        *  buf);
233
234   /* sinkpads virtual methods */
235   gboolean          (*sink_event)     (GstAggregator    *  aggregator,
236                                        GstAggregatorPad *  aggregator_pad,
237                                        GstEvent         *  event);
238
239   gboolean          (*sink_query)     (GstAggregator    *  aggregator,
240                                        GstAggregatorPad *  aggregator_pad,
241                                        GstQuery         *  query);
242
243   /* srcpad virtual methods */
244   gboolean          (*src_event)      (GstAggregator    *  aggregator,
245                                        GstEvent         *  event);
246
247   gboolean          (*src_query)      (GstAggregator    *  aggregator,
248                                        GstQuery         *  query);
249
250   gboolean          (*src_activate)   (GstAggregator    *  aggregator,
251                                        GstPadMode          mode,
252                                        gboolean            active);
253
254   GstFlowReturn     (*aggregate)      (GstAggregator    *  aggregator,
255                                        gboolean            timeout);
256
257   gboolean          (*stop)           (GstAggregator    *  aggregator);
258
259   gboolean          (*start)          (GstAggregator    *  aggregator);
260
261   GstClockTime      (*get_next_time)  (GstAggregator    *  aggregator);
262
263   GstAggregatorPad * (*create_new_pad) (GstAggregator  * self,
264                                         GstPadTemplate * templ,
265                                         const gchar    * req_name,
266                                         const GstCaps  * caps);
267   GstFlowReturn     (*update_src_caps) (GstAggregator *  self,
268                                         GstCaps       *  caps,
269                                         GstCaps       ** ret);
270   GstCaps *         (*fixate_src_caps) (GstAggregator *  self,
271                                         GstCaps       *  caps);
272   gboolean          (*negotiated_src_caps) (GstAggregator *  self,
273                                             GstCaps      *  caps);
274   gboolean          (*decide_allocation) (GstAggregator * self,
275                                           GstQuery * query);
276   gboolean          (*propose_allocation) (GstAggregator * self,
277                                            GstAggregatorPad * pad,
278                                            GstQuery * decide_query,
279                                            GstQuery * query);
280   /*< private >*/
281   gpointer          _gst_reserved[GST_PADDING_LARGE];
282 };
283
284 /************************************
285  * GstAggregator convenience macros *
286  ***********************************/
287
288 /**
289  * GST_AGGREGATOR_SRC_PAD:
290  * @agg: a #GstAggregator
291  *
292  * Convenience macro to access the source pad of #GstAggregator
293  *
294  * Since: 1.6
295  */
296 #define GST_AGGREGATOR_SRC_PAD(agg) (((GstAggregator *)(agg))->srcpad)
297
298 /*************************
299  * GstAggregator methods *
300  ************************/
301
302 GST_EXPORT
303 GstFlowReturn  gst_aggregator_finish_buffer         (GstAggregator                *  self,
304                                                      GstBuffer                    *  buffer);
305
306 GST_EXPORT
307 void           gst_aggregator_set_src_caps          (GstAggregator                *  self,
308                                                      GstCaps                      *  caps);
309
310 GST_EXPORT
311 void           gst_aggregator_set_latency           (GstAggregator                *  self,
312                                                      GstClockTime                    min_latency,
313                                                      GstClockTime                    max_latency);
314
315 GST_EXPORT
316 GType gst_aggregator_get_type(void);
317
318 GST_EXPORT
319 GstClockTime  gst_aggregator_get_latency           (GstAggregator                 *  self);
320
321 GST_EXPORT
322 GstBufferPool * gst_aggregator_get_buffer_pool     (GstAggregator                 * self);
323
324 GST_EXPORT
325 void            gst_aggregator_get_allocator       (GstAggregator                 * self,
326                                                     GstAllocator                 ** allocator,
327                                                     GstAllocationParams           * params);
328
329 G_END_DECLS
330
331 #endif /* __GST_AGGREGATOR_H__ */