2 * Copyright (C) 2014 Mathieu Duponchelle <mathieu.duponchelle@oencreed.com>
3 * Copyright (C) 2014 Thibault Saunier <tsaunier@gnome.org>
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.
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.
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.
23 #ifndef __GST_AGGREGATOR_H__
24 #define __GST_AGGREGATOR_H__
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."
35 /**************************
36 * GstAggregator Structs *
37 *************************/
39 typedef struct _GstAggregator GstAggregator;
40 typedef struct _GstAggregatorPrivate GstAggregatorPrivate;
41 typedef struct _GstAggregatorClass GstAggregatorClass;
43 /************************
44 * GstAggregatorPad API *
45 ***********************/
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))
54 /****************************
55 * GstAggregatorPad Structs *
56 ***************************/
58 typedef struct _GstAggregatorPad GstAggregatorPad;
59 typedef struct _GstAggregatorPadClass GstAggregatorPadClass;
60 typedef struct _GstAggregatorPadPrivate GstAggregatorPadPrivate;
64 * @buffer: currently queued buffer.
65 * @segment: last segment received.
67 * The implementation the GstPad to use with #GstAggregator
69 struct _GstAggregatorPad
78 GstAggregatorPadPrivate * priv;
80 gpointer _gst_reserved[GST_PADDING];
84 * GstAggregatorPadClass:
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.
91 struct _GstAggregatorPadClass
93 GstPadClass parent_class;
95 GstFlowReturn (*flush) (GstAggregatorPad * aggpad, GstAggregator * aggregator);
98 gpointer _gst_reserved[GST_PADDING_LARGE];
101 GType gst_aggregator_pad_get_type (void);
103 /****************************
104 * GstAggregatorPad methods *
105 ***************************/
107 GstBuffer * gst_aggregator_pad_steal_buffer (GstAggregatorPad * pad);
108 GstBuffer * gst_aggregator_pad_get_buffer (GstAggregatorPad * pad);
110 /*********************
111 * GstAggregator API *
112 ********************/
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))
121 #define GST_FLOW_CUSTOM_SUCCESS GST_FLOW_NOT_HANDLED
125 * @aggregator_pads: #GList of #GstAggregatorPad managed by this #GstAggregator.
127 * Collectpads object.
129 struct _GstAggregator
138 GstAggregatorPrivate * priv;
145 gpointer _gst_reserved[GST_PADDING_LARGE];
149 * GstAggregatorClass:
150 * @sinkpads_type: Optional.
151 * The type of the pads that should be created when
152 * GstElement.request_new_pad is called.
154 * Called after a succesful flushing seek, once all the flush
155 * stops have been received. Flush pad-specific data in
156 * #GstAggregatorPad->flush.
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.
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.
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.
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.
203 * It will also take care of event ordering (stream-start, segment, eos).
205 * Basically, a basic implementation will override @aggregate, and call
206 * _finish_buffer from inside that function.
208 struct _GstAggregatorClass {
209 GstElementClass parent_class;
213 GstFlowReturn (*flush) (GstAggregator * aggregator);
215 GstFlowReturn (*clip) (GstAggregator * agg,
216 GstAggregatorPad * bpad,
218 GstBuffer ** outbuf);
220 /* sinkpads virtual methods */
221 gboolean (*sink_event) (GstAggregator * aggregate,
222 GstAggregatorPad * bpad,
225 gboolean (*sink_query) (GstAggregator * aggregate,
226 GstAggregatorPad * bpad,
229 /* srcpad virtual methods */
230 gboolean (*src_event) (GstAggregator * aggregate,
233 gboolean (*src_query) (GstAggregator * aggregate,
236 gboolean (*src_activate) (GstAggregator * aggregator,
240 GstFlowReturn (*aggregate) (GstAggregator * aggregator,
243 gboolean (*stop) (GstAggregator * aggregator);
245 gboolean (*start) (GstAggregator * aggregator);
247 GstClockTime (*get_next_time) (GstAggregator * aggregator);
250 gpointer _gst_reserved[GST_PADDING_LARGE];
253 /*************************
254 * GstAggregator methods *
255 ************************/
257 GstFlowReturn gst_aggregator_finish_buffer (GstAggregator * agg,
259 void gst_aggregator_set_src_caps (GstAggregator * agg,
262 void gst_aggregator_set_latency (GstAggregator * self,
263 GstClockTime min_latency,
264 GstClockTime max_latency);
266 GType gst_aggregator_get_type(void);
268 /* API that should eventually land in GstElement itself*/
269 typedef gboolean (*GstAggregatorPadForeachFunc) (GstAggregator * self,
272 gboolean gst_aggregator_iterate_sinkpads (GstAggregator * self,
273 GstAggregatorPadForeachFunc func,
276 void gst_aggregator_get_latency (GstAggregator * self,
283 #endif /* __GST_AGGREGATOR_H__ */