gstreamer/subprojects/gst-plugins-good/gst/udp/gstudpsink.c

263 lines
7 KiB
C
Raw Normal View History

/* GStreamer
2005-05-12 15:32:51 +00:00
* Copyright (C) <2005> Wim Taymans <wim@fluendo.com>
2012-01-17 10:18:15 +00:00
* Copyright (C) <2012> Collabora Ltd.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* 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
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* SECTION:element-udpsink
* @title: udpsink
* @see_also: udpsrc, multifdsink
*
* udpsink is a network sink that sends UDP packets to the network.
* It can be combined with RTP payloaders to implement RTP streaming.
*
* ## Examples
* |[
* gst-launch-1.0 -v audiotestsrc ! udpsink
* ]|
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstudpelements.h"
#include "gstudpsink.h"
#define UDP_DEFAULT_HOST "localhost"
#define UDP_DEFAULT_PORT 5004
/* UDPSink signals and args */
enum
{
/* FILL ME */
LAST_SIGNAL
};
enum
{
2005-05-12 15:32:51 +00:00
PROP_0,
PROP_HOST,
PROP_PORT,
PROP_URI,
/* FILL ME */
};
Fix a bunch of leaks shown by the newly-added states test. Original commit message from CVS: * ext/flac/gstflacenc.c: (gst_flac_enc_finalize): * ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init), (gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize): * ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init), (gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose), (gst_gconf_audio_src_finalize), (do_toggle_element): * ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init), (gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize), (do_toggle_element): * ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init), (gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose), (gst_gconf_video_src_finalize), (do_toggle_element): * ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init), (gst_switch_sink_reset), (gst_switch_sink_set_child): * ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init): * ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init): * ext/shout2/gstshout2.c: (gst_shout2send_class_init), (gst_shout2send_init), (gst_shout2send_finalize): * gst/debug/testplugin.c: (gst_test_class_init), (gst_test_finalize): * gst/flx/gstflxdec.c: (gst_flxdec_class_init), (gst_flxdec_dispose): * gst/multipart/multipartmux.c: (gst_multipart_mux_finalize): * gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize): * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init), (gst_rtspsrc_finalize): * gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context): * gst/rtsp/rtspextwms.h: * gst/smpte/gstsmpte.c: (gst_smpte_class_init), (gst_smpte_finalize): * gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize): * gst/udp/gstudpsink.c: (gst_udpsink_class_init), (gst_udpsink_finalize): * gst/wavparse/gstwavparse.c: (gst_wavparse_dispose), (gst_wavparse_sink_activate): * sys/oss/gstosssink.c: (gst_oss_sink_finalise): * sys/oss/gstosssrc.c: (gst_oss_src_class_init), (gst_oss_src_finalize): * sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy): * sys/v4l2/gstv4l2object.h: * sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init), (gst_v4l2src_finalize): * sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get): Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
static void gst_udpsink_finalize (GstUDPSink * udpsink);
static void gst_udpsink_uri_handler_init (gpointer g_iface,
gpointer iface_data);
static void gst_udpsink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_udpsink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
/*static guint gst_udpsink_signals[LAST_SIGNAL] = { 0 }; */
2011-04-19 15:35:47 +00:00
#define gst_udpsink_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstUDPSink, gst_udpsink, GST_TYPE_MULTIUDPSINK,
G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_udpsink_uri_handler_init));
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (udpsink, "udpsink", GST_RANK_NONE,
GST_TYPE_UDPSINK, udp_element_init (plugin));
static void
2011-04-19 15:35:47 +00:00
gst_udpsink_class_init (GstUDPSinkClass * klass)
{
GObjectClass *gobject_class;
2011-04-19 15:35:47 +00:00
GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
2011-04-19 15:35:47 +00:00
gstelement_class = (GstElementClass *) klass;
gobject_class->set_property = gst_udpsink_set_property;
gobject_class->get_property = gst_udpsink_get_property;
Fix a bunch of leaks shown by the newly-added states test. Original commit message from CVS: * ext/flac/gstflacenc.c: (gst_flac_enc_finalize): * ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init), (gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize): * ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init), (gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose), (gst_gconf_audio_src_finalize), (do_toggle_element): * ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init), (gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize), (do_toggle_element): * ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init), (gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose), (gst_gconf_video_src_finalize), (do_toggle_element): * ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init), (gst_switch_sink_reset), (gst_switch_sink_set_child): * ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init): * ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init): * ext/shout2/gstshout2.c: (gst_shout2send_class_init), (gst_shout2send_init), (gst_shout2send_finalize): * gst/debug/testplugin.c: (gst_test_class_init), (gst_test_finalize): * gst/flx/gstflxdec.c: (gst_flxdec_class_init), (gst_flxdec_dispose): * gst/multipart/multipartmux.c: (gst_multipart_mux_finalize): * gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize): * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init), (gst_rtspsrc_finalize): * gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context): * gst/rtsp/rtspextwms.h: * gst/smpte/gstsmpte.c: (gst_smpte_class_init), (gst_smpte_finalize): * gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize): * gst/udp/gstudpsink.c: (gst_udpsink_class_init), (gst_udpsink_finalize): * gst/wavparse/gstwavparse.c: (gst_wavparse_dispose), (gst_wavparse_sink_activate): * sys/oss/gstosssink.c: (gst_oss_sink_finalise): * sys/oss/gstosssrc.c: (gst_oss_src_class_init), (gst_oss_src_finalize): * sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy): * sys/v4l2/gstv4l2object.h: * sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init), (gst_v4l2src_finalize): * sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get): Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
gobject_class->finalize = (GObjectFinalizeFunc) gst_udpsink_finalize;
2005-05-12 15:32:51 +00:00
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HOST,
g_param_spec_string ("host", "host",
"The host/IP/Multicast group to send the packets to",
UDP_DEFAULT_HOST, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2005-05-12 15:32:51 +00:00
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT,
g_param_spec_int ("port", "port", "The port to send the packets to",
0, 65535, UDP_DEFAULT_PORT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_set_static_metadata (gstelement_class, "UDP packet sender",
2011-04-19 15:35:47 +00:00
"Sink/Network",
"Send data over the network via UDP", "Wim Taymans <wim@fluendo.com>");
}
static void
gst_udpsink_init (GstUDPSink * udpsink)
{
2012-01-17 10:18:15 +00:00
udpsink->host = g_strdup (UDP_DEFAULT_HOST);
udpsink->port = UDP_DEFAULT_PORT;
udpsink->uri = g_strdup_printf ("udp://%s:%d", udpsink->host, udpsink->port);
2012-01-17 10:18:15 +00:00
gst_multiudpsink_add (GST_MULTIUDPSINK (udpsink), udpsink->host,
udpsink->port);
}
Fix a bunch of leaks shown by the newly-added states test. Original commit message from CVS: * ext/flac/gstflacenc.c: (gst_flac_enc_finalize): * ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init), (gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize): * ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init), (gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose), (gst_gconf_audio_src_finalize), (do_toggle_element): * ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init), (gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize), (do_toggle_element): * ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init), (gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose), (gst_gconf_video_src_finalize), (do_toggle_element): * ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init), (gst_switch_sink_reset), (gst_switch_sink_set_child): * ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init): * ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init): * ext/shout2/gstshout2.c: (gst_shout2send_class_init), (gst_shout2send_init), (gst_shout2send_finalize): * gst/debug/testplugin.c: (gst_test_class_init), (gst_test_finalize): * gst/flx/gstflxdec.c: (gst_flxdec_class_init), (gst_flxdec_dispose): * gst/multipart/multipartmux.c: (gst_multipart_mux_finalize): * gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize): * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init), (gst_rtspsrc_finalize): * gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context): * gst/rtsp/rtspextwms.h: * gst/smpte/gstsmpte.c: (gst_smpte_class_init), (gst_smpte_finalize): * gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize): * gst/udp/gstudpsink.c: (gst_udpsink_class_init), (gst_udpsink_finalize): * gst/wavparse/gstwavparse.c: (gst_wavparse_dispose), (gst_wavparse_sink_activate): * sys/oss/gstosssink.c: (gst_oss_sink_finalise): * sys/oss/gstosssrc.c: (gst_oss_src_class_init), (gst_oss_src_finalize): * sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy): * sys/v4l2/gstv4l2object.h: * sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init), (gst_v4l2src_finalize): * sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get): Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
static void
gst_udpsink_finalize (GstUDPSink * udpsink)
{
2012-01-17 10:18:15 +00:00
g_free (udpsink->host);
udpsink->host = NULL;
g_free (udpsink->uri);
udpsink->uri = NULL;
Fix a bunch of leaks shown by the newly-added states test. Original commit message from CVS: * ext/flac/gstflacenc.c: (gst_flac_enc_finalize): * ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init), (gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize): * ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init), (gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose), (gst_gconf_audio_src_finalize), (do_toggle_element): * ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init), (gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize), (do_toggle_element): * ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init), (gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose), (gst_gconf_video_src_finalize), (do_toggle_element): * ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init), (gst_switch_sink_reset), (gst_switch_sink_set_child): * ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init): * ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init): * ext/shout2/gstshout2.c: (gst_shout2send_class_init), (gst_shout2send_init), (gst_shout2send_finalize): * gst/debug/testplugin.c: (gst_test_class_init), (gst_test_finalize): * gst/flx/gstflxdec.c: (gst_flxdec_class_init), (gst_flxdec_dispose): * gst/multipart/multipartmux.c: (gst_multipart_mux_finalize): * gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize): * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init), (gst_rtspsrc_finalize): * gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context): * gst/rtsp/rtspextwms.h: * gst/smpte/gstsmpte.c: (gst_smpte_class_init), (gst_smpte_finalize): * gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize): * gst/udp/gstudpsink.c: (gst_udpsink_class_init), (gst_udpsink_finalize): * gst/wavparse/gstwavparse.c: (gst_wavparse_dispose), (gst_wavparse_sink_activate): * sys/oss/gstosssink.c: (gst_oss_sink_finalise): * sys/oss/gstosssrc.c: (gst_oss_src_class_init), (gst_oss_src_finalize): * sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy): * sys/v4l2/gstv4l2object.h: * sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init), (gst_v4l2src_finalize): * sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get): Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
G_OBJECT_CLASS (parent_class)->finalize ((GObject *) udpsink);
}
2005-05-12 15:32:51 +00:00
static gboolean
gst_udpsink_set_uri (GstUDPSink * sink, const gchar * uri, GError ** error)
{
gchar *host;
guint16 port;
2012-01-17 10:18:15 +00:00
gst_multiudpsink_remove (GST_MULTIUDPSINK (sink), sink->host, sink->port);
if (!gst_udp_parse_uri (uri, &host, &port, NULL))
goto wrong_uri;
g_free (sink->host);
sink->host = host;
sink->port = port;
2012-01-17 10:18:15 +00:00
g_free (sink->uri);
sink->uri = g_strdup (uri);
gst_multiudpsink_add (GST_MULTIUDPSINK (sink), sink->host, sink->port);
return TRUE;
/* ERRORS */
wrong_uri:
{
GST_ELEMENT_ERROR (sink, RESOURCE, READ, (NULL),
("error parsing uri %s", uri));
g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
"Could not parse UDP URI");
return FALSE;
}
}
static void
gst_udpsink_set_property (GObject * object, guint prop_id, const GValue * value,
GParamSpec * pspec)
{
GstUDPSink *udpsink;
udpsink = GST_UDPSINK (object);
2005-05-12 15:32:51 +00:00
/* remove old host */
gst_multiudpsink_remove (GST_MULTIUDPSINK (udpsink),
2012-01-17 10:18:15 +00:00
udpsink->host, udpsink->port);
2005-05-12 15:32:51 +00:00
switch (prop_id) {
2005-05-12 15:32:51 +00:00
case PROP_HOST:
{
const gchar *host;
host = g_value_get_string (value);
2012-01-17 10:18:15 +00:00
g_free (udpsink->host);
udpsink->host = g_strdup (host);
g_free (udpsink->uri);
udpsink->uri =
g_strdup_printf ("udp://%s:%d", udpsink->host, udpsink->port);
break;
}
2005-05-12 15:32:51 +00:00
case PROP_PORT:
2012-01-17 10:18:15 +00:00
udpsink->port = g_value_get_int (value);
g_free (udpsink->uri);
udpsink->uri =
g_strdup_printf ("udp://%s:%d", udpsink->host, udpsink->port);
break;
default:
2005-05-12 15:32:51 +00:00
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
2005-05-12 15:32:51 +00:00
/* add new host */
gst_multiudpsink_add (GST_MULTIUDPSINK (udpsink),
2012-01-17 10:18:15 +00:00
udpsink->host, udpsink->port);
}
static void
gst_udpsink_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstUDPSink *udpsink;
udpsink = GST_UDPSINK (object);
switch (prop_id) {
2005-05-12 15:32:51 +00:00
case PROP_HOST:
2012-01-17 10:18:15 +00:00
g_value_set_string (value, udpsink->host);
break;
2005-05-12 15:32:51 +00:00
case PROP_PORT:
2012-01-17 10:18:15 +00:00
g_value_set_int (value, udpsink->port);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
2005-05-12 15:32:51 +00:00
/*** GSTURIHANDLER INTERFACE *************************************************/
static GstURIType
2011-07-04 16:15:42 +00:00
gst_udpsink_uri_get_type (GType type)
{
2005-05-12 15:32:51 +00:00
return GST_URI_SINK;
}
static const gchar *const *
2011-07-04 16:15:42 +00:00
gst_udpsink_uri_get_protocols (GType type)
{
static const gchar *protocols[] = { "udp", NULL };
2005-05-12 15:32:51 +00:00
return protocols;
}
static gchar *
2005-05-12 15:32:51 +00:00
gst_udpsink_uri_get_uri (GstURIHandler * handler)
{
2005-05-12 15:32:51 +00:00
GstUDPSink *sink = GST_UDPSINK (handler);
2012-01-17 10:18:15 +00:00
return g_strdup (sink->uri);
2005-05-12 15:32:51 +00:00
}
2005-05-12 15:32:51 +00:00
static gboolean
gst_udpsink_uri_set_uri (GstURIHandler * handler, const gchar * uri,
GError ** error)
2005-05-12 15:32:51 +00:00
{
return gst_udpsink_set_uri (GST_UDPSINK (handler), uri, error);
2005-05-12 15:32:51 +00:00
}
2005-05-12 15:32:51 +00:00
static void
gst_udpsink_uri_handler_init (gpointer g_iface, gpointer iface_data)
{
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
iface->get_type = gst_udpsink_uri_get_type;
iface->get_protocols = gst_udpsink_uri_get_protocols;
iface->get_uri = gst_udpsink_uri_get_uri;
iface->set_uri = gst_udpsink_uri_set_uri;
}