From patchwork Fri Nov 20 07:20:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23840 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 AFDC7448F87 for ; Fri, 20 Nov 2020 09:40:19 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2859A68BC52; Fri, 20 Nov 2020 09:25:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5439868BB4D for ; Fri, 20 Nov 2020 09:25:38 +0200 (EET) Received: by mail-ed1-f51.google.com with SMTP id q3so8445574edr.12 for ; Thu, 19 Nov 2020 23:25:38 -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=hQ0UUNPZsP/janMwKgjcg92p4dfXyf0etoKRiXzSS2M=; b=kBS/1lloaR8lQm6vgHvQOHsrqNhoK9GkLdFahWX/BwvEqbj8udmnx3wMtVNIPqFYZX 9w8ygMvqKfdeJ7PyjoeoWStQHTGqdhPy2rK3nhh0ZVwV/Zx4mcgTvINfm2ZvOZgm7Q2C lK/YXIp2a3bYskO4RgBgU/5hJxfbTVIR6fqDYpC217dD+Vs0ZmyIA350j7j6rPnLrmz9 FFSfWW2MsA1bxRL+rlVwjvZd1kqyea1Lv7s45tK15fHIWAPmoKSGmXoyY8h5cQ0ti8/N lKN+BA7BDTyIF1ro0D8Tysa5j28XnjUsG+qY6fhKPluOvIYVG0DoKRV3EQT4xHXldWA1 wD+Q== 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=hQ0UUNPZsP/janMwKgjcg92p4dfXyf0etoKRiXzSS2M=; b=SAyzS21GBNXKZuwV6ueS2zWPYoQyiY5UoAxTHC9LgWqdwFg8S5xAPbXyNKCBz2Kxhs jygKHe59Uyv+hEuXid3MnUU5Xx4Vxw+HZInN7s4/Hz9YNzQVpO5jyRM4SP/oqUoCz8+A ggy3MwwihmWoNfVb+OVqBb57VgCwZX7OvhJCZ0MoLycf+xl602xFxuauVRsofu/AgcJi XJmJivrbs2lz2s+gF7imkk0/eYj+B6EhyrTtcCjyPwvPK7ibT0L3IaAHt8lM0hYExYaI qvPcIogZmKz/GyiAjNJhav76dzn0RnhcnVGWVvapJwaJ+dlbD9Vjp62CsrgDwEXPOg+E 1Aug== X-Gm-Message-State: AOAM530WEjL7TnBLQAdHFaBKorFwPqQUsH1TUrHANX5cHbzxlRQA5f0J namZsDLqPgRW/0j2JaoLKk5IXOK739uUdg== X-Google-Smtp-Source: ABdhPJw3cuHeF3b01NfAgaJY7Ierz4Ftd+kSsL044S+QRCSV7dSdDPR9MJeDZ3Jw4o8dT37dp61qkA== X-Received: by 2002:a05:6402:3098:: with SMTP id de24mr33472973edb.155.1605857137237; Thu, 19 Nov 2020 23:25:37 -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.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:25:36 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:20:00 +0100 Message-Id: <20201120072116.818090-88-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 087/162] avcodec/mpeg4videodec: Make studio VLCs static 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/mpeg4video.h | 4 -- libavcodec/mpeg4videodec.c | 88 ++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 56 deletions(-) diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h index 3de598465f..e919db87a5 100644 --- a/libavcodec/mpeg4video.h +++ b/libavcodec/mpeg4video.h @@ -115,10 +115,6 @@ typedef struct Mpeg4DecContext { int cplx_estimation_trash_p; int cplx_estimation_trash_b; - VLC studio_intra_tab[12]; - VLC studio_luma_dc; - VLC studio_chroma_dc; - int rgb; } Mpeg4DecContext; diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index cc3c36d722..19dcaff764 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -25,6 +25,7 @@ #include "libavutil/internal.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" +#include "libavutil/thread.h" #include "error_resilience.h" #include "hwconfig.h" #include "idctdsp.h" @@ -53,6 +54,9 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb); static VLC dc_lum, dc_chrom; static VLC sprite_trajectory; static VLC mb_type_b_vlc; +static VLC studio_intra_tab[12]; +static VLC studio_luma_dc; +static VLC studio_chroma_dc; static const int mb_type_b_map[4] = { MB_TYPE_DIRECT2 | MB_TYPE_L0L1, @@ -1820,7 +1824,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0, additional_code_len, sign, mismatch; - VLC *cur_vlc = &ctx->studio_intra_tab[0]; + const VLC *cur_vlc = &studio_intra_tab[0]; uint8_t *const scantable = s->intra_scantable.permutated; const uint16_t *quant_matrix; uint32_t flc; @@ -1834,14 +1838,14 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n if (n < 4) { cc = 0; - dct_dc_size = get_vlc2(&s->gb, ctx->studio_luma_dc.table, STUDIO_INTRA_BITS, 2); + dct_dc_size = get_vlc2(&s->gb, studio_luma_dc.table, STUDIO_INTRA_BITS, 2); quant_matrix = s->intra_matrix; } else { cc = (n & 1) + 1; if (ctx->rgb) - dct_dc_size = get_vlc2(&s->gb, ctx->studio_luma_dc.table, STUDIO_INTRA_BITS, 2); + dct_dc_size = get_vlc2(&s->gb, studio_luma_dc.table, STUDIO_INTRA_BITS, 2); else - dct_dc_size = get_vlc2(&s->gb, ctx->studio_chroma_dc.table, STUDIO_INTRA_BITS, 2); + dct_dc_size = get_vlc2(&s->gb, studio_chroma_dc.table, STUDIO_INTRA_BITS, 2); quant_matrix = s->chroma_intra_matrix; } @@ -1878,7 +1882,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n } additional_code_len = ac_state_tab[group][0]; - cur_vlc = &ctx->studio_intra_tab[ac_state_tab[group][1]]; + cur_vlc = &studio_intra_tab[ac_state_tab[group][1]]; if (group == 0) { /* End of Block */ @@ -3501,40 +3505,36 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, } #endif -static av_cold int init_studio_vlcs(Mpeg4DecContext *ctx) +static av_cold void mpeg4_init_static(void) { - int i, ret; - - for (i = 0; i < 12; i++) { - ret = ff_init_vlc_from_lengths(&ctx->studio_intra_tab[i], - STUDIO_INTRA_BITS, 24, - &ff_mpeg4_studio_intra[i][0][1], 2, - &ff_mpeg4_studio_intra[i][0][0], 2, 1, - 0, 0, NULL); - - if (ret < 0) - return ret; + INIT_VLC_STATIC_FROM_LENGTHS(&studio_luma_dc, STUDIO_INTRA_BITS, 19, + &ff_mpeg4_studio_dc_luma[0][1], 2, + &ff_mpeg4_studio_dc_luma[0][0], 2, 1, + 0, 0, 528); + + INIT_VLC_STATIC_FROM_LENGTHS(&studio_chroma_dc, STUDIO_INTRA_BITS, 19, + &ff_mpeg4_studio_dc_chroma[0][1], 2, + &ff_mpeg4_studio_dc_chroma[0][0], 2, 1, + 0, 0, 528); + + for (unsigned i = 0, offset = 0; i < 12; i++) { + static VLC_TYPE vlc_buf[6498][2]; + + studio_intra_tab[i].table = &vlc_buf[offset]; + studio_intra_tab[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset; + ff_init_vlc_from_lengths(&studio_intra_tab[i], + STUDIO_INTRA_BITS, 24, + &ff_mpeg4_studio_intra[i][0][1], 2, + &ff_mpeg4_studio_intra[i][0][0], 2, 1, + 0, INIT_VLC_STATIC_OVERLONG, NULL); + offset += studio_intra_tab[i].table_size; } - - ret = ff_init_vlc_from_lengths(&ctx->studio_luma_dc, STUDIO_INTRA_BITS, 19, - &ff_mpeg4_studio_dc_luma[0][1], 2, - &ff_mpeg4_studio_dc_luma[0][0], 2, 1, - 0, 0, NULL); - if (ret < 0) - return ret; - - ret = ff_init_vlc_from_lengths(&ctx->studio_chroma_dc, STUDIO_INTRA_BITS, 19, - &ff_mpeg4_studio_dc_chroma[0][1], 2, - &ff_mpeg4_studio_dc_chroma[0][0], 2, 1, - 0, 0, NULL); - if (ret < 0) - return ret; - - return 0; + ff_mpeg4videodec_static_init(); } static av_cold int decode_init(AVCodecContext *avctx) { + static AVOnce static_init_once = AV_ONCE_INIT; Mpeg4DecContext *ctx = avctx->priv_data; MpegEncContext *s = &ctx->m; int ret; @@ -3547,10 +3547,6 @@ static av_cold int decode_init(AVCodecContext *avctx) if ((ret = ff_h263_decode_init(avctx)) < 0) return ret; - ff_mpeg4videodec_static_init(); - if ((ret = init_studio_vlcs(ctx)) < 0) - return ret; - s->h263_pred = 1; s->low_delay = 0; /* default, might be overridden in the vol header during header parsing */ s->decode_mb = mpeg4_decode_mb; @@ -3558,21 +3554,9 @@ static av_cold int decode_init(AVCodecContext *avctx) avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; - return 0; -} + ff_thread_once(&static_init_once, mpeg4_init_static); -static av_cold int decode_end(AVCodecContext *avctx) -{ - Mpeg4DecContext *ctx = avctx->priv_data; - int i; - - for (i = 0; i < 12; i++) - ff_free_vlc(&ctx->studio_intra_tab[i]); - - ff_free_vlc(&ctx->studio_luma_dc); - ff_free_vlc(&ctx->studio_chroma_dc); - - return ff_h263_decode_end(avctx); + return 0; } static const AVOption mpeg4_options[] = { @@ -3595,7 +3579,7 @@ AVCodec ff_mpeg4_decoder = { .id = AV_CODEC_ID_MPEG4, .priv_data_size = sizeof(Mpeg4DecContext), .init = decode_init, - .close = decode_end, + .close = ff_h263_decode_end, .decode = ff_h263_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY |