From patchwork Fri Nov 20 07:19:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23804 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 5237444A644 for ; Fri, 20 Nov 2020 09:33:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 30EA968BB0A; Fri, 20 Nov 2020 09:25:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E3BC068BAE8 for ; Fri, 20 Nov 2020 09:25:03 +0200 (EET) Received: by mail-ed1-f65.google.com with SMTP id cq7so8476633edb.4 for ; Thu, 19 Nov 2020 23:25:03 -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=iOltP6FUV7Gdi1bIGCpbYDLZzVnp3QK3jTzEHMxtplU=; b=LJwI3LUggTwZ3lfYbYsPJQh65npRy7ocncW5fd3m2DHVRaqgx/nRdhPw5WaYW/xcWH 6EIRZV8ftbog/lAWEV26LVf2ExBLfApgzq+7CEdYE0G6CE1wRzpX1F84rpsrNnCnforQ JUviosNUlaitYUUoIsdj4F3s0qQBHag2xjoqxhkXJoWv4E0uyUv225z1WwTZa8glx6pm yUjWgz0hBZPWQCTCqar9z9ovyL4YgRGbeVvVcmBh0Ybh3mLOJKPaGa+GC2jWGFCFrhnF VlnSRq3tsCN1TbMxY9p5QZEF/Bu5+RF/a/BUaK/Nd2W6PPtjIhLzAgy4+QKUoRQfjEtk Cshw== 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=iOltP6FUV7Gdi1bIGCpbYDLZzVnp3QK3jTzEHMxtplU=; b=WSV6qVBHaANUprclG8qmrQLGBMLZ2LHUKoplEDEC7HOYwoTvYWNWSgxBGs85pa+noy p6UQBC/hPoBA6SmTEpkvcAvPLS60lwkdpxj+tuFkQfQ530PjJQSVKSfi/PA0kfrCNgzM vHIdlesaYLfad9HccZbBSX/UvUlNxSVYPD88VB3F6fV2ljQ6FzKKua0E0XKA8Ma8E4fp 27nchIwhDoQDCtpYNcOAaubBq1rRFk7Qv/TrsriEqZT9DC3mr99/husFb+rhNAthZIp+ yG0g8xIxSHrMHibt4M+z5/nEqJwHZq6SLGQmkdGxluE5IWls7k7+pjlK/Zm5xOhBrHO7 RQJg== X-Gm-Message-State: AOAM532WuRYLN+GxKeq/inxl+JrC8HgvAb3Rqx7Wb/37hjFxiyyP6iDI UshNGB5Tak4xgdK4ABnoCFXUCLA3F5raOA== X-Google-Smtp-Source: ABdhPJwpqE/EHzMazZNKyFgNiCGGNpR/HSAra2qwkBjnKu3pHXsktvhi11XK8p2blzzUsdR4GoH3Vw== X-Received: by 2002:aa7:d601:: with SMTP id c1mr33604199edr.323.1605857103136; Thu, 19 Nov 2020 23:25:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:25:02 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:19:25 +0100 Message-Id: <20201120072116.818090-53-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 052/162] avcodec/mpc8: Reduce the size of some 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" Several of the quantisation VLCs come in pairs and up until now the number of bits used for each VLC was set to the same value for both VLCs in such a pair even when one of the two required only a lower number. This is a waste given that the get_vlc2() call is compatible with these two VLCs using a different number of bits (it uses vlc->bits). Given that the code lengths are descending it is easily possible to know the length of the longest code for a given VLC: It is the length of the first one. With this information one can easily use the least amount of bits. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpc8.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c index 64b1967d8d..e7c631f1a6 100644 --- a/libavcodec/mpc8.c +++ b/libavcodec/mpc8.c @@ -87,10 +87,10 @@ static int mpc8_get_mask(GetBitContext *gb, int size, int t) } static const uint16_t vlc_offsets[13] = { - 0, 640, 1184, 1748, 2298, 2426, 2554, 3066, 3578, 4106, 4618, 5196, 5708 + 0, 640, 1184, 1748, 2298, 2426, 2490, 3002, 3258, 3786, 4298, 4876, 5388 }; -static av_cold void build_vlc(VLC *vlc, int nb_bits, +static av_cold void build_vlc(VLC *vlc, const uint8_t codes_counts[16], const uint8_t syms[], int offset) { @@ -101,7 +101,7 @@ static av_cold void build_vlc(VLC *vlc, int nb_bits, for (unsigned tmp = num + codes_counts[i - 1]; num < tmp; num++) len[num] = i; - ff_init_vlc_from_lengths(vlc, nb_bits, num, len, 1, + ff_init_vlc_from_lengths(vlc, FFMIN(len[0], 9), num, len, 1, syms, 1, 1, offset, INIT_VLC_USE_NEW_STATIC, NULL); } @@ -112,7 +112,7 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) GetBitContext gb; static int vlc_initialized = 0; int channels; - static VLC_TYPE codes_table[5708][2]; + static VLC_TYPE codes_table[5388][2]; if(avctx->extradata_size < 2){ av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); @@ -152,7 +152,7 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) static VLC_TYPE table[static_size][2]; \ (vlc)->table = table; \ (vlc)->table_allocated = static_size; \ - build_vlc(vlc, bits, len_counts, symbols, offset); \ + build_vlc(vlc, len_counts, symbols, offset); \ } while (0) @@ -182,29 +182,29 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) for(i = 0; i < 2; i++){ res_vlc[i].table = &codes_table[vlc_offsets[0+i]]; res_vlc[i].table_allocated = vlc_offsets[1+i] - vlc_offsets[0+i]; - build_vlc(&res_vlc[i], MPC8_RES_BITS, + build_vlc(&res_vlc[i], mpc8_res_len_counts[i], mpc8_res_syms[i], 0); q2_vlc[i].table = &codes_table[vlc_offsets[2+i]]; q2_vlc[i].table_allocated = vlc_offsets[3+i] - vlc_offsets[2+i]; - build_vlc(&q2_vlc[i], MPC8_Q2_BITS, + build_vlc(&q2_vlc[i], mpc8_q2_len_counts[i], mpc8_q2_syms[i], 0); quant_vlc[0][i].table = &codes_table[vlc_offsets[4+i]]; quant_vlc[0][i].table_allocated = vlc_offsets[5+i] - vlc_offsets[4+i]; - build_vlc(&quant_vlc[0][i], MPC8_Q5_BITS, + build_vlc(&quant_vlc[0][i], mpc8_q5_len_counts[i], mpc8_q5_syms[i], MPC8_Q5_OFFSET); quant_vlc[1][i].table = &codes_table[vlc_offsets[6+i]]; quant_vlc[1][i].table_allocated = vlc_offsets[7+i] - vlc_offsets[6+i]; - build_vlc(&quant_vlc[1][i], MPC8_Q6_BITS, + build_vlc(&quant_vlc[1][i], mpc8_q6_len_counts[i], mpc8_q6_syms[i], MPC8_Q6_OFFSET); quant_vlc[2][i].table = &codes_table[vlc_offsets[8+i]]; quant_vlc[2][i].table_allocated = vlc_offsets[9+i] - vlc_offsets[8+i]; - build_vlc(&quant_vlc[2][i], MPC8_Q7_BITS, + build_vlc(&quant_vlc[2][i], mpc8_q7_len_counts[i], mpc8_q7_syms[i], MPC8_Q7_OFFSET); quant_vlc[3][i].table = &codes_table[vlc_offsets[10+i]]; quant_vlc[3][i].table_allocated = vlc_offsets[11+i] - vlc_offsets[10+i]; - build_vlc(&quant_vlc[3][i], MPC8_Q8_BITS, + build_vlc(&quant_vlc[3][i], mpc8_q8_len_counts[i], mpc8_q8_syms[i], MPC8_Q8_OFFSET); } vlc_initialized = 1;