From 548bbc31471bdad19b65598991992d9d865680d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 14 Oct 2021 10:09:31 +0200 Subject: [PATCH] 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. Part-of: --- subprojects/gst-plugins-bad/ext/dash/gstmpdclient.c | 19 +++++++------------ subprojects/gst-plugins-bad/ext/dash/gstmpdparser.c | 18 +++++++++++++++--- subprojects/gst-plugins-bad/ext/dash/gstmpdparser.h | 2 +- .../ext/adaptivedemux2/dash/gstmpdclient.c | 19 +++++++------------ .../ext/adaptivedemux2/dash/gstmpdparser.c | 18 +++++++++++++++--- .../ext/adaptivedemux2/dash/gstmpdparser.h | 2 +- 6 files changed, 46 insertions(+), 32 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/dash/gstmpdclient.c b/subprojects/gst-plugins-bad/ext/dash/gstmpdclient.c index 8938ce7..60a523c 100644 --- a/subprojects/gst-plugins-bad/ext/dash/gstmpdclient.c +++ b/subprojects/gst-plugins-bad/ext/dash/gstmpdclient.c @@ -2041,9 +2041,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 = @@ -2315,9 +2313,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; @@ -2325,9 +2322,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; } @@ -2362,9 +2358,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 54ef72e..9a8862a 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 f51b962..c0930a4 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 diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdclient.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdclient.c index 50af5ea..c245012 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdclient.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdclient.c @@ -2045,9 +2045,7 @@ gst_mpd_client2_get_next_fragment (GstMPDClient2 * 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 = @@ -2320,9 +2318,8 @@ gst_mpd_client2_get_next_header (GstMPDClient2 * 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; @@ -2330,9 +2327,8 @@ gst_mpd_client2_get_next_header (GstMPDClient2 * 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; } @@ -2367,9 +2363,8 @@ gst_mpd_client2_get_next_header_index (GstMPDClient2 * 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-good/ext/adaptivedemux2/dash/gstmpdparser.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdparser.c index 7178411..9914ec1 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdparser.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdparser.c @@ -1397,7 +1397,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) { @@ -1409,9 +1415,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) @@ -1424,7 +1436,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-good/ext/adaptivedemux2/dash/gstmpdparser.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdparser.h index 7dd6f96..7ffadb2 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdparser.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstmpdparser.h @@ -165,7 +165,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 -- 2.7.4