From 466ac95829f31639ff5d834667402afc53eb3c28 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 11 Oct 2023 11:40:18 +0200 Subject: [PATCH] recv buf: issue a warning if unable to set Issue a warning if unable to set the buffers andreceiving uncompressed stream, but not not on initial setting, only if increase requested. The logic is not entirely straightforward - as we are increasing only, do not assume that the buffer is set to the initial size but rather read the actual value, which will be less if wasn't possible to set. So the second attemp issues the warning. --- src/rtp/net_udp.c | 13 +++++++++++++ src/rtp/net_udp.h | 1 + src/rtp/rtp.c | 6 ++++++ src/rtp/rtp.h | 1 + src/video_rxtx/rtp.cpp | 11 ++++------- src/video_rxtx/ultragrid_rtp.cpp | 2 +- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/rtp/net_udp.c b/src/rtp/net_udp.c index fa4012250..e446e62e5 100644 --- a/src/rtp/net_udp.c +++ b/src/rtp/net_udp.c @@ -1433,6 +1433,19 @@ static int resolve_address(socket_udp *s, const char *addr, uint16_t tx_port) return ret; } +int +udp_get_recv_buf(socket_udp *s) +{ + int opt = 0; + socklen_t opt_size = sizeof opt; + if (GETSOCKOPT(s->local->tx_fd, SOL_SOCKET, SO_RCVBUF, (sockopt_t) &opt, + &opt_size) != 0) { + socket_error("Unable to get socket buffer size"); + return -1; + } + return opt; +} + static bool udp_set_buf(socket_udp *s, int sockopt, int size) { diff --git a/src/rtp/net_udp.h b/src/rtp/net_udp.h index 97b7241c3..3ebaedaac 100644 --- a/src/rtp/net_udp.h +++ b/src/rtp/net_udp.h @@ -92,6 +92,7 @@ void udp_fd_zero(void); void udp_fd_set(socket_udp *s); int udp_fd_isset(socket_udp *s); +int udp_get_recv_buf(socket_udp *s); bool udp_set_recv_buf(socket_udp *s, int size); bool udp_set_send_buf(socket_udp *s, int size); void udp_flush_recv_buf(socket_udp *s); diff --git a/src/rtp/rtp.c b/src/rtp/rtp.c index 140c949d5..b431efd69 100644 --- a/src/rtp/rtp.c +++ b/src/rtp/rtp.c @@ -3945,6 +3945,12 @@ bool rtp_set_recv_buf(struct rtp *session, int bufsize) return udp_set_recv_buf(session->rtp_socket, bufsize); } +int +rtp_get_recv_buf(struct rtp *session) +{ + return udp_get_recv_buf(session->rtp_socket); +} + /** * Sets sender buffer size * @param session the RTP Session diff --git a/src/rtp/rtp.h b/src/rtp/rtp.h index 35dfbb0d8..715017a0b 100644 --- a/src/rtp/rtp.h +++ b/src/rtp/rtp.h @@ -304,6 +304,7 @@ bool rtp_set_my_ssrc(struct rtp *session, uint32_t ssrc); uint8_t *rtp_get_userdata(struct rtp *session); void rtp_set_recv_iov(struct rtp *session, struct msghdr *m); +int rtp_get_recv_buf(struct rtp *session); bool rtp_set_recv_buf(struct rtp *session, int bufsize); bool rtp_set_send_buf(struct rtp *session, int bufsize); diff --git a/src/video_rxtx/rtp.cpp b/src/video_rxtx/rtp.cpp index 8c36d519e..f4dba467f 100644 --- a/src/video_rxtx/rtp.cpp +++ b/src/video_rxtx/rtp.cpp @@ -250,13 +250,13 @@ rtp_video_rxtx::~rtp_video_rxtx() void rtp_video_rxtx::display_buf_increase_warning(int size) { - log_msg(LOG_LEVEL_VERBOSE, "\n***\n" + log_msg(LOG_LEVEL_INFO, "\n***\n" "Unable to set buffer size to %d B.\n" #if defined WIN32 "See https://github.com/CESNET/UltraGrid/wiki/Extending-Network-Buffers-%%28Windows%%29 for details.\n", #else - "Please set net.core.rmem_max value to %d or greater. (see also\n" - "https://github.com/CESNET/UltraGrid/wiki/OS-Setup-UltraGrid)\n" + "Please set net.core.rmem_max value to %d or greater (see also\n" + "https://github.com/CESNET/UltraGrid/wiki/OS-Setup-UltraGrid):\n" #ifdef HAVE_MACOSX "\tsysctl -w kern.ipc.maxsockbuf=%d\n" "\tsysctl -w net.inet.udp.recvspace=%d\n" @@ -301,10 +301,7 @@ struct rtp *rtp_video_rxtx::initialize_network(const char *addr, int recv_port, rtp_set_option(device, RTP_OPT_SEND_BACK, TRUE); } - if (!rtp_set_recv_buf(device, INITIAL_VIDEO_RECV_BUFFER_SIZE)) { - display_buf_increase_warning(INITIAL_VIDEO_RECV_BUFFER_SIZE); - } - + rtp_set_recv_buf(device, INITIAL_VIDEO_RECV_BUFFER_SIZE); rtp_set_send_buf(device, INITIAL_VIDEO_SEND_BUFFER_SIZE); pdb_add(participants, rtp_my_ssrc(device)); diff --git a/src/video_rxtx/ultragrid_rtp.cpp b/src/video_rxtx/ultragrid_rtp.cpp index 360541277..e7dffa8d6 100644 --- a/src/video_rxtx/ultragrid_rtp.cpp +++ b/src/video_rxtx/ultragrid_rtp.cpp @@ -278,7 +278,7 @@ void *ultragrid_rtp_video_rxtx::receiver_loop() set_thread_name(__func__); struct pdb_e *cp; int fr; - int last_buf_size = INITIAL_VIDEO_RECV_BUFFER_SIZE; + int last_buf_size = rtp_get_recv_buf(m_network_device); #ifdef SHARED_DECODER struct vcodec_state *shared_decoder = new_video_decoder(m_display_device);