1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-10-06 05:47:18 +02:00

avformat/libsrt: use ff_parse_opts_from_query_string() to set URL parameters

Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
Marton Balint
2025-08-25 01:50:13 +02:00
parent 70e0e3e257
commit 2d06ed9308
2 changed files with 8 additions and 149 deletions

View File

@@ -1554,18 +1554,13 @@ srt://@var{hostname}:@var{port}[?@var{options}]
@end example @end example
@var{options} contains a list of &-separated options of the form @var{options} contains a list of &-separated options of the form
@var{key}=@var{val}. @var{key}=@var{val}. Standard percent-encoding (and using the plus sign for
space) can be used to escape keys and values.
or Options can also can be specified via command line options (or in code via
@code{AVOption}s).
@example The list of supported options follows.
@var{options} srt://@var{hostname}:@var{port}
@end example
@var{options} contains a list of '-@var{key} @var{val}'
options.
This protocol accepts the following options.
@table @option @table @option
@item connect_timeout=@var{milliseconds} @item connect_timeout=@var{milliseconds}

View File

@@ -386,8 +386,6 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
struct addrinfo hints = { 0 }, *ai, *cur_ai; struct addrinfo hints = { 0 }, *ai, *cur_ai;
int port, fd; int port, fd;
SRTContext *s = h->priv_data; SRTContext *s = h->priv_data;
const char *p;
char buf[256];
int ret; int ret;
char hostname[1024],proto[1024],path[1024]; char hostname[1024],proto[1024],path[1024];
char portstr[10]; char portstr[10];
@@ -402,15 +400,6 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
av_log(h, AV_LOG_ERROR, "Port missing in uri\n"); av_log(h, AV_LOG_ERROR, "Port missing in uri\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
p = strchr(uri, '?');
if (p) {
if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
s->rw_timeout = strtoll(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) {
s->listen_timeout = strtoll(buf, NULL, 10);
}
}
if (s->rw_timeout >= 0) { if (s->rw_timeout >= 0) {
open_timeout = h->rw_timeout = s->rw_timeout; open_timeout = h->rw_timeout = s->rw_timeout;
} }
@@ -534,7 +523,6 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
{ {
SRTContext *s = h->priv_data; SRTContext *s = h->priv_data;
const char * p; const char * p;
char buf[1024];
int ret = 0; int ret = 0;
if (srt_startup() < 0) { if (srt_startup() < 0) {
@@ -544,133 +532,9 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
/* SRT options (srt/srt.h) */ /* SRT options (srt/srt.h) */
p = strchr(uri, '?'); p = strchr(uri, '?');
if (p) { if (p) {
if (av_find_info_tag(buf, sizeof(buf), "maxbw", p)) { ret = ff_parse_opts_from_query_string(s, p, 0);
s->maxbw = strtoll(buf, NULL, 10); if (ret < 0)
} goto err;
if (av_find_info_tag(buf, sizeof(buf), "pbkeylen", p)) {
s->pbkeylen = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "passphrase", p)) {
av_freep(&s->passphrase);
s->passphrase = ff_urldecode(buf, 1);
if (!s->passphrase) {
ret = AVERROR(ENOMEM);
goto err;
}
}
#if SRT_VERSION_VALUE >= 0x010302
if (av_find_info_tag(buf, sizeof(buf), "enforced_encryption", p)) {
s->enforced_encryption = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "kmrefreshrate", p)) {
s->kmrefreshrate = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "kmpreannounce", p)) {
s->kmpreannounce = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "snddropdelay", p)) {
s->snddropdelay = strtoll(buf, NULL, 10);
}
#endif
if (av_find_info_tag(buf, sizeof(buf), "mss", p)) {
s->mss = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "ffs", p)) {
s->ffs = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "ipttl", p)) {
s->ipttl = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "iptos", p)) {
s->iptos = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "inputbw", p)) {
s->inputbw = strtoll(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "oheadbw", p)) {
s->oheadbw = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "latency", p)) {
s->latency = strtoll(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "tsbpddelay", p)) {
s->latency = strtoll(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "rcvlatency", p)) {
s->rcvlatency = strtoll(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "peerlatency", p)) {
s->peerlatency = strtoll(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "tlpktdrop", p)) {
s->tlpktdrop = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "nakreport", p)) {
s->nakreport = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "connect_timeout", p)) {
s->connect_timeout = strtoll(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "payload_size", p) ||
av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
s->payload_size = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "mode", p)) {
if (!strcmp(buf, "caller")) {
s->mode = SRT_MODE_CALLER;
} else if (!strcmp(buf, "listener")) {
s->mode = SRT_MODE_LISTENER;
} else if (!strcmp(buf, "rendezvous")) {
s->mode = SRT_MODE_RENDEZVOUS;
} else {
ret = AVERROR(EINVAL);
goto err;
}
}
if (av_find_info_tag(buf, sizeof(buf), "sndbuf", p)) {
s->sndbuf = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "rcvbuf", p)) {
s->rcvbuf = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "lossmaxttl", p)) {
s->lossmaxttl = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "minversion", p)) {
s->minversion = strtol(buf, NULL, 0);
}
if (av_find_info_tag(buf, sizeof(buf), "streamid", p)) {
av_freep(&s->streamid);
s->streamid = ff_urldecode(buf, 1);
if (!s->streamid) {
ret = AVERROR(ENOMEM);
goto err;
}
}
if (av_find_info_tag(buf, sizeof(buf), "smoother", p)) {
av_freep(&s->smoother);
s->smoother = ff_urldecode(buf, 1);
if(!s->smoother) {
ret = AVERROR(ENOMEM);
goto err;
}
}
if (av_find_info_tag(buf, sizeof(buf), "messageapi", p)) {
s->messageapi = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "transtype", p)) {
if (!strcmp(buf, "live")) {
s->transtype = SRTT_LIVE;
} else if (!strcmp(buf, "file")) {
s->transtype = SRTT_FILE;
} else {
ret = AVERROR(EINVAL);
goto err;
}
}
if (av_find_info_tag(buf, sizeof(buf), "linger", p)) {
s->linger = strtol(buf, NULL, 10);
}
} }
ret = libsrt_setup(h, uri, flags); ret = libsrt_setup(h, uri, flags);
if (ret < 0) if (ret < 0)