From 01c6512d5f0601639114a692df4d74e80fe49c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 15 Feb 2013 14:11:36 +0000 Subject: [PATCH] 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 --- gst/udp/gstudpsrc.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/gst/udp/gstudpsrc.c b/gst/udp/gstudpsrc.c index 82f183c2a9..100f9e25cb 100644 --- a/gst/udp/gstudpsrc.c +++ b/gst/udp/gstudpsrc.c @@ -112,9 +112,13 @@ #include +#if GLIB_CHECK_VERSION (2, 35, 7) +#include +#else #ifdef HAVE_SYS_SOCKET_H #include #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);