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