dash: handle 0 duration in gst_xml_helper_set_prop_duration
authorStéphane Cerveau <scerveau@igalia.com>
Mon, 18 Nov 2024 11:31:21 +0000 (12:31 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 20 Dec 2024 12:55:51 +0000 (12:55 +0000)
Add dash_mpdparser_check_mpd_client_set_period_to_0
unit test to demonstrate it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8114>

subprojects/gst-plugins-bad/ext/dash/gstxmlhelper.c
subprojects/gst-plugins-bad/tests/check/elements/dash_mpd.c

index d4db559c8e522df666d82bc3ddb35d3318dfabfc..6cf176863d9ff82b5450bdf09f584fc292f80709 100644 (file)
@@ -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");
   }
 }
 
index 91d6cc505d91f0671535c3f93261741f0555e044..2f91a8129410b64f094e360ee0d035d39311a952 100644 (file)
@@ -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 = "<?xml version=\"1.0\"?>\n"
+      "<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\" "
+      "schemaLocation=\"TestSchemaLocation\" xmlns:xsi=\"TestNamespaceXSI\" xmlns:ext=\"TestNamespaceEXT\" "
+      "id=\"testId\" type=\"static\" minBufferTime=\"P0Y0M0DT0H0M2.0S\">"
+      "<BaseURL serviceLocation=\"TestServiceLocation\" byteRange=\"TestByteRange\">TestBaseURL</BaseURL>"
+      "<Period id=\"TestId\" start=\"PT0S\" duration=\"P0Y0M0DT0H0M40.0S\" bitstreamSwitching=\"true\"/></MPD>\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);