diff --git a/ChangeLog b/ChangeLog index 79533bc45e..df773dde93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2005-09-25 Stefan Kost + + * docs/gst/gstreamer-sections.txt: + * docs/gst/tmpl/.cvsignore: + * docs/gst/tmpl/gstpad.sgml: + * docs/gst/tmpl/gstpadtemplate.sgml: + * gst/Makefile.am: + * gst/gstpad.c: (gst_pad_class_init), (gst_pad_dispose), + (gst_pad_finalize), (gst_pad_set_pad_template): + * gst/gstpad.h: + * gst/gstpadtemplate.c: (gst_pad_template_get_type), + (gst_pad_template_class_init), (gst_pad_template_init), + (gst_pad_template_dispose), (name_is_valid), + (gst_static_pad_template_get), (gst_pad_template_new), + (gst_static_pad_template_get_caps), (gst_pad_template_get_caps), + (gst_pad_template_pad_created): + * gst/gstpadtemplate.h: + inlined two more docs + factored gstpadtemplate out of gstpad + 2005-09-24 Tim-Philipp Müller * check/gst/gstbin.c: (test_children_state_change_order_flagged_sink), diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 4dd6a2ebf0..d46c813d44 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -1137,7 +1137,6 @@ GstPadDispatcherFunction GstPadDirection GstPadFlags GstPadLinkReturn -GstPadPresence GstFlowReturn GstActivateMode @@ -1297,7 +1296,6 @@ GST_PAD_SET_FLUSHING GST_PAD_TASK GST_PAD_UNSET_FLUSHING - GST_PAD_ACCEPTCAPSFUNC GST_PAD_ACTIVATEFUNC GST_PAD_ACTIVATEPULLFUNC @@ -1331,10 +1329,12 @@ GST_PAD_TEMPLATE_PRESENCE GST_PAD_TEMPLATE_CAPS GST_PAD_TEMPLATE_IS_FIXED GstPadTemplateFlags +GstPadPresence gst_pad_template_new gst_static_pad_template_get gst_static_pad_template_get_caps gst_pad_template_get_caps + GstPadTemplateClass GST_PAD_TEMPLATE @@ -1344,9 +1344,11 @@ GST_IS_PAD_TEMPLATE_CLASS GST_STATIC_PAD_TEMPLATE GST_TYPE_PAD_TEMPLATE GST_TYPE_PAD_TEMPLATE_FLAGS + gst_pad_template_get_type gst_pad_template_flags_get_type +gst_pad_template_pad_created diff --git a/docs/gst/tmpl/.gitignore b/docs/gst/tmpl/.gitignore index acf2fa0e7a..af468c14c1 100644 --- a/docs/gst/tmpl/.gitignore +++ b/docs/gst/tmpl/.gitignore @@ -38,6 +38,8 @@ gstmemchunk.sgml gstmessage.sgml gstminiobject.sgml gstobject.sgml +gstpad.sgml +gstpadtemplate.sgml gstparse.sgml gstpluginfeature.sgml gstpushsrc.sgml diff --git a/docs/gst/tmpl/gstpad.sgml b/docs/gst/tmpl/gstpad.sgml deleted file mode 100644 index 857f223d61..0000000000 --- a/docs/gst/tmpl/gstpad.sgml +++ /dev/null @@ -1,1338 +0,0 @@ - -GstPad - - -Object contained by elements that allows links to other elements - - - -A #GstElement is linked to other elements via "pads", which are extremely -light-weight generic link points. -After two pads are retrieved from an element with gst_element_get_pad(), -the pads can be link with gst_pad_link(). (For quick links, -you can also use gst_element_link(), which will make the obvious -link for you if it's straightforward.) - - -Pads are typically created from a #GstPadTemplate with -gst_pad_new_from_template(). - - -Pads have #GstCaps attached to it to describe the media type they -are capable of dealing with. -gst_pad_get_caps() and gst_pad_try_set_caps() are used to -manipulate the caps of the pads. -Pads created from a pad template cannot set capabilities that are -incompatible with the pad template capabilities. - - -Pads without pad templates can be created with gst_pad_new(), -which takes a direction and a name as an argument. If the name is NULL, -then a guaranteed unique name will be assigned to it. - - -gst_pad_get_parent() will retrieve the #GstElement that owns the pad. - - -A #GstElement creating a pad will typically use the various -gst_pad_set_*_function() calls to register callbacks for various events -on the pads. - - -GstElements will use gst_pad_push() and gst_pad_pull() to push out -or pull in a buffer. -gst_pad_select() and gst_pad_selectv() are used by plugins to wait for the -first incoming buffer or event on any of the given set of pads. - - -To send a #GstEvent on a pad, use gst_pad_send_event(). - - - -Last reviewed on December 13th, 2002 (0.5.0.1) - - - - -#GstPadTemplate, #GstElement, #GstEvent - - - - - - - - - - -@stream_rec_lock: -@task: -@preroll_lock: -@preroll_cond: -@block_cond: -@block_callback: -@block_data: -@caps: -@getcapsfunc: -@setcapsfunc: -@acceptcapsfunc: -@fixatecapsfunc: -@activatefunc: -@activatepushfunc: -@activatepullfunc: -@linkfunc: -@unlinkfunc: -@peer: -@sched_private: -@chainfunc: -@checkgetrangefunc: -@getrangefunc: -@eventfunc: -@mode: -@querytypefunc: -@queryfunc: -@intlinkfunc: -@bufferallocfunc: -@do_buffer_signals: -@do_event_signals: - - - - - - -@gstpad: the object which received the signal. -@arg1: -@Returns: - - - - - - -@gstpad: the object which received the signal. -@arg1: - - - - - - -@gstpad: the object which received the signal. - - - - - - -@gstpad: the object which received the signal. -@arg1: - - - - - - - - - - - - - - - - - - -Macro to test if the given #GstPadLinkReturn value indicates a -failed negotiation step (REFUSED/DELAYED). - - -@ret: the #GstPadLinkReturn value - - - - -Macro to test if the given #GstPadLinkReturn value indicates a -successfull negotiation step (OK/DONE). - - -@ret: the #GstPadLinkReturn value - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@active: -@Returns: - - - - - - - -@pad: -@blocked: -@user_data: - - - - -A function that will be called when chaining buffers. - - -@pad: the #GstPad that performed the chain. -@buffer: -@Returns: - -@data: -@buf: the #GstBuffer that is chained. - - - - -Function signature to handle an event for the pad. - - -@pad: the #GstPad to handle the event. -@event: the #GstEvent to handle. -@Returns: TRUE if the pad could handle the event. - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@offset: -@length: -@buffer: -@Returns: - - - - -The signature of the query function. - - -@pad: the #GstPad to query. -@query: -@Returns: TRUE if the query could be performed. - -@type: the #GstPadQueryType. -@format: a pointer to the target #GstFormat. -@value: a pointer to the target value. - - - - -The signature of the internal pad link function. - - -@pad: The #GstPad to query. -@Returns: a newly allocated #GList of pads that are linked to - the given pad on the inside of the parent element. - The caller must call g_list_free() on it after use. - - - - -The signature of the query types function. - - -@pad: a #GstPad to query -@Returns: an array of query types - - - - -Function signature to handle a new link on the pad. - - -@pad: the #GstPad that is linked. -@peer: -@Returns: the result of the link with the specified caps. - -@caps: the peer's #GstCaps. - - - - - - - -@pad: - - - - - - - -@pad: -@caps: -@Returns: - - - - - - - -@pad: -@caps: - - - - -Returns a copy of the capabilities of the specified pad. By default this -function will return the pad template capabilities, but can optionally -be overridden. - - -@pad: the #GstPad to get the capabilities of. -@Returns: a newly allocated copy #GstCaps of the pad. - -@caps: the peer's #GstCaps, can be used to filter the capabilities. - - - - - - - -@pad: -@caps: -@Returns: - - - - - - - -@pad: -@offset: -@size: -@caps: -@buf: -@Returns: - - - - -A dispatcher function is called for all internally linked pads, see -gst_pad_dispatcher(). - - -@pad: the #GstPad that is dispatched. -@data: the gpointer to optional user data. -@Returns: TRUE if the dispatching procedure has to be stopped. - - - - -The direction of a pad. - - -@GST_PAD_UNKNOWN: direction is unknown. -@GST_PAD_SRC: the pad is a source pad. -@GST_PAD_SINK: the pad is a sink pad. - - - - - - -@GST_PAD_BLOCKED: -@GST_PAD_FLUSHING: -@GST_PAD_IN_GETCAPS: -@GST_PAD_IN_SETCAPS: -@GST_PAD_FLAG_LAST: - - - - -@GST_PAD_LINK_OK: -@GST_PAD_LINK_WRONG_HIERARCHY: -@GST_PAD_LINK_WAS_LINKED: -@GST_PAD_LINK_WRONG_DIRECTION: -@GST_PAD_LINK_NOFORMAT: -@GST_PAD_LINK_NOSCHED: -@GST_PAD_LINK_REFUSED: - - - -Indicates when this pad will become available. - - -@GST_PAD_ALWAYS: the pad is always available -@GST_PAD_SOMETIMES: the pad will become available depending on the media stream -@GST_PAD_REQUEST: the pad is only available on request with -gst_element_request_pad_by_name() or gst_element_request_compatible_pad(). - - - - - - -@GST_FLOW_RESEND: -@GST_FLOW_OK: -@GST_FLOW_NOT_LINKED: -@GST_FLOW_WRONG_STATE: -@GST_FLOW_UNEXPECTED: -@GST_FLOW_NOT_NEGOTIATED: -@GST_FLOW_ERROR: -@GST_FLOW_NOT_SUPPORTED: - - - - - - -@GST_ACTIVATE_NONE: -@GST_ACTIVATE_PUSH: -@GST_ACTIVATE_PULL: - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@pad: -@timeval: - - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@pad: -@t: - - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@pad: - - - - - - - -@ret: - - - - - - - -@name: -@direction: -@Returns: - - - - - - - -@templ: -@name: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@active: -@Returns: - -@mode: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@blocked: -@Returns: - - - - - - - -@pad: -@blocked: -@callback: -@user_data: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@priv: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@bufalloc: - -@bufferalloc: - - - - - - - -@pad: -@offset: -@size: -@caps: -@buf: -@Returns: - - - - - - - -@pad: -@chain: - - - - - - - -@pad: -@buffer: -@Returns: - - - - - - - -@pad: -@check: - - - - - - - -@pad: -@get: - - - - - - - -@pad: -@offset: -@size: -@buffer: -@Returns: - - - - - - - -@pad: -@event: - - - - - - - -@pad: -@unlink: - - - - - - - -@pad: -@activate: - - - - - - - -@pad: -@activatepull: - - - - - - - -@pad: -@func: -@data: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@srcpad: -@sinkpad: -@Returns: - - - - - - - -@srcpad: -@sinkpad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@link: - - - - - - - -@srcpad: -@sinkpad: -@Returns: - - - - - - - -@pad: -@caps: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@caps: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@acceptcaps: - - - - - - - -@pad: -@getcaps: - - - - - - - -@pad: -@setcaps: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@caps: -@Returns: - - - - - - - -@srcpad: -@Returns: - -@pad: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@caps: -@Returns: - - - - - - - -@pad: - - - - - - - -@pad: -@caps: - - - - - - - -@pad: -@fixatecaps: - - - - - - - -@pad: -@activatepush: - - - - - - - -@pad: -@buffer: -@Returns: - -@data: -@buf: - - - - - - - -@pad: -@event: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@offset: -@size: -@buffer: -@Returns: - - - - - - - -@pad: -@active: -@Returns: - - - - - - - -@pad: -@active: -@Returns: - - - - - - - -@pad: -@event: -@Returns: - - - - - - - -@pad: -@event: -@Returns: - - - - - - - -@pad: -@query: - - - - - - - -@pad: -@type_func: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@query: -@Returns: - -@type: -@format: -@value: - - - - - - - -@pad: -@query: -@Returns: - -@type: -@format: -@value: - - - - - - - -@pad: -@format: -@cur: -@end: -@Returns: - - - - - - - -@pad: -@src_format: -@src_val: -@dest_format: -@dest_val: -@Returns: - -@dest_fmt: - - - - - - - -@pad: -@intlink: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@Returns: - - - - - - - -@pad: -@dispatch: -@data: -@Returns: - - - - - - - -@self: -@parent: - - - - - - - -@pad: -@handler: -@data: -@Returns: - - - - - - - -@pad: -@handler: -@data: -@Returns: - - - - - - - -@pad: -@handler: -@data: -@Returns: - - - - - - - -@pad: -@handler_id: - -@handler: -@data: - - - - - - - -@pad: -@handler_id: - -@handler: -@data: - - - - - - - -@pad: -@handler_id: - -@handler: -@data: - - diff --git a/docs/gst/tmpl/gstpadtemplate.sgml b/docs/gst/tmpl/gstpadtemplate.sgml deleted file mode 100644 index 117ebb677e..0000000000 --- a/docs/gst/tmpl/gstpadtemplate.sgml +++ /dev/null @@ -1,202 +0,0 @@ - -GstPadTemplate - - -Describe the media type of a pad. - - - -Padtemplates describe the possible media types a pad or an elementfactory can -handle. - - -Pad and PadTemplates have #GstCaps attached to it to describe the media type they -are capable of dealing with. gst_pad_template_get_caps() is used to get the -caps of a padtemplate. It's not possible to modify the caps of a padtemplate after -creation. - - -Padtemplates can be created with gst_pad_template_new() or with the convenient -GST_PAD_TEMPLATE_FACTORY() macro. A padtemplate can be used to create a pad or -to add to an elementfactory. - - -The following code example shows the code to create a pad from a padtemplate. - -Create a pad from a padtemplate - - GstStaticPadTemplate my_template = - GST_STATIC_PAD_TEMPLATE ( - "sink", /* the name of the pad */ - GST_PAD_SINK, /* the direction of the pad */ - GST_PAD_ALWAYS, /* when this pad will be present */ - GST_STATIC_CAPS ( /* the capabilities of the padtemplate */ - "audio/x-raw-int, " - "channels = (int) [ 1, 6 ]" - ) - ) - - void - my_method (void) - { - GstPad *pad; - - pad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (my_template_factory), "sink"); - ... - } - - - - -The following example shows you how to add the padtemplate to an elementfactory: - - gboolean - my_factory_init (GstPlugin *plugin) - { - GstElementFactory *factory; - - factory = gst_element_factory_new ("my_factory", GST_TYPE_MYFACTORY, &gst_myfactory_details); - g_return_val_if_fail (factory != NULL, FALSE); - - gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (my_template_factory)); - - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); - - return TRUE; - } - - - - - - -#GstPad, #GstElementFactory - - - - - - - -The padtemplate object. - - - - - -This signal is fired when an element creates a pad from this -template. - - -@gstpadtemplate: the object which received the signal. -@arg1: The pad that was created. - - - - - - -@name_template: -@direction: -@presence: -@static_caps: - - - - - - -@obj: - - - - -Get the nametemplate of the padtemplate. - - -@templ: the template to query - - - - -Get the direction of the padtemplate. - - -@templ: the template to query - - - - -Get the presence of the padtemplate. - - -@templ: the template to query - - - - -Get a handle to the padtemplate #GstCaps - - -@templ: the template to query - - - - -Check if the properties of the padtemplate are fixed - - -@templ: the template to query - - - - -Flags for the padtemplate - - -@GST_PAD_TEMPLATE_FIXED: the padtemplate has no variable properties -@GST_PAD_TEMPLATE_FLAG_LAST: first flag that can be used by subclasses. - - - - - - -@name_template: -@direction: -@presence: -@caps: -@Returns: - -@Varargs: - - - - - - - -@pad_template: -@Returns: - -@templ: - - - - - - - -@templ: -@Returns: - - - - - - - -@templ: -@Returns: - - diff --git a/gst/Makefile.am b/gst/Makefile.am index de9037ac0c..549bda9975 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -91,6 +91,7 @@ libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \ gstmessage.c \ gstminiobject.c \ gstpad.c \ + gstpadtemplate.c \ gstpipeline.c \ gstplugin.c \ gstpluginfeature.c \ @@ -168,6 +169,7 @@ gst_headers = \ gstmessage.h \ gstminiobject.h \ gstpad.h \ + gstpadtemplate.h \ gstpipeline.h \ gstplugin.h \ gstpluginfeature.h \ diff --git a/gst/gstpad.c b/gst/gstpad.c index 6fe5151d85..9f5263b11f 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -19,10 +19,52 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ +/** + * SECTION:gstpad + * @short_description: Object contained by elements that allows links to other elements + * @see_also: #GstPadTemplate, #GstElement, #GstEvent + * + * A #GstElement is linked to other elements via "pads", which are extremely + * light-weight generic link points. + * After two pads are retrieved from an element with gst_element_get_pad(), + * the pads can be link with gst_pad_link(). (For quick links, + * you can also use gst_element_link(), which will make the obvious + * link for you if it's straightforward.) + * + * Pads are typically created from a #GstPadTemplate with + * gst_pad_new_from_template(). + * + * Pads have #GstCaps attached to it to describe the media type they are capable + * of dealing with. + * gst_pad_get_caps() and gst_pad_try_set_caps() are used to manipulate the caps + * of the pads. + * Pads created from a pad template cannot set capabilities that are + * incompatible with the pad template capabilities. + * + * Pads without pad templates can be created with gst_pad_new(), + * which takes a direction and a name as an argument. If the name is NULL, + * then a guaranteed unique name will be assigned to it. + * + * gst_pad_get_parent() will retrieve the #GstElement that owns the pad. + * + * A #GstElement creating a pad will typically use the various + * gst_pad_set_*_function() calls to register callbacks for various events + * on the pads. + * + * GstElements will use gst_pad_push() and gst_pad_pull() to push out + * or pull in a buffer. + * gst_pad_select() and gst_pad_selectv() are used by plugins to wait for the + * first incoming buffer or event on any of the given set of pads. + * + * To send a #GstEvent on a pad, use gst_pad_send_event(). + * + * Last reviewed on December 13th, 2002 (0.5.0.1) + */ #include "gst_private.h" #include "gstpad.h" +#include "gstpadtemplate.h" #include "gstenumtypes.h" #include "gstmarshal.h" #include "gstutils.h" @@ -44,16 +86,6 @@ GST_DEBUG_CATEGORY_STATIC (debug_dataflow); }G_STMT_END #define GST_CAT_DEFAULT GST_CAT_PADS -enum -{ - TEMPL_PAD_CREATED, - /* FILL ME */ - TEMPL_LAST_SIGNAL -}; - -static GstObject *padtemplate_parent_class = NULL; -static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 }; - /* Pad signals and args */ enum { @@ -62,7 +94,7 @@ enum PAD_REQUEST_LINK, PAD_HAVE_DATA, /* FILL ME */ - PAD_LAST_SIGNAL + LAST_SIGNAL }; enum @@ -93,8 +125,8 @@ static gboolean gst_pad_activate_default (GstPad * pad); static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent); #endif -static GstObjectClass *pad_parent_class = NULL; -static guint gst_pad_signals[PAD_LAST_SIGNAL] = { 0 }; +static GstObjectClass *parent_class = NULL; +static guint gst_pad_signals[LAST_SIGNAL] = { 0 }; static GQuark buffer_quark; static GQuark event_quark; @@ -152,7 +184,7 @@ gst_pad_class_init (GstPadClass * klass) gobject_class = (GObjectClass *) klass; gstobject_class = (GstObjectClass *) klass; - pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT); + parent_class = g_type_class_ref (GST_TYPE_OBJECT); gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose); gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_pad_finalize); @@ -295,7 +327,7 @@ gst_pad_dispose (GObject * object) gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad); } - G_OBJECT_CLASS (pad_parent_class)->dispose (object); + G_OBJECT_CLASS (parent_class)->dispose (object); } static void @@ -327,7 +359,7 @@ gst_pad_finalize (GObject * object) pad->block_cond = NULL; } - G_OBJECT_CLASS (pad_parent_class)->finalize (object); + G_OBJECT_CLASS (parent_class)->finalize (object); } static void @@ -1628,11 +1660,8 @@ gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ) gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ); GST_UNLOCK (pad); - if (templ) { - gst_object_sink (GST_OBJECT (templ)); - g_signal_emit (G_OBJECT (templ), - gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad); - } + if (templ) + gst_pad_template_pad_created (templ, pad); } /** @@ -3487,220 +3516,6 @@ dropping: } } -/************************************************************************ - * - * templates - * - */ -static void gst_pad_template_class_init (GstPadTemplateClass * klass); -static void gst_pad_template_init (GstPadTemplate * templ); -static void gst_pad_template_dispose (GObject * object); - -GType -gst_pad_template_get_type (void) -{ - static GType padtemplate_type = 0; - - if (!padtemplate_type) { - static const GTypeInfo padtemplate_info = { - sizeof (GstPadTemplateClass), NULL, NULL, - (GClassInitFunc) gst_pad_template_class_init, NULL, NULL, - sizeof (GstPadTemplate), - 0, - (GInstanceInitFunc) gst_pad_template_init, NULL - }; - - padtemplate_type = - g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate", - &padtemplate_info, 0); - } - return padtemplate_type; -} - -static void -gst_pad_template_class_init (GstPadTemplateClass * klass) -{ - GObjectClass *gobject_class; - GstObjectClass *gstobject_class; - - gobject_class = (GObjectClass *) klass; - gstobject_class = (GstObjectClass *) klass; - - padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT); - - gst_pad_template_signals[TEMPL_PAD_CREATED] = - g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstPadTemplateClass, pad_created), - NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD); - - gobject_class->dispose = gst_pad_template_dispose; - - gstobject_class->path_string_separator = "*"; -} - -static void -gst_pad_template_init (GstPadTemplate * templ) -{ -} - -static void -gst_pad_template_dispose (GObject * object) -{ - GstPadTemplate *templ = GST_PAD_TEMPLATE (object); - - g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ)); - if (GST_PAD_TEMPLATE_CAPS (templ)) { - gst_caps_unref (GST_PAD_TEMPLATE_CAPS (templ)); - } - - G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object); -} - -/* ALWAYS padtemplates cannot have conversion specifications (like src_%d), - * since it doesn't make sense. - * SOMETIMES padtemplates can do whatever they want, they are provided by the - * element. - * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the - * 'sink%d' template is automatically selected), so we need to restrict their - * naming. - */ -static gboolean -name_is_valid (const gchar * name, GstPadPresence presence) -{ - const gchar *str; - - if (presence == GST_PAD_ALWAYS) { - if (strchr (name, '%')) { - g_warning ("invalid name template %s: conversion specifications are not" - " allowed for GST_PAD_ALWAYS padtemplates", name); - return FALSE; - } - } else if (presence == GST_PAD_REQUEST) { - if ((str = strchr (name, '%')) && strchr (str + 1, '%')) { - g_warning ("invalid name template %s: only one conversion specification" - " allowed in GST_PAD_REQUEST padtemplate", name); - return FALSE; - } - if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) { - g_warning ("invalid name template %s: conversion specification must be of" - " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name); - return FALSE; - } - if (str && (*(str + 2) != '\0')) { - g_warning ("invalid name template %s: conversion specification must" - " appear at the end of the GST_PAD_REQUEST padtemplate name", name); - return FALSE; - } - } - - return TRUE; -} - -/** - * gst_static_pad_template_get: - * @pad_template: the static pad template - * - * Converts a #GstStaticPadTemplate into a #GstPadTemplate. - * - * Returns: a new #GstPadTemplate. - */ -GstPadTemplate * -gst_static_pad_template_get (GstStaticPadTemplate * pad_template) -{ - GstPadTemplate *new; - - if (!name_is_valid (pad_template->name_template, pad_template->presence)) - return NULL; - - new = g_object_new (gst_pad_template_get_type (), - "name", pad_template->name_template, NULL); - - GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template); - GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction; - GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence; - - GST_PAD_TEMPLATE_CAPS (new) = - gst_caps_copy (gst_static_caps_get (&pad_template->static_caps)); - - return new; -} - -/** - * gst_pad_template_new: - * @name_template: the name template. - * @direction: the #GstPadDirection of the template. - * @presence: the #GstPadPresence of the pad. - * @caps: a #GstCaps set for the template. The caps are taken ownership of. - * - * Creates a new pad template with a name according to the given template - * and with the given arguments. This functions takes ownership of the provided - * caps, so be sure to not use them afterwards. - * - * Returns: a new #GstPadTemplate. - */ -GstPadTemplate * -gst_pad_template_new (const gchar * name_template, - GstPadDirection direction, GstPadPresence presence, GstCaps * caps) -{ - GstPadTemplate *new; - - g_return_val_if_fail (name_template != NULL, NULL); - g_return_val_if_fail (caps != NULL, NULL); - g_return_val_if_fail (direction == GST_PAD_SRC - || direction == GST_PAD_SINK, NULL); - g_return_val_if_fail (presence == GST_PAD_ALWAYS - || presence == GST_PAD_SOMETIMES || presence == GST_PAD_REQUEST, NULL); - - if (!name_is_valid (name_template, presence)) { - gst_caps_unref (caps); - return NULL; - } - - new = g_object_new (gst_pad_template_get_type (), - "name", name_template, NULL); - - GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template); - GST_PAD_TEMPLATE_DIRECTION (new) = direction; - GST_PAD_TEMPLATE_PRESENCE (new) = presence; - GST_PAD_TEMPLATE_CAPS (new) = caps; - - return new; -} - -/** - * gst_static_pad_template_get_caps: - * @templ: a #GstStaticPadTemplate to get capabilities of. - * - * Gets the capabilities of the static pad template. - * - * Returns: the #GstCaps of the static pad template. If you need to keep a - * reference to the caps, take a ref (see gst_caps_ref ()). - */ -GstCaps * -gst_static_pad_template_get_caps (GstStaticPadTemplate * templ) -{ - g_return_val_if_fail (templ, NULL); - - return (GstCaps *) gst_static_caps_get (&templ->static_caps); -} - -/** - * gst_pad_template_get_caps: - * @templ: a #GstPadTemplate to get capabilities of. - * - * Gets the capabilities of the pad template. - * - * Returns: the #GstCaps of the pad template. If you need to keep a reference to - * the caps, take a ref (see gst_caps_ref ()). - */ -GstCaps * -gst_pad_template_get_caps (GstPadTemplate * templ) -{ - g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL); - - return GST_PAD_TEMPLATE_CAPS (templ); -} - /** * gst_pad_set_element_private: * @pad: the #GstPad to set the private data of. diff --git a/gst/gstpad.h b/gst/gstpad.h index aa87e05cf3..06ea19a2d5 100644 --- a/gst/gstpad.h +++ b/gst/gstpad.h @@ -52,10 +52,6 @@ GST_EXPORT GType _gst_pad_type; typedef struct _GstPad GstPad; typedef struct _GstPadClass GstPadClass; -typedef struct _GstPadTemplate GstPadTemplate; -typedef struct _GstPadTemplateClass GstPadTemplateClass; -typedef struct _GstStaticPadTemplate GstStaticPadTemplate; - /** * GstPadLinkReturn: * @GST_PAD_LINK_OK : link succeeded @@ -76,7 +72,22 @@ typedef enum { GST_PAD_LINK_REFUSED = -6, } GstPadLinkReturn; +/** + * GST_PAD_LINK_FAILED: + * @ret: the #GstPadLinkReturn value + * + * Macro to test if the given #GstPadLinkReturn value indicates a failed + * negotiation step (REFUSED/DELAYED). + */ #define GST_PAD_LINK_FAILED(ret) ((ret) < GST_PAD_LINK_OK) + +/** + * GST_PAD_LINK_SUCCESSFUL: + * @ret: the #GstPadLinkReturn value + * + * Macro to test if the given #GstPadLinkReturn value indicates a successfull + * negotiation step (OK/DONE). + */ #define GST_PAD_LINK_SUCCESSFUL(ret) ((ret) >= GST_PAD_LINK_OK) typedef enum { @@ -106,38 +117,136 @@ typedef enum { typedef gboolean (*GstPadActivateFunction) (GstPad *pad); typedef gboolean (*GstPadActivateModeFunction) (GstPad *pad, gboolean active); + /* data passing */ +/** + * GstPadChainFunction: + * @pad: the #GstPad that performed the chain. + * @buffer: the #GstBuffer that is chained. + * + * A function that will be called when chaining buffers. + * + * + */ typedef GstFlowReturn (*GstPadChainFunction) (GstPad *pad, GstBuffer *buffer); typedef GstFlowReturn (*GstPadGetRangeFunction) (GstPad *pad, guint64 offset, guint length, GstBuffer **buffer); + +/** + * GstPadEventFunction: + * @pad: the #GstPad to handle the event. + * @event: the #GstEvent to handle. + * + * Function signature to handle an event for the pad. + * + * Returns: TRUE if the pad could handle the event. + */ typedef gboolean (*GstPadEventFunction) (GstPad *pad, GstEvent *event); + /* deprecate me, check range should use seeking query */ typedef gboolean (*GstPadCheckGetRangeFunction) (GstPad *pad); + /* internal links */ +/** + * GstPadIntLinkFunction: + * @pad: The #GstPad to query. + * + * The signature of the internal pad link function. + * + * Returns: a newly allocated #GList of pads that are linked to the given pad on + * the inside of the parent element. + * The caller must call g_list_free() on it after use. + * + */ typedef GList* (*GstPadIntLinkFunction) (GstPad *pad); + /* generic query function */ +/** + * GstPadQueryTypeFunction: + * @pad: a #GstPad to query + * + * The signature of the query types function. + * + * Returns: an array of query types + */ typedef const GstQueryType* (*GstPadQueryTypeFunction) (GstPad *pad); + +/** + * GstPadQueryFunction: + * @pad: the #GstPad to query. + * @query: the #GstQuery object to execute + * + * The signature of the query function. + * + * Returns: TRUE if the query could be performed. + */ typedef gboolean (*GstPadQueryFunction) (GstPad *pad, GstQuery *query); + /* linking */ +/** + * GstPadLinkFunction + * @pad: the #GstPad that is linked. + * @peer: the peer #GstPad of the link + * + * Function signature to handle a new link on the pad. + * + * Returns: the result of the link with the specified peer. + */ typedef GstPadLinkReturn (*GstPadLinkFunction) (GstPad *pad, GstPad *peer); +/** + * GstPadUnlinkFunction + * @pad: the #GstPad that is linked. + * + * Function signature to handle a unlinking the pad prom its peer. + */ typedef void (*GstPadUnlinkFunction) (GstPad *pad); + /* caps nego */ +/** + * GstPadGetCapsFunction: + * @pad: the #GstPad to get the capabilities of. + * + * Returns a copy of the capabilities of the specified pad. By default this + * function will return the pad template capabilities, but can optionally + * be overridden. + * + * Returns: a newly allocated copy #GstCaps of the pad. + */ typedef GstCaps* (*GstPadGetCapsFunction) (GstPad *pad); typedef gboolean (*GstPadSetCapsFunction) (GstPad *pad, GstCaps *caps); typedef gboolean (*GstPadAcceptCapsFunction) (GstPad *pad, GstCaps *caps); typedef void (*GstPadFixateCapsFunction) (GstPad *pad, GstCaps *caps); typedef GstFlowReturn (*GstPadBufferAllocFunction) (GstPad *pad, guint64 offset, guint size, GstCaps *caps, GstBuffer **buf); + /* misc */ +/** + * GstPadDispatcherFunction: + * @pad: the #GstPad that is dispatched. + * @data: the gpointer to optional user data. + * + * A dispatcher function is called for all internally linked pads, see + * gst_pad_dispatcher(). + * + * Returns: TRUE if the dispatching procedure has to be stopped. + */ typedef gboolean (*GstPadDispatcherFunction) (GstPad *pad, gpointer data); typedef void (*GstPadBlockCallback) (GstPad *pad, gboolean blocked, gpointer user_data); +/** + * GstPadDirection: + * @GST_PAD_UNKNOWN: direction is unknown. + * @GST_PAD_SRC: the pad is a source pad. + * @GST_PAD_SINK: the pad is a sink pad. + * + * The direction of a pad. + */ typedef enum { GST_PAD_UNKNOWN, GST_PAD_SRC, @@ -153,6 +262,9 @@ typedef enum { GST_PAD_FLAG_LAST = GST_OBJECT_FLAG_LAST + 8 } GstPadFlags; +/* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */ +typedef struct _GstPadTemplate GstPadTemplate; + struct _GstPad { GstObject object; @@ -306,67 +418,8 @@ struct _GstPadClass { #define GST_PAD_BLOCK_WAIT(pad) (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_GET_LOCK (pad))) #define GST_PAD_BLOCK_SIGNAL(pad) (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad))) -/***** PadTemplate *****/ -#define GST_TYPE_PAD_TEMPLATE (gst_pad_template_get_type ()) -#define GST_PAD_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD_TEMPLATE,GstPadTemplate)) -#define GST_PAD_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD_TEMPLATE,GstPadTemplateClass)) -#define GST_IS_PAD_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD_TEMPLATE)) -#define GST_IS_PAD_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD_TEMPLATE)) - -typedef enum { - GST_PAD_ALWAYS, - GST_PAD_SOMETIMES, - GST_PAD_REQUEST -} GstPadPresence; - -#define GST_PAD_TEMPLATE_NAME_TEMPLATE(templ) (((GstPadTemplate *)(templ))->name_template) -#define GST_PAD_TEMPLATE_DIRECTION(templ) (((GstPadTemplate *)(templ))->direction) -#define GST_PAD_TEMPLATE_PRESENCE(templ) (((GstPadTemplate *)(templ))->presence) -#define GST_PAD_TEMPLATE_CAPS(templ) (((GstPadTemplate *)(templ))->caps) - -typedef enum { - GST_PAD_TEMPLATE_FIXED = GST_OBJECT_FLAG_LAST, - - GST_PAD_TEMPLATE_FLAG_LAST = GST_OBJECT_FLAG_LAST + 4 -} GstPadTemplateFlags; - -#define GST_PAD_TEMPLATE_IS_FIXED(templ) (GST_FLAG_IS_SET(templ, GST_PAD_TEMPLATE_FIXED)) - -struct _GstPadTemplate { - GstObject object; - - gchar *name_template; - GstPadDirection direction; - GstPadPresence presence; - GstCaps *caps; - - gpointer _gst_reserved[GST_PADDING]; -}; - -struct _GstPadTemplateClass { - GstObjectClass parent_class; - - /* signal callbacks */ - void (*pad_created) (GstPadTemplate *templ, GstPad *pad); - - gpointer _gst_reserved[GST_PADDING]; -}; - -struct _GstStaticPadTemplate { - gchar *name_template; - GstPadDirection direction; - GstPadPresence presence; - GstStaticCaps static_caps; -}; - -#define GST_STATIC_PAD_TEMPLATE(padname, dir, pres, caps) \ - { \ - /* name_template */ padname, \ - /* direction */ dir, \ - /* presence */ pres, \ - /* caps */ caps \ - } - +/* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */ +#include GType gst_pad_get_type (void); @@ -482,19 +535,6 @@ gboolean gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch, void gst_pad_load_and_link (xmlNodePtr self, GstObject *parent); #endif - -/* templates and factories */ -GType gst_pad_template_get_type (void); - -GstPadTemplate* gst_pad_template_new (const gchar *name_template, - GstPadDirection direction, GstPadPresence presence, - GstCaps *caps); - -GstPadTemplate * gst_static_pad_template_get (GstStaticPadTemplate *pad_template); -GstCaps* gst_static_pad_template_get_caps (GstStaticPadTemplate *templ); -GstCaps* gst_pad_template_get_caps (GstPadTemplate *templ); - - G_END_DECLS #endif /* __GST_PAD_H__ */ diff --git a/gst/gstpadtemplate.c b/gst/gstpadtemplate.c new file mode 100644 index 0000000000..bb4bba03f0 --- /dev/null +++ b/gst/gstpadtemplate.c @@ -0,0 +1,331 @@ +/* GStreamer + * Copyright (C) 1999,2000 Erik Walthinsen + * 2000 Wim Taymans + * + * gstpadtemplate.c: Templates for pad creation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +/** + * SECTION:gstpadtemplate + * @short_description: Describe the media type of a pad. + * @see_also: #GstPad, #GstElementFactory + * + * Padtemplates describe the possible media types a pad or an elementfactory can + * handle. + * + * Pad and PadTemplates have #GstCaps attached to it to describe the media type they + * are capable of dealing with. gst_pad_template_get_caps() is used to get the + * caps of a padtemplate. It's not possible to modify the caps of a padtemplate after + * creation. + * + * Padtemplates can be created with gst_pad_template_new() or with the convenient + * GST_PAD_TEMPLATE_FACTORY() macro. A padtemplate can be used to create a pad or + * to add to an elementfactory. + * + * The following code example shows the code to create a pad from a padtemplate. + * + * Create a pad from a padtemplate + * + * GstStaticPadTemplate my_template = + * GST_STATIC_PAD_TEMPLATE ( + * "sink", // the name of the pad + * GST_PAD_SINK, // the direction of the pad + * GST_PAD_ALWAYS, // when this pad will be present + * GST_STATIC_CAPS ( // the capabilities of the padtemplate + * "audio/x-raw-int, " + * "channels = (int) [ 1, 6 ]" + * ) + * ) + * + * void + * my_method (void) + * { + * GstPad *pad; + * + * pad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (my_template_factory), "sink"); + * ... + * } + * + * + * + * The following example shows you how to add the padtemplate to an elementfactory: + * + * + * gboolean + * my_factory_init (GstPlugin *plugin) + * { + * GstElementFactory *factory; + * + * factory = gst_element_factory_new ("my_factory", GST_TYPE_MYFACTORY, &gst_myfactory_details); + * g_return_val_if_fail (factory != NULL, FALSE); + * + * gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (my_template_factory)); + * + * gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); + * + * return TRUE; + * } + * + * + */ + +#include "gst_private.h" + +#include "gstpad.h" +#include "gstpadtemplate.h" +#include "gstenumtypes.h" +#include "gstmarshal.h" +#include "gstutils.h" +#include "gstinfo.h" +#include "gsterror.h" +#include "gstvalue.h" + +#define GST_CAT_DEFAULT GST_CAT_PADS + +enum +{ + TEMPL_PAD_CREATED, + /* FILL ME */ + LAST_SIGNAL +}; + +static GstObject *parent_class = NULL; +static guint gst_pad_template_signals[LAST_SIGNAL] = { 0 }; + +static void gst_pad_template_class_init (GstPadTemplateClass * klass); +static void gst_pad_template_init (GstPadTemplate * templ); +static void gst_pad_template_dispose (GObject * object); + +GType +gst_pad_template_get_type (void) +{ + static GType padtemplate_type = 0; + + if (!padtemplate_type) { + static const GTypeInfo padtemplate_info = { + sizeof (GstPadTemplateClass), NULL, NULL, + (GClassInitFunc) gst_pad_template_class_init, NULL, NULL, + sizeof (GstPadTemplate), + 0, + (GInstanceInitFunc) gst_pad_template_init, NULL + }; + + padtemplate_type = + g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate", + &padtemplate_info, 0); + } + return padtemplate_type; +} + +static void +gst_pad_template_class_init (GstPadTemplateClass * klass) +{ + GObjectClass *gobject_class; + GstObjectClass *gstobject_class; + + gobject_class = (GObjectClass *) klass; + gstobject_class = (GstObjectClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_OBJECT); + + /** + * GstPadTemplate::pad-created: + * @pad_template: the object which received the signal. + * @pad: the pad that was created. + * + * This signal is fired when an element creates a pad from this template. + */ + gst_pad_template_signals[TEMPL_PAD_CREATED] = + g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstPadTemplateClass, pad_created), + NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD); + + gobject_class->dispose = gst_pad_template_dispose; + + gstobject_class->path_string_separator = "*"; +} + +static void +gst_pad_template_init (GstPadTemplate * templ) +{ +} + +static void +gst_pad_template_dispose (GObject * object) +{ + GstPadTemplate *templ = GST_PAD_TEMPLATE (object); + + g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ)); + if (GST_PAD_TEMPLATE_CAPS (templ)) { + gst_caps_unref (GST_PAD_TEMPLATE_CAPS (templ)); + } + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +/* ALWAYS padtemplates cannot have conversion specifications (like src_%d), + * since it doesn't make sense. + * SOMETIMES padtemplates can do whatever they want, they are provided by the + * element. + * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the + * 'sink%d' template is automatically selected), so we need to restrict their + * naming. + */ +static gboolean +name_is_valid (const gchar * name, GstPadPresence presence) +{ + const gchar *str; + + if (presence == GST_PAD_ALWAYS) { + if (strchr (name, '%')) { + g_warning ("invalid name template %s: conversion specifications are not" + " allowed for GST_PAD_ALWAYS padtemplates", name); + return FALSE; + } + } else if (presence == GST_PAD_REQUEST) { + if ((str = strchr (name, '%')) && strchr (str + 1, '%')) { + g_warning ("invalid name template %s: only one conversion specification" + " allowed in GST_PAD_REQUEST padtemplate", name); + return FALSE; + } + if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) { + g_warning ("invalid name template %s: conversion specification must be of" + " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name); + return FALSE; + } + if (str && (*(str + 2) != '\0')) { + g_warning ("invalid name template %s: conversion specification must" + " appear at the end of the GST_PAD_REQUEST padtemplate name", name); + return FALSE; + } + } + + return TRUE; +} + +/** + * gst_static_pad_template_get: + * @pad_template: the static pad template + * + * Converts a #GstStaticPadTemplate into a #GstPadTemplate. + * + * Returns: a new #GstPadTemplate. + */ +GstPadTemplate * +gst_static_pad_template_get (GstStaticPadTemplate * pad_template) +{ + GstPadTemplate *new; + + if (!name_is_valid (pad_template->name_template, pad_template->presence)) + return NULL; + + new = g_object_new (gst_pad_template_get_type (), + "name", pad_template->name_template, NULL); + + GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template); + GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction; + GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence; + + GST_PAD_TEMPLATE_CAPS (new) = + gst_caps_copy (gst_static_caps_get (&pad_template->static_caps)); + + return new; +} + +/** + * gst_pad_template_new: + * @name_template: the name template. + * @direction: the #GstPadDirection of the template. + * @presence: the #GstPadPresence of the pad. + * @caps: a #GstCaps set for the template. The caps are taken ownership of. + * + * Creates a new pad template with a name according to the given template + * and with the given arguments. This functions takes ownership of the provided + * caps, so be sure to not use them afterwards. + * + * Returns: a new #GstPadTemplate. + */ +GstPadTemplate * +gst_pad_template_new (const gchar * name_template, + GstPadDirection direction, GstPadPresence presence, GstCaps * caps) +{ + GstPadTemplate *new; + + g_return_val_if_fail (name_template != NULL, NULL); + g_return_val_if_fail (caps != NULL, NULL); + g_return_val_if_fail (direction == GST_PAD_SRC + || direction == GST_PAD_SINK, NULL); + g_return_val_if_fail (presence == GST_PAD_ALWAYS + || presence == GST_PAD_SOMETIMES || presence == GST_PAD_REQUEST, NULL); + + if (!name_is_valid (name_template, presence)) { + gst_caps_unref (caps); + return NULL; + } + + new = g_object_new (gst_pad_template_get_type (), + "name", name_template, NULL); + + GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template); + GST_PAD_TEMPLATE_DIRECTION (new) = direction; + GST_PAD_TEMPLATE_PRESENCE (new) = presence; + GST_PAD_TEMPLATE_CAPS (new) = caps; + + return new; +} + +/** + * gst_static_pad_template_get_caps: + * @templ: a #GstStaticPadTemplate to get capabilities of. + * + * Gets the capabilities of the static pad template. + * + * Returns: the #GstCaps of the static pad template. If you need to keep a + * reference to the caps, take a ref (see gst_caps_ref ()). + */ +GstCaps * +gst_static_pad_template_get_caps (GstStaticPadTemplate * templ) +{ + g_return_val_if_fail (templ, NULL); + + return (GstCaps *) gst_static_caps_get (&templ->static_caps); +} + +/** + * gst_pad_template_get_caps: + * @templ: a #GstPadTemplate to get capabilities of. + * + * Gets the capabilities of the pad template. + * + * Returns: the #GstCaps of the pad template. If you need to keep a reference to + * the caps, take a ref (see gst_caps_ref ()). + */ +GstCaps * +gst_pad_template_get_caps (GstPadTemplate * templ) +{ + g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL); + + return GST_PAD_TEMPLATE_CAPS (templ); +} + +void +gst_pad_template_pad_created (GstPadTemplate * templ, GstPad * pad) +{ + gst_object_sink (GST_OBJECT (templ)); + g_signal_emit (G_OBJECT (templ), + gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad); +} diff --git a/gst/gstpadtemplate.h b/gst/gstpadtemplate.h new file mode 100644 index 0000000000..f17e838bee --- /dev/null +++ b/gst/gstpadtemplate.h @@ -0,0 +1,174 @@ +/* GStreamer + * Copyright (C) 1999,2000 Erik Walthinsen + * 2000 Wim Taymans + * + * gstpadtemplate.h: Header for GstPadTemplate object + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_PAD_TEMPLATE_H__ +#define __GST_PAD_TEMPLATE_H__ + +#include + +#include +#include +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +/* FIXME: this awful circular dependency need to be resolved properly (see pad.h) */ +//typedef struct _GstPadTemplate GstPadTemplate; +typedef struct _GstPadTemplateClass GstPadTemplateClass; +typedef struct _GstStaticPadTemplate GstStaticPadTemplate; + +#define GST_TYPE_PAD_TEMPLATE (gst_pad_template_get_type ()) +#define GST_PAD_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD_TEMPLATE,GstPadTemplate)) +#define GST_PAD_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD_TEMPLATE,GstPadTemplateClass)) +#define GST_IS_PAD_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD_TEMPLATE)) +#define GST_IS_PAD_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD_TEMPLATE)) + +/** + * GstPadPresence: + * @GST_PAD_ALWAYS: the pad is always available + * @GST_PAD_SOMETIMES: the pad will become available depending on the media stream + * @GST_PAD_REQUEST: the pad is only available on request with + * gst_element_request_pad_by_name() or gst_element_request_compatible_pad(). + * + * Indicates when this pad will become available. + */ +typedef enum { + GST_PAD_ALWAYS, + GST_PAD_SOMETIMES, + GST_PAD_REQUEST +} GstPadPresence; + +/** + * GST_PAD_TEMPLATE_NAME_TEMPLATE: + * @templ: the template to query + * + * Get the nametemplate of the padtemplate. + */ +#define GST_PAD_TEMPLATE_NAME_TEMPLATE(templ) (((GstPadTemplate *)(templ))->name_template) + +/** + * GST_PAD_TEMPLATE_DIRECTION: + * @templ: the template to query + * + * Get the direction of the padtemplate. + */ +#define GST_PAD_TEMPLATE_DIRECTION(templ) (((GstPadTemplate *)(templ))->direction) + +/** + * GST_PAD_TEMPLATE_PRESENCE: + * @templ: the template to query + * + * Get the presence of the padtemplate. + */ +#define GST_PAD_TEMPLATE_PRESENCE(templ) (((GstPadTemplate *)(templ))->presence) + +/** + * GST_PAD_TEMPLATE_CAPS: + * @templ: the template to query + * + * Get a handle to the padtemplate #GstCaps + */ +#define GST_PAD_TEMPLATE_CAPS(templ) (((GstPadTemplate *)(templ))->caps) + +/** + * GstPadTemplateFlags: + * @GST_PAD_TEMPLATE_FIXED: the padtemplate has no variable properties + * @GST_PAD_TEMPLATE_FLAG_LAST: first flag that can be used by subclasses. + * + * Flags for the padtemplate + */ +typedef enum { + GST_PAD_TEMPLATE_FIXED = GST_OBJECT_FLAG_LAST, + + GST_PAD_TEMPLATE_FLAG_LAST = GST_OBJECT_FLAG_LAST + 4 +} GstPadTemplateFlags; + +/** + * GST_PAD_TEMPLATE_IS_FIXED: + * @templ: the template to query + * + * Check if the properties of the padtemplate are fixed + */ +#define GST_PAD_TEMPLATE_IS_FIXED(templ) (GST_FLAG_IS_SET(templ, GST_PAD_TEMPLATE_FIXED)) + +/** + * GstPadTemplate: + * + * The padtemplate object. + */ +struct _GstPadTemplate { + GstObject object; + + gchar *name_template; + GstPadDirection direction; + GstPadPresence presence; + GstCaps *caps; + + gpointer _gst_reserved[GST_PADDING]; +}; + +struct _GstPadTemplateClass { + GstObjectClass parent_class; + + /* signal callbacks */ + void (*pad_created) (GstPadTemplate *templ, GstPad *pad); + + gpointer _gst_reserved[GST_PADDING]; +}; + +struct _GstStaticPadTemplate { + gchar *name_template; + GstPadDirection direction; + GstPadPresence presence; + GstStaticCaps static_caps; +}; + +#define GST_STATIC_PAD_TEMPLATE(padname, dir, pres, caps) \ +{ \ + /* name_template */ padname, \ + /* direction */ dir, \ + /* presence */ pres, \ + /* caps */ caps \ +} + +/* templates and factories */ +GType gst_pad_template_get_type (void); + +GstPadTemplate* gst_pad_template_new (const gchar *name_template, + GstPadDirection direction, GstPadPresence presence, + GstCaps *caps); + +GstPadTemplate * gst_static_pad_template_get (GstStaticPadTemplate *pad_template); +GstCaps* gst_static_pad_template_get_caps (GstStaticPadTemplate *templ); +GstCaps* gst_pad_template_get_caps (GstPadTemplate *templ); + +void gst_pad_template_pad_created (GstPadTemplate * templ, GstPad * pad); + +G_END_DECLS + +#endif /* __GST_PAD_TEMPLATE_H__ */ +