summaryrefslogtreecommitdiffstats
path: root/gst
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim.muller@collabora.co.uk>2013-02-15 14:11:36 +0000
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2013-04-29 08:51:19 +0200
commit1603fbd24f2c82be69aa1c97ba0905472fbfc9aa (patch)
tree6aa72fd76ddbf16d2891ae3f317d185d7a0e148e /gst
parent75b1558da1d36215c9ee9ff1049cf42fea885740 (diff)
downloadgst-plugins-good-1603fbd24f2c82be69aa1c97ba0905472fbfc9aa.tar.gz
gst-plugins-good-1603fbd24f2c82be69aa1c97ba0905472fbfc9aa.tar.xz
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 Conflicts: gst/udp/gstudpsrc.c
Diffstat (limited to 'gst')
-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 bd20a124f..4013240f2 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
GST_DEBUG_CATEGORY_STATIC (udpsrc_debug);
#define GST_CAT_DEFAULT (udpsrc_debug)
@@ -811,7 +815,39 @@ gst_udpsrc_start (GstBaseSrc * bsrc)
if (src->timeout)
g_socket_set_timeout (src->used_socket, src->timeout / GST_SECOND);
-#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;
@@ -845,6 +881,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);