Merge remote-tracking branch 'origin/master' into 0.11
[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 typedef struct _GstPad GstPad;
30 typedef struct _GstPadPrivate GstPadPrivate;
31 typedef struct _GstPadClass GstPadClass;
32
33 /**
34  * GstPadDirection:
35  * @GST_PAD_UNKNOWN: direction is unknown.
36  * @GST_PAD_SRC: the pad is a source pad.
37  * @GST_PAD_SINK: the pad is a sink pad.
38  *
39  * The direction of a pad.
40  */
41 typedef enum {
42   GST_PAD_UNKNOWN,
43   GST_PAD_SRC,
44   GST_PAD_SINK
45 } GstPadDirection;
46
47 /**
48  * GstPadMode:
49  * @GST_PAD_MODE_NONE: Pad will not handle dataflow
50  * @GST_PAD_MODE_PUSH: Pad handles dataflow in downstream push mode
51  * @GST_PAD_MODE_PULL: Pad handles dataflow in upstream pull mode
52  *
53  * The status of a GstPad. After activating a pad, which usually happens when the
54  * parent element goes from READY to PAUSED, the GstPadMode defines if the
55  * pad operates in push or pull mode.
56  */
57 typedef enum {
58   GST_PAD_MODE_NONE,
59   GST_PAD_MODE_PUSH,
60   GST_PAD_MODE_PULL
61 } GstPadMode;
62
63 #include <gst/gstobject.h>
64 #include <gst/gstbuffer.h>
65 #include <gst/gstbufferlist.h>
66 #include <gst/gstcaps.h>
67 #include <gst/gstpadtemplate.h>
68 #include <gst/gstevent.h>
69 #include <gst/gstquery.h>
70 #include <gst/gsttask.h>
71
72 G_BEGIN_DECLS
73
74 /*
75  * Pad base class
76  */
77 #define GST_TYPE_PAD                    (gst_pad_get_type ())
78 #define GST_IS_PAD(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD))
79 #define GST_IS_PAD_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD))
80 #define GST_PAD(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD, GstPad))
81 #define GST_PAD_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD, GstPadClass))
82 #define GST_PAD_CAST(obj)               ((GstPad*)(obj))
83
84
85
86 /**
87  * GstPadLinkReturn:
88  * @GST_PAD_LINK_OK             : link succeeded
89  * @GST_PAD_LINK_WRONG_HIERARCHY: pads have no common grandparent
90  * @GST_PAD_LINK_WAS_LINKED     : pad was already linked
91  * @GST_PAD_LINK_WRONG_DIRECTION: pads have wrong direction
92  * @GST_PAD_LINK_NOFORMAT       : pads do not have common format
93  * @GST_PAD_LINK_NOSCHED        : pads cannot cooperate in scheduling
94  * @GST_PAD_LINK_REFUSED        : refused for some reason
95  *
96  * Result values from gst_pad_link and friends.
97  */
98 typedef enum {
99   GST_PAD_LINK_OK               =  0,
100   GST_PAD_LINK_WRONG_HIERARCHY  = -1,
101   GST_PAD_LINK_WAS_LINKED       = -2,
102   GST_PAD_LINK_WRONG_DIRECTION  = -3,
103   GST_PAD_LINK_NOFORMAT         = -4,
104   GST_PAD_LINK_NOSCHED          = -5,
105   GST_PAD_LINK_REFUSED          = -6
106 } GstPadLinkReturn;
107
108 /**
109  * GST_PAD_LINK_FAILED:
110  * @ret: the #GstPadLinkReturn value
111  *
112  * Macro to test if the given #GstPadLinkReturn value indicates a failed
113  * link step.
114  */
115 #define GST_PAD_LINK_FAILED(ret) ((ret) < GST_PAD_LINK_OK)
116
117 /**
118  * GST_PAD_LINK_SUCCESSFUL:
119  * @ret: the #GstPadLinkReturn value
120  *
121  * Macro to test if the given #GstPadLinkReturn value indicates a successful
122  * link step.
123  */
124 #define GST_PAD_LINK_SUCCESSFUL(ret) ((ret) >= GST_PAD_LINK_OK)
125
126 /**
127  * GstFlowReturn:
128  * @GST_FLOW_RESEND:             Resend buffer, possibly with new caps (not
129  *                                 sent yet) (unused/unimplemented).
130  * @GST_FLOW_OK:                 Data passing was ok.
131  * @GST_FLOW_NOT_LINKED:         Pad is not linked.
132  * @GST_FLOW_WRONG_STATE:        Pad is in wrong state.
133  * @GST_FLOW_EOS:                Pad is EOS.
134  * @GST_FLOW_NOT_NEGOTIATED:     Pad is not negotiated.
135  * @GST_FLOW_ERROR:              Some (fatal) error occured. Element generating
136  *                               this error should post an error message with more
137  *                               details.
138  * @GST_FLOW_NOT_SUPPORTED:      This operation is not supported.
139  * @GST_FLOW_CUSTOM_SUCCESS:     Elements can use values starting from
140  *                               this (and higher) to define custom success
141  *                               codes. Since 0.10.7.
142  * @GST_FLOW_CUSTOM_SUCCESS_1:   Pre-defined custom success code (define your
143  *                               custom success code to this to avoid compiler
144  *                               warnings). Since 0.10.29.
145  * @GST_FLOW_CUSTOM_SUCCESS_2:   Pre-defined custom success code. Since 0.10.29.
146  * @GST_FLOW_CUSTOM_ERROR:       Elements can use values starting from
147  *                               this (and lower) to define custom error codes.
148  *                               Since 0.10.7.
149  * @GST_FLOW_CUSTOM_ERROR_1:     Pre-defined custom error code (define your
150  *                               custom error code to this to avoid compiler
151  *                               warnings). Since 0.10.29.
152  * @GST_FLOW_CUSTOM_ERROR_2:     Pre-defined custom error code. Since 0.10.29.
153  *
154  * The result of passing data to a pad.
155  *
156  * Note that the custom return values should not be exposed outside of the
157  * element scope and are available since 0.10.7.
158  */
159 /* FIXME 0.11: remove custom flow returns */
160 typedef enum {
161   /* custom success starts here */
162   GST_FLOW_CUSTOM_SUCCESS_2 = 102,
163   GST_FLOW_CUSTOM_SUCCESS_1 = 101,
164   GST_FLOW_CUSTOM_SUCCESS = 100,
165
166   /* core predefined */
167   GST_FLOW_RESEND         =  1,
168   GST_FLOW_OK             =  0,
169   /* expected failures */
170   GST_FLOW_NOT_LINKED     = -1,
171   GST_FLOW_WRONG_STATE    = -2,
172   /* error cases */
173   GST_FLOW_EOS            = -3,
174   GST_FLOW_NOT_NEGOTIATED = -4,
175   GST_FLOW_ERROR          = -5,
176   GST_FLOW_NOT_SUPPORTED  = -6,
177
178   /* custom error starts here */
179   GST_FLOW_CUSTOM_ERROR   = -100,
180   GST_FLOW_CUSTOM_ERROR_1 = -101,
181   GST_FLOW_CUSTOM_ERROR_2 = -102
182 } GstFlowReturn;
183
184 const gchar*            gst_flow_get_name       (GstFlowReturn ret);
185 GQuark                  gst_flow_to_quark       (GstFlowReturn ret);
186
187 /**
188  * GstPadLinkCheck:
189  * @GST_PAD_LINK_CHECK_NOTHING: Don't check hierarchy or caps compatibility.
190  * @GST_PAD_LINK_CHECK_HIERARCHY: Check the pads have same parents/grandparents.
191  *   Could be omitted if it is already known that the two elements that own the
192  *   pads are in the same bin.
193  * @GST_PAD_LINK_CHECK_TEMPLATE_CAPS: Check if the pads are compatible by using
194  *   their template caps. This is much faster than @GST_PAD_LINK_CHECK_CAPS, but
195  *   would be unsafe e.g. if one pad has %GST_CAPS_ANY.
196  * @GST_PAD_LINK_CHECK_CAPS: Check if the pads are compatible by comparing the
197  *   caps returned by gst_pad_query_caps().
198  *
199  * The amount of checking to be done when linking pads. @GST_PAD_LINK_CHECK_CAPS
200  * and @GST_PAD_LINK_CHECK_TEMPLATE_CAPS are mutually exclusive. If both are
201  * specified, expensive but safe @GST_PAD_LINK_CHECK_CAPS are performed.
202  *
203  * <warning><para>
204  * Only disable some of the checks if you are 100% certain you know the link
205  * will not fail because of hierarchy/caps compatibility failures. If uncertain,
206  * use the default checks (%GST_PAD_LINK_CHECK_DEFAULT) or the regular methods
207  * for linking the pads.
208  * </para></warning>
209  *
210  * Since: 0.10.30
211  */
212
213 typedef enum {
214   GST_PAD_LINK_CHECK_NOTHING       = 0,
215   GST_PAD_LINK_CHECK_HIERARCHY     = 1 << 0,
216   GST_PAD_LINK_CHECK_TEMPLATE_CAPS = 1 << 1,
217   GST_PAD_LINK_CHECK_CAPS          = 1 << 2
218 } GstPadLinkCheck;
219
220 /**
221  * GST_PAD_LINK_CHECK_DEFAULT:
222  *
223  * The default checks done when linking pads (i.e. the ones used by
224  * gst_pad_link()).
225  *
226  * Since: 0.10.30
227  */
228 #define GST_PAD_LINK_CHECK_DEFAULT ((GstPadLinkCheck) (GST_PAD_LINK_CHECK_HIERARCHY | GST_PAD_LINK_CHECK_CAPS))
229
230 /* pad states */
231 /**
232  * GstPadActivateFunction:
233  * @pad: a #GstPad
234  * @parent: the parent of @pad
235  *
236  * This function is called when the pad is activated during the element
237  * READY to PAUSED state change. By default this function will call the
238  * activate function that puts the pad in push mode but elements can
239  * override this function to activate the pad in pull mode if they wish.
240  *
241  * Returns: TRUE if the pad could be activated.
242  */
243 typedef gboolean                (*GstPadActivateFunction)       (GstPad *pad, GstObject *parent);
244 /**
245  * GstPadActivateModeFunction:
246  * @pad: a #GstPad
247  * @parent: the parent of @pad
248  * @mode: the requested activation mode of @pad
249  * @active: activate or deactivate the pad.
250  *
251  * The prototype of the push and pull activate functions.
252  *
253  * Returns: TRUE if the pad could be activated or deactivated.
254  */
255 typedef gboolean                (*GstPadActivateModeFunction)   (GstPad *pad, GstObject *parent,
256                                                                  GstPadMode mode, gboolean active);
257
258
259 /* data passing */
260 /**
261  * GstPadChainFunction:
262  * @pad: the sink #GstPad that performed the chain.
263  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
264  *          @parent is guaranteed to be not-NULL and remain valid during the
265  *          execution of this function.
266  * @buffer: the #GstBuffer that is chained, not %NULL.
267  *
268  * A function that will be called on sinkpads when chaining buffers.
269  * The function typically processes the data contained in the buffer and
270  * either consumes the data or passes it on to the internally linked pad(s).
271  *
272  * The implementer of this function receives a refcount to @buffer and should
273  * gst_buffer_unref() when the buffer is no longer needed.
274  *
275  * When a chain function detects an error in the data stream, it must post an
276  * error on the bus and return an appropriate #GstFlowReturn value.
277  *
278  * Returns: #GST_FLOW_OK for success
279  */
280 typedef GstFlowReturn           (*GstPadChainFunction)          (GstPad *pad, GstObject *parent,
281                                                                  GstBuffer *buffer);
282
283 /**
284  * GstPadChainListFunction:
285  * @pad: the sink #GstPad that performed the chain.
286  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
287  *          @parent is guaranteed to be not-NULL and remain valid during the
288  *          execution of this function.
289  * @list: the #GstBufferList that is chained, not %NULL.
290  *
291  * A function that will be called on sinkpads when chaining buffer lists.
292  * The function typically processes the data contained in the buffer list and
293  * either consumes the data or passes it on to the internally linked pad(s).
294  *
295  * The implementer of this function receives a refcount to @list and
296  * should gst_buffer_list_unref() when the list is no longer needed.
297  *
298  * When a chainlist function detects an error in the data stream, it must
299  * post an error on the bus and return an appropriate #GstFlowReturn value.
300  *
301  * Returns: #GST_FLOW_OK for success
302  */
303 typedef GstFlowReturn           (*GstPadChainListFunction)      (GstPad *pad, GstObject *parent,
304                                                                  GstBufferList *list);
305
306 /**
307  * GstPadGetRangeFunction:
308  * @pad: the src #GstPad to perform the getrange on.
309  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
310  *          @parent is guaranteed to be not-NULL and remain valid during the
311  *          execution of this function.
312  * @offset: the offset of the range
313  * @length: the length of the range
314  * @buffer: a memory location to hold the result buffer, cannot be NULL.
315  *
316  * This function will be called on source pads when a peer element
317  * request a buffer at the specified @offset and @length. If this function
318  * returns #GST_FLOW_OK, the result buffer will be stored in @buffer. The
319  * contents of @buffer is invalid for any other return value.
320  *
321  * This function is installed on a source pad with
322  * gst_pad_set_getrange_function() and can only be called on source pads after
323  * they are successfully activated with gst_pad_activate_pull().
324  *
325  * @offset and @length are always given in byte units. @offset must normally be a value
326  * between 0 and the length in bytes of the data available on @pad. The
327  * length (duration in bytes) can be retrieved with a #GST_QUERY_DURATION or with a
328  * #GST_QUERY_SEEKING.
329  *
330  * Any @offset larger or equal than the length will make the function return
331  * #GST_FLOW_UNEXPECTED, which corresponds to EOS. In this case @buffer does not
332  * contain a valid buffer.
333  *
334  * The buffer size of @buffer will only be smaller than @length when @offset is
335  * near the end of the stream. In all other cases, the size of @buffer must be
336  * exactly the requested size.
337  *
338  * It is allowed to call this function with a 0 @length and valid @offset, in
339  * which case @buffer will contain a 0-sized buffer and the function returns
340  * #GST_FLOW_OK.
341  *
342  * When this function is called with a -1 @offset, the sequentially next buffer
343  * of length @length in the stream is returned.
344  *
345  * When this function is called with a -1 @length, a buffer with a default
346  * optimal length is returned in @buffer. The length might depend on the value
347  * of @offset.
348  *
349  * Returns: #GST_FLOW_OK for success and a valid buffer in @buffer. Any other
350  * return value leaves @buffer undefined.
351  */
352 typedef GstFlowReturn           (*GstPadGetRangeFunction)       (GstPad *pad, GstObject *parent,
353                                                                  guint64 offset, guint length,
354                                                                  GstBuffer **buffer);
355
356 /**
357  * GstPadEventFunction:
358  * @pad: the #GstPad to handle the event.
359  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
360  *          @parent is guaranteed to be not-NULL and remain valid during the
361  *          execution of this function.
362  * @event: the #GstEvent to handle.
363  *
364  * Function signature to handle an event for the pad.
365  *
366  * Returns: TRUE if the pad could handle the event.
367  */
368 typedef gboolean                (*GstPadEventFunction)          (GstPad *pad, GstObject *parent,
369                                                                  GstEvent *event);
370
371
372 /* internal links */
373 /**
374  * GstPadIterIntLinkFunction:
375  * @pad: The #GstPad to query.
376  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
377  *          @parent is guaranteed to be not-NULL and remain valid during the
378  *          execution of this function.
379  *
380  * The signature of the internal pad link iterator function.
381  *
382  * Returns: a new #GstIterator that will iterate over all pads that are
383  * linked to the given pad on the inside of the parent element.
384  *
385  * the caller must call gst_iterator_free() after usage.
386  *
387  * Since 0.10.21
388  */
389 typedef GstIterator*           (*GstPadIterIntLinkFunction)    (GstPad *pad, GstObject *parent);
390
391 /* generic query function */
392 /**
393  * GstPadQueryFunction:
394  * @pad: the #GstPad to query.
395  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
396  *          @parent is guaranteed to be not-NULL and remain valid during the
397  *          execution of this function.
398  * @query: the #GstQuery object to execute
399  *
400  * The signature of the query function.
401  *
402  * Returns: TRUE if the query could be performed.
403  */
404 typedef gboolean                (*GstPadQueryFunction)          (GstPad *pad, GstObject *parent,
405                                                                  GstQuery *query);
406
407
408 /* linking */
409 /**
410  * GstPadLinkFunction
411  * @pad: the #GstPad that is linked.
412  * @peer: the peer #GstPad of the link
413  *
414  * Function signature to handle a new link on the pad.
415  *
416  * Returns: the result of the link with the specified peer.
417  */
418 typedef GstPadLinkReturn        (*GstPadLinkFunction)           (GstPad *pad, GstPad *peer);
419 /**
420  * GstPadUnlinkFunction
421  * @pad: the #GstPad that is linked.
422  *
423  * Function signature to handle a unlinking the pad prom its peer.
424  */
425 typedef void                    (*GstPadUnlinkFunction)         (GstPad *pad);
426
427
428 /* misc */
429 /**
430  * GstPadForwardFunction:
431  * @pad: the #GstPad that is forwarded.
432  * @user_data: the gpointer to optional user data.
433  *
434  * A forward function is called for all internally linked pads, see
435  * gst_pad_forward().
436  *
437  * Returns: TRUE if the dispatching procedure has to be stopped.
438  */
439 typedef gboolean                (*GstPadForwardFunction)        (GstPad *pad, gpointer user_data);
440
441 /**
442  * GstPadProbeType:
443  * @GST_PAD_PROBE_TYPE_INVALID: invalid probe type
444  * @GST_PAD_PROBE_TYPE_IDLE: probe idle pads and block
445  * @GST_PAD_PROBE_TYPE_BLOCK: probe and block pads
446  * @GST_PAD_PROBE_TYPE_BUFFER: probe buffers
447  * @GST_PAD_PROBE_TYPE_BUFFER_LIST: probe buffer lists
448  * @GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM: probe downstream events
449  * @GST_PAD_PROBE_TYPE_EVENT_UPSTREAM: probe upstream events
450  * @GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM: probe downstream queries
451  * @GST_PAD_PROBE_TYPE_QUERY_UPSTREAM: probe upstream queries
452  * @GST_PAD_PROBE_TYPE_PUSH: probe push
453  * @GST_PAD_PROBE_TYPE_PULL: probe pull
454  *
455  * The different probing types that can occur. When either one of
456  * @GST_PAD_PROBE_TYPE_IDLE or @GST_PAD_PROBE_TYPE_BLOCK is used, the probe will be a
457  * blocking probe.
458  */
459 typedef enum
460 {
461   GST_PAD_PROBE_TYPE_INVALID          = 0,
462   /* flags to control blocking */
463   GST_PAD_PROBE_TYPE_IDLE             = (1 << 0),
464   GST_PAD_PROBE_TYPE_BLOCK            = (1 << 1),
465   /* flags to select datatypes */
466   GST_PAD_PROBE_TYPE_BUFFER           = (1 << 4),
467   GST_PAD_PROBE_TYPE_BUFFER_LIST      = (1 << 5),
468   GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM = (1 << 6),
469   GST_PAD_PROBE_TYPE_EVENT_UPSTREAM   = (1 << 7),
470   GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM = (1 << 8),
471   GST_PAD_PROBE_TYPE_QUERY_UPSTREAM   = (1 << 9),
472   /* flags to select scheduling mode */
473   GST_PAD_PROBE_TYPE_PUSH             = (1 << 12),
474   GST_PAD_PROBE_TYPE_PULL             = (1 << 13),
475 } GstPadProbeType;
476
477 #define GST_PAD_PROBE_TYPE_BLOCKING         (GST_PAD_PROBE_TYPE_IDLE | GST_PAD_PROBE_TYPE_BLOCK)
478 #define GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM (GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM)
479 #define GST_PAD_PROBE_TYPE_BLOCK_UPSTREAM   (GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_DATA_UPSTREAM)
480 #define GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM  (GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST | \
481                                              GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)
482 #define GST_PAD_PROBE_TYPE_DATA_UPSTREAM    (GST_PAD_PROBE_TYPE_EVENT_UPSTREAM)
483 #define GST_PAD_PROBE_TYPE_DATA_BOTH        (GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM | \
484                                              GST_PAD_PROBE_TYPE_DATA_UPSTREAM)
485 #define GST_PAD_PROBE_TYPE_EVENT_BOTH       (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
486                                              GST_PAD_PROBE_TYPE_EVENT_UPSTREAM)
487 #define GST_PAD_PROBE_TYPE_QUERY_BOTH       (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM | \
488                                              GST_PAD_PROBE_TYPE_QUERY_UPSTREAM)
489 #define GST_PAD_PROBE_TYPE_ALL_BOTH         (GST_PAD_PROBE_TYPE_DATA_BOTH | \
490                                              GST_PAD_PROBE_TYPE_QUERY_BOTH)
491 #define GST_PAD_PROBE_TYPE_SCHEDULING       (GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_PULL)
492
493 /**
494  * GstPadProbeReturn:
495  * @GST_PAD_PROBE_OK: normal probe return value
496  * @GST_PAD_PROBE_DROP: drop data in data probes
497  * @GST_PAD_PROBE_REMOVE: remove probe
498  * @GST_PAD_PROBE_PASS: pass the data item in the block probe and block on
499  *                         the next item
500  *
501  * Different return values for the #GstPadProbeCallback.
502  */
503 typedef enum
504 {
505   GST_PAD_PROBE_DROP,
506   GST_PAD_PROBE_OK,
507   GST_PAD_PROBE_REMOVE,
508   GST_PAD_PROBE_PASS,
509 } GstPadProbeReturn;
510
511
512 /**
513  * GstPadProbeInfo:
514  * @type: the current probe type
515  * @data: type specific data, check the @type field to know the datatype.
516  *    This field can be NULL.
517  * @offset: offset of pull probe, this field is valid when @type contains
518  *    #GST_PAD_PROBE_TYPE_PULL
519  * @size: size of pull probe, this field is valid when @type contains
520  *    #GST_PAD_PROBE_TYPE_PULL
521  *
522  * Info passed in the #GstPadProbeCallback.
523  */
524 typedef struct
525 {
526   GstPadProbeType type;
527   gpointer data;
528   guint64 offset;
529   guint size;
530
531   gpointer _gst_reserved[GST_PADDING];
532 } GstPadProbeInfo;
533
534 #define GST_PAD_PROBE_INFO_TYPE(d)         ((d)->type)
535 #define GST_PAD_PROBE_INFO_DATA(d)         ((d)->data)
536
537 #define GST_PAD_PROBE_INFO_BUFFER(d)       GST_BUFFER_CAST(GST_PAD_PROBE_INFO_DATA(d))
538 #define GST_PAD_PROBE_INFO_BUFFER_LIST(d)  GST_BUFFER_LIST_CAST(GST_PAD_PROBE_INFO_DATA(d))
539 #define GST_PAD_PROBE_INFO_EVENT(d)        GST_EVENT_CAST(GST_PAD_PROBE_INFO_DATA(d))
540 #define GST_PAD_PROBE_INFO_QUERY(d)        GST_QUERY_CAST(GST_PAD_PROBE_INFO_DATA(d))
541
542 #define GST_PAD_PROBE_INFO_OFFSET(d)       ((d)->offset)
543 #define GST_PAD_PROBE_INFO_SIZE(d)         ((d)->size)
544
545 /**
546  * GstPadProbeCallback
547  * @pad: the #GstPad that is blocked
548  * @info: #GstPadProbeInfo
549  * @user_data: the gpointer to optional user data.
550  *
551  * Callback used by gst_pad_add_probe(). Gets called to notify about the current
552  * blocking type.
553  *
554  * The callback is allowed to modify the data pointer in @info.
555  */
556 typedef GstPadProbeReturn   (*GstPadProbeCallback)   (GstPad *pad, GstPadProbeInfo *info,
557                                                       gpointer user_data);
558
559 /**
560  * GstPadStickyEventsForeachFunction:
561  * @pad: the #GstPad.
562  * @event: a sticky #GstEvent.
563  * @user_data: the #gpointer to optional user data.
564  *
565  * Callback used by gst_pad_sticky_events_foreach().
566  *
567  * When this function returns %TRUE, the next event will be
568  * returned. When %FALSE is returned, gst_pad_sticky_events_foreach() will return.
569  *
570  * When @event is set to NULL, the item will be removed from the list of sticky events.
571  * When @event has been made writable, the new buffer reference can be assigned
572  * to @event. This function is responsible for unreffing the old event when
573  * removing or modifying.
574  *
575  * Returns: %TRUE if the iteration should continue
576  */
577 typedef gboolean  (*GstPadStickyEventsForeachFunction) (GstPad *pad, GstEvent **event,
578                                                         gpointer user_data);
579
580 /**
581  * GstPadFlags:
582  * @GST_PAD_FLAG_BLOCKED: is dataflow on a pad blocked
583  * @GST_PAD_FLAG_FLUSHING: is pad refusing buffers
584  * @GST_PAD_FLAG_BLOCKING: is pad currently blocking on a buffer or event
585  * @GST_PAD_FLAG_NEED_RECONFIGURE: the pad should be reconfigured/renegotiated.
586  *                            The flag has to be unset manually after
587  *                            reconfiguration happened.
588  *                            Since: 0.10.34.
589  * @GST_PAD_FLAG_PENDING_EVENTS: the pad has pending events
590  * @GST_PAD_FLAG_FIXED_CAPS: the pad is using fixed caps this means that once the
591  *                      caps are set on the pad, the caps query function only
592  *                      returns those caps.
593  * @GST_PAD_FLAG_PROXY_CAPS: the default event and query handler will forward
594  *                      all events and queries to the internally linked pads
595  *                      instead of discarding them.
596  * @GST_PAD_FLAG_NEED_PARENT: ensure that there is a parent object before calling
597  *                       into the pad callbacks.
598  * @GST_PAD_FLAG_LAST: offset to define more flags
599  *
600  * Pad state flags
601  */
602 typedef enum {
603   GST_PAD_FLAG_BLOCKED          = (GST_OBJECT_FLAG_LAST << 0),
604   GST_PAD_FLAG_FLUSHING         = (GST_OBJECT_FLAG_LAST << 1),
605   GST_PAD_FLAG_BLOCKING         = (GST_OBJECT_FLAG_LAST << 2),
606   GST_PAD_FLAG_NEED_RECONFIGURE = (GST_OBJECT_FLAG_LAST << 3),
607   GST_PAD_FLAG_PENDING_EVENTS   = (GST_OBJECT_FLAG_LAST << 4),
608   GST_PAD_FLAG_FIXED_CAPS       = (GST_OBJECT_FLAG_LAST << 5),
609   GST_PAD_FLAG_PROXY_CAPS       = (GST_OBJECT_FLAG_LAST << 6),
610   GST_PAD_FLAG_NEED_PARENT      = (GST_OBJECT_FLAG_LAST << 7),
611   /* padding */
612   GST_PAD_FLAG_LAST        = (GST_OBJECT_FLAG_LAST << 16)
613 } GstPadFlags;
614
615 /**
616  * GstPad:
617  * @element_private: private data owned by the parent element
618  * @padtemplate: padtemplate for this pad
619  * @direction: the direction of the pad, cannot change after creating
620  *             the pad.
621  *
622  * The #GstPad structure. Use the functions to update the variables.
623  */
624 struct _GstPad {
625   GstObject                      object;
626
627   /*< public >*/
628   gpointer                       element_private;
629
630   GstPadTemplate                *padtemplate;
631
632   GstPadDirection                direction;
633
634   /*< private >*/
635   /* streaming rec_lock */
636   GStaticRecMutex                stream_rec_lock;
637   GstTask                       *task;
638
639   /* block cond, mutex is from the object */
640   GCond                         *block_cond;
641   GHookList                      probes;
642
643   GstPadMode                     mode;
644   GstPadActivateFunction         activatefunc;
645   GDestroyNotify                 activatenotify;
646   GstPadActivateModeFunction     activatemodefunc;
647   GDestroyNotify                 activatemodenotify;
648
649   /* pad link */
650   GstPad                        *peer;
651   GstPadLinkFunction             linkfunc;
652   GDestroyNotify                 linknotify;
653   GstPadUnlinkFunction           unlinkfunc;
654   GDestroyNotify                 unlinknotify;
655
656   /* data transport functions */
657   GstPadChainFunction            chainfunc;
658   GDestroyNotify                 chainnotify;
659   GstPadChainListFunction        chainlistfunc;
660   GDestroyNotify                 chainlistnotify;
661   GstPadGetRangeFunction         getrangefunc;
662   GDestroyNotify                 getrangenotify;
663   GstPadEventFunction            eventfunc;
664   GDestroyNotify                 eventnotify;
665
666   /* pad offset */
667   gint64                         offset;
668
669   /* generic query method */
670   GstPadQueryFunction            queryfunc;
671   GDestroyNotify                 querynotify;
672
673   /* internal links */
674   GstPadIterIntLinkFunction      iterintlinkfunc;
675   GDestroyNotify                 iterintlinknotify;
676
677   /* counts number of probes attached. */
678   gint                           num_probes;
679   gint                           num_blocked;
680
681   GstPadPrivate                 *priv;
682
683   gpointer _gst_reserved[GST_PADDING];
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
693   /*< private >*/
694   gpointer _gst_reserved[GST_PADDING];
695 };
696
697
698 /***** helper macros *****/
699 /* GstPad */
700 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
701 #define GST_PAD_PARENT(pad)             (GST_ELEMENT_CAST(GST_OBJECT_PARENT(pad)))
702 #define GST_PAD_ELEMENT_PRIVATE(pad)    (GST_PAD_CAST(pad)->element_private)
703 #define GST_PAD_PAD_TEMPLATE(pad)       (GST_PAD_CAST(pad)->padtemplate)
704 #define GST_PAD_DIRECTION(pad)          (GST_PAD_CAST(pad)->direction)
705 #define GST_PAD_TASK(pad)               (GST_PAD_CAST(pad)->task)
706 #define GST_PAD_MODE(pad)               (GST_PAD_CAST(pad)->mode)
707
708 #define GST_PAD_ACTIVATEFUNC(pad)       (GST_PAD_CAST(pad)->activatefunc)
709 #define GST_PAD_ACTIVATEMODEFUNC(pad)   (GST_PAD_CAST(pad)->activatemodefunc)
710 #define GST_PAD_CHAINFUNC(pad)          (GST_PAD_CAST(pad)->chainfunc)
711 #define GST_PAD_CHAINLISTFUNC(pad)      (GST_PAD_CAST(pad)->chainlistfunc)
712 #define GST_PAD_GETRANGEFUNC(pad)       (GST_PAD_CAST(pad)->getrangefunc)
713 #define GST_PAD_EVENTFUNC(pad)          (GST_PAD_CAST(pad)->eventfunc)
714 #define GST_PAD_QUERYFUNC(pad)          (GST_PAD_CAST(pad)->queryfunc)
715 #define GST_PAD_ITERINTLINKFUNC(pad)    (GST_PAD_CAST(pad)->iterintlinkfunc)
716
717 #define GST_PAD_PEER(pad)               (GST_PAD_CAST(pad)->peer)
718 #define GST_PAD_LINKFUNC(pad)           (GST_PAD_CAST(pad)->linkfunc)
719 #define GST_PAD_UNLINKFUNC(pad)         (GST_PAD_CAST(pad)->unlinkfunc)
720
721 #define GST_PAD_IS_SRC(pad)             (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
722 #define GST_PAD_IS_SINK(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
723
724 #define GST_PAD_IS_LINKED(pad)          (GST_PAD_PEER(pad) != NULL)
725
726 #define GST_PAD_IS_ACTIVE(pad)          (GST_PAD_MODE(pad) != GST_PAD_MODE_NONE)
727
728 #define GST_PAD_IS_BLOCKED(pad)         (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED))
729 #define GST_PAD_IS_BLOCKING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKING))
730
731 #define GST_PAD_IS_FLUSHING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_FLUSHING))
732 #define GST_PAD_SET_FLUSHING(pad)       (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_FLUSHING))
733 #define GST_PAD_UNSET_FLUSHING(pad)     (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_FLUSHING))
734
735 #define GST_PAD_NEEDS_RECONFIGURE(pad)  (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE))
736 #define GST_PAD_HAS_PENDING_EVENTS(pad) (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_PENDING_EVENTS))
737 #define GST_PAD_IS_FIXED_CAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_FIXED_CAPS))
738 #define GST_PAD_NEEDS_PARENT(pad)       (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_NEED_PARENT))
739
740 #define GST_PAD_IS_PROXY_CAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_PROXY_CAPS))
741 #define GST_PAD_SET_PROXY_CAPS(pad)     (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PROXY_CAPS))
742 #define GST_PAD_UNSET_PROXY_CAPS(pad)   (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PROXY_CAPS))
743
744 /**
745  * GST_PAD_GET_STREAM_LOCK:
746  * @pad: a #GstPad
747  *
748  * Get the stream lock of @pad. The stream lock is protecting the
749  * resources used in the data processing functions of @pad.
750  */
751 #define GST_PAD_GET_STREAM_LOCK(pad)    (&(GST_PAD_CAST(pad)->stream_rec_lock))
752 /**
753  * GST_PAD_STREAM_LOCK:
754  * @pad: a #GstPad
755  *
756  * Lock the stream lock of @pad.
757  */
758 #define GST_PAD_STREAM_LOCK(pad)        (g_static_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad)))
759 /**
760  * GST_PAD_STREAM_TRYLOCK:
761  * @pad: a #GstPad
762  *
763  * Try to Lock the stream lock of the pad, return TRUE if the lock could be
764  * taken.
765  */
766 #define GST_PAD_STREAM_TRYLOCK(pad)     (g_static_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad)))
767 /**
768  * GST_PAD_STREAM_UNLOCK:
769  * @pad: a #GstPad
770  *
771  * Unlock the stream lock of @pad.
772  */
773 #define GST_PAD_STREAM_UNLOCK(pad)      (g_static_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad)))
774
775 #define GST_PAD_BLOCK_GET_COND(pad)     (GST_PAD_CAST(pad)->block_cond)
776 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_OBJECT_GET_LOCK (pad)))
777 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
778 #define GST_PAD_BLOCK_BROADCAST(pad)    (g_cond_broadcast(GST_PAD_BLOCK_GET_COND (pad)))
779
780 GType                   gst_pad_get_type                        (void);
781
782 /* creating pads */
783 GstPad*                 gst_pad_new                             (const gchar *name, GstPadDirection direction);
784 GstPad*                 gst_pad_new_from_template               (GstPadTemplate *templ, const gchar *name);
785 GstPad*                 gst_pad_new_from_static_template        (GstStaticPadTemplate *templ, const gchar *name);
786
787
788 /**
789  * gst_pad_get_name:
790  * @pad: the pad to get the name from
791  *
792  * Get a copy of the name of the pad. g_free() after usage.
793  *
794  * MT safe.
795  */
796 #define gst_pad_get_name(pad) gst_object_get_name (GST_OBJECT_CAST (pad))
797 /**
798  * gst_pad_get_parent:
799  * @pad: the pad to get the parent of
800  *
801  * Get the parent of @pad. This function increases the refcount
802  * of the parent object so you should gst_object_unref() it after usage.
803  * Can return NULL if the pad did not have a parent.
804  *
805  * MT safe.
806  */
807 #define gst_pad_get_parent(pad) gst_object_get_parent (GST_OBJECT_CAST (pad))
808
809 GstPadDirection         gst_pad_get_direction                   (GstPad *pad);
810
811 gboolean                gst_pad_set_active                      (GstPad *pad, gboolean active);
812 gboolean                gst_pad_is_active                       (GstPad *pad);
813 gboolean                gst_pad_activate_mode                   (GstPad *pad, GstPadMode mode,
814                                                                  gboolean active);
815
816 gulong                  gst_pad_add_probe                       (GstPad *pad,
817                                                                  GstPadProbeType mask,
818                                                                  GstPadProbeCallback callback,
819                                                                  gpointer user_data,
820                                                                  GDestroyNotify destroy_data);
821 void                    gst_pad_remove_probe                    (GstPad *pad, gulong id);
822
823 gboolean                gst_pad_is_blocked                      (GstPad *pad);
824 gboolean                gst_pad_is_blocking                     (GstPad *pad);
825
826 void                    gst_pad_mark_reconfigure                (GstPad *pad);
827 gboolean                gst_pad_check_reconfigure               (GstPad *pad);
828
829 void                    gst_pad_set_element_private             (GstPad *pad, gpointer priv);
830 gpointer                gst_pad_get_element_private             (GstPad *pad);
831
832 GstPadTemplate*         gst_pad_get_pad_template                (GstPad *pad);
833
834 GstEvent*               gst_pad_get_sticky_event                (GstPad *pad, GstEventType event_type,
835                                                                  guint idx);
836 void                    gst_pad_sticky_events_foreach           (GstPad *pad, GstPadStickyEventsForeachFunction foreach_func, gpointer user_data);
837
838 /* data passing setup functions */
839 void                    gst_pad_set_activate_function_full      (GstPad *pad,
840                                                                  GstPadActivateFunction activate,
841                                                                  GDestroyNotify notify);
842 void                    gst_pad_set_activatemode_function_full  (GstPad *pad,
843                                                                  GstPadActivateModeFunction activatemode,
844                                                                  GDestroyNotify notify);
845 /* data passing functions */
846 void                    gst_pad_set_chain_function_full         (GstPad *pad,
847                                                                  GstPadChainFunction chain,
848                                                                  GDestroyNotify notify);
849 void                    gst_pad_set_chain_list_function_full    (GstPad *pad,
850                                                                  GstPadChainListFunction chainlist,
851                                                                  GDestroyNotify notify);
852 void                    gst_pad_set_getrange_function_full      (GstPad *pad,
853                                                                  GstPadGetRangeFunction get,
854                                                                  GDestroyNotify notify);
855 void                    gst_pad_set_event_function_full         (GstPad *pad,
856                                                                  GstPadEventFunction event,
857                                                                  GDestroyNotify notify);
858
859 #define gst_pad_set_activate_function(p,f)      gst_pad_set_activate_function_full((p),(f),NULL)
860 #define gst_pad_set_activatemode_function(p,f)  gst_pad_set_activatemode_function_full((p),(f),NULL)
861 #define gst_pad_set_chain_function(p,f)         gst_pad_set_chain_function_full((p),(f),NULL)
862 #define gst_pad_set_chain_list_function(p,f)    gst_pad_set_chain_list_function_full((p),(f),NULL)
863 #define gst_pad_set_getrange_function(p,f)      gst_pad_set_getrange_function_full((p),(f),NULL)
864 #define gst_pad_set_event_function(p,f)         gst_pad_set_event_function_full((p),(f),NULL)
865
866 /* pad links */
867 void                    gst_pad_set_link_function_full          (GstPad *pad,
868                                                                  GstPadLinkFunction link,
869                                                                  GDestroyNotify notify);
870 void                    gst_pad_set_unlink_function_full        (GstPad *pad,
871                                                                  GstPadUnlinkFunction unlink,
872                                                                  GDestroyNotify notify);
873
874 #define gst_pad_set_link_function(p,f)          gst_pad_set_link_function_full((p),(f),NULL)
875 #define gst_pad_set_unlink_function(p,f)        gst_pad_set_unlink_function_full((p),(f),NULL)
876
877 gboolean                gst_pad_can_link                        (GstPad *srcpad, GstPad *sinkpad);
878 GstPadLinkReturn        gst_pad_link                            (GstPad *srcpad, GstPad *sinkpad);
879 GstPadLinkReturn        gst_pad_link_full                       (GstPad *srcpad, GstPad *sinkpad, GstPadLinkCheck flags);
880 gboolean                gst_pad_unlink                          (GstPad *srcpad, GstPad *sinkpad);
881 gboolean                gst_pad_is_linked                       (GstPad *pad);
882
883 GstPad*                 gst_pad_get_peer                        (GstPad *pad);
884
885 GstCaps*                gst_pad_get_pad_template_caps           (GstPad *pad);
886
887 /* capsnego function for linked/unlinked pads */
888 GstCaps *               gst_pad_get_current_caps                (GstPad * pad);
889 gboolean                gst_pad_has_current_caps                (GstPad * pad);
890 gboolean                gst_pad_set_caps                        (GstPad * pad, GstCaps *caps);
891
892 /* capsnego for linked pads */
893 GstCaps *               gst_pad_get_allowed_caps                (GstPad * pad);
894
895 /* pad offsets */
896 gint64                  gst_pad_get_offset                      (GstPad *pad);
897 void                    gst_pad_set_offset                      (GstPad *pad, gint64 offset);
898
899 /* data passing functions to peer */
900 GstFlowReturn           gst_pad_push                            (GstPad *pad, GstBuffer *buffer);
901 GstFlowReturn           gst_pad_push_list                       (GstPad *pad, GstBufferList *list);
902 GstFlowReturn           gst_pad_pull_range                      (GstPad *pad, guint64 offset, guint size,
903                                                                  GstBuffer **buffer);
904 gboolean                gst_pad_push_event                      (GstPad *pad, GstEvent *event);
905 gboolean                gst_pad_event_default                   (GstPad *pad, GstObject *parent,
906                                                                  GstEvent *event);
907
908 /* data passing functions on pad */
909 GstFlowReturn           gst_pad_chain                           (GstPad *pad, GstBuffer *buffer);
910 GstFlowReturn           gst_pad_chain_list                      (GstPad *pad, GstBufferList *list);
911 GstFlowReturn           gst_pad_get_range                       (GstPad *pad, guint64 offset, guint size,
912                                                                  GstBuffer **buffer);
913 gboolean                gst_pad_send_event                      (GstPad *pad, GstEvent *event);
914
915 /* pad tasks */
916 gboolean                gst_pad_start_task                      (GstPad *pad, GstTaskFunction func,
917                                                                  gpointer data);
918 gboolean                gst_pad_pause_task                      (GstPad *pad);
919 gboolean                gst_pad_stop_task                       (GstPad *pad);
920
921 /* internal links */
922 void                    gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
923                                                                  GstPadIterIntLinkFunction iterintlink,
924                                                                  GDestroyNotify notify);
925 GstIterator *           gst_pad_iterate_internal_links          (GstPad * pad);
926 GstIterator *           gst_pad_iterate_internal_links_default  (GstPad * pad, GstObject *parent);
927
928 #define gst_pad_set_iterate_internal_links_function(p,f) gst_pad_set_iterate_internal_links_function_full((p),(f),NULL)
929
930 /* generic query function */
931 gboolean                gst_pad_query                           (GstPad *pad, GstQuery *query);
932 gboolean                gst_pad_peer_query                      (GstPad *pad, GstQuery *query);
933 void                    gst_pad_set_query_function_full         (GstPad *pad, GstPadQueryFunction query,
934                                                                  GDestroyNotify notify);
935 gboolean                gst_pad_query_default                   (GstPad *pad, GstObject *parent,
936                                                                  GstQuery *query);
937
938 #define gst_pad_set_query_function(p,f)   gst_pad_set_query_function_full((p),(f),NULL)
939
940 /* misc helper functions */
941 gboolean                gst_pad_forward                         (GstPad *pad, GstPadForwardFunction forward,
942                                                                  gpointer user_data);
943
944 G_END_DECLS
945
946 #endif /* __GST_PAD_H__ */