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