From patchwork Wed Aug 31 07:13:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mirs fang X-Patchwork-Id: 37571 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp179044pzh; Wed, 31 Aug 2022 00:16:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR5ZBbvRb9UcYPhfs6ghRoTafR++XjjEKyVeDaW3WxfQXCBOtmnk0zOEHw973N4DKCI6elIn X-Received: by 2002:a05:6402:138b:b0:447:9f18:dbc5 with SMTP id b11-20020a056402138b00b004479f18dbc5mr23840338edv.113.1661930162105; Wed, 31 Aug 2022 00:16:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661930162; cv=none; d=google.com; s=arc-20160816; b=zWhVJ2fRsFhG7gzzluiJN0ycTKxcYEykWDhSxc8hzzuJhUXuAzSfHwrcaXTgUzLjGy LsFkQJ0sY27KJMPCMAfc1qKNfbjUa0kR9ZYXHc6YoKsnBe5CUh5Lvl1njpkktMUC6wEw M/LKjlYSABqwgEOelgcpSwWH46ZaMBA3Ap0hFgelZsmfOwQ7kvqlCZijc1yUQ5R7opQO taR6yv8kvSJujZAAl8kOGwYqY5lIGyiVY5PPilAtCW1nzejDamtbmY/kdbOmcLupjHNP ag4efxzGdSSbSt0jD5Mm0zE+bq/PL3j8XLiZr0bYurwHbgR2Gue/B6LHDcd0D8PDUguQ VDrw== 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=LFqq/RO1GeQVGJm9IoRgubytCoMD/aPVYoo+hPwj1yI=; b=WaUYCzWHAN+FiU/LrN6XFzFxAmQejGZw0iRA8dJQSM3YssaZFzYNl3+019RWBoAgUc /1JpB6A541xg8UsZTzYLDRxyIOmJYwGWIpQi3dxzyyZzD38xGyzY7Tg/rYUDdmzueRqr dVoGDAMPDtICz8T6xK73LJMZFwrbbArnytOBuR9oHNkXWPFtD5u19kpCI7FyKSBIIraL tLL6xdnqxMUxMxDyO9LHcfU0B7TQ5z0HiMTTKa0oep8D2hnFr1zicFBj3F6wq+3fhzx/ nUslq8XLrR9ikPTuc8ekc7Av7Ew/3WCCynI4osbMmG9+vS6k8b4y0ma/KZqS/tiNYy3N w7JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=UXsZTa9D; 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 ga28-20020a1709070c1c00b00730d106e832si8090648ejc.248.2022.08.31.00.16.00; Wed, 31 Aug 2022 00:16:02 -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=UXsZTa9D; 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 A426A68BB26; Wed, 31 Aug 2022 10:15:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AB4CD68B45F for ; Wed, 31 Aug 2022 10:15:49 +0300 (EEST) Received: by mail-pf1-f178.google.com with SMTP id z187so13571045pfb.12 for ; Wed, 31 Aug 2022 00:15:49 -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=WOQ9vbcCUJQcKinzM61OBCQy1orPXhavzJN+edDIyMU=; b=UXsZTa9DWOkd50boDoXhMQp8gBA+UGQzG5LZiTbm87xPA8J2YWNUluVBh/8yCr2zDF LHikvNPR8O/+QmgDu1Y9EwT2xm3BP2U5N1C7EFj1UwO/f1CdgUFBcEn8ypmaVDwTt4M3 eRpvER5rz5Do/njb1qCTLJcTj43Kw4XpTBLX7FW15wNJHsCHzIOg96F4a+1RZRH/VVwz udM7BukG2tuY1jWifvslpZF8ephhlrQ7hUW6bBPPBkGd8B9WItJKbcxv3miN3xlROGlO 1VELPUwZu80JYwm2gdoOSxgGxiNQJt1L5Hl+uJWKGbwqek4hIYVOKaPYU6zdNd7qYr83 GHZg== 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=WOQ9vbcCUJQcKinzM61OBCQy1orPXhavzJN+edDIyMU=; b=MiItNE7+mHySzL1WWIssKHDPCClBxyFrWmJafTJox+7JACl8VgSNCYAtizDDOgjERq 4hMLu9lQey00sAuYySALX3R02wVBah2j8lQmm+8ngozO+FPl8xk3v/FVIrRWG11+b+Su A/pFI0AcJoBVV6fcMEbWlpifHo45NhrSYm9GSW0E0hRoD3CQBo/7cQEaKs5cKhF3KOsO 5sFhz7SmNLunXwQxkNKmOa9RLX2Nh4Bxg8Rn0EQ9Y5O+oM8sFZ4CQS5Z3jrbFEaqynqZ 9qZkCGoyGM9ZA8YAISlRSN3fALcfOsBPYWYl3egmYlG7+lOL1lJy/iK+tyTs7vO6N+T5 1xlA== X-Gm-Message-State: ACgBeo34FuxXF6H0h4rUziXPzzQ5iwK56uLl5aA7DlQGzou9T/QqX94E k4a/QveGbfw4N3gEmPBYnsuBTlYg5c/b49SF X-Received: by 2002:a63:f44:0:b0:42c:5a16:dfa1 with SMTP id 4-20020a630f44000000b0042c5a16dfa1mr8415839pgp.305.1661930147488; Wed, 31 Aug 2022 00:15:47 -0700 (PDT) Received: from localhost.localdomain ([220.203.232.198]) by smtp.gmail.com with ESMTPSA id m20-20020a17090ade1400b001fad1f975casm691367pjv.12.2022.08.31.00.15.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 31 Aug 2022 00:15:47 -0700 (PDT) From: mirsfang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Aug 2022 15:13:09 +0800 Message-Id: <20220831071308.85780-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: 43TdMo//bqPn From: mirs Signed-off-by: mirs add option for hls when client reqeust segment url maybe use get parameters for user authenticatio --- libavformat/hls.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 3dc7bd3930..06d0a89a95 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,25 @@ static void free_rendition_list(HLSContext *c) c->n_renditions = 0; } +static void hls_make_url(const HLSContext * c,char *buf, int size, const char *base, + const char *rel) +{ + ff_make_absolute_url(buf, size, base, 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) { @@ -318,7 +338,7 @@ static struct playlist *new_playlist(HLSContext *c, const char *url, av_free(pls); return NULL; } - ff_make_absolute_url(pls->url, sizeof(pls->url), base, url); + hls_make_url(c,pls->url, sizeof(pls->url), base, url); if (!pls->url[0]) { av_packet_free(&pls->pkt); av_free(pls); @@ -411,7 +431,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) { @@ -428,7 +448,7 @@ static struct segment *new_init_section(struct playlist *pls, if (!av_strncasecmp(info->uri, "data:", 5)) { ptr = info->uri; } else { - ff_make_absolute_url(tmp_str, sizeof(tmp_str), url_base, info->uri); + hls_make_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; @@ -876,7 +896,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_make_url(c,tmp_str, sizeof(tmp_str), url, key); if (!tmp_str[0]) { av_free(cur_init_section); ret = AVERROR_INVALIDDATA; @@ -948,7 +968,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_make_url(c,tmp_str, sizeof(tmp_str), url, key); if (!tmp_str[0]) { ret = AVERROR_INVALIDDATA; av_free(seg); @@ -964,7 +984,7 @@ static int parse_playlist(HLSContext *c, const char *url, seg->key = NULL; } - ff_make_absolute_url(tmp_str, sizeof(tmp_str), url, line); + hls_make_url(c,tmp_str, sizeof(tmp_str), url, line); if (!tmp_str[0]) { ret = AVERROR_INVALIDDATA; if (seg->key) @@ -2548,6 +2568,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 = 0}, 0, 1, FLAGS}, {NULL} };