diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-03-26 12:10:05 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-03-26 12:10:05 +0100 |
commit | eaea85ed4a2f8e442b713b50d89d5df35322c746 (patch) | |
tree | 437f3a29b14dfd1d523660899e6c0b8b9fd17acf /gst/xdgmime | |
parent | 81af2259c256ece5e576c1ff2ed375b5b00587fa (diff) | |
download | gst-plugins-bad-eaea85ed4a2f8e442b713b50d89d5df35322c746.tar.gz gst-plugins-bad-eaea85ed4a2f8e442b713b50d89d5df35322c746.tar.bz2 gst-plugins-bad-eaea85ed4a2f8e442b713b50d89d5df35322c746.zip |
xdgmime: Use GIOs g_content_type_guess() if possible
Diffstat (limited to 'gst/xdgmime')
-rw-r--r-- | gst/xdgmime/Makefile.am | 16 | ||||
-rw-r--r-- | gst/xdgmime/gstxdgmime.c | 56 |
2 files changed, 55 insertions, 17 deletions
diff --git a/gst/xdgmime/Makefile.am b/gst/xdgmime/Makefile.am index 0c1c7542..960747e7 100644 --- a/gst/xdgmime/Makefile.am +++ b/gst/xdgmime/Makefile.am @@ -1,7 +1,6 @@ plugin_LTLIBRARIES = libgstxdgmime.la -libgstxdgmime_la_SOURCES = gstxdgmime.c \ - xdgmime/xdgmimealias.c \ +xdgmime_sources = xdgmime/xdgmimealias.c \ xdgmime/xdgmime.c \ xdgmime/xdgmimecache.c \ xdgmime/xdgmimeglob.c \ @@ -9,8 +8,15 @@ libgstxdgmime_la_SOURCES = gstxdgmime.c \ xdgmime/xdgmimeint.c \ xdgmime/xdgmimemagic.c \ xdgmime/xdgmimeparent.c -libgstxdgmime_la_CFLAGS = $(GST_CFLAGS) -DXDG_PREFIX=gst_xdg_mime -libgstxdgmime_la_LIBADD = $(GST_LIBS) $(XDG_LIBS) + +if HAVE_GIO +libgstxdgmime_la_SOURCES = gstxdgmime.c +else +libgstxdgmime_la_SOURCES = gstxdgmime.c $(xdgmime_sources) +endif + +libgstxdgmime_la_CFLAGS = $(GIO_CFLAGS) $(GST_CFLAGS) -DXDG_PREFIX=gst_xdg_mime +libgstxdgmime_la_LIBADD = $(GIO_LIBS) $(GST_LIBS) $(XDG_LIBS) libgstxdgmime_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstxdgmime_la_LIBTOOLFLAGS = --tag=disable-static @@ -23,4 +29,4 @@ noinst_HEADERS = xdgmime/xdgmimealias.h \ xdgmime/xdgmimemagic.h \ xdgmime/xdgmimeparent.h -EXTRA_DIST = +EXTRA_DIST = $(xdgmime_sources) diff --git a/gst/xdgmime/gstxdgmime.c b/gst/xdgmime/gstxdgmime.c index 74253bfa..cd20764a 100644 --- a/gst/xdgmime/gstxdgmime.c +++ b/gst/xdgmime/gstxdgmime.c @@ -26,15 +26,18 @@ GST_DEBUG_CATEGORY (xdgmime_debug); #define GST_CAT_DEFAULT xdgmime_debug +#if GLIB_CHECK_VERSION (2, 16, 0) +#include <gio/gio.h> +#else G_LOCK_DEFINE_STATIC (xdg_lock); +#endif static void xdgmime_typefind (GstTypeFind * find, gpointer user_data) { - const gchar *mimetype; + gchar *mimetype; gsize length = 16384; guint64 tf_length; - gint prio; guint8 *data; if ((tf_length = gst_type_find_get_length (find)) > 0) @@ -43,18 +46,45 @@ xdgmime_typefind (GstTypeFind * find, gpointer user_data) if ((data = gst_type_find_peek (find, 0, length)) == NULL) return; - /* FIXME: xdg-mime is not thread-safe as it stores the cache globally - * and updates it from every call if changes were done without - * any locking - */ - G_LOCK (xdg_lock); - mimetype = xdg_mime_get_mime_type_for_data (data, length, &prio); - G_UNLOCK (xdg_lock); +#if GLIB_CHECK_VERSION (2, 16, 0) + { + gchar *tmp; - if (mimetype == NULL || g_str_equal (mimetype, XDG_MIME_TYPE_UNKNOWN)) - 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); + } +#else + { + const gchar *tmp; + gint prio; - GST_DEBUG ("Got mimetype '%s' with prio %d", mimetype, prio); + /* FIXME: xdg-mime is not thread-safe as it stores the cache globally + * and updates it from every call if changes were done without + * any locking + */ + G_LOCK (xdg_lock); + tmp = xdg_mime_get_mime_type_for_data (data, length, &prio); + G_UNLOCK (xdg_lock); + + if (tmp == NULL || g_str_equal (tmp, XDG_MIME_TYPE_UNKNOWN)) + return; + + GST_DEBUG ("Got mimetype '%s' with prio %d", tmp, prio); + + mimetype = g_strdup (tmp); + } +#endif /* Ignore audio/video types: * - our own typefinders in -base are likely to be better at this @@ -67,6 +97,7 @@ xdgmime_typefind (GstTypeFind * find, gpointer user_data) if (g_str_has_prefix (mimetype, "audio/") || g_str_has_prefix (mimetype, "video/")) { GST_LOG ("Ignoring audio/video mime type"); + g_free (mimetype); return; } @@ -75,6 +106,7 @@ xdgmime_typefind (GstTypeFind * find, gpointer user_data) * 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); } static gboolean |