From patchwork Sat Oct 24 11:04:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23194 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 81E9144939A for ; Sat, 24 Oct 2020 14:05:44 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 658A168AB18; Sat, 24 Oct 2020 14:05:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 82CF368A98A for ; Sat, 24 Oct 2020 14:05:33 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id d3so5213800wma.4 for ; Sat, 24 Oct 2020 04:05:33 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=DXMSQB8LgsUUHi8ZkFGCooTQaMJsd6OC6XijV8EMXIM=; b=emtKJbKtJHBX0E2YAr+eCDGOsRTdHMx9oFXszZy/TWTudMYoh/9BuoHniBo7iScTNT yyHsYsUZV1NEwS6oe64JwUatSrgKTqp7Umu8gYu0KpklcqTFbHCLPkQkaIebHgfy+Jly /Fw+SZ9P22ZYsejQk8kWPHXnY+Bhj1V760KJcvyuAOdUJLpLsjupdNL7p9SZB0rAm2JP PP81RlwvgRXCTEkR2vAZN4yos3lCDGq2QMVfqxVwnnhkb9Du7t55KNxh46OHJs292aCF MHksHfPfp6Ctzg6X07+3F+/O4dpL29hGEeFcEDnDpVbcOJLYZEV3EE8cKseEb5RWXRMo t/PA== 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:mime-version:content-transfer-encoding; bh=DXMSQB8LgsUUHi8ZkFGCooTQaMJsd6OC6XijV8EMXIM=; b=bck8zDXT5LE9V8IKKpu924GAH/lqxewRUvfLgcZLpvbzb2axPbQHT+lxnZnfh5EFs1 FN+oXUp1TwS/NvS4xyNk1vwwAUx9gwgCc+wKNvGCjM0pv+sTCVnwe9jCkNHw5SLu/qb9 Q4P59I6xJ5szE0t3UAonLUKEbliTjYYtiIYJHpFaahEr8/eqjtkuV9/4AnpBeDOpdLqz cOSFtWJVbGnknie9yWU+yXwUmpDJvkBrVV2eZDDgZLVs4jFN01l+TvBvyaNa25YZs/AB ZZL9AmPLiCUPYima4VtxHE6wZgcXg0zprXuhWUa0kdFzZBTTDt2gcZ9x2igyKWR9WtSj 6CHg== X-Gm-Message-State: AOAM533qYHID4Nk+lF2loyUXvoGpJaHpEats9J30uLOOvfUKF1CTqmRi lyLZGoBraP6DUpHuoa7htvXa3sIKkVA= X-Google-Smtp-Source: ABdhPJwWV43645dcpi57JT7xIoV410Mtbq7WfaMWRkHSYp0Bf41D0MaONA0KJyYcMMZzqZZk7fl/9A== X-Received: by 2002:a1c:99d3:: with SMTP id b202mr1609087wme.0.1603537532571; Sat, 24 Oct 2020 04:05:32 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m1sm8476890wme.48.2020.10.24.04.05.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Oct 2020 04:05:32 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Oct 2020 13:04:59 +0200 Message-Id: <20201024110500.5424-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201024110500.5424-1-andreas.rheinhardt@gmail.com> References: <20201024110500.5424-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] avcodec/mobiclip: Use static 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/mobiclip.c | 71 ++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 42 deletions(-) diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c index ab4baac099..4e74033498 100644 --- a/libavcodec/mobiclip.c +++ b/libavcodec/mobiclip.c @@ -316,9 +316,6 @@ typedef struct MobiClipContext { uint8_t *bitstream; int bitstream_size; - VLC vlc[2]; - VLC mv_vlc[2][16]; - int qtab[2][64]; uint8_t pre[32]; MotionXY *motion; @@ -327,10 +324,12 @@ typedef struct MobiClipContext { BswapDSPContext bdsp; } MobiClipContext; +static VLC rl_vlc[2]; +static VLC mv_vlc[2][16]; + static av_cold int mobiclip_init(AVCodecContext *avctx) { MobiClipContext *s = avctx->priv_data; - int ret; if (avctx->width & 15 || avctx->height & 15) { av_log(avctx, AV_LOG_ERROR, "width/height not multiple of 16\n"); @@ -341,20 +340,6 @@ static av_cold int mobiclip_init(AVCodecContext *avctx) avctx->pix_fmt = AV_PIX_FMT_YUV420P; - ret = ff_init_vlc_sparse(&s->vlc[0], MOBI_RL_VLC_BITS, 104, - bits0, sizeof(*bits0), sizeof(*bits0), - codes0, sizeof(*codes0), sizeof(*codes0), - syms0, sizeof(*syms0), sizeof(*syms0), 0); - if (ret < 0) - return ret; - - ret = ff_init_vlc_sparse(&s->vlc[1], MOBI_RL_VLC_BITS, 104, - bits0, sizeof(*bits0), sizeof(*bits0), - codes0, sizeof(*codes0), sizeof(*codes0), - syms1, sizeof(*syms1), sizeof(*syms1), 0); - if (ret < 0) - return ret; - s->motion = av_calloc(avctx->width / 16 + 3, sizeof(MotionXY)); if (!s->motion) return AVERROR(ENOMEM); @@ -366,20 +351,30 @@ static av_cold int mobiclip_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } + INIT_VLC_SPARSE_STATIC(&rl_vlc[0], MOBI_RL_VLC_BITS, 104, + bits0, sizeof(*bits0), sizeof(*bits0), + codes0, sizeof(*codes0), sizeof(*codes0), + syms0, sizeof(*syms0), sizeof(*syms0), + 1 << MOBI_RL_VLC_BITS); + INIT_VLC_SPARSE_STATIC(&rl_vlc[1], MOBI_RL_VLC_BITS, 104, + bits0, sizeof(*bits0), sizeof(*bits0), + codes0, sizeof(*codes0), sizeof(*codes0), + syms1, sizeof(*syms1), sizeof(*syms1), + 1 << MOBI_RL_VLC_BITS); for (int j = 0; j < 16; j++) { - ret = ff_init_vlc_sparse(&s->mv_vlc[0][j], MOBI_MV_VLC_BITS, mv_len[j], - mv_bits_mods[j], sizeof(*mv_bits_mods[j]), sizeof(*mv_bits_mods[j]), - mv_codes_mods[j], sizeof(*mv_codes_mods[j]), sizeof(*mv_codes_mods[j]), - mv_syms_mods[j], sizeof(*mv_syms_mods[j]), sizeof(*mv_syms_mods[j]), 0); - if (ret < 0) - return ret; - - ret = ff_init_vlc_sparse(&s->mv_vlc[1][j], MOBI_MV_VLC_BITS, mv_len[j], - mv_bits[j], sizeof(*mv_bits[j]), sizeof(*mv_bits[j]), - mv_codes[j], sizeof(*mv_codes[j]), sizeof(*mv_codes[j]), - mv_syms[j], sizeof(*mv_syms[j]), sizeof(*mv_syms[j]), 0); - if (ret < 0) - return ret; + static VLC_TYPE vlc_buf[2 * 16 << MOBI_MV_VLC_BITS][2]; + mv_vlc[0][j].table = &vlc_buf[2 * j << MOBI_MV_VLC_BITS]; + mv_vlc[0][j].table_allocated = 1 << MOBI_MV_VLC_BITS; + ff_init_vlc_sparse(&mv_vlc[0][j], MOBI_MV_VLC_BITS, mv_len[j], + mv_bits_mods[j], sizeof(*mv_bits_mods[j]), sizeof(*mv_bits_mods[j]), + mv_codes_mods[j], sizeof(*mv_codes_mods[j]), sizeof(*mv_codes_mods[j]), + mv_syms_mods[j], sizeof(*mv_syms_mods[j]), sizeof(*mv_syms_mods[j]), INIT_VLC_USE_NEW_STATIC); + mv_vlc[1][j].table = &vlc_buf[(2 * j + 1) << MOBI_MV_VLC_BITS]; + mv_vlc[1][j].table_allocated = 1 << MOBI_MV_VLC_BITS; + ff_init_vlc_sparse(&mv_vlc[1][j], MOBI_MV_VLC_BITS, mv_len[j], + mv_bits[j], sizeof(*mv_bits[j]), sizeof(*mv_bits[j]), + mv_codes[j], sizeof(*mv_codes[j]), sizeof(*mv_codes[j]), + mv_syms[j], sizeof(*mv_syms[j]), sizeof(*mv_syms[j]), INIT_VLC_USE_NEW_STATIC); } return 0; @@ -465,7 +460,7 @@ static void read_run_encoding(AVCodecContext *avctx, { MobiClipContext *s = avctx->priv_data; GetBitContext *gb = &s->gb; - int n = get_vlc2(gb, s->vlc[s->dct_tab_idx].table, + int n = get_vlc2(gb, rl_vlc[s->dct_tab_idx].table, MOBI_RL_VLC_BITS, 1); *last = (n >> 11) == 1; @@ -1249,7 +1244,7 @@ static int predict_motion(AVCodecContext *avctx, for (int i = 0; i < 2; i++) { int ret, idx2; - idx2 = get_vlc2(gb, s->mv_vlc[s->moflex][tidx].table, + idx2 = get_vlc2(gb, mv_vlc[s->moflex][tidx].table, MOBI_MV_VLC_BITS, 1); ret = predict_motion(avctx, width, height, idx2, @@ -1323,7 +1318,7 @@ static int mobiclip_decode(AVCodecContext *avctx, void *data, motion[x / 16 + 2].x = 0; motion[x / 16 + 2].y = 0; - idx = get_vlc2(gb, s->mv_vlc[s->moflex][0].table, + idx = get_vlc2(gb, mv_vlc[s->moflex][0].table, MOBI_MV_VLC_BITS, 1); if (idx == 6 || idx == 7) { @@ -1382,14 +1377,6 @@ static av_cold int mobiclip_close(AVCodecContext *avctx) { MobiClipContext *s = avctx->priv_data; - ff_free_vlc(&s->vlc[0]); - ff_free_vlc(&s->vlc[1]); - - for (int i = 0; i < 16; i++) { - ff_free_vlc(&s->mv_vlc[0][i]); - ff_free_vlc(&s->mv_vlc[1][i]); - } - av_freep(&s->bitstream); s->bitstream_size = 0; av_freep(&s->motion);