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__
28 /**************************
29 * GstAggregator Structs *
30 *************************/
32 typedef struct _GstAggregator GstAggregator;
33 typedef struct _GstAggregatorPrivate GstAggregatorPrivate;
34 typedef struct _GstAggregatorClass GstAggregatorClass;
36 /************************
37 * GstAggregatorPad API *
38 ***********************/
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))
48 /****************************
49 * GstAggregatorPad Structs *
50 ***************************/
52 typedef struct _GstAggregatorPad GstAggregatorPad;
53 typedef struct _GstAggregatorPadClass GstAggregatorPadClass;
54 typedef struct _GstAggregatorPadPrivate GstAggregatorPadPrivate;
58 * @segment: last segment received.
60 * The implementation the GstPad to use with #GstAggregator
62 struct _GstAggregatorPad
66 /* Protected by the OBJECT_LOCK */
70 GstAggregatorPadPrivate * priv;
72 gpointer _gst_reserved[GST_PADDING];
76 * GstAggregatorPadClass:
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 * @skip_buffer: Optional
82 * Called before input buffers are queued in the pad, return %TRUE
83 * if the buffer should be skipped.
86 struct _GstAggregatorPadClass
88 GstPadClass parent_class;
90 GstFlowReturn (*flush) (GstAggregatorPad * aggpad, GstAggregator * aggregator);
91 gboolean (*skip_buffer) (GstAggregatorPad * aggpad, GstAggregator * aggregator, GstBuffer * buffer);
94 gpointer _gst_reserved[GST_PADDING_LARGE];
98 GType gst_aggregator_pad_get_type (void);
100 /****************************
101 * GstAggregatorPad methods *
102 ***************************/
105 GstBuffer * gst_aggregator_pad_pop_buffer (GstAggregatorPad * pad);
108 GstBuffer * gst_aggregator_pad_peek_buffer (GstAggregatorPad * pad);
111 gboolean gst_aggregator_pad_drop_buffer (GstAggregatorPad * pad);
114 gboolean gst_aggregator_pad_is_eos (GstAggregatorPad * pad);
116 /*********************
117 * GstAggregator API *
118 ********************/
120 #define GST_TYPE_AGGREGATOR (gst_aggregator_get_type())
121 #define GST_AGGREGATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR,GstAggregator))
122 #define GST_AGGREGATOR_CAST(obj) ((GstAggregator *)(obj))
123 #define GST_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AGGREGATOR,GstAggregatorClass))
124 #define GST_AGGREGATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_AGGREGATOR,GstAggregatorClass))
125 #define GST_IS_AGGREGATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AGGREGATOR))
126 #define GST_IS_AGGREGATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AGGREGATOR))
128 #define GST_AGGREGATOR_FLOW_NEED_DATA GST_FLOW_CUSTOM_ERROR
132 * @srcpad: the aggregator's source pad
133 * @segment: the output segment
135 * Aggregator base class object structure.
137 struct _GstAggregator
144 GstAggregatorPrivate * priv;
146 gpointer _gst_reserved[GST_PADDING_LARGE];
150 * GstAggregatorClass:
152 * Called after a successful flushing seek, once all the flush
153 * stops have been received. Flush pad-specific data in
154 * #GstAggregatorPad->flush.
156 * Called when a buffer is received on a sink pad, the task of
157 * clipping it and translating it to the current segment falls
158 * on the subclass. The function should use the segment of data
159 * and the negotiated media type on the pad to perform
160 * clipping of input buffer. This function takes ownership of
161 * buf and should output a buffer or return NULL in
162 * if the buffer should be dropped.
163 * @finish_buffer: Optional.
164 * Called when a subclass calls gst_aggregator_finish_buffer()
165 * from their aggregate function to push out a buffer.
166 * Subclasses can override this to modify or decorate buffers
167 * before they get pushed out. This function takes ownership
168 * of the buffer passed. Subclasses that override this method
169 * should always chain up to the parent class virtual method.
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;
236 GstFlowReturn (*flush) (GstAggregator * aggregator);
238 GstBuffer * (*clip) (GstAggregator * aggregator,
239 GstAggregatorPad * aggregator_pad,
242 GstFlowReturn (*finish_buffer) (GstAggregator * aggregator,
245 /* sinkpads virtual methods */
246 gboolean (*sink_event) (GstAggregator * aggregator,
247 GstAggregatorPad * aggregator_pad,
250 gboolean (*sink_query) (GstAggregator * aggregator,
251 GstAggregatorPad * aggregator_pad,
254 /* srcpad virtual methods */
255 gboolean (*src_event) (GstAggregator * aggregator,
258 gboolean (*src_query) (GstAggregator * aggregator,
261 gboolean (*src_activate) (GstAggregator * aggregator,
265 GstFlowReturn (*aggregate) (GstAggregator * aggregator,
268 gboolean (*stop) (GstAggregator * aggregator);
270 gboolean (*start) (GstAggregator * aggregator);
272 GstClockTime (*get_next_time) (GstAggregator * aggregator);
274 GstAggregatorPad * (*create_new_pad) (GstAggregator * self,
275 GstPadTemplate * templ,
276 const gchar * req_name,
277 const GstCaps * caps);
278 GstFlowReturn (*update_src_caps) (GstAggregator * self,
281 GstCaps * (*fixate_src_caps) (GstAggregator * self,
283 gboolean (*negotiated_src_caps) (GstAggregator * self,
285 gboolean (*decide_allocation) (GstAggregator * self,
287 gboolean (*propose_allocation) (GstAggregator * self,
288 GstAggregatorPad * pad,
289 GstQuery * decide_query,
292 gpointer _gst_reserved[GST_PADDING_LARGE];
295 /************************************
296 * GstAggregator convenience macros *
297 ***********************************/
300 * GST_AGGREGATOR_SRC_PAD:
301 * @agg: a #GstAggregator
303 * Convenience macro to access the source pad of #GstAggregator
307 #define GST_AGGREGATOR_SRC_PAD(agg) (((GstAggregator *)(agg))->srcpad)
309 /*************************
310 * GstAggregator methods *
311 ************************/
314 GstFlowReturn gst_aggregator_finish_buffer (GstAggregator * aggregator,
318 void gst_aggregator_set_src_caps (GstAggregator * self,
322 void gst_aggregator_set_latency (GstAggregator * self,
323 GstClockTime min_latency,
324 GstClockTime max_latency);
327 GType gst_aggregator_get_type(void);
330 GstClockTime gst_aggregator_get_latency (GstAggregator * self);
333 GstBufferPool * gst_aggregator_get_buffer_pool (GstAggregator * self);
336 void gst_aggregator_get_allocator (GstAggregator * self,
337 GstAllocator ** allocator,
338 GstAllocationParams * params);
342 #endif /* __GST_AGGREGATOR_H__ */