0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-19 20:32:15 +02:00

obs-outputs: Only log SO_SNDBUF on RTMP socket

From Windows 7 onwards, dynamic send buffering is enabled. By setting
SO_SNDBUF explicitly, we actually disabled the dynamic send buffering
feature which results in reduced throughput. Thankfully this did not
affect the majority of users since the default send buffer is usually
already 64k.

This commit replaces the setting of SO_SNDBUF with log output showing
the current value of SO_SNDBUF at stream start and end. This will aid in
debugging throughput issues caused by a buffer that isn't big enough,
perhaps as a result of the user disabling dynamic send buffering
system-wide.
This commit is contained in:
Richard Stanway 2021-12-22 19:26:28 +01:00 committed by Jim
parent 1655ebf18f
commit af6844f5c2

View File

@ -583,12 +583,31 @@ static void dbr_add_frame(struct rtmp_stream *stream, struct dbr_frame *back)
static void dbr_set_bitrate(struct rtmp_stream *stream);
static bool rtmp_stream_start(void *data);
#ifdef _WIN32
#define socklen_t int
#endif
static void log_sndbuf_size(struct rtmp_stream *stream)
{
int cur_sendbuf_size;
socklen_t int_size = sizeof(int);
if (!getsockopt(stream->rtmp.m_sb.sb_socket, SOL_SOCKET, SO_SNDBUF,
(char *)&cur_sendbuf_size, &int_size)) {
info("Socket send buffer is %d bytes", cur_sendbuf_size);
}
}
static void *send_thread(void *data)
{
struct rtmp_stream *stream = data;
os_set_thread_name("rtmp-stream: send_thread");
#if defined(_WIN32)
log_sndbuf_size(stream);
#endif
while (os_sem_wait(stream->send_sem) == 0) {
struct encoder_packet packet;
struct dbr_frame dbr_frame;
@ -653,6 +672,10 @@ static void *send_thread(void *data)
info("User stopped the stream");
}
#if defined(_WIN32)
log_sndbuf_size(stream);
#endif
if (stream->new_socket_loop) {
os_event_signal(stream->send_thread_signaled_exit);
os_event_signal(stream->buffer_has_data_event);
@ -794,36 +817,11 @@ static inline bool reset_semaphore(struct rtmp_stream *stream)
return os_sem_init(&stream->send_sem, 0) == 0;
}
#ifdef _WIN32
#define socklen_t int
#endif
#define MIN_SENDBUF_SIZE 65535
static void adjust_sndbuf_size(struct rtmp_stream *stream, int new_size)
{
int cur_sendbuf_size = new_size;
socklen_t int_size = sizeof(int);
getsockopt(stream->rtmp.m_sb.sb_socket, SOL_SOCKET, SO_SNDBUF,
(char *)&cur_sendbuf_size, &int_size);
if (cur_sendbuf_size < new_size) {
cur_sendbuf_size = new_size;
setsockopt(stream->rtmp.m_sb.sb_socket, SOL_SOCKET, SO_SNDBUF,
(const char *)&cur_sendbuf_size, int_size);
}
}
static int init_send(struct rtmp_stream *stream)
{
int ret;
obs_output_t *context = stream->output;
#if defined(_WIN32)
adjust_sndbuf_size(stream, MIN_SENDBUF_SIZE);
#endif
if (!silently_reconnecting(stream))
reset_semaphore(stream);