From patchwork Tue Nov 10 10:58:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23571 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 CD8B144B238 for ; Tue, 10 Nov 2020 13:15:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 541B868C0B2; Tue, 10 Nov 2020 12:59:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4770768C080 for ; Tue, 10 Nov 2020 12:59:30 +0200 (EET) Received: by mail-wr1-f65.google.com with SMTP id p1so12159551wrf.12 for ; Tue, 10 Nov 2020 02:59:30 -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=QsF7DEL6y8LGpcnR7rrSa802b+WMFosAevcTfBUKbLo=; b=dIWIzXQ2LQwn7MHlAhGS3F1zhlxv0fz5nWHCnXciosmQWAxEv9CWFf7PdAzYttSDdW kpXPrJQVrLbM0PpqXh+hWoAijS/H9RUnUhgipQW0ooaYmOXkyfKY1E1Uo4w6N+SNq367 Nin8Tia0Y2snNBUo4HhXAstKUYpTcumtpndthC8HdGE50S0CDnJ+fs/X/+83/9Kga8MY 7zqXZkC0rmf+V4J47We9H8v/9XolWVwrK+C94XADeeUSLaj0KTyyRJ7ccDOwhn5Kmztu 2CPsbbbeeIsUvjB9v76Y75cIlAb5U0KhwJUp8TLiP4QSPQMwkfddn1Spt++7v5MIce57 vOog== 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=QsF7DEL6y8LGpcnR7rrSa802b+WMFosAevcTfBUKbLo=; b=pLZHS1Bwlx4fVKYFBRM6xqrb85nSTlzbEpJF18LHUxITVMPbI/qQZW/STbUdcV/RB9 lPRiSZpf20Bn8HC6FE+RL9rOjOHR17K5z+KenMSI6/H6AkgBCC8kYgAqxb1s1iuIn3CX MmVU4f952rrxwb4uxtUMN89MZqnXhoOqMjt58x4IgRRSQool3VzO4JPOfXNCAiHkwW4n MpOBbJtK9QdelOPSsdXNQh0BYltdq9kpTxNA/mEjFAPejdH4hAjLhiBEiOA12LR1h7OP R1eSEGDWA/6i+SJ6/qAGcKkSaV4gEto/3ozhjXpQXDC7XdKjvs4mA1YkncyS5i9HqqnH wLfw== X-Gm-Message-State: AOAM530diMgSEMzTnnziTq+L8cmfkpXi9jJVWvITLEUJ/TaCPCPh2qa0 HlA45Iy5uQdvBkb9VzDErqa758OEaGY= X-Google-Smtp-Source: ABdhPJwZsA0SyfDBL+2r/sCda2tXI6a2GGmgIZ7AOzgmy0ieVd7Ra0/hczg8pYeRJd88ggzQiR8ojQ== X-Received: by 2002:adf:df88:: with SMTP id z8mr23016444wrl.113.1605005969344; Tue, 10 Nov 2020 02:59:29 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id o197sm2561308wme.17.2020.11.10.02.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 02:59:28 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Nov 2020 11:58:28 +0100 Message-Id: <20201110105836.321916-15-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201110104851.321029-1-andreas.rheinhardt@gmail.com> References: <20201110104851.321029-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 106/114] avcodec/atrac3: Use symbols table 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" Expressions like array[get_vlc2()] can be optimized by using a symbols table if the array is always the same for a given VLC. This requirement is fulfilled for several VLCs used by ATRAC3, therefore this commit implements this. This comes without any additional costs when using ff_init_vlc_from_lengths() as one can then remove the codes tables. While at it, remove the arrays of pointers to the individual arrays and put all lengths+symbol pairs in one big array. Signed-off-by: Andreas Rheinhardt --- libavcodec/atrac3.c | 18 ++++---- libavcodec/atrac3data.h | 100 ++++++++++++++-------------------------- 2 files changed, 43 insertions(+), 75 deletions(-) diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 1e884a56b6..cd09b6dbb0 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -246,13 +246,8 @@ static void read_quant_spectral_coeffs(GetBitContext *gb, int selector, /* variable length coding (VLC) */ if (selector != 1) { for (i = 0; i < num_codes; i++) { - huff_symb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, - ATRAC3_VLC_BITS, 1); - huff_symb += 1; - code = huff_symb >> 1; - if (huff_symb & 1) - code = -code; - mantissas[i] = code; + mantissas[i] = get_vlc2(gb, spectral_coeff_tab[selector-1].table, + ATRAC3_VLC_BITS, 1); } } else { for (i = 0; i < num_codes; i++) { @@ -854,6 +849,7 @@ static int atrac3al_decode_frame(AVCodecContext *avctx, void *data, static av_cold void atrac3_init_static_data(void) { VLC_TYPE (*table)[2] = atrac3_vlc_table; + const uint8_t (*hufftabs)[2] = atrac3_hufftabs; int i; init_imdct_window(); @@ -863,9 +859,11 @@ static av_cold void atrac3_init_static_data(void) for (i = 0; i < 7; i++) { spectral_coeff_tab[i].table = table; spectral_coeff_tab[i].table_allocated = 256; - init_vlc(&spectral_coeff_tab[i], ATRAC3_VLC_BITS, huff_tab_sizes[i], - huff_bits[i], 1, 1, - huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + ff_init_vlc_from_lengths(&spectral_coeff_tab[i], ATRAC3_VLC_BITS, huff_tab_sizes[i], + &hufftabs[0][1], 2, + &hufftabs[0][0], 2, 1, + -31, INIT_VLC_USE_NEW_STATIC); + hufftabs += huff_tab_sizes[i]; table += 256; } } diff --git a/libavcodec/atrac3data.h b/libavcodec/atrac3data.h index a731fb7c4a..d050c0f380 100644 --- a/libavcodec/atrac3data.h +++ b/libavcodec/atrac3data.h @@ -32,77 +32,47 @@ /* VLC tables */ -static const uint8_t huffcode1[9] = { - 0x0, 0x4, 0x5, 0xC, 0xD, 0x1C, 0x1D, 0x1E, 0x1F -}; - -static const uint8_t huffbits1[9] = { 1, 3, 3, 4, 4, 5, 5, 5, 5 }; - -static const uint8_t huffcode2[5] = { 0x0, 0x4, 0x5, 0x6, 0x7 }; - -static const uint8_t huffbits2[5] = { 1, 3, 3, 3, 3 }; - -static const uint8_t huffcode3[7] = { 0x0, 0x4, 0x5, 0xC, 0xD, 0xE, 0xF }; - -static const uint8_t huffbits3[7] = { 1, 3, 3, 4, 4, 4, 4 }; - -static const uint8_t huffcode4[9] = { - 0x0, 0x4, 0x5, 0xC, 0xD, 0x1C, 0x1D, 0x1E, 0x1F -}; - -static const uint8_t huffbits4[9] = { 1, 3, 3, 4, 4, 5, 5, 5, 5 }; - -static const uint8_t huffcode5[15] = { - 0x00, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x1C, - 0x1D, 0x3C, 0x3D, 0x3E, 0x3F, 0x0C, 0x0D -}; - -static const uint8_t huffbits5[15] = { - 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 4, 4 -}; - -static const uint8_t huffcode6[31] = { - 0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x34, 0x35, 0x36, - 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x78, 0x79, 0x7A, - 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x08, 0x09 -}; - -static const uint8_t huffbits6[31] = { - 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, - 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 4, 4 -}; - -static const uint8_t huffcode7[63] = { - 0x00, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, - 0x0F, 0x10, 0x11, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, - 0x31, 0x32, 0x33, 0x68, 0x69, 0x6A, 0x6B, 0x6C, - 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, - 0x75, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, - 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, - 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x02, 0x03 -}; - -static const uint8_t huffbits7[63] = { - 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4 +static const uint8_t atrac3_hufftabs[][2] = { + /* Spectral coefficient 1 - 9 entries */ + { 31, 1 }, { 32, 3 }, { 33, 3 }, { 34, 4 }, { 35, 4 }, + { 36, 5 }, { 37, 5 }, { 38, 5 }, { 39, 5 }, + /* Spectral coefficient 2 - 5 entries */ + { 31, 1 }, { 32, 3 }, { 30, 3 }, { 33, 3 }, { 29, 3 }, + /* Spectral coefficient 3 - 7 entries */ + { 31, 1 }, { 32, 3 }, { 30, 3 }, { 33, 4 }, + { 29, 4 }, { 34, 4 }, { 28, 4 }, + /* Spectral coefficient 4 - 9 entries */ + { 31, 1 }, { 32, 3 }, { 30, 3 }, { 33, 4 }, { 29, 4 }, + { 34, 5 }, { 28, 5 }, { 35, 5 }, { 27, 5 }, + /* Spectral coefficient 5 - 15 entries */ + { 31, 2 }, { 32, 3 }, { 30, 3 }, { 33, 4 }, { 29, 4 }, + { 34, 4 }, { 28, 4 }, { 38, 4 }, { 24, 4 }, { 35, 5 }, + { 27, 5 }, { 36, 6 }, { 26, 6 }, { 37, 6 }, { 25, 6 }, + /* Spectral coefficient 6 - 31 entries */ + { 31, 3 }, { 32, 4 }, { 30, 4 }, { 33, 4 }, { 29, 4 }, { 34, 4 }, + { 28, 4 }, { 46, 4 }, { 16, 4 }, { 35, 5 }, { 27, 5 }, { 36, 5 }, + { 26, 5 }, { 37, 5 }, { 25, 5 }, { 38, 6 }, { 24, 6 }, { 39, 6 }, + { 23, 6 }, { 40, 6 }, { 22, 6 }, { 41, 6 }, { 21, 6 }, { 42, 7 }, + { 20, 7 }, { 43, 7 }, { 19, 7 }, { 44, 7 }, { 18, 7 }, { 45, 7 }, + { 17, 7 }, + /* Spectral coefficient 7 - 63 entries */ + { 31, 3 }, { 62, 4 }, { 0, 4 }, { 32, 5 }, { 30, 5 }, { 33, 5 }, + { 29, 5 }, { 34, 5 }, { 28, 5 }, { 35, 5 }, { 27, 5 }, { 36, 5 }, + { 26, 5 }, { 37, 6 }, { 25, 6 }, { 38, 6 }, { 24, 6 }, { 39, 6 }, + { 23, 6 }, { 40, 6 }, { 22, 6 }, { 41, 6 }, { 21, 6 }, { 42, 6 }, + { 20, 6 }, { 43, 6 }, { 19, 6 }, { 44, 6 }, { 18, 6 }, { 45, 7 }, + { 17, 7 }, { 46, 7 }, { 16, 7 }, { 47, 7 }, { 15, 7 }, { 48, 7 }, + { 14, 7 }, { 49, 7 }, { 13, 7 }, { 50, 7 }, { 12, 7 }, { 51, 7 }, + { 11, 7 }, { 52, 8 }, { 10, 8 }, { 53, 8 }, { 9, 8 }, { 54, 8 }, + { 8, 8 }, { 55, 8 }, { 7, 8 }, { 56, 8 }, { 6, 8 }, { 57, 8 }, + { 5, 8 }, { 58, 8 }, { 4, 8 }, { 59, 8 }, { 3, 8 }, { 60, 8 }, + { 2, 8 }, { 61, 8 }, { 1, 8 }, }; static const uint8_t huff_tab_sizes[7] = { 9, 5, 7, 9, 15, 31, 63, }; -static const uint8_t* const huff_codes[7] = { - huffcode1, huffcode2, huffcode3, huffcode4, huffcode5, huffcode6, huffcode7 -}; - -static const uint8_t* const huff_bits[7] = { - huffbits1, huffbits2, huffbits3, huffbits4, huffbits5, huffbits6, huffbits7, -}; - /* selector tables */ static const uint8_t clc_length_tab[8] = { 0, 4, 3, 3, 4, 4, 5, 6 };