rtspsrc: Fix regression when using hostname in the location property

When the address can't be parsed as an IP address, it should just be
treated as a hostname and used as-is.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1576

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3420>
This commit is contained in:
Nirbheek Chauhan 2022-11-16 13:33:39 +05:30 committed by GStreamer Marge Bot
parent c39400b52c
commit 13723198a1

View file

@ -4469,25 +4469,29 @@ element_make_from_addr (const GstURIType type, const char *addr_s,
char *uri = NULL; char *uri = NULL;
addr = g_inet_address_new_from_string (addr_s); addr = g_inet_address_new_from_string (addr_s);
if (addr == NULL) {
switch (g_inet_address_get_family (addr)) { /* Address is a hostname, not an IP address */
case G_SOCKET_FAMILY_IPV6: uri = g_strdup_printf ("udp://%s:%i", addr_s, port);
uri = g_strdup_printf ("udp://[%s]:%i", addr_s, port); } else {
break; switch (g_inet_address_get_family (addr)) {
case G_SOCKET_FAMILY_INVALID: case G_SOCKET_FAMILY_IPV6:
GST_ERROR ("Unknown family type for %s", addr_s); uri = g_strdup_printf ("udp://[%s]:%i", addr_s, port);
goto out; break;
case G_SOCKET_FAMILY_UNIX: case G_SOCKET_FAMILY_INVALID:
GST_ERROR ("Unexpected family type UNIX for %s", addr_s); GST_ERROR ("Unknown family type for %s", addr_s);
goto out; goto out;
case G_SOCKET_FAMILY_IPV4: case G_SOCKET_FAMILY_UNIX:
uri = g_strdup_printf ("udp://%s:%i", addr_s, port); GST_ERROR ("Unexpected family type UNIX for %s", addr_s);
break; goto out;
case G_SOCKET_FAMILY_IPV4:
uri = g_strdup_printf ("udp://%s:%i", addr_s, port);
break;
}
} }
element = gst_element_make_from_uri (type, uri, name, error); element = gst_element_make_from_uri (type, uri, name, error);
out: out:
g_object_unref (addr); g_clear_object (&addr);
g_free (uri); g_free (uri);
return element; return element;
} }