2009-02-24 14:26:27 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (xdgmime_debug);
|
|
|
|
#define GST_CAT_DEFAULT xdgmime_debug
|
|
|
|
|
2009-03-26 11:10:05 +00:00
|
|
|
#include <gio/gio.h>
|
2009-03-02 15:27:55 +00:00
|
|
|
|
2009-02-24 14:26:27 +00:00
|
|
|
static void
|
|
|
|
xdgmime_typefind (GstTypeFind * find, gpointer user_data)
|
|
|
|
{
|
2009-03-26 11:10:05 +00:00
|
|
|
gchar *mimetype;
|
2009-02-24 14:26:27 +00:00
|
|
|
gsize length = 16384;
|
|
|
|
guint64 tf_length;
|
|
|
|
guint8 *data;
|
2009-08-30 20:17:53 +00:00
|
|
|
gchar *tmp;
|
2009-02-24 14:26:27 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-03-26 11:10:05 +00:00
|
|
|
|
2009-08-30 20:17:53 +00:00
|
|
|
tmp = g_content_type_guess (NULL, data, length, NULL);
|
|
|
|
if (tmp == NULL || g_content_type_is_unknown (tmp)) {
|
2009-03-26 11:10:05 +00:00
|
|
|
g_free (tmp);
|
2009-08-30 20:17:53 +00:00
|
|
|
return;
|
2009-03-26 11:10:05 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 20:17:53 +00:00
|
|
|
mimetype = g_content_type_get_mime_type (tmp);
|
|
|
|
g_free (tmp);
|
2009-03-26 11:10:05 +00:00
|
|
|
|
2009-08-30 20:17:53 +00:00
|
|
|
if (mimetype == NULL)
|
|
|
|
return;
|
2009-03-26 11:10:05 +00:00
|
|
|
|
2009-08-30 20:17:53 +00:00
|
|
|
GST_DEBUG ("Got mimetype '%s'", mimetype);
|
2009-02-24 14:26:27 +00:00
|
|
|
|
2009-03-12 23:54:12 +00:00
|
|
|
/* 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");
|
2009-03-26 11:10:05 +00:00
|
|
|
g_free (mimetype);
|
2009-03-12 23:54:12 +00:00
|
|
|
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);
|
2009-03-26 11:10:05 +00:00
|
|
|
g_free (mimetype);
|
2009-02-24 14:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2009-02-27 19:21:23 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2009-02-24 14:26:27 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (xdgmime_debug, "xdgmime", 0, "XDG-MIME");
|
|
|
|
|
2009-02-27 19:21:23 +00:00
|
|
|
ret = gst_type_find_register (plugin,
|
2009-08-30 20:17:53 +00:00
|
|
|
"xdgmime", GST_RANK_MARGINAL, xdgmime_typefind, NULL, NULL, NULL, NULL);
|
2009-02-27 19:21:23 +00:00
|
|
|
|
|
|
|
return ret;
|
2009-02-24 14:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"xdgmime",
|
|
|
|
"XDG-MIME",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|