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; }