[FFmpeg-devel] [PATCH 1/4] libformat/tcp: Moved all options to a separate structure
Karthick J
kjeyapal at akamai.com
Fri Nov 3 10:27:00 EET 2017
---
libavformat/tcp.c | 46 +++++++++++++++++++++++++---------------------
1 file changed, 25 insertions(+), 21 deletions(-)
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 07b4ed9..06368ff 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -32,18 +32,22 @@
#include <poll.h>
#endif
-typedef struct TCPContext {
- const AVClass *class;
- int fd;
+typedef struct TCPOptions {
int listen;
- int open_timeout;
int rw_timeout;
int listen_timeout;
int recv_buffer_size;
int send_buffer_size;
+} TCPOptions;
+
+typedef struct TCPContext {
+ const AVClass *class;
+ int fd;
+ int open_timeout;
+ TCPOptions options;
} TCPContext;
-#define OFFSET(x) offsetof(TCPContext, x)
+#define OFFSET(x) (offsetof(TCPContext, options) + offsetof(TCPOptions, x))
#define D AV_OPT_FLAG_DECODING_PARAM
#define E AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
@@ -87,26 +91,26 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
if (p) {
if (av_find_info_tag(buf, sizeof(buf), "listen", p)) {
char *endptr = NULL;
- s->listen = strtol(buf, &endptr, 10);
+ s->options.listen = strtol(buf, &endptr, 10);
/* assume if no digits were found it is a request to enable it */
if (buf == endptr)
- s->listen = 1;
+ s->options.listen = 1;
}
if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
- s->rw_timeout = strtol(buf, NULL, 10);
+ s->options.rw_timeout = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) {
- s->listen_timeout = strtol(buf, NULL, 10);
+ s->options.listen_timeout = strtol(buf, NULL, 10);
}
}
- if (s->rw_timeout >= 0) {
+ if (s->options.rw_timeout >= 0) {
s->open_timeout =
- h->rw_timeout = s->rw_timeout;
+ h->rw_timeout = s->options.rw_timeout;
}
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
snprintf(portstr, sizeof(portstr), "%d", port);
- if (s->listen)
+ if (s->options.listen)
hints.ai_flags |= AI_PASSIVE;
if (!hostname[0])
ret = getaddrinfo(NULL, portstr, &hints, &ai);
@@ -142,21 +146,21 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
/* 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->options.recv_buffer_size > 0) {
+ setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &s->options.recv_buffer_size, sizeof (s->options.recv_buffer_size));
}
- if (s->send_buffer_size > 0) {
- setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size));
+ if (s->options.send_buffer_size > 0) {
+ setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->options.send_buffer_size, sizeof (s->options.send_buffer_size));
}
- if (s->listen == 2) {
+ if (s->options.listen == 2) {
// multi-client
if ((ret = ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen)) < 0)
goto fail1;
- } else if (s->listen == 1) {
+ } else if (s->options.listen == 1) {
// single client
if ((ret = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
- s->listen_timeout, h)) < 0)
+ s->options.listen_timeout, h)) < 0)
goto fail1;
// Socket descriptor already closed here. Safe to overwrite to client one.
fd = ret;
@@ -198,11 +202,11 @@ static int tcp_accept(URLContext *s, URLContext **c)
TCPContext *sc = s->priv_data;
TCPContext *cc;
int ret;
- av_assert0(sc->listen);
+ av_assert0(sc->options.listen);
if ((ret = ffurl_alloc(c, s->filename, s->flags, &s->interrupt_callback)) < 0)
return ret;
cc = (*c)->priv_data;
- ret = ff_accept(sc->fd, sc->listen_timeout, s);
+ ret = ff_accept(sc->fd, sc->options.listen_timeout, s);
if (ret < 0)
return ret;
cc->fd = ret;
--
1.9.1
More information about the ffmpeg-devel
mailing list