mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-30 04:45:36 +00:00
udpsrc: Port to GIO
This commit is contained in:
parent
d55f75f6f4
commit
7f74fc9ef6
7 changed files with 362 additions and 420 deletions
|
@ -15,10 +15,8 @@ BUILT_SOURCES = $(built_sources) $(built_headers)
|
||||||
|
|
||||||
libgstudp_la_SOURCES = gstudp.c gstudpsrc.c gstudpsink.c gstmultiudpsink.c gstdynudpsink.c gstudpnetutils.c
|
libgstudp_la_SOURCES = gstudp.c gstudpsrc.c gstudpsink.c gstmultiudpsink.c gstdynudpsink.c gstudpnetutils.c
|
||||||
|
|
||||||
# adding -D_GNU_SOURCE to get non-POSIX extensions like EAI_ADDRFAMILY
|
libgstudp_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_NET_CFLAGS) $(GST_CFLAGS) $(GIO_CFLAGS) -D_GNU_SOURCE
|
||||||
# with glibc >= 2.8 when including netdb.h (see glibc sources bug 6452)
|
libgstudp_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_NET_LIBS) $(GIO_LIBS)
|
||||||
libgstudp_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_NET_CFLAGS) $(GST_CFLAGS) -D_GNU_SOURCE
|
|
||||||
libgstudp_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_NET_LIBS) $(WIN32_LIBS)
|
|
||||||
libgstudp_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
libgstudp_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||||
libgstudp_la_LIBTOOLFLAGS = --tag=disable-static
|
libgstudp_la_LIBTOOLFLAGS = --tag=disable-static
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,7 @@ gst_dynudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
||||||
struct sockaddr_in theiraddr;
|
struct sockaddr_in theiraddr;
|
||||||
guint16 destport;
|
guint16 destport;
|
||||||
guint32 destaddr;
|
guint32 destaddr;
|
||||||
|
const guint8 *destaddr_bytes;
|
||||||
|
|
||||||
memset (&theiraddr, 0, sizeof (theiraddr));
|
memset (&theiraddr, 0, sizeof (theiraddr));
|
||||||
|
|
||||||
|
@ -199,7 +200,12 @@ gst_dynudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
||||||
GST_DEBUG ("about to send %" G_GSIZE_FORMAT " bytes", size);
|
GST_DEBUG ("about to send %" G_GSIZE_FORMAT " bytes", size);
|
||||||
|
|
||||||
/* let's get the address from the metaata */
|
/* let's get the address from the metaata */
|
||||||
gst_net_address_get_ip4_address (&meta->naddr, &destaddr, &destport);
|
destaddr_bytes =
|
||||||
|
g_inet_address_to_bytes (g_inet_socket_address_get_address
|
||||||
|
(G_INET_SOCKET_ADDRESS (meta->addr)));
|
||||||
|
destaddr = GST_READ_UINT32_BE (destaddr_bytes);
|
||||||
|
destport =
|
||||||
|
g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (meta->addr));
|
||||||
|
|
||||||
GST_DEBUG ("sending %" G_GSIZE_FORMAT " bytes to client %d port %d", size,
|
GST_DEBUG ("sending %" G_GSIZE_FORMAT " bytes to client %d port %d", size,
|
||||||
destaddr, destport);
|
destaddr, destport);
|
||||||
|
|
|
@ -367,8 +367,8 @@ gst_udp_uri_update (GstUDPUri * uri, const gchar * host, gint port)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
gboolean
|
||||||
gst_udp_parse_uri (const gchar * uristr, GstUDPUri * uri)
|
gst_udp_parse_uri (const gchar * uristr, gchar ** host, guint16 * port)
|
||||||
{
|
{
|
||||||
gchar *protocol, *location_start;
|
gchar *protocol, *location_start;
|
||||||
gchar *location, *location_end;
|
gchar *location, *location_end;
|
||||||
|
@ -402,49 +402,45 @@ gst_udp_parse_uri (const gchar * uristr, GstUDPUri * uri)
|
||||||
if (location_end == NULL)
|
if (location_end == NULL)
|
||||||
goto wrong_address;
|
goto wrong_address;
|
||||||
|
|
||||||
uri->is_ipv6 = TRUE;
|
*host = g_strndup (location + 1, location_end - location - 1);
|
||||||
g_free (uri->host);
|
|
||||||
uri->host = g_strndup (location + 1, location_end - location - 1);
|
|
||||||
colptr = strrchr (location_end, ':');
|
colptr = strrchr (location_end, ':');
|
||||||
} else {
|
} else {
|
||||||
GST_DEBUG ("parse IPV4 address '%s'", location);
|
GST_DEBUG ("parse IPV4 address '%s'", location);
|
||||||
uri->is_ipv6 = FALSE;
|
|
||||||
colptr = strrchr (location, ':');
|
colptr = strrchr (location, ':');
|
||||||
|
|
||||||
g_free (uri->host);
|
|
||||||
if (colptr != NULL) {
|
if (colptr != NULL) {
|
||||||
uri->host = g_strndup (location, colptr - location);
|
*host = g_strndup (location, colptr - location);
|
||||||
} else {
|
} else {
|
||||||
uri->host = g_strdup (location);
|
*host = g_strdup (location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GST_DEBUG ("host set to '%s'", uri->host);
|
GST_DEBUG ("host set to '%s'", *host);
|
||||||
|
|
||||||
if (colptr != NULL) {
|
if (colptr != NULL) {
|
||||||
uri->port = atoi (colptr + 1);
|
*port = atoi (colptr + 1);
|
||||||
}
|
}
|
||||||
g_free (location_start);
|
g_free (location_start);
|
||||||
|
|
||||||
return 0;
|
return TRUE;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
no_protocol:
|
no_protocol:
|
||||||
{
|
{
|
||||||
GST_ERROR ("error parsing uri %s: no protocol", uristr);
|
GST_ERROR ("error parsing uri %s: no protocol", uristr);
|
||||||
return -1;
|
return FALSE;
|
||||||
}
|
}
|
||||||
wrong_protocol:
|
wrong_protocol:
|
||||||
{
|
{
|
||||||
GST_ERROR ("error parsing uri %s: wrong protocol (%s != udp)", uristr,
|
GST_ERROR ("error parsing uri %s: wrong protocol (%s != udp)", uristr,
|
||||||
protocol);
|
protocol);
|
||||||
g_free (protocol);
|
g_free (protocol);
|
||||||
return -1;
|
return FALSE;
|
||||||
}
|
}
|
||||||
wrong_address:
|
wrong_address:
|
||||||
{
|
{
|
||||||
GST_ERROR ("error parsing uri %s", uristr);
|
GST_ERROR ("error parsing uri %s", uristr);
|
||||||
g_free (location);
|
g_free (location);
|
||||||
return -1;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ gboolean gst_udp_net_utils_win32_wsa_startup (GstObject * obj);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
gchar *host;
|
gchar *host;
|
||||||
gint port;
|
guint16 port;
|
||||||
gboolean is_ipv6;
|
gboolean is_ipv6;
|
||||||
} GstUDPUri;
|
} GstUDPUri;
|
||||||
|
|
||||||
|
@ -102,9 +102,10 @@ int gst_udp_leave_group (int sockfd, struct sockaddr_storage *addr)
|
||||||
/* uri handling */
|
/* uri handling */
|
||||||
void gst_udp_uri_init (GstUDPUri *uri, const gchar *host, gint port);
|
void gst_udp_uri_init (GstUDPUri *uri, const gchar *host, gint port);
|
||||||
int gst_udp_uri_update (GstUDPUri *uri, const gchar *host, gint port);
|
int gst_udp_uri_update (GstUDPUri *uri, const gchar *host, gint port);
|
||||||
int gst_udp_parse_uri (const gchar *uristr, GstUDPUri *uri);
|
|
||||||
gchar * gst_udp_uri_string (GstUDPUri *uri);
|
gchar * gst_udp_uri_string (GstUDPUri *uri);
|
||||||
void gst_udp_uri_free (GstUDPUri *uri);
|
void gst_udp_uri_free (GstUDPUri *uri);
|
||||||
|
|
||||||
|
gboolean gst_udp_parse_uri (const gchar *uristr, gchar **host, guint16 *port);
|
||||||
|
|
||||||
#endif /* __GST_UDP_NET_UTILS_H__*/
|
#endif /* __GST_UDP_NET_UTILS_H__*/
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ gst_udpsink_set_uri (GstUDPSink * sink, const gchar * uri, GError ** error)
|
||||||
gst_multiudpsink_remove (GST_MULTIUDPSINK (sink), sink->uri.host,
|
gst_multiudpsink_remove (GST_MULTIUDPSINK (sink), sink->uri.host,
|
||||||
sink->uri.port);
|
sink->uri.port);
|
||||||
|
|
||||||
if (gst_udp_parse_uri (uri, &sink->uri) < 0)
|
if (gst_udp_parse_uri (uri, &sink->uri.host, &sink->uri.port) < 0)
|
||||||
goto wrong_uri;
|
goto wrong_uri;
|
||||||
|
|
||||||
gst_multiudpsink_add (GST_MULTIUDPSINK (sink), sink->uri.host,
|
gst_multiudpsink_add (GST_MULTIUDPSINK (sink), sink->uri.host,
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -23,15 +23,11 @@
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/base/gstpushsrc.h>
|
#include <gst/base/gstpushsrc.h>
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include "gstudpnetutils.h"
|
#include "gstudpnetutils.h"
|
||||||
|
|
||||||
#include "gstudp.h"
|
#include "gstudp.h"
|
||||||
|
|
||||||
#define GST_TYPE_UDPSRC \
|
#define GST_TYPE_UDPSRC \
|
||||||
|
@ -53,27 +49,26 @@ struct _GstUDPSrc {
|
||||||
GstPushSrc parent;
|
GstPushSrc parent;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
GstUDPUri uri;
|
gchar *host;
|
||||||
|
gint port;
|
||||||
gchar *multi_iface;
|
gchar *multi_iface;
|
||||||
gint ttl;
|
gint ttl;
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
gint buffer_size;
|
gint buffer_size;
|
||||||
guint64 timeout;
|
guint64 timeout;
|
||||||
gint skip_first_bytes;
|
gint skip_first_bytes;
|
||||||
int sockfd;
|
GSocket *socket;
|
||||||
gboolean closefd;
|
gboolean close_socket;
|
||||||
gboolean auto_multicast;
|
gboolean auto_multicast;
|
||||||
gboolean reuse;
|
gboolean reuse;
|
||||||
|
|
||||||
/* our sockets */
|
/* our sockets */
|
||||||
GstPollFD sock;
|
GSocket *used_socket;
|
||||||
GstPoll *fdset;
|
GCancellable *cancellable;
|
||||||
gboolean externalfd;
|
GInetSocketAddress *addr;
|
||||||
gboolean is_ipv6;
|
gboolean external_socket;
|
||||||
|
|
||||||
struct sockaddr_storage myaddr;
|
gchar *uri;
|
||||||
|
|
||||||
gchar *uristr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstUDPSrcClass {
|
struct _GstUDPSrcClass {
|
||||||
|
|
Loading…
Reference in a new issue