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