From patchwork Sat Mar 30 03:15:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 47667 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp2319404pzb; Fri, 29 Mar 2024 20:15:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWSd4igxvJSCY5ATzlWs7J4loDNcMo0UK0Cnccgwgq3LurCEskEQyIXGcsVPYxyk9qKvqoGXlAhHufIIqFbye13KW1u8G2gQqVYrw== X-Google-Smtp-Source: AGHT+IEBaeoSxGLd6EPqNRMiSwfpues9VpDf4BCbeIgC6rxFYddWbQtYRoIY1be3r1K+Pt6JAEyg X-Received: by 2002:a17:906:d112:b0:a4e:3910:72fd with SMTP id b18-20020a170906d11200b00a4e391072fdmr2440845ejz.20.1711768541423; Fri, 29 Mar 2024 20:15:41 -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 ws6-20020a170907704600b00a46a13e555csi2436810ejb.838.2024.03.29.20.15.40; Fri, 29 Mar 2024 20:15:41 -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=V7aCViuF; 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 2938168D43E; Sat, 30 Mar 2024 05:15:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2049.outbound.protection.outlook.com [40.92.89.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C6C8B68D3DC for ; Sat, 30 Mar 2024 05:15:26 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AjEN2m8xP50keWQfiN58mwHjELRYRfULAmC2Z+QE4gEz5aiUTSR2mNKyCji3oAHxuP2OuukolkI/LpH5a8RYxkUAGBDlGGhWsjaxk/Az3smtKqYB/CVA34bme9p9fZoVnymVStzBuGeJDs979RVhLvGciBG/B2Wd5fMPPwIve2nNEwITMReg++VP/RvM4ATdVSFdFzXBINLnRNaSKOYvgXoFuCbOvheMr1BWX3RAZqH8mPfdZ/16DnKvalQyzfzkU338OED0pke3y/pePrj4gk+35bVDXoUlioqsqZknqDSbG5vGQa2bp8n8EzfuGyL+089ZIIEaHXKLxLBTLmvhBw== 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=yrBCecLbH8vS9kIGOJgQ2DPaV00tDbhca3KKhsthmc4=; b=FZYl0HCMQ+lKATLYtWD4DI4J24iJrifjzObXnCfn1Bjn/OwHzai/j3gv3cSV0NzyTTXlPKgVozPMoHT2ip1nHyRwBJ1iipNdhIQx+5AaVlN9RX2LBI67dO/iqk05bAHa6csPHgBxg4QR9ro9O2k5OIVDCjpGKZPJnp256CJn98TiNgzaiSKYMZfKbX9oFpJja58sfoREcbMvg+EJ6l2aZ4SFwXQuPz9hjI8jr5kdI6N/EK29UC0ns19fLUzi6JTTKtQjFwKLuTxgyXaiB9n8J20RZsShpsPPOSw/skth5qbPsG2ppGx8lyiVJVSTW3eh1eE6I9KdEvz1cSuV1YQgWg== 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=yrBCecLbH8vS9kIGOJgQ2DPaV00tDbhca3KKhsthmc4=; b=V7aCViuFKw1orqSdDgsZUxtatpK31y6c3Koe4jMQjEEMQFHLDWE039L2KNpVRx/tHOhTu3MckQhT2bW1X67XJilJ/pNwAUu+qEhY/SlK7sTnUNrR2f5D26aHdFiOz9sOBe/RoZ12BsY0DntRNRTe1z3iNTxjusXCh4Wh0R9FeLP0qUdrtze/G43H0nLivA1ZLQdgaNXd0Buc8F9zyCLjKXYRhng72kdJUSWTmyVeW9W6dGwS7vvXEuFWChUWe315HNWRdBx8xalX37dWkGw8cRQ7qNzeY4o9fwaNeCFdxLhfsLwNCzus+zMaWmKA9GtnBrzcyutX17vFf2WttEk2jQ== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by AS8P250MB0038.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:359::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.42; Sat, 30 Mar 2024 03:15:24 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d%4]) with mapi id 15.20.7409.039; Sat, 30 Mar 2024 03:15:24 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 Mar 2024 04:15:11 +0100 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [PIUWuAdq3HHruqZJv3npacXmjoMBzd2XYbBVHlCiOC4=] X-ClientProxiedBy: FR3P281CA0172.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a0::10) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240330031512.2615619-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|AS8P250MB0038:EE_ X-MS-Office365-Filtering-Correlation-Id: 46e3a2ae-e9a5-4614-af70-08dc5067a3ea X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UpxoMPzDWR/heoFu30TuGh86dhVi59E81PGk3Qq4MgS1qGQVSGfRkXt0ihCnp+tHLQw+5PNM7aKy8l+Fnl+edvxa1z1/NfMlJCWYx7bUDmFbkkj9iwTCYaT/VvSY3d0K7yySCAkMcMuAAvBQjjawfPTaZrFTlS312SjTfST4rJw2GA9QpYEUDXNc28t84MInvs+hjAiXKsfGaiJPmitjrtm3Ryl0mAmEjS4oBKrLvAcEEauR3gJPAGTSFyoG2zQPhxh5Wx+nqhidVsRmojD+k4MoiX/1Ai2gLipYkgdvPDFJ4ljtlB4p8pGXS4MwiabclEJKfURA9D5jdC2RK7qdZzzswIe9zDQJiScUj/IHjadotYO9szwMGQH3cLUK3CNc2by3EMGtsiyz2fsR/v8Aauyq2fy6+L1cUx/WOGHD87fn05TqROAN7Sop8/CxypnAgDFh/fEE8OoFRMKsQnn5oDzXXGjNO5etz7oWqoZuQ3QZU0GBs11nvXttglhTjipIpSDzwiBuLRGckWxZvfFiiCFeAhl4UdQQXswWhyZIu3Oqo/dm3qa26tV2Hgz+rnnIlUokJ4MW6gyz0Mj08sxSQsXksM1M29hV8xJAS6Bh0isTgJwhFhGoqrd5bbBbhs2P X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-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/yF/FRifqkVWXbZa3HtrwRDk7QlQDxWlNhszgAi9W/DVWq0UZ+EbvOFzl0Msx2A6RIp62xUkIhw7BJzdiaChGkFfNbdorldeteRFqHkTwRgxaTXLw7dzX7qme8bu5AhsQ7WHd9ks06mEmPl0OA0xBRibXEmXtpcowIsP6cROa3yuIExCJ4rGe1YM4OCxaNe+DEKxoIn0TzoFUFIjX0B2AVmNn99yDb4rAR3bQKJY+alJAaxBFWpA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46e3a2ae-e9a5-4614-af70-08dc5067a3ea X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2024 03:15:24.3329 (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: AS8P250MB0038 Subject: [FFmpeg-devel] [PATCH 11/12] avcodec/vlc, bitstream: Fix multi VLC with uint8_t syms on BE 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: lMRxfJNAvzgK VLC_MULTI_ELEM contains an uint8_t array that is supposed to be treated as an array of uint16_t when the used symbols have a size of two; otherwise it should be treated as just an array of uint8_t, but it was not always treated that way: vlc_multi_gen() initialized the first entry of the array by writing the symbol via AV_WN16; on big endian systems, the intended value was instead written into the second entry of the array (where it would likely be overwritten lateron during initialization). read_vlc_multi() also treated this case incorrectly: In case the code is so long that it needs a classical multi-stage lookup, the symbol has been written to the destination as if via AV_WN16. On little endian systems, this sets the correct first symbol and clobbers (zeroes) the next one, but the next one will be overwritten lateron anyway, so it won't be recognized. But on big-endian systems, the first symbol will be set to zero and the actually read symbol will be put into the slot for the next one (where it will be overwritten lateron). This commit fixes this; this fixes the magicyuv and utvideo FATE-tests on big endian arches. Signed-off-by: Andreas Rheinhardt --- libavcodec/bitstream_template.h | 8 ++++++-- libavcodec/get_bits.h | 3 ++- libavcodec/magicyuv.c | 2 +- libavcodec/utvideodec.c | 2 +- libavcodec/vlc.c | 5 ++++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libavcodec/bitstream_template.h b/libavcodec/bitstream_template.h index 4f3d07275f..c8e4a5131e 100644 --- a/libavcodec/bitstream_template.h +++ b/libavcodec/bitstream_template.h @@ -536,7 +536,8 @@ static inline int BS_FUNC(read_vlc)(BSCTX *bc, const VLCElem *table, static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8], const VLC_MULTI_ELEM *const Jtable, const VLCElem *const table, - const int bits, const int max_depth) + const int bits, const int max_depth, + const int symbols_size) { unsigned idx = BS_FUNC(peek)(bc, bits); int ret, nb_bits, code, n = Jtable[idx].len; @@ -554,7 +555,10 @@ static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8], code = BS_FUNC(priv_set_idx)(bc, code, &n, &nb_bits, table); } } - AV_WN16(dst, code); + if (symbols_size == 1) + *dst = code; + else + AV_WN16(dst, code); ret = n > 0; } BS_FUNC(priv_skip_remaining)(bc, n); diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index cfcf97c021..fe2f6378b4 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -667,7 +667,8 @@ static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, static inline int get_vlc_multi(GetBitContext *s, uint8_t *dst, const VLC_MULTI_ELEM *const Jtable, const VLCElem *const table, - const int bits, const int max_depth) + const int bits, const int max_depth, + const int symbols_size) { dst[0] = get_vlc2(s, table, bits, max_depth); return 1; diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 3f6348b531..4f30493626 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -124,7 +124,7 @@ static void magicyuv_median_pred16(uint16_t *dst, const uint16_t *src1, x = 0; \ for (; CACHED_BITSTREAM_READER && x < width-c && get_bits_left(&gb) > 0;) {\ ret = get_vlc_multi(&gb, (uint8_t *)dst + x * b, multi, \ - vlc, vlc_bits, 3); \ + vlc, vlc_bits, 3, b); \ if (ret <= 0) \ return AVERROR_INVALIDDATA; \ x += ret; \ diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c index ce5d00f7af..0c2e67e282 100644 --- a/libavcodec/utvideodec.c +++ b/libavcodec/utvideodec.c @@ -120,7 +120,7 @@ static int build_huff(UtvideoContext *c, const uint8_t *src, VLC *vlc, i = 0; \ for (; CACHED_BITSTREAM_READER && i < width-end && get_bits_left(&gb) > 0;) {\ ret = get_vlc_multi(&gb, (uint8_t *)buf + i * b, multi.table, \ - vlc.table, VLC_BITS, 3); \ + vlc.table, VLC_BITS, 3, b); \ if (ret > 0) \ i += ret; \ if (ret <= 0) \ diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c index 78510e30d6..e01cc41689 100644 --- a/libavcodec/vlc.c +++ b/libavcodec/vlc.c @@ -499,7 +499,10 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC *single, for (int j = 0; j < 1<table[j].len; table[j].num = single->table[j].len > 0 ? 1 : 0; - AV_WN16(table[j].val, single->table[j].sym); + if (is16bit) + AV_WN16(table[j].val, single->table[j].sym); + else + table[j].val[0] = single->table[j].sym; } add_level(table, is16bit, nb_codes, numbits, buf,