mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
xdgmime: Use GIOs g_content_type_guess() if possible
This commit is contained in:
parent
81af2259c2
commit
eaea85ed4a
3 changed files with 61 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 16, 0)
|
||||
{
|
||||
gchar *tmp;
|
||||
|
||||
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;
|
||||
|
||||
/* 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);
|
||||
tmp = xdg_mime_get_mime_type_for_data (data, length, &prio);
|
||||
G_UNLOCK (xdg_lock);
|
||||
|
||||
if (mimetype == NULL || g_str_equal (mimetype, XDG_MIME_TYPE_UNKNOWN))
|
||||
if (tmp == NULL || g_str_equal (tmp, XDG_MIME_TYPE_UNKNOWN))
|
||||
return;
|
||||
|
||||
GST_DEBUG ("Got mimetype '%s' with prio %d", mimetype, prio);
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue