From patchwork Tue Apr 12 08:15:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 35278 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:671c:b0:7c:62c8:b2d1 with SMTP id q28csp1454252pzh; Tue, 12 Apr 2022 01:15:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdiDIYz9FNWe9uV5nn8SZE+lYXkNtK+p0s6PRxw3yGRBCuElRc1k11qwunssoQk20sHDD/ X-Received: by 2002:a17:907:6e88:b0:6da:8f01:7a8f with SMTP id sh8-20020a1709076e8800b006da8f017a8fmr33839471ejc.619.1649751358120; Tue, 12 Apr 2022 01:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649751358; cv=none; d=google.com; s=arc-20160816; b=fAZ7VomdDwAlbqc3LdT2h8PDxEtL9kzDnQgC/PwRRON0whtzYAMasJj2fgzXywShsO Cwmek5zdXb8VhMWo+BQ+X6WsBqQwosGpBB1W6p+oZGEMCwqkQekql58YgqY3XhynchmO rf+b/ID8+oZFB08jL9JOs54Jp5X/N9HiKweHG8KnJXqAR4S+eLN0P8U48n7PbTlOl96l TNksxTkvQoxwwW0PkCvPBVEdo0mKg7ALl0SH6hvJb7kpsxTAPpBb5C8Kr9rmvU4ov3Ct zpS4MQlj+NDyBxIEOAsJmv8B15x5neDITQgOullu3QgFdp4RUxixutxrplfmFSPU53ff Cg5A== 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:date:to:from:message-id :dkim-signature:delivered-to; bh=A7Nu2rZsZQL7yAF7okpntgrGpWRLMx0XE8AZtT7SVcM=; b=zuDg93JyX/8yKHXJJsm6JIGpPaVaaQZXzCx2uDGgAQ5O9osBPtny1H123SWD7aNYJd 79LgYQXeB1GiFcEmzJ7YacvJYUaEmFKdkJkHfxOoGRbc3n/nwpp/A0N0HUP1Uu4fX8Is FO79IK/Q65LjyRZphwYaHk3ueMBJB+wS1YjAzyAERRObLjpSOBryh47lUNHgldUmVLBg AAj+P8WSLHQ6Ji8vbpDTjYOhLbo7gGyD8nwEfr9HQPp4zKuaO+A0zhKWG5iGax+WtG3X aDwjeYJbohcRd/Df9lqsGuO5IvS7yE4U6QU8PI72H0ENLP9YnYFX/gGKdFVfUTfFUVke Muvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=ZGE96sQJ; 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=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id bm11-20020a170906c04b00b006df76385d9bsi8402079ejb.571.2022.04.12.01.15.56; Tue, 12 Apr 2022 01:15:58 -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=@foxmail.com header.s=s201512 header.b=ZGE96sQJ; 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=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 15E6E68B382; Tue, 12 Apr 2022 11:15:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-221-221.mail.qq.com (out203-205-221-221.mail.qq.com [203.205.221.221]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E894568B370 for ; Tue, 12 Apr 2022 11:15:42 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1649751336; bh=xvYN4AveD0wkK9kbEi9953kcWFSiiXYy7Xn9Q19TNF8=; h=From:To:Cc:Subject:Date; b=ZGE96sQJ9UVO7lc5Dws5ZFrbLjNGe/i6FirsRnfoFia/CTPCKuPwvght153/5P5W1 ElVeYaQr+QJfdDwwk70OVLX2rhWnWCG5sUbkbEf4SdpU6n2se2SPgN5LmkjzDF4eKP q8PK7Go7HnAkbEV6v/PFG6VMw2SPBSGArylhjuDI= Received: from ZHILIZHAO-MB2.tencent.com ([113.108.77.68]) by newxmesmtplogicsvrsza8.qq.com (NewEsmtp) with SMTP id 3E314CF9; Tue, 12 Apr 2022 16:15:35 +0800 X-QQ-mid: xmsmtpt1649751335txoae7y1k Message-ID: X-QQ-XMAILINFO: OZZSS56D9fAjm3Ewc3sGagZq8X4QawDMMgAzzK3tKPkxhiCp+L5JPvrgyEp7iS h2SCQs8GCqwfW62Zxis5VNNjrpkJU1gWHIXOlh3lTQ3eNDrHgZQ4ZzDjSE8q7zghz+1gA8JcNhhs prjqAElcS/dM/TFdtUtXygpBWgmWX6wYgWVIkF0StgQjRaaAeuUIgcKmT8UBqTtxsMvfG9M5WBlD IBv4Vglb4KANEoIaHFAzxWNxRzyngHtoeV7Bw/GDFMV1jF6IoMOGV6y4Onnq6VtRrh7Cz8szMnIj y5t7cOwo6p3ytKLON1BOe843rL0odIBRrAsJykedaU1gSmJfHQcLj6f5KWIuuIF5NILLNBFN+EHF OHtmdL59u+5cWhAsMIwXy5Q/BNGc6DKNMPVkk1KCHkVaLjjMD/bKI6lkzq6dEvOG10w51iCCDlxT a8BFMXwAR+FMcxPT4i9AM0eYFROTWTaH13X1xrm2hBPEOZtrTuPp3QGExZPt5gDkA/x2K0QqQb3I K4V+auUSpneBSeD7qXzNDXu8T8H4yto2dlzPEm0yzmlEDYORrK57FMouXf+ihiPXXrBIF2cMW0fr BivN1oVHsvFaaMUuzhkwMJA8mTi36eBRbORT8PMVHqGw+jBvlTN/yTDX5eUIS7BnRP0gOu0Mu7dP liNkzPClN5yuvtNTAooOdfCDSTXyKNCimkJAYgT3HMdTZN59mWPI19Z/C0C+fjW1NeKtlJ10iQRt yefE/Ce4RsuZ0MGScFPPyvPvJCcOhFYX9WV9u1LF4nrRVAhCiyppgZGZQNug7fk9Gj2yzvk7oVkN FzSczvV+ETxlfzErqfXinLjlWWoxx2cstVIsrgdfmHHqVOYJuPES8lGhhHiNhk+avQ13DMwIsCdX 4b7uQwket3oKMxZm+/waqzQuY/nHIykrJqroYZuvjjWy418Bd1MmaNmBWTPCGHKQ== From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Apr 2022 16:15:13 +0800 X-OQ-MSGID: <20220412081522.43246-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/10] avformat/hls: fix repeated requests for media init section 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: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 0u3Kfsa7ID3n --- libavformat/hls.c | 59 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 83ff4cc607..67c9650e0b 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -407,48 +407,65 @@ struct init_section_info { char byterange[32]; }; -static struct segment *new_init_section(struct playlist *pls, +/* + * Return a new init section if info is new, otherwise return an entry + * from pls->init_sections. + */ +static struct segment *get_init_section(struct playlist *pls, struct init_section_info *info, - const char *url_base) + const char *url_base, + int *new_init) { - struct segment *sec; + struct segment *sec_ptr = NULL; + struct segment sec = {}; char tmp_str[MAX_URL_SIZE], *ptr = tmp_str; + *new_init = 1; if (!info->uri[0]) return NULL; - sec = av_mallocz(sizeof(*sec)); - if (!sec) - return NULL; - if (!av_strncasecmp(info->uri, "data:", 5)) { ptr = info->uri; } else { ff_make_absolute_url(tmp_str, sizeof(tmp_str), url_base, info->uri); if (!tmp_str[0]) { - av_free(sec); return NULL; } } - sec->url = av_strdup(ptr); - if (!sec->url) { - av_free(sec); - return NULL; - } + // Don't dup until make sure it's a new initialization section + sec.url = ptr; if (info->byterange[0]) { - sec->size = strtoll(info->byterange, NULL, 10); + sec.size = strtoll(info->byterange, NULL, 10); ptr = strchr(info->byterange, '@'); if (ptr) - sec->url_offset = strtoll(ptr+1, NULL, 10); + sec.url_offset = strtoll(ptr+1, NULL, 10); } else { /* the entire file is the init section */ - sec->size = -1; + sec.size = -1; } - dynarray_add(&pls->init_sections, &pls->n_init_sections, sec); + for (int i = 0; i < pls->n_init_sections; i++) { + sec_ptr = pls->init_sections[i]; + if (!strcmp(sec_ptr->url, sec.url) && + sec_ptr->size == sec.size && + sec_ptr->url_offset == sec.url_offset) { + *new_init = 0; + return sec_ptr; + } + } + + sec_ptr = av_malloc(sizeof(*sec_ptr)); + if (!sec_ptr) return NULL; + *sec_ptr = sec; + sec_ptr->url = av_strdup(ptr); + if (!sec_ptr->url) { + av_free(sec_ptr); + return NULL; + } + dynarray_add(&pls->init_sections, &pls->n_init_sections, sec_ptr); - return sec; + return sec_ptr; } static void handle_init_section_args(struct init_section_info *info, const char *key, @@ -851,13 +868,17 @@ static int parse_playlist(HLSContext *c, const char *url, else if (!strcmp(ptr, "VOD")) pls->type = PLS_TYPE_VOD; } else if (av_strstart(line, "#EXT-X-MAP:", &ptr)) { + int new_init = 1; struct init_section_info info = {{0}}; ret = ensure_playlist(c, &pls, url); if (ret < 0) 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 = get_init_section(pls, &info, url, &new_init); + /* Skip if it's the same init section */ + if (!new_init) + continue; if (!cur_init_section) { ret = AVERROR(ENOMEM); goto fail;