summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-01-21 12:48:18 +0100
committerWim Taymans <wim@wtay.(none)>2009-01-21 12:48:18 +0100
commit8620bc32950d1b1bb90b65b9b43f79a9d1770b5a (patch)
treee2c02cc1b7eac53f6c6881082551fe4dbcca1201 /libs
parent809372066a196200c3e02a5eddf672d09f9f111c (diff)
Add new typefing helper function to guess the caps based on the file
extension. See #566661. API: gst_type_find_helper_for_extension()
Diffstat (limited to 'libs')
-rw-r--r--libs/gst/base/gsttypefindhelper.c65
-rw-r--r--libs/gst/base/gsttypefindhelper.h3
2 files changed, 68 insertions, 0 deletions
diff --git a/libs/gst/base/gsttypefindhelper.c b/libs/gst/base/gsttypefindhelper.c
index 24eceebc00..e6a237d2f2 100644
--- a/libs/gst/base/gsttypefindhelper.c
+++ b/libs/gst/base/gsttypefindhelper.c
@@ -476,3 +476,68 @@ gst_type_find_helper_for_buffer (GstObject * obj, GstBuffer * buf,
return result;
}
+
+/**
+ * gst_type_find_helper_for_extension:
+ * @obj: object doing the typefinding, or NULL (used for logging)
+ * @extension: an extension
+ *
+ * Tries to find the best #GstCaps associated with @extension.
+ *
+ * All available typefinders will be checked against the extension in order
+ * of rank. The caps of the first typefinder that can handle @extension will be
+ * returned.
+ *
+ * Returns: The #GstCaps corresponding to @extension, or #NULL if no type could
+ * be found. The caller should free the caps returned with gst_caps_unref().
+ *
+ * Since: 0.10.23
+ */
+GstCaps *
+gst_type_find_helper_for_extension (GstObject * obj, const gchar * extension)
+{
+ GList *l, *type_list;
+ GstCaps *result = NULL;
+
+ g_return_val_if_fail (extension != NULL, NULL);
+
+ GST_LOG_OBJECT (obj, "finding caps for extension %s", extension);
+
+ type_list = gst_type_find_factory_get_list ();
+ type_list = g_list_sort (type_list, type_find_factory_rank_cmp);
+
+ for (l = type_list; l; l = g_list_next (l)) {
+ GstTypeFindFactory *factory;
+ gchar **ext;
+ gint i;
+
+ factory = GST_TYPE_FIND_FACTORY (l->data);
+
+ /* get the extension that this typefind factory can handle */
+ ext = gst_type_find_factory_get_extensions (factory);
+ if (ext == NULL)
+ continue;
+
+ /* we only want to check those factories without a function */
+ if (factory->function != NULL)
+ continue;
+
+ /* there are extension, see if one of them matches the requested
+ * extension */
+ for (i = 0; ext[i]; i++) {
+ if (strcmp (ext[i], extension) == 0) {
+ /* we found a matching extension, take the caps */
+ if ((result = gst_type_find_factory_get_caps (factory))) {
+ gst_caps_ref (result);
+ goto done;
+ }
+ }
+ }
+ }
+done:
+ gst_plugin_feature_list_free (type_list);
+
+ GST_LOG_OBJECT (obj, "Returning %" GST_PTR_FORMAT, result);
+
+ return result;
+}
diff --git a/libs/gst/base/gsttypefindhelper.h b/libs/gst/base/gsttypefindhelper.h
index 65966a1f30..c3534a402b 100644
--- a/libs/gst/base/gsttypefindhelper.h
+++ b/libs/gst/base/gsttypefindhelper.h
@@ -34,6 +34,9 @@ GstCaps * gst_type_find_helper_for_buffer (GstObject *obj,
GstBuffer *buf,
GstTypeFindProbability *prob);
+GstCaps * gst_type_find_helper_for_extension (GstObject * obj,
+ const gchar * extension);
+
/**
* GstTypeFindHelperGetRangeFunction:
* @obj: a #GstObject that will handle the getrange request