From patchwork Tue Nov 10 10:47:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23537 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 16AF544AD0B for ; Tue, 10 Nov 2020 13:02:56 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 085DC68BF1D; Tue, 10 Nov 2020 12:50:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9F10768BEC2 for ; Tue, 10 Nov 2020 12:50:18 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id 23so12139328wrc.8 for ; Tue, 10 Nov 2020 02:50:18 -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=CW3qGLBtCpEP6b3MjKrGYyYDtuxcdDWElbcfPE5D+0A=; b=XbZzfKeTkvZPSWAJQMaJiOfJZokh9Rq4sx7/w54XpsTpNZvdVsmVO7CEcIhoKrLH+t xhx+mK2ews6WGOE00dvG3J7FWAiT0Q/NevcmOAxMIbBL7BAWk/xIblO7uQWXVMPgJCVx u6nXCAe5hza227ESlNWKimrp4R3vAi0A21J/g9cbh/RsE0lYJTWtF/z/2lcn234ntSyV IhisCCgdlB6jkHysMnFLZOaUOPKpoCKWWklSCRJYdkpKBvjh0eWNO/T4f+nLydBeru+n THsr574hIfpXrASDfLfjyPA3vYcYvYQfAyby1S1y8r8kIJsv6ZTBCr4T393j/EtbiRb0 5aEg== 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=CW3qGLBtCpEP6b3MjKrGYyYDtuxcdDWElbcfPE5D+0A=; b=Th37/cs5fir5FjDlnRHszNbBjxqshcpWaHxFxfCW9TPWjPNjHyEJpGRdjzsOSYaV7e Zo6K0xQWFsjhAxFKikmJkt7/pC5GIby+UHMru+G5ey2QAyNWhezBT+S8QddXNFMJ5B0T T5pbXcmAqg6O0VgLrYdWe3VvHVmyuiNcep8gVJXSTgyzs1A62C0djpHhQnq4fkECcDFz od6xLW1XqWQxF5nq6c3a6EYSAJ3dBlwMpg5EM8WGwgR2oVkoZOEoiH/Tbgrxp6r9RpVK LkPjkWBmcRNcFuJL8+u56JlYSF+L/KiyNy8ErJQ4wXSKZQA7cUXMjS4p3zPjmVidiUQL viRQ== X-Gm-Message-State: AOAM533qKrCm69qWZGN13exZps1WYQvZdaFvrPwos3ayvOhBz0ZO0QWO Ty03+IXmM+/01QuEbV0I80QTrOO/cx4= X-Google-Smtp-Source: ABdhPJz7YgitOlMKAY7xw5lVXMim5I8O/EsOujL/ZmNvydYVdFln4Kfn24prDdB4Sxd7HKPGYOzBuA== X-Received: by 2002:adf:9e4c:: with SMTP id v12mr22394203wre.22.1605005417903; Tue, 10 Nov 2020 02:50:17 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 02:50:17 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Nov 2020 11:47:56 +0100 Message-Id: <20201110104851.321029-60-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 059/114] avcodec/mss4: Simplify creating VLC tables 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" The lengths of the codes used by the mss4 decoder are ascending from left to right and therefore the lengths can be run-length encoded and the codes can be easily derived from them. And this is how it is indeed done. Yet some things can nevertheless be improved: a) The number of entries of the current VLC is implicitly contained in the run-length table and needn't be externally prescribed. b) The maximum length of a code is just the length of the last code (given that the lengths are ascending), so there is no point in setting max_bits in the loop itself. c) One can offload the actual calculation of the codes to ff_init_vlc_from_lengths(). Signed-off-by: Andreas Rheinhardt --- libavcodec/mss4.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/libavcodec/mss4.c b/libavcodec/mss4.c index c421a07c5d..a459503417 100644 --- a/libavcodec/mss4.c +++ b/libavcodec/mss4.c @@ -143,25 +143,21 @@ typedef struct MSS4Context { } MSS4Context; static av_cold int mss4_init_vlc(VLC *vlc, const uint8_t *lens, - const uint8_t *syms, int num_syms) + const uint8_t *syms) { uint8_t bits[MAX_ENTRIES]; - uint16_t codes[MAX_ENTRIES]; int i, j; - int prefix = 0, max_bits = 0, idx = 0; + int idx = 0; for (i = 0; i < 16; i++) { for (j = 0; j < lens[i]; j++) { bits[idx] = i + 1; - codes[idx] = prefix++; - max_bits = i + 1; idx++; } - prefix <<= 1; } - return ff_init_vlc_sparse(vlc, FFMIN(max_bits, 9), num_syms, bits, 1, 1, - codes, 2, 2, syms, 1, 1, 0); + return ff_init_vlc_from_lengths(vlc, FFMIN(bits[idx - 1], 9), idx, + bits, 1, syms, 1, 1, 0, 0); } static av_cold int mss4_init_vlcs(MSS4Context *ctx) @@ -169,15 +165,15 @@ static av_cold int mss4_init_vlcs(MSS4Context *ctx) int ret, i; for (i = 0; i < 2; i++) { - ret = mss4_init_vlc(&ctx->dc_vlc[i], mss4_dc_vlc_lens[i], NULL, 12); + ret = mss4_init_vlc(&ctx->dc_vlc[i], mss4_dc_vlc_lens[i], NULL); if (ret) return ret; ret = mss4_init_vlc(&ctx->ac_vlc[i], mss4_ac_vlc_lens[i], - mss4_ac_vlc_syms[i], 162); + mss4_ac_vlc_syms[i]); if (ret) return ret; ret = mss4_init_vlc(&ctx->vec_entry_vlc[i], mss4_vec_entry_vlc_lens[i], - mss4_vec_entry_vlc_syms[i], 9); + mss4_vec_entry_vlc_syms[i]); if (ret) return ret; }