mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-04 09:42:19 +00:00
netbuffer: Implement NetAddress with metadata
Make a NetAddress metadata.
This commit is contained in:
parent
c7c8f3e13d
commit
9ecff3c985
2 changed files with 43 additions and 86 deletions
|
@ -34,79 +34,48 @@
|
|||
|
||||
#include "gstnetbuffer.h"
|
||||
|
||||
#if 0
|
||||
static void gst_netbuffer_finalize (GstNetBuffer * nbuf);
|
||||
static GstNetBuffer *gst_netbuffer_copy (GstNetBuffer * nbuf);
|
||||
|
||||
static GstBufferClass *parent_class;
|
||||
|
||||
G_DEFINE_TYPE (GstNetBuffer, gst_netbuffer, GST_TYPE_BUFFER);
|
||||
|
||||
static void
|
||||
gst_netbuffer_class_init (GstNetBufferClass * netbuffer_class)
|
||||
meta_net_address_copy (GstBuffer * copy, GstMetaNetAddress * meta,
|
||||
GstBuffer * buffer)
|
||||
{
|
||||
GstMiniObjectClass *mo_class = GST_MINI_OBJECT_CLASS (netbuffer_class);
|
||||
GstMetaNetAddress *naddr;
|
||||
|
||||
parent_class = g_type_class_peek_parent (netbuffer_class);
|
||||
GST_DEBUG ("copy called from buffer %p to %p, meta %p", buffer, copy, meta);
|
||||
|
||||
mo_class->copy = (GstMiniObjectCopyFunction) gst_netbuffer_copy;
|
||||
mo_class->finalize = (GstMiniObjectFinalizeFunction) gst_netbuffer_finalize;
|
||||
naddr = gst_buffer_add_meta_net_address (copy);
|
||||
memcpy (&naddr->naddr, &meta->naddr, sizeof (meta->naddr));
|
||||
}
|
||||
|
||||
static void
|
||||
gst_netbuffer_init (GstNetBuffer * instance)
|
||||
meta_net_address_sub (GstBuffer * sub, GstMetaNetAddress * meta,
|
||||
GstBuffer * buffer, guint offset, guint size)
|
||||
{
|
||||
GstMetaNetAddress *naddr;
|
||||
|
||||
GST_DEBUG ("sub called from buffer %p to %p, meta %p, %u-%u", buffer, sub,
|
||||
meta, offset, size);
|
||||
|
||||
naddr = gst_buffer_add_meta_net_address (sub);
|
||||
memcpy (&naddr->naddr, &meta->naddr, sizeof (meta->naddr));
|
||||
}
|
||||
|
||||
static void
|
||||
gst_netbuffer_finalize (GstNetBuffer * nbuf)
|
||||
const GstMetaInfo *
|
||||
gst_meta_net_address_get_info (void)
|
||||
{
|
||||
GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (nbuf));
|
||||
static const GstMetaInfo *meta_info = NULL;
|
||||
|
||||
if (meta_info == NULL) {
|
||||
meta_info = gst_meta_register ("GstMetaNetAddress", "GstMetaNetAddress",
|
||||
sizeof (GstMetaNetAddress),
|
||||
(GstMetaInitFunction) NULL,
|
||||
(GstMetaFreeFunction) NULL,
|
||||
(GstMetaCopyFunction) meta_net_address_copy,
|
||||
(GstMetaSubFunction) meta_net_address_sub,
|
||||
(GstMetaSerializeFunction) NULL, (GstMetaDeserializeFunction) NULL);
|
||||
}
|
||||
return meta_info;
|
||||
}
|
||||
|
||||
static GstNetBuffer *
|
||||
gst_netbuffer_copy (GstNetBuffer * nbuf)
|
||||
{
|
||||
GstNetBuffer *copy;
|
||||
|
||||
copy = gst_netbuffer_new ();
|
||||
|
||||
/* we simply copy everything from our parent */
|
||||
GST_BUFFER_DATA (copy) =
|
||||
g_memdup (GST_BUFFER_DATA (nbuf), GST_BUFFER_SIZE (nbuf));
|
||||
/* make sure it gets freed (even if the parent is subclassed, we return a
|
||||
normal buffer) */
|
||||
GST_BUFFER_MALLOCDATA (copy) = GST_BUFFER_DATA (copy);
|
||||
GST_BUFFER_SIZE (copy) = GST_BUFFER_SIZE (nbuf);
|
||||
|
||||
memcpy (©->to, &nbuf->to, sizeof (nbuf->to));
|
||||
memcpy (©->from, &nbuf->from, sizeof (nbuf->from));
|
||||
|
||||
/* copy metadata */
|
||||
gst_buffer_copy_metadata (GST_BUFFER_CAST (copy),
|
||||
GST_BUFFER_CAST (nbuf), GST_BUFFER_COPY_ALL);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_netbuffer_new:
|
||||
*
|
||||
* Create a new network buffer.
|
||||
*
|
||||
* Returns: a new #GstNetBuffer.
|
||||
*/
|
||||
GstNetBuffer *
|
||||
gst_netbuffer_new (void)
|
||||
{
|
||||
GstNetBuffer *buf;
|
||||
|
||||
buf = (GstNetBuffer *) gst_mini_object_new (GST_TYPE_NETBUFFER);
|
||||
|
||||
return buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* gst_netaddress_set_ip4_address:
|
||||
* @naddr: a network address
|
||||
|
|
|
@ -66,7 +66,7 @@ typedef enum {
|
|||
/**
|
||||
* GstNetAddress:
|
||||
*
|
||||
* An opaque network address as used in #GstNetBuffer.
|
||||
* An opaque network address as used in #GstMetaNetAddress.
|
||||
*/
|
||||
struct _GstNetAddress {
|
||||
/*< private >*/
|
||||
|
@ -80,38 +80,26 @@ struct _GstNetAddress {
|
|||
gpointer _gst_reserved[GST_PADDING];
|
||||
};
|
||||
|
||||
#if 0
|
||||
typedef struct _GstMetaNetAddress GstMetaNetAddress;
|
||||
|
||||
/**
|
||||
* GstNetBuffer:
|
||||
* @buffer: the parent #GstBuffer
|
||||
* @from: the address where this buffer came from.
|
||||
* @to: the address where this buffer should go to.
|
||||
* GstMetaNetAddress:
|
||||
*
|
||||
* buffer for use in network sources and sinks.
|
||||
* It contains the source or destination address of the buffer.
|
||||
* Buffer metadata for network addresses.
|
||||
*/
|
||||
struct _GstNetBuffer {
|
||||
GstBuffer buffer;
|
||||
struct _GstMetaNetAddress {
|
||||
GstMeta meta;
|
||||
|
||||
GstNetAddress from;
|
||||
GstNetAddress to;
|
||||
|
||||
/*< private >*/
|
||||
gpointer _gst_reserved[GST_PADDING];
|
||||
GstNetAddress naddr;
|
||||
};
|
||||
|
||||
struct _GstNetBufferClass {
|
||||
GstBufferClass buffer_class;
|
||||
const GstMetaInfo *gst_meta_net_address_get_info (void);
|
||||
#define GST_META_NET_ADDRESS_INFO (gst_meta_net_address_get_info())
|
||||
|
||||
/*< private >*/
|
||||
gpointer _gst_reserved[GST_PADDING];
|
||||
};
|
||||
|
||||
/* creating buffers */
|
||||
GType gst_netbuffer_get_type (void);
|
||||
|
||||
GstNetBuffer* gst_netbuffer_new (void);
|
||||
#endif
|
||||
#define gst_buffer_get_meta_net_address(b) \
|
||||
((GstMetaNetAddress*)gst_buffer_get_meta((b),GST_META_NET_ADDRESS_INFO))
|
||||
#define gst_buffer_add_meta_net_address(b) \
|
||||
((GstMetaNetAddress*)gst_buffer_add_meta((b),GST_META_TIMING_INFO,NULL))
|
||||
|
||||
/* address operations */
|
||||
void gst_netaddress_set_ip4_address (GstNetAddress *naddr, guint32 address, guint16 port);
|
||||
|
|
Loading…
Reference in a new issue