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 EBA254A1B4 for ; Thu, 23 May 2024 00:56:41 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6647568D416; Thu, 23 May 2024 03:56:38 +0300 (EEST) Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AB70568D274 for ; Thu, 23 May 2024 03:56:31 +0300 (EEST) Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-56e56ee8d5cso12282259a12.2 for ; Wed, 22 May 2024 17:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716425791; x=1717030591; darn=ffmpeg.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=bumX4lpHYQsyajFaIBuONhHoPJVNcZXfHND/NodhgOI=; b=IlqycTz1K0M4lsYb2myl4VQjqL4Ju/npgPzOMc6rI1FAJorIYJ8wEnpCMX8Oq0OUcF myrubbEpXv+TTYO98O/2KckdXtZt60LLDI8ViEfjC9wxQH2GKh11LsAYAOx1W2K8B5tM iJisUiZPQG20ul0mmvx2aXKYd4IkdOMgzfkYEqfDAiCc0Eb2bk7qUJEkleeHG6DvXpvf ImiDVvPH4C5kkifJf4W6UyAoJk/BarrHw/Q1KnMK0kQyNVTWOCJBkyVvqIJRWp68uQiI Bz+gRoi5wiUB/8DTbyL54o0KFE3VMTlTBpNodZN1AKULgXd4eMOlDh9sF4pOkduN8Agr elnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716425791; x=1717030591; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bumX4lpHYQsyajFaIBuONhHoPJVNcZXfHND/NodhgOI=; b=iifJ1IFb2G+9LgpMRMFqQ9kexgAu1LftMkSgrfCw+sYaq6GT4OJpF+kRjCKG/gtoXQ DKbQhJjfd4fFnvMIxi+YTqs/yqghS6Tkk5F2KJ2GGLBxJT3Pb+NveJVe9lITG8GT8vZt xLGHWjF1dLtE6oR0sO3FuEVmU1NHm3gj/HUR1synEpvUDeUcqQLuQPPEavesSx53Mp1I 855lGLcFaO0KZslZ5wOicAINCnwq3fUqtOHf0UIn+RwR9fAV3BnZvgSHATy03O2AJ6rJ NEmMVu+L0bQtEs6d25Qd6UjsgZSYixqs+bz/5ffC0cpLDwLtqfF5UwLtqC87URE9hy1I vJog== X-Gm-Message-State: AOJu0YyEOQYTdVWaqgEK9EMPx/DgXzYnOgx5U7qvQgdINAFrlVv5lAQk oO2GMPYzjzfppVluDwoeqjPg7szvJyBrO+TIGh5Ox2ObsO3c7JRhcXsHB7Z4ITfIOWkMJDz56RK D5X5P0axTllOfJS+SDC/dMPkGh1Te9Q== X-Google-Smtp-Source: AGHT+IE2wfBcWF/qOuXw7/nw2mb7fT6/2B5RnK0qe3+bmwG6qf2rh7yjMOjbjBTRv37a03+9z8Z2Mo+B2fLkISQtMlU= X-Received: by 2002:a17:906:fb0a:b0:a59:c220:16a5 with SMTP id a640c23a62f3a-a6227e3e13dmr228591366b.9.1716425790491; Wed, 22 May 2024 17:56:30 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Pavel Koshevoy Date: Wed, 22 May 2024 18:56:21 -0600 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] [PATCH 2/5] avfilter/af_atempo: Simplify resetting 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-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 Wed, May 22, 2024, 02:59 Andreas Rheinhardt < andreas.rheinhardt@outlook.com> wrote: > The earlier code distinguished between a partial reset > (yae_clear()) and a complete reset (yae_release_buffers() > which also releases the buffers); this separation existed > to avoid allocations, as buffers were reallocated on reconfigs. > > Yet it is pointless since a5704659e3e41b7698812b89f67d9a7467a74d20, > so simply use yae_release_buffers() everywhere. > > Signed-off-by: Andreas Rheinhardt > --- > libavfilter/af_atempo.c | 69 +++++++++++++++++++++-------------------- > 1 file changed, 35 insertions(+), 34 deletions(-) > > diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c > index 1aedb82060..110f792eec 100644 > --- a/libavfilter/af_atempo.c > +++ b/libavfilter/af_atempo.c > @@ -244,18 +244,6 @@ static void yae_release_buffers(ATempoContext *atempo) > av_tx_uninit(&atempo->complex_to_real); > } > > -/* av_realloc is not aligned enough; fortunately, the data does not need > to > - * be preserved */ > -#define RE_MALLOC_OR_FAIL(field, field_size, element_size) \ > - do { \ > - av_freep(&field); \ > - field = av_calloc(field_size, element_size); \ > - if (!field) { \ > - yae_release_buffers(atempo); \ > - return AVERROR(ENOMEM); \ > - } \ > - } while (0) > - > /** > * Prepare filter for processing audio data of given format, > * sample rate and number of channels. > @@ -289,40 +277,51 @@ static int yae_reset(ATempoContext *atempo, > nlevels++; > } > > + /* av_realloc is not aligned enough, so simply discard all the old > buffers > + * (fortunately, their data does not need to be preserved) */ > + yae_release_buffers(atempo); > + > // initialize audio fragment buffers: > - RE_MALLOC_OR_FAIL(atempo->frag[0].data, atempo->window, > atempo->stride); > - RE_MALLOC_OR_FAIL(atempo->frag[1].data, atempo->window, > atempo->stride); > - RE_MALLOC_OR_FAIL(atempo->frag[0].xdat_in, (atempo->window + 1), > sizeof(AVComplexFloat)); > - RE_MALLOC_OR_FAIL(atempo->frag[1].xdat_in, (atempo->window + 1), > sizeof(AVComplexFloat)); > - RE_MALLOC_OR_FAIL(atempo->frag[0].xdat, (atempo->window + 1), > sizeof(AVComplexFloat)); > - RE_MALLOC_OR_FAIL(atempo->frag[1].xdat, (atempo->window + 1), > sizeof(AVComplexFloat)); > + if (!(atempo->frag[0].data = av_calloc(atempo->window, > atempo->stride)) || > + !(atempo->frag[1].data = av_calloc(atempo->window, > atempo->stride)) || > + !(atempo->frag[0].xdat_in = av_calloc(atempo->window + 1, > sizeof(AVComplexFloat))) || > + !(atempo->frag[1].xdat_in = av_calloc(atempo->window + 1, > sizeof(AVComplexFloat))) || > + !(atempo->frag[0].xdat = av_calloc(atempo->window + 1, > sizeof(AVComplexFloat))) || > + !(atempo->frag[1].xdat = av_calloc(atempo->window + 1, > sizeof(AVComplexFloat)))) { > + ret = AVERROR(ENOMEM); > + goto fail; > + } > > // initialize rDFT contexts: > - av_tx_uninit(&atempo->real_to_complex); > - av_tx_uninit(&atempo->complex_to_real); > - > ret = av_tx_init(&atempo->real_to_complex, &atempo->r2c_fn, > AV_TX_FLOAT_RDFT, 0, 1 << (nlevels + 1), &scale, 0); > - if (ret < 0) { > - yae_release_buffers(atempo); > - return ret; > - } > + if (ret < 0) > + goto fail; > > ret = av_tx_init(&atempo->complex_to_real, &atempo->c2r_fn, > AV_TX_FLOAT_RDFT, 1, 1 << (nlevels + 1), &iscale, 0); > - if (ret < 0) { > - yae_release_buffers(atempo); > - return ret; > - } > + if (ret < 0) > + goto fail; > > - RE_MALLOC_OR_FAIL(atempo->correlation_in, (atempo->window + 1), > sizeof(AVComplexFloat)); > - RE_MALLOC_OR_FAIL(atempo->correlation, atempo->window, > sizeof(AVComplexFloat)); > + if (!(atempo->correlation_in = av_calloc(atempo->window + 1, > sizeof(AVComplexFloat))) || > + !(atempo->correlation = av_calloc(atempo->window, > sizeof(AVComplexFloat)))) { > + ret = AVERROR(ENOMEM); > + goto fail; > + } > > atempo->ring = atempo->window * 3; > - RE_MALLOC_OR_FAIL(atempo->buffer, atempo->ring, atempo->stride); > + atempo->buffer = av_calloc(atempo->ring, atempo->stride); > + if (!atempo->buffer) { > + ret = AVERROR(ENOMEM); > + goto fail; > + } > > // initialize the Hann window function: > - RE_MALLOC_OR_FAIL(atempo->hann, atempo->window, sizeof(float)); > + atempo->hann = av_malloc_array(atempo->window, sizeof(float)); > + if (!atempo->hann) { > + ret = AVERROR(ENOMEM); > + goto fail; > + } > > for (i = 0; i < atempo->window; i++) { > double t = (double)i / (double)(atempo->window - 1); > @@ -330,8 +329,10 @@ static int yae_reset(ATempoContext *atempo, > atempo->hann[i] = (float)h; > } > > - yae_clear(atempo); > return 0; > +fail: > + yae_release_buffers(atempo); > + return ret; > } > > static int yae_update(AVFilterContext *ctx) > -- > 2.40.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". > This doesn't feel like a necessary change (how frequently is the affected code actually traversed, realistically?)... but since you've already spent the effort to make this change I have no objection. Pavel > _______________________________________________ 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".