diff options
author | Perette Barella <perette@barella.org> | 2016-01-19 13:22:13 -0500 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2016-01-22 15:36:30 +0100 |
commit | 84110f4f7760c4f0a9c3e394447304e7cd2384a3 (patch) | |
tree | dcd5f58f08b5e7e3d49928936c0086a71adb783b /libavformat | |
parent | 1fb5ae44c43de48fa497b29f559dcf32313f5290 (diff) | |
download | ffmpeg-84110f4f7760c4f0a9c3e394447304e7cd2384a3.tar.gz |
libavformat/tcp.c : add send_buffer_size and recv_buffer_size options
adds two new options that may be set via the dictionary:
- send_buffer_size
- recv_buffer_size
When present, setsockopt() is used with SO_SNDBUF and SO_RCVBUF to set
socket buffer sizes. I chose to make send and receive independent
because buffering requirements are often asymmetric.
Errors in setting the buffer size mean the socket will use its
default, so they are ignored.
There is no sanity checking on values, as the kernel/socket layers
already impose reasonable limits if asked for something crazy.
Rationale for enlarging receive buffers is to reduce susceptibility
to intermittent network delays/congestion. I added setting the send
buffer for symmetry.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/tcp.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libavformat/tcp.c b/libavformat/tcp.c index e02c64b800..5738690843 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -39,6 +39,8 @@ typedef struct TCPContext { int open_timeout; int rw_timeout; int listen_timeout; + int recv_buffer_size; + int send_buffer_size; } TCPContext; #define OFFSET(x) offsetof(TCPContext, x) @@ -48,6 +50,8 @@ static const AVOption options[] = { { "listen", "Listen for incoming connections", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, .flags = D|E }, { "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, { "listen_timeout", "Connection awaiting timeout (in milliseconds)", OFFSET(listen_timeout), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, + { "send_buffer_size", "Socket send buffer size (in bytes)", OFFSET(send_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, + { "recv_buffer_size", "Socket receive buffer size (in bytes)", OFFSET(recv_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, { NULL } }; @@ -150,6 +154,15 @@ static int tcp_open(URLContext *h, const char *uri, int flags) h->is_streamed = 1; s->fd = fd; + /* Set the socket's send or receive buffer sizes, if specified. + If unspecified or setting fails, system default is used. */ + if (s->recv_buffer_size > 0) { + setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &s->recv_buffer_size, sizeof (s->recv_buffer_size)); + } + if (s->send_buffer_size > 0) { + setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size)); + } + freeaddrinfo(ai); return 0; |