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 * @buffer: currently queued buffer.
64 * @segment: last segment received.
66 * The implementation the GstPad to use with #GstAggregator
68 struct _GstAggregatorPad
72 /* Protected by the OBJECT_LOCK */
76 GstAggregatorPadPrivate * priv;
78 gpointer _gst_reserved[GST_PADDING];
82 * GstAggregatorPadClass:
84 * Called when the pad has received a flush stop, this is the place
85 * to flush any information specific to the pad, it allows for individual
86 * pads to be flushed while others might not be.
89 struct _GstAggregatorPadClass
91 GstPadClass parent_class;
93 GstFlowReturn (*flush) (GstAggregatorPad * aggpad, GstAggregator * aggregator);
96 gpointer _gst_reserved[GST_PADDING_LARGE];
99 GType gst_aggregator_pad_get_type (void);
101 /****************************
102 * GstAggregatorPad methods *
103 ***************************/
105 GstBuffer * gst_aggregator_pad_steal_buffer (GstAggregatorPad * pad);
106 GstBuffer * gst_aggregator_pad_get_buffer (GstAggregatorPad * pad);
107 gboolean gst_aggregator_pad_is_eos (GstAggregatorPad * pad);
109 /*********************
110 * GstAggregator API *
111 ********************/
113 #define GST_TYPE_AGGREGATOR (gst_aggregator_get_type())
114 #define GST_AGGREGATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AGGREGATOR,GstAggregator))
115 #define GST_AGGREGATOR_CAST(obj) ((GstAggregator *)(obj))
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 * @srcpad: the aggregator's source pad
126 * @segment: the output segment
128 * Aggregator base class object structure.
130 struct _GstAggregator
136 /* Only access with the object lock held */
140 GstAggregatorPrivate * priv;
142 gpointer _gst_reserved[GST_PADDING_LARGE];
146 * GstAggregatorClass:
147 * @sinkpads_type: Optional.
148 * The type of the pads that should be created when
149 * GstElement.request_new_pad is called.
151 * Called after a succesful flushing seek, once all the flush
152 * stops have been received. Flush pad-specific data in
153 * #GstAggregatorPad->flush.
155 * Called when a buffer is received on a sink pad, the task
156 * of clipping it and translating it to the current segment
157 * falls on the subclass.
158 * @sink_event: Optional.
159 * Called when an event is received on a sink pad, the subclass
160 * should always chain up.
161 * @sink_query: Optional.
162 * Called when a query is received on a sink pad, the subclass
163 * should always chain up.
164 * @src_event: Optional.
165 * Called when an event is received on the src pad, the subclass
166 * should always chain up.
167 * @src_query: Optional.
168 * Called when a query is received on the src pad, the subclass
169 * should always chain up.
170 * @src_activate: Optional.
171 * Called when the src pad is activated, it will start/stop its
172 * pad task right after that call.
173 * @aggregate: Mandatory.
174 * Called when buffers are queued on all sinkpads. Classes
175 * should iterate the GstElement->sinkpads and peek or steal
176 * buffers from the #GstAggregatorPads. If the subclass returns
177 * GST_FLOW_EOS, sending of the eos event will be taken care
178 * of. Once / if a buffer has been constructed from the
179 * aggregated buffers, the subclass should call _finish_buffer.
181 * Called when the element goes from PAUSED to READY.
182 * The subclass should free all resources and reset its state.
184 * Called when the element goes from READY to PAUSED.
185 * The subclass should get ready to process
186 * aggregated buffers.
187 * @get_next_time: Optional.
188 * Called when the element needs to know the time of the next
189 * rendered buffer for live pipelines. This causes deadline
190 * based aggregation to occur. Defaults to returning
191 * GST_CLOCK_TIME_NONE causing the element to wait for buffers
192 * on all sink pads before aggregating.
194 * The aggregator base class will handle in a thread-safe way all manners of
195 * concurrent flushes, seeks, pad additions and removals, leaving to the
196 * subclass the responsibility of clipping buffers, and aggregating buffers in
197 * the way the implementor sees fit.
199 * It will also take care of event ordering (stream-start, segment, eos).
201 * Basically, a basic implementation will override @aggregate, and call
202 * _finish_buffer from inside that function.
204 struct _GstAggregatorClass {
205 GstElementClass parent_class;
209 GstFlowReturn (*flush) (GstAggregator * aggregator);
211 GstFlowReturn (*clip) (GstAggregator * aggregator,
212 GstAggregatorPad * aggregator_pad,
214 GstBuffer ** outbuf);
216 /* sinkpads virtual methods */
217 gboolean (*sink_event) (GstAggregator * aggregator,
218 GstAggregatorPad * aggregator_pad,
221 gboolean (*sink_query) (GstAggregator * aggregator,
222 GstAggregatorPad * aggregator_pad,
225 /* srcpad virtual methods */
226 gboolean (*src_event) (GstAggregator * aggregator,
229 gboolean (*src_query) (GstAggregator * aggregator,
232 gboolean (*src_activate) (GstAggregator * aggregator,
236 GstFlowReturn (*aggregate) (GstAggregator * aggregator,
239 gboolean (*stop) (GstAggregator * aggregator);
241 gboolean (*start) (GstAggregator * aggregator);
243 GstClockTime (*get_next_time) (GstAggregator * aggregator);
246 gpointer _gst_reserved[GST_PADDING_LARGE];
249 /*************************
250 * GstAggregator methods *
251 ************************/
253 GstFlowReturn gst_aggregator_finish_buffer (GstAggregator * agg,
255 void gst_aggregator_set_src_caps (GstAggregator * agg,
258 void gst_aggregator_set_latency (GstAggregator * self,
259 GstClockTime min_latency,
260 GstClockTime max_latency);
262 GType gst_aggregator_get_type(void);
264 /* API that should eventually land in GstElement itself (FIXME) */
265 typedef gboolean (*GstAggregatorPadForeachFunc) (GstAggregator * aggregator,
266 GstAggregatorPad * aggregator_pad,
269 gboolean gst_aggregator_iterate_sinkpads (GstAggregator * self,
270 GstAggregatorPadForeachFunc func,
273 void gst_aggregator_get_latency_unlocked (GstAggregator * self,
280 #endif /* __GST_AGGREGATOR_H__ */