38 #ifndef SRT_LIVE_DEFAULT_PAYLOAD_SIZE
39 #define SRT_LIVE_DEFAULT_PAYLOAD_SIZE 1316
43 #ifndef SRT_LIVE_MAX_PAYLOAD_SIZE
44 #define SRT_LIVE_MAX_PAYLOAD_SIZE 1456
89 #define D AV_OPT_FLAG_DECODING_PARAM
90 #define E AV_OPT_FLAG_ENCODING_PARAM
91 #define OFFSET(x) offsetof(SRTContext, x)
93 {
"rw_timeout",
"Timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags =
D|
E },
94 {
"listen_timeout",
"Connection awaiting timeout",
OFFSET(listen_timeout),
AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags =
D|
E },
95 {
"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 },
96 {
"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 },
101 {
"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 },
102 {
"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 },
103 {
"passphrase",
"Crypto PBKDF2 Passphrase size[0,10..64] 0:disable crypto",
OFFSET(passphrase),
AV_OPT_TYPE_STRING, { .str =
NULL }, .flags =
D|
E },
105 {
"ffs",
"Flight flag size (window size) (in bytes)",
OFFSET(ffs),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
108 {
"inputbw",
"Estimated input stream rate",
OFFSET(inputbw),
AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags =
D|
E },
109 {
"oheadbw",
"MaxBW ceiling based on % over input stream rate",
OFFSET(oheadbw),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 100, .flags =
D|
E },
110 {
"latency",
"receiver delay to absorb bursts of missed packet retransmissions",
OFFSET(latency),
AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags =
D|
E },
111 {
"tsbpddelay",
"deprecated, same effect as latency option",
OFFSET(latency),
AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags =
D|
E },
114 {
"tlpktdrop",
"Enable receiver pkt drop",
OFFSET(tlpktdrop),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, .flags =
D|
E },
115 {
"nakreport",
"Enable receiver to send periodic NAK reports",
OFFSET(nakreport),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, .flags =
D|
E },
116 {
"connect_timeout",
"Connect timeout. Caller default: 3000, rendezvous (x 10)",
OFFSET(connect_timeout),
AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags =
D|
E },
117 {
"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" },
121 {
"sndbuf",
"Send buffer size (in bytes)",
OFFSET(sndbuf),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
122 {
"rcvbuf",
"Receive buffer size (in bytes)",
OFFSET(rcvbuf),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
123 {
"lossmaxttl",
"Maximum possible packet reorder tolerance",
OFFSET(lossmaxttl),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
124 {
"minversion",
"The minimum SRT version that is required from the peer",
OFFSET(minversion),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
125 {
"streamid",
"A string of up to 512 characters that an Initiator can pass to a Responder",
OFFSET(streamid),
AV_OPT_TYPE_STRING, { .str =
NULL }, .flags =
D|
E },
126 {
"smoother",
"The type of Smoother used for the transmission for that socket",
OFFSET(smoother),
AV_OPT_TYPE_STRING, { .str =
NULL }, .flags =
D|
E },
127 {
"messageapi",
"Enable message API",
OFFSET(messageapi),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, .flags =
D|
E },
128 {
"transtype",
"The transmission type for the socket",
OFFSET(transtype),
AV_OPT_TYPE_INT, { .i64 = SRTT_INVALID }, SRTT_LIVE, SRTT_INVALID, .flags =
D|
E,
"transtype" },
136 int err = srt_getlasterror(
NULL);
138 if (err == SRT_EASYNCRCV)
145 int ret = srt_setsockopt(socket, 0, SRTO_SNDSYN, &enable,
sizeof(enable));
148 return srt_setsockopt(socket, 0, SRTO_RCVSYN, &enable,
sizeof(enable));
154 int modes = write ? SRT_EPOLL_OUT : SRT_EPOLL_IN;
157 if (srt_epoll_add_usock(eid, fd, &modes) < 0)
160 ret = srt_epoll_wait(eid, 0, 0, ready, &len,
POLLING_TIME, 0, 0, 0, 0);
162 ret = srt_epoll_wait(eid, ready, &len, 0, 0,
POLLING_TIME, 0, 0, 0, 0);
165 if (srt_getlasterror(
NULL) == SRT_ETIMEOUT)
172 if (srt_epoll_remove_usock(eid, fd) < 0)
182 int64_t wait_start = 0;
203 if (srt_setsockopt(fd, SOL_SOCKET, SRTO_REUSEADDR, &reuse,
sizeof(reuse))) {
206 ret = srt_bind(fd, addr, addrlen);
210 ret = srt_listen(fd, 1);
239 while ((ret = srt_connect(fd, addr, addrlen))) {
251 ret = srt_getlasterror(
NULL);
252 srt_clearlasterror();
259 "Connection to %s failed (%s), trying next address\n",
274 if (srt_setsockopt(fd, 0, optname, optval, optlen) < 0) {
275 av_log(h,
AV_LOG_ERROR,
"failed to set option %s on socket: %s\n", optnamestr, srt_getlasterror_str());
283 if (srt_getsockopt(fd, 0, optname, optval, optlen) < 0) {
284 av_log(h,
AV_LOG_ERROR,
"failed to get option %s on socket: %s\n", optnamestr, srt_getlasterror_str());
312 int latency = s->
latency / 1000;
331 (connect_timeout >= 0 &&
libsrt_setsockopt(h, fd, SRTO_CONNTIMEO,
"SRTO_CONNTIMEO", &connect_timeout,
sizeof(connect_timeout)) <0 ) ||
348 struct addrinfo hints = { 0 }, *ai, *cur_ai;
354 char hostname[1024],proto[1024],path[1024];
356 int open_timeout = 5000000;
359 eid = srt_epoll_create();
365 &port, path,
sizeof(path), uri);
366 if (strcmp(proto,
"srt"))
368 if (port <= 0 || port >= 65536) {
372 p = strchr(uri,
'?');
386 snprintf(portstr,
sizeof(portstr),
"%d", port);
389 ret =
getaddrinfo(hostname[0] ? hostname :
NULL, portstr, &hints, &ai);
392 "Failed to resolve hostname %s: %s\n",
401 fd = srt_socket(cur_ai->ai_family, cur_ai->ai_socktype, 0);
421 if ((ret =
libsrt_listen(s->
eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, open_timeout / 1000)) < 0)
426 ret = srt_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
432 open_timeout / 1000, h, !!cur_ai->ai_next)) < 0) {
445 int optlen =
sizeof(packet_size);
446 ret =
libsrt_getsockopt(h, fd, SRTO_PAYLOADSIZE,
"SRTO_PAYLOADSIZE", &packet_size, &optlen);
460 if (cur_ai->ai_next) {
462 cur_ai = cur_ai->ai_next;
481 if (srt_startup() < 0) {
486 p = strchr(uri,
'?');
498 s->
mss = strtol(buf,
NULL, 10);
501 s->
ffs = strtol(buf,
NULL, 10);
541 if (!strcmp(buf,
"caller")) {
543 }
else if (!strcmp(buf,
"listener")) {
545 }
else if (!strcmp(buf,
"rendezvous")) {
575 if (!strcmp(buf,
"live")) {
577 }
else if (!strcmp(buf,
"file")) {
598 ret = srt_recvmsg(s->
fd, buf, size);
617 ret = srt_sendmsg(s->
fd, buf, size, -1, 0);
631 srt_epoll_release(s->
eid);
660 .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
#define AVIO_FLAG_WRITE
write-only
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.
static int libsrt_getsockopt(URLContext *h, int fd, SRT_SOCKOPT optname, const char *optnamestr, void *optval, int *optlen)
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)
#define SRT_LIVE_MAX_PAYLOAD_SIZE
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)
#define SRT_LIVE_DEFAULT_PAYLOAD_SIZE
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[]
char * av_strdup(const char *s)
Duplicate a string.
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.
#define flags(name, subs,...)
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)
int max_packet_size
if non zero, the stream is packetized with this max packet size
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)