1 /* GStreamer
2 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
3 *
4 * gstcollect_pads.h:
5 *
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.
10 *
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.
15 *
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.
20 */
22 #ifndef __GST_COLLECT_PADS_H__
23 #define __GST_COLLECT_PADS_H__
25 #include <gst/gst.h>
27 G_BEGIN_DECLS
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;
41 /**
42 * GstCollectDataDestroyNotify:
43 * @data: the #GstCollectData that will be freed
44 *
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.
48 *
49 * Since: 0.10.12
50 */
51 typedef void (*GstCollectDataDestroyNotify) (GstCollectData *data);
53 /**
54 * GstCollectPadsClipFunction:
55 * @pads: a #GstCollectPads
56 * @data: a #GstCollectData
57 * @buffer: a #GstBuffer
58 * @user_data: user data
59 *
60 * A function that will be called when @buffer is received on the pad managed
61 * by @data in the collecpad object @pads.
62 *
63 * The function should use the segment of @data and the negotiated media type on
64 * the pad to perform clipping of @buffer.
65 *
66 * This function takes ownership of @buffer.
67 *
68 * Returns: a #GstBuffer that contains the clipped data of @buffer or NULL when
69 * the buffer has been clipped completely.
70 *
71 * Since: 0.10.26
72 */
73 typedef GstBuffer * (*GstCollectPadsClipFunction) (GstCollectPads *pads, GstCollectData *data,
74 GstBuffer *buffer, gpointer user_data);
76 /**
77 * GstCollectData:
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.
83 *
84 * Structure used by the collect_pads.
85 */
86 struct _GstCollectData
87 {
88 /* with LOCK of @collect */
89 GstCollectPads *collect;
90 GstPad *pad;
91 GstBuffer *buffer;
92 guint pos;
93 GstSegment segment;
95 /*< private >*/
96 union {
97 struct {
98 gboolean flushing;
99 gboolean new_segment;
100 gboolean eos;
101 gint refcount;
102 } ABI;
103 /* adding + 0 to mark ABI change to be undone later */
104 gpointer _gst_reserved[GST_PADDING + 0];
105 } abidata;
106 };
108 /**
109 * GstCollectPadsFunction:
110 * @pads: the #GstCollectPads that triggered the callback
111 * @user_data: user data passed to gst_collect_pads_set_function()
112 *
113 * A function that will be called when all pads have received data.
114 *
115 * Returns: #GST_FLOW_OK for success
116 */
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)))
128 /**
129 * GstCollectPads:
130 * @data: #GList of #GstCollectData managed by this #GstCollectPads.
131 *
132 * Collectpads object.
133 * Note that @data is only reliable for iterating the list of #GstCollectData
134 * when inside the #GstCollectPadsFunction callback.
135 */
136 struct _GstCollectPads {
137 GstObject object;
139 /*< public >*/ /* with LOCK */
140 GSList *data; /* list of CollectData items */
142 /*< private >*/
143 guint32 cookie; /* @data list cookie */
145 /* with LOCK */
146 GCond *cond; /* to signal removal of data */
148 GstCollectPadsFunction func; /* function and user_data for callback */
149 gpointer user_data;
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*/
156 gboolean started;
158 /*< private >*/
159 union {
160 struct {
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;
166 } ABI;
167 /* adding + 0 to mark ABI change to be undone later */
168 gpointer _gst_reserved[GST_PADDING + 0];
169 } abidata;
170 };
172 struct _GstCollectPadsClass {
173 GstObjectClass parent_class;
175 /*< private >*/
176 gpointer _gst_reserved[GST_PADDING];
177 };
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,
186 gpointer user_data);
187 void gst_collect_pads_set_clip_function (GstCollectPads *pads, GstCollectPadsClipFunction clipfunc,
188 gpointer user_data);
190 /* pad management */
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 guint gst_collect_pads_read (GstCollectPads *pads, GstCollectData *data,
213 guint8 **bytes, guint size);
214 GstBuffer * gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data,
215 guint size);
216 GstBuffer * gst_collect_pads_take_buffer (GstCollectPads * pads, GstCollectData * data,
217 guint size);
218 guint gst_collect_pads_flush (GstCollectPads *pads, GstCollectData *data,
219 guint size);
221 G_END_DECLS
223 #endif /* __GST_COLLECT_PADS_H__ */