Skip to content

Commit

Permalink
recv buf: issue a warning if unable to set
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MartinPulec committed Oct 11, 2023
1 parent c0e69d5 commit 466ac95
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/rtp/net_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/rtp/net_udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/rtp/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/rtp/rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 4 additions & 7 deletions src/video_rxtx/rtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/video_rxtx/ultragrid_rtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 466ac95

Please sign in to comment.