From patchwork Wed Aug 31 13:12:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mirs fang X-Patchwork-Id: 37574 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp344348pzh; Wed, 31 Aug 2022 06:13:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR4hj5mIE8H1zZbykwTB7iCucig8ZammV0lBalJFdEefkq6T18/iONh00p6qNbF8+a95Kvbj X-Received: by 2002:a17:907:1c1b:b0:73d:6a20:5664 with SMTP id nc27-20020a1709071c1b00b0073d6a205664mr19921047ejc.583.1661951590564; Wed, 31 Aug 2022 06:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661951590; cv=none; d=google.com; s=arc-20160816; b=n7a2+eJyPrSOK96LSnkG21A3qGP5b/fkzmIBcWqY3FOEIAJDwyfMDS1GbZ0SdpXw8O wCtaKjZLp6/vwRPyjOEkTiwrrny+Y5O6C5I8YwlvpDixiHyZUu1iMjpegIJL3RfAgwcf ksx5i2AvO7hk+NZIf1Anaoku/U8JpB4L2AzwjPH5/UJFUFAluZL+i0U1YvcrBYdWnmk4 VXYEBw/mLCgR1puFYDMX1+pWzuayyz9dRn/iBrHNqffFB6s+S9IRGIL8mlR6jL2gQPBy G/jEbYoWVDqmVLfgT88lyyU2pcJCu4JfM7ZaS+rzXbI8bZ0bv3/JV8U4bqhCHGUr95g4 fuzw== 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 :dkim-signature:delivered-to; bh=gKhQH/eIK3CN3c5aKvscHlqH0SBbcr9MzeyA8p0Ccno=; b=g2ewDy+wVzOkFS9YI8ntP2GiBR1I82i3rXPR41dfChi+OHibL6WfhwhSP8c9qvYKIK lt2ZJQJCpNaElj/KbW8zaHk8zddBNqGWb/xXZOhLM6w4opeH+7EXRaI7aUI3NT4+RLO3 zLNMzRh4JhvHN0wzid8cWP0VpRL8A7ZN06yrdXjiqW6JjFMrLDwi5x/dccDwdtxCg0iC OapJyk8YMhfqtNnriPl1R20YcBBuxadJP9Sp03tUjEfz7VYMNM1LhGc1UDX9eR/6i8LS WEmUGdoCP+90Uhsiu/MBiQvUoBwK4lmiOM5mZhlGizizwIoeJ577X/KBpkgytT6JTq03 xZUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=e6sqOTBV; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q11-20020a50cc8b000000b004467c12a6bdsi11008546edi.459.2022.08.31.06.13.09; Wed, 31 Aug 2022 06:13:10 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=e6sqOTBV; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3126E68BB27; Wed, 31 Aug 2022 16:13:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 34A3468B823 for ; Wed, 31 Aug 2022 16:13:00 +0300 (EEST) Received: by mail-pg1-f174.google.com with SMTP id v4so13466606pgi.10 for ; Wed, 31 Aug 2022 06:13:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=aZlFhoMDvIi6e3zaUVNWekiBfe8rRdr9FAcsuOZOxbk=; b=e6sqOTBVRqBLa1qr8iCXqMNp9RDdw/8GAzJ9PBCR8IcwNJRRQ6c6s/gKIM2N5G2s/y NdDNRzNBbTTjhFr0At3w8qa1IRD4dKXjqTHBNJMkzBSrI1cj6+wO+CziZq4yZSPA1ski lS0pXWD8hf43D2avZnytdQtFKQbVdMWBFKnFvtEyhnKVdjv4/Yc3HIRXeJN/rUJJqVY2 etPPn3pTWdXuFW5JTDmxyg79JJoFzaV/xcwp7E6c7Cje03/Vk5wgyVbf+bIAKsX+Nke/ Qd6ymrSdetazYWsOlmfJVnZp8fMmZxxyO3cEHM0mRv5yKhn5h+BG//KwhM7PU0eJw3wr Fxhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=aZlFhoMDvIi6e3zaUVNWekiBfe8rRdr9FAcsuOZOxbk=; b=i77Gv6a+cEKeuJlGXIsyHQU9Rpeluj+BeO6y1XF7VFQ9T+1ObfxBLnizIBMthkdJsV UVsN8J6COlHlo3DHrbj0Aw7jFDN5qOB2EMYTjPAFYYWKyZn+D088g47lB4LysLbD9SR0 /DQUjOcoRwoGbGSRJaHMqfkWrSttVeMe56vc6i4X7OLM1J6Lfe6kX9Z/W2C9eTe9tLlL cLT09FBhD1pIMqNTckqA7g7egmqWYX4zUhaVMhPeMZd1dlBl3U4MJ+8pnRBuyYpCmAy8 /TQHiOzElUEpCrfz3nQYtRQFOxnorrTlbuycFI72ggf7w7g2zn9oV3lKmZETGx+Upc4J jXag== X-Gm-Message-State: ACgBeo0D/dJoOaUwZICW9EGxmZuEJOA7o7JgutP5LeMulUnIpA3MvYXa SIJFaOFkSSDKHVORog2qN0O+5gHVjmcFh0R3 X-Received: by 2002:a05:6a00:b43:b0:52f:59dc:93 with SMTP id p3-20020a056a000b4300b0052f59dc0093mr26016600pfo.26.1661951578063; Wed, 31 Aug 2022 06:12:58 -0700 (PDT) Received: from localhost ([220.203.232.198]) by smtp.gmail.com with ESMTPSA id e6-20020a170902784600b0016dcbdf9492sm11610301pln.92.2022.08.31.06.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 06:12:57 -0700 (PDT) From: mirsfang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Aug 2022 21:12:54 +0800 Message-Id: <20220831131254.21788-1-mirsfang@gmail.com> X-Mailer: git-send-email 2.32.1 (Apple Git-133) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1] lavf/hls: add option for hls segment request append http get request parameters 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: mirs Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +N6lYpW/Q71J From: mirs Signed-off-by: mirs --- libavformat/hls.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 3dc7bd3930..3a1cc855c4 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -220,6 +220,7 @@ typedef struct HLSContext { AVIOInterruptCB *interrupt_callback; AVDictionary *avio_opts; AVDictionary *seg_format_opts; + int seg_append_http_get_params; char *allowed_extensions; int max_reload; int http_persistent; @@ -307,6 +308,23 @@ static void free_rendition_list(HLSContext *c) c->n_renditions = 0; } +static void hls_append_param_to_url(const HLSContext * c,char *buf, int size, const char *base, + const char *rel) +{ + if (c && c->seg_append_http_get_params && base) { + char * ch = strchr(base, '?'); + if (!ch) { + return; + } + + if (strchr(buf, '?')) { + ch++; + av_strlcat(buf, "&", size); + } + av_strlcat(buf, ch, size); + } +} + static struct playlist *new_playlist(HLSContext *c, const char *url, const char *base) { @@ -319,6 +337,7 @@ static struct playlist *new_playlist(HLSContext *c, const char *url, return NULL; } ff_make_absolute_url(pls->url, sizeof(pls->url), base, url); + hls_append_param_to_url(c,pls->url, sizeof(pls->url), base, url); if (!pls->url[0]) { av_packet_free(&pls->pkt); av_free(pls); @@ -411,7 +430,7 @@ struct init_section_info { char byterange[32]; }; -static struct segment *new_init_section(struct playlist *pls, +static struct segment *new_init_section(const HLSContext * c,struct playlist *pls, struct init_section_info *info, const char *url_base) { @@ -429,6 +448,7 @@ static struct segment *new_init_section(struct playlist *pls, ptr = info->uri; } else { ff_make_absolute_url(tmp_str, sizeof(tmp_str), url_base, info->uri); + hls_append_param_to_url(c,tmp_str, sizeof(tmp_str), url_base, info->uri); if (!tmp_str[0]) { av_free(sec); return NULL; @@ -861,7 +881,7 @@ static int parse_playlist(HLSContext *c, const char *url, goto fail; ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_init_section_args, &info); - cur_init_section = new_init_section(pls, &info, url); + cur_init_section = new_init_section(c,pls, &info, url); if (!cur_init_section) { ret = AVERROR(ENOMEM); goto fail; @@ -877,6 +897,7 @@ static int parse_playlist(HLSContext *c, const char *url, if (key_type != KEY_NONE) { ff_make_absolute_url(tmp_str, sizeof(tmp_str), url, key); + hls_append_param_to_url(c,tmp_str, sizeof(tmp_str), url, key); if (!tmp_str[0]) { av_free(cur_init_section); ret = AVERROR_INVALIDDATA; @@ -949,6 +970,7 @@ static int parse_playlist(HLSContext *c, const char *url, if (key_type != KEY_NONE) { ff_make_absolute_url(tmp_str, sizeof(tmp_str), url, key); + hls_append_param_to_url(c,tmp_str, sizeof(tmp_str), url, key); if (!tmp_str[0]) { ret = AVERROR_INVALIDDATA; av_free(seg); @@ -963,8 +985,9 @@ static int parse_playlist(HLSContext *c, const char *url, } else { seg->key = NULL; } - ff_make_absolute_url(tmp_str, sizeof(tmp_str), url, line); + hls_append_param_to_url(c,tmp_str, sizeof(tmp_str), url, line); + if (!tmp_str[0]) { ret = AVERROR_INVALIDDATA; if (seg->key) @@ -2548,6 +2571,8 @@ static const AVOption hls_options[] = { OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS}, {"seg_format_options", "Set options for segment demuxer", OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS}, + {"seg_append_http_get_params", "Segment request append http get parameters 0 = disable 1 = enable", + OFFSET(seg_append_http_get_params), AV_OPT_TYPE_BOOL,{.i64 = 1}, 0, 1, FLAGS}, {NULL} };