summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungha Yang <seungha@centricular.com>2021-06-26 20:00:03 +0900
committerTim-Philipp Müller <tim@centricular.com>2021-07-08 13:15:00 +0100
commit71813280b8e58e620e54d817aaa4248b2ca0dc51 (patch)
tree430ad2bd726972184cd9180c117e38a3b4b2df21
parent20cb300706d16d570bd93322fd3b7ad6664daa34 (diff)
downloadgstreamer-plugins-good-71813280b8e58e620e54d817aaa4248b2ca0dc51.tar.gz
multiudpsink: Fix broken SO_SNDBUF get/set on Windows
SO_SNDBUF has been undefined on Windows because of missing WinSock2.h include. And don't use native socket functions (e.g., setsockopt()) if code is expected to be built on Windows. We don't link ws2_32.lib for this plugin. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/1026>
-rw-r--r--gst/udp/gstmultiudpsink.c47
1 files changed, 22 insertions, 25 deletions
diff --git a/gst/udp/gstmultiudpsink.c b/gst/udp/gstmultiudpsink.c
index 3cece6a1f..30ca4b7a9 100644
--- a/gst/udp/gstmultiudpsink.c
+++ b/gst/udp/gstmultiudpsink.c
@@ -41,6 +41,8 @@
#include <sys/socket.h>
#endif
+#include <gio/gnetworking.h>
+
#include "gst/net/net.h"
#include "gst/glib-compat-private.h"
@@ -1338,10 +1340,9 @@ gst_multiudpsink_start (GstBaseSink * bsink)
}
#ifdef SO_SNDBUF
{
- socklen_t len;
- gint sndsize, ret;
+ gint sndsize;
+ GError *opt_err = NULL;
- len = sizeof (sndsize);
if (sink->buffer_size != 0) {
sndsize = sink->buffer_size;
@@ -1351,24 +1352,22 @@ gst_multiudpsink_start (GstBaseSink * bsink)
* Linux. */
if (sink->used_socket) {
- ret =
- setsockopt (g_socket_get_fd (sink->used_socket), SOL_SOCKET,
- SO_SNDBUF, (void *) &sndsize, len);
- if (ret != 0) {
+ if (!g_socket_set_option (sink->used_socket, SOL_SOCKET, SO_SNDBUF,
+ sndsize, &opt_err)) {
GST_ELEMENT_WARNING (sink, RESOURCE, SETTINGS, (NULL),
- ("Could not create a buffer of requested %d bytes, %d: %s",
- sndsize, ret, g_strerror (errno)));
+ ("Could not create a buffer of requested %d bytes (%s)",
+ sndsize, opt_err->message));
+ g_clear_error (&opt_err);
}
}
if (sink->used_socket_v6) {
- ret =
- setsockopt (g_socket_get_fd (sink->used_socket_v6), SOL_SOCKET,
- SO_SNDBUF, (void *) &sndsize, len);
- if (ret != 0) {
+ if (!g_socket_set_option (sink->used_socket_v6, SOL_SOCKET, SO_SNDBUF,
+ sndsize, &opt_err)) {
GST_ELEMENT_WARNING (sink, RESOURCE, SETTINGS, (NULL),
- ("Could not create a buffer of requested %d bytes, %d: %s",
- sndsize, ret, g_strerror (errno)));
+ ("Could not create a buffer of requested %d bytes (%s)",
+ sndsize, opt_err->message));
+ g_clear_error (&opt_err);
}
}
}
@@ -1377,23 +1376,21 @@ gst_multiudpsink_start (GstBaseSink * bsink)
* 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 (sink->used_socket) {
- ret =
- getsockopt (g_socket_get_fd (sink->used_socket), SOL_SOCKET,
- SO_SNDBUF, (void *) &sndsize, &len);
- if (ret == 0)
+ if (g_socket_get_option (sink->used_socket, SOL_SOCKET, SO_SNDBUF,
+ &sndsize, NULL)) {
GST_DEBUG_OBJECT (sink, "have UDP buffer of %d bytes", sndsize);
- else
+ } else {
GST_DEBUG_OBJECT (sink, "could not get UDP buffer size");
+ }
}
if (sink->used_socket_v6) {
- ret =
- getsockopt (g_socket_get_fd (sink->used_socket_v6), SOL_SOCKET,
- SO_SNDBUF, (void *) &sndsize, &len);
- if (ret == 0)
+ if (g_socket_get_option (sink->used_socket_v6, SOL_SOCKET, SO_SNDBUF,
+ &sndsize, NULL)) {
GST_DEBUG_OBJECT (sink, "have UDPv6 buffer of %d bytes", sndsize);
- else
+ } else {
GST_DEBUG_OBJECT (sink, "could not get UDPv6 buffer size");
+ }
}
}
#endif