2 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
3 * Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sourceforge.net>
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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #ifndef __GST_COLLECT_PADS2_H__
24 #define __GST_COLLECT_PADS2_H__
30 #define GST_TYPE_COLLECT_PADS2 (gst_collect_pads2_get_type())
31 #define GST_COLLECT_PADS2(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_COLLECT_PADS2,GstCollectPads2))
32 #define GST_COLLECT_PADS2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_COLLECT_PADS2,GstCollectPads2Class))
33 #define GST_COLLECT_PADS2_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_COLLECT_PADS2,GstCollectPads2Class))
34 #define GST_IS_COLLECT_PADS2(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_COLLECT_PADS2))
35 #define GST_IS_COLLECT_PADS2_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_COLLECT_PADS2))
37 typedef struct _GstCollectData2 GstCollectData2;
38 typedef struct _GstCollectData2Private GstCollectData2Private;
39 typedef struct _GstCollectPads2 GstCollectPads2;
40 typedef struct _GstCollectPads2Private GstCollectPads2Private;
41 typedef struct _GstCollectPads2Class GstCollectPads2Class;
44 * GstCollectData2DestroyNotify:
45 * @data: the #GstCollectData2 that will be freed
47 * A function that will be called when the #GstCollectData2 will be freed.
48 * It is passed the pointer to the structure and should free any custom
49 * memory and resources allocated for it.
53 typedef void (*GstCollectData2DestroyNotify) (GstCollectData2 *data);
56 * GstCollectPads2StateFlags:
57 * @GST_COLLECT_PADS2_STATE_EOS: Set if collectdata's pad is EOS.
58 * @GST_COLLECT_PADS2_STATE_FLUSHING: Set if collectdata's pad is flushing.
59 * @GST_COLLECT_PADS2_STATE_NEW_SEGMENT: Set if collectdata's pad received a
61 * @GST_COLLECT_PADS2_STATE_WAITING: Set if collectdata's pad must be waited
62 * for when collecting.
63 * @GST_COLLECT_PADS2_STATE_LOCKED: Set collectdata's pad WAITING state must
65 * #GstCollectPads2StateFlags indicate private state of a collectdata('s pad).
70 GST_COLLECT_PADS2_STATE_EOS = 1 << 0,
71 GST_COLLECT_PADS2_STATE_FLUSHING = 1 << 1,
72 GST_COLLECT_PADS2_STATE_NEW_SEGMENT = 1 << 2,
73 GST_COLLECT_PADS2_STATE_WAITING = 1 << 3,
74 GST_COLLECT_PADS2_STATE_LOCKED = 1 << 4
75 } GstCollectPads2StateFlags;
78 * GST_COLLECT_PADS2_STATE:
79 * @data: a #GstCollectData2.
81 * A flags word containing #GstCollectPads2StateFlags flags set
82 * on this collected pad.
86 #define GST_COLLECT_PADS2_STATE(data) (((GstCollectData2 *) data)->state)
88 * GST_COLLECT_PADS2_STATE_IS_SET:
89 * @data: a #GstCollectData2.
90 * @flag: the #GstCollectPads2StateFlags to check.
92 * Gives the status of a specific flag on a collected pad.
96 #define GST_COLLECT_PADS2_STATE_IS_SET(data,flag) !!(GST_COLLECT_PADS2_STATE (data) & flag)
98 * GST_COLLECT_PADS2_STATE_SET:
99 * @data: a #GstCollectData2.
100 * @flag: the #GstCollectPads2StateFlags to set.
102 * Sets a state flag on a collected pad.
106 #define GST_COLLECT_PADS2_STATE_SET(data,flag) (GST_COLLECT_PADS2_STATE (data) |= flag)
108 * GST_COLLECT_PADS2_STATE_UNSET:
109 * @data: a #GstCollectData2.
110 * @flag: the #GstCollectPads2StateFlags to clear.
112 * Clears a state flag on a collected pad.
116 #define GST_COLLECT_PADS2_STATE_UNSET(data,flag) (GST_COLLECT_PADS2_STATE (data) &= ~(flag))
120 * @collect: owner #GstCollectPads2
121 * @pad: #GstPad managed by this data
122 * @buffer: currently queued buffer.
123 * @pos: position in the buffer
124 * @segment: last segment received.
126 * Structure used by the collect_pads2.
130 struct _GstCollectData2
132 /* with STREAM_LOCK of @collect */
133 GstCollectPads2 *collect;
140 /* state: bitfield for easier extension;
141 * eos, flushing, new_segment, waiting */
142 GstCollectPads2StateFlags state;
144 GstCollectData2Private *priv;
146 gpointer _gst_reserved[GST_PADDING];
150 * GstCollectPads2Function:
151 * @pads: the #GstCollectPads2 that trigered the callback
152 * @user_data: user data passed to gst_collect_pads2_set_function()
154 * A function that will be called when all pads have received data.
156 * Returns: #GST_FLOW_OK for success
160 typedef GstFlowReturn (*GstCollectPads2Function) (GstCollectPads2 *pads, gpointer user_data);
163 * GstCollectPads2BufferFunction:
164 * @pads: the #GstCollectPads2 that trigered the callback
165 * @data: the #GstCollectData2 of pad that has received the buffer
166 * @buffer: the #GstBuffer
167 * @user_data: user data passed to gst_collect_pads2_set_buffer_function()
169 * A function that will be called when a (considered oldest) buffer can be muxed.
170 * If all pads have reached EOS, this function is called with NULL @buffer
173 * Returns: #GST_FLOW_OK for success
177 typedef GstFlowReturn (*GstCollectPads2BufferFunction) (GstCollectPads2 *pads, GstCollectData2 *data,
178 GstBuffer *buffer, gpointer user_data);
181 * GstCollectPads2CompareFunction:
182 * @pads: the #GstCollectPads that is comparing the timestamps
183 * @data1: the first #GstCollectData2
184 * @timestamp1: the first timestamp
185 * @data2: the second #GstCollectData2
186 * @timestamp2: the second timestamp
187 * @user_data: user data passed to gst_collect_pads2_set_compare_function()
189 * A function for comparing two timestamps of buffers or newsegments collected on one pad.
191 * Returns: Integer less than zero when first timestamp is deemed older than the second one.
192 * Zero if the timestamps are deemed equally old.
193 * Integer greate than zero when second timestamp is deemed older than the first one.
197 typedef gint (*GstCollectPads2CompareFunction) (GstCollectPads2 *pads,
198 GstCollectData2 * data1, GstClockTime timestamp1,
199 GstCollectData2 * data2, GstClockTime timestamp2,
203 * GstCollectPads2EventFunction:
204 * @pads: the #GstCollectPads2 that trigered the callback
205 * @pad: the #GstPad that received an event
206 * @event: the #GstEvent received
207 * @user_data: user data passed to gst_collect_pads2_set_event_function()
209 * A function that will be called while processing an event. It takes
210 * ownership of the event and is responsible for chaining up (to
211 * gst_collect_pads2_event_default()) or dropping events (such typical cases
212 * being handled by the default handler).
214 * Returns: %TRUE if the pad could handle the event
218 typedef gboolean (*GstCollectPads2EventFunction) (GstCollectPads2 *pads, GstCollectData2 * pad,
219 GstEvent * event, gpointer user_data);
223 * GstCollectPads2QueryFunction:
224 * @pads: the #GstCollectPads2 that trigered the callback
225 * @pad: the #GstPad that received an event
226 * @query: the #GstEvent received
227 * @user_data: user data passed to gst_collect_pads2_set_query_function()
229 * A function that will be called while processing a query. It takes
230 * ownership of the query and is responsible for chaining up (to
231 * events downstream (with gst_pad_event_default()).
233 * Returns: %TRUE if the pad could handle the event
237 typedef gboolean (*GstCollectPads2QueryFunction) (GstCollectPads2 *pads, GstCollectData2 * pad,
238 GstQuery * query, gpointer user_data);
241 * GstCollectPads2ClipFunction:
242 * @pads: a #GstCollectPads2
243 * @data: a #GstCollectData2
244 * @inbuffer: the input #GstBuffer
245 * @outbuffer: the output #GstBuffer
246 * @user_data: user data
248 * A function that will be called when @inbuffer is received on the pad managed
249 * by @data in the collecpad object @pads.
251 * The function should use the segment of @data and the negotiated media type on
252 * the pad to perform clipping of @inbuffer.
254 * This function takes ownership of @inbuffer and should output a buffer in
255 * @outbuffer or return %NULL in @outbuffer if the buffer should be dropped.
257 * Returns: a #GstFlowReturn that corresponds to the result of clipping.
261 typedef GstFlowReturn (*GstCollectPads2ClipFunction) (GstCollectPads2 *pads, GstCollectData2 *data,
262 GstBuffer *inbuffer, GstBuffer **outbuffer,
266 * GST_COLLECT_PADS2_GET_STREAM_LOCK:
267 * @pads: a #GstCollectPads2
269 * Get the stream lock of @pads. The stream lock is used to coordinate and
270 * serialize execution among the various streams being collected, and in
271 * protecting the resources used to accomplish this.
275 #define GST_COLLECT_PADS2_GET_STREAM_LOCK(pads) (&((GstCollectPads2 *)pads)->stream_lock)
277 * GST_COLLECT_PADS2_STREAM_LOCK:
278 * @pads: a #GstCollectPads2
280 * Lock the stream lock of @pads.
284 #define GST_COLLECT_PADS2_STREAM_LOCK(pads) g_rec_mutex_lock(GST_COLLECT_PADS2_GET_STREAM_LOCK (pads))
286 * GST_COLLECT_PADS2_STREAM_UNLOCK:
287 * @pads: a #GstCollectPads2
289 * Unlock the stream lock of @pads.
293 #define GST_COLLECT_PADS2_STREAM_UNLOCK(pads) g_rec_mutex_unlock(GST_COLLECT_PADS2_GET_STREAM_LOCK (pads))
297 * @data: #GList of #GstCollectData2 managed by this #GstCollectPads2.
299 * Collectpads object.
303 struct _GstCollectPads2 {
306 /*< public >*/ /* with LOCK and/or STREAM_LOCK */
307 GSList *data; /* list of CollectData items */
310 GRecMutex stream_lock; /* used to serialize collection among several streams */
312 GstCollectPads2Private *priv;
314 gpointer _gst_reserved[GST_PADDING];
317 struct _GstCollectPads2Class {
318 GstObjectClass parent_class;
321 gpointer _gst_reserved[GST_PADDING];
324 GType gst_collect_pads2_get_type(void);
326 /* creating the object */
327 GstCollectPads2* gst_collect_pads2_new (void);
329 /* set the callbacks */
330 void gst_collect_pads2_set_function (GstCollectPads2 *pads,
331 GstCollectPads2Function func,
333 void gst_collect_pads2_set_buffer_function (GstCollectPads2 *pads,
334 GstCollectPads2BufferFunction func,
336 void gst_collect_pads2_set_event_function (GstCollectPads2 *pads,
337 GstCollectPads2EventFunction func,
339 void gst_collect_pads2_set_query_function (GstCollectPads2 *pads,
340 GstCollectPads2QueryFunction func,
342 void gst_collect_pads2_set_compare_function (GstCollectPads2 *pads,
343 GstCollectPads2CompareFunction func,
345 void gst_collect_pads2_set_clip_function (GstCollectPads2 *pads,
346 GstCollectPads2ClipFunction clipfunc,
350 GstCollectData2* gst_collect_pads2_add_pad (GstCollectPads2 *pads, GstPad *pad, guint size);
351 GstCollectData2* gst_collect_pads2_add_pad_full (GstCollectPads2 *pads, GstPad *pad, guint size,
352 GstCollectData2DestroyNotify destroy_notify,
354 gboolean gst_collect_pads2_remove_pad (GstCollectPads2 *pads, GstPad *pad);
355 gboolean gst_collect_pads2_is_active (GstCollectPads2 *pads, GstPad *pad);
357 /* start/stop collection */
358 GstFlowReturn gst_collect_pads2_collect (GstCollectPads2 *pads);
359 GstFlowReturn gst_collect_pads2_collect_range (GstCollectPads2 *pads, guint64 offset, guint length);
361 void gst_collect_pads2_start (GstCollectPads2 *pads);
362 void gst_collect_pads2_stop (GstCollectPads2 *pads);
363 void gst_collect_pads2_set_flushing (GstCollectPads2 *pads, gboolean flushing);
365 /* get collected buffers */
366 GstBuffer* gst_collect_pads2_peek (GstCollectPads2 *pads, GstCollectData2 *data);
367 GstBuffer* gst_collect_pads2_pop (GstCollectPads2 *pads, GstCollectData2 *data);
369 /* get collected bytes */
370 guint gst_collect_pads2_available (GstCollectPads2 *pads);
371 guint gst_collect_pads2_flush (GstCollectPads2 *pads, GstCollectData2 *data,
373 GstBuffer* gst_collect_pads2_read_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
375 GstBuffer* gst_collect_pads2_take_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
378 /* setting and unsetting waiting mode */
379 void gst_collect_pads2_set_waiting (GstCollectPads2 *pads, GstCollectData2 *data,
382 /* convenience helper */
383 GstFlowReturn gst_collect_pads2_clip_running_time (GstCollectPads2 * pads,
384 GstCollectData2 * cdata, GstBuffer * buf, GstBuffer ** outbuf,
387 /* default handlers */
388 gboolean gst_collect_pads2_event_default (GstCollectPads2 * pads2, GstCollectData2 * data,
389 GstEvent * event, gboolean discard);
390 gboolean gst_collect_pads2_query_default (GstCollectPads2 * pads, GstCollectData2 * data,
391 GstQuery * query, gboolean discard);
396 #endif /* __GST_COLLECT_PADS22_H__ */