2011-11-03 15:46:35 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-11-03 15:46:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstnetaddressmeta
|
2017-01-16 14:26:16 +00:00
|
|
|
* @title: GstNetAddressMeta
|
2011-11-03 15:46:35 +00:00
|
|
|
* @short_description: Network address metadata
|
|
|
|
*
|
2015-06-14 15:22:54 +00:00
|
|
|
* #GstNetAddressMeta can be used to store a network address (a #GSocketAddress)
|
|
|
|
* in a #GstBuffer so that it network elements can track the to and from address
|
|
|
|
* of the buffer.
|
2011-11-03 15:46:35 +00:00
|
|
|
*/
|
2018-08-25 21:56:01 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2011-11-03 15:46:35 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstnetaddressmeta.h"
|
|
|
|
|
2012-01-16 12:34:28 +00:00
|
|
|
static gboolean
|
2012-02-28 15:17:47 +00:00
|
|
|
net_address_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
|
2012-01-16 12:34:28 +00:00
|
|
|
{
|
2012-02-28 15:17:47 +00:00
|
|
|
GstNetAddressMeta *nmeta = (GstNetAddressMeta *) meta;
|
|
|
|
|
|
|
|
nmeta->addr = NULL;
|
2012-01-16 12:34:28 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:17:47 +00:00
|
|
|
static gboolean
|
|
|
|
net_address_meta_transform (GstBuffer * transbuf, GstMeta * meta,
|
2012-02-24 09:23:27 +00:00
|
|
|
GstBuffer * buffer, GQuark type, gpointer data)
|
2011-11-03 15:46:35 +00:00
|
|
|
{
|
2015-07-07 01:46:48 +00:00
|
|
|
GstNetAddressMeta *smeta, *dmeta;
|
|
|
|
smeta = (GstNetAddressMeta *) meta;
|
2012-02-28 15:17:47 +00:00
|
|
|
|
2012-02-24 09:23:27 +00:00
|
|
|
/* we always copy no matter what transform */
|
2015-07-07 01:46:48 +00:00
|
|
|
dmeta = gst_buffer_add_net_address_meta (transbuf, smeta->addr);
|
|
|
|
if (!dmeta)
|
|
|
|
return FALSE;
|
2012-02-28 15:17:47 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2012-01-16 12:34:28 +00:00
|
|
|
}
|
2011-11-03 15:46:35 +00:00
|
|
|
|
2012-01-16 12:34:28 +00:00
|
|
|
static void
|
2012-02-28 15:17:47 +00:00
|
|
|
net_address_meta_free (GstMeta * meta, GstBuffer * buffer)
|
2012-01-16 12:34:28 +00:00
|
|
|
{
|
2012-02-28 15:17:47 +00:00
|
|
|
GstNetAddressMeta *nmeta = (GstNetAddressMeta *) meta;
|
|
|
|
|
|
|
|
if (nmeta->addr)
|
|
|
|
g_object_unref (nmeta->addr);
|
|
|
|
nmeta->addr = NULL;
|
2011-11-03 15:46:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 16:20:23 +00:00
|
|
|
GType
|
|
|
|
gst_net_address_meta_api_get_type (void)
|
|
|
|
{
|
|
|
|
static volatile GType type;
|
|
|
|
static const gchar *tags[] = { "origin", NULL };
|
|
|
|
|
|
|
|
if (g_once_init_enter (&type)) {
|
|
|
|
GType _type = gst_meta_api_type_register ("GstNetAddressMetaAPI", tags);
|
|
|
|
g_once_init_leave (&type, _type);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2011-11-03 15:46:35 +00:00
|
|
|
const GstMetaInfo *
|
|
|
|
gst_net_address_meta_get_info (void)
|
|
|
|
{
|
|
|
|
static const GstMetaInfo *meta_info = NULL;
|
|
|
|
|
2016-11-14 19:27:05 +00:00
|
|
|
if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
|
2012-10-03 11:45:22 +00:00
|
|
|
const GstMetaInfo *mi = gst_meta_register (GST_NET_ADDRESS_META_API_TYPE,
|
2012-02-29 16:20:23 +00:00
|
|
|
"GstNetAddressMeta",
|
2011-11-03 15:46:35 +00:00
|
|
|
sizeof (GstNetAddressMeta),
|
2012-02-28 15:17:47 +00:00
|
|
|
net_address_meta_init,
|
2012-02-29 16:20:23 +00:00
|
|
|
net_address_meta_free, net_address_meta_transform);
|
2016-11-14 19:27:05 +00:00
|
|
|
g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) mi);
|
2011-11-03 15:46:35 +00:00
|
|
|
}
|
|
|
|
return meta_info;
|
|
|
|
}
|
|
|
|
|
2014-07-05 16:29:29 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_add_net_address_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @addr: a @GSocketAddress to connect to @buffer
|
|
|
|
*
|
|
|
|
* Attaches @addr as metadata in a #GstNetAddressMeta to @buffer.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a #GstNetAddressMeta connected to @buffer
|
|
|
|
*/
|
2012-01-16 12:34:28 +00:00
|
|
|
GstNetAddressMeta *
|
|
|
|
gst_buffer_add_net_address_meta (GstBuffer * buffer, GSocketAddress * addr)
|
2011-11-03 15:46:35 +00:00
|
|
|
{
|
2012-01-16 12:34:28 +00:00
|
|
|
GstNetAddressMeta *meta;
|
2011-11-03 15:46:35 +00:00
|
|
|
|
2012-01-16 12:34:28 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_SOCKET_ADDRESS (addr), NULL);
|
2011-11-03 15:46:35 +00:00
|
|
|
|
2012-01-16 12:34:28 +00:00
|
|
|
meta =
|
|
|
|
(GstNetAddressMeta *) gst_buffer_add_meta (buffer,
|
|
|
|
GST_NET_ADDRESS_META_INFO, NULL);
|
2011-11-03 15:46:35 +00:00
|
|
|
|
2012-01-16 12:34:28 +00:00
|
|
|
meta->addr = g_object_ref (addr);
|
2011-11-03 15:46:35 +00:00
|
|
|
|
2012-01-16 12:34:28 +00:00
|
|
|
return meta;
|
2011-11-03 15:46:35 +00:00
|
|
|
}
|
2015-10-26 11:50:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_get_net_address_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
*
|
|
|
|
* Find the #GstNetAddressMeta on @buffer.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the #GstNetAddressMeta or %NULL when there
|
|
|
|
* is no such metadata on @buffer.
|
|
|
|
*/
|
|
|
|
GstNetAddressMeta *
|
|
|
|
gst_buffer_get_net_address_meta (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
return (GstNetAddressMeta *)
|
|
|
|
gst_buffer_get_meta (buffer, GST_NET_ADDRESS_META_API_TYPE);
|
|
|
|
}
|