From patchwork Thu Apr 1 15:53:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26691 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 D354944B30B for ; Thu, 1 Apr 2021 18:54:23 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B77EF68A880; Thu, 1 Apr 2021 18:54:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-oln040092072058.outbound.protection.outlook.com [40.92.72.58]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 90E8B68A831 for ; Thu, 1 Apr 2021 18:54:17 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OFyMmUHPsa7w5HOuk31VHzK0JctFOWlr7HJql7TsppN8JDxm3v8tzrW9WZg0h1ctNG8Tu3rWSJoCSooXV24fOIN/FPKK71N24CMsnaP7pdyPvE4WyYgRcL//5lqKgkVIZmmiSvGs5W/qkd3mHTLYCHixqOVWT8uGVdggTz3tM5mIkwe23VaZ8OHs6NNF0YIhmqJpszuyNOmPL3DEHVnMPnJg5Ys/mE+KxrqBOEv++eIVMtatWsdv+58NLVKxwdLOVxmFvb2Hn2nsPjTpZrNw5rIPg9eu9+lAL+LHGO5G5qZqY1Yv85oBHLxZtyfZFGIn0FT8E9TJqr4nHyB+DBZoHA== 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-SenderADCheck; bh=iY9ghLhW+0+8upCgJNJzxiM+UIACxJQ55Wh6BpG3V2o=; b=jzLs+kjJyn+dKYDxDDJollvRDndYnyur2iBuWbQvZmWaNaCCNOOLL+BjqIaKqjPEYKWtIHCvagx25OlJmH3mCUkFzZ5VjoDJWxiSY6hr54yVQUOfiW5bP3jemquVgWpPNAfJsVs+eHOJ5Gk0lCC/WoNTOW4Bd7E0fn6593tA+8UvsCOnbPv3PxvJRTyNeOVxP/O4xVBqq6Zk5sZ2VplDC/i29yajDfVrgBCnuVPGTAg7Me31mF7dZW6TnBY9cXTdPxpIYd9OJGEgFeTlcAcChhYF6q2Xb6AQNShOWzm50cwjbGigu0vFgnLOzwiDPYEZOZMO9e9trCKqN4pfwvlC+Q== 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=iY9ghLhW+0+8upCgJNJzxiM+UIACxJQ55Wh6BpG3V2o=; b=g2ut13aCcoF0JPvjmjUYV/AhFCBmoNrc1FtzkiAVcKvgTIedLD7A1ULZakvZs1pZ3FJtaAQdMQhabf98L/o9IlEKQX8xv+cRCMn06rjupQkfPk6aeCq/djTEmR4VA7RvRfT1ytljyi3iyHqPeCSD2IhDuw4yP12C8P2BmuGk5lXFl7+7vSuex3k1Ta8j6bNAT8WiUdAad2bpMXs8G0fD+UVhWZGcE3Ro3QqPpdA8anijwqDX6Q0fyU2Ed2SJjM9qDYUvzIu3vXWBEBy+zMONcnBxWww4A7AJjOYTR3yhx6/NnYBJ4uH8tIOwinLlJZR3ZnD1LwFLP2EXhMLS34Rvwg== Received: from VE1EUR03FT043.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::4a) by VE1EUR03HT188.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Thu, 1 Apr 2021 15:54:16 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e09::42) by VE1EUR03FT043.mail.protection.outlook.com (2a01:111:e400:7e09::378) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Thu, 1 Apr 2021 15:54:16 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:056FF198DC83F91DDE8AD6ADE055EA6A0E413E122FC168B9E9A255573D85910F; UpperCasedChecksum:9BD4FFABAAF68766F7438584875557090D2EAE1383606195E4E3CA65658645E2; SizeAsReceived:7581; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3999.028; Thu, 1 Apr 2021 15:54:16 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Apr 2021 17:53:56 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [NYEnPjwY5f2a9vlX5pOJUzppPp73dn91] X-ClientProxiedBy: AM0PR10CA0094.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::47) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210401155356.2035788-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM0PR10CA0094.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27 via Frontend Transport; Thu, 1 Apr 2021 15:54:14 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 383002f4-7260-4ec3-da75-08d8f526675c X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiRmQk3JzeNKq1p0dsiv88hWBpMURZ34JcEva0iN7553qC20rXpgyJ23KYDJP4eACeHNFDUP9THgdAB2Gw4OrgJnIv2sJJxqIvm/dZsypz4ud5eYGaRtJ0FbUFGgQsqcGX+eLKICiCbC8xkYo97Ii+Y+9yzGQVmeEqbn0VdUNjWG/AlWMfaJS2ShyX4wErxC6nJ8ywsvgrSm8shQIS7WTk2yr8lJMXsF0/21aN5VjfQ16gPshp0gSC0IQugz9tvTwb2zTDF//56mW4f9wlJ9ajCow91boQ/NXUjZGXa6JxMDEaqCs7xsYYMGSTwvT6u6ipKkQ+uMkQYR3aLbqT308OY/zWIhmpwhKxxztoYiqp0hE23sBjrs833JF+tIF+MHyQbkdkh4jljsllE/tjjPlPeAWA7ncjoMaS9KTZUNTvCNDz9aQvNZ2jpV80GOzvvuTANetg+YrQXCwLV1NEa6cfDQ96s2L/vXyGQuYMOr537WAWyQMj0JtkuF9FW8ygX/Gpbazti+tsRaewNNpdnEL6ryWODfpRePwu1rqZ3MuleYv4xhtyqixgnLkAiyI04o7DKp3b+iisXOqBffWZGwyX6xwPbJEiBdIfPiaHLaCD/geecOHbKWzeBb5rB4xcC+/qfQBGuXpy36N3H0vvOK7dbUY1V5DdyUyJliIYa66C+Vqt7Sh2vjkIknqgp8x7kTBhFBUnuZqNE2jEwBvLX2qUovvrlCziUUoGDqbyZL9VfHtajr/exJwnuP919FQHWl10o= X-MS-TrafficTypeDiagnostic: VE1EUR03HT188: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 59pd4PBEo/dqlRc6FPfuSCLS70OnrMxXW4trDxEAhDJl7E/UxUR+DrFiRdjq5mlcRMBTst0Gph6yyVk7cSTjPvlc8gtLoX8PUvyku8x4Tf6DdfuRDrwejrBwhqdE3AQJvfi2sCPlsYNid/qGF0sOcolHAGoasnCbQ0YQLhtDjs8jRurSDEemqHxpP91tWPA7yLGnfVbKu7ncyDEZU4UUAhNvrixrIYGIxWGap0LHYrZ0gTlIOyhZiy3UyW4x/V+S3cH7cWQTLmhRbMZVwLhvu9YnhPGqD7S15OYPn9B47PrXgUhBn+OdirxmrrxohTqtq1X7BIZ97loMNFwMssDV+Z1poJAE5Uwj75dT+0GqGVjAnZiNJeqGdpwgMYvA8tIdJmyA8Z9cIMOPVYCJ3CrTtA== X-MS-Exchange-AntiSpam-MessageData: Evrhv2V7Pn16xijkoFuENbl09rfkUr7FgVYJob78z4KnJm2P0LEitSdh7u5XsYbejYLImx1Yeb6AiTA9tkWdmOXgFhzw7xFvMuDmHlkwciIsPl9Us+/NjM+NDeQeukPSD8IbC2Qm2EAQjXcPBWwM9g== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 383002f4-7260-4ec3-da75-08d8f526675c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2021 15:54:16.6635 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT188 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/ac3enc: Simplify AC-3 bit counting 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 encoding E-AC-3, whether coupling is on or not determines whether an additional frame based coupling exponent strategy element frmcplexpstr (of size five bits) is present in the bitstream. So just add five to the number of bits when counting them instead of adding 5*s->cpl_on (the latter field is currently only 0 or 1, so it doesn't make a difference). Furthermore, move some parts of the bit allocation that doesn't change per-frame to count_frame_bits_fixed() (which is only run once during init). Signed-off-by: Andreas Rheinhardt --- libavcodec/ac3enc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index e27858e1b0..8d9de8e108 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -784,6 +784,10 @@ static void count_frame_bits_fixed(AC3EncodeContext *s) if (s->eac3) frame_bits++; + /* coupling strategy exists: cplstre */ + if (!s->eac3) + frame_bits++; + if (!s->eac3) { /* exponent strategy */ frame_bits += 2 * s->fbw_channels; @@ -796,9 +800,8 @@ static void count_frame_bits_fixed(AC3EncodeContext *s) frame_bits += 2 + 2 + 2 + 2 + 3; } - /* converter snr offset */ - if (s->eac3) - frame_bits++; + /* snroffste for AC-3, convsnroffste for E-AC-3 */ + frame_bits++; if (!s->eac3) { /* delta bit allocation */ @@ -904,7 +907,7 @@ static void count_frame_bits(AC3EncodeContext *s) /* coupling exponent strategy */ if (s->cpl_on) { if (s->use_frame_exp_strategy) { - frame_bits += 5 * s->cpl_on; + frame_bits += 5; } else { for (blk = 0; blk < s->num_blocks; blk++) frame_bits += 2 * s->blocks[blk].cpl_in_use; @@ -926,8 +929,6 @@ static void count_frame_bits(AC3EncodeContext *s) AC3Block *block = &s->blocks[blk]; /* coupling strategy */ - if (!s->eac3) - frame_bits++; if (block->new_cpl_strategy) { if (!s->eac3) frame_bits++; @@ -983,7 +984,6 @@ static void count_frame_bits(AC3EncodeContext *s) /* snr offsets and fast gain codes */ if (!s->eac3) { - frame_bits++; if (block->new_snr_offsets) frame_bits += 6 + (s->channels + block->cpl_in_use) * (4 + 3); }