From patchwork Mon Oct 12 08:12:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22865 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5D5E044B947 for ; Mon, 12 Oct 2020 11:12:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3CD7868BB89; Mon, 12 Oct 2020 11:12:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC7F268BB6D for ; Mon, 12 Oct 2020 11:12:46 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id n6so17767255wrm.13 for ; Mon, 12 Oct 2020 01:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=N8X0p4WiJjwkjPqUz4o3YmRnx7I5oUyzRyh6ou1bFbA=; b=Q65gzxksjk0inrT1VI9OYkBKsl+FIQPIVgoA+G1hp2oj+kshjZ1xaMjlM49EoMEn+o iksnf5UvkLHtXV53DrAeSty+iZ2v8W/2Tz/1C4dA43ElU9LniyJqZ+uSu9Vzxv2wAbnU vAscSeVdD5fQZ4oYIZOoU9Z8Uw4pCSCsWeHRpeypULMVQhOjqUzLZhvWz+ffjykb5wAJ DuERqogmvGOHijGD0srMn1isXF104dCjIZIbm9wywBBbyYllE0SWz3BS6kGA88JPckQZ /wjB3W2yngbEKDXQHJaNOZXrLVnYK7o1x1e09eUJapUI/wYc1wL3Hyuzn0+u20kCY4Jd GdRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=N8X0p4WiJjwkjPqUz4o3YmRnx7I5oUyzRyh6ou1bFbA=; b=JMSes4c5FYklJ5mZ3w3P6U0rY63xl1+NVQmX8FcEveGNtI3XyHVfjkL8GZRlILMF34 3Q1+qNC7saFY3k3uWwwyY2UhaJwF47rxXObvQxv9+RRVCB+MgO0DgazizrqD1Kd8TWOf l/cwr8InXWyYovUFg7iLjuJAMVusdLYyBxy0tcnuIGjwU6GDZ9DkGQUXFeepZ/ABAj7U nQ4iCAqJ3htTcBT7YSvMwuKaAP5F4lvEH1A97CZWWZOtFJA7KFqH0srJBCVe3QQPmetl o3VBycb1+LPxlv3oesJB071j+4zOZWVsHZZtuxY2codTC4NSDNf9ZLriN/pjVWU3Lriv aBBw== X-Gm-Message-State: AOAM532SJxA5AiZpoaT5Zypw9k3qgKCJ3lHjBMZJd3A/6H1w4iuC6Mya Q45ShwgPnI0ozsCPuLRbQKYk9bEosNs= X-Google-Smtp-Source: ABdhPJzGHMjjq01/OEcMlHHDUfwMKfjwk8YWcfNLf0he8HzgU3xWQGtY9ntoJ0y/vr4KxRPpM6Zqww== X-Received: by 2002:adf:c045:: with SMTP id c5mr20796902wrf.405.1602490365924; Mon, 12 Oct 2020 01:12:45 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id j7sm2247928wmc.7.2020.10.12.01.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 01:12:45 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Oct 2020 10:12:14 +0200 Message-Id: <20201012081217.1643833-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> References: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7] avcodec/vlc, bitstream: Allow to use BE codes to initialize LE VLC X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This is easily possible because ff_init_vlc_sparse() already transforms both LE as well as BE codes to a normal form internally before processing them further. This will be used in subsequent commits. Signed-off-by: Andreas Rheinhardt --- libavcodec/bitstream.c | 6 +++--- libavcodec/vlc.h | 29 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index 95e5092b44..77c2b9ce05 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -182,7 +182,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, j = code >> (32 - table_nb_bits); nb = 1 << (table_nb_bits - n); inc = 1; - if (flags & INIT_VLC_LE) { + if (flags & INIT_VLC_OUTPUT_LE) { j = bitswap_32(code); inc = 1 << n; } @@ -217,7 +217,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, subtable_bits = FFMAX(subtable_bits, n); } subtable_bits = FFMIN(subtable_bits, table_nb_bits); - j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix; + j = (flags & INIT_VLC_OUTPUT_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix; table[j][1] = -subtable_bits; ff_dlog(NULL, "%4x: n=%d (subtable)\n", j, codes[i].bits + table_nb_bits); @@ -319,7 +319,7 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, av_free(buf); \ return AVERROR(EINVAL); \ } \ - if (flags & INIT_VLC_LE) \ + if (flags & INIT_VLC_INPUT_LE) \ buf[j].code = bitswap_32(buf[j].code); \ else \ buf[j].code <<= 32 - buf[j].bits; \ diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h index 42ccddf3fc..22d3e33485 100644 --- a/libavcodec/vlc.h +++ b/libavcodec/vlc.h @@ -51,26 +51,35 @@ int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, int flags); void ff_free_vlc(VLC *vlc); -#define INIT_VLC_LE 2 +/* If INIT_VLC_INPUT_LE is set, the LSB bit of the codes used to + * initialize the VLC table is the first bit to be read. */ +#define INIT_VLC_INPUT_LE 2 +/* If set the VLC is intended for a little endian bitstream reader. */ +#define INIT_VLC_OUTPUT_LE 8 +#define INIT_VLC_LE (INIT_VLC_INPUT_LE | INIT_VLC_OUTPUT_LE) #define INIT_VLC_USE_NEW_STATIC 4 -#define INIT_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \ +#define INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \ + h, i, j, flags, static_size) \ do { \ static VLC_TYPE table[static_size][2]; \ (vlc)->table = table; \ (vlc)->table_allocated = static_size; \ ff_init_vlc_sparse(vlc, bits, a, b, c, d, e, f, g, h, i, j, \ - INIT_VLC_USE_NEW_STATIC); \ + flags | INIT_VLC_USE_NEW_STATIC); \ } while (0) +#define INIT_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \ + INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \ + h, i, j, 0, static_size) + #define INIT_LE_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \ - do { \ - static VLC_TYPE table[static_size][2]; \ - (vlc)->table = table; \ - (vlc)->table_allocated = static_size; \ - ff_init_vlc_sparse(vlc, bits, a, b, c, d, e, f, g, h, i, j, \ - INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE); \ - } while (0) + INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \ + h, i, j, INIT_VLC_LE, static_size) + +#define INIT_CUSTOM_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, flags, static_size) \ + INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \ + NULL, 0, 0, flags, static_size) #define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \ INIT_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, NULL, 0, 0, static_size)