From patchwork Tue Nov 10 10:58:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23569 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 D827344B238 for ; Tue, 10 Nov 2020 13:14:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 89C3868C0AE; Tue, 10 Nov 2020 12:59: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 A726368BFEB for ; Tue, 10 Nov 2020 12:59:27 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id s8so5082823wrw.10 for ; Tue, 10 Nov 2020 02:59:27 -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=s2FFLMfC1uzdUpCAPabFWeKoiqS29D4vNN2RV7T26yM=; b=AxFxVeCRU7Lvy4Ewn6ZINA+AmrSZKmE0t0fnkDdglaNXpZ/OyvI9HYv+U/TPbIY9f1 caTb68XGI9fvr2e8APAikbMnFq/WyQ8y2usMuORwcIf+vnBOr0SUQgQ8mhB0mkO0wrAR cWfgoSI/lMmWIHiYj8ItufG18cvW0F5d2CM7U6qodROnS78bcLS/TBc+Tou0KhEdQ7gp IwiVklht8ti1dQAMh+u8rWDQ2zBRqsEPPSlEZ6EECYn6iy+Qq53X+xq2Om6Xjt0oK+0R N17h0YVHBTk03xLwLBy8VTgUGKPd/1mFfyj2qpELhjGjY30zzIT2HqYgiZ+yyCVjp8xU 6fVQ== 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=s2FFLMfC1uzdUpCAPabFWeKoiqS29D4vNN2RV7T26yM=; b=XNO5vVOInLqucC6PYXnEdIRDdlj27z1mlcz3V+KOo0wAch20K8I4xoE5KvElg0NsWq hpEwEMbYzver6Lh5LnNvrItII1qZnTkFFX6InfRTyBOOTyTv1XgKAveumdUEfydcCQi6 KwBSHbqWYzkyqTz87OimCAyzswS+2Eda4ngcgsnzaxyyNAAXJFGSjGZ0PpRQPmHlK6sC zIFK685b6djlZv6swoZgPThW908TZetSym0yCruut4L38Uxiy9gisSvjKrzlyLwP7fg4 a+aD7O5rwU/fDYxcVZf/LVj13zv/fsBg9MuT86EItk1neqFK+EXm0QFROYHOR2l9rg9t 6+yw== X-Gm-Message-State: AOAM530nk/0lY6DOyHS55fdKNGC8s3wsXw+oEgfFP9xyvhevI/ZoPqD2 R44wF2hKuBFBCwLnZnmLO8xOlaUSr50= X-Google-Smtp-Source: ABdhPJxrPipEaNtPUZ4Ci0dCrOjFktAILtjN6DsW6Vnu8OqspipOBNOk7vG3OimnrF6cnM4C2P5b8A== X-Received: by 2002:adf:de05:: with SMTP id b5mr21300159wrm.131.1605005966971; Tue, 10 Nov 2020 02:59:26 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id o197sm2561308wme.17.2020.11.10.02.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 02:59:26 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Nov 2020 11:58:26 +0100 Message-Id: <20201110105836.321916-13-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 104/114] avcodec/intrax8: Avoid code duplication when initializing 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/intrax8.c | 46 ++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c index 71a50cc063..9b7958e5f2 100644 --- a/libavcodec/intrax8.c +++ b/libavcodec/intrax8.c @@ -31,6 +31,8 @@ #include "intrax8dsp.h" #include "mpegutils.h" +#define VLC_BUFFER_SIZE 28150 + #define MAX_TABLE_DEPTH(table_bits, max_bits) \ ((max_bits + table_bits - 1) / table_bits) @@ -46,21 +48,27 @@ static VLC j_ac_vlc[2][2][8]; // [quant < 13], [intra / inter], [select] static VLC j_dc_vlc[2][8]; // [quant], [select] static VLC j_orient_vlc[2][4]; // [quant], [select] +static av_cold void x8_init_vlc(VLC *vlc, int nb_bits, int nb_codes, + int *offset, const uint16_t table[][2]) +{ + static VLC_TYPE vlc_buf[VLC_BUFFER_SIZE][2]; + + vlc->table = &vlc_buf[*offset]; + vlc->table_allocated = VLC_BUFFER_SIZE - *offset; + init_vlc(vlc, nb_bits, nb_codes, &table[0][1], 4, 2, + &table[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC); + *offset += vlc->table_size; +} + static av_cold int x8_vlc_init(void) { int i; int offset = 0; - static VLC_TYPE table[28150][2]; - // set ac tables #define init_ac_vlc(dst, src) \ do { \ - dst.table = &table[offset]; \ - dst.table_allocated = FF_ARRAY_ELEMS(table) - offset; \ - init_vlc(&dst, AC_VLC_BITS, 77, &src[1], 4, 2, &src[0], 4, 2, \ - INIT_VLC_USE_NEW_STATIC); \ - offset += dst.table_size; \ + x8_init_vlc(&dst, AC_VLC_BITS, 77, &offset, &src); \ } while(0) for (i = 0; i < 8; i++) { @@ -74,11 +82,7 @@ static av_cold int x8_vlc_init(void) // set dc tables #define init_dc_vlc(dst, src) \ do { \ - dst.table = &table[offset]; \ - dst.table_allocated = FF_ARRAY_ELEMS(table) - offset; \ - init_vlc(&dst, DC_VLC_BITS, 34, &src[1], 4, 2, &src[0], 4, 2, \ - INIT_VLC_USE_NEW_STATIC); \ - offset += dst.table_size; \ + x8_init_vlc(&dst, DC_VLC_BITS, 34, &offset, &src); \ } while(0) for (i = 0; i < 8; i++) { @@ -88,22 +92,14 @@ static av_cold int x8_vlc_init(void) #undef init_dc_vlc // set orient tables -#define init_or_vlc(dst, src) \ - do { \ - dst.table = &table[offset]; \ - dst.table_allocated = FF_ARRAY_ELEMS(table) - offset; \ - init_vlc(&dst, OR_VLC_BITS, 12, &src[1], 4, 2, &src[0], 4, 2, \ - INIT_VLC_USE_NEW_STATIC); \ - offset += dst.table_size; \ - } while(0) - for (i = 0; i < 2; i++) - init_or_vlc(j_orient_vlc[0][i], x8_orient_highquant_table[i][0]); + x8_init_vlc(&j_orient_vlc[0][i], OR_VLC_BITS, 12, + &offset, x8_orient_highquant_table[i]); for (i = 0; i < 4; i++) - init_or_vlc(j_orient_vlc[1][i], x8_orient_lowquant_table[i][0]); -#undef init_or_vlc + x8_init_vlc(&j_orient_vlc[1][i], OR_VLC_BITS, 12, + &offset, x8_orient_lowquant_table[i]); - av_assert2(offset == FF_ARRAY_ELEMS(table)); + av_assert2(offset == VLC_BUFFER_SIZE); return 0; }