From patchwork Thu May 4 15:14:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 41468 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp455649pzb; Thu, 4 May 2023 08:14:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ523bfKzneu3QzKQh8orlRdNnWZRID4Ln4sg/nTnMtWmz4yFcPu8wssKAlL5tsiN1/x8jQO X-Received: by 2002:a17:906:6a14:b0:953:7be7:91de with SMTP id qw20-20020a1709066a1400b009537be791demr7068347ejc.20.1683213293486; Thu, 04 May 2023 08:14:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683213293; cv=none; d=google.com; s=arc-20160816; b=jet1nLaEkleE8V1GV9Vn2FlhOXUqBAVaV7fzVzKCRzMJlRmPrpzNGaaYV+h8dHnMiD 43y82qjBV0zpEAUrKGIcfOqvT9CTRC3LcZO2LpB38jDaGq9OF6kbxDQEyxaYsyzX80rt 64z8s4epvm+hBy1Rg90y/Y+gYLP/t6SLd5oTQFbaKKEP9g+Lz392S4MSaVflx7rg9K0g 7XIRF4quN/U7HCw5uaOOLVMDsNTbz5rXTSAjJuUqjKWgmh0B7twPcK3s9wG53klO1xRA a5ic8X+Gc2L8d3iTjbd3GZGATL0yu6j//ls+gzNlu5D4vpU1ytB2uZlpdDgxkVHNaDPW 5S4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=cgG8mn8pjZKNs1gJZeOiWF4vveshzwMRFYwPLCTZ7A0=; b=nfWSZP8Wg4w/dnuF6pQ9fmmkhtTWmejGrOgVGC/0CFqfCQXtXMaWW/ZyGxI6Fd7i3X +mRVckxSWAWFu4L2yMeUivHAz5cyeA8IgRSHyIYPkTeZlaITwee0Dh4yNqeg1N2ngwPN H1HYIfaAdEvWlH6KaDGvB96UKiXpgrP+AURDz1+UY9ObhdUu7WkS1i27y2UlAYfCPDTu 3+KzApAGbj/XsxXdcL0bu6FcareZsgiJsS7guDZmOtEd672rMBWUfXJyuUpYGZhkIpSx V1GEv19hLw06hSz8animThlWJF13/F6xcB927RpbvpCmuzxyrfq3fz6xGAbjeiH0/tT4 2YKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a7-20020a1709065f8700b0096100aef745si9608843eju.979.2023.05.04.08.14.50; Thu, 04 May 2023 08:14:53 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A931E68C0C7; Thu, 4 May 2023 18:14:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 50F3A68BF34 for ; Thu, 4 May 2023 18:14:39 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 9D6BEC0014 for ; Thu, 4 May 2023 15:14:38 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 4 May 2023 17:14:37 +0200 Message-Id: <20230504151437.20070-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] libavformat: simplify ffurl_open_whitelist() by using parent contexts X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: SS0jb+Qtg9OJ This also simplifies passing more things from parent contexts in the future It also avoids bugs as the calls are simpler. In that sense this change adds a missing interrupt callback to icecast Signed-off-by: Michael Niedermayer --- libavformat/avio.c | 18 ++++++++++++++++++ libavformat/cache.c | 3 +-- libavformat/concat.c | 6 ++---- libavformat/crypto.c | 4 +--- libavformat/ftp.c | 9 +++------ libavformat/gopher.c | 3 +-- libavformat/hlsproto.c | 4 +--- libavformat/http.c | 16 ++++++---------- libavformat/icecast.c | 3 +-- libavformat/ipfsgateway.c | 5 +---- libavformat/md5proto.c | 4 +--- libavformat/mmst.c | 5 ++--- libavformat/prompeg.c | 6 ++---- libavformat/rtmpcrypt.c | 5 ++--- libavformat/rtmpproto.c | 9 +++------ libavformat/rtpproto.c | 13 ++++--------- libavformat/rtsp.c | 19 +++++++++---------- libavformat/rtspdec.c | 10 ++++------ libavformat/sapdec.c | 4 +--- libavformat/sapenc.c | 8 ++------ libavformat/smoothstreamingenc.c | 8 +++----- libavformat/srtpproto.c | 3 +-- libavformat/subfile.c | 3 +-- libavformat/teeproto.c | 6 ++---- libavformat/tls.c | 5 ++--- libavformat/url.h | 13 +++++++++++++ 26 files changed, 87 insertions(+), 105 deletions(-) diff --git a/libavformat/avio.c b/libavformat/avio.c index ab1c19a58d..6437118c75 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -353,6 +353,24 @@ fail: return ret; } +int ffurl_open_with_parent(URLContext **puc, const char *filename, int flags, + AVDictionary **options, URLContext *parent) +{ + return ffurl_open_whitelist(puc, filename, flags, + &parent->interrupt_callback, options, + parent->protocol_whitelist, + parent->protocol_blacklist, parent); +} + +int ffurl_open_with_avfmt(URLContext **puc, const char *filename, int flags, + AVDictionary **options, AVFormatContext *avfmt) +{ + return ffurl_open_whitelist(puc, filename, flags, + &avfmt->interrupt_callback, options, + avfmt->protocol_whitelist, + avfmt->protocol_blacklist, NULL); +} + static inline int retry_transfer_wrapper(URLContext *h, uint8_t *buf, int size, int size_min, int (*transfer_func)(URLContext *h, diff --git a/libavformat/cache.c b/libavformat/cache.c index 115c2c2490..0cfc290e67 100644 --- a/libavformat/cache.c +++ b/libavformat/cache.c @@ -92,8 +92,7 @@ static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary ** else c->filename = buffername; - return ffurl_open_whitelist(&c->inner, arg, flags, &h->interrupt_callback, - options, h->protocol_whitelist, h->protocol_blacklist, h); + return ffurl_open_with_parent(&c->inner, arg, flags, options, h); } static int add_entry(URLContext *h, const unsigned char *buf, int size) diff --git a/libavformat/concat.c b/libavformat/concat.c index 825e43a7fa..4b6397acaf 100644 --- a/libavformat/concat.c +++ b/libavformat/concat.c @@ -99,8 +99,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags) uri += len + strspn(uri + len, AV_CAT_SEPARATOR); /* creating URLContext */ - err = ffurl_open_whitelist(&uc, node_uri, flags, - &h->interrupt_callback, NULL, h->protocol_whitelist, h->protocol_blacklist, h); + err = ffurl_open_with_parent(&uc, node_uri, flags, NULL, h); if (err < 0) break; @@ -267,8 +266,7 @@ static av_cold int concatf_open(URLContext *h, const char *uri, int flags) } /* creating URLContext */ - err = ffurl_open_whitelist(&uc, node_uri, flags, - &h->interrupt_callback, NULL, h->protocol_whitelist, h->protocol_blacklist, h); + err = ffurl_open_with_parent(&uc, node_uri, flags, NULL, h); av_free(node_uri); if (err < 0) break; diff --git a/libavformat/crypto.c b/libavformat/crypto.c index 1d4514e0f2..8650ee9c5b 100644 --- a/libavformat/crypto.c +++ b/libavformat/crypto.c @@ -140,9 +140,7 @@ static int crypto_open2(URLContext *h, const char *uri, int flags, AVDictionary goto err; } - if ((ret = ffurl_open_whitelist(&c->hd, nested_url, flags, - &h->interrupt_callback, options, - h->protocol_whitelist, h->protocol_blacklist, h)) < 0) { + if ((ret = ffurl_open_with_parent(&c->hd, nested_url, flags, options, h)) < 0) { av_log(h, AV_LOG_ERROR, "Unable to open resource: %s\n", nested_url); goto err; } diff --git a/libavformat/ftp.c b/libavformat/ftp.c index 883668b37b..b360079b2f 100644 --- a/libavformat/ftp.c +++ b/libavformat/ftp.c @@ -574,9 +574,8 @@ static int ftp_connect_control_connection(URLContext *h) if (s->rw_timeout != -1) { av_dict_set_int(&opts, "timeout", s->rw_timeout, 0); } /* if option is not given, don't pass it and let tcp use its own default */ - err = ffurl_open_whitelist(&s->conn_control, buf, AVIO_FLAG_READ_WRITE, - &h->interrupt_callback, &opts, - h->protocol_whitelist, h->protocol_blacklist, h); + err = ffurl_open_with_parent(&s->conn_control, buf, + AVIO_FLAG_READ_WRITE, &opts, h); av_dict_free(&opts); if (err < 0) { av_log(h, AV_LOG_ERROR, "Cannot open control connection\n"); @@ -628,9 +627,7 @@ static int ftp_connect_data_connection(URLContext *h) if (s->rw_timeout != -1) { av_dict_set_int(&opts, "timeout", s->rw_timeout, 0); } /* if option is not given, don't pass it and let tcp use its own default */ - err = ffurl_open_whitelist(&s->conn_data, buf, h->flags, - &h->interrupt_callback, &opts, - h->protocol_whitelist, h->protocol_blacklist, h); + err = ffurl_open_with_parent(&s->conn_data, buf, h->flags, &opts, h); av_dict_free(&opts); if (err < 0) return err; diff --git a/libavformat/gopher.c b/libavformat/gopher.c index 9497ffacf2..4706d6899b 100644 --- a/libavformat/gopher.c +++ b/libavformat/gopher.c @@ -98,8 +98,7 @@ static int gopher_open(URLContext *h, const char *uri, int flags) ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL); s->hd = NULL; - err = ffurl_open_whitelist(&s->hd, buf, AVIO_FLAG_READ_WRITE, - &h->interrupt_callback, NULL, h->protocol_whitelist, h->protocol_blacklist, h); + err = ffurl_open_with_parent(&s->hd, buf, AVIO_FLAG_READ_WRITE, NULL, h); if (err < 0) goto fail; diff --git a/libavformat/hlsproto.c b/libavformat/hlsproto.c index 6a2765bbe9..f87495363b 100644 --- a/libavformat/hlsproto.c +++ b/libavformat/hlsproto.c @@ -295,9 +295,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_whitelist(&s->seg_hd, url, AVIO_FLAG_READ, - &h->interrupt_callback, NULL, - h->protocol_whitelist, h->protocol_blacklist, h); + ret = ffurl_open_with_parent(&s->seg_hd, url, AVIO_FLAG_READ, NULL, h); if (ret < 0) { if (ff_check_interrupt(&h->interrupt_callback)) return AVERROR_EXIT; diff --git a/libavformat/http.c b/libavformat/http.c index 0817aafb5b..5410de4f1e 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -263,9 +263,8 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL); if (!s->hd) { - err = ffurl_open_whitelist(&s->hd, buf, AVIO_FLAG_READ_WRITE, - &h->interrupt_callback, options, - h->protocol_whitelist, h->protocol_blacklist, h); + err = ffurl_open_with_parent(&s->hd, buf, AVIO_FLAG_READ_WRITE, + options, h); } end: @@ -662,10 +661,8 @@ static int http_listen(URLContext *h, const char *uri, int flags, NULL); if ((ret = av_dict_set_int(options, "listen", s->listen, 0)) < 0) goto fail; - if ((ret = ffurl_open_whitelist(&s->hd, lower_url, AVIO_FLAG_READ_WRITE, - &h->interrupt_callback, options, - h->protocol_whitelist, h->protocol_blacklist, h - )) < 0) + if ((ret = ffurl_open_with_parent(&s->hd, lower_url, AVIO_FLAG_READ_WRITE, + options, h)) < 0) goto fail; s->handshake_step = LOWER_PROTO; if (s->listen == HTTP_SINGLE) { /* single client */ @@ -2066,9 +2063,8 @@ static int http_proxy_open(URLContext *h, const char *uri, int flags) ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port, NULL); redo: - ret = ffurl_open_whitelist(&s->hd, lower_url, AVIO_FLAG_READ_WRITE, - &h->interrupt_callback, NULL, - h->protocol_whitelist, h->protocol_blacklist, h); + ret = ffurl_open_with_parent(&s->hd, lower_url, AVIO_FLAG_READ_WRITE, + NULL, h); if (ret < 0) return ret; diff --git a/libavformat/icecast.c b/libavformat/icecast.c index b06c53cabd..b7382a6503 100644 --- a/libavformat/icecast.c +++ b/libavformat/icecast.c @@ -168,8 +168,7 @@ static int icecast_open(URLContext *h, const char *uri, int flags) s->tls ? "https" : "http", auth, host, port, "%s", path); // Finally open http proto handler - ret = ffurl_open_whitelist(&s->hd, h_url, AVIO_FLAG_READ_WRITE, NULL, - &opt_dict, h->protocol_whitelist, h->protocol_blacklist, h); + ret = ffurl_open_with_parent(&s->hd, h_url, AVIO_FLAG_READ_WRITE, &opt_dict, h); cleanup: av_freep(&user); diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c index 9c0d461099..ad05b6a5fd 100644 --- a/libavformat/ipfsgateway.c +++ b/libavformat/ipfsgateway.c @@ -290,10 +290,7 @@ static int translate_ipfs_to_http(URLContext *h, const char *uri, int flags, AVD } // Pass the URL back to FFMpeg's protocol handler. - ret = ffurl_open_whitelist(&c->inner, fulluri, flags, - &h->interrupt_callback, options, - h->protocol_whitelist, - h->protocol_blacklist, h); + ret = ffurl_open_with_parent(&c->inner, fulluri, flags, options, h); if (ret < 0) { av_log(h, AV_LOG_WARNING, "Unable to open resource: %s\n", fulluri); goto err; diff --git a/libavformat/md5proto.c b/libavformat/md5proto.c index 14cefe719c..064aeb5c4d 100644 --- a/libavformat/md5proto.c +++ b/libavformat/md5proto.c @@ -69,9 +69,7 @@ static int md5_close(URLContext *h) av_strstart(filename, "md5:", &filename); if (*filename) { - err = ffurl_open_whitelist(&out, filename, AVIO_FLAG_WRITE, - &h->interrupt_callback, NULL, - h->protocol_whitelist, h->protocol_blacklist, h); + err = ffurl_open_with_parent(&out, filename, AVIO_FLAG_WRITE, NULL, h); if (err) return err; err = ffurl_write(out, buf, sizeof(buf)); diff --git a/libavformat/mmst.c b/libavformat/mmst.c index 20b04b12aa..a4ab56ae54 100644 --- a/libavformat/mmst.c +++ b/libavformat/mmst.c @@ -528,9 +528,8 @@ 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_whitelist(&mms->mms_hd, tcpname, AVIO_FLAG_READ_WRITE, - &h->interrupt_callback, NULL, - h->protocol_whitelist, h->protocol_blacklist, h); + err = ffurl_open_with_parent(&mms->mms_hd, tcpname, AVIO_FLAG_READ_WRITE, + NULL, h); if (err) goto fail; diff --git a/libavformat/prompeg.c b/libavformat/prompeg.c index 59faa824bb..daf0050a1e 100644 --- a/libavformat/prompeg.c +++ b/libavformat/prompeg.c @@ -295,12 +295,10 @@ static int prompeg_open(URLContext *h, const char *uri, int flags) { } ff_url_join(buf, sizeof (buf), "udp", NULL, hostname, rtp_port + 2, NULL); - if (ffurl_open_whitelist(&s->fec_col_hd, buf, flags, &h->interrupt_callback, - &udp_opts, h->protocol_whitelist, h->protocol_blacklist, h) < 0) + if (ffurl_open_with_parent(&s->fec_col_hd, buf, flags, &udp_opts, h) < 0) goto fail; ff_url_join(buf, sizeof (buf), "udp", NULL, hostname, rtp_port + 4, NULL); - if (ffurl_open_whitelist(&s->fec_row_hd, buf, flags, &h->interrupt_callback, - &udp_opts, h->protocol_whitelist, h->protocol_blacklist, h) < 0) + if (ffurl_open_with_parent(&s->fec_row_hd, buf, flags, &udp_opts, h) < 0) goto fail; h->max_packet_size = s->fec_col_hd->max_packet_size; diff --git a/libavformat/rtmpcrypt.c b/libavformat/rtmpcrypt.c index a835ab263f..f65df984a3 100644 --- a/libavformat/rtmpcrypt.c +++ b/libavformat/rtmpcrypt.c @@ -264,9 +264,8 @@ static int rtmpe_open(URLContext *h, const char *uri, int flags) } /* open the tcp or ffrtmphttp connection */ - if ((ret = ffurl_open_whitelist(&rt->stream, url, AVIO_FLAG_READ_WRITE, - &h->interrupt_callback, NULL, - h->protocol_whitelist, h->protocol_blacklist, h)) < 0) { + if ((ret = ffurl_open_with_parent(&rt->stream, url, AVIO_FLAG_READ_WRITE, + NULL, h)) < 0) { rtmpe_close(h); return ret; } diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index f0ef223f05..c8eb617a34 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -1121,9 +1121,8 @@ static int rtmp_calc_swfhash(URLContext *s) int ret = 0; /* Get the SWF player file. */ - if ((ret = ffurl_open_whitelist(&stream, rt->swfverify, AVIO_FLAG_READ, - &s->interrupt_callback, NULL, - s->protocol_whitelist, s->protocol_blacklist, s)) < 0) { + if ((ret = ffurl_open_with_parent(&stream, rt->swfverify, AVIO_FLAG_READ, + NULL, s)) < 0) { av_log(s, AV_LOG_ERROR, "Cannot open connection %s.\n", rt->swfverify); goto fail; } @@ -2663,9 +2662,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags, AVDictionary **o } reconnect: - if ((ret = ffurl_open_whitelist(&rt->stream, buf, AVIO_FLAG_READ_WRITE, - &s->interrupt_callback, opts, - s->protocol_whitelist, s->protocol_blacklist, s)) < 0) { + if ((ret = ffurl_open_with_parent(&rt->stream, buf, AVIO_FLAG_READ_WRITE, opts, s)) < 0) { av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf); goto fail; } diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index b970901d01..4627d6399d 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -327,8 +327,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) build_udp_url(s, buf, sizeof(buf), hostname, s->localaddr, rtp_port, s->local_rtpport, sources, block); - if (ffurl_open_whitelist(&s->rtp_hd, buf, flags, &h->interrupt_callback, - NULL, h->protocol_whitelist, h->protocol_blacklist, h) < 0) + if (ffurl_open_with_parent(&s->rtp_hd, buf, flags, NULL, h) < 0) goto fail; s->local_rtpport = ff_udp_get_local_port(s->rtp_hd); if(s->local_rtpport == 65535) { @@ -341,9 +340,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) build_udp_url(s, buf, sizeof(buf), hostname, s->localaddr, s->rtcp_port, s->local_rtcpport, sources, block); - if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, - &h->interrupt_callback, NULL, - h->protocol_whitelist, h->protocol_blacklist, h) < 0) { + if (ffurl_open_with_parent(&s->rtcp_hd, buf, rtcpflags, NULL, h) < 0) { s->local_rtpport = s->local_rtcpport = -1; continue; } @@ -352,8 +349,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) build_udp_url(s, buf, sizeof(buf), hostname, s->localaddr, s->rtcp_port, s->local_rtcpport, sources, block); - if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, &h->interrupt_callback, - NULL, h->protocol_whitelist, h->protocol_blacklist, h) < 0) + if (ffurl_open_with_parent(&s->rtcp_hd, buf, rtcpflags, NULL, h) < 0) goto fail; break; } @@ -361,8 +357,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) s->fec_hd = NULL; if (fec_protocol) { ff_url_join(buf, sizeof(buf), fec_protocol, NULL, hostname, rtp_port, NULL); - if (ffurl_open_whitelist(&s->fec_hd, buf, flags, &h->interrupt_callback, - &fec_opts, h->protocol_whitelist, h->protocol_blacklist, h) < 0) + if (ffurl_open_with_parent(&s->fec_hd, buf, flags, &fec_opts, h) < 0) goto fail; } diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index cfafb4be80..60a6819477 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -1523,8 +1523,8 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, "?localport=%d", j); /* we will use two ports per rtp stream (rtp and rtcp) */ j += 2; - err = ffurl_open_whitelist(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE, - &s->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist, NULL); + err = ffurl_open_with_avfmt(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE, + &opts, s); av_dict_free(&opts); @@ -1678,8 +1678,8 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); ff_url_join(url, sizeof(url), "rtp", NULL, namebuf, port, "%s", optbuf); - err = ffurl_open_whitelist(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, - &s->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist, NULL); + err = ffurl_open_with_avfmt(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, + &opts, s); av_dict_free(&opts); if (err < 0) { @@ -1893,8 +1893,8 @@ redirect: ff_url_join(tcpname, sizeof(tcpname), lower_rtsp_proto, NULL, host, port, "?timeout=%"PRId64, rt->stimeout); - if ((ret = ffurl_open_whitelist(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE, - &s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL)) < 0) { + if ((ret = ffurl_open_with_avfmt(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE, + NULL, s)) < 0) { err = ret; goto fail; } @@ -2450,8 +2450,8 @@ static int sdp_read_header(AVFormatContext *s) append_source_addrs(url, sizeof(url), "block", rtsp_st->nb_exclude_source_addrs, rtsp_st->exclude_source_addrs); - err = ffurl_open_whitelist(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ, - &s->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist, NULL); + err = ffurl_open_with_avfmt(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ, + &opts, s); av_dict_free(&opts); @@ -2524,8 +2524,7 @@ static int rtp_read_header(AVFormatContext *s) return AVERROR(EIO); opts = map_to_opts(rt); - ret = ffurl_open_whitelist(&in, s->url, AVIO_FLAG_READ, - &s->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist, NULL); + ret = ffurl_open_with_avfmt(&in, s->url, AVIO_FLAG_READ, &opts, s); av_dict_free(&opts); if (ret) goto fail; diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c index bbabec7db8..7b1bc0baee 100644 --- a/libavformat/rtspdec.c +++ b/libavformat/rtspdec.c @@ -312,9 +312,8 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl) av_dict_set_int(&opts, "buffer_size", rt->buffer_size, 0); ff_url_join(url, sizeof(url), "rtp", NULL, host, localport, NULL); av_log(s, AV_LOG_TRACE, "Opening: %s\n", url); - ret = ffurl_open_whitelist(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, - &s->interrupt_callback, &opts, - s->protocol_whitelist, s->protocol_blacklist, NULL); + ret = ffurl_open_with_avfmt(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, + &opts, s); av_dict_free(&opts); if (ret) localport += 2; @@ -684,9 +683,8 @@ static int rtsp_listen(AVFormatContext *s) ff_url_join(tcpname, sizeof(tcpname), lower_proto, NULL, host, port, "?listen&listen_timeout=%d", rt->initial_timeout * 1000); - if (ret = ffurl_open_whitelist(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE, - &s->interrupt_callback, NULL, - s->protocol_whitelist, s->protocol_blacklist, NULL)) { + if (ret = ffurl_open_with_avfmt(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE, + NULL, s)) { av_log(s, AV_LOG_ERROR, "Unable to open RTSP for listening\n"); goto fail; } diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c index fd0e662433..08815a837a 100644 --- a/libavformat/sapdec.c +++ b/libavformat/sapdec.c @@ -83,9 +83,7 @@ static int sap_read_header(AVFormatContext *s) ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d", port); - ret = ffurl_open_whitelist(&sap->ann_fd, url, AVIO_FLAG_READ, - &s->interrupt_callback, NULL, - s->protocol_whitelist, s->protocol_blacklist, NULL); + ret = ffurl_open_with_avfmt(&sap->ann_fd, url, AVIO_FLAG_READ, NULL, s); if (ret) goto fail; diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c index 28839b837f..86327bb57b 100644 --- a/libavformat/sapenc.c +++ b/libavformat/sapenc.c @@ -150,9 +150,7 @@ static int sap_write_header(AVFormatContext *s) "?ttl=%d", ttl); if (!same_port) base_port += 2; - ret = ffurl_open_whitelist(&fd, url, AVIO_FLAG_WRITE, - &s->interrupt_callback, NULL, - s->protocol_whitelist, s->protocol_blacklist, NULL); + ret = ffurl_open_with_avfmt(&fd, url, AVIO_FLAG_WRITE, NULL, s); if (ret) { ret = AVERROR(EIO); goto fail; @@ -175,9 +173,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_whitelist(&sap->ann_fd, url, AVIO_FLAG_WRITE, - &s->interrupt_callback, NULL, - s->protocol_whitelist, s->protocol_blacklist, NULL); + ret = ffurl_open_with_avfmt(&sap->ann_fd, url, AVIO_FLAG_WRITE, NULL, s); if (ret) { ret = AVERROR(EIO); goto fail; diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c index 3c050ca54e..78d2de905c 100644 --- a/libavformat/smoothstreamingenc.c +++ b/libavformat/smoothstreamingenc.c @@ -113,8 +113,7 @@ static int64_t ism_seek(void *opaque, int64_t offset, int whence) AVDictionary *opts = NULL; os->tail_out = os->out; av_dict_set(&opts, "truncate", "0", 0); - ret = ffurl_open_whitelist(&os->out, frag->file, AVIO_FLAG_WRITE, - &os->ctx->interrupt_callback, &opts, os->ctx->protocol_whitelist, os->ctx->protocol_blacklist, NULL); + ret = ffurl_open_with_avfmt(&os->out, frag->file, AVIO_FLAG_WRITE, &opts, os->ctx); av_dict_free(&opts); if (ret < 0) { os->out = os->tail_out; @@ -122,8 +121,7 @@ static int64_t ism_seek(void *opaque, int64_t offset, int whence) return ret; } av_dict_set(&opts, "truncate", "0", 0); - ffurl_open_whitelist(&os->out2, frag->infofile, AVIO_FLAG_WRITE, - &os->ctx->interrupt_callback, &opts, os->ctx->protocol_whitelist, os->ctx->protocol_blacklist, NULL); + ffurl_open_with_avfmt(&os->out2, frag->infofile, AVIO_FLAG_WRITE, &opts, os->ctx); av_dict_free(&opts); ffurl_seek(os->out, offset - frag->start_pos, SEEK_SET); if (os->out2) @@ -507,7 +505,7 @@ static int ism_flush(AVFormatContext *s, int final) continue; snprintf(filename, sizeof(filename), "%s/temp", os->dirname); - ret = ffurl_open_whitelist(&os->out, filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL); + ret = ffurl_open_with_avfmt(&os->out, filename, AVIO_FLAG_WRITE, NULL, s); if (ret < 0) break; os->cur_start_pos = os->tail_pos; diff --git a/libavformat/srtpproto.c b/libavformat/srtpproto.c index 13e2245015..13a2398d01 100644 --- a/libavformat/srtpproto.c +++ b/libavformat/srtpproto.c @@ -79,8 +79,7 @@ static int srtp_open(URLContext *h, const char *uri, int flags) av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port, path, sizeof(path), uri); ff_url_join(buf, sizeof(buf), "rtp", NULL, hostname, rtp_port, "%s", path); - if ((ret = ffurl_open_whitelist(&s->rtp_hd, buf, flags, &h->interrupt_callback, - NULL, h->protocol_whitelist, h->protocol_blacklist, h)) < 0) + if ((ret = ffurl_open_with_parent(&s->rtp_hd, buf, flags, NULL, h)) < 0) goto fail; h->max_packet_size = FFMIN(s->rtp_hd->max_packet_size, diff --git a/libavformat/subfile.c b/libavformat/subfile.c index 2936c79e06..3a268f38db 100644 --- a/libavformat/subfile.c +++ b/libavformat/subfile.c @@ -79,8 +79,7 @@ static int subfile_open(URLContext *h, const char *filename, int flags, return AVERROR(EINVAL); } av_strstart(filename, "subfile:", &filename); - ret = ffurl_open_whitelist(&c->h, filename, flags, &h->interrupt_callback, - options, h->protocol_whitelist, h->protocol_blacklist, h); + ret = ffurl_open_with_parent(&c->h, filename, flags, options, h); if (ret < 0) return ret; c->pos = c->start; diff --git a/libavformat/teeproto.c b/libavformat/teeproto.c index dca97a6741..b7b3cf4741 100644 --- a/libavformat/teeproto.c +++ b/libavformat/teeproto.c @@ -111,10 +111,8 @@ static int tee_open(URLContext *h, const char *filename, int flags) if (ret < 0) goto loop_fail; - ret = ffurl_open_whitelist(&c->child[c->child_count].url_context, child_name, flags, - &h->interrupt_callback, &options, - h->protocol_whitelist, h->protocol_blacklist, - h); + ret = ffurl_open_with_parent(&c->child[c->child_count].url_context, child_name, flags, + &options, h); loop_fail: av_freep(&child_string); av_dict_free(&options); diff --git a/libavformat/tls.c b/libavformat/tls.c index 33e8ec384f..3a3f323f8c 100644 --- a/libavformat/tls.c +++ b/libavformat/tls.c @@ -125,7 +125,6 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV } freeenv_utf8(env_http_proxy); - return ffurl_open_whitelist(&c->tcp, buf, AVIO_FLAG_READ_WRITE, - &parent->interrupt_callback, options, - parent->protocol_whitelist, parent->protocol_blacklist, parent); + return ffurl_open_with_parent(&c->tcp, buf, AVIO_FLAG_READ_WRITE, + options, parent); } diff --git a/libavformat/url.h b/libavformat/url.h index 3cfe3ecc5c..30a73b6846 100644 --- a/libavformat/url.h +++ b/libavformat/url.h @@ -24,6 +24,7 @@ #ifndef AVFORMAT_URL_H #define AVFORMAT_URL_H +#include "avformat.h" #include "avio.h" #include "libavutil/dict.h" @@ -147,6 +148,18 @@ int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const char *whitelist, const char* blacklist, URLContext *parent); +/** + * same as ffurl_open_whitelist but using the parent context to setup arguments. + */ +int ffurl_open_with_parent(URLContext **puc, const char *filename, int flags, + AVDictionary **options, URLContext *parent); + +/** + * same as ffurl_open_whitelist but using the AVFormatContext to setup arguments. + */ +int ffurl_open_with_avfmt(URLContext **puc, const char *filename, int flags, + AVDictionary **options, AVFormatContext *avfmt); + /** * Accept an URLContext c on an URLContext s *