From patchwork Tue Sep 8 21:18:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22195 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 646A644BE02 for ; Wed, 9 Sep 2020 00:20:46 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EA9ED68B777; Wed, 9 Sep 2020 00:19:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 48A9568B75C for ; Wed, 9 Sep 2020 00:19:39 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id j2so679524wrx.7 for ; Tue, 08 Sep 2020 14:19:39 -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=SPzwi7u0Kv2Bz0aWWlKRLBvRZ6Q0p0YnJCR5mu9V8pA=; b=XH9rV2clXwnO+ZixA1VtM+lFjMqCoxhAmQfm1I7pAhEEpqhMJsKUX2899QGAnUISyM xAkv+xhtm9s/YNqX0xr3ersaCneDjttlmgKAQfsvs7i7mvJ8i1Bdn0h/mi3kSyZ9IVki v3vqnS26QsXuHXGQ7R5v6tm1lFTP6A0oaBGxIIgS4W1dDgPHTvg295g07dvjE+zk6hj5 MZXHabtGVi5Di7BWFwp4TJqhxuis4xKnKu8uJ5gpMQyFYyenquo/vpEym5CstOFie81N ozENz5y7HRfy9NJbmDnwyaU/Hx3wGObuiSjb7FstRSxMF+313phTnlq2FYLhERSpy5pW zW6Q== 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=SPzwi7u0Kv2Bz0aWWlKRLBvRZ6Q0p0YnJCR5mu9V8pA=; b=hJdmXQ4qc1bh6MlDOHDj5y8GiGHxklEFyV18+etBCsnI0TH4Phichg6R6A4/O6zWLA zJLCDIlafcNyP63hA6bZ6ovfmqePX6zAjpsU0O83IKzPMiK/RAENvYm7o7/jDQyfgklJ XCBmy4WvPWBnHAifeAu5b8MfRXO5lNYS34QK4fdmHoa6Nvi1UJV8OazposdOj/RgVtwH uJVxGQfp1V7OhEryzoxKKXNylQZimMLcXEXuqbS9AE6NbwDkdZAuDToRfuq8rvbR/Dgf 6GHqiJHTmgD8vVAw/9mlclKouCrhkNsbO2DnhzocmQkETnj99iHI/StusSZjbRRN9x5/ WwxA== X-Gm-Message-State: AOAM53270HzvbaifiWWQGmt/pvycF6VexDpTEjRlzNUf0ZzH/ZapwNZO g+lp2HlItHkNF6QHNDUqmZnl6VcjN3Y= X-Google-Smtp-Source: ABdhPJyaaVltxL0w2M2+bxe7Rw7+3+ChOOMJBFFJGCwbqq2hPOAEldk8FAwRZBeCnZNpMbiVdLo68Q== X-Received: by 2002:a05:6000:12c3:: with SMTP id l3mr603642wrx.164.1599599978390; Tue, 08 Sep 2020 14:19:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:37 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:49 +0200 Message-Id: <20200908211856.16290-18-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 18/25] avfilter/af_headphone: Avoid intermediate buffer III 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" The headphone filter allocates a pair of buffers to be used as intermediate buffers lateron: Before every use they are zeroed, then some elements of the buffer are set and lateron the complete buffers are copied into another, bigger buffer. These intermediate buffers are unnecessary as the data can be directly written into the bigger buffer. Furthermore, the whole buffer has been zeroed initially and because no piece of this buffer is set twice (due to the fact that duplicate channel map entries are skipped), it is unnecessary to rezero the part of the big buffer that is about to be written to. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index b5c2bd6121..d57ecb1f50 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -367,9 +367,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) const int ir_len = s->ir_len; int nb_input_channels = ctx->inputs[0]->channels; float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10); - FFTComplex *fft_in_l = NULL; - FFTComplex *fft_in_r = NULL; - int offset = 0, ret = 0; + int ret = 0; int n_fft; int i, j, k; @@ -381,13 +379,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) s->n_fft = n_fft = 1 << (32 - ff_clz(ir_len + s->size)); if (s->type == FREQUENCY_DOMAIN) { - fft_in_l = av_calloc(n_fft, sizeof(*fft_in_l)); - fft_in_r = av_calloc(n_fft, sizeof(*fft_in_r)); - if (!fft_in_l || !fft_in_r) { - ret = AVERROR(ENOMEM); - goto fail; - } - s->fft[0] = av_fft_init(av_log2(s->n_fft), 0); s->fft[1] = av_fft_init(av_log2(s->n_fft), 0); s->ifft[0] = av_fft_init(av_log2(s->n_fft), 1); @@ -464,10 +455,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) data_ir_r[j] = ptr[len * 2 - j * 2 - 1] * gain_lin; } } else { - memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l)); - memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r)); + FFTComplex *fft_in_l = s->data_hrtf[0] + idx * n_fft; + FFTComplex *fft_in_r = s->data_hrtf[1] + idx * n_fft; - offset = idx * n_fft; for (j = 0; j < len; j++) { fft_in_l[j].re = ptr[j * 2 ] * gain_lin; fft_in_r[j].re = ptr[j * 2 + 1] * gain_lin; @@ -475,10 +465,8 @@ 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(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(s->data_hrtf[1] + offset, fft_in_r, n_fft * sizeof(*fft_in_r)); } } else { int I, N = ctx->inputs[1]->channels; @@ -499,10 +487,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) data_ir_r[j] = ptr[len * N - j * N - N + I + 1] * gain_lin; } } else { - memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l)); - memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r)); + FFTComplex *fft_in_l = s->data_hrtf[0] + idx * n_fft; + FFTComplex *fft_in_r = s->data_hrtf[1] + idx * n_fft; - offset = idx * n_fft; for (j = 0; j < len; j++) { fft_in_l[j].re = ptr[j * N + I ] * gain_lin; fft_in_r[j].re = ptr[j * N + I + 1] * gain_lin; @@ -510,10 +497,8 @@ 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(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(s->data_hrtf[1] + offset, fft_in_r, n_fft * sizeof(*fft_in_r)); } } } @@ -528,9 +513,6 @@ fail: for (i = 0; i < s->nb_inputs - 1; i++) av_frame_free(&s->in[i + 1].frame); - av_freep(&fft_in_l); - av_freep(&fft_in_r); - return ret; }