From patchwork Tue Nov 10 10:47:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23470 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 C4027449B06 for ; Tue, 10 Nov 2020 12:49:32 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A1B9368BDAA; Tue, 10 Nov 2020 12:49:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9449868BD9D for ; Tue, 10 Nov 2020 12:49:23 +0200 (EET) Received: by mail-wm1-f67.google.com with SMTP id 10so2532332wml.2 for ; Tue, 10 Nov 2020 02:49:23 -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=kGiLO41i/fx/mCJwNEdS9v/rAIsFqjA044SDP/O7uho=; b=YMCq58w6qb+YIwrN7w/SKfbgihE078t8v35SVYhKnpj1GOC8XusGBVB8kdg2/llOrL chsfEU4mwid1u2l79rZ1XsLTx4Z4OELy1HzJKaMqxTWc4aewjc0C1o41sUKt7ITZfazN aomvVT8t6NoQKdoidx4p1tkSOloIuZkCPP9B6IYo33fdSXO++pkgNhRTqnEKpoILkSpd iz/T+5kKqGIWolWDLi01t2/eR2ghILgNudl/o6JfB9Z4E26OBD5uqJfwf8hNw6UpEBrQ zSpFXXCrJC1sxUVndLW6yPJ380hMXG0drw34WRNclMAmWD4iRbwQPl+/kCs1eblT7NOS 9d6A== 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=kGiLO41i/fx/mCJwNEdS9v/rAIsFqjA044SDP/O7uho=; b=HitkqufCcYY2JBkqWQEBikAJ0HBQu5CN8ZDuj73nVg1L5ZbnnkIvCMH27xBnvvYVZ8 yXIkysk0jCDCJ+BCG8KFUbl0dCeMvGB8Uw1ySsqZk9DexvV1ZI9T//rtM9c0BKErxhzo YDuNZerY4CHilaGPcWuObSp14i3hIApqn8gbAw0EABHHYvKlanlHj+6tgkZyxrB3SSbE PPmhm1DksY3+d2/UFUxzdYmrMeOb8QS7F879gmlwgfp/ITbwPLU8J7SnTIzJ52iq2BF0 aqFYyZGxIisjDe41Hju+RssqEcu+flh9otyj6MQ4ne692uH8qvC+/9PWYsyrVQDYIIG6 Liyg== X-Gm-Message-State: AOAM532bWIgklqOBmlSCRUvKeZvbk8bHerSt2/ViTpqRwjhImbXtPq2v cShNG7MuXMeeYTaXYgXUYBYvB+RP3/k= X-Google-Smtp-Source: ABdhPJzxKuYAhlSHRghE+3R37F/TbNi+/AX9/Hso1L6l2YslEliPsdCYV9DWeofDCTSQg6BfZx18Tw== X-Received: by 2002:a1c:3907:: with SMTP id g7mr4023574wma.176.1605005362780; Tue, 10 Nov 2020 02:49:22 -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.49.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 02:49:22 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Nov 2020 11:47:01 +0100 Message-Id: <20201110104851.321029-5-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 004/114] 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 removes 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. 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(); offset += vlcs[i].table_size; } Of course, BUF_SIZE should be equal to the number of entries actually needed. Signed-off-by: Andreas Rheinhardt --- libavcodec/bitstream.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index 03d39ad88c..4ffec7e17a 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -281,9 +281,6 @@ 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) - 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 {