diff options
author | Philippe Normand <philn@igalia.com> | 2015-06-11 18:14:47 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2015-06-11 19:46:02 +0200 |
commit | d182e66bcef175a14a0c2afb2c46558be7bd038f (patch) | |
tree | d1ae6b4791bc96b8b70d35e48d99e06135af17ca | |
parent | 9c47e7d5e6fd273107c3b7acc7dc428f4a8766df (diff) |
typefindfunctions: UTF-8 MSS Manifest detection support
Check if the first bytes of data contain an UTF-8 BOM.
https://bugzilla.gnome.org/show_bug.cgi?id=750802
-rw-r--r-- | gst/typefind/gsttypefindfunctions.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index 2aa0bf0f5..def9217a6 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -3580,6 +3580,7 @@ mss_manifest_type_find (GstTypeFind * tf, gpointer unused) glong n_read = 0, size = 0; guint length; gchar *utf8; + gboolean utf8_bom_detected = FALSE; if (xml_check_first_element (tf, "SmoothStreamingMedia", 20, TRUE)) { gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MSS_MANIFEST_CAPS); @@ -3595,7 +3596,9 @@ mss_manifest_type_find (GstTypeFind * tf, gpointer unused) return; /* look for a possible BOM */ - if (data[0] == 0xFF && data[1] == 0xFE) + if (data[0] == 0xEF && data[1] == 0xBB) + utf8_bom_detected = TRUE; + else if (data[0] == 0xFF && data[1] == 0xFE) data_endianness = G_LITTLE_ENDIAN; else if (data[0] == 0xFE && data[1] == 0xFF) data_endianness = G_BIG_ENDIAN; @@ -3619,20 +3622,29 @@ mss_manifest_type_find (GstTypeFind * tf, gpointer unused) data += 2; length -= 2; - length = GST_ROUND_DOWN_2 (length); - - /* convert to native endian UTF-16 */ - mss_manifest_load_utf16 (utf16_ne, data, length, data_endianness); + if (utf8_bom_detected) { + /* skip last byte of the BOM */ + data++; + length--; - /* and now convert to UTF-8 */ - utf8 = g_utf16_to_utf8 (utf16_ne, length / 2, &n_read, &size, NULL); - if (utf8 != NULL && n_read > 0) { - if (xml_check_first_element_from_data ((const guint8 *) utf8, size, + if (xml_check_first_element_from_data (data, length, "SmoothStreamingMedia", 20, TRUE)) gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MSS_MANIFEST_CAPS); - } + } else { + length = GST_ROUND_DOWN_2 (length); - g_free (utf8); + /* convert to native endian UTF-16 */ + mss_manifest_load_utf16 (utf16_ne, data, length, data_endianness); + + /* and now convert to UTF-8 */ + utf8 = g_utf16_to_utf8 (utf16_ne, length / 2, &n_read, &size, NULL); + if (utf8 != NULL && n_read > 0) { + if (xml_check_first_element_from_data ((const guint8 *) utf8, size, + "SmoothStreamingMedia", 20, TRUE)) + gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MSS_MANIFEST_CAPS); + } + g_free (utf8); + } } /*** image/jpeg ***/ |