summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Bass <floobleflam@gmail.com>2020-08-25 14:56:50 +0100
committerTim-Philipp Müller <tim@centricular.com>2020-12-05 20:50:34 +0000
commit84a287c2dfd9409154fd2d4f363230116bd21a94 (patch)
treedb2ed9e579a8be17d4e0f69a2198a97745e81973
parent2e981f069031dfe25d2d865bb521445529dd2459 (diff)
downloadgstreamer-plugins-bad-84a287c2dfd9409154fd2d4f363230116bd21a94.tar.gz
ttmlparse: Handle whitespace before XML declaration
When ttmlparse is in, e.g., an MPEG-DASH pipeline, there may be whitespace between successive TTML documents in ttmlparse's accumulated input. As libxml2 will fail to parse documents that have whitespace before the opening XML declaration, ensure that any preceding whitespace is not passed to libxml2. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1859>
-rw-r--r--ext/ttml/ttmlparse.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/ext/ttml/ttmlparse.c b/ext/ttml/ttmlparse.c
index 4914910f7..3c7d8f07c 100644
--- a/ext/ttml/ttmlparse.c
+++ b/ext/ttml/ttmlparse.c
@@ -1926,6 +1926,7 @@ ttml_find_child (xmlNodePtr parent, const gchar * name)
return child;
}
+#define XML_START_TAG "<?xml"
#define TTML_END_TAG "</tt>"
guint
@@ -1941,7 +1942,8 @@ ttml_parse (const gchar * input, GstClockTime begin, GstClockTime duration,
guint cellres_x, cellres_y;
TtmlWhitespaceMode doc_whitespace_mode = TTML_WHITESPACE_MODE_DEFAULT;
guint consumed = 0;
- gchar *end_tt;
+ guint start_offset = 0;
+ gchar *start_xml, *end_tt;
g_return_val_if_fail (parsed != NULL, 0);
@@ -1952,14 +1954,16 @@ ttml_parse (const gchar * input, GstClockTime begin, GstClockTime duration,
}
GST_CAT_LOG (ttmlparse_debug, "Input:\n%s", input);
+ start_xml = g_strstr_len (input, strlen (input), XML_START_TAG);
end_tt = g_strstr_len (input, strlen (input), TTML_END_TAG);
- if (!end_tt) {
+ if (!start_xml || !end_tt) {
GST_CAT_DEBUG (ttmlparse_debug, "Need more data");
return 0;
}
consumed = end_tt - input + strlen (TTML_END_TAG);
+ start_offset = start_xml - input;
styles_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) ttml_delete_element);
@@ -1967,7 +1971,8 @@ ttml_parse (const gchar * input, GstClockTime begin, GstClockTime duration,
(GDestroyNotify) ttml_delete_element);
/* Parse input. */
- doc = xmlReadMemory (input, consumed, "any_doc_name", NULL, 0);
+ doc = xmlReadMemory (start_xml, consumed - start_offset, "any_doc_name",
+ NULL, 0);
if (!doc) {
GST_CAT_ERROR (ttmlparse_debug, "Failed to parse document.");
return 0;