2 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #ifndef __GST_COLLECT_PADS_H__
23 #define __GST_COLLECT_PADS_H__
29 #define GST_TYPE_COLLECT_PADS (gst_collect_pads_get_type())
30 #define GST_COLLECT_PADS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_COLLECT_PADS,GstCollectPads))
31 #define GST_COLLECT_PADS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_COLLECT_PADS,GstCollectPadsClass))
32 #define GST_COLLECT_PADS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_COLLECT_PADS,GstCollectPadsClass))
33 #define GST_IS_COLLECT_PADS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_COLLECT_PADS))
34 #define GST_IS_COLLECT_PADS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_COLLECT_PADS))
36 typedef struct _GstCollectData GstCollectData;
37 typedef struct _GstCollectPads GstCollectPads;
38 typedef struct _GstCollectPadsPrivate GstCollectPadsPrivate;
39 typedef struct _GstCollectPadsClass GstCollectPadsClass;
42 * GstCollectDataDestroyNotify:
43 * @data: the #GstCollectData that will be freed
45 * A function that will be called when the #GstCollectData 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 (*GstCollectDataDestroyNotify) (GstCollectData *data);
54 * GstCollectPadsClipFunction:
55 * @pads: a #GstCollectPads
56 * @data: a #GstCollectData
57 * @buffer: a #GstBuffer
58 * @user_data: user data
60 * A function that will be called when @buffer is received on the pad managed
61 * by @data in the collecpad object @pads.
63 * The function should use the segment of @data and the negotiated media type on
64 * the pad to perform clipping of @buffer.
66 * This function takes ownership of @buffer.
68 * Returns: a #GstBuffer that contains the clipped data of @buffer or NULL when
69 * the buffer has been clipped completely.
73 typedef GstBuffer * (*GstCollectPadsClipFunction) (GstCollectPads *pads, GstCollectData *data,
74 GstBuffer *buffer, gpointer user_data);
78 * @collect: owner #GstCollectPads
79 * @pad: #GstPad managed by this data
80 * @buffer: currently queued buffer.
81 * @pos: position in the buffer
82 * @segment: last segment received.
84 * Structure used by the collect_pads.
86 struct _GstCollectData
88 /* with LOCK of @collect */
89 GstCollectPads *collect;
103 /* adding + 0 to mark ABI change to be undone later */
104 gpointer _gst_reserved[GST_PADDING + 0];
109 * GstCollectPadsFunction:
110 * @pads: the #GstCollectPads that triggered the callback
111 * @user_data: user data passed to gst_collect_pads_set_function()
113 * A function that will be called when all pads have received data.
115 * Returns: #GST_FLOW_OK for success
117 typedef GstFlowReturn (*GstCollectPadsFunction) (GstCollectPads *pads, gpointer user_data);
119 #define GST_COLLECT_PADS_GET_PAD_LOCK(pads) (((GstCollectPads *)pads)->abidata.ABI.pad_lock)
120 #define GST_COLLECT_PADS_PAD_LOCK(pads) (g_mutex_lock(GST_COLLECT_PADS_GET_PAD_LOCK (pads)))
121 #define GST_COLLECT_PADS_PAD_UNLOCK(pads) (g_mutex_unlock(GST_COLLECT_PADS_GET_PAD_LOCK (pads)))
123 #define GST_COLLECT_PADS_GET_COND(pads) (((GstCollectPads *)pads)->cond)
124 #define GST_COLLECT_PADS_WAIT(pads) (g_cond_wait (GST_COLLECT_PADS_GET_COND (pads), GST_OBJECT_GET_LOCK (pads)))
125 #define GST_COLLECT_PADS_SIGNAL(pads) (g_cond_signal (GST_COLLECT_PADS_GET_COND (pads)))
126 #define GST_COLLECT_PADS_BROADCAST(pads)(g_cond_broadcast (GST_COLLECT_PADS_GET_COND (pads)))
130 * @data: #GList of #GstCollectData managed by this #GstCollectPads.
132 * Collectpads object.
133 * Note that @data is only reliable for iterating the list of #GstCollectData
134 * when inside the #GstCollectPadsFunction callback.
136 struct _GstCollectPads {
139 /*< public >*/ /* with LOCK */
140 GSList *data; /* list of CollectData items */
143 guint32 cookie; /* @data list cookie */
146 GCond *cond; /* to signal removal of data */
148 GstCollectPadsFunction func; /* function and user_data for callback */
151 guint numpads; /* number of pads in @data */
152 guint queuedpads; /* number of pads with a buffer */
153 guint eospads; /* number of pads that are EOS */
155 /* with LOCK and PAD_LOCK*/
161 /* since 0.10.6 */ /* with PAD_LOCK */
162 GMutex *pad_lock; /* used to serialize add/remove */
163 GSList *pad_list; /* updated pad list */
164 guint32 pad_cookie; /* updated cookie */
165 GstCollectPadsPrivate *priv;
167 /* adding + 0 to mark ABI change to be undone later */
168 gpointer _gst_reserved[GST_PADDING + 0];
172 struct _GstCollectPadsClass {
173 GstObjectClass parent_class;
176 gpointer _gst_reserved[GST_PADDING];
179 GType gst_collect_pads_get_type(void);
181 /* creating the object */
182 GstCollectPads* gst_collect_pads_new (void);
184 /* set the callbacks */
185 void gst_collect_pads_set_function (GstCollectPads *pads, GstCollectPadsFunction func,
187 void gst_collect_pads_set_clip_function (GstCollectPads *pads, GstCollectPadsClipFunction clipfunc,
191 GstCollectData* gst_collect_pads_add_pad (GstCollectPads *pads, GstPad *pad, guint size);
192 GstCollectData* gst_collect_pads_add_pad_full (GstCollectPads *pads, GstPad *pad, guint size, GstCollectDataDestroyNotify destroy_notify);
195 gboolean gst_collect_pads_remove_pad (GstCollectPads *pads, GstPad *pad);
196 gboolean gst_collect_pads_is_active (GstCollectPads *pads, GstPad *pad);
198 /* start/stop collection */
199 GstFlowReturn gst_collect_pads_collect (GstCollectPads *pads);
200 GstFlowReturn gst_collect_pads_collect_range (GstCollectPads *pads, guint64 offset, guint length);
202 void gst_collect_pads_start (GstCollectPads *pads);
203 void gst_collect_pads_stop (GstCollectPads *pads);
204 void gst_collect_pads_set_flushing (GstCollectPads *pads, gboolean flushing);
206 /* get collected buffers */
207 GstBuffer* gst_collect_pads_peek (GstCollectPads *pads, GstCollectData *data);
208 GstBuffer* gst_collect_pads_pop (GstCollectPads *pads, GstCollectData *data);
210 /* get collected bytes */
211 guint gst_collect_pads_available (GstCollectPads *pads);
212 GstBuffer * gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data,
214 GstBuffer * gst_collect_pads_take_buffer (GstCollectPads * pads, GstCollectData * data,
216 guint gst_collect_pads_flush (GstCollectPads *pads, GstCollectData *data,
221 #endif /* __GST_COLLECT_PADS_H__ */