From 2a19805f7d86212107fb7280e69690124567695d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Mon, 18 Nov 2024 12:31:21 +0100 Subject: [PATCH] dash: handle 0 duration in gst_xml_helper_set_prop_duration Add dash_mpdparser_check_mpd_client_set_period_to_0 unit test to demonstrate it. Part-of: --- .../gst-plugins-bad/ext/dash/gstxmlhelper.c | 2 + .../tests/check/elements/dash_mpd.c | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/subprojects/gst-plugins-bad/ext/dash/gstxmlhelper.c b/subprojects/gst-plugins-bad/ext/dash/gstxmlhelper.c index d4db559c8e..6cf176863d 100644 --- a/subprojects/gst-plugins-bad/ext/dash/gstxmlhelper.c +++ b/subprojects/gst-plugins-bad/ext/dash/gstxmlhelper.c @@ -1203,6 +1203,8 @@ gst_xml_helper_set_prop_duration (xmlNode * node, const gchar * name, GST_LOG ("duration %" G_GUINT64_FORMAT " -> %s", value, text); xmlSetProp (node, (xmlChar *) name, (xmlChar *) text); g_free (text); + } else { + xmlSetProp (node, (xmlChar *) name, (xmlChar *) "PT0S"); } } diff --git a/subprojects/gst-plugins-bad/tests/check/elements/dash_mpd.c b/subprojects/gst-plugins-bad/tests/check/elements/dash_mpd.c index 91d6cc505d..2f91a81294 100644 --- a/subprojects/gst-plugins-bad/tests/check/elements/dash_mpd.c +++ b/subprojects/gst-plugins-bad/tests/check/elements/dash_mpd.c @@ -6520,6 +6520,53 @@ GST_START_TEST (dash_mpdparser_check_mpd_client_set_methods) GST_END_TEST; +GST_START_TEST (dash_mpdparser_check_mpd_client_set_period_to_0) +{ + GstMPDClient *mpdclient = NULL; + GstMPDPeriodNode *period; + gchar *period_id; + gchar *new_xml; + gint new_xml_size; + const gchar *xml = "\n" + "" + "TestBaseURL" + "\n"; + + mpdclient = gst_mpd_client_new (); + gst_mpd_client_set_root_node (mpdclient, + "default-namespace", "urn:mpeg:dash:schema:mpd:2011", + "profiles", "urn:mpeg:dash:profile:isoff-main:2011", + "schema-location", "TestSchemaLocation", + "namespace-xsi", "TestNamespaceXSI", + "namespace-ext", "TestNamespaceEXT", "id", "testId", NULL); + gst_mpd_client_add_baseurl_node (mpdclient, + "url", "TestBaseURL", + "service-location", "TestServiceLocation", + "byte-range", "TestByteRange", NULL); + period_id = gst_mpd_client_set_period_node (mpdclient, (gchar *) "TestId", "start", (guint64) 0, // ms + "duration", (guint64) 40000, "bitstream-switching", 1, NULL); + + /* Period */ + period = (GstMPDPeriodNode *) mpdclient->mpd_root_node->Periods->data; + + assert_equals_string (period_id, "TestId"); + assert_equals_string (period->id, "TestId"); + assert_equals_int64 (period->start, 0); + assert_equals_int64 (period->duration, 40000); + assert_equals_int (period->bitstreamSwitching, 1); + + /* XML content */ + gst_mpd_client_get_xml_content (mpdclient, &new_xml, &new_xml_size); + assert_equals_string (xml, new_xml); + g_free (new_xml); + + gst_mpd_client_free (mpdclient); +} + +GST_END_TEST; + /* * create a test suite containing all dash testcases */ @@ -6544,6 +6591,8 @@ dash_suite (void) /* test mpd client set methods */ tcase_add_test (tc_simpleMPD, dash_mpdparser_check_mpd_client_set_methods); + tcase_add_test (tc_simpleMPD, + dash_mpdparser_check_mpd_client_set_period_to_0); /* tests parsing attributes from each element type */ tcase_add_test (tc_simpleMPD, dash_mpdparser_mpd);