From 3ccf81a9e20283de238590f9976a4f2195b501e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 14 Oct 2021 10:18:40 +0200 Subject: [PATCH 1/4] mpdparser: Return correct mediaURL value This fixes a problem where get_mediaURL was returning NULL when segmentURL was unavailable instead of baseURL as a fallback. --- .../gst-plugins-bad/ext/dash/gstmpdparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c b/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c index f88bb6c807..54ef72e815 100644 --- a/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c +++ b/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c @@ -1393,7 +1393,7 @@ gst_mpdparser_get_mediaURL (GstActiveStream * stream, url_prefix = segmentURL->media ? segmentURL->media : stream->baseURL; g_return_val_if_fail (url_prefix != NULL, NULL); - return segmentURL->media; + return url_prefix; } /* navigation functions */ -- GitLab From 6a23c364759af3db4ff752d43a835ac25f94ed63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 14 Oct 2021 10:09:31 +0200 Subject: [PATCH 2/4] mpdparser: Be consistent about returning duplicated URL Instead of returning a "const gchar" or a "gchar" that should not be freed, always return a duplicated string as those functions were used together with g_strdup anyway. This is needed to prepare support for returning modified strings in next commit. --- .../gst-plugins-bad/ext/dash/gstmpdclient.c | 19 +++++++------------ .../gst-plugins-bad/ext/dash/gstmpdparser.c | 18 +++++++++++++++--- .../gst-plugins-bad/ext/dash/gstmpdparser.h | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/dash/gstmpdclient.c b/subprojects/gst-plugins-bad/ext/dash/gstmpdclient.c index fdaaa659c8..dc63a95212 100644 --- a/subprojects/gst-plugins-bad/ext/dash/gstmpdclient.c +++ b/subprojects/gst-plugins-bad/ext/dash/gstmpdclient.c @@ -2025,9 +2025,7 @@ gst_mpd_client_get_next_fragment (GstMPDClient * client, GST_DEBUG ("currentChunk->SegmentURL = %p", currentChunk->SegmentURL); if (currentChunk->SegmentURL != NULL) { - mediaURL = - g_strdup (gst_mpdparser_get_mediaURL (stream, - currentChunk->SegmentURL)); + mediaURL = gst_mpdparser_get_mediaURL (stream, currentChunk->SegmentURL); indexURL = g_strdup (currentChunk->SegmentURL->index); } else if (stream->cur_seg_template != NULL) { mediaURL = @@ -2299,9 +2297,8 @@ gst_mpd_client_get_next_header (GstMPDClient * client, gchar ** uri, *uri = NULL; if (stream->cur_segment_base) { if (stream->cur_segment_base->Initialization) { - *uri = - g_strdup (gst_mpdparser_get_initializationURL (stream, - stream->cur_segment_base->Initialization)); + *uri = gst_mpdparser_get_initializationURL (stream, + stream->cur_segment_base->Initialization); if (stream->cur_segment_base->Initialization->range) { *range_start = stream->cur_segment_base->Initialization->range->first_byte_pos; @@ -2309,9 +2306,8 @@ gst_mpd_client_get_next_header (GstMPDClient * client, gchar ** uri, stream->cur_segment_base->Initialization->range->last_byte_pos; } } else if (stream->cur_segment_base->indexRange) { - *uri = - g_strdup (gst_mpdparser_get_initializationURL (stream, - stream->cur_segment_base->Initialization)); + *uri = gst_mpdparser_get_initializationURL (stream, + stream->cur_segment_base->Initialization); *range_start = 0; *range_end = stream->cur_segment_base->indexRange->first_byte_pos - 1; } @@ -2346,9 +2342,8 @@ gst_mpd_client_get_next_header_index (GstMPDClient * client, gchar ** uri, GST_DEBUG ("Looking for current representation index"); *uri = NULL; if (stream->cur_segment_base && stream->cur_segment_base->indexRange) { - *uri = - g_strdup (gst_mpdparser_get_initializationURL (stream, - stream->cur_segment_base->RepresentationIndex)); + *uri = gst_mpdparser_get_initializationURL (stream, + stream->cur_segment_base->RepresentationIndex); *range_start = stream->cur_segment_base->indexRange->first_byte_pos; *range_end = stream->cur_segment_base->indexRange->last_byte_pos; } else if (stream->cur_seg_template && stream->cur_seg_template->index) { diff --git a/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c b/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c index 54ef72e815..9a8862a1f1 100644 --- a/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c +++ b/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c @@ -1366,7 +1366,13 @@ gst_mpdparser_free_active_stream (GstActiveStream * active_stream) } } -const gchar * +/* + * gst_mpdparser_get_initializationURL: + * + * Returns: (transfer full): stream initializationURL if available, + * baseURL otherwise. + */ +gchar * gst_mpdparser_get_initializationURL (GstActiveStream * stream, GstMPDURLTypeNode * InitializationURL) { @@ -1378,9 +1384,15 @@ gst_mpdparser_get_initializationURL (GstActiveStream * stream, && InitializationURL->sourceURL) ? InitializationURL->sourceURL : stream-> baseURL; - return url_prefix; + return g_strdup (url_prefix); } +/* + * gst_mpdparser_get_mediaURL: + * + * Returns: (transfer full): stream mediaURL if available, + * baseURL otherwise. + */ gchar * gst_mpdparser_get_mediaURL (GstActiveStream * stream, GstMPDSegmentURLNode * segmentURL) @@ -1393,7 +1405,7 @@ gst_mpdparser_get_mediaURL (GstActiveStream * stream, url_prefix = segmentURL->media ? segmentURL->media : stream->baseURL; g_return_val_if_fail (url_prefix != NULL, NULL); - return url_prefix; + return g_strdup (url_prefix); } /* navigation functions */ diff --git a/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.h b/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.h index f51b962bf1..c0930a45e0 100644 --- a/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.h +++ b/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.h @@ -162,7 +162,7 @@ void gst_mpdparser_media_fragment_info_clear (GstMediaFragmentInfo * fragment); /* Active stream methods*/ void gst_mpdparser_init_active_stream_segments (GstActiveStream * stream); gchar *gst_mpdparser_get_mediaURL (GstActiveStream * stream, GstMPDSegmentURLNode * segmentURL); -const gchar *gst_mpdparser_get_initializationURL (GstActiveStream * stream, GstMPDURLTypeNode * InitializationURL); +gchar *gst_mpdparser_get_initializationURL (GstActiveStream * stream, GstMPDURLTypeNode * InitializationURL); gchar *gst_mpdparser_build_URL_from_template (const gchar * url_template, const gchar * id, guint number, guint bandwidth, guint64 time); G_END_DECLS -- GitLab From d7e2756d3207da49c6254c2ad84a842d3448009b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 14 Oct 2021 10:12:51 +0200 Subject: [PATCH 3/4] mpdparser: Fix missing baseURL query When no initializationURL or mediaURL, return baseURL that also contains original URI query if available. This fixes a problem where URI query was being omitted in the HTTP requests. --- .../gst-plugins-bad/ext/dash/gstmpdparser.c | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c b/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c index 9a8862a1f1..c36f2acb5b 100644 --- a/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c +++ b/subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c @@ -1366,46 +1366,56 @@ gst_mpdparser_free_active_stream (GstActiveStream * active_stream) } } +static gchar * +get_base_url_with_query (GstActiveStream * stream) +{ + GstUri *uri; + gchar *uri_str; + + if (!stream->queryURL) + return g_strdup (stream->baseURL); + + uri = gst_uri_from_string (stream->baseURL); + gst_uri_set_query_string (uri, stream->queryURL); + uri_str = gst_uri_to_string (uri); + + gst_uri_unref (uri); + return uri_str; +} + /* * gst_mpdparser_get_initializationURL: * * Returns: (transfer full): stream initializationURL if available, - * baseURL otherwise. + * baseURL combined with queryURL otherwise. */ gchar * gst_mpdparser_get_initializationURL (GstActiveStream * stream, GstMPDURLTypeNode * InitializationURL) { - const gchar *url_prefix; - g_return_val_if_fail (stream != NULL, NULL); - url_prefix = (InitializationURL - && InitializationURL->sourceURL) ? InitializationURL->sourceURL : stream-> - baseURL; - - return g_strdup (url_prefix); + return (InitializationURL && InitializationURL->sourceURL) + ? g_strdup (InitializationURL->sourceURL) + : get_base_url_with_query (stream); } /* * gst_mpdparser_get_mediaURL: * * Returns: (transfer full): stream mediaURL if available, - * baseURL otherwise. + * baseURL combined with queryURL otherwise. */ gchar * gst_mpdparser_get_mediaURL (GstActiveStream * stream, GstMPDSegmentURLNode * segmentURL) { - const gchar *url_prefix; - g_return_val_if_fail (stream != NULL, NULL); g_return_val_if_fail (segmentURL != NULL, NULL); - url_prefix = segmentURL->media ? segmentURL->media : stream->baseURL; - g_return_val_if_fail (url_prefix != NULL, NULL); - - return g_strdup (url_prefix); + return (segmentURL->media) + ? g_strdup (segmentURL->media) + : get_base_url_with_query (stream); } /* navigation functions */ -- GitLab From e029547ff59647f83690eeced60cdbf82cc0795b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 14 Oct 2021 11:56:58 +0200 Subject: [PATCH 4/4] tests: Add DASH MPD baseURL with query test --- .../tests/check/elements/dash_mpd.c | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) 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 c7adab8f34..7ca250ecd0 100644 --- a/subprojects/gst-plugins-bad/tests/check/elements/dash_mpd.c +++ b/subprojects/gst-plugins-bad/tests/check/elements/dash_mpd.c @@ -4230,6 +4230,57 @@ GST_START_TEST (dash_mpdparser_get_baseURL8) GST_END_TEST; +/* + * Test getting baseURL with query + * + */ +GST_START_TEST (dash_mpdparser_get_baseURL_with_query) +{ + gboolean ret; + gchar *uri; + gint64 range_start, range_end; + const gchar *xml = + "" + "" + " " + " " + " " + " http://example.com/test?param1=value1&param2=value2" + " " + " " + " " + " "; + + GstMPDClient *mpdclient = setup_mpd_client (xml); + + /* get segment url and range from segment Initialization */ + ret = + gst_mpd_client_get_next_header (mpdclient, &uri, 0, &range_start, + &range_end); + assert_equals_int (ret, TRUE); + assert_equals_string (uri, + "http://example.com/test?param1=value1¶m2=value2"); + assert_equals_int64 (range_start, 0); + assert_equals_int64 (range_end, 100); + g_free (uri); + + /* get segment url and range from segment indexRange */ + ret = + gst_mpd_client_get_next_header_index (mpdclient, &uri, 0, &range_start, + &range_end); + assert_equals_int (ret, TRUE); + assert_equals_string (uri, + "http://example.com/test?param1=value1¶m2=value2"); + assert_equals_int64 (range_start, 100); + assert_equals_int64 (range_end, 200); + g_free (uri); + + gst_mpd_client_free (mpdclient); +} + +GST_END_TEST; + /* * Test getting mediaPresentationDuration * @@ -6631,6 +6682,7 @@ dash_suite (void) tcase_add_test (tc_complexMPD, dash_mpdparser_get_baseURL6); tcase_add_test (tc_complexMPD, dash_mpdparser_get_baseURL7); tcase_add_test (tc_complexMPD, dash_mpdparser_get_baseURL8); + tcase_add_test (tc_complexMPD, dash_mpdparser_get_baseURL_with_query); tcase_add_test (tc_complexMPD, dash_mpdparser_get_mediaPresentationDuration); tcase_add_test (tc_complexMPD, dash_mpdparser_get_streamPresentationOffset); tcase_add_test (tc_complexMPD, dash_mpdparser_segments); -- GitLab