Go to the documentation of this file.
52 #define OFFSET(x) offsetof(TCPContext, x)
53 #define D AV_OPT_FLAG_DECODING_PARAM
54 #define E AV_OPT_FLAG_ENCODING_PARAM
56 {
"listen",
"Listen for incoming connections",
OFFSET(listen),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, .flags =
D|
E },
59 {
"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 },
60 {
"listen_timeout",
"Connection awaiting timeout (in milliseconds)",
OFFSET(listen_timeout),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
61 {
"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 },
62 {
"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 },
63 {
"tcp_nodelay",
"Use TCP_NODELAY to disable nagle's algorithm",
OFFSET(tcp_nodelay),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags =
D|
E },
65 {
"tcp_mss",
"Maximum segment size for outgoing TCP packets",
OFFSET(tcp_mss),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
81 if (
s->local_addr ||
s->local_port) {
82 struct addrinfo hints = { 0 }, *ai, *cur_ai;
91 "Failed to getaddrinfo local addr: %s port: %s err: %s\n",
98 ret = bind(fd, (
struct sockaddr *)cur_ai->ai_addr, (
int)cur_ai->ai_addrlen);
100 cur_ai = cur_ai->ai_next;
113 if (
s->recv_buffer_size > 0) {
114 if (setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &
s->recv_buffer_size, sizeof (
s->recv_buffer_size))) {
118 if (
s->send_buffer_size > 0) {
119 if (setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &
s->send_buffer_size, sizeof (
s->send_buffer_size))) {
123 if (
s->tcp_nodelay > 0) {
124 if (setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &
s->tcp_nodelay, sizeof (
s->tcp_nodelay))) {
129 if (
s->tcp_mss > 0) {
130 if (setsockopt (fd, IPPROTO_TCP, TCP_MAXSEG, &
s->tcp_mss, sizeof (
s->tcp_mss))) {
142 struct addrinfo hints = { 0 }, *ai, *cur_ai;
148 char hostname[1024],proto[1024],path[1024];
150 s->open_timeout = 5000000;
153 &port, path,
sizeof(path), uri);
154 if (strcmp(proto,
"tcp"))
156 if (port <= 0 || port >= 65536) {
160 p = strchr(uri,
'?');
164 s->listen = strtol(buf, &endptr, 10);
182 s->rw_timeout = strtol(buf,
NULL, 10);
185 s->listen_timeout = strtol(buf,
NULL, 10);
188 s->tcp_nodelay = strtol(buf,
NULL, 10);
191 if (
s->rw_timeout >= 0) {
193 h->rw_timeout =
s->rw_timeout;
197 snprintf(portstr,
sizeof(portstr),
"%d", port);
206 "Failed to resolve hostname %s: %s\n",
213 #if HAVE_STRUCT_SOCKADDR_IN6
215 if (cur_ai->ai_family == AF_INET6){
216 struct sockaddr_in6 * sockaddr_v6 = (
struct sockaddr_in6 *)cur_ai->ai_addr;
217 if (!sockaddr_v6->sin6_port){
218 sockaddr_v6->sin6_port = htons(port);
224 while (cur_ai && fd < 0) {
227 cur_ai->ai_protocol,
h);
230 cur_ai = cur_ai->ai_next;
238 if (
s->listen == 2) {
240 if ((
ret =
ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
h)) < 0)
242 }
else if (
s->listen == 1) {
245 s->listen_timeout,
h)) < 0)
276 cc = (*c)->priv_data;
329 return shutdown(
s->fd, how);
349 socklen_t avail_len =
sizeof(avail);
354 if (
s->recv_buffer_size < 0) {
359 if (getsockopt(
s->fd, SOL_SOCKET, SO_RCVBUF, &avail, &avail_len)) {
#define AV_LOG_WARNING
Something somehow does not look correct.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
Attempt to find a specific tag in a URL.
static int tcp_accept(URLContext *s, URLContext **c)
#define URL_PROTOCOL_FLAG_NETWORK
#define AVERROR_EOF
End of file.
static int tcp_write(URLContext *h, const uint8_t *buf, int size)
void ff_log_net_error(void *ctx, int level, const char *prefix)
int ff_listen_bind(int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h)
Bind to a file descriptor and poll for a connection.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int customize_fd(void *ctx, int fd, int family)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AVIO_FLAG_WRITE
write-only
static int tcp_open(URLContext *h, const char *uri, int flags)
static int tcp_read(URLContext *h, uint8_t *buf, int size)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
const char * av_default_item_name(void *ptr)
Return the context name.
int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb)
This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds Uses ff_network_wa...
static const AVOption options[]
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static int tcp_close(URLContext *h)
const URLProtocol ff_tcp_protocol
int ff_accept(int fd, int timeout, URLContext *h)
Poll for a single connection on the passed file descriptor.
static int tcp_get_file_handle(URLContext *h)
static int tcp_get_window_size(URLContext *h)
int ffurl_alloc(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb)
Create a URLContext for accessing to the resource indicated by url, but do not initiate the connectio...
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address, int parallel, URLContext *h, int *fd, int(*customize_fd)(void *, int, int), void *customize_ctx)
Connect to any of the given addrinfo addresses, with multiple attempts running in parallel.
static int tcp_shutdown(URLContext *h, int flags)
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int ff_listen(int fd, const struct sockaddr *addr, socklen_t addrlen, void *logctx)
Bind to a file descriptor to an address without accepting connections.
static const AVClass tcp_class
#define AVIO_FLAG_READ
read-only
char * av_strdup(const char *s)
Duplicate a string.
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
#define flags(name, subs,...)
int ff_socket(int af, int type, int proto, void *logctx)