Merge remote-tracking branch 'origin/master' into 0.11
[platform/upstream/gstreamer.git] / libs / gst / base / gstcollectpads.h
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  */
21
22 #ifndef __GST_COLLECT_PADS_H__
23 #define __GST_COLLECT_PADS_H__
24
25 #include <gst/gst.h>
26
27 G_BEGIN_DECLS
28
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))
35
36 typedef struct _GstCollectData GstCollectData;
37 typedef struct _GstCollectPads GstCollectPads;
38 typedef struct _GstCollectPadsPrivate GstCollectPadsPrivate;
39 typedef struct _GstCollectPadsClass GstCollectPadsClass;
40
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);
52
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);
75
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;
94
95   gboolean               flushing;
96   gboolean               new_segment;
97   gboolean               eos;
98   gint                   refcount;
99  
100   GstCollectDataDestroyNotify destroy_notify;
101
102   /*< private >*/
103   union {
104     /*struct {
105     } ABI;*/
106     /* adding + 0 to mark ABI change to be undone later */
107     gpointer _gst_reserved[GST_PADDING];
108   } abidata;
109 };
110
111 /**
112  * GstCollectPadsFunction:
113  * @pads: the #GstCollectPads that triggered the callback
114  * @user_data: user data passed to gst_collect_pads_set_function()
115  *
116  * A function that will be called when all pads have received data.
117  *
118  * Returns: #GST_FLOW_OK for success
119  */
120 typedef GstFlowReturn (*GstCollectPadsFunction) (GstCollectPads *pads, gpointer user_data);
121
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)))
125
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)))
130
131 /**
132  * GstCollectPads:
133  * @data: #GList of #GstCollectData managed by this #GstCollectPads.
134  *
135  * Collectpads object.
136  * Note that @data is only reliable for iterating the list of #GstCollectData
137  * when inside the #GstCollectPadsFunction callback.
138  */
139 struct _GstCollectPads {
140   GstObject      object;
141
142   /*< public >*/ /* with LOCK */
143   GSList        *data;                  /* list of CollectData items */
144
145   /*< private >*/
146   guint32        cookie;                /* @data list cookie */
147
148   /* with LOCK */
149   GCond         *cond;                  /* to signal removal of data */
150
151   GstCollectPadsFunction func;          /* function and user_data for callback */
152   gpointer       user_data;
153
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 */
157
158   /* with LOCK and PAD_LOCK*/
159   gboolean       started;
160
161   /* 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
167   /*< private >*/
168   union {
169     /*struct {
170     } ABI;*/
171     /* adding + 0 to mark ABI change to be undone later */
172     gpointer _gst_reserved[GST_PADDING];
173   } abidata;
174 };
175
176 struct _GstCollectPadsClass {
177   GstObjectClass parent_class;
178
179   /*< private >*/
180   gpointer _gst_reserved[GST_PADDING];
181 };
182
183 GType gst_collect_pads_get_type(void);
184
185 /* creating the object */
186 GstCollectPads* gst_collect_pads_new            (void);
187
188 /* set the callbacks */
189 void            gst_collect_pads_set_function      (GstCollectPads *pads, GstCollectPadsFunction func,
190                                                     gpointer user_data);
191 void            gst_collect_pads_set_clip_function (GstCollectPads *pads, GstCollectPadsClipFunction clipfunc,
192                                                     gpointer user_data);
193
194 /* pad management */
195 GstCollectData* gst_collect_pads_add_pad        (GstCollectPads *pads, GstPad *pad, guint size, GstCollectDataDestroyNotify destroy_notify);
196
197
198 gboolean        gst_collect_pads_remove_pad     (GstCollectPads *pads, GstPad *pad);
199 gboolean        gst_collect_pads_is_active      (GstCollectPads *pads, GstPad *pad);
200
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);
204
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);
208
209 /* get collected buffers */
210 GstBuffer*      gst_collect_pads_peek           (GstCollectPads *pads, GstCollectData *data);
211 GstBuffer*      gst_collect_pads_pop            (GstCollectPads *pads, GstCollectData *data);
212
213 /* get collected bytes */
214 guint           gst_collect_pads_available      (GstCollectPads *pads);
215 GstBuffer *     gst_collect_pads_read_buffer    (GstCollectPads * pads, GstCollectData * data,
216                                                  guint size);
217 GstBuffer *     gst_collect_pads_take_buffer    (GstCollectPads * pads, GstCollectData * data,
218                                                  guint size);
219 guint           gst_collect_pads_flush          (GstCollectPads *pads, GstCollectData *data,
220                                                  guint size);
221
222 G_END_DECLS
223
224 #endif /* __GST_COLLECT_PADS_H__ */