From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C1C7242A54 for ; Tue, 12 Apr 2022 08:15:55 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C367B68B370; Tue, 12 Apr 2022 11:15:51 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- 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; -- 2.31.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".