22 #include "libavutil/parseutils.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/time.h"
42 #define OFFSET(x) offsetof(TCPContext, x)
43 #define D AV_OPT_FLAG_DECODING_PARAM
44 #define E AV_OPT_FLAG_ENCODING_PARAM
47 {
"timeout",
"timeout of socket i/o operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
48 {
"listen_timeout",
"connection awaiting timeout",
OFFSET(listen_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
62 struct addrinfo hints = { 0 }, *ai, *cur_ai;
68 char hostname[1024],proto[1024],path[1024];
72 av_url_split(proto,
sizeof(proto), NULL, 0, hostname,
sizeof(hostname),
73 &port, path,
sizeof(path), uri);
74 if (strcmp(proto,
"tcp"))
76 if (port <= 0 || port >= 65536) {
97 snprintf(portstr,
sizeof(portstr),
"%d", port);
106 "Failed to resolve hostname %s: %s\n",
116 cur_ai->ai_protocol);
145 if (cur_ai->ai_next) {
147 cur_ai = cur_ai->ai_next;
170 ret = recv(s->
fd, buf, size, 0);
184 ret = send(s->
fd, buf, size, 0);
201 return shutdown(s->
fd, how);
226 .priv_data_class = &tcp_context_class,
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.
#define URL_PROTOCOL_FLAG_NETWORK
static int tcp_open(URLContext *h, const char *uri, int flags)
#define LIBAVUTIL_VERSION_INT
int is_streamed
true if streamed (no seek possible), default = false
AVIOInterruptCB interrupt_callback
int64_t rw_timeout
maximum time to wait for (network) read/write operation completion, in mcs
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
URLProtocol ff_tcp_protocol
int ff_socket(int af, int type, int proto)
static const AVClass tcp_context_class
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.
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
miscellaneous OS support macros and functions.
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.
int ff_listen_connect(int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h, int will_try_next)
Connect to a file descriptor and poll for result.
const OptionDef options[]
static int tcp_read(URLContext *h, uint8_t *buf, int size)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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 int tcp_close(URLContext *h)
static int tcp_shutdown(URLContext *h, int flags)
Describe the class of an AVClass context structure.
static int tcp_write(URLContext *h, const uint8_t *buf, int size)
unbuffered private I/O API
static int tcp_get_file_handle(URLContext *h)