avformat/aviobuf: ffio_copy_url_options

Signed-off-by: Pierre-Anthony Lemieux <pal@palemieux.com>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
This commit is contained in:
Pierre-Anthony Lemieux 2021-12-14 16:35:14 -08:00 committed by Zane van Iperen
parent a8a7c5d502
commit c8b5f2848d
No known key found for this signature in database
GPG Key ID: 68616B2D8AC4DCC5
4 changed files with 32 additions and 49 deletions

View File

@ -206,6 +206,12 @@ int ffio_fdopen(AVIOContext **s, URLContext *h);
*/
URLContext *ffio_geturlcontext(AVIOContext *s);
/**
* Read url related dictionary options from the AVIOContext and write to the given dictionary
*/
int ffio_copy_url_options(AVIOContext* pb, AVDictionary** avio_opts);
/**
* Open a write-only fake memory stream. The written data is not stored
* anywhere - this is only used for measuring the amount of data

View File

@ -1020,6 +1020,30 @@ URLContext* ffio_geturlcontext(AVIOContext *s)
return NULL;
}
int ffio_copy_url_options(AVIOContext* pb, AVDictionary** avio_opts)
{
const char *opts[] = {
"headers", "user_agent", "cookies", "http_proxy", "referer", "rw_timeout", "icy", NULL };
const char **opt = opts;
uint8_t *buf = NULL;
int ret = 0;
while (*opt) {
if (av_opt_get(pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
if (buf[0] != '\0') {
ret = av_dict_set(avio_opts, *opt, buf, AV_DICT_DONT_STRDUP_VAL);
if (ret < 0)
return ret;
} else {
av_freep(&buf);
}
}
opt++;
}
return ret;
}
static void update_checksum(AVIOContext *s)
{
if (s->update_checksum && s->buf_ptr > s->checksum_ptr) {

View File

@ -1833,31 +1833,6 @@ end:
return ret;
}
static int save_avio_options(AVFormatContext *s)
{
DASHContext *c = s->priv_data;
const char *opts[] = {
"headers", "user_agent", "cookies", "http_proxy", "referer", "rw_timeout", "icy", NULL };
const char **opt = opts;
uint8_t *buf = NULL;
int ret = 0;
while (*opt) {
if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
if (buf[0] != '\0') {
ret = av_dict_set(&c->avio_opts, *opt, buf, AV_DICT_DONT_STRDUP_VAL);
if (ret < 0)
return ret;
} else {
av_freep(&buf);
}
}
opt++;
}
return ret;
}
static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url,
int flags, AVDictionary **opts)
{
@ -2057,7 +2032,7 @@ static int dash_read_header(AVFormatContext *s)
c->interrupt_callback = &s->interrupt_callback;
if ((ret = save_avio_options(s)) < 0)
if ((ret = ffio_copy_url_options(s->pb, &c->avio_opts)) < 0)
return ret;
if ((ret = parse_manifest(s, s->url, s->pb)) < 0)

View File

@ -1717,28 +1717,6 @@ static int64_t select_cur_seq_no(HLSContext *c, struct playlist *pls)
return pls->start_seq_no;
}
static int save_avio_options(AVFormatContext *s)
{
HLSContext *c = s->priv_data;
static const char * const opts[] = {
"headers", "http_proxy", "user_agent", "cookies", "referer", "rw_timeout", "icy", NULL };
const char * const * opt = opts;
uint8_t *buf;
int ret = 0;
while (*opt) {
if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN | AV_OPT_ALLOW_NULL, &buf) >= 0) {
ret = av_dict_set(&c->avio_opts, *opt, buf,
AV_DICT_DONT_STRDUP_VAL);
if (ret < 0)
return ret;
}
opt++;
}
return ret;
}
static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url,
int flags, AVDictionary **opts)
{
@ -1884,7 +1862,7 @@ static int hls_read_header(AVFormatContext *s)
c->first_timestamp = AV_NOPTS_VALUE;
c->cur_timestamp = AV_NOPTS_VALUE;
if ((ret = save_avio_options(s)) < 0)
if ((ret = ffio_copy_url_options(s->pb, &c->avio_opts)) < 0)
return ret;
/* XXX: Some HLS servers don't like being sent the range header,