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 7137442A92 for ; Tue, 12 Apr 2022 11:45:45 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F28368B3EB; Tue, 12 Apr 2022 14:45:42 +0300 (EEST) Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 74B4E68B35E for ; Tue, 12 Apr 2022 14:45:35 +0300 (EEST) Received: by mail-lj1-f177.google.com with SMTP id 17so23730553lji.1 for ; Tue, 12 Apr 2022 04:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=bCH7s6phFUeg2Iq1h0ZMMBQpFR7dD3CTC0wZUqAPV7A=; b=dPY/2l8AhzBRyioMR2rVoaGET+XX/jEoJ3fH5Pz/l60Ri83QQ4GAfvwidsl3x+NSFF ZiaXJZcgNnNyJH4EGsTRLLLAp2m73IrgPOj6Ofx/TncWCdnAqf8BN3NZ3gcXvAIuyiXv M6AUqTbL27wnmnMolkONZK/jabB+wExkbi0dIj6kpp6FF8PGtNZFOK0Ff5eZFU90OQmn /maUNCW3c9tkU67Ze7zwvDz20pmWQvXNtmcglo+8tBa7wRldTc99M9thOM6+DxBqkPp1 4j1MZ+J7qIAf5pnaaTBb9Kaj10mFR+wfdsvTmtu8Lpzi39vs/SlqGQXThsTAo1TJocSF ibwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=bCH7s6phFUeg2Iq1h0ZMMBQpFR7dD3CTC0wZUqAPV7A=; b=fTXqHd+Qkq6Rw+gjdwU0subvoz7sqgjCNGyieuIN92kW5GsxHKbOSIluVzoJEsZPdp A5UZ0G7lLSJB8IwD7bnH2XYNdXImIFPaP9p9zZiBYNRGpchANVgrsb133liekYXa8t69 jHZMThhOeXoTWPs7Req0oC1d4hB1E0vdcoLh9Zlz3Z3yzSZAbWgoHv007kXKI7jIuUq9 zupKTSxW8pQXaHXXU3+uXv0d0o+quvhhsYdGcDKg6yNpECDJ4LZIAFQleaGvvlcgQAny 0e4El/qkoFR340xaFQd1Gkm+xkCAZ4z4zJYznp48ZNFS53w030jzSqVO0K+Q6AgMrMpQ WBLw== X-Gm-Message-State: AOAM5338/PNHaS6PblscNBBFJjkgemvxIhWOKCCYYig0BKh4daOxXvuX XMq+/7IKTsiZfgo4gi6ppixeFzBUBOYCIpqV+zsrbnvoUKM= X-Google-Smtp-Source: ABdhPJwe2fljlGC41DliYekiOm2oMLas6hrzJCEg7sZsxxsGk+SjMFA0ydDbWpR3iFSBBQ/8O8Blv8blyEMnZp2v348= X-Received: by 2002:a05:651c:2003:b0:24b:543e:3e80 with SMTP id s3-20020a05651c200300b0024b543e3e80mr12187536ljo.435.1649763934291; Tue, 12 Apr 2022 04:45:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "mypopy@gmail.com" Date: Tue, 12 Apr 2022 19:45:22 +0800 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [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: On Tue, Apr 12, 2022 at 4:15 PM Zhao Zhili wrote: > > --- > 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 Can these patches handle multiple instances of the media init sections? _______________________________________________ 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".