2 * Copyright (C) <2005> Wim Taymans <wim@fluendo.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 * SECTION:element-udpsink
21 * @see_also: udpsrc, multifdsink
23 * udpsink is a network sink that sends UDP packets to the network.
24 * It can be combined with RTP payloaders to implement RTP streaming.
27 * <title>Examples</title>
29 * gst-launch -v audiotestsrc ! udpsink
36 #include "gstudpsink.h"
46 #define UDP_DEFAULT_HOST "localhost"
47 #define UDP_DEFAULT_PORT 4951
49 /* UDPSink signals and args */
65 static void gst_udpsink_base_init (gpointer g_class);
66 static void gst_udpsink_class_init (GstUDPSink * klass);
67 static void gst_udpsink_init (GstUDPSink * udpsink);
68 static void gst_udpsink_finalize (GstUDPSink * udpsink);
70 static void gst_udpsink_uri_handler_init (gpointer g_iface,
73 static void gst_udpsink_set_property (GObject * object, guint prop_id,
74 const GValue * value, GParamSpec * pspec);
75 static void gst_udpsink_get_property (GObject * object, guint prop_id,
76 GValue * value, GParamSpec * pspec);
78 static GstElementClass *parent_class = NULL;
80 /*static guint gst_udpsink_signals[LAST_SIGNAL] = { 0 }; */
83 gst_udpsink_get_type (void)
85 static GType udpsink_type = 0;
88 static const GTypeInfo udpsink_info = {
89 sizeof (GstUDPSinkClass),
90 gst_udpsink_base_init,
92 (GClassInitFunc) gst_udpsink_class_init,
97 (GInstanceInitFunc) gst_udpsink_init,
100 static const GInterfaceInfo urihandler_info = {
101 gst_udpsink_uri_handler_init,
107 g_type_register_static (GST_TYPE_MULTIUDPSINK, "GstUDPSink",
110 g_type_add_interface_static (udpsink_type, GST_TYPE_URI_HANDLER,
118 gst_udpsink_base_init (gpointer g_class)
120 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
122 gst_element_class_set_details_simple (element_class, "UDP packet sender",
124 "Send data over the network via UDP", "Wim Taymans <wim@fluendo.com>");
128 gst_udpsink_class_init (GstUDPSink * klass)
130 GObjectClass *gobject_class;
132 gobject_class = (GObjectClass *) klass;
134 parent_class = g_type_class_peek_parent (klass);
136 gobject_class->set_property = gst_udpsink_set_property;
137 gobject_class->get_property = gst_udpsink_get_property;
139 gobject_class->finalize = (GObjectFinalizeFunc) gst_udpsink_finalize;
141 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HOST,
142 g_param_spec_string ("host", "host",
143 "The host/IP/Multicast group to send the packets to",
144 UDP_DEFAULT_HOST, G_PARAM_READWRITE));
145 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT,
146 g_param_spec_int ("port", "port", "The port to send the packets to",
147 0, 65535, UDP_DEFAULT_PORT, G_PARAM_READWRITE));
152 gst_udpsink_init (GstUDPSink * udpsink)
154 gst_udp_uri_init (&udpsink->uri, UDP_DEFAULT_HOST, UDP_DEFAULT_PORT);
156 gst_multiudpsink_add (GST_MULTIUDPSINK (udpsink), udpsink->uri.host,
161 gst_udpsink_finalize (GstUDPSink * udpsink)
163 gst_udp_uri_free (&udpsink->uri);
164 g_free (udpsink->uristr);
166 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) udpsink);
170 gst_udpsink_set_uri (GstUDPSink * sink, const gchar * uri)
172 gst_multiudpsink_remove (GST_MULTIUDPSINK (sink), sink->uri.host,
175 if (gst_udp_parse_uri (uri, &sink->uri) < 0)
178 gst_multiudpsink_add (GST_MULTIUDPSINK (sink), sink->uri.host,
186 GST_ELEMENT_ERROR (sink, RESOURCE, READ, (NULL),
187 ("error parsing uri %s", uri));
193 gst_udpsink_set_property (GObject * object, guint prop_id, const GValue * value,
198 udpsink = GST_UDPSINK (object);
200 /* remove old host */
201 gst_multiudpsink_remove (GST_MULTIUDPSINK (udpsink),
202 udpsink->uri.host, udpsink->uri.port);
209 host = g_value_get_string (value);
212 gst_udp_uri_update (&udpsink->uri, host, -1);
214 gst_udp_uri_update (&udpsink->uri, UDP_DEFAULT_HOST, -1);
218 gst_udp_uri_update (&udpsink->uri, NULL, g_value_get_int (value));
221 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
225 gst_multiudpsink_add (GST_MULTIUDPSINK (udpsink),
226 udpsink->uri.host, udpsink->uri.port);
230 gst_udpsink_get_property (GObject * object, guint prop_id, GValue * value,
235 udpsink = GST_UDPSINK (object);
239 g_value_set_string (value, udpsink->uri.host);
242 g_value_set_int (value, udpsink->uri.port);
245 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
250 /*** GSTURIHANDLER INTERFACE *************************************************/
253 gst_udpsink_uri_get_type (void)
259 gst_udpsink_uri_get_protocols (void)
261 static gchar *protocols[] = { (char *) "udp", NULL };
267 gst_udpsink_uri_get_uri (GstURIHandler * handler)
269 GstUDPSink *sink = GST_UDPSINK (handler);
271 g_free (sink->uristr);
272 sink->uristr = gst_udp_uri_string (&sink->uri);
278 gst_udpsink_uri_set_uri (GstURIHandler * handler, const gchar * uri)
281 GstUDPSink *sink = GST_UDPSINK (handler);
283 ret = gst_udpsink_set_uri (sink, uri);
289 gst_udpsink_uri_handler_init (gpointer g_iface, gpointer iface_data)
291 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
293 iface->get_type = gst_udpsink_uri_get_type;
294 iface->get_protocols = gst_udpsink_uri_get_protocols;
295 iface->get_uri = gst_udpsink_uri_get_uri;
296 iface->set_uri = gst_udpsink_uri_set_uri;