From patchwork Tue Sep 8 21:18:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22189 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6FC4E44BD83 for ; Wed, 9 Sep 2020 00:19:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5452B68B761; Wed, 9 Sep 2020 00:19:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 31C0E68B74B for ; Wed, 9 Sep 2020 00:19:36 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id g4so688333wrs.5 for ; Tue, 08 Sep 2020 14:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MAw2nAIK/pooL93pBhUq513eyK4MOG8NYPNxOgYLWVA=; b=lAGlPz3rxb/lOKdPluN58YG9+qw9Uk68KG4O8fN5UV0E7boLJ+JBDKKeoEF5Tm0/61 JRQlWH9b7YkO5xSa/0LUDyQxwSof6Q/uGT4XIgKgWdptVex7RMaTvFjb/5n1zLRqp4wP PIersblWL7nkpUauniMFJ7dMDQ4Nb2ph3kDW3bNTcYCGSO5vSv0sfVrXqaUvWU15fucx PadKzVY5G1RVAI5AJvsju4QrGITm5O+69Bb1PheeSEP10wqKpUYQ6/ot1CBTUlz6fTBv fLtCfUpyCv9liTnXzcx4dmmUHAcosgOnjD4n7iAhSmD98EwQZoYy8e50WdeEwkVKNvPE GJJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MAw2nAIK/pooL93pBhUq513eyK4MOG8NYPNxOgYLWVA=; b=ud0ZDD8KXm9ZOVs7mO6qXlZUwveHaRsEBUZm/DCkH5WhkOCcBZsBVZOT+rk5ppBo6a ckyufdb/TgbymOzzjDKamdCVusw6D0GFP8tY0jMjHqAI5HWZvx/tK6kYItCUjsKdgxtg PCS99WpfS/ohWo3/eJCqt29DkoUQe2r0CE5effjHwkOAMLjnFuIyVe+qk0fiM+9gdOOO Hry7mDUAH2nVs5u/kOOHzbCESVxcZf94ZmfSP2EjZQtXIFP/ZinCcpd6vsEDTGAR0aVN 6UowDC/t7rcL5lgxXCyTVIKAafqrS51Z0lvpvLDyPjpNKgzwVuJiM0mrsst7HKjcrTgu JNeA== X-Gm-Message-State: AOAM530ZOBId9eKdCK3IeQliwSfFmjxTjVQitK96rF5Dhen7FrlZPvVu 8f1V4ecP3R1fbw/5qpDdJ+vc0MOGzyQ= X-Google-Smtp-Source: ABdhPJwSoXnm+ZKTi6ENll7riXmSBk+pKtfdcUPxJod/GCEqAVigJFZYApEpRTA7mtaMa9cEdlS8lg== X-Received: by 2002:adf:eacf:: with SMTP id o15mr616179wrn.12.1599599975345; Tue, 08 Sep 2020 14:19:35 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id a15sm1074304wrn.3.2020.09.08.14.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:34 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:46 +0200 Message-Id: <20200908211856.16290-15-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200908211856.16290-1-andreas.rheinhardt@gmail.com> References: <20200908211856.16290-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/25] avfilter/af_headphone: Avoid intermediate buffers II X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" When the headphone filter is configured to perform its processing in the frequency domain, it allocates (among other things) two pairs of buffers, all of the same size. One pair is used to store data in it during the initialization of the filter; the other pair is only allocated lateron. It is zero-initialized and yet its data is immediately overwritten by the content of the other pair of buffers mentioned above; the latter pair is then freed. This commit eliminates the pair of intermediate buffers. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 359174d4b4..fb6af7a966 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -371,8 +371,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) int nb_irs = s->nb_irs; int nb_input_channels = ctx->inputs[0]->channels; float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10); - FFTComplex *data_hrtf_l = NULL; - FFTComplex *data_hrtf_r = NULL; FFTComplex *fft_in_l = NULL; FFTComplex *fft_in_r = NULL; int offset = 0, ret = 0; @@ -439,9 +437,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) goto fail; } } else { - data_hrtf_l = av_calloc(n_fft, sizeof(*data_hrtf_l) * nb_irs); - data_hrtf_r = av_calloc(n_fft, sizeof(*data_hrtf_r) * nb_irs); - if (!data_hrtf_r || !data_hrtf_l) { + s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_irs); + s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_irs); + if (!s->data_hrtf[0] || !s->data_hrtf[1]) { ret = AVERROR(ENOMEM); goto fail; } @@ -488,10 +486,10 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) av_fft_permute(s->fft[0], fft_in_l); av_fft_calc(s->fft[0], fft_in_l); - memcpy(data_hrtf_l + offset, fft_in_l, n_fft * sizeof(*fft_in_l)); + memcpy(s->data_hrtf[0] + offset, fft_in_l, n_fft * sizeof(*fft_in_l)); av_fft_permute(s->fft[0], fft_in_r); av_fft_calc(s->fft[0], fft_in_r); - memcpy(data_hrtf_r + offset, fft_in_r, n_fft * sizeof(*fft_in_r)); + memcpy(s->data_hrtf[1] + offset, fft_in_r, n_fft * sizeof(*fft_in_r)); } } else { int I, N = ctx->inputs[1]->channels; @@ -529,10 +527,10 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) av_fft_permute(s->fft[0], fft_in_l); av_fft_calc(s->fft[0], fft_in_l); - memcpy(data_hrtf_l + offset, fft_in_l, n_fft * sizeof(*fft_in_l)); + memcpy(s->data_hrtf[0] + offset, fft_in_l, n_fft * sizeof(*fft_in_l)); av_fft_permute(s->fft[0], fft_in_r); av_fft_calc(s->fft[0], fft_in_r); - memcpy(data_hrtf_r + offset, fft_in_r, n_fft * sizeof(*fft_in_r)); + memcpy(s->data_hrtf[1] + offset, fft_in_r, n_fft * sizeof(*fft_in_r)); } } } @@ -540,20 +538,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) av_frame_free(&s->in[i + 1].frame); } - if (s->type == FREQUENCY_DOMAIN) { - s->data_hrtf[0] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex)); - s->data_hrtf[1] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex)); - if (!s->data_hrtf[0] || !s->data_hrtf[1]) { - ret = AVERROR(ENOMEM); - goto fail; - } - - memcpy(s->data_hrtf[0], data_hrtf_l, - sizeof(FFTComplex) * nb_irs * n_fft); - memcpy(s->data_hrtf[1], data_hrtf_r, - sizeof(FFTComplex) * nb_irs * n_fft); - } - s->have_hrirs = 1; fail: @@ -561,9 +545,6 @@ fail: for (i = 0; i < s->nb_inputs - 1; i++) av_frame_free(&s->in[i + 1].frame); - av_freep(&data_hrtf_l); - av_freep(&data_hrtf_r); - av_freep(&fft_in_l); av_freep(&fft_in_r);