mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-19 05:45:58 +00:00
tcp: Convert tcpclientsrc to new helpers.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1105>
This commit is contained in:
parent
0fefbc932a
commit
13743353cb
1 changed files with 33 additions and 44 deletions
|
@ -408,58 +408,50 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc)
|
|||
{
|
||||
GstTCPClientSrc *src = GST_TCP_CLIENT_SRC (bsrc);
|
||||
GError *err = NULL;
|
||||
GInetAddress *addr;
|
||||
GList *addrs;
|
||||
GList *cur_addr;
|
||||
GSocketAddress *saddr;
|
||||
GResolver *resolver;
|
||||
|
||||
src->bytes_received = 0;
|
||||
gst_clear_structure (&src->stats);
|
||||
|
||||
/* look up name if we need to */
|
||||
addr = g_inet_address_new_from_string (src->host);
|
||||
if (!addr) {
|
||||
GList *results;
|
||||
addrs =
|
||||
tcp_get_addresses (GST_ELEMENT (src), src->host, src->cancellable, &err);
|
||||
if (!addrs)
|
||||
goto name_resolve;
|
||||
|
||||
resolver = g_resolver_get_default ();
|
||||
cur_addr = addrs;
|
||||
while (cur_addr) {
|
||||
/* iterate over addresses until one works */
|
||||
src->socket =
|
||||
tcp_create_socket (GST_ELEMENT (src), &cur_addr, src->port, &saddr,
|
||||
&err);
|
||||
if (!src->socket)
|
||||
break;
|
||||
|
||||
results =
|
||||
g_resolver_lookup_by_name (resolver, src->host, src->cancellable, &err);
|
||||
if (!results)
|
||||
goto name_resolve;
|
||||
addr = G_INET_ADDRESS (g_object_ref (results->data));
|
||||
/* create receiving client socket */
|
||||
GST_DEBUG_OBJECT (src, "opening receiving client socket to %s:%d",
|
||||
src->host, src->port);
|
||||
|
||||
g_resolver_free_addresses (results);
|
||||
g_object_unref (resolver);
|
||||
g_socket_set_timeout (src->socket, src->timeout);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "opened receiving client socket");
|
||||
GST_OBJECT_FLAG_SET (src, GST_TCP_CLIENT_SRC_OPEN);
|
||||
|
||||
/* connect to server */
|
||||
if (g_socket_connect (src->socket, saddr, src->cancellable, &err))
|
||||
break;
|
||||
|
||||
/* failed to connect, release and try next address... */
|
||||
g_clear_object (&src->socket);
|
||||
g_clear_object (&saddr);
|
||||
}
|
||||
#ifndef GST_DISABLE_GST_DEBUG
|
||||
{
|
||||
gchar *ip = g_inet_address_to_string (addr);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "IP address for host %s is %s", src->host, ip);
|
||||
g_free (ip);
|
||||
}
|
||||
#endif
|
||||
|
||||
saddr = g_inet_socket_address_new (addr, src->port);
|
||||
g_object_unref (addr);
|
||||
|
||||
/* create receiving client socket */
|
||||
GST_DEBUG_OBJECT (src, "opening receiving client socket to %s:%d",
|
||||
src->host, src->port);
|
||||
|
||||
src->socket =
|
||||
g_socket_new (g_socket_address_get_family (saddr), G_SOCKET_TYPE_STREAM,
|
||||
G_SOCKET_PROTOCOL_TCP, &err);
|
||||
g_list_free_full (addrs, g_object_unref);
|
||||
if (!src->socket)
|
||||
goto no_socket;
|
||||
|
||||
g_socket_set_timeout (src->socket, src->timeout);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "opened receiving client socket");
|
||||
GST_OBJECT_FLAG_SET (src, GST_TCP_CLIENT_SRC_OPEN);
|
||||
|
||||
/* connect to server */
|
||||
if (!g_socket_connect (src->socket, saddr, src->cancellable, &err))
|
||||
/* we should only have a valid saddr if connect was successful */
|
||||
if (!saddr)
|
||||
goto connect_failed;
|
||||
|
||||
g_object_unref (saddr);
|
||||
|
@ -471,19 +463,17 @@ no_socket:
|
|||
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
|
||||
("Failed to create socket: %s", err->message));
|
||||
g_clear_error (&err);
|
||||
g_object_unref (saddr);
|
||||
return FALSE;
|
||||
}
|
||||
name_resolve:
|
||||
{
|
||||
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||
GST_DEBUG_OBJECT (src, "Cancelled name resolval");
|
||||
GST_DEBUG_OBJECT (src, "Cancelled name resolution");
|
||||
} else {
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
|
||||
("Failed to resolve host '%s': %s", src->host, err->message));
|
||||
}
|
||||
g_clear_error (&err);
|
||||
g_object_unref (resolver);
|
||||
return FALSE;
|
||||
}
|
||||
connect_failed:
|
||||
|
@ -496,7 +486,6 @@ connect_failed:
|
|||
err->message));
|
||||
}
|
||||
g_clear_error (&err);
|
||||
g_object_unref (saddr);
|
||||
gst_tcp_client_src_stop (GST_BASE_SRC (src));
|
||||
return FALSE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue