68 #define D AV_OPT_FLAG_DECODING_PARAM 69 #define E AV_OPT_FLAG_ENCODING_PARAM 70 #define OFFSET(x) offsetof(SRTContext, x) 76 {
"maxbw",
"Maximum bandwidth (bytes per second) that the connection can use",
OFFSET(
maxbw),
AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags =
D|
E },
77 {
"pbkeylen",
"Crypto key len in bytes {16,24,32} Default: 16 (128-bit)",
OFFSET(
pbkeylen),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 32, .flags =
D|
E },
80 {
"ffs",
"Flight flag size (window size) (in bytes)",
OFFSET(
ffs),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
85 {
"tsbpddelay",
"TsbPd receiver delay to absorb burst of missed packet retransmission",
OFFSET(
tsbpddelay),
AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags =
D|
E },
89 {
"mode",
"Connection mode (caller, listener, rendezvous)",
OFFSET(
mode),
AV_OPT_TYPE_INT, { .i64 =
SRT_MODE_CALLER },
SRT_MODE_CALLER,
SRT_MODE_RENDEZVOUS, .flags =
D|
E,
"mode" },
98 int err = srt_getlasterror(
NULL);
100 if (err == SRT_EASYNCRCV)
107 int ret = srt_setsockopt(socket, 0, SRTO_SNDSYN, &enable,
sizeof(enable));
110 return srt_setsockopt(socket, 0, SRTO_RCVSYN, &enable,
sizeof(enable));
116 int modes = write ? SRT_EPOLL_OUT : SRT_EPOLL_IN;
119 if (srt_epoll_add_usock(eid, fd, &modes) < 0)
122 ret = srt_epoll_wait(eid, 0, 0, ready, &len,
POLLING_TIME, 0, 0, 0, 0);
124 ret = srt_epoll_wait(eid, ready, &len, 0, 0,
POLLING_TIME, 0, 0, 0, 0);
127 if (srt_getlasterror(
NULL) == SRT_ETIMEOUT)
134 if (srt_epoll_remove_usock(eid, fd) < 0)
144 int64_t wait_start = 0;
165 if (srt_setsockopt(fd, SOL_SOCKET, SRTO_REUSEADDR, &reuse,
sizeof(reuse))) {
168 ret = srt_bind(fd, addr, addrlen);
172 ret = srt_listen(fd, 1);
201 while ((ret = srt_connect(fd, addr, addrlen))) {
213 ret = srt_getlasterror(
NULL);
214 srt_clearlasterror();
221 "Connection to %s failed (%s), trying next address\n",
236 if (srt_setsockopt(fd, 0, optname, optval, optlen) < 0) {
237 av_log(h,
AV_LOG_ERROR,
"failed to set option %s on socket: %s\n", optnamestr, srt_getlasterror_str());
276 (tsbpddelay >= 0 &&
libsrt_setsockopt(h, fd, SRTO_TSBPDDELAY,
"SRTO_TSBPDELAY", &tsbpddelay,
sizeof(tsbpddelay)) < 0) ||
279 (connect_timeout >= 0 &&
libsrt_setsockopt(h, fd, SRTO_CONNTIMEO,
"SRTO_CONNTIMEO", &connect_timeout,
sizeof(connect_timeout)) <0 )) {
288 struct addrinfo hints = { 0 }, *ai, *cur_ai;
294 char hostname[1024],proto[1024],path[1024];
296 int open_timeout = 5000000;
299 eid = srt_epoll_create();
305 &port, path,
sizeof(path), uri);
306 if (strcmp(proto,
"srt"))
308 if (port <= 0 || port >= 65536) {
312 p = strchr(uri,
'?');
326 snprintf(portstr,
sizeof(portstr),
"%d", port);
329 ret =
getaddrinfo(hostname[0] ? hostname :
NULL, portstr, &hints, &ai);
332 "Failed to resolve hostname %s: %s\n",
341 fd = srt_socket(cur_ai->ai_family, cur_ai->ai_socktype, 0);
361 if ((ret =
libsrt_listen(s->
eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, open_timeout / 1000)) < 0)
366 ret = srt_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
372 open_timeout / 1000, h, !!cur_ai->ai_next)) < 0) {
390 if (cur_ai->ai_next) {
392 cur_ai = cur_ai->ai_next;
411 if (srt_startup() < 0) {
416 p = strchr(uri,
'?');
428 s->
mss = strtol(buf,
NULL, 10);
431 s->
ffs = strtol(buf,
NULL, 10);
458 if (!strcmp(buf,
"caller")) {
460 }
else if (!strcmp(buf,
"listener")) {
462 }
else if (!strcmp(buf,
"rendezvous")) {
483 ret = srt_recvmsg(s->
fd, buf, size);
502 ret = srt_sendmsg(s->
fd, buf, size, -1, 0);
516 srt_epoll_release(s->
eid);
545 .priv_data_class = &libsrt_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 libsrt_open(URLContext *h, const char *uri, int flags)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
int is_streamed
true if streamed (no seek possible), default = false
AVIOInterruptCB interrupt_callback
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t rw_timeout
maximum time to wait for (network) read/write operation completion, in mcs
static int libsrt_setsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char *optnamestr, const void *optval, int optlen)
static int libsrt_socket_nonblock(int socket, int enable)
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.
Callback for checking whether to abort blocking functions.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const AVClass libsrt_class
static int libsrt_setup(URLContext *h, const char *uri, int flags)
const AVIOInterruptCB int_cb
static int libsrt_listen(int eid, int fd, const struct sockaddr *addr, socklen_t addrlen, URLContext *h, int timeout)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int libsrt_set_options_post(URLContext *h, int fd)
simple assert() macros that are a bit more flexible than ISO C assert().
static int libsrt_network_wait_fd(URLContext *h, int eid, int fd, int write)
static int libsrt_read(URLContext *h, uint8_t *buf, int size)
static int libsrt_network_wait_fd_timeout(URLContext *h, int eid, int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb)
static int libsrt_get_file_handle(URLContext *h)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
static const AVOption libsrt_options[]
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
const URLProtocol ff_libsrt_protocol
Describe the class of an AVClass context structure.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
char * filename
specified URL
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static const SiprModeParam modes[MODE_COUNT]
static int libsrt_write(URLContext *h, const uint8_t *buf, int size)
static int libsrt_close(URLContext *h)
static int libsrt_listen_connect(int eid, int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h, int will_try_next)
unbuffered private I/O API
mode
Use these values in ebur128_init (or'ed).
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
static int libsrt_set_options_pre(URLContext *h, int fd)
static int libsrt_neterrno(URLContext *h)