From patchwork Fri Oct 7 20:20:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38606 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp204393pzc; Fri, 7 Oct 2022 13:20:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7yHEEtEXPgHqfBfbgcF6msFW2D20Iz1ILxwdZFEwAESskOOjG8QE4TQvGeCxmUXvqqMy8S X-Received: by 2002:a17:907:c78e:b0:78d:138a:ec4b with SMTP id tz14-20020a170907c78e00b0078d138aec4bmr5441616ejc.381.1665174050585; Fri, 07 Oct 2022 13:20:50 -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 nc4-20020a1709071c0400b0078d45293551si3079548ejc.487.2022.10.07.13.20.46; Fri, 07 Oct 2022 13:20:50 -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=SFAITXrH; 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 C58DC68BB6A; Fri, 7 Oct 2022 23:20:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-oln040092065066.outbound.protection.outlook.com [40.92.65.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F04268009F for ; Fri, 7 Oct 2022 23:20:36 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iqgEsq9pKfmAjVf0+Hn/xlKx7dmxICGUL7jtLdJ4IIofVg3u1VA4iSn7Y4VGLKif+4KgAO66eFdBpd34ndISPs6s085FdOLAPVEpxA32MCjX9WGhDOZxCw0ZA5EmjLOGOmDXysoSNHP/vVil/I++QzGAtTiSAHBE3Plk/66NbTAQNuYxJck2TrCkKpiTGdy5I9aAPoblMlMYrPYB2v8V9/JlrL5SY/TMJm7zuRsl1WCWNYVhGpxfqud8BxMmGAkm/uxERDYmYAVVdeaZKUSoi7clcCae1I0cGGQ0rOh8t+qmkIjUz4jZZbvanVW/R5xmaOS3bDMXc5lVqdBuKqn2tg== 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=SlbS9xP9W3mGGI6524ZGML9iX2lwWNoYIbPbYnAJ3hc=; b=cM7BJ2LBsRkY0ysVdfdmf6wJxLrolFJbKSTvf8qakU406SlHm5SR9rXUGjosCB3mNbhOPavVZ1a1NrOI2oP7Q9i+whAuLI0w8WJy+nnOfWtwBrRB0pvzCJSxejP6zMtXVXilZ4nWjRetALZTq5KoQ8vG/kHj5LdLbiHwmrgic3m6F7I5xV32AXW4Vbc6Jvqa9KoNxbm2PEi0RbjOBXU6YnKjZ8o4uZ5PbeNUArrBRPjuwobpby8Vv8pLyIYB+Kz/vAxkbYXlmUI9EDPs86MfxDd2Te5y9R2vw7SMnArQQNzmKyJ6HgWcguNbBaYodCJXtA/Nani01ahk/K4PIuy3sg== 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=SlbS9xP9W3mGGI6524ZGML9iX2lwWNoYIbPbYnAJ3hc=; b=SFAITXrHPORAkhWwa01pWIHlVYNEBcZuJ86Q2Q3O0yjyIRGMQO80rzMANBjp+qeTvKLn/mCGpz6BVxJgFuvHTovt1TDB60W+goW3HXoX1dyulis6v/tSr48BdAgeG0d7D83H+7H1LhCQ9n2Xab9Sf/9mYo070492WCHctDhQyr+V3lFFp4I7zTLfEYZowKuwWdVdvScWlDLh5bT6g7o6nEQhjK4V4wFpcpGD3EZS56c05UJQuFTcSRoXshD4r6vCxoxJMApsaEmjOjJZF0ykxjDFwVlQcHbTE7jRHTmiCklC0HxGU2EUBT6UJzLldI0xZkzTUUk4KW2iHBRbMXE/ZA== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by AS1P250MB0479.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:4a4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.31; Fri, 7 Oct 2022 20:20:34 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.028; Fri, 7 Oct 2022 20:20:33 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 22:20:27 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 X-TMN: [WEyu2+OXsNuN8iWR64ytnQjDLIa7boq2ncJH5V9inuc=] X-ClientProxiedBy: ZR0P278CA0146.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:41::7) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221007202035.4188030-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|AS1P250MB0479:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ca31182-07d2-4ac1-59f1-08daa8a16355 X-MS-Exchange-SLBlob-MailProps: ZILSnhm0P3kriUXd04K/td43akM44RrIlGWASQQ7udR6YCXzIp4y3KbPs8YZCaRtfT5pk3XcpSmLzkSrXHq1FaUHm944A5S4qE5VdeON7FvWLc+Z6AZCGAO1Wx+jhvyTeE4wAuRujQi46I8Qra++P7FY4FEyN6xPik6LroAlrWEOR7lH2MBr8AAVBVH2GfK5BzgYbHCrHjTkyqne+9kcQqi7tWkBARMosW4lkt8hs8ae5v0O7vGdjZZJyF61JtHVBYqXGkiGyvDRaWbAPsVm4Fo/ZVm9xpgWSKsjbxlEeqpm/taqtzxfBqXUhW7x268NLbgyTrTOfIH0V2/g/yBaumIVacv8EzFg/Xv16Sr6icxdIVOKTQZS9bVIQiBo5fNgj7t8+Au3Icua5npjk28eksjrpMQjIqAIUe0K8b+3rrXag+fm2o3R8CsbSY9qxPJkzr/XFaCYsI07D+8djWWNZ3jMnQ//5ok6kdebYORxU4zVdqH8ADZwAqZ7LmiOxMJxyvnqHgcPFR82Zw6m1XHLLjqygsIoTCFCbWmqw+wTm8BzLcuowmXPHapGkSPQJ55w+B/KwXaE9/5PKIlAJbqcBLiIok4t693Cc6hcxVYtJ1Su8/AhCLQ//PZ7avERPmzNTEJxmQ3DHCoySJ1HbjlV+dMi7/2nGmYLjkexIvaIXKocw7ipUrVLdtsQRkWGwzfmbWDW2UpMwnPs0oO1yongWWW28A6AZaB47SkWKXcPWY1tG751uowRu0F9RM2cQ4AT88kGFK8tjUezYhF2jAe+H+NTOiuQUoo0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LKaXn12LcEsDGPDIqi4m+hZqL6gxPvXJi7Z/zEmpN9K/TkULrHa2LuaYk3CNmNnQ3rtAqdHXH+bQYIlCeIu4xbOzORVvseThELXAyB8AnwMF/oM+n/IyzWkMDinTfGkxIADKyADQlEdjdwJkZB83CenmQa9N8+BwD1AbAVsdlTZDRVg1+Lmh9zJV9HBArv2qdOsCku3fEBCDGplElm7UjsziO5Mp+wunPPS+yw614PWY86eY4mfT9Qv6CyA33384qiVN+bJvLiIBVfGUYV6aOZqKwV07o8sEegt52Xg6tNAENGNaG8jhK+SMih94xYz/IN46W/PyBEnnjb02r8HI3KWX65uJvsR8YPK8vFi1pZ/Q7EajSHxASmMvDc0JHArQN89X62lTT/2QjSP4oLciogmFReSZA0SeiR4CLLJuq+3AzIsa4c6yj8Nd8woFhopnEbZy7te+gRJg9xYmUOg2JsnBP2tfYkzTG8/dutNmsrn8DpTRJ7w0MMd761GPnAVEboGaoDOj0HXL9z/R9nUS6SpAZQQmXn4VZYe/Inw1rP9QTvGsozhg1KEIfjKnJM2YyLdfc4DMwaeeRJRKs0i2xTPunX6Jl7kR9RuR5e1l4ZHjHJfZfEFbOWO+7w6+DcClDi/xnG9Z6pRuVZ9qSiWcgCzn8YIQOzsua5h8XaZKhTwTnsRRr6fq3FNKW8KWbsXu X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Qjybb93qx0cxha5rrwb5wYsDEraZLU8tQjJz6a5qaX1GvKOYL/NUjzrMJ6MOngcxfgnVLxb/OeNqZRYRWsFug1+zx69w7Cgx5T6bNCD2uZQMBRk1nNdY+RY9RHt9ou78D+IXbguuDgqDT9ozKM+UwBOXbxlFneLch6xxqP9dqbn22HDJVFW30RLjaTkzpRy2hnTiO1ktAlsloKzXYRSQgMBXAppi6nPBbiyU1gkOycawoVS9GN4wy9/9GosJ0218AXseUtxiBQJ742OO9LvrF+zuKovb/fMcNT+0pzQ1CUxfNnnE0BM7GUjaR2dKyJqt3/YdRnftt/segKS0rUZvDcvaY18QIjTIe5girhyOliAOTwrT4s3rdjaHONvcmY26KZ6xS/azmWi0dx/QjbCa+yTRo5S341SlB+25zqEx3sEEVHlXU8+dAROytEWzK2+KOysGFNp6RZuc/ImFHnNR+cBFg6C/iKhLBT19uhy6RyWmdV3xIc8MfyPZgROL6seOKidRz2GVu58dMzihJYUUlyfDO8UN4AHMSuolWgiD9i585AOsmpqlmcnLp6nm4qoccEnrqrVORvCp/Ov3Hb1HeswC/cL9qsOCmY5y5UQMznDYmT1OGfHH06crqpkFJfeh/IIIVHbqoe9uFsQYo/Oxt40p2Ut4kCIWSvlhB5D6c/y60UDolc4zSTiLMnPOaDgiDhhrh/ym+fGVQ6pbUGLYQ46siNRzyEZodvJFF1e/crWbXFi7G97HPUmUheX0UBINYo8+QqRx76+qblOYZQBaxkGZYkgf1xemVFiHnGyN92UM5mSXJ4Kb1KcO8p5l3DBdpxCgeEIwxTpADQsPbjCXpOzAOiUtU/y7RZA2HDJ+0ZgpPEPu2gLnnhVS2lwRQMzBwkwyN86cIIgGjTQbOeNSwYbqxF0BlFAJxqS+Fc13PwK+LAqkitpUMj+i4SYcajbDk+f4Iq/9FqdLvNflrb1sf4Qlay/j53hfZVp9UYUmEt9qZwO1BBlRMKn7ImV2rSGNonW5kDGNe3PSjM/uVQa6gE/NdMAIbyx/WZGelTKCxIXZhs676zFZDClXeSxpklLDv/KzuUZoJrZD/cc00PdlWCAdNm8ubf7UbYOiIUGIdHI8I3oU4SyBR0wT04SePOWj7LfSP4ZzE4ka7NyFbJlSo8kVlIlfmNUhEcrAhrEED3Rc7rr5qjyXYKK6QbNq2mVrrgxT31MSpYnMDVjzi8MneCQeinvWmZVVBtwynDDGymd+K8l6WRKsL34CEiJBdZC0GOsHGVSRM6oUIeUuBaBEmneKTRdqshaVCc/VEDrmyX0= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ca31182-07d2-4ac1-59f1-08daa8a16355 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 20:20:33.8741 (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: AS1P250MB0479 Subject: [FFmpeg-devel] [PATCH 1/9] avcodec/opus_rc: Remove write-only waste from OpusRangeCoder 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: qbJZ0RIyBT76 Write-only since e7d977b446194649aa30f2aacc6c17bce7aeb90b (and local to ff_opus_rc_enc_end() before that). Signed-off-by: Andreas Rheinhardt --- libavcodec/opus_rc.c | 2 -- libavcodec/opus_rc.h | 3 --- 2 files changed, 5 deletions(-) diff --git a/libavcodec/opus_rc.c b/libavcodec/opus_rc.c index c432eb90c9..2061418e52 100644 --- a/libavcodec/opus_rc.c +++ b/libavcodec/opus_rc.c @@ -383,8 +383,6 @@ void ff_opus_rc_enc_end(OpusRangeCoder *rc, uint8_t *dst, int size) rng_bytes = rc->rng_cur - rc->buf; memcpy(dst, rc->buf, rng_bytes); - rc->waste = size*8 - (rc->rb.bytes*8 + rc->rb.cachelen) - rng_bytes*8; - /* Put the rawbits part, if any */ if (rc->rb.bytes || rc->rb.cachelen) { int i, lap; diff --git a/libavcodec/opus_rc.h b/libavcodec/opus_rc.h index 627f83229e..1b3cb93a15 100644 --- a/libavcodec/opus_rc.h +++ b/libavcodec/opus_rc.h @@ -49,9 +49,6 @@ typedef struct OpusRangeCoder { uint8_t *rng_cur; /* Current range coded byte */ int ext; /* Awaiting propagation */ int rem; /* Carryout flag */ - - /* Encoding stats */ - int waste; } OpusRangeCoder; /** From patchwork Fri Oct 7 20:25:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38607 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp205875pzc; Fri, 7 Oct 2022 13:25:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4QRyPIxB9aWgbrW2fxfrTIaWCKVLAeLDa+vj1iTWM543tFy0GxHMEWNhl+aEsRF+PS/god X-Received: by 2002:a17:906:c14f:b0:78d:105b:e57f with SMTP id dp15-20020a170906c14f00b0078d105be57fmr5552767ejc.672.1665174321160; Fri, 07 Oct 2022 13:25:21 -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 i24-20020aa7c718000000b004593a09f7cdsi2720905edq.394.2022.10.07.13.25.20; Fri, 07 Oct 2022 13:25:21 -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=Pcd3pD19; 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 942DA68BB74; Fri, 7 Oct 2022 23:25:18 +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-oln040092072055.outbound.protection.outlook.com [40.92.72.55]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F37668B580 for ; Fri, 7 Oct 2022 23:25:12 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f/CySkgllQF1OwIZTwd9B2CWvVv5dDQBNIjbA7VPyAe1yy9x9lxpStGnZL/UFU5WzV2+CYE0RZ15cDAhxMqz0NinVIWhdYFJ9+D4bs3SmG62vwCuVTR4D9Gbk2lICK9JMT1w8QVOQ1nEZMmA6Vu7ppYt5rKBPEsYaR+nIn4dko2qmxnor3SlNKNxjHM4suQKcGJ4dU0POcbE4XGacwBs7Pvmw3kXxZ2yaoDcDo4RaNmqBKIQDT2M91YhtBVsVTlaEqZGeJ+D4b7T92lI4qH0PTR1qEDf2cwvV44u7PMnlGV1ozIfXKResXr8InSbJ7TT/Z4Dp2wFysp/lDo+0llK5Q== 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=qhUCAHaJyQS0WmRlXnSNm3ihx3rHtNDqy9jzBJIt1pw=; b=QleXevg5WMfxDx7rCoQ8jA/36AbXfQNWukV/Jb5Q58cQbE0r0q0PiZhgBZub0gMsxBzsrK4dIc36T0o99bj0KdnFULxxVEkMaPrtWTq6Kpx52HEFBqwJsWLdT2FVVxSvjFne4ehUNj3nEWkfXuZWGORrZmqLn0g6dCLj+V8lBLWeo7jLNEbJnd3s7ZxAUsIPIb+3/8k9iVg/KdETVNC2x/i3tvX9o4E+Pclm4mA/+mjRLZlDq42r0bxuytKu9667PRLCoZJup7eg8jhcOexLqQEshaZeA5ILuIg6Fa5jtfsQsBm3gU2yLl0MONzuUGuTiJLGv2APo9Q0XfzcbyCLSg== 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=qhUCAHaJyQS0WmRlXnSNm3ihx3rHtNDqy9jzBJIt1pw=; b=Pcd3pD19HRHaVlHQWurU2+wWZyK+ORiPYr4npkZUYUKLr5WNfJrhicfUOOU6ZTTG8IO/Zyp8SVUTynD9gBBYn9d1SPRRcqYsNly1ynPFQaCgW+L8XGW2JshzmIzEoH4P9pC9fA1F9QvyCDBs/n/2Hhre4rmmOrYkxDt/+W74CFULKgsrGdbFG745H8xw8np01X6AhInZHiOM049kYYVjt3GsrY9fQ+sx7VKHh4oSXkesrs6SQxEPR0IzCj+rrS/DQiPyR0jk4bMMiB3apd/4ITFqRrcixC867p5iVinWhDC1EVfeBVpSe9oTStCuIyaY8cMBubqg4FAxzzAyVQUNgg== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0285.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Fri, 7 Oct 2022 20:25:10 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.028; Fri, 7 Oct 2022 20:25:10 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 22:25:01 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [BMqCYZvYAoUr7Ht45IxJThyEbcLhGjmFuCZ7SFQLbBQ=] X-ClientProxiedBy: ZR0P278CA0106.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:23::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221007202508.4188148-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0285:EE_ X-MS-Office365-Filtering-Correlation-Id: a756a25c-aef4-431a-14f5-08daa8a2085b X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmpXYlgiiriwpqBJSiirmy7KGcnKhdjKPfaFSp+LtJjLvYEset3+K/J7Dm6MvoKNq35uWmQ5M6k3Z+c2Wkl2MEF5b1PKi88V4WAZUZZwxEOQZal9u3afHrsIcIyolc4dXFxz4myC5d3BY5HcnbhxMNHg/asfp0W22SJZzyPrtiCD79iHCt8XbnsrmNEYyKmfe7YuBm2tZ989HmFzLY4On8AqyE1VKBCvLKOM2JUULgDDmq/oYfrPlZHCg2A/OMiGOFqNSiwOjSCEoj6pxiTIvuE/YnvFCvh9lUzWHLcqY29uUs/SzrfXf8D49pHPtCsKdzjvITZhoG0cW9Q7BSGtIFG7VSvLBEPVRARd2Bi4hu+TKVcNatgegZE9iIsOYfhbaT/owAsE5jctmaLjt2LxgEmnAbgIBsqBMjZgd/oWFfOc2tOM+sS4/rnTbFgOGLW39UnsUmwmFdkmb9HZwiLiw7EkWpm7RMuDXleTnYVTp/9fl3+aRmZ/mUaycxdIcvpL6OiDbZa45nS6lFtmftPEU7BCfV4LQ6mcgLW8HaGS8EKXRCpJnIbkXdUMG5fWfkZNZJTFfYD9X4HWo8RIhV84ke0yv4QN+cviA5pBLyUoi3PcV4muonlVAEg4YQM8l7qSTf0Zrm1RFT5iOXdYOt+UEC8pXbRgdSy8Zu1GCgaQ1NZpmL700lsEgpx7a/3IgKsoa5i31YddRerUZZoRGIDJaGPmmjMO3mSKpo0fjyDEcWXDH7PEWJ1HUDFAsZKJVEaJK48= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R8rWaAj5YzTZTixTdJnXUVVniLKXrwSlqFz4DjOodiGtauYQesnBU5OPIwpY+iOKGRyAtWkOe3BwcKLMabjOG5jxrdZf3btCUFX0Wh/mjNsy6phNbhFAnw0ZGLdqWa6l9fw9HOy4X0tpziCCInsnp7grXGdI0QZIZ3bGBJZmQ0yynzDDAavLf4xLa7mL3VxR8Qo/TI7v+Vhygw60FsWvb3s3zKvtYxtAEW2fFAKhI+VSJZ4DMkMeB3FBfWbo/7JAgNa3BA+g2By9oJKa/XXRlcDKr2TizCWT5IRok0Y/Gqsoa6XlRRm1hmuvuDYSGyQziJWElpMIXmh6g2yKtcMWzPVtfd5Xe7vK7XFwJTlZ5i7VBS7hAKpTn9E0z4PnKClS1AGybm819gGN0D0ItjfO2mFW1ohV2ijHbnVDB/S1Mw4NlIxTNA0tt/Z0/JcgiTlqo/9TcjAkKlz01W3VoccjPfcMxVP8caEjpaI3xAy/bGp5pEjyxuHAkdtDrgAw7B1qTd1NLP2vlacfaCSLwpMq6LdROVHG7LBTTw2AyyY3m+Kznx3clP0UFD8j8xtjzj5H3DLLQSmpNBD6h/h6NspC72uMKMkr3lqIXAH8JgTkp1W8SbW4188kWdm+QdKI/ECYvIecI5aKC5+Cy+LZC34ib8YpeYnruooR2l1RCVELB0llGFC696BSf0pCxcWQDvb7 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Sf8T1nNKhSSZyOKwlDOaz9mOy3ySUncdecZjRnsqVBqU76vGeGSCxMiimnMfPF4r66V3lno0efRu9NP9voOIWsKoLvW82F288w8QMFgHQFvwPqPdQCNrHYkab4O7Q1x+f5Lw3QsBmH5z7aWyq23p2VmeNH/dU/3u5FZFmS4/rBEKF6kDQQvpJGjAaNWcW6fhBswarlaISzoLf1ee+DpeTZHpPhXe+v2UAYZLCX15kyCJEgpmitqXEvrOaPY6vr+nqIYTWg1IuXiuMg/edYkK6TQUscxTCIRjjIwwYb/vI6YgVuw8VMgKZukka1j+RdaqJdG9XlrfHs2TPrIVsZC2+s5mxpFq5NKJErzLmFFmfo+qZ2CVc2yqQ25alWX+2ua1gfkJka7AM/XkR0rj6VvE4xMfDQTrEG/D9D8ZEhfGYOuDdxu9LVp13xOj7ONT5AxXHlrpaToPVHgyXbW//vXB2sXUAm7GJ8w6VMFHH5lfS8HbRPN2RswLgpFw9arpNhJMcJPyZbr+ZfdoNSkGYVYPBNSUkGcwJJN17I5GauiOali9vAZf5PRKROZNuPEvha0MjvP9ugobQGo7FE/c3WlXWi5kd+Q+25f7Cr2i+r7ho4GjCDoXsZGV2g7RSqw7W8MNVR+Sino4T/lTgjKRcJAzrQqaJ2PcRvxGuYTCbpC12VTEq3xkEmXOyJrekfMSnEY13Ymj7bCBqOnccvrag/L0ghnJYcfUw1M0blSXihLMnkYZDju0x4acsg5XcDDjQHY3TAmVUjX4+7R4YMkCEdW+XaRtgc5vtqiBQqsypVPu874mzHelMhjxDt1E80sTZ8ry4EsfaUtkIhHgei8LpzJkMxa4iDMjTjF/ooN0nnDGyfm5Xj5F55aovcjTE2clmUGaDgHOzrB0bxdEW3dn/GGDhqBsHqL4jFXTJzJk2VEGha3L9xNulazqaxL4tU1wPKBdNgif+Nn4bNxKmq+Wln0X+g7dxH9nJxkCsEOP2n29rahR58TdyGmDl+mxGUfoe98SE/52qQ6xD+WLy5howLNiG/xGgXN8n2OTMKj8p9gKWFwwrKqJlXGGRwTSLtY9qCLwPgFrSK27EEnlP8k+x9wfg2vLB3CEtybz10OHxVZK90pb6gt4Qm0KwIX6kJj6ebjgC9BZ7QxTtEWi36JysETMYO1eKw0CeUqhmxZd5jshJjJu+3leZbFH2XZd/m/jLxtAqiLoDnEtHzH+M2+3cB94vIc7uT/Mv3kfhh5tROL6l0R4K65hpHx2x2ebPVCEg5qRBCQ5+y/K51yMcZ58ARJ+Cv7csIr6IJ+CEbWs0jYlMUo= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a756a25c-aef4-431a-14f5-08daa8a2085b X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 20:25:10.6576 (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: DU2P250MB0285 Subject: [FFmpeg-devel] [PATCH 2/9] avcodec/opusenc_psy: Remove unused function parameter 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: jFboxcYlVbRG Signed-off-by: Andreas Rheinhardt --- libavcodec/opusenc.c | 2 +- libavcodec/opusenc_psy.c | 2 +- libavcodec/opusenc_psy.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c index 7695e95884..280425c74f 100644 --- a/libavcodec/opusenc.c +++ b/libavcodec/opusenc.c @@ -594,7 +594,7 @@ static int opus_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, opus_packet_assembler(s, avpkt); /* Update the psychoacoustic system */ - ff_opus_psy_postencode_update(&s->psyctx, s->frame, s->rc); + ff_opus_psy_postencode_update(&s->psyctx, s->frame); /* Remove samples from queue and skip if needed */ ff_af_queue_remove(&s->afq, s->packet.frames*frame_size, &avpkt->pts, &avpkt->duration); diff --git a/libavcodec/opusenc_psy.c b/libavcodec/opusenc_psy.c index 9b11651dbe..94c37fb8b1 100644 --- a/libavcodec/opusenc_psy.c +++ b/libavcodec/opusenc_psy.c @@ -479,7 +479,7 @@ int ff_opus_psy_celt_frame_process(OpusPsyContext *s, CeltFrame *f, int index) return 0; } -void ff_opus_psy_postencode_update(OpusPsyContext *s, CeltFrame *f, OpusRangeCoder *rc) +void ff_opus_psy_postencode_update(OpusPsyContext *s, CeltFrame *f) { int i, frame_size = OPUS_BLOCK_SIZE(s->p.framesize); int steps_out = s->p.frames*(frame_size/120); diff --git a/libavcodec/opusenc_psy.h b/libavcodec/opusenc_psy.h index 67e96b2fa5..ee58b0cdf9 100644 --- a/libavcodec/opusenc_psy.h +++ b/libavcodec/opusenc_psy.h @@ -98,7 +98,7 @@ typedef struct OpusPsyContext { int ff_opus_psy_process (OpusPsyContext *s, OpusPacketInfo *p); void ff_opus_psy_celt_frame_init (OpusPsyContext *s, CeltFrame *f, int index); int ff_opus_psy_celt_frame_process(OpusPsyContext *s, CeltFrame *f, int index); -void ff_opus_psy_postencode_update (OpusPsyContext *s, CeltFrame *f, OpusRangeCoder *rc); +void ff_opus_psy_postencode_update (OpusPsyContext *s, CeltFrame *f); int ff_opus_psy_init(OpusPsyContext *s, AVCodecContext *avctx, struct FFBufQueue *bufqueue, OpusEncOptions *options); From patchwork Fri Oct 7 20:25:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38608 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp205951pzc; Fri, 7 Oct 2022 13:25:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4PxxBdlmzDlqqvAWPDLAn2+vqaesAY7alnRgJtVMqb56a0H5MgCXukQGNgaBcfpyA+/knB X-Received: by 2002:a17:907:7fa1:b0:782:7c58:5341 with SMTP id qk33-20020a1709077fa100b007827c585341mr5506379ejc.368.1665174333170; Fri, 07 Oct 2022 13:25:33 -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 k16-20020a170906159000b007396bf19f8csi3034487ejd.137.2022.10.07.13.25.28; Fri, 07 Oct 2022 13:25:33 -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=Q2ergwjM; 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 931E368B2BC; Fri, 7 Oct 2022 23:25: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-oln040092072055.outbound.protection.outlook.com [40.92.72.55]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 417C368B2BC for ; Fri, 7 Oct 2022 23:25:17 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KDtDpOo9EDmseqtev47ncCLLAimC3KaWKwGqeYa/a3xG84uI8XybRUPIr7LHFlbD//lh1//cGTO0A2PSOWzHYy91nZCHEsEBNhHMIwKPHawoOxikPHzHNypu3foE5NiOwXW7JkIIGorV2F1nEP8bR1np90lFFHzcMcc56KSPx9/ocAUnSO/WiUOwyKfvGu22fw8SsT7MBtW1C9EFCwdnI/69HP3G3KPxFjNRhjeeIknVZ0BsDL6xek853tUsBOmAl5NHM0cXt2BrePzgnfkqM0ExlGhps1XrqxdhhUw0WKni+vl0p/7xOnf+I1FZLaONjm9UCRKcfwbQ3eQ5vO8hEw== 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=B7xmRF8j4oHEaJ0UQfZOLN4QA3XcLilLTuNIw17X/ck=; b=fBVNz3emxxmCETZO583ySuxbeOnE9xzpuibCKl0jbtAQX1efEDFk0oNgX5TVagBB9Z9yUrqfQ2DK31MvAq77bPo525m6LPc4NINfUmQ7XRp1Fh+V0AlSkW7itDs0x71fzkPPt/KsSbuvIK7U0sdMXN+ovOD7PI3juE2n+uPdn0+emvfPethS3Jyltc1FwdEdyGenkcwLZuTbaEW+j6TMW3D/rizFAQVe7sOPs3dxgEVtfhJJq5/0A3LFTmEdoN+k09l67Mk92JWu9qZoQm8cBovEdpsRVfaiT3CaiLBylFE7v7hTfcVvJDT4q9x/B3mwyHLW5NfESt26pspmbsH+dA== 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=B7xmRF8j4oHEaJ0UQfZOLN4QA3XcLilLTuNIw17X/ck=; b=Q2ergwjMMMYbI5Hob5m3xYCSIsb4rpDfR1gwfi4SLTFf03vu+QlDKEv+sQCqmYXsoOWaL0oKVBaVIMdK3BZR8eWqIWJAn1d8kuSU7Qbs6S6Wg0bEWa663CbBNxa0tBc2RMxjyIeUeSFAjlqELXgOtc9abG586U973dWiP4QEFInM++qE9CgX6Lq+HyvlqzNhFDW0bWRUmv3EgrDjJC+HqyUV8H25s6qwnAyWlhtWz4sIw5PZor5D1AQBJbjoipmAn3fW1ygaFG/X6+ewGnHm7dnc4QXCgQmilaFzpUgfPop4Ar4ZC0PBolKLYYNgFQZFOiCI5qMvZq/lpPINg8QqgA== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0285.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Fri, 7 Oct 2022 20:25:13 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.028; Fri, 7 Oct 2022 20:25:12 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 22:25:02 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [hZVqrNH7DfE6UVzORmr3yEAkL/0GIXwnZTF4VwOA0fw=] X-ClientProxiedBy: ZR0P278CA0106.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:23::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221007202508.4188148-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0285:EE_ X-MS-Office365-Filtering-Correlation-Id: bbbde35e-a58e-4416-3c46-08daa8a209b2 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmpXYlgiiriwpqBJSiirmy7K+k4H6GtwpE6jRqkApit/L8BeA8LRBZb/k2/e6Ns1vn+XyyzpCmE/leRuT4scQA9mwcdPZGGfqKqYwUTBX+I7fvYNFqZR432c4KNKZFZzx/Hkrp66TmvnLXvewhsaemZOAxlfrldLyqujyIRY33AA0toOGn1xLaqpaievohMPVZKh37SOZE0dUtaINWXJPwJbY372gc33qO0LzBVdltBk0VirGLkywKPtNgiOpQUO8Q6nkvXZmGjCqNt+Dd3y8fPIv5rj5JkzEvz2b8atVAOvrqcetSn9YL2/Twpxh8PldZBFA7gFZfhK3JNGUAB5Phstp0iMENIlhFgOB8+GVJ5G4JFCZnnwfx4TPJFNSOdMCBlSAi86AuuTDWsal1De7B9B/2cpqfmLDWItR2MXzNES/2ZT5sIOAHaNFGGxTYFKo6wFYNofqw7AfO0aMN2cAQL/sy00n+aocK9XsSGFXWJ3wxR8686QaSlZqOEclorCqtZnodmxqo3VUnN1kFFWJWFSQkMPYymAE829E65K2e+RBbt9flNRJoLDydJxPvoAJwV5yQHzScGUyM5lfw8kw31gFxNvAu+XZpzkCBHVwWBCzGfj5KZ6o0dbWua61rAUEySd0Ius+3dcLdZKABucfBOZyaHmtGp/99acjZC3LDuC4bqh/orNVYd94mVPqeBe3Jj1+ptF7/nQ1Q8LpQ8BchBgGGkHs1bKF2Vp8QO3+sAFqMSVYKvRV7MTT+0UtVvLfDo= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fV9itOmBDfSF86kJitsKIXfnSVh0OBcdXLeflJ7hqBMipanUL4l0oVGrvhc2af1e0WtFKfUqEUZxQqImFUAweq87Q/6QbmRZ2ZB/V/uyR1hRuw9lSF+x1rnUob1gUdLez3b9QBtieNICaWFChNwFX3i49uKSXQRELfX6x5Cc7dscnOQTJJ51m1V+OY8OWwVcKRMllTLXdD39U2pR97HSWR5jlatjwiVVZbBxacXUUaWoXCuolSsFxWEPuAk6Cq0El2VakqnLLE7XKAeTHBK7nIuZLoCaKny+71XWoDchqppalg2dxh81QqifPw2co4FK5t49m8g9HVcj3nktViTq+4qtgqo5e2f0Q/zvoRzIg+6eD4j6BXm7V9OtLmEwfEE5p3ZWcDAXNVjh/4f2hKJO1yAfg4Vmy5lu2TqffBkUF/CgUHMY9MlUc9v7FztUfnVexs0pdupw0xfIfNBkA4kEgHprx2uEZY5WN2hacCz7vZis/gceKFtuzuBPj0cQ4CCN+M8ZB7q0Asa5RhJeRotebT4O1OmYVua3RcmO5SppC/PFAnpaxvOiwf6mLRkCeBsD9q1pDRAogl/86sW2CBqqfuJyH2CecdtUdxfhCbur5VCVeBHoyBEVEAwxCn/vI66qcbhXdwk4BrvGySCOqbU1fx7aSzSFW/SdIvpHP8PS6DK6wbbX+FKkMt1koC3OLnZh X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: czGwBWbD7Z0M2mGjQy/OzBM1Lc6pAAvZxQSohNKdFCYqScdmj4Mu3dQQrdEMri0gunQo0zHO5ITK4pG+Ol+mWWwV05IV/fxGEnI5nhAgLk/+4508yvPQJbS6LSYnS30ck1elZV8/8gvMCfLcse0gNm6+Uk4C1GqysbXs2LOLnMJBjBZYM6JSG8dek15CPkEVepda93mo+8O6xOJNoJZgVFp1jh03T5m9yHmk1IZvoC0QMO1u3MH3JdJMQU6mEoAdho9SMIW3yQOsBeUbAG1rcC+96rC+PPMIm3IyJbbq6CfmhMG3SJkgbNnzMWsS3NPEesFyasjbjE2nNJanyEeYFT+4FL5Clg6ehOshnUi8S6L8C2cUxJwlb2nK4RzRoPMW2MRoO+Crka7ew8SxhZPmm3kQ6cBtZMWmJyv8TOM2jFbF/K5oTllhLf1Qx6xRIxyUWB1awKdDi4hgvwYWiy15Q7axRq8X5SMqSYaD1w6/H6YFb8rS3jEIL0SRcvEgqu2vAyBsbimnZYU2a9KuIADjAVIvm2ZFtTMC6U+psez5z70ezXtK/+SkqQay5ObOuUYWAanh0UqxphtvqBZcgq131Zzl5h3aeEjqtSU8i8vgTsK9Tw7nM1Y3b8JpUjwvvjxAp72uJVatHAinOmmY70Gy864IkSdJc8P8EsolDYIcNbYdumGSsYNykM/bnqZUrkNf1VESpQhSbMt/qLoKCjOqBQ2mILbdnK4M46clQNGvN/09vOFG3DhpuS6BvaAxWmPDKWnMdkYZ+8zvV+EOOOnAAAbZge7udNWIQWr1HDSwqS2SNa7zfhH9yzEthpwueptML/JfpNwSTMUC4WOrKHAczB31YtCF+eOST5/q9pu2tRPUyMYjap+6V2llpmctBr5+G6CersX01zNJwy3xHdkufHEHPKGSV6fFWNgDKLVedsnBesQGwfePg041ZJASWzZcYe6JMip4zfnNG1XINubmKpFRgtH7GWvlVuhgyxAxRljq7WCj0yCUaaLK340tAMsDoNLBFkW/s7M791F9kvcOTWn7nd7CWrml6Bi29InD+aEaGTI0hcLQAY9AHZzqkDQorBIZ9pliTJ8bdR+JAQYuid9ATF/XqSuKI2M1CgF5DybsrXNYkgpMdZIA08bfguo2Ym/8HSFNaK/cpYyRMgd073zq9QfxmxsuvwS6q8mqV+XpQFAtBMnFNU6uLNk9W6dXrmXh9m2HiZQ3qjw2Y87CWnSNY+oziXvgA95jA/eIlxVdI5IBvSccqX03E7moL+4xwknjUHjSDZuRTa3cCEojOaHeqJM2Iar+f6HroG8W9ts= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbbde35e-a58e-4416-3c46-08daa8a209b2 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 20:25:12.9065 (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: DU2P250MB0285 Subject: [FFmpeg-devel] [PATCH 3/9] avcodec/opusenc_psy: Remove unused/write-only context members 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: J3FOh8RZosP8 Signed-off-by: Andreas Rheinhardt --- libavcodec/opusenc_psy.c | 5 ----- libavcodec/opusenc_psy.h | 11 ----------- 2 files changed, 16 deletions(-) diff --git a/libavcodec/opusenc_psy.c b/libavcodec/opusenc_psy.c index 94c37fb8b1..5c768ae68e 100644 --- a/libavcodec/opusenc_psy.c +++ b/libavcodec/opusenc_psy.c @@ -470,12 +470,9 @@ int ff_opus_psy_celt_frame_process(OpusPsyContext *s, CeltFrame *f, int index) if (f->transient != start_transient_flag) { f->blocks = f->transient ? OPUS_BLOCK_SIZE(s->p.framesize)/CELT_OVERLAP : 1; - s->redo_analysis = 1; return 1; } - s->redo_analysis = 0; - return 0; } @@ -509,7 +506,6 @@ void ff_opus_psy_postencode_update(OpusPsyContext *s, CeltFrame *f) s->avg_is_band /= (s->p.frames + 1); - s->cs_num = 0; s->steps_to_process = 0; s->buffered_steps -= steps_out; s->total_packets_out += s->p.frames; @@ -521,7 +517,6 @@ av_cold int ff_opus_psy_init(OpusPsyContext *s, AVCodecContext *avctx, { int i, ch, ret; - s->redo_analysis = 0; s->lambda = 1.0f; s->options = options; s->avctx = avctx; diff --git a/libavcodec/opusenc_psy.h b/libavcodec/opusenc_psy.h index ee58b0cdf9..bc1a88c03d 100644 --- a/libavcodec/opusenc_psy.h +++ b/libavcodec/opusenc_psy.h @@ -49,20 +49,12 @@ typedef struct OpusBandExcitation { float excitation_init; } OpusBandExcitation; -typedef struct PsyChain { - int start; - int end; -} PsyChain; - typedef struct OpusPsyContext { AVCodecContext *avctx; AVFloatDSPContext *dsp; struct FFBufQueue *bufqueue; OpusEncOptions *options; - PsyChain cs[128]; - int cs_num; - OpusBandExcitation ex[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; FFBesselFilter bfilter_lo[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; FFBesselFilter bfilter_hi[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; @@ -78,15 +70,12 @@ typedef struct OpusPsyContext { DECLARE_ALIGNED(32, float, scratch)[2048]; /* Stats */ - float rc_waste; float avg_is_band; int64_t dual_stereo_used; int64_t total_packets_out; /* State */ - FFBesselFilter lambda_lp; OpusPacketInfo p; - int redo_analysis; int buffered_steps; int steps_to_process; int eof; From patchwork Fri Oct 7 20:25:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38609 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp205975pzc; Fri, 7 Oct 2022 13:25:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM76KPNWLJNJuxfj0S+lxdTvDtCrLe0mFNPqLVhZ9oB/RjUzPxizInogwgV8jxZcvkdDgzaZ X-Received: by 2002:a17:906:ef8c:b0:78d:46b7:6847 with SMTP id ze12-20020a170906ef8c00b0078d46b76847mr5400061ejb.241.1665174338000; Fri, 07 Oct 2022 13:25:38 -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 l20-20020a056402255400b00451bc675cc9si3034218edb.335.2022.10.07.13.25.37; Fri, 07 Oct 2022 13:25:37 -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=UIdbxcEv; 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 9715A68BBB0; Fri, 7 Oct 2022 23:25:28 +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-oln040092072055.outbound.protection.outlook.com [40.92.72.55]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6276268B580 for ; Fri, 7 Oct 2022 23:25:22 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lcus1ImfTVNlQiTlY1JCTgtC5aPM6Q9keNkd9BXDrByTQEg+Nk/VX298mwdZqDuUYILEMushwUSPCreapgmZrOejI4YguH4Y1YJNWlDSzm/qrmPx7ekMYpUAyA/OaEDVHvGr5Tnj7i6vMFgAcUg6Rwv6DCjpMwRaEqLhqvTpugwmRWz4AEcVXkkRuIJxQXYZCrpfnYeVLJVcrRvufwaLiVyjhJUpku7ubb16frk8C4X6p7Qm8KyORIVemjMiBTB02PWi/2gSLw0Va30Jllw49l5/xDomRjGe9ePt+Y6dbM6jjgiFd7GqWVPHqzFUmVsgZKttIyj3snxVH8dWdJsHug== 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=Sx2HkIb/sdqnuQCFLF44+DT2KmPQPAfyC/QuiXD6UTk=; b=mkzoB7i8jiIts7QeZeDqTTMJsV9W3dzdnwYc64N36y7Fl8PmMrVqq5MhdMkCpw9OeDA3+zZisdo4P64ydM8eAR1WDHVwaPAVSL06kAfkiPQkGYuJ2KCKzYIXKhel/8BHLX2J1f0wnCyYwF5FgMIHuas8RshGppNjtvsQ+FpUHV1054x0Zndx3EviDIp1f3po8ZXgI5+IxHZ8NO2lqrQFTkrC3pQDy1AsWnoLTMaQbUeNz232KjlMERSIo4w48VNXhLTLmPanlijd4PIKWICo1igdojHEjYP5QKlQXeB7qADXVSZ9KkgmzqY6QM0m9I+uWpniRgE4SqmywjSASDXcuw== 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=Sx2HkIb/sdqnuQCFLF44+DT2KmPQPAfyC/QuiXD6UTk=; b=UIdbxcEvrZ0tokNC0Bzs+0MW++vdOHugofukbUHi6vKWIPGYXfdk3j/FXJjE9JUnDTpfJnYFIZXZlPM50xk41qt4WaAFK4XY365nunhe0WqMUe0HJ7dPRqdMqy7oozXByfAv1A+LYHLiS+ATlM9MW6SU5MorW4dAciEZRDEFaCWQz6yNDVTDJx0hSiHNVUgltOpPiMYxEIX/9Z3xP5uKuyMQG9wbRpb6eRB0d5CeGFNUpg9+gmuHJFeED82EoYMAWCRxSe5Snjxh/ChnQBf9yoDkzptssXkukh+Q8/KGkNJuyyK6yG+8zRdnjesCLfSq9S+uvStmJviokPzfgmXVRQ== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0285.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Fri, 7 Oct 2022 20:25:14 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.028; Fri, 7 Oct 2022 20:25:14 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 22:25:03 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [x62jT1jSLIs7IT6WNCEiIDZOanHRCNQOc2zV4eCV3uw=] X-ClientProxiedBy: ZR0P278CA0106.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:23::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221007202508.4188148-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0285:EE_ X-MS-Office365-Filtering-Correlation-Id: c59dc403-a205-48d2-5337-08daa8a20aaa X-MS-Exchange-SLBlob-MailProps: feAVlmA1hHVH57rSaMIQaiIXYFvQh5UDsFrg+Pzxrds6e+7DHIMUlTelTqnXCqpJ6XGmhfektvztHYLSngd8iiGeQ91soFKj35TWJIHCzpV410v6M8NL/00eVUepoUAP74lo3Vlu2HmlpTZ2m0UsGncMZ78U0g8qCpVaJA9VCnUgcxlU+Q700Oy5eEAqkmDEVMuHcVODFnKUEjRfqoXF7N8zAqjVBmSBlTCmHQGYTjvYOihFKkV315QmvKpxbrMZrC+NbfDRoOPEl9qlmfqtDB0Oj4mBT/iN05XLPp26n0P3rJxp0BKcHuE0sirjECnFJjJLxgPTKPjbgPMHG1uByWS0pweuplmwwimEqq1JBS+USUVf312lUmuO7VJJihWNby4BZ8sGyOg8X+epZtGdsysJqbse7rsjb0pvXAzAVVTpy+5QTe0Q3aNtdNRY5J3Dxy8gyKJvM+QEKvdJXodW/GXGsG6NNg7mu8HoaV98nk8u9YfX5DdtbZo7e00Jm3tjJOqEKYzo7jsf1+FvHox5x+ioKkyKCtiNa4bNfc5iTSzk97bwWi54DlCI1vxmqi/GntH1/tUZXpjE0Rdxga43rIlqnjP0SUaRTI2DISbISYnBjhOK37unFzeR1LTG1Y/0p/6l9owc08TZrEUWqq9OSY6OHc/s96Illn0NK6xQAv9e7fv26JGfR/eAJFM+rNeftKvT5CV293Hw1p+hD8Icig== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WrhuN97dhDmjKXAM/s93iwq9RcXPASO6rLPmWg6fJK0rFlVEZGG886D/Dk27NkhqAeRVZBD6r1lrP6/6EJzeZbJYGV5gBlMxVBT4C2nbxnHuYiqom9DUk5zIteESKS2cc3Y/GJHAjQ8A6yESYdFm1MiryQxvwWsHscUnkWFWo0BSe7j8j+ivry732AiPmcUk/rsBJ9XUqEUzn6mHumZxQTjNVaQNjOi2uSv2WQfiGMn5Fex451R2eexFYghg1Z3Np5srjo00rpswxqiOH/thcZucQozXXbZiDw3ptpjZY6YwfWIsSr84vUpFfyDfoveVynrBxeNwAQA1/icn6OLwnl8Jx9Z3RGwiVJodg5anGRYMZPzcT2R9fIi44aoDGQSRo0AlCWb0UR/+/cN6UAymM7kilt1KJ7nKQoKf37F/Z3NRmOel6YJ8oQmWr0oGBW3kCglqNAbbDXPXGSSpFIaUSbp2r7xeVdYRKmZQzpnFoihwg7EV6TXSUtAPvYdfXgAF6Vx0UsdxXQvuYUkhIbHT+pogDm3NvNmZkXQ0gpehoeRhQD27p0t/K6ahbbCAWmflo0T2pAiQuB00fpXajzWa4mpmpBJsyC6N0lViJSIV1f3R5k4MCkh0aWq2Ld6mHdMES2vylEz3BAa2mr7vDocQoupd9EgRIWm5eZ52TNIhQrIw5bai+HmzjUUuEQK1RpVo X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: e0SW6+OOWlBIZePsfTAXMLYA2yHt4B66DjeRK/65xbjKqDO5WrqSEXmxKvbcMbG+nnUWFyyJITM3i7w9wUvBJNfLAEJcMfdShhTM8EwNtSHlWWNRwsilTdWZWsvNHDIGojRfU5u3HpoMQ+9QzkmegRYg4xkGTSfpxIrmG1JA7PwqUIIfOEPtDTc989XuX8A/swaL/XkzvV5MYcBsqDPOXcJj7rnDmOGPf66r5gGk32f5iDdQBAdjW1LGhYTmifSmA7MzGtzewel9if3of4h6hP2zxP9AQTuxdpcLeW3M6Pvz7ljCZLD4x1moW1bqKmhe/QGR5JRRON7UQ4Q9ZBr+yt11n6fg4BIGSO6GeLdmQIpYmucLUgqMgkY0Do6LTp9q5toubwt3ZMkj8k2dU6PnYgKGXODImklU131ntmFxG7QRUsXh8etI8b6UZssLqUgY3BKX2tWT5GTRNlIG1unNHbOJuUSPKRIXQGsvEWurz1CxrLh/IJmiN1uSwG1NCiTrmTxxLVm4hXjb00lNjQ46qxg31/wkIhULndsIWJ3aH/rx3wdtoIKByNnF7nhCW2iPGQ0OLR1a22FXffBn34IHxRP+JUABh2VS/ol24OxoP2BEsOTXu2cI7Fh/u0TdcikdgVhOhaAqcZ7hOTD1QUcIGVh0xAcH08WhFm+rg7gRcS3gIflXoAPhO/rpxR3IF6yJi4AOj7Mesbod4LzU549abxtZ7QN+bxtG1KKMS16aaNAWzzS9oBUJ++fEfPhhu2dBHCjgvtjScfyCIStImPn/uwjWhgHBalO/hWmYVIsjCWwl06D6hQuL6e6qzkKO6zUrujQnS/z0MF8/6GLr2EXNZlI2kRB6CiMCis3yuLQAMfSaM1WOk/DFxZZMQN9pCIJ9p5uR25hc+cDrQU1e0q2gFjmEgMn+d4mrKVsyLE/Ht1SxCthyJCEk6Lyndr2fk6TJtOR1prGSKY3rsq8RHmZKlUwmASzrN5kCXXEdvppELWlyrnuXFSkvljerYPfGe043wNEu6VSXq2zHKOrDIlp5OVyqRdRvKy1C0YrFH6kvOA660BZgEJmQFOUgB3dpHTl0IdeWbIlccZ9XnYM5kbY5ub0cyw2VhR0EG470t3jD943Sh0B2/vnztobapmGgoaZfr8Orcz9xh2lkY9BJEBz6YtgP2Rpae46TLQf11VgySUy8+kjlBpfmgA2MrMTo53UiDh0Fcn0zSXr2Q1I742Oi3VbYb5oACd99FEEN78GcTf0vhrfxoGEq08ZwqXZ39k8lmY9kQVzJq1r6H1Zqe/dOrD+ERq0dqb/Gh2pL5fShvFA= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c59dc403-a205-48d2-5337-08daa8a20aaa X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 20:25:14.5324 (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: DU2P250MB0285 Subject: [FFmpeg-devel] [PATCH 4/9] avcodec/opus: Use prefix for defines 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: KJPECNAdQlRY Signed-off-by: Andreas Rheinhardt --- libavcodec/opus.h | 6 +++--- libavcodec/opus_parse.c | 12 ++++++------ libavcodec/opus_parse.h | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libavcodec/opus.h b/libavcodec/opus.h index 4d061cf5f8..f87b63aaca 100644 --- a/libavcodec/opus.h +++ b/libavcodec/opus.h @@ -25,9 +25,9 @@ #include -#define MAX_FRAME_SIZE 1275 -#define MAX_FRAMES 48 -#define MAX_PACKET_DUR 5760 +#define OPUS_MAX_FRAME_SIZE 1275 +#define OPUS_MAX_FRAMES 48 +#define OPUS_MAX_PACKET_DUR 5760 #define OPUS_TS_HEADER 0x7FE0 // 0x3ff (11 bits) #define OPUS_TS_MASK 0xFFE0 // top 11 bits diff --git a/libavcodec/opus_parse.c b/libavcodec/opus_parse.c index 39765c5b79..e922d1f304 100644 --- a/libavcodec/opus_parse.c +++ b/libavcodec/opus_parse.c @@ -128,7 +128,7 @@ int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, } frame_bytes = end - ptr; - if (frame_bytes > MAX_FRAME_SIZE) + if (frame_bytes > OPUS_MAX_FRAME_SIZE) goto fail; pkt->frame_offset[0] = ptr - buf; pkt->frame_size[0] = frame_bytes; @@ -147,7 +147,7 @@ int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, } frame_bytes = end - ptr; - if (frame_bytes & 1 || frame_bytes >> 1 > MAX_FRAME_SIZE) + if (frame_bytes & 1 || frame_bytes >> 1 > OPUS_MAX_FRAME_SIZE) goto fail; pkt->frame_offset[0] = ptr - buf; pkt->frame_size[0] = frame_bytes >> 1; @@ -177,7 +177,7 @@ int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, /* calculate 2nd frame size */ frame_bytes = end - ptr - pkt->frame_size[0]; - if (frame_bytes < 0 || frame_bytes > MAX_FRAME_SIZE) + if (frame_bytes < 0 || frame_bytes > OPUS_MAX_FRAME_SIZE) goto fail; pkt->frame_offset[1] = pkt->frame_offset[0] + pkt->frame_size[0]; pkt->frame_size[1] = frame_bytes; @@ -189,7 +189,7 @@ int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, padding = (i >> 6) & 0x01; pkt->vbr = (i >> 7) & 0x01; - if (pkt->frame_count == 0 || pkt->frame_count > MAX_FRAMES) + if (pkt->frame_count == 0 || pkt->frame_count > OPUS_MAX_FRAMES) goto fail; /* read padding size */ @@ -239,7 +239,7 @@ int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, } else { frame_bytes = end - ptr - padding; if (frame_bytes % pkt->frame_count || - frame_bytes / pkt->frame_count > MAX_FRAME_SIZE) + frame_bytes / pkt->frame_count > OPUS_MAX_FRAME_SIZE) goto fail; frame_bytes /= pkt->frame_count; } @@ -258,7 +258,7 @@ int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, /* total packet duration cannot be larger than 120ms */ pkt->frame_duration = opus_frame_duration[pkt->config]; - if (pkt->frame_duration * pkt->frame_count > MAX_PACKET_DUR) + if (pkt->frame_duration * pkt->frame_count > OPUS_MAX_PACKET_DUR) goto fail; /* set mode and bandwidth */ diff --git a/libavcodec/opus_parse.h b/libavcodec/opus_parse.h index 8e5c6a880c..83ed3c7887 100644 --- a/libavcodec/opus_parse.h +++ b/libavcodec/opus_parse.h @@ -37,8 +37,8 @@ typedef struct OpusPacket { int config; /**< configuration: tells the audio mode, ** bandwidth, and frame duration */ int frame_count; /**< frame count */ - int frame_offset[MAX_FRAMES]; /**< frame offsets */ - int frame_size[MAX_FRAMES]; /**< frame sizes */ + int frame_offset[OPUS_MAX_FRAMES]; /**< frame offsets */ + int frame_size[OPUS_MAX_FRAMES]; /**< frame sizes */ int frame_duration; /**< frame duration, in samples @ 48kHz */ enum OpusMode mode; /**< mode */ enum OpusBandwidth bandwidth; /**< bandwidth */ From patchwork Fri Oct 7 20:25:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38610 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp206026pzc; Fri, 7 Oct 2022 13:25:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7+EFPpOL0cVUmAw9QTEH+V9DOnGu0jYQSCmBZ350+it0R8R4LO1boeJjoZC9uByiR26awB X-Received: by 2002:a17:907:1b24:b0:76d:7b9d:2f8b with SMTP id mp36-20020a1709071b2400b0076d7b9d2f8bmr5422359ejc.414.1665174346391; Fri, 07 Oct 2022 13:25:46 -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 e22-20020a17090658d600b0078ac0d5d03esi4264041ejs.562.2022.10.07.13.25.46; Fri, 07 Oct 2022 13:25:46 -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=h9BYQHVO; 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 8E45A68BBCD; Fri, 7 Oct 2022 23:25:33 +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-oln040092072055.outbound.protection.outlook.com [40.92.72.55]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 83B3F68B64A for ; Fri, 7 Oct 2022 23:25:27 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fLvUHTX5078fCrX31mPZOwQVmvUKNn4dJ40OOD1B+qvyirNCfADVeoP+sYVX6PXG1MKzVsprPbvm8p0CXBHKEPg4RKVisxZE6wcuNPdIOOL8gS6RY/rXTPGurpDjyKzX0HgPlcVeVWapckk9dKbjJkvO21vQuMJTLJgx1FCTjeTJeSbXqmBtE2oVUOa4kVUJjTCdHqvFrT494J3qtTD9SFRtmVzVJk18zAKLd6AdK8oiRsfhjIutf3fWp0qzFTqiv8Pfbj0xfDhVmupeLnERue+vZ0E7HJpFC9PeBg9RnbouF0YuhciQiAjioo1UuriPEOL70nDWylvbtjL38SbO1A== 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=iaLmjUdmwbJmSLaegSqsB/i4/xYpgysOnRl3fxGT0bw=; b=jDV/64+KS1GavNJwn+xpus/yURkhXJb4fIRdJ+9UXO5hKod41ZN3leowUsAJSC2dxMuaXGuUmW+slQfhTMFTfICjAotkjVqGVZof2DmFdWI7SJ380IqUygnS6S4JIqnR6Z8sxxP/4CBIt0urJduYb6dUPzZ4t9Ofwa6SVBc4gfTICmffWmHJSQU+5/ZsmXxOOBZZOfvrkFREEX84ivaCtIRzZlRXB5YbkHb+Jt9kGJPLTdrYOMeNfgghWZEsTwPbclI84Dkgw5NBVkbNWkK7dh9C6QRCZpuHh3s1DJEKDHDU+yf1Ks0Xfa0DN/L4bBDm4tTYm2VYh+kIpoXkDRpFRw== 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=iaLmjUdmwbJmSLaegSqsB/i4/xYpgysOnRl3fxGT0bw=; b=h9BYQHVOuycuEX3wz4AuNtasMPcNG+tmE42YuE/GkKjnm3L7+tAqbn7Jsgjy8zcw8/j/IGbbrJzHS2QV8vIGqGDqKZipOL6y9ssAEFTMLEpnwkBm/M/lc41i1imJD1Dxf/uLAYK2VADP1p7BxX0JmwolcWbbaA8FxCw/nmfJbaYKmhvXoRy0kCaKzWaTXck5b6ABJ2KDperUyDr6Vmp4Fet0y3uDUzI5WuRo6lxlFtfSQRpBePaA+A1gVDiYDkAuW5FNM+UUcBoxBdgAt6INkcw/+511jBk/EX28GxdOyCTvj6Ta4cGDdgrExZ9qaaLA2oQY3Y4J1QrfsEVsiEimEA== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0285.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Fri, 7 Oct 2022 20:25:22 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.028; Fri, 7 Oct 2022 20:25:22 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 22:25:04 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [Yz0bn0ItEfiwKfAiqqgeY/28SOODUKPZWKw3Q6GHkZo=] X-ClientProxiedBy: ZR0P278CA0106.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:23::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221007202508.4188148-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0285:EE_ X-MS-Office365-Filtering-Correlation-Id: 271ace78-5b77-4739-096a-08daa8a20f61 X-MS-Exchange-SLBlob-MailProps: a+H6FLLcF3rUGeq4fk4l5dm1gk0Jy5LfykjbcWFEUQW8+xShW43XatM2ydCRotpYefDZKzJXQVQA1HRw3r2pjJnju7larmrGEJ1ePGDTsrvvulPH7NLBkQP/MixoY3w28ZpO4u4ZtHJ7TXfC+jqYSpuKZVXUMYxvIljpkcHDagyrlBRrxSnxr3msxMBenOT9egfdiT67TLG7FBIql9/6Fl5CtZpje8yHUOzAWFaypgFAtuY8+Hw7DK+uzspThQDhXyoLqp8Cm5kwfMbCJl+Egw7GfDkbsn6dHfAG+MZpC6TdEVjKI89ZfOiMsqwoEW0K8yyHu8Rbjn8DfTJDxyT2S91qLecF7Ch6i6wcC2bpKM+nzbMKKu74exK2Y42J/ha5NiDYfuGZH7yaFpEC+u5jrGD6HqVTvMNjeps+UYfhp/RFdYU6FLeaYFiLU1jgaPoAQbPktmaiWnqF6GPMRrqO2bPexOBuROals1nSSf7glMjpKbHABAl1IZMYMUlPyZblVIax6FeJC8L4fSFA6AIbhG43i4Zqc7Q7OkNEh5MsXDDBnwK7gKaKKRa4RXUcGou2rymC1SAjO17s2ctGEyqecOfeeoCXmym03JyPNpV3mkWGmB7Spuxc6PAIRCb7KfyKxfeuvUirU931Bj5RApqE7Zt+zeGb5IswZtRocctGGba4TRHqbsb7o/uLnK+Rb04l0FS/Nl3IFGEoyjoZI2tyKn1X0ycfXEiXH6k6OlNu5R+uKRbOf+WN+UC+qpldZBi5F+W4wg9Yfc7eU1uOs2/LXVo9bDrLr/k29p9wjfYIUSuROXHpqD7vuMNO1cmiT1eT X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0Hhxh4cypn6UF1NKR+kI79AMkcMw0Zgkrhx3RYwcWLzJEJl8Uka3YJhVmVDjH64RtN2TTFtYKYEiuFJmEyMcEb53IQ6Htj3Fi4LrmlmXSo4y8GEJ1PqHLx03hhRjvPTA7jU4oQgpag2V0YVYMzNMPKMvKL9dt1vL2sSzEABdebpl60mq4oFbF03CB/XJd040Bo1EgUO5zRhncxM2y34eImHNPIBBfgCgYsuRwIzo7GPZdqd6hgHUuLQlrgmWT7GJixFLyF/A2+UhqSyQonx8XHH2lp3E1sNjng7Bnh0/QWwCWreyPnWvQb5JaJoJOgsp7xm1W83p0AU3ycPPUmzVoq02mIg5oOC6qp4wnrvOxfwCwPqrx59IAdFg89ma4MR4dxS2LflBajEgHewCweZ+MFePLhdMJC9QUnH596hKgVws+q/mtff+mqDzOfRV6H639IOOJraC8fHf2V5Gh4OVmcgD9PEEVqhZyN4Py6QL5nVrmsbm4fI+YYmJEEIeHtOjypO1LYqOi6DSGYAcFpyT1nctyBJs8R3xVrFKSGPE+TJDQOPuHhuu7W+FZozFI7/5dQ59Ura54zeXG5QE3wjWK5zgPQgPKKA17oVWQ+vyfoRaN8t5bk+ikhDGNZ6L47bzVOhfhXsERRwOkyyJQRmiRA3u0bk/kynUCUbM9gBinBofnWYp6rIzzZhIku72Bfbi X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9f/i7up5eYhSor7CJflhQvKa21j4zPxuhRJ5i59WYRKC8z/F6fRBcUMIOjO8KUSUbh1T4O/NahTOBQb6kl7BR7nvJZfLwh5ilgB2PDq9WYmR0l3n4yWqZWu4FZAmn+slC3aEXj8yv3i6o/vmpvgt128amtbBiRmIAI/63Wh+ZA1iG2P2DpKA6GhUNn1GkHdU2uyvuEX3ikeZhbpKi+WehNq1l01EuD43xWPM8YfAxCxuHol9cvG8ZBfKUQNb1DswNx9pMBblxnJBsINYRh0Xoem/xzb7PuZhAVbV03oE+NkHulWtMvI35EmLTxA7i30kvLYEqyXpsxRzWxGNtGwKutrrVgeXhVsaDYVGqDeRC+wqIVsBChg/y+rhYz8TfFQWz1DbBCGaGhN0vzZBwyrAUUpeIsWwg66U/C58jssePZEqhWvHd6BaMI6alPrJpArisLMLlWRCDzWJcp5SQIyks+z8awmgPk8dS2J6/sHg5jipFDzxmaOC6FkR+doQYyZbXkBGM8owYhnifybXkAuQ+sp25JxORLkU6x9cJKt09vvtCDptvAEfUcOU8avzxJZRQeR23DurBjVuS3VPJOPY8GhTqbW6gh4fczIfkZ4CA6rOzDlRc3Tiq6bv40r8IVqpCebeQ3RYelBGXks14FSZfYHBcdaeoRGrSfvTxYM6fPwOxzYGjCdKfe8j87O2m/TRh8s8hMFaQ4hpHguW7HxGkQkG4x3bVNnFQzMaQwJ6uljCY0nna/hdh6Oh+dDDKr0O0ac9pggl2QJQnZgPoJZwV+irh5t/ApdfxzLRC9qweTBo7ZUFvCROG3bwd8Nvn/8wDlESdVJZRXAZ856R5G/nNoj/8cYe3lJ39KOP4Z4ERxnk+aDgoyxpjvdzc2JLPFAzfvoMHBvpr4kISE9xG81FhGmr6Sq2KeIuQJznw5MJbSk5ydeE1sCpmnaTWZummujKN3tTX+weluInrCnUoNU6gCTUP9wxoHMALt94gG2mgvFvEKIov9pGgZNuwmScg34nQhgq2Ig8zRjXfdhoEmWxCWw7bKSK9lR5HzLSwN57eEawLNNWNQtJ1Pcv/z5hN7UDdmiRBccagpd4418LHes/DHy3+pwACIeRsj9MS/gAgjj1yBXdh3aT+i1IlI1xgOc2jbBrSoqqQcKrhkaCu9fHnQojJ7Y1mYT5OCQGjFQv1sYNkL+SwkvYWhfOoBLQvmbsw0/gwha+KzAhVHNle+BS15CGe3X9hhIGRZ/wpKyeeR7HPqi+Y97MvpHsLhg0wFWyZFEcNpUMLCZ88HMKILg1hE/pbxNgqDZh+aZNzvblEDM= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 271ace78-5b77-4739-096a-08daa8a20f61 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 20:25:22.4406 (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: DU2P250MB0285 Subject: [FFmpeg-devel] [PATCH 5/9] avcodec/opus_rc: Don't duplicate define 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: xN+NKVvV1ClD Signed-off-by: Andreas Rheinhardt --- libavcodec/opus_rc.c | 4 ++-- libavcodec/opus_rc.h | 5 ++--- libavcodec/opusenc_psy.c | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libavcodec/opus_rc.c b/libavcodec/opus_rc.c index 2061418e52..1a26d889b7 100644 --- a/libavcodec/opus_rc.c +++ b/libavcodec/opus_rc.c @@ -388,7 +388,7 @@ void ff_opus_rc_enc_end(OpusRangeCoder *rc, uint8_t *dst, int size) int i, lap; uint8_t *rb_src, *rb_dst; ff_opus_rc_put_raw(rc, 0, 32 - rc->rb.cachelen); - rb_src = rc->buf + OPUS_MAX_PACKET_SIZE + 12 - rc->rb.bytes; + rb_src = rc->buf + OPUS_MAX_FRAME_SIZE + 12 - rc->rb.bytes; rb_dst = dst + FFMAX(size - rc->rb.bytes, 0); lap = &dst[rng_bytes] - rb_dst; for (i = 0; i < lap; i++) @@ -405,5 +405,5 @@ void ff_opus_rc_enc_init(OpusRangeCoder *rc) rc->rem = -1; rc->ext = 0; rc->rng_cur = rc->buf; - ff_opus_rc_dec_raw_init(rc, rc->buf + OPUS_MAX_PACKET_SIZE + 8, 0); + ff_opus_rc_dec_raw_init(rc, rc->buf + OPUS_MAX_FRAME_SIZE + 8, 0); } diff --git a/libavcodec/opus_rc.h b/libavcodec/opus_rc.h index 1b3cb93a15..72e683b075 100644 --- a/libavcodec/opus_rc.h +++ b/libavcodec/opus_rc.h @@ -25,8 +25,7 @@ #include #include "get_bits.h" - -#define OPUS_MAX_PACKET_SIZE 1275 +#include "opus.h" #define opus_ilog(i) (av_log2(i) + !!(i)) @@ -45,7 +44,7 @@ typedef struct OpusRangeCoder { uint32_t total_bits; /* Encoder */ - uint8_t buf[OPUS_MAX_PACKET_SIZE + 12]; /* memcpy vs (memmove + overreading) */ + uint8_t buf[OPUS_MAX_FRAME_SIZE + 12]; /* memcpy vs (memmove + overreading) */ uint8_t *rng_cur; /* Current range coded byte */ int ext; /* Awaiting propagation */ int rem; /* Carryout flag */ diff --git a/libavcodec/opusenc_psy.c b/libavcodec/opusenc_psy.c index 5c768ae68e..48ccd2ebd0 100644 --- a/libavcodec/opusenc_psy.c +++ b/libavcodec/opusenc_psy.c @@ -359,7 +359,7 @@ static void celt_gauge_psy_weight(OpusPsyContext *s, OpusPsyStep **start, rate /= s->avctx->sample_rate/frame_size; f_out->framebits = lrintf(rate); - f_out->framebits = FFMIN(f_out->framebits, OPUS_MAX_PACKET_SIZE*8); + f_out->framebits = FFMIN(f_out->framebits, OPUS_MAX_FRAME_SIZE * 8); f_out->framebits = FFALIGN(f_out->framebits, 8); } From patchwork Fri Oct 7 20:25:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38611 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp206077pzc; Fri, 7 Oct 2022 13:25:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/RUYWAhIGf4QowK6qhkXLL965MEiDSq/X0TrwHFoYDBXgmMxNB7sxHXvdsx8Q4AvvqI4G X-Received: by 2002:a17:907:2c62:b0:77a:e3ce:5ef0 with SMTP id ib2-20020a1709072c6200b0077ae3ce5ef0mr5440280ejc.553.1665174355394; Fri, 07 Oct 2022 13:25:55 -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 gn3-20020a1709070d0300b00781c2fc93c1si3367210ejc.676.2022.10.07.13.25.55; Fri, 07 Oct 2022 13:25:55 -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=t1i0y76p; 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 8628768BB85; Fri, 7 Oct 2022 23:25:34 +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-oln040092072055.outbound.protection.outlook.com [40.92.72.55]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B5F2568B64A for ; Fri, 7 Oct 2022 23:25:32 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P9qK53lpYqrgqHC1D1Cnhy4rkubzVGJn3DNO3/lKXp7zTEjNINVNcjiTAEVtg76sLL2PUMPfHC4trGK5cLwpGGkf1TCGQM/YitqdRGWWZ1RIKNXhxF56W2joI/Hr3SLlyZVcftvEeAvUBSMtc5Cq8IVzmVYBsvNqWCoZEVDsCloIEK88iq+WBAIZ213lVLfdvnYgqo4WGDjV/sqqFlLRfyiGxitEf6IDl/yz9Rk1M40cJCafy+Kw9Ndo2svRR92VRRO3n0VvLG2yn65+Ze79R9fnK55KxiJEGZLSJTlRaEYK5xo5d06OaSXy+9r6B+aQoWi0QSpmeDlYuR1k2moK1w== 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=oxNDJKGii8BqV6BhLCGeCWrauBWFWv7vRbdqAUwuLYI=; b=esiXc+2C1nJeTuI/AZeGKWp1uBM32lKDNAkqjqSts6sNyxI4+DzC4u0K1jMwXaLRy5/l6tEkUtmuI5UoESwTWy2Uz+9eyCiKuWoGrdPG4ANA9PqQ7/LBcUGtx3h7F+yL7nlX1elryqLpo3Z+lK/x41A39vGu8F/d8Fgb7lUmWBQyYI3h2dQxbUO4awtiAV4v8Gc+591iAwIfftebNVIG7kvORQjIDsl6qU89T+yBQZXtedjMANnWdjvnI3LYWZ8KF60RKVmnA3KZt745K6/QCjFMx/TrdnkedbNFiJ8X+hNkibMrnJi5qlRyAYJeopseKnAJBf02BghpXMQAMO4qGg== 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=oxNDJKGii8BqV6BhLCGeCWrauBWFWv7vRbdqAUwuLYI=; b=t1i0y76pdmbU7QjeWEzXJUrWD0Vrg130LdoNmxmu/SSHA1vefHMhzwQl4nO1MbKI9u92EYCPayTwUmNWpoIXf0UlhlK2TKLXnJ1sXixrMQMKjfKZv5lwL8QwFxk2uFv8HJAX+yHU+Q87+hPe++IlCIvDonc0Mi0Aw3Dc5fBj6BNGhRfNk32QP5rqvk8vrMT8R9SDYBc0p7KkgYHuJZy3RGruNAK3H0zISwx3rMnXtVuoTIaG1TLR0LOq1x2Dpl1CBuKU7T5NWIg1Nt/v1fKLJVHuPylAtbYcwGD0dMvM7LwgMKoqIKDcQp55wcTOcR6LDYTTO8t9dZ3HoJfGhtq5+g== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0285.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Fri, 7 Oct 2022 20:25:24 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.028; Fri, 7 Oct 2022 20:25:24 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 22:25:05 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [Ch1hOP39KVl+Xubj6bFp7/j9FPTm5B/a4P1WIOXFisM=] X-ClientProxiedBy: ZR0P278CA0106.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:23::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221007202508.4188148-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0285:EE_ X-MS-Office365-Filtering-Correlation-Id: cdb75f8a-f991-4e6b-2e73-08daa8a2106c X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmpXYlgiiriwpqBJSiirmy7KcaN9BHV82kcYQI15DKWns1Uzu8oACZLzAg9166NpNABTG+AtYaq6EQxfP2NPvGwKgD9Aj3zCHDkWoZDHY5w5ekvKV9zOW81cTIw9IjTmde1gO6uAkib+J2o9JP+NY7l7HRVRG7fcSKvc2qzlDSc0PWraojGXrjPCHyW6sPNm0eCV1SDhmRhWbEeiXLrC1kn+qUQNU3oUjDKoxekMzMUse0NFK+LdO3v9Se4ejCp5/JKm/sdt7wMiKVDSyJGcoU0EJb5WMGQR7B+Nd+uCrnVWX152MVfIbWPlKqlL3dCY1rSGOOnwoYDJstSmu4/JAikmkJIuZ/C0vS5sjMj9x6nuP6mXNyRKzMYeHPEpx5zHeL2aa+cv5+nr4NHdLNye04o/g+yeIdSO6YSMQ3BiVTfDeDPwCjTGwB/IGssNRQcJAFSEYhujwZBtNn/74mT9q13XP9ZCW/kUzSr4SHXfrTwjVAmpKZzn+lXqX4tCvyl1YPQt1EEU3dtexpVGxa4U0dyv+RfxiM0F3ma01Uz5F5rtzaesDrAL2hsH85pF28zkW1yXTkZL4Ko4L7sHNvKlvyymFi5HqP0dh7U+wGsBToVdtmhMRoqmKQ/7LT9+AZEtL7gHqZnHM/ZpZQd8Fa8+bqjrJx82iZePdK4VPUZDkL1uJS9IhVfE9pT/xTkNXk4h8jSsLm4OW8tWJGT36EkUEGVmP0uc/kO1zh43idJnRL9Hq3J4dUlJ08wSjrmytaaGJ6g= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xk7JVrU/EVL159e2y4r2BMTdE8Sb5pxmjLl50sRt6TugCkrE88Uzg7HKbHsTZsisn9EH1kBAu9ORtN3UiEBxWPpmEzA+hF1IyyhJgZcTVYIZUVyK32FxOGFRQSlAOPbIn9xEUGbXRhNNLbFeMJy1fSI/Cok9Ri2CMoQQ9skglXPrTjCDjW3OdH7DAlxdFoWdmOLKyLbIJXONsDRMbod313kd09tcis6g6lNjKN2o72eMISHxu9CeyHPuk3wEOAgyu/SRPahurxLJ4AOLqU040AZefgyWTOIbGjVKk6e+aIrgtMPPWrTFzUxeE7F8qGuuLvz7pL/LZ6MgMBUtpKbFFAqa338+vo1psxabH0GijBfS4SzfNpaFIhc4q9S7ygxFnZ+DX1Glyf3SjGiy4uk6P3Wdx4Eshfp4ewRDv7PNTN3IKYYr6ZR2jxsNBHvmPO/DSNGk2lIVTNmMbjs2MmnVNbOr7kaFOukuEPYjj8O3UM7AdVyiSVwJQ59i2knIMskXWaDa7+9F6bKGjE6DI1/kxtym8HyvSOApNf0AK5OtaJXnsmIczcoCwAkKryb4t5f2WoTXQ3Ujyri5ndDY7vS/JMr/VvPQWlS9ixIm3fYCQv2+hqlMg8v5GAGe696z+JAOfl7+0YQPepguV9pOtNfFHT/shR5IAqdqdYD6hd2hRl2HCUNuQqDb3zTzuOQhfqHj X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uu0qb+pi8RbNTf7jpblzlc8jecpER7AXN1GZVi10Vblx4izG8dProG86YCRbPsI9MZu9Ov0DghVcxbXaNYT5NyfLpxSy7rNm7Dl4eXvhQsaEqjq4XmxYKc6qbo/it73me3zRN6v/K/Wja14HYxq60hrTRLrlMHpD2f7eQZAPIxgHC03VjSG7Mfk5CdcVT3RRN1HmdMlzCTxFlNYvCxRVxx3XC8VC4jEmoZQapuT23gsb6nXybhIbv8IG2hoXbTjJjt6czApfBHkDdYhX4K2s4p9gyHu3C5Xm9faxfTxmTDsMpSwDpgnNpmVLB/Uju3gpDumsizA8L9xvj7t7wgKdNkBnTqUbF7Y2d+qn8DdmFEpvKOfNV9yKkpYvx5L+8JtJ7Dg407I0Y/GKC3Tjjiwq3Rb7rkv+R8/atQ5lBl2htXeryzNNRPlg0geKB+x4x9wI7Ktz5RPQtOOKysF7vBGMN5WSBjufbwG/gWFkeOY1TiMAMJumalEANI+w9tm6La8LqSudAptR1MHZcs77+o2XDnLhae6JeuVDbha2TEh4M7s4PiuJX0404EzXg1gXpX6xiDysPR22GwWtabtxaDqyibpeBWewhg4l31mvps1eNV27Dx/gSYo4/dqO4aMLgXCOor1AKbGh6qpragfj6V3n8WZF4UdaQAXS37Q+wwoejFTGxsyhyVQsGdxG9bwU3uN488YGtsd1MVJ07su531/pRWBn1u5kYBbSNa1zK8VBupi/FquPL21AdEyhQnguKHJIGPkCYPDSrvJAFYLX94YHnW8W3SlChRfcVI/JQHYOH9S1nChUXgk8AQ8JDpGIq3hGj7+kGmqWlkOow3q9ScjLb9/Q7h+fI5ddzrOcX0GR2PPK/+5trMvHopiuNN8WrCD7QUhX5tv2DfgDej4Lxa/8IpDA6cZYx0jTrcMAGVrPUhFqmpurWbcMUowvnjpklIfixMeiwCpJiivsYtMKbxEO4C+epTLMcgzr2hej03ElnYP87zN8WHK6sLZCcutzP57nl+uQDx3PDr/FxMwsgJ6imcTVpVasUjLZDelOFAKT/BohuKhGCk0TxiZuXUJKI/tBuNJSHGMTxyDTXVqvQOR44NDVisNahs7uOmEukMfXcSvn46uOWmfntxB3mIulufdlUi3m2DhUzyChjWnvP9yI2rKsL2lH/fviwE8fAiE0PDOBDZ2D2GxU4e0gs5tbplzQV+RgeytI97V3qJ5Vk2zzgAkkIR03wjimogYCJ2q9Ks/NmTcueyu28X2ouhbstYrNhTbAyEYfdlmkBlFkZK+dYHafrkgcWsCr6e6rwO/z764= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdb75f8a-f991-4e6b-2e73-08daa8a2106c X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 20:25:24.2227 (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: DU2P250MB0285 Subject: [FFmpeg-devel] [PATCH 6/9] avcodec/opus_pvq: Don't build ppp_pvq_search_c when unused 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: K+E3vTJzKNoy Signed-off-by: Andreas Rheinhardt --- libavcodec/opus_pvq.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavcodec/opus_pvq.c b/libavcodec/opus_pvq.c index 79101847af..d08dcd7413 100644 --- a/libavcodec/opus_pvq.c +++ b/libavcodec/opus_pvq.c @@ -366,6 +366,7 @@ static inline float celt_decode_pulses(OpusRangeCoder *rc, int *y, uint32_t N, u return celt_cwrsi(N, K, idx, y); } +#if CONFIG_OPUS_ENCODER /* * Faster than libopus's search, operates entirely in the signed domain. * Slightly worse/better depending on N, K and the input vector. @@ -418,6 +419,7 @@ static float ppp_pvq_search_c(float *X, int *y, int K, int N) return (float)y_norm; } +#endif static uint32_t celt_alg_quant(OpusRangeCoder *rc, float *X, uint32_t N, uint32_t K, enum CeltSpread spread, uint32_t blocks, float gain, @@ -907,11 +909,13 @@ int av_cold ff_celt_pvq_init(CeltPVQ **pvq, int encode) if (!s) return AVERROR(ENOMEM); - s->pvq_search = ppp_pvq_search_c; s->quant_band = encode ? pvq_encode_band : pvq_decode_band; -#if CONFIG_OPUS_ENCODER && ARCH_X86 +#if CONFIG_OPUS_ENCODER + s->pvq_search = ppp_pvq_search_c; +#if ARCH_X86 ff_celt_pvq_init_x86(s); +#endif #endif *pvq = s; From patchwork Fri Oct 7 20:25:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38612 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp206128pzc; Fri, 7 Oct 2022 13:26:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5pNpNZsYXPdlZ4okbgKDB98fjPqiPnEExBjiX3abbjfOPvUl1My7w9RLlQdeQijJrPSVZr X-Received: by 2002:a05:6402:4003:b0:459:b859:ed09 with SMTP id d3-20020a056402400300b00459b859ed09mr6134054eda.135.1665174365748; Fri, 07 Oct 2022 13:26:05 -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 t10-20020a056402524a00b0043c19cd608dsi3480889edd.33.2022.10.07.13.26.05; Fri, 07 Oct 2022 13:26:05 -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=ihhSKN4T; 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 A362B68BB63; Fri, 7 Oct 2022 23:25:36 +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-oln040092072055.outbound.protection.outlook.com [40.92.72.55]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D6D8D68BBA7 for ; Fri, 7 Oct 2022 23:25:32 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZtXBsJqtuRrSI/HDX9BXBDqDbDdUF7rdNwa0wv6mrM6FbGaEDqKJP4P+g+HSBWlB65F1pXHbo3L2S8qNE9vldpKmX6COdoCxLr0/v6O45Vooo6+tURmK0hhBybWMteNVNMscFmvryKvsp4ypp7EXDDUfrJsrOT5TB1IZbVN9+13dCFA3PazyZvo1rudNuovXUafvrCdkQa4cAAvyym/5+GRLfuj9nB6qzs1jvULSLo3fN4IEEYz79dw/+VaGk51+BY2Xmc7fO6pruLxMr9tXFa6SUbO9uOrgChVb1xfmeryl/ItWwdp92YnWBbC3dkj6DLGy8EgjAd/zYNcQL/7nbQ== 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=P7NMgkcGJ7YsH/9H7oertYyx8jK4xWJS7IuQL3u3mF8=; b=DQS48O5VdFJ5EzbcRSHWFoFi4b4XmCFVk1Rq63M8wTgOy6quy94+5SsSnpgzCGSfYzTnhscgmpgVYcfje9FdCaBAySn7y6sN/i+OLrhlsyeyadpG9ZkcGgTf3Lk88tb+FnWQMfKkngIQrnpAgVlS1e8RXzzWz0zLl2VbMfqRwwm37yC/h2qc0qiS7T9GGC32+KcvY2+ArFNuShiGfMTLSZHHdfgzO5YD8ltHPdjyQO85t4ppgidGnI/tq1hd5r2ntf1DqKAT4F4EQESIWgDU0ea47AHj9tWiWdeNgR0kuUPoJl1nskUcSI6DKvZsJI6l3nVBP7E6rkx+6o2R0GodKA== 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=P7NMgkcGJ7YsH/9H7oertYyx8jK4xWJS7IuQL3u3mF8=; b=ihhSKN4Te2I882xKKODHvLdWUDPLcOYQDXqtGTI3qfYj3vEjI3kIn1hFLSxNkXP7IFPnFsLclenS/QU0gY127PDxRBoMyPcIa/pKnMHdjqtdKWBevjzL3I+XceQV3o4cROchorrWZCa31kLskRRCVGmY49iGnU/sMZGA7LkHYGQV86mrzVzHW3suVj4y3Vvnh9i0G7OMkfTPMFuHie2eNMrpcOiB7mdUH73ZYkgVgVbtguBmwojRlWdnjlK3h38kI1GqWm3Zl6CUdkSAb9j4OZX5OtIFl5XR6hTy7hSYGPOqYEIafNiadQObskAfKuQz64HELupQXD3/bsxhFr7jng== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0285.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Fri, 7 Oct 2022 20:25:28 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.028; Fri, 7 Oct 2022 20:25:28 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 22:25:06 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [Ac5yFKmqiDKmoUeiu9+DguL+1MF2+rVsZ+6ykoutyX8=] X-ClientProxiedBy: ZR0P278CA0106.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:23::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221007202508.4188148-6-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0285:EE_ X-MS-Office365-Filtering-Correlation-Id: f01b748b-3ae7-456c-b5fb-08daa8a2130c X-MS-Exchange-SLBlob-MailProps: V85gaVfRD4+01U1U5L0H0p6VrfPRQyfW2BKY2hEq0iEmmggSmi8Hx4p0qeWuAntUmnrreAoRKYmCFCqw8q9cNfqcYcGwZeIufAF+a78UiagBXgT9ePpWzw1wGVXkJgLhu0sZ8ynWqmVEuPoijM78/zCMbDrBZwdVL6DcfBVkuzCVHS/7z0aVVDC0yh4bPKUmQp47XGkJABT0o4uoRlUK1kgjVKGCEcGEBpe3Ll2NCky7ORKLreWOMZoIjB1iITyVNIe5R1hYQpw3HZkxo2oasxxyAJvftxGWGQQoAO9sPqWBgyUkrKXGbQupiX3SoHtxFewDguCEkPkY/w4NP11n1IUxxDPP6KCUfuH2nsr3JwILiFq3ctlwauAGgTmX37Gh8QNJ6+AQgCVLm/1OplHUayrKgXuv9EXbejiXRKkHGrWqC+bNi0rGQ+dud9ce8wEcEAMKDg4HtRQWdtOx5I1dnvhFUl/8cXc0xhBa2iqLTkWS+3iV9UBbbz655rl/QP0TUUAhtM4JPzmYGhkZNinfvTQTCx6K6IMzsOkVz+w5tiDy+rUiuz64ocLw+9KOvJzsq6LBhDiKWD/BQuLaSYyZZcNZi2QnAf1aCLX7BaMDvR0KHVUOZtnfkn4IX4Wdcn82OjUFoZwgLpwSJmvxG27rHMyRGbIbM50jW+3/NLIlmSJSFtUZhDxnUhlRFjsEjP8KyIm/NLN45e78xYJcueBhhcwflvLGs/CW8wWBdP8h0DyYRrb1KwD83LbpM2BBRq6LeLFi6glkPE+crdpNTU+GD+sRXjRNwGAob9Bj5eY++8d/CBc8WJa5c2EcX8SV8T5SYtY3J+zDUye6w9Ec61K7NQ== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Kg+RCSrFTER/BSU2sY1klt3dGWYZe0bBsEhg0DNIgJJ54P7HK2/Q7dE26no4/qT2+78T6o7PidwGpz+a62MNZ9x9T2j1oDCJ8RCNvuRNPlAC/zG5XgUXn7NDc0dTq+2SSaxUW/hgGnYG+yAEELmqFeDDgEDIPcGKarJ4HZ/zJKzRXf3cVklNfT2aMbkTfd8Z8SHsUALpmfqcJ6CiFn5C4qOxMSWzsSTt7u5EUIiHFtnnueomnn2qcwMb3qEJNbTzIzjF7EEzhiWRpYTlobRQ01byNbH2Y+H8ABlUC+Y9WjJgdkMnKaGHAefrryTiKRCrC8D+sH1MOLSqaq9R/NYVPtnmkqAg1/EpGlLMDbzwItlRvSJ4OF5/PveUZY3wXkU7rBYo12/HIpzN4IKa0vmlec+UFj8EHLKEkkUw11zuktTsOuiGCns2wq6x/GEM3WGLeYonQCWqCKFGfK2tBzhQOl2mv9+niLaNgOuseKjYqNK743RoO+9P8SeAb7frQNMY0nfu2cy2N1qMAsopBi9nZH/I3zzt5naQEsUChpEC+vaPxdstrXkfvBSIN/D53Ej9N8QqSd1c7twfEox0TVrKPmqpMjlO6mQkfLqB5b+wgl7ifD/IrbKlE98Fhk5QmAIN X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: C3IMjEkqLw9CostMpeO16+vhKBhVsSLTpVnvGdOKvbjFaiXL2SeGZFwW+pg+n/17UXizaZEMdGURa9KKpxEpBv2+FlJtCIs3yXtBv65B6mndVw92Wegv2dvXxZ6romMW2IyidmfeZOW5vDaV9GcM4K3IrsU1+/7Xf+ELM+qyAwI075wyDttetObUpNM84og78H0dth9XgFXc9NSjUsfS4k7ouE5ZYsLwr3FwwVMtzEXUjfgJjqMCPYzJlqgYaZOfR4Bd3sRf3oXOkLm43RosNjm0TQYHq6YoKhBsvs85BqMeUYYlQobg4XOENgw9m2DV/bJaJb8I4rXJ4YAVgypYIHAd/hRzliM2Rga0zpfD/W+XLI6AevdRGVWgTGxxtKdlS3H/XiiGez4TVPojzfLiGkU3njKkY/g2EUoKknFMFsXyipFQ/qwUdS+ZbgVEpOyh9z67oc62rkO8dKSaToKq9HydbN7RDtJo6TMOSq59K8Dy1biRSWQRp/mWv3LXox2zRz3EtCWSPnE8cvAw3Q7DnIAIv7UvbVrb30FXIf8pSfMYtQVMiC9RQyenzU27N80FkJbZpofV666vc1fIlLo+OXAAP4oweGf/NuF0WHUywRYuxZnaeb9Alz1ztz9aI2gQCuqPTWQb4n0myNp6DYdJlAt/Og34bEizvCD9B3PlAWuak0ns41Cxxx86uFLmSjmhSkgFBGTNBPxMl3NlAiQegZtokmuQWK+fzsaq31NwZJZVqWwr5FtU8Y6IOvfRv6Vbg+UPjkgp5y1hvuDEN5+/wLdM965V1O6NmVa5k8kGhNX7JN4UDYr2Eif/Ndk1jWHKpZFwMnWSqRwb9tY35DqYvmVMNbq2GKah33wslt21ByvLYNOAuO0mH7DQ46xW8hFulZdZTUu7oWRhrLK6DanljZA4B/y9AC+Vdtv0wdPxGX5aAJgNnCZBR5WZk4dvqIAVrQaK3J9DVq7X9+biUAQL7lTgsnIQeiaYr2+MZD7ofBmiEPv+NdrpX/qxe2p52oCVcne3MoQWGawpn6eOiHVC/m3pFqQQ3xpbq2NhJFo6TElDVWHcC5CfYjtHnHfhW4b4jfQ6Tea4/jPvNHfLdK7snHn2SYunbnXgNf2AZwLyidMNbLTPtE8dTeeezTRtns20yp/t9PMQ2tCT/eWkdQQpCb+15JDs9ylUaTwuvqou0W4I7G19eJM9jTtX53w8UIP45ALyszIaGcy6DNYs4hkBAmzJd/ivpGbb2k4hOvulbgxMD9lIwJYE1rc9kQN4FQ74wFE8BE4wqLjV119+G+iAVsTe3NlY6LF56eDDH8fKzys= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f01b748b-3ae7-456c-b5fb-08daa8a2130c X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 20:25:28.7082 (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: DU2P250MB0285 Subject: [FFmpeg-devel] [PATCH 7/9] avcodec/opus_rc: Split de/encoder-only parts off OpusRangeContext 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: Ja6vWVv+B+WB The decoder currently only uses 72 bytes of 1376; furthermore, the GetBitContext in OpusRangeCoder is unused by the encoder, but its existence adds an unnecessary inclusion of get_bits.h to the encoder-only files. So split OpusRangeContext; also split opus_rc.c into an encoder- and a decoder-only part. This necessitated trivial changes in several other files. The only part where the changes where these changes were involved was opus_pvq.c, where the quant_band functions are now defined in a template file instead of being created via an av_always_inline function. Signed-off-by: Andreas Rheinhardt --- libavcodec/Makefile | 8 +- libavcodec/opus.c | 62 ++++- libavcodec/opus_celt.c | 39 +-- libavcodec/opus_celt.h | 3 +- libavcodec/opus_pvq.c | 456 +++------------------------------ libavcodec/opus_pvq_template.c | 432 +++++++++++++++++++++++++++++++ libavcodec/opus_rc.c | 409 ----------------------------- libavcodec/opus_rc.h | 66 ++--- libavcodec/opus_silk.c | 11 +- libavcodec/opus_silk.h | 4 +- libavcodec/opusdec.c | 11 +- libavcodec/opusdec_rc.c | 214 ++++++++++++++++ libavcodec/opusdec_rc.h | 53 ++++ libavcodec/opusenc.c | 39 +-- libavcodec/opusenc_psy.c | 14 +- libavcodec/opusenc_psy.h | 1 + libavcodec/opusenc_rc.c | 210 +++++++++++++++ libavcodec/opusenc_rc.h | 64 +++++ 18 files changed, 1139 insertions(+), 957 deletions(-) create mode 100644 libavcodec/opus_pvq_template.c delete mode 100644 libavcodec/opus_rc.c create mode 100644 libavcodec/opusdec_rc.c create mode 100644 libavcodec/opusdec_rc.h create mode 100644 libavcodec/opusenc_rc.c create mode 100644 libavcodec/opusenc_rc.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 592d9347f6..b7eb3b1e48 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -554,11 +554,11 @@ OBJS-$(CONFIG_NELLYMOSER_ENCODER) += nellymoserenc.o nellymoser.o OBJS-$(CONFIG_NOTCHLC_DECODER) += notchlc.o OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o OBJS-$(CONFIG_ON2AVC_DECODER) += on2avc.o on2avcdata.o -OBJS-$(CONFIG_OPUS_DECODER) += opusdec.o opus.o opus_celt.o opus_rc.o \ +OBJS-$(CONFIG_OPUS_DECODER) += opusdec.o opus.o opus_celt.o \ opus_pvq.o opus_silk.o opustab.o vorbis_data.o \ - opusdsp.o opus_parse.o -OBJS-$(CONFIG_OPUS_ENCODER) += opusenc.o opus.o opus_rc.o opustab.o opus_pvq.o \ - opusenc_psy.o + opusdec_rc.o opusdsp.o opus_parse.o +OBJS-$(CONFIG_OPUS_ENCODER) += opusenc.o opus.o opusenc_psy.o \ + opusenc_rc.o opustab.o opus_pvq.o OBJS-$(CONFIG_PAF_AUDIO_DECODER) += pafaudio.o OBJS-$(CONFIG_PAF_VIDEO_DECODER) += pafvideo.o OBJS-$(CONFIG_PAM_DECODER) += pnmdec.o pnm.o diff --git a/libavcodec/opus.c b/libavcodec/opus.c index a24c38be52..8def5e6e34 100644 --- a/libavcodec/opus.c +++ b/libavcodec/opus.c @@ -21,9 +21,45 @@ #include +#include "config_components.h" #include "opus_celt.h" #include "opus_pvq.h" #include "opustab.h" +#include "opus_rc.h" +#include "opusdec_rc.h" +#include "opusenc_rc.h" + +#if !CONFIG_OPUS_ENCODER +#define ff_opus_rc_enc_log(...) +#define ff_opus_rc_enc_cdf(...) +#define ff_opus_rc_enc_uint(...) +#endif + +#if !CONFIG_OPUS_DECODER +#define ff_opus_rc_dec_log(...) 0 +#define ff_opus_rc_dec_cdf(...) 0 +#define ff_opus_rc_dec_uint(...) 0 +#endif + +static inline void opus_rc_enc_log(OpusRangeCoder *rc, int val, uint32_t bits) +{ + ff_opus_rc_enc_log((OpusEncRangeCoder*)rc, val, bits); +} + +static inline uint32_t opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits) +{ + return ff_opus_rc_dec_log((OpusDecRangeCoder*)rc, bits); +} + +static inline void opus_rc_enc_cdf(OpusRangeCoder *rc, int val, const uint16_t *cdf) +{ + ff_opus_rc_enc_cdf((OpusEncRangeCoder*)rc, val, cdf); +} + +static inline uint32_t opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf) +{ + return ff_opus_rc_dec_cdf((OpusDecRangeCoder*)rc, cdf); +} void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc) { @@ -150,12 +186,14 @@ void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode) int bits1[CELT_MAX_BANDS]; int bits2[CELT_MAX_BANDS]; + if (!CONFIG_OPUS_DECODER || !CONFIG_OPUS_ENCODER) + encode = CONFIG_OPUS_ENCODER; /* Spread */ if (opus_rc_tell(rc) + 4 <= f->framebits) { if (encode) - ff_opus_rc_enc_cdf(rc, f->spread, ff_celt_model_spread); + opus_rc_enc_cdf(rc, f->spread, ff_celt_model_spread); else - f->spread = ff_opus_rc_dec_cdf(rc, ff_celt_model_spread); + f->spread = opus_rc_dec_cdf(rc, ff_celt_model_spread); } else { f->spread = CELT_SPREAD_NORMAL; } @@ -176,9 +214,9 @@ void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode) int is_boost; if (encode) { is_boost = boost_amount--; - ff_opus_rc_enc_log(rc, is_boost, b_dynalloc); + opus_rc_enc_log(rc, is_boost, b_dynalloc); } else { - is_boost = ff_opus_rc_dec_log(rc, b_dynalloc); + is_boost = opus_rc_dec_log(rc, b_dynalloc); } if (!is_boost) @@ -199,9 +237,9 @@ void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode) f->alloc_trim = 5; if (opus_rc_tell_frac(rc) + (6 << 3) <= tbits_8ths) if (encode) - ff_opus_rc_enc_cdf(rc, f->alloc_trim, ff_celt_model_alloc_trim); + opus_rc_enc_cdf(rc, f->alloc_trim, ff_celt_model_alloc_trim); else - f->alloc_trim = ff_opus_rc_dec_cdf(rc, ff_celt_model_alloc_trim); + f->alloc_trim = opus_rc_dec_cdf(rc, ff_celt_model_alloc_trim); /* Anti-collapse bit reservation */ tbits_8ths = (f->framebits << 3) - opus_rc_tell_frac(rc) - 1; @@ -358,9 +396,9 @@ void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode) int do_not_skip; if (encode) { do_not_skip = f->coded_bands <= f->skip_band_floor; - ff_opus_rc_enc_log(rc, do_not_skip, 1); + opus_rc_enc_log(rc, do_not_skip, 1); } else { - do_not_skip = ff_opus_rc_dec_log(rc, 1); + do_not_skip = opus_rc_dec_log(rc, 1); } if (do_not_skip) @@ -385,12 +423,12 @@ void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode) if (encode) { if (intensitystereo_bit) { f->intensity_stereo = FFMIN(f->intensity_stereo, f->coded_bands); - ff_opus_rc_enc_uint(rc, f->intensity_stereo, f->coded_bands + 1 - f->start_band); + ff_opus_rc_enc_uint((OpusEncRangeCoder*)rc, f->intensity_stereo, f->coded_bands + 1 - f->start_band); } } else { f->intensity_stereo = f->dual_stereo = 0; if (intensitystereo_bit) - f->intensity_stereo = f->start_band + ff_opus_rc_dec_uint(rc, f->coded_bands + 1 - f->start_band); + f->intensity_stereo = f->start_band + ff_opus_rc_dec_uint((OpusDecRangeCoder*)rc, f->coded_bands + 1 - f->start_band); } /* DS flag */ @@ -398,9 +436,9 @@ void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode) tbits_8ths += dualstereo_bit; /* no intensity stereo means no dual stereo */ else if (dualstereo_bit) if (encode) - ff_opus_rc_enc_log(rc, f->dual_stereo, 1); + opus_rc_enc_log(rc, f->dual_stereo, 1); else - f->dual_stereo = ff_opus_rc_dec_log(rc, 1); + f->dual_stereo = opus_rc_dec_log(rc, 1); /* Supply the remaining bits in this frame to lower bands */ remaining = tbits_8ths - total; diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c index c2904cc9e0..a14764ec18 100644 --- a/libavcodec/opus_celt.c +++ b/libavcodec/opus_celt.c @@ -28,12 +28,13 @@ #include #include "opus_celt.h" +#include "opusdec_rc.h" #include "opustab.h" #include "opus_pvq.h" /* Use the 2D z-transform to apply prediction in both the time domain (alpha) * and the frequency domain (beta) */ -static void celt_decode_coarse_energy(CeltFrame *f, OpusRangeCoder *rc) +static void celt_decode_coarse_energy(CeltFrame *f, OpusDecRangeCoder *rc) { int i, j; float prev[2] = { 0 }; @@ -42,7 +43,7 @@ static void celt_decode_coarse_energy(CeltFrame *f, OpusRangeCoder *rc) const uint8_t *model = ff_celt_coarse_energy_dist[f->size][0]; /* intra frame */ - if (opus_rc_tell(rc) + 3 <= f->framebits && ff_opus_rc_dec_log(rc, 3)) { + if (opus_rc_tell(&rc->c) + 3 <= f->framebits && ff_opus_rc_dec_log(rc, 3)) { alpha = 0.0f; beta = 1.0f - (4915.0f/32768.0f); model = ff_celt_coarse_energy_dist[f->size][1]; @@ -59,7 +60,7 @@ static void celt_decode_coarse_energy(CeltFrame *f, OpusRangeCoder *rc) continue; } - available = f->framebits - opus_rc_tell(rc); + available = f->framebits - opus_rc_tell(&rc->c); if (available >= 15) { /* decode using a Laplace distribution */ int k = FFMIN(i, 20) << 1; @@ -77,7 +78,7 @@ static void celt_decode_coarse_energy(CeltFrame *f, OpusRangeCoder *rc) } } -static void celt_decode_fine_energy(CeltFrame *f, OpusRangeCoder *rc) +static void celt_decode_fine_energy(CeltFrame *f, OpusDecRangeCoder *rc) { int i; for (i = f->start_band; i < f->end_band; i++) { @@ -96,10 +97,10 @@ static void celt_decode_fine_energy(CeltFrame *f, OpusRangeCoder *rc) } } -static void celt_decode_final_energy(CeltFrame *f, OpusRangeCoder *rc) +static void celt_decode_final_energy(CeltFrame *f, OpusDecRangeCoder *rc) { int priority, i, j; - int bits_left = f->framebits - opus_rc_tell(rc); + int bits_left = f->framebits - opus_rc_tell(&rc->c); for (priority = 0; priority < 2; priority++) { for (i = f->start_band; i < f->end_band && bits_left >= f->channels; i++) { @@ -118,18 +119,18 @@ static void celt_decode_final_energy(CeltFrame *f, OpusRangeCoder *rc) } } -static void celt_decode_tf_changes(CeltFrame *f, OpusRangeCoder *rc) +static void celt_decode_tf_changes(CeltFrame *f, OpusDecRangeCoder *rc) { int i, diff = 0, tf_select = 0, tf_changed = 0, tf_select_bit; int consumed, bits = f->transient ? 2 : 4; - consumed = opus_rc_tell(rc); + consumed = opus_rc_tell(&rc->c); tf_select_bit = (f->size != 0 && consumed+bits+1 <= f->framebits); for (i = f->start_band; i < f->end_band; i++) { if (consumed+bits+tf_select_bit <= f->framebits) { diff ^= ff_opus_rc_dec_log(rc, bits); - consumed = opus_rc_tell(rc); + consumed = opus_rc_tell(&rc->c); tf_changed |= diff; } f->tf_change[i] = diff; @@ -232,7 +233,7 @@ static void celt_postfilter(CeltFrame *f, CeltBlock *block) memmove(block->buf, block->buf + len, (1024 + CELT_OVERLAP / 2) * sizeof(float)); } -static int parse_postfilter(CeltFrame *f, OpusRangeCoder *rc, int consumed) +static int parse_postfilter(CeltFrame *f, OpusDecRangeCoder *rc, int consumed) { int i; @@ -248,7 +249,7 @@ static int parse_postfilter(CeltFrame *f, OpusRangeCoder *rc, int consumed) octave = ff_opus_rc_dec_uint(rc, 6); period = (16 << octave) + ff_opus_rc_get_raw(rc, 4 + octave) - 1; gain = 0.09375f * (ff_opus_rc_get_raw(rc, 3) + 1); - tapset = (opus_rc_tell(rc) + 2 <= f->framebits) ? + tapset = (opus_rc_tell(&rc->c) + 2 <= f->framebits) ? ff_opus_rc_dec_cdf(rc, ff_celt_model_tapset) : 0; for (i = 0; i < 2; i++) { @@ -261,7 +262,7 @@ static int parse_postfilter(CeltFrame *f, OpusRangeCoder *rc, int consumed) } } - consumed = opus_rc_tell(rc); + consumed = opus_rc_tell(&rc->c); } return consumed; @@ -319,7 +320,7 @@ static void process_anticollapse(CeltFrame *f, CeltBlock *block, float *X) } } -int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, +int ff_celt_decode_frame(CeltFrame *f, OpusDecRangeCoder *rc, float **output, int channels, int frame_size, int start_band, int end_band) { @@ -346,7 +347,7 @@ int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, f->channels = channels; f->start_band = start_band; f->end_band = end_band; - f->framebits = rc->rb.bytes * 8; + f->framebits = rc->c.rb.bytes * 8; f->size = av_log2(frame_size / CELT_SHORT_BLOCKSIZE); if (f->size > CELT_MAX_LOG_BLOCKS || @@ -364,7 +365,7 @@ int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, memset(f->block[i].collapse_masks, 0, sizeof(f->block[i].collapse_masks)); } - consumed = opus_rc_tell(rc); + consumed = opus_rc_tell(&rc->c); /* obtain silence flag */ if (consumed >= f->framebits) @@ -375,7 +376,7 @@ int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, if (f->silence) { consumed = f->framebits; - rc->total_bits += f->framebits - opus_rc_tell(rc); + rc->c.total_bits += f->framebits - opus_rc_tell(&rc->c); } /* obtain post-filter options */ @@ -398,9 +399,9 @@ int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, celt_decode_coarse_energy(f, rc); celt_decode_tf_changes (f, rc); - ff_celt_bitalloc (f, rc, 0); + ff_celt_bitalloc (f, &rc->c, 0); celt_decode_fine_energy (f, rc); - ff_celt_quant_bands (f, rc); + ff_celt_quant_bands (f, &rc->c); if (f->anticollapse_needed) f->anticollapse = ff_opus_rc_get_raw(rc, 1); @@ -486,7 +487,7 @@ int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, } } - f->seed = rc->range; + f->seed = rc->c.range; return 0; } diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h index 2dbb79be6c..beb6abd55d 100644 --- a/libavcodec/opus_celt.h +++ b/libavcodec/opus_celt.h @@ -171,7 +171,8 @@ void ff_celt_free(CeltFrame **f); void ff_celt_flush(CeltFrame *f); -int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, +struct OpusDecRangeCoder; +int ff_celt_decode_frame(CeltFrame *f, struct OpusDecRangeCoder *rc, float **output, int coded_channels, int frame_size, int startband, int endband); /* Encode or decode CELT bands */ diff --git a/libavcodec/opus_pvq.c b/libavcodec/opus_pvq.c index d08dcd7413..8ef0f85a81 100644 --- a/libavcodec/opus_pvq.c +++ b/libavcodec/opus_pvq.c @@ -30,6 +30,9 @@ #include "mathops.h" #include "opustab.h" #include "opus_pvq.h" +#include "opus_rc.h" +#include "opusdec_rc.h" +#include "opusenc_rc.h" #define ROUND_MUL16(a,b) ((MUL16(a, b) + 16384) >> 15) @@ -355,18 +358,12 @@ static inline uint64_t celt_cwrsi(uint32_t N, uint32_t K, uint32_t i, int *y) return norm; } -static inline void celt_encode_pulses(OpusRangeCoder *rc, int *y, uint32_t N, uint32_t K) +#if CONFIG_OPUS_ENCODER +static inline void celt_encode_pulses(OpusEncRangeCoder *rc, int *y, uint32_t N, uint32_t K) { ff_opus_rc_enc_uint(rc, celt_icwrsi(N, K, y), CELT_PVQ_V(N, K)); } -static inline float celt_decode_pulses(OpusRangeCoder *rc, int *y, uint32_t N, uint32_t K) -{ - const uint32_t idx = ff_opus_rc_dec_uint(rc, CELT_PVQ_V(N, K)); - return celt_cwrsi(N, K, idx, y); -} - -#if CONFIG_OPUS_ENCODER /* * Faster than libopus's search, operates entirely in the signed domain. * Slightly worse/better depending on N, K and the input vector. @@ -419,9 +416,8 @@ static float ppp_pvq_search_c(float *X, int *y, int K, int N) return (float)y_norm; } -#endif -static uint32_t celt_alg_quant(OpusRangeCoder *rc, float *X, uint32_t N, uint32_t K, +static uint32_t celt_alg_quant(OpusEncRangeCoder *rc, float *X, uint32_t N, uint32_t K, enum CeltSpread spread, uint32_t blocks, float gain, CeltPVQ *pvq) { @@ -434,10 +430,18 @@ static uint32_t celt_alg_quant(OpusRangeCoder *rc, float *X, uint32_t N, uint32_ celt_exp_rotation(X, N, blocks, K, spread, 0); return celt_extract_collapse_mask(y, N, blocks); } +#endif + +#if CONFIG_OPUS_DECODER +static inline float celt_decode_pulses(OpusDecRangeCoder *rc, int *y, uint32_t N, uint32_t K) +{ + const uint32_t idx = ff_opus_rc_dec_uint(rc, CELT_PVQ_V(N, K)); + return celt_cwrsi(N, K, idx, y); +} /** Decode pulse vector and combine the result with the pitch vector to produce the final normalised signal in the current band. */ -static uint32_t celt_alg_unquant(OpusRangeCoder *rc, float *X, uint32_t N, uint32_t K, +static uint32_t celt_alg_unquant(OpusDecRangeCoder *rc, float *X, uint32_t N, uint32_t K, enum CeltSpread spread, uint32_t blocks, float gain, CeltPVQ *pvq) { @@ -448,6 +452,7 @@ static uint32_t celt_alg_unquant(OpusRangeCoder *rc, float *X, uint32_t N, uint3 celt_exp_rotation(X, N, blocks, K, spread, 0); return celt_extract_collapse_mask(y, N, blocks); } +#endif static int celt_calc_theta(const float *X, const float *Y, int coupling, int N) { @@ -467,6 +472,7 @@ static int celt_calc_theta(const float *X, const float *Y, int coupling, int N) return lrintf(32768.0f*atan2f(sqrtf(e[1]), sqrtf(e[0]))/M_PI); } +#if CONFIG_OPUS_ENCODER static void celt_stereo_is_decouple(float *X, float *Y, float e_l, float e_r, int N) { int i; @@ -487,421 +493,15 @@ static void celt_stereo_ms_decouple(float *X, float *Y, int N) } } -static av_always_inline uint32_t quant_band_template(CeltPVQ *pvq, CeltFrame *f, - OpusRangeCoder *rc, - const int band, float *X, - float *Y, int N, int b, - uint32_t blocks, float *lowband, - int duration, float *lowband_out, - int level, float gain, - float *lowband_scratch, - int fill, int quant) -{ - int i; - const uint8_t *cache; - int stereo = !!Y, split = stereo; - int imid = 0, iside = 0; - uint32_t N0 = N; - int N_B = N / blocks; - int N_B0 = N_B; - int B0 = blocks; - int time_divide = 0; - int recombine = 0; - int inv = 0; - float mid = 0, side = 0; - int longblocks = (B0 == 1); - uint32_t cm = 0; - - if (N == 1) { - float *x = X; - for (i = 0; i <= stereo; i++) { - int sign = 0; - if (f->remaining2 >= 1 << 3) { - if (quant) { - sign = x[0] < 0; - ff_opus_rc_put_raw(rc, sign, 1); - } else { - sign = ff_opus_rc_get_raw(rc, 1); - } - f->remaining2 -= 1 << 3; - } - x[0] = 1.0f - 2.0f*sign; - x = Y; - } - if (lowband_out) - lowband_out[0] = X[0]; - return 1; - } - - if (!stereo && level == 0) { - int tf_change = f->tf_change[band]; - int k; - if (tf_change > 0) - recombine = tf_change; - /* Band recombining to increase frequency resolution */ - - if (lowband && - (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) { - for (i = 0; i < N; i++) - lowband_scratch[i] = lowband[i]; - lowband = lowband_scratch; - } - - for (k = 0; k < recombine; k++) { - if (quant || lowband) - celt_haar1(quant ? X : lowband, N >> k, 1 << k); - fill = ff_celt_bit_interleave[fill & 0xF] | ff_celt_bit_interleave[fill >> 4] << 2; - } - blocks >>= recombine; - N_B <<= recombine; - - /* Increasing the time resolution */ - while ((N_B & 1) == 0 && tf_change < 0) { - if (quant || lowband) - celt_haar1(quant ? X : lowband, N_B, blocks); - fill |= fill << blocks; - blocks <<= 1; - N_B >>= 1; - time_divide++; - tf_change++; - } - B0 = blocks; - N_B0 = N_B; - - /* Reorganize the samples in time order instead of frequency order */ - if (B0 > 1 && (quant || lowband)) - celt_deinterleave_hadamard(pvq->hadamard_tmp, quant ? X : lowband, - N_B >> recombine, B0 << recombine, - longblocks); - } - - /* If we need 1.5 more bit than we can produce, split the band in two. */ - cache = ff_celt_cache_bits + - ff_celt_cache_index[(duration + 1) * CELT_MAX_BANDS + band]; - if (!stereo && duration >= 0 && b > cache[cache[0]] + 12 && N > 2) { - N >>= 1; - Y = X + N; - split = 1; - duration -= 1; - if (blocks == 1) - fill = (fill & 1) | (fill << 1); - blocks = (blocks + 1) >> 1; - } - - if (split) { - int qn; - int itheta = quant ? celt_calc_theta(X, Y, stereo, N) : 0; - int mbits, sbits, delta; - int qalloc; - int pulse_cap; - int offset; - int orig_fill; - int tell; - - /* Decide on the resolution to give to the split parameter theta */ - pulse_cap = ff_celt_log_freq_range[band] + duration * 8; - offset = (pulse_cap >> 1) - (stereo && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE : - CELT_QTHETA_OFFSET); - qn = (stereo && band >= f->intensity_stereo) ? 1 : - celt_compute_qn(N, b, offset, pulse_cap, stereo); - tell = opus_rc_tell_frac(rc); - if (qn != 1) { - if (quant) - itheta = (itheta*qn + 8192) >> 14; - /* Entropy coding of the angle. We use a uniform pdf for the - * time split, a step for stereo, and a triangular one for the rest. */ - if (quant) { - if (stereo && N > 2) - ff_opus_rc_enc_uint_step(rc, itheta, qn / 2); - else if (stereo || B0 > 1) - ff_opus_rc_enc_uint(rc, itheta, qn + 1); - else - ff_opus_rc_enc_uint_tri(rc, itheta, qn); - itheta = itheta * 16384 / qn; - if (stereo) { - if (itheta == 0) - celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], - f->block[1].lin_energy[band], N); - else - celt_stereo_ms_decouple(X, Y, N); - } - } else { - if (stereo && N > 2) - itheta = ff_opus_rc_dec_uint_step(rc, qn / 2); - else if (stereo || B0 > 1) - itheta = ff_opus_rc_dec_uint(rc, qn+1); - else - itheta = ff_opus_rc_dec_uint_tri(rc, qn); - itheta = itheta * 16384 / qn; - } - } else if (stereo) { - if (quant) { - inv = f->apply_phase_inv ? itheta > 8192 : 0; - if (inv) { - for (i = 0; i < N; i++) - Y[i] *= -1; - } - celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], - f->block[1].lin_energy[band], N); - - if (b > 2 << 3 && f->remaining2 > 2 << 3) { - ff_opus_rc_enc_log(rc, inv, 2); - } else { - inv = 0; - } - } else { - inv = (b > 2 << 3 && f->remaining2 > 2 << 3) ? ff_opus_rc_dec_log(rc, 2) : 0; - inv = f->apply_phase_inv ? inv : 0; - } - itheta = 0; - } - qalloc = opus_rc_tell_frac(rc) - tell; - b -= qalloc; - - orig_fill = fill; - if (itheta == 0) { - imid = 32767; - iside = 0; - fill = av_mod_uintp2(fill, blocks); - delta = -16384; - } else if (itheta == 16384) { - imid = 0; - iside = 32767; - fill &= ((1 << blocks) - 1) << blocks; - delta = 16384; - } else { - imid = celt_cos(itheta); - iside = celt_cos(16384-itheta); - /* This is the mid vs side allocation that minimizes squared error - in that band. */ - delta = ROUND_MUL16((N - 1) << 7, celt_log2tan(iside, imid)); - } - - mid = imid / 32768.0f; - side = iside / 32768.0f; - - /* This is a special case for N=2 that only works for stereo and takes - advantage of the fact that mid and side are orthogonal to encode - the side with just one bit. */ - if (N == 2 && stereo) { - int c; - int sign = 0; - float tmp; - float *x2, *y2; - mbits = b; - /* Only need one bit for the side */ - sbits = (itheta != 0 && itheta != 16384) ? 1 << 3 : 0; - mbits -= sbits; - c = (itheta > 8192); - f->remaining2 -= qalloc+sbits; - - x2 = c ? Y : X; - y2 = c ? X : Y; - if (sbits) { - if (quant) { - sign = x2[0]*y2[1] - x2[1]*y2[0] < 0; - ff_opus_rc_put_raw(rc, sign, 1); - } else { - sign = ff_opus_rc_get_raw(rc, 1); - } - } - sign = 1 - 2 * sign; - /* We use orig_fill here because we want to fold the side, but if - itheta==16384, we'll have cleared the low bits of fill. */ - cm = pvq->quant_band(pvq, f, rc, band, x2, NULL, N, mbits, blocks, lowband, duration, - lowband_out, level, gain, lowband_scratch, orig_fill); - /* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse), - and there's no need to worry about mixing with the other channel. */ - y2[0] = -sign * x2[1]; - y2[1] = sign * x2[0]; - X[0] *= mid; - X[1] *= mid; - Y[0] *= side; - Y[1] *= side; - tmp = X[0]; - X[0] = tmp - Y[0]; - Y[0] = tmp + Y[0]; - tmp = X[1]; - X[1] = tmp - Y[1]; - Y[1] = tmp + Y[1]; - } else { - /* "Normal" split code */ - float *next_lowband2 = NULL; - float *next_lowband_out1 = NULL; - int next_level = 0; - int rebalance; - uint32_t cmt; - - /* Give more bits to low-energy MDCTs than they would - * otherwise deserve */ - if (B0 > 1 && !stereo && (itheta & 0x3fff)) { - if (itheta > 8192) - /* Rough approximation for pre-echo masking */ - delta -= delta >> (4 - duration); - else - /* Corresponds to a forward-masking slope of - * 1.5 dB per 10 ms */ - delta = FFMIN(0, delta + (N << 3 >> (5 - duration))); - } - mbits = av_clip((b - delta) / 2, 0, b); - sbits = b - mbits; - f->remaining2 -= qalloc; - - if (lowband && !stereo) - next_lowband2 = lowband + N; /* >32-bit split case */ - - /* Only stereo needs to pass on lowband_out. - * Otherwise, it's handled at the end */ - if (stereo) - next_lowband_out1 = lowband_out; - else - next_level = level + 1; - - rebalance = f->remaining2; - if (mbits >= sbits) { - /* In stereo mode, we do not apply a scaling to the mid - * because we need the normalized mid for folding later */ - cm = pvq->quant_band(pvq, f, rc, band, X, NULL, N, mbits, blocks, - lowband, duration, next_lowband_out1, next_level, - stereo ? 1.0f : (gain * mid), lowband_scratch, fill); - rebalance = mbits - (rebalance - f->remaining2); - if (rebalance > 3 << 3 && itheta != 0) - sbits += rebalance - (3 << 3); - - /* For a stereo split, the high bits of fill are always zero, - * so no folding will be done to the side. */ - cmt = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks, - next_lowband2, duration, NULL, next_level, - gain * side, NULL, fill >> blocks); - cm |= cmt << ((B0 >> 1) & (stereo - 1)); - } else { - /* For a stereo split, the high bits of fill are always zero, - * so no folding will be done to the side. */ - cm = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks, - next_lowband2, duration, NULL, next_level, - gain * side, NULL, fill >> blocks); - cm <<= ((B0 >> 1) & (stereo - 1)); - rebalance = sbits - (rebalance - f->remaining2); - if (rebalance > 3 << 3 && itheta != 16384) - mbits += rebalance - (3 << 3); - - /* In stereo mode, we do not apply a scaling to the mid because - * we need the normalized mid for folding later */ - cm |= pvq->quant_band(pvq, f, rc, band, X, NULL, N, mbits, blocks, - lowband, duration, next_lowband_out1, next_level, - stereo ? 1.0f : (gain * mid), lowband_scratch, fill); - } - } - } else { - /* This is the basic no-split case */ - uint32_t q = celt_bits2pulses(cache, b); - uint32_t curr_bits = celt_pulses2bits(cache, q); - f->remaining2 -= curr_bits; - - /* Ensures we can never bust the budget */ - while (f->remaining2 < 0 && q > 0) { - f->remaining2 += curr_bits; - curr_bits = celt_pulses2bits(cache, --q); - f->remaining2 -= curr_bits; - } - - if (q != 0) { - /* Finally do the actual (de)quantization */ - if (quant) { - cm = celt_alg_quant(rc, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1), - f->spread, blocks, gain, pvq); - } else { - cm = celt_alg_unquant(rc, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1), - f->spread, blocks, gain, pvq); - } - } else { - /* If there's no pulse, fill the band anyway */ - uint32_t cm_mask = (1 << blocks) - 1; - fill &= cm_mask; - if (fill) { - if (!lowband) { - /* Noise */ - for (i = 0; i < N; i++) - X[i] = (((int32_t)celt_rng(f)) >> 20); - cm = cm_mask; - } else { - /* Folded spectrum */ - for (i = 0; i < N; i++) { - /* About 48 dB below the "normal" folding level */ - X[i] = lowband[i] + (((celt_rng(f)) & 0x8000) ? 1.0f / 256 : -1.0f / 256); - } - cm = fill; - } - celt_renormalize_vector(X, N, gain); - } else { - memset(X, 0, N*sizeof(float)); - } - } - } - - /* This code is used by the decoder and by the resynthesis-enabled encoder */ - if (stereo) { - if (N > 2) - celt_stereo_merge(X, Y, mid, N); - if (inv) { - for (i = 0; i < N; i++) - Y[i] *= -1; - } - } else if (level == 0) { - int k; - - /* Undo the sample reorganization going from time order to frequency order */ - if (B0 > 1) - celt_interleave_hadamard(pvq->hadamard_tmp, X, N_B >> recombine, - B0 << recombine, longblocks); - - /* Undo time-freq changes that we did earlier */ - N_B = N_B0; - blocks = B0; - for (k = 0; k < time_divide; k++) { - blocks >>= 1; - N_B <<= 1; - cm |= cm >> blocks; - celt_haar1(X, N_B, blocks); - } - - for (k = 0; k < recombine; k++) { - cm = ff_celt_bit_deinterleave[cm]; - celt_haar1(X, N0>>k, 1<quant_band = encode ? pvq_encode_band : pvq_decode_band; - #if CONFIG_OPUS_ENCODER +#if CONFIG_OPUS_DECODER + s->quant_band = encode ? pvq_quant_band_enc : pvq_quant_band_dec; +#else + s->quant_band = pvq_quant_band_enc; +#endif s->pvq_search = ppp_pvq_search_c; #if ARCH_X86 ff_celt_pvq_init_x86(s); #endif +#else + s->quant_band = pvq_quant_band_dec; + s->pvq_search = NULL; #endif *pvq = s; diff --git a/libavcodec/opus_pvq_template.c b/libavcodec/opus_pvq_template.c new file mode 100644 index 0000000000..5f03f3d415 --- /dev/null +++ b/libavcodec/opus_pvq_template.c @@ -0,0 +1,432 @@ +/* + * Copyright (c) 2007-2008 CSIRO + * Copyright (c) 2007-2009 Xiph.Org Foundation + * Copyright (c) 2008-2009 Gregory Maxwell + * Copyright (c) 2012 Andrew D'Addesio + * Copyright (c) 2013-2014 Mozilla Corporation + * Copyright (c) 2017 Rostislav Pehlivanov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#undef FUNC + +#if ENCODING +#define FUNC(name) name ## _enc +#else +#define FUNC(name) name ## _dec +#endif + +static +uint32_t FUNC(pvq_quant_band)(CeltPVQ *const pvq, CeltFrame *const f, + OpusRangeCoder *const rc, + const int band, float *X, + float *Y, int N, int b, + uint32_t blocks, float *lowband, + int duration, float *lowband_out, + int level, float gain, + float *lowband_scratch, + int fill) +{ +#if ENCODING + OpusEncRangeCoder *const rce = (OpusEncRangeCoder*)rc; +#else + OpusDecRangeCoder *const rcd = (OpusDecRangeCoder*)rc; +#endif + const uint8_t *cache; + int stereo = !!Y, split = stereo; + uint32_t N0 = N; + int N_B = N / blocks; + int N_B0 = N_B; + int B0 = blocks; + int time_divide = 0; + int recombine = 0; + int inv = 0; + float mid = 0, side = 0; + int longblocks = (B0 == 1); + uint32_t cm = 0; + + if (N == 1) { + float *x = X; + for (int i = 0; i <= stereo; i++) { + int sign = 0; + if (f->remaining2 >= 1 << 3) { +#if ENCODING + sign = x[0] < 0; + ff_opus_rc_put_raw(rce, sign, 1); +#else + sign = ff_opus_rc_get_raw(rcd, 1); +#endif + f->remaining2 -= 1 << 3; + } + x[0] = 1.0f - 2.0f*sign; + x = Y; + } + if (lowband_out) + lowband_out[0] = X[0]; + return 1; + } + + if (!stereo && level == 0) { + int tf_change = f->tf_change[band]; + int k; + if (tf_change > 0) + recombine = tf_change; + /* Band recombining to increase frequency resolution */ + + if (lowband && + (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) { + for (int i = 0; i < N; i++) + lowband_scratch[i] = lowband[i]; + lowband = lowband_scratch; + } + + for (k = 0; k < recombine; k++) { + if (ENCODING || lowband) + celt_haar1(ENCODING ? X : lowband, N >> k, 1 << k); + fill = ff_celt_bit_interleave[fill & 0xF] | ff_celt_bit_interleave[fill >> 4] << 2; + } + blocks >>= recombine; + N_B <<= recombine; + + /* Increasing the time resolution */ + while ((N_B & 1) == 0 && tf_change < 0) { + if (ENCODING || lowband) + celt_haar1(ENCODING ? X : lowband, N_B, blocks); + fill |= fill << blocks; + blocks <<= 1; + N_B >>= 1; + time_divide++; + tf_change++; + } + B0 = blocks; + N_B0 = N_B; + + /* Reorganize the samples in time order instead of frequency order */ + if (B0 > 1 && (ENCODING || lowband)) + celt_deinterleave_hadamard(pvq->hadamard_tmp, ENCODING ? X : lowband, + N_B >> recombine, B0 << recombine, + longblocks); + } + + /* If we need 1.5 more bit than we can produce, split the band in two. */ + cache = ff_celt_cache_bits + + ff_celt_cache_index[(duration + 1) * CELT_MAX_BANDS + band]; + if (!stereo && duration >= 0 && b > cache[cache[0]] + 12 && N > 2) { + N >>= 1; + Y = X + N; + split = 1; + duration -= 1; + if (blocks == 1) + fill = (fill & 1) | (fill << 1); + blocks = (blocks + 1) >> 1; + } + + if (split) { + int qn; + int itheta = ENCODING ? celt_calc_theta(X, Y, stereo, N) : 0; + int mbits, sbits, delta; + int imid = 0, iside = 0; + int qalloc; + int pulse_cap; + int offset; + int orig_fill; + int tell; + + /* Decide on the resolution to give to the split parameter theta */ + pulse_cap = ff_celt_log_freq_range[band] + duration * 8; + offset = (pulse_cap >> 1) - (stereo && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE : + CELT_QTHETA_OFFSET); + qn = (stereo && band >= f->intensity_stereo) ? 1 : + celt_compute_qn(N, b, offset, pulse_cap, stereo); + tell = opus_rc_tell_frac(rc); + if (qn != 1) { +#if ENCODING + itheta = (itheta * qn + 8192) >> 14; + /* Entropy coding of the angle. We use a uniform pdf for the + * time split, a step for stereo, and a triangular one for the rest. */ + if (stereo && N > 2) + ff_opus_rc_enc_uint_step(rce, itheta, qn / 2); + else if (stereo || B0 > 1) + ff_opus_rc_enc_uint(rce, itheta, qn + 1); + else + ff_opus_rc_enc_uint_tri(rce, itheta, qn); + itheta = itheta * 16384 / qn; + if (stereo) { + if (itheta == 0) + celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], + f->block[1].lin_energy[band], N); + else + celt_stereo_ms_decouple(X, Y, N); + } +#else + if (stereo && N > 2) + itheta = ff_opus_rc_dec_uint_step(rcd, qn / 2); + else if (stereo || B0 > 1) + itheta = ff_opus_rc_dec_uint(rcd, qn+1); + else + itheta = ff_opus_rc_dec_uint_tri(rcd, qn); + itheta = itheta * 16384 / qn; +#endif + } else if (stereo) { +#if ENCODING + inv = f->apply_phase_inv ? itheta > 8192 : 0; + if (inv) { + for (int i = 0; i < N; i++) + Y[i] *= -1; + } + celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band], + f->block[1].lin_energy[band], N); + + if (b > 2 << 3 && f->remaining2 > 2 << 3) { + ff_opus_rc_enc_log(rce, inv, 2); + } else { + inv = 0; + } +#else + inv = (b > 2 << 3 && f->remaining2 > 2 << 3) ? ff_opus_rc_dec_log(rcd, 2) : 0; + inv = f->apply_phase_inv ? inv : 0; +#endif + itheta = 0; + } + qalloc = opus_rc_tell_frac(rc) - tell; + b -= qalloc; + + orig_fill = fill; + if (itheta == 0) { + imid = 32767; + iside = 0; + fill = av_mod_uintp2(fill, blocks); + delta = -16384; + } else if (itheta == 16384) { + imid = 0; + iside = 32767; + fill &= ((1 << blocks) - 1) << blocks; + delta = 16384; + } else { + imid = celt_cos(itheta); + iside = celt_cos(16384 - itheta); + /* This is the mid vs side allocation that minimizes squared error + in that band. */ + delta = ROUND_MUL16((N - 1) << 7, celt_log2tan(iside, imid)); + } + + mid = imid / 32768.0f; + side = iside / 32768.0f; + + /* This is a special case for N=2 that only works for stereo and takes + advantage of the fact that mid and side are orthogonal to encode + the side with just one bit. */ + if (N == 2 && stereo) { + int c; + int sign = 0; + float tmp; + float *x2, *y2; + mbits = b; + /* Only need one bit for the side */ + sbits = (itheta != 0 && itheta != 16384) ? 1 << 3 : 0; + mbits -= sbits; + c = (itheta > 8192); + f->remaining2 -= qalloc + sbits; + + x2 = c ? Y : X; + y2 = c ? X : Y; + if (sbits) { +#if ENCODING + sign = x2[0]*y2[1] - x2[1]*y2[0] < 0; + ff_opus_rc_put_raw(rce, sign, 1); +#else + sign = ff_opus_rc_get_raw(rcd, 1); +#endif + } + sign = 1 - 2 * sign; + /* We use orig_fill here because we want to fold the side, but if + itheta==16384, we'll have cleared the low bits of fill. */ + cm = pvq->quant_band(pvq, f, rc, band, x2, NULL, N, mbits, blocks, lowband, duration, + lowband_out, level, gain, lowband_scratch, orig_fill); + /* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse), + and there's no need to worry about mixing with the other channel. */ + y2[0] = -sign * x2[1]; + y2[1] = sign * x2[0]; + X[0] *= mid; + X[1] *= mid; + Y[0] *= side; + Y[1] *= side; + tmp = X[0]; + X[0] = tmp - Y[0]; + Y[0] = tmp + Y[0]; + tmp = X[1]; + X[1] = tmp - Y[1]; + Y[1] = tmp + Y[1]; + } else { + /* "Normal" split code */ + float *next_lowband2 = NULL; + float *next_lowband_out1 = NULL; + int next_level = 0; + int rebalance; + uint32_t cmt; + + /* Give more bits to low-energy MDCTs than they would + * otherwise deserve */ + if (B0 > 1 && !stereo && (itheta & 0x3fff)) { + if (itheta > 8192) + /* Rough approximation for pre-echo masking */ + delta -= delta >> (4 - duration); + else + /* Corresponds to a forward-masking slope of + * 1.5 dB per 10 ms */ + delta = FFMIN(0, delta + (N << 3 >> (5 - duration))); + } + mbits = av_clip((b - delta) / 2, 0, b); + sbits = b - mbits; + f->remaining2 -= qalloc; + + if (lowband && !stereo) + next_lowband2 = lowband + N; /* >32-bit split case */ + + /* Only stereo needs to pass on lowband_out. + * Otherwise, it's handled at the end */ + if (stereo) + next_lowband_out1 = lowband_out; + else + next_level = level + 1; + + rebalance = f->remaining2; + if (mbits >= sbits) { + /* In stereo mode, we do not apply a scaling to the mid + * because we need the normalized mid for folding later */ + cm = pvq->quant_band(pvq, f, rc, band, X, NULL, N, mbits, blocks, + lowband, duration, next_lowband_out1, next_level, + stereo ? 1.0f : (gain * mid), lowband_scratch, fill); + rebalance = mbits - (rebalance - f->remaining2); + if (rebalance > 3 << 3 && itheta != 0) + sbits += rebalance - (3 << 3); + + /* For a stereo split, the high bits of fill are always zero, + * so no folding will be done to the side. */ + cmt = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks, + next_lowband2, duration, NULL, next_level, + gain * side, NULL, fill >> blocks); + cm |= cmt << ((B0 >> 1) & (stereo - 1)); + } else { + /* For a stereo split, the high bits of fill are always zero, + * so no folding will be done to the side. */ + cm = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks, + next_lowband2, duration, NULL, next_level, + gain * side, NULL, fill >> blocks); + cm <<= ((B0 >> 1) & (stereo - 1)); + rebalance = sbits - (rebalance - f->remaining2); + if (rebalance > 3 << 3 && itheta != 16384) + mbits += rebalance - (3 << 3); + + /* In stereo mode, we do not apply a scaling to the mid because + * we need the normalized mid for folding later */ + cm |= pvq->quant_band(pvq, f, rc, band, X, NULL, N, mbits, blocks, + lowband, duration, next_lowband_out1, next_level, + stereo ? 1.0f : (gain * mid), lowband_scratch, fill); + } + } + } else { + /* This is the basic no-split case */ + uint32_t q = celt_bits2pulses(cache, b); + uint32_t curr_bits = celt_pulses2bits(cache, q); + f->remaining2 -= curr_bits; + + /* Ensures we can never bust the budget */ + while (f->remaining2 < 0 && q > 0) { + f->remaining2 += curr_bits; + curr_bits = celt_pulses2bits(cache, --q); + f->remaining2 -= curr_bits; + } + + if (q != 0) { + /* Finally do the actual (de)quantization */ +#if ENCODING + cm = celt_alg_quant(rce, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1), + f->spread, blocks, gain, pvq); +#else + cm = celt_alg_unquant(rcd, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1), + f->spread, blocks, gain, pvq); +#endif + } else { + /* If there's no pulse, fill the band anyway */ + uint32_t cm_mask = (1 << blocks) - 1; + fill &= cm_mask; + if (fill) { + if (!lowband) { + /* Noise */ + for (int i = 0; i < N; i++) + X[i] = (((int32_t)celt_rng(f)) >> 20); + cm = cm_mask; + } else { + /* Folded spectrum */ + for (int i = 0; i < N; i++) { + /* About 48 dB below the "normal" folding level */ + X[i] = lowband[i] + (((celt_rng(f)) & 0x8000) ? 1.0f / 256 : -1.0f / 256); + } + cm = fill; + } + celt_renormalize_vector(X, N, gain); + } else { + memset(X, 0, N*sizeof(float)); + } + } + } + + /* This code is used by the decoder and by the resynthesis-enabled encoder */ + if (stereo) { + if (N > 2) + celt_stereo_merge(X, Y, mid, N); + if (inv) { + for (int i = 0; i < N; i++) + Y[i] *= -1; + } + } else if (level == 0) { + int k; + + /* Undo the sample reorganization going from time order to frequency order */ + if (B0 > 1) + celt_interleave_hadamard(pvq->hadamard_tmp, X, N_B >> recombine, + B0 << recombine, longblocks); + + /* Undo time-freq changes that we did earlier */ + N_B = N_B0; + blocks = B0; + for (k = 0; k < time_divide; k++) { + blocks >>= 1; + N_B <<= 1; + cm |= cm >> blocks; + celt_haar1(X, N_B, blocks); + } + + for (k = 0; k < recombine; k++) { + cm = ff_celt_bit_deinterleave[cm]; + celt_haar1(X, N0>>k, 1< - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "opus_rc.h" - -#define OPUS_RC_BITS 32 -#define OPUS_RC_SYM 8 -#define OPUS_RC_CEIL ((1 << OPUS_RC_SYM) - 1) -#define OPUS_RC_TOP (1u << 31) -#define OPUS_RC_BOT (OPUS_RC_TOP >> OPUS_RC_SYM) -#define OPUS_RC_SHIFT (OPUS_RC_BITS - OPUS_RC_SYM - 1) - -static av_always_inline void opus_rc_enc_carryout(OpusRangeCoder *rc, int cbuf) -{ - const int cb = cbuf >> OPUS_RC_SYM, mb = (OPUS_RC_CEIL + cb) & OPUS_RC_CEIL; - if (cbuf == OPUS_RC_CEIL) { - rc->ext++; - return; - } - rc->rng_cur[0] = rc->rem + cb; - rc->rng_cur += (rc->rem >= 0); - for (; rc->ext > 0; rc->ext--) - *rc->rng_cur++ = mb; - av_assert0(rc->rng_cur < rc->rb.position); - rc->rem = cbuf & OPUS_RC_CEIL; /* Propagate */ -} - -static av_always_inline void opus_rc_dec_normalize(OpusRangeCoder *rc) -{ - while (rc->range <= OPUS_RC_BOT) { - rc->value = ((rc->value << OPUS_RC_SYM) | (get_bits(&rc->gb, OPUS_RC_SYM) ^ OPUS_RC_CEIL)) & (OPUS_RC_TOP - 1); - rc->range <<= OPUS_RC_SYM; - rc->total_bits += OPUS_RC_SYM; - } -} - -static av_always_inline void opus_rc_enc_normalize(OpusRangeCoder *rc) -{ - while (rc->range <= OPUS_RC_BOT) { - opus_rc_enc_carryout(rc, rc->value >> OPUS_RC_SHIFT); - rc->value = (rc->value << OPUS_RC_SYM) & (OPUS_RC_TOP - 1); - rc->range <<= OPUS_RC_SYM; - rc->total_bits += OPUS_RC_SYM; - } -} - -static av_always_inline void opus_rc_dec_update(OpusRangeCoder *rc, uint32_t scale, - uint32_t low, uint32_t high, - uint32_t total) -{ - rc->value -= scale * (total - high); - rc->range = low ? scale * (high - low) - : rc->range - scale * (total - high); - opus_rc_dec_normalize(rc); -} - -/* Main encoding function, this needs to go fast */ -static av_always_inline void opus_rc_enc_update(OpusRangeCoder *rc, uint32_t b, uint32_t p, - uint32_t p_tot, const int ptwo) -{ - uint32_t rscaled, cnd = !!b; - if (ptwo) /* Whole function is inlined so hopefully branch is optimized out */ - rscaled = rc->range >> ff_log2(p_tot); - else - rscaled = rc->range/p_tot; - rc->value += cnd*(rc->range - rscaled*(p_tot - b)); - rc->range = (!cnd)*(rc->range - rscaled*(p_tot - p)) + cnd*rscaled*(p - b); - opus_rc_enc_normalize(rc); -} - -uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf) -{ - unsigned int k, scale, total, symbol, low, high; - - total = *cdf++; - - scale = rc->range / total; - symbol = rc->value / scale + 1; - symbol = total - FFMIN(symbol, total); - - for (k = 0; cdf[k] <= symbol; k++); - high = cdf[k]; - low = k ? cdf[k-1] : 0; - - opus_rc_dec_update(rc, scale, low, high, total); - - return k; -} - -void ff_opus_rc_enc_cdf(OpusRangeCoder *rc, int val, const uint16_t *cdf) -{ - opus_rc_enc_update(rc, (!!val)*cdf[val], cdf[val + 1], cdf[0], 1); -} - -uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits) -{ - uint32_t k, scale; - scale = rc->range >> bits; // in this case, scale = symbol - - if (rc->value >= scale) { - rc->value -= scale; - rc->range -= scale; - k = 0; - } else { - rc->range = scale; - k = 1; - } - opus_rc_dec_normalize(rc); - return k; -} - -void ff_opus_rc_enc_log(OpusRangeCoder *rc, int val, uint32_t bits) -{ - bits = (1 << bits) - 1; - opus_rc_enc_update(rc, (!!val)*bits, bits + !!val, bits + 1, 1); -} - -/** - * CELT: read 1-25 raw bits at the end of the frame, backwards byte-wise - */ -uint32_t ff_opus_rc_get_raw(OpusRangeCoder *rc, uint32_t count) -{ - uint32_t value = 0; - - while (rc->rb.bytes && rc->rb.cachelen < count) { - rc->rb.cacheval |= *--rc->rb.position << rc->rb.cachelen; - rc->rb.cachelen += 8; - rc->rb.bytes--; - } - - value = av_mod_uintp2(rc->rb.cacheval, count); - rc->rb.cacheval >>= count; - rc->rb.cachelen -= count; - rc->total_bits += count; - - return value; -} - -/** - * CELT: write 0 - 31 bits to the rawbits buffer - */ -void ff_opus_rc_put_raw(OpusRangeCoder *rc, uint32_t val, uint32_t count) -{ - const int to_write = FFMIN(32 - rc->rb.cachelen, count); - - rc->total_bits += count; - rc->rb.cacheval |= av_mod_uintp2(val, to_write) << rc->rb.cachelen; - rc->rb.cachelen = (rc->rb.cachelen + to_write) % 32; - - if (!rc->rb.cachelen && count) { - AV_WB32((uint8_t *)rc->rb.position, rc->rb.cacheval); - rc->rb.bytes += 4; - rc->rb.position -= 4; - rc->rb.cachelen = count - to_write; - rc->rb.cacheval = av_mod_uintp2(val >> to_write, rc->rb.cachelen); - av_assert0(rc->rng_cur < rc->rb.position); - } -} - -/** - * CELT: read a uniform distribution - */ -uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size) -{ - uint32_t bits, k, scale, total; - - bits = opus_ilog(size - 1); - total = (bits > 8) ? ((size - 1) >> (bits - 8)) + 1 : size; - - scale = rc->range / total; - k = rc->value / scale + 1; - k = total - FFMIN(k, total); - opus_rc_dec_update(rc, scale, k, k + 1, total); - - if (bits > 8) { - k = k << (bits - 8) | ff_opus_rc_get_raw(rc, bits - 8); - return FFMIN(k, size - 1); - } else - return k; -} - -/** - * CELT: write a uniformly distributed integer - */ -void ff_opus_rc_enc_uint(OpusRangeCoder *rc, uint32_t val, uint32_t size) -{ - const int ps = FFMAX(opus_ilog(size - 1) - 8, 0); - opus_rc_enc_update(rc, val >> ps, (val >> ps) + 1, ((size - 1) >> ps) + 1, 0); - ff_opus_rc_put_raw(rc, val, ps); -} - -uint32_t ff_opus_rc_dec_uint_step(OpusRangeCoder *rc, int k0) -{ - /* Use a probability of 3 up to itheta=8192 and then use 1 after */ - uint32_t k, scale, symbol, total = (k0+1)*3 + k0; - scale = rc->range / total; - symbol = rc->value / scale + 1; - symbol = total - FFMIN(symbol, total); - - k = (symbol < (k0+1)*3) ? symbol/3 : symbol - (k0+1)*2; - - opus_rc_dec_update(rc, scale, (k <= k0) ? 3*(k+0) : (k-1-k0) + 3*(k0+1), - (k <= k0) ? 3*(k+1) : (k-0-k0) + 3*(k0+1), total); - return k; -} - -void ff_opus_rc_enc_uint_step(OpusRangeCoder *rc, uint32_t val, int k0) -{ - const uint32_t a = val <= k0, b = 2*a + 1; - k0 = (k0 + 1) << 1; - val = b*(val + k0) - 3*a*k0; - opus_rc_enc_update(rc, val, val + b, (k0 << 1) - 1, 0); -} - -uint32_t ff_opus_rc_dec_uint_tri(OpusRangeCoder *rc, int qn) -{ - uint32_t k, scale, symbol, total, low, center; - - total = ((qn>>1) + 1) * ((qn>>1) + 1); - scale = rc->range / total; - center = rc->value / scale + 1; - center = total - FFMIN(center, total); - - if (center < total >> 1) { - k = (ff_sqrt(8 * center + 1) - 1) >> 1; - low = k * (k + 1) >> 1; - symbol = k + 1; - } else { - k = (2*(qn + 1) - ff_sqrt(8*(total - center - 1) + 1)) >> 1; - low = total - ((qn + 1 - k) * (qn + 2 - k) >> 1); - symbol = qn + 1 - k; - } - - opus_rc_dec_update(rc, scale, low, low + symbol, total); - - return k; -} - -void ff_opus_rc_enc_uint_tri(OpusRangeCoder *rc, uint32_t k, int qn) -{ - uint32_t symbol, low, total; - - total = ((qn>>1) + 1) * ((qn>>1) + 1); - - if (k <= qn >> 1) { - low = k * (k + 1) >> 1; - symbol = k + 1; - } else { - low = total - ((qn + 1 - k) * (qn + 2 - k) >> 1); - symbol = qn + 1 - k; - } - - opus_rc_enc_update(rc, low, low + symbol, total, 0); -} - -int ff_opus_rc_dec_laplace(OpusRangeCoder *rc, uint32_t symbol, int decay) -{ - /* extends the range coder to model a Laplace distribution */ - int value = 0; - uint32_t scale, low = 0, center; - - scale = rc->range >> 15; - center = rc->value / scale + 1; - center = (1 << 15) - FFMIN(center, 1 << 15); - - if (center >= symbol) { - value++; - low = symbol; - symbol = 1 + ((32768 - 32 - symbol) * (16384-decay) >> 15); - - while (symbol > 1 && center >= low + 2 * symbol) { - value++; - symbol *= 2; - low += symbol; - symbol = (((symbol - 2) * decay) >> 15) + 1; - } - - if (symbol <= 1) { - int distance = (center - low) >> 1; - value += distance; - low += 2 * distance; - } - - if (center < low + symbol) - value *= -1; - else - low += symbol; - } - - opus_rc_dec_update(rc, scale, low, FFMIN(low + symbol, 32768), 32768); - - return value; -} - -void ff_opus_rc_enc_laplace(OpusRangeCoder *rc, int *value, uint32_t symbol, int decay) -{ - uint32_t low = symbol; - int i = 1, val = FFABS(*value), pos = *value > 0; - if (!val) { - opus_rc_enc_update(rc, 0, symbol, 1 << 15, 1); - return; - } - symbol = ((32768 - 32 - symbol)*(16384 - decay)) >> 15; - for (; i < val && symbol; i++) { - low += (symbol << 1) + 2; - symbol = (symbol*decay) >> 14; - } - if (symbol) { - low += (++symbol)*pos; - } else { - const int distance = FFMIN(val - i, (((32768 - low) - !pos) >> 1) - 1); - low += pos + (distance << 1); - symbol = FFMIN(1, 32768 - low); - *value = FFSIGN(*value)*(distance + i); - } - opus_rc_enc_update(rc, low, low + symbol, 1 << 15, 1); -} - -int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size) -{ - int ret = init_get_bits8(&rc->gb, data, size); - if (ret < 0) - return ret; - - rc->range = 128; - rc->value = 127 - get_bits(&rc->gb, 7); - rc->total_bits = 9; - opus_rc_dec_normalize(rc); - - return 0; -} - -void ff_opus_rc_dec_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, uint32_t bytes) -{ - rc->rb.position = rightend; - rc->rb.bytes = bytes; - rc->rb.cachelen = 0; - rc->rb.cacheval = 0; -} - -void ff_opus_rc_enc_end(OpusRangeCoder *rc, uint8_t *dst, int size) -{ - int rng_bytes, bits = OPUS_RC_BITS - opus_ilog(rc->range); - uint32_t mask = (OPUS_RC_TOP - 1) >> bits; - uint32_t end = (rc->value + mask) & ~mask; - - if ((end | mask) >= rc->value + rc->range) { - bits++; - mask >>= 1; - end = (rc->value + mask) & ~mask; - } - - /* Finish what's left */ - while (bits > 0) { - opus_rc_enc_carryout(rc, end >> OPUS_RC_SHIFT); - end = (end << OPUS_RC_SYM) & (OPUS_RC_TOP - 1); - bits -= OPUS_RC_SYM; - } - - /* Flush out anything left or marked */ - if (rc->rem >= 0 || rc->ext > 0) - opus_rc_enc_carryout(rc, 0); - - rng_bytes = rc->rng_cur - rc->buf; - memcpy(dst, rc->buf, rng_bytes); - - /* Put the rawbits part, if any */ - if (rc->rb.bytes || rc->rb.cachelen) { - int i, lap; - uint8_t *rb_src, *rb_dst; - ff_opus_rc_put_raw(rc, 0, 32 - rc->rb.cachelen); - rb_src = rc->buf + OPUS_MAX_FRAME_SIZE + 12 - rc->rb.bytes; - rb_dst = dst + FFMAX(size - rc->rb.bytes, 0); - lap = &dst[rng_bytes] - rb_dst; - for (i = 0; i < lap; i++) - rb_dst[i] |= rb_src[i]; - memcpy(&rb_dst[lap], &rb_src[lap], FFMAX(rc->rb.bytes - lap, 0)); - } -} - -void ff_opus_rc_enc_init(OpusRangeCoder *rc) -{ - rc->value = 0; - rc->range = OPUS_RC_TOP; - rc->total_bits = OPUS_RC_BITS + 1; - rc->rem = -1; - rc->ext = 0; - rc->rng_cur = rc->buf; - ff_opus_rc_dec_raw_init(rc, rc->buf + OPUS_MAX_FRAME_SIZE + 8, 0); -} diff --git a/libavcodec/opus_rc.h b/libavcodec/opus_rc.h index 72e683b075..332f3fa883 100644 --- a/libavcodec/opus_rc.h +++ b/libavcodec/opus_rc.h @@ -24,11 +24,16 @@ #define AVCODEC_OPUS_RC_H #include -#include "get_bits.h" -#include "opus.h" + +#include "libavutil/common.h" #define opus_ilog(i) (av_log2(i) + !!(i)) +#define OPUS_RC_SYM 8 +#define OPUS_RC_CEIL ((1 << OPUS_RC_SYM) - 1) +#define OPUS_RC_TOP (1u << 31) +#define OPUS_RC_BOT (OPUS_RC_TOP >> OPUS_RC_SYM) + typedef struct RawBitsContext { const uint8_t *position; uint32_t bytes; @@ -37,19 +42,21 @@ typedef struct RawBitsContext { } RawBitsContext; typedef struct OpusRangeCoder { - GetBitContext gb; RawBitsContext rb; uint32_t range; uint32_t value; uint32_t total_bits; - - /* Encoder */ - uint8_t buf[OPUS_MAX_FRAME_SIZE + 12]; /* memcpy vs (memmove + overreading) */ - uint8_t *rng_cur; /* Current range coded byte */ - int ext; /* Awaiting propagation */ - int rem; /* Carryout flag */ } OpusRangeCoder; +static inline void ff_opus_rc_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, + uint32_t bytes) +{ + rc->rb.position = rightend; + rc->rb.bytes = bytes; + rc->rb.cachelen = 0; + rc->rb.cacheval = 0; +} + /** * CELT: estimate bits of entropy that have thus far been consumed for the * current CELT frame, to integer and fractional (1/8th bit) precision @@ -78,45 +85,4 @@ static av_always_inline uint32_t opus_rc_tell_frac(const OpusRangeCoder *rc) return total_bits - rcbuffer; } -uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf); -void ff_opus_rc_enc_cdf(OpusRangeCoder *rc, int val, const uint16_t *cdf); - -uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits); -void ff_opus_rc_enc_log(OpusRangeCoder *rc, int val, uint32_t bits); - -uint32_t ff_opus_rc_dec_uint_step(OpusRangeCoder *rc, int k0); -void ff_opus_rc_enc_uint_step(OpusRangeCoder *rc, uint32_t val, int k0); - -uint32_t ff_opus_rc_dec_uint_tri(OpusRangeCoder *rc, int qn); -void ff_opus_rc_enc_uint_tri(OpusRangeCoder *rc, uint32_t k, int qn); - -uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size); -void ff_opus_rc_enc_uint(OpusRangeCoder *rc, uint32_t val, uint32_t size); - -uint32_t ff_opus_rc_get_raw(OpusRangeCoder *rc, uint32_t count); -void ff_opus_rc_put_raw(OpusRangeCoder *rc, uint32_t val, uint32_t count); - -int ff_opus_rc_dec_laplace(OpusRangeCoder *rc, uint32_t symbol, int decay); -void ff_opus_rc_enc_laplace(OpusRangeCoder *rc, int *value, uint32_t symbol, int decay); - -int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size); -void ff_opus_rc_dec_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, uint32_t bytes); - -void ff_opus_rc_enc_end(OpusRangeCoder *rc, uint8_t *dst, int size); -void ff_opus_rc_enc_init(OpusRangeCoder *rc); - -#define OPUS_RC_CHECKPOINT_UPDATE(rc) \ - rc_rollback_bits = opus_rc_tell_frac(rc); \ - rc_rollback_ctx = *rc - -#define OPUS_RC_CHECKPOINT_SPAWN(rc) \ - uint32_t rc_rollback_bits = opus_rc_tell_frac(rc); \ - OpusRangeCoder rc_rollback_ctx = *rc \ - -#define OPUS_RC_CHECKPOINT_BITS(rc) \ - (opus_rc_tell_frac(rc) - rc_rollback_bits) - -#define OPUS_RC_CHECKPOINT_ROLLBACK(rc) \ - memcpy(rc, &rc_rollback_ctx, sizeof(OpusRangeCoder)); \ - #endif /* AVCODEC_OPUS_RC_H */ diff --git a/libavcodec/opus_silk.c b/libavcodec/opus_silk.c index cf8b16acff..99696e26d2 100644 --- a/libavcodec/opus_silk.c +++ b/libavcodec/opus_silk.c @@ -29,6 +29,7 @@ #include "mathops.h" #include "opus.h" #include "opus_rc.h" +#include "opusdec_rc.h" #include "opus_silk.h" #include "opustab.h" @@ -308,7 +309,7 @@ static void silk_lsf2lpc(const int16_t nlsf[16], float lpcf[16], int order) } static inline void silk_decode_lpc(SilkContext *s, SilkFrame *frame, - OpusRangeCoder *rc, + OpusDecRangeCoder *rc, float lpc_leadin[16], float lpc[16], int *lpc_order, int *has_lpc_leadin, int voiced) { @@ -404,7 +405,7 @@ static inline void silk_decode_lpc(SilkContext *s, SilkFrame *frame, memcpy(frame->lpc, lpc, order * sizeof(lpc[0])); } -static inline void silk_count_children(OpusRangeCoder *rc, int model, int32_t total, +static inline void silk_count_children(OpusDecRangeCoder *rc, int model, int32_t total, int32_t child[2]) { if (total != 0) { @@ -417,7 +418,7 @@ static inline void silk_count_children(OpusRangeCoder *rc, int model, int32_t to } } -static inline void silk_decode_excitation(SilkContext *s, OpusRangeCoder *rc, +static inline void silk_decode_excitation(SilkContext *s, OpusDecRangeCoder *rc, float* excitationf, int qoffset_high, int active, int voiced) { @@ -511,7 +512,7 @@ static inline void silk_decode_excitation(SilkContext *s, OpusRangeCoder *rc, /** Order of the LTP filter */ #define LTP_ORDER 5 -static void silk_decode_frame(SilkContext *s, OpusRangeCoder *rc, +static void silk_decode_frame(SilkContext *s, OpusDecRangeCoder *rc, int frame_num, int channel, int coded_channels, int active, int active1, int redundant) { @@ -788,7 +789,7 @@ static void silk_flush_frame(SilkFrame *frame) frame->coded = 0; } -int ff_silk_decode_superframe(SilkContext *s, OpusRangeCoder *rc, +int ff_silk_decode_superframe(SilkContext *s, OpusDecRangeCoder *rc, float *output[2], enum OpusBandwidth bandwidth, int coded_channels, diff --git a/libavcodec/opus_silk.h b/libavcodec/opus_silk.h index 6552c166a4..cd6920920e 100644 --- a/libavcodec/opus_silk.h +++ b/libavcodec/opus_silk.h @@ -25,7 +25,7 @@ #include "avcodec.h" #include "opus.h" -#include "opus_rc.h" +#include "opusdec_rc.h" #define SILK_HISTORY 322 #define SILK_MAX_LPC 16 @@ -40,7 +40,7 @@ void ff_silk_flush(SilkContext *s); * Decode the LP layer of one Opus frame (which may correspond to several SILK * frames). */ -int ff_silk_decode_superframe(SilkContext *s, OpusRangeCoder *rc, +int ff_silk_decode_superframe(SilkContext *s, OpusDecRangeCoder *rc, float *output[2], enum OpusBandwidth bandwidth, int coded_channels, int duration_ms); diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c index c5f06e0600..468bc6ddff 100644 --- a/libavcodec/opusdec.c +++ b/libavcodec/opusdec.c @@ -54,6 +54,7 @@ #include "opus_celt.h" #include "opus_parse.h" #include "opus_rc.h" +#include "opusdec_rc.h" #include "opus_silk.h" static const uint16_t silk_frame_duration_ms[16] = { @@ -83,8 +84,8 @@ typedef struct OpusStreamContext { * the streams when they have different resampling delays */ AVAudioFifo *sync_buffer; - OpusRangeCoder rc; - OpusRangeCoder redundancy_rc; + OpusDecRangeCoder rc; + OpusDecRangeCoder redundancy_rc; SilkContext *silk; CeltFrame *celt; AVFloatDSPContext *fdsp; @@ -218,7 +219,7 @@ static int opus_decode_redundancy(OpusStreamContext *s, const uint8_t *data, int int ret = ff_opus_rc_dec_init(&s->redundancy_rc, data, size); if (ret < 0) goto fail; - ff_opus_rc_dec_raw_init(&s->redundancy_rc, data + size, size); + ff_opus_rc_raw_init(&s->redundancy_rc.c, data + size, size); ret = ff_celt_decode_frame(s->celt, &s->redundancy_rc, s->redundancy_output, @@ -274,7 +275,7 @@ static int opus_decode_frame(OpusStreamContext *s, const uint8_t *data, int size ff_silk_flush(s->silk); // decode redundancy information - consumed = opus_rc_tell(&s->rc); + consumed = opus_rc_tell(&s->rc.c); if (s->packet.mode == OPUS_MODE_HYBRID && consumed + 37 <= size * 8) redundancy = ff_opus_rc_dec_log(&s->rc, 12); else if (s->packet.mode == OPUS_MODE_SILK && consumed + 17 <= size * 8) @@ -328,7 +329,7 @@ static int opus_decode_frame(OpusStreamContext *s, const uint8_t *data, int size } } - ff_opus_rc_dec_raw_init(&s->rc, data + size, size); + ff_opus_rc_raw_init(&s->rc.c, data + size, size); ret = ff_celt_decode_frame(s->celt, &s->rc, dst, s->packet.stereo + 1, diff --git a/libavcodec/opusdec_rc.c b/libavcodec/opusdec_rc.c new file mode 100644 index 0000000000..fb2bce0b72 --- /dev/null +++ b/libavcodec/opusdec_rc.c @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2012 Andrew D'Addesio + * Copyright (c) 2013-2014 Mozilla Corporation + * Copyright (c) 2017 Rostislav Pehlivanov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "opus_rc.h" +#include "opusdec_rc.h" + +static av_always_inline void opus_rc_dec_normalize(OpusDecRangeCoder *rc) +{ + while (rc->c.range <= OPUS_RC_BOT) { + rc->c.value = ((rc->c.value << OPUS_RC_SYM) | (get_bits(&rc->gb, OPUS_RC_SYM) ^ OPUS_RC_CEIL)) & (OPUS_RC_TOP - 1); + rc->c.range <<= OPUS_RC_SYM; + rc->c.total_bits += OPUS_RC_SYM; + } +} + +static av_always_inline void opus_rc_dec_update(OpusDecRangeCoder *rc, uint32_t scale, + uint32_t low, uint32_t high, + uint32_t total) +{ + rc->c.value -= scale * (total - high); + rc->c.range = low ? scale * (high - low) + : rc->c.range - scale * (total - high); + opus_rc_dec_normalize(rc); +} + +uint32_t ff_opus_rc_dec_cdf(OpusDecRangeCoder *rc, const uint16_t *cdf) +{ + unsigned int k, scale, total, symbol, low, high; + + total = *cdf++; + + scale = rc->c.range / total; + symbol = rc->c.value / scale + 1; + symbol = total - FFMIN(symbol, total); + + for (k = 0; cdf[k] <= symbol; k++); + high = cdf[k]; + low = k ? cdf[k-1] : 0; + + opus_rc_dec_update(rc, scale, low, high, total); + + return k; +} + +uint32_t ff_opus_rc_dec_log(OpusDecRangeCoder *rc, uint32_t bits) +{ + uint32_t k, scale; + scale = rc->c.range >> bits; // in this case, scale = symbol + + if (rc->c.value >= scale) { + rc->c.value -= scale; + rc->c.range -= scale; + k = 0; + } else { + rc->c.range = scale; + k = 1; + } + opus_rc_dec_normalize(rc); + return k; +} + +/** + * CELT: read 1-25 raw bits at the end of the frame, backwards byte-wise + */ +uint32_t ff_opus_rc_get_raw(OpusDecRangeCoder *rc, uint32_t count) +{ + uint32_t value = 0; + + while (rc->c.rb.bytes && rc->c.rb.cachelen < count) { + rc->c.rb.cacheval |= *--rc->c.rb.position << rc->c.rb.cachelen; + rc->c.rb.cachelen += 8; + rc->c.rb.bytes--; + } + + value = av_mod_uintp2(rc->c.rb.cacheval, count); + rc->c.rb.cacheval >>= count; + rc->c.rb.cachelen -= count; + rc->c.total_bits += count; + + return value; +} + +/** + * CELT: read a uniform distribution + */ +uint32_t ff_opus_rc_dec_uint(OpusDecRangeCoder *rc, uint32_t size) +{ + uint32_t bits, k, scale, total; + + bits = opus_ilog(size - 1); + total = (bits > 8) ? ((size - 1) >> (bits - 8)) + 1 : size; + + scale = rc->c.range / total; + k = rc->c.value / scale + 1; + k = total - FFMIN(k, total); + opus_rc_dec_update(rc, scale, k, k + 1, total); + + if (bits > 8) { + k = k << (bits - 8) | ff_opus_rc_get_raw(rc, bits - 8); + return FFMIN(k, size - 1); + } else + return k; +} + +uint32_t ff_opus_rc_dec_uint_step(OpusDecRangeCoder *rc, int k0) +{ + /* Use a probability of 3 up to itheta=8192 and then use 1 after */ + uint32_t k, scale, symbol, total = (k0+1)*3 + k0; + scale = rc->c.range / total; + symbol = rc->c.value / scale + 1; + symbol = total - FFMIN(symbol, total); + + k = (symbol < (k0+1)*3) ? symbol/3 : symbol - (k0+1)*2; + + opus_rc_dec_update(rc, scale, (k <= k0) ? 3*(k+0) : (k-1-k0) + 3*(k0+1), + (k <= k0) ? 3*(k+1) : (k-0-k0) + 3*(k0+1), total); + return k; +} + +uint32_t ff_opus_rc_dec_uint_tri(OpusDecRangeCoder *rc, int qn) +{ + uint32_t k, scale, symbol, total, low, center; + + total = ((qn>>1) + 1) * ((qn>>1) + 1); + scale = rc->c.range / total; + center = rc->c.value / scale + 1; + center = total - FFMIN(center, total); + + if (center < total >> 1) { + k = (ff_sqrt(8 * center + 1) - 1) >> 1; + low = k * (k + 1) >> 1; + symbol = k + 1; + } else { + k = (2*(qn + 1) - ff_sqrt(8*(total - center - 1) + 1)) >> 1; + low = total - ((qn + 1 - k) * (qn + 2 - k) >> 1); + symbol = qn + 1 - k; + } + + opus_rc_dec_update(rc, scale, low, low + symbol, total); + + return k; +} + +int ff_opus_rc_dec_laplace(OpusDecRangeCoder *rc, uint32_t symbol, int decay) +{ + /* extends the range coder to model a Laplace distribution */ + int value = 0; + uint32_t scale, low = 0, center; + + scale = rc->c.range >> 15; + center = rc->c.value / scale + 1; + center = (1 << 15) - FFMIN(center, 1 << 15); + + if (center >= symbol) { + value++; + low = symbol; + symbol = 1 + ((32768 - 32 - symbol) * (16384-decay) >> 15); + + while (symbol > 1 && center >= low + 2 * symbol) { + value++; + symbol *= 2; + low += symbol; + symbol = (((symbol - 2) * decay) >> 15) + 1; + } + + if (symbol <= 1) { + int distance = (center - low) >> 1; + value += distance; + low += 2 * distance; + } + + if (center < low + symbol) + value *= -1; + else + low += symbol; + } + + opus_rc_dec_update(rc, scale, low, FFMIN(low + symbol, 32768), 32768); + + return value; +} + +int ff_opus_rc_dec_init(OpusDecRangeCoder *rc, const uint8_t *data, int size) +{ + int ret = init_get_bits8(&rc->gb, data, size); + if (ret < 0) + return ret; + + rc->c.range = 128; + rc->c.value = 127 - get_bits(&rc->gb, 7); + rc->c.total_bits = 9; + opus_rc_dec_normalize(rc); + + return 0; +} diff --git a/libavcodec/opusdec_rc.h b/libavcodec/opusdec_rc.h new file mode 100644 index 0000000000..96889e3d7f --- /dev/null +++ b/libavcodec/opusdec_rc.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2012 Andrew D'Addesio + * Copyright (c) 2013-2014 Mozilla Corporation + * Copyright (c) 2017 Rostislav Pehlivanov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_OPUSDEC_RC_H +#define AVCODEC_OPUSDEC_RC_H + +#include + +#include "get_bits.h" +#include "opus_rc.h" + +typedef struct OpusDecRangeCoder { + OpusRangeCoder c; + + GetBitContext gb; +} OpusDecRangeCoder; + +uint32_t ff_opus_rc_dec_cdf(OpusDecRangeCoder *rc, const uint16_t *cdf); + +uint32_t ff_opus_rc_dec_log(OpusDecRangeCoder *rc, uint32_t bits); + +uint32_t ff_opus_rc_dec_uint_step(OpusDecRangeCoder *rc, int k0); + +uint32_t ff_opus_rc_dec_uint_tri(OpusDecRangeCoder *rc, int qn); + +uint32_t ff_opus_rc_dec_uint(OpusDecRangeCoder *rc, uint32_t size); + +uint32_t ff_opus_rc_get_raw(OpusDecRangeCoder *rc, uint32_t count); + +int ff_opus_rc_dec_laplace(OpusDecRangeCoder *rc, uint32_t symbol, int decay); + +int ff_opus_rc_dec_init(OpusDecRangeCoder *rc, const uint8_t *data, int size); + +#endif /* AVCODEC_OPUSDEC_RC_H */ diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c index 280425c74f..f1283827b7 100644 --- a/libavcodec/opusenc.c +++ b/libavcodec/opusenc.c @@ -25,6 +25,7 @@ #include "opusenc.h" #include "opus_pvq.h" #include "opusenc_psy.h" +#include "opusenc_rc.h" #include "opustab.h" #include "libavutil/channel_layout.h" @@ -55,7 +56,7 @@ typedef struct OpusEncContext { int channels; CeltFrame *frame; - OpusRangeCoder *rc; + OpusEncRangeCoder *rc; /* Actual energy the decoder will have */ float last_quantized_energy[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; @@ -258,15 +259,15 @@ static void celt_frame_mdct(OpusEncContext *s, CeltFrame *f) } } -static void celt_enc_tf(CeltFrame *f, OpusRangeCoder *rc) +static void celt_enc_tf(CeltFrame *f, OpusEncRangeCoder *rc) { int tf_select = 0, diff = 0, tf_changed = 0, tf_select_needed; int bits = f->transient ? 2 : 4; - tf_select_needed = ((f->size && (opus_rc_tell(rc) + bits + 1) <= f->framebits)); + tf_select_needed = ((f->size && (opus_rc_tell(&rc->c) + bits + 1) <= f->framebits)); for (int i = f->start_band; i < f->end_band; i++) { - if ((opus_rc_tell(rc) + bits + tf_select_needed) <= f->framebits) { + if ((opus_rc_tell(&rc->c) + bits + tf_select_needed) <= f->framebits) { const int tbit = (diff ^ 1) == f->tf_change[i]; ff_opus_rc_enc_log(rc, tbit, bits); diff ^= tbit; @@ -285,7 +286,7 @@ static void celt_enc_tf(CeltFrame *f, OpusRangeCoder *rc) f->tf_change[i] = ff_celt_tf_select[f->size][f->transient][tf_select][f->tf_change[i]]; } -static void celt_enc_quant_pfilter(OpusRangeCoder *rc, CeltFrame *f) +static void celt_enc_quant_pfilter(OpusEncRangeCoder *rc, CeltFrame *f) { float gain = f->pf_gain; int txval, octave = f->pf_octave, period = f->pf_period, tapset = f->pf_tapset; @@ -307,7 +308,7 @@ static void celt_enc_quant_pfilter(OpusRangeCoder *rc, CeltFrame *f) ff_opus_rc_put_raw(rc, txval, 3); gain = 0.09375f * (txval + 1); /* Tapset */ - if ((opus_rc_tell(rc) + 2) <= f->framebits) + if ((opus_rc_tell(&rc->c) + 2) <= f->framebits) ff_opus_rc_enc_cdf(rc, tapset, ff_celt_model_tapset); else tapset = 0; @@ -322,14 +323,14 @@ static void celt_enc_quant_pfilter(OpusRangeCoder *rc, CeltFrame *f) } } -static void exp_quant_coarse(OpusRangeCoder *rc, CeltFrame *f, +static void exp_quant_coarse(OpusEncRangeCoder *rc, CeltFrame *f, float last_energy[][CELT_MAX_BANDS], int intra) { float alpha, beta, prev[2] = { 0, 0 }; const uint8_t *pmod = ff_celt_coarse_energy_dist[f->size][intra]; /* Inter is really just differential coding */ - if (opus_rc_tell(rc) + 3 <= f->framebits) + if (opus_rc_tell(&rc->c) + 3 <= f->framebits) ff_opus_rc_enc_log(rc, intra, 3); else intra = 0; @@ -345,7 +346,7 @@ static void exp_quant_coarse(OpusRangeCoder *rc, CeltFrame *f, for (int i = f->start_band; i < f->end_band; i++) { for (int ch = 0; ch < f->channels; ch++) { CeltBlock *block = &f->block[ch]; - const int left = f->framebits - opus_rc_tell(rc); + const int left = f->framebits - opus_rc_tell(&rc->c); const float last = FFMAX(-9.0f, last_energy[ch][i]); float diff = block->energy[i] - prev[ch] - last*alpha; int q_en = lrintf(diff); @@ -365,7 +366,7 @@ static void exp_quant_coarse(OpusRangeCoder *rc, CeltFrame *f, } } -static void celt_quant_coarse(CeltFrame *f, OpusRangeCoder *rc, +static void celt_quant_coarse(CeltFrame *f, OpusEncRangeCoder *rc, float last_energy[][CELT_MAX_BANDS]) { uint32_t inter, intra; @@ -385,7 +386,7 @@ static void celt_quant_coarse(CeltFrame *f, OpusRangeCoder *rc, } } -static void celt_quant_fine(CeltFrame *f, OpusRangeCoder *rc) +static void celt_quant_fine(CeltFrame *f, OpusEncRangeCoder *rc) { for (int i = f->start_band; i < f->end_band; i++) { if (!f->fine_bits[i]) @@ -402,10 +403,10 @@ static void celt_quant_fine(CeltFrame *f, OpusRangeCoder *rc) } } -static void celt_quant_final(OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f) +static void celt_quant_final(OpusEncContext *s, OpusEncRangeCoder *rc, CeltFrame *f) { for (int priority = 0; priority < 2; priority++) { - for (int i = f->start_band; i < f->end_band && (f->framebits - opus_rc_tell(rc)) >= f->channels; i++) { + for (int i = f->start_band; i < f->end_band && (f->framebits - opus_rc_tell(&rc->c)) >= f->channels; i++) { if (f->fine_priority[i] != priority || f->fine_bits[i] >= CELT_MAX_FINE_BITS) continue; for (int ch = 0; ch < f->channels; ch++) { @@ -420,7 +421,7 @@ static void celt_quant_final(OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f } } -static void celt_encode_frame(OpusEncContext *s, OpusRangeCoder *rc, +static void celt_encode_frame(OpusEncContext *s, OpusEncRangeCoder *rc, CeltFrame *f, int index) { ff_opus_rc_enc_init(rc); @@ -457,19 +458,19 @@ static void celt_encode_frame(OpusEncContext *s, OpusRangeCoder *rc, ff_opus_rc_enc_log(rc, 0, 15); /* Pitch filter */ - if (!f->start_band && opus_rc_tell(rc) + 16 <= f->framebits) + if (!f->start_band && opus_rc_tell(&rc->c) + 16 <= f->framebits) celt_enc_quant_pfilter(rc, f); /* Transient flag */ - if (f->size && opus_rc_tell(rc) + 3 <= f->framebits) + if (f->size && opus_rc_tell(&rc->c) + 3 <= f->framebits) ff_opus_rc_enc_log(rc, f->transient, 3); /* Main encoding */ celt_quant_coarse (f, rc, s->last_quantized_energy); celt_enc_tf (f, rc); - ff_celt_bitalloc (f, rc, 1); + ff_celt_bitalloc (f, &rc->c, 1); celt_quant_fine (f, rc); - ff_celt_quant_bands(f, rc); + ff_celt_quant_bands(f, &rc->c); /* Anticollapse bit */ if (f->anticollapse_needed) @@ -694,7 +695,7 @@ static av_cold int opus_encode_init(AVCodecContext *avctx) s->frame = av_malloc(max_frames*sizeof(CeltFrame)); if (!s->frame) return AVERROR(ENOMEM); - s->rc = av_malloc(max_frames*sizeof(OpusRangeCoder)); + s->rc = av_malloc_array(max_frames, sizeof(*s->rc)); if (!s->rc) return AVERROR(ENOMEM); diff --git a/libavcodec/opusenc_psy.c b/libavcodec/opusenc_psy.c index 48ccd2ebd0..17a2efd8d5 100644 --- a/libavcodec/opusenc_psy.c +++ b/libavcodec/opusenc_psy.c @@ -22,12 +22,13 @@ #include #include "opusenc_psy.h" +#include "opusenc_rc.h" #include "opus_celt.h" #include "opus_pvq.h" #include "opustab.h" #include "libavfilter/window_func.h" -static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusRangeCoder *rc, int band, +static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusEncRangeCoder *rce, int band, float *bits, float lambda) { int i, b = 0; @@ -39,7 +40,8 @@ static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusRangeCoder *rc, int b float *X_orig = f->block[0].coeffs + (ff_celt_freq_bands[band] << f->size); float *Y = (f->channels == 2) ? &buf[176] : NULL; float *Y_orig = f->block[1].coeffs + (ff_celt_freq_bands[band] << f->size); - OPUS_RC_CHECKPOINT_SPAWN(rc); + OpusRangeCoder *const rc = &rce->c; + OPUS_RC_CHECKPOINT_SPAWN(rce); memcpy(X, X_orig, band_size*sizeof(float)); if (Y) @@ -69,10 +71,10 @@ static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusRangeCoder *rc, int b } dist = sqrtf(err_x) + sqrtf(err_y); - cost = OPUS_RC_CHECKPOINT_BITS(rc)/8.0f; + cost = OPUS_RC_CHECKPOINT_BITS(rce)/8.0f; *bits += cost; - OPUS_RC_CHECKPOINT_ROLLBACK(rc); + OPUS_RC_CHECKPOINT_ROLLBACK(rce); return lambda*dist*cost; } @@ -366,10 +368,10 @@ static void celt_gauge_psy_weight(OpusPsyContext *s, OpusPsyStep **start, static int bands_dist(OpusPsyContext *s, CeltFrame *f, float *total_dist) { int i, tdist = 0.0f; - OpusRangeCoder dump; + OpusEncRangeCoder dump; ff_opus_rc_enc_init(&dump); - ff_celt_bitalloc(f, &dump, 1); + ff_celt_bitalloc(f, &dump.c, 1); for (i = 0; i < CELT_MAX_BANDS; i++) { float bits = 0.0f; diff --git a/libavcodec/opusenc_psy.h b/libavcodec/opusenc_psy.h index bc1a88c03d..2d35e76d2c 100644 --- a/libavcodec/opusenc_psy.h +++ b/libavcodec/opusenc_psy.h @@ -26,6 +26,7 @@ #include "libavutil/mem_internal.h" #include "opusenc.h" +#include "opusenc_rc.h" #include "opus_celt.h" #include "opusenc_utils.h" diff --git a/libavcodec/opusenc_rc.c b/libavcodec/opusenc_rc.c new file mode 100644 index 0000000000..6c749c3a34 --- /dev/null +++ b/libavcodec/opusenc_rc.c @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2012 Andrew D'Addesio + * Copyright (c) 2013-2014 Mozilla Corporation + * Copyright (c) 2017 Rostislav Pehlivanov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/avassert.h" +#include "libavutil/intreadwrite.h" + +#include "opusenc_rc.h" + +#define OPUS_RC_BITS 32 +#define OPUS_RC_SHIFT (OPUS_RC_BITS - OPUS_RC_SYM - 1) + +static av_always_inline void opus_rc_enc_carryout(OpusEncRangeCoder *rc, int cbuf) +{ + const int cb = cbuf >> OPUS_RC_SYM, mb = (OPUS_RC_CEIL + cb) & OPUS_RC_CEIL; + if (cbuf == OPUS_RC_CEIL) { + rc->ext++; + return; + } + rc->rng_cur[0] = rc->rem + cb; + rc->rng_cur += (rc->rem >= 0); + for (; rc->ext > 0; rc->ext--) + *rc->rng_cur++ = mb; + av_assert0(rc->rng_cur < rc->c.rb.position); + rc->rem = cbuf & OPUS_RC_CEIL; /* Propagate */ +} + +static av_always_inline void opus_rc_enc_normalize(OpusEncRangeCoder *rc) +{ + while (rc->c.range <= OPUS_RC_BOT) { + opus_rc_enc_carryout(rc, rc->c.value >> OPUS_RC_SHIFT); + rc->c.value = (rc->c.value << OPUS_RC_SYM) & (OPUS_RC_TOP - 1); + rc->c.range <<= OPUS_RC_SYM; + rc->c.total_bits += OPUS_RC_SYM; + } +} + +/* Main encoding function, this needs to go fast */ +static av_always_inline void opus_rc_enc_update(OpusEncRangeCoder *rc, uint32_t b, uint32_t p, + uint32_t p_tot, const int ptwo) +{ + uint32_t rscaled, cnd = !!b; + if (ptwo) /* Whole function is inlined so hopefully branch is optimized out */ + rscaled = rc->c.range >> ff_log2(p_tot); + else + rscaled = rc->c.range/p_tot; + rc->c.value += cnd*(rc->c.range - rscaled*(p_tot - b)); + rc->c.range = (!cnd)*(rc->c.range - rscaled*(p_tot - p)) + cnd*rscaled*(p - b); + opus_rc_enc_normalize(rc); +} + +void ff_opus_rc_enc_cdf(OpusEncRangeCoder *rc, int val, const uint16_t *cdf) +{ + opus_rc_enc_update(rc, (!!val)*cdf[val], cdf[val + 1], cdf[0], 1); +} + +void ff_opus_rc_enc_log(OpusEncRangeCoder *rc, int val, uint32_t bits) +{ + bits = (1 << bits) - 1; + opus_rc_enc_update(rc, (!!val)*bits, bits + !!val, bits + 1, 1); +} + +/** + * CELT: write 0 - 31 bits to the rawbits buffer + */ +void ff_opus_rc_put_raw(OpusEncRangeCoder *rc, uint32_t val, uint32_t count) +{ + const int to_write = FFMIN(32 - rc->c.rb.cachelen, count); + + rc->c.total_bits += count; + rc->c.rb.cacheval |= av_mod_uintp2(val, to_write) << rc->c.rb.cachelen; + rc->c.rb.cachelen = (rc->c.rb.cachelen + to_write) % 32; + + if (!rc->c.rb.cachelen && count) { + AV_WB32((uint8_t *)rc->c.rb.position, rc->c.rb.cacheval); + rc->c.rb.bytes += 4; + rc->c.rb.position -= 4; + rc->c.rb.cachelen = count - to_write; + rc->c.rb.cacheval = av_mod_uintp2(val >> to_write, rc->c.rb.cachelen); + av_assert0(rc->rng_cur < rc->c.rb.position); + } +} + +/** + * CELT: write a uniformly distributed integer + */ +void ff_opus_rc_enc_uint(OpusEncRangeCoder *rc, uint32_t val, uint32_t size) +{ + const int ps = FFMAX(opus_ilog(size - 1) - 8, 0); + opus_rc_enc_update(rc, val >> ps, (val >> ps) + 1, ((size - 1) >> ps) + 1, 0); + ff_opus_rc_put_raw(rc, val, ps); +} + +void ff_opus_rc_enc_uint_step(OpusEncRangeCoder *rc, uint32_t val, int k0) +{ + const uint32_t a = val <= k0, b = 2*a + 1; + k0 = (k0 + 1) << 1; + val = b*(val + k0) - 3*a*k0; + opus_rc_enc_update(rc, val, val + b, (k0 << 1) - 1, 0); +} + +void ff_opus_rc_enc_uint_tri(OpusEncRangeCoder *rc, uint32_t k, int qn) +{ + uint32_t symbol, low, total; + + total = ((qn>>1) + 1) * ((qn>>1) + 1); + + if (k <= qn >> 1) { + low = k * (k + 1) >> 1; + symbol = k + 1; + } else { + low = total - ((qn + 1 - k) * (qn + 2 - k) >> 1); + symbol = qn + 1 - k; + } + + opus_rc_enc_update(rc, low, low + symbol, total, 0); +} + +void ff_opus_rc_enc_laplace(OpusEncRangeCoder *rc, int *value, uint32_t symbol, int decay) +{ + uint32_t low = symbol; + int i = 1, val = FFABS(*value), pos = *value > 0; + if (!val) { + opus_rc_enc_update(rc, 0, symbol, 1 << 15, 1); + return; + } + symbol = ((32768 - 32 - symbol)*(16384 - decay)) >> 15; + for (; i < val && symbol; i++) { + low += (symbol << 1) + 2; + symbol = (symbol*decay) >> 14; + } + if (symbol) { + low += (++symbol)*pos; + } else { + const int distance = FFMIN(val - i, (((32768 - low) - !pos) >> 1) - 1); + low += pos + (distance << 1); + symbol = FFMIN(1, 32768 - low); + *value = FFSIGN(*value)*(distance + i); + } + opus_rc_enc_update(rc, low, low + symbol, 1 << 15, 1); +} + +void ff_opus_rc_enc_end(OpusEncRangeCoder *rc, uint8_t *dst, int size) +{ + int rng_bytes, bits = OPUS_RC_BITS - opus_ilog(rc->c.range); + uint32_t mask = (OPUS_RC_TOP - 1) >> bits; + uint32_t end = (rc->c.value + mask) & ~mask; + + if ((end | mask) >= rc->c.value + rc->c.range) { + bits++; + mask >>= 1; + end = (rc->c.value + mask) & ~mask; + } + + /* Finish what's left */ + while (bits > 0) { + opus_rc_enc_carryout(rc, end >> OPUS_RC_SHIFT); + end = (end << OPUS_RC_SYM) & (OPUS_RC_TOP - 1); + bits -= OPUS_RC_SYM; + } + + /* Flush out anything left or marked */ + if (rc->rem >= 0 || rc->ext > 0) + opus_rc_enc_carryout(rc, 0); + + rng_bytes = rc->rng_cur - rc->buf; + memcpy(dst, rc->buf, rng_bytes); + + /* Put the rawbits part, if any */ + if (rc->c.rb.bytes || rc->c.rb.cachelen) { + int lap; + uint8_t *rb_src, *rb_dst; + ff_opus_rc_put_raw(rc, 0, 32 - rc->c.rb.cachelen); + rb_src = rc->buf + OPUS_MAX_FRAME_SIZE + 12 - rc->c.rb.bytes; + rb_dst = dst + FFMAX(size - rc->c.rb.bytes, 0); + lap = &dst[rng_bytes] - rb_dst; + for (int i = 0; i < lap; i++) + rb_dst[i] |= rb_src[i]; + memcpy(&rb_dst[lap], &rb_src[lap], FFMAX(rc->c.rb.bytes - lap, 0)); + } +} + +void ff_opus_rc_enc_init(OpusEncRangeCoder *rc) +{ + rc->c.value = 0; + rc->c.range = OPUS_RC_TOP; + rc->c.total_bits = OPUS_RC_BITS + 1; + rc->rem = -1; + rc->ext = 0; + rc->rng_cur = rc->buf; + ff_opus_rc_raw_init(&rc->c, rc->buf + OPUS_MAX_FRAME_SIZE + 8, 0); +} diff --git a/libavcodec/opusenc_rc.h b/libavcodec/opusenc_rc.h new file mode 100644 index 0000000000..40c48d04f0 --- /dev/null +++ b/libavcodec/opusenc_rc.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2012 Andrew D'Addesio + * Copyright (c) 2013-2014 Mozilla Corporation + * Copyright (c) 2017 Rostislav Pehlivanov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_OPUSENC_RC_H +#define AVCODEC_OPUSENC_RC_H + +#include + +#include "opus.h" +#include "opus_rc.h" + +typedef struct OpusEncRangeCoder { + OpusRangeCoder c; + + uint8_t *rng_cur; /* Current range coded byte */ + int ext; /* Awaiting propagation */ + int rem; /* Carryout flag */ + uint8_t buf[OPUS_MAX_FRAME_SIZE + 12]; /* memcpy vs (memmove + overreading) */ +} OpusEncRangeCoder; + +void ff_opus_rc_enc_cdf(OpusEncRangeCoder *rc, int val, const uint16_t *cdf); +void ff_opus_rc_enc_log(OpusEncRangeCoder *rc, int val, uint32_t bits); +void ff_opus_rc_enc_uint_step(OpusEncRangeCoder *rc, uint32_t val, int k0); +void ff_opus_rc_enc_uint_tri(OpusEncRangeCoder *rc, uint32_t k, int qn); +void ff_opus_rc_enc_uint(OpusEncRangeCoder *rc, uint32_t val, uint32_t size); +void ff_opus_rc_put_raw(OpusEncRangeCoder *rc, uint32_t val, uint32_t count); +void ff_opus_rc_enc_laplace(OpusEncRangeCoder *rc, int *value, uint32_t symbol, int decay); +void ff_opus_rc_enc_end(OpusEncRangeCoder *rc, uint8_t *dst, int size); +void ff_opus_rc_enc_init(OpusEncRangeCoder *rc); + +#define OPUS_RC_CHECKPOINT_UPDATE(rc) \ + rc_rollback_bits = opus_rc_tell_frac(&rc->c); \ + rc_rollback_ctx = *rc + +#define OPUS_RC_CHECKPOINT_SPAWN(rc) \ + uint32_t rc_rollback_bits = opus_rc_tell_frac(&rc->c); \ + OpusEncRangeCoder rc_rollback_ctx = *rc \ + +#define OPUS_RC_CHECKPOINT_BITS(rc) \ + (opus_rc_tell_frac(&rc->c) - rc_rollback_bits) + +#define OPUS_RC_CHECKPOINT_ROLLBACK(rc) \ + memcpy(rc, &rc_rollback_ctx, sizeof(*rc)); \ + +#endif /* AVCODEC_OPUSENC_RC_H */ From patchwork Fri Oct 7 20:25:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38613 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp206187pzc; Fri, 7 Oct 2022 13:26:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6sm6sObklaBRBce77tIvQZPbDaWLKw6IKB8PJp+kMOkgvoe8WaQdQ13MpnP65hLliSSHJT X-Received: by 2002:a05:6402:3887:b0:458:289e:c9cc with SMTP id fd7-20020a056402388700b00458289ec9ccmr6257023edb.101.1665174377103; Fri, 07 Oct 2022 13:26:17 -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 4-20020a508744000000b004571c47b13csi2627546edv.418.2022.10.07.13.26.16; Fri, 07 Oct 2022 13:26:17 -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=IbxxdPzj; 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 B305268BBCE; Fri, 7 Oct 2022 23:25:44 +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-oln040092072056.outbound.protection.outlook.com [40.92.72.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D34068BA9F for ; Fri, 7 Oct 2022 23:25:43 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S377TG0O4KYjJScvlLbmyrwnN5uLQd1iAAw0p9LbA1aBzyrGOr1aqODqZosqD3G+xXjgkpdcaDOQrLZMhh/kII9xLeMBd+qESswev585d9FaR+VYFlPfTXO2YC7eIvA1Py3c/W21O5AWgDr3XzanqsgxN0vQtBiN27sEXd7wsHBovuLf0mjQ2lsW51Pg092F0i7j0p1fV0TF8SqzEj7dyRnpQoVC3MHw+wUWB9meo+jDmkRaXRqnEkhv5jpsDpqyOA03fkwY09khcpFA3eADM9S+00LseSQuFEQ+MK72g6hG/IT9h7D28fiX1D8suXVbeWKSG+K3WpCcLYjFSgFVUA== 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=8qN1m4cKh9loVoZ7a4qMx+GlIT7RatyBJWxgM8yrIzw=; b=lxNORFiBJQ/7OQ3BlObdwx9C2QKQgMZSGOWPitH5JwX07SiaXveczHZoFBYmdio3SXWtme8yuX3CsHd1niJSpuGO83FzhsBw3sv7B8gE/S3vFzbaLhxfMO9qUPvA+q3oFD1ADlpNsHkV6MGnKuVmf6HoD3VRwERqZHwo9aG754jdMSglSzbAePyJ6OkXorKLRWo6/XBZKey1PQinm9z79UOw5/6I9dYB9bAdjRp2ICwY/1laTm4Vd+Q0EM05rXAOi3EYiVSAqbzcQrg/hdKGpj4dq3OxxeKChk+Sg5H7I7yeIT6K4RTevW6sBM1qiYlT/ZRvUe1E5unCh614HW+qag== 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=8qN1m4cKh9loVoZ7a4qMx+GlIT7RatyBJWxgM8yrIzw=; b=IbxxdPzjw9N9co1tNl6nZTm5SgjvpALNWHqpzvRspfZT6HUJxu1fXsOsGEcH7DVFpMoWvyWEduDhJT6hfarb2S7KD7hfu/tw2tAki2GLjdAs8AjxdU5h2LXe2BTVB4jX3FutIMCkG3xBEWU6q0Ird57+j5ysbYKBNrbS+Aw8NFVhzV/lHuhg/I3e2JQU+1RH2YmkzOeIDH9SU1US45jUlXHwnzYG5ignHEt45FnxS1mdXiZIiYgF0e4zTB7TJQlpTOXNs7HrpNcggbXOuV0w+jDmKSOiHAT9rQydRegIhtw56bmtt2EInKK64yWp0/DvFb7y2PEbIW/1cUlQDLKqSg== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0285.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Fri, 7 Oct 2022 20:25:41 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.028; Fri, 7 Oct 2022 20:25:41 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 22:25:07 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [6shd98M9tX3BIFyQKLzGZt7bU5dDT8069mr63NVay38=] X-ClientProxiedBy: ZR0P278CA0106.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:23::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221007202508.4188148-7-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0285:EE_ X-MS-Office365-Filtering-Correlation-Id: a05e542a-cc1f-4a5c-62e8-08daa8a21a73 X-MS-Exchange-SLBlob-MailProps: EgT5Wr3QDKyO3QjhF2EUZd1To6DGOTfGc/7qxJv1aOW5TRWxszAFO8OKUyowSimZ4lhts6vald+WTW5m3n1v8nxESHy0TawUW9o6p/0OdiEAbj/F5OKDoXpJqufcBz2RbNhdz6WpH3FHFpmpXjvt8VCVhoKe2oBhyvVUnGeqPIyqvS5zh1PEJXBAtnGLL8yL3L+vGWa/wjffDHceSllQk/cK0DJnQVLL6Ic5F6Hi4tJ2QlyORFQY0bapSYh5UEnKTTPLgNLRSCRFhpHqZMVLp6QvoKLGETfOi3MgIa7iEHhYE9u0CEKBZ0df9hHEi49gxDFOuN+D6Ox4kzFn7w6bagH1VwTgCKmSm3dxPrqwYcAamQtcRcnf8swD3DQcIzu8wGP5GPjjX15FV8si2idCzV/Gnb7FI45sZ1mTNvIci2xMEKXl4YD13LyM7OC0u7q877bcMhuW2iXomF+n7SpfYw6Fe5wdSFVWX6+8ywO9xG4h9Q53xhmc1w5DRGPmrd3J2yl5pLZNsQcWRxX8aCYybJ9nxsy06kGmhFp7IbD/I9Dq+BGI6CWj0obkPTDJ17G8gWnQaG0e6vt9AAt/sf/qq6ZhUIxvvwOf0hxG7bSvhNjGzdtkvllXDvG/Y46ZWO5dc7LXUMIFY7VwkyVaTgVoWeS1GWRwIXfQsyeuCjnFYGxbyIZKTs14oxqHeo8Vvvgw/JgMyRXf0+LGMTlw46TKFZGMhfPXSeLQLbrUSzNs9HU= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FpyDhShTR0zxLJYAo40b18kvg4eDYXN+PYovtorCtWAqiCrbdmT8Nnr70PIk5YFVeeQJJ3YdHSzmX0U0T5DQc3NZF3i1YkC5hwGSMec/Ch70vOGW+X226KM4Za1aC0AStcQH2CLKtV727s2u0bjz4WzuiOOMpk5PqM8eCNshR+2PcRQFElRZV2K67+KivPc+eZQ10kN/7lbvny//cUHZi1MCjP4vermrqnvAj3Uo9Q+7JFzm2zqmQgIdzwUOMVNEdo+fIsxzov0cUf+Z/vk4jVIntaKGysMR+SwsHiaFPU8EASo+v6SLVQbaqK98sjwD96xgMF3fz+kNIsjx2VZju7KM4BOr1LtXj6YJq09dwdaEvVfE7+5fLsVep3KYLSvKkrqCZKENFPwxuQlyGsdqQB2jLmLESl3klM2ZVrLXItJ/fZZEKfVkwqoSRmljET1AsnjIBsYKjlIFxW9krMUvz31Wu27jiy+JTL8GEwSpPtyloLp2ldijSzOu/HF21AZ6hxfstiz6HjWp8prMMv1VIhIouhXdHesB6/2Iv/8XMti5WUnZ2mwIAgP7Yqp9cXQXfRpVMuzN3Xbz/Dvbg8oGe7VdiLQHX/P243QSUnpIfiPXxKsyzm2ajvz40mg5tNdEk9Mz3YNosazX+ppJT+cbsN+1s97YBRP/K8p/jamB7ncj3du/4ZPMTn2H1bvA6wy4 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eBV7DeFfu1NtQGLxkr1N/7wLh4vNcSEkYH7uTojWe5G4SENuyjARqAzWDWUevnxop+WkJKzdf9qsnFOB5LRlFLdwDHchOEdrcdhf7tR6ByImE5m4gstDy1Nqd2t8SaSvI8/OiZAq3IZzN3WqEnwsOVropoh+gjf4XXXlSPp8vKwwgrlXd4UHw+PwzzdHgDUPumPBaI1NIhZUDfrafgyqQYpVjXbdM4i2J3vLEj1ZMADun67h7PxdnxFMDbtaJFtcRz0ftnrl2y7pW3BBbn66hkMUfJx7k6nDVFAHo73eUFyzDQ4lVke1mRSg60N1T/pPHBN6ickQ63C3q2/fobnVRefTBbnWsuZMvsR8pGuO/wDHTFLF6bbL4ZJb/eQaR4UZ6873UzoO60WU9gT3lVOGWJpfCsn1ddk6FKsRH5oqfRy6t4Vmhi2vNtwCyRhdj8VOFg8hqammIUrv9O0JAWw+fiuPaP6NsVrUGuvPR9PZ3anAVzn28ClHCgq6aoxXqAlbiqnTh7kCTuBGAcTnqlHn/UgeYABE6j2CdZNaFziTJBeTqp85V9cN+VcY5jUer2rDKLjwrGpISdh0PaFvqBBVpaFMbYGz2vTuLvVso1w5wKd1fj09QAQYhRcLPPxUSdBbE97MwL3HNyEcwm2VizvyLWbpse9isrtx07Sb34FG4KAd+z+BVaoBmzaJ/fo5m9pLJaFijqvd7LRtBw+roLTwoGlPlxRNWMkNBvVkxHw5GBNjxmwsv16KHRz3ZKqoc5USc5lM3+VLESY9psrQuSJhgkzjhVm0I4CXvPXh1UBHCRonpHB5G6X+7K2ACOcd3cdFr0hDPn0PgSOUlXipzRZM4hS5MBbO7ny71Fe00bkZVGXLJcFeXUSLW/26e0hEeU2d0bVC7rFTNI3HQswOfzLvepnpAxegqaV1mtjTfkfUMv0K9DxVK8Ooc+TpYgFZPykcl+TGRDl4A/Ylid29b7oXQhA5pQif32B+KblEQw2C5x3/p00VxtGTagw5zGPCgXzz4T5cxEssIttWJ3iy0KK/+jJbmBgO1iD36PgHbXhICSwgZzruIvCSj735Ri1fUJ8SHBTUmRViE4WcV389QUpD1biqmhOkBoEXYnvuiCLzvp1u57HjOKiygJgD0rUtjB8xeConLL53ocTzR/T4Mmen88l8ZwUAGIvNiNq3LhcMyTVgIfi+9ML1mqa0uybFFvajdx5HJkzXpvYZUpr3Z79BDX2aExIcfGV8gJ2S/8bIxD8/7UzQXvJ+dlZMwhZSVFdGXIie9GaKB9tE1w6uE5gKFYLyi9f/p5l5nz2rrKBshg8= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a05e542a-cc1f-4a5c-62e8-08daa8a21a73 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 20:25:41.0783 (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: DU2P250MB0285 Subject: [FFmpeg-devel] [PATCH 8/9] avcodec/opus: Rename opus.c->opus_celt.c, opus_celt.c->opusdec_celt.c 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: I5JzJGBqFgXV Since commit 4fc2531fff112836026aad2bdaf128c9d15a72e3 opus.c contains only the celt stuff shared between decoder and encoder. meanwhile, opus_celt.c is decoder-only. So the new names reflect the actual content better than the current ones. Signed-off-by: Andreas Rheinhardt --- libavcodec/Makefile | 4 +- libavcodec/opus.c | 522 ---------------------- libavcodec/opus_celt.c | 899 ++++++++++++++++++-------------------- libavcodec/opusdec_celt.c | 587 +++++++++++++++++++++++++ 4 files changed, 1006 insertions(+), 1006 deletions(-) delete mode 100644 libavcodec/opus.c create mode 100644 libavcodec/opusdec_celt.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index b7eb3b1e48..949c65a0e3 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -554,10 +554,10 @@ OBJS-$(CONFIG_NELLYMOSER_ENCODER) += nellymoserenc.o nellymoser.o OBJS-$(CONFIG_NOTCHLC_DECODER) += notchlc.o OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o OBJS-$(CONFIG_ON2AVC_DECODER) += on2avc.o on2avcdata.o -OBJS-$(CONFIG_OPUS_DECODER) += opusdec.o opus.o opus_celt.o \ +OBJS-$(CONFIG_OPUS_DECODER) += opusdec.o opusdec_celt.o opus_celt.o \ opus_pvq.o opus_silk.o opustab.o vorbis_data.o \ opusdec_rc.o opusdsp.o opus_parse.o -OBJS-$(CONFIG_OPUS_ENCODER) += opusenc.o opus.o opusenc_psy.o \ +OBJS-$(CONFIG_OPUS_ENCODER) += opusenc.o opus_celt.o opusenc_psy.o \ opusenc_rc.o opustab.o opus_pvq.o OBJS-$(CONFIG_PAF_AUDIO_DECODER) += pafaudio.o OBJS-$(CONFIG_PAF_VIDEO_DECODER) += pafvideo.o diff --git a/libavcodec/opus.c b/libavcodec/opus.c deleted file mode 100644 index 8def5e6e34..0000000000 --- a/libavcodec/opus.c +++ /dev/null @@ -1,522 +0,0 @@ -/* - * Copyright (c) 2012 Andrew D'Addesio - * Copyright (c) 2013-2014 Mozilla Corporation - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "config_components.h" -#include "opus_celt.h" -#include "opus_pvq.h" -#include "opustab.h" -#include "opus_rc.h" -#include "opusdec_rc.h" -#include "opusenc_rc.h" - -#if !CONFIG_OPUS_ENCODER -#define ff_opus_rc_enc_log(...) -#define ff_opus_rc_enc_cdf(...) -#define ff_opus_rc_enc_uint(...) -#endif - -#if !CONFIG_OPUS_DECODER -#define ff_opus_rc_dec_log(...) 0 -#define ff_opus_rc_dec_cdf(...) 0 -#define ff_opus_rc_dec_uint(...) 0 -#endif - -static inline void opus_rc_enc_log(OpusRangeCoder *rc, int val, uint32_t bits) -{ - ff_opus_rc_enc_log((OpusEncRangeCoder*)rc, val, bits); -} - -static inline uint32_t opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits) -{ - return ff_opus_rc_dec_log((OpusDecRangeCoder*)rc, bits); -} - -static inline void opus_rc_enc_cdf(OpusRangeCoder *rc, int val, const uint16_t *cdf) -{ - ff_opus_rc_enc_cdf((OpusEncRangeCoder*)rc, val, cdf); -} - -static inline uint32_t opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf) -{ - return ff_opus_rc_dec_cdf((OpusDecRangeCoder*)rc, cdf); -} - -void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc) -{ - float lowband_scratch[8 * 22]; - float norm1[2 * 8 * 100]; - float *norm2 = norm1 + 8 * 100; - - int totalbits = (f->framebits << 3) - f->anticollapse_needed; - - int update_lowband = 1; - int lowband_offset = 0; - - int i, j; - - for (i = f->start_band; i < f->end_band; i++) { - uint32_t cm[2] = { (1 << f->blocks) - 1, (1 << f->blocks) - 1 }; - int band_offset = ff_celt_freq_bands[i] << f->size; - int band_size = ff_celt_freq_range[i] << f->size; - float *X = f->block[0].coeffs + band_offset; - float *Y = (f->channels == 2) ? f->block[1].coeffs + band_offset : NULL; - float *norm_loc1, *norm_loc2; - - int consumed = opus_rc_tell_frac(rc); - int effective_lowband = -1; - int b = 0; - - /* Compute how many bits we want to allocate to this band */ - if (i != f->start_band) - f->remaining -= consumed; - f->remaining2 = totalbits - consumed - 1; - if (i <= f->coded_bands - 1) { - int curr_balance = f->remaining / FFMIN(3, f->coded_bands-i); - b = av_clip_uintp2(FFMIN(f->remaining2 + 1, f->pulses[i] + curr_balance), 14); - } - - if ((ff_celt_freq_bands[i] - ff_celt_freq_range[i] >= ff_celt_freq_bands[f->start_band] || - i == f->start_band + 1) && (update_lowband || lowband_offset == 0)) - lowband_offset = i; - - if (i == f->start_band + 1) { - /* Special Hybrid Folding (RFC 8251 section 9). Copy the first band into - the second to ensure the second band never has to use the LCG. */ - int count = (ff_celt_freq_range[i] - ff_celt_freq_range[i-1]) << f->size; - - memcpy(&norm1[band_offset], &norm1[band_offset - count], count * sizeof(float)); - - if (f->channels == 2) - memcpy(&norm2[band_offset], &norm2[band_offset - count], count * sizeof(float)); - } - - /* Get a conservative estimate of the collapse_mask's for the bands we're - going to be folding from. */ - if (lowband_offset != 0 && (f->spread != CELT_SPREAD_AGGRESSIVE || - f->blocks > 1 || f->tf_change[i] < 0)) { - int foldstart, foldend; - - /* This ensures we never repeat spectral content within one band */ - effective_lowband = FFMAX(ff_celt_freq_bands[f->start_band], - ff_celt_freq_bands[lowband_offset] - ff_celt_freq_range[i]); - foldstart = lowband_offset; - while (ff_celt_freq_bands[--foldstart] > effective_lowband); - foldend = lowband_offset - 1; - while (++foldend < i && ff_celt_freq_bands[foldend] < effective_lowband + ff_celt_freq_range[i]); - - cm[0] = cm[1] = 0; - for (j = foldstart; j < foldend; j++) { - cm[0] |= f->block[0].collapse_masks[j]; - cm[1] |= f->block[f->channels - 1].collapse_masks[j]; - } - } - - if (f->dual_stereo && i == f->intensity_stereo) { - /* Switch off dual stereo to do intensity */ - f->dual_stereo = 0; - for (j = ff_celt_freq_bands[f->start_band] << f->size; j < band_offset; j++) - norm1[j] = (norm1[j] + norm2[j]) / 2; - } - - norm_loc1 = effective_lowband != -1 ? norm1 + (effective_lowband << f->size) : NULL; - norm_loc2 = effective_lowband != -1 ? norm2 + (effective_lowband << f->size) : NULL; - - if (f->dual_stereo) { - cm[0] = f->pvq->quant_band(f->pvq, f, rc, i, X, NULL, band_size, b >> 1, - f->blocks, norm_loc1, f->size, - norm1 + band_offset, 0, 1.0f, - lowband_scratch, cm[0]); - - cm[1] = f->pvq->quant_band(f->pvq, f, rc, i, Y, NULL, band_size, b >> 1, - f->blocks, norm_loc2, f->size, - norm2 + band_offset, 0, 1.0f, - lowband_scratch, cm[1]); - } else { - cm[0] = f->pvq->quant_band(f->pvq, f, rc, i, X, Y, band_size, b >> 0, - f->blocks, norm_loc1, f->size, - norm1 + band_offset, 0, 1.0f, - lowband_scratch, cm[0] | cm[1]); - cm[1] = cm[0]; - } - - f->block[0].collapse_masks[i] = (uint8_t)cm[0]; - f->block[f->channels - 1].collapse_masks[i] = (uint8_t)cm[1]; - f->remaining += f->pulses[i] + consumed; - - /* Update the folding position only as long as we have 1 bit/sample depth */ - update_lowband = (b > band_size << 3); - } -} - -#define NORMC(bits) ((bits) << (f->channels - 1) << f->size >> 2) - -void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode) -{ - int i, j, low, high, total, done, bandbits, remaining, tbits_8ths; - int skip_startband = f->start_band; - int skip_bit = 0; - int intensitystereo_bit = 0; - int dualstereo_bit = 0; - int dynalloc = 6; - int extrabits = 0; - - int boost[CELT_MAX_BANDS] = { 0 }; - int trim_offset[CELT_MAX_BANDS]; - int threshold[CELT_MAX_BANDS]; - int bits1[CELT_MAX_BANDS]; - int bits2[CELT_MAX_BANDS]; - - if (!CONFIG_OPUS_DECODER || !CONFIG_OPUS_ENCODER) - encode = CONFIG_OPUS_ENCODER; - /* Spread */ - if (opus_rc_tell(rc) + 4 <= f->framebits) { - if (encode) - opus_rc_enc_cdf(rc, f->spread, ff_celt_model_spread); - else - f->spread = opus_rc_dec_cdf(rc, ff_celt_model_spread); - } else { - f->spread = CELT_SPREAD_NORMAL; - } - - /* Initialize static allocation caps */ - for (i = 0; i < CELT_MAX_BANDS; i++) - f->caps[i] = NORMC((ff_celt_static_caps[f->size][f->channels - 1][i] + 64) * ff_celt_freq_range[i]); - - /* Band boosts */ - tbits_8ths = f->framebits << 3; - for (i = f->start_band; i < f->end_band; i++) { - int quanta = ff_celt_freq_range[i] << (f->channels - 1) << f->size; - int b_dynalloc = dynalloc; - int boost_amount = f->alloc_boost[i]; - quanta = FFMIN(quanta << 3, FFMAX(6 << 3, quanta)); - - while (opus_rc_tell_frac(rc) + (b_dynalloc << 3) < tbits_8ths && boost[i] < f->caps[i]) { - int is_boost; - if (encode) { - is_boost = boost_amount--; - opus_rc_enc_log(rc, is_boost, b_dynalloc); - } else { - is_boost = opus_rc_dec_log(rc, b_dynalloc); - } - - if (!is_boost) - break; - - boost[i] += quanta; - tbits_8ths -= quanta; - - b_dynalloc = 1; - } - - if (boost[i]) - dynalloc = FFMAX(dynalloc - 1, 2); - } - - /* Allocation trim */ - if (!encode) - f->alloc_trim = 5; - if (opus_rc_tell_frac(rc) + (6 << 3) <= tbits_8ths) - if (encode) - opus_rc_enc_cdf(rc, f->alloc_trim, ff_celt_model_alloc_trim); - else - f->alloc_trim = opus_rc_dec_cdf(rc, ff_celt_model_alloc_trim); - - /* Anti-collapse bit reservation */ - tbits_8ths = (f->framebits << 3) - opus_rc_tell_frac(rc) - 1; - f->anticollapse_needed = 0; - if (f->transient && f->size >= 2 && tbits_8ths >= ((f->size + 2) << 3)) - f->anticollapse_needed = 1 << 3; - tbits_8ths -= f->anticollapse_needed; - - /* Band skip bit reservation */ - if (tbits_8ths >= 1 << 3) - skip_bit = 1 << 3; - tbits_8ths -= skip_bit; - - /* Intensity/dual stereo bit reservation */ - if (f->channels == 2) { - intensitystereo_bit = ff_celt_log2_frac[f->end_band - f->start_band]; - if (intensitystereo_bit <= tbits_8ths) { - tbits_8ths -= intensitystereo_bit; - if (tbits_8ths >= 1 << 3) { - dualstereo_bit = 1 << 3; - tbits_8ths -= 1 << 3; - } - } else { - intensitystereo_bit = 0; - } - } - - /* Trim offsets */ - for (i = f->start_band; i < f->end_band; i++) { - int trim = f->alloc_trim - 5 - f->size; - int band = ff_celt_freq_range[i] * (f->end_band - i - 1); - int duration = f->size + 3; - int scale = duration + f->channels - 1; - - /* PVQ minimum allocation threshold, below this value the band is - * skipped */ - threshold[i] = FFMAX(3 * ff_celt_freq_range[i] << duration >> 4, - f->channels << 3); - - trim_offset[i] = trim * (band << scale) >> 6; - - if (ff_celt_freq_range[i] << f->size == 1) - trim_offset[i] -= f->channels << 3; - } - - /* Bisection */ - low = 1; - high = CELT_VECTORS - 1; - while (low <= high) { - int center = (low + high) >> 1; - done = total = 0; - - for (i = f->end_band - 1; i >= f->start_band; i--) { - bandbits = NORMC(ff_celt_freq_range[i] * ff_celt_static_alloc[center][i]); - - if (bandbits) - bandbits = FFMAX(bandbits + trim_offset[i], 0); - bandbits += boost[i]; - - if (bandbits >= threshold[i] || done) { - done = 1; - total += FFMIN(bandbits, f->caps[i]); - } else if (bandbits >= f->channels << 3) { - total += f->channels << 3; - } - } - - if (total > tbits_8ths) - high = center - 1; - else - low = center + 1; - } - high = low--; - - /* Bisection */ - for (i = f->start_band; i < f->end_band; i++) { - bits1[i] = NORMC(ff_celt_freq_range[i] * ff_celt_static_alloc[low][i]); - bits2[i] = high >= CELT_VECTORS ? f->caps[i] : - NORMC(ff_celt_freq_range[i] * ff_celt_static_alloc[high][i]); - - if (bits1[i]) - bits1[i] = FFMAX(bits1[i] + trim_offset[i], 0); - if (bits2[i]) - bits2[i] = FFMAX(bits2[i] + trim_offset[i], 0); - - if (low) - bits1[i] += boost[i]; - bits2[i] += boost[i]; - - if (boost[i]) - skip_startband = i; - bits2[i] = FFMAX(bits2[i] - bits1[i], 0); - } - - /* Bisection */ - low = 0; - high = 1 << CELT_ALLOC_STEPS; - for (i = 0; i < CELT_ALLOC_STEPS; i++) { - int center = (low + high) >> 1; - done = total = 0; - - for (j = f->end_band - 1; j >= f->start_band; j--) { - bandbits = bits1[j] + (center * bits2[j] >> CELT_ALLOC_STEPS); - - if (bandbits >= threshold[j] || done) { - done = 1; - total += FFMIN(bandbits, f->caps[j]); - } else if (bandbits >= f->channels << 3) - total += f->channels << 3; - } - if (total > tbits_8ths) - high = center; - else - low = center; - } - - /* Bisection */ - done = total = 0; - for (i = f->end_band - 1; i >= f->start_band; i--) { - bandbits = bits1[i] + (low * bits2[i] >> CELT_ALLOC_STEPS); - - if (bandbits >= threshold[i] || done) - done = 1; - else - bandbits = (bandbits >= f->channels << 3) ? - f->channels << 3 : 0; - - bandbits = FFMIN(bandbits, f->caps[i]); - f->pulses[i] = bandbits; - total += bandbits; - } - - /* Band skipping */ - for (f->coded_bands = f->end_band; ; f->coded_bands--) { - int allocation; - j = f->coded_bands - 1; - - if (j == skip_startband) { - /* all remaining bands are not skipped */ - tbits_8ths += skip_bit; - break; - } - - /* determine the number of bits available for coding "do not skip" markers */ - remaining = tbits_8ths - total; - bandbits = remaining / (ff_celt_freq_bands[j+1] - ff_celt_freq_bands[f->start_band]); - remaining -= bandbits * (ff_celt_freq_bands[j+1] - ff_celt_freq_bands[f->start_band]); - allocation = f->pulses[j] + bandbits * ff_celt_freq_range[j]; - allocation += FFMAX(remaining - (ff_celt_freq_bands[j] - ff_celt_freq_bands[f->start_band]), 0); - - /* a "do not skip" marker is only coded if the allocation is - * above the chosen threshold */ - if (allocation >= FFMAX(threshold[j], (f->channels + 1) << 3)) { - int do_not_skip; - if (encode) { - do_not_skip = f->coded_bands <= f->skip_band_floor; - opus_rc_enc_log(rc, do_not_skip, 1); - } else { - do_not_skip = opus_rc_dec_log(rc, 1); - } - - if (do_not_skip) - break; - - total += 1 << 3; - allocation -= 1 << 3; - } - - /* the band is skipped, so reclaim its bits */ - total -= f->pulses[j]; - if (intensitystereo_bit) { - total -= intensitystereo_bit; - intensitystereo_bit = ff_celt_log2_frac[j - f->start_band]; - total += intensitystereo_bit; - } - - total += f->pulses[j] = (allocation >= f->channels << 3) ? f->channels << 3 : 0; - } - - /* IS start band */ - if (encode) { - if (intensitystereo_bit) { - f->intensity_stereo = FFMIN(f->intensity_stereo, f->coded_bands); - ff_opus_rc_enc_uint((OpusEncRangeCoder*)rc, f->intensity_stereo, f->coded_bands + 1 - f->start_band); - } - } else { - f->intensity_stereo = f->dual_stereo = 0; - if (intensitystereo_bit) - f->intensity_stereo = f->start_band + ff_opus_rc_dec_uint((OpusDecRangeCoder*)rc, f->coded_bands + 1 - f->start_band); - } - - /* DS flag */ - if (f->intensity_stereo <= f->start_band) - tbits_8ths += dualstereo_bit; /* no intensity stereo means no dual stereo */ - else if (dualstereo_bit) - if (encode) - opus_rc_enc_log(rc, f->dual_stereo, 1); - else - f->dual_stereo = opus_rc_dec_log(rc, 1); - - /* Supply the remaining bits in this frame to lower bands */ - remaining = tbits_8ths - total; - bandbits = remaining / (ff_celt_freq_bands[f->coded_bands] - ff_celt_freq_bands[f->start_band]); - remaining -= bandbits * (ff_celt_freq_bands[f->coded_bands] - ff_celt_freq_bands[f->start_band]); - for (i = f->start_band; i < f->coded_bands; i++) { - const int bits = FFMIN(remaining, ff_celt_freq_range[i]); - f->pulses[i] += bits + bandbits * ff_celt_freq_range[i]; - remaining -= bits; - } - - /* Finally determine the allocation */ - for (i = f->start_band; i < f->coded_bands; i++) { - int N = ff_celt_freq_range[i] << f->size; - int prev_extra = extrabits; - f->pulses[i] += extrabits; - - if (N > 1) { - int dof; /* degrees of freedom */ - int temp; /* dof * channels * log(dof) */ - int fine_bits; - int max_bits; - int offset; /* fine energy quantization offset, i.e. - * extra bits assigned over the standard - * totalbits/dof */ - - extrabits = FFMAX(f->pulses[i] - f->caps[i], 0); - f->pulses[i] -= extrabits; - - /* intensity stereo makes use of an extra degree of freedom */ - dof = N * f->channels + (f->channels == 2 && N > 2 && !f->dual_stereo && i < f->intensity_stereo); - temp = dof * (ff_celt_log_freq_range[i] + (f->size << 3)); - offset = (temp >> 1) - dof * CELT_FINE_OFFSET; - if (N == 2) /* dof=2 is the only case that doesn't fit the model */ - offset += dof << 1; - - /* grant an additional bias for the first and second pulses */ - if (f->pulses[i] + offset < 2 * (dof << 3)) - offset += temp >> 2; - else if (f->pulses[i] + offset < 3 * (dof << 3)) - offset += temp >> 3; - - fine_bits = (f->pulses[i] + offset + (dof << 2)) / (dof << 3); - max_bits = FFMIN((f->pulses[i] >> 3) >> (f->channels - 1), CELT_MAX_FINE_BITS); - max_bits = FFMAX(max_bits, 0); - f->fine_bits[i] = av_clip(fine_bits, 0, max_bits); - - /* If fine_bits was rounded down or capped, - * give priority for the final fine energy pass */ - f->fine_priority[i] = (f->fine_bits[i] * (dof << 3) >= f->pulses[i] + offset); - - /* the remaining bits are assigned to PVQ */ - f->pulses[i] -= f->fine_bits[i] << (f->channels - 1) << 3; - } else { - /* all bits go to fine energy except for the sign bit */ - extrabits = FFMAX(f->pulses[i] - (f->channels << 3), 0); - f->pulses[i] -= extrabits; - f->fine_bits[i] = 0; - f->fine_priority[i] = 1; - } - - /* hand back a limited number of extra fine energy bits to this band */ - if (extrabits > 0) { - int fineextra = FFMIN(extrabits >> (f->channels + 2), - CELT_MAX_FINE_BITS - f->fine_bits[i]); - f->fine_bits[i] += fineextra; - - fineextra <<= f->channels + 2; - f->fine_priority[i] = (fineextra >= extrabits - prev_extra); - extrabits -= fineextra; - } - } - f->remaining = extrabits; - - /* skipped bands dedicate all of their bits for fine energy */ - for (; i < f->end_band; i++) { - f->fine_bits[i] = f->pulses[i] >> (f->channels - 1) >> 3; - f->pulses[i] = 0; - f->fine_priority[i] = f->fine_bits[i] < 1; - } -} diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c index a14764ec18..8def5e6e34 100644 --- a/libavcodec/opus_celt.c +++ b/libavcodec/opus_celt.c @@ -1,7 +1,6 @@ /* * Copyright (c) 2012 Andrew D'Addesio * Copyright (c) 2013-2014 Mozilla Corporation - * Copyright (c) 2016 Rostislav Pehlivanov * * This file is part of FFmpeg. * @@ -20,568 +19,504 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/** - * @file - * Opus CELT decoder - */ - -#include +#include +#include "config_components.h" #include "opus_celt.h" -#include "opusdec_rc.h" -#include "opustab.h" #include "opus_pvq.h" +#include "opustab.h" +#include "opus_rc.h" +#include "opusdec_rc.h" +#include "opusenc_rc.h" -/* Use the 2D z-transform to apply prediction in both the time domain (alpha) - * and the frequency domain (beta) */ -static void celt_decode_coarse_energy(CeltFrame *f, OpusDecRangeCoder *rc) -{ - int i, j; - float prev[2] = { 0 }; - float alpha = ff_celt_alpha_coef[f->size]; - float beta = ff_celt_beta_coef[f->size]; - const uint8_t *model = ff_celt_coarse_energy_dist[f->size][0]; - - /* intra frame */ - if (opus_rc_tell(&rc->c) + 3 <= f->framebits && ff_opus_rc_dec_log(rc, 3)) { - alpha = 0.0f; - beta = 1.0f - (4915.0f/32768.0f); - model = ff_celt_coarse_energy_dist[f->size][1]; - } - - for (i = 0; i < CELT_MAX_BANDS; i++) { - for (j = 0; j < f->channels; j++) { - CeltBlock *block = &f->block[j]; - float value; - int available; - - if (i < f->start_band || i >= f->end_band) { - block->energy[i] = 0.0; - continue; - } +#if !CONFIG_OPUS_ENCODER +#define ff_opus_rc_enc_log(...) +#define ff_opus_rc_enc_cdf(...) +#define ff_opus_rc_enc_uint(...) +#endif - available = f->framebits - opus_rc_tell(&rc->c); - if (available >= 15) { - /* decode using a Laplace distribution */ - int k = FFMIN(i, 20) << 1; - value = ff_opus_rc_dec_laplace(rc, model[k] << 7, model[k+1] << 6); - } else if (available >= 2) { - int x = ff_opus_rc_dec_cdf(rc, ff_celt_model_energy_small); - value = (x>>1) ^ -(x&1); - } else if (available >= 1) { - value = -(float)ff_opus_rc_dec_log(rc, 1); - } else value = -1; - - block->energy[i] = FFMAX(-9.0f, block->energy[i]) * alpha + prev[j] + value; - prev[j] += beta * value; - } - } -} +#if !CONFIG_OPUS_DECODER +#define ff_opus_rc_dec_log(...) 0 +#define ff_opus_rc_dec_cdf(...) 0 +#define ff_opus_rc_dec_uint(...) 0 +#endif -static void celt_decode_fine_energy(CeltFrame *f, OpusDecRangeCoder *rc) +static inline void opus_rc_enc_log(OpusRangeCoder *rc, int val, uint32_t bits) { - int i; - for (i = f->start_band; i < f->end_band; i++) { - int j; - if (!f->fine_bits[i]) - continue; - - for (j = 0; j < f->channels; j++) { - CeltBlock *block = &f->block[j]; - int q2; - float offset; - q2 = ff_opus_rc_get_raw(rc, f->fine_bits[i]); - offset = (q2 + 0.5f) * (1 << (14 - f->fine_bits[i])) / 16384.0f - 0.5f; - block->energy[i] += offset; - } - } + ff_opus_rc_enc_log((OpusEncRangeCoder*)rc, val, bits); } -static void celt_decode_final_energy(CeltFrame *f, OpusDecRangeCoder *rc) +static inline uint32_t opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits) { - int priority, i, j; - int bits_left = f->framebits - opus_rc_tell(&rc->c); - - for (priority = 0; priority < 2; priority++) { - for (i = f->start_band; i < f->end_band && bits_left >= f->channels; i++) { - if (f->fine_priority[i] != priority || f->fine_bits[i] >= CELT_MAX_FINE_BITS) - continue; - - for (j = 0; j < f->channels; j++) { - int q2; - float offset; - q2 = ff_opus_rc_get_raw(rc, 1); - offset = (q2 - 0.5f) * (1 << (14 - f->fine_bits[i] - 1)) / 16384.0f; - f->block[j].energy[i] += offset; - bits_left--; - } - } - } + return ff_opus_rc_dec_log((OpusDecRangeCoder*)rc, bits); } -static void celt_decode_tf_changes(CeltFrame *f, OpusDecRangeCoder *rc) +static inline void opus_rc_enc_cdf(OpusRangeCoder *rc, int val, const uint16_t *cdf) { - int i, diff = 0, tf_select = 0, tf_changed = 0, tf_select_bit; - int consumed, bits = f->transient ? 2 : 4; - - consumed = opus_rc_tell(&rc->c); - tf_select_bit = (f->size != 0 && consumed+bits+1 <= f->framebits); - - for (i = f->start_band; i < f->end_band; i++) { - if (consumed+bits+tf_select_bit <= f->framebits) { - diff ^= ff_opus_rc_dec_log(rc, bits); - consumed = opus_rc_tell(&rc->c); - tf_changed |= diff; - } - f->tf_change[i] = diff; - bits = f->transient ? 4 : 5; - } - - if (tf_select_bit && ff_celt_tf_select[f->size][f->transient][0][tf_changed] != - ff_celt_tf_select[f->size][f->transient][1][tf_changed]) - tf_select = ff_opus_rc_dec_log(rc, 1); - - for (i = f->start_band; i < f->end_band; i++) { - f->tf_change[i] = ff_celt_tf_select[f->size][f->transient][tf_select][f->tf_change[i]]; - } + ff_opus_rc_enc_cdf((OpusEncRangeCoder*)rc, val, cdf); } -static void celt_denormalize(CeltFrame *f, CeltBlock *block, float *data) +static inline uint32_t opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf) { - int i, j; - - for (i = f->start_band; i < f->end_band; i++) { - float *dst = data + (ff_celt_freq_bands[i] << f->size); - float log_norm = block->energy[i] + ff_celt_mean_energy[i]; - float norm = exp2f(FFMIN(log_norm, 32.0f)); - - for (j = 0; j < ff_celt_freq_range[i] << f->size; j++) - dst[j] *= norm; - } + return ff_opus_rc_dec_cdf((OpusDecRangeCoder*)rc, cdf); } -static void celt_postfilter_apply_transition(CeltBlock *block, float *data) +void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc) { - const int T0 = block->pf_period_old; - const int T1 = block->pf_period; - - float g00, g01, g02; - float g10, g11, g12; - - float x0, x1, x2, x3, x4; - - int i; - - if (block->pf_gains[0] == 0.0 && - block->pf_gains_old[0] == 0.0) - return; - - g00 = block->pf_gains_old[0]; - g01 = block->pf_gains_old[1]; - g02 = block->pf_gains_old[2]; - g10 = block->pf_gains[0]; - g11 = block->pf_gains[1]; - g12 = block->pf_gains[2]; - - x1 = data[-T1 + 1]; - x2 = data[-T1]; - x3 = data[-T1 - 1]; - x4 = data[-T1 - 2]; - - for (i = 0; i < CELT_OVERLAP; i++) { - float w = ff_celt_window2[i]; - x0 = data[i - T1 + 2]; - - data[i] += (1.0 - w) * g00 * data[i - T0] + - (1.0 - w) * g01 * (data[i - T0 - 1] + data[i - T0 + 1]) + - (1.0 - w) * g02 * (data[i - T0 - 2] + data[i - T0 + 2]) + - w * g10 * x2 + - w * g11 * (x1 + x3) + - w * g12 * (x0 + x4); - x4 = x3; - x3 = x2; - x2 = x1; - x1 = x0; - } -} + float lowband_scratch[8 * 22]; + float norm1[2 * 8 * 100]; + float *norm2 = norm1 + 8 * 100; -static void celt_postfilter(CeltFrame *f, CeltBlock *block) -{ - int len = f->blocksize * f->blocks; - const int filter_len = len - 2 * CELT_OVERLAP; + int totalbits = (f->framebits << 3) - f->anticollapse_needed; - celt_postfilter_apply_transition(block, block->buf + 1024); + int update_lowband = 1; + int lowband_offset = 0; - block->pf_period_old = block->pf_period; - memcpy(block->pf_gains_old, block->pf_gains, sizeof(block->pf_gains)); + int i, j; - block->pf_period = block->pf_period_new; - memcpy(block->pf_gains, block->pf_gains_new, sizeof(block->pf_gains)); + for (i = f->start_band; i < f->end_band; i++) { + uint32_t cm[2] = { (1 << f->blocks) - 1, (1 << f->blocks) - 1 }; + int band_offset = ff_celt_freq_bands[i] << f->size; + int band_size = ff_celt_freq_range[i] << f->size; + float *X = f->block[0].coeffs + band_offset; + float *Y = (f->channels == 2) ? f->block[1].coeffs + band_offset : NULL; + float *norm_loc1, *norm_loc2; + + int consumed = opus_rc_tell_frac(rc); + int effective_lowband = -1; + int b = 0; + + /* Compute how many bits we want to allocate to this band */ + if (i != f->start_band) + f->remaining -= consumed; + f->remaining2 = totalbits - consumed - 1; + if (i <= f->coded_bands - 1) { + int curr_balance = f->remaining / FFMIN(3, f->coded_bands-i); + b = av_clip_uintp2(FFMIN(f->remaining2 + 1, f->pulses[i] + curr_balance), 14); + } - if (len > CELT_OVERLAP) { - celt_postfilter_apply_transition(block, block->buf + 1024 + CELT_OVERLAP); + if ((ff_celt_freq_bands[i] - ff_celt_freq_range[i] >= ff_celt_freq_bands[f->start_band] || + i == f->start_band + 1) && (update_lowband || lowband_offset == 0)) + lowband_offset = i; - if (block->pf_gains[0] > FLT_EPSILON && filter_len > 0) - f->opusdsp.postfilter(block->buf + 1024 + 2 * CELT_OVERLAP, - block->pf_period, block->pf_gains, - filter_len); + if (i == f->start_band + 1) { + /* Special Hybrid Folding (RFC 8251 section 9). Copy the first band into + the second to ensure the second band never has to use the LCG. */ + int count = (ff_celt_freq_range[i] - ff_celt_freq_range[i-1]) << f->size; - block->pf_period_old = block->pf_period; - memcpy(block->pf_gains_old, block->pf_gains, sizeof(block->pf_gains)); - } + memcpy(&norm1[band_offset], &norm1[band_offset - count], count * sizeof(float)); - memmove(block->buf, block->buf + len, (1024 + CELT_OVERLAP / 2) * sizeof(float)); -} + if (f->channels == 2) + memcpy(&norm2[band_offset], &norm2[band_offset - count], count * sizeof(float)); + } -static int parse_postfilter(CeltFrame *f, OpusDecRangeCoder *rc, int consumed) -{ - int i; - - memset(f->block[0].pf_gains_new, 0, sizeof(f->block[0].pf_gains_new)); - memset(f->block[1].pf_gains_new, 0, sizeof(f->block[1].pf_gains_new)); - - if (f->start_band == 0 && consumed + 16 <= f->framebits) { - int has_postfilter = ff_opus_rc_dec_log(rc, 1); - if (has_postfilter) { - float gain; - int tapset, octave, period; - - octave = ff_opus_rc_dec_uint(rc, 6); - period = (16 << octave) + ff_opus_rc_get_raw(rc, 4 + octave) - 1; - gain = 0.09375f * (ff_opus_rc_get_raw(rc, 3) + 1); - tapset = (opus_rc_tell(&rc->c) + 2 <= f->framebits) ? - ff_opus_rc_dec_cdf(rc, ff_celt_model_tapset) : 0; - - for (i = 0; i < 2; i++) { - CeltBlock *block = &f->block[i]; - - block->pf_period_new = FFMAX(period, CELT_POSTFILTER_MINPERIOD); - block->pf_gains_new[0] = gain * ff_celt_postfilter_taps[tapset][0]; - block->pf_gains_new[1] = gain * ff_celt_postfilter_taps[tapset][1]; - block->pf_gains_new[2] = gain * ff_celt_postfilter_taps[tapset][2]; + /* Get a conservative estimate of the collapse_mask's for the bands we're + going to be folding from. */ + if (lowband_offset != 0 && (f->spread != CELT_SPREAD_AGGRESSIVE || + f->blocks > 1 || f->tf_change[i] < 0)) { + int foldstart, foldend; + + /* This ensures we never repeat spectral content within one band */ + effective_lowband = FFMAX(ff_celt_freq_bands[f->start_band], + ff_celt_freq_bands[lowband_offset] - ff_celt_freq_range[i]); + foldstart = lowband_offset; + while (ff_celt_freq_bands[--foldstart] > effective_lowband); + foldend = lowband_offset - 1; + while (++foldend < i && ff_celt_freq_bands[foldend] < effective_lowband + ff_celt_freq_range[i]); + + cm[0] = cm[1] = 0; + for (j = foldstart; j < foldend; j++) { + cm[0] |= f->block[0].collapse_masks[j]; + cm[1] |= f->block[f->channels - 1].collapse_masks[j]; } } - consumed = opus_rc_tell(&rc->c); - } + if (f->dual_stereo && i == f->intensity_stereo) { + /* Switch off dual stereo to do intensity */ + f->dual_stereo = 0; + for (j = ff_celt_freq_bands[f->start_band] << f->size; j < band_offset; j++) + norm1[j] = (norm1[j] + norm2[j]) / 2; + } - return consumed; -} + norm_loc1 = effective_lowband != -1 ? norm1 + (effective_lowband << f->size) : NULL; + norm_loc2 = effective_lowband != -1 ? norm2 + (effective_lowband << f->size) : NULL; -static void process_anticollapse(CeltFrame *f, CeltBlock *block, float *X) -{ - int i, j, k; + if (f->dual_stereo) { + cm[0] = f->pvq->quant_band(f->pvq, f, rc, i, X, NULL, band_size, b >> 1, + f->blocks, norm_loc1, f->size, + norm1 + band_offset, 0, 1.0f, + lowband_scratch, cm[0]); - for (i = f->start_band; i < f->end_band; i++) { - int renormalize = 0; - float *xptr; - float prev[2]; - float Ediff, r; - float thresh, sqrt_1; - int depth; - - /* depth in 1/8 bits */ - depth = (1 + f->pulses[i]) / (ff_celt_freq_range[i] << f->size); - thresh = exp2f(-1.0 - 0.125f * depth); - sqrt_1 = 1.0f / sqrtf(ff_celt_freq_range[i] << f->size); - - xptr = X + (ff_celt_freq_bands[i] << f->size); - - prev[0] = block->prev_energy[0][i]; - prev[1] = block->prev_energy[1][i]; - if (f->channels == 1) { - CeltBlock *block1 = &f->block[1]; - - prev[0] = FFMAX(prev[0], block1->prev_energy[0][i]); - prev[1] = FFMAX(prev[1], block1->prev_energy[1][i]); - } - Ediff = block->energy[i] - FFMIN(prev[0], prev[1]); - Ediff = FFMAX(0, Ediff); - - /* r needs to be multiplied by 2 or 2*sqrt(2) depending on LM because - short blocks don't have the same energy as long */ - r = exp2f(1 - Ediff); - if (f->size == 3) - r *= M_SQRT2; - r = FFMIN(thresh, r) * sqrt_1; - for (k = 0; k < 1 << f->size; k++) { - /* Detect collapse */ - if (!(block->collapse_masks[i] & 1 << k)) { - /* Fill with noise */ - for (j = 0; j < ff_celt_freq_range[i]; j++) - xptr[(j << f->size) + k] = (celt_rng(f) & 0x8000) ? r : -r; - renormalize = 1; - } + cm[1] = f->pvq->quant_band(f->pvq, f, rc, i, Y, NULL, band_size, b >> 1, + f->blocks, norm_loc2, f->size, + norm2 + band_offset, 0, 1.0f, + lowband_scratch, cm[1]); + } else { + cm[0] = f->pvq->quant_band(f->pvq, f, rc, i, X, Y, band_size, b >> 0, + f->blocks, norm_loc1, f->size, + norm1 + band_offset, 0, 1.0f, + lowband_scratch, cm[0] | cm[1]); + cm[1] = cm[0]; } - /* We just added some energy, so we need to renormalize */ - if (renormalize) - celt_renormalize_vector(xptr, ff_celt_freq_range[i] << f->size, 1.0f); + f->block[0].collapse_masks[i] = (uint8_t)cm[0]; + f->block[f->channels - 1].collapse_masks[i] = (uint8_t)cm[1]; + f->remaining += f->pulses[i] + consumed; + + /* Update the folding position only as long as we have 1 bit/sample depth */ + update_lowband = (b > band_size << 3); } } -int ff_celt_decode_frame(CeltFrame *f, OpusDecRangeCoder *rc, - float **output, int channels, int frame_size, - int start_band, int end_band) -{ - int i, j, downmix = 0; - int consumed; // bits of entropy consumed thus far for this frame - AVTXContext *imdct; - av_tx_fn imdct_fn; - - if (channels != 1 && channels != 2) { - av_log(f->avctx, AV_LOG_ERROR, "Invalid number of coded channels: %d\n", - channels); - return AVERROR_INVALIDDATA; - } - if (start_band < 0 || start_band > end_band || end_band > CELT_MAX_BANDS) { - av_log(f->avctx, AV_LOG_ERROR, "Invalid start/end band: %d %d\n", - start_band, end_band); - return AVERROR_INVALIDDATA; - } +#define NORMC(bits) ((bits) << (f->channels - 1) << f->size >> 2) - f->silence = 0; - f->transient = 0; - f->anticollapse = 0; - f->flushed = 0; - f->channels = channels; - f->start_band = start_band; - f->end_band = end_band; - f->framebits = rc->c.rb.bytes * 8; - - f->size = av_log2(frame_size / CELT_SHORT_BLOCKSIZE); - if (f->size > CELT_MAX_LOG_BLOCKS || - frame_size != CELT_SHORT_BLOCKSIZE * (1 << f->size)) { - av_log(f->avctx, AV_LOG_ERROR, "Invalid CELT frame size: %d\n", - frame_size); - return AVERROR_INVALIDDATA; +void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode) +{ + int i, j, low, high, total, done, bandbits, remaining, tbits_8ths; + int skip_startband = f->start_band; + int skip_bit = 0; + int intensitystereo_bit = 0; + int dualstereo_bit = 0; + int dynalloc = 6; + int extrabits = 0; + + int boost[CELT_MAX_BANDS] = { 0 }; + int trim_offset[CELT_MAX_BANDS]; + int threshold[CELT_MAX_BANDS]; + int bits1[CELT_MAX_BANDS]; + int bits2[CELT_MAX_BANDS]; + + if (!CONFIG_OPUS_DECODER || !CONFIG_OPUS_ENCODER) + encode = CONFIG_OPUS_ENCODER; + /* Spread */ + if (opus_rc_tell(rc) + 4 <= f->framebits) { + if (encode) + opus_rc_enc_cdf(rc, f->spread, ff_celt_model_spread); + else + f->spread = opus_rc_dec_cdf(rc, ff_celt_model_spread); + } else { + f->spread = CELT_SPREAD_NORMAL; } - if (!f->output_channels) - f->output_channels = channels; + /* Initialize static allocation caps */ + for (i = 0; i < CELT_MAX_BANDS; i++) + f->caps[i] = NORMC((ff_celt_static_caps[f->size][f->channels - 1][i] + 64) * ff_celt_freq_range[i]); - for (i = 0; i < f->channels; i++) { - memset(f->block[i].coeffs, 0, sizeof(f->block[i].coeffs)); - memset(f->block[i].collapse_masks, 0, sizeof(f->block[i].collapse_masks)); - } + /* Band boosts */ + tbits_8ths = f->framebits << 3; + for (i = f->start_band; i < f->end_band; i++) { + int quanta = ff_celt_freq_range[i] << (f->channels - 1) << f->size; + int b_dynalloc = dynalloc; + int boost_amount = f->alloc_boost[i]; + quanta = FFMIN(quanta << 3, FFMAX(6 << 3, quanta)); + + while (opus_rc_tell_frac(rc) + (b_dynalloc << 3) < tbits_8ths && boost[i] < f->caps[i]) { + int is_boost; + if (encode) { + is_boost = boost_amount--; + opus_rc_enc_log(rc, is_boost, b_dynalloc); + } else { + is_boost = opus_rc_dec_log(rc, b_dynalloc); + } - consumed = opus_rc_tell(&rc->c); + if (!is_boost) + break; - /* obtain silence flag */ - if (consumed >= f->framebits) - f->silence = 1; - else if (consumed == 1) - f->silence = ff_opus_rc_dec_log(rc, 15); + boost[i] += quanta; + tbits_8ths -= quanta; + b_dynalloc = 1; + } - if (f->silence) { - consumed = f->framebits; - rc->c.total_bits += f->framebits - opus_rc_tell(&rc->c); + if (boost[i]) + dynalloc = FFMAX(dynalloc - 1, 2); } - /* obtain post-filter options */ - consumed = parse_postfilter(f, rc, consumed); - - /* obtain transient flag */ - if (f->size != 0 && consumed+3 <= f->framebits) - f->transient = ff_opus_rc_dec_log(rc, 3); - - f->blocks = f->transient ? 1 << f->size : 1; - f->blocksize = frame_size / f->blocks; - - imdct = f->tx[f->transient ? 0 : f->size]; - imdct_fn = f->tx_fn[f->transient ? 0 : f->size]; - - if (channels == 1) { - for (i = 0; i < CELT_MAX_BANDS; i++) - f->block[0].energy[i] = FFMAX(f->block[0].energy[i], f->block[1].energy[i]); + /* Allocation trim */ + if (!encode) + f->alloc_trim = 5; + if (opus_rc_tell_frac(rc) + (6 << 3) <= tbits_8ths) + if (encode) + opus_rc_enc_cdf(rc, f->alloc_trim, ff_celt_model_alloc_trim); + else + f->alloc_trim = opus_rc_dec_cdf(rc, ff_celt_model_alloc_trim); + + /* Anti-collapse bit reservation */ + tbits_8ths = (f->framebits << 3) - opus_rc_tell_frac(rc) - 1; + f->anticollapse_needed = 0; + if (f->transient && f->size >= 2 && tbits_8ths >= ((f->size + 2) << 3)) + f->anticollapse_needed = 1 << 3; + tbits_8ths -= f->anticollapse_needed; + + /* Band skip bit reservation */ + if (tbits_8ths >= 1 << 3) + skip_bit = 1 << 3; + tbits_8ths -= skip_bit; + + /* Intensity/dual stereo bit reservation */ + if (f->channels == 2) { + intensitystereo_bit = ff_celt_log2_frac[f->end_band - f->start_band]; + if (intensitystereo_bit <= tbits_8ths) { + tbits_8ths -= intensitystereo_bit; + if (tbits_8ths >= 1 << 3) { + dualstereo_bit = 1 << 3; + tbits_8ths -= 1 << 3; + } + } else { + intensitystereo_bit = 0; + } } - celt_decode_coarse_energy(f, rc); - celt_decode_tf_changes (f, rc); - ff_celt_bitalloc (f, &rc->c, 0); - celt_decode_fine_energy (f, rc); - ff_celt_quant_bands (f, &rc->c); - - if (f->anticollapse_needed) - f->anticollapse = ff_opus_rc_get_raw(rc, 1); - - celt_decode_final_energy(f, rc); + /* Trim offsets */ + for (i = f->start_band; i < f->end_band; i++) { + int trim = f->alloc_trim - 5 - f->size; + int band = ff_celt_freq_range[i] * (f->end_band - i - 1); + int duration = f->size + 3; + int scale = duration + f->channels - 1; - /* apply anti-collapse processing and denormalization to - * each coded channel */ - for (i = 0; i < f->channels; i++) { - CeltBlock *block = &f->block[i]; + /* PVQ minimum allocation threshold, below this value the band is + * skipped */ + threshold[i] = FFMAX(3 * ff_celt_freq_range[i] << duration >> 4, + f->channels << 3); - if (f->anticollapse) - process_anticollapse(f, block, f->block[i].coeffs); + trim_offset[i] = trim * (band << scale) >> 6; - celt_denormalize(f, block, f->block[i].coeffs); + if (ff_celt_freq_range[i] << f->size == 1) + trim_offset[i] -= f->channels << 3; } - /* stereo -> mono downmix */ - if (f->output_channels < f->channels) { - f->dsp->vector_fmac_scalar(f->block[0].coeffs, f->block[1].coeffs, 1.0, FFALIGN(frame_size, 16)); - downmix = 1; - } else if (f->output_channels > f->channels) - memcpy(f->block[1].coeffs, f->block[0].coeffs, frame_size * sizeof(float)); - - if (f->silence) { - for (i = 0; i < 2; i++) { - CeltBlock *block = &f->block[i]; - - for (j = 0; j < FF_ARRAY_ELEMS(block->energy); j++) - block->energy[j] = CELT_ENERGY_SILENCE; + /* Bisection */ + low = 1; + high = CELT_VECTORS - 1; + while (low <= high) { + int center = (low + high) >> 1; + done = total = 0; + + for (i = f->end_band - 1; i >= f->start_band; i--) { + bandbits = NORMC(ff_celt_freq_range[i] * ff_celt_static_alloc[center][i]); + + if (bandbits) + bandbits = FFMAX(bandbits + trim_offset[i], 0); + bandbits += boost[i]; + + if (bandbits >= threshold[i] || done) { + done = 1; + total += FFMIN(bandbits, f->caps[i]); + } else if (bandbits >= f->channels << 3) { + total += f->channels << 3; + } } - memset(f->block[0].coeffs, 0, sizeof(f->block[0].coeffs)); - memset(f->block[1].coeffs, 0, sizeof(f->block[1].coeffs)); - } - /* transform and output for each output channel */ - for (i = 0; i < f->output_channels; i++) { - CeltBlock *block = &f->block[i]; + if (total > tbits_8ths) + high = center - 1; + else + low = center + 1; + } + high = low--; - /* iMDCT and overlap-add */ - for (j = 0; j < f->blocks; j++) { - float *dst = block->buf + 1024 + j * f->blocksize; + /* Bisection */ + for (i = f->start_band; i < f->end_band; i++) { + bits1[i] = NORMC(ff_celt_freq_range[i] * ff_celt_static_alloc[low][i]); + bits2[i] = high >= CELT_VECTORS ? f->caps[i] : + NORMC(ff_celt_freq_range[i] * ff_celt_static_alloc[high][i]); + + if (bits1[i]) + bits1[i] = FFMAX(bits1[i] + trim_offset[i], 0); + if (bits2[i]) + bits2[i] = FFMAX(bits2[i] + trim_offset[i], 0); + + if (low) + bits1[i] += boost[i]; + bits2[i] += boost[i]; + + if (boost[i]) + skip_startband = i; + bits2[i] = FFMAX(bits2[i] - bits1[i], 0); + } - imdct_fn(imdct, dst + CELT_OVERLAP / 2, f->block[i].coeffs + j, - sizeof(float)*f->blocks); - f->dsp->vector_fmul_window(dst, dst, dst + CELT_OVERLAP / 2, - ff_celt_window, CELT_OVERLAP / 2); + /* Bisection */ + low = 0; + high = 1 << CELT_ALLOC_STEPS; + for (i = 0; i < CELT_ALLOC_STEPS; i++) { + int center = (low + high) >> 1; + done = total = 0; + + for (j = f->end_band - 1; j >= f->start_band; j--) { + bandbits = bits1[j] + (center * bits2[j] >> CELT_ALLOC_STEPS); + + if (bandbits >= threshold[j] || done) { + done = 1; + total += FFMIN(bandbits, f->caps[j]); + } else if (bandbits >= f->channels << 3) + total += f->channels << 3; } - - if (downmix) - f->dsp->vector_fmul_scalar(&block->buf[1024], &block->buf[1024], 0.5f, frame_size); - - /* postfilter */ - celt_postfilter(f, block); - - /* deemphasis */ - block->emph_coeff = f->opusdsp.deemphasis(output[i], - &block->buf[1024 - frame_size], - block->emph_coeff, frame_size); + if (total > tbits_8ths) + high = center; + else + low = center; } - if (channels == 1) - memcpy(f->block[1].energy, f->block[0].energy, sizeof(f->block[0].energy)); + /* Bisection */ + done = total = 0; + for (i = f->end_band - 1; i >= f->start_band; i--) { + bandbits = bits1[i] + (low * bits2[i] >> CELT_ALLOC_STEPS); - for (i = 0; i < 2; i++ ) { - CeltBlock *block = &f->block[i]; + if (bandbits >= threshold[i] || done) + done = 1; + else + bandbits = (bandbits >= f->channels << 3) ? + f->channels << 3 : 0; - if (!f->transient) { - memcpy(block->prev_energy[1], block->prev_energy[0], sizeof(block->prev_energy[0])); - memcpy(block->prev_energy[0], block->energy, sizeof(block->prev_energy[0])); - } else { - for (j = 0; j < CELT_MAX_BANDS; j++) - block->prev_energy[0][j] = FFMIN(block->prev_energy[0][j], block->energy[j]); - } - - for (j = 0; j < f->start_band; j++) { - block->prev_energy[0][j] = CELT_ENERGY_SILENCE; - block->energy[j] = 0.0; - } - for (j = f->end_band; j < CELT_MAX_BANDS; j++) { - block->prev_energy[0][j] = CELT_ENERGY_SILENCE; - block->energy[j] = 0.0; - } + bandbits = FFMIN(bandbits, f->caps[i]); + f->pulses[i] = bandbits; + total += bandbits; } - f->seed = rc->c.range; + /* Band skipping */ + for (f->coded_bands = f->end_band; ; f->coded_bands--) { + int allocation; + j = f->coded_bands - 1; - return 0; -} - -void ff_celt_flush(CeltFrame *f) -{ - int i, j; - - if (f->flushed) - return; + if (j == skip_startband) { + /* all remaining bands are not skipped */ + tbits_8ths += skip_bit; + break; + } - for (i = 0; i < 2; i++) { - CeltBlock *block = &f->block[i]; + /* determine the number of bits available for coding "do not skip" markers */ + remaining = tbits_8ths - total; + bandbits = remaining / (ff_celt_freq_bands[j+1] - ff_celt_freq_bands[f->start_band]); + remaining -= bandbits * (ff_celt_freq_bands[j+1] - ff_celt_freq_bands[f->start_band]); + allocation = f->pulses[j] + bandbits * ff_celt_freq_range[j]; + allocation += FFMAX(remaining - (ff_celt_freq_bands[j] - ff_celt_freq_bands[f->start_band]), 0); + + /* a "do not skip" marker is only coded if the allocation is + * above the chosen threshold */ + if (allocation >= FFMAX(threshold[j], (f->channels + 1) << 3)) { + int do_not_skip; + if (encode) { + do_not_skip = f->coded_bands <= f->skip_band_floor; + opus_rc_enc_log(rc, do_not_skip, 1); + } else { + do_not_skip = opus_rc_dec_log(rc, 1); + } - for (j = 0; j < CELT_MAX_BANDS; j++) - block->prev_energy[0][j] = block->prev_energy[1][j] = CELT_ENERGY_SILENCE; + if (do_not_skip) + break; - memset(block->energy, 0, sizeof(block->energy)); - memset(block->buf, 0, sizeof(block->buf)); + total += 1 << 3; + allocation -= 1 << 3; + } - memset(block->pf_gains, 0, sizeof(block->pf_gains)); - memset(block->pf_gains_old, 0, sizeof(block->pf_gains_old)); - memset(block->pf_gains_new, 0, sizeof(block->pf_gains_new)); + /* the band is skipped, so reclaim its bits */ + total -= f->pulses[j]; + if (intensitystereo_bit) { + total -= intensitystereo_bit; + intensitystereo_bit = ff_celt_log2_frac[j - f->start_band]; + total += intensitystereo_bit; + } - /* libopus uses CELT_EMPH_COEFF on init, but 0 is better since there's - * a lesser discontinuity when seeking. - * The deemphasis functions differ from libopus in that they require - * an initial state divided by the coefficient. */ - block->emph_coeff = 0.0f / CELT_EMPH_COEFF; + total += f->pulses[j] = (allocation >= f->channels << 3) ? f->channels << 3 : 0; } - f->seed = 0; - - f->flushed = 1; -} - -void ff_celt_free(CeltFrame **f) -{ - CeltFrame *frm = *f; - int i; - - if (!frm) - return; - for (i = 0; i < FF_ARRAY_ELEMS(frm->tx); i++) - av_tx_uninit(&frm->tx[i]); - - ff_celt_pvq_uninit(&frm->pvq); - - av_freep(&frm->dsp); - av_freep(f); -} - -int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, - int apply_phase_inv) -{ - CeltFrame *frm; - int i, ret; + /* IS start band */ + if (encode) { + if (intensitystereo_bit) { + f->intensity_stereo = FFMIN(f->intensity_stereo, f->coded_bands); + ff_opus_rc_enc_uint((OpusEncRangeCoder*)rc, f->intensity_stereo, f->coded_bands + 1 - f->start_band); + } + } else { + f->intensity_stereo = f->dual_stereo = 0; + if (intensitystereo_bit) + f->intensity_stereo = f->start_band + ff_opus_rc_dec_uint((OpusDecRangeCoder*)rc, f->coded_bands + 1 - f->start_band); + } - if (output_channels != 1 && output_channels != 2) { - av_log(avctx, AV_LOG_ERROR, "Invalid number of output channels: %d\n", - output_channels); - return AVERROR(EINVAL); + /* DS flag */ + if (f->intensity_stereo <= f->start_band) + tbits_8ths += dualstereo_bit; /* no intensity stereo means no dual stereo */ + else if (dualstereo_bit) + if (encode) + opus_rc_enc_log(rc, f->dual_stereo, 1); + else + f->dual_stereo = opus_rc_dec_log(rc, 1); + + /* Supply the remaining bits in this frame to lower bands */ + remaining = tbits_8ths - total; + bandbits = remaining / (ff_celt_freq_bands[f->coded_bands] - ff_celt_freq_bands[f->start_band]); + remaining -= bandbits * (ff_celt_freq_bands[f->coded_bands] - ff_celt_freq_bands[f->start_band]); + for (i = f->start_band; i < f->coded_bands; i++) { + const int bits = FFMIN(remaining, ff_celt_freq_range[i]); + f->pulses[i] += bits + bandbits * ff_celt_freq_range[i]; + remaining -= bits; } - frm = av_mallocz(sizeof(*frm)); - if (!frm) - return AVERROR(ENOMEM); + /* Finally determine the allocation */ + for (i = f->start_band; i < f->coded_bands; i++) { + int N = ff_celt_freq_range[i] << f->size; + int prev_extra = extrabits; + f->pulses[i] += extrabits; + + if (N > 1) { + int dof; /* degrees of freedom */ + int temp; /* dof * channels * log(dof) */ + int fine_bits; + int max_bits; + int offset; /* fine energy quantization offset, i.e. + * extra bits assigned over the standard + * totalbits/dof */ + + extrabits = FFMAX(f->pulses[i] - f->caps[i], 0); + f->pulses[i] -= extrabits; + + /* intensity stereo makes use of an extra degree of freedom */ + dof = N * f->channels + (f->channels == 2 && N > 2 && !f->dual_stereo && i < f->intensity_stereo); + temp = dof * (ff_celt_log_freq_range[i] + (f->size << 3)); + offset = (temp >> 1) - dof * CELT_FINE_OFFSET; + if (N == 2) /* dof=2 is the only case that doesn't fit the model */ + offset += dof << 1; + + /* grant an additional bias for the first and second pulses */ + if (f->pulses[i] + offset < 2 * (dof << 3)) + offset += temp >> 2; + else if (f->pulses[i] + offset < 3 * (dof << 3)) + offset += temp >> 3; + + fine_bits = (f->pulses[i] + offset + (dof << 2)) / (dof << 3); + max_bits = FFMIN((f->pulses[i] >> 3) >> (f->channels - 1), CELT_MAX_FINE_BITS); + max_bits = FFMAX(max_bits, 0); + f->fine_bits[i] = av_clip(fine_bits, 0, max_bits); + + /* If fine_bits was rounded down or capped, + * give priority for the final fine energy pass */ + f->fine_priority[i] = (f->fine_bits[i] * (dof << 3) >= f->pulses[i] + offset); + + /* the remaining bits are assigned to PVQ */ + f->pulses[i] -= f->fine_bits[i] << (f->channels - 1) << 3; + } else { + /* all bits go to fine energy except for the sign bit */ + extrabits = FFMAX(f->pulses[i] - (f->channels << 3), 0); + f->pulses[i] -= extrabits; + f->fine_bits[i] = 0; + f->fine_priority[i] = 1; + } - frm->avctx = avctx; - frm->output_channels = output_channels; - frm->apply_phase_inv = apply_phase_inv; + /* hand back a limited number of extra fine energy bits to this band */ + if (extrabits > 0) { + int fineextra = FFMIN(extrabits >> (f->channels + 2), + CELT_MAX_FINE_BITS - f->fine_bits[i]); + f->fine_bits[i] += fineextra; - for (i = 0; i < FF_ARRAY_ELEMS(frm->tx); i++) { - const float scale = -1.0f/32768; - if ((ret = av_tx_init(&frm->tx[i], &frm->tx_fn[i], AV_TX_FLOAT_MDCT, 1, 15 << (i + 3), &scale, 0)) < 0) - goto fail; + fineextra <<= f->channels + 2; + f->fine_priority[i] = (fineextra >= extrabits - prev_extra); + extrabits -= fineextra; + } } + f->remaining = extrabits; - if ((ret = ff_celt_pvq_init(&frm->pvq, 0)) < 0) - goto fail; - - frm->dsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); - if (!frm->dsp) { - ret = AVERROR(ENOMEM); - goto fail; + /* skipped bands dedicate all of their bits for fine energy */ + for (; i < f->end_band; i++) { + f->fine_bits[i] = f->pulses[i] >> (f->channels - 1) >> 3; + f->pulses[i] = 0; + f->fine_priority[i] = f->fine_bits[i] < 1; } - - ff_opus_dsp_init(&frm->opusdsp); - ff_celt_flush(frm); - - *f = frm; - - return 0; -fail: - ff_celt_free(&frm); - return ret; } diff --git a/libavcodec/opusdec_celt.c b/libavcodec/opusdec_celt.c new file mode 100644 index 0000000000..a14764ec18 --- /dev/null +++ b/libavcodec/opusdec_celt.c @@ -0,0 +1,587 @@ +/* + * Copyright (c) 2012 Andrew D'Addesio + * Copyright (c) 2013-2014 Mozilla Corporation + * Copyright (c) 2016 Rostislav Pehlivanov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Opus CELT decoder + */ + +#include + +#include "opus_celt.h" +#include "opusdec_rc.h" +#include "opustab.h" +#include "opus_pvq.h" + +/* Use the 2D z-transform to apply prediction in both the time domain (alpha) + * and the frequency domain (beta) */ +static void celt_decode_coarse_energy(CeltFrame *f, OpusDecRangeCoder *rc) +{ + int i, j; + float prev[2] = { 0 }; + float alpha = ff_celt_alpha_coef[f->size]; + float beta = ff_celt_beta_coef[f->size]; + const uint8_t *model = ff_celt_coarse_energy_dist[f->size][0]; + + /* intra frame */ + if (opus_rc_tell(&rc->c) + 3 <= f->framebits && ff_opus_rc_dec_log(rc, 3)) { + alpha = 0.0f; + beta = 1.0f - (4915.0f/32768.0f); + model = ff_celt_coarse_energy_dist[f->size][1]; + } + + for (i = 0; i < CELT_MAX_BANDS; i++) { + for (j = 0; j < f->channels; j++) { + CeltBlock *block = &f->block[j]; + float value; + int available; + + if (i < f->start_band || i >= f->end_band) { + block->energy[i] = 0.0; + continue; + } + + available = f->framebits - opus_rc_tell(&rc->c); + if (available >= 15) { + /* decode using a Laplace distribution */ + int k = FFMIN(i, 20) << 1; + value = ff_opus_rc_dec_laplace(rc, model[k] << 7, model[k+1] << 6); + } else if (available >= 2) { + int x = ff_opus_rc_dec_cdf(rc, ff_celt_model_energy_small); + value = (x>>1) ^ -(x&1); + } else if (available >= 1) { + value = -(float)ff_opus_rc_dec_log(rc, 1); + } else value = -1; + + block->energy[i] = FFMAX(-9.0f, block->energy[i]) * alpha + prev[j] + value; + prev[j] += beta * value; + } + } +} + +static void celt_decode_fine_energy(CeltFrame *f, OpusDecRangeCoder *rc) +{ + int i; + for (i = f->start_band; i < f->end_band; i++) { + int j; + if (!f->fine_bits[i]) + continue; + + for (j = 0; j < f->channels; j++) { + CeltBlock *block = &f->block[j]; + int q2; + float offset; + q2 = ff_opus_rc_get_raw(rc, f->fine_bits[i]); + offset = (q2 + 0.5f) * (1 << (14 - f->fine_bits[i])) / 16384.0f - 0.5f; + block->energy[i] += offset; + } + } +} + +static void celt_decode_final_energy(CeltFrame *f, OpusDecRangeCoder *rc) +{ + int priority, i, j; + int bits_left = f->framebits - opus_rc_tell(&rc->c); + + for (priority = 0; priority < 2; priority++) { + for (i = f->start_band; i < f->end_band && bits_left >= f->channels; i++) { + if (f->fine_priority[i] != priority || f->fine_bits[i] >= CELT_MAX_FINE_BITS) + continue; + + for (j = 0; j < f->channels; j++) { + int q2; + float offset; + q2 = ff_opus_rc_get_raw(rc, 1); + offset = (q2 - 0.5f) * (1 << (14 - f->fine_bits[i] - 1)) / 16384.0f; + f->block[j].energy[i] += offset; + bits_left--; + } + } + } +} + +static void celt_decode_tf_changes(CeltFrame *f, OpusDecRangeCoder *rc) +{ + int i, diff = 0, tf_select = 0, tf_changed = 0, tf_select_bit; + int consumed, bits = f->transient ? 2 : 4; + + consumed = opus_rc_tell(&rc->c); + tf_select_bit = (f->size != 0 && consumed+bits+1 <= f->framebits); + + for (i = f->start_band; i < f->end_band; i++) { + if (consumed+bits+tf_select_bit <= f->framebits) { + diff ^= ff_opus_rc_dec_log(rc, bits); + consumed = opus_rc_tell(&rc->c); + tf_changed |= diff; + } + f->tf_change[i] = diff; + bits = f->transient ? 4 : 5; + } + + if (tf_select_bit && ff_celt_tf_select[f->size][f->transient][0][tf_changed] != + ff_celt_tf_select[f->size][f->transient][1][tf_changed]) + tf_select = ff_opus_rc_dec_log(rc, 1); + + for (i = f->start_band; i < f->end_band; i++) { + f->tf_change[i] = ff_celt_tf_select[f->size][f->transient][tf_select][f->tf_change[i]]; + } +} + +static void celt_denormalize(CeltFrame *f, CeltBlock *block, float *data) +{ + int i, j; + + for (i = f->start_band; i < f->end_band; i++) { + float *dst = data + (ff_celt_freq_bands[i] << f->size); + float log_norm = block->energy[i] + ff_celt_mean_energy[i]; + float norm = exp2f(FFMIN(log_norm, 32.0f)); + + for (j = 0; j < ff_celt_freq_range[i] << f->size; j++) + dst[j] *= norm; + } +} + +static void celt_postfilter_apply_transition(CeltBlock *block, float *data) +{ + const int T0 = block->pf_period_old; + const int T1 = block->pf_period; + + float g00, g01, g02; + float g10, g11, g12; + + float x0, x1, x2, x3, x4; + + int i; + + if (block->pf_gains[0] == 0.0 && + block->pf_gains_old[0] == 0.0) + return; + + g00 = block->pf_gains_old[0]; + g01 = block->pf_gains_old[1]; + g02 = block->pf_gains_old[2]; + g10 = block->pf_gains[0]; + g11 = block->pf_gains[1]; + g12 = block->pf_gains[2]; + + x1 = data[-T1 + 1]; + x2 = data[-T1]; + x3 = data[-T1 - 1]; + x4 = data[-T1 - 2]; + + for (i = 0; i < CELT_OVERLAP; i++) { + float w = ff_celt_window2[i]; + x0 = data[i - T1 + 2]; + + data[i] += (1.0 - w) * g00 * data[i - T0] + + (1.0 - w) * g01 * (data[i - T0 - 1] + data[i - T0 + 1]) + + (1.0 - w) * g02 * (data[i - T0 - 2] + data[i - T0 + 2]) + + w * g10 * x2 + + w * g11 * (x1 + x3) + + w * g12 * (x0 + x4); + x4 = x3; + x3 = x2; + x2 = x1; + x1 = x0; + } +} + +static void celt_postfilter(CeltFrame *f, CeltBlock *block) +{ + int len = f->blocksize * f->blocks; + const int filter_len = len - 2 * CELT_OVERLAP; + + celt_postfilter_apply_transition(block, block->buf + 1024); + + block->pf_period_old = block->pf_period; + memcpy(block->pf_gains_old, block->pf_gains, sizeof(block->pf_gains)); + + block->pf_period = block->pf_period_new; + memcpy(block->pf_gains, block->pf_gains_new, sizeof(block->pf_gains)); + + if (len > CELT_OVERLAP) { + celt_postfilter_apply_transition(block, block->buf + 1024 + CELT_OVERLAP); + + if (block->pf_gains[0] > FLT_EPSILON && filter_len > 0) + f->opusdsp.postfilter(block->buf + 1024 + 2 * CELT_OVERLAP, + block->pf_period, block->pf_gains, + filter_len); + + block->pf_period_old = block->pf_period; + memcpy(block->pf_gains_old, block->pf_gains, sizeof(block->pf_gains)); + } + + memmove(block->buf, block->buf + len, (1024 + CELT_OVERLAP / 2) * sizeof(float)); +} + +static int parse_postfilter(CeltFrame *f, OpusDecRangeCoder *rc, int consumed) +{ + int i; + + memset(f->block[0].pf_gains_new, 0, sizeof(f->block[0].pf_gains_new)); + memset(f->block[1].pf_gains_new, 0, sizeof(f->block[1].pf_gains_new)); + + if (f->start_band == 0 && consumed + 16 <= f->framebits) { + int has_postfilter = ff_opus_rc_dec_log(rc, 1); + if (has_postfilter) { + float gain; + int tapset, octave, period; + + octave = ff_opus_rc_dec_uint(rc, 6); + period = (16 << octave) + ff_opus_rc_get_raw(rc, 4 + octave) - 1; + gain = 0.09375f * (ff_opus_rc_get_raw(rc, 3) + 1); + tapset = (opus_rc_tell(&rc->c) + 2 <= f->framebits) ? + ff_opus_rc_dec_cdf(rc, ff_celt_model_tapset) : 0; + + for (i = 0; i < 2; i++) { + CeltBlock *block = &f->block[i]; + + block->pf_period_new = FFMAX(period, CELT_POSTFILTER_MINPERIOD); + block->pf_gains_new[0] = gain * ff_celt_postfilter_taps[tapset][0]; + block->pf_gains_new[1] = gain * ff_celt_postfilter_taps[tapset][1]; + block->pf_gains_new[2] = gain * ff_celt_postfilter_taps[tapset][2]; + } + } + + consumed = opus_rc_tell(&rc->c); + } + + return consumed; +} + +static void process_anticollapse(CeltFrame *f, CeltBlock *block, float *X) +{ + int i, j, k; + + for (i = f->start_band; i < f->end_band; i++) { + int renormalize = 0; + float *xptr; + float prev[2]; + float Ediff, r; + float thresh, sqrt_1; + int depth; + + /* depth in 1/8 bits */ + depth = (1 + f->pulses[i]) / (ff_celt_freq_range[i] << f->size); + thresh = exp2f(-1.0 - 0.125f * depth); + sqrt_1 = 1.0f / sqrtf(ff_celt_freq_range[i] << f->size); + + xptr = X + (ff_celt_freq_bands[i] << f->size); + + prev[0] = block->prev_energy[0][i]; + prev[1] = block->prev_energy[1][i]; + if (f->channels == 1) { + CeltBlock *block1 = &f->block[1]; + + prev[0] = FFMAX(prev[0], block1->prev_energy[0][i]); + prev[1] = FFMAX(prev[1], block1->prev_energy[1][i]); + } + Ediff = block->energy[i] - FFMIN(prev[0], prev[1]); + Ediff = FFMAX(0, Ediff); + + /* r needs to be multiplied by 2 or 2*sqrt(2) depending on LM because + short blocks don't have the same energy as long */ + r = exp2f(1 - Ediff); + if (f->size == 3) + r *= M_SQRT2; + r = FFMIN(thresh, r) * sqrt_1; + for (k = 0; k < 1 << f->size; k++) { + /* Detect collapse */ + if (!(block->collapse_masks[i] & 1 << k)) { + /* Fill with noise */ + for (j = 0; j < ff_celt_freq_range[i]; j++) + xptr[(j << f->size) + k] = (celt_rng(f) & 0x8000) ? r : -r; + renormalize = 1; + } + } + + /* We just added some energy, so we need to renormalize */ + if (renormalize) + celt_renormalize_vector(xptr, ff_celt_freq_range[i] << f->size, 1.0f); + } +} + +int ff_celt_decode_frame(CeltFrame *f, OpusDecRangeCoder *rc, + float **output, int channels, int frame_size, + int start_band, int end_band) +{ + int i, j, downmix = 0; + int consumed; // bits of entropy consumed thus far for this frame + AVTXContext *imdct; + av_tx_fn imdct_fn; + + if (channels != 1 && channels != 2) { + av_log(f->avctx, AV_LOG_ERROR, "Invalid number of coded channels: %d\n", + channels); + return AVERROR_INVALIDDATA; + } + if (start_band < 0 || start_band > end_band || end_band > CELT_MAX_BANDS) { + av_log(f->avctx, AV_LOG_ERROR, "Invalid start/end band: %d %d\n", + start_band, end_band); + return AVERROR_INVALIDDATA; + } + + f->silence = 0; + f->transient = 0; + f->anticollapse = 0; + f->flushed = 0; + f->channels = channels; + f->start_band = start_band; + f->end_band = end_band; + f->framebits = rc->c.rb.bytes * 8; + + f->size = av_log2(frame_size / CELT_SHORT_BLOCKSIZE); + if (f->size > CELT_MAX_LOG_BLOCKS || + frame_size != CELT_SHORT_BLOCKSIZE * (1 << f->size)) { + av_log(f->avctx, AV_LOG_ERROR, "Invalid CELT frame size: %d\n", + frame_size); + return AVERROR_INVALIDDATA; + } + + if (!f->output_channels) + f->output_channels = channels; + + for (i = 0; i < f->channels; i++) { + memset(f->block[i].coeffs, 0, sizeof(f->block[i].coeffs)); + memset(f->block[i].collapse_masks, 0, sizeof(f->block[i].collapse_masks)); + } + + consumed = opus_rc_tell(&rc->c); + + /* obtain silence flag */ + if (consumed >= f->framebits) + f->silence = 1; + else if (consumed == 1) + f->silence = ff_opus_rc_dec_log(rc, 15); + + + if (f->silence) { + consumed = f->framebits; + rc->c.total_bits += f->framebits - opus_rc_tell(&rc->c); + } + + /* obtain post-filter options */ + consumed = parse_postfilter(f, rc, consumed); + + /* obtain transient flag */ + if (f->size != 0 && consumed+3 <= f->framebits) + f->transient = ff_opus_rc_dec_log(rc, 3); + + f->blocks = f->transient ? 1 << f->size : 1; + f->blocksize = frame_size / f->blocks; + + imdct = f->tx[f->transient ? 0 : f->size]; + imdct_fn = f->tx_fn[f->transient ? 0 : f->size]; + + if (channels == 1) { + for (i = 0; i < CELT_MAX_BANDS; i++) + f->block[0].energy[i] = FFMAX(f->block[0].energy[i], f->block[1].energy[i]); + } + + celt_decode_coarse_energy(f, rc); + celt_decode_tf_changes (f, rc); + ff_celt_bitalloc (f, &rc->c, 0); + celt_decode_fine_energy (f, rc); + ff_celt_quant_bands (f, &rc->c); + + if (f->anticollapse_needed) + f->anticollapse = ff_opus_rc_get_raw(rc, 1); + + celt_decode_final_energy(f, rc); + + /* apply anti-collapse processing and denormalization to + * each coded channel */ + for (i = 0; i < f->channels; i++) { + CeltBlock *block = &f->block[i]; + + if (f->anticollapse) + process_anticollapse(f, block, f->block[i].coeffs); + + celt_denormalize(f, block, f->block[i].coeffs); + } + + /* stereo -> mono downmix */ + if (f->output_channels < f->channels) { + f->dsp->vector_fmac_scalar(f->block[0].coeffs, f->block[1].coeffs, 1.0, FFALIGN(frame_size, 16)); + downmix = 1; + } else if (f->output_channels > f->channels) + memcpy(f->block[1].coeffs, f->block[0].coeffs, frame_size * sizeof(float)); + + if (f->silence) { + for (i = 0; i < 2; i++) { + CeltBlock *block = &f->block[i]; + + for (j = 0; j < FF_ARRAY_ELEMS(block->energy); j++) + block->energy[j] = CELT_ENERGY_SILENCE; + } + memset(f->block[0].coeffs, 0, sizeof(f->block[0].coeffs)); + memset(f->block[1].coeffs, 0, sizeof(f->block[1].coeffs)); + } + + /* transform and output for each output channel */ + for (i = 0; i < f->output_channels; i++) { + CeltBlock *block = &f->block[i]; + + /* iMDCT and overlap-add */ + for (j = 0; j < f->blocks; j++) { + float *dst = block->buf + 1024 + j * f->blocksize; + + imdct_fn(imdct, dst + CELT_OVERLAP / 2, f->block[i].coeffs + j, + sizeof(float)*f->blocks); + f->dsp->vector_fmul_window(dst, dst, dst + CELT_OVERLAP / 2, + ff_celt_window, CELT_OVERLAP / 2); + } + + if (downmix) + f->dsp->vector_fmul_scalar(&block->buf[1024], &block->buf[1024], 0.5f, frame_size); + + /* postfilter */ + celt_postfilter(f, block); + + /* deemphasis */ + block->emph_coeff = f->opusdsp.deemphasis(output[i], + &block->buf[1024 - frame_size], + block->emph_coeff, frame_size); + } + + if (channels == 1) + memcpy(f->block[1].energy, f->block[0].energy, sizeof(f->block[0].energy)); + + for (i = 0; i < 2; i++ ) { + CeltBlock *block = &f->block[i]; + + if (!f->transient) { + memcpy(block->prev_energy[1], block->prev_energy[0], sizeof(block->prev_energy[0])); + memcpy(block->prev_energy[0], block->energy, sizeof(block->prev_energy[0])); + } else { + for (j = 0; j < CELT_MAX_BANDS; j++) + block->prev_energy[0][j] = FFMIN(block->prev_energy[0][j], block->energy[j]); + } + + for (j = 0; j < f->start_band; j++) { + block->prev_energy[0][j] = CELT_ENERGY_SILENCE; + block->energy[j] = 0.0; + } + for (j = f->end_band; j < CELT_MAX_BANDS; j++) { + block->prev_energy[0][j] = CELT_ENERGY_SILENCE; + block->energy[j] = 0.0; + } + } + + f->seed = rc->c.range; + + return 0; +} + +void ff_celt_flush(CeltFrame *f) +{ + int i, j; + + if (f->flushed) + return; + + for (i = 0; i < 2; i++) { + CeltBlock *block = &f->block[i]; + + for (j = 0; j < CELT_MAX_BANDS; j++) + block->prev_energy[0][j] = block->prev_energy[1][j] = CELT_ENERGY_SILENCE; + + memset(block->energy, 0, sizeof(block->energy)); + memset(block->buf, 0, sizeof(block->buf)); + + memset(block->pf_gains, 0, sizeof(block->pf_gains)); + memset(block->pf_gains_old, 0, sizeof(block->pf_gains_old)); + memset(block->pf_gains_new, 0, sizeof(block->pf_gains_new)); + + /* libopus uses CELT_EMPH_COEFF on init, but 0 is better since there's + * a lesser discontinuity when seeking. + * The deemphasis functions differ from libopus in that they require + * an initial state divided by the coefficient. */ + block->emph_coeff = 0.0f / CELT_EMPH_COEFF; + } + f->seed = 0; + + f->flushed = 1; +} + +void ff_celt_free(CeltFrame **f) +{ + CeltFrame *frm = *f; + int i; + + if (!frm) + return; + + for (i = 0; i < FF_ARRAY_ELEMS(frm->tx); i++) + av_tx_uninit(&frm->tx[i]); + + ff_celt_pvq_uninit(&frm->pvq); + + av_freep(&frm->dsp); + av_freep(f); +} + +int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, + int apply_phase_inv) +{ + CeltFrame *frm; + int i, ret; + + if (output_channels != 1 && output_channels != 2) { + av_log(avctx, AV_LOG_ERROR, "Invalid number of output channels: %d\n", + output_channels); + return AVERROR(EINVAL); + } + + frm = av_mallocz(sizeof(*frm)); + if (!frm) + return AVERROR(ENOMEM); + + frm->avctx = avctx; + frm->output_channels = output_channels; + frm->apply_phase_inv = apply_phase_inv; + + for (i = 0; i < FF_ARRAY_ELEMS(frm->tx); i++) { + const float scale = -1.0f/32768; + if ((ret = av_tx_init(&frm->tx[i], &frm->tx_fn[i], AV_TX_FLOAT_MDCT, 1, 15 << (i + 3), &scale, 0)) < 0) + goto fail; + } + + if ((ret = ff_celt_pvq_init(&frm->pvq, 0)) < 0) + goto fail; + + frm->dsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); + if (!frm->dsp) { + ret = AVERROR(ENOMEM); + goto fail; + } + + ff_opus_dsp_init(&frm->opusdsp); + ff_celt_flush(frm); + + *f = frm; + + return 0; +fail: + ff_celt_free(&frm); + return ret; +} From patchwork Fri Oct 7 20:25:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38614 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp206226pzc; Fri, 7 Oct 2022 13:26:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7wuiCnZ0qo5uDG/TbNqdXTHxDN0BMxV0oeF0i4qExkDuxtMqbw1xhXdsQ4/uxZPilSwKYO X-Received: by 2002:a05:6402:1604:b0:458:b2b7:bd5a with SMTP id f4-20020a056402160400b00458b2b7bd5amr6010326edv.73.1665174386604; Fri, 07 Oct 2022 13:26:26 -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 mp14-20020a1709071b0e00b00783204942e5si3665548ejc.885.2022.10.07.13.26.26; Fri, 07 Oct 2022 13:26:26 -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=JsOVM88g; 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 C80AF68BBFD; Fri, 7 Oct 2022 23:25:50 +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-am6eur05olkn2027.outbound.protection.outlook.com [40.92.91.27]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8F27B68BB66 for ; Fri, 7 Oct 2022 23:25:49 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DZTOtb4wpVFp0h/Ras35KTDgUvgnwxo7aeZVgVSla4fswr2xRr+cfURqRVA9yu/uSoXCW22gDOdsThUcgWCDjvN3vdiQPQ5bR7o8V+PYY68o7hqQYReQsjgGXByLhLp9s3a4d6m8rkThOH/2c1DVNRPY9piLMI3jhu+sIkEKuqTqQaNuMPzq8rzzx+JomljL/yJxEsVqp8O70J6YO4DWpyqyOgxkbyPwKWsiSJ/HXsDaV9TQTIyJeY1PgrNX6XN8VpcuGjt7Sxa6avfILAXs5cfTMzp7G7EW558qHKQFD6vyN0HTYw4AyO3ovr7DVhnKpCBEOGBodsMDoLCl3bggCw== 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=wxaGL7JehcgOWKnyZseMdYYCbX6U+mAhgTq5dbsXfrY=; b=WUkZbfSTh5QPR0vvTsUYxgp8t8tKFKiWlWWlY24HTza8bfJ0EmT2BkrqoSD+ggK0Seu0/T6VMTnU6acF5TaP2Lru6xuziILDTOE/QLrXO7NGB0yM/MaECoc1+geophrq/aq3Ls7WICZZJ9SteINGcut6Acfc9iLSwR3kf5vTESy9pHNpYYpK09WEBTDTrehRtQO+GTaD49XG8ULYPwJOODKRr0ORYI4mfiELCktqtic38xq1HeIXzfIoTWHCOkrMa+ucTOkEQ7db4+4uElLmcXRq5wqzc5oAN1alB28j1ukOg443CJgQGNRbrNoq93vlpU0oew7I72pp3/P8p8LqtQ== 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=wxaGL7JehcgOWKnyZseMdYYCbX6U+mAhgTq5dbsXfrY=; b=JsOVM88g4GdDHRKjAygWtXR0zruVj4Anfx0+xauBzpFgAePxqC1KTMxb5SlYZSujqfduknG9PXEhXWVKA+iBtBKtG8pN8G0u4ns0VUfKKRNWHHfj9dUxGQlXizSZrye5Qj+n2u1MBph9Rdx8ELiEqRdEPzDzxobNps7X6S0lH5b+7ff9kWq2fBQlJa+cJRx1mtp0PK1FPpY34nVFhMENGTVXAIcxkbhqt5S05Dzr8xpCvE4PuTPplbeVahgmJLMI55yEKbKnmXUmSsqrtOfvet7gSOlhdiigNF5DGgZ/yz1PCl3h5AheT8q+xXjqih1gek2V00kPqvMThSmX+sHVoQ== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0285.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Fri, 7 Oct 2022 20:25:47 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.028; Fri, 7 Oct 2022 20:25:47 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 22:25:08 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [ZYaCX5qbu62DN05Tk5QrVctWA/CC9XaGJkOMIxVT1CM=] X-ClientProxiedBy: ZR0P278CA0106.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:23::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221007202508.4188148-8-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0285:EE_ X-MS-Office365-Filtering-Correlation-Id: c01feb82-964d-4a03-5c7c-08daa8a21e77 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmpXYlgiiriwpqBJSiirmy7K/np4/kextCOtHBL6l87Ud5nGvGfDuHCyR9knAek64QPkIADnbQcW+lIf77npK+tLn0MPrHBXnm1PkX8FeDUBoxIEtIQJjaoDAesTfXvLKG3rFdzxkIpe/xAKo+EKkGIPycCvRFqt5ISel1u194ngOq6ZhgLRPV2aDhxTuwGl+9JpZiiS81mid0IR29WF5FXT53VPtC7y5JXtzUWLAwhPoIFgv3jFrY2CBqi8r6IFfdrswiMWqtuERGKrsrg/MRVCDoS/MMylgCl2tRvGB0u/TN06wnPicRkkoYrxbsJRDFmz9AKG74I8ccJN1+o5d4CNl56CsS2OOsINoZ9CQTsFiX3p06X/WcHLlcG/JlzKKQbJms/tikk5le/pj9fEzrYk9qDwxw7smeMnDdrjIdtScSBNIlelQgrAPrMgubbUNi3xzViMaa4PtyJD7wWfidIYsPYHmzL7aCQCxcv57ynioiPe1bsXL19XVg7PXV+Xeeq1yZ9avHdgnVdOuOOrq+oI1SVg9SNLNi1pL29pNbpTa1T0bBiZmdQ/hPVHYezlHmJji5OkU4bsuymyTWgrE4Iw2a3EIT8pANdpdl/98gLsbwc9zAsxfEWAHUeD1Khess7AdY4bRtIW2HsYtFdr7vbh15errBm8IB1GJiik6/e+H+PNwl6XPUhgppnlKW+teGOHCQyQGEgu9Stww6EZs4TI5M9ZVK9fBmzxZbQixGIr/vGK3hWMd0yueR5U1WhrEhw= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 21cr7jB/9L96Dgz6/tpGEjbdMIvBUlsq9Xcpq6r02xTD1qycitOfK9rF5IadyeaU1NXxpJiud84hCVTOKrHrfe5naYVOio48howp24O9ALzJzJPVTZYlT7aeiUiA+vojwYPn2CJUJMke/yhVYr9zFsgXxVisstD6cLI7PY8s4OH03RgnaZ7EVz4j5CvWF4BYmcL0rYq9YSZDIYQHwAiGu6w05ZBCzyu0hAVwf1Ypv3U/dGi35/n6H2TxUsW6Wxxm1gx8oLWC5Xy867V0pRG/3zWtmp7C/IkGKZ7JoO6b+WOFzemV2GaHHXX46zbjOVsW2khNor8cVJG7CvEkqF/0eF37vAy0KqYCNDIrNpoUJU1PeBQuHgpbHseuvb0i6IA+JTXQmT20pyjG2XBsSBIU5HtQ6iyiA0w0MFZKaRqte1YDNwEC3FNKWcO4pznhLOokSoxy47tDjee/DaOqFcCcDnPUzKJjaRuWiXNdWQoHix13b52EO7Pfy8iF/KAh+kuW7rzSRZkk0meCdPrc03nVAUKaVTA4RVZwpUYLOoHewkRW0bu/nEOJzbbNW7e4tj5gAN3ZXZ2/6v1KSqIb0eh66kvvkh18YyPjVMb1+yNY3P1cl6/vlPTV/DPJltdfDkz7VSM46nPBJ8wqdVNRIXfW/DTLeo8aQhIq0ntTD0Ll84aFhIQCP+Y/ywsvkTdtAITe X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: t++9cxWpFNcYlFVWBcP2i0pwUCLIORRcHirl0tF13v8s/sKTzXhqDgiFoUfiNfaozgsOEPOMfcX49B8FcErykTHUcf4IEv2wYpGXkruvpfPywz1vEq0i84YROaqD3R3s9Zz4UG4QU7zjXfg4WX0EOF2sMl9RHpYhNNU0KQGh2hTejACwmnEMO6CFJJIFQ+dvb5o7Xe/olAaqioNNOwCNJY26xnr22KZfn9elCnat/h5hQvVhBOVBcMI+FTiJt7Nzwrso37dvqHJXmn+QouQpPcZsX7pF4v4TXCE2InY1WY658DihHDkpggt4poBWqPBpNZcz7fyiyR39WSU2B9sd5tm+Ko6YV3kmSHvFZekn9ZXyn6bVNSb4C9BklbSQSLJ6D0YYXSZYMdVDkznGeEUlZEYVZOsWZXKE71JVaB8emQfHxDK1Jc/N+fVOduw3LVK2BhsrVTQWHGM3gGq+IhxbJRCI8e5sIf3/glk0pCJNQPQ22nXQDUbx9YnJ+h4WWB3/tl30C7nACsBAx9j19WVcmTsoO5jz/h3kbYWQKp2h4YUaoyEiRXhjnUZcQtvmHe8RVuDYzyDnaAEbmzRLswXMI/a+aGmymINsYW8YxLaoQrbHzZC0MhMsgAVPXQBk/v7fhQgbBEtafZJp+yLunCb8h8u/FpZswq4qO9BbUi9pOYtA+vEhJvrH+z8BTegZmZwrTdAyRcIc0KdM6CvG0pK1Y5iUEyfGpkO/eLFcpSbCQ2Hs79z3y9766tE8rPpIyUOLBLh/82qLYqbSZpuKe6XKF4ZGwUgNGtap2B2+wLdeMkJKQqLh/vbNaSwkL0/kIAEoyI+6bkdioq9GM56trgqGFDd/SlFxNs8zkx0dOw8af57/jCYmoKLApLsFa98UkFQiiJ3zKuZ9WrR1OhRrg5AYNklmPp5pGQI7cujtL0b+RamWPKoUFwQWm1zSeDFsmWpuNEztPVY8yMrYXtgNa1wqTc6sRrKzFfAyyxQXQ6qRtdMfQspgd37EXMDJJXMSUJ9ReB3tho2dqy2zYoNt2AvVtuNP0AQOmkYQY1JWFrKJHZuKee9PkSj2Wjw9g7Wp5EMec5+zt8XpFLV8s/G7IE2lYFEcVhG1xjrmWxFk73SOMJc9+l8/gOH/Z/E5H7icu8n6B5bAl8CZAa+3qoD1q3iTYPqQz5DfxXLsePYJ7/CEQPKA9f+NuKVzC2vmej0no/4DSWjUr5L+V7BkJBWAQ13si0NA0e8u7h7tM4J61JitgvhI5kci6VfsMFsudM3Y9jf/4djWZ7zq9Mu0+iZ1N119s4M0/+oG4fNVJl6PHxDK0go= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c01feb82-964d-4a03-5c7c-08daa8a21e77 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 20:25:47.7215 (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: DU2P250MB0285 Subject: [FFmpeg-devel] [PATCH 9/9] avcodec/opus_pvq: Avoid indirection when possible 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: 0X87aGZvB/0P Signed-off-by: Andreas Rheinhardt --- libavcodec/opus_pvq.c | 4 ++-- libavcodec/opus_pvq.h | 3 +++ libavcodec/opus_pvq_template.c | 35 ++++++++++++++++++---------------- libavcodec/opusenc_psy.c | 12 ++++++------ 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/libavcodec/opus_pvq.c b/libavcodec/opus_pvq.c index 8ef0f85a81..26d4e436e1 100644 --- a/libavcodec/opus_pvq.c +++ b/libavcodec/opus_pvq.c @@ -511,9 +511,9 @@ int av_cold ff_celt_pvq_init(CeltPVQ **pvq, int encode) #if CONFIG_OPUS_ENCODER #if CONFIG_OPUS_DECODER - s->quant_band = encode ? pvq_quant_band_enc : pvq_quant_band_dec; + s->quant_band = encode ? ff_pvq_quant_band_enc : pvq_quant_band_dec; #else - s->quant_band = pvq_quant_band_enc; + s->quant_band = ff_pvq_quant_band_enc; #endif s->pvq_search = ppp_pvq_search_c; #if ARCH_X86 diff --git a/libavcodec/opus_pvq.h b/libavcodec/opus_pvq.h index b71bc49034..4907025125 100644 --- a/libavcodec/opus_pvq.h +++ b/libavcodec/opus_pvq.h @@ -26,6 +26,7 @@ #include "libavutil/mem_internal.h" #include "opus_celt.h" +#include "opus_rc.h" #define QUANT_FN(name) uint32_t (name)(struct CeltPVQ *pvq, CeltFrame *f, \ OpusRangeCoder *rc, const int band, float *X, \ @@ -47,4 +48,6 @@ void ff_celt_pvq_init_x86(struct CeltPVQ *s); int ff_celt_pvq_init(struct CeltPVQ **pvq, int encode); void ff_celt_pvq_uninit(struct CeltPVQ **pvq); +QUANT_FN(ff_pvq_quant_band_enc); + #endif /* AVCODEC_OPUS_PVQ_H */ diff --git a/libavcodec/opus_pvq_template.c b/libavcodec/opus_pvq_template.c index 5f03f3d415..79e8e4ca52 100644 --- a/libavcodec/opus_pvq_template.c +++ b/libavcodec/opus_pvq_template.c @@ -24,14 +24,17 @@ */ #undef FUNC +#undef STATIC #if ENCODING -#define FUNC(name) name ## _enc +#define STATIC +#define FUNC(name) ff_ ## name ## _enc #else +#define STATIC static #define FUNC(name) name ## _dec #endif -static +STATIC uint32_t FUNC(pvq_quant_band)(CeltPVQ *const pvq, CeltFrame *const f, OpusRangeCoder *const rc, const int band, float *X, @@ -256,8 +259,8 @@ uint32_t FUNC(pvq_quant_band)(CeltPVQ *const pvq, CeltFrame *const f, sign = 1 - 2 * sign; /* We use orig_fill here because we want to fold the side, but if itheta==16384, we'll have cleared the low bits of fill. */ - cm = pvq->quant_band(pvq, f, rc, band, x2, NULL, N, mbits, blocks, lowband, duration, - lowband_out, level, gain, lowband_scratch, orig_fill); + cm = FUNC(pvq_quant_band)(pvq, f, rc, band, x2, NULL, N, mbits, blocks, lowband, duration, + lowband_out, level, gain, lowband_scratch, orig_fill); /* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse), and there's no need to worry about mixing with the other channel. */ y2[0] = -sign * x2[1]; @@ -309,25 +312,25 @@ uint32_t FUNC(pvq_quant_band)(CeltPVQ *const pvq, CeltFrame *const f, if (mbits >= sbits) { /* In stereo mode, we do not apply a scaling to the mid * because we need the normalized mid for folding later */ - cm = pvq->quant_band(pvq, f, rc, band, X, NULL, N, mbits, blocks, - lowband, duration, next_lowband_out1, next_level, - stereo ? 1.0f : (gain * mid), lowband_scratch, fill); + cm = FUNC(pvq_quant_band)(pvq, f, rc, band, X, NULL, N, mbits, blocks, + lowband, duration, next_lowband_out1, next_level, + stereo ? 1.0f : (gain * mid), lowband_scratch, fill); rebalance = mbits - (rebalance - f->remaining2); if (rebalance > 3 << 3 && itheta != 0) sbits += rebalance - (3 << 3); /* For a stereo split, the high bits of fill are always zero, * so no folding will be done to the side. */ - cmt = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks, - next_lowband2, duration, NULL, next_level, - gain * side, NULL, fill >> blocks); + cmt = FUNC(pvq_quant_band)(pvq, f, rc, band, Y, NULL, N, sbits, blocks, + next_lowband2, duration, NULL, next_level, + gain * side, NULL, fill >> blocks); cm |= cmt << ((B0 >> 1) & (stereo - 1)); } else { /* For a stereo split, the high bits of fill are always zero, * so no folding will be done to the side. */ - cm = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks, - next_lowband2, duration, NULL, next_level, - gain * side, NULL, fill >> blocks); + cm = FUNC(pvq_quant_band)(pvq, f, rc, band, Y, NULL, N, sbits, blocks, + next_lowband2, duration, NULL, next_level, + gain * side, NULL, fill >> blocks); cm <<= ((B0 >> 1) & (stereo - 1)); rebalance = sbits - (rebalance - f->remaining2); if (rebalance > 3 << 3 && itheta != 16384) @@ -335,9 +338,9 @@ uint32_t FUNC(pvq_quant_band)(CeltPVQ *const pvq, CeltFrame *const f, /* In stereo mode, we do not apply a scaling to the mid because * we need the normalized mid for folding later */ - cm |= pvq->quant_band(pvq, f, rc, band, X, NULL, N, mbits, blocks, - lowband, duration, next_lowband_out1, next_level, - stereo ? 1.0f : (gain * mid), lowband_scratch, fill); + cm |= FUNC(pvq_quant_band)(pvq, f, rc, band, X, NULL, N, mbits, blocks, + lowband, duration, next_lowband_out1, next_level, + stereo ? 1.0f : (gain * mid), lowband_scratch, fill); } } } else { diff --git a/libavcodec/opusenc_psy.c b/libavcodec/opusenc_psy.c index 17a2efd8d5..0ec915d3c5 100644 --- a/libavcodec/opusenc_psy.c +++ b/libavcodec/opusenc_psy.c @@ -54,14 +54,14 @@ static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusEncRangeCoder *rce, i } if (f->dual_stereo) { - pvq->quant_band(pvq, f, rc, band, X, NULL, band_size, b / 2, f->blocks, NULL, - f->size, norm1, 0, 1.0f, lowband_scratch, cm[0]); + ff_pvq_quant_band_enc(pvq, f, rc, band, X, NULL, band_size, b / 2, f->blocks, NULL, + f->size, norm1, 0, 1.0f, lowband_scratch, cm[0]); - pvq->quant_band(pvq, f, rc, band, Y, NULL, band_size, b / 2, f->blocks, NULL, - f->size, norm2, 0, 1.0f, lowband_scratch, cm[1]); + ff_pvq_quant_band_enc(pvq, f, rc, band, Y, NULL, band_size, b / 2, f->blocks, NULL, + f->size, norm2, 0, 1.0f, lowband_scratch, cm[1]); } else { - pvq->quant_band(pvq, f, rc, band, X, Y, band_size, b, f->blocks, NULL, f->size, - norm1, 0, 1.0f, lowband_scratch, cm[0] | cm[1]); + ff_pvq_quant_band_enc(pvq, f, rc, band, X, Y, band_size, b, f->blocks, NULL, f->size, + norm1, 0, 1.0f, lowband_scratch, cm[0] | cm[1]); } for (i = 0; i < band_size; i++) {