avio: Copy URLContext generic options into child URLContexts

Since all URLContexts have the same AVOptions, such AVOptions
will be applied on the outermost context only and removed from the
dict, while they probably make sense on all contexts.

This makes sure that rw_timeout gets propagated to the innermost
URLContext (to make sure it gets passed to the tcp protocol, when
opening a http connection for instance).

Alternatively, such matching options would be kept in the dict
and only removed after the ffurl_connect call.

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Martin Storsjö 2015-02-28 02:00:50 +02:00
parent 564b4591bb
commit fab8156b2f
21 changed files with 37 additions and 32 deletions

View File

@ -174,11 +174,14 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags,
int ffurl_open(URLContext **puc, const char *filename, int flags,
const AVIOInterruptCB *int_cb, AVDictionary **options,
const URLProtocol **protocols)
const URLProtocol **protocols,
URLContext *parent)
{
int ret = ffurl_alloc(puc, filename, flags, int_cb, protocols);
if (ret)
return ret;
if (parent)
av_opt_copy(*puc, parent);
if (options &&
(ret = av_opt_set_dict(*puc, options)) < 0)
goto fail;

View File

@ -905,7 +905,7 @@ int avio_open2(AVIOContext **s, const char *filename, int flags,
if (!protocols)
return AVERROR(ENOMEM);
err = ffurl_open(&h, filename, flags, int_cb, options, protocols);
err = ffurl_open(&h, filename, flags, int_cb, options, protocols, NULL);
if (err < 0) {
av_freep(&protocols);
return err;

View File

@ -95,7 +95,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags)
/* creating URLContext */
if ((err = ffurl_open(&uc, node_uri, flags,
&h->interrupt_callback, NULL, h->protocols)) < 0)
&h->interrupt_callback, NULL, h->protocols, h)) < 0)
break;
/* creating size */

View File

@ -83,7 +83,7 @@ static int crypto_open(URLContext *h, const char *uri, int flags)
goto err;
}
if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ,
&h->interrupt_callback, NULL, h->protocols)) < 0) {
&h->interrupt_callback, NULL, h->protocols, h)) < 0) {
av_log(h, AV_LOG_ERROR, "Unable to open input\n");
goto err;
}

View File

@ -94,7 +94,7 @@ static int gopher_open(URLContext *h, const char *uri, int flags)
s->hd = NULL;
err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, NULL, h->protocols);
&h->interrupt_callback, NULL, h->protocols, h);
if (err < 0)
goto fail;

View File

@ -304,7 +304,7 @@ retry:
url = s->segments[s->cur_seq_no - s->start_seq_no]->url,
av_log(h, AV_LOG_DEBUG, "opening %s\n", url);
ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ,
&h->interrupt_callback, NULL, h->protocols);
&h->interrupt_callback, NULL, h->protocols, h);
if (ret < 0) {
if (ff_check_interrupt(&h->interrupt_callback))
return AVERROR_EXIT;

View File

@ -181,7 +181,7 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options)
if (!s->hd) {
err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, options, h->protocols);
&h->interrupt_callback, options, h->protocols, h);
if (err < 0)
return err;
}
@ -1079,7 +1079,7 @@ static int http_proxy_open(URLContext *h, const char *uri, int flags)
NULL);
redo:
ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, NULL, h->protocols);
&h->interrupt_callback, NULL, h->protocols, h);
if (ret < 0)
return ret;

View File

@ -177,7 +177,7 @@ static int icecast_open(URLContext *h, const char *uri, int flags)
ff_url_join(h_url, sizeof(h_url), "http", auth, host, port, "%s", path);
// Finally open http proto handler
ret = ffurl_open(&s->hd, h_url, AVIO_FLAG_READ_WRITE, NULL, &opt_dict,
h->protocols);
h->protocols, h);
cleanup:
// Free variables

View File

@ -71,7 +71,7 @@ static int md5_close(URLContext *h)
if (*filename) {
err = ffurl_open(&out, filename, AVIO_FLAG_WRITE,
&h->interrupt_callback, NULL,
h->protocols);
h->protocols, h);
if (err)
return err;
err = ffurl_write(out, buf, i*2+1);

View File

@ -520,7 +520,7 @@ static int mms_open(URLContext *h, const char *uri, int flags)
// establish tcp connection.
ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL);
err = ffurl_open(&mms->mms_hd, tcpname, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, NULL, h->protocols);
&h->interrupt_callback, NULL, h->protocols, h);
if (err)
goto fail;

View File

@ -265,7 +265,7 @@ static int rtmpe_open(URLContext *h, const char *uri, int flags)
/* open the tcp or ffrtmphttp connection */
if ((ret = ffurl_open(&rt->stream, url, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, NULL, h->protocols)) < 0) {
&h->interrupt_callback, NULL, h->protocols, h)) < 0) {
rtmpe_close(h);
return ret;
}

View File

@ -1119,7 +1119,7 @@ static int rtmp_calc_swfhash(URLContext *s)
/* Get the SWF player file. */
if ((ret = ffurl_open(&stream, rt->swfverify, AVIO_FLAG_READ,
&s->interrupt_callback, NULL, s->protocols)) < 0) {
&s->interrupt_callback, NULL, s->protocols, s)) < 0) {
av_log(s, AV_LOG_ERROR, "Cannot open connection %s.\n", rt->swfverify);
goto fail;
}
@ -2641,7 +2641,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
reconnect:
if ((ret = ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, &opts, s->protocols)) < 0) {
&s->interrupt_callback, &opts, s->protocols, s)) < 0) {
av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf);
goto fail;
}

View File

@ -369,7 +369,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
build_udp_url(s, buf, sizeof(buf),
hostname, rtp_port, s->local_rtpport, sources, block);
if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL,
h->protocols) < 0)
h->protocols, h) < 0)
goto fail;
if (s->local_rtpport >= 0 && s->local_rtcpport < 0)
s->local_rtcpport = ff_udp_get_local_port(s->rtp_hd) + 1;
@ -377,7 +377,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
build_udp_url(s, buf, sizeof(buf),
hostname, s->rtcp_port, s->local_rtcpport, sources, block);
if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL,
h->protocols) < 0)
h->protocols, h) < 0)
goto fail;
/* just to ease handle access. XXX: need to suppress direct handle

View File

@ -1466,7 +1466,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
/* we will use two ports per rtp stream (rtp and rtcp) */
j += 2;
err = ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, &opts, rt->protocols);
&s->interrupt_callback, &opts, rt->protocols, NULL);
av_dict_free(&opts);
@ -1610,7 +1610,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,
port, "%s", optbuf);
if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, NULL, rt->protocols) < 0) {
&s->interrupt_callback, NULL, rt->protocols, NULL) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
@ -1804,7 +1804,7 @@ redirect:
ff_url_join(tcpname, sizeof(tcpname), lower_rtsp_proto, NULL,
host, port, NULL);
if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, NULL, rt->protocols) < 0) {
&s->interrupt_callback, NULL, rt->protocols, NULL) < 0) {
err = AVERROR(EIO);
goto fail;
}
@ -2311,7 +2311,7 @@ static int sdp_read_header(AVFormatContext *s)
rtsp_st->nb_exclude_source_addrs,
rtsp_st->exclude_source_addrs);
err = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, &opts, rt->protocols);
&s->interrupt_callback, &opts, rt->protocols, NULL);
av_dict_free(&opts);
@ -2388,7 +2388,7 @@ static int rtp_read_header(AVFormatContext *s)
}
ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ,
&s->interrupt_callback, NULL, rt->protocols);
&s->interrupt_callback, NULL, rt->protocols, NULL);
if (ret)
goto fail;

View File

@ -295,7 +295,7 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl)
ff_url_join(url, sizeof(url), "rtp", NULL, host, localport, NULL);
av_log(s, AV_LOG_TRACE, "Opening: %s", url);
ret = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, &opts, rt->protocols);
&s->interrupt_callback, &opts, rt->protocols, NULL);
av_dict_free(&opts);
if (ret)
localport += 2;
@ -667,7 +667,7 @@ static int rtsp_listen(AVFormatContext *s)
"?listen&listen_timeout=%d", rt->initial_timeout * 1000);
if (ret = ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, NULL, rt->protocols)) {
&s->interrupt_callback, NULL, rt->protocols, NULL)) {
av_log(s, AV_LOG_ERROR, "Unable to open RTSP for listening\n");
return ret;
}

View File

@ -95,7 +95,7 @@ static int sap_read_header(AVFormatContext *s)
ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",
port);
ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_READ,
&s->interrupt_callback, NULL, sap->protocols);
&s->interrupt_callback, NULL, sap->protocols, NULL);
if (ret)
goto fail;

View File

@ -160,7 +160,7 @@ static int sap_write_header(AVFormatContext *s)
if (!same_port)
base_port += 2;
ret = ffurl_open(&fd, url, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL,
sap->protocols);
sap->protocols, NULL);
if (ret) {
ret = AVERROR(EIO);
goto fail;
@ -179,7 +179,7 @@ static int sap_write_header(AVFormatContext *s)
ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port,
"?ttl=%d&connect=1", ttl);
ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL, sap->protocols);
&s->interrupt_callback, NULL, sap->protocols, NULL);
if (ret) {
ret = AVERROR(EIO);
goto fail;

View File

@ -126,7 +126,7 @@ static int64_t ism_seek(void *opaque, int64_t offset, int whence)
os->tail_out = os->out;
av_dict_set(&opts, "truncate", "0", 0);
ret = ffurl_open(&os->out, frag->file, AVIO_FLAG_WRITE, &os->ctx->interrupt_callback, &opts,
os->protocols);
os->protocols, NULL);
av_dict_free(&opts);
if (ret < 0) {
os->out = os->tail_out;
@ -135,7 +135,7 @@ static int64_t ism_seek(void *opaque, int64_t offset, int whence)
}
av_dict_set(&opts, "truncate", "0", 0);
ffurl_open(&os->out2, frag->infofile, AVIO_FLAG_WRITE, &os->ctx->interrupt_callback, &opts,
os->protocols);
os->protocols, NULL);
av_dict_free(&opts);
ffurl_seek(os->out, offset - frag->start_pos, SEEK_SET);
if (os->out2)
@ -541,7 +541,7 @@ static int ism_flush(AVFormatContext *s, int final)
snprintf(filename, sizeof(filename), "%s/temp", os->dirname);
ret = ffurl_open(&os->out, filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL,
c->protocols);
c->protocols, NULL);
if (ret < 0)
break;
os->cur_start_pos = os->tail_pos;

View File

@ -81,7 +81,7 @@ static int srtp_open(URLContext *h, const char *uri, int flags)
path, sizeof(path), uri);
ff_url_join(buf, sizeof(buf), "rtp", NULL, hostname, rtp_port, "%s", path);
if ((ret = ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL,
h->protocols)) < 0)
h->protocols, h)) < 0)
goto fail;
h->max_packet_size = FFMIN(s->rtp_hd->max_packet_size,

View File

@ -76,5 +76,5 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV
}
return ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE,
&parent->interrupt_callback, options, parent->protocols);
&parent->interrupt_callback, options, parent->protocols, parent);
}

View File

@ -137,12 +137,14 @@ int ffurl_connect(URLContext *uc, AVDictionary **options);
* @param protocols a NULL-terminate list of protocols available for use by
* this context and its children. The caller must ensure this
* list remains valid until the context is closed.
* @param parent An enclosing URLContext, whose generic options should
* be applied to this URLContext as well.
* @return 0 in case of success, a negative value corresponding to an
* AVERROR code in case of failure
*/
int ffurl_open(URLContext **puc, const char *filename, int flags,
const AVIOInterruptCB *int_cb, AVDictionary **options,
const URLProtocol **protocols);
const URLProtocol **protocols, URLContext *parent);
/**
* Read up to size bytes from the resource accessed by h, and store