mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-19 14:56:36 +00:00
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
This commit is contained in:
parent
9c47e7d5e6
commit
d182e66bce
1 changed files with 23 additions and 11 deletions
|
@ -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);
|
||||
if (utf8_bom_detected) {
|
||||
/* skip last byte of the BOM */
|
||||
data++;
|
||||
length--;
|
||||
|
||||
/* 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,
|
||||
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 ***/
|
||||
|
|
Loading…
Reference in a new issue