PR #22788 opened by igutidze
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22788
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22788.patch

According to https://man7.org/linux/man-pages/man7/socket.7.html,
the kernel doubles requested SO_RCVBUF value set using setsockopt
and this doubled value is returned by getsockopt.

Take into account this effect when checking whether requested buffer size
has been applied.

Signed-off-by: igutidze <[email protected]>


>From 0f68272b738680c5df34ca6cbc9eababcd32f89f Mon Sep 17 00:00:00 2001
From: igutidze <[email protected]>
Date: Sat, 11 Apr 2026 06:51:09 +0000
Subject: [PATCH] avformat/udp: take into account the doubling of SO_RCVBUF
 size on linux

According to https://man7.org/linux/man-pages/man7/socket.7.html,
the kernel doubles requested SO_RCVBUF value set using setsockopt
and this doubled value is returned by getsockopt.

Take into account this effect when checking whether requested buffer size
has been applied.

Signed-off-by: igutidze <[email protected]>
---
 libavformat/udp.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 0874d18397..d4f830c708 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -885,6 +885,10 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
         if (getsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, &len) < 0) {
             ff_log_net_error(h, AV_LOG_WARNING, "getsockopt(SO_RCVBUF)");
         } else {
+#ifdef __linux__
+            /* on linux, setsockopt doubles the requested value, while 
getsockopt returns this doubled value, so correct it */
+            tmp /= 2;
+#endif
             av_log(h, AV_LOG_DEBUG, "end receive buffer size reported is 
%d\n", tmp);
             if(tmp < s->buffer_size)
                 av_log(h, AV_LOG_WARNING, "attempted to set receive buffer to 
size %d but it only ended up set as %d\n", s->buffer_size, tmp);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to