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>
pull/235/head^2
Martin Storsjö 10 years ago
parent 564b4591bb
commit fab8156b2f
  1. 5
      libavformat/avio.c
  2. 2
      libavformat/aviobuf.c
  3. 2
      libavformat/concat.c
  4. 2
      libavformat/crypto.c
  5. 2
      libavformat/gopher.c
  6. 2
      libavformat/hlsproto.c
  7. 4
      libavformat/http.c
  8. 2
      libavformat/icecast.c
  9. 2
      libavformat/md5proto.c
  10. 2
      libavformat/mmst.c
  11. 2
      libavformat/rtmpcrypt.c
  12. 4
      libavformat/rtmpproto.c
  13. 4
      libavformat/rtpproto.c
  14. 10
      libavformat/rtsp.c
  15. 4
      libavformat/rtspdec.c
  16. 2
      libavformat/sapdec.c
  17. 4
      libavformat/sapenc.c
  18. 6
      libavformat/smoothstreamingenc.c
  19. 2
      libavformat/srtpproto.c
  20. 2
      libavformat/tls.c
  21. 4
      libavformat/url.h

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

@ -905,7 +905,7 @@ int avio_open2(AVIOContext **s, const char *filename, int flags,
if (!protocols) if (!protocols)
return AVERROR(ENOMEM); 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) { if (err < 0) {
av_freep(&protocols); av_freep(&protocols);
return err; return err;

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

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

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

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

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

@ -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); ff_url_join(h_url, sizeof(h_url), "http", auth, host, port, "%s", path);
// Finally open http proto handler // Finally open http proto handler
ret = ffurl_open(&s->hd, h_url, AVIO_FLAG_READ_WRITE, NULL, &opt_dict, ret = ffurl_open(&s->hd, h_url, AVIO_FLAG_READ_WRITE, NULL, &opt_dict,
h->protocols); h->protocols, h);
cleanup: cleanup:
// Free variables // Free variables

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

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

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

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

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

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

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

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

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

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

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

@ -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, return ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE,
&parent->interrupt_callback, options, parent->protocols); &parent->interrupt_callback, options, parent->protocols, parent);
} }

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

Loading…
Cancel
Save