gstreamer_core/gst/gstpadtemplate.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
   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 {
       
   121   TEMPL_PAD_CREATED,
   113   TEMPL_PAD_CREATED,
   122   /* FILL ME */
   114   /* FILL ME */
   123   LAST_SIGNAL
   115   LAST_SIGNAL
   124 };
   116 };
   125 
   117 
   126 static GstObject *parent_class = NULL;
   118 static GstObject *parent_class = NULL;
   127 static guint gst_pad_template_signals[LAST_SIGNAL] = { 0 };
   119 static guint gst_pad_template_signals[LAST_SIGNAL] = { 0 };
   128 
   120 
       
   121 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
       
   122 static void gst_pad_template_init (GstPadTemplate * templ,
       
   123     GstPadTemplateClass * klass);
   129 static void gst_pad_template_dispose (GObject * object);
   124 static void gst_pad_template_dispose (GObject * object);
   130 static void gst_pad_template_set_property (GObject * object, guint prop_id,
   125 #ifdef __SYMBIAN32__
   131     const GValue * value, GParamSpec * pspec);
   126 EXPORT_C
   132 static void gst_pad_template_get_property (GObject * object, guint prop_id,
   127 #endif
   133     GValue * value, GParamSpec * pspec);
   128 
   134 
   129 
   135 G_DEFINE_TYPE (GstPadTemplate, gst_pad_template, GST_TYPE_OBJECT);
   130 GType
       
   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 }
   136 
   150 
   137 static void
   151 static void
   138 gst_pad_template_class_init (GstPadTemplateClass * klass)
   152 gst_pad_template_class_init (GstPadTemplateClass * klass)
   139 {
   153 {
   140   GObjectClass *gobject_class;
   154   GObjectClass *gobject_class;
   157       G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
   171       G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
   158       NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
   172       NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
   159 
   173 
   160   gobject_class->dispose = gst_pad_template_dispose;
   174   gobject_class->dispose = gst_pad_template_dispose;
   161 
   175 
   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 
       
   216   gstobject_class->path_string_separator = "*";
   176   gstobject_class->path_string_separator = "*";
   217 }
   177 }
   218 
   178 
   219 static void
   179 static void
   220 gst_pad_template_init (GstPadTemplate * templ)
   180 gst_pad_template_init (GstPadTemplate * templ, GstPadTemplateClass * klass)
   221 {
   181 {
   222   /* FIXME 0.11: Does anybody remember why this is here? If not, let's
   182   /* FIXME 0.11: Does anybody remember why this is here? If not, let's
   223    * change it for 0.11 and let gst_element_class_add_pad_template() for
   183    * change it for 0.11 and let gst_element_class_add_pad_template() for
   224    * example ref/sink the pad templates.
   184    * example ref/sink the pad templates.
   225    */
   185    */
   229    *
   189    *
   230    * For consistency, then, we only produce them  with sunken references
   190    * For consistency, then, we only produce them  with sunken references
   231    * owned by the creator of the object
   191    * owned by the creator of the object
   232    */
   192    */
   233   if (GST_OBJECT_IS_FLOATING (templ)) {
   193   if (GST_OBJECT_IS_FLOATING (templ)) {
   234     gst_object_ref_sink (templ);
   194     gst_object_ref (templ);
       
   195     gst_object_sink (templ);
   235   }
   196   }
   236 }
   197 }
   237 
   198 
   238 static void
   199 static void
   239 gst_pad_template_dispose (GObject * object)
   200 gst_pad_template_dispose (GObject * object)
   271     if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
   232     if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
   272       g_warning ("invalid name template %s: only one conversion specification"
   233       g_warning ("invalid name template %s: only one conversion specification"
   273           " allowed in GST_PAD_REQUEST padtemplate", name);
   234           " allowed in GST_PAD_REQUEST padtemplate", name);
   274       return FALSE;
   235       return FALSE;
   275     }
   236     }
   276     if (str && (*(str + 1) != 's' && *(str + 1) != 'd' && *(str + 1) != 'u')) {
   237     if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
   277       g_warning ("invalid name template %s: conversion specification must be of"
   238       g_warning ("invalid name template %s: conversion specification must be of"
   278           " type '%%d', '%%u' or '%%s' for GST_PAD_REQUEST padtemplate", name);
   239           " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
   279       return FALSE;
   240       return FALSE;
   280     }
   241     }
   281     if (str && (*(str + 2) != '\0')) {
   242     if (str && (*(str + 2) != '\0')) {
   282       g_warning ("invalid name template %s: conversion specification must"
   243       g_warning ("invalid name template %s: conversion specification must"
   283           " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
   244           " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
   318 
   279 
   319 GstPadTemplate *
   280 GstPadTemplate *
   320 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
   281 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
   321 {
   282 {
   322   GstPadTemplate *new;
   283   GstPadTemplate *new;
   323   GstCaps *caps;
       
   324 
   284 
   325   if (!name_is_valid (pad_template->name_template, pad_template->presence))
   285   if (!name_is_valid (pad_template->name_template, pad_template->presence))
   326     return NULL;
   286     return NULL;
   327 
   287 
   328   caps = gst_static_caps_get (&pad_template->static_caps);
       
   329 
       
   330   new = g_object_new (gst_pad_template_get_type (),
   288   new = g_object_new (gst_pad_template_get_type (),
   331       "name", pad_template->name_template,
   289       "name", pad_template->name_template, NULL);
   332       "name-template", pad_template->name_template,
   290 
   333       "direction", pad_template->direction,
   291   GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
   334       "presence", pad_template->presence, "caps", caps, NULL);
   292   GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
   335 
   293   GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
   336   gst_caps_unref (caps);
   294 
       
   295   GST_PAD_TEMPLATE_CAPS (new) =
       
   296       gst_caps_make_writable (gst_static_caps_get (&pad_template->static_caps));
   337 
   297 
   338   return new;
   298   return new;
   339 }
   299 }
   340 
   300 
   341 /**
   301 /**
   371     gst_caps_unref (caps);
   331     gst_caps_unref (caps);
   372     return NULL;
   332     return NULL;
   373   }
   333   }
   374 
   334 
   375   new = g_object_new (gst_pad_template_get_type (),
   335   new = g_object_new (gst_pad_template_get_type (),
   376       "name", name_template, "name-template", name_template,
   336       "name", name_template, NULL);
   377       "direction", direction, "presence", presence, "caps", caps, NULL);
   337 
   378 
   338   GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
   379   if (caps)
   339   GST_PAD_TEMPLATE_DIRECTION (new) = direction;
   380     gst_caps_unref (caps);
   340   GST_PAD_TEMPLATE_PRESENCE (new) = presence;
       
   341   GST_PAD_TEMPLATE_CAPS (new) = caps;
   381 
   342 
   382   return new;
   343   return new;
   383 }
   344 }
   384 
   345 
   385 /**
   346 /**
   386  * gst_static_pad_template_get_caps:
   347  * gst_static_pad_template_get_caps:
   387  * @templ: a #GstStaticPadTemplate to get capabilities of.
   348  * @templ: a #GstStaticPadTemplate to get capabilities of.
   388  *
   349  *
   389  * Gets the capabilities of the static pad template.
   350  * Gets the capabilities of the static pad template.
   390  *
   351  *
   391  * Returns: the #GstCaps of the static pad template.
   352  * Returns: the #GstCaps of the static pad template. If you need to keep a
   392  * Unref after usage. Since the core holds an additional
   353  * reference to the caps, take a ref (see gst_caps_ref ()).
   393  * ref to the returned caps, use gst_caps_make_writable()
       
   394  * on the returned caps to modify it.
       
   395  */
   354  */
   396 #ifdef __SYMBIAN32__
   355 #ifdef __SYMBIAN32__
   397 EXPORT_C
   356 EXPORT_C
   398 #endif
   357 #endif
   399 
   358 
   441 gst_pad_template_pad_created (GstPadTemplate * templ, GstPad * pad)
   400 gst_pad_template_pad_created (GstPadTemplate * templ, GstPad * pad)
   442 {
   401 {
   443   g_signal_emit (G_OBJECT (templ),
   402   g_signal_emit (G_OBJECT (templ),
   444       gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
   403       gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
   445 }
   404 }
   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 }