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_finalize (GstUDPSink * udpsink);
67 static void gst_udpsink_uri_handler_init (gpointer g_iface,
70 static void gst_udpsink_set_property (GObject * object, guint prop_id,
71 const GValue * value, GParamSpec * pspec);
72 static void gst_udpsink_get_property (GObject * object, guint prop_id,
73 GValue * value, GParamSpec * pspec);
75 /*static guint gst_udpsink_signals[LAST_SIGNAL] = { 0 }; */
76 #define gst_udpsink_parent_class parent_class
77 G_DEFINE_TYPE_WITH_CODE (GstUDPSink, gst_udpsink, GST_TYPE_MULTIUDPSINK,
78 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_udpsink_uri_handler_init));
81 gst_udpsink_class_init (GstUDPSinkClass * klass)
83 GObjectClass *gobject_class;
84 GstElementClass *gstelement_class;
86 gobject_class = (GObjectClass *) klass;
87 gstelement_class = (GstElementClass *) klass;
89 gobject_class->set_property = gst_udpsink_set_property;
90 gobject_class->get_property = gst_udpsink_get_property;
92 gobject_class->finalize = (GObjectFinalizeFunc) gst_udpsink_finalize;
94 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HOST,
95 g_param_spec_string ("host", "host",
96 "The host/IP/Multicast group to send the packets to",
97 UDP_DEFAULT_HOST, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
98 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT,
99 g_param_spec_int ("port", "port", "The port to send the packets to",
100 0, 65535, UDP_DEFAULT_PORT,
101 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
103 gst_element_class_set_details_simple (gstelement_class, "UDP packet sender",
105 "Send data over the network via UDP", "Wim Taymans <wim@fluendo.com>");
109 gst_udpsink_init (GstUDPSink * udpsink)
111 gst_udp_uri_init (&udpsink->uri, UDP_DEFAULT_HOST, UDP_DEFAULT_PORT);
113 gst_multiudpsink_add (GST_MULTIUDPSINK (udpsink), udpsink->uri.host,
118 gst_udpsink_finalize (GstUDPSink * udpsink)
120 gst_udp_uri_free (&udpsink->uri);
121 g_free (udpsink->uristr);
123 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) udpsink);
127 gst_udpsink_set_uri (GstUDPSink * sink, const gchar * uri, GError ** error)
129 gst_multiudpsink_remove (GST_MULTIUDPSINK (sink), sink->uri.host,
132 if (gst_udp_parse_uri (uri, &sink->uri) < 0)
135 gst_multiudpsink_add (GST_MULTIUDPSINK (sink), sink->uri.host,
143 GST_ELEMENT_ERROR (sink, RESOURCE, READ, (NULL),
144 ("error parsing uri %s", uri));
145 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
146 "Could not parse UDP URI");
152 gst_udpsink_set_property (GObject * object, guint prop_id, const GValue * value,
157 udpsink = GST_UDPSINK (object);
159 /* remove old host */
160 gst_multiudpsink_remove (GST_MULTIUDPSINK (udpsink),
161 udpsink->uri.host, udpsink->uri.port);
168 host = g_value_get_string (value);
171 gst_udp_uri_update (&udpsink->uri, host, -1);
173 gst_udp_uri_update (&udpsink->uri, UDP_DEFAULT_HOST, -1);
177 gst_udp_uri_update (&udpsink->uri, NULL, g_value_get_int (value));
180 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
184 gst_multiudpsink_add (GST_MULTIUDPSINK (udpsink),
185 udpsink->uri.host, udpsink->uri.port);
189 gst_udpsink_get_property (GObject * object, guint prop_id, GValue * value,
194 udpsink = GST_UDPSINK (object);
198 g_value_set_string (value, udpsink->uri.host);
201 g_value_set_int (value, udpsink->uri.port);
204 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
209 /*** GSTURIHANDLER INTERFACE *************************************************/
212 gst_udpsink_uri_get_type (GType type)
217 static const gchar *const *
218 gst_udpsink_uri_get_protocols (GType type)
220 static const gchar *protocols[] = { "udp", NULL };
226 gst_udpsink_uri_get_uri (GstURIHandler * handler)
228 GstUDPSink *sink = GST_UDPSINK (handler);
230 g_free (sink->uristr);
231 sink->uristr = gst_udp_uri_string (&sink->uri);
233 return g_strdup (sink->uristr);
237 gst_udpsink_uri_set_uri (GstURIHandler * handler, const gchar * uri,
240 return gst_udpsink_set_uri (GST_UDPSINK (handler), uri, error);
244 gst_udpsink_uri_handler_init (gpointer g_iface, gpointer iface_data)
246 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
248 iface->get_type = gst_udpsink_uri_get_type;
249 iface->get_protocols = gst_udpsink_uri_get_protocols;
250 iface->get_uri = gst_udpsink_uri_get_uri;
251 iface->set_uri = gst_udpsink_uri_set_uri;