From 231524cbbcd063a77e4f144b583629b2d607635d Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Sun, 29 Jul 2018 20:55:26 +0900 Subject: [PATCH] srt: Allow the host name "localhost" Add support "srt://localhost:port" style uri, and change the default host to "localhost" https://bugzilla.gnome.org/show_bug.cgi?id=796842 --- ext/srt/gstsrt.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++--------- ext/srt/gstsrt.h | 2 +- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/ext/srt/gstsrt.c b/ext/srt/gstsrt.c index 2f409a2..79e27a0 100644 --- a/ext/srt/gstsrt.c +++ b/ext/srt/gstsrt.c @@ -32,6 +32,56 @@ #define GST_CAT_DEFAULT gst_debug_srt GST_DEBUG_CATEGORY (GST_CAT_DEFAULT); +static GSocketAddress * +gst_srt_socket_address_new (GstElement * elem, const gchar * host, guint16 port) +{ + GInetAddress *iaddr = NULL; + GSocketAddress *addr = NULL; + GError *error = NULL; + + if (host == NULL) { + iaddr = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4); + } else { + iaddr = g_inet_address_new_from_string (host); + } + + if (!iaddr) { + GList *results; + GResolver *resolver = g_resolver_get_default (); + + results = g_resolver_lookup_by_name (resolver, host, NULL, &error); + + if (!results) { + GST_ERROR_OBJECT (elem, "Failed to resolve %s: %s", host, error->message); + g_object_unref (resolver); + goto failed; + } + + iaddr = G_INET_ADDRESS (g_object_ref (results->data)); + + g_resolver_free_addresses (results); + g_object_unref (resolver); + } +#ifndef GST_DISABLE_GST_DEBUG + { + gchar *ip = g_inet_address_to_string (iaddr); + + GST_DEBUG_OBJECT (elem, "IP address for host %s is %s", host, ip); + g_free (ip); + } +#endif + + addr = g_inet_socket_address_new (iaddr, port); + g_object_unref (iaddr); + + return addr; + +failed: + g_clear_error (&error); + + return NULL; +} + SRTSOCKET gst_srt_client_connect (GstElement * elem, int sender, const gchar * host, guint16 port, int rendez_vous, @@ -53,7 +103,7 @@ gst_srt_client_connect (GstElement * elem, int sender, goto failed; } - *socket_address = g_inet_socket_address_new_from_string (host, port); + *socket_address = gst_srt_socket_address_new (elem, host, port); if (*socket_address == NULL) { GST_ELEMENT_ERROR (elem, RESOURCE, OPEN_READ, ("Invalid host"), @@ -177,14 +227,7 @@ gst_srt_server_listen (GstElement * elem, int sender, const gchar * host, size_t sa_len; GSocketAddress *addr = NULL; - if (host == NULL) { - GInetAddress *any = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4); - - addr = g_inet_socket_address_new (any, port); - g_object_unref (any); - } else { - addr = g_inet_socket_address_new_from_string (host, port); - } + addr = gst_srt_socket_address_new (elem, host, port); if (addr == NULL) { GST_WARNING_OBJECT (elem, diff --git a/ext/srt/gstsrt.h b/ext/srt/gstsrt.h index 776593e..5f0e973 100644 --- a/ext/srt/gstsrt.h +++ b/ext/srt/gstsrt.h @@ -29,7 +29,7 @@ #define SRT_URI_SCHEME "srt" #define SRT_DEFAULT_PORT 7001 -#define SRT_DEFAULT_HOST "127.0.0.1" +#define SRT_DEFAULT_HOST "localhost" #define SRT_DEFAULT_URI SRT_URI_SCHEME"://"SRT_DEFAULT_HOST":"G_STRINGIFY(SRT_DEFAULT_PORT) #define SRT_DEFAULT_LATENCY 125 #define SRT_DEFAULT_KEY_LENGTH 16 -- 2.7.4