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;
100 GstCollectDataDestroyNotify destroy_notify;
106 /* adding + 0 to mark ABI change to be undone later */
107 gpointer _gst_reserved[GST_PADDING];
112 * GstCollectPadsFunction:
113 * @pads: the #GstCollectPads that triggered the callback
114 * @user_data: user data passed to gst_collect_pads_set_function()
116 * A function that will be called when all pads have received data.
118 * Returns: #GST_FLOW_OK for success
120 typedef GstFlowReturn (*GstCollectPadsFunction) (GstCollectPads *pads, gpointer user_data);
122 #define GST_COLLECT_PADS_GET_PAD_LOCK(pads) (((GstCollectPads *)pads)->pad_lock)
123 #define GST_COLLECT_PADS_PAD_LOCK(pads) (g_mutex_lock(GST_COLLECT_PADS_GET_PAD_LOCK (pads)))
124 #define GST_COLLECT_PADS_PAD_UNLOCK(pads) (g_mutex_unlock(GST_COLLECT_PADS_GET_PAD_LOCK (pads)))
126 #define GST_COLLECT_PADS_GET_COND(pads) (((GstCollectPads *)pads)->cond)
127 #define GST_COLLECT_PADS_WAIT(pads) (g_cond_wait (GST_COLLECT_PADS_GET_COND (pads), GST_OBJECT_GET_LOCK (pads)))
128 #define GST_COLLECT_PADS_SIGNAL(pads) (g_cond_signal (GST_COLLECT_PADS_GET_COND (pads)))
129 #define GST_COLLECT_PADS_BROADCAST(pads)(g_cond_broadcast (GST_COLLECT_PADS_GET_COND (pads)))
133 * @data: #GList of #GstCollectData managed by this #GstCollectPads.
135 * Collectpads object.
136 * Note that @data is only reliable for iterating the list of #GstCollectData
137 * when inside the #GstCollectPadsFunction callback.
139 struct _GstCollectPads {
142 /*< public >*/ /* with LOCK */
143 GSList *data; /* list of CollectData items */
146 guint32 cookie; /* @data list cookie */
149 GCond *cond; /* to signal removal of data */
151 GstCollectPadsFunction func; /* function and user_data for callback */
154 guint numpads; /* number of pads in @data */
155 guint queuedpads; /* number of pads with a buffer */
156 guint eospads; /* number of pads that are EOS */
158 /* with LOCK and 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;
171 /* adding + 0 to mark ABI change to be undone later */
172 gpointer _gst_reserved[GST_PADDING];
176 struct _GstCollectPadsClass {
177 GstObjectClass parent_class;
180 gpointer _gst_reserved[GST_PADDING];
183 GType gst_collect_pads_get_type(void);
185 /* creating the object */
186 GstCollectPads* gst_collect_pads_new (void);
188 /* set the callbacks */
189 void gst_collect_pads_set_function (GstCollectPads *pads, GstCollectPadsFunction func,
191 void gst_collect_pads_set_clip_function (GstCollectPads *pads, GstCollectPadsClipFunction clipfunc,
195 GstCollectData* gst_collect_pads_add_pad (GstCollectPads *pads, GstPad *pad, guint size, GstCollectDataDestroyNotify destroy_notify);
198 gboolean gst_collect_pads_remove_pad (GstCollectPads *pads, GstPad *pad);
199 gboolean gst_collect_pads_is_active (GstCollectPads *pads, GstPad *pad);
201 /* start/stop collection */
202 GstFlowReturn gst_collect_pads_collect (GstCollectPads *pads);
203 GstFlowReturn gst_collect_pads_collect_range (GstCollectPads *pads, guint64 offset, guint length);
205 void gst_collect_pads_start (GstCollectPads *pads);
206 void gst_collect_pads_stop (GstCollectPads *pads);
207 void gst_collect_pads_set_flushing (GstCollectPads *pads, gboolean flushing);
209 /* get collected buffers */
210 GstBuffer* gst_collect_pads_peek (GstCollectPads *pads, GstCollectData *data);
211 GstBuffer* gst_collect_pads_pop (GstCollectPads *pads, GstCollectData *data);
213 /* get collected bytes */
214 guint gst_collect_pads_available (GstCollectPads *pads);
215 GstBuffer * gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data,
217 GstBuffer * gst_collect_pads_take_buffer (GstCollectPads * pads, GstCollectData * data,
219 guint gst_collect_pads_flush (GstCollectPads *pads, GstCollectData *data,
224 #endif /* __GST_COLLECT_PADS_H__ */