gstreamer_core/gst/gstpadtemplate.c
branchRCL_3
changeset 29 567bb019e3e3
parent 0 0e761a78d257
child 30 7e817e7e631c
equal deleted inserted replaced
6:9b2c3c7a1a9c 29:567bb019e3e3
   108 
   108 
   109 #define GST_CAT_DEFAULT GST_CAT_PADS
   109 #define GST_CAT_DEFAULT GST_CAT_PADS
   110 
   110 
   111 enum
   111 enum
   112 {
   112 {
       
   113   PROP_NAME_TEMPLATE = 1,
       
   114   PROP_DIRECTION,
       
   115   PROP_PRESENCE,
       
   116   PROP_CAPS
       
   117 };
       
   118 
       
   119 enum
       
   120 {
   113   TEMPL_PAD_CREATED,
   121   TEMPL_PAD_CREATED,
   114   /* FILL ME */
   122   /* FILL ME */
   115   LAST_SIGNAL
   123   LAST_SIGNAL
   116 };
   124 };
   117 
   125 
   118 static GstObject *parent_class = NULL;
   126 static GstObject *parent_class = NULL;
   119 static guint gst_pad_template_signals[LAST_SIGNAL] = { 0 };
   127 static guint gst_pad_template_signals[LAST_SIGNAL] = { 0 };
   120 
   128 
   121 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
       
   122 static void gst_pad_template_init (GstPadTemplate * templ,
       
   123     GstPadTemplateClass * klass);
       
   124 static void gst_pad_template_dispose (GObject * object);
   129 static void gst_pad_template_dispose (GObject * object);
   125 #ifdef __SYMBIAN32__
   130 static void gst_pad_template_set_property (GObject * object, guint prop_id,
   126 EXPORT_C
   131     const GValue * value, GParamSpec * pspec);
   127 #endif
   132 static void gst_pad_template_get_property (GObject * object, guint prop_id,
   128 
   133     GValue * value, GParamSpec * pspec);
   129 
   134 
   130 GType
   135 G_DEFINE_TYPE (GstPadTemplate, gst_pad_template, GST_TYPE_OBJECT);
   131 gst_pad_template_get_type (void)
       
   132 {
       
   133   static GType padtemplate_type = 0;
       
   134 
       
   135   if (G_UNLIKELY (padtemplate_type == 0)) {
       
   136     static const GTypeInfo padtemplate_info = {
       
   137       sizeof (GstPadTemplateClass), NULL, NULL,
       
   138       (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
       
   139       sizeof (GstPadTemplate),
       
   140       0,
       
   141       (GInstanceInitFunc) gst_pad_template_init, NULL
       
   142     };
       
   143 
       
   144     padtemplate_type =
       
   145         g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
       
   146         &padtemplate_info, 0);
       
   147   }
       
   148   return padtemplate_type;
       
   149 }
       
   150 
   136 
   151 static void
   137 static void
   152 gst_pad_template_class_init (GstPadTemplateClass * klass)
   138 gst_pad_template_class_init (GstPadTemplateClass * klass)
   153 {
   139 {
   154   GObjectClass *gobject_class;
   140   GObjectClass *gobject_class;
   171       G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
   157       G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
   172       NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
   158       NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
   173 
   159 
   174   gobject_class->dispose = gst_pad_template_dispose;
   160   gobject_class->dispose = gst_pad_template_dispose;
   175 
   161 
       
   162   gobject_class->get_property = gst_pad_template_get_property;
       
   163   gobject_class->set_property = gst_pad_template_set_property;
       
   164 
       
   165   /**
       
   166    * GstPadTemplate:name-template
       
   167    *
       
   168    * The name template of the pad template.
       
   169    *
       
   170    * Since: 0.10.21
       
   171    */
       
   172   g_object_class_install_property (gobject_class, PROP_NAME_TEMPLATE,
       
   173       g_param_spec_string ("name-template", "Name template",
       
   174           "The name template of the pad template", NULL,
       
   175           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
       
   176 
       
   177   /**
       
   178    * GstPadTemplate:direction
       
   179    *
       
   180    * The direction of the pad described by the pad template.
       
   181    *
       
   182    * Since: 0.10.21
       
   183    */
       
   184   g_object_class_install_property (gobject_class, PROP_DIRECTION,
       
   185       g_param_spec_enum ("direction", "Direction",
       
   186           "The direction of the pad described by the pad template",
       
   187           GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
       
   188           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
       
   189 
       
   190   /**
       
   191    * GstPadTemplate:presence
       
   192    *
       
   193    * When the pad described by the pad template will become available.
       
   194    *
       
   195    * Since: 0.10.21
       
   196    */
       
   197   g_object_class_install_property (gobject_class, PROP_PRESENCE,
       
   198       g_param_spec_enum ("presence", "Presence",
       
   199           "When the pad described by the pad template will become available",
       
   200           GST_TYPE_PAD_PRESENCE, GST_PAD_ALWAYS,
       
   201           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
       
   202 
       
   203   /**
       
   204    * GstPadTemplate:caps
       
   205    *
       
   206    * The capabilities of the pad described by the pad template.
       
   207    *
       
   208    * Since: 0.10.21
       
   209    */
       
   210   g_object_class_install_property (gobject_class, PROP_CAPS,
       
   211       g_param_spec_boxed ("caps", "Caps",
       
   212           "The capabilities of the pad described by the pad template",
       
   213           GST_TYPE_CAPS,
       
   214           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
       
   215 
   176   gstobject_class->path_string_separator = "*";
   216   gstobject_class->path_string_separator = "*";
   177 }
   217 }
   178 
   218 
   179 static void
   219 static void
   180 gst_pad_template_init (GstPadTemplate * templ, GstPadTemplateClass * klass)
   220 gst_pad_template_init (GstPadTemplate * templ)
   181 {
   221 {
   182   /* FIXME 0.11: Does anybody remember why this is here? If not, let's
   222   /* FIXME 0.11: Does anybody remember why this is here? If not, let's
   183    * change it for 0.11 and let gst_element_class_add_pad_template() for
   223    * change it for 0.11 and let gst_element_class_add_pad_template() for
   184    * example ref/sink the pad templates.
   224    * example ref/sink the pad templates.
   185    */
   225    */
   189    *
   229    *
   190    * For consistency, then, we only produce them  with sunken references
   230    * For consistency, then, we only produce them  with sunken references
   191    * owned by the creator of the object
   231    * owned by the creator of the object
   192    */
   232    */
   193   if (GST_OBJECT_IS_FLOATING (templ)) {
   233   if (GST_OBJECT_IS_FLOATING (templ)) {
   194     gst_object_ref (templ);
   234     gst_object_ref_sink (templ);
   195     gst_object_sink (templ);
       
   196   }
   235   }
   197 }
   236 }
   198 
   237 
   199 static void
   238 static void
   200 gst_pad_template_dispose (GObject * object)
   239 gst_pad_template_dispose (GObject * object)
   232     if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
   271     if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
   233       g_warning ("invalid name template %s: only one conversion specification"
   272       g_warning ("invalid name template %s: only one conversion specification"
   234           " allowed in GST_PAD_REQUEST padtemplate", name);
   273           " allowed in GST_PAD_REQUEST padtemplate", name);
   235       return FALSE;
   274       return FALSE;
   236     }
   275     }
   237     if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
   276     if (str && (*(str + 1) != 's' && *(str + 1) != 'd' && *(str + 1) != 'u')) {
   238       g_warning ("invalid name template %s: conversion specification must be of"
   277       g_warning ("invalid name template %s: conversion specification must be of"
   239           " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
   278           " type '%%d', '%%u' or '%%s' for GST_PAD_REQUEST padtemplate", name);
   240       return FALSE;
   279       return FALSE;
   241     }
   280     }
   242     if (str && (*(str + 2) != '\0')) {
   281     if (str && (*(str + 2) != '\0')) {
   243       g_warning ("invalid name template %s: conversion specification must"
   282       g_warning ("invalid name template %s: conversion specification must"
   244           " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
   283           " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
   279 
   318 
   280 GstPadTemplate *
   319 GstPadTemplate *
   281 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
   320 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
   282 {
   321 {
   283   GstPadTemplate *new;
   322   GstPadTemplate *new;
       
   323   GstCaps *caps;
   284 
   324 
   285   if (!name_is_valid (pad_template->name_template, pad_template->presence))
   325   if (!name_is_valid (pad_template->name_template, pad_template->presence))
   286     return NULL;
   326     return NULL;
   287 
   327 
       
   328   caps = gst_static_caps_get (&pad_template->static_caps);
       
   329 
   288   new = g_object_new (gst_pad_template_get_type (),
   330   new = g_object_new (gst_pad_template_get_type (),
   289       "name", pad_template->name_template, NULL);
   331       "name", pad_template->name_template,
   290 
   332       "name-template", pad_template->name_template,
   291   GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
   333       "direction", pad_template->direction,
   292   GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
   334       "presence", pad_template->presence, "caps", caps, NULL);
   293   GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
   335 
   294 
   336   gst_caps_unref (caps);
   295   GST_PAD_TEMPLATE_CAPS (new) =
       
   296       gst_caps_make_writable (gst_static_caps_get (&pad_template->static_caps));
       
   297 
   337 
   298   return new;
   338   return new;
   299 }
   339 }
   300 
   340 
   301 /**
   341 /**
   331     gst_caps_unref (caps);
   371     gst_caps_unref (caps);
   332     return NULL;
   372     return NULL;
   333   }
   373   }
   334 
   374 
   335   new = g_object_new (gst_pad_template_get_type (),
   375   new = g_object_new (gst_pad_template_get_type (),
   336       "name", name_template, NULL);
   376       "name", name_template, "name-template", name_template,
   337 
   377       "direction", direction, "presence", presence, "caps", caps, NULL);
   338   GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
   378 
   339   GST_PAD_TEMPLATE_DIRECTION (new) = direction;
   379   if (caps)
   340   GST_PAD_TEMPLATE_PRESENCE (new) = presence;
   380     gst_caps_unref (caps);
   341   GST_PAD_TEMPLATE_CAPS (new) = caps;
       
   342 
   381 
   343   return new;
   382   return new;
   344 }
   383 }
   345 
   384 
   346 /**
   385 /**
   347  * gst_static_pad_template_get_caps:
   386  * gst_static_pad_template_get_caps:
   348  * @templ: a #GstStaticPadTemplate to get capabilities of.
   387  * @templ: a #GstStaticPadTemplate to get capabilities of.
   349  *
   388  *
   350  * Gets the capabilities of the static pad template.
   389  * Gets the capabilities of the static pad template.
   351  *
   390  *
   352  * Returns: the #GstCaps of the static pad template. If you need to keep a
   391  * Returns: the #GstCaps of the static pad template.
   353  * reference to the caps, take a ref (see gst_caps_ref ()).
   392  * Unref after usage. Since the core holds an additional
       
   393  * ref to the returned caps, use gst_caps_make_writable()
       
   394  * on the returned caps to modify it.
   354  */
   395  */
   355 #ifdef __SYMBIAN32__
   396 #ifdef __SYMBIAN32__
   356 EXPORT_C
   397 EXPORT_C
   357 #endif
   398 #endif
   358 
   399 
   400 gst_pad_template_pad_created (GstPadTemplate * templ, GstPad * pad)
   441 gst_pad_template_pad_created (GstPadTemplate * templ, GstPad * pad)
   401 {
   442 {
   402   g_signal_emit (G_OBJECT (templ),
   443   g_signal_emit (G_OBJECT (templ),
   403       gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
   444       gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
   404 }
   445 }
       
   446 
       
   447 static void
       
   448 gst_pad_template_set_property (GObject * object, guint prop_id,
       
   449     const GValue * value, GParamSpec * pspec)
       
   450 {
       
   451   /* these properties are all construct-only */
       
   452   switch (prop_id) {
       
   453     case PROP_NAME_TEMPLATE:
       
   454       GST_PAD_TEMPLATE_NAME_TEMPLATE (object) = g_value_dup_string (value);
       
   455       break;
       
   456     case PROP_DIRECTION:
       
   457       GST_PAD_TEMPLATE_DIRECTION (object) = g_value_get_enum (value);
       
   458       break;
       
   459     case PROP_PRESENCE:
       
   460       GST_PAD_TEMPLATE_PRESENCE (object) = g_value_get_enum (value);
       
   461       break;
       
   462     case PROP_CAPS:
       
   463       /* allow caps == NULL for backwards compatibility (ie. g_object_new()
       
   464        * called without any of the new properties) (FIXME 0.11) */
       
   465       if (g_value_get_boxed (value) != NULL) {
       
   466         GST_PAD_TEMPLATE_CAPS (object) =
       
   467             gst_caps_copy (g_value_get_boxed (value));
       
   468       }
       
   469       break;
       
   470     default:
       
   471       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       
   472       break;
       
   473   }
       
   474 }
       
   475 
       
   476 static void
       
   477 gst_pad_template_get_property (GObject * object, guint prop_id, GValue * value,
       
   478     GParamSpec * pspec)
       
   479 {
       
   480   /* these properties are all construct-only */
       
   481   switch (prop_id) {
       
   482     case PROP_NAME_TEMPLATE:
       
   483       g_value_set_string (value, GST_PAD_TEMPLATE_NAME_TEMPLATE (object));
       
   484       break;
       
   485     case PROP_DIRECTION:
       
   486       g_value_set_enum (value, GST_PAD_TEMPLATE_DIRECTION (object));
       
   487       break;
       
   488     case PROP_PRESENCE:
       
   489       g_value_set_enum (value, GST_PAD_TEMPLATE_PRESENCE (object));
       
   490       break;
       
   491     case PROP_CAPS:
       
   492       g_value_set_boxed (value, GST_PAD_TEMPLATE_CAPS (object));
       
   493       break;
       
   494     default:
       
   495       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       
   496       break;
       
   497   }
       
   498 }