From patchwork Sun Apr 7 21:09:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 47900 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp2147109pzd; Sun, 7 Apr 2024 14:10:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXQ2lvz31yht+UCJ6IbVIG3AI7aKqyXGOwfeRcIH7DewKicOd9lD9t9F/KO2C98JDpw3OVYHZ1wFJUwsUY28HLVtW/PiHlfSTBn3Q== X-Google-Smtp-Source: AGHT+IGmxSMFP0Afdg7xHPU5IdBsVLMvYDiqaSFvc2vdIxwnXlglARHkjkpvKsdEd5ksLGhTTk7a X-Received: by 2002:a50:c05e:0:b0:56e:5b2:2d2a with SMTP id u30-20020a50c05e000000b0056e05b22d2amr6327579edd.3.1712524232181; Sun, 07 Apr 2024 14:10:32 -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 d17-20020a50f691000000b00568bc639c51si3143457edn.1.2024.04.07.14.10.31; Sun, 07 Apr 2024 14:10:32 -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=J7CElsJv; 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 122B768D18D; Mon, 8 Apr 2024 00:09:54 +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 E7DF868D1D2 for ; Mon, 8 Apr 2024 00:09:49 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iDOYbw5ku4NTHvzecM7ZRRWyt1Pzzjj4GpQP6OqSlWTbQ9bsAbOkuPHSkMOSRPJk1XW3JS89VIMmovnc8OW1PQdOZNXvFfH3zQU8IVlKCN+gVaL4Stv3eWEY68uatO/1IY5DJ/mBB5vLNgxI9Qd4sKdS/+S86EZAQbHYBNWjj8s2OP/GLMIEJJj8BGYw6fXu4JqfZYPeV9BI4V2UgAT/9UcF+PKSTeJlszDMdQJjpDe/MBQjOeO1Cb+8UIibxsVPgaiIDB9NJ+sVf0qhv1W7v4TG5azCd3J8jLP/Z61UmO4GxPYZqaO3n+T+Dr5CfruNI1TMCY3+uyQMCnO3K8o/UQ== 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=R1Sjj2n3ibAajZI++huhzjdwvkYyQX+ZX4UVn5LsEQ8=; b=E/kNpI/+oD0Z2BThbfqxKOYt+UJv2n4RKsgk/czsOtzc+qwxL0I8zYR9OctrYAmLP1A9RWWpV7xAVpkB9/9sU2ap97ZVNpww6H6g1Kpm5+16sWQaAEuztuTMWNDMles9axGoI7RluojQyV9SElpxnMYXj539AhVaIDWpO6NReCwENsr959DdiSXqB+8z7Kd0neayuDarOtvjE7Exgb6u2lRFCETkYwxokicF25lAy6nVk4yuEDXsThfFz6yveJdKi4hYnx19TXBXSQKAfEJ8h73dBsHsZ/9ym/ksmK61AlEIV/Ybb0vkq6V1tWWHi5KGP4Aa8AeWSq/e8FpFhoPquQ== 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=R1Sjj2n3ibAajZI++huhzjdwvkYyQX+ZX4UVn5LsEQ8=; b=J7CElsJv8XEeA2xc3l5W9eLHukiDzybu1dsyrRJpwauGXVAc6gNO6Dsdl7ULzsdL5pBUaSxcsorSlV6IZB3fuq9ZPhTq/paSXXKMQ+wjw2OBKifdbzijf3xUT+giD0Eb8jgCRS30WhbKERyVVO+Xe7PtceXKFFJy6Dwa3QNqH5zq/I6gNZVPOGBN+3PWauQFxEvaYYM6ft4YP+rbYrIBIyH56WH956C4IuWtVMs8O8npx7NPWxEHWNTTB0F8Cn5I2kpA47tCZTh75arvEuxtDA5b9mT9e90XtwGaQn9K9xLgA7SI7rTrwp4bbFqtc0P9Y258FKu7dvPMMKWqYagZWA== 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:40 +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:40 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 Apr 2024 23:09:08 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [AbX5fBCPX2lfJA14aGix+dbSc5ZFv0pqtocUdKcwxnM=] 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-9-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: dccfed32-b82a-4296-d9c9-08dc574709d1 X-MS-Exchange-SLBlob-MailProps: Cq7lScuPrnpOxDCcKCE3ew6GouC7ydNhHlEvF8L3gR4A8HukG/i0GNN8xlztWsBlcN06n40p9meoLyQJMd1zWlaKobekQGieJ8aNNNVo17QVfTRG+0LEaQZmThfKlRkU6DdMvC6cKlaH8Hk9ORbjumE28FEQzeDYhRjW6KYYJ7t2C0ttfAw9rVtbDF25bWXn5NcFjLo4M+etnQrKTHghKXXpcD31hbGm5WCellf0GSsgrxgdZ1VLbDHgH2+ExgRTO/RTPtdAUWpPWNyj9lTfgr+84y+iYJl4e7xCtiPh8VmZ+Fe1TBZ9GbqgWhXZTRjp6THM56itUR4Bpi9hXCO1HsB3zeD9zHFEVCylTsm5oFK9h19OxU6pFd45TJuPkTxfoLH1fcY/FQVbO9XHM+KL2TRedAthSSEKgk/g9em05Q4xKc8SAWAooHMYOYRqGAm11/Io8Y2XiDrtvx/kRmdaD/CkN3BOVD1mJT+KmMH9xRhOYvcyZyUqAgA5zkLpt8ovBl14b2S783VOqbv5RItf9qcQdrQeslLhDpeO0wApExGlDRrlqpbDCPrYi30Cdi25J1I9j8gZzJDSA4HSUUXlGes7k/pFGsdLr2EyfPzy1UOX/SGzU9Ab6dVBRweJaWzKIGEr5buldpIW59dwA+zbRgwT0xIosXzZT1DU07zHL/WyNWk/LDFAohz8pNUZHYohY+4WsZEYonuURSXlwMpUCMFGKH4ZdQ3ozs43qahU53pxg/qytKL6oxMapKrtr8mEfftDZXWaiBU= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EpjTbvCZyFLVRFbnmiV0VbxHxLdvwAUoNeTDCJLKSdNJQvxj70BT/0gi6yd4JKJPj7AK5yvofCNplN3i0KkQZJJ8J3NAq0TFxEom15k4ORZkw/Zv0SBmdlsO/IzdRPwoX+jkMbTiXlTS+DNRYyyk5V3JlHReb18C10AZJQS+MXVexktG97CSMeEv0V9ahiCmMNjoHP4Oqu/QnVj0NHuooaCDW3kJIMr9STm0jTGxDXt6pYFhMzN2aTegBNwuu9285GyghUXajjeeAeWEOec3+P4tyPPYyUesAWBPBS208ppiM4Q+AOHm0BZhCzk4fLR+pvDEyj1bLph8nNsTLSlLVUO7uBbpBoWhC8/StBTehp2R7f2AiLHpn2dWenmU32o7fJ5lwQcey2VpiBguPjmmVXVBpOilgEPSLZLEAcjRds1ctrdv8pJeyOuwlbHBvwVO2+dSrlT67LYk/40PtdRiwfA3G99O1gCm9mag5BWPmRWp+u1G4Z9GAwZowMnutYRkK0Zd4XfI+8AHj8CXlaESZ3HG5zS8XEfUY64aAxG14qGi/ktxEdpjKb5+ceV4yjTWmprQFB7JhqcoUFWGLfsJoZPyPneYUB7h5/Cl4Fhpi6gX/EDbH8eVtcV6+49ojDvO X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OBJ70V+BdGXw9kgYNv8PWqTeNU9wZfIwFNFXQll35vIGM2TV61ceDW4CiwdJaq2wcL0oOspPJsihEapmgDiLFK3oHqSxbF4BTzuEIiryWD7BXJQYnnRCcuFfI9NczfuTOWWllV+V0hWA6HzQcyNqlMwnvwY5E7k4j8M8pCGdbda6+lBI+tDfErQC9I0AzxzBhngvxRmBo69WpQyjY/BZp2GgXhMZdwJ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: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: dccfed32-b82a-4296-d9c9-08dc574709d1 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:40.0646 (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 10/17] avcodec/ac3enc: Share more code between fixed/float encoders 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: R7QcijVs3vMM Signed-off-by: Andreas Rheinhardt --- libavcodec/ac3enc.c | 19 +++++++++++++------ libavcodec/ac3enc.h | 5 +---- libavcodec/ac3enc_template.c | 15 +-------------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 1f05436720..ef1ac381c1 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -315,7 +315,7 @@ static void validate_mix_level(void *log_ctx, const char *opt_name, * * @param s AC-3 encoder private context */ -int ff_ac3_validate_metadata(AC3EncodeContext *s) +static int ac3_validate_metadata(AC3EncodeContext *s) { AVCodecContext *avctx = s->avctx; AC3EncOptions *opt = &s->options; @@ -488,7 +488,7 @@ int ff_ac3_validate_metadata(AC3EncodeContext *s) * * @param s AC-3 encoder private context */ -void ff_ac3_adjust_frame_size(AC3EncodeContext *s) +static void ac3_adjust_frame_size(AC3EncodeContext *s) { while (s->bits_written >= s->bit_rate && s->samples_written >= s->sample_rate) { s->bits_written -= s->bit_rate; @@ -1984,9 +1984,16 @@ int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, AC3EncodeContext *const s = avctx->priv_data; int ret; - ret = s->encode_frame(s, frame); - if (ret < 0) - return ret; + if (s->options.allow_per_frame_metadata) { + ret = ac3_validate_metadata(s); + if (ret) + return ret; + } + + if (s->bit_alloc.sr_code == 1 || s->eac3) + ac3_adjust_frame_size(s); + + s->encode_frame(s, frame); ac3_apply_rematrixing(s); @@ -2327,7 +2334,7 @@ static av_cold int validate_options(AC3EncodeContext *s) if (s->cutoff > (s->sample_rate >> 1)) s->cutoff = s->sample_rate >> 1; - ret = ff_ac3_validate_metadata(s); + ret = ac3_validate_metadata(s); if (ret) return ret; diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h index 1a51423ac1..3dc8acfd91 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 */ - int (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame); + void (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame); /* fixed vs. float function pointers */ int (*mdct_init)(struct AC3EncodeContext *s); @@ -277,9 +277,6 @@ int ff_ac3_float_encode_init(AVCodecContext *avctx); int ff_ac3_encode_close(AVCodecContext *avctx); -int ff_ac3_validate_metadata(AC3EncodeContext *s); - -void ff_ac3_adjust_frame_size(AC3EncodeContext *s); void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s); diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c index 2e0fb9e85a..56ce36c012 100644 --- a/libavcodec/ac3enc_template.c +++ b/libavcodec/ac3enc_template.c @@ -371,19 +371,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) } -static int encode_frame(AC3EncodeContext *s, const AVFrame *frame) +static void encode_frame(AC3EncodeContext *s, const AVFrame *frame) { - int ret; - - if (s->options.allow_per_frame_metadata) { - ret = ff_ac3_validate_metadata(s); - if (ret) - return ret; - } - - if (s->bit_alloc.sr_code == 1 || (AC3ENC_FLOAT && s->eac3)) - ff_ac3_adjust_frame_size(s); - copy_input_samples(s, (SampleType **)frame->extended_data); apply_mdct(s); @@ -399,6 +388,4 @@ static int encode_frame(AC3EncodeContext *s, const AVFrame *frame) #if AC3ENC_FLOAT scale_coefficients(s); #endif - - return 0; }