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