rtspsrc: use version template in user-agent property

Avoids documentation churn when the version changes.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5090>
This commit is contained in:
Tim-Philipp Müller 2023-08-05 17:27:31 +01:00 committed by GStreamer Marge Bot
parent e89a64cd1f
commit 5bbd8c2d71
3 changed files with 61 additions and 4 deletions

View file

@ -21628,7 +21628,7 @@
"construct": false,
"construct-only": false,
"controllable": false,
"default": "GStreamer/1.23.0.1",
"default": "GStreamer/{VERSION}",
"mutable": "null",
"readable": true,
"type": "gchararray",

View file

@ -29,6 +29,53 @@ G_BEGIN_DECLS
/* copies */
#if !GLIB_CHECK_VERSION(2,68,0)
#ifndef g_string_replace
#define g_string_replace gst_g_string_replace
#endif
static inline guint
gst_g_string_replace (GString *string,
const gchar *find,
const gchar *replace,
guint limit)
{
gsize f_len, r_len, pos;
gchar *cur, *next;
guint n = 0;
g_return_val_if_fail (string != NULL, 0);
g_return_val_if_fail (find != NULL, 0);
g_return_val_if_fail (replace != NULL, 0);
f_len = strlen (find);
r_len = strlen (replace);
cur = string->str;
while ((next = strstr (cur, find)) != NULL)
{
pos = next - string->str;
g_string_erase (string, pos, f_len);
g_string_insert (string, pos, replace);
cur = string->str + pos + r_len;
n++;
/* Only match the empty string once at any given position, to
* avoid infinite loops */
if (f_len == 0)
{
if (cur[0] == '\0')
break;
else
cur++;
}
if (n == limit)
break;
}
return n;
}
#endif /* GLIB_CHECK_VERSION */
/* adaptations */
G_END_DECLS

View file

@ -117,6 +117,8 @@
#include "gstrtspelements.h"
#include "gstrtspsrc.h"
#include <gst/glib-compat-private.h>
GST_DEBUG_CATEGORY_STATIC (rtspsrc_debug);
#define GST_CAT_DEFAULT (rtspsrc_debug)
@ -299,7 +301,7 @@ gst_rtsp_backchannel_get_type (void)
#define DEFAULT_TLS_INTERACTION NULL
#define DEFAULT_DO_RETRANSMISSION TRUE
#define DEFAULT_NTP_TIME_SOURCE NTP_TIME_SOURCE_NTP
#define DEFAULT_USER_AGENT "GStreamer/" PACKAGE_VERSION
#define DEFAULT_USER_AGENT "GStreamer/{VERSION}"
#define DEFAULT_MAX_RTCP_RTP_TIME_DIFF 1000
#define DEFAULT_RFC7273_SYNC FALSE
#define DEFAULT_ADD_REFERENCE_TIMESTAMP_META FALSE
@ -895,6 +897,9 @@ gst_rtspsrc_class_init (GstRTSPSrcClass * klass)
*
* The string to set in the User-Agent header.
*
* If the string contains `{VERSION}` that will be replaced with the
* GStreamer version at runtime (since GStreamer 1.24).
*
* Since: 1.6
*/
g_object_class_install_property (gobject_class, PROP_USER_AGENT,
@ -5467,8 +5472,13 @@ gst_rtspsrc_init_request (GstRTSPSrc * src, GstRTSPMessage * msg,
return res;
/* set user-agent */
if (src->user_agent)
gst_rtsp_message_add_header (msg, GST_RTSP_HDR_USER_AGENT, src->user_agent);
if (src->user_agent) {
GString *user_agent = g_string_new (src->user_agent);
g_string_replace (user_agent, "{VERSION}", PACKAGE_VERSION, 0);
gst_rtsp_message_add_header (msg, GST_RTSP_HDR_USER_AGENT, user_agent->str);
g_string_free (user_agent, TRUE);
}
return res;
}