From patchwork Fri Nov 20 07:19:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23816 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 4714644AFE3 for ; Fri, 20 Nov 2020 09:35:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5E6068BB52; Fri, 20 Nov 2020 09:25:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B6D2568BB30 for ; Fri, 20 Nov 2020 09:25:12 +0200 (EET) Received: by mail-ej1-f68.google.com with SMTP id s25so11497105ejy.6 for ; Thu, 19 Nov 2020 23:25:12 -0800 (PST) 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=RbQ9XrwHGCFgFQWPAHUJi8p1fBTm0bCUCAofhk8YIOg=; b=QXiDy6IyxJU8PyiDeQzhIWpHWW/PLQbEp52zXt+MTpxMHtTwaXofPPWSMBObi8S7Hz SlW7FjhIenXp7rEHeeyhEnatj9Xvz1RXJBgPI0jBq8IuNRuhGGFDmJABJHvse/gp48e8 Uz208kAm+wAjqO/rAzXaW0LtXikdhjbULevciyQbjtuMXuwIdbKiTVSPJ12q7HCmb96x 1BByRlQflgWGYmEsPpdMyTSSGvQna0XSMBwpbF/h2VafIva40uXIC829nxuB87A/rgBV ijB4yXX5Ipr8/4OrhcS0LpRzaN+fR0qbMCiKnT0L+2lFf/ERNa59Zb9k0SV3XaHzbzo1 +O3Q== 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=RbQ9XrwHGCFgFQWPAHUJi8p1fBTm0bCUCAofhk8YIOg=; b=gZsAwsFdwLIezoYBey/E+jfzsE4yICGNvfiMxPr9dlzZ9q742NxbMIS8MqzJyysXZ9 rdFt0ZwxyodhGkk6quY9lV5ECUwekysD9CYW8m+E7hE+huwjM2OmxN4Qc2cFZbiIZ3wi wq91Jlwr/RWlOP8zAmAZg7kMK/HjSNXyoPd/TW0sbCRHRCISDnPBk8qBGfXj2/2sD1QB CO1ceDJWUZizYZFk2y5vX6iLdOjdHCYUmDmJ+2lzYAMMtvukhkq8ohB+bgslg0mSxanO fms1CS9hqm4ssMush6A+Am+SXDD91iY36Kq02+YiBSj1Dh9eL8pcjIcGV2momzQef/XD yAJA== X-Gm-Message-State: AOAM533cN2SYNFBNTw+KgsvQ/LrkjRJZm44ZzKAU+nLxkvKqoe7kV1sg wwgrVFXfDYOUKLmFst1oofYTZwgddkrcCw== X-Google-Smtp-Source: ABdhPJzZDf+HUx0daWwD6FOWgVgInMWzTcCBdNZdYj92eDVlAQqmZX3GWkpXYXqDqiD57Q1HL8TmOg== X-Received: by 2002:a17:906:2345:: with SMTP id m5mr186157eja.329.1605857111682; Thu, 19 Nov 2020 23:25:11 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id lz27sm779419ejb.39.2020.11.19.23.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:25:11 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:19:34 +0100 Message-Id: <20201120072116.818090-62-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> References: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 061/162] avcodec/mobiclip: Avoid redundant codes table to initialize VLCs 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" If both codes, lengths and symbols tables are ordered so that the codes are sorted from left to right in the tree, the codes can be easily derived from the lengths and therefore become redundant. This is exploited in this commit to remove the codes tables for the mobiclip decoder; notice that tables for the run-length VLC were already ordered correctly. Signed-off-by: Andreas Rheinhardt --- libavcodec/mobiclip.c | 204 ++++++++++++++++-------------------------- 1 file changed, 75 insertions(+), 129 deletions(-) diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c index 42d33cf6a5..db9266f72a 100644 --- a/libavcodec/mobiclip.c +++ b/libavcodec/mobiclip.c @@ -128,19 +128,6 @@ static const uint8_t bits0[] = { 6, 6, 6, 6, 6, 6, 5, 5, 5, 4, 2, 3, 4, 4, }; -static const uint8_t codes0[] = { - 0x0, 0x4, 0x5, 0x6, 0x7, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, - 0xB, 0xC, 0xD, 0xE, 0xF, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, - 0x26, 0x27, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x3, 0x20, - 0x21, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, - 0x24, 0x25, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, - 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, - 0x13, 0x14, 0x15, 0xB, 0xC, 0xD, 0x7, 0x2, 0x6, 0xE, 0xF, -}; - static const uint16_t syms0[] = { 0x0, 0x822, 0x803, 0xB, 0xA, 0xB81, 0xB61, 0xB41, 0xB21, 0x122, 0x102, 0xE2, 0xC2, 0xA2, 0x63, 0x43, 0x24, 0xC, 0x25, 0x2E1, 0x301, @@ -172,122 +159,82 @@ static const uint8_t mv_len[16] = static const uint8_t mv_bits[16][10] = { - { 1, 3, 3, 4, 4, 5, 5, 5, 6, 6 }, - { 2, 2, 3, 3, 3, 4, 5, 5 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, - { 1, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 3, 4, 5, 5 }, - { 2, 3, 3, 3, 3, 3, 4, 4 }, + { 3, 4, 5, 5, 3, 5, 6, 6, 4, 1 }, + { 2, 3, 4, 5, 5, 2, 3, 3 }, + { 2, 4, 4, 3, 3, 4, 4, 2 }, + { 1, 4, 4, 3, 4, 4, 3 }, + { 3, 3, 2, 4, 5, 5, 3, 2 }, + { 3, 4, 4, 3, 3, 3, 3, 2 }, { 1, 3, 3, 4, 4, 4, 5, 5 }, - { 1, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, + { 1, 4, 4, 3, 3, 4, 4 }, + { 2, 4, 4, 3, 3, 4, 4, 2 }, { 1, 3, 3, 4, 4, 4, 5, 5 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 3, 4, 4 }, - { 1, 3, 3, 4, 4, 4, 4 }, - { 1, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 3, 4, 4 }, - { 2, 2, 3, 3, 3, 3 }, -}; - -static const uint8_t mv_codes[16][10] = -{ - { 1, 0, 2, 2, 7, 6, 7, 12, 26, 27 }, - { 0, 2, 2, 6, 7, 6, 14, 15 }, - { 0, 3, 3, 4, 4, 5, 10, 11 }, - { 0, 5, 7, 8, 9, 12, 13 }, - { 1, 3, 0, 1, 5, 8, 18, 19 }, - { 3, 0, 2, 3, 4, 5, 2, 3 }, - { 0, 4, 5, 12, 13, 14, 30, 31 }, - { 0, 5, 6, 8, 9, 14, 15 }, - { 0, 3, 3, 4, 4, 5, 10, 11 }, - { 0, 4, 5, 12, 13, 14, 30, 31 }, - { 0, 3, 2, 5, 6, 7, 8, 9 }, - { 0, 3, 2, 3, 5, 8, 9 }, - { 0, 5, 6, 8, 9, 14, 15 }, - { 0, 5, 6, 8, 9, 14, 15 }, - { 0, 3, 2, 3, 5, 8, 9 }, - { 0, 3, 2, 3, 4, 5 }, + { 2, 3, 4, 4, 4, 4, 3, 2 }, + { 2, 3, 3, 4, 4, 3, 2 }, + { 1, 4, 4, 3, 3, 4, 4 }, + { 1, 4, 4, 3, 3, 4, 4 }, + { 2, 3, 3, 4, 4, 3, 2 }, + { 2, 3, 3, 3, 3, 2 }, }; static const uint8_t mv_syms[16][10] = { - { 0, 8, 1, 2, 9, 3, 6, 7, 5, 4 }, - { 9, 1, 2, 8, 0, 3, 5, 4 }, - { 0, 1, 2, 9, 5, 4, 3, 8 }, - { 1, 2, 0, 5, 4, 8, 3 }, - { 8, 1, 2, 9, 0, 3, 5, 4 }, - { 1, 3, 2, 9, 8, 0, 5, 4 }, + { 8, 2, 3, 6, 1, 7, 5, 4, 9, 0 }, + { 9, 2, 3, 5, 4, 1, 8, 0 }, + { 0, 5, 4, 2, 9, 3, 8, 1 }, + { 1, 5, 4, 2, 8, 3, 0 }, + { 2, 9, 8, 3, 5, 4, 0, 1 }, + { 3, 5, 4, 2, 9, 8, 0, 1 }, { 1, 2, 0, 9, 8, 3, 5, 4 }, - { 1, 2, 0, 8, 5, 4, 3 }, - { 0, 1, 2, 8, 5, 4, 3, 9 }, + { 1, 8, 5, 2, 0, 4, 3 }, + { 0, 5, 4, 2, 8, 3, 9, 1 }, { 1, 2, 0, 9, 8, 3, 5, 4 }, - { 0, 1, 3, 2, 9, 8, 5, 4 }, - { 0, 1, 4, 3, 2, 8, 5 }, - { 1, 2, 0, 5, 4, 9, 3 }, - { 1, 2, 0, 9, 5, 4, 3 }, - { 0, 1, 5, 3, 2, 9, 4 }, - { 0, 1, 4, 5, 3, 2 }, + { 0, 3, 9, 8, 5, 4, 2, 1 }, + { 0, 4, 3, 8, 5, 2, 1 }, + { 1, 5, 4, 2, 0, 9, 3 }, + { 1, 9, 5, 2, 0, 4, 3 }, + { 0, 5, 3, 9, 4, 2, 1 }, + { 0, 4, 5, 3, 2, 1 }, }; static const uint8_t mv_bits_mods[16][10] = { - { 2, 2, 3, 3, 4, 4, 5, 5, 5, 5 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, - { 1, 3, 3, 3, 4, 5, 5 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 2, 3, 4, 5, 5 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 3, 4, 5, 5 }, - { 2, 2, 3, 3, 3, 4, 4 }, - { 1, 3, 3, 4, 4, 4, 4 }, - { 2, 2, 3, 3, 3, 4, 4 }, - { 2, 2, 3, 3, 3, 4, 4 }, - { 2, 2, 3, 3, 3, 3 }, -}; - -static const uint8_t mv_codes_mods[16][10] = -{ - { 0, 3, 2, 3, 9, 10, 16, 17, 22, 23 }, - { 0, 3, 2, 4, 6, 7, 10, 11 }, - { 1, 3, 0, 5, 2, 3, 8, 9 }, - { 0, 4, 6, 7, 10, 22, 23 }, - { 0, 3, 3, 4, 4, 5, 10, 11 }, - { 0, 3, 2, 5, 6, 7, 8, 9 }, - { 0, 3, 2, 5, 6, 7, 8, 9 }, - { 0, 1, 3, 4, 10, 22, 23 }, - { 0, 3, 2, 4, 6, 7, 10, 11 }, - { 0, 3, 3, 5, 4, 5, 8, 9 }, - { 0, 3, 2, 3, 5, 9, 16, 17 }, - { 0, 3, 2, 4, 5, 6, 7 }, - { 0, 5, 6, 8, 9, 14, 15 }, - { 0, 3, 2, 4, 5, 6, 7 }, - { 0, 3, 2, 4, 5, 6, 7 }, - { 1, 2, 0, 1, 6, 7 }, + { 2, 3, 3, 5, 5, 4, 4, 5, 5, 2 }, + { 2, 3, 4, 4, 3, 4, 4, 2 }, + { 3, 4, 4, 2, 4, 4, 3, 2 }, + { 1, 3, 4, 5, 5, 3, 3 }, + { 2, 4, 4, 3, 3, 4, 4, 2 }, + { 2, 3, 4, 4, 4, 4, 3, 2 }, + { 2, 3, 4, 4, 4, 4, 3, 2 }, + { 2, 2, 3, 4, 5, 5, 2 }, + { 2, 3, 4, 4, 3, 4, 4, 2 }, + { 2, 4, 4, 3, 4, 4, 3, 2 }, + { 2, 3, 3, 5, 5, 4, 3, 2 }, + { 2, 3, 4, 4, 3, 3, 2 }, + { 1, 4, 4, 3, 3, 4, 4 }, + { 2, 3, 4, 4, 3, 3, 2 }, + { 2, 3, 4, 4, 3, 3, 2 }, + { 3, 3, 2, 2, 3, 3 }, }; static const uint8_t mv_syms_mods[16][10] = { - { 1, 0, 8, 9, 2, 7, 4, 3, 5, 6 }, - { 0, 1, 9, 2, 5, 4, 3, 8 }, - { 0, 1, 3, 2, 9, 5, 4, 8 }, - { 1, 3, 2, 0, 4, 8, 5 }, - { 0, 1, 8, 2, 5, 4, 3, 9 }, - { 0, 1, 3, 2, 5, 9, 4, 8 }, - { 0, 1, 3, 2, 9, 5, 8, 4 }, - { 0, 2, 1, 3, 4, 8, 5 }, - { 0, 1, 3, 2, 8, 4, 5, 9 }, - { 2, 1, 3, 0, 8, 9, 5, 4 }, - { 0, 1, 4, 3, 2, 5, 8, 9 }, - { 0, 1, 4, 3, 2, 8, 5 }, - { 1, 2, 0, 9, 4, 5, 3 }, - { 2, 1, 4, 3, 0, 9, 5 }, - { 0, 1, 4, 3, 2, 9, 5 }, - { 1, 0, 5, 4, 3, 2 }, + { 1, 8, 9, 4, 3, 2, 7, 5, 6, 0 }, + { 0, 9, 5, 4, 2, 3, 8, 1 }, + { 3, 9, 5, 0, 4, 8, 2, 1 }, + { 1, 3, 4, 8, 5, 2, 0 }, + { 0, 5, 4, 8, 2, 3, 9, 1 }, + { 0, 3, 5, 9, 4, 8, 2, 1 }, + { 0, 3, 9, 5, 8, 4, 2, 1 }, + { 0, 2, 3, 4, 8, 5, 1 }, + { 0, 3, 8, 4, 2, 5, 9, 1 }, + { 2, 8, 9, 3, 5, 4, 0, 1 }, + { 0, 4, 3, 8, 9, 5, 2, 1 }, + { 0, 4, 8, 5, 3, 2, 1 }, + { 1, 9, 4, 2, 0, 5, 3 }, + { 2, 4, 9, 5, 3, 0, 1 }, + { 0, 4, 9, 5, 3, 2, 1 }, + { 5, 4, 1, 0, 3, 2 }, }; typedef struct BlockXY { @@ -351,30 +298,29 @@ static av_cold int mobiclip_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } - INIT_VLC_SPARSE_STATIC(&rl_vlc[0], MOBI_RL_VLC_BITS, 104, - bits0, sizeof(*bits0), sizeof(*bits0), - codes0, sizeof(*codes0), sizeof(*codes0), + INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[0], MOBI_RL_VLC_BITS, 104, + bits0, sizeof(*bits0), syms0, sizeof(*syms0), sizeof(*syms0), - 1 << MOBI_RL_VLC_BITS); - INIT_VLC_SPARSE_STATIC(&rl_vlc[1], MOBI_RL_VLC_BITS, 104, - bits0, sizeof(*bits0), sizeof(*bits0), - codes0, sizeof(*codes0), sizeof(*codes0), + 0, 0, 1 << MOBI_RL_VLC_BITS); + INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[1], MOBI_RL_VLC_BITS, 104, + bits0, sizeof(*bits0), syms1, sizeof(*syms1), sizeof(*syms1), - 1 << MOBI_RL_VLC_BITS); + 0, 0, 1 << MOBI_RL_VLC_BITS); for (int j = 0; j < 16; j++) { static VLC_TYPE vlc_buf[2 * 16 << MOBI_MV_VLC_BITS][2]; mv_vlc[0][j].table = &vlc_buf[2 * j << MOBI_MV_VLC_BITS]; mv_vlc[0][j].table_allocated = 1 << MOBI_MV_VLC_BITS; - ff_init_vlc_sparse(&mv_vlc[0][j], MOBI_MV_VLC_BITS, mv_len[j], - mv_bits_mods[j], sizeof(*mv_bits_mods[j]), sizeof(*mv_bits_mods[j]), - mv_codes_mods[j], sizeof(*mv_codes_mods[j]), sizeof(*mv_codes_mods[j]), - mv_syms_mods[j], sizeof(*mv_syms_mods[j]), sizeof(*mv_syms_mods[j]), INIT_VLC_USE_NEW_STATIC); + ff_init_vlc_from_lengths(&mv_vlc[0][j], MOBI_MV_VLC_BITS, mv_len[j], + mv_bits_mods[j], sizeof(*mv_bits_mods[j]), + mv_syms_mods[j], sizeof(*mv_syms_mods[j]), + sizeof(*mv_syms_mods[j]), 0, + INIT_VLC_USE_NEW_STATIC, NULL); mv_vlc[1][j].table = &vlc_buf[(2 * j + 1) << MOBI_MV_VLC_BITS]; mv_vlc[1][j].table_allocated = 1 << MOBI_MV_VLC_BITS; - ff_init_vlc_sparse(&mv_vlc[1][j], MOBI_MV_VLC_BITS, mv_len[j], - mv_bits[j], sizeof(*mv_bits[j]), sizeof(*mv_bits[j]), - mv_codes[j], sizeof(*mv_codes[j]), sizeof(*mv_codes[j]), - mv_syms[j], sizeof(*mv_syms[j]), sizeof(*mv_syms[j]), INIT_VLC_USE_NEW_STATIC); + ff_init_vlc_from_lengths(&mv_vlc[1][j], MOBI_MV_VLC_BITS, mv_len[j], + mv_bits[j], sizeof(*mv_bits[j]), + mv_syms[j], sizeof(*mv_syms[j]), sizeof(*mv_syms[j]), + 0, INIT_VLC_USE_NEW_STATIC, NULL); } return 0;