2005-07-01 20:56:07 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
|
2006-01-07 20:01:09 +00:00
|
|
|
* Copyright (C) <2005> Nokia Corporation <kai.vehmanen@nokia.com>
|
2006-07-24 11:48:03 +00:00
|
|
|
* Copyright (C) <2006> Joni Valtanen <joni.valtanen@movial.fi>
|
2012-01-17 08:32:27 +00:00
|
|
|
* Copyright (C) <2012> Collabora Ltd.
|
|
|
|
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
2005-07-01 20:56:07 +00:00
|
|
|
*
|
|
|
|
* 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-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2005-07-01 20:56:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
#include "gstdynudpsink.h"
|
2007-11-02 21:16:09 +00:00
|
|
|
|
2011-11-03 15:43:00 +00:00
|
|
|
#include <gst/net/gstnetaddressmeta.h>
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2006-06-22 19:31:04 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (dynudpsink_debug);
|
2005-07-01 20:56:07 +00:00
|
|
|
#define GST_CAT_DEFAULT (dynudpsink_debug)
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
/* DynUDPSink signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* methods */
|
|
|
|
SIGNAL_GET_STATS,
|
|
|
|
|
|
|
|
/* signals */
|
|
|
|
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
#define UDP_DEFAULT_SOCKET NULL
|
|
|
|
#define UDP_DEFAULT_CLOSE_SOCKET TRUE
|
2013-05-23 16:42:09 +00:00
|
|
|
#define UDP_DEFAULT_BIND_ADDRESS NULL
|
|
|
|
#define UDP_DEFAULT_BIND_PORT 0
|
gst/udp/: Rework the socket allocation a bit based on the sockfd argument so that it becomes usable.
Original commit message from CVS:
Patch by: Laurent Glayal <spglegle at yahoo dot fr>
* gst/udp/gstdynudpsink.c: (gst_dynudpsink_class_init),
(gst_dynudpsink_init), (gst_dynudpsink_set_property),
(gst_dynudpsink_get_property), (gst_dynudpsink_init_send),
(gst_dynudpsink_close):
* gst/udp/gstdynudpsink.h:
* gst/udp/gstudpsrc.c: (gst_udpsrc_class_init), (gst_udpsrc_init),
(gst_udpsrc_create), (gst_udpsrc_set_property),
(gst_udpsrc_get_property), (gst_udpsrc_start), (gst_udpsrc_stop):
* gst/udp/gstudpsrc.h:
Rework the socket allocation a bit based on the sockfd argument so that
it becomes usable.
Add a closefd property to instruct the udp elements to close the custom
file descriptors when going to READY. Fixes #423304.
API:GstUDPSrc::closefd property
API:GstDynUDPSink::closefd property
2007-03-29 09:59:23 +00:00
|
|
|
|
2005-07-01 20:56:07 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2012-01-17 08:32:27 +00:00
|
|
|
PROP_SOCKET,
|
2013-04-25 08:44:44 +00:00
|
|
|
PROP_SOCKET_V6,
|
2013-05-23 16:42:09 +00:00
|
|
|
PROP_CLOSE_SOCKET,
|
|
|
|
PROP_BIND_ADDRESS,
|
|
|
|
PROP_BIND_PORT
|
2005-07-01 20:56:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void gst_dynudpsink_finalize (GObject * object);
|
|
|
|
|
|
|
|
static GstFlowReturn gst_dynudpsink_render (GstBaseSink * sink,
|
|
|
|
GstBuffer * buffer);
|
2012-01-17 08:32:27 +00:00
|
|
|
static gboolean gst_dynudpsink_stop (GstBaseSink * bsink);
|
|
|
|
static gboolean gst_dynudpsink_start (GstBaseSink * bsink);
|
|
|
|
static gboolean gst_dynudpsink_unlock (GstBaseSink * bsink);
|
|
|
|
static gboolean gst_dynudpsink_unlock_stop (GstBaseSink * bsink);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
|
|
|
static void gst_dynudpsink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_dynudpsink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2012-01-26 15:30:41 +00:00
|
|
|
static GstStructure *gst_dynudpsink_get_stats (GstDynUDPSink * sink,
|
|
|
|
const gchar * host, gint port);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
|
|
|
static guint gst_dynudpsink_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2011-04-19 15:35:47 +00:00
|
|
|
#define gst_dynudpsink_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstDynUDPSink, gst_dynudpsink, GST_TYPE_BASE_SINK);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
|
|
|
static void
|
2011-04-19 15:35:47 +00:00
|
|
|
gst_dynudpsink_class_init (GstDynUDPSinkClass * klass)
|
2005-07-01 20:56:07 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
GstBaseSinkClass *gstbasesink_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gstbasesink_class = (GstBaseSinkClass *) klass;
|
|
|
|
|
2006-04-08 21:21:45 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_dynudpsink_set_property;
|
|
|
|
gobject_class->get_property = gst_dynudpsink_get_property;
|
|
|
|
gobject_class->finalize = gst_dynudpsink_finalize;
|
|
|
|
|
|
|
|
gst_dynudpsink_signals[SIGNAL_GET_STATS] =
|
2012-01-26 15:37:23 +00:00
|
|
|
g_signal_new ("get-stats", G_TYPE_FROM_CLASS (klass),
|
2012-01-26 15:48:01 +00:00
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2005-07-01 20:56:07 +00:00
|
|
|
G_STRUCT_OFFSET (GstDynUDPSinkClass, get_stats),
|
2013-04-25 07:13:51 +00:00
|
|
|
NULL, NULL, g_cclosure_marshal_generic, GST_TYPE_STRUCTURE, 2,
|
2005-07-01 20:56:07 +00:00
|
|
|
G_TYPE_STRING, G_TYPE_INT);
|
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SOCKET,
|
|
|
|
g_param_spec_object ("socket", "Socket",
|
|
|
|
"Socket to use for UDP sending. (NULL == allocate)",
|
|
|
|
G_TYPE_SOCKET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2013-04-25 08:44:44 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SOCKET_V6,
|
|
|
|
g_param_spec_object ("socket-v6", "Socket IPv6",
|
|
|
|
"Socket to use for UDPv6 sending. (NULL == allocate)",
|
|
|
|
G_TYPE_SOCKET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-17 08:32:27 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CLOSE_SOCKET,
|
|
|
|
g_param_spec_boolean ("close-socket", "Close socket",
|
|
|
|
"Close socket if passed as property on state change",
|
|
|
|
UDP_DEFAULT_CLOSE_SOCKET,
|
2010-10-13 14:21:23 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2013-05-23 16:42:09 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BIND_ADDRESS,
|
|
|
|
g_param_spec_string ("bind-address", "Bind Address",
|
|
|
|
"Address to bind the socket to", UDP_DEFAULT_BIND_ADDRESS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_BIND_PORT,
|
|
|
|
g_param_spec_int ("bind-port", "Bind Port",
|
|
|
|
"Port to bind the socket to", 0, G_MAXUINT16,
|
|
|
|
UDP_DEFAULT_BIND_PORT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2006-01-07 20:01:09 +00:00
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
|
2011-04-19 15:35:47 +00:00
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class, "UDP packet sender",
|
2011-04-19 15:35:47 +00:00
|
|
|
"Sink/Network",
|
2014-06-16 15:40:07 +00:00
|
|
|
"Send data over the network via UDP with packet destinations picked up "
|
|
|
|
"dynamically from meta on the buffers passed",
|
2011-04-19 15:35:47 +00:00
|
|
|
"Philippe Khalaf <burger@speedy.org>");
|
|
|
|
|
2005-07-01 20:56:07 +00:00
|
|
|
gstbasesink_class->render = gst_dynudpsink_render;
|
2012-01-17 08:32:27 +00:00
|
|
|
gstbasesink_class->start = gst_dynudpsink_start;
|
|
|
|
gstbasesink_class->stop = gst_dynudpsink_stop;
|
|
|
|
gstbasesink_class->unlock = gst_dynudpsink_unlock;
|
|
|
|
gstbasesink_class->unlock_stop = gst_dynudpsink_unlock_stop;
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2012-01-26 15:30:41 +00:00
|
|
|
klass->get_stats = gst_dynudpsink_get_stats;
|
|
|
|
|
2005-07-01 20:56:07 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (dynudpsink_debug, "dynudpsink", 0, "UDP sink");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dynudpsink_init (GstDynUDPSink * sink)
|
|
|
|
{
|
2012-01-17 08:32:27 +00:00
|
|
|
sink->socket = UDP_DEFAULT_SOCKET;
|
2013-04-25 08:44:44 +00:00
|
|
|
sink->socket_v6 = UDP_DEFAULT_SOCKET;
|
2012-01-17 08:32:27 +00:00
|
|
|
sink->close_socket = UDP_DEFAULT_CLOSE_SOCKET;
|
|
|
|
sink->external_socket = FALSE;
|
2013-05-23 16:42:09 +00:00
|
|
|
sink->bind_address = UDP_DEFAULT_BIND_ADDRESS;
|
|
|
|
sink->bind_port = UDP_DEFAULT_BIND_PORT;
|
gst/udp/: Rework the socket allocation a bit based on the sockfd argument so that it becomes usable.
Original commit message from CVS:
Patch by: Laurent Glayal <spglegle at yahoo dot fr>
* gst/udp/gstdynudpsink.c: (gst_dynudpsink_class_init),
(gst_dynudpsink_init), (gst_dynudpsink_set_property),
(gst_dynudpsink_get_property), (gst_dynudpsink_init_send),
(gst_dynudpsink_close):
* gst/udp/gstdynudpsink.h:
* gst/udp/gstudpsrc.c: (gst_udpsrc_class_init), (gst_udpsrc_init),
(gst_udpsrc_create), (gst_udpsrc_set_property),
(gst_udpsrc_get_property), (gst_udpsrc_start), (gst_udpsrc_stop):
* gst/udp/gstudpsrc.h:
Rework the socket allocation a bit based on the sockfd argument so that
it becomes usable.
Add a closefd property to instruct the udp elements to close the custom
file descriptors when going to READY. Fixes #423304.
API:GstUDPSrc::closefd property
API:GstDynUDPSink::closefd property
2007-03-29 09:59:23 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
sink->used_socket = NULL;
|
2013-04-25 08:44:44 +00:00
|
|
|
sink->used_socket_v6 = NULL;
|
2005-07-01 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dynudpsink_finalize (GObject * object)
|
|
|
|
{
|
2012-01-17 08:32:27 +00:00
|
|
|
GstDynUDPSink *sink;
|
2008-08-20 11:51:38 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
sink = GST_DYNUDPSINK (object);
|
2008-08-20 11:51:38 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
if (sink->socket)
|
|
|
|
g_object_unref (sink->socket);
|
|
|
|
sink->socket = NULL;
|
2006-07-24 11:48:03 +00:00
|
|
|
|
2013-04-25 08:44:44 +00:00
|
|
|
if (sink->socket_v6)
|
|
|
|
g_object_unref (sink->socket_v6);
|
|
|
|
sink->socket_v6 = NULL;
|
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
if (sink->used_socket)
|
|
|
|
g_object_unref (sink->used_socket);
|
|
|
|
sink->used_socket = NULL;
|
|
|
|
|
2013-04-25 08:44:44 +00:00
|
|
|
if (sink->used_socket_v6)
|
|
|
|
g_object_unref (sink->used_socket_v6);
|
|
|
|
sink->used_socket_v6 = NULL;
|
|
|
|
|
2013-05-23 16:42:09 +00:00
|
|
|
g_free (sink->bind_address);
|
|
|
|
sink->bind_address = NULL;
|
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2005-07-01 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_dynudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstDynUDPSink *sink;
|
2012-01-17 08:32:27 +00:00
|
|
|
gssize ret;
|
2012-01-24 13:38:58 +00:00
|
|
|
GstMapInfo map;
|
2011-10-31 01:35:51 +00:00
|
|
|
GstNetAddressMeta *meta;
|
2012-01-17 08:32:27 +00:00
|
|
|
GSocketAddress *addr;
|
|
|
|
GError *err = NULL;
|
2012-01-17 08:38:33 +00:00
|
|
|
GSocketFamily family;
|
2013-04-25 08:44:44 +00:00
|
|
|
GSocket *socket;
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2011-10-31 01:35:51 +00:00
|
|
|
meta = gst_buffer_get_net_address_meta (buffer);
|
2011-02-28 12:14:37 +00:00
|
|
|
|
|
|
|
if (meta == NULL) {
|
2013-04-25 08:44:44 +00:00
|
|
|
GST_DEBUG ("Received buffer without GstNetAddressMeta, skipping");
|
2005-07-01 20:56:07 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sink = GST_DYNUDPSINK (bsink);
|
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
/* let's get the address from the metadata */
|
|
|
|
addr = meta->addr;
|
|
|
|
|
2012-01-17 08:38:33 +00:00
|
|
|
family = g_socket_address_get_family (addr);
|
2013-04-25 08:44:44 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6 && !sink->used_socket_v6)
|
2012-01-17 08:32:27 +00:00
|
|
|
goto invalid_family;
|
|
|
|
|
2012-01-24 13:38:58 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2012-01-24 13:38:58 +00:00
|
|
|
GST_DEBUG ("about to send %" G_GSIZE_FORMAT " bytes", map.size);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
{
|
|
|
|
gchar *host;
|
|
|
|
|
|
|
|
host =
|
|
|
|
g_inet_address_to_string (g_inet_socket_address_get_address
|
|
|
|
(G_INET_SOCKET_ADDRESS (addr)));
|
2012-01-24 13:38:58 +00:00
|
|
|
GST_DEBUG ("sending %" G_GSIZE_FORMAT " bytes to client %s port %d",
|
|
|
|
map.size, host,
|
|
|
|
g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr)));
|
2012-01-17 08:32:27 +00:00
|
|
|
g_free (host);
|
|
|
|
}
|
2008-10-27 08:36:43 +00:00
|
|
|
#endif
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2013-04-25 08:44:44 +00:00
|
|
|
/* Select socket to send from for this address */
|
|
|
|
if (family == G_SOCKET_FAMILY_IPV6 || !sink->used_socket)
|
|
|
|
socket = sink->used_socket_v6;
|
|
|
|
else
|
|
|
|
socket = sink->used_socket;
|
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
ret =
|
2013-04-25 08:44:44 +00:00
|
|
|
g_socket_send_to (socket, addr, (gchar *) map.data, map.size,
|
2012-01-17 08:32:27 +00:00
|
|
|
sink->cancellable, &err);
|
2012-01-24 13:38:58 +00:00
|
|
|
gst_buffer_unmap (buffer, &map);
|
2011-04-05 15:06:41 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto send_error;
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
GST_DEBUG ("sent %" G_GSSIZE_FORMAT " bytes", ret);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
send_error:
|
|
|
|
{
|
2014-06-13 09:12:07 +00:00
|
|
|
GstFlowReturn flow_ret;
|
|
|
|
|
|
|
|
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
|
|
|
GST_DEBUG_OBJECT (sink, "send cancelled");
|
|
|
|
flow_ret = GST_FLOW_FLUSHING;
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL),
|
|
|
|
("send error: %s", err->message));
|
|
|
|
flow_ret = GST_FLOW_ERROR;
|
|
|
|
}
|
2012-01-17 08:32:27 +00:00
|
|
|
g_clear_error (&err);
|
2014-06-13 09:12:07 +00:00
|
|
|
return flow_ret;
|
2012-01-17 08:32:27 +00:00
|
|
|
}
|
|
|
|
invalid_family:
|
|
|
|
{
|
2013-04-25 08:44:44 +00:00
|
|
|
GST_DEBUG ("invalid address family (got %d)", family);
|
2005-07-01 20:56:07 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dynudpsink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstDynUDPSink *udpsink;
|
|
|
|
|
|
|
|
udpsink = GST_DYNUDPSINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-01-17 08:32:27 +00:00
|
|
|
case PROP_SOCKET:
|
|
|
|
if (udpsink->socket != NULL && udpsink->socket != udpsink->used_socket &&
|
|
|
|
udpsink->close_socket) {
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
if (!g_socket_close (udpsink->socket, &err)) {
|
|
|
|
GST_ERROR ("failed to close socket %p: %s", udpsink->socket,
|
|
|
|
err->message);
|
|
|
|
g_clear_error (&err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (udpsink->socket)
|
|
|
|
g_object_unref (udpsink->socket);
|
|
|
|
udpsink->socket = g_value_dup_object (value);
|
|
|
|
GST_DEBUG ("setting socket to %p", udpsink->socket);
|
gst/udp/: Rework the socket allocation a bit based on the sockfd argument so that it becomes usable.
Original commit message from CVS:
Patch by: Laurent Glayal <spglegle at yahoo dot fr>
* gst/udp/gstdynudpsink.c: (gst_dynudpsink_class_init),
(gst_dynudpsink_init), (gst_dynudpsink_set_property),
(gst_dynudpsink_get_property), (gst_dynudpsink_init_send),
(gst_dynudpsink_close):
* gst/udp/gstdynudpsink.h:
* gst/udp/gstudpsrc.c: (gst_udpsrc_class_init), (gst_udpsrc_init),
(gst_udpsrc_create), (gst_udpsrc_set_property),
(gst_udpsrc_get_property), (gst_udpsrc_start), (gst_udpsrc_stop):
* gst/udp/gstudpsrc.h:
Rework the socket allocation a bit based on the sockfd argument so that
it becomes usable.
Add a closefd property to instruct the udp elements to close the custom
file descriptors when going to READY. Fixes #423304.
API:GstUDPSrc::closefd property
API:GstDynUDPSink::closefd property
2007-03-29 09:59:23 +00:00
|
|
|
break;
|
2013-04-25 08:44:44 +00:00
|
|
|
case PROP_SOCKET_V6:
|
|
|
|
if (udpsink->socket_v6 != NULL
|
|
|
|
&& udpsink->socket_v6 != udpsink->used_socket_v6
|
|
|
|
&& udpsink->close_socket) {
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
if (!g_socket_close (udpsink->socket_v6, &err)) {
|
|
|
|
GST_ERROR ("failed to close socket %p: %s", udpsink->socket_v6,
|
|
|
|
err->message);
|
|
|
|
g_clear_error (&err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (udpsink->socket_v6)
|
|
|
|
g_object_unref (udpsink->socket_v6);
|
|
|
|
udpsink->socket_v6 = g_value_dup_object (value);
|
|
|
|
GST_DEBUG ("setting socket v6 to %p", udpsink->socket_v6);
|
|
|
|
break;
|
2012-01-17 08:32:27 +00:00
|
|
|
case PROP_CLOSE_SOCKET:
|
|
|
|
udpsink->close_socket = g_value_get_boolean (value);
|
|
|
|
break;
|
2013-05-23 16:42:09 +00:00
|
|
|
case PROP_BIND_ADDRESS:
|
|
|
|
g_free (udpsink->bind_address);
|
|
|
|
udpsink->bind_address = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_BIND_PORT:
|
|
|
|
udpsink->bind_port = g_value_get_int (value);
|
|
|
|
break;
|
2005-07-01 20:56:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dynudpsink_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstDynUDPSink *udpsink;
|
|
|
|
|
|
|
|
udpsink = GST_DYNUDPSINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-01-17 08:32:27 +00:00
|
|
|
case PROP_SOCKET:
|
|
|
|
g_value_set_object (value, udpsink->socket);
|
gst/udp/: Rework the socket allocation a bit based on the sockfd argument so that it becomes usable.
Original commit message from CVS:
Patch by: Laurent Glayal <spglegle at yahoo dot fr>
* gst/udp/gstdynudpsink.c: (gst_dynudpsink_class_init),
(gst_dynudpsink_init), (gst_dynudpsink_set_property),
(gst_dynudpsink_get_property), (gst_dynudpsink_init_send),
(gst_dynudpsink_close):
* gst/udp/gstdynudpsink.h:
* gst/udp/gstudpsrc.c: (gst_udpsrc_class_init), (gst_udpsrc_init),
(gst_udpsrc_create), (gst_udpsrc_set_property),
(gst_udpsrc_get_property), (gst_udpsrc_start), (gst_udpsrc_stop):
* gst/udp/gstudpsrc.h:
Rework the socket allocation a bit based on the sockfd argument so that
it becomes usable.
Add a closefd property to instruct the udp elements to close the custom
file descriptors when going to READY. Fixes #423304.
API:GstUDPSrc::closefd property
API:GstDynUDPSink::closefd property
2007-03-29 09:59:23 +00:00
|
|
|
break;
|
2013-04-25 08:44:44 +00:00
|
|
|
case PROP_SOCKET_V6:
|
|
|
|
g_value_set_object (value, udpsink->socket_v6);
|
|
|
|
break;
|
2012-01-17 08:32:27 +00:00
|
|
|
case PROP_CLOSE_SOCKET:
|
|
|
|
g_value_set_boolean (value, udpsink->close_socket);
|
|
|
|
break;
|
2013-05-23 16:42:09 +00:00
|
|
|
case PROP_BIND_ADDRESS:
|
|
|
|
g_value_set_string (value, udpsink->bind_address);
|
|
|
|
break;
|
|
|
|
case PROP_BIND_PORT:
|
|
|
|
g_value_set_int (value, udpsink->bind_port);
|
|
|
|
break;
|
2005-07-01 20:56:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 15:31:23 +00:00
|
|
|
static void
|
|
|
|
gst_dynudpsink_create_cancellable (GstDynUDPSink * sink)
|
|
|
|
{
|
|
|
|
GPollFD pollfd;
|
|
|
|
|
|
|
|
sink->cancellable = g_cancellable_new ();
|
|
|
|
sink->made_cancel_fd = g_cancellable_make_pollfd (sink->cancellable, &pollfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dynudpsink_free_cancellable (GstDynUDPSink * sink)
|
|
|
|
{
|
|
|
|
if (sink->made_cancel_fd) {
|
|
|
|
g_cancellable_release_fd (sink->cancellable);
|
|
|
|
sink->made_cancel_fd = FALSE;
|
|
|
|
}
|
|
|
|
g_object_unref (sink->cancellable);
|
|
|
|
sink->cancellable = NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-01 20:56:07 +00:00
|
|
|
/* create a socket for sending to remote machine */
|
|
|
|
static gboolean
|
2012-01-17 08:32:27 +00:00
|
|
|
gst_dynudpsink_start (GstBaseSink * bsink)
|
2005-07-01 20:56:07 +00:00
|
|
|
{
|
2012-01-17 08:32:27 +00:00
|
|
|
GstDynUDPSink *udpsink;
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
udpsink = GST_DYNUDPSINK (bsink);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2015-05-27 15:31:23 +00:00
|
|
|
gst_dynudpsink_create_cancellable (udpsink);
|
|
|
|
|
2013-04-25 08:44:44 +00:00
|
|
|
udpsink->external_socket = FALSE;
|
|
|
|
|
|
|
|
if (udpsink->socket) {
|
|
|
|
if (g_socket_get_family (udpsink->socket) == G_SOCKET_FAMILY_IPV6) {
|
|
|
|
udpsink->used_socket_v6 = G_SOCKET (g_object_ref (udpsink->socket));
|
|
|
|
udpsink->external_socket = TRUE;
|
|
|
|
} else {
|
|
|
|
udpsink->used_socket = G_SOCKET (g_object_ref (udpsink->socket));
|
|
|
|
udpsink->external_socket = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (udpsink->socket_v6) {
|
|
|
|
g_return_val_if_fail (g_socket_get_family (udpsink->socket) !=
|
|
|
|
G_SOCKET_FAMILY_IPV6, FALSE);
|
|
|
|
|
|
|
|
if (udpsink->used_socket_v6
|
|
|
|
&& udpsink->used_socket_v6 != udpsink->socket_v6) {
|
|
|
|
GST_ERROR_OBJECT (udpsink,
|
|
|
|
"Provided different IPv6 sockets in socket and socket-v6 properties");
|
|
|
|
return FALSE;
|
2012-01-17 08:38:33 +00:00
|
|
|
}
|
2006-01-07 20:01:09 +00:00
|
|
|
|
2013-04-25 08:44:44 +00:00
|
|
|
udpsink->used_socket_v6 = G_SOCKET (g_object_ref (udpsink->socket_v6));
|
2012-01-17 08:32:27 +00:00
|
|
|
udpsink->external_socket = TRUE;
|
gst/udp/: Rework the socket allocation a bit based on the sockfd argument so that it becomes usable.
Original commit message from CVS:
Patch by: Laurent Glayal <spglegle at yahoo dot fr>
* gst/udp/gstdynudpsink.c: (gst_dynudpsink_class_init),
(gst_dynudpsink_init), (gst_dynudpsink_set_property),
(gst_dynudpsink_get_property), (gst_dynudpsink_init_send),
(gst_dynudpsink_close):
* gst/udp/gstdynudpsink.h:
* gst/udp/gstudpsrc.c: (gst_udpsrc_class_init), (gst_udpsrc_init),
(gst_udpsrc_create), (gst_udpsrc_set_property),
(gst_udpsrc_get_property), (gst_udpsrc_start), (gst_udpsrc_stop):
* gst/udp/gstudpsrc.h:
Rework the socket allocation a bit based on the sockfd argument so that
it becomes usable.
Add a closefd property to instruct the udp elements to close the custom
file descriptors when going to READY. Fixes #423304.
API:GstUDPSrc::closefd property
API:GstDynUDPSink::closefd property
2007-03-29 09:59:23 +00:00
|
|
|
}
|
2012-01-17 08:32:27 +00:00
|
|
|
|
2013-04-25 08:44:44 +00:00
|
|
|
if (!udpsink->used_socket && !udpsink->used_socket_v6) {
|
2013-05-23 16:05:07 +00:00
|
|
|
GSocketAddress *bind_addr;
|
|
|
|
GInetAddress *bind_iaddr;
|
2013-04-25 08:44:44 +00:00
|
|
|
|
2013-05-23 16:42:09 +00:00
|
|
|
if (udpsink->bind_address) {
|
|
|
|
GSocketFamily family;
|
|
|
|
|
|
|
|
bind_iaddr = g_inet_address_new_from_string (udpsink->bind_address);
|
|
|
|
if (!bind_iaddr) {
|
|
|
|
GList *results;
|
|
|
|
GResolver *resolver;
|
|
|
|
|
|
|
|
resolver = g_resolver_get_default ();
|
|
|
|
results =
|
|
|
|
g_resolver_lookup_by_name (resolver, udpsink->bind_address,
|
|
|
|
udpsink->cancellable, &err);
|
|
|
|
if (!results) {
|
|
|
|
g_object_unref (resolver);
|
|
|
|
goto name_resolve;
|
|
|
|
}
|
|
|
|
bind_iaddr = G_INET_ADDRESS (g_object_ref (results->data));
|
|
|
|
g_resolver_free_addresses (results);
|
|
|
|
g_object_unref (resolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
bind_addr = g_inet_socket_address_new (bind_iaddr, udpsink->bind_port);
|
|
|
|
g_object_unref (bind_iaddr);
|
|
|
|
family = g_socket_address_get_family (G_SOCKET_ADDRESS (bind_addr));
|
|
|
|
|
|
|
|
if ((udpsink->used_socket =
|
|
|
|
g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
|
|
|
|
G_SOCKET_PROTOCOL_UDP, &err)) == NULL) {
|
|
|
|
g_object_unref (bind_addr);
|
|
|
|
goto no_socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_socket_bind (udpsink->used_socket, bind_addr, TRUE, &err);
|
|
|
|
if (err != NULL)
|
|
|
|
goto bind_error;
|
2013-05-23 16:05:07 +00:00
|
|
|
} else {
|
2013-05-23 16:42:09 +00:00
|
|
|
/* create sender sockets if none available */
|
|
|
|
if ((udpsink->used_socket = g_socket_new (G_SOCKET_FAMILY_IPV4,
|
|
|
|
G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &err)) == NULL)
|
|
|
|
goto no_socket;
|
|
|
|
|
|
|
|
bind_iaddr = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4);
|
2013-05-23 16:05:07 +00:00
|
|
|
bind_addr = g_inet_socket_address_new (bind_iaddr, 0);
|
2013-05-23 16:42:09 +00:00
|
|
|
g_socket_bind (udpsink->used_socket, bind_addr, TRUE, &err);
|
2013-05-23 16:05:07 +00:00
|
|
|
g_object_unref (bind_addr);
|
|
|
|
g_object_unref (bind_iaddr);
|
|
|
|
if (err != NULL)
|
|
|
|
goto bind_error;
|
2013-05-23 16:42:09 +00:00
|
|
|
|
|
|
|
if ((udpsink->used_socket_v6 = g_socket_new (G_SOCKET_FAMILY_IPV6,
|
|
|
|
G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP,
|
|
|
|
&err)) == NULL) {
|
|
|
|
GST_INFO_OBJECT (udpsink, "Failed to create IPv6 socket: %s",
|
|
|
|
err->message);
|
|
|
|
g_clear_error (&err);
|
|
|
|
} else {
|
|
|
|
bind_iaddr = g_inet_address_new_any (G_SOCKET_FAMILY_IPV6);
|
|
|
|
bind_addr = g_inet_socket_address_new (bind_iaddr, 0);
|
|
|
|
g_socket_bind (udpsink->used_socket_v6, bind_addr, TRUE, &err);
|
|
|
|
g_object_unref (bind_addr);
|
|
|
|
g_object_unref (bind_iaddr);
|
|
|
|
if (err != NULL)
|
|
|
|
goto bind_error;
|
|
|
|
}
|
2013-04-25 08:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (udpsink->used_socket)
|
|
|
|
g_socket_set_broadcast (udpsink->used_socket, TRUE);
|
|
|
|
if (udpsink->used_socket_v6)
|
|
|
|
g_socket_set_broadcast (udpsink->used_socket_v6, TRUE);
|
2012-01-17 08:38:33 +00:00
|
|
|
|
2005-07-01 20:56:07 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_socket:
|
|
|
|
{
|
2013-04-25 08:44:44 +00:00
|
|
|
GST_ERROR_OBJECT (udpsink, "Failed to create IPv4 socket: %s",
|
|
|
|
err->message);
|
2012-01-17 08:32:27 +00:00
|
|
|
g_clear_error (&err);
|
2005-07-01 20:56:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-05-23 16:05:07 +00:00
|
|
|
bind_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (udpsink, RESOURCE, FAILED, (NULL),
|
|
|
|
("Failed to bind socket: %s", err->message));
|
|
|
|
g_clear_error (&err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-05-23 16:42:09 +00:00
|
|
|
name_resolve:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (udpsink, RESOURCE, FAILED, (NULL),
|
|
|
|
("Failed to resolve bind address %s: %s", udpsink->bind_address,
|
|
|
|
err->message));
|
|
|
|
g_clear_error (&err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-07-01 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 15:30:41 +00:00
|
|
|
static GstStructure *
|
2005-07-01 20:56:07 +00:00
|
|
|
gst_dynudpsink_get_stats (GstDynUDPSink * sink, const gchar * host, gint port)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dynudpsink_stop (GstBaseSink * bsink)
|
2005-07-01 20:56:07 +00:00
|
|
|
{
|
2012-01-17 08:32:27 +00:00
|
|
|
GstDynUDPSink *udpsink;
|
|
|
|
|
|
|
|
udpsink = GST_DYNUDPSINK (bsink);
|
|
|
|
|
|
|
|
if (udpsink->used_socket) {
|
|
|
|
if (udpsink->close_socket || !udpsink->external_socket) {
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
if (!g_socket_close (udpsink->used_socket, &err)) {
|
|
|
|
GST_ERROR_OBJECT (udpsink, "Failed to close socket: %s", err->message);
|
|
|
|
g_clear_error (&err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (udpsink->used_socket);
|
|
|
|
udpsink->used_socket = NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-25 08:44:44 +00:00
|
|
|
if (udpsink->used_socket_v6) {
|
|
|
|
if (udpsink->close_socket || !udpsink->external_socket) {
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
if (!g_socket_close (udpsink->used_socket_v6, &err)) {
|
|
|
|
GST_ERROR_OBJECT (udpsink, "Failed to close socket: %s", err->message);
|
|
|
|
g_clear_error (&err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (udpsink->used_socket_v6);
|
|
|
|
udpsink->used_socket_v6 = NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-27 15:31:23 +00:00
|
|
|
gst_dynudpsink_free_cancellable (udpsink);
|
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
return TRUE;
|
2005-07-01 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dynudpsink_unlock (GstBaseSink * bsink)
|
2005-07-01 20:56:07 +00:00
|
|
|
{
|
2012-01-17 08:32:27 +00:00
|
|
|
GstDynUDPSink *udpsink;
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
udpsink = GST_DYNUDPSINK (bsink);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
g_cancellable_cancel (udpsink->cancellable);
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dynudpsink_unlock_stop (GstBaseSink * bsink)
|
|
|
|
{
|
|
|
|
GstDynUDPSink *udpsink;
|
2005-07-01 20:56:07 +00:00
|
|
|
|
2012-01-17 08:32:27 +00:00
|
|
|
udpsink = GST_DYNUDPSINK (bsink);
|
|
|
|
|
2015-05-27 15:31:23 +00:00
|
|
|
gst_dynudpsink_free_cancellable (udpsink);
|
|
|
|
gst_dynudpsink_create_cancellable (udpsink);
|
2012-01-17 08:32:27 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2005-07-01 20:56:07 +00:00
|
|
|
}
|