From patchwork Fri Nov 20 07:18:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23748 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 A2EF644A644 for ; Fri, 20 Nov 2020 09:24:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8C18068B984; Fri, 20 Nov 2020 09:24:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2899568B900 for ; Fri, 20 Nov 2020 09:24:10 +0200 (EET) Received: by mail-ej1-f68.google.com with SMTP id i19so11469688ejx.9 for ; Thu, 19 Nov 2020 23:24:10 -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=isUcl6KzQvlFd+BvfNsECK96ELHkOjs3KdIeTah0WPE=; b=XN1zUWJKOs/XNOAB32OYr9EFD70WFjQF5I08UUERqiZ63/UvXPwJW99E36njrTKtRG iBMPjEw7DXjkH5ErTxeLhcQ3hH1X6ksKdH6F4HOqwU8pKXpuQ4UibWrCiaIf2M+7yl3T UzLZcd5P0gPY+BxTQ1fZ4np/8AP5179AJBV5RG79Qzx3xIk5uhPWpf6OasJG6bS9h7Oh Q8TURWv+7LHpXq+mvUP5hxh3XEliyXubTvE+RnDg9gKTiefNdvnJSJB1D2AUSKm6iiKd 2hRQRGh6TQFUOSCOl6UmvqV5UFTyNK7+q2iyP4+yHgPTD+yyiC9pbxt3+QSsUIN97RGs GqLQ== 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=isUcl6KzQvlFd+BvfNsECK96ELHkOjs3KdIeTah0WPE=; b=afMmHFKI35Gafai8+/ndy8cKFRvhMRcaYs1Dq7rzExLHaQ42WYbn4/7uSYH9a0Qu0i 8WbrFXNAWnZECBSFlb/XpbWlmM36a19fM6MqJxPco+/H6Tg8RtlUMk6yJlJpN2ZQT/kE qWLhbutMLzpteZuDzL/TxiH4wrpNNvnkti859DsLUrgAnhLsrCxQ3st7/0s6eMNtp6HW R6F9GasBy9i9/8khJOdTHTXqzBsSX+CzL8UsUUDy53mvog8ISXzrC3+Jq7N9T8q67R7L vmnKd1ZTgu+CjRFaxPL6zZ991Q/d2CiVSbCOLgqOSJovyl6+GObSBfFcXXYZ9VfEzE7x Unag== X-Gm-Message-State: AOAM531FtyqH8Cu5fhVW9tjqAkF/VqQca3cXKvUMHjUw4BLsJ0Si50Vw y6+5aXAfTYchCscxsSbcSQ7T8sMSNWgJNA== X-Google-Smtp-Source: ABdhPJx01sIU+YVguskfXw3ZFtG6RgViDW4gul5CgotcEAcNXnG0H64PwdzqTv3CH93ibHadsey8gQ== X-Received: by 2002:a17:907:9d0:: with SMTP id bx16mr32732568ejc.426.1605857049309; Thu, 19 Nov 2020 23:24:09 -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.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:24:08 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:18:37 +0100 Message-Id: <20201120072116.818090-5-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 004/162] avcodec/bitstream: Allow static VLC tables to be bigger than needed 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" Right now the allocated size of the VLC table of a static VLC has to exactly match the size actually used for the VLC: If it is not enough, abort is called; if it is more than enough, an error message is emitted. This is no problem when one wants to initialize an individual VLC via one of the INIT_VLC macros as one just hardcodes the needed size. Yet it is an obstacle when one wants to initialize several VLCs in a loop as one then needs to add an array for the sizes/offsets of the VLC tables (unless max_depth of all arrays is one in which case the sizes are derivable from the number of bits used). Yet said size array is not necessary if one disables the warning for too big buffers. The reason is that the amount of entries needed for the table is of course generated as a byproduct of initializing the VLC. To this end a flag that disables the warning has been added. So one can proceed as follows: static VLC vlcs[NUM]; static VLC_TYPE vlc_table[BUF_SIZE][2]; for (int i = 0, offset = 0; i < NUM; i++) { vlcs[i].table = &vlc_table[offset]; vlcs[i].table_allocated = BUF_SIZE - offset; init_vlc(); /* With INIT_VLC_STATIC_OVERLONG flag */ offset += vlcs[i].table_size; } Of course, BUF_SIZE should be equal to the number of entries actually needed. Signed-off-by: Andreas Rheinhardt --- Default behaviour is unchanged as Paul wished. The reason I opted for the flag (and not AV_LOG_DEBUG) is that initialization of all static VLCs should be done via ff_thread_once() in the future (this patchset already does this for several of them), so that no logcontext will be available anyway. And therefore it should be completely quiet in normal mode. libavcodec/bitstream.c | 4 ++-- libavcodec/vlc.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index 4ce49fd51c..7570fb2204 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -281,9 +281,9 @@ static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes, int ret = build_table(vlc, nb_bits, nb_codes, codes, flags); if (flags & INIT_VLC_USE_NEW_STATIC) { - if(vlc->table_size != vlc->table_allocated) + if (vlc->table_size != vlc->table_allocated && + !(flags & (INIT_VLC_STATIC_OVERLONG & ~INIT_VLC_USE_NEW_STATIC))) av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated); - av_assert0(ret >= 0); *vlc_arg = *vlc; } else { diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h index 50a1834b84..6879c3ca6a 100644 --- a/libavcodec/vlc.h +++ b/libavcodec/vlc.h @@ -93,6 +93,7 @@ void ff_free_vlc(VLC *vlc); #define INIT_VLC_OUTPUT_LE 8 #define INIT_VLC_LE (INIT_VLC_INPUT_LE | INIT_VLC_OUTPUT_LE) #define INIT_VLC_USE_NEW_STATIC 4 +#define INIT_VLC_STATIC_OVERLONG (1 | INIT_VLC_USE_NEW_STATIC) #define INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \ h, i, j, flags, static_size) \