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 5DBE240242 for ; Mon, 20 Dec 2021 00:00:39 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8453D68AEE9; Mon, 20 Dec 2021 02:00:37 +0200 (EET) Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 508F868ADD0 for ; Mon, 20 Dec 2021 02:00:31 +0200 (EET) Received: by mail-qk1-f173.google.com with SMTP id t83so7871147qke.8 for ; Sun, 19 Dec 2021 16:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=ps1/RRRHerv3qLfFJmx23yqJSM+QiVM+R2Vf3o9C07A=; b=noEttJNnwYAReSCyTThlcFK0Q60ZNmr4n9QFq8ilpoTUfHYjUzhYNv0k7MSd6zQbEA z5SDSCzJHyYuuqcof65nAotMpRLbIEtnokJfHxuTAedd0YB/VtgDsoOeUv+uCZOdD26Q s8JtVm54/wI+NmL0wAvOn6AwafmJ2Bh4reHWZG7DHH2s8LakqFtkyRzAY5+/j7dhIGH0 hkYn/XeDo5DBwnSVV04I8fiL5tafhB7fGdlODIsFYrfN8/dw0AcZJQpLoBe2zgF0tRiY I8yilya7Tkz6MTv85aob8YsZTwvqdtYO+a0uYjm517+6hzkE/yIQUbyKt+NUWBOzEybT FfeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=ps1/RRRHerv3qLfFJmx23yqJSM+QiVM+R2Vf3o9C07A=; b=4VSFLop/8GOO/FPGH9tgshkSNZtun1e6/rDKxlc+pmqQkbgGT764OCsLp+MTtntfaj lzb1JGD5mjyUlykGpSUh8wrpcznYV/CS+3ZcPKQ1I933efJ9emITh0l7igiW63eImrVL O8FY03h2xOFd1MAsogU5p4d0Qym308GUUXNT/6vnk1yolfrOO1fNYw7HCYf9hsOsGbt8 rEhZk903dneiSFSOdakFTWsGuXVcTi4Qx/arNSdcyoAeNJ1MvXEf8ZaMoAT+zcIEz+Hl 3CyMILgeV7oahK65ii0kqIIVrxzMnNrJo74m99Mmhx5CU0VYuv5TnoOUar/mpfvVVd/u HetQ== X-Gm-Message-State: AOAM532LYlBg7cDR9SoYw1jYNYIqlDL1o0AyfgFA6Hkbe/6DIzMXXEu/ iPXO3i3c1U1jK8weOZqf37Ngfwx4mJXDhA== X-Google-Smtp-Source: ABdhPJzbXLk+iPWEIKv1+q4nrRvIcOxKuo7DzTRNqCD21XS5jwqO6CtDyA+bnEESfvJas3Ja/tvhOA== X-Received: by 2002:a05:620a:4156:: with SMTP id k22mr8077639qko.636.1639958429683; Sun, 19 Dec 2021 16:00:29 -0800 (PST) Received: from [192.168.0.13] ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id h22sm9653017qkk.14.2021.12.19.16.00.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 Dec 2021 16:00:29 -0800 (PST) Message-ID: <1cb14cd4-ba85-ec5b-4969-0e7c6b13b7b0@gmail.com> Date: Sun, 19 Dec 2021 21:00:27 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20211219235700.16595-1-michael@niedermayer.cc> From: James Almer In-Reply-To: <20211219235700.16595-1-michael@niedermayer.cc> Subject: Re: [FFmpeg-devel] [PATCH 1/3] avcodec/ass: Faster ff_ass_add_rect() 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 12/19/2021 8:56 PM, Michael Niedermayer wrote: > Signed-off-by: Michael Niedermayer > --- > libavcodec/ass.c | 33 +++++++++++++++++++++++++++------ > libavcodec/ass.h | 7 +++++++ > 2 files changed, 34 insertions(+), 6 deletions(-) > > diff --git a/libavcodec/ass.c b/libavcodec/ass.c > index 725e4d42ba1..06714678722 100644 > --- a/libavcodec/ass.c > +++ b/libavcodec/ass.c > @@ -114,17 +114,31 @@ char *ff_ass_get_dialog(int readorder, int layer, const char *style, > speaker ? speaker : "", text); > } > > -int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, > +int ff_ass_add_rect2(AVSubtitle *sub, const char *dialog, > int readorder, int layer, const char *style, > - const char *speaker) > + const char *speaker, unsigned *nb_rect_allocated) > { > - AVSubtitleRect **rects, *rect; > + AVSubtitleRect **rects = sub->rects, *rect; > char *ass_str; > + uint64_t new_nb = 0; > > - rects = av_realloc_array(sub->rects, sub->num_rects+1, sizeof(*sub->rects)); > - if (!rects) > + if (sub->num_rects >= UINT_MAX) > return AVERROR(ENOMEM); > - sub->rects = rects; > + > + if (nb_rect_allocated && *nb_rect_allocated <= sub->num_rects) { > + new_nb = FFMIN(sub->num_rects + sub->num_rects/16LL + 1, UINT_MAX); Isn't this what av_fast_realloc() is for? > + } else if (!nb_rect_allocated) > + new_nb = sub->num_rects + 1LL; > + > + if (new_nb) { > + rects = av_realloc_array(rects, new_nb, sizeof(*sub->rects)); > + if (!rects) > + return AVERROR(ENOMEM); > + if (nb_rect_allocated) > + *nb_rect_allocated = new_nb; > + sub->rects = rects; > + } > + > rect = av_mallocz(sizeof(*rect)); > if (!rect) > return AVERROR(ENOMEM); > @@ -137,6 +151,13 @@ int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, > return 0; > } > > +int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, > + int readorder, int layer, const char *style, > + const char *speaker) > +{ > + return ff_ass_add_rect2(sub, dialog, readorder, layer, style, speaker, NULL); > +} > + > void ff_ass_decoder_flush(AVCodecContext *avctx) > { > FFASSDecoderContext *s = avctx->priv_data; > diff --git a/libavcodec/ass.h b/libavcodec/ass.h > index 2c260e4e785..4dffe923d9f 100644 > --- a/libavcodec/ass.h > +++ b/libavcodec/ass.h > @@ -118,6 +118,13 @@ int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, > int readorder, int layer, const char *style, > const char *speaker); > > +/** > + * Add an ASS dialog to a subtitle. > + */ > +int ff_ass_add_rect2(AVSubtitle *sub, const char *dialog, > + int readorder, int layer, const char *style, > + const char *speaker, unsigned *nb_rect_allocated); > + > /** > * Helper to flush a text subtitles decoder making use of the > * FFASSDecoderContext. _______________________________________________ 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".