From patchwork Fri May 17 17:57: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: 48960 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp3035469pzb; Fri, 17 May 2024 10:57:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV6Na1y3vLZCRDZNG0cNPpj1j7othFhBSFZI7HjQk89dYjRYM2Hq77aphsJCjK2/Wyk38dIkpF+FAYYqrVGRXLhGShhDK+zXoZu2Q== X-Google-Smtp-Source: AGHT+IHq4U8n7W8Em5GAZwZp5nhQ5QIofIt/0Sb2MHSdGW0d/WD3dFP/3xBe30pHmNXvSF9jBKEp X-Received: by 2002:a17:906:f296:b0:a59:cb29:3fa8 with SMTP id a640c23a62f3a-a5a2d53adbbmr2257713466b.14.1715968656500; Fri, 17 May 2024 10:57:36 -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 a640c23a62f3a-a5a179463d1si959635866b.147.2024.05.17.10.57.30; Fri, 17 May 2024 10:57:36 -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=H88bTwh0; 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 87E3568C15A; Fri, 17 May 2024 20:57:26 +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-db5eur01olkn2091.outbound.protection.outlook.com [40.92.64.91]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 018AE68C15A for ; Fri, 17 May 2024 20:57:19 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SMDK7g0jzb+wDXY2nphklUonNI1pQhiMHDwbFCHw3iJmzPX1DRC6+99/5sa26QkQURCV2DNzKd/BycRWoZA6jzjDJ/xO2xCsQ6tIW1B2LvFlVUui98QZG00WncR2snLEz26NmMcZq0Q12Et1HOZEmcYqHHYChTw9OOesJmDEkYOM2fAURZxO2xt8CzF8kUpzZoD6wPiP4YWIhWwitIUZ4j13rJKkJl3q/LAP2RPGNFcae2M+TpnyuesVJbJ9O+Z4+ROFC2FSWq4cw5qsueRgYA5qerEYkcR0pM5jdBQi4ah0Z5cPgzce9+lvwfkG7/xyC0/HZpWoJt3IqXjlNlN8ow== 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=HMd8kK07m6X7UeVnqBn/EsHAvviwE74iXq3gY6gNa3I=; b=WjqI9raY4spBo5Jm81eiSeIZ9PJdA9f4v1OcbMrxrvjADIOlL7tIVc30EsPWpT38iAQAQiwyC9C53OeQ1plBILfdbuIU9ZLI8RSpIoDvdTpkDxheyJw20u42e6WFt1XfBxpUGieCh7v5p2ilaZSYJztHoLiaIdXA2TfgefWCXHpt61Nrs+1sDy+w1m93Dse57+rSWyTTXlNDA82QQ9IiCYV+a6GIwoB52kmdQQiFLWpjl82KdXvxVP06/p5VjbaknYdkW30mpIkYNveSsi/jkKF3EvnYLQ2NanXs3S1iPs2A+Qz7AGjBedWVkemn1XHrqJKMVqxdyk7J7sZOYLcNXw== 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=HMd8kK07m6X7UeVnqBn/EsHAvviwE74iXq3gY6gNa3I=; b=H88bTwh060pxNYXbCC4x5R8Vfz0xZBJrr/j0Vhzd8xUbEFYyP+KM5odD6njht1M6PFTw4plrf8eCRA6l13b9lx+sylC0QL+rhCdaEnyh5CG5U7IzV3YUvam5l6U4JeDbDew4qglc9GIOmCTW/a0rTeza7PjqX4XBxzc/R1YuKDWkjmtQSuNf6PC/7LpvCEIQ5vtVEqQ2iaB8CAnhiKtWANNepXYaqZkKOcPIi6Cb0fd9CpPjKug0ZO++Pdx+Q93Y90OAeXZioOQaqPo95P0fvCKq3A+nRf1DM4McPLn9z9YYbBnU1xy4tTnaTc58RZV03nDTzfJPi7Yv18ayYWkKhw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by PA2P250MB1070.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:40b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28; Fri, 17 May 2024 17:57:18 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9%4]) with mapi id 15.20.7544.052; Fri, 17 May 2024 17:57:18 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2024 19:57:10 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 X-TMN: [WOwvpbXMr8RSnx4yWXb5Pe/NSPI2gkC35JRs1IYlapo=] X-ClientProxiedBy: FR3P281CA0007.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1d::6) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240517175711.3969422-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|PA2P250MB1070:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e7f5eee-91cd-4d48-6b59-08dc769acae1 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|440099019|3412199016|1710799017; X-Microsoft-Antispam-Message-Info: H1W0hRLqYtOvF1hvlAdWab/vcdNKikwR9o1I4MD20hdC01GHR/MfUWte0Q5a2OC6vWUUZ5PmwkoGgfTXf1NYfVKCdlSs3yBigUY3lCXVwZQ03zs+QXK8b0xQWspvzEbvsXKMzh6SganrfwdnTkB5VpnZX/y61hMAUfhtYAk6dW637P4vdx6P/aRqC9uzes3RC9dV5Sq63E2w01W3w2DsVoE6pd8IB5fET6GVsYTqB4xMTj09tB/GYowRZlGdw78uQCLkfd5ovVjBO2B9PuUXbngTcljXK8zuPPseJFzbgkd30kJWuKYxy+34G1IkhdDRW06ZFWcCKbIn1GUWYZOXchShcWRp/52vxS2qcojswCeRfbwRD4McIfF98+sklS8or29JQMlapsMVrU3Kj5JAIU1VXTGO1golzg/3EP+lZZer0+l7ULCMwLCpP6u4QRt1dkXhSyun7/YCMaZ/1JdYfpq6wRRUQywqmFshiBBn+XdG49JGt1OP193lEX6EVEpV0H8HOGb6BtJ2UvcL6CtWxhcbPsfqMlsuszfJw5xvFgHkPSPOPVvgV82QNu6t9Hxw1Wj5GML1PVnADiig8hWrsTWc7dC8ITHHVxd1GN84LFQXnaXoglXizNEvT0UzJmV0 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1nvKdsYnVW+L50Ui37gWPdBjO3SO5Z2JPHJY8/vRIVi3b1JeOtdEQkx4P0l976aNixfQykqgjOpZLkQ3iT2OgdWAfzbS/SU4jfxifAaOYBjPSjEJQbn7Z9AK2JCtiLRaQPAsYyAkeMT7QlEcmDHWg0DdIPV0gY1NM5bYV3Ejd+S1QbF2OsojYcnZhVCNzbWbXLQVX/naXoqBsVkRclvjNCENvylg1sZSxs6o0o6yWIpOAiej94eMbeozXF7G4c3+/gVH1sr3SX9jTTMYOvgea48BNS17rBGgDVYsbtVT88CSGKT95EOgzJVxZ4tL50ZpJCUYlQzz7QFX1ko+Ix68wAvtWEYzptgt2HzfHoLude3WdxP/rjUzO5+Nmz7hyPrZJpDVLJZznN+CGsByGb1t+CA6sBDO8HLMuQpgI2nYa3w7wMxAWVZF6nw+rkA+GKX1S1r3pGmvsIvjQfVZzaYLRKqJQpGmj7hn890MPaqIdf76WeLSOCoCatNMequDlytSlTT46Y5ZiQh0PTZESDrvGQVnAZJRZmMvZsVjPTRmuPtXBz0wyyZZa8ofs6+jGAeczWjVg7W/0GFI8flOUiPKZ1vgvtcdLYRE2X+QxDguEKYxHJG1kj92PFIcff9onVIBNpXCpVfdLD8t1TIJcensXXJgIZLSmP2Opv1DmzH2AkIwKytNB2neOFXRPUkckDYtngEbuV4XsjmYeUXrEUmwyp1lvAS5SPLQ8sc4fE4SGJ+k5XPALaPHRNYKnkzIQc6XZ4HB267voKhjnlzYm2GzQsBx7NkicPud1QxIlOhB5pHuLg9BcKEUjlAPT9Yi+Y0OdD9fOLvl+pzErsWwyWTmf6J8LNY9kTYVYuwDari/LfJAqtt6IB3Vx2//pDaTdiHnzJX2/abVxQxo1EsC7uDibD9anTmddQFMfh2xGAD/4F6+JCEAwonGXtxCIDoll5JaQhanwenkS8DAUYHe54vheimqli+KaxubMgfSVhe91xTQw5AORjL5+oCYrJyuqKdY1cBL/9OB1cLRtBr8zng7mi52WlE/fGUOO2iOTm/3fFbLLhejUwqOwyY5kAei1L2pRtutAyrKAKvr0nTRLR/g6eOcZFfh/2+foypBzwJgstzGyVrtjJLAOEe8JSurKgSLZdBMx4hVBYfTMrmF+4dCMW45qd5hzEMj3mrp0FDnHRXxQTWp23HtjKWMgWW6a+MdNwHrP4uZvdlt5a0L+olFNv9FBsNjptZxOStx06iaJCC34WnU5KMD583CIWb9TlQgxWll2bZsz/SPCAhrdb23QQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e7f5eee-91cd-4d48-6b59-08dc769acae1 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2024 17:57:18.2475 (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: PA2P250MB1070 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/ac3enc_template: Avoid always-true check 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: xwHwOvidUBSI This might also help Coverity with issue #1596532. Signed-off-by: Andreas Rheinhardt --- libavcodec/ac3enc_template.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c index 49fc6d7f37..049666fdca 100644 --- a/libavcodec/ac3enc_template.c +++ b/libavcodec/ac3enc_template.c @@ -31,6 +31,7 @@ #include #include "libavutil/attributes.h" +#include "libavutil/avassert.h" #include "libavutil/mem_internal.h" #include "audiodsp.h" @@ -50,14 +51,15 @@ */ static void apply_mdct(AC3EncodeContext *s, uint8_t * const *samples) { - int blk, ch; + av_assert1(s->num_blocks > 0); - for (ch = 0; ch < s->channels; ch++) { + for (int ch = 0; ch < s->channels; ch++) { const SampleType *input_samples0 = (const SampleType*)s->planar_samples[ch]; /* Reorder channels from native order to AC-3 order. */ const SampleType *input_samples1 = (const SampleType*)samples[s->channel_map[ch]]; + int blk = 0; - for (blk = 0; blk < s->num_blocks; blk++) { + do { AC3Block *block = &s->blocks[blk]; SampleType *windowed_samples = s->RENAME(windowed_samples); @@ -71,7 +73,8 @@ static void apply_mdct(AC3EncodeContext *s, uint8_t * const *samples) windowed_samples, sizeof(*windowed_samples)); input_samples0 = input_samples1; input_samples1 += AC3_BLOCK_SIZE; - } + } while (++blk < s->num_blocks); + /* Store last 256 samples of current frame */ memcpy(s->planar_samples[ch], input_samples0, AC3_BLOCK_SIZE * sizeof(*input_samples0)); From patchwork Fri May 17 17:59: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: 48961 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp3036207pzb; Fri, 17 May 2024 10:59:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUjWZRUeZu3Qo0M4i/k7aolLjhDEJEGEsd9jfunWZEZbPo91yo9O1FDcusPvxO9Jufrw22VjpTJB2XkUhnTgTyCj9HdAZOQmTyNDg== X-Google-Smtp-Source: AGHT+IEc+aA2vnBzMXtL7MCHy0eHkk8h7tgc0J74C6yoexL1IsJJFqyCrx73ajXo/qNDucQIR33r X-Received: by 2002:adf:fe8c:0:b0:351:c7c7:985f with SMTP id ffacd0b85a97d-351c7c79963mr9092114f8f.53.1715968770066; Fri, 17 May 2024 10:59:30 -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 4fb4d7f45d1cf-574ec8bd2b6si4140655a12.195.2024.05.17.10.59.29; Fri, 17 May 2024 10:59:30 -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=s7L2NZGB; 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 EA03468C15A; Fri, 17 May 2024 20:59:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2016.outbound.protection.outlook.com [40.92.91.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 812BC68CABD for ; Fri, 17 May 2024 20:59:18 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Et0iCAuJA8leQhBUL+hACqSM5lSyic9+o2DJDOBrffdyhMo8Qo4xhpFjWavJ/P8zHDpwabAhuTR6Qy62nYIjFhejHf/TDkDBxOi019KQX+9la08Z014UGUdIWWhTPYi1UIx9qRSb9JbitGC6rJK1Q/wgsvMv52ENUHadsjQ5Ryl6GLJf/0huAIBeLhrP5qAlALr/Xzn7g5Ku2862gT5Xk/o+197UIlgkhDZ24KfseGGQo95shxn+cR0u00OjvJXPlTpWP+mrCEST2WG7PJ1RIUTRkZWEywxu5vpREf5vfH++F+QtUS17Z+nsDlj/O6cDQ9+o+5LR8xmCy+Q88QOPQQ== 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=Y7lru4ByaQvaGG8wH6vEc+7Da+xnpPsadRRaDGbrfSE=; b=mDsoCIVsSD7gOrpdpq7eSO6ETxKwBiOdiWZN34ZrCcYdtd/yOxXfVghnJP994bXg1vRY+gDen0kOQhwEp7rtGHMKy+eVKQVqrR4Xw45cFfqd2k4wMSiVizsihz2pp4ZdQQo2rUr6THLUhxIUlUUCChJZNlno8WgFbjSxwXLpodC7p/BachRj0kAvM3bkoaVBEZFLx0O77kteAver50I9MjUjQyYzBr2IW6MNKAuuaTP1bIODiZGGMw9ENxxm+hWkgCdrSNFmQgYtVm+LqSrlM3hPlXhfCTbYqq+hNbqmtFaFK1eAztjaNsp46wgzYqLEieUCFXRZ6/Jsvh5mMIAZ1g== 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=Y7lru4ByaQvaGG8wH6vEc+7Da+xnpPsadRRaDGbrfSE=; b=s7L2NZGBOS2EWB0J2AzNtqZXcyfQosLOsSqG0EFq8crE5O53VH4FblOcmPKT1fCUERlkU5jfUCaeXQ6DsUu0XnGM2kIqOAOqq0QglNpk9U/ff1Oa+HxB55Mt3D28wrWg1djt9Kxiq+o0a4q7ZzEM3kBg1pI6TAjIj4NsSCdO7abbePTbndw+dftwVLri070gIQjGgr3eufNrNugNfgM33pBjKF8HA2vFEPh3/LMpGqsOMgY5VsVHRwsVdUWtYz1U7rcV8jpEZi40WnKzCSTcfjQqmTXHlorfNYhaINgpWP/qPy/C9FnddhQtpXi1oY/kKjRPQluK8HNCtGHAh8VziA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by PR3P250MB0002.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:14d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28; Fri, 17 May 2024 17:59:16 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9%4]) with mapi id 15.20.7544.052; Fri, 17 May 2024 17:59:16 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2024 19:59:08 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [cqj7T1HsxWIPkgyg6U6y2WIEBdpPMTS5QXqnG2jZ0SE=] X-ClientProxiedBy: ZR0P278CA0222.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:6a::18) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240517175908.4017657-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|PR3P250MB0002:EE_ X-MS-Office365-Filtering-Correlation-Id: 50a9e655-7894-4dc0-7cb9-08dc769b1151 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|440099019|3412199016|1710799017; X-Microsoft-Antispam-Message-Info: 5DXRkmCPpdFJqwOg9tqS7Ku1QQNGBCQczTaBkT6wOwHxZ7YjS3tdm71minDSwyO9KRmUcUaBUfuO9FLDjz0dZF2Q+npf6MXEy+tSFN9T2aQphVVm/oxUVHoer3hZOfW2maOdUiLUzT/5it7Rz8XExWwKeS/dSqHbA3YtSt7fWVrQcBVf5wh4YUguAk7gynI9w6B32H1Z6qbr0J1dWZNgEXNHVX/JeSshGgcv7RN+oY8WY7Vk7QU/OG83g4tGGIWTlGhgdk5cUms3uteFpfyZ1Wl25LDxShAsYfI2PjEYxlJw2eOqs6bHGd3Lmhgh5gZ5KZKajbXEHuYUy4IEAm/FUMggP5VQ/6jN4OiV7PU7VlqHrBiScRRMC6IkYU8YKQl9m4aa472ACFfEAIDwtAjaplSbh0INSRIXq1ZNI/0w+HWNNft1t/0ADemdRK9uDm8dz3jkQ402a0yZfcqM8FsnWE0XMju8CraCbviJXsDRhteYPAbXKHrX85KnrabEa3V4pTExip4s0fAxEjHXTSwBp67TECE8T5hLs8bZWEWhNpqBFtZVsAxIqesMt58DZUv56vWYzHP8X55VugpaQON+fKAa0veWEMI66ef90Hjg3NLHxubk+cxtY2vlTvx23wvC X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: X9rDUdWR9XXz/v8P9YVC/eRVnN+X40LoUDJ29TKoTHEVAUzljuKhnPIq6laT7YCaZW3eP8h0CPf2wmjtWrYRGS5N5Ilk6+yJWmP1Yv96YLtHM9CbEL7tLN/Cb2yULqwjbqNA9In7JFxgptDK41W1DIr/vJuJlkGZasAHtJ/nntHdoLOF0fYpnhkZuaRv0zipfW1nqKpX0BU/LdrqP6sezO1sc2kB6nNbip9nJjMb2H2M0DXQ9UlN7PcLmeGcqvdX77WqXZkcU1d0uYapoZ1PLJmIpFhChBqradXtYq3QK5Bb/wDrVWh8NbqiMtYm4y/ZflKehr15l0WuLBzwyi3z+dnHao/1aI5Sy2dTjLYq3rZ8JpV0e4kDH2N02JX46esuRZC5UKFGKyHjm51/i2ChG+Ugxkop5Y8vU+YRSUtn9nvCtKfG6ELmCyCTdeWuPrcr+YuH5CpkGryWZkqBJARhAD05nuPfxbYCgZ3saWcvAEdfN374kAN4UKqnZZvgWbMaF+EudL9mwqIX5CLg1YqLQk7S6zfu1HPxu0nfTdNAbtvTWiP27HRvb1jn8MSG3zvhbAhmYGUQfwVu8bl8jlCODPZvr5efXXPaNFrCgqGZy/Uz8zJsENQKXZHlA9FE9zk2DVXmvQHHyUaq7fN9ePGD/q9y6UZxISeppC1CqdaWhFNp9k7KF8DnJz8gobYQg+xoBtH/X73RStywEl08/afWVkyVCuFY64mpCIbE3vZg1ib9lsg7xDHrWd30tqPFgLu5QfhJul1OggD4Fw/eUzR3R+gFf/pqXUa5OGPAIQTnyLRRXtJ+BS1tIlNG8lGcP3sj21M5ETZAGE3PQ39BiUhj6ih9UHIFe+yEoDAM7+DVPk5L2PtE5RQudRClhEzjUT/3XWQZ8yg05HgeHN46dQMS7snj26ktTqvbBvS7jHm6VkT14lI86TaNMlCJtz8sulr99FPTz44/d0RlHqje5nV5CbZE3mgKLkA60T6xD0vgvN1PJw/Of/p3L5XpkfkAGdI4cVisEwZbLNkFvZhYQe7y5l54ued+9lDcdSqjod2EbaD5VGTy9BUvhnU5UAcpZsAoJipoBnTBK2pdde1/36VXgos9ZlAdx0oOEGElV2naD0RxnmL4//7Hcll6N1ac3toOr+lcg0iTOeogQ6VnA9HmJIDseyWQ6hLycgA7COKi0EbmCPr0SIOEzDScFUPKiyTxykZ1MHicPkpqBi7zb3WuqojZgGOzE7vPMVyIjoqjaJlMjAfqVOdd8z0qTqffqyFlbknfNTiD1FbdfDEF5jJXcw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50a9e655-7894-4dc0-7cb9-08dc769b1151 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2024 17:59:16.3940 (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: PR3P250MB0002 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/ac3enc: Move transient PutBitContext to stack 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: O/HRPUjS1zsq Signed-off-by: Andreas Rheinhardt --- libavcodec/ac3enc.c | 187 ++++++++++++++++++++++--------------------- libavcodec/ac3enc.h | 6 +- libavcodec/eac3enc.c | 123 ++++++++++++++-------------- 3 files changed, 159 insertions(+), 157 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 1a869ab865..3649289865 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -1634,63 +1634,63 @@ static void ac3_quantize_mantissas(AC3EncodeContext *s) /* * Write the AC-3 frame header to the output bitstream. */ -static void ac3_output_frame_header(AC3EncodeContext *s) +static void ac3_output_frame_header(AC3EncodeContext *s, PutBitContext *pb) { AC3EncOptions *opt = &s->options; - put_bits(&s->pb, 16, 0x0b77); /* frame header */ - put_bits(&s->pb, 16, 0); /* crc1: will be filled later */ - put_bits(&s->pb, 2, s->bit_alloc.sr_code); - put_bits(&s->pb, 6, s->frame_size_code + (s->frame_size - s->frame_size_min) / 2); - put_bits(&s->pb, 5, s->bitstream_id); - put_bits(&s->pb, 3, s->bitstream_mode); - put_bits(&s->pb, 3, s->channel_mode); + put_bits(pb, 16, 0x0b77); /* frame header */ + put_bits(pb, 16, 0); /* crc1: will be filled later */ + put_bits(pb, 2, s->bit_alloc.sr_code); + put_bits(pb, 6, s->frame_size_code + (s->frame_size - s->frame_size_min) / 2); + put_bits(pb, 5, s->bitstream_id); + put_bits(pb, 3, s->bitstream_mode); + put_bits(pb, 3, s->channel_mode); if ((s->channel_mode & 0x01) && s->channel_mode != AC3_CHMODE_MONO) - put_bits(&s->pb, 2, s->center_mix_level); + put_bits(pb, 2, s->center_mix_level); if (s->channel_mode & 0x04) - put_bits(&s->pb, 2, s->surround_mix_level); + put_bits(pb, 2, s->surround_mix_level); if (s->channel_mode == AC3_CHMODE_STEREO) - put_bits(&s->pb, 2, opt->dolby_surround_mode); - put_bits(&s->pb, 1, s->lfe_on); /* LFE */ - put_bits(&s->pb, 5, -opt->dialogue_level); - put_bits(&s->pb, 1, 0); /* no compression control word */ - put_bits(&s->pb, 1, 0); /* no lang code */ - put_bits(&s->pb, 1, opt->audio_production_info); + put_bits(pb, 2, opt->dolby_surround_mode); + put_bits(pb, 1, s->lfe_on); /* LFE */ + put_bits(pb, 5, -opt->dialogue_level); + put_bits(pb, 1, 0); /* no compression control word */ + put_bits(pb, 1, 0); /* no lang code */ + put_bits(pb, 1, opt->audio_production_info); if (opt->audio_production_info) { - put_bits(&s->pb, 5, opt->mixing_level - 80); - put_bits(&s->pb, 2, opt->room_type); + put_bits(pb, 5, opt->mixing_level - 80); + put_bits(pb, 2, opt->room_type); } - put_bits(&s->pb, 1, opt->copyright); - put_bits(&s->pb, 1, opt->original); + put_bits(pb, 1, opt->copyright); + put_bits(pb, 1, opt->original); if (s->bitstream_id == 6) { /* alternate bit stream syntax */ - put_bits(&s->pb, 1, opt->extended_bsi_1); + put_bits(pb, 1, opt->extended_bsi_1); if (opt->extended_bsi_1) { - put_bits(&s->pb, 2, opt->preferred_stereo_downmix); - put_bits(&s->pb, 3, s->ltrt_center_mix_level); - put_bits(&s->pb, 3, s->ltrt_surround_mix_level); - put_bits(&s->pb, 3, s->loro_center_mix_level); - put_bits(&s->pb, 3, s->loro_surround_mix_level); + put_bits(pb, 2, opt->preferred_stereo_downmix); + put_bits(pb, 3, s->ltrt_center_mix_level); + put_bits(pb, 3, s->ltrt_surround_mix_level); + put_bits(pb, 3, s->loro_center_mix_level); + put_bits(pb, 3, s->loro_surround_mix_level); } - put_bits(&s->pb, 1, opt->extended_bsi_2); + put_bits(pb, 1, opt->extended_bsi_2); if (opt->extended_bsi_2) { - put_bits(&s->pb, 2, opt->dolby_surround_ex_mode); - put_bits(&s->pb, 2, opt->dolby_headphone_mode); - put_bits(&s->pb, 1, opt->ad_converter_type); - put_bits(&s->pb, 9, 0); /* xbsi2 and encinfo : reserved */ + put_bits(pb, 2, opt->dolby_surround_ex_mode); + put_bits(pb, 2, opt->dolby_headphone_mode); + put_bits(pb, 1, opt->ad_converter_type); + put_bits(pb, 9, 0); /* xbsi2 and encinfo : reserved */ } } else { - put_bits(&s->pb, 1, 0); /* no time code 1 */ - put_bits(&s->pb, 1, 0); /* no time code 2 */ + put_bits(pb, 1, 0); /* no time code 1 */ + put_bits(pb, 1, 0); /* no time code 2 */ } - put_bits(&s->pb, 1, 0); /* no additional bit stream info */ + put_bits(pb, 1, 0); /* no additional bit stream info */ } /* * Write one audio block to the output bitstream. */ -static void output_audio_block(AC3EncodeContext *s, int blk) +static void output_audio_block(AC3EncodeContext *s, PutBitContext *pb, int blk) { int ch, i, baie, bnd, got_cpl, av_uninit(ch0); AC3Block *block = &s->blocks[blk]; @@ -1698,48 +1698,48 @@ static void output_audio_block(AC3EncodeContext *s, int blk) /* block switching */ if (!s->eac3) { for (ch = 0; ch < s->fbw_channels; ch++) - put_bits(&s->pb, 1, 0); + put_bits(pb, 1, 0); } /* dither flags */ if (!s->eac3) { for (ch = 0; ch < s->fbw_channels; ch++) - put_bits(&s->pb, 1, 1); + put_bits(pb, 1, 1); } /* dynamic range codes */ - put_bits(&s->pb, 1, 0); + put_bits(pb, 1, 0); /* spectral extension */ if (s->eac3) - put_bits(&s->pb, 1, 0); + put_bits(pb, 1, 0); /* channel coupling */ if (!s->eac3) - put_bits(&s->pb, 1, block->new_cpl_strategy); + put_bits(pb, 1, block->new_cpl_strategy); if (block->new_cpl_strategy) { if (!s->eac3) - put_bits(&s->pb, 1, block->cpl_in_use); + put_bits(pb, 1, block->cpl_in_use); if (block->cpl_in_use) { int start_sub, end_sub; if (s->eac3) - put_bits(&s->pb, 1, 0); /* enhanced coupling */ + put_bits(pb, 1, 0); /* enhanced coupling */ if (!s->eac3 || s->channel_mode != AC3_CHMODE_STEREO) { for (ch = 1; ch <= s->fbw_channels; ch++) - put_bits(&s->pb, 1, block->channel_in_cpl[ch]); + put_bits(pb, 1, block->channel_in_cpl[ch]); } if (s->channel_mode == AC3_CHMODE_STEREO) - put_bits(&s->pb, 1, 0); /* phase flags in use */ + put_bits(pb, 1, 0); /* phase flags in use */ start_sub = (s->start_freq[CPL_CH] - 37) / 12; end_sub = (s->cpl_end_freq - 37) / 12; - put_bits(&s->pb, 4, start_sub); - put_bits(&s->pb, 4, end_sub - 3); + put_bits(pb, 4, start_sub); + put_bits(pb, 4, end_sub - 3); /* coupling band structure */ if (s->eac3) { - put_bits(&s->pb, 1, 0); /* use default */ + put_bits(pb, 1, 0); /* use default */ } else { for (bnd = start_sub+1; bnd < end_sub; bnd++) - put_bits(&s->pb, 1, ff_eac3_default_cpl_band_struct[bnd]); + put_bits(pb, 1, ff_eac3_default_cpl_band_struct[bnd]); } } } @@ -1749,12 +1749,12 @@ static void output_audio_block(AC3EncodeContext *s, int blk) for (ch = 1; ch <= s->fbw_channels; ch++) { if (block->channel_in_cpl[ch]) { if (!s->eac3 || block->new_cpl_coords[ch] != 2) - put_bits(&s->pb, 1, block->new_cpl_coords[ch]); + put_bits(pb, 1, block->new_cpl_coords[ch]); if (block->new_cpl_coords[ch]) { - put_bits(&s->pb, 2, block->cpl_master_exp[ch]); + put_bits(pb, 2, block->cpl_master_exp[ch]); for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { - put_bits(&s->pb, 4, block->cpl_coord_exp [ch][bnd]); - put_bits(&s->pb, 4, block->cpl_coord_mant[ch][bnd]); + put_bits(pb, 4, block->cpl_coord_exp [ch][bnd]); + put_bits(pb, 4, block->cpl_coord_mant[ch][bnd]); } } } @@ -1764,26 +1764,26 @@ static void output_audio_block(AC3EncodeContext *s, int blk) /* stereo rematrixing */ if (s->channel_mode == AC3_CHMODE_STEREO) { if (!s->eac3 || blk > 0) - put_bits(&s->pb, 1, block->new_rematrixing_strategy); + put_bits(pb, 1, block->new_rematrixing_strategy); if (block->new_rematrixing_strategy) { /* rematrixing flags */ for (bnd = 0; bnd < block->num_rematrixing_bands; bnd++) - put_bits(&s->pb, 1, block->rematrixing_flags[bnd]); + put_bits(pb, 1, block->rematrixing_flags[bnd]); } } /* exponent strategy */ if (!s->eac3) { for (ch = !block->cpl_in_use; ch <= s->fbw_channels; ch++) - put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); + put_bits(pb, 2, s->exp_strategy[ch][blk]); if (s->lfe_on) - put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); + put_bits(pb, 1, s->exp_strategy[s->lfe_channel][blk]); } /* bandwidth */ for (ch = 1; ch <= s->fbw_channels; ch++) { if (s->exp_strategy[ch][blk] != EXP_REUSE && !block->channel_in_cpl[ch]) - put_bits(&s->pb, 6, s->bandwidth_code); + put_bits(pb, 6, s->bandwidth_code); } /* exponents */ @@ -1795,58 +1795,58 @@ static void output_audio_block(AC3EncodeContext *s, int blk) continue; /* DC exponent */ - put_bits(&s->pb, 4, block->grouped_exp[ch][0] >> cpl); + put_bits(pb, 4, block->grouped_exp[ch][0] >> cpl); /* exponent groups */ nb_groups = exponent_group_tab[cpl][s->exp_strategy[ch][blk]-1][block->end_freq[ch]-s->start_freq[ch]]; for (i = 1; i <= nb_groups; i++) - put_bits(&s->pb, 7, block->grouped_exp[ch][i]); + put_bits(pb, 7, block->grouped_exp[ch][i]); /* gain range info */ if (ch != s->lfe_channel && !cpl) - put_bits(&s->pb, 2, 0); + put_bits(pb, 2, 0); } /* bit allocation info */ if (!s->eac3) { baie = (blk == 0); - put_bits(&s->pb, 1, baie); + put_bits(pb, 1, baie); if (baie) { - put_bits(&s->pb, 2, s->slow_decay_code); - put_bits(&s->pb, 2, s->fast_decay_code); - put_bits(&s->pb, 2, s->slow_gain_code); - put_bits(&s->pb, 2, s->db_per_bit_code); - put_bits(&s->pb, 3, s->floor_code); + put_bits(pb, 2, s->slow_decay_code); + put_bits(pb, 2, s->fast_decay_code); + put_bits(pb, 2, s->slow_gain_code); + put_bits(pb, 2, s->db_per_bit_code); + put_bits(pb, 3, s->floor_code); } } /* snr offset */ if (!s->eac3) { - put_bits(&s->pb, 1, block->new_snr_offsets); + put_bits(pb, 1, block->new_snr_offsets); if (block->new_snr_offsets) { - put_bits(&s->pb, 6, s->coarse_snr_offset); + put_bits(pb, 6, s->coarse_snr_offset); for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { - put_bits(&s->pb, 4, s->fine_snr_offset[ch]); - put_bits(&s->pb, 3, s->fast_gain_code[ch]); + put_bits(pb, 4, s->fine_snr_offset[ch]); + put_bits(pb, 3, s->fast_gain_code[ch]); } } } else { - put_bits(&s->pb, 1, 0); /* no converter snr offset */ + put_bits(pb, 1, 0); /* no converter snr offset */ } /* coupling leak */ if (block->cpl_in_use) { if (!s->eac3 || block->new_cpl_leak != 2) - put_bits(&s->pb, 1, block->new_cpl_leak); + put_bits(pb, 1, block->new_cpl_leak); if (block->new_cpl_leak) { - put_bits(&s->pb, 3, s->bit_alloc.cpl_fast_leak); - put_bits(&s->pb, 3, s->bit_alloc.cpl_slow_leak); + put_bits(pb, 3, s->bit_alloc.cpl_fast_leak); + put_bits(pb, 3, s->bit_alloc.cpl_slow_leak); } } if (!s->eac3) { - put_bits(&s->pb, 1, 0); /* no delta bit allocation */ - put_bits(&s->pb, 1, 0); /* no data to skip */ + put_bits(pb, 1, 0); /* no delta bit allocation */ + put_bits(pb, 1, 0); /* no data to skip */ } /* mantissas */ @@ -1864,13 +1864,13 @@ static void output_audio_block(AC3EncodeContext *s, int blk) b = s->ref_bap[ch][blk][i]; switch (b) { case 0: break; - case 1: if (q != 128) put_bits (&s->pb, 5, q); break; - case 2: if (q != 128) put_bits (&s->pb, 7, q); break; - case 3: put_sbits(&s->pb, 3, q); break; - case 4: if (q != 128) put_bits (&s->pb, 7, q); break; - case 14: put_sbits(&s->pb, 14, q); break; - case 15: put_sbits(&s->pb, 16, q); break; - default: put_sbits(&s->pb, b-1, q); break; + case 1: if (q != 128) put_bits (pb, 5, q); break; + case 2: if (q != 128) put_bits (pb, 7, q); break; + case 3: put_sbits(pb, 3, q); break; + case 4: if (q != 128) put_bits (pb, 7, q); break; + case 14: put_sbits(pb, 14, q); break; + case 15: put_sbits(pb, 16, q); break; + default: put_sbits(pb, b-1, q); break; } } if (ch == CPL_CH) @@ -1917,7 +1917,7 @@ static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly) /* * Fill the end of the frame with 0's and compute the two CRCs. */ -static void output_frame_end(AC3EncodeContext *s) +static void output_frame_end(AC3EncodeContext *s, PutBitContext *pb) { const AVCRC *crc_ctx = av_crc_get_table(AV_CRC_16_ANSI); int frame_size_58, pad_bytes, crc1, crc2, crc_inv; @@ -1926,13 +1926,13 @@ static void output_frame_end(AC3EncodeContext *s) frame_size_58 = ((s->frame_size >> 2) + (s->frame_size >> 4)) << 1; /* pad the remainder of the frame with zeros */ - av_assert2(s->frame_size * 8 - put_bits_count(&s->pb) >= 18); - flush_put_bits(&s->pb); - frame = s->pb.buf; - pad_bytes = s->frame_size - (put_bits_ptr(&s->pb) - frame) - 2; + av_assert2(s->frame_size * 8 - put_bits_count(pb) >= 18); + flush_put_bits(pb); + frame = pb->buf; + pad_bytes = s->frame_size - (put_bits_ptr(pb) - frame) - 2; av_assert2(pad_bytes >= 0); if (pad_bytes > 0) - memset(put_bits_ptr(&s->pb), 0, pad_bytes); + memset(put_bits_ptr(pb), 0, pad_bytes); if (s->eac3) { /* compute crc2 */ @@ -1969,16 +1969,17 @@ static void output_frame_end(AC3EncodeContext *s) */ static void ac3_output_frame(AC3EncodeContext *s, unsigned char *frame) { + PutBitContext pb; int blk; - init_put_bits(&s->pb, frame, s->frame_size); + init_put_bits(&pb, frame, s->frame_size); - s->output_frame_header(s); + s->output_frame_header(s, &pb); for (blk = 0; blk < s->num_blocks; blk++) - output_audio_block(s, blk); + output_audio_block(s, &pb, blk); - output_frame_end(s); + output_frame_end(s, &pb); } int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h index 30812617cc..5e98ad188b 100644 --- a/libavcodec/ac3enc.h +++ b/libavcodec/ac3enc.h @@ -41,7 +41,6 @@ #include "codec_internal.h" #include "mathops.h" #include "me_cmp.h" -#include "put_bits.h" #include "audiodsp.h" #ifndef AC3ENC_FLOAT @@ -151,6 +150,8 @@ typedef struct AC3Block { int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin (endmant) } AC3Block; +struct PutBitContext; + /** * AC-3 encoder private context. */ @@ -158,7 +159,6 @@ typedef struct AC3EncodeContext { AVClass *av_class; ///< AVClass used for AVOption AC3EncOptions options; ///< encoding options AVCodecContext *avctx; ///< parent AVCodecContext - PutBitContext pb; ///< bitstream writer context AudioDSPContext adsp; #if AC3ENC_FLOAT AVFloatDSPContext *fdsp; @@ -256,7 +256,7 @@ typedef struct AC3EncodeContext { void (*encode_frame)(struct AC3EncodeContext *s, uint8_t * const *samples); /* AC-3 vs. E-AC-3 function pointers */ - void (*output_frame_header)(struct AC3EncodeContext *s); + void (*output_frame_header)(struct AC3EncodeContext *s, struct PutBitContext *pb); union { DECLARE_ALIGNED(32, float, mdct_window_float)[AC3_BLOCK_SIZE]; diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c index c957174a70..8ef3e7e773 100644 --- a/libavcodec/eac3enc.c +++ b/libavcodec/eac3enc.c @@ -32,6 +32,7 @@ #include "codec_internal.h" #include "eac3enc.h" #include "eac3_data.h" +#include "put_bits.h" static const AVClass eac3enc_class = { @@ -129,124 +130,124 @@ void ff_eac3_set_cpl_states(AC3EncodeContext *s) /** * Write the E-AC-3 frame header to the output bitstream. */ -static void eac3_output_frame_header(AC3EncodeContext *s) +static void eac3_output_frame_header(AC3EncodeContext *s, PutBitContext *pb) { int blk, ch; AC3EncOptions *opt = &s->options; - put_bits(&s->pb, 16, 0x0b77); /* sync word */ + put_bits(pb, 16, 0x0b77); /* sync word */ /* BSI header */ - put_bits(&s->pb, 2, 0); /* stream type = independent */ - put_bits(&s->pb, 3, 0); /* substream id = 0 */ - put_bits(&s->pb, 11, (s->frame_size / 2) - 1); /* frame size */ - put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */ - put_bits(&s->pb, 2, s->num_blks_code); /* number of blocks */ - put_bits(&s->pb, 3, s->channel_mode); /* audio coding mode */ - put_bits(&s->pb, 1, s->lfe_on); /* LFE channel indicator */ - put_bits(&s->pb, 5, s->bitstream_id); /* bitstream id (EAC3=16) */ - put_bits(&s->pb, 5, -opt->dialogue_level); /* dialogue normalization level */ - put_bits(&s->pb, 1, 0); /* no compression gain */ + put_bits(pb, 2, 0); /* stream type = independent */ + put_bits(pb, 3, 0); /* substream id = 0 */ + put_bits(pb, 11, (s->frame_size / 2) - 1); /* frame size */ + put_bits(pb, 2, s->bit_alloc.sr_code); /* sample rate code */ + put_bits(pb, 2, s->num_blks_code); /* number of blocks */ + put_bits(pb, 3, s->channel_mode); /* audio coding mode */ + put_bits(pb, 1, s->lfe_on); /* LFE channel indicator */ + put_bits(pb, 5, s->bitstream_id); /* bitstream id (EAC3=16) */ + put_bits(pb, 5, -opt->dialogue_level); /* dialogue normalization level */ + put_bits(pb, 1, 0); /* no compression gain */ /* mixing metadata*/ - put_bits(&s->pb, 1, opt->eac3_mixing_metadata); + put_bits(pb, 1, opt->eac3_mixing_metadata); if (opt->eac3_mixing_metadata) { if (s->channel_mode > AC3_CHMODE_STEREO) - put_bits(&s->pb, 2, opt->preferred_stereo_downmix); + put_bits(pb, 2, opt->preferred_stereo_downmix); if (s->has_center) { - put_bits(&s->pb, 3, s->ltrt_center_mix_level); - put_bits(&s->pb, 3, s->loro_center_mix_level); + put_bits(pb, 3, s->ltrt_center_mix_level); + put_bits(pb, 3, s->loro_center_mix_level); } if (s->has_surround) { - put_bits(&s->pb, 3, s->ltrt_surround_mix_level); - put_bits(&s->pb, 3, s->loro_surround_mix_level); + put_bits(pb, 3, s->ltrt_surround_mix_level); + put_bits(pb, 3, s->loro_surround_mix_level); } if (s->lfe_on) - put_bits(&s->pb, 1, 0); - put_bits(&s->pb, 1, 0); /* no program scale */ - put_bits(&s->pb, 1, 0); /* no ext program scale */ - put_bits(&s->pb, 2, 0); /* no mixing parameters */ + put_bits(pb, 1, 0); + put_bits(pb, 1, 0); /* no program scale */ + put_bits(pb, 1, 0); /* no ext program scale */ + put_bits(pb, 2, 0); /* no mixing parameters */ if (s->channel_mode < AC3_CHMODE_STEREO) - put_bits(&s->pb, 1, 0); /* no pan info */ - put_bits(&s->pb, 1, 0); /* no frame mix config info */ + put_bits(pb, 1, 0); /* no pan info */ + put_bits(pb, 1, 0); /* no frame mix config info */ } /* info metadata*/ - put_bits(&s->pb, 1, opt->eac3_info_metadata); + put_bits(pb, 1, opt->eac3_info_metadata); if (opt->eac3_info_metadata) { - put_bits(&s->pb, 3, s->bitstream_mode); - put_bits(&s->pb, 1, opt->copyright); - put_bits(&s->pb, 1, opt->original); + put_bits(pb, 3, s->bitstream_mode); + put_bits(pb, 1, opt->copyright); + put_bits(pb, 1, opt->original); if (s->channel_mode == AC3_CHMODE_STEREO) { - put_bits(&s->pb, 2, opt->dolby_surround_mode); - put_bits(&s->pb, 2, opt->dolby_headphone_mode); + put_bits(pb, 2, opt->dolby_surround_mode); + put_bits(pb, 2, opt->dolby_headphone_mode); } if (s->channel_mode >= AC3_CHMODE_2F2R) - put_bits(&s->pb, 2, opt->dolby_surround_ex_mode); - put_bits(&s->pb, 1, opt->audio_production_info); + put_bits(pb, 2, opt->dolby_surround_ex_mode); + put_bits(pb, 1, opt->audio_production_info); if (opt->audio_production_info) { - put_bits(&s->pb, 5, opt->mixing_level - 80); - put_bits(&s->pb, 2, opt->room_type); - put_bits(&s->pb, 1, opt->ad_converter_type); + put_bits(pb, 5, opt->mixing_level - 80); + put_bits(pb, 2, opt->room_type); + put_bits(pb, 1, opt->ad_converter_type); } - put_bits(&s->pb, 1, 0); + put_bits(pb, 1, 0); } if (s->num_blocks != 6) - put_bits(&s->pb, 1, !(s->avctx->frame_num % 6)); /* converter sync flag */ - put_bits(&s->pb, 1, 0); /* no additional bit stream info */ + put_bits(pb, 1, !(s->avctx->frame_num % 6)); /* converter sync flag */ + put_bits(pb, 1, 0); /* no additional bit stream info */ /* frame header */ if (s->num_blocks == 6) { - put_bits(&s->pb, 1, !s->use_frame_exp_strategy); /* exponent strategy syntax */ - put_bits(&s->pb, 1, 0); /* aht enabled = no */ + put_bits(pb, 1, !s->use_frame_exp_strategy); /* exponent strategy syntax */ + put_bits(pb, 1, 0); /* aht enabled = no */ } - put_bits(&s->pb, 2, 0); /* snr offset strategy = 1 */ - put_bits(&s->pb, 1, 0); /* transient pre-noise processing enabled = no */ - put_bits(&s->pb, 1, 0); /* block switch syntax enabled = no */ - put_bits(&s->pb, 1, 0); /* dither flag syntax enabled = no */ - put_bits(&s->pb, 1, 0); /* bit allocation model syntax enabled = no */ - put_bits(&s->pb, 1, 0); /* fast gain codes enabled = no */ - put_bits(&s->pb, 1, 0); /* dba syntax enabled = no */ - put_bits(&s->pb, 1, 0); /* skip field syntax enabled = no */ - put_bits(&s->pb, 1, 0); /* spx enabled = no */ + put_bits(pb, 2, 0); /* snr offset strategy = 1 */ + put_bits(pb, 1, 0); /* transient pre-noise processing enabled = no */ + put_bits(pb, 1, 0); /* block switch syntax enabled = no */ + put_bits(pb, 1, 0); /* dither flag syntax enabled = no */ + put_bits(pb, 1, 0); /* bit allocation model syntax enabled = no */ + put_bits(pb, 1, 0); /* fast gain codes enabled = no */ + put_bits(pb, 1, 0); /* dba syntax enabled = no */ + put_bits(pb, 1, 0); /* skip field syntax enabled = no */ + put_bits(pb, 1, 0); /* spx enabled = no */ /* coupling strategy use flags */ if (s->channel_mode > AC3_CHMODE_MONO) { - put_bits(&s->pb, 1, s->blocks[0].cpl_in_use); + put_bits(pb, 1, s->blocks[0].cpl_in_use); for (blk = 1; blk < s->num_blocks; blk++) { AC3Block *block = &s->blocks[blk]; - put_bits(&s->pb, 1, block->new_cpl_strategy); + put_bits(pb, 1, block->new_cpl_strategy); if (block->new_cpl_strategy) - put_bits(&s->pb, 1, block->cpl_in_use); + put_bits(pb, 1, block->cpl_in_use); } } /* exponent strategy */ if (s->use_frame_exp_strategy) { for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) - put_bits(&s->pb, 5, s->frame_exp_strategy[ch]); + put_bits(pb, 5, s->frame_exp_strategy[ch]); } else { for (blk = 0; blk < s->num_blocks; blk++) for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++) - put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); + put_bits(pb, 2, s->exp_strategy[ch][blk]); } if (s->lfe_on) { for (blk = 0; blk < s->num_blocks; blk++) - put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); + put_bits(pb, 1, s->exp_strategy[s->lfe_channel][blk]); } /* E-AC-3 to AC-3 converter exponent strategy (not optional when num blocks == 6) */ if (s->num_blocks != 6) { - put_bits(&s->pb, 1, 0); + put_bits(pb, 1, 0); } else { for (ch = 1; ch <= s->fbw_channels; ch++) { if (s->use_frame_exp_strategy) - put_bits(&s->pb, 5, s->frame_exp_strategy[ch]); + put_bits(pb, 5, s->frame_exp_strategy[ch]); else - put_bits(&s->pb, 5, 0); + put_bits(pb, 5, 0); } } /* snr offsets */ - put_bits(&s->pb, 6, s->coarse_snr_offset); - put_bits(&s->pb, 4, s->fine_snr_offset[1]); + put_bits(pb, 6, s->coarse_snr_offset); + put_bits(pb, 4, s->fine_snr_offset[1]); /* block start info */ if (s->num_blocks > 1) - put_bits(&s->pb, 1, 0); + put_bits(pb, 1, 0); } static av_cold int eac3_encode_init(AVCodecContext *avctx)