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
This commit is contained in:
Vincent Penquerc'h 2011-01-24 11:45:21 +00:00 committed by Sebastian Dröge
parent 7cfa18545c
commit 7caf9e5e81

View file

@ -3869,6 +3869,48 @@ xdgmime_typefind (GstTypeFind * find, gpointer user_data)
} }
#endif /* USE_GIO */ #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***/ /*** generic typefind for streams that have some data at a specific position***/
typedef struct typedef struct
{ {
@ -4332,6 +4374,8 @@ plugin_init (GstPlugin * plugin)
GST_TYPE_FIND_LIKELY); GST_TYPE_FIND_LIKELY);
TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-yuv4mpeg", TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-yuv4mpeg",
GST_RANK_SECONDARY, y4m_exts, "YUV4MPEG2 ", 10, GST_TYPE_FIND_LIKELY); 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 #ifdef USE_GIO
TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL, TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,