mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
avformat/tcp: add option to enable TCP_NODELAY
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>
This commit is contained in:
parent
ce001bb8fc
commit
80bb81a8f3
@ -1242,6 +1242,9 @@ Set receive buffer size, expressed bytes.
|
|||||||
|
|
||||||
@item send_buffer_size=@var{bytes}
|
@item send_buffer_size=@var{bytes}
|
||||||
Set send buffer size, expressed bytes.
|
Set send buffer size, expressed bytes.
|
||||||
|
|
||||||
|
@item tcp_nodelay=@var{1|0}
|
||||||
|
Set TCP_NODELAY to disable Nagle's algorithm. Default value is 0.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
The following example shows how to setup a listening TCP connection
|
The following example shows how to setup a listening TCP connection
|
||||||
|
@ -59,6 +59,7 @@ int ff_neterrno(void);
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
#define ff_neterrno() AVERROR(errno)
|
#define ff_neterrno() AVERROR(errno)
|
||||||
|
@ -41,6 +41,7 @@ typedef struct TCPContext {
|
|||||||
int listen_timeout;
|
int listen_timeout;
|
||||||
int recv_buffer_size;
|
int recv_buffer_size;
|
||||||
int send_buffer_size;
|
int send_buffer_size;
|
||||||
|
int tcp_nodelay;
|
||||||
} TCPContext;
|
} TCPContext;
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(TCPContext, x)
|
#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 },
|
{ "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 },
|
{ "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 },
|
{ "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 }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -148,6 +150,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
|
|||||||
if (s->send_buffer_size > 0) {
|
if (s->send_buffer_size > 0) {
|
||||||
setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size));
|
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) {
|
if (s->listen == 2) {
|
||||||
// multi-client
|
// multi-client
|
||||||
|
Loading…
Reference in New Issue
Block a user