dashdemux: Handle encoding specified in the <xml> element when dumping nodes

Previous patch did not handle the case where an encoding (e.g. UTF-8) is
specified in the <xml ?> element. Added an extra test for with and without
encoding.

https://bugzilla.gnome.org/show_bug.cgi?id=753813
This commit is contained in:
Sebastian Dröge 2015-08-19 21:33:09 +03:00
parent 6a884bf08d
commit 551e7b97f3
2 changed files with 48 additions and 11 deletions

View file

@ -972,18 +972,10 @@ gst_mpdparser_get_xml_node_as_string (xmlNode * a_node, gchar ** content)
{ {
gboolean exists = FALSE; gboolean exists = FALSE;
const char *txt_encoding; const char *txt_encoding;
xmlCharEncodingHandlerPtr conv_hdlr = NULL;
xmlOutputBufferPtr out_buf; xmlOutputBufferPtr out_buf;
txt_encoding = (const char *) a_node->doc->encoding; txt_encoding = (const char *) a_node->doc->encoding;
if (txt_encoding != NULL) { out_buf = xmlAllocOutputBuffer (NULL);
conv_hdlr = xmlFindCharEncodingHandler (txt_encoding);
if (conv_hdlr == NULL) {
GST_ERROR ("Unable to find encoder for encoding: %s", txt_encoding);
return FALSE;
}
}
out_buf = xmlAllocOutputBuffer (conv_hdlr);
g_assert (out_buf != NULL); g_assert (out_buf != NULL);
xmlNodeDumpOutput (out_buf, a_node->doc, a_node, 0, 0, txt_encoding); xmlNodeDumpOutput (out_buf, a_node->doc, a_node, 0, 0, txt_encoding);
xmlOutputBufferFlush (out_buf); xmlOutputBufferFlush (out_buf);

View file

@ -1281,7 +1281,7 @@ GST_START_TEST (dash_mpdparser_contentProtection_no_value)
GstRepresentationBaseType *representationBase; GstRepresentationBaseType *representationBase;
GstDescriptorType *contentProtection; GstDescriptorType *contentProtection;
const gchar *xml = const gchar *xml =
"<?xml version=\"1.0\"?>" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\"" "<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\">" " profiles=\"urn:mpeg:dash:profile:isoff-main:2011\">"
" <Period>" " <Period>"
@ -1310,7 +1310,6 @@ GST_START_TEST (dash_mpdparser_contentProtection_no_value)
assert_equals_string (contentProtection->schemeIdUri, assert_equals_string (contentProtection->schemeIdUri,
"urn:uuid:5e629af5-38da-4063-8977-97ffbd9902d4"); "urn:uuid:5e629af5-38da-4063-8977-97ffbd9902d4");
fail_if (contentProtection->value == NULL); fail_if (contentProtection->value == NULL);
g_print ("%s\n", contentProtection->value);
/* We can't do a simple compare of value (which should be an XML dump /* We can't do a simple compare of value (which should be an XML dump
of the ContentProtection element), because the whitespace of the ContentProtection element), because the whitespace
formatting from xmlDump might differ between versions of libxml */ formatting from xmlDump might differ between versions of libxml */
@ -1331,6 +1330,50 @@ GST_START_TEST (dash_mpdparser_contentProtection_no_value)
GST_END_TEST; GST_END_TEST;
/*
* Test parsing ContentProtection element that has no value attribute
* nor an XML encoding
*/
GST_START_TEST (dash_mpdparser_contentProtection_no_value_no_encoding)
{
GstPeriodNode *periodNode;
GstAdaptationSetNode *adaptationSet;
GstRepresentationBaseType *representationBase;
GstDescriptorType *contentProtection;
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\">"
" <Period>"
" <AdaptationSet>"
" <ContentProtection schemeIdUri=\"urn:mpeg:dash:mp4protection:2011\" value=\"cenc\"/>"
" <ContentProtection xmlns:mas=\"urn:marlin:mas:1-0:services:schemas:mpd\" schemeIdUri=\"urn:uuid:5e629af5-38da-4063-8977-97ffbd9902d4\">"
" <mas:MarlinContentIds>"
" <mas:MarlinContentId>urn:marlin:kid:02020202020202020202020202020202</mas:MarlinContentId>"
" </mas:MarlinContentIds>"
" </ContentProtection>" "</AdaptationSet></Period></MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, (gint) strlen (xml));
assert_equals_int (ret, TRUE);
periodNode = (GstPeriodNode *) mpdclient->mpd_node->Periods->data;
adaptationSet = (GstAdaptationSetNode *) periodNode->AdaptationSets->data;
representationBase = adaptationSet->RepresentationBase;
assert_equals_int (g_list_length (representationBase->ContentProtection), 2);
contentProtection =
(GstDescriptorType *) g_list_nth (representationBase->ContentProtection,
1)->data;
assert_equals_string (contentProtection->schemeIdUri,
"urn:uuid:5e629af5-38da-4063-8977-97ffbd9902d4");
fail_if (contentProtection->value == NULL);
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/* /*
* Test parsing Period AdaptationSet Accessibility attributes * Test parsing Period AdaptationSet Accessibility attributes
* *
@ -4405,6 +4448,8 @@ dash_suite (void)
tcase_add_test (tc_simpleMPD, tcase_add_test (tc_simpleMPD,
dash_mpdparser_period_adaptationSet_representationBase_contentProtection); dash_mpdparser_period_adaptationSet_representationBase_contentProtection);
tcase_add_test (tc_simpleMPD, dash_mpdparser_contentProtection_no_value); tcase_add_test (tc_simpleMPD, dash_mpdparser_contentProtection_no_value);
tcase_add_test (tc_simpleMPD,
dash_mpdparser_contentProtection_no_value_no_encoding);
tcase_add_test (tc_simpleMPD, tcase_add_test (tc_simpleMPD,
dash_mpdparser_period_adaptationSet_accessibility); dash_mpdparser_period_adaptationSet_accessibility);
tcase_add_test (tc_simpleMPD, dash_mpdparser_period_adaptationSet_role); tcase_add_test (tc_simpleMPD, dash_mpdparser_period_adaptationSet_role);