From patchwork Tue Nov 10 10:47:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23523 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 F3DF544A3F2 for ; Tue, 10 Nov 2020 12:59:43 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8716A68BE8D; Tue, 10 Nov 2020 12:50:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B0CF668BE54 for ; Tue, 10 Nov 2020 12:50:04 +0200 (EET) Received: by mail-wm1-f66.google.com with SMTP id 19so987837wmf.1 for ; Tue, 10 Nov 2020 02:50:04 -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=nsW1FBwo+zssPnw/9nIz+KqW6u99NQx7fGFvzHdPuyk=; b=kbtg/YXaBqr7x9O/pkkgF534hE43KZiSTaJEv9mFw2JcHjRwm9gV7bmsokttZOp6BY RsW/qFnDBtOvJU51tsJmj+HsOGH8rWspVAEU7CLAuV4R85YMw7LIgcFAOIOdgA7lPt1F Hfq/sZecpRlNSzdX70IxoCp4DUTqVcWSPAgxwIKcdWBEOXitxCqMj3AYmcFKIFI7UDd6 XwdV1uVm3Wzix+vEPckfek1maz52+sO7Bn2jSLJkGq6BycKIE+gKa+BdLPMJi9AddmFj oc2ECNU6lrmAANG8w3FxeB9kvzrTTw+rqoReZ+7DEAySpRWDV3NPd3HnYdN3Bg+MlEXe YyQw== 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=nsW1FBwo+zssPnw/9nIz+KqW6u99NQx7fGFvzHdPuyk=; b=C5NRBQlSbi9vRzWmimi2X48I0OXfsCrR2/qrQLqM+zeuQVktb+qClEncv9DkqPFi8a T42FcIgJ5Qumcf6Ts3n/bFqXyXqcpAgRnMIUKV9qSFJQWOLA1EcAf9xHKObUp4kJyGHZ pcAzKOHjLRr0c7uZf8jO37M11EAg4ww1xd0hnSNTLv5A9sJMWn6hmDgYchnGhEw8YPeD lJpIKxjZ/xh3OXtGKa3CHMfLfVmqWiyOQiSPojWBSATjiRuCT5SJ0UxY+ZitmN54iMV9 Dy96Bz7nmKPKHaDnU95WtklOgtAA5l8uGJEvlrATGi1YLoYbtZJRu4iaMOq5Eh0QVKK2 iZ2g== X-Gm-Message-State: AOAM5331d+kZoopsb0CLlKn0PSBIBL4mcpUPAzLz54ax80wf9/IyGhwj uRQuAbjhr33JTcztuoeSfICsnNYRkhY= X-Google-Smtp-Source: ABdhPJy7mGd9vxDL+aP5PFg+VRfoEr8YuK7LKj/J0tw+44a5BG1k7ZrSTkvvVe4U+iy0pX3n3aSxkQ== X-Received: by 2002:a7b:c101:: with SMTP id w1mr4068581wmi.170.1605005403966; Tue, 10 Nov 2020 02:50:03 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id l24sm2572543wmi.7.2020.11.10.02.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 02:50:03 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Nov 2020 11:47:41 +0100 Message-Id: <20201110104851.321029-45-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 044/114] 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 ef0fd6622a..4863ec0953 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); } @@ -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;