From patchwork Fri Nov 20 07:32: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: 23857 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 C99E044B17A for ; Fri, 20 Nov 2020 09:45:25 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1677D68BCAE; Fri, 20 Nov 2020 09:34:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 931B068BC27 for ; Fri, 20 Nov 2020 09:34:12 +0200 (EET) Received: by mail-ej1-f67.google.com with SMTP id f20so11518291ejz.4 for ; Thu, 19 Nov 2020 23:34: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=0KKYWrAKUH177MSrYHy8eeqocWuKckv1tQU5zEPYFr4=; b=QoIqgbwOLlmjvz1KIDH2WWeKSthpbWO6fgcm35kNcgwMQ2fugMnepLAOTjQE2VSfFZ pNJUGgYwQRw/mXBBdRbFBPnTigM4pL3pfZdm5xAZ1GQwug04XBOU0xcoI7DgSIMOMR8/ 2muI9aAgBNVKSxNZsYOA7tlqtzvSsSoJLBp3Z+doFrbuk7QJ4UT7VE78r6P3utvPRUTg ZOR2mJejZnybli2T1bTC05EDH/bDAZY5TgzyVzJlcdHZ5+foUygnLfSbxPUZPO69TGyX 53T13n/xpkEd4FVV1ucxhGcYF+X1pWQf49qu4lxZrU5HfQDDPCaUSXCN0cfL4CHmymcb 00HQ== 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=0KKYWrAKUH177MSrYHy8eeqocWuKckv1tQU5zEPYFr4=; b=YyaTVJt2JmqiBGb2nxA9C+83vDDsDN9OEDyFXC00JWVtGMueJHxpY6Y7Q50/Zyb2Ug PWXEH77Dlf0TG3Uf0KsI9zSqHDo8gs9Djk1Bq1z0kuJCc/jp4/acDYHI62xpf1TvbfJu a7PzKw5Sc3+9Gg6zQZhFur5mKED9VaSw/PKWe7WLZ/3oT627eGGUg/jqwpKZ4v2Ze+ye TFCz+SOFPAZqXotAoPea+vEEVkXVwfkC39vmwENwla9ogXMo5ot/d4iYVEBysI/PcmU4 LrASQ4IPbhCsErRaYP0OgJOqay0tR6GkG/ULc7aXLTywQQbRadttVstCF9oeYD5I6Qrb sq9g== X-Gm-Message-State: AOAM530PBM6YOUAAAAerdFHiPY56A1EYo4TElsua6Sfc9t5ieYDOQHjR OJmEYxThmvzdLG4eYKn5EogL2xzYVX3LuA== X-Google-Smtp-Source: ABdhPJzq+PyckiiIht8d7Jp5lE4ABz8Q5RETONkJ3/henEGaQitYvtphqagpM89UKb7pC9ks2fLNnA== X-Received: by 2002:a17:906:4a02:: with SMTP id w2mr13909722eju.267.1605857651293; Thu, 19 Nov 2020 23:34:11 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id i13sm769110ejv.84.2020.11.19.23.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:34:10 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:32:34 +0100 Message-Id: <20201120073327.820745-10-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 109/162] avcodec/vc1: Avoid code duplication when initializing 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" This has been achieved by switching those VLCs that still used ff_init_vlc_sparse() to ff_init_vlc_lengths() even though the codes tables used uint8_t in these cases. But it allows to use one auxiliary function to initialize the VLCs and by using tables that interleave symbols and lengths said function only needs one parameter for the tables, not two. The only table that uses an uint16_t symbols table still has to be treated specially for this reason. The offsets table has been removed as a byproduct of these changes; furthermore, some of the loops have been combined while just at it. Signed-off-by: Andreas Rheinhardt --- libavcodec/vc1.c | 174 +++++++++++++++---------------------------- libavcodec/vc1data.c | 159 +++++++++++++++++++-------------------- libavcodec/vc1data.h | 36 +++++---- 3 files changed, 154 insertions(+), 215 deletions(-) diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c index d4378cbae9..ed31b03a8a 100644 --- a/libavcodec/vc1.c +++ b/libavcodec/vc1.c @@ -1346,138 +1346,84 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) return 0; } -static const uint16_t vlc_offs[] = { - 0, 520, 552, 616, 1128, 1160, 1224, 1740, 1772, 1836, 1900, 2436, - 2986, 3050, 3610, 4154, 4218, 4746, 5326, 5390, 5902, 6554, 7658, 8342, - 9304, 9988, 10630, 11234, 12174, 13006, 13560, 14232, 14786, 15432, 16350, 17522, - 20372, 21818, 22330, 22394, 23166, 23678, 23742, 24820, 25332, 25396, 26460, 26980, - 27048, 27592, 27600, 27608, 27616, 27624, 28224, 28258, 28290, 28802, 28834, 28866, - 29378, 29412, 29444, 29960, 29994, 30026, 30538, 30572, 30604, 31120, 31154, 31186, - 31714, 31746, 31778, 32306, 32340, 32372 -}; +static VLC_TYPE vlc_buf[33080][2]; + +static av_cold void vc1_init_vlc(VLC *vlc, int nb_bits, int nb_codes, + unsigned *buf_offset, const uint8_t (*tab)[2], + int offset) +{ + vlc->table = &vlc_buf[*buf_offset]; + vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *buf_offset; + + ff_init_vlc_from_lengths(vlc, nb_bits, nb_codes, + &tab[0][1], 2, &tab[0][0], 2, 1, + offset, INIT_VLC_STATIC_OVERLONG, NULL); + *buf_offset += vlc->table_size; +} static av_cold void vc1_init_static(void) { + unsigned offset = 0; int i = 0; - static VLC_TYPE vlc_table[32372][2]; - - INIT_VLC_STATIC(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23, - ff_vc1_bfraction_bits, 1, 1, - ff_vc1_bfraction_codes, 1, 1, 1 << VC1_BFRACTION_VLC_BITS); - INIT_VLC_STATIC(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4, - ff_vc1_norm2_bits, 1, 1, - ff_vc1_norm2_codes, 1, 1, 1 << VC1_NORM2_VLC_BITS); - INIT_VLC_STATIC_FROM_LENGTHS(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 77, - &ff_vc1_norm6_tab[0][1], 2, - &ff_vc1_norm6_tab[0][0], 2, 1, 0, 0, 556); - INIT_VLC_STATIC(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7, - ff_vc1_imode_bits, 1, 1, - ff_vc1_imode_codes, 1, 1, 1 << VC1_IMODE_VLC_BITS); + + vc1_init_vlc(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23, + &offset, ff_vc1_bfraction_tab, 0); + vc1_init_vlc(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4, + &offset, ff_vc1_norm2_tab, 0); + vc1_init_vlc(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 77, + &offset, ff_vc1_norm6_tab, 0); + vc1_init_vlc(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7, + &offset, ff_vc1_imode_tab, 0); for (i = 0; i < 3; i++) { - ff_vc1_ttmb_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 0]]; - ff_vc1_ttmb_vlc[i].table_allocated = vlc_offs[i * 3 + 1] - vlc_offs[i * 3 + 0]; - ff_init_vlc_from_lengths(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16, - &ff_vc1_ttmb_tabs[i][0][1], 2, - &ff_vc1_ttmb_tabs[i][0][0], 2, 1, - 0, INIT_VLC_USE_NEW_STATIC, NULL); - ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 1]]; - ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i * 3 + 2] - vlc_offs[i * 3 + 1]; - ff_init_vlc_from_lengths(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8, - &ff_vc1_ttblk_tabs[i][0][1], 2, - &ff_vc1_ttblk_tabs[i][0][0], 2, 1, - 0, INIT_VLC_USE_NEW_STATIC, NULL); - ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 2]]; - ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i * 3 + 3] - vlc_offs[i * 3 + 2]; - ff_init_vlc_from_lengths(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15, - &ff_vc1_subblkpat_tabs[i][0][1], 2, - &ff_vc1_subblkpat_tabs[i][0][0], 2, 1, - 0, INIT_VLC_USE_NEW_STATIC, NULL); + vc1_init_vlc(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16, + &offset, ff_vc1_ttmb_tabs[i], 0); + vc1_init_vlc(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8, + &offset, ff_vc1_ttblk_tabs[i], 0); + vc1_init_vlc(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15, + &offset, ff_vc1_subblkpat_tabs[i], 0); } for (i = 0; i < 4; i++) { - ff_vc1_4mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 9]]; - ff_vc1_4mv_block_pattern_vlc[i].table_allocated = vlc_offs[i * 3 + 10] - vlc_offs[i * 3 + 9]; - init_vlc(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16, - ff_vc1_4mv_block_pattern_bits[i], 1, 1, - ff_vc1_4mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); - ff_vc1_cbpcy_p_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 10]]; - ff_vc1_cbpcy_p_vlc[i].table_allocated = vlc_offs[i * 3 + 11] - vlc_offs[i * 3 + 10]; - ff_init_vlc_from_lengths(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64, - &ff_vc1_cbpcy_p_tabs[i][0][1], 2, - &ff_vc1_cbpcy_p_tabs[i][0][0], 2, 1, - 0, INIT_VLC_USE_NEW_STATIC, NULL); - ff_vc1_mv_diff_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 11]]; - ff_vc1_mv_diff_vlc[i].table_allocated = vlc_offs[i * 3 + 12] - vlc_offs[i * 3 + 11]; - ff_init_vlc_from_lengths(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73, - &ff_vc1_mv_diff_tabs[i][0][1], 2, - &ff_vc1_mv_diff_tabs[i][0][0], 2, 1, - -4, INIT_VLC_USE_NEW_STATIC, NULL); + vc1_init_vlc(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16, + &offset, ff_vc1_4mv_block_pattern_tabs[i], 0); + vc1_init_vlc(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64, + &offset, ff_vc1_cbpcy_p_tabs[i], 0); + vc1_init_vlc(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73, + &offset, ff_vc1_mv_diff_tabs[i], -4); + /* initialize 4MV MBMODE VLC tables for interlaced frame P picture */ + vc1_init_vlc(&ff_vc1_intfr_4mv_mbmode_vlc[i], VC1_INTFR_4MV_MBMODE_VLC_BITS, 15, + &offset, ff_vc1_intfr_4mv_mbmode_tabs[i], 0); + /* initialize NON-4MV MBMODE VLC tables for the same */ + vc1_init_vlc(&ff_vc1_intfr_non4mv_mbmode_vlc[i], VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 9, + &offset, ff_vc1_intfr_non4mv_mbmode_tabs[i], 0); + /* initialize interlaced MVDATA tables (1-Ref) */ + vc1_init_vlc(&ff_vc1_1ref_mvdata_vlc[i], VC1_1REF_MVDATA_VLC_BITS, 72, + &offset, ff_vc1_1ref_mvdata_tabs[i], 0); + /* Initialize 2MV Block pattern VLC tables */ + vc1_init_vlc(&ff_vc1_2mv_block_pattern_vlc[i], VC1_2MV_BLOCK_PATTERN_VLC_BITS, 4, + &offset, ff_vc1_2mv_block_pattern_tabs[i], 0); } for (int i = 0, ac_offset = 0; i < 8; i++) { - ff_vc1_ac_coeff_table[i].table = &vlc_table[vlc_offs[i * 2 + 21]]; - ff_vc1_ac_coeff_table[i].table_allocated = vlc_offs[i * 2 + 22] - vlc_offs[i * 2 + 21]; + ff_vc1_ac_coeff_table[i].table = &vlc_buf[offset]; + ff_vc1_ac_coeff_table[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset; ff_init_vlc_from_lengths(&ff_vc1_ac_coeff_table[i], AC_VLC_BITS, ff_vc1_ac_sizes[i], ff_vc1_ac_coeff_lens + ac_offset, 1, ff_vc1_ac_coeff_syms + ac_offset, 2, 2, - 0, INIT_VLC_USE_NEW_STATIC, NULL); + 0, INIT_VLC_STATIC_OVERLONG, NULL); ac_offset += ff_vc1_ac_sizes[i]; + offset += ff_vc1_ac_coeff_table[i].table_size; /* initialize interlaced MVDATA tables (2-Ref) */ - ff_vc1_2ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 2 + 22]]; - ff_vc1_2ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 2 + 23] - vlc_offs[i * 2 + 22]; - ff_init_vlc_from_lengths(&ff_vc1_2ref_mvdata_vlc[i], VC1_2REF_MVDATA_VLC_BITS, 126, - &ff_vc1_2ref_mvdata_tabs[i][0][1], 2, - &ff_vc1_2ref_mvdata_tabs[i][0][0], 2, 1, - 0, INIT_VLC_USE_NEW_STATIC, NULL); - } - for (i = 0; i < 4; i++) { - /* initialize 4MV MBMODE VLC tables for interlaced frame P picture */ - ff_vc1_intfr_4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 37]]; - ff_vc1_intfr_4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 38] - vlc_offs[i * 3 + 37]; - ff_init_vlc_from_lengths(&ff_vc1_intfr_4mv_mbmode_vlc[i], VC1_INTFR_4MV_MBMODE_VLC_BITS, 15, - &ff_vc1_intfr_4mv_mbmode_tabs[i][0][1], 2, - &ff_vc1_intfr_4mv_mbmode_tabs[i][0][0], 2, 1, - 0, INIT_VLC_USE_NEW_STATIC, NULL); - /* initialize NON-4MV MBMODE VLC tables for the same */ - ff_vc1_intfr_non4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 38]]; - ff_vc1_intfr_non4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 39] - vlc_offs[i * 3 + 38]; - ff_init_vlc_from_lengths(&ff_vc1_intfr_non4mv_mbmode_vlc[i], VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 9, - &ff_vc1_intfr_non4mv_mbmode_tabs[i][0][1], 2, - &ff_vc1_intfr_non4mv_mbmode_tabs[i][0][0], 2, 1, - 0, INIT_VLC_USE_NEW_STATIC, NULL); - /* initialize interlaced MVDATA tables (1-Ref) */ - ff_vc1_1ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 39]]; - ff_vc1_1ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 3 + 40] - vlc_offs[i * 3 + 39]; - ff_init_vlc_from_lengths(&ff_vc1_1ref_mvdata_vlc[i], VC1_1REF_MVDATA_VLC_BITS, 72, - &ff_vc1_1ref_mvdata_tabs[i][0][1], 2, - &ff_vc1_1ref_mvdata_tabs[i][0][0], 2, 1, - 0, INIT_VLC_USE_NEW_STATIC, NULL); - } - for (i = 0; i < 4; i++) { - /* Initialize 2MV Block pattern VLC tables */ - ff_vc1_2mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i + 49]]; - ff_vc1_2mv_block_pattern_vlc[i].table_allocated = vlc_offs[i + 50] - vlc_offs[i + 49]; - init_vlc(&ff_vc1_2mv_block_pattern_vlc[i], VC1_2MV_BLOCK_PATTERN_VLC_BITS, 4, - ff_vc1_2mv_block_pattern_bits[i], 1, 1, - ff_vc1_2mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + vc1_init_vlc(&ff_vc1_2ref_mvdata_vlc[i], VC1_2REF_MVDATA_VLC_BITS, 126, + &offset, ff_vc1_2ref_mvdata_tabs[i], 0); } for (i = 0; i < 8; i++) { /* Initialize interlaced CBPCY VLC tables (Table 124 - Table 131) */ - ff_vc1_icbpcy_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 53]]; - ff_vc1_icbpcy_vlc[i].table_allocated = vlc_offs[i * 3 + 54] - vlc_offs[i * 3 + 53]; - ff_init_vlc_from_lengths(&ff_vc1_icbpcy_vlc[i], VC1_ICBPCY_VLC_BITS, 63, - &ff_vc1_icbpcy_p_tabs[i][0][1], 2, - &ff_vc1_icbpcy_p_tabs[i][0][0], 2, 1, - 0, INIT_VLC_USE_NEW_STATIC, NULL); + vc1_init_vlc(&ff_vc1_icbpcy_vlc[i], VC1_ICBPCY_VLC_BITS, 63, + &offset, ff_vc1_icbpcy_p_tabs[i], 0); /* Initialize interlaced field picture MBMODE VLC tables */ - ff_vc1_if_mmv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 54]]; - ff_vc1_if_mmv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 55] - vlc_offs[i * 3 + 54]; - init_vlc(&ff_vc1_if_mmv_mbmode_vlc[i], VC1_IF_MMV_MBMODE_VLC_BITS, 8, - ff_vc1_if_mmv_mbmode_bits[i], 1, 1, - ff_vc1_if_mmv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); - ff_vc1_if_1mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 55]]; - ff_vc1_if_1mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 56] - vlc_offs[i * 3 + 55]; - init_vlc(&ff_vc1_if_1mv_mbmode_vlc[i], VC1_IF_1MV_MBMODE_VLC_BITS, 6, - ff_vc1_if_1mv_mbmode_bits[i], 1, 1, - ff_vc1_if_1mv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + vc1_init_vlc(&ff_vc1_if_mmv_mbmode_vlc[i], VC1_IF_MMV_MBMODE_VLC_BITS, 8, + &offset, ff_vc1_if_mmv_mbmode_tabs[i], 0); + vc1_init_vlc(&ff_vc1_if_1mv_mbmode_vlc[i], VC1_IF_1MV_MBMODE_VLC_BITS, 6, + &offset, ff_vc1_if_1mv_mbmode_tabs[i], 0); } } diff --git a/libavcodec/vc1data.c b/libavcodec/vc1data.c index 6c78895a38..9c4e95f2f3 100644 --- a/libavcodec/vc1data.c +++ b/libavcodec/vc1data.c @@ -129,23 +129,14 @@ const int16_t ff_vc1_bfraction_lut[23] = { }; #endif -const uint8_t ff_vc1_bfraction_bits[23] = { - 3, 3, 3, 3, - 3, 3, 3, - 7, 7, 7, 7, - 7, 7, 7, 7, - 7, 7, 7, 7, - 7, 7, - 7, 7 -}; -const uint8_t ff_vc1_bfraction_codes[23] = { - 0, 1, 2, 3, - 4, 5, 6, - 112, 113, 114, 115, - 116, 117, 118, 119, - 120, 121, 122, 123, - 124, 125, - 126, 127 +const uint8_t ff_vc1_bfraction_tab[23][2] = { + { 0, 3 }, { 1, 3 }, { 2, 3 }, { 3, 3 }, + { 4, 3 }, { 5, 3 }, { 6, 3 }, + { 7, 7 }, { 8, 7 }, { 9, 7 }, { 10, 7 }, + { 11, 7 }, { 12, 7 }, { 13, 7 }, { 14, 7 }, + { 15, 7 }, { 16, 7 }, { 17, 7 }, { 18, 7 }, + { 19, 7 }, { 20, 7 }, + { 21, 7 }, { 22, 7 }, }; //Same as H.264 @@ -169,19 +160,14 @@ const AVRational ff_vc1_pixel_aspect[16] = { }; /* BitPlane IMODE - such a small table... */ -const uint8_t ff_vc1_imode_codes[7] = { - 0, 2, 1, 3, 1, 2, 3 -}; -const uint8_t ff_vc1_imode_bits[7] = { - 4, 2, 3, 2, 4, 3, 3 +const uint8_t ff_vc1_imode_tab[7][2] = { + { IMODE_RAW, 4 }, { IMODE_DIFF6, 4 }, { IMODE_DIFF2, 3 }, { IMODE_ROWSKIP, 3 }, + { IMODE_COLSKIP, 3 }, { IMODE_NORM2, 2 }, { IMODE_NORM6, 2 }, }; /* Normal-2 imode */ -const uint8_t ff_vc1_norm2_codes[4] = { - 0, 4, 5, 3 -}; -const uint8_t ff_vc1_norm2_bits[4] = { - 1, 3, 3, 2 +const uint8_t ff_vc1_norm2_tab[4][2] = { + { 0, 1 }, { 1, 3 }, { 2, 3 }, { 3, 2 }, }; /* The negative lengths in the following table correspond to @@ -206,26 +192,39 @@ const uint8_t ff_vc1_norm6_tab[77][2] = { }; /* 4MV Block pattern VLC tables */ -const uint8_t ff_vc1_4mv_block_pattern_codes[4][16] = { - { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2 }, - { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0 }, - { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0 }, - { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 10 } -}; -const uint8_t ff_vc1_4mv_block_pattern_bits[4][16] = { - { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2 }, - { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2 }, - { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3 }, - { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4 } +const uint8_t ff_vc1_4mv_block_pattern_tabs[4][16][2] = { + { + { 0x0B, 3 }, { 0x0D, 3 }, { 0x0E, 3 }, { 0x04, 5 }, { 0x08, 5 }, + { 0x00, 5 }, { 0x06, 5 }, { 0x0F, 2 }, { 0x09, 5 }, { 0x03, 5 }, + { 0x05, 5 }, { 0x0A, 5 }, { 0x0C, 5 }, { 0x01, 6 }, { 0x02, 6 }, + { 0x07, 4 }, + }, + { + { 0x0F, 2 }, { 0x03, 4 }, { 0x05, 4 }, { 0x0A, 4 }, { 0x0C, 4 }, + { 0x00, 4 }, { 0x01, 5 }, { 0x02, 5 }, { 0x04, 5 }, { 0x08, 5 }, + { 0x07, 4 }, { 0x0B, 4 }, { 0x0D, 4 }, { 0x0E, 4 }, { 0x06, 5 }, + { 0x09, 5 }, + }, + { + { 0x0F, 3 }, { 0x03, 4 }, { 0x05, 4 }, { 0x0A, 4 }, { 0x0C, 4 }, + { 0x01, 4 }, { 0x02, 4 }, { 0x04, 4 }, { 0x07, 4 }, { 0x08, 4 }, + { 0x0B, 4 }, { 0x0D, 4 }, { 0x0E, 4 }, { 0x06, 5 }, { 0x09, 5 }, + { 0x00, 4 }, + }, + { + { 0x00, 2 }, { 0x03, 4 }, { 0x05, 4 }, { 0x0A, 4 }, { 0x0C, 4 }, + { 0x07, 5 }, { 0x0B, 5 }, { 0x0D, 5 }, { 0x0E, 5 }, { 0x0F, 4 }, + { 0x01, 4 }, { 0x02, 4 }, { 0x04, 4 }, { 0x08, 4 }, { 0x06, 5 }, + { 0x09, 5 }, + }, }; /* 2MV Block pattern VLC tables */ -const uint8_t ff_vc1_2mv_block_pattern_codes[4][4] = { - { 2, 1, 0, 3 }, { 1, 0, 2, 3 }, { 2, 0, 3, 1 }, { 1, 3, 2, 0 } -}; - -const uint8_t ff_vc1_2mv_block_pattern_bits[4][4] = { - { 2, 2, 2, 2 }, { 1, 2, 3, 3 }, { 3, 2, 3, 1 }, { 1, 3, 3, 2 } +const uint8_t ff_vc1_2mv_block_pattern_tabs[4][4][2] = { + { { 0x02, 2 }, { 0x01, 2 }, { 0x00, 2 }, { 0x03, 2 } }, + { { 0x01, 2 }, { 0x02, 3 }, { 0x03, 3 }, { 0x00, 1 } }, + { { 0x01, 2 }, { 0x00, 3 }, { 0x02, 3 }, { 0x03, 1 } }, + { { 0x03, 2 }, { 0x02, 3 }, { 0x01, 3 }, { 0x00, 1 } }, }; /* Interlaced frame picture 4MV MBMODE VLC tables (tables 160-163) */ @@ -350,46 +349,42 @@ const uint8_t ff_vc1_intfr_non4mv_mbmode_tabs[4][9][2] = { /* Interlaced field picture MBMODE VLC tables (p. 356 - 11.4.1, 11.4.2) */ /* mixed-MV */ -const uint8_t ff_vc1_if_mmv_mbmode_codes[8][8] = { - { 16, 17, 3, 3, 0, 5, 9, 2 }, - { 8, 9, 3, 6, 7, 0, 5, 2 }, - { 16, 17, 5, 3, 0, 3, 9, 2 }, - { 56, 57, 15, 4, 5, 6, 29, 0 }, - { 52, 53, 27, 14, 15, 2, 12, 0 }, - { 56, 57, 29, 5, 6, 0, 15, 4 }, - { 16, 17, 6, 7, 0, 1, 9, 5 }, - { 56, 57, 0, 5, 6, 29, 4, 15 } -}; -const uint8_t ff_vc1_if_mmv_mbmode_bits[8][8] = { - { 6, 6, 2, 3, 2, 4, 5, 2 }, - { 5, 5, 3, 3, 3, 2, 4, 2 }, - { 6, 6, 4, 3, 2, 2, 5, 2 }, - { 6, 6, 4, 3, 3, 3, 5, 1 }, - { 6, 6, 5, 4, 4, 2, 4, 1 }, - { 6, 6, 5, 3, 3, 1, 4, 3 }, - { 5, 5, 3, 3, 2, 2, 4, 3 }, - { 6, 6, 1, 3, 3, 5, 3, 4 } +const uint8_t ff_vc1_if_mmv_mbmode_tabs[8][8][2] = { + { { 0x04, 2 }, { 0x00, 6 }, { 0x01, 6 }, { 0x06, 5 }, + { 0x05, 4 }, { 0x03, 3 }, { 0x07, 2 }, { 0x02, 2 } }, + { { 0x05, 2 }, { 0x00, 5 }, { 0x01, 5 }, { 0x06, 4 }, + { 0x02, 3 }, { 0x07, 2 }, { 0x03, 3 }, { 0x04, 3 } }, + { { 0x04, 2 }, { 0x00, 6 }, { 0x01, 6 }, { 0x06, 5 }, + { 0x02, 4 }, { 0x03, 3 }, { 0x07, 2 }, { 0x05, 2 } }, + { { 0x07, 1 }, { 0x03, 3 }, { 0x04, 3 }, { 0x05, 3 }, + { 0x00, 6 }, { 0x01, 6 }, { 0x06, 5 }, { 0x02, 4 } }, + { { 0x07, 1 }, { 0x05, 2 }, { 0x06, 4 }, { 0x00, 6 }, + { 0x01, 6 }, { 0x02, 5 }, { 0x03, 4 }, { 0x04, 4 } }, + { { 0x05, 1 }, { 0x07, 3 }, { 0x03, 3 }, { 0x04, 3 }, + { 0x00, 6 }, { 0x01, 6 }, { 0x02, 5 }, { 0x06, 4 } }, + { { 0x04, 2 }, { 0x05, 2 }, { 0x00, 5 }, { 0x01, 5 }, + { 0x06, 4 }, { 0x07, 3 }, { 0x02, 3 }, { 0x03, 3 } }, + { { 0x02, 1 }, { 0x06, 3 }, { 0x03, 3 }, { 0x04, 3 }, + { 0x00, 6 }, { 0x01, 6 }, { 0x05, 5 }, { 0x07, 4 } }, }; /* 1MV */ -const uint8_t ff_vc1_if_1mv_mbmode_codes[8][6] = { - { 0, 1, 1, 1, 1, 1 }, - { 0, 1, 1, 1, 1, 1 }, - { 16, 17, 3, 0, 9, 5 }, - { 20, 21, 3, 11, 0, 4 }, - { 4, 5, 2, 3, 3, 0 }, - { 4, 5, 3, 2, 0, 3 }, - { 0, 1, 1, 1, 1, 1 }, - { 16, 17, 9, 5, 3, 0 } -}; -const uint8_t ff_vc1_if_1mv_mbmode_bits[8][6] = { - { 5, 5, 1, 3, 2, 4 }, - { 5, 5, 1, 2, 3, 4 }, - { 5, 5, 2, 1, 4, 3 }, - { 5, 5, 2, 4, 1, 3 }, - { 4, 4, 2, 3, 2, 2 }, - { 4, 4, 3, 2, 2, 2 }, - { 5, 5, 3, 4, 1, 2 }, - { 5, 5, 4, 3, 2, 1 } +const uint8_t ff_vc1_if_1mv_mbmode_tabs[8][6][2] = { + { { 0x00, 5 }, { 0x01, 5 }, { 0x05, 4 }, + { 0x03, 3 }, { 0x04, 2 }, { 0x02, 1 } }, + { { 0x00, 5 }, { 0x01, 5 }, { 0x05, 4 }, + { 0x04, 3 }, { 0x03, 2 }, { 0x02, 1 } }, + { { 0x03, 1 }, { 0x00, 5 }, { 0x01, 5 }, + { 0x04, 4 }, { 0x05, 3 }, { 0x02, 2 } }, + { { 0x04, 1 }, { 0x05, 3 }, { 0x00, 5 }, + { 0x01, 5 }, { 0x03, 4 }, { 0x02, 2 } }, + { { 0x05, 2 }, { 0x00, 4 }, { 0x01, 4 }, + { 0x03, 3 }, { 0x02, 2 }, { 0x04, 2 } }, + { { 0x04, 2 }, { 0x00, 4 }, { 0x01, 4 }, + { 0x02, 3 }, { 0x03, 2 }, { 0x05, 2 } }, + { { 0x00, 5 }, { 0x01, 5 }, { 0x03, 4 }, + { 0x02, 3 }, { 0x05, 2 }, { 0x04, 1 } }, + { { 0x05, 1 }, { 0x00, 5 }, { 0x01, 5 }, + { 0x02, 4 }, { 0x03, 3 }, { 0x04, 2 } }, }; /* Interlaced frame/field picture MVDATA VLC tables */ diff --git a/libavcodec/vc1data.h b/libavcodec/vc1data.h index f08b1feedd..17c112d6b9 100644 --- a/libavcodec/vc1data.h +++ b/libavcodec/vc1data.h @@ -94,32 +94,31 @@ extern VLC ff_vc1_ac_coeff_table[8]; /* pre-computed scales for all bfractions and base=256 */ extern const int16_t ff_vc1_bfraction_lut[23]; -extern const uint8_t ff_vc1_bfraction_bits[23]; -extern const uint8_t ff_vc1_bfraction_codes[23]; +extern const uint8_t ff_vc1_bfraction_tab[23][2]; /* based upon table 40 */ //Same as H.264 extern const AVRational ff_vc1_pixel_aspect[16]; -/* BitPlane IMODE - such a small table... */ -extern const uint8_t ff_vc1_imode_codes[7]; -extern const uint8_t ff_vc1_imode_bits[7]; +/* BitPlane IMODE (table #69) + * The symbols contain enum Imode (IMODE_*) values. */ +extern const uint8_t ff_vc1_imode_tab[7][2]; -/* Normal-2 imode */ -extern const uint8_t ff_vc1_norm2_codes[4]; -extern const uint8_t ff_vc1_norm2_bits[4]; +/* Normal-2 imode (table #80) + * 'SYMBOL 2N' is contained in the 0x1 bit, 'SYMBOL 2N+1' in 0x2. */ +extern const uint8_t ff_vc1_norm2_tab[4][2]; /* Normal-6 imode (based upon table #81) * The symbols contain the complete code of the tile, i.e. * the possibly existing fixed length code resp. the second VLC * are already incorporated. */ extern const uint8_t ff_vc1_norm6_tab[77][2]; -/* 4MV Block pattern VLC tables */ -extern const uint8_t ff_vc1_4mv_block_pattern_codes[4][16]; -extern const uint8_t ff_vc1_4mv_block_pattern_bits[4][16]; +/* 4MV Block pattern VLC tables (tables #116-#119) + * The symbols contain the '4-MV Coded Pattern'. */ +extern const uint8_t ff_vc1_4mv_block_pattern_tabs[4][16][2]; -/* 2MV Block pattern VLC tables */ -extern const uint8_t ff_vc1_2mv_block_pattern_codes[4][4]; -extern const uint8_t ff_vc1_2mv_block_pattern_bits[4][4]; +/* 2MV Block pattern VLC tables (tables #120-#123) + * Bit 0x1 of the symbols contains the 'Bottom' value, 0x2 the 'Top' value. */ +extern const uint8_t ff_vc1_2mv_block_pattern_tabs[4][4][2]; extern const uint8_t ff_wmv3_dc_scale_table[32]; @@ -167,11 +166,10 @@ enum MBModeProperties { extern const uint8_t ff_vc1_intfr_4mv_mbmode_tabs[4][15][2]; extern const uint8_t ff_vc1_intfr_non4mv_mbmode_tabs[4][9][2]; -/* Interlaced field picture MBMODE VLC tables (p. 356 - 11.4.1, 11.4.2) */ -extern const uint8_t ff_vc1_if_mmv_mbmode_codes[8][8]; -extern const uint8_t ff_vc1_if_mmv_mbmode_bits[8][8]; -extern const uint8_t ff_vc1_if_1mv_mbmode_codes[8][6]; -extern const uint8_t ff_vc1_if_1mv_mbmode_bits[8][6]; +/* Interlaced field picture MBMODE VLC tables (p. 356 - 11.4.1, 11.4.2) + * The symbols contain the MB Mode value. */ +extern const uint8_t ff_vc1_if_mmv_mbmode_tabs[8][8][2]; /* tables #144-#151 */ +extern const uint8_t ff_vc1_if_1mv_mbmode_tabs[8][6][2]; /* tables #152-#159 */ /* Interlaced frame/field picture MVDATA VLC tables * The escape value of each table has the symbol 0;