From patchwork Tue Sep 8 21:18:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22175 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 E850F44BD83 for ; Wed, 9 Sep 2020 00:19:12 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C433768B63A; Wed, 9 Sep 2020 00:19:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD1C468B603 for ; Wed, 9 Sep 2020 00:19:05 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id m6so718008wrn.0 for ; Tue, 08 Sep 2020 14:19:05 -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:mime-version :content-transfer-encoding; bh=sDfk3q/KfnfxHRNn216orGJBhybZ5AdpUznD/R8XbXY=; b=FV0QEwtxkIgkd0vcLhZDJf0mf7dNvdkNScHg5dB1oQHZASEpRtmIR9s26ytQawidX0 fXMNXoPiHiLZNqCsYU2AwhJexuYR//molhVQDCcHgU5R75dB7Z/9l74xi2W/uRKNiFft QYvAod7b8p11ruZhUSTF/ZbJlFLr1DMDyWdwmGtGbcaogMSHy3POlMuropr+tzLpTHjl fvVNlfgwA0GuUZfGuBcd8D2CFsJq0/yHMawhfjyC07346/zctqwHAIc0o39peigNKDZl Sls7Cn3ycnICdcsHa440oxhAwmNWgpo9yO/ebdCJPnsVwi3D/JDYdAkCvvF0ntd/xC/+ ZpnA== 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:mime-version :content-transfer-encoding; bh=sDfk3q/KfnfxHRNn216orGJBhybZ5AdpUznD/R8XbXY=; b=O0GRm5DP4raqDvheHHg+VPdLLHKnf3rifa+VWs2Iy9BYgmDZNI00fUQbwkI+dEDonD a5ce7AlAWOzoezeh/X3rHQxifPttH2Py1nx59RRGba7/uAOQSrh7HvJyxjOanvA6vZzJ PePTjqE8NQ1/V4DCtPzPdwuhC32EFknX7rb0WxJmcMp6Iz7mVcvXAP2FB/52aWRR2E1o QfV8aGoW611A8oqgEFS8JsdKBSwHPgMV/8pCPJ2ROryacfJ5a2Bng+BlHqRl80+qfwtt 1kHjQxOPHy4kt3oDJFsL6l+aWqAcpjIJ7SjWlxDZ4x4YqMWOddsws60dXi4U58eJiOeQ T6AA== X-Gm-Message-State: AOAM532B8uA/DLaUH85s3sBwcw/LL668NTGpHRnwnyBTTJXkagUvXtdg z0RMmx29xdhXoxYYPtiC7dlBHK+qqVQ= X-Google-Smtp-Source: ABdhPJxoAQLvKo+Loz10Ti6yfBgPuExd1ppk7JmgQK9iGlTn8C9ICJ5YnPaYVVicJc91atmgE18ELg== X-Received: by 2002:adf:f843:: with SMTP id d3mr598805wrq.226.1599599945022; Tue, 08 Sep 2020 14:19:05 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:04 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:32 +0200 Message-Id: <20200908211856.16290-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/25] avfilter/af_headphone: Don't use uninitialized buffer in log message 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" This buffer was supposed to be initialized by sscanf(input, "%7[A-Z]%n", buf, &len), yet if the first input character is not in the A-Z range, buf is not touched (in particular it needn't be zero-terminated if the failure happened when parsing the first channel and it still contains the last channel name if the failure happened when one channel name could be successfully parsed). This is treated as error in which case buf is used directly in the log message. This commit fixes this by actually using the string that could not be matched in the log message instead. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 58d82ac41d..e590d02eff 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -135,7 +135,7 @@ static void parse_map(AVFilterContext *ctx) p = NULL; if (parse_channel_name(s, s->nb_irs, &arg, &out_ch_id, buf)) { - av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf); + av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", arg); continue; } s->mapping[s->nb_irs] = out_ch_id; From patchwork Tue Sep 8 21:18:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22178 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 D5AC744BD83 for ; Wed, 9 Sep 2020 00:19:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BF3D668B6C3; Wed, 9 Sep 2020 00:19:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5182168B6A4 for ; Wed, 9 Sep 2020 00:19:22 +0300 (EEST) Received: by mail-wr1-f43.google.com with SMTP id g4so687851wrs.5 for ; Tue, 08 Sep 2020 14:19:22 -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=im8YbTKrPFBMIf0PCdlQNShmyaFCdcpbDsNlQFsWMig=; b=ZI1Uiq+POdPDBbc+34o1Svn5sNHVh46f0Laj3caqhOr9IPdiTrvL1n2FxOp9SBHmUO Zd4fIW14VmCtR14Fbro/eu4G1NQ0aFEqZ6mvtpeciS2ybdc5cf02xZAsYOoijjiFXQfm G8obb+d9s7deM7SVPAvsmB22JO9I85fkbupaPD41Pipt60BKCVIjjcWM4FHAiIbNx7YL /N+Ln8GZBO5NaQnNv2D4tCu5MrM2hd3u7qLePv+pvpWyMCWKHcsGsi3ZRiG8gRbVYIk7 kiOfvNI0/7QPU7S2qGL6jeHOuTwcrGFdcKvujtUQcQq+fzawtNmWwdP4v31aS3l7tWco RCzQ== 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=im8YbTKrPFBMIf0PCdlQNShmyaFCdcpbDsNlQFsWMig=; b=IYy352M68/UIZ2T9lvFJ/ViIfxt3T00zGkXVoi8lFHlm+ZMj8CeFY8zzfViYlVSylG echaP/Hdd7kSN+Y+KBGK9T+rLreYDXvGDALT7ni3oZLLEH7k9736Ujs82eKFBluroSI5 yC+tQIFOzq9YQgF+DNOHtZPIxPKJ2wklAMYA+w7rPGtsc1ckeiL4SmP+B5dKue82rCwf 3opR0zaT11/5AbuNA4v8+1SQaSQUczqOiKN3rMPeN1cDcE9tIA6/ffSB/JTgC2vBEccN Axjg0RoWCXFuRQxZnB8W6ahMLS+Voc1U0au4vwBBmG2a5Zd63/ubZYVr9DqpuMAu1uvq mXiQ== X-Gm-Message-State: AOAM532GrvjmeadX2sW/94c5TYf2izR3Juh10tdkJBembKTEoiKxqYrX 6vfnZlyvqUftVOqGgwDj86gJqbkuvxY= X-Google-Smtp-Source: ABdhPJyG12AbeVw954GC4U4eYVqNrM9DOJBVHL0QeJEo6YzeOd0v+5SlaXKgazjZxK2BXLWYqca73A== X-Received: by 2002:adf:df81:: with SMTP id z1mr431259wrl.9.1599599961479; Tue, 08 Sep 2020 14:19:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:21 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:33 +0200 Message-Id: <20200908211856.16290-2-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 02/25] avfilter/af_headphone: Remove always true check 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" Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index e590d02eff..1024ff57b1 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -631,10 +631,8 @@ static int activate(AVFilterContext *ctx) if ((ret = check_ir(ctx->inputs[i], i)) < 0) return ret; - if (!s->in[i].eof) { if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF) s->in[i].eof = 1; - } } for (i = 1; i < s->nb_inputs; i++) { From patchwork Tue Sep 8 21:18:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22180 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 99FED44BD83 for ; Wed, 9 Sep 2020 00:19:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7BE6968B6E2; Wed, 9 Sep 2020 00:19:30 +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 488C268B6A0 for ; Wed, 9 Sep 2020 00:19:23 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id z4so695072wrr.4 for ; Tue, 08 Sep 2020 14:19:23 -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=rU/UIq0sClk9e6t2EtMg5QEgHmNVMD16B9Wzg3J2hM4=; b=NA26A2eLqW4R4iVUWtGmzLzDV306f0c+j0i63QYIPQtquVyOUyggzaEGi9TQAVK6AZ uxlJyPAA02UuKav4+eJGhJ7Fx55GWeGyqk3lIzU80egxekUeiBhXKNRsXzNpDcGz8AwJ 6YotSNKXWzlYEDNwCmXX4nkT3HI4TisjJEdZHwgaOuImFHsujbfZbzV7GP7+zHo1hdjw X5mhA54NIjzoieUtF2L/MyGRf/LyBtkkBniOhdLiTJT2wfehoQ2gZWsqI+mwJyLK2RhQ TDMd8x2pMo/iGSlaJkHTKRNsARFd8rz1VHWaW2A67x5ez1slYyxUd+7QRQ/BBRcvn8Rg Wakw== 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=rU/UIq0sClk9e6t2EtMg5QEgHmNVMD16B9Wzg3J2hM4=; b=SFg+79aI1jSmeAImddBjkThleEUF5CVhmpJibskRciWzGtX5ahRfhvUEsl0ECG9c5m 5GlSWKorWyqoIAlBtaa+FMvvL/S0NjHHEaGggVxxv2U+O2tAitC/s1qtouD9bV48R8Rj 7OmTAxl4LbFFNZjyp36jCX8j2CgNXwd7P6hh0/6IqGR+aHF5C+hyyP9RH6GANcCgZMrJ M6vSBiBLYWc64RMyU+b9hhsl5/qWIdQndMF9eGU2h9fjJXH4oh1k446MwCJfne9sOqxi mujIPBH3HqMSglj4xlKdQHGfrGavH7AxdG26M+5D6LcDYQk5W/fdH/NVzs35fNiE8Yd3 N8ng== X-Gm-Message-State: AOAM533Tvh+aDVA7rM/Oo7syhCWHo3Xz3RvIU6K/WEY9EL4noTw+4swj WXW9JNTitqS81L3ZFyzTzcqfuwkNRao= X-Google-Smtp-Source: ABdhPJzko+vMr3Bo/VGhV13ciXxP45oz6jDkl4liv/feGFRMP6ME+2gXwWG3rCpcBLt0x/hGtIyZIw== X-Received: by 2002:a5d:4a0e:: with SMTP id m14mr410679wrq.313.1599599962539; Tue, 08 Sep 2020 14:19:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:22 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:34 +0200 Message-Id: <20200908211856.16290-3-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 03/25] avfilter/af_headphone: Check for the existence of samples 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" Not providing any samples makes no sense at all. And if no samples were provided for one of the HRIR streams, one would either run into an av_assert1 in ff_inlink_consume_samples() or into a segfault in take_samples() in avfilter.c. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 1024ff57b1..f488e0e28d 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -631,8 +631,14 @@ static int activate(AVFilterContext *ctx) if ((ret = check_ir(ctx->inputs[i], i)) < 0) return ret; - if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF) + if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF) { + if (!ff_inlink_queued_samples(ctx->inputs[i])) { + av_log(ctx, AV_LOG_ERROR, "No samples provided for " + "HRIR stream %d.\n", i - 1); + return AVERROR_INVALIDDATA; + } s->in[i].eof = 1; + } } for (i = 1; i < s->nb_inputs; i++) { From patchwork Tue Sep 8 21:18:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22182 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 3A1CD44BD83 for ; Wed, 9 Sep 2020 00:19:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1774268B71E; Wed, 9 Sep 2020 00:19:32 +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 5974A68B6C0 for ; Wed, 9 Sep 2020 00:19:24 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id e16so702867wrm.2 for ; Tue, 08 Sep 2020 14:19:24 -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=OQVGeVwEZTDw3ccFW0oEJqes9ad1nt4piK6R42rDwK0=; b=Sk2Ugcr2yy7HkMOo/5MKck1tX1+aRNuDL0cczNAKojhB2nsTgAqz5/G7rghOJqYMEh 3RXCV++xT9GzoNQeOI3kJyTN/pkpHSVHo+RNaBS9XYNzAYVzh1rA67acRBDCaeNpe81C onvpV7IxfpCS4uB+9bdDiHa+PFoYbDRaGyDnVyN4OzoQh/MXdcb13kUW5lK3vZsIDPE/ 3IpmTEtRWW40JDktCFAsnhuDwSa4wi99Gue0d0Lco3QVqG9t0XvnIJjOOK6r5OyrvJkS Dgo0dm54NTw+ly9Q28Rtch4CDe4xWm1e6TxZXAIe0Mm0YGJfyI66wfOwkh96tb/iLIE1 68xA== 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=OQVGeVwEZTDw3ccFW0oEJqes9ad1nt4piK6R42rDwK0=; b=smtRqQZ0BThohCri4h4ZMPE0oTAuyFMuVB8Nyt8lFyLJPWeKt4diickTPtkZYF45w8 F0K2BsWi1mLnKzW+ZG30IG0MaUNuOueNa3NtCa+cV5+Gr7Fwi2qZ2Wo6zgk1V71YOmz0 bSkasMI4ZSiZ2iRfOre0umykFXn9R+8bxaQmMayCWs7oqfW6p3G0Ea2upkxBfYrJ6apY SBrQhDEbhk92w+iRzUCMwexnldb+hyZS+2k+3iAHg6PQCqEZ27uBJbJ0ueMdNJliywCl 3V/Dn3os2SCNksOHGL1MNc2DGRuxx1TGn8j72TGj7wKJBIyRuIPqdt92kdJJMu08YacF RHig== X-Gm-Message-State: AOAM530KEgYPrJp7OGKvSlSSPNYLVsZZyoL3ivUEFsZc6KRALWkqGHB0 tw5yXeu0VQ+ukEHKDPBbKBIZaiCXbAM= X-Google-Smtp-Source: ABdhPJzOD6qqnCcBdwMVaRHXoC67T1UOEsRCjqILTjas8L9vdIVD+vO6vXuC9C+cevigu9njXpRaPw== X-Received: by 2002:adf:df87:: with SMTP id z7mr404921wrl.239.1599599963592; Tue, 08 Sep 2020 14:19:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:22 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:35 +0200 Message-Id: <20200908211856.16290-4-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 04/25] avfilter/af_headphone: Fix segfault when using very short streams 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 does its processing in the time domain, the lengths of the buffers involved are determined by three parameters, only two of which are relevant here: ir_len and air_len. The former is the length (in samples) of the longest HRIR input stream and the latter is the smallest power-of-two bigger than ir_len. Using optimized functions to calculate the convolution places restrictions on the alignment of the length of the vectors whose scalar product is calculated. Therefore said length, namely ir_len, is aligned on 32; but the number of elements of the buffers used is given by air_len and for ir_len < 16 a buffer overflow happens. This commit fixes this by ensuring that air_len is always >= 32 if processing happens in the time domain. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index f488e0e28d..54b5dfec4c 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -405,6 +405,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) int i, j, k; s->air_len = 1 << (32 - ff_clz(ir_len)); + if (s->type == TIME_DOMAIN) { + s->air_len = FFALIGN(s->air_len, 32); + } s->buffer_length = 1 << (32 - ff_clz(s->air_len)); s->n_fft = n_fft = 1 << (32 - ff_clz(ir_len + s->size)); From patchwork Tue Sep 8 21:18:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22176 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 E894744BD83 for ; Wed, 9 Sep 2020 00:19:26 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D10CC68B6A3; Wed, 9 Sep 2020 00:19:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 86A5068B698 for ; Wed, 9 Sep 2020 00:19:25 +0300 (EEST) Received: by mail-wm1-f43.google.com with SMTP id l9so365917wme.3 for ; Tue, 08 Sep 2020 14:19:25 -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=RE1P2xBdlY4ivyEzi5RXEHTkW2dZokWyhgXi4rfYCf0=; b=rWCIZn5bhF6MEdsyU76EuxazHHrOoOJOM0w1UZ7ArqT68ho3m2pgaOwIr7Q3MlT0vV 01aJo2vbcJkNqEk147WBlX+CK6a8Kqk4yx/H3MzBYBw/zoUdymB3HXxrpJ/ZbzfEiTd3 prML1SiwJGJ8niC/mVRHIG4VP+w2ado0y2ogssXshl2jEK+nZdhVbmLdauET+kssQ12b +Box8PxP9wzM0M7WpG5va25+I/fvQarMcPn17c+8aAwWlurb+EinJdy2AZHqn6jx3h31 3e3CxwJet78l/QwA3YELEy5M4qSaRiUC6ybvRwFWJn20F/8yN6scg16EdXEBdymyZp/f 1Qeg== 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=RE1P2xBdlY4ivyEzi5RXEHTkW2dZokWyhgXi4rfYCf0=; b=JgC7xWrHuPbP2Jce+CF/2+LreYeoGcBndKhrjbYje2v0/k2T+Kjdtk6ME1THt2aR2k hXLzSCqdts06rN7tc4MvtJXsdt6yauH4pYIyw9g1/9o0Ot6KISWuu3P2+/waOI69PMTZ jT5EZbru5wVPwxz+L1/eEp1hSSs3kBvmKurgOlupSRbU+sPcF97vaRILsSsmRJxh14cJ QB64SBkLtkbbshG8VqODiJo3v9gye1vo6REC3FL6oKN8fT0zfYhLS5bdZL7RGaoIn4FM Zkd8NM3dhUeR3YGoTtlKdtZHvJJkCTlqbIMgiC9xSiM42PsZoBm1xpiKk6M8dzcjfL2Z UXUQ== X-Gm-Message-State: AOAM533WkN1wd7OzmCV1O6x+yT8Xhp6pGogSAKM+MxrvfVf2qTG08NOl DCvVDeaUEsC1RrHTCxK0L9BQ3pqYCLo= X-Google-Smtp-Source: ABdhPJwNVefUP/DhD9CsB/cvr/cJmVrWsFDeSIogM8QOq9tIP/OAy9KFF19yVozSeQu7aNv0os2vSw== X-Received: by 2002:a1c:c906:: with SMTP id f6mr342411wmb.9.1599599964550; Tue, 08 Sep 2020 14:19:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:23 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:36 +0200 Message-Id: <20200908211856.16290-5-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 05/25] avfilter/af_headphone: Don't overrun 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 stores the channel position of the ith HRIR stream in the ith element of an array of 64 elements; but because there is no check for duplicate channels, it is easy to write beyond the end of the array by simply repeating channels. This commit adds a check for duplicate channels to rule this out. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 54b5dfec4c..99bdefbcff 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -88,15 +88,13 @@ typedef struct HeadphoneContext { } *in; } HeadphoneContext; -static int parse_channel_name(HeadphoneContext *s, int x, char **arg, int *rchannel, char *buf) +static int parse_channel_name(char **arg, int *rchannel, char *buf) { int len, i, channel_id = 0; int64_t layout, layout0; if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) { layout0 = layout = av_get_channel_layout(buf); - if (layout == AV_CH_LOW_FREQUENCY) - s->lfe_channel = x; for (i = 32; i > 0; i >>= 1) { if (layout >= 1LL << i) { channel_id += i; @@ -116,6 +114,7 @@ static void parse_map(AVFilterContext *ctx) { HeadphoneContext *s = ctx->priv; char *arg, *tokenizer, *p, *args = av_strdup(s->map); + uint64_t used_channels = 0; int i; if (!args) @@ -134,10 +133,17 @@ static void parse_map(AVFilterContext *ctx) char buf[8]; p = NULL; - if (parse_channel_name(s, s->nb_irs, &arg, &out_ch_id, buf)) { + if (parse_channel_name(&arg, &out_ch_id, buf)) { av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", arg); continue; } + if (used_channels & (1ULL << out_ch_id)) { + av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", buf); + continue; + } + used_channels |= 1ULL << out_ch_id; + if (out_ch_id == av_log2(AV_CH_LOW_FREQUENCY)) + s->lfe_channel = s->nb_irs; s->mapping[s->nb_irs] = out_ch_id; s->nb_irs++; } From patchwork Tue Sep 8 21:18:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22177 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 DE22544BD83 for ; Wed, 9 Sep 2020 00:19:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CA24468B6A9; Wed, 9 Sep 2020 00:19:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A6DCF68B618 for ; Wed, 9 Sep 2020 00:19:26 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id e17so364541wme.0 for ; Tue, 08 Sep 2020 14:19:26 -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=uUl64ojI/TtGx8MTkxUIfZ17suIm0eS4Xh9ICCfM+Zc=; b=LpJ9OoJcpFx83KxcvmJ3VKUlwfLQwXoPMldMOisVXUVG2c3Bn8kMJwabe+0Aby+5iv vcFUXgptP+U2nzCxqAQDAdiOhdAbTyGNWBU4ZnqQwQ6QWXM3uAwemsQpnZolyM9tokJk S/vtjVuGqCPHQvBMGUA57DYl4A3MOx80SByWedgcGSIJxwQDV75kMOtOJfOwEIqEVKiw dcFZRJvjC1zxcDNYezJc15n3zuUD/LlQty0T1x+SNw7q8BlTvFZd3mNfUU+4AObW9ZN3 rssyYwJrrxCIVtJV2iSOfOkswwwhtONE9nm/WPLrUC0lULlPUba8woa7urbmnisXyn/z 0r4Q== 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=uUl64ojI/TtGx8MTkxUIfZ17suIm0eS4Xh9ICCfM+Zc=; b=eQwGcleLxpcC99V5ACYkGz2q+GUpdSjCbJCIVYAYKKjs2YSFaj9cXRXPhkizPkUiYl Kwt84S7nkiZtcaBGyyHbhP6eaHHbGMzIKVz1FF0qQXZXglZu8uSxJxmGQVl8OeU/ckPO cU50/JQ9S2MzQwSlbsLgzNe1C6QTE3viyUdW254erqyGKCV87z2yjyNRBX80GhwCxFjC QvTD8B1RCC2GksnJwmIVCruAw+tExsjJfgwNpAILBnXYXZ1zyKu8cdxffFnFxNdfgWdw 7yt2Vg7PVj6dp1cgg65jNCLefbCxNDtO5nasLQIuK9N0/whkE7nsIv7BfAZSIM+GzHup Eguw== X-Gm-Message-State: AOAM533q1L8g9O8z8Ks0Zm9wRisiFIV3dFhDspOycbrEsn5CMITj7Zq/ RMavj3oFDPM0uO9IRUKc1P/GmRmPgF4= X-Google-Smtp-Source: ABdhPJw69BmMUWuX8B4akibiSsd3B6ICWfh6KbeHOguxX22hKDWvkBj2EwFmjzMfP3OG3OxqFVvh4A== X-Received: by 2002:a1c:92:: with SMTP id 140mr338646wma.39.1599599965451; Tue, 08 Sep 2020 14:19:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:24 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:37 +0200 Message-Id: <20200908211856.16290-6-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 06/25] avfilter/af_headphone: Fix stack buffer overflow 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 number of channels can be up to 64, not only 16. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 99bdefbcff..42adc82df8 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -187,7 +187,7 @@ static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n const int in_channels = in->channels; const int buffer_length = s->buffer_length; const uint32_t modulo = (uint32_t)buffer_length - 1; - float *buffer[16]; + float *buffer[64]; int wr = *write; int read; int i, l; From patchwork Tue Sep 8 21:18:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22179 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 B3F7744BD83 for ; Wed, 9 Sep 2020 00:19:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9D09568B6DF; Wed, 9 Sep 2020 00:19:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D42C68B6AA for ; Wed, 9 Sep 2020 00:19:27 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id q9so356239wmj.2 for ; Tue, 08 Sep 2020 14:19:27 -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=EKB+3nEcyA8TSqQL0hyGVcRTMBTLE5vEAYw1wMAs/yQ=; b=H6c+UWOrHGcZ29ej8ZkNMJwv1lTovpBOiIFSJqKQBze22+k+KYGSNJYEk2l367Z1D8 m+OOM/YDNqa2LS1pWSVZFp8KVoCfp1rG99Q2SdIo4mIOBUYArrF+o0uj38hGDnDKwHSV 5t3ZR9f62teX+dmFtB8PcXwk+a8BpYm5eLKS8CN4K+rYF+h2BWhaGPX2JiFjE971Q0Cb ZdlZpZvR9YxOQy+3yKNjvZCTEngqCwuZnZOSTNx+4brgEsXeo0+SuI1So3+HLRWiWeV/ Q7K8I8amd35Ewy4j9C8E5+xx8ohA/TUJ3tbgaKy0XnHI2OCicsklzhce91Gi/ihhH9A1 r5Ng== 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=EKB+3nEcyA8TSqQL0hyGVcRTMBTLE5vEAYw1wMAs/yQ=; b=BcH5ONgrytn3kBXLGP7E+nevAyVqo7UI6FJcq/kV/jksP47wgchIPMI/9Gn7bpe9si EiGiFwJveOqC1uQbA5L4StH+UdMjGbxVKC7fnE8HBpLCVIfYG+ZwQF+t/CXGNLCvWpn2 KQQyIL4Sw+bYJCzrWUQRSb/BPhXnSrHScdEW5fIgT/7FoqLLfQnxJZuqngoeFrGDuS/J C3M1K4Oxkc3j3D8EKNMaQjBZ9okxqaCQ0R0InPKLCst628EqDcPuB/tOi3Oymn8P6XV9 MZFL1Oqcga8AqxGDYJiW2Vpr8v+LOT/sFSJVNBfUvU//7tgyZacsDOUJBz+Nn9msRseU nysw== X-Gm-Message-State: AOAM533PmKG2ZvV7NTis5uWanB3axiKLO1h96HXprhEWgrSd9+AG8GK6 c6RcCFxKdOxkz772DyGs1FTJs0l3A4M= X-Google-Smtp-Source: ABdhPJw3aMIvMn2EtUEvUw47Z+2Nr1WtKKBmO6w6oX7y8dnB9qH2ckv3yNmC86FvCiLboS8BczXGTQ== X-Received: by 2002:a1c:2903:: with SMTP id p3mr341314wmp.170.1599599966614; Tue, 08 Sep 2020 14:19:26 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:25 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:38 +0200 Message-Id: <20200908211856.16290-7-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 07/25] avfilter/af_headphone: Combine several loops when checking for EOF 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" Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 42adc82df8..c71f43c5c8 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -633,6 +633,7 @@ 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) continue; @@ -647,26 +648,15 @@ static int activate(AVFilterContext *ctx) return AVERROR_INVALIDDATA; } s->in[i].eof = 1; + } else { + if (ff_outlink_frame_wanted(ctx->outputs[0])) + ff_inlink_request_frame(ctx->inputs[i]); + eof = 0; } } - - for (i = 1; i < s->nb_inputs; i++) { - if (!s->in[i].eof) - break; - } - - if (i != s->nb_inputs) { - if (ff_outlink_frame_wanted(ctx->outputs[0])) { - for (i = 1; i < s->nb_inputs; i++) { - if (!s->in[i].eof) - ff_inlink_request_frame(ctx->inputs[i]); - } - } - + if (!eof) return 0; - } else { - s->eof_hrirs = 1; - } + s->eof_hrirs = 1; } if (!s->have_hrirs && s->eof_hrirs) { From patchwork Tue Sep 8 21:18:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22181 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 66FE344BD83 for ; Wed, 9 Sep 2020 00:19:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 533FD68B6E5; Wed, 9 Sep 2020 00:19:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE2F668B6CC for ; Wed, 9 Sep 2020 00:19:28 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id a65so344050wme.5 for ; Tue, 08 Sep 2020 14:19:28 -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=UM2rmfgp02RXo//oaFXLnZoFmAoi7guHbQHQQfyMxI4=; b=neC5oeCW6cUMa+ODRhI0JWbUM19fJusUt5vBjkkxb72GSwiZS8ksaD7F7YE3bFE7I/ 4bivkGWR1Jz57T6pYT2nJfFnntJboPqAhJzd213zox+d/OzM4L//SOPN8pT4PiI7aZyI pGSIyIdMIu/Eip/U2K1rYYw3hhQNc9C9zprI40w8PlIWOWWtzSxFikwx8nFCOsgo9iKZ NFPOqcXuVusp75f8TOEJt0/XbPTaGS8Se7aGGu99EhzM3zg+P35RhPuKmACuZ+rWGA9r KcjbKeMs4jngXY3LlaKyAz6eGDmUA87fFS3g/xXZloxrlI9wjRPDauCofkr50Du4anzZ hp5A== 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=UM2rmfgp02RXo//oaFXLnZoFmAoi7guHbQHQQfyMxI4=; b=nYkp6ukvF/Ma1Bl7vXVwOfPii25tlhnmki08RgZTc3RA/AguG1Hq1zbullqhG9ak5w IvBck/XY88Gcsv+CcP7mtgggKjVGzmvdgmFFoZohMqzsNiAay3418rDJ+D1eYyGv6nXK xqXzM635lwKZIyBjHW3yF+QuGPi+uNuTs6EWl5Xn9z4jRyewB0jLE6J+s2e5WU43UC05 OqEIC/1+rOYkcze6r7g+94s5fA+a7PsDeUSnSNeEUrT+dXqAz6hIuvWyHKibdPLLMvkC uiK2nnKaALwZvI+JKnCHjqg8T8m64xe2JK/UzIrh0eLBy1CSYEdmQSJKb7iTRKEFgot+ PURA== X-Gm-Message-State: AOAM533FO4F273J+tSU2qzi0MFJ3kxpSrXDoaweD1YXBvOLVwUnJgqrA ytryqE9tEvgB4YXI8L7BTI/SenMxKCg= X-Google-Smtp-Source: ABdhPJzK2AG8oPbGG9u6tEy06H45DKv6Z8K7uQ2bvqsfOCvq8QA5oj14QFBD1MG2CyJl5kwEO4SEOA== X-Received: by 2002:a1c:5a56:: with SMTP id o83mr326057wmb.77.1599599967729; Tue, 08 Sep 2020 14:19:27 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:27 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:39 +0200 Message-Id: <20200908211856.16290-8-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 08/25] avfilter/af_headphone: Only attempt once to init coeffs 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 does most of its initialization after its init function, because it can perform certain tasks only after all but its first input streams have reached eof. When this happens, it allocates certain buffers and errors out if an allocation fails. Yet the filter didn't check whether some of these buffers already exist (which may happen if an earlier attempt has been interrupted in the middle (due to an allocation error)) in which case the old buffers leak. This commit makes sure that initializing the buffers is only attempted once; if not successfull at the first attempt, future calls to the filter will error out. Trying to support resuming initialization doesn't seem worthwhile. Notice that some allocations were freed before a new allocation was performed; yet this effort was incomplete. Said code has been removed. Signed-off-by: Andreas Rheinhardt --- While I am sure about the aim of this patch, I am not sure if simply returning EOF is enough or if I have to use one of those FF_FILTER status macros to return that this filter is finished. libavfilter/af_headphone.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index c71f43c5c8..4a68d35e66 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -425,12 +425,8 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) goto fail; } - av_fft_end(s->fft[0]); - av_fft_end(s->fft[1]); s->fft[0] = av_fft_init(av_log2(s->n_fft), 0); s->fft[1] = av_fft_init(av_log2(s->n_fft), 0); - av_fft_end(s->ifft[0]); - av_fft_end(s->ifft[1]); s->ifft[0] = av_fft_init(av_log2(s->n_fft), 1); s->ifft[1] = av_fft_init(av_log2(s->n_fft), 1); @@ -657,13 +653,12 @@ static int activate(AVFilterContext *ctx) if (!eof) return 0; s->eof_hrirs = 1; - } - if (!s->have_hrirs && s->eof_hrirs) { ret = convert_coeffs(ctx, inlink); if (ret < 0) return ret; - } + } else if (!s->have_hrirs) + return AVERROR_EOF; if ((ret = ff_inlink_consume_samples(ctx->inputs[0], s->size, s->size, &in)) > 0) { ret = headphone_frame(s, in, outlink); From patchwork Tue Sep 8 21:18:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22183 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 146D144BD83 for ; Wed, 9 Sep 2020 00:19:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF67468B72E; Wed, 9 Sep 2020 00:19:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8F0B968B6C0 for ; Wed, 9 Sep 2020 00:19:29 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id a9so371248wmm.2 for ; Tue, 08 Sep 2020 14:19:29 -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=VPCVE2QtglGX0pwkKja5nOdhrel1TVxEUKQDb2o3Kh4=; b=i5FQYoOrJOLUVrfYiosACGYPWE/Jk3KlcjKdYoiz8qy0DdP2HPQYe1c/5V522ui8zH WQuE6PRU5NcJ414MCv1C8AJMRQsYRsm3r4vq38UtYU4uZUAHj+0B1mOtT9BykpDD1x/e ybRUSesvs4Y1YK7F2RYJ8iXiASRg5ThW/rHjobIO3bYS3Chi8Ik92w//plfbFMhNoa8H E16YUL9Fww8Ohi3BVKpmVBQcMW4uSaUDmi3lQaw8ksPp4B6Q1+b8gQqw3M1K8A0hcNc+ +Gkn9IR5mmN/H/sWnqUXGNVg38A5BMEE90R8iVDAATruODqBDwgei3h7thMz0zrCxJfD M2Ow== 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=VPCVE2QtglGX0pwkKja5nOdhrel1TVxEUKQDb2o3Kh4=; b=QLAza8UIxrYkNalLs1g4ZtGCePEQfjSxceD/DftqKygKcoybK61AqTwgji0jHVQE// dtWk7QZ9lcncn/8oVKlqgf0hozJpuMjRCooTEJ122/IjCQfuMLqG+nLNpDAcT6Bj+/w/ 006AUr3ZGgCZMri1c4SGmGZRVfN1q/0Teuc9W0usb+uCtpfYOIbDKKdCBVfbVN60oWuL Idf9Y5l92zkMGhd3Z7vTLLCSb205WrYhiiT22Zh/uJs/PWx14EB3rqgPMk7IG4NZOgA2 3k+NdsBdGEqRAmO+gNHwW+mxWhAxz2es9cxJwnMy0snNJ047ffUuPFD6P7B8a/EioXYa zk0w== X-Gm-Message-State: AOAM532WyPqHqIlfXzMkH9GjC7LBG23mBTyj65WJSRXa7B5eCeI9k+6C lh09JMeNCDrngWu789uafgGu3fQMlJ4= X-Google-Smtp-Source: ABdhPJwf5laN0oVuPA16nIXZtHGByrJrsKR7Lo3jzIK4K4TQlfcwwojmzKnaeHY0kbhHgvdWZlJexw== X-Received: by 2002:a1c:1b8f:: with SMTP id b137mr321695wmb.151.1599599968633; Tue, 08 Sep 2020 14:19:28 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:28 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:40 +0200 Message-Id: <20200908211856.16290-9-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 09/25] avfilter/af_headphone: Use uint64_t for channel mapping 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 has an option for the user to specify an assignment of inputs to channels (or from pairs of channels of the second input to channels). Up until now, these channels were stored in an int containing the logarithm of the channel layout. Yet it is not the logarithm that is used lateron and so a retransformation was necessary. Therefore this commit simply stores the uint64_t as is, avoiding the retransformation. This also has the advantage that unset channels (whose corresponding entry is zero) can't be mistaken for valid channels any more; the old code had to initialize the channels to -1 to solve this problem and had to check for whether a channel is set before the retransformation (because 1 << -1 is UB). The only downside of this approach is that the size of the context increases (by 256 bytes); but this is not exceedingly much. Finally, the array has been moved to the end of the context; it is only used a few times during the initialization process and moving it decreased the offsets of lots of other entries, reducing codesize. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 40 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 4a68d35e66..8db712e9a0 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -52,8 +52,6 @@ typedef struct HeadphoneContext { int ir_len; int air_len; - int mapping[64]; - int nb_inputs; int nb_irs; @@ -86,12 +84,13 @@ typedef struct HeadphoneContext { int delay_r; int eof; } *in; + uint64_t mapping[64]; } HeadphoneContext; -static int parse_channel_name(char **arg, int *rchannel, char *buf) +static int parse_channel_name(char **arg, uint64_t *rchannel, char *buf) { int len, i, channel_id = 0; - int64_t layout, layout0; + uint64_t layout, layout0; if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) { layout0 = layout = av_get_channel_layout(buf); @@ -101,9 +100,9 @@ static int parse_channel_name(char **arg, int *rchannel, char *buf) layout >>= i; } } - if (channel_id >= 64 || layout0 != 1LL << channel_id) + if (channel_id >= 64 || layout0 != 1ULL << channel_id) return AVERROR(EINVAL); - *rchannel = channel_id; + *rchannel = layout0; *arg += len; return 0; } @@ -115,7 +114,6 @@ static void parse_map(AVFilterContext *ctx) HeadphoneContext *s = ctx->priv; char *arg, *tokenizer, *p, *args = av_strdup(s->map); uint64_t used_channels = 0; - int i; if (!args) return; @@ -124,27 +122,23 @@ static void parse_map(AVFilterContext *ctx) s->lfe_channel = -1; s->nb_inputs = 1; - for (i = 0; i < 64; i++) { - s->mapping[i] = -1; - } - while ((arg = av_strtok(p, "|", &tokenizer))) { - int out_ch_id; + uint64_t out_channel; char buf[8]; p = NULL; - if (parse_channel_name(&arg, &out_ch_id, buf)) { + if (parse_channel_name(&arg, &out_channel, buf)) { av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", arg); continue; } - if (used_channels & (1ULL << out_ch_id)) { + if (used_channels & out_channel) { av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", buf); continue; } - used_channels |= 1ULL << out_ch_id; - if (out_ch_id == av_log2(AV_CH_LOW_FREQUENCY)) + used_channels |= out_channel; + if (out_channel == AV_CH_LOW_FREQUENCY) s->lfe_channel = s->nb_irs; - s->mapping[s->nb_irs] = out_ch_id; + s->mapping[s->nb_irs] = out_channel; s->nb_irs++; } @@ -499,11 +493,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) int idx = -1; for (j = 0; j < inlink->channels; j++) { - if (s->mapping[i] < 0) { - continue; - } - - if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == (1LL << s->mapping[i])) { + if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[i]) { idx = i; break; } @@ -541,11 +531,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) int idx = -1; for (j = 0; j < inlink->channels; j++) { - if (s->mapping[k] < 0) { - continue; - } - - if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == (1LL << s->mapping[k])) { + if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[k]) { idx = k; break; } From patchwork Tue Sep 8 21:18:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22184 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 ED36844BD83 for ; Wed, 9 Sep 2020 00:19:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D80AD68B73F; Wed, 9 Sep 2020 00:19:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5F87C68B6D4 for ; Wed, 9 Sep 2020 00:19:30 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id w2so359414wmi.1 for ; Tue, 08 Sep 2020 14:19:30 -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=FZFv6R5/ZEEnDNgFqdwvQEFkfS6IHzWnLNcksMJgZuQ=; b=GyJiYQvR6Oq9MxFLwZL8OSneMuX60sUtCaAdqpBhABDonYKNv7P53DkVW47Fkdx1yY yIGIaqGHBEpH42RONfHy8kOdbMhr30CviMxgEkc2ugS9UFVuolRfZ3A459AJoOwLXe90 cl/T403p6sRpOZz/8tV3Tmm8DfdAgiEXMuT1wtIfNQMfnx5UTpQc7hRhAWnmmW0UVehc 1q/+hDStjtolhiGSh+Q5F9NI6KofuBgVyxZqozWhe2OzYCqcwKP2ZoV4uuQF4p1u/B3C Z00Gn+fdygHhz3gqeMeoh1nEeZnE573fPCswaHA7w347lOesneL8FgE9yiCwI/n3BhLS My9w== 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=FZFv6R5/ZEEnDNgFqdwvQEFkfS6IHzWnLNcksMJgZuQ=; b=BLyyAHw+oz67G8xbMxY1Bwh1/jter5UHrbPBmqRZ3IMV3um5RaAk8oi9KdusN+j6on gEMiJeYt7WyhHulq2t0Rcaoj6pPrqy7bRM/5dqk5az4cd/7eYzKAe0DwrF8ShxcithAi ONgXq+KQtj6nbchag+/Fe5JIu2YeUJtJJrj2hNTwLw7Y2T5qGpFgiE6DmGCCSc68WFV8 Z1z+PlpURHYPQ/HBtOH1Ndi35/Y8pIYCW061JYMHluVkOzJJRyOvoz7hG7uglD1k0lQb InTT7BzeLC/w07kz2rs9VWNcsa0msUbRJC4halOfhjn2i9tkPALkJHrnHcEumeCvR1La WHoQ== X-Gm-Message-State: AOAM533pDYQANZYv5nRdKXR7E3aNBIcDOo/DuHWy+yNnj5wFkwFGCZuJ FWDX5KWOskj+ZGDjIi41m/J/1vMQ9Dw= X-Google-Smtp-Source: ABdhPJzm14JXZP/IZJcqg3nQ2+Lu1qB/yvhZohtqZ4ggUM37WZ7MqYShOjas4/L8SkGW2G5VRvL2yg== X-Received: by 2002:a05:600c:228e:: with SMTP id 14mr343353wmf.17.1599599969574; Tue, 08 Sep 2020 14:19:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:41 +0200 Message-Id: <20200908211856.16290-10-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 10/25] avfilter/af_headphone: Simplify parsing channel mapping string 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 parsing the channel mapping string (a string containing '|' delimited tokens each of which is supposed to contain a channel name like "FR"), the old code would at each step read up to seven uppercase characters from the input string and give this to av_get_channel_layout() to parse. The returned layout is then checked for being a layout with a single channel set by computing its logarithm. Besides being overtly complicated this also has the drawback of relying on the assumption that every channel name consists of at most seven uppercase letters only; but said assumption is wrong: The abbreviation of the second low frequency channel is LFE2. Furthermore it treats garbage like "FRfoo" as valid channel. This commit changes this by using av_get_channel_layout() directly; furthermore, av_get_channel_layout_nb_channels() (which uses popcount) is used to find out the number of channels instead of the custom code to calculate the logarithm. (As a consequence, certain other formats to specify the channel layouts are now accepted (like the hex versions of av_get_channel_layout()); but this is actually not bad at all.) Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 8db712e9a0..32939af854 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -87,26 +87,14 @@ typedef struct HeadphoneContext { uint64_t mapping[64]; } HeadphoneContext; -static int parse_channel_name(char **arg, uint64_t *rchannel, char *buf) +static int parse_channel_name(const char *arg, uint64_t *rchannel) { - int len, i, channel_id = 0; - uint64_t layout, layout0; - - if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) { - layout0 = layout = av_get_channel_layout(buf); - for (i = 32; i > 0; i >>= 1) { - if (layout >= 1LL << i) { - channel_id += i; - layout >>= i; - } - } - if (channel_id >= 64 || layout0 != 1ULL << channel_id) - return AVERROR(EINVAL); - *rchannel = layout0; - *arg += len; - return 0; - } - return AVERROR(EINVAL); + uint64_t layout = av_get_channel_layout(arg); + + if (av_get_channel_layout_nb_channels(layout) != 1) + return AVERROR(EINVAL); + *rchannel = layout; + return 0; } static void parse_map(AVFilterContext *ctx) @@ -124,15 +112,14 @@ static void parse_map(AVFilterContext *ctx) while ((arg = av_strtok(p, "|", &tokenizer))) { uint64_t out_channel; - char buf[8]; p = NULL; - if (parse_channel_name(&arg, &out_channel, buf)) { + if (parse_channel_name(arg, &out_channel)) { av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", arg); continue; } if (used_channels & out_channel) { - av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", buf); + av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", arg); continue; } used_channels |= out_channel; From patchwork Tue Sep 8 21:18:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22185 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 07C3A44BD83 for ; Wed, 9 Sep 2020 00:19:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E220068B705; Wed, 9 Sep 2020 00:19:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E751E68B716 for ; Wed, 9 Sep 2020 00:19:31 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id q9so356417wmj.2 for ; Tue, 08 Sep 2020 14:19:31 -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=rfxGHm1i0CW1OODYCf/DHoUsRdZtLMcDPyfsyh+rk1w=; b=qMAaBHf7+nWsj6E8k2UZk6iwr+7NEdLCoB36p9BaVBSE4VXvkvEOUTNPi8E8xlXpPc gEc2DIUiAXu7ibj/cRmUO1SAgKdCRYBTWp2vmOq9TD9Ge3b/0YL/v/jnJ4XrYO7WzilS 5Noa719CQHy9XdKm0AOqb2D9j5OZ6nmOoCBJbJ2VlEtdJ5DbEiY/wOAC5hY8D/qJZIZX 4506JNbsNnwDqYlcAoUjr+dvmef3Mw2YvllF92l5d+d/JpgMEjnzrEer11zse91z8OFN S23xq/0NEXVzgwdA6cRzHYRSBRSJX+ux64fiHD6ES7NaTPa4U4PR/HzxyNi1tN+FQKqd vgYg== 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=rfxGHm1i0CW1OODYCf/DHoUsRdZtLMcDPyfsyh+rk1w=; b=osx31pF2oIxgIXjsWEHF/kTZFlG081RwzO76oapReOVkEA/POgige/dSmXRXuitZVs XQADxVILE6IYmlmrKZ8Am/diI7dNxwFDdqGJWZy9Ooo8iMrLQrADXknNYWDmx0KDSPux blCZjfHVIzbiS2h0O6WU10ZEiB6RP2rIfTtShjW4FUHyZbv260tMMpr09DFJA1q8yfak 0lF7cZbU5PzvFsIbpEDZR0KD5Gqp6eFWBkohxONwjk+dbu8g864MxNvUhCs7BW052SbX HghZ6hGn3wlnZnieQtJHy6gG1bGBL6vLeIGn70ynBnmhOgJ1GYAXc2lNqEIxC0uOyL7g imiA== X-Gm-Message-State: AOAM532Yv2kla15WfE82snauI0ZAQVD7aliTkm71feEerN7ONX5INAOV n3fKRyduXbhoYVtsPKWhm12SzGRef4k= X-Google-Smtp-Source: ABdhPJxaWkhIwowETAn8Q8o8J5Me86M6jygqmRrrXsbBUSUZ/CTQJ93J6Lk9oCssn83wGYwV0vDC4g== X-Received: by 2002:a1c:bad5:: with SMTP id k204mr322749wmf.111.1599599971137; Tue, 08 Sep 2020 14:19:31 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:30 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:42 +0200 Message-Id: <20200908211856.16290-11-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 11/25] avfilter/af_headphone: Avoid duplicating string needlessly 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 string given by an AVOption that contains the channel assignment is used only once; ergo it doesn't matter that parsing the string via av_strtok() is destructive. There is no need to make a copy. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 32939af854..967f8ed5a6 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -100,16 +100,13 @@ static int parse_channel_name(const char *arg, uint64_t *rchannel) static void parse_map(AVFilterContext *ctx) { HeadphoneContext *s = ctx->priv; - char *arg, *tokenizer, *p, *args = av_strdup(s->map); + char *arg, *tokenizer, *p; uint64_t used_channels = 0; - if (!args) - return; - p = args; - s->lfe_channel = -1; s->nb_inputs = 1; + p = s->map; while ((arg = av_strtok(p, "|", &tokenizer))) { uint64_t out_channel; @@ -133,8 +130,6 @@ static void parse_map(AVFilterContext *ctx) s->nb_inputs = 2; else s->nb_inputs = s->nb_irs + 1; - - av_free(args); } typedef struct ThreadData { From patchwork Tue Sep 8 21:18:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22186 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 DC4C944BD83 for ; Wed, 9 Sep 2020 00:19:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C0A8968B747; Wed, 9 Sep 2020 00:19:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D71FC68B703 for ; Wed, 9 Sep 2020 00:19:32 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id e11so452148wme.0 for ; Tue, 08 Sep 2020 14:19:32 -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=tihYtS7wGoMEV6OoAT2BYKLQbOlAK5myash5WlT5XSU=; b=Rmb621JLWT+D/WVq+XJFA7D+wKDFuBZ6m6gTPPVSmtCTiLLd+AqlnSOGBKufQm8/Yl CUZoAs3ZrhRMI3dcMrGaOII6iYQzZbwjfmheS9egjRbrmD7llSYLBOvNxgyotC+wsEft k7JnaXx7gn2T8aD3Q96JyvIvqS8YhrjgEIS0NGYJBjpFsFUFzhsNbIrd6HegLvBK7JSf QGXa0I7YSeFxUJizM5MCSRmNSrjuKY/3/uerMvC4P2GOdxm95oaZooYQsSUWo4Q3YgWj o3uuJ8/U6ljHq+/jF6O7EB5oJLYggMw42BCV7TDKOIQB9Je4xXc8x/YlJ3vEjVBnEzPj OiIw== 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=tihYtS7wGoMEV6OoAT2BYKLQbOlAK5myash5WlT5XSU=; b=D4kHj0ykZiyOkqRm5omxLme+wgmWXXpv3jcvaK0jNIKKefqrDiHR3GummvQwN4cj8V Rz7efw+rSuk2O3FIaIJtOSFD+GKjCsOdNmP5D6MCzH0WOcVY2wudLswoeg7D+kUeoV6x QbdgKT+bxnuwVK1oBjEcRPWYV5Mx0HVSmu2Zv22eTtezERUrynAVR25gI07ZACUPco3J x72nkhb1qHiTHzA/VeQNUTCii4ZV0MDRhPEDDKxrf+gpem9QHHZ8n5dGHJTb+1jTSU7M kv0t4WrrAbA3RhcwZ8OJJMyeqRS22zToKHhU56Mincuf4EmemHloF2eFkEPzXgHpNABJ HPFw== X-Gm-Message-State: AOAM531OAF+5GQW6ml556JuAB67qTc03PY2begO7bXqP+NsHOe4+El7V 2w16QSll6hgp1slzYG6XL6e1C/M6sfE= X-Google-Smtp-Source: ABdhPJxxny5wcCeYUhyuVZUwMzJE2eKptcThe508iqoCSfbmdzpZWYk8oiWurg/O5qkiWTa9mgGMtw== X-Received: by 2002:a1c:5641:: with SMTP id k62mr345529wmb.13.1599599971983; Tue, 08 Sep 2020 14:19:31 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:31 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:43 +0200 Message-Id: <20200908211856.16290-12-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 12/25] avfilter/af_headphone: Remove unused arrays 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 delay arrays were never properly initialized, only zero-initialized; furthermore these arrays duplicate fields in the headphone_inputs struct. So remove them. (Btw: The allocations for them have not been checked.) Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 967f8ed5a6..f9799d8548 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -67,7 +67,6 @@ typedef struct HeadphoneContext { int size; int hrir_fmt; - int *delay[2]; float *data_ir[2]; float *temp_src[2]; FFTComplex *temp_fft[2]; @@ -135,7 +134,6 @@ static void parse_map(AVFilterContext *ctx) typedef struct ThreadData { AVFrame *in, *out; int *write; - int **delay; float **ir; int *n_clippings; float **ringbuffer; @@ -151,7 +149,6 @@ static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n AVFrame *in = td->in, *out = td->out; int offset = jobnr; int *write = &td->write[jobnr]; - const int *const delay = td->delay[jobnr]; const float *const ir = td->ir[jobnr]; int *n_clippings = &td->n_clippings[jobnr]; float *ringbuffer = td->ringbuffer[jobnr]; @@ -190,7 +187,7 @@ static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n continue; } - read = (wr - *(delay + l) - (ir_len - 1) + buffer_length) & modulo; + read = (wr - (ir_len - 1) + buffer_length) & modulo; if (read + ir_len < buffer_length) { memcpy(temp_src, bptr + read, ir_len * sizeof(*temp_src)); @@ -348,7 +345,7 @@ static int headphone_frame(HeadphoneContext *s, AVFrame *in, AVFilterLink *outli out->pts = in->pts; td.in = in; td.out = out; td.write = s->write; - td.delay = s->delay; td.ir = s->data_ir; td.n_clippings = n_clippings; + td.ir = s->data_ir; td.n_clippings = n_clippings; td.ringbuffer = s->ringbuffer; td.temp_src = s->temp_src; td.temp_fft = s->temp_fft; td.temp_afft = s->temp_afft; @@ -415,8 +412,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) s->data_ir[0] = av_calloc(s->air_len, sizeof(float) * s->nb_irs); s->data_ir[1] = av_calloc(s->air_len, sizeof(float) * s->nb_irs); - s->delay[0] = av_calloc(s->nb_irs, sizeof(float)); - s->delay[1] = av_calloc(s->nb_irs, sizeof(float)); if (s->type == TIME_DOMAIN) { s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels); @@ -782,8 +777,6 @@ static av_cold void uninit(AVFilterContext *ctx) av_fft_end(s->ifft[1]); av_fft_end(s->fft[0]); av_fft_end(s->fft[1]); - av_freep(&s->delay[0]); - av_freep(&s->delay[1]); av_freep(&s->data_ir[0]); av_freep(&s->data_ir[1]); av_freep(&s->ringbuffer[0]); From patchwork Tue Sep 8 21:18:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22187 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 CAE8F44BD83 for ; Wed, 9 Sep 2020 00:19:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B0B1F68B603; Wed, 9 Sep 2020 00:19:36 +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 CF3B368B6FE for ; Wed, 9 Sep 2020 00:19:33 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id m6so718993wrn.0 for ; Tue, 08 Sep 2020 14:19:33 -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=aQ5iKf1yCtbwV8P9AiDOPUgUL0Ipuee9Ufu3xHe6IHI=; b=QlC7g10hyn/rC0VNFCQxJ/fT9G4zuuqo0s4gHqXtotBSRbvuWUZBEbDpSblonRhUcK Mj6YMcLIgZGgL+UPBPRdI7AUHn+DFdi5fg/KN57oK6WI2TYgz2lwva1/1IJSge5vIi2A 3bxuRPa0gLHAiYbCP8v2/glxMAfq0a5YZNHx1pgy0todagLqTcOFwnRYwkitwpQLpC46 IK3zOm7a8gBP2hsOn9YmFlzUd4vcj5oJZh/+4hVhK7PfIyiryg/k2wQDus8NFRUaKqTi nCZvels4soatxVamofcfPBqqWW+A0aptnRGHyypUwqGPtF4clQIqNKRZ+wuSNDAHMmge oRgQ== 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=aQ5iKf1yCtbwV8P9AiDOPUgUL0Ipuee9Ufu3xHe6IHI=; b=K3DRDyWvozicmvF75GLB2It+r81STwNhV5iRw5KS7oSGQXlRihjJMMz1IgfBEhHvzD TGVTkDAajdJ84D2/V0hH4B9xspJhobuGHLLyoWpCXz2vV0r5Df45vMY+XvWzzOEJ2LNs TyWFoi1j/uOYsQDqYEgi0gBtMcJH7kntfJjKHhooYoCbhjGzqhWM+a4yaYxDdprZxare Ws7KjVAhB6JjSpVsjXyIpWKjXEu+mdjdrkjQaSvt+TsJ1RaDuyDASVJ6IQ9TpJOJ4igv C0GzbG0zL1Oigaer5FuNfuUFhBSifTDVtaSuQDbtmcKg2FpDzcoiqVy68caT2H0lGC8i QgrQ== X-Gm-Message-State: AOAM533XgWpXYo0oef79O+1MTxPrFZg4x8fQVDn5smzV/wXNz4h5kGTi HS1NtC+7JwW2oZfj5TnoNZ55xeAu6VM= X-Google-Smtp-Source: ABdhPJwJoKKKIbftCW8E8WwaBKRColHEeFmwIyWoeXLqy46oKVywjkYzf1GQMsJqt6hJP+D6Omaokg== X-Received: by 2002:adf:ed12:: with SMTP id a18mr596218wro.178.1599599972891; Tue, 08 Sep 2020 14:19:32 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:32 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:44 +0200 Message-Id: <20200908211856.16290-13-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 13/25] avfilter/af_headphone: Remove delay fields 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" They seem to exist for an option that was never implemented. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index f9799d8548..f862181cbb 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -79,8 +79,6 @@ typedef struct HeadphoneContext { struct headphone_inputs { AVFrame *frame; int ir_len; - int delay_l; - int delay_r; int eof; } *in; uint64_t mapping[64]; @@ -457,8 +455,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) for (i = 0; i < s->nb_inputs - 1; i++) { int len = s->in[i + 1].ir_len; - int delay_l = s->in[i + 1].delay_l; - int delay_r = s->in[i + 1].delay_r; float *ptr; ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &s->in[i + 1].frame); @@ -490,8 +486,8 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) offset = idx * n_fft; for (j = 0; j < len; j++) { - fft_in_l[delay_l + j].re = ptr[j * 2 ] * gain_lin; - fft_in_r[delay_r + j].re = ptr[j * 2 + 1] * gain_lin; + fft_in_l[j].re = ptr[j * 2 ] * gain_lin; + fft_in_r[j].re = ptr[j * 2 + 1] * gain_lin; } av_fft_permute(s->fft[0], fft_in_l); @@ -529,8 +525,8 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) offset = idx * n_fft; for (j = 0; j < len; j++) { - fft_in_l[delay_l + j].re = ptr[j * N + I ] * gain_lin; - fft_in_r[delay_r + j].re = ptr[j * N + I + 1] * gain_lin; + fft_in_l[j].re = ptr[j * N + I ] * gain_lin; + fft_in_r[j].re = ptr[j * N + I + 1] * gain_lin; } av_fft_permute(s->fft[0], fft_in_l); From patchwork Tue Sep 8 21:18:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22188 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 2E32C44BD83 for ; Wed, 9 Sep 2020 00:19:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1243768B753; Wed, 9 Sep 2020 00:19:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42CD368B6B4 for ; Wed, 9 Sep 2020 00:19:35 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id m6so719036wrn.0 for ; Tue, 08 Sep 2020 14:19:35 -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=pQSVcDRd3DlbvDZobuGlhZipA6D4JydkknPfG/ADZdc=; b=lv5bfTyRbsUoPmpwQIcZnzAf7SguSEtNiy7M8kORKpH6a8GZB1fg8UxvFCyQv7SufU UyOLrH2QGGFrnSoIiJdNSEK9SQwdHwDFdXhhwU7oW+wU9I/mFCsaSjvBn1SSY028uqFp 9rwjEiLvdkksvpqVmims788dj1hw1J/UEJ4AAovQAp77yvbSe4q92PyN3U/C8nfGl64w wZ5Bx02CLE9Hv3R8nSZvpB0Lcyv0fJ7JLx9IEDcGY/iEZFqWEugUaDFH7f5BV8oEGhvr vgo/VuPvB1rmHz2qNUDYxaK2D3D2bWw/jD20xqV89jQEmxy+XOYHOqs0eIgdqwGBaiSG Z1lg== 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=pQSVcDRd3DlbvDZobuGlhZipA6D4JydkknPfG/ADZdc=; b=oM7S9tbxGTdPu2V9eVVq+fOSKsgwSAUhiK3WEOGww6RWwgv3AqNuThpZVZ1noqV8z9 Fj3UR47IA3cXob4pYhn8/wDIEQTK7sujyD/sxXbjU4dAEYt3Eo/4v8+Y3ashgASQ7Xlm X7V0Yjd8WpcGIvAEJu0z81mxbmLT/Kf2nkGkH+V1B6fHdKE+Xto1jWFlO+lXAtSysy7y hZryzQMfVZUTskM5LgQss1HyNXa6nVJrQqWtqW382E+E3AmlC/of6lHu5G8SpKwdBZTW vUMzu27XJqi9j4/Z4DvwvXM0172OFaR/ESjW+ab5SihyybiU6bjNJms5JldnRzRmhmTb a3Tw== X-Gm-Message-State: AOAM532PB+WDE5vHiludojkIoqMerDqIgyTiylRMWebeXINqM2o4UCGm 30gMBolMdgprzdYvb8ZfOJ84NPyip9Q= X-Google-Smtp-Source: ABdhPJzlwztPkcKuS5lvo8kkIsjWrsIPMtk3RvVDq8BAmv1GQqmdu1IKkhYgjzYlE79ja/cvupdV1A== X-Received: by 2002:a5d:4682:: with SMTP id u2mr600897wrq.254.1599599974414; Tue, 08 Sep 2020 14:19:34 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:33 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:45 +0200 Message-Id: <20200908211856.16290-14-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 14/25] avfilter/af_headphone: Avoid intermediate buffers I 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 has two modes; in one of them (say A), it needs certain buffers to store data. But it allocated them in both modes. Furthermore when in mode A it also allocated intermediate buffers of the same size, initialized them, copied their contents into the permanent buffers and freed them. This commit changes this: The permanent buffer is only allocated when needed; the temporary buffer has been completely avoided. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index f862181cbb..359174d4b4 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -375,8 +375,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) FFTComplex *data_hrtf_r = NULL; FFTComplex *fft_in_l = NULL; FFTComplex *fft_in_r = NULL; - float *data_ir_l = NULL; - float *data_ir_r = NULL; int offset = 0, ret = 0; int n_fft; int i, j, k; @@ -408,9 +406,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) } } - s->data_ir[0] = av_calloc(s->air_len, sizeof(float) * s->nb_irs); - s->data_ir[1] = av_calloc(s->air_len, sizeof(float) * s->nb_irs); - if (s->type == TIME_DOMAIN) { s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels); s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels); @@ -428,8 +423,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) } } - if (!s->data_ir[0] || !s->data_ir[1] || - !s->ringbuffer[0] || !s->ringbuffer[1]) { + if (!s->ringbuffer[0] || !s->ringbuffer[1]) { ret = AVERROR(ENOMEM); goto fail; } @@ -438,9 +432,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) s->temp_src[0] = av_calloc(s->air_len, sizeof(float)); s->temp_src[1] = av_calloc(s->air_len, sizeof(float)); - data_ir_l = av_calloc(nb_irs * s->air_len, sizeof(*data_ir_l)); - data_ir_r = av_calloc(nb_irs * s->air_len, sizeof(*data_ir_r)); - if (!data_ir_r || !data_ir_l || !s->temp_src[0] || !s->temp_src[1]) { + s->data_ir[0] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[0])); + s->data_ir[1] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[1])); + if (!s->data_ir[0] || !s->data_ir[1] || !s->temp_src[0] || !s->temp_src[1]) { ret = AVERROR(ENOMEM); goto fail; } @@ -475,10 +469,12 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) if (idx == -1) continue; if (s->type == TIME_DOMAIN) { - offset = idx * s->air_len; + float *data_ir_l = s->data_ir[0] + idx * s->air_len; + float *data_ir_r = s->data_ir[1] + idx * s->air_len; + for (j = 0; j < len; j++) { - data_ir_l[offset + j] = ptr[len * 2 - j * 2 - 2] * gain_lin; - data_ir_r[offset + j] = ptr[len * 2 - j * 2 - 1] * gain_lin; + data_ir_l[j] = ptr[len * 2 - j * 2 - 2] * gain_lin; + data_ir_r[j] = ptr[len * 2 - j * 2 - 1] * gain_lin; } } else { memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l)); @@ -514,10 +510,12 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) I = idx * 2; if (s->type == TIME_DOMAIN) { - offset = idx * s->air_len; + float *data_ir_l = s->data_ir[0] + idx * s->air_len; + float *data_ir_r = s->data_ir[1] + idx * s->air_len; + for (j = 0; j < len; j++) { - data_ir_l[offset + j] = ptr[len * N - j * N - N + I ] * gain_lin; - data_ir_r[offset + j] = ptr[len * N - j * N - N + I + 1] * gain_lin; + data_ir_l[j] = ptr[len * N - j * N - N + I ] * gain_lin; + 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)); @@ -542,10 +540,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) av_frame_free(&s->in[i + 1].frame); } - if (s->type == TIME_DOMAIN) { - memcpy(s->data_ir[0], data_ir_l, sizeof(float) * nb_irs * s->air_len); - memcpy(s->data_ir[1], data_ir_r, sizeof(float) * nb_irs * s->air_len); - } else { + 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]) { @@ -566,9 +561,6 @@ fail: for (i = 0; i < s->nb_inputs - 1; i++) av_frame_free(&s->in[i + 1].frame); - av_freep(&data_ir_l); - av_freep(&data_ir_r); - av_freep(&data_hrtf_l); av_freep(&data_hrtf_r); 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); From patchwork Tue Sep 8 21:18:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22192 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 52AA144BE02 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 238D868B76C; Wed, 9 Sep 2020 00:19:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8BD4E68B737 for ; Wed, 9 Sep 2020 00:19:37 +0300 (EEST) Received: by mail-wm1-f50.google.com with SMTP id e11so452229wme.0 for ; Tue, 08 Sep 2020 14:19:37 -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=9DKNNQQIfZtwEjMgMK0r4a7lKrq8S8/26k2jYHAXF4g=; b=ggmiwXyE15Jb+axL/IBkRx3znzz+b7AxE5Q1OxjnuuUeFXuDxd2llw3Aw/m4Y/aNuU QmifMZgUskLxiz16C4gA2w3So3NYNFOUsPSyTi7qYrj8vhq6NoLuvd8Kwnd3EyzQDwW2 jV4P1UcPlJkPnZoc2Lo1ryLWVQuUxiMbIS22GIiNBD6Vx6DaQ4iEq2T065bMge6DHXIn egQKcgMBQ/o7I0C3jibSk9dxAwjB/NIje47LSpuLzLEgaqsHFZJHQLEjdOGeHbut+mxG 0aCcty148SURXQhX6Z9lYNah8r/JrAGToSZyet2nZaCTBYZ4SvGAkDDlQjmYOzsaRmYR X4GQ== 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=9DKNNQQIfZtwEjMgMK0r4a7lKrq8S8/26k2jYHAXF4g=; b=fRXI/oXIwpClJ+KJjH9kzut8Rm1EJaQYKKH9nmVUQqE461HkITO5bercy/jWMZzlid 4sQVChyosAyGQWMa5p4ulNrKkeq0eqZy2ERMDCmJ3zrKBj5amKGtErPrQwGasxljjYFv GOJndrnyZkJX5K7nHUnaskWZfDINDlabEOE8FqnLyxdM2ox0poqwAPTr+xQS6S9zuba5 WnzYEg45gZ/aeW7G8ou85xqtPWG3vPttM/zPjJmOuCI4j+ECPg4TWoVmVgLLa+Cl2G1c S2id3vrhw1DFDhEoDse7+KNbygZ7IJnLt26yS5pTyhPbCgsCkBU3a4ZH6xgUH7O+SBM/ 9KhA== X-Gm-Message-State: AOAM5338/TLJ0Wh2C55OOivCyRakxCVGYsiHFYuR3hsrYt7r5DPMDKDS smXP0cvQEpB1sZtK/9fUoXNcGYn+ci8= X-Google-Smtp-Source: ABdhPJy3h00MFwBquCB6p54Z8N8vaCU5tkPkrgwczHaKwMiyQAt/RzwViFLW0EyDpTnwOsdiEiAHnw== X-Received: by 2002:a7b:c397:: with SMTP id s23mr342859wmj.174.1599599976567; Tue, 08 Sep 2020 14:19:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:35 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:47 +0200 Message-Id: <20200908211856.16290-16-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 16/25] avfilter/af_headphone: Fix channel assignment 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 documentation of the map argument of the headphone filter states: "Set mapping of input streams for convolution. The argument is a ’|’-separated list of channel names in order as they are given as additional stream inputs for filter." Yet this has not been honoured at all. Instead for the kth given HRIR channel pair it was checked whether there was a kth mapping and if the channel position so given was present in the channel layout of the main input; if so, then the given HRIR channel pair was matched to the kth channel of the main input. It should actually have been matched to the channel given by the kth mapping. A consequence of the current algorithm is that if N additional HRIR channel pairs are given, a permutation of the first N entries of the mapping does not affect the output at all. The old code might even set arrays belonging to streams that don't exist (i.e. whose index is >= the number of channels of the main input stream); these parts were not read lateron at all. The new code doesn't do this any longer and therefore the number of elements of some of the allocated arrays has been reduced (in case the number of mappings was bigger than the number of channels of the first input stream). Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index fb6af7a966..d6647ff80b 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -117,8 +117,6 @@ static void parse_map(AVFilterContext *ctx) continue; } used_channels |= out_channel; - if (out_channel == AV_CH_LOW_FREQUENCY) - s->lfe_channel = s->nb_irs; s->mapping[s->nb_irs] = out_channel; s->nb_irs++; } @@ -368,7 +366,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) { struct HeadphoneContext *s = ctx->priv; const int ir_len = s->ir_len; - 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 *fft_in_l = NULL; @@ -430,15 +427,15 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) s->temp_src[0] = av_calloc(s->air_len, sizeof(float)); s->temp_src[1] = av_calloc(s->air_len, sizeof(float)); - s->data_ir[0] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[0])); - s->data_ir[1] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[1])); + s->data_ir[0] = av_calloc(nb_input_channels * s->air_len, sizeof(*s->data_ir[0])); + s->data_ir[1] = av_calloc(nb_input_channels * s->air_len, sizeof(*s->data_ir[1])); if (!s->data_ir[0] || !s->data_ir[1] || !s->temp_src[0] || !s->temp_src[1]) { ret = AVERROR(ENOMEM); goto fail; } } else { - 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); + s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_input_channels); + s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_input_channels); if (!s->data_hrtf[0] || !s->data_hrtf[1]) { ret = AVERROR(ENOMEM); goto fail; @@ -459,7 +456,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) for (j = 0; j < inlink->channels; j++) { if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[i]) { - idx = i; + idx = j; + if (s->mapping[i] == AV_CH_LOW_FREQUENCY) + s->lfe_channel = j; break; } } @@ -499,14 +498,16 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) for (j = 0; j < inlink->channels; j++) { if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[k]) { - idx = k; + idx = j; + if (s->mapping[k] == AV_CH_LOW_FREQUENCY) + s->lfe_channel = j; break; } } if (idx == -1) continue; - I = idx * 2; + I = k * 2; if (s->type == TIME_DOMAIN) { float *data_ir_l = s->data_ir[0] + idx * s->air_len; float *data_ir_r = s->data_ir[1] + idx * s->air_len; From patchwork Tue Sep 8 21:18:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22193 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 5ABFA44BE02 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 EC86268B766; Wed, 9 Sep 2020 00:19:40 +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 5526B68B6D3 for ; Wed, 9 Sep 2020 00:19:38 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id z4so695573wrr.4 for ; Tue, 08 Sep 2020 14:19:38 -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=YGlrKylm7iO5i9WIabm5PFRmdbq7qyfMoF5Z1zPgON4=; b=uIWHBDzcX1c/RCcNqZzp6cfr7D/t6Y8d40FHY7L0d6LDvpaoZzQh5uLQOqqsGrynVA ehZ3K3TPCQuqfD5O4fCnp/2IyFWikMZAGYuzoRxcV8mzsNKtaZlvFxWOXE/KraYLmLiD 88bMcP3wIlEjN1Gw0w5lV+NfXYLU+tdCBADlxQWNEnXuHH/aghK5NaouOC6joDLj/p1P IYVNy2GIekzwolKG/RE0HIzfAlUkDWDhZ9H66ms8cp5sDlN/1Qv/aI0G+5IgO744XttY gDxe55p1vTSTgdlchZCe/yEdJ3p73tiz1XL83N4DOOyY1wPbv1GaROp8UkGA0ZpStKih qdFg== 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=YGlrKylm7iO5i9WIabm5PFRmdbq7qyfMoF5Z1zPgON4=; b=ZwgljXSLAmwIhK9BfZfGRF01VjNUD8eI5bFHWM4UDQ9rzjxezNfLi3n4WKAwjtyFv4 q7K/QM6lbumzXBDk/zXmjstjR6YE6UbUwGmMt/wEl6TkdApAn3gjQFzJpi/Fxj3pqWNx eerTIStX2xhz3jLn+w/2ZLeGucBKdxYPFwEbIQIt+VhaQdRAUHo45i8ro998v0EXx6VU bQjyQ7zZMgsQRzBqeaSJZ7jNucKDXX4PZXelp6BFHztuE0Nu0iaHX518B/bPLgTRbFeY FD1Jv3/VpsbozT9RISqI3CFW/ho/xxDVaD7VhnraEGbBKkug5QHlWlREjlu8/tlSya+F IM5w== X-Gm-Message-State: AOAM531IEOJ98gwJELo4yHTMsjzgNrIrMwTUZlUg/FrY+LYqEhNhQ832 VUK9jzWz5dPpYe5hB5z1iIVJScxx028= X-Google-Smtp-Source: ABdhPJz6S07KyIcoy4vTvKy+GrsKOTIPPEozQmLMR6/3Iu+V4WtBrsHUKTBJVGJDX6DdzBuHMKGFQw== X-Received: by 2002:adf:e7c8:: with SMTP id e8mr441264wrn.358.1599599977522; Tue, 08 Sep 2020 14:19:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:36 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:48 +0200 Message-Id: <20200908211856.16290-17-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 17/25] avfilter/af_headphone: Simplify finding channel index 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" Before this commit, the headphone filter called av_channel_layout_extract_channel() in a loop in order to find out the index of a channel (given via its AV_CH_* value) in a channel layout. This commit changes this to av_get_channel_layout_channel_index() instead. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index d6647ff80b..b5c2bd6121 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -100,7 +100,6 @@ static void parse_map(AVFilterContext *ctx) char *arg, *tokenizer, *p; uint64_t used_channels = 0; - s->lfe_channel = -1; s->nb_inputs = 1; p = s->map; @@ -452,18 +451,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) ptr = (float *)s->in[i + 1].frame->extended_data[0]; if (s->hrir_fmt == HRIR_STEREO) { - int idx = -1; - - for (j = 0; j < inlink->channels; j++) { - if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[i]) { - idx = j; - if (s->mapping[i] == AV_CH_LOW_FREQUENCY) - s->lfe_channel = j; - break; - } - } - - if (idx == -1) + int idx = av_get_channel_layout_channel_index(inlink->channel_layout, + s->mapping[i]); + if (idx < 0) continue; if (s->type == TIME_DOMAIN) { float *data_ir_l = s->data_ir[0] + idx * s->air_len; @@ -494,17 +484,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) int I, N = ctx->inputs[1]->channels; for (k = 0; k < N / 2; k++) { - int idx = -1; - - for (j = 0; j < inlink->channels; j++) { - if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[k]) { - idx = j; - if (s->mapping[k] == AV_CH_LOW_FREQUENCY) - s->lfe_channel = j; - break; - } - } - if (idx == -1) + int idx = av_get_channel_layout_channel_index(inlink->channel_layout, + s->mapping[k]); + if (idx < 0) continue; I = k * 2; @@ -671,6 +653,8 @@ static int config_input(AVFilterLink *inlink) return AVERROR(EINVAL); } + s->lfe_channel = av_get_channel_layout_channel_index(inlink->channel_layout, + AV_CH_LOW_FREQUENCY); return 0; } 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; } From patchwork Tue Sep 8 21:18:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22194 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 5F74A44BE02 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 C366B68B75A; Wed, 9 Sep 2020 00:19:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E01268B76F for ; Wed, 9 Sep 2020 00:19:40 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id e11so452284wme.0 for ; Tue, 08 Sep 2020 14:19:40 -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=dwPvuJna/+049PVxJcRI4sACnpZXA4YcdwLEvxQQbK0=; b=EBCgf4sJ4+MoWCRz1itYH0E0Vu3z2qd4yMW4VmQhe/j9yHtSntzfd+138s6m5oauCo WAqgVQfTSfJWfACGVSDTVFXKTQsg7dtWUKlwFtrzeyG9YEHylYgauCdyGfSYPN2mzv1b 0OVqvTWNIYcuBz5ppi6QIgs70/ohX0RQ8fHCapmnBKwLR+KZkbQ3o8Rjz+/TlcSAfTko KPE1YO4idI+osvtP9+Rmo3QUZ55gnI8+scRDd7JwwCb8Ce271gKrOtbP8dwb7+7EADLX VQCYuAIsM3B/Nx/cMITR5G+3TSgPIQ907gxrGnuiQxoz6kwZ5VyNnh+mxIT5w9yBhCkC n4dw== 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=dwPvuJna/+049PVxJcRI4sACnpZXA4YcdwLEvxQQbK0=; b=qLLd6A9QptuuBBSzUdGlrhstdSsYm9odufY2xALQZoGLUkta/l3ix6XoHWs89vzOoI 8TSaK3D2M8/RcG4z8FjuyQuMZY3GDJ2jK+ePSSbHQZ4hVzLEOUL645KageakOI6NS+va wshOQe75yP6iFqfERLFnRm8KJoL44zMXzTJhPEoTyPawvnbwWIr1nBGPWM5FdYvr5BE0 o8SljmGTTZWBDnWAWBnzkeSdFtkrgOITvtAdlV1O7ADKKoJ/u1mOODaWt6P7EWvaFyQS QmKRRhxHKiv5HVE/KGlxmYJMAeBO3PdhexABps1SNYsAYzPiCsGX2of44JxKho8w1Dw+ J3jw== X-Gm-Message-State: AOAM530Da/xORhGhW8J+hVaxgAkOU33XI5KaeKIGj6OCcq0DwB4tb2+1 R529+p+cGHqbOFoXV+SEaFAvMRoyWbI= X-Google-Smtp-Source: ABdhPJz12dyOuZpC4G698Dzg4Eafb9zwHSMhn8ikq/myGAXGoYVKnKQH0/ZvtUqPGAQlEOugbcxX3Q== X-Received: by 2002:a1c:7215:: with SMTP id n21mr351200wmc.154.1599599979366; Tue, 08 Sep 2020 14:19:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:38 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:50 +0200 Message-Id: <20200908211856.16290-19-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 19/25] avfilter/af_headphone: Only keep one AVFrame at a time 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" Despite the headphone filter only using one AVFrame at a time, it kept an array each of whose entries contained a pointer to an AVFrame at all times; the pointers were mostly NULL. This commit instead replaces them by using a single pointer to an AVFrame on the stack of the only function that actually uses them. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index d57ecb1f50..c84142e1ce 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -77,7 +77,6 @@ typedef struct HeadphoneContext { AVFloatDSPContext *fdsp; struct headphone_inputs { - AVFrame *frame; int ir_len; int eof; } *in; @@ -367,6 +366,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); + AVFrame *frame; int ret = 0; int n_fft; int i, j, k; @@ -432,14 +432,14 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) } } - for (i = 0; i < s->nb_inputs - 1; i++) { + for (i = 0; i < s->nb_inputs - 1; av_frame_free(&frame), i++) { int len = s->in[i + 1].ir_len; float *ptr; - ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &s->in[i + 1].frame); + ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &frame); if (ret < 0) goto fail; - ptr = (float *)s->in[i + 1].frame->extended_data[0]; + ptr = (float *)frame->extended_data[0]; if (s->hrir_fmt == HRIR_STEREO) { int idx = av_get_channel_layout_channel_index(inlink->channel_layout, @@ -502,17 +502,11 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) } } } - - av_frame_free(&s->in[i + 1].frame); } s->have_hrirs = 1; fail: - - for (i = 0; i < s->nb_inputs - 1; i++) - av_frame_free(&s->in[i + 1].frame); - return ret; } 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); } From patchwork Tue Sep 8 21:18:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22190 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 CB51D44BD83 for ; Wed, 9 Sep 2020 00:19:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AD3C368B7A3; Wed, 9 Sep 2020 00:19:45 +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 0138B68B784 for ; Wed, 9 Sep 2020 00:19:41 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id w5so668800wrp.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=UF7b5g2ux9uFAuwrGi41ODjmENqn1cuTWHvaBg3a3XQ=; b=SZ1bnIa8oFc36bCTTMBUMM8zblEbBrZH1A2C88B86mQ1N8CO9gD8hOi2gS08nvtcgO Jt/PY2gBhTZ/vFhvzT7hH5VBOB1uvnTTo8t3OZKIHRDbgmI/gFckFVQQHLQQj4Jnw2af sSIMDmuCdl7+eeH0YBCSNoxf3D5cOTOPIIaFnOjn3mGBS4C+/q5LcJ6aZGHvRyQ5oemQ +GADfLBQv3NhZYuyum1IxICL439PR1oGlJOVIG0ogt5uwxxz22CEeNoluIWjd8tJu2uD 8NhirxUiRMXCCm2jVyNz40XVNY8ah2u51z9RrGTTgPmB3ur/PZs2XbcQD68BX8I78mfg ybmw== 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=UF7b5g2ux9uFAuwrGi41ODjmENqn1cuTWHvaBg3a3XQ=; b=tyL2oSWfKMpJzt17BN9fLU84VJWBHoZ2QWRngRFWWAIGr9u2VzdzlmGJb1tUnu41Tx OX2RL72Rh1SH4gHVmoORgGnSJ5qt5DAd9tn/bObmduODEjruEwD1BtTYlPTqRGGvfaJI nqeTRbSPmFg7vTOC9pPoFcg1Eq80o+jTM99XMoLa7+KoeBoKvWKrK4lB9DKOD05BgM+Y /AjMNJy8Bx+olz0nIZLkoP7SiQD1WYJd9PVvDHFGxY/zoRPR11f8BrITjbfo5hGzQmP2 sh+3kQdwKBcmeGPU1VRrcH+aqru2WEcGsU5wrbeEVNK+kqvnv9ezU2ZdBty6+OkGNv5r Q6wA== X-Gm-Message-State: AOAM530oibAsbCvz7tg8qqei5gskGAVESupt9cn6H+ZVCaMCMCGDfW2q G+Z2nUgSTgEPlWbE2RpDSdmL3R2oVtI= X-Google-Smtp-Source: ABdhPJwSeyaFjqQfosEYIVwt7O0QAaxbofNXnHVH/cY3tmqN8D7IQItTHDBZbIxBu55iv3aiFxy7Aw== X-Received: by 2002:adf:e989:: with SMTP id h9mr627756wrm.38.1599599981202; Tue, 08 Sep 2020 14:19:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:40 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:52 +0200 Message-Id: <20200908211856.16290-21-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 21/25] avfilter/af_headphone: Avoid allocating 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" Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index bbbe32a475..2d2b57d819 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -79,7 +79,7 @@ typedef struct HeadphoneContext { struct hrir_inputs { int ir_len; int eof; - } *hrir_in; + } hrir_in[64]; uint64_t mapping[64]; } HeadphoneContext; @@ -654,10 +654,6 @@ static av_cold int init(AVFilterContext *ctx) parse_map(ctx); - s->hrir_in = av_calloc(s->nb_hrir_inputs, sizeof(*s->hrir_in)); - if (!s->hrir_in) - return AVERROR(ENOMEM); - for (i = 0; i < s->nb_hrir_inputs; i++) { char *name = av_asprintf("hrir%d", i); AVFilterPad pad = { @@ -721,7 +717,6 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&s->data_hrtf[1]); av_freep(&s->fdsp); - av_freep(&s->hrir_in); for (unsigned i = 1; i < ctx->nb_inputs; i++) av_freep(&ctx->input_pads[i].name); } From patchwork Tue Sep 8 21:18:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22197 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 6AF3944BE02 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 9DE4068B7CA; Wed, 9 Sep 2020 00:19:46 +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 2606768B77D for ; Wed, 9 Sep 2020 00:19:43 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id z4so695754wrr.4 for ; Tue, 08 Sep 2020 14:19:43 -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=PpsM4jelC2FxQJAFKqgwaOSVG0sbe6xjR3vICjIVIN4=; b=RBCJ5Vdo4CMeaZ63bfHRMaybt4OF7SpjmnxBk+qMczCZ7YswR72sIVm2YbjrnFb/Xo 6u+rgVzOOGZaamonsffE2E+1dohENqBQ06HIRFPPuLSWG9ewUitbheNVST8mF6MV23Ln qW5opQRPqF2UHkLVoqFNokucyNps6O7mBwxbAiGA8lFpjFO9IGEuyhvaBP6yGmS4TFXK zgwNciY5eYsgmGvNzDvADwtSbqMWw7pUdLlXpgUd0SkcAY5udXEizl0JQPB4dy4yF253 LdXpj0LEKXQGbGpzhG44xb6tflElzp+4CHAHvVIUnevpIig/MljdBY+8/Jdbb0Xm2N92 7VDA== 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=PpsM4jelC2FxQJAFKqgwaOSVG0sbe6xjR3vICjIVIN4=; b=ik6VC+fE8s1jhcwhEFV6sNCI1oJugkufutwK3OSTZJ3fXcBUNChpStkAJ3XkEwLKnI k3OZh3lEVGpLAwGyN8IBuqjymWJMV/DACXuIg8B19i93fOyWAU0CzxnH53M7UPbBMB19 o+3u4kRsbQkvDS3nnqfAvgmFKo6QPXzBZYiDg7I9tmHlLkUV1LBt+TgLiL1MVs5PLLTL KeHgZhaJLmjGeAp4w2Z1/CBd65Nqmlm0OLOOXMvE/a3EW4Tt5NfJswrOwVZUwt70fbEa Pqjt02ebLxUy20XLKBdIhkbbpBYr3JagS0yA3gorokTfnxRbnVyqhi4qIw3zxFNBFE8c G3GQ== X-Gm-Message-State: AOAM530j4KG6qv1fDDrxnsVZyB6+ARaCyRoAciO1zIiSgZOkQJtVpbsN gYykkGVKzyAkYRRaYW2gIIeKp9HDxGI= X-Google-Smtp-Source: ABdhPJy1ELk8EXxBG/GtORym0ZZ/E06RnjlEx5dbVgcc8uGqvAlduN9IdiaQ2p2ETRtBS0ppkxtdcg== X-Received: by 2002:adf:dccc:: with SMTP id x12mr409313wrm.241.1599599982390; Tue, 08 Sep 2020 14:19:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:41 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:53 +0200 Message-Id: <20200908211856.16290-22-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 22/25] avfilter/af_headphone: Avoid indirection for function pointer 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" Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 2d2b57d819..8b0a431c45 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -75,7 +75,7 @@ typedef struct HeadphoneContext { FFTContext *fft[2], *ifft[2]; FFTComplex *data_hrtf[2]; - AVFloatDSPContext *fdsp; + float (*scalarproduct_float)(const float *v1, const float *v2, int len); struct hrir_inputs { int ir_len; int eof; @@ -190,7 +190,7 @@ static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n memcpy(temp_src + len, bptr, (air_len - len) * sizeof(*temp_src)); } - dst[0] += s->fdsp->scalarproduct_float(temp_ir, temp_src, FFALIGN(ir_len, 32)); + dst[0] += s->scalarproduct_float(temp_ir, temp_src, FFALIGN(ir_len, 32)); temp_ir += air_len; } @@ -668,9 +668,13 @@ static av_cold int init(AVFilterContext *ctx) } } - s->fdsp = avpriv_float_dsp_alloc(0); - if (!s->fdsp) - return AVERROR(ENOMEM); + if (s->type == TIME_DOMAIN) { + AVFloatDSPContext *fdsp = avpriv_float_dsp_alloc(0); + if (!fdsp) + return AVERROR(ENOMEM); + s->scalarproduct_float = fdsp->scalarproduct_float; + av_free(fdsp); + } return 0; } @@ -715,7 +719,6 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&s->temp_afft[1]); av_freep(&s->data_hrtf[0]); av_freep(&s->data_hrtf[1]); - av_freep(&s->fdsp); for (unsigned i = 1; i < ctx->nb_inputs; i++) av_freep(&ctx->input_pads[i].name); From patchwork Tue Sep 8 21:18:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22199 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 6F9C244BE02 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 8609C68B7C9; Wed, 9 Sep 2020 00:19:47 +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 80D0D68B782 for ; Wed, 9 Sep 2020 00:19:44 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id z4so695802wrr.4 for ; Tue, 08 Sep 2020 14:19:44 -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=Kt1xDL97JnG0ru2ELD0IJpfI9NPRrLQapY+kwzuJKt4=; b=Jqq/N4egri4ArqeP/7TF70rBhJXQGVf5j/METi6hEJDFK7HqvmaBXkJ6X2Vkx1RPv2 ZpJV44Xb9no1t7of715MIhc1H5htOIiUAjmMw6tohElBm3ztsdSGYYrNwEA7o193Nbfm cplxF1INxzUU64AKHzAkskBWdFQp5vwegbgf3CPfgZp6Pl8DSDocdteQXdxSLkCXsQXJ qwD9NKijfmRdCu9IbPEAULR+Lc9bTLXx2/axx2flgez3hdBaP8TUxaFbkCqOSFbKqgup 2XKI+lGdqpik4YVhnR5kBPZV6zZnbbTGp5hUV3nbNMIq8rocBzh4sv3pxpjdcF6LheMU g5BA== 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=Kt1xDL97JnG0ru2ELD0IJpfI9NPRrLQapY+kwzuJKt4=; b=fMHSmOpJV2knOj76m07/WHoau5Mp5BTtOZKKVO5pZBgAGq342FXGFFOJGGHb40/PGj W7pbuCAHUCvvmsU/QIU4P4OPVczbIO1rKkH5I37E5yDkFpX8w8ioJLUhe+y7VpsgpIF9 hJ0VsWhbJyTTflhp+nmFdWaS6uwQ3/MAI7Ri5boTnGmk3JFMePrbmzdM1BmwjBx9YSHl nymriBpX44htQJeOz7z99uVKaPIPlo+5THeclnKwKgHST2XKCltmc5rrptHNgDiJ1YxA PVjXl98IjW/khRSsBfre4BUi5Cz+S582nlBj31GHCAYrOvbpjvdq9aAQbn9iyZUdzC1s AW4Q== X-Gm-Message-State: AOAM530dYR+Y0qotkuelGVKFk/5lINCaIvPoAxPSwqvh735G3ZF4JOnS 32Y3l3VB6zYRcZgyQ6+f31qrdYY4xY0= X-Google-Smtp-Source: ABdhPJxtEIPyxdZQNSZX/z+1u/JtmApuoGTk7OygAK5j7/V5khlhqQH96Falgvtaj2UssPCGpGLE+Q== X-Received: by 2002:a5d:4682:: with SMTP id u2mr601422wrq.254.1599599983713; Tue, 08 Sep 2020 14:19:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:43 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:54 +0200 Message-Id: <20200908211856.16290-23-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 23/25] avfilter/af_headphone: Use more appropriate variable name 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" Also unify incrementing the variable containing the pointer to the currently used HRIR data. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 8b0a431c45..8db546adbf 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -163,19 +163,18 @@ static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n } for (i = 0; i < in->nb_samples; i++) { - const float *temp_ir = ir; + const float *cur_ir = ir; *dst = 0; for (l = 0; l < in_channels; l++) { *(buffer[l] + wr) = src[l]; } - for (l = 0; l < in_channels; l++) { + for (l = 0; l < in_channels; cur_ir += air_len, l++) { const float *const bptr = buffer[l]; if (l == s->lfe_channel) { *dst += *(buffer[s->lfe_channel] + wr) * s->gain_lfe; - temp_ir += air_len; continue; } @@ -190,8 +189,7 @@ static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n memcpy(temp_src + len, bptr, (air_len - len) * sizeof(*temp_src)); } - dst[0] += s->scalarproduct_float(temp_ir, temp_src, FFALIGN(ir_len, 32)); - temp_ir += air_len; + dst[0] += s->scalarproduct_float(cur_ir, temp_src, FFALIGN(ir_len, 32)); } if (fabsf(dst[0]) > 1) From patchwork Tue Sep 8 21:18:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22198 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 6CFD544BE25 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 7AD7E68B7A0; Wed, 9 Sep 2020 00:19:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB52768B7A7 for ; Wed, 9 Sep 2020 00:19:45 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id z9so375325wmk.1 for ; Tue, 08 Sep 2020 14:19:45 -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=j7RICgBj+n+d/Afm6itoujgH4v2WSn2k20eMyedp3RQ=; b=Abt5flmav10vDv6b5dDa1DaYv5v5HmfljEjP3i2/FEBrkXVtTcRiiHqKSXwKsA67Fe r9T68I5Xyt2pF7tRj0UaaRm+cinfSU8NEh5vAz/zFpTxMe8/JvZooens/N3BwyKkPPRf oWwu9dYt2Q77WszXJ3zdlhGfGnGf3xD89SCv5TQAqKUrpWclwAiCQGbQdMCQ4oxDZdLR IyG81oBIR38/1DlB22/x9Yuf5l89J6HVqRu7TA31zY7Qw+Sy0oVjcT9ci0/Yi4BZPV6t hwhfpEjoUpq7pyddzafwSMkUYjzmRSaD7PiK/2fOtz2n4oxRtPk0kjjbPtenNQCGKry6 rLXQ== 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=j7RICgBj+n+d/Afm6itoujgH4v2WSn2k20eMyedp3RQ=; b=fyar1Duz3XK0O8ACvqMcvHQvkW0ttoZcgPYeOvAEpMMAQXBRrRAbW0meeN925FiI+r HSEAfG4VeBU7p7GlR05xeczGw5lKQcTdTk2wnzQcY6wF8J30lPRpudBusu7/DKnFzTjd KPvcNfLJdeaeHVaaUzsFp0p7Q2Afw1APfm9lZHNO0+u4g5Z4MRiCxQgWdrWUE7fv67DU PQGczo3+2LnnMyNuTgoq/q7uS1+b1dxx0RGeMI+84wz4BrdErVwb9rlpTnff7jFOxyuA OD0IKMrXclGgFxjBxk5waqGsMzXz4n+AMC/QgxQGKbThPIQTD3dvKUaB0Ods50mswq1M NuqQ== X-Gm-Message-State: AOAM5310/KEBHHW77tCdgxLjJ9SkKqBl6Ks2kSxU7jW02w8CIz+TqMyG 1YDSnfeV1ZxX518cE8hCpnwLlYIqV4s= X-Google-Smtp-Source: ABdhPJwW0+xHoswSJNskaLRN2nfdFkQuCMbfEPiLXA8M69ShlwHHfEf/z9n4+KAGwm0SWJakxCbp8Q== X-Received: by 2002:a1c:9883:: with SMTP id a125mr324754wme.133.1599599984552; Tue, 08 Sep 2020 14:19:44 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:44 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:55 +0200 Message-Id: <20200908211856.16290-24-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 24/25] avfilter/af_headphone: Remove pointless additions 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" buffer_length is a power-of-two and modulo is buffer_length - 1, so that buffer_length & modulo is zero. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 8db546adbf..03ef88c4a4 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -178,7 +178,7 @@ static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n continue; } - read = (wr - (ir_len - 1) + buffer_length) & modulo; + read = (wr - (ir_len - 1)) & modulo; if (read + ir_len < buffer_length) { memcpy(temp_src, bptr + read, ir_len * sizeof(*temp_src)); From patchwork Tue Sep 8 21:18:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22191 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 86EEB44BD83 for ; Wed, 9 Sep 2020 00:19:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 71FE868B7BA; Wed, 9 Sep 2020 00:19:49 +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 196B468B7A7 for ; Wed, 9 Sep 2020 00:19:46 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id j2so679780wrx.7 for ; Tue, 08 Sep 2020 14:19:46 -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=a7fgdKq7h0nRwQb+xIMagC4HIHBddc6nAYFpWXdB2/U=; b=R0YQlZiRd3FG+trrf4w1myVJiTnIl8+2PXzTHz5TB22FzcTIWeN3o7XwqDaZX3RUOI x0LMazWUufXi4jJeZera0FKcIQe+XyitgFNAbu9BB55A2PrUyoTnZTUFO01HX0fdqfFf GAiH1wttNF1+etSAsQMRmZfF/Oc/9/Z6b27EjMjAR91BodweeAJIGtLNXw3GpD07NkbK cKsm7wHxfNhC71crEXmHdAX6z6PKENglQlSDSGJUDo8vbDXX1ubrEnZ9EGlOmoDTcyNl 7GNhQvslg4qnoIVufgPgPgcQ5rIZ+L0+kjQuzY39ogbSsAwAa0OXaVa7VfLWC09xED1n oZvQ== 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=a7fgdKq7h0nRwQb+xIMagC4HIHBddc6nAYFpWXdB2/U=; b=J7+q8hajUyRU5ko/WFQWBcUqWio7hqrv1axNHOPb8GGMozuiwuPwB14llaCsXBeZSq CE01J1cF+2+Ezdij/6WYUY4H5dwiOuxdXb1JbS0bFlnypS8vNvQdSEaFKRD5jP5apxzC mktMf5vfsB+QZofX9vA1DlWTb0GXbPUhqwS+TvylbDgZr4lLAwsNUIUvA0YCNUh8Ae+a sRgqAUDm9WinJBjMp4yKnmA5M7tWk42AYiisc4iyy+vgMKK4vWAnIUs67mGJt42OH4w4 mKshtGXKTk5NqwNRQ58zYIjMqFDBAENDC6zD0ndjtWgJTG1QPz4H2fPBBvyOtwKx9Lbh G84Q== X-Gm-Message-State: AOAM531TWQVaZd9OanqPkgKKNFvxcdzgD+txNsTAv+k6YTdCs1vh5AbH N1EFCv/YBXXzwAjxGiogrQn2277bQiQ= X-Google-Smtp-Source: ABdhPJzKJKw0lgiPEh93fWnX2r4PCta6H6Ckm9YRcrA9rXqOyqRgpv1V5LeTnwxaiGRpTHnY+qKeBQ== X-Received: by 2002:a5d:5261:: with SMTP id l1mr394043wrc.193.1599599985374; Tue, 08 Sep 2020 14:19:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:44 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:56 +0200 Message-Id: <20200908211856.16290-25-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 25/25] avfilter/af_headphone: Don't check for clipping in separate loop 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" Signed-off-by: Andreas Rheinhardt --- More patches will be coming later. libavfilter/af_headphone.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 03ef88c4a4..edf8e773d7 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -281,6 +281,8 @@ static int headphone_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, for (j = 0; j < in->nb_samples; j++) { dst[2 * j] += fft_acc[j].re * fft_scale; + if (fabsf(dst[2 * j]) > 1) + n_clippings[0]++; } for (j = 0; j < ir_len - 1; j++) { @@ -289,14 +291,6 @@ static int headphone_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, *(ringbuffer + write_pos) += fft_acc[in->nb_samples + j].re * fft_scale; } - for (i = 0; i < out->nb_samples; i++) { - if (fabsf(dst[0]) > 1) { - n_clippings[0]++; - } - - dst += 2; - } - *write = wr; return 0;