From patchwork Wed Dec 15 00:35:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 32508 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7691632iog; Tue, 14 Dec 2021 16:35:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8TlL9Z4nXpNVvxZk3MVYbaRlhC4mEO660QwIMnZtQn7iE2PoHOXnCzjLv7tulroF7NhOE X-Received: by 2002:a05:6402:40d1:: with SMTP id z17mr12104734edb.340.1639528532818; Tue, 14 Dec 2021 16:35:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639528532; cv=none; d=google.com; s=arc-20160816; b=wPGIAbrDsBTdcUH6y6k+1jKFWWIyZ3AQmobyL1AFVXbADKEBuaOrb9naqd5aKQ1xIF KfbwOlI+9VIibkW6teYqoMJ4ARabo1yhZ3xR4mJTphBzZ3Q9RduJSN439KpwonA8hHBs umNJ2vVzmKXnyxy318N5oDyawrrLzAtUj/Z97FatThaBIGMq/cvEK6gr7kFRZtYiHXVh jdZ9zLpWHukWbewVkv34XOUjM1Kf3lJ6r7uGqzn0wgbzlZr+47dFDcXf0/gSGk1E7G/h 4T7lFc3gCI7CPFpI6vt+TiKxHKysL2IR4Dt5xjEsGjKI2lKQYxzLc28yrtqLsc/G0IY8 yQqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=B5uQ0aEiYU8UE9ufIt3QMjKmf1EelWL0fOLICkS0N6M=; b=pfFccxOvs5OCfb9sPuXbw6DyyqQCWGpx4/j+wyg9JBHopLDH7njaK0Bh45LAIyMaA0 udqQ/A5oDbXfZTuEHdVM35M9/Coqt1LSWCawredAIfGc8DD+iX1dySvoLoITVkodjhai +qMX3Ij7o1t2Akj+7mPeMivNSw5hdRfDGIT6MCOjAp9e5Uebv/axURop9v/Pv3B3v2fK u/4lslBeZrpQgZcj+AulO7eybzYReXKrPHRJwkgLh9eXn2K9RwuIYwtP/DnDliHAv+Ie qB045jE7sZUwwGuQaS3AQm3Ds9kYNm7ppTahdZgnt2eQUPAjrCyRInJmxKs90ZKebeGz BTKA== 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 o9si65627edr.208.2021.12.14.16.35.31; Tue, 14 Dec 2021 16:35:32 -0800 (PST) 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 E027A68AFF8; Wed, 15 Dec 2021 02:35:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E8D468ABD1 for ; Wed, 15 Dec 2021 02:35:21 +0200 (EET) Received: by mail-pj1-f41.google.com with SMTP id k6-20020a17090a7f0600b001ad9d73b20bso17562142pjl.3 for ; Tue, 14 Dec 2021 16:35:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uCfcu3hsjjIrN9T0KO6ugwZuOZFK+lstdM/esqE3cXA=; b=ddNXf6He94+9d532+Fw8s1f03LtF4eP1W5QXv8Hu5W4NSP/vQDAE1x4aMGtdErwPm7 wuWgHnFwLtOtjtjHDu2+BQaNEOL7kNEIqe2xWOgsuBDpp1314mMuo//hkPvP+zzE4XJp rWVfuTeIeSd5Ho+kBYVyXA6MT36MkHaj5XtRzAcIbsi/Gs/e8gkeO5CVbFnMXuW9/JOR YEQVElwCyBbG9Ct0ZJt7ut0H9+fsbRdp+TpwcbfxskHc9T6FEc9QigQH2Eeo9YcCA9jf 7wSifyxRxZG8bi3tcgSkH3QSBd8Cfbodq2brEMD4TEgCranpF0/tOLTqZsjL7lWYz8pM PxGQ== X-Gm-Message-State: AOAM5320GQc2Jj0Q0Xua7DyRnvHdGlXA3CmXSwBzy3J5vyZ5wkSRmAU4 qp6Qfl5XBT7DTrEcSQoZFEcTRYUeUV8= X-Received: by 2002:a17:902:e84e:b0:141:e3f2:36c5 with SMTP id t14-20020a170902e84e00b00141e3f236c5mr9321637plg.74.1639528519220; Tue, 14 Dec 2021 16:35:19 -0800 (PST) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id z14sm253567pfh.60.2021.12.14.16.35.17 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Dec 2021 16:35:18 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Tue, 14 Dec 2021 16:35:15 -0800 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Dec 2021 16:35:14 -0800 Message-Id: <20211215003514.23851-1-pal@sandflow.com> X-Mailer: git-send-email 2.34.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1] avformat/aviobuf: ffio_copy_url_options 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: w2lhkgctFR4r From: Pierre-Anthony Lemieux Signed-off-by: Pierre-Anthony Lemieux --- Notes: Refactors save_avio_options() from dashdec.c and hls.c into a common ffio_copy_url_options() in libavformat/aviobuf.c. Co-authored: Nicholas Vanderzwet libavformat/avio_internal.h | 6 ++++++ libavformat/aviobuf.c | 24 ++++++++++++++++++++++++ libavformat/dashdec.c | 27 +-------------------------- libavformat/hls.c | 24 +----------------------- 4 files changed, 32 insertions(+), 49 deletions(-) diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index 187433f283..1f5e3d474b 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -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 diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 969c127b23..096f37ae23 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1022,6 +1022,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) { diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 983dc85d65..797fe74157 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -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) diff --git a/libavformat/hls.c b/libavformat/hls.c index 557faf8e8d..8c526f748f 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -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,