mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
udpsrc: Refactor address resolval into its own function
This commit is contained in:
parent
966f848edb
commit
edf6d28765
1 changed files with 45 additions and 31 deletions
|
@ -769,33 +769,21 @@ gst_udpsrc_get_property (GObject * object, guint prop_id, GValue * value,
|
|||
}
|
||||
}
|
||||
|
||||
/* create a socket for sending to remote machine */
|
||||
static gboolean
|
||||
gst_udpsrc_start (GstBaseSrc * bsrc)
|
||||
static GInetAddress *
|
||||
gst_udpsrc_resolve (GstUDPSrc * src, const gchar * address)
|
||||
{
|
||||
GstUDPSrc *src;
|
||||
GInetAddress *addr, *bind_addr;
|
||||
GSocketAddress *bind_saddr;
|
||||
GResolver *resolver;
|
||||
GInetAddress *addr;
|
||||
GError *err = NULL;
|
||||
GResolver *resolver;
|
||||
|
||||
src = GST_UDPSRC (bsrc);
|
||||
|
||||
if (src->socket == NULL) {
|
||||
/* need to allocate a socket */
|
||||
GST_DEBUG_OBJECT (src, "allocating socket for %s:%d", src->multi_group,
|
||||
src->port);
|
||||
|
||||
addr = g_inet_address_new_from_string (src->multi_group);
|
||||
addr = g_inet_address_new_from_string (address);
|
||||
if (!addr) {
|
||||
GList *results;
|
||||
|
||||
GST_DEBUG_OBJECT (src, "resolving IP address for host %s",
|
||||
src->multi_group);
|
||||
GST_DEBUG_OBJECT (src, "resolving IP address for host %s", address);
|
||||
resolver = g_resolver_get_default ();
|
||||
results =
|
||||
g_resolver_lookup_by_name (resolver, src->multi_group,
|
||||
src->cancellable, &err);
|
||||
g_resolver_lookup_by_name (resolver, address, src->cancellable, &err);
|
||||
if (!results)
|
||||
goto name_resolve;
|
||||
addr = G_INET_ADDRESS (g_object_ref (results->data));
|
||||
|
@ -807,12 +795,42 @@ gst_udpsrc_start (GstBaseSrc * bsrc)
|
|||
{
|
||||
gchar *ip = g_inet_address_to_string (addr);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "IP address for host %s is %s", src->multi_group,
|
||||
ip);
|
||||
GST_DEBUG_OBJECT (src, "IP address for host %s is %s", address, ip);
|
||||
g_free (ip);
|
||||
}
|
||||
#endif
|
||||
|
||||
return addr;
|
||||
|
||||
name_resolve:
|
||||
{
|
||||
GST_WARNING_OBJECT (src, "Failed to resolve %s: %s", address, err->message);
|
||||
g_clear_error (&err);
|
||||
g_object_unref (resolver);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* create a socket for sending to remote machine */
|
||||
static gboolean
|
||||
gst_udpsrc_start (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstUDPSrc *src;
|
||||
GInetAddress *addr, *bind_addr;
|
||||
GSocketAddress *bind_saddr;
|
||||
GError *err = NULL;
|
||||
|
||||
src = GST_UDPSRC (bsrc);
|
||||
|
||||
if (src->socket == NULL) {
|
||||
/* need to allocate a socket */
|
||||
GST_DEBUG_OBJECT (src, "allocating socket for %s:%d", src->multi_group,
|
||||
src->port);
|
||||
|
||||
addr = gst_udpsrc_resolve (src, src->multi_group);
|
||||
if (!addr)
|
||||
goto name_resolve;
|
||||
|
||||
if ((src->used_socket =
|
||||
g_socket_new (g_inet_address_get_family (addr),
|
||||
G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &err)) == NULL)
|
||||
|
@ -971,10 +989,6 @@ gst_udpsrc_start (GstBaseSrc * bsrc)
|
|||
/* ERRORS */
|
||||
name_resolve:
|
||||
{
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
|
||||
("Name resolval failed: %s", err->message));
|
||||
g_clear_error (&err);
|
||||
g_object_unref (resolver);
|
||||
return FALSE;
|
||||
}
|
||||
no_socket:
|
||||
|
|
Loading…
Reference in a new issue