summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim.muller@collabora.co.uk>2013-02-15 14:11:36 +0000
committerTim-Philipp Müller <tim.muller@collabora.co.uk>2013-02-15 14:11:36 +0000
commit01c6512d5f0601639114a692df4d74e80fe49c38 (patch)
tree82075af41568be2956e61d8ee60def8740cd4691
parent24cdefcb755543c397ae9dde5d59ff0b697f8dcd (diff)
udpsrc: use g_socket_set_option() to set buffer size with newer GLib versions
So we have to worry less about portability. https://bugzilla.gnome.org/show_bug.cgi?id=692400
-rw-r--r--gst/udp/gstudpsrc.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/gst/udp/gstudpsrc.c b/gst/udp/gstudpsrc.c
index 82f183c2a..100f9e25c 100644
--- a/gst/udp/gstudpsrc.c
+++ b/gst/udp/gstudpsrc.c
@@ -112,9 +112,13 @@
#include <gst/net/gstnetaddressmeta.h>
+#if GLIB_CHECK_VERSION (2, 35, 7)
+#include <gio/gnetworking.h>
+#else
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
+#endif
/* not 100% correct, but a good upper bound for memory allocation purposes */
#define MAX_IPV4_UDP_PACKET_SIZE (65536 - 8)
@@ -823,7 +827,39 @@ gst_udpsrc_start (GstBaseSrc * bsrc)
goto getsockname_error;
}
-#ifdef SO_RCVBUF
+#if GLIB_CHECK_VERSION (2, 35, 7)
+ {
+ gint val = 0;
+
+ if (src->buffer_size != 0) {
+ GError *opt_err = NULL;
+
+ GST_INFO_OBJECT (src, "setting udp buffer of %d bytes", src->buffer_size);
+ /* set buffer size, Note that on Linux this is typically limited to a
+ * maximum of around 100K. Also a minimum of 128 bytes is required on
+ * Linux. */
+ if (!g_socket_set_option (src->used_socket, SOL_SOCKET, SO_RCVBUF,
+ src->buffer_size, &opt_err)) {
+ GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, (NULL),
+ ("Could not create a buffer of requested %d bytes: %s",
+ src->buffer_size, opt_err->message));
+ g_error_free (opt_err);
+ opt_err = NULL;
+ }
+ }
+
+ /* read the value of the receive buffer. Note that on linux this returns
+ * 2x the value we set because the kernel allocates extra memory for
+ * metadata. The default on Linux is about 100K (which is about 50K
+ * without metadata) */
+ if (g_socket_get_option (src->used_socket, SOL_SOCKET, SO_RCVBUF, &val,
+ NULL)) {
+ GST_INFO_OBJECT (src, "have udp buffer of %d bytes", val);
+ } else {
+ GST_DEBUG_OBJECT (src, "could not get udp buffer size");
+ }
+ }
+#elif defined (SO_RCVBUF)
{
gint rcvsize, ret;
socklen_t len;
@@ -857,6 +893,12 @@ gst_udpsrc_start (GstBaseSrc * bsrc)
else
GST_DEBUG_OBJECT (src, "could not get udp buffer size");
}
+#else
+ if (src->buffer_size != 0) {
+ GST_WARNING_OBJECT (src, "don't know how to set udp buffer size on this "
+ "OS. Consider upgrading your GLib to >= 2.35.7 and re-compiling the "
+ "GStreamer udp plugin");
+ }
#endif
g_socket_set_broadcast (src->used_socket, TRUE);