mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
typefinding: move gio-based xdg mime typefinder from -bad to -base
Its purposes is mainly to avoid false positives (e.g. mp3 typefinder reporting a 20% probability and somesuch). Won't be registered if the gio plugin has been disabled via ./configure --disable-gio.
This commit is contained in:
parent
889c318798
commit
4cacc441d8
3 changed files with 73 additions and 3 deletions
|
@ -528,7 +528,7 @@ AG_GST_CHECK_FEATURE(GNOME_VFS, [GNOME VFS], gnomevfs, [
|
|||
dnl *** libgio ***
|
||||
translit(dnm, m, l) AM_CONDITIONAL(USE_GIO, true)
|
||||
AG_GST_CHECK_FEATURE(GIO, [GIO library], gio, [
|
||||
PKG_CHECK_MODULES(GIO, gio-2.0 >= 2.15.2, [
|
||||
PKG_CHECK_MODULES(GIO, gio-2.0 >= 2.16, [
|
||||
HAVE_GIO="yes"
|
||||
GIO_MODULE_DIR="`$PKG_CONFIG --variable=giomoduledir gio-2.0`"
|
||||
AC_DEFINE_UNQUOTED(GIO_MODULE_DIR, "$GIO_MODULE_DIR",
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
plugin_LTLIBRARIES = libgsttypefindfunctions.la
|
||||
|
||||
libgsttypefindfunctions_la_SOURCES = gsttypefindfunctions.c
|
||||
libgsttypefindfunctions_la_CFLAGS = $(GST_CFLAGS)
|
||||
libgsttypefindfunctions_la_CFLAGS = $(GST_CFLAGS) $(GIO_CFLAGS)
|
||||
libgsttypefindfunctions_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||
libgsttypefindfunctions_la_LIBADD = $(GST_LIBS)
|
||||
libgsttypefindfunctions_la_LIBADD = $(GST_LIBS) $(GIO_LIBS)
|
||||
libgsttypefindfunctions_la_LIBTOOLFLAGS = --tag=disable-static
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
||||
* Copyright (C) 2005-2009 Tim-Philipp Müller <tim centricular net>
|
||||
* Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
*
|
||||
* gsttypefindfunctions.c: collection of various typefind functions
|
||||
*
|
||||
|
@ -25,6 +27,12 @@
|
|||
|
||||
#include <glib.h>
|
||||
|
||||
/* don't want to add gio xdgmime typefinder if gio was disabled via configure */
|
||||
#ifdef HAVE_GIO
|
||||
#include <gio/gio.h>
|
||||
#define USE_GIO
|
||||
#endif
|
||||
|
||||
#include <gst/gsttypefind.h>
|
||||
#include <gst/gstelement.h>
|
||||
#include <gst/gstversion.h>
|
||||
|
@ -3242,6 +3250,62 @@ vivo_type_find (GstTypeFind * tf, gpointer unused)
|
|||
}
|
||||
}
|
||||
|
||||
/*** XDG MIME typefinder (to avoid false positives mostly) ***/
|
||||
|
||||
#ifdef USE_GIO
|
||||
static void
|
||||
xdgmime_typefind (GstTypeFind * find, gpointer user_data)
|
||||
{
|
||||
gchar *mimetype;
|
||||
gsize length = 16384;
|
||||
guint64 tf_length;
|
||||
guint8 *data;
|
||||
gchar *tmp;
|
||||
|
||||
if ((tf_length = gst_type_find_get_length (find)) > 0)
|
||||
length = MIN (length, tf_length);
|
||||
|
||||
if ((data = gst_type_find_peek (find, 0, length)) == NULL)
|
||||
return;
|
||||
|
||||
tmp = g_content_type_guess (NULL, data, length, NULL);
|
||||
if (tmp == NULL || g_content_type_is_unknown (tmp)) {
|
||||
g_free (tmp);
|
||||
return;
|
||||
}
|
||||
|
||||
mimetype = g_content_type_get_mime_type (tmp);
|
||||
g_free (tmp);
|
||||
|
||||
if (mimetype == NULL)
|
||||
return;
|
||||
|
||||
GST_DEBUG ("Got mimetype '%s'", mimetype);
|
||||
|
||||
/* Ignore audio/video types:
|
||||
* - our own typefinders in -base are likely to be better at this
|
||||
* (and if they're not, we really want to fix them, that's why we don't
|
||||
* report xdg-detected audio/video types at all, not even with a low
|
||||
* probability)
|
||||
* - we want to detect GStreamer media types and not MIME types
|
||||
* - the purpose of this xdg mime finder is mainly to prevent false
|
||||
* positives of non-media formats, not to typefind audio/video formats */
|
||||
if (g_str_has_prefix (mimetype, "audio/") ||
|
||||
g_str_has_prefix (mimetype, "video/")) {
|
||||
GST_LOG ("Ignoring audio/video mime type");
|
||||
g_free (mimetype);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Again, we mainly want the xdg typefinding to prevent false-positives on
|
||||
* non-media formats, so suggest the type with a probability that trumps
|
||||
* uncertain results of our typefinders, but not more than that. */
|
||||
GST_LOG ("Suggesting '%s' with probability POSSIBLE", mimetype);
|
||||
gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE, mimetype, NULL);
|
||||
g_free (mimetype);
|
||||
}
|
||||
#endif /* USE_GIO */
|
||||
|
||||
/*** generic typefind for streams that have some data at a specific position***/
|
||||
typedef struct
|
||||
{
|
||||
|
@ -3688,6 +3752,12 @@ plugin_init (GstPlugin * plugin)
|
|||
TYPE_FIND_REGISTER_START_WITH (plugin, "image/vnd.adobe.photoshop",
|
||||
GST_RANK_SECONDARY, psd_exts, "8BPS\000\001\000\000\000\000", 10,
|
||||
GST_TYPE_FIND_LIKELY);
|
||||
|
||||
#ifdef USE_GIO
|
||||
TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,
|
||||
xdgmime_typefind, NULL, NULL, NULL, NULL);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue