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