From patchwork Sat Oct 24 11:04:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23191 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 909EC44BC1A for ; Sat, 24 Oct 2020 14:05:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 512BC68A315; Sat, 24 Oct 2020 14:05:16 +0300 (EEST) 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 C3E4468A0C3 for ; Sat, 24 Oct 2020 14:05:08 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id d3so5213138wma.4 for ; Sat, 24 Oct 2020 04:05:08 -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:mime-version :content-transfer-encoding; bh=K1mPxQwzwWJaTH1Rq2g6RauGh8vbCFGzOBA9CKv5/Rc=; b=BFdTerYBONmoy7DG8lH4UT0lgg6U8BKH6YMcUjhkLDZzzWHXRfx//FYTMIs3wejcjS W5XoKpCfTY0e5OWOGlHODCvx35/aCip+utUlpLRP/Uc1JdpSmBw0Q9bjYB6WrbbFS8ll 8E3kqv+aXt/MG+lEgmB7OIFdmOpJ31j4+GCMF6zjxuQFShE5XjDLVppV4dOjYgsVHb2M DK1SenusiNdvY4v6fqum/lnSvfFuEhnAQaPlMz6879jDxSAV4uoyED8TdkVRUedVmkQI TBx3YVDhscUuaFHchQ54QqHBL0aMxzhxi68G8uO6KFDlQFYnFOCsPulO2PEIQWlaiyFX HElQ== 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:mime-version :content-transfer-encoding; bh=K1mPxQwzwWJaTH1Rq2g6RauGh8vbCFGzOBA9CKv5/Rc=; b=RjhumWmfiLP0++cK4UNkobhnOdL70Y5ZAPH9+W03cDgCaT2pfwkpJ6tHDENsDgbW8d qr4Z358gH/JCJ5l2ccAPz6Nqy/JxcNrQjBsQq5YElX9bx0VUxBuFg+Ym5R/KSRG+6Q1i Gv37Q5dNYfQxY8vxfUjFGRie65srUdZxYcQdw91tV7ZYZdfdqaUXXt5+r8ohviOY9Kzq 2gsSTUwC5f993IBuePrgSPZYk2Jr9xRKaUkkwCulqTsfUMjFAlzeMKmyIoxfNQL6+zFL gkSm9BQLTIjS+BPZXeoFPgE9mHJoC8F3o9B+ilTki8kSyJxULijXtNjzFm3wDD4gchSw A7bg== X-Gm-Message-State: AOAM531F440OxVUuOd4tQaTK78wpFd7plHAaO+HuSA8f3klWFaEG90q3 iY7YeJkZDuQH+1WqUUIiY2xiTgiCX2w= X-Google-Smtp-Source: ABdhPJxGoSsudZ3mmyORwtmnjGws9VPHeeHqICNv97nEjw8xj9U0XRof6CptLeaVZvLPSQN7a01D9Q== X-Received: by 2002:a1c:4306:: with SMTP id q6mr6923541wma.189.1603537507609; Sat, 24 Oct 2020 04:05:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Oct 2020 04:05:07 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Oct 2020 13:04:56 +0200 Message-Id: <20201024110500.5424-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avcodec/mobiclip: Reduce size of VLCs, inline constants 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" The longest motion vector VLC for mobiclip is six bits long, so using eight bits for the VLC table is wasteful. Furthermore, the length can be inlined. Signed-off-by: Andreas Rheinhardt --- libavcodec/mobiclip.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c index 48467614ab..8d37243d87 100644 --- a/libavcodec/mobiclip.c +++ b/libavcodec/mobiclip.c @@ -31,6 +31,8 @@ #include "golomb.h" #include "internal.h" +#define MOBI_MV_VLC_BITS 6 + static const uint8_t zigzag4x4_tab[] = { 0x00, 0x04, 0x01, 0x02, 0x05, 0x08, 0x0C, 0x09, 0x06, 0x03, 0x07, 0x0A, @@ -364,14 +366,14 @@ static av_cold int mobiclip_init(AVCodecContext *avctx) } for (int j = 0; j < 16; j++) { - ret = ff_init_vlc_sparse(&s->mv_vlc[0][j], 8, mv_len[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], 8, mv_len[j], + 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); @@ -1259,7 +1261,7 @@ static int predict_motion(AVCodecContext *avctx, int ret, idx2; idx2 = get_vlc2(gb, s->mv_vlc[s->moflex][tidx].table, - s->mv_vlc[s->moflex][tidx].bits, 1); + MOBI_MV_VLC_BITS, 1); if (idx2 < 0) return AVERROR_INVALIDDATA; @@ -1335,7 +1337,7 @@ static int mobiclip_decode(AVCodecContext *avctx, void *data, motion[x / 16 + 2].y = 0; idx = get_vlc2(gb, s->mv_vlc[s->moflex][0].table, - s->mv_vlc[s->moflex][0].bits, 1); + MOBI_MV_VLC_BITS, 1); if (idx < 0) return AVERROR_INVALIDDATA; From patchwork Sat Oct 24 11:04:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23192 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 D262544BC1A for ; Sat, 24 Oct 2020 14:05:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AC2E868A903; Sat, 24 Oct 2020 14:05:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 86B1D689A01 for ; Sat, 24 Oct 2020 14:05:31 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id w23so3707005wmi.4 for ; Sat, 24 Oct 2020 04:05:31 -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=ALdbyrZdB0skhW0XxdKCJf0t/QaYi04X29sunTBtpac=; b=VoqOBFkwTO1ma/aNeNg+/+DtEjHCTMq82mVUzoSa8FlUWnWQVfWRZ8+ixQJ0E+V/nl aHld502PDQ9TEZdkoSYIlyhSj9pmVul01XjIs1AfL5u2SvmeCen+fi9IOVTPVFJt6Y+z SU4PYgynKSN+CxLaeXN2ffl56kP0jJIyrx6FqGKMR7jzr2RuuMsENrkDGpcGJB7Ghgym JnZ3ZfiwVXudb+nCZO4XXM3LoZodTRdX+qTD+KkylkVaEuJL65TTPU0vNdzwPjqFbpp2 FFdfP+jezaTIxRewZcQAXxVAjc0NEtElqt0E6jEEGQZ+K+C3i6PBlnLUSvN/qZaW87mo ggvg== 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=ALdbyrZdB0skhW0XxdKCJf0t/QaYi04X29sunTBtpac=; b=S8ifNp5E4Rt36pV2fyjuxwer+UhPIgAjy2LfbAuvsS0L6zBhRdUCiScRrimeu3Y/y1 Rse54CzEQAxNoDd/ZQbblrP1eUvVQA/TWQUldde3iaFy/g6frs6GhbzNHSphSD5sGX4d 3o7vvXlbWQdKZHpDz0jATS75muwU6hfQRzwIDj8IFF/7bKjwgsM7aQb8Z9tE8D5H30O0 wYroi7UQPi2GCpayq+HrhcHnoILvxqS5+R98/bzeg3K3bCsYHb8sbDtfBmNf49Luy0/d LBpdc/GV9xbnkviId31MzRJuEzjoerkiHj2yOyUcuZt4HEfIV+dv0idnb4TmSbgCIelm KJ5w== X-Gm-Message-State: AOAM530DTR4Helwl+E0tRM8HQL2uSF8n5z6wu+aIytgxeVAaeBsHg1hu Qy6sJPVBJoURTWSZ36yrbbxSObsxppY= X-Google-Smtp-Source: ABdhPJzgXF+KFhwy5OZP3ajNkCd0moSTsANlyhnUDeWCgdpCkdGJ2Vxh6hLvKUdpexLHn+emgkNhNw== X-Received: by 2002:a1c:9e0e:: with SMTP id h14mr6327525wme.18.1603537530762; Sat, 24 Oct 2020 04:05:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Oct 2020 04:05:30 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Oct 2020 13:04:57 +0200 Message-Id: <20201024110500.5424-2-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 2/5] avcodec/mobiclip: Don't check for errors for complete 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/mobiclip.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c index 8d37243d87..d209a53b07 100644 --- a/libavcodec/mobiclip.c +++ b/libavcodec/mobiclip.c @@ -459,7 +459,7 @@ static void idct(int *arr, int size) arr[7] = tmp[0] - x0; } -static int read_run_encoding(AVCodecContext *avctx, +static void read_run_encoding(AVCodecContext *avctx, int *last, int *run, int *level) { MobiClipContext *s = avctx->priv_data; @@ -467,14 +467,9 @@ static int read_run_encoding(AVCodecContext *avctx, int n = get_vlc2(gb, s->vlc[s->dct_tab_idx].table, s->vlc[s->dct_tab_idx].bits, 2); - if (n < 0) - return AVERROR_INVALIDDATA; - *last = (n >> 11) == 1; *run = (n >> 5) & 0x3F; *level = n & 0x1F; - - return 0; } static int add_coefficients(AVCodecContext *avctx, AVFrame *frame, @@ -486,29 +481,22 @@ static int add_coefficients(AVCodecContext *avctx, AVFrame *frame, const uint8_t *ztab = size == 8 ? ff_zigzag_direct : zigzag4x4_tab; const int *qtab = s->qtab[size == 8]; uint8_t *dst = frame->data[plane] + by * frame->linesize[plane] + bx; - int ret = 0; for (int pos = 0; get_bits_left(gb) > 0; pos++) { int qval, last, run, level; - ret = read_run_encoding(avctx, &last, &run, &level); - if (ret < 0) - return ret; + read_run_encoding(avctx, &last, &run, &level); if (level) { if (get_bits1(gb)) level = -level; } else if (!get_bits1(gb)) { - ret = read_run_encoding(avctx, &last, &run, &level); - if (ret < 0) - return ret; + read_run_encoding(avctx, &last, &run, &level); level += run_residue[s->dct_tab_idx][(last ? 64 : 0) + run]; if (get_bits1(gb)) level = -level; } else if (!get_bits1(gb)) { - ret = read_run_encoding(avctx, &last, &run, &level); - if (ret < 0) - return ret; + read_run_encoding(avctx, &last, &run, &level); run += run_residue[s->dct_tab_idx][128 + (last ? 64 : 0) + level]; if (get_bits1(gb)) level = -level; @@ -547,7 +535,7 @@ static int add_coefficients(AVCodecContext *avctx, AVFrame *frame, dst += frame->linesize[plane]; } - return ret; + return 0; } static int add_pframe_coefficients(AVCodecContext *avctx, AVFrame *frame, @@ -1262,8 +1250,6 @@ static int predict_motion(AVCodecContext *avctx, idx2 = get_vlc2(gb, s->mv_vlc[s->moflex][tidx].table, MOBI_MV_VLC_BITS, 1); - if (idx2 < 0) - return AVERROR_INVALIDDATA; ret = predict_motion(avctx, width, height, idx2, offsetm, offsetx + i * adjx, offsety + i * adjy); @@ -1338,8 +1324,6 @@ static int mobiclip_decode(AVCodecContext *avctx, void *data, idx = get_vlc2(gb, s->mv_vlc[s->moflex][0].table, MOBI_MV_VLC_BITS, 1); - if (idx < 0) - return AVERROR_INVALIDDATA; if (idx == 6 || idx == 7) { ret = decode_macroblock(avctx, frame, x, y, idx == 7); From patchwork Sat Oct 24 11:04:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23193 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 62DF7442607 for ; Sat, 24 Oct 2020 14:05:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1B40168A9BB; Sat, 24 Oct 2020 14:05:40 +0300 (EEST) 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 6575E68A7F2 for ; Sat, 24 Oct 2020 14:05:32 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id k21so2713294wmi.1 for ; Sat, 24 Oct 2020 04:05:32 -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=5/jZSkI+kFZn/4ZsPVRHTPF5IdimyU+NTDInjfJjtEc=; b=TAfbcpOBwoxnrNeFqv7NuRIM/ai7/UgmHZCvEge4xeit0c225KT5Ip7X1DQ1rzR5HT o8YcKKXnvfi2fglM6i6ic5hJ31XahICIZaKnQj+TmTOguahLDiMOjnqM9QIYnlGb52I0 l4aTrL0JEtBh1A4piyjs/woOytBO6OV0PSJjdZ8d2cQ9EUTnhjHFKSLnIMjbPsP4VtlU 7pgbeng+hKBnzuOt4oHlKx5ItMSjtaXE/GCMnzl/3c0ji0Rr+MdZ/is+OJ/NvErUQICE VqIoLnEZQPH/D5ZIHLiQKLLc2+FhBuC6vpPyCnol6Kw9YNwmSnLZ0turye8KFbDXK2lK GZzg== 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=5/jZSkI+kFZn/4ZsPVRHTPF5IdimyU+NTDInjfJjtEc=; b=EqMwBdu7SLgHyJH3qHgYp9BN9bwOg3uU2V+O6HJyC75FJqhTNqV0vWc+e3n5CYGI7F Bp2O2mT30/wPy7/jHfoAMbY8wmzoLlHnnY97r/DL0KfHAtfppqN9EmnwaQ23YWkAUNHX 5r45XqvaIv1jiN1VZmCc94iGLdn3jV9xsWqUNbQJJLztMR9DhhZo6O0kHlEooN98XUPt +oPqY6aOZpIt93xRTgvr4k7Ky5YuSdmfD3LtKWq2puNk3f7PSCJ2v++f3vYSaPHvBsyl CO0Sobj62NBfovrYbhNYoH5QTpae3cFXZc0XMv+mXLjbO8fnUId0RF+zDzpVeW/hEU+m itSw== X-Gm-Message-State: AOAM533PrESZZ0IoQusvt3ynUPzjot4387T4nrwGArHPR9JEFyQ7APwK oiBI5virB42Rbiyo7glV0D2mdkyIftc= X-Google-Smtp-Source: ABdhPJx5qCBPJ6x7ICVVXf3xoDI949MJQ/HGMecrPYWBGdYAU4P74BgRYO7ClzS9FdJYmS2SwIB27w== X-Received: by 2002:a7b:cf04:: with SMTP id l4mr7041079wmg.137.1603537531608; Sat, 24 Oct 2020 04:05:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Oct 2020 04:05:31 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Oct 2020 13:04:58 +0200 Message-Id: <20201024110500.5424-3-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 3/5] avcodec/mobiclip: Don't use too big max_depth, inline constants 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c index d209a53b07..ab4baac099 100644 --- a/libavcodec/mobiclip.c +++ b/libavcodec/mobiclip.c @@ -31,6 +31,7 @@ #include "golomb.h" #include "internal.h" +#define MOBI_RL_VLC_BITS 12 #define MOBI_MV_VLC_BITS 6 static const uint8_t zigzag4x4_tab[] = @@ -340,14 +341,14 @@ static av_cold int mobiclip_init(AVCodecContext *avctx) avctx->pix_fmt = AV_PIX_FMT_YUV420P; - ret = ff_init_vlc_sparse(&s->vlc[0], 12, 104, + 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], 12, 104, + 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); @@ -465,7 +466,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, - s->vlc[s->dct_tab_idx].bits, 2); + MOBI_RL_VLC_BITS, 1); *last = (n >> 11) == 1; *run = (n >> 5) & 0x3F; 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); From patchwork Sat Oct 24 11:05: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: 23195 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 9EE1B44939A for ; Sat, 24 Oct 2020 14:05:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8302B68AC4C; Sat, 24 Oct 2020 14:05:45 +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 1C80868004A for ; Sat, 24 Oct 2020 14:05:34 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id l20so2179307wme.0 for ; Sat, 24 Oct 2020 04:05:34 -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=Z/9qDrodoLSlEjI/1zjY6btYq7JqXJtft+bAzzgb5jk=; b=h69ZPYqh3SWlWo64STz/kKkj4J5c/WtoZTKKaFqKrMff6UbdWBEJ8w8O3oR5/m1SsD aTBeFVF8gd7fPtvLZqLIyJdUTPHsycNXw/4jEEX3ae/LukCt4B4tIrbk0I5YUrUbEwOR 6m01cUtxdyj+Nu8u5rIx9EvV5juMpOdiOW2+wqg/uoVL0AYJgGRLkMzO5wKgOwyYDQQf ouYs07b566NqjJH7wcombUc+Wr6Ec0AhNgDQ6NmiG8mzgwMNcrZR4kjX9QRcIB0xFQAk MVR3l+eMhniMZZ9pZV1mElpSWKXaR3GdZ/Xd+Ctt7XMCky8pYCgPv1bkYsjhkHKbAVrg I9Sw== 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=Z/9qDrodoLSlEjI/1zjY6btYq7JqXJtft+bAzzgb5jk=; b=NSrArh75//NmE2MqjKSbAJJ3yHoQNFcspLJjbo8BssA9ipmPYg4Rx1GBrz7913TCIS 0ngmALbOkyaiSzxzMcL48cGvk7WDdFnqmqYytPg9xYUdPYrOrZZUG2+0mfIL822GHfgd TqZKpOqr3vDQRGKqOo7x1mNDjOC/Q7kkyi2D/c1xO7bp5GvsR4MZVFyaOJA7NtA2cC3C 4hhvU6qgRUbGxS3H0WwhjAwBX4L4KE9YYImdrOO+sP9LjdRE2cCSVKmaupo9qR8JYA3q 8DZoD5wAPExu5HNu1inweTDwxuZXGRrTVtBOpw/30kwixDsgZ5M/fNeNzXoFR8nt+qgo EhAw== X-Gm-Message-State: AOAM531276qhgOzkGkvuCWK1EqfJgUK60EXTPuylcbx0MkmyUSAi0y0a GvCPOC0R01RI+PyOB1963ndpMSoftg8= X-Google-Smtp-Source: ABdhPJy0qsR2KQYtseR1+YFEBF2aqyispp1Tb1fivzSWXZ97Y6pcdjhnNykXm54w6JcRp6JaK5oEZA== X-Received: by 2002:a1c:9a4b:: with SMTP id c72mr6325954wme.157.1603537533368; Sat, 24 Oct 2020 04:05:33 -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.32 (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:05:00 +0200 Message-Id: <20201024110500.5424-5-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 5/5] avcodec/mobiclip: Use smaller type for codes 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" Even though the length of these codes is > 8, only the lowest seven bits are ever set (because the long codes are on the left of the tree), so one can use an uint8_t for them, saving space. Signed-off-by: Andreas Rheinhardt --- libavcodec/mobiclip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c index 4e74033498..9fa88e84a0 100644 --- a/libavcodec/mobiclip.c +++ b/libavcodec/mobiclip.c @@ -128,7 +128,7 @@ static const uint8_t bits0[] = { 6, 6, 6, 6, 6, 6, 5, 5, 5, 4, 2, 3, 4, 4, }; -static const uint16_t codes0[] = { +static const uint8_t codes0[] = { 0x0, 0x4, 0x5, 0x6, 0x7, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,