Message ID | 20171114174059.14555-1-ffmpeg@tmm1.net |
---|---|
State | New |
Headers | show |
On Tue, Nov 14, 2017 at 9:40 AM, Aman Gupta <ffmpeg@tmm1.net> wrote: > From: Aman Gupta <aman@tmm1.net> > > This can reduce latency and increase throughput, particularly on high > latency networks. > Oops, I forgot to remove "enabled by default" from the commit message subject. Fixed locally. > > Signed-off-by: Aman Gupta <aman@tmm1.net> > Reviewed-by: Jeyapal, Karthick <kjeyapal@akamai.com> > --- > libavformat/network.h | 1 + > libavformat/tcp.c | 5 +++++ > 2 files changed, 6 insertions(+) > > diff --git a/libavformat/network.h b/libavformat/network.h > index f83c796a95..b78e3ad6ed 100644 > --- a/libavformat/network.h > +++ b/libavformat/network.h > @@ -59,6 +59,7 @@ int ff_neterrno(void); > #include <sys/types.h> > #include <sys/socket.h> > #include <netinet/in.h> > +#include <netinet/tcp.h> > #include <netdb.h> > > #define ff_neterrno() AVERROR(errno) > diff --git a/libavformat/tcp.c b/libavformat/tcp.c > index 07b4ed9fa3..f3f9d4f431 100644 > --- a/libavformat/tcp.c > +++ b/libavformat/tcp.c > @@ -41,6 +41,7 @@ typedef struct TCPContext { > int listen_timeout; > int recv_buffer_size; > int send_buffer_size; > + int tcp_nodelay; > } TCPContext; > > #define OFFSET(x) offsetof(TCPContext, x) > @@ -52,6 +53,7 @@ static const AVOption options[] = { > { "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 }, > + { "tcp_nodelay", "Use TCP_NODELAY to disable nagle's algorithm", > OFFSET(tcp_nodelay), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, > .flags = D|E }, > { NULL } > }; > > @@ -148,6 +150,9 @@ static int tcp_open(URLContext *h, const char *uri, > int flags) > if (s->send_buffer_size > 0) { > setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, > sizeof (s->send_buffer_size)); > } > + if (s->tcp_nodelay > 0) { > + setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof > (s->tcp_nodelay)); > + } > > if (s->listen == 2) { > // multi-client > -- > 2.14.2 > >
On Tue, Nov 14, 2017 at 09:40:58 -0800, Aman Gupta wrote: > From: Aman Gupta <aman@tmm1.net> > Subject: avformat/tcp: enable TCP_NODELAY by default The commit message is no longer correct -> avformat/tcp: allow setting TCP_NODELAY Moritz
>On 11/14/17, 11:11 PM, "Aman Gupta" <aman@tmm1.net on behalf of ffmpeg@tmm1.net> wrote: > >From: Aman Gupta <aman@tmm1.net> > >This can reduce latency and increase throughput, particularly on high >latency networks. > >Signed-off-by: Aman Gupta <aman@tmm1.net> >Reviewed-by: Jeyapal, Karthick <kjeyapal@akamai.com> --- I forgot to mention last time. You would also need to update the doc/protocols.texi documentation explaining this new option. Regards, Karthick
diff --git a/libavformat/network.h b/libavformat/network.h index f83c796a95..b78e3ad6ed 100644 --- a/libavformat/network.h +++ b/libavformat/network.h @@ -59,6 +59,7 @@ int ff_neterrno(void); #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> +#include <netinet/tcp.h> #include <netdb.h> #define ff_neterrno() AVERROR(errno) diff --git a/libavformat/tcp.c b/libavformat/tcp.c index 07b4ed9fa3..f3f9d4f431 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -41,6 +41,7 @@ typedef struct TCPContext { int listen_timeout; int recv_buffer_size; int send_buffer_size; + int tcp_nodelay; } TCPContext; #define OFFSET(x) offsetof(TCPContext, x) @@ -52,6 +53,7 @@ static const AVOption options[] = { { "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 }, + { "tcp_nodelay", "Use TCP_NODELAY to disable nagle's algorithm", OFFSET(tcp_nodelay), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E }, { NULL } }; @@ -148,6 +150,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags) if (s->send_buffer_size > 0) { setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size)); } + if (s->tcp_nodelay > 0) { + setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof (s->tcp_nodelay)); + } if (s->listen == 2) { // multi-client