From fd1e75900db48fc008899c5712a39ca16a0681b0 Mon Sep 17 00:00:00 2001 From: Alex Ashley Date: Tue, 24 Aug 2021 14:33:42 +0100 Subject: dashdemux: copy ContentProtection element including xml namespaces Commit bc09d8cc changed gstmpdparser to put the entire element in the "value" field, so that DRMs other than PlayReady could make use of the data inside this element. However, the data in the "value" field does not include any XML namespace declarations that are used within the element. This causes problems for a namespace aware XML parser that wants to make use of this data. This commit modifies the way the XML is converted to a string so that XML namespaces are preserved in the output. Part-of: --- ext/dash/gstxmlhelper.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/dash/gstxmlhelper.c b/ext/dash/gstxmlhelper.c index ee7aa661c..d4db559c8 100644 --- a/ext/dash/gstxmlhelper.c +++ b/ext/dash/gstxmlhelper.c @@ -975,11 +975,24 @@ gst_xml_helper_get_node_as_string (xmlNode * a_node, gchar ** content) gboolean exists = FALSE; const char *txt_encoding; xmlOutputBufferPtr out_buf; + xmlNode *ncopy = NULL; txt_encoding = (const char *) a_node->doc->encoding; out_buf = xmlAllocOutputBuffer (NULL); g_assert (out_buf != NULL); - xmlNodeDumpOutput (out_buf, a_node->doc, a_node, 0, 0, txt_encoding); + + /* Need to make a copy of XML element so that it includes namespaces + in the output, so that the resulting string can be parsed by an XML parser + that is namespace aware. + Use extended=1 for recursive copy (properties, namespaces and children) */ + ncopy = xmlDocCopyNode (a_node, a_node->doc, 1); + + if (!ncopy) { + GST_WARNING ("Failed to clone XML node"); + goto done; + } + xmlNodeDumpOutput (out_buf, ncopy->doc, ncopy, 0, 0, txt_encoding); + (void) xmlOutputBufferFlush (out_buf); #ifdef LIBXML2_NEW_BUFFER if (xmlOutputBufferGetSize (out_buf) > 0) { @@ -999,6 +1012,8 @@ gst_xml_helper_get_node_as_string (xmlNode * a_node, gchar ** content) exists = TRUE; } #endif // LIBXML2_NEW_BUFFER + xmlFreeNode (ncopy); +done: (void) xmlOutputBufferClose (out_buf); if (exists) { -- cgit v1.2.1