gst/gstpad.c: Some small cleanups. Improve debugging.
[platform/upstream/gstreamer.git] / gst / gstpad.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *
5  * gstpad.h: Header for GstPad object
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
24 #ifndef __GST_PAD_H__
25 #define __GST_PAD_H__
26
27 #include <gst/gstconfig.h>
28
29 #include <gst/gstobject.h>
30 #include <gst/gstbuffer.h>
31 #include <gst/gstcaps.h>
32 #include <gst/gstevent.h>
33 #include <gst/gstquery.h>
34 #include <gst/gsttask.h>
35
36 G_BEGIN_DECLS
37
38 /*
39  * Pad base class
40  */
41 #define GST_TYPE_PAD                    (gst_pad_get_type ())
42 #define GST_IS_PAD(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD))
43 #define GST_IS_PAD_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD))
44 #define GST_PAD(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD, GstPad))
45 #define GST_PAD_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD, GstPadClass))
46 #define GST_PAD_CAST(obj)               ((GstPad*)(obj))
47
48
49 typedef struct _GstPad GstPad;
50 typedef struct _GstPadClass GstPadClass;
51
52 /**
53  * GstPadLinkReturn:
54  * @GST_PAD_LINK_OK             : link succeeded
55  * @GST_PAD_LINK_WRONG_HIERARCHY: pads have no common grandparent
56  * @GST_PAD_LINK_WAS_LINKED     : pad was already linked
57  * @GST_PAD_LINK_WRONG_DIRECTION: pads have wrong direction
58  * @GST_PAD_LINK_NOFORMAT       : pads do not have common format
59  * @GST_PAD_LINK_NOSCHED        : pads cannot cooperate in scheduling
60  * @GST_PAD_LINK_REFUSED        : refused for some reason
61  *
62  * Result values from gst_pad_link and friends.
63  */
64 typedef enum {
65   GST_PAD_LINK_OK               =  0,
66   GST_PAD_LINK_WRONG_HIERARCHY  = -1,
67   GST_PAD_LINK_WAS_LINKED       = -2,
68   GST_PAD_LINK_WRONG_DIRECTION  = -3,
69   GST_PAD_LINK_NOFORMAT         = -4,
70   GST_PAD_LINK_NOSCHED          = -5,
71   GST_PAD_LINK_REFUSED          = -6
72 } GstPadLinkReturn;
73
74 /**
75  * GST_PAD_LINK_FAILED:
76  * @ret: the #GstPadLinkReturn value
77  *
78  * Macro to test if the given #GstPadLinkReturn value indicates a failed
79  * link step.
80  */
81 #define GST_PAD_LINK_FAILED(ret) ((ret) < GST_PAD_LINK_OK)
82
83 /**
84  * GST_PAD_LINK_SUCCESSFUL:
85  * @ret: the #GstPadLinkReturn value
86  *
87  * Macro to test if the given #GstPadLinkReturn value indicates a successful
88  * link step.
89  */
90 #define GST_PAD_LINK_SUCCESSFUL(ret) ((ret) >= GST_PAD_LINK_OK)
91
92 /**
93  * GstFlowReturn:
94  * @GST_FLOW_CUSTOM_SUCCESS:     Elements can use values starting from
95  *                               this to define custom success codes. 
96  *                               Since 0.10.7.
97  * @GST_FLOW_RESEND:             Resend buffer, possibly with new caps.
98  * @GST_FLOW_OK:                 Data passing was ok.
99  * @GST_FLOW_NOT_LINKED:         Pad is not linked.
100  * @GST_FLOW_WRONG_STATE:        Pad is in wrong state.
101  * @GST_FLOW_UNEXPECTED:         Did not expect anything, like after EOS.
102  * @GST_FLOW_NOT_NEGOTIATED:     Pad is not negotiated.
103  * @GST_FLOW_ERROR:              Some (fatal) error occured. Element generating
104  *                               this error should post an error message with more
105  *                               details.
106  * @GST_FLOW_NOT_SUPPORTED:      This operation is not supported.
107  * @GST_FLOW_CUSTOM_ERROR:       Elements can use values starting from
108  *                               this to define custom error codes. Since 0.10.7.
109  *
110  * The result of passing data to a pad. 
111  *
112  * Note that the custom return values should not be exposed outside of the 
113  * element scope and are available since 0.10.7.
114  */
115 typedef enum {
116   /* custom success starts here */ 
117   GST_FLOW_CUSTOM_SUCCESS = 100,
118
119   /* core predefined */ 
120   GST_FLOW_RESEND         =  1,
121   GST_FLOW_OK             =  0,
122   /* expected failures */
123   GST_FLOW_NOT_LINKED     = -1,
124   GST_FLOW_WRONG_STATE    = -2,
125   /* error cases */
126   GST_FLOW_UNEXPECTED     = -3,
127   GST_FLOW_NOT_NEGOTIATED = -4,
128   GST_FLOW_ERROR          = -5,
129   GST_FLOW_NOT_SUPPORTED  = -6,
130
131   /* custom error starts here */ 
132   GST_FLOW_CUSTOM_ERROR   = -100
133 } GstFlowReturn;
134
135 /**
136  * GST_FLOW_IS_FATAL:
137  * @ret: a #GstFlowReturn value
138  *
139  * Macro to test if the given #GstFlowReturn value indicates a fatal
140  * error. This macro is mainly used in elements to decide when an error
141  * message should be posted on the bus.
142  */
143 #define GST_FLOW_IS_FATAL(ret) ((ret) <= GST_FLOW_UNEXPECTED)
144
145 /**
146  * GST_FLOW_IS_SUCCESS:
147  * @ret: a #GstFlowReturn value
148  *
149  * Macro to test if the given #GstFlowReturn value indicates a 
150  * successfull result
151  * This macro is mainly used in elements to decide if the processing
152  * of a buffer was successfull.
153  *
154  * Since: 0.10.7
155  */
156 #define GST_FLOW_IS_SUCCESS(ret) ((ret) >= GST_FLOW_OK)
157
158 G_CONST_RETURN gchar*   gst_flow_get_name       (GstFlowReturn ret);
159 GQuark                  gst_flow_to_quark       (GstFlowReturn ret);
160
161 /**
162  * GstActivateMode:
163  * @GST_ACTIVATE_NONE:           Pad will not handle dataflow
164  * @GST_ACTIVATE_PUSH:           Pad handles dataflow in downstream push mode
165  * @GST_ACTIVATE_PULL:           Pad handles dataflow in upstream pull mode
166  *
167  * The status of a GstPad. After activating a pad, which usually happens when the
168  * parent element goes from READY to PAUSED, the GstActivateMode defines if the
169  * pad operates in push or pull mode.
170  */
171 typedef enum {
172   GST_ACTIVATE_NONE,
173   GST_ACTIVATE_PUSH,
174   GST_ACTIVATE_PULL
175 } GstActivateMode;
176
177 /**
178  * GST_PAD_MODE_ACTIVATE:
179  * @mode: a #GstActivateMode
180  *
181  * Macro to test if the given #GstActivateMode value indicates that datapassing
182  * is possible or not.
183  */
184 #define GST_PAD_MODE_ACTIVATE(mode) ((mode) != GST_ACTIVATE_NONE)
185
186 /* pad states */
187 /**
188  * GstPadActivateFunction:
189  * @pad: a #GstPad
190  *
191  * This function is called when the pad is activated during the element
192  * READY to PAUSED state change. By default this function will call the
193  * activate function that puts the pad in push mode but elements can
194  * override this function to activate the pad in pull mode if they wish.
195  *
196  * Returns: TRUE if the pad could be activated.
197  */
198 typedef gboolean                (*GstPadActivateFunction)       (GstPad *pad);
199 /**
200  * GstPadActivateModeFunction:
201  * @pad: a #GstPad
202  * @active: activate or deactivate the pad.
203  *
204  * The prototype of the push and pull activate functions. 
205  *
206  * Returns: TRUE if the pad could be activated or deactivated.
207  */
208 typedef gboolean                (*GstPadActivateModeFunction)   (GstPad *pad, gboolean active);
209
210
211 /* data passing */
212 /**
213  * GstPadChainFunction:
214  * @pad: the sink #GstPad that performed the chain.
215  * @buffer: the #GstBuffer that is chained, not %NULL.
216  *
217  * A function that will be called on sinkpads when chaining buffers.
218  * The function typically processes the data contained in the buffer and 
219  * either consumes the data or passes it on to the internally linked pad(s).
220  *
221  * The implementer of this function receives a refcount to @buffer and should
222  * gst_buffer_unref() when the buffer is no longer needed.
223  *
224  * When a chain function detects an error in the data stream, it must post an
225  * error on the buffer and return an appropriate #GstFlowReturn value.
226  *
227  * Returns: #GST_FLOW_OK for success
228  */
229 typedef GstFlowReturn           (*GstPadChainFunction)          (GstPad *pad, GstBuffer *buffer);
230 /**
231  * GstPadGetRangeFunction:
232  * @pad: the src #GstPad to perform the getrange on.
233  * @offset: the offset of the range
234  * @length: the length of the range
235  * @buffer: a memory location to hold the result buffer, cannot be NULL.
236  *
237  * This function will be called on source pads when a peer element
238  * request a buffer at the specified @offset and @length. If this function
239  * returns #GST_FLOW_OK, the result buffer will be stored in @buffer. The 
240  * contents of @buffer is invalid for any other return value.
241  *
242  * This function is installed on a source pad with
243  * gst_pad_set_getrange_function() and can only be called on source pads after 
244  * they are successfully activated with gst_pad_activate_pull().
245  *
246  * @offset and @length are always given in byte units. @offset must normally be a value
247  * between 0 and the length in bytes of the data available on @pad. The
248  * length (duration in bytes) can be retrieved with a #GST_QUERY_DURATION or with a
249  * #GST_QUERY_SEEKING. 
250  *
251  * Any @offset larger or equal than the length will make the function return
252  * #GST_FLOW_UNEXPECTED, which corresponds to EOS. In this case @buffer does not
253  * contain a valid buffer.
254  *
255  * The buffer size of @buffer might be smaller than @length when @offset is near
256  * the end of the stream.
257  *
258  * It is allowed to call this function with a 0 @length and valid @offset, in 
259  * which case @buffer will contain a 0-sized buffer and the function returns
260  * #GST_FLOW_OK.
261  *
262  * When this function is called with a -1 @offset, the sequentially next buffer
263  * of length @length in the stream is returned. 
264  *
265  * When this function is called with a -1 @length, a buffer with a default
266  * optimal length is returned in @buffer. The length might depend on the value
267  * of @offset.
268  *
269  * Returns: #GST_FLOW_OK for success
270  */
271 typedef GstFlowReturn           (*GstPadGetRangeFunction)       (GstPad *pad, guint64 offset,
272                                                                  guint length, GstBuffer **buffer);
273
274 /**
275  * GstPadEventFunction:
276  * @pad: the #GstPad to handle the event.
277  * @event: the #GstEvent to handle.
278  *
279  * Function signature to handle an event for the pad.
280  *
281  * Returns: TRUE if the pad could handle the event.
282  */
283 typedef gboolean                (*GstPadEventFunction)          (GstPad *pad, GstEvent *event);
284
285
286 /* FIXME: 0.11: deprecate me, check range should use seeking query */
287 /**
288  * GstPadCheckGetRangeFunction:
289  * @pad: a #GstPad
290  *
291  * Check if @pad can be activated in pull mode.
292  *
293  * This function will be deprecated after 0.10; use the seeking query to check
294  * if a pad can support random access.
295  *
296  * Returns: TRUE if the pad can operate in pull mode.
297  */
298 typedef gboolean                (*GstPadCheckGetRangeFunction)  (GstPad *pad);
299
300 /* internal links */
301 /**
302  * GstPadIntLinkFunction:
303  * @pad: The #GstPad to query.
304  *
305  * The signature of the internal pad link function.
306  *
307  * Returns: a newly allocated #GList of pads that are linked to the given pad on
308  *  the inside of the parent element.
309  *  The caller must call g_list_free() on it after use.
310  */
311 typedef GList*                  (*GstPadIntLinkFunction)        (GstPad *pad);
312
313
314 /* generic query function */
315 /**
316  * GstPadQueryTypeFunction:
317  * @pad: a #GstPad to query
318  *
319  * The signature of the query types function.
320  *
321  * Returns: a constant array of query types
322  */
323 typedef const GstQueryType*     (*GstPadQueryTypeFunction)      (GstPad *pad);
324
325 /**
326  * GstPadQueryFunction:
327  * @pad: the #GstPad to query.
328  * @query: the #GstQuery object to execute
329  *
330  * The signature of the query function.
331  *
332  * Returns: TRUE if the query could be performed.
333  */
334 typedef gboolean                (*GstPadQueryFunction)          (GstPad *pad, GstQuery *query);
335
336
337 /* linking */
338 /**
339  * GstPadLinkFunction
340  * @pad: the #GstPad that is linked.
341  * @peer: the peer #GstPad of the link
342  *
343  * Function signature to handle a new link on the pad.
344  *
345  * Returns: the result of the link with the specified peer.
346  */
347 typedef GstPadLinkReturn        (*GstPadLinkFunction)           (GstPad *pad, GstPad *peer);
348 /**
349  * GstPadUnlinkFunction
350  * @pad: the #GstPad that is linked.
351  *
352  * Function signature to handle a unlinking the pad prom its peer.
353  */
354 typedef void                    (*GstPadUnlinkFunction)         (GstPad *pad);
355
356
357 /* caps nego */
358 /**
359  * GstPadGetCapsFunction:
360  * @pad: the #GstPad to get the capabilities of.
361  *
362  * Returns a copy of the capabilities of the specified pad. By default this
363  * function will return the pad template capabilities, but can optionally
364  * be overridden by elements.
365  *
366  * Returns: a newly allocated copy #GstCaps of the pad.
367  */
368 typedef GstCaps*                (*GstPadGetCapsFunction)        (GstPad *pad);
369
370 /**
371  * GstPadSetCapsFunction:
372  * @pad: the #GstPad to set the capabilities of.
373  * @caps: the #GstCaps to set
374  *
375  * Set @caps on @pad. By default this function updates the caps of the
376  * pad but the function can be overriden by elements to perform extra 
377  * actions or verifications.
378  *
379  * Returns: TRUE if the caps could be set on the pad.
380  */
381 typedef gboolean                (*GstPadSetCapsFunction)        (GstPad *pad, GstCaps *caps);
382 /**
383  * GstPadAcceptCapsFunction:
384  * @pad: the #GstPad to check
385  * @caps: the #GstCaps to check
386  *
387  * Check if @pad can accept @caps. By default this function will see if @caps
388  * intersect with the result from gst_pad_get_caps() by can be overridden to
389  * perform extra checks.
390  *
391  * Returns: TRUE if the caps can be accepted by the pad.
392  */
393 typedef gboolean                (*GstPadAcceptCapsFunction)     (GstPad *pad, GstCaps *caps);
394 /**
395  * GstPadFixateCapsFunction:
396  * @pad: a #GstPad  
397  * @caps: the #GstCaps to fixate
398  *
399  * Given possibly unfixed caps @caps, let @pad use its default prefered 
400  * format to make a fixed caps. @caps should be writable. By default this
401  * function will pick the first value of any ranges or lists in the caps but
402  * elements can override this function to perform other behaviour.
403  */
404 typedef void                    (*GstPadFixateCapsFunction)     (GstPad *pad, GstCaps *caps);
405 /**
406  * GstPadBufferAllocFunction:
407  * @pad: a sink #GstPad  
408  * @offset: the desired offset of the buffer
409  * @size: the desired size of the buffer
410  * @caps: the desired caps of the buffer
411  * @buf: pointer to hold the allocated buffer.
412  *
413  * Ask the sinkpad @pad to allocate a buffer with @offset, @size and @caps.
414  * The result will be stored in @buf.
415  *
416  * The purpose of this function is to allocate a buffer that is optimal to
417  * be processed by @pad. The function is mostly overridden by elements that can
418  * provide a hardware buffer in order to avoid additional memcpy operations.
419  *
420  * The function can return a buffer that does not have @caps, in which case the
421  * upstream element requests a format change. If a format change was requested,
422  * the returned buffer will be one to hold the data of said new caps, so its
423  * size might be different from @size.
424  *
425  * When this function returns anything else than #GST_FLOW_OK, the buffer allocation
426  * failed and @buf does not contain valid data.
427  *
428  * By default this function returns a new buffer of @size and with @caps containing
429  * purely malloced data. The buffer should be freed with gst_buffer_unref()
430  * after usage.
431  *
432  * Returns: #GST_FLOW_OK if @buf contains a valid buffer, any other return
433  *  value means @buf does not hold a valid buffer.
434  */
435 typedef GstFlowReturn           (*GstPadBufferAllocFunction)    (GstPad *pad, guint64 offset, guint size,
436                                                                  GstCaps *caps, GstBuffer **buf);
437
438 /* misc */
439 /**
440  * GstPadDispatcherFunction:
441  * @pad: the #GstPad that is dispatched.
442  * @data: the gpointer to optional user data.
443  *
444  * A dispatcher function is called for all internally linked pads, see
445  * gst_pad_dispatcher().
446  *
447  * Returns: TRUE if the dispatching procedure has to be stopped.
448  */
449 typedef gboolean                (*GstPadDispatcherFunction)     (GstPad *pad, gpointer data);
450
451 /**
452  * GstPadBlockCallback:
453  * @pad: the #GstPad that is blockend or unblocked.
454  * @blocked: blocking state for the pad
455  * @user_data: the gpointer to optional user data.
456  *
457  * Callback used by gst_pad_set_blocked_async(). Gets called when the blocking
458  * operation succeeds.
459  */
460 typedef void                    (*GstPadBlockCallback)          (GstPad *pad, gboolean blocked, gpointer user_data);
461
462 /**
463  * GstPadDirection:
464  * @GST_PAD_UNKNOWN: direction is unknown.
465  * @GST_PAD_SRC: the pad is a source pad.
466  * @GST_PAD_SINK: the pad is a sink pad.
467  *
468  * The direction of a pad.
469  */
470 typedef enum {
471   GST_PAD_UNKNOWN,
472   GST_PAD_SRC,
473   GST_PAD_SINK
474 } GstPadDirection;
475
476 /**
477  * GstPadFlags:
478  * @GST_PAD_BLOCKED: is dataflow on a pad blocked
479  * @GST_PAD_FLUSHING: is pad refusing buffers
480  * @GST_PAD_IN_GETCAPS: GstPadGetCapsFunction() is running now
481  * @GST_PAD_IN_SETCAPS: GstPadSetCapsFunction() is running now
482  * @GST_PAD_BLOCKING: is pad currently blocking on a buffer or event
483  * @GST_PAD_FLAG_LAST: offset to define more flags
484  *
485  * Pad state flags
486  */
487 typedef enum {
488   GST_PAD_BLOCKED       = (GST_OBJECT_FLAG_LAST << 0),
489   GST_PAD_FLUSHING      = (GST_OBJECT_FLAG_LAST << 1),
490   GST_PAD_IN_GETCAPS    = (GST_OBJECT_FLAG_LAST << 2),
491   GST_PAD_IN_SETCAPS    = (GST_OBJECT_FLAG_LAST << 3),
492   GST_PAD_BLOCKING      = (GST_OBJECT_FLAG_LAST << 4),
493   /* padding */
494   GST_PAD_FLAG_LAST     = (GST_OBJECT_FLAG_LAST << 8)
495 } GstPadFlags;
496
497 /* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */
498 typedef struct _GstPadTemplate GstPadTemplate;
499
500 /**
501  * GstPad:
502  * @element_private: private data owned by the parent element
503  * @padtemplate: padtemplate for this pad
504  * @direction: the direction of the pad, cannot change after creating
505  *             the pad.
506  * @stream_rec_lock: recursive stream lock of the pad, used to protect
507  *                   the data used in streaming.
508  * @task: task for this pad if the pad is actively driving dataflow.
509  * @preroll_lock: lock used when prerolling
510  * @preroll_cond: conf to signal preroll
511  * @block_cond: conditional to signal pad block
512  * @block_callback: callback for the pad block if any
513  * @block_data: user data for @block_callback
514  * @caps: the current caps of the pad
515  * @getcapsfunc: function to get caps of the pad
516  * @setcapsfunc: function to set caps on the pad
517  * @acceptcapsfunc: function to check if pad can accept caps
518  * @fixatecapsfunc: function to fixate caps
519  * @activatefunc: pad activation function
520  * @activatepushfunc: function to activate/deactivate pad in push mode
521  * @activatepullfunc: function to activate/deactivate pad in pull mode
522  * @linkfunc: function called when pad is linked
523  * @unlinkfunc: function called when pad is unlinked
524  * @peer: the pad this pad is linked to
525  * @sched_private: private storage for the scheduler
526  * @chainfunc: function to chain data to pad
527  * @checkgetrangefunc: function to check if pad can operate in pull mode
528  * @getrangefunc: function to get a range of data from a pad
529  * @eventfunc: function to send an event to a pad
530  * @mode: current activation mode of the pad
531  * @querytypefunc: get list of supported queries
532  * @queryfunc: perform a query on the pad
533  * @intlinkfunc: get the internal links of this pad
534  * @bufferallocfunc: function to allocate a buffer for this pad
535  * @do_buffer_signals: counter counting installed buffer signals
536  * @do_event_signals: counter counting installed event signals
537  * 
538  * The #GstPad structure. Use the functions to update the variables.
539  */
540 struct _GstPad {
541   GstObject                     object;
542
543   /*< public >*/
544   gpointer                      element_private;
545
546   GstPadTemplate                *padtemplate;
547
548   GstPadDirection                direction;
549
550   /*< public >*/ /* with STREAM_LOCK */
551   /* streaming rec_lock */
552   GStaticRecMutex               *stream_rec_lock;
553   GstTask                       *task;
554   /*< public >*/ /* with PREROLL_LOCK */
555   GMutex                        *preroll_lock;
556   GCond                         *preroll_cond;
557
558   /*< public >*/ /* with LOCK */
559   /* block cond, mutex is from the object */
560   GCond                         *block_cond;
561   GstPadBlockCallback            block_callback;
562   gpointer                       block_data;
563
564   /* the pad capabilities */
565   GstCaps                       *caps;
566   GstPadGetCapsFunction         getcapsfunc;
567   GstPadSetCapsFunction         setcapsfunc;
568   GstPadAcceptCapsFunction       acceptcapsfunc;
569   GstPadFixateCapsFunction       fixatecapsfunc;
570
571   GstPadActivateFunction         activatefunc;
572   GstPadActivateModeFunction     activatepushfunc;
573   GstPadActivateModeFunction     activatepullfunc;
574
575   /* pad link */
576   GstPadLinkFunction             linkfunc;
577   GstPadUnlinkFunction           unlinkfunc;
578   GstPad                        *peer;
579
580   gpointer                       sched_private;
581
582   /* data transport functions */
583   GstPadChainFunction            chainfunc;
584   GstPadCheckGetRangeFunction    checkgetrangefunc;
585   GstPadGetRangeFunction         getrangefunc;
586   GstPadEventFunction            eventfunc;
587
588   GstActivateMode                mode;
589
590   /* generic query method */
591   GstPadQueryTypeFunction        querytypefunc;
592   GstPadQueryFunction            queryfunc;
593
594   /* internal links */
595   GstPadIntLinkFunction          intlinkfunc;
596
597   GstPadBufferAllocFunction      bufferallocfunc;
598
599   /* whether to emit signals for have-data. counts number
600    * of handlers attached. */
601   gint                           do_buffer_signals;
602   gint                           do_event_signals;
603
604   /*< private >*/
605   gpointer _gst_reserved[GST_PADDING];
606 };
607
608 struct _GstPadClass {
609   GstObjectClass        parent_class;
610
611   /* signal callbacks */
612   void          (*linked)               (GstPad *pad, GstPad *peer);
613   void          (*unlinked)             (GstPad *pad, GstPad *peer);
614   void          (*request_link)         (GstPad *pad);
615   gboolean      (*have_data)            (GstPad *pad, GstMiniObject *data);
616
617   /*< private >*/
618   gpointer _gst_reserved[GST_PADDING];
619 };
620
621
622 /***** helper macros *****/
623 /* GstPad */
624 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
625 #define GST_PAD_PARENT(pad)             (GST_ELEMENT_CAST(GST_OBJECT_PARENT(pad)))
626 #define GST_PAD_ELEMENT_PRIVATE(pad)    (GST_PAD_CAST(pad)->element_private)
627 #define GST_PAD_PAD_TEMPLATE(pad)       (GST_PAD_CAST(pad)->padtemplate)
628 #define GST_PAD_DIRECTION(pad)          (GST_PAD_CAST(pad)->direction)
629 #define GST_PAD_TASK(pad)               (GST_PAD_CAST(pad)->task)
630 #define GST_PAD_ACTIVATE_MODE(pad)      (GST_PAD_CAST(pad)->mode)
631
632 #define GST_PAD_ACTIVATEFUNC(pad)       (GST_PAD_CAST(pad)->activatefunc)
633 #define GST_PAD_ACTIVATEPUSHFUNC(pad)   (GST_PAD_CAST(pad)->activatepushfunc)
634 #define GST_PAD_ACTIVATEPULLFUNC(pad)   (GST_PAD_CAST(pad)->activatepullfunc)
635 #define GST_PAD_CHAINFUNC(pad)          (GST_PAD_CAST(pad)->chainfunc)
636 #define GST_PAD_CHECKGETRANGEFUNC(pad)  (GST_PAD_CAST(pad)->checkgetrangefunc)
637 #define GST_PAD_GETRANGEFUNC(pad)       (GST_PAD_CAST(pad)->getrangefunc)
638 #define GST_PAD_EVENTFUNC(pad)          (GST_PAD_CAST(pad)->eventfunc)
639 #define GST_PAD_QUERYTYPEFUNC(pad)      (GST_PAD_CAST(pad)->querytypefunc)
640 #define GST_PAD_QUERYFUNC(pad)          (GST_PAD_CAST(pad)->queryfunc)
641 #define GST_PAD_INTLINKFUNC(pad)        (GST_PAD_CAST(pad)->intlinkfunc)
642
643 #define GST_PAD_PEER(pad)               (GST_PAD_CAST(pad)->peer)
644 #define GST_PAD_LINKFUNC(pad)           (GST_PAD_CAST(pad)->linkfunc)
645 #define GST_PAD_UNLINKFUNC(pad)         (GST_PAD_CAST(pad)->unlinkfunc)
646
647 #define GST_PAD_CAPS(pad)               (GST_PAD_CAST(pad)->caps)
648 #define GST_PAD_GETCAPSFUNC(pad)        (GST_PAD_CAST(pad)->getcapsfunc)
649 #define GST_PAD_SETCAPSFUNC(pad)        (GST_PAD_CAST(pad)->setcapsfunc)
650 #define GST_PAD_ACCEPTCAPSFUNC(pad)     (GST_PAD_CAST(pad)->acceptcapsfunc)
651 #define GST_PAD_FIXATECAPSFUNC(pad)     (GST_PAD_CAST(pad)->fixatecapsfunc)
652
653 #define GST_PAD_BUFFERALLOCFUNC(pad)    (GST_PAD_CAST(pad)->bufferallocfunc)
654
655 #define GST_PAD_DO_BUFFER_SIGNALS(pad)  (GST_PAD_CAST(pad)->do_buffer_signals)
656 #define GST_PAD_DO_EVENT_SIGNALS(pad)   (GST_PAD_CAST(pad)->do_event_signals)
657
658 #define GST_PAD_IS_LINKED(pad)          (GST_PAD_PEER(pad) != NULL)
659 #define GST_PAD_IS_BLOCKED(pad)         (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED))
660 #define GST_PAD_IS_BLOCKING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING))
661 #define GST_PAD_IS_FLUSHING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING))
662 #define GST_PAD_IS_IN_GETCAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_GETCAPS))
663 #define GST_PAD_IS_IN_SETCAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_SETCAPS))
664 #define GST_PAD_IS_SRC(pad)             (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
665 #define GST_PAD_IS_SINK(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
666
667 #define GST_PAD_SET_FLUSHING(pad)       (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLUSHING))
668 #define GST_PAD_UNSET_FLUSHING(pad)     (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLUSHING))
669
670 /**
671  * GST_PAD_GET_STREAM_LOCK:
672  * @pad: a #GstPad
673  *
674  * Get the stream lock of @pad. The stream lock is protecting the
675  * resources used in the data processing functions of @pad.
676  */
677 #define GST_PAD_GET_STREAM_LOCK(pad)    (GST_PAD_CAST(pad)->stream_rec_lock)
678 /**
679  * GST_PAD_STREAM_LOCK:
680  * @pad: a #GstPad
681  *
682  * Lock the stream lock of @pad.
683  */
684 #define GST_PAD_STREAM_LOCK(pad)        (g_static_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad)))
685 /**
686  * GST_PAD_STREAM_LOCK_FULL:
687  * @pad: a #GstPad
688  * @t: the number of times to recursively lock
689  *
690  * Lock the stream lock of @pad @t times.
691  */
692 #define GST_PAD_STREAM_LOCK_FULL(pad,t) (g_static_rec_mutex_lock_full(GST_PAD_GET_STREAM_LOCK(pad), t))
693 /**
694  * GST_PAD_STREAM_TRYLOCK:
695  * @pad: a #GstPad
696  *
697  * Try to Lock the stream lock of the pad, return TRUE if the lock could be
698  * taken.
699  */
700 #define GST_PAD_STREAM_TRYLOCK(pad)     (g_static_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad)))
701 /**
702  * GST_PAD_STREAM_UNLOCK:
703  * @pad: a #GstPad
704  *
705  * Unlock the stream lock of @pad.
706  */
707 #define GST_PAD_STREAM_UNLOCK(pad)      (g_static_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad)))
708 /**
709  * GST_PAD_STREAM_UNLOCK_FULL:
710  * @pad: a #GstPad
711  *
712  * Fully unlock the recursive stream lock of @pad, return the number of times
713  * @pad was locked.
714  */
715 #define GST_PAD_STREAM_UNLOCK_FULL(pad) (g_static_rec_mutex_unlock_full(GST_PAD_GET_STREAM_LOCK(pad)))
716
717 #define GST_PAD_GET_PREROLL_LOCK(pad)   (GST_PAD_CAST(pad)->preroll_lock)
718 #define GST_PAD_PREROLL_LOCK(pad)       (g_mutex_lock(GST_PAD_GET_PREROLL_LOCK(pad)))
719 #define GST_PAD_PREROLL_TRYLOCK(pad)    (g_mutex_trylock(GST_PAD_GET_PREROLL_LOCK(pad)))
720 #define GST_PAD_PREROLL_UNLOCK(pad)     (g_mutex_unlock(GST_PAD_GET_PREROLL_LOCK(pad)))
721
722 #define GST_PAD_GET_PREROLL_COND(pad)   (GST_PAD_CAST(pad)->preroll_cond)
723 #define GST_PAD_PREROLL_WAIT(pad)       \
724     g_cond_wait (GST_PAD_GET_PREROLL_COND (pad), GST_PAD_GET_PREROLL_LOCK (pad))
725 #define GST_PAD_PREROLL_TIMED_WAIT(pad, timeval) \
726     g_cond_timed_wait (GST_PAD_GET_PREROLL_COND (pad), GST_PAD_GET_PREROLL_LOCK (pad), timeval)
727 #define GST_PAD_PREROLL_SIGNAL(pad)     g_cond_signal (GST_PAD_GET_PREROLL_COND (pad));
728 #define GST_PAD_PREROLL_BROADCAST(pad)  g_cond_broadcast (GST_PAD_GET_PREROLL_COND (pad));
729
730 #define GST_PAD_BLOCK_GET_COND(pad)     (GST_PAD_CAST(pad)->block_cond)
731 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_OBJECT_GET_LOCK (pad)))
732 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
733 #define GST_PAD_BLOCK_BROADCAST(pad)    (g_cond_broadcast(GST_PAD_BLOCK_GET_COND (pad)))
734
735 /* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */
736 #include <gst/gstpadtemplate.h>
737
738 GType                   gst_pad_get_type                        (void);
739
740 /* creating pads */
741 GstPad*                 gst_pad_new                             (const gchar *name, GstPadDirection direction);
742 GstPad*                 gst_pad_new_from_template               (GstPadTemplate *templ, const gchar *name);
743 GstPad*                 gst_pad_new_from_static_template        (GstStaticPadTemplate *templ, const gchar *name);
744
745
746 /**
747  * gst_pad_get_name:
748  * @pad: the pad to get the name from
749  *
750  * Get a copy of the name of the pad. g_free() after usage.
751  *
752  * MT safe.
753  */
754 #define gst_pad_get_name(pad) gst_object_get_name (GST_OBJECT_CAST (pad))
755 /**
756  * gst_pad_get_parent:
757  * @pad: the pad to get the parent of
758  *
759  * Get the parent of @pad. This function increases the refcount
760  * of the parent object so you should gst_object_unref() it after usage.
761  * Can return NULL if the pad did not have a parent.
762  *
763  * MT safe.
764  */
765 #define gst_pad_get_parent(pad) gst_object_get_parent (GST_OBJECT_CAST (pad))
766
767 GstPadDirection         gst_pad_get_direction                   (GstPad *pad);
768
769 gboolean                gst_pad_set_active                      (GstPad *pad, gboolean active);
770 gboolean                gst_pad_is_active                       (GstPad *pad);
771 gboolean                gst_pad_activate_pull                   (GstPad *pad, gboolean active);
772 gboolean                gst_pad_activate_push                   (GstPad *pad, gboolean active);
773
774 gboolean                gst_pad_set_blocked                     (GstPad *pad, gboolean blocked);
775 gboolean                gst_pad_set_blocked_async               (GstPad *pad, gboolean blocked,
776                                                                  GstPadBlockCallback callback, gpointer user_data);
777 gboolean                gst_pad_is_blocked                      (GstPad *pad);
778 gboolean                gst_pad_is_blocking                     (GstPad *pad);
779
780 void                    gst_pad_set_element_private             (GstPad *pad, gpointer priv);
781 gpointer                gst_pad_get_element_private             (GstPad *pad);
782
783 GstPadTemplate*         gst_pad_get_pad_template                (GstPad *pad);
784
785 void                    gst_pad_set_bufferalloc_function        (GstPad *pad, GstPadBufferAllocFunction bufalloc);
786 GstFlowReturn           gst_pad_alloc_buffer                    (GstPad *pad, guint64 offset, gint size,
787                                                                  GstCaps *caps, GstBuffer **buf);
788 GstFlowReturn           gst_pad_alloc_buffer_and_set_caps       (GstPad *pad, guint64 offset, gint size,
789                                                                  GstCaps *caps, GstBuffer **buf);
790
791 /* data passing setup functions */
792 void                    gst_pad_set_activate_function           (GstPad *pad, GstPadActivateFunction activate);
793 void                    gst_pad_set_activatepull_function       (GstPad *pad, GstPadActivateModeFunction activatepull);
794 void                    gst_pad_set_activatepush_function       (GstPad *pad, GstPadActivateModeFunction activatepush);
795 void                    gst_pad_set_chain_function              (GstPad *pad, GstPadChainFunction chain);
796 void                    gst_pad_set_getrange_function           (GstPad *pad, GstPadGetRangeFunction get);
797 void                    gst_pad_set_checkgetrange_function      (GstPad *pad, GstPadCheckGetRangeFunction check);
798 void                    gst_pad_set_event_function              (GstPad *pad, GstPadEventFunction event);
799
800 /* pad links */
801 void                    gst_pad_set_link_function               (GstPad *pad, GstPadLinkFunction link);
802 void                    gst_pad_set_unlink_function             (GstPad *pad, GstPadUnlinkFunction unlink);
803
804 GstPadLinkReturn        gst_pad_link                            (GstPad *srcpad, GstPad *sinkpad);
805 gboolean                gst_pad_unlink                          (GstPad *srcpad, GstPad *sinkpad);
806 gboolean                gst_pad_is_linked                       (GstPad *pad);
807
808 GstPad*                 gst_pad_get_peer                        (GstPad *pad);
809
810 /* capsnego functions */
811 void                    gst_pad_set_getcaps_function            (GstPad *pad, GstPadGetCapsFunction getcaps);
812 void                    gst_pad_set_acceptcaps_function         (GstPad *pad, GstPadAcceptCapsFunction acceptcaps);
813 void                    gst_pad_set_fixatecaps_function         (GstPad *pad, GstPadFixateCapsFunction fixatecaps);
814 void                    gst_pad_set_setcaps_function            (GstPad *pad, GstPadSetCapsFunction setcaps);
815
816 G_CONST_RETURN GstCaps* gst_pad_get_pad_template_caps           (GstPad *pad);
817
818 /* capsnego function for connected/unconnected pads */
819 GstCaps *               gst_pad_get_caps                        (GstPad * pad);
820 void                    gst_pad_fixate_caps                     (GstPad * pad, GstCaps *caps);
821 gboolean                gst_pad_accept_caps                     (GstPad * pad, GstCaps *caps);
822 gboolean                gst_pad_set_caps                        (GstPad * pad, GstCaps *caps);
823
824 GstCaps *               gst_pad_peer_get_caps                   (GstPad * pad);
825 gboolean                gst_pad_peer_accept_caps                (GstPad * pad, GstCaps *caps);
826
827 /* capsnego for connected pads */
828 GstCaps *               gst_pad_get_allowed_caps                (GstPad * srcpad);
829 GstCaps *               gst_pad_get_negotiated_caps             (GstPad * pad);
830
831 /* data passing functions to peer */
832 GstFlowReturn           gst_pad_push                            (GstPad *pad, GstBuffer *buffer);
833 gboolean                gst_pad_check_pull_range                (GstPad *pad);
834 GstFlowReturn           gst_pad_pull_range                      (GstPad *pad, guint64 offset, guint size,
835                                                                  GstBuffer **buffer);
836 gboolean                gst_pad_push_event                      (GstPad *pad, GstEvent *event);
837 gboolean                gst_pad_event_default                   (GstPad *pad, GstEvent *event);
838
839 /* data passing functions on pad */
840 GstFlowReturn           gst_pad_chain                           (GstPad *pad, GstBuffer *buffer);
841 GstFlowReturn           gst_pad_get_range                       (GstPad *pad, guint64 offset, guint size,
842                                                                  GstBuffer **buffer);
843 gboolean                gst_pad_send_event                      (GstPad *pad, GstEvent *event);
844
845 /* pad tasks */
846 gboolean                gst_pad_start_task                      (GstPad *pad, GstTaskFunction func,
847                                                                  gpointer data);
848 gboolean                gst_pad_pause_task                      (GstPad *pad);
849 gboolean                gst_pad_stop_task                       (GstPad *pad);
850
851 /* internal links */
852 void                    gst_pad_set_internal_link_function      (GstPad *pad, GstPadIntLinkFunction intlink);
853 GList*                  gst_pad_get_internal_links              (GstPad *pad);
854 GList*                  gst_pad_get_internal_links_default      (GstPad *pad);
855
856 /* generic query function */
857 void                    gst_pad_set_query_type_function         (GstPad *pad, GstPadQueryTypeFunction type_func);
858 G_CONST_RETURN GstQueryType*
859                         gst_pad_get_query_types                 (GstPad *pad);
860 G_CONST_RETURN GstQueryType*
861                         gst_pad_get_query_types_default         (GstPad *pad);
862
863 gboolean                gst_pad_query                           (GstPad *pad, GstQuery *query);
864 void                    gst_pad_set_query_function              (GstPad *pad, GstPadQueryFunction query);
865 gboolean                gst_pad_query_default                   (GstPad *pad, GstQuery *query);
866
867 /* misc helper functions */
868 gboolean                gst_pad_dispatcher                      (GstPad *pad, GstPadDispatcherFunction dispatch,
869                                                                  gpointer data);
870
871 #ifndef GST_DISABLE_LOADSAVE
872 void                    gst_pad_load_and_link                   (xmlNodePtr self, GstObject *parent);
873 #endif
874
875 G_END_DECLS
876
877 #endif /* __GST_PAD_H__ */