From patchwork Sun Apr 7 21:09:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 47903 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp2147231pzd; Sun, 7 Apr 2024 14:10:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWG2HKjf+ynqiGpgDHcbZahq6VJXCWPMcrcxOlTrE+zeqrkC9Nu+iTGdrdWJ3N55s8zx2wqFJLLn5gIvpjbvcnGwJS6qmwvLYWfBw== X-Google-Smtp-Source: AGHT+IGk7ijM42MJq2VKHJdl7P97Al5ScT9qIe55JJN3CBUYCRI5J8b/xvrIm4+k3M5E5wExSSFV X-Received: by 2002:a17:907:7dab:b0:a51:92df:6a29 with SMTP id oz43-20020a1709077dab00b00a5192df6a29mr6219250ejc.1.1712524256287; Sun, 07 Apr 2024 14:10:56 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gn41-20020a1709070d2900b00a51d83c1af6si194018ejc.126.2024.04.07.14.10.55; Sun, 07 Apr 2024 14:10:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b="p9dxhqQ/"; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CFC0668D23E; Mon, 8 Apr 2024 00:09:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01olkn2083.outbound.protection.outlook.com [40.92.64.83]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6682B68D20F for ; Mon, 8 Apr 2024 00:09:50 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=asxEI5ZRw8cwJ+kgkErZo3Eos3IRh/EIVsYzjEmJT0Q+28eaBOaB+j+94pv9pXWlDeZsgqM8k4AepTo0aKcni5m4yzIU29VVKL4t3ZWMVUCZIhHmM7zKi4ND9peFMK/2pWEi87L6jvkqKm41Cra87UtaIpUTnt5m5Mq7HK01ekXNq230uR4Lip1p5EeXPfgyhZy5IvmAoKz6YqAOdw5f5Y4zgdK1xZO+ryzLQyeGbnlvoreh9nd8MiVnkZwp5MzMkPx1IY4CklB3NPT1IMQEdvTKdCl/5VOiXzYdLjEGdC4gwnbeuRkm1soAUlqS8SbqKA6vlBzYK22WAOJFRlt89w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FNPxaTwXtihT2uDNqAhKpO7xkelB4uLUqyLKBTvZgC0=; b=YLkwauaxucz2nAcYsLvNnTDRQOAUVlawU4SFv/6FelrX6Kga1bdoHmbq7NR9ajoQeLNIwGH3KV3Q036ZASlWSTXQqj2PEzZ9nU7hbOYXq8TZsK2V6wF7glbNYv+VdN/5EOa2dnJpswygi/HQQZd/Z5PQvBdQO7StlXepmD2tp2+LHZvvRQqG2VlMwrnUngS0K7Wr1BPo5WnVSc/hUVL/ZEBANagQE+f4UuzEsyuarYQ4+RNZLmxMVv0rbESyVvd8ZMOnJEsjD7iz0qW9cndlTtd067qEFWAGHXerJUTM9wdnI5TTdqgXVHPCrXpccN2/ySyKEnOdsWhnWVk02jM62Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FNPxaTwXtihT2uDNqAhKpO7xkelB4uLUqyLKBTvZgC0=; b=p9dxhqQ/VPAeuaU7rDg+TMDPvXelP0VTQxsdkzk3Hg5pbXfB25AOEwqInfR9NkSZBaF4nP86jalWkNH4bTdn+KdY5Lg+HzyD9SSVHBJYgBq4wdzrJRORMqL6rUbbd67lTA72Qt6fSK+DtwfywJeilf7n1Y//HR8LFp8VRPFCGyF0+1/8VRPEv31PRMeLhwyyPT1Fd+l/dKBsCtlYw/8QlnTuF4R4EdXhyR37m+3DknxNkRh3I7tZ8DuSOzaLyX56K7jYbQwKVCjjpI+293G0cGmkrpY+2vKTFVY7iiSjrFuO9uH8SxUn+5JekNXFWr7mAG85ZWfDF5xUT5mkBmYzZA== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by AS8P250MB0234.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.55; Sun, 7 Apr 2024 21:09:41 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d%4]) with mapi id 15.20.7409.042; Sun, 7 Apr 2024 21:09:41 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 Apr 2024 23:09:10 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [ztGGLhVWvBabczOmFmbZxNiMK7QCHFtHt6h1AlqBlgE=] X-ClientProxiedBy: ZR0P278CA0038.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::7) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240407210915.895619-11-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|AS8P250MB0234:EE_ X-MS-Office365-Filtering-Correlation-Id: 4cf1efc4-8647-4e3f-2b86-08dc57470af3 X-MS-Exchange-SLBlob-MailProps: Cq7lScuPrnpOxDCcKCE3ew6GouC7ydNhd5zciuXZEen9o1o3fXLwnZBageyMAdX8gYyebmY2CLKzYdA7Y7zu9p5N82MsgxHtcr4r7th21btDZ2gQB3XGkXb8YgA7AFSBkFIoaV6FR9j0IYrOC8zkZFMq9NN0fDTPGnZqy88bWlR9au0pXe5Y9lGYzVPA5TyJ1Q2WdvVFFZ75xc7BTaVJEBhvWT2fs1qA6ysxrxnBMC8CskTK4Z3YIqYZXdVmqf22TE2pt4Pw2dtNDOIVvnRRbjRumJkPTnuzBJ1ycvcZJtVI0nEO1VZt/o+bcsUKb1RykVv+JZkNvfDwDExBNt4JHT+grCWR7oSnTKjFAoQ0GzLIfj4xbdc0IAD0Z0AP2wuPV+tmDn0fRPrEXE8UNOlfj/j105YsuZowWrKFFGdJqolwtD7wKkK0/OJazsHyQWUGk031z4eDA4VxNvXjZXB3osxBQuCg7i8IEr+GscIvHYes2Jhem3yvqBFeXqjfsEntfKx/7g7FH+N0c4FlQ3j5ihjknp/vbEaCxd81Riz60TnV8EH7k47gqqMFOAuxuFaWaGLgk6+dVG8fJkuLhrOSpwW8YjyNEsp98JYcBZAkPJ5KcLLHKPNbEg46rNZbF/zz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URrSPTtoCdPb38RJOaDV0+M+aw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4cf1efc4-8647-4e3f-2b86-08dc57470af3 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2024 21:09:41.9405 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P250MB0234 Subject: [FFmpeg-devel] [PATCH 12/17] avcodec/ac3enc: Deduplicate copying input samples X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: tjhdp2FMk2LK These memcpy operands only depend upon sizeof(SampleType) (and this size is actually the same for both the fixed-point and the floating-point encoders for most (all supported?) systems). Signed-off-by: Andreas Rheinhardt --- libavcodec/ac3enc.c | 25 ++++++++++++++++++++++++- libavcodec/ac3enc.h | 2 +- libavcodec/ac3enc_template.c | 27 +-------------------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 681b227d3d..7adb1c444a 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -503,6 +503,27 @@ static void ac3_adjust_frame_size(AC3EncodeContext *s) s->samples_written += AC3_BLOCK_SIZE * s->num_blocks; } +/* + * Copy input samples. + * Channels are reordered from FFmpeg's default order to AC-3 order. + */ +static void copy_input_samples(AC3EncodeContext *s, uint8_t * const *samples) +{ + const unsigned sampletype_size = SAMPLETYPE_SIZE(s); + + /* copy and remap input samples */ + for (int ch = 0; ch < s->channels; ch++) { + /* copy last 256 samples of previous frame to the start of the current frame */ + memcpy(&s->planar_samples[ch][0], + s->planar_samples[ch] + AC3_BLOCK_SIZE * sampletype_size * s->num_blocks, + AC3_BLOCK_SIZE * sampletype_size); + + /* copy new samples for current frame */ + memcpy(s->planar_samples[ch] + AC3_BLOCK_SIZE * sampletype_size, + samples[s->channel_map[ch]], + sampletype_size * AC3_BLOCK_SIZE * s->num_blocks); + } +} /** * Set the initial coupling strategy parameters prior to coupling analysis. @@ -1996,7 +2017,9 @@ int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (s->bit_alloc.sr_code == 1 || s->eac3) ac3_adjust_frame_size(s); - s->encode_frame(s, frame); + copy_input_samples(s, frame->extended_data); + + s->encode_frame(s); ac3_apply_rematrixing(s); diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h index 8d6cb3b3de..271f0eb8eb 100644 --- a/libavcodec/ac3enc.h +++ b/libavcodec/ac3enc.h @@ -255,7 +255,7 @@ typedef struct AC3EncodeContext { int ref_bap_set; ///< indicates if ref_bap pointers have been set /** fixed vs. float function pointers */ - void (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame); + void (*encode_frame)(struct AC3EncodeContext *s); /* fixed vs. float function pointers */ int (*mdct_init)(struct AC3EncodeContext *s); diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c index 3646e1dcaa..b0f9e69ee8 100644 --- a/libavcodec/ac3enc_template.c +++ b/libavcodec/ac3enc_template.c @@ -38,29 +38,6 @@ #include "eac3enc.h" -/* - * Copy input samples. - * Channels are reordered from FFmpeg's default order to AC-3 order. - */ -static void copy_input_samples(AC3EncodeContext *s, SampleType **samples) -{ - int ch; - - /* copy and remap input samples */ - for (ch = 0; ch < s->channels; ch++) { - /* copy last 256 samples of previous frame to the start of the current frame */ - memcpy(&s->planar_samples[ch][0], - (SampleType*)s->planar_samples[ch] + AC3_BLOCK_SIZE * s->num_blocks, - AC3_BLOCK_SIZE * sizeof(SampleType)); - - /* copy new samples for current frame */ - memcpy((SampleType*)s->planar_samples[ch] + AC3_BLOCK_SIZE, - samples[s->channel_map[ch]], - AC3_BLOCK_SIZE * s->num_blocks * sizeof(SampleType)); - } -} - - /* * Apply the MDCT to input samples to generate frequency coefficients. * This applies the KBD window and normalizes the input to reduce precision @@ -353,10 +330,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) } -static void encode_frame(AC3EncodeContext *s, const AVFrame *frame) +static void encode_frame(AC3EncodeContext *s) { - copy_input_samples(s, (SampleType **)frame->extended_data); - apply_mdct(s); s->cpl_on = s->cpl_enabled;