From patchwork Tue Sep 8 21:18:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22196 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 6774B44BE02 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 AE1D268B790; Wed, 9 Sep 2020 00:19:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 217A368B6F8 for ; Wed, 9 Sep 2020 00:19:41 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id w5so668772wrp.8 for ; Tue, 08 Sep 2020 14:19:41 -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=TDo2vVISnER7dzl2hl1F1b9kb9B/szHaDGpb9IlAYlo=; b=UbMy2hUJjTfiC/SK1pvNT3+CXI5nIX/bCvMiGwgada00cczCOW/I2lv4GQDe83JRz/ M26kB4U2T8i9T9cR152dlAWK7vCs2il7xMUEPjO/oJUnaTMt/VyOgT4bkNGn/u6+geln ETO9odWLt4rzR8SrJ7wOvn7SFkvbDSetGFvtibhKP69arUDt3FdBbgo0Hml3i/AvRPcL XWFBiJIkH3/YwFKWUlOHV1vl0oJORuFtTyJsZOxGItsUH3Gqk0GMEqAjqBOF7Q5wR1mP sBMwKx/whqAmncO7tGrbXR29GCHv4HNxuufKIx1Pj7ho16IMg/RydESsJKqgaIanKowE T0Hw== 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=TDo2vVISnER7dzl2hl1F1b9kb9B/szHaDGpb9IlAYlo=; b=GfE4nrROVz20XKv34gWXkfTjLiqrGcyVTxTi3X0MZ8K7m6eiTJ7w2KbT5Uq4eR2c36 cId+jlJmQrhX0LBubycGwqSUW5lqK9OlROdoJNUWR2pz54IZ9ScWEWG9yqEt3LqC/l2u wk6QO9HmpLrA5fRLGY2tlv6FqUHwpssCAeGyyDuKcBMCQzrmDZBMXibqgtGckPKAM82f HqlLNoCtjyxvquE285mWm6Q+DeMWvgvaxdAZuw9YdKcRjlfiyb9ta8NCIS6DFWp/zZ6f A2VlLzTxJnMvndHkI1IBStA12qX5DLmb3U2k4WGek36XFCIFyJiibNh7uN8nz0aPSH+o g63A== X-Gm-Message-State: AOAM533UBrXBacQXXCu54Ow/UuTqXj4ZMut4oHD+CSL83OcXq3u4xjxe 8OOQJhTuuN3aZ/g1EzmvGzUXzslQ98Q= X-Google-Smtp-Source: ABdhPJzhKk6k22mpJYGS4OcRwdUx+GLUMcWgfkjopWN0bL1tIoWVU+OryTUoQa2pPZ0zx2kaDAOjRg== X-Received: by 2002:adf:e488:: with SMTP id i8mr605722wrm.116.1599599980237; Tue, 08 Sep 2020 14:19:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:39 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:51 +0200 Message-Id: <20200908211856.16290-20-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 20/25] avfilter/af_headphone: Don't allocate unused element in array 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 uses an array with as many elements as the filter has inputs to store some per-input information; yet actually it only stores information for all inputs except the very first one (which is special for this filter). Therefore this commit modifies the code to remove this unused element. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index c84142e1ce..bbbe32a475 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -52,7 +52,7 @@ typedef struct HeadphoneContext { int ir_len; int air_len; - int nb_inputs; + int nb_hrir_inputs; int nb_irs; @@ -76,10 +76,10 @@ typedef struct HeadphoneContext { FFTComplex *data_hrtf[2]; AVFloatDSPContext *fdsp; - struct headphone_inputs { + struct hrir_inputs { int ir_len; int eof; - } *in; + } *hrir_in; uint64_t mapping[64]; } HeadphoneContext; @@ -99,8 +99,6 @@ static void parse_map(AVFilterContext *ctx) char *arg, *tokenizer, *p; uint64_t used_channels = 0; - s->nb_inputs = 1; - p = s->map; while ((arg = av_strtok(p, "|", &tokenizer))) { uint64_t out_channel; @@ -120,9 +118,9 @@ static void parse_map(AVFilterContext *ctx) } if (s->hrir_fmt == HRIR_MULTI) - s->nb_inputs = 2; + s->nb_hrir_inputs = 1; else - s->nb_inputs = s->nb_irs + 1; + s->nb_hrir_inputs = s->nb_irs; } typedef struct ThreadData { @@ -318,7 +316,7 @@ static int check_ir(AVFilterLink *inlink, int input_number) av_log(ctx, AV_LOG_ERROR, "Too big length of IRs: %d > %d.\n", ir_len, max_ir_len); return AVERROR(EINVAL); } - s->in[input_number].ir_len = ir_len; + s->hrir_in[input_number].ir_len = ir_len; s->ir_len = FFMAX(ir_len, s->ir_len); return 0; @@ -432,8 +430,8 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) } } - for (i = 0; i < s->nb_inputs - 1; av_frame_free(&frame), i++) { - int len = s->in[i + 1].ir_len; + for (i = 0; i < s->nb_hrir_inputs; av_frame_free(&frame), i++) { + int len = s->hrir_in[i].ir_len; float *ptr; ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &frame); @@ -521,23 +519,25 @@ static int activate(AVFilterContext *ctx) FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx); if (!s->eof_hrirs) { int eof = 1; - for (i = 1; i < s->nb_inputs; i++) { - if (s->in[i].eof) + for (i = 0; i < s->nb_hrir_inputs; i++) { + AVFilterLink *input = ctx->inputs[i + 1]; + + if (s->hrir_in[i].eof) continue; - if ((ret = check_ir(ctx->inputs[i], i)) < 0) + if ((ret = check_ir(input, i)) < 0) return ret; - if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF) { - if (!ff_inlink_queued_samples(ctx->inputs[i])) { + if (ff_outlink_get_status(input) == AVERROR_EOF) { + if (!ff_inlink_queued_samples(input)) { av_log(ctx, AV_LOG_ERROR, "No samples provided for " - "HRIR stream %d.\n", i - 1); + "HRIR stream %d.\n", i); return AVERROR_INVALIDDATA; } - s->in[i].eof = 1; + s->hrir_in[i].eof = 1; } else { if (ff_outlink_frame_wanted(ctx->outputs[0])) - ff_inlink_request_frame(ctx->inputs[i]); + ff_inlink_request_frame(input); eof = 0; } } @@ -606,7 +606,7 @@ static int query_formats(AVFilterContext *ctx) if (ret) return ret; } else { - for (i = 1; i < s->nb_inputs; i++) { + for (i = 1; i <= s->nb_hrir_inputs; i++) { ret = ff_channel_layouts_ref(stereo_layout, &ctx->inputs[i]->outcfg.channel_layouts); if (ret) return ret; @@ -654,19 +654,19 @@ static av_cold int init(AVFilterContext *ctx) parse_map(ctx); - s->in = av_calloc(s->nb_inputs, sizeof(*s->in)); - if (!s->in) + s->hrir_in = av_calloc(s->nb_hrir_inputs, sizeof(*s->hrir_in)); + if (!s->hrir_in) return AVERROR(ENOMEM); - for (i = 1; i < s->nb_inputs; i++) { - char *name = av_asprintf("hrir%d", i - 1); + for (i = 0; i < s->nb_hrir_inputs; i++) { + char *name = av_asprintf("hrir%d", i); AVFilterPad pad = { .name = name, .type = AVMEDIA_TYPE_AUDIO, }; if (!name) return AVERROR(ENOMEM); - if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) { + if ((ret = ff_insert_inpad(ctx, i + 1, &pad)) < 0) { av_freep(&pad.name); return ret; } @@ -721,7 +721,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&s->data_hrtf[1]); av_freep(&s->fdsp); - av_freep(&s->in); + av_freep(&s->hrir_in); for (unsigned i = 1; i < ctx->nb_inputs; i++) av_freep(&ctx->input_pads[i].name); }