[gst-cvs] gstreamer: typefind: add a new method that also uses the file extension
Wim Taymans
wtay at kemper.freedesktop.org
Tue Jan 12 08:43:36 PST 2010
Module: gstreamer
Branch: master
Commit: 8fff434835dd9fd1a5a4a8fa93b63b2802988d88
URL: http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=8fff434835dd9fd1a5a4a8fa93b63b2802988d88
Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date: Tue Jan 12 17:34:39 2010 +0100
typefind: add a new method that also uses the file extension
Add a method to perform get_range typefinding that also uses the
uri/location extension as an extra hint. It will first try to call the
typefind functions of the factories that handle the given extension. The result
is that in the common case, we only call one typefind function, which speeds up
the typefinding a lot.
---
docs/libs/gstreamer-libs-sections.txt | 1 +
libs/gst/base/gsttypefindhelper.c | 93 ++++++++++++++++++++++++++++++---
libs/gst/base/gsttypefindhelper.h | 6 ++
win32/common/libgstbase.def | 1 +
4 files changed, 93 insertions(+), 8 deletions(-)
diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt
index 57a6c53..9ddccb6 100644
--- a/docs/libs/gstreamer-libs-sections.txt
+++ b/docs/libs/gstreamer-libs-sections.txt
@@ -675,6 +675,7 @@ gst_type_find_helper_for_buffer
gst_type_find_helper_for_extension
GstTypeFindHelperGetRangeFunction
gst_type_find_helper_get_range
+gst_type_find_helper_get_range_ext
<SUBSECTION Private>
</SECTION>
diff --git a/libs/gst/base/gsttypefindhelper.c b/libs/gst/base/gsttypefindhelper.c
index 054424c..e586e39 100644
--- a/libs/gst/base/gsttypefindhelper.c
+++ b/libs/gst/base/gsttypefindhelper.c
@@ -215,11 +215,12 @@ helper_find_get_length (gpointer data)
}
/**
- * gst_type_find_helper_get_range:
+ * gst_type_find_helper_get_range_ext:
* @obj: A #GstObject that will be passed as first argument to @func
* @func: A generic #GstTypeFindHelperGetRangeFunction that will be used
* to access data at random offsets when doing the typefinding
* @size: The length in bytes
+ * @extension: extenstion of the media
* @prob: location to store the probability of the found caps, or #NULL
*
* Utility function to do pull-based typefinding. Unlike gst_type_find_helper()
@@ -231,20 +232,26 @@ helper_find_get_length (gpointer data)
* callback can then call the upstream peer pad with offsets adjusted for the
* tag size, for example).
*
+ * When @extension is not NULL, this function will first try the typefind
+ * functions for the given extension, which might speed up the typefinding
+ * in many cases.
+ *
* Returns: The #GstCaps corresponding to the data stream.
* Returns #NULL if no #GstCaps matches the data stream.
+ *
+ * Since: 0.10.26
*/
-
GstCaps *
-gst_type_find_helper_get_range (GstObject * obj,
+gst_type_find_helper_get_range_ext (GstObject * obj,
GstTypeFindHelperGetRangeFunction func, guint64 size,
- GstTypeFindProbability * prob)
+ const gchar * extension, GstTypeFindProbability * prob)
{
GstTypeFindHelper helper;
GstTypeFind find;
GSList *walk;
GList *l, *type_list;
GstCaps *result = NULL;
+ gint pos = 0;
g_return_val_if_fail (GST_IS_OBJECT (obj), NULL);
g_return_val_if_fail (func != NULL, NULL);
@@ -269,6 +276,48 @@ gst_type_find_helper_get_range (GstObject * obj,
type_list = gst_type_find_factory_get_list ();
+ /* move the typefinders for the extension first in the list. The idea is that
+ * when one of them returns MAX we don't need to search further as there is a
+ * very high chance we got the right type. */
+ if (extension) {
+ GList *next;
+
+ GST_LOG_OBJECT (obj, "sorting typefind for extension %s to head",
+ extension);
+
+ for (l = type_list; l; l = next) {
+ GstTypeFindFactory *factory;
+ gint i;
+ gchar **ext;
+
+ next = l->next;
+
+ factory = GST_TYPE_FIND_FACTORY (l->data);
+
+ ext = gst_type_find_factory_get_extensions (factory);
+ if (ext == NULL)
+ continue;
+
+ GST_LOG_OBJECT (obj, "testing factory %s for extension %s",
+ GST_PLUGIN_FEATURE_NAME (factory), extension);
+
+ for (i = 0; ext[i]; i++) {
+ if (strcmp (ext[i], extension) == 0) {
+ /* found extension, move in front */
+ GST_LOG_OBJECT (obj, "moving typefind for extension %s to head",
+ extension);
+ /* remove entry from list */
+ type_list = g_list_delete_link (type_list, l);
+ /* insert at the position */
+ type_list = g_list_insert (type_list, factory, pos);
+ /* next element will be inserted after this one */
+ pos++;
+ break;
+ }
+ }
+ }
+ }
+
for (l = type_list; l; l = l->next) {
helper.factory = GST_TYPE_FIND_FACTORY (l->data);
gst_type_find_factory_call_function (helper.factory, &find);
@@ -294,6 +343,34 @@ gst_type_find_helper_get_range (GstObject * obj,
}
/**
+ * gst_type_find_helper_get_range:
+ * @obj: A #GstObject that will be passed as first argument to @func
+ * @func: A generic #GstTypeFindHelperGetRangeFunction that will be used
+ * to access data at random offsets when doing the typefinding
+ * @size: The length in bytes
+ * @prob: location to store the probability of the found caps, or #NULL
+ *
+ * Utility function to do pull-based typefinding. Unlike gst_type_find_helper()
+ * however, this function will use the specified function @func to obtain the
+ * data needed by the typefind functions, rather than operating on a given
+ * source pad. This is useful mostly for elements like tag demuxers which
+ * strip off data at the beginning and/or end of a file and want to typefind
+ * the stripped data stream before adding their own source pad (the specified
+ * callback can then call the upstream peer pad with offsets adjusted for the
+ * tag size, for example).
+ *
+ * Returns: The #GstCaps corresponding to the data stream.
+ * Returns #NULL if no #GstCaps matches the data stream.
+ */
+GstCaps *
+gst_type_find_helper_get_range (GstObject * obj,
+ GstTypeFindHelperGetRangeFunction func, guint64 size,
+ GstTypeFindProbability * prob)
+{
+ return gst_type_find_helper_get_range_ext (obj, func, size, NULL, prob);
+}
+
+/**
* gst_type_find_helper:
* @src: A source #GstPad
* @size: The length in bytes
@@ -496,15 +573,15 @@ gst_type_find_helper_for_extension (GstObject * obj, const gchar * extension)
factory = GST_TYPE_FIND_FACTORY (l->data);
+ /* we only want to check those factories without a function */
+ if (factory->function != NULL)
+ continue;
+
/* 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++) {
diff --git a/libs/gst/base/gsttypefindhelper.h b/libs/gst/base/gsttypefindhelper.h
index c3534a4..b6ad517 100644
--- a/libs/gst/base/gsttypefindhelper.h
+++ b/libs/gst/base/gsttypefindhelper.h
@@ -64,6 +64,12 @@ GstCaps * gst_type_find_helper_get_range (GstObject * obj
guint64 size,
GstTypeFindProbability *prob);
+GstCaps * gst_type_find_helper_get_range_ext (GstObject * obj,
+ GstTypeFindHelperGetRangeFunction func,
+ guint64 size,
+ const gchar *extension,
+ GstTypeFindProbability *prob);
+
G_END_DECLS
#endif /* __GST_TYPEFINDHELPER_H__ */
diff --git a/win32/common/libgstbase.def b/win32/common/libgstbase.def
index eef6d75..7e0ba98 100644
--- a/win32/common/libgstbase.def
+++ b/win32/common/libgstbase.def
@@ -220,3 +220,4 @@ EXPORTS
gst_type_find_helper_for_buffer
gst_type_find_helper_for_extension
gst_type_find_helper_get_range
+ gst_type_find_helper_get_range_ext
More information about the Gstreamer-commits
mailing list