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 _GstCollectPads2 GstCollectPads2;
39 typedef struct _GstCollectPads2Class GstCollectPads2Class;
42 * GstCollectData2DestroyNotify:
43 * @data: the #GstCollectData2 that will be freed
45 * A function that will be called when the #GstCollectData2 will be freed.
46 * It is passed the pointer to the structure and should free any custom
47 * memory and resources allocated for it.
51 typedef void (*GstCollectData2DestroyNotify) (GstCollectData2 *data);
54 * GstCollectPads2StateFlags:
55 * @GST_COLLECT_PADS2_STATE_EOS: Set if collectdata's pad is EOS.
56 * @GST_COLLECT_PADS2_STATE_FLUSHING: Set if collectdata's pad is flushing.
57 * @GST_COLLECT_PADS2_STATE_NEW_SEGMENT: Set if collectdata's pad received a
59 * @GST_COLLECT_PADS2_STATE_WAITING: Set if collectdata's pad must be waited
60 * for when collecting.
61 * @GST_COLLECT_PADS2_STATE_LOCKED: Set collectdata's pad WAITING state must
63 * #GstCollectPads2StateFlags indicate private state of a collectdata('s pad).
66 GST_COLLECT_PADS2_STATE_EOS = 1 << 0,
67 GST_COLLECT_PADS2_STATE_FLUSHING = 1 << 1,
68 GST_COLLECT_PADS2_STATE_NEW_SEGMENT = 1 << 2,
69 GST_COLLECT_PADS2_STATE_WAITING = 1 << 3,
70 GST_COLLECT_PADS2_STATE_LOCKED = 1 << 4
71 } GstCollectPads2StateFlags;
74 * GST_COLLECT_PADS2_STATE:
75 * @data: a #GstCollectData2.
77 * A flags word containing #GstCollectPads2StateFlags flags set
78 * on this collected pad.
80 #define GST_COLLECT_PADS2_STATE(data) (((GstCollectData2 *) data)->state)
82 * GST_COLLECT_PADS2_STATE_IS_SET:
83 * @data: a #GstCollectData2.
84 * @flag: the #GstCollectPads2StateFlags to check.
86 * Gives the status of a specific flag on a collected pad.
88 #define GST_COLLECT_PADS2_STATE_IS_SET(data,flag) !!(GST_COLLECT_PADS2_STATE (data) & flag)
90 * GST_COLLECT_PADS2_STATE_SET:
91 * @data: a #GstCollectData2.
92 * @flag: the #GstCollectPads2StateFlags to set.
94 * Sets a state flag on a collected pad.
96 #define GST_COLLECT_PADS2_STATE_SET(data,flag) (GST_COLLECT_PADS2_STATE (data) |= flag)
98 * GST_COLLECT_PADS2_STATE_UNSET:
99 * @data: a #GstCollectData2.
100 * @flag: the #GstCollectPads2StateFlags to clear.
102 * Clears a state flag on a collected pad.
104 #define GST_COLLECT_PADS2_STATE_UNSET(data,flag) (GST_COLLECT_PADS2_STATE (data) &= ~(flag))
106 #define GST_COLLECT_PADS2_FLOW_DROP GST_FLOW_CUSTOM_SUCCESS
110 * @collect: owner #GstCollectPads2
111 * @pad: #GstPad managed by this data
112 * @buffer: currently queued buffer.
113 * @pos: position in the buffer
114 * @segment: last segment received.
116 * Structure used by the collect_pads2.
118 struct _GstCollectData2
120 /* with STREAM_LOCK of @collect */
121 GstCollectPads2 *collect;
128 /* state: bitfield for easier extension;
129 * eos, flushing, new_segment, waiting */
132 /* refcounting for struct, and destroy callback */
133 GstCollectData2DestroyNotify destroy_notify;
136 gpointer _gst_reserved[GST_PADDING];
140 * GstCollectPads2Function:
141 * @pads: the #GstCollectPads2 that trigered the callback
142 * @user_data: user data passed to gst_collect_pads2_set_function()
144 * A function that will be called when all pads have received data.
146 * Returns: #GST_FLOW_OK for success
148 typedef GstFlowReturn (*GstCollectPads2Function) (GstCollectPads2 *pads, gpointer user_data);
151 * GstCollectPads2BufferFunction:
152 * @pads: the #GstCollectPads2 that trigered the callback
153 * @data: the #GstCollectData2 of pad that has received the buffer
154 * @buffer: the #GstBuffer
155 * @user_data: user data passed to gst_collect_pads2_set_buffer_function()
157 * A function that will be called when a (considered oldest) buffer can be muxed.
158 * If all pads have reached EOS, this function is called with NULL @buffer
161 * Returns: #GST_FLOW_OK for success
163 typedef GstFlowReturn (*GstCollectPads2BufferFunction) (GstCollectPads2 *pads, GstCollectData2 *data,
164 GstBuffer *buffer, gpointer user_data);
167 * GstCollectPads2CompareFunction:
168 * @pads: the #GstCollectPads that is comparing the timestamps
169 * @data1: the first #GstCollectData2
170 * @timestamp1: the first timestamp
171 * @data2: the second #GstCollectData2
172 * @timestamp2: the second timestamp
173 * @user_data: user data passed to gst_collect_pads2_set_compare_function()
175 * A function for comparing two timestamps of buffers or newsegments collected on one pad.
177 * Returns: Integer less than zero when first timestamp is deemed older than the second one.
178 * Zero if the timestamps are deemed equally old.
179 * Integer greate than zero when second timestamp is deemed older than the first one.
181 typedef gint (*GstCollectPads2CompareFunction) (GstCollectPads2 *pads,
182 GstCollectData2 * data1, GstClockTime timestamp1,
183 GstCollectData2 * data2, GstClockTime timestamp2,
187 * GstCollectPads2EventFunction:
188 * @pads: the #GstCollectPads2 that trigered the callback
189 * @pad: the #GstPad that received an event
190 * @event: the #GstEvent received
191 * @user_data: user data passed to gst_collect_pads2_set_event_function()
193 * A function that will be called after collectpads has processed the event.
195 * Returns: %TRUE if the pad could handle the event
197 typedef gboolean (*GstCollectPads2EventFunction) (GstCollectPads2 *pads, GstCollectData2 * pad,
198 GstEvent * event, gpointer user_data);
201 * GST_COLLECT_PADS2_GET_STREAM_LOCK:
202 * @pads: a #GstCollectPads2
204 * Get the stream lock of @pads. The stream lock is used to coordinate and
205 * serialize execution among the various streams being collected, and in
206 * protecting the resources used to accomplish this.
208 #define GST_COLLECT_PADS2_GET_STREAM_LOCK(pads) (&((GstCollectPads2 *)pads)->stream_lock)
210 * GST_COLLECT_PADS2_STREAM_LOCK:
211 * @pads: a #GstCollectPads2
213 * Lock the stream lock of @pads.
215 #define GST_COLLECT_PADS2_STREAM_LOCK(pads) (g_static_rec_mutex_lock(GST_COLLECT_PADS2_GET_STREAM_LOCK (pads)))
217 * GST_COLLECT_PADS2_STREAM_UNLOCK:
218 * @pads: a #GstCollectPads2
220 * Unlock the stream lock of @pads.
222 #define GST_COLLECT_PADS2_STREAM_UNLOCK(pads) (g_static_rec_mutex_unlock(GST_COLLECT_PADS2_GET_STREAM_LOCK (pads)))
226 * @data: #GList of #GstCollectData2 managed by this #GstCollectPads2.
228 * Collectpads object.
230 struct _GstCollectPads2 {
233 /*< public >*/ /* with LOCK and/or STREAM_LOCK */
234 GSList *data; /* list of CollectData items */
237 GStaticRecMutex stream_lock; /* used to serialize collection among several streams */
238 /* with LOCK and/or STREAM_LOCK*/
241 /* with STREAM_LOCK */
242 guint32 cookie; /* @data list cookie */
243 guint numpads; /* number of pads in @data */
244 guint queuedpads; /* number of pads with a buffer */
245 guint eospads; /* number of pads that are EOS */
246 GstClockTime earliest_time; /* Current earliest time */
247 GstCollectData2 *earliest_data; /* Pad data for current earliest time */
250 GSList *pad_list; /* updated pad list */
251 guint32 pad_cookie; /* updated cookie */
253 GstCollectPads2Function func; /* function and user_data for callback */
255 GstCollectPads2BufferFunction prepare_buffer_func; /* function and user_data for prepare buffer callback */
256 gpointer prepare_buffer_user_data;
257 GstCollectPads2BufferFunction buffer_func; /* function and user_data for buffer callback */
258 gpointer buffer_user_data;
259 GstCollectPads2CompareFunction compare_func;
260 gpointer compare_user_data;
261 GstCollectPads2EventFunction event_func; /* function and data for event callback */
262 gpointer event_user_data;
264 /* no other lock needed */
265 GMutex *evt_lock; /* these make up sort of poor man's event signaling */
269 gpointer _gst_reserved[GST_PADDING + 0];
273 struct _GstCollectPads2Class {
274 GstObjectClass parent_class;
277 gpointer _gst_reserved[GST_PADDING];
280 GType gst_collect_pads2_get_type(void);
282 /* creating the object */
283 GstCollectPads2* gst_collect_pads2_new (void);
285 /* set the callbacks */
286 void gst_collect_pads2_set_function (GstCollectPads2 *pads, GstCollectPads2Function func,
288 void gst_collect_pads2_set_prepare_buffer_function (GstCollectPads2 *pads,
289 GstCollectPads2BufferFunction func, gpointer user_data);
290 void gst_collect_pads2_set_buffer_function (GstCollectPads2 *pads,
291 GstCollectPads2BufferFunction func, gpointer user_data);
292 void gst_collect_pads2_set_event_function (GstCollectPads2 *pads,
293 GstCollectPads2EventFunction func, gpointer user_data);
294 void gst_collect_pads2_set_compare_function (GstCollectPads2 *pads,
295 GstCollectPads2CompareFunction func, gpointer user_data);
298 GstCollectData2* gst_collect_pads2_add_pad (GstCollectPads2 *pads, GstPad *pad, guint size);
299 GstCollectData2* gst_collect_pads2_add_pad_full (GstCollectPads2 *pads, GstPad *pad, guint size, GstCollectData2DestroyNotify destroy_notify,
301 gboolean gst_collect_pads2_remove_pad (GstCollectPads2 *pads, GstPad *pad);
302 gboolean gst_collect_pads2_is_active (GstCollectPads2 *pads, GstPad *pad);
303 void gst_mux_pads_set_locked (GstCollectPads2 *pads, GstCollectData2 *data,
306 /* start/stop collection */
307 GstFlowReturn gst_collect_pads2_collect (GstCollectPads2 *pads);
308 GstFlowReturn gst_collect_pads2_collect_range (GstCollectPads2 *pads, guint64 offset, guint length);
310 void gst_collect_pads2_start (GstCollectPads2 *pads);
311 void gst_collect_pads2_stop (GstCollectPads2 *pads);
312 void gst_collect_pads2_set_flushing (GstCollectPads2 *pads, gboolean flushing);
314 /* get collected buffers */
315 GstBuffer* gst_collect_pads2_peek (GstCollectPads2 *pads, GstCollectData2 *data);
316 GstBuffer* gst_collect_pads2_pop (GstCollectPads2 *pads, GstCollectData2 *data);
318 /* get collected bytes */
319 guint gst_collect_pads2_available (GstCollectPads2 *pads);
320 guint gst_collect_pads2_read (GstCollectPads2 *pads, GstCollectData2 *data,
321 guint8 **bytes, guint size);
322 guint gst_collect_pads2_flush (GstCollectPads2 *pads, GstCollectData2 *data,
324 GstBuffer* gst_collect_pads2_read_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
326 GstBuffer* gst_collect_pads2_take_buffer (GstCollectPads2 * pads, GstCollectData2 * data,
329 /* setting and unsetting waiting mode */
330 void gst_collect_pads2_set_waiting (GstCollectPads2 *pads, GstCollectData2 *data,
336 #endif /* __GST_COLLECT_PADS22_H__ */