From patchwork Wed Sep 28 10:48:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38436 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp121848pzh; Wed, 28 Sep 2022 03:49:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7uIC6bXEdnW5Qaxa9hGYZBsgOmGqvvMorNx3Ptlux5X9I3QHpTyznYjlxqMNMZ+zzkr0U9 X-Received: by 2002:aa7:d5cc:0:b0:456:f5f1:540 with SMTP id d12-20020aa7d5cc000000b00456f5f10540mr22250281eds.95.1664362187678; Wed, 28 Sep 2022 03:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664362187; cv=none; d=google.com; s=arc-20160816; b=0NKV/dc19UhoX1n/AR/oKl4UrWCIZSuHKL2BjHneWLvwOLxcQFfQTuPINU3wBzSEQ1 wgcMXC9sU5ZYtNIzd8kn5vn4JX1C59ZbUIVoY/4cGz6iCtU242Ya5yLOye7eYnBNcijg 4Kigx6A4+DatO9h5TtrMtNxaomuPKgTHZAWv5kH9aMZiuSCjx/WdQPA1yAeIybuDb/hx N9Uce3lDHdSyAf5HaXr8viF9RGh8PHYOjlzYKyu4eBaFOAguhZJfOm+SNneLT3h1EHNP FWMeQE1gRvEXKLX0woj4Fe422/YUsN32SukuOVZxmsBhYUJP3gXOae5sMhMV+D3CMeg1 5TUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=13q5jSkEG/gnCNeTcP7GPibLwcAohGRWNUG8dv5Q+HE=; b=koTKbOf8d+voPQdtSxK+r0C6tEkC9Ug9+Zkf9w8dohp2QuDi4sxVQwYAVgTl4jiPfR OF+JW9qeC9dCrZp/Al4nDyhVHgE3sc0At97pkp2q3nnLLHXSNAQnj+Da8HEpPCMTCYF6 5e9hTtgAF/Vj2gVoBj/PTR6MPcxLB4BoAbchMhe6iTdU1/pCBM7wM0bp3eSL1bpusw85 cSKN5M5MTllSNj5KA0urgxTuUDgBTaNhyvnsYT84jULhUgsDBveBWuC2oivTZo6PuynZ KmZ6bFjSl17XaZtmQIakp6thpDHkNPY9pvK8DkttRWJV28pdCHcB4EsTRWo8nrJfJx2o MLhA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t2-20020a056402524200b00457c9eddd10si3898866edd.617.2022.09.28.03.49.47; Wed, 28 Sep 2022 03:49:47 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1A9F668BC07; Wed, 28 Sep 2022 13:49:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0CB0B68BA2F for ; Wed, 28 Sep 2022 13:49:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 999032404E4 for ; Wed, 28 Sep 2022 12:49:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NhvAk49Ia3n1 for ; Wed, 28 Sep 2022 12:48:59 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id C78302404F5 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9F1173A0DA0 for ; Wed, 28 Sep 2022 12:48:57 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 12:48:52 +0200 Message-Id: <20220928104854.18629-4-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220928104854.18629-1-anton@khirnov.net> References: <20220928104854.18629-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/6] lavfi: replace av_fast_realloc() with av_realloc_reuse() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AL4ymDf9L5xf --- libavfilter/af_adelay.c | 4 ++-- libavfilter/asrc_afirsrc.c | 12 ++++++------ libavfilter/avf_showspectrum.c | 8 ++++---- libavfilter/f_drawgraph.c | 18 +++++++++--------- libavfilter/f_graphmonitor.c | 8 ++++---- libavfilter/f_reverse.c | 16 ++++++++-------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/libavfilter/af_adelay.c b/libavfilter/af_adelay.c index 9e63e2d618..6eb2aa400c 100644 --- a/libavfilter/af_adelay.c +++ b/libavfilter/af_adelay.c @@ -31,7 +31,7 @@ typedef struct ChanDelay { int64_t delay; size_t delay_index; size_t index; - unsigned int samples_size; + size_t samples_size; uint8_t *samples; } ChanDelay; @@ -116,7 +116,7 @@ static int resize_samples_## name ##p(ChanDelay *d, int64_t new_delay) return 0; \ } \ \ - samples = (type *) av_fast_realloc(d->samples, &d->samples_size, new_delay * sizeof(type)); \ + samples = (type *) av_realloc_reuse(d->samples, &d->samples_size, new_delay * sizeof(type)); \ if (!samples) { \ return AVERROR(ENOMEM); \ } \ diff --git a/libavfilter/asrc_afirsrc.c b/libavfilter/asrc_afirsrc.c index 615242e0f5..ad65b7498b 100644 --- a/libavfilter/asrc_afirsrc.c +++ b/libavfilter/asrc_afirsrc.c @@ -43,9 +43,9 @@ typedef struct AudioFIRSourceContext { float *freq; float *magnitude; float *phase; - int freq_size; - int magnitude_size; - int phase_size; + size_t freq_size; + size_t magnitude_size; + size_t phase_size; int nb_freq; int nb_magnitude; int nb_phase; @@ -126,12 +126,12 @@ static av_cold int query_formats(AVFilterContext *ctx) return ff_set_common_samplerates_from_list(ctx, sample_rates); } -static int parse_string(char *str, float **items, int *nb_items, int *items_size) +static int parse_string(char *str, float **items, int *nb_items, size_t *items_size) { float *new_items; char *tail; - new_items = av_fast_realloc(NULL, items_size, 1 * sizeof(float)); + new_items = av_realloc_reuse(NULL, items_size, 1 * sizeof(float)); if (!new_items) return AVERROR(ENOMEM); *items = new_items; @@ -142,7 +142,7 @@ static int parse_string(char *str, float **items, int *nb_items, int *items_size do { (*items)[(*nb_items)++] = av_strtod(tail, &tail); - new_items = av_fast_realloc(*items, items_size, (*nb_items + 1) * sizeof(float)); + new_items = av_realloc_reuse(*items, items_size, (*nb_items + 1) * sizeof(float)); if (!new_items) return AVERROR(ENOMEM); *items = new_items; diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c index b111471116..a9ee8458f3 100644 --- a/libavfilter/avf_showspectrum.c +++ b/libavfilter/avf_showspectrum.c @@ -114,7 +114,7 @@ typedef struct ShowSpectrumContext { AVFrame **frames; unsigned int nb_frames; - unsigned int frames_size; + size_t frames_size; } ShowSpectrumContext; #define OFFSET(x) offsetof(ShowSpectrumContext, x) @@ -1300,8 +1300,8 @@ static int config_output(AVFilterLink *outlink) if (!s->in_frame) return AVERROR(ENOMEM); - s->frames = av_fast_realloc(NULL, &s->frames_size, - DEFAULT_LENGTH * sizeof(*(s->frames))); + s->frames = av_realloc_reuse(NULL, &s->frames_size, + DEFAULT_LENGTH * sizeof(*(s->frames))); if (!s->frames) return AVERROR(ENOMEM); @@ -1840,7 +1840,7 @@ static int showspectrumpic_filter_frame(AVFilterLink *inlink, AVFrame *insamples void *ptr; if (s->nb_frames + 1ULL > s->frames_size / sizeof(*(s->frames))) { - ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2); + ptr = av_realloc_reuse(s->frames, &s->frames_size, s->frames_size * 2); if (!ptr) return AVERROR(ENOMEM); s->frames = ptr; diff --git a/libavfilter/f_drawgraph.c b/libavfilter/f_drawgraph.c index 000255fc52..f616bd2c04 100644 --- a/libavfilter/f_drawgraph.c +++ b/libavfilter/f_drawgraph.c @@ -49,7 +49,7 @@ typedef struct DrawGraphContext { int prev_y[4]; int first[4]; float *values[4]; - int values_size[4]; + size_t values_size[4]; int nb_values; int64_t prev_pts; } DrawGraphContext; @@ -114,10 +114,10 @@ static av_cold int init(AVFilterContext *ctx) s->first[0] = s->first[1] = s->first[2] = s->first[3] = 1; if (s->slide == 4) { - s->values[0] = av_fast_realloc(NULL, &s->values_size[0], 2000); - s->values[1] = av_fast_realloc(NULL, &s->values_size[1], 2000); - s->values[2] = av_fast_realloc(NULL, &s->values_size[2], 2000); - s->values[3] = av_fast_realloc(NULL, &s->values_size[3], 2000); + s->values[0] = av_realloc_reuse(NULL, &s->values_size[0], 2000); + s->values[1] = av_realloc_reuse(NULL, &s->values_size[1], 2000); + s->values[2] = av_realloc_reuse(NULL, &s->values_size[2], 2000); + s->values[3] = av_realloc_reuse(NULL, &s->values_size[3], 2000); if (!s->values[0] || !s->values[1] || !s->values[2] || !s->values[3]) { @@ -174,22 +174,22 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) if (s->slide == 4 && s->nb_values >= s->values_size[0] / sizeof(float)) { float *ptr; - ptr = av_fast_realloc(s->values[0], &s->values_size[0], s->values_size[0] * 2); + ptr = av_realloc_reuse(s->values[0], &s->values_size[0], s->values_size[0] * 2); if (!ptr) return AVERROR(ENOMEM); s->values[0] = ptr; - ptr = av_fast_realloc(s->values[1], &s->values_size[1], s->values_size[1] * 2); + ptr = av_realloc_reuse(s->values[1], &s->values_size[1], s->values_size[1] * 2); if (!ptr) return AVERROR(ENOMEM); s->values[1] = ptr; - ptr = av_fast_realloc(s->values[2], &s->values_size[2], s->values_size[2] * 2); + ptr = av_realloc_reuse(s->values[2], &s->values_size[2], s->values_size[2] * 2); if (!ptr) return AVERROR(ENOMEM); s->values[2] = ptr; - ptr = av_fast_realloc(s->values[3], &s->values_size[3], s->values_size[3] * 2); + ptr = av_realloc_reuse(s->values[3], &s->values_size[3], s->values_size[3] * 2); if (!ptr) return AVERROR(ENOMEM); s->values[3] = ptr; diff --git a/libavfilter/f_graphmonitor.c b/libavfilter/f_graphmonitor.c index 016a707a27..3f0f35ea68 100644 --- a/libavfilter/f_graphmonitor.c +++ b/libavfilter/f_graphmonitor.c @@ -57,7 +57,7 @@ typedef struct GraphMonitorContext { uint8_t bg[4]; CacheItem *cache; - unsigned int cache_size; + size_t cache_size; unsigned int cache_index; } GraphMonitorContext; @@ -119,8 +119,8 @@ static av_cold int init(AVFilterContext *ctx) { GraphMonitorContext *s = ctx->priv; - s->cache = av_fast_realloc(NULL, &s->cache_size, - 8192 * sizeof(*(s->cache))); + s->cache = av_realloc_reuse(NULL, &s->cache_size, + 8192 * sizeof(*(s->cache))); if (!s->cache) return AVERROR(ENOMEM); @@ -314,7 +314,7 @@ static int draw_items(AVFilterContext *ctx, AVFrame *out, s->cache[s->cache_index].previous_pts_us = l->current_pts_us; if (s->cache_index + 1 >= s->cache_size / sizeof(*(s->cache))) { - void *ptr = av_fast_realloc(s->cache, &s->cache_size, s->cache_size * 2); + void *ptr = av_realloc_reuse(s->cache, &s->cache_size, s->cache_size * 2); if (!ptr) return AVERROR(ENOMEM); diff --git a/libavfilter/f_reverse.c b/libavfilter/f_reverse.c index 2c99557c75..301f36d823 100644 --- a/libavfilter/f_reverse.c +++ b/libavfilter/f_reverse.c @@ -31,8 +31,8 @@ typedef struct ReverseContext { int nb_frames; AVFrame **frames; - unsigned int frames_size; - unsigned int pts_size; + size_t frames_size; + size_t pts_size; int64_t *pts; int flush_idx; int64_t nb_samples; @@ -42,13 +42,13 @@ static av_cold int init(AVFilterContext *ctx) { ReverseContext *s = ctx->priv; - s->pts = av_fast_realloc(NULL, &s->pts_size, - DEFAULT_LENGTH * sizeof(*(s->pts))); + s->pts = av_realloc_reuse(NULL, &s->pts_size, + DEFAULT_LENGTH * sizeof(*(s->pts))); if (!s->pts) return AVERROR(ENOMEM); - s->frames = av_fast_realloc(NULL, &s->frames_size, - DEFAULT_LENGTH * sizeof(*(s->frames))); + s->frames = av_realloc_reuse(NULL, &s->frames_size, + DEFAULT_LENGTH * sizeof(*(s->frames))); if (!s->frames) { av_freep(&s->pts); return AVERROR(ENOMEM); @@ -77,14 +77,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) void *ptr; if (s->nb_frames + 1 > s->pts_size / sizeof(*(s->pts))) { - ptr = av_fast_realloc(s->pts, &s->pts_size, s->pts_size * 2); + ptr = av_realloc_reuse(s->pts, &s->pts_size, s->pts_size * 2); if (!ptr) return AVERROR(ENOMEM); s->pts = ptr; } if (s->nb_frames + 1 > s->frames_size / sizeof(*(s->frames))) { - ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2); + ptr = av_realloc_reuse(s->frames, &s->frames_size, s->frames_size * 2); if (!ptr) return AVERROR(ENOMEM); s->frames = ptr;