docs: convert NULL, TRUE, and FALSE to %NULL, %TRUE, and %FALSE
[platform/upstream/gstreamer.git] / gst / gstelementfactory.c
index 1cf9039..aa0c5af 100644 (file)
@@ -17,8 +17,8 @@
  *
  * 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.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -27,7 +27,7 @@
  * @see_also: #GstElement, #GstPlugin, #GstPluginFeature, #GstPadTemplate.
  *
  * #GstElementFactory is used to create instances of elements. A
- * GstElementfactory can be added to a #GstPlugin as it is also a
+ * GstElementFactory can be added to a #GstPlugin as it is also a
  * #GstPluginFeature.
  *
  * Use the gst_element_factory_find() and gst_element_factory_create()
@@ -53,8 +53,6 @@
  *   ...
  * </programlisting>
  * </example>
- *
- * Last reviewed on 2005-11-23 (0.9.5)
  */
 
 #include "gst_private.h"
@@ -125,7 +123,7 @@ gst_element_factory_finalize (GObject * object)
  * Search for an element factory of the given name. Refs the returned
  * element factory; caller is responsible for unreffing.
  *
- * Returns: (transfer full): #GstElementFactory if found, NULL otherwise
+ * Returns: (transfer full): #GstElementFactory if found, %NULL otherwise
  */
 GstElementFactory *
 gst_element_factory_find (const gchar * name)
@@ -177,11 +175,19 @@ gst_element_factory_cleanup (GstElementFactory * factory)
   factory->interfaces = NULL;
 }
 
+#define CHECK_METADATA_FIELD(klass, name, key)                                 \
+  G_STMT_START {                                                               \
+    const gchar *metafield = gst_element_class_get_metadata (klass, key);      \
+    if (G_UNLIKELY (metafield == NULL || *metafield == '\0')) {                \
+      g_warning ("Element factory metadata for '%s' has no valid %s field", name, key);    \
+      goto detailserror;                                                       \
+    } \
+  } G_STMT_END;
+
 /**
  * gst_element_register:
- * @plugin: (allow-none): #GstPlugin to register the element with, or NULL for
- *     a static element (note that passing NULL only works in GStreamer 0.10.13
- *     and later)
+ * @plugin: (allow-none): #GstPlugin to register the element with, or %NULL for
+ *     a static element.
  * @name: name of elements of this type
  * @rank: rank of element (higher rank means more importance when autoplugging)
  * @type: GType of element to register
@@ -189,7 +195,7 @@ gst_element_factory_cleanup (GstElementFactory * factory)
  * Create a new elementfactory capable of instantiating objects of the
  * @type and add the factory to @plugin.
  *
- * Returns: TRUE, if the registering succeeded, FALSE on error
+ * Returns: %TRUE, if the registering succeeded, %FALSE on error
  */
 gboolean
 gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
@@ -234,12 +240,11 @@ gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
   /* provide info needed during class structure setup */
   g_type_set_qdata (type, __gst_elementclass_factory, factory);
   klass = GST_ELEMENT_CLASS (g_type_class_ref (type));
-#if 0
-  /* FIXME */
-  if ((klass->details.longname == NULL) ||
-      (klass->details.klass == NULL) || (klass->details.author == NULL))
-    goto detailserror;
-#endif
+
+  CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_LONGNAME);
+  CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_KLASS);
+  CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_DESCRIPTION);
+  CHECK_METADATA_FIELD (klass, name, GST_ELEMENT_METADATA_AUTHOR);
 
   factory->type = type;
   factory->metadata = gst_structure_copy ((GstStructure *) klass->metadata);
@@ -313,28 +318,24 @@ urierror:
     return FALSE;
   }
 
-#if 0
 detailserror:
   {
-    GST_WARNING_OBJECT (factory,
-        "The GstElementDetails don't seem to have been set properly");
     gst_element_factory_cleanup (factory);
     return FALSE;
   }
-#endif
 }
 
 /**
  * gst_element_factory_create:
  * @factory: factory to instantiate
- * @name: (allow-none): name of new element, or NULL to automatically create
+ * @name: (allow-none): name of new element, or %NULL to automatically create
  *    a unique name
  *
  * Create a new element of the type defined by the given elementfactory.
  * It will be given the name supplied, since all elements require a name as
  * their first argument.
  *
- * Returns: (transfer floating): new #GstElement or NULL if the element couldn't
+ * Returns: (transfer floating): new #GstElement or %NULL if the element couldn't
  *     be created
  */
 GstElement *
@@ -413,15 +414,15 @@ no_element:
 /**
  * gst_element_factory_make:
  * @factoryname: a named factory to instantiate
- * @name: (allow-none): name of new element, or NULL to automatically create
+ * @name: (allow-none): name of new element, or %NULL to automatically create
  *    a unique name
  *
  * Create a new element of the type defined by the given element factory.
- * If name is NULL, then the element will receive a guaranteed unique name,
+ * If name is %NULL, then the element will receive a guaranteed unique name,
  * consisting of the element factory name and a number.
  * If name is given, it will be given the name supplied.
  *
- * Returns: (transfer floating): new #GstElement or NULL if unable to create element
+ * Returns: (transfer floating): new #GstElement or %NULL if unable to create element
  */
 GstElement *
 gst_element_factory_make (const gchar * factoryname, const gchar * name)
@@ -492,6 +493,16 @@ gst_element_factory_get_element_type (GstElementFactory * factory)
   return factory->type;
 }
 
+/**
+ * gst_element_factory_get_metadata:
+ * @factory: a #GstElementFactory
+ * @key: a key
+ *
+ * Get the metadata on @factory with @key.
+ *
+ * Returns: the metadata with @key on @factory or %NULL when there was no
+ * metadata with the given @key.
+ */
 const gchar *
 gst_element_factory_get_metadata (GstElementFactory * factory,
     const gchar * key)
@@ -500,6 +511,41 @@ gst_element_factory_get_metadata (GstElementFactory * factory,
 }
 
 /**
+ * gst_element_factory_get_metadata_keys:
+ * @factory: a #GstElementFactory
+ *
+ * Get the available keys for the metadata on @factory.
+ *
+ * Returns: (transfer full) (element-type utf8) (array zero-terminated=1):
+ * a %NULL-terminated array of key strings, or %NULL when there is no
+ * metadata. Free with g_strfreev() when no longer needed.
+ */
+gchar **
+gst_element_factory_get_metadata_keys (GstElementFactory * factory)
+{
+  GstStructure *metadata;
+  gchar **arr;
+  gint i, num;
+
+  g_return_val_if_fail (GST_IS_ELEMENT_FACTORY (factory), NULL);
+
+  metadata = (GstStructure *) factory->metadata;
+  if (metadata == NULL)
+    return NULL;
+
+  num = gst_structure_n_fields (metadata);
+  if (num == 0)
+    return NULL;
+
+  arr = g_new (gchar *, num + 1);
+  for (i = 0; i < num; ++i) {
+    arr[i] = g_strdup (gst_structure_nth_field_name (metadata, i));
+  }
+  arr[i] = NULL;
+  return arr;
+}
+
+/**
  * gst_element_factory_get_num_pad_templates:
  * @factory: a #GstElementFactory
  *
@@ -573,13 +619,13 @@ gst_element_factory_get_uri_type (GstElementFactory * factory)
  * gst_element_factory_get_uri_protocols:
  * @factory: a #GstElementFactory
  *
- * Gets a NULL-terminated array of protocols this element supports or NULL if
+ * Gets a %NULL-terminated array of protocols this element supports or %NULL if
  * no protocols are supported. You may not change the contents of the returned
  * array, as it is still owned by the element factory. Use g_strdupv() to
  * make a copy of the protocol string array if you need to.
  *
  * Returns: (transfer none) (array zero-terminated=1): the supported protocols
- *     or NULL
+ *     or %NULL
  */
 const gchar *const *
 gst_element_factory_get_uri_protocols (GstElementFactory * factory)
@@ -596,9 +642,7 @@ gst_element_factory_get_uri_protocols (GstElementFactory * factory)
  *
  * Check if @factory implements the interface with name @interfacename.
  *
- * Returns: #TRUE when @factory implement the interface.
- *
- * Since: 0.10.14
+ * Returns: %TRUE when @factory implement the interface.
  */
 gboolean
 gst_element_factory_has_interface (GstElementFactory * factory,
@@ -633,8 +677,6 @@ typedef struct
  * Check if @factory is of the given types.
  *
  * Returns: %TRUE if @factory is of @type.
- *
- * Since: 0.10.31
  */
 gboolean
 gst_element_factory_list_is_type (GstElementFactory * factory,
@@ -646,6 +688,11 @@ gst_element_factory_list_is_type (GstElementFactory * factory,
   klass =
       gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
 
+  if (klass == NULL) {
+    GST_ERROR_OBJECT (factory, "element factory is missing klass identifiers");
+    return res;
+  }
+
   /* Filter by element type first, as soon as it matches
    * one type, we skip all other tests */
   if (!res && (type & GST_ELEMENT_FACTORY_TYPE_SINK))
@@ -681,17 +728,24 @@ gst_element_factory_list_is_type (GstElementFactory * factory,
     res = (strstr (klass, "Formatter") != NULL);
 
   /* Filter by media type now, we only test if it
-   * matched any of the types above. */
-  if (res
+   * matched any of the types above or only checking the media
+   * type was requested. */
+  if ((res || !(type & (GST_ELEMENT_FACTORY_TYPE_MAX_ELEMENTS - 1)))
       && (type & (GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO |
               GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
-              GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)))
+              GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE |
+              GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE |
+              GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)))
     res = ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)
         && (strstr (klass, "Audio") != NULL))
         || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO)
         && (strstr (klass, "Video") != NULL))
         || ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)
-        && (strstr (klass, "Image") != NULL));
+        && (strstr (klass, "Image") != NULL)) ||
+        ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE)
+        && (strstr (klass, "Subtitle") != NULL)) ||
+        ((type & GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA)
+        && (strstr (klass, "Metadata") != NULL));
 
   return res;
 }
@@ -724,8 +778,6 @@ element_filter (GstPluginFeature * feature, FilterData * data)
  * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
  *     #GstElementFactory elements. Use gst_plugin_feature_list_free() after
  *     usage.
- *
- * Since: 0.10.31
  */
 GList *
 gst_element_factory_list_get_elements (GstElementFactoryListType type,
@@ -764,10 +816,8 @@ gst_element_factory_list_get_elements (GstElementFactoryListType type,
  * whose pad templates caps can intersect with @caps will be returned.
  *
  * Returns: (transfer full) (element-type Gst.ElementFactory): a #GList of
- *     #GstElementFactory elements that match the given requisits.
+ *     #GstElementFactory elements that match the given requisites.
  *     Use #gst_plugin_feature_list_free after usage.
- *
- * Since: 0.10.31
  */
 GList *
 gst_element_factory_list_filter (GList * list,