1 /* GStreamer aggregator base class
2 * Copyright (C) 2014 Mathieu Duponchelle <mathieu.duponchelle@oencreed.com>
3 * Copyright (C) 2014 Thibault Saunier <tsaunier@gnome.org>
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.
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.
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.
21 #ifndef __GST_AGGREGATOR_H__
22 #define __GST_AGGREGATOR_H__
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."
33 /**************************
34 * GstAggregator Structs *
35 *************************/
37 typedef struct _GstAggregator GstAggregator;
38 typedef struct _GstAggregatorPrivate GstAggregatorPrivate;
39 typedef struct _GstAggregatorClass GstAggregatorClass;
41 /************************
42 * GstAggregatorPad API *
43 ***********************/
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))
53 /****************************
54 * GstAggregatorPad Structs *
55 ***************************/
57 typedef struct _GstAggregatorPad GstAggregatorPad;
58 typedef struct _GstAggregatorPadClass GstAggregatorPadClass;
59 typedef struct _GstAggregatorPadPrivate GstAggregatorPadPrivate;
63 * @segment: last segment received.
65 * The implementation the GstPad to use with #GstAggregator
67 struct _GstAggregatorPad
71 /* Protected by the OBJECT_LOCK */
75 GstAggregatorPadPrivate * priv;
77 gpointer _gst_reserved[GST_PADDING];
81 * GstAggregatorPadClass:
83 * Called when the pad has received a flush stop, this is the place
84 * to flush any information specific to the pad, it allows for individual
85 * pads to be flushed while others might not be.
88 struct _GstAggregatorPadClass
90 GstPadClass parent_class;
92 GstFlowReturn (*flush) (GstAggregatorPad * aggpad, GstAggregator * aggregator);
95 gpointer _gst_reserved[GST_PADDING_LARGE];
99 GType gst_aggregator_pad_get_type (void);
101 /****************************
102 * GstAggregatorPad methods *
103 ***************************/
106 GstBuffer * gst_aggregator_pad_steal_buffer (GstAggregatorPad * pad);
109 GstBuffer * gst_aggregator_pad_get_buffer (GstAggregatorPad * pad);
112 gboolean gst_aggregator_pad_drop_buffer (GstAggregatorPad * pad);
115 gboolean gst_aggregator_pad_is_eos (GstAggregatorPad * pad);
117 /*********************
118 * GstAggregator API *
119 ********************/
121 #define GST_TYPE_AGGREGATOR (gst_aggregator_get_type())
122 #define GST_AGGREGATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR,GstAggregator))
123 #define GST_AGGREGATOR_CAST(obj) ((GstAggregator *)(obj))
124 #define GST_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGGREGATOR,GstAggregatorClass))
125 #define GST_AGGREGATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AGGREGATOR,GstAggregatorClass))
126 #define GST_IS_AGGREGATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGGREGATOR))
127 #define GST_IS_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGGREGATOR))
129 #define GST_AGGREGATOR_FLOW_NEED_DATA GST_FLOW_CUSTOM_ERROR
133 * @srcpad: the aggregator's source pad
134 * @segment: the output segment
136 * Aggregator base class object structure.
138 struct _GstAggregator
144 /* Only access with the object lock held */
148 GstAggregatorPrivate * priv;
150 gpointer _gst_reserved[GST_PADDING_LARGE];
154 * GstAggregatorClass:
155 * @sinkpads_type: Optional.
156 * The type of the pads that should be created when
157 * GstElement.request_new_pad is called.
159 * Called after a successful flushing seek, once all the flush
160 * stops have been received. Flush pad-specific data in
161 * #GstAggregatorPad->flush.
163 * Called when a buffer is received on a sink pad, the task of
164 * clipping it and translating it to the current segment falls
165 * on the subclass. The function should use the segment of data
166 * and the negotiated media type on the pad to perform
167 * clipping of input buffer. This function takes ownership of
168 * buf and should output a buffer or return NULL in
169 * if the buffer should be dropped.
170 * @sink_event: Optional.
171 * Called when an event is received on a sink pad, the subclass
172 * should always chain up.
173 * @sink_query: Optional.
174 * Called when a query is received on a sink pad, the subclass
175 * should always chain up.
176 * @src_event: Optional.
177 * Called when an event is received on the src pad, the subclass
178 * should always chain up.
179 * @src_query: Optional.
180 * Called when a query is received on the src pad, the subclass
181 * should always chain up.
182 * @src_activate: Optional.
183 * Called when the src pad is activated, it will start/stop its
184 * pad task right after that call.
185 * @aggregate: Mandatory.
186 * Called when buffers are queued on all sinkpads. Classes
187 * should iterate the GstElement->sinkpads and peek or steal
188 * buffers from the #GstAggregatorPads. If the subclass returns
189 * GST_FLOW_EOS, sending of the eos event will be taken care
190 * of. Once / if a buffer has been constructed from the
191 * aggregated buffers, the subclass should call _finish_buffer.
193 * Called when the element goes from PAUSED to READY.
194 * The subclass should free all resources and reset its state.
196 * Called when the element goes from READY to PAUSED.
197 * The subclass should get ready to process
198 * aggregated buffers.
199 * @get_next_time: Optional.
200 * Called when the element needs to know the running time of the next
201 * rendered buffer for live pipelines. This causes deadline
202 * based aggregation to occur. Defaults to returning
203 * GST_CLOCK_TIME_NONE causing the element to wait for buffers
204 * on all sink pads before aggregating.
205 * @update_src_caps: Lets subclasses update the #GstCaps representing
206 * the src pad caps before usage. The result should end up
207 * in @ret. Return %GST_AGGREGATOR_FLOW_NEED_DATA to indicate that the
208 * element needs more information (caps, a buffer, etc) to
209 * choose the correct caps. Should return ANY caps if the
210 * stream has not caps at all.
211 * @fixate_src_caps: Optional.
212 * Fixate and return the src pad caps provided. The function takes
213 * ownership of @caps and returns a fixated version of
214 * @caps. @caps is not guaranteed to be writable.
215 * @negotiated_src_caps: Optional.
216 * Notifies subclasses what caps format has been negotiated
217 * @decide_allocation: Optional.
218 * Allows the subclass to influence the allocation choices.
219 * Setup the allocation parameters for allocating output
220 * buffers. The passed in query contains the result of the
221 * downstream allocation query.
223 * The aggregator base class will handle in a thread-safe way all manners of
224 * concurrent flushes, seeks, pad additions and removals, leaving to the
225 * subclass the responsibility of clipping buffers, and aggregating buffers in
226 * the way the implementor sees fit.
228 * It will also take care of event ordering (stream-start, segment, eos).
230 * Basically, a simple implementation will override @aggregate, and call
231 * _finish_buffer from inside that function.
233 struct _GstAggregatorClass {
234 GstElementClass parent_class;
238 GstFlowReturn (*flush) (GstAggregator * aggregator);
240 GstBuffer * (*clip) (GstAggregator * aggregator,
241 GstAggregatorPad * aggregator_pad,
244 /* sinkpads virtual methods */
245 gboolean (*sink_event) (GstAggregator * aggregator,
246 GstAggregatorPad * aggregator_pad,
249 gboolean (*sink_query) (GstAggregator * aggregator,
250 GstAggregatorPad * aggregator_pad,
253 /* srcpad virtual methods */
254 gboolean (*src_event) (GstAggregator * aggregator,
257 gboolean (*src_query) (GstAggregator * aggregator,
260 gboolean (*src_activate) (GstAggregator * aggregator,
264 GstFlowReturn (*aggregate) (GstAggregator * aggregator,
267 gboolean (*stop) (GstAggregator * aggregator);
269 gboolean (*start) (GstAggregator * aggregator);
271 GstClockTime (*get_next_time) (GstAggregator * aggregator);
273 GstAggregatorPad * (*create_new_pad) (GstAggregator * self,
274 GstPadTemplate * templ,
275 const gchar * req_name,
276 const GstCaps * caps);
277 GstFlowReturn (*update_src_caps) (GstAggregator * self,
280 GstCaps * (*fixate_src_caps) (GstAggregator * self,
282 gboolean (*negotiated_src_caps) (GstAggregator * self,
284 gboolean (*decide_allocation) (GstAggregator * self,
286 gboolean (*propose_allocation) (GstAggregator * self,
287 GstAggregatorPad * pad,
288 GstQuery * decide_query,
291 gpointer _gst_reserved[GST_PADDING_LARGE];
294 /************************************
295 * GstAggregator convenience macros *
296 ***********************************/
299 * GST_AGGREGATOR_SRC_PAD:
300 * @agg: a #GstAggregator
302 * Convenience macro to access the source pad of #GstAggregator
306 #define GST_AGGREGATOR_SRC_PAD(agg) (((GstAggregator *)(agg))->srcpad)
308 /*************************
309 * GstAggregator methods *
310 ************************/
313 GstFlowReturn gst_aggregator_finish_buffer (GstAggregator * self,
317 void gst_aggregator_set_src_caps (GstAggregator * self,
321 void gst_aggregator_set_latency (GstAggregator * self,
322 GstClockTime min_latency,
323 GstClockTime max_latency);
326 GType gst_aggregator_get_type(void);
328 /* API that should eventually land in GstElement itself (FIXME) */
329 typedef gboolean (*GstAggregatorPadForeachFunc) (GstAggregator * aggregator,
330 GstAggregatorPad * aggregator_pad,
334 gboolean gst_aggregator_iterate_sinkpads (GstAggregator * self,
335 GstAggregatorPadForeachFunc func,
339 GstClockTime gst_aggregator_get_latency (GstAggregator * self);
342 GstBufferPool * gst_aggregator_get_buffer_pool (GstAggregator * self);
345 void gst_aggregator_get_allocator (GstAggregator * self,
346 GstAllocator ** allocator,
347 GstAllocationParams * params);
351 #endif /* __GST_AGGREGATOR_H__ */