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

avformat/tcp: 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:52:00 +02:00
parent 7e58fff9d0
commit 49c6e6cc44
2 changed files with 9 additions and 33 deletions

View File

@@ -1913,7 +1913,11 @@ tcp://@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.
Options can also can be specified via command line options (or in code via
@code{AVOption}s).
The list of supported options follows. The list of supported options follows.

View File

@@ -25,6 +25,7 @@
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "libavutil/time.h" #include "libavutil/time.h"
#include "internal.h"
#include "network.h" #include "network.h"
#include "os_support.h" #include "os_support.h"
#include "url.h" #include "url.h"
@@ -151,7 +152,6 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
int port, fd = -1; int port, fd = -1;
TCPContext *s = h->priv_data; TCPContext *s = h->priv_data;
const char *p; 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];
@@ -167,37 +167,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
} }
p = strchr(uri, '?'); p = strchr(uri, '?');
if (p) { if (p) {
if (av_find_info_tag(buf, sizeof(buf), "listen", p)) { int ret = ff_parse_opts_from_query_string(s, p, 1);
char *endptr = NULL; if (ret < 0)
s->listen = strtol(buf, &endptr, 10); return ret;
/* assume if no digits were found it is a request to enable it */
if (buf == endptr)
s->listen = 1;
}
if (av_find_info_tag(buf, sizeof(buf), "local_port", p)) {
av_freep(&s->local_port);
s->local_port = av_strdup(buf);
if (!s->local_port)
return AVERROR(ENOMEM);
}
if (av_find_info_tag(buf, sizeof(buf), "local_addr", p)) {
av_freep(&s->local_addr);
s->local_addr = av_strdup(buf);
if (!s->local_addr)
return AVERROR(ENOMEM);
}
if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
s->rw_timeout = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) {
s->listen_timeout = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "tcp_nodelay", p)) {
s->tcp_nodelay = strtol(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "tcp_keepalive", p)) {
s->tcp_keepalive = strtol(buf, NULL, 10);
}
} }
if (s->rw_timeout >= 0) { if (s->rw_timeout >= 0) {
s->open_timeout = s->open_timeout =