udp: implement NetAddress with metadata

This commit is contained in:
Wim Taymans 2011-02-28 13:14:37 +01:00
parent de1ca68077
commit 6c4ccb272c
3 changed files with 18 additions and 26 deletions

View file

@ -211,34 +211,29 @@ gst_dynudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
GstDynUDPSink *sink;
gint ret, size;
guint8 *data;
GstBuffer *netbuf;
GstMetaNetAddress *meta;
struct sockaddr_in theiraddr;
guint16 destport;
guint32 destaddr;
memset (&theiraddr, 0, sizeof (theiraddr));
#if 0
if (GST_IS_NETBUFFER (buffer)) {
netbuf = GST_NETBUFFER (buffer);
} else
#endif
{
meta = gst_buffer_get_meta_net_address (buffer);
if (meta == NULL) {
GST_DEBUG ("Received buffer is not a GstNetBuffer, skipping");
return GST_FLOW_OK;
}
sink = GST_DYNUDPSINK (bsink);
size = GST_BUFFER_SIZE (netbuf);
data = GST_BUFFER_DATA (netbuf);
size = GST_BUFFER_SIZE (buffer);
data = GST_BUFFER_DATA (buffer);
GST_DEBUG ("about to send %d bytes", size);
#if 0
// let's get the address from the netbuffer
gst_netaddress_get_ip4_address (&netbuf->to, &destaddr, &destport);
#endif
/* let's get the address from the metaata */
gst_netaddress_get_ip4_address (&meta->naddr, &destaddr, &destport);
GST_DEBUG ("sending %d bytes to client %d port %d", size, destaddr, destport);

View file

@ -36,11 +36,10 @@ plugin_init (GstPlugin * plugin)
return FALSE;
#endif
#if 0
/* register type of the netbuffer so that we can use it from multiple threads
* right away. Note that the plugin loading is always serialized */
gst_netbuffer_get_type ();
#endif
/* register info of the netaddress metadata so that we can use it from
* multiple threads right away. Note that the plugin loading is always
* serialized */
gst_meta_net_address_get_info ();
if (!gst_element_register (plugin, "udpsink", GST_RANK_NONE,
GST_TYPE_UDPSINK))

View file

@ -409,9 +409,7 @@ static GstFlowReturn
gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
{
GstUDPSrc *udpsrc;
#if 0
GstNetBuffer *outbuf;
#endif
GstMetaNetAddress *meta;
GstBuffer *outbuf;
union gst_sockaddr
{
@ -530,7 +528,6 @@ no_select:
break;
}
/* FIXME use buffer metadata so receivers can also track the address */
outbuf = gst_buffer_new ();
GST_BUFFER_MALLOCDATA (outbuf) = pktdata;
@ -545,11 +542,13 @@ no_select:
GST_BUFFER_DATA (outbuf) = pktdata;
GST_BUFFER_SIZE (outbuf) = ret;
#if 0
/* use buffer metadata so receivers can also track the address */
meta = gst_buffer_add_meta_net_address (outbuf);
switch (sa.sa.sa_family) {
case AF_INET:
{
gst_netaddress_set_ip4_address (&outbuf->from, sa.sa_in.sin_addr.s_addr,
gst_netaddress_set_ip4_address (&meta->naddr, sa.sa_in.sin_addr.s_addr,
sa.sa_in.sin_port);
}
break;
@ -558,7 +557,7 @@ no_select:
guint8 ip6[16];
memcpy (ip6, &sa.sa_in6.sin6_addr, sizeof (ip6));
gst_netaddress_set_ip6_address (&outbuf->from, ip6, sa.sa_in6.sin6_port);
gst_netaddress_set_ip6_address (&meta->naddr, ip6, sa.sa_in6.sin6_port);
}
break;
default:
@ -569,7 +568,6 @@ no_select:
#endif
goto receive_error;
}
#endif
GST_LOG_OBJECT (udpsrc, "read %d bytes", (int) readsize);
*buf = GST_BUFFER_CAST (outbuf);