From patchwork Sat Sep 3 20:35:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37638 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp1748081pzh; Sat, 3 Sep 2022 13:36:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR7HijDnd2gH6J0IX/s+hNBEL5jvMsA9oWgrCZnm4thTNwpvTxbzM5Vp+JF8XvmD+M6wVbMN X-Received: by 2002:a17:907:9812:b0:742:2865:eca8 with SMTP id ji18-20020a170907981200b007422865eca8mr16137972ejc.537.1662237387298; Sat, 03 Sep 2022 13:36:27 -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 sb28-20020a1709076d9c00b007413d6c7ebcsi3333948ejc.362.2022.09.03.13.36.26; Sat, 03 Sep 2022 13:36:27 -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=Xy3e9hVG; 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 3DDDC68B411; Sat, 3 Sep 2022 23:36:18 +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-oln040092065072.outbound.protection.outlook.com [40.92.65.72]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2794368009F for ; Sat, 3 Sep 2022 23:36:11 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cVKU7bLq8Zv1hg1lNCZcrUGnx7eHkuBxWMbg3WH2lVuCKYGIboPEOVLLX8lzP+BZvALlNZtKhD3KdWUCIxDJeMMf+Q0Qo0sO5OgFVjK94/K8MSwc3e+qynBcQxqOWV1z/f1GTDUvu3BaQ8qq0nW3/Aq8iFReTgQlpZ6uOh9uAEEvekjxfQsA887W/QDBZAFpk6uFcWmonJJ8j90mb4mKlausiH7NWqCuPRmBLFSwmmJ1hkut6EFgTCFNAasUQ4rA8cPys6SuWeDRun9ZVX2Y+4qMFmOspJ/S8CrOYIJhMwtKHGltASwBMd7SHhc5FKuSHKMEVx5gZ8ZdL1K0/ORxOg== 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=pgp4RhThCY2pddbtqvYJj3fIQxOXO/iWrIt878ZbZtE=; b=kkcrNGOurycTWK9HlQsa8/xQKwE6uA2jZhgsT7svzIclnePMriSW7rUbQD7l7G1uiJjZdp/JpWAXgOgQS4JExGeH4SdwXbDCEiEeQ+tJRqabbwH2ThlJEPh81p/9+TGBxXqpq5un7YPloMcCRS9K6xllnb2gi4hDC6CASJ66Rng9MxUhrkaCCvFuzVSy9A/Q2crMZDZHgNsFRn+D15SZP2bmJvacasWdwgjpDF8tndayzuVF+PtKKoZN50vfsz+AoLcGh2GEgwFckAmC0QhENmxbHlPIj0EhkUrz5dcvI3xAAJp77TrbPduXym54Wwpm5QlX+V2toVMAkEXIlwEFDw== 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=pgp4RhThCY2pddbtqvYJj3fIQxOXO/iWrIt878ZbZtE=; b=Xy3e9hVGIoRwpu3GepJ2cHJWnVVNWVODuZVSuNiMBmzXpNpIvsDw2FiyJJC2QnAltzHm7WcNusl69A5Kxqo/aHY10vojQmh3y7kje0rAzfBxNZ87Vo+nSsKPTY+BDDr5aaVpCZi/th8UDHnFv4RgLI2iFy+xC/20lFJW18iYFyPGa5xwtLFYf01xDOLQuh6qVP60Bk9v+ae2A6NxdpVLavEnNLA5vFy3chv9FILRlFkX7ix3J/uBD3PdYYx177bZUf2FLbQCMdL/JwkfkfTzsOxEEPKleYrAEQXaLT1ye/PT+JFKjP84A2KJR7gx+3z0UdFW5aJwrAPya37u7ZAJ0w== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by PR3P250MB0241.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:17c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.12; Sat, 3 Sep 2022 20:36:05 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::f85a:9a02:f8be:7c47]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::f85a:9a02:f8be:7c47%2]) with mapi id 15.20.5588.010; Sat, 3 Sep 2022 20:36:05 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 3 Sep 2022 22:35:57 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [3Eyp6KSZfiMJOeJSSmS1vZoX3lbJmDJ3CgrIU2rssHI=] X-ClientProxiedBy: AM6P193CA0086.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::27) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20220903203559.1961353-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f8fb4bb-c9d6-4143-e8e2-08da8debec43 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmpvZmz4TmgkoDzJrsVMX7C8czoNbO2n/w68gWYTXszAZbMgPObdHJDFXAL6m20sa9XBAFH7ovRN9PpcZI3LyZqHJy/lyjzF2EEgP5DFgeUTHPxsc+Cx33rM+qsrLGWH43aQCiX+7VfDurzxqy0dXOYSTKTf4k+A8hmg+LKpqlx0FUW00mYIq3dM4/ZuHhonm5G+j4m/6EmvrIYhkha3IydQu0xyET4gs8s+baciG8YpWpR2nTAdAa9XzWcUGPRdzzBAyFwm6vYhJRjnY1RJYB2ti1m66QHtIZeMd0SuRxtvTuLY5UthFPJoT+ReyGLt/rdv9W3m6lUEN8yeIj5QnKo/2EcmcVe8AYE3AmoMsehaSnYJqT72bWar67wJ7HHDdTeAr4yJzL9yoNj1mXygitvgVbseSGgn+9XFDT7ot3fL3caJe5HqFbczzIZBovER2K3T+bFXTSdrmI6t+Yam5wU9zZUu470b3pGd4yr3wXvbOadePumJA1XvLlkVY52Eq1vjpcYam6xLFR1Crl49BxnVIwfUUpD7HPTMpyGYdzWG+V4v96/WhXkd8uggAF4iGsjNdkWhHB8KQZPI2Tz4ItKcKtRowsVJ593zq792oeyFOJ9l95woIR6pRetpnBuJAlp5ARz7Pw578BKgjaQPYndw2xt9jxyZL+LngZdY/5o6jBSitLFeGV+R6S6Lf6u7hDCzchWvJBJb9V6beCp8PejxGJTGA2sk9k+jDOktOfwpQO5V18KI7yik2JSuoZdzf08= X-MS-TrafficTypeDiagnostic: PR3P250MB0241:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uJ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S-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Sep 2022 20:36:04.9393 (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: PR3P250MB0241 Subject: [FFmpeg-devel] [PATCH 3/5] avcodec/cfhddata: Avoid code duplication when creating codebooks 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: Tfmlx3/TAGvK Signed-off-by: Andreas Rheinhardt --- libavcodec/cfhddata.c | 94 ++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 55 deletions(-) diff --git a/libavcodec/cfhddata.c b/libavcodec/cfhddata.c index 7c4b1454f3..017eb9375c 100644 --- a/libavcodec/cfhddata.c +++ b/libavcodec/cfhddata.c @@ -124,38 +124,42 @@ static const CFHD_RL_ELEM table_18_vlc[NB_VLC_TABLE_18] = { { 1, 29, 12 }, { 1, 18, 10 }, { 1, 8, 7 }, { 1, 2, 3 }, }; -av_cold int ff_cfhd_init_vlcs(CFHDContext *s) +static av_cold int cfhd_init_vlc(CFHD_RL_VLC_ELEM out[], unsigned out_size, + const CFHD_RL_ELEM table_vlc[], unsigned table_size, + VLC *vlc, void *logctx) { - int i, j, ret = 0; uint8_t new_cfhd_vlc_len[NB_VLC_TABLE_18 * 2]; uint16_t new_cfhd_vlc_run[NB_VLC_TABLE_18 * 2]; int16_t new_cfhd_vlc_level[NB_VLC_TABLE_18 * 2]; + unsigned j; + int ret; /** Similar to dv.c, generate signed VLC tables **/ - /* Table 9 */ - for (i = 0, j = 0; i < NB_VLC_TABLE_9; i++, j++) { - new_cfhd_vlc_len[j] = table_9_vlc[i].len; - new_cfhd_vlc_run[j] = table_9_vlc[i].run; - new_cfhd_vlc_level[j] = table_9_vlc[i].level; + for (unsigned i = j = 0; i < table_size; i++, j++) { + new_cfhd_vlc_len[j] = table_vlc[i].len; + new_cfhd_vlc_run[j] = table_vlc[i].run; + new_cfhd_vlc_level[j] = table_vlc[i].level; /* Don't include the zero level nor escape bits */ - if (table_9_vlc[i].level && table_9_vlc[i].run) { + if (table_vlc[i].level && table_vlc[i].run) { new_cfhd_vlc_len[j]++; j++; - new_cfhd_vlc_len[j] = table_9_vlc[i].len + 1; - new_cfhd_vlc_run[j] = table_9_vlc[i].run; - new_cfhd_vlc_level[j] = -table_9_vlc[i].level; + new_cfhd_vlc_len[j] = table_vlc[i].len + 1; + new_cfhd_vlc_run[j] = table_vlc[i].run; + new_cfhd_vlc_level[j] = -table_vlc[i].level; } } - ret = ff_init_vlc_from_lengths(&s->vlc_9, VLC_BITS, j, new_cfhd_vlc_len, - 1, NULL, 0, 0, 0, 0, s->avctx); + ret = ff_init_vlc_from_lengths(vlc, VLC_BITS, j, new_cfhd_vlc_len, + 1, NULL, 0, 0, 0, 0, logctx); if (ret < 0) return ret; - for (i = 0; i < s->vlc_9.table_size; i++) { - int code = s->vlc_9.table[i].sym; - int len = s->vlc_9.table[i].len; + av_assert0(vlc->table_size == out_size); + + for (unsigned i = 0; i < out_size; i++) { + int code = vlc->table[i].sym; + int len = vlc->table[i].len; int level, run; if (len < 0) { // more bits needed @@ -165,49 +169,29 @@ av_cold int ff_cfhd_init_vlcs(CFHDContext *s) run = new_cfhd_vlc_run[code]; level = new_cfhd_vlc_level[code]; } - s->table_9_rl_vlc[i].len = len; - s->table_9_rl_vlc[i].level = level; - s->table_9_rl_vlc[i].run = run; + out[i].len = len; + out[i].level = level; + out[i].run = run; } - /* Table 18 */ - for (i = 0, j = 0; i < NB_VLC_TABLE_18; i++, j++) { - new_cfhd_vlc_len[j] = table_18_vlc[i].len; - new_cfhd_vlc_run[j] = table_18_vlc[i].run; - new_cfhd_vlc_level[j] = table_18_vlc[i].level; + return 0; +} - /* Don't include the zero level nor escape bits */ - if (table_18_vlc[i].level && table_18_vlc[i].run) { - new_cfhd_vlc_len[j]++; - j++; - new_cfhd_vlc_len[j] = table_18_vlc[i].len + 1; - new_cfhd_vlc_run[j] = table_18_vlc[i].run; - new_cfhd_vlc_level[j] = -table_18_vlc[i].level; - } - } +av_cold int ff_cfhd_init_vlcs(CFHDContext *s) +{ + int ret; - ret = ff_init_vlc_from_lengths(&s->vlc_18, VLC_BITS, j, new_cfhd_vlc_len, - 1, NULL, 0, 0, 0, 0, s->avctx); + /* Table 9 */ + ret = cfhd_init_vlc(s->table_9_rl_vlc, FF_ARRAY_ELEMS(s->table_9_rl_vlc), + table_9_vlc, FF_ARRAY_ELEMS(table_9_vlc), + &s->vlc_9, s->avctx); if (ret < 0) return ret; - av_assert0(s->vlc_18.table_size == 4572); - - for (i = 0; i < s->vlc_18.table_size; i++) { - int code = s->vlc_18.table[i].sym; - int len = s->vlc_18.table[i].len; - int level, run; - - if (len < 0) { // more bits needed - run = 0; - level = code; - } else { - run = new_cfhd_vlc_run[code]; - level = new_cfhd_vlc_level[code]; - } - s->table_18_rl_vlc[i].len = len; - s->table_18_rl_vlc[i].level = level; - s->table_18_rl_vlc[i].run = run; - } - - return ret; + /* Table 18 */ + ret = cfhd_init_vlc(s->table_18_rl_vlc, FF_ARRAY_ELEMS(s->table_18_rl_vlc), + table_18_vlc, FF_ARRAY_ELEMS(table_18_vlc), + &s->vlc_18, s->avctx); + if (ret < 0) + return ret; + return 0; }