upload tizen1.0 source
[framework/multimedia/gst-plugins-good0.10.git] / gst / videomixer / gstcollectpads2.h
1 /* GStreamer
2  * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
3  * Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sourceforge.net>
4  *
5  * gstcollectpads2.h:
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifndef __GST_COLLECT_PADS2_H__
24 #define __GST_COLLECT_PADS2_H__
25
26 #include <gst/gst.h>
27
28 G_BEGIN_DECLS
29
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))
36
37 typedef struct _GstCollectData2 GstCollectData2;
38 typedef struct _GstCollectPads2 GstCollectPads2;
39 typedef struct _GstCollectPads2Class GstCollectPads2Class;
40
41 /**
42  * GstCollectData2DestroyNotify:
43  * @data: the #GstCollectData2 that will be freed
44  *
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.
48  *
49  * Since: 0.10.12
50  */
51 typedef void (*GstCollectData2DestroyNotify) (GstCollectData2 *data);
52
53 /**
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
58  *                                      new_segment event.
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
62  *                                      not be changed.
63  * #GstCollectPads2StateFlags indicate private state of a collectdata('s pad).
64  */
65 typedef enum {
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;
72
73 /**
74  * GST_COLLECT_PADS2_STATE:
75  * @data: a #GstCollectData2.
76  *
77  * A flags word containing #GstCollectPads2StateFlags flags set
78  * on this collected pad.
79  */
80 #define GST_COLLECT_PADS2_STATE(data)                 (((GstCollectData2 *) data)->state)
81 /**
82  * GST_COLLECT_PADS2_STATE_IS_SET:
83  * @data: a #GstCollectData2.
84  * @flag: the #GstCollectPads2StateFlags to check.
85  *
86  * Gives the status of a specific flag on a collected pad.
87  */
88 #define GST_COLLECT_PADS2_STATE_IS_SET(data,flag)     !!(GST_COLLECT_PADS2_STATE (data) & flag)
89 /**
90  * GST_COLLECT_PADS2_STATE_SET:
91  * @data: a #GstCollectData2.
92  * @flag: the #GstCollectPads2StateFlags to set.
93  *
94  * Sets a state flag on a collected pad.
95  */
96 #define GST_COLLECT_PADS2_STATE_SET(data,flag)        (GST_COLLECT_PADS2_STATE (data) |= flag)
97 /**
98  * GST_COLLECT_PADS2_STATE_UNSET:
99  * @data: a #GstCollectData2.
100  * @flag: the #GstCollectPads2StateFlags to clear.
101  *
102  * Clears a state flag on a collected pad.
103  */
104 #define GST_COLLECT_PADS2_STATE_UNSET(data,flag)      (GST_COLLECT_PADS2_STATE (data) &= ~(flag))
105
106 #define GST_COLLECT_PADS2_FLOW_DROP GST_FLOW_CUSTOM_SUCCESS
107
108 /**
109  * GstCollectData2:
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.
115  *
116  * Structure used by the collect_pads2.
117  */
118 struct _GstCollectData2
119 {
120   /* with STREAM_LOCK of @collect */
121   GstCollectPads2       *collect;
122   GstPad                *pad;
123   GstBuffer             *buffer;
124   guint                  pos;
125   GstSegment             segment;
126
127   /*< private >*/
128   /* state: bitfield for easier extension;
129    * eos, flushing, new_segment, waiting */
130   guint                  state;
131
132   /* refcounting for struct, and destroy callback */
133   GstCollectData2DestroyNotify destroy_notify;
134   gint                   refcount;
135
136   gpointer _gst_reserved[GST_PADDING];
137 };
138
139 /**
140  * GstCollectPads2Function:
141  * @pads: the #GstCollectPads2 that trigered the callback
142  * @user_data: user data passed to gst_collect_pads2_set_function()
143  *
144  * A function that will be called when all pads have received data.
145  *
146  * Returns: #GST_FLOW_OK for success
147  */
148 typedef GstFlowReturn (*GstCollectPads2Function) (GstCollectPads2 *pads, gpointer user_data);
149
150 /**
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()
156  *
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
159  * and NULL @data.
160  *
161  * Returns: #GST_FLOW_OK for success
162  */
163 typedef GstFlowReturn (*GstCollectPads2BufferFunction) (GstCollectPads2 *pads, GstCollectData2 *data,
164                                                         GstBuffer *buffer, gpointer user_data);
165
166 /**
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()
174  *
175  * A function for comparing two timestamps of buffers or newsegments collected on one pad.
176  *
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.
180  */
181 typedef gint (*GstCollectPads2CompareFunction) (GstCollectPads2 *pads,
182                                                 GstCollectData2 * data1, GstClockTime timestamp1,
183                                                 GstCollectData2 * data2, GstClockTime timestamp2,
184                                                 gpointer user_data);
185
186 /**
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()
192  *
193  * A function that will be called after collectpads has processed the event.
194  *
195  * Returns: %TRUE if the pad could handle the event
196  */
197 typedef gboolean (*GstCollectPads2EventFunction)        (GstCollectPads2 *pads, GstCollectData2 * pad,
198                                                          GstEvent * event, gpointer user_data);
199
200 /**
201  * GST_COLLECT_PADS2_GET_STREAM_LOCK:
202  * @pads: a #GstCollectPads2
203  *
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.
207  */
208 #define GST_COLLECT_PADS2_GET_STREAM_LOCK(pads) (&((GstCollectPads2 *)pads)->stream_lock)
209 /**
210  * GST_COLLECT_PADS2_STREAM_LOCK:
211  * @pads: a #GstCollectPads2
212  *
213  * Lock the stream lock of @pads.
214  */
215 #define GST_COLLECT_PADS2_STREAM_LOCK(pads)     (g_static_rec_mutex_lock(GST_COLLECT_PADS2_GET_STREAM_LOCK (pads)))
216 /**
217  * GST_COLLECT_PADS2_STREAM_UNLOCK:
218  * @pads: a #GstCollectPads2
219  *
220  * Unlock the stream lock of @pads.
221  */
222 #define GST_COLLECT_PADS2_STREAM_UNLOCK(pads)   (g_static_rec_mutex_unlock(GST_COLLECT_PADS2_GET_STREAM_LOCK (pads)))
223
224 /**
225  * GstCollectPads2:
226  * @data: #GList of #GstCollectData2 managed by this #GstCollectPads2.
227  *
228  * Collectpads object.
229  */
230 struct _GstCollectPads2 {
231   GstObject      object;
232
233   /*< public >*/ /* with LOCK and/or STREAM_LOCK */
234   GSList        *data;                  /* list of CollectData items */
235
236   /*< private >*/
237   GStaticRecMutex stream_lock;          /* used to serialize collection among several streams */
238   /* with LOCK and/or STREAM_LOCK*/
239   gboolean       started;
240
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 */
248
249   /* with LOCK */
250   GSList        *pad_list;              /* updated pad list */
251   guint32        pad_cookie;            /* updated cookie */
252
253   GstCollectPads2Function func;         /* function and user_data for callback */
254   gpointer       user_data;
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;
263
264   /* no other lock needed */
265   GMutex        *evt_lock;              /* these make up sort of poor man's event signaling */
266   GCond         *evt_cond;
267   guint32        evt_cookie;
268
269   gpointer _gst_reserved[GST_PADDING + 0];
270
271 };
272
273 struct _GstCollectPads2Class {
274   GstObjectClass parent_class;
275
276   /*< private >*/
277   gpointer _gst_reserved[GST_PADDING];
278 };
279
280 GType gst_collect_pads2_get_type(void);
281
282 /* creating the object */
283 GstCollectPads2*        gst_collect_pads2_new           (void);
284
285 /* set the callbacks */
286 void            gst_collect_pads2_set_function  (GstCollectPads2 *pads, GstCollectPads2Function func,
287                                                  gpointer user_data);
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);
296
297 /* pad management */
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,
300                                                  gboolean lock);
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,
304                                                  gboolean locked);
305
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);
309
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);
313
314 /* get collected buffers */
315 GstBuffer*      gst_collect_pads2_peek          (GstCollectPads2 *pads, GstCollectData2 *data);
316 GstBuffer*      gst_collect_pads2_pop           (GstCollectPads2 *pads, GstCollectData2 *data);
317
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,
323                                                  guint size);
324 GstBuffer*      gst_collect_pads2_read_buffer   (GstCollectPads2 * pads, GstCollectData2 * data,
325                                                  guint size);
326 GstBuffer*      gst_collect_pads2_take_buffer   (GstCollectPads2 * pads, GstCollectData2 * data,
327                                                  guint size);
328
329 /* setting and unsetting waiting mode */
330 void            gst_collect_pads2_set_waiting   (GstCollectPads2 *pads, GstCollectData2 *data,
331                                                  gboolean waiting);
332
333
334 G_END_DECLS
335
336 #endif /* __GST_COLLECT_PADS22_H__ */