summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac6
-rw-r--r--gst/xdgmime/Makefile.am16
-rw-r--r--gst/xdgmime/gstxdgmime.c56
3 files changed, 61 insertions, 17 deletions
diff --git a/configure.ac b/configure.ac
index 77eacfb2..64427808 100644
--- a/configure.ac
+++ b/configure.ac
@@ -316,6 +316,12 @@ dnl disable experimental plug-ins
#if test "x$BUILD_EXPERIMENTAL" != "xyes"; then
#fi
+# For xdgmime, to use g_content_type_guess()
+PKG_CHECK_MODULES(GIO, gio-2.0 >= 2.16, HAVE_GIO=yes, HAVE_GIO=no)
+AM_CONDITIONAL(HAVE_GIO, test "x$HAVE_GIO" = "xyes")
+AC_SUBST(GIO_CFLAGS)
+AC_SUBST(GIO_LIBS)
+
dnl disable gst plugins we might not be able to build on this
dnl platform: librfb (ugly but minimally invasive)
dnl FIXME: maybe move to sys, or make work with winsock2
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