From 7caf9e5e81ab9846918729b32e6e653fb80c6e14 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Mon, 24 Jan 2011 11:45:21 +0000 Subject: [PATCH] typefind: add detection for windows icon files to get them out of the way Some of them can otherwise be misdetected for MPEG audio. https://bugzilla.gnome.org/show_bug.cgi?id=620364 --- gst/typefind/gsttypefindfunctions.c | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index 373df083d6..afdff15c3c 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -3869,6 +3869,48 @@ xdgmime_typefind (GstTypeFind * find, gpointer user_data) } #endif /* USE_GIO */ +/*** Windows icon typefinder (to avoid false positives mostly) ***/ + +static void +windows_icon_typefind (GstTypeFind * find, gpointer user_data) +{ + guint8 *data; + gint64 datalen; + guint16 type, nimages; + gint32 size, offset; + + datalen = gst_type_find_get_length (find); + if ((data = gst_type_find_peek (find, 0, 6)) == NULL) + return; + + /* header - simple and not enough to rely on it alone */ + if (GST_READ_UINT16_LE (data) != 0) + return; + type = GST_READ_UINT16_LE (data + 2); + if (type != 1 && type != 2) + return; + nimages = GST_READ_UINT16_LE (data + 4); + if (nimages == 0) /* we can assume we can't have an empty image file ? */ + return; + + /* first image */ + if (data[6 + 3] != 0) + return; + if (type == 1) { + guint16 planes = GST_READ_UINT16_LE (data + 6 + 4); + if (planes > 1) + return; + } + size = GST_READ_UINT32_LE (data + 6 + 8); + offset = GST_READ_UINT32_LE (data + 6 + 12); + if (offset < 0 || size <= 0 || size >= datalen || offset >= datalen + || size + offset > datalen) + return; + + gst_type_find_suggest_simple (find, GST_TYPE_FIND_NEARLY_CERTAIN, + "image/vnd.microsoft.icon", NULL); +} + /*** generic typefind for streams that have some data at a specific position***/ typedef struct { @@ -4332,6 +4374,8 @@ plugin_init (GstPlugin * plugin) GST_TYPE_FIND_LIKELY); TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-yuv4mpeg", GST_RANK_SECONDARY, y4m_exts, "YUV4MPEG2 ", 10, GST_TYPE_FIND_LIKELY); + TYPE_FIND_REGISTER (plugin, "image/vnd.microsoft.icon", GST_RANK_MARGINAL, + windows_icon_typefind, NULL, NULL, NULL, NULL); #ifdef USE_GIO TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,