From patchwork Mon Oct 12 08:12:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22862 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 38A9544B947 for ; Mon, 12 Oct 2020 11:12:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 12AB068BB64; Mon, 12 Oct 2020 11:12:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0BD7B68BB55 for ; Mon, 12 Oct 2020 11:12:28 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id y12so12679372wrp.6 for ; Mon, 12 Oct 2020 01:12:28 -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:reply-to:mime-version :content-transfer-encoding; bh=1Uq75cNhPsRAlHZY7Fcr9eyepLPlKP4TahlSJhvT4Vg=; b=jiV3bwtdpi7VkhUFAl/1A6lLI6AbHEimsZdR/OqE9N7GAOcVHTZAL0SIxD4i6vXnwm s0GRazhHO2QS1Q0lYOK4VQXf4cSD1+J2a9saN1G2Orlt6bbfmOnBAW+N5Xu6DXroMeOL Wm60Ypa5Rk48ZUNS5aetUavOOEwjact8bOOX8MQBRWXb2tgPOoAj7B9Wc9ysLAgPvETI 5vTkubiwlxm7zz59bhytKyDK8EQnwfr00isB/z8O5CWX0iJ97ViYJfrsOjk4rZVt7uqT JWAJuGr2dEHLkvVZ3453bzWGN6AwIllJqBRAUB9Fh1rbkS6BWZqHNV401WVFVqoAy0gM 3y8A== 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:reply-to :mime-version:content-transfer-encoding; bh=1Uq75cNhPsRAlHZY7Fcr9eyepLPlKP4TahlSJhvT4Vg=; b=m+cu5fO0YK0NhXkmA/d69i+ECEHjq3EDMDdtNor17nxe8kpgZgWskWhnEuQUIKSa+R 2fHwN46DMq39eI/mubiDhEOYgw163tnFd5t+YCxy/HQOqz3LZOMOvlJ2yLxiIBxgOInm Snuym+p335gab1eW5HMOU0jNBty8XtIfGQT+MFWPXGRHsxZAvKEZJ+y6VGWSJ0LTQxyT Wa/e/WYGBS7Z47XqweA5jvw4GkvltecNkMu96+LUIKopdEZWXYxVpea1CwDFWL7GiN1Y TEfDof9A6cAUA3u81qZBgOd64TfitMZfTEq3cQaGm6KJkDji0rcN2rlAsLvw3j/SYhai WJqg== X-Gm-Message-State: AOAM530epb1AFchyrOpXCsPYBITPKjA6Ap1lhjx5DJiRm2uGiQEstFYs 9Nro/lThCSAep6+8A1uPT8HE6y/1AvA= X-Google-Smtp-Source: ABdhPJx8NGaWDBvX682W8krSIN+LIyPqK76g5LYDkL96tyJXVpCKQyJZVIYVaO1sIkG0Zn3BNzKgqQ== X-Received: by 2002:adf:d850:: with SMTP id k16mr28319238wrl.259.1602490347124; Mon, 12 Oct 2020 01:12:27 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id j7sm2247928wmc.7.2020.10.12.01.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 01:12:26 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Oct 2020 10:12:11 +0200 Message-Id: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/7] avcodec/indeo2: Remove #ifdef BITSTREAM_READER_LE cruft 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" Before the LE bitstream reader was used in the Indeo 2 decoder, a standard BE bitstream reader with swapped bits was used; when the LE bitstream reader was added, the old code was only #ifdef'ed away and not removed. Said code has several problems: It modifies the input packet without ensuring that the packet is indeed writable; and it doesn't work since 09c4e5c5988c0037d108c5fc2a137d9ad488f7f4 because said commit removed the BE table used to initialize the VLC table. So just remove this cruft from the actual decoder, too. Also use INIT_LE_VLC_STATIC while at it. Signed-off-by: Andreas Rheinhardt --- libavcodec/indeo2.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c index ccf6cd84cb..7a568bfbc4 100644 --- a/libavcodec/indeo2.c +++ b/libavcodec/indeo2.c @@ -174,10 +174,6 @@ static int ir2_decode_frame(AVCodecContext *avctx, s->decode_delta = buf[18]; /* decide whether frame uses deltas or not */ -#ifndef BITSTREAM_READER_LE - for (i = 0; i < buf_size; i++) - buf[i] = ff_reverse[buf[i]]; -#endif if ((ret = init_get_bits8(&s->gb, buf + start, buf_size - start)) < 0) return ret; @@ -232,7 +228,6 @@ static int ir2_decode_frame(AVCodecContext *avctx, static av_cold int ir2_decode_init(AVCodecContext *avctx) { Ir2Context * const ic = avctx->priv_data; - static VLC_TYPE vlc_tables[1 << CODE_VLC_BITS][2]; ic->avctx = avctx; @@ -242,17 +237,9 @@ static av_cold int ir2_decode_init(AVCodecContext *avctx) if (!ic->picture) return AVERROR(ENOMEM); - ir2_vlc.table = vlc_tables; - ir2_vlc.table_allocated = 1 << CODE_VLC_BITS; -#ifdef BITSTREAM_READER_LE - init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, - &ir2_codes[0][1], 4, 2, - &ir2_codes[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE); -#else - init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, - &ir2_codes[0][1], 4, 2, - &ir2_codes[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC); -#endif + INIT_LE_VLC_STATIC(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, + &ir2_codes[0][1], 4, 2, + &ir2_codes[0][0], 4, 2, 1 << CODE_VLC_BITS); return 0; } From patchwork Mon Oct 12 08:12:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22863 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 5CCBB44B947 for ; Mon, 12 Oct 2020 11:12:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4923C68BB74; Mon, 12 Oct 2020 11:12:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 72C1C68BB6C for ; Mon, 12 Oct 2020 11:12:44 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id e18so18043333wrw.9 for ; Mon, 12 Oct 2020 01:12:44 -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:reply-to :mime-version:content-transfer-encoding; bh=xxAuykg/Cpv2wUUxcy32wrVwvm8OjV1uMxXFZrKWULU=; b=eFrT/30ok5If6+QLLXM+H1oMG0jylF9PrtA2S9HBcJWIGtzaNKpnBBR9sNRqzo106G zQvvaHBW3vUU56cvlv9nQtkSIpPfoNPNgEA2LRdaiZGiWaT5uq+MJBepVUyXiDoLai/k O1G95zNndK5ArMV2PoABwM0+z5/rIoM2afMRP121PgmcrwSbXyJ7vRxMsR6z9wu8sk6f v4Hhpy//rBzr9qmybAIWQkL5udB62glnepIxZAzIQqqOwSocQt2h0MnI3/1IVN6aYS/o ZsIoLnyRV47yLmpQ6LDByKrdcevN3G76vv73ZaRZK++fajBKpx7MYAJ9DUp/DAlb7q3w wWWQ== 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=xxAuykg/Cpv2wUUxcy32wrVwvm8OjV1uMxXFZrKWULU=; b=CT+phMioHP7YnHU+KbqsmLotNVbyXWHoTDWlKs+dN1w0Djw314IPTkIDjI0ryZ7POr uzAdKqk7uy5dULqAZTDbaFVaBmDBkWGKlvyBIFI7sUgizsrXAVgi6hjL/VXZteGT3gJA NsHM1bNEMklDlwn/iFuLpjMr7SXx5QR1NL9mR4GwDY6Gv3wIW06uklAKNKaNrICiHNFT JwWuVKi6/0TFHcthzGERxbMQ7KLm4IwiRASkGqB1VIoZCOqxZwocv3ak+s8TKQbpFT8U Lp66hBYpiEZlH37HNCasRuIWudpu7ho7vsM6tYDpX/xfuuplUf73pkDo0+JLfGxnbFCf n03w== X-Gm-Message-State: AOAM531WYiS7w340PwktPetPZMAnU87SQtv84Jgi7ilYI100hmZdVnIL D7xCRoGUykWddLHqvlKAWekCjlvVQD4= X-Google-Smtp-Source: ABdhPJzFKoT/YmgCjkjt5/B3j0xSG4lcg/49yrXbwMQPGPY6tEZvSg+GNcaTHYF5tjoFxEevI9qfQA== X-Received: by 2002:adf:f792:: with SMTP id q18mr1516984wrp.333.1602490363764; Mon, 12 Oct 2020 01:12:43 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id j7sm2247928wmc.7.2020.10.12.01.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 01:12:43 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Oct 2020 10:12:12 +0200 Message-Id: <20201012081217.1643833-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> References: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/7] avcodec/speedhq: Don't pretend reading DC can fail 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" It can't, because the tables used don't have any loose ends. This also fixes a bug in the only caller of decode_dc_le(): It didn't check the return value. Signed-off-by: Andreas Rheinhardt --- libavcodec/speedhq.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c index b834b79f28..64758164de 100644 --- a/libavcodec/speedhq.c +++ b/libavcodec/speedhq.c @@ -168,10 +168,6 @@ static inline int decode_dc_le(GetBitContext *gb, int component) } else { code = get_vlc2(gb, ff_dc_chroma_vlc_le.table, DC_VLC_BITS, 2); } - if (code < 0) { - av_log(NULL, AV_LOG_ERROR, "invalid dc code at\n"); - return 0xffff; - } if (!code) { diff = 0; } else { From patchwork Mon Oct 12 08:12:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22864 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 3280344B947 for ; Mon, 12 Oct 2020 11:12:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1C66C68BB7C; Mon, 12 Oct 2020 11:12:52 +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 DAD1E68BB76 for ; Mon, 12 Oct 2020 11:12:45 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id p15so16356712wmi.4 for ; Mon, 12 Oct 2020 01:12:45 -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:reply-to :mime-version:content-transfer-encoding; bh=4YBz8ssmhNavNBvfIgRWfXPFdYDvYSicDPbtQvbrU0g=; b=j52OawHHBdfVHTqKH6j6XY5fx3hsYBx7u6308RUJhDDtNByZbHD+YNqJ043y/PaInr TYkmWCH/6kb9NFt3jhqVVqZcJXi2AztGf1ozs7NwFOE1E/eqb0ZP9Uoc9EPhX6jT2MVx 6KUCNm5pXg2Mqhb6Nu0CKTDdsvj/zFijtfi69KMhGJUImRe+Omf2PrchLk0AWMmYqm7d O6xyOXw/6EdAkkgc2v9C+H5fqIyKJQLf8ChVsdEoOn183zweFxLTXNeKn6TJOkLHNOgA ATy/T+HH2TvKLX8Gi+6RwB2nNYoAxtgh27tADziiJqF1tnq5Zck4tOrYCT+pVfL7/dQi uZbw== 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=4YBz8ssmhNavNBvfIgRWfXPFdYDvYSicDPbtQvbrU0g=; b=gp/DTA0AgVqxaTesCiIq8lLS1nnfhgpW3PKLJSzZHhTvhQJrXqLr7grIUSH9IXP6bH nSuE4OjEvjLAf+R892+ouJYc+zAwvhUq+/NGMqW5HA0KdFJaO+HStuZ/3nCu/E36jESV XGcNqGt7Lj1Rh2vL7+HKq0Y/+PHsBRqYlWqyI+6mFacvdX7h19nSVz9alDF48TnLxDgc 9fAv3GqOi2JcxvFXL0Xux0CbiepgzimZMUUjaTnmzl+C8VvUBi0C+flOEaUxKGDf7Z8W gj9GdrZ41K7PzYX0F89ulAmK+nFhxzhqX6PUYyuE1Zj6BiDTt+H2In/3lshm/pAHIjJY Palw== X-Gm-Message-State: AOAM533NubwgSioBxwfm9G31uhjQC/nxHEAfXO34LjVe28eE89N+9EYb pHpqpvDOPV+PNpApJ5IWPIZfu756Vik= X-Google-Smtp-Source: ABdhPJxm24/9e5ZseD/fw0YsUIYRNhH5WhY+SMhze2KBilR5NO6yytMLbpRWYLZ8mseIN8nhKLsHEg== X-Received: by 2002:a7b:cb44:: with SMTP id v4mr9594758wmj.101.1602490364889; Mon, 12 Oct 2020 01:12:44 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id j7sm2247928wmc.7.2020.10.12.01.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 01:12:44 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Oct 2020 10:12:13 +0200 Message-Id: <20201012081217.1643833-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> References: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/7] avcodec/speedhq: Don't use ff_ prefix for static symbols 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/speedhq.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c index 64758164de..5759cdb036 100644 --- a/libavcodec/speedhq.c +++ b/libavcodec/speedhq.c @@ -132,7 +132,7 @@ static const uint8_t speedhq_run[121] = { 31, }; -static RLTable ff_rl_speedhq = { +static RLTable rl_speedhq = { 121, 121, (const uint16_t (*)[])speedhq_vlc, @@ -152,21 +152,21 @@ static const uint8_t unscaled_quant_matrix[64] = { 27, 29, 35, 38, 46, 56, 69, 83 }; -static uint8_t ff_speedhq_static_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; +static uint8_t speedhq_static_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; -static VLC ff_dc_lum_vlc_le; -static VLC ff_dc_chroma_vlc_le; -static VLC ff_dc_alpha_run_vlc_le; -static VLC ff_dc_alpha_level_vlc_le; +static VLC dc_lum_vlc_le; +static VLC dc_chroma_vlc_le; +static VLC dc_alpha_run_vlc_le; +static VLC dc_alpha_level_vlc_le; static inline int decode_dc_le(GetBitContext *gb, int component) { int code, diff; if (component == 0 || component == 3) { - code = get_vlc2(gb, ff_dc_lum_vlc_le.table, DC_VLC_BITS, 2); + code = get_vlc2(gb, dc_lum_vlc_le.table, DC_VLC_BITS, 2); } else { - code = get_vlc2(gb, ff_dc_chroma_vlc_le.table, DC_VLC_BITS, 2); + code = get_vlc2(gb, dc_chroma_vlc_le.table, DC_VLC_BITS, 2); } if (!code) { diff = 0; @@ -190,7 +190,7 @@ static inline int decode_alpha_block(const SHQContext *s, GetBitContext *gb, uin int run, level; UPDATE_CACHE_LE(re, gb); - GET_VLC(run, re, gb, ff_dc_alpha_run_vlc_le.table, ALPHA_VLC_BITS, 2); + GET_VLC(run, re, gb, dc_alpha_run_vlc_le.table, ALPHA_VLC_BITS, 2); if (run < 0) break; i += run; @@ -198,7 +198,7 @@ static inline int decode_alpha_block(const SHQContext *s, GetBitContext *gb, uin return AVERROR_INVALIDDATA; UPDATE_CACHE_LE(re, gb); - GET_VLC(level, re, gb, ff_dc_alpha_level_vlc_le.table, ALPHA_VLC_BITS, 2); + GET_VLC(level, re, gb, dc_alpha_level_vlc_le.table, ALPHA_VLC_BITS, 2); block[i++] = level; } @@ -236,7 +236,7 @@ static inline int decode_dct_block(const SHQContext *s, GetBitContext *gb, int l for ( ;; ) { int level, run; UPDATE_CACHE_LE(re, gb); - GET_RL_VLC(level, run, re, gb, ff_rl_speedhq.rl_vlc[0], + GET_RL_VLC(level, run, re, gb, rl_speedhq.rl_vlc[0], TEX_VLC_BITS, 2, 0); if (level == 127) { break; @@ -511,7 +511,7 @@ static av_cold void compute_alpha_vlcs(void) av_assert0(entry == FF_ARRAY_ELEMS(run_code)); - INIT_LE_VLC_SPARSE_STATIC(&ff_dc_alpha_run_vlc_le, ALPHA_VLC_BITS, + INIT_LE_VLC_SPARSE_STATIC(&dc_alpha_run_vlc_le, ALPHA_VLC_BITS, FF_ARRAY_ELEMS(run_code), run_bits, 1, 1, run_code, 2, 2, @@ -551,7 +551,7 @@ static av_cold void compute_alpha_vlcs(void) av_assert0(entry == FF_ARRAY_ELEMS(level_code)); - INIT_LE_VLC_SPARSE_STATIC(&ff_dc_alpha_level_vlc_le, ALPHA_VLC_BITS, + INIT_LE_VLC_SPARSE_STATIC(&dc_alpha_level_vlc_le, ALPHA_VLC_BITS, FF_ARRAY_ELEMS(level_code), level_bits, 1, 1, level_code, 2, 2, @@ -582,19 +582,19 @@ static av_cold void speedhq_static_init(void) ff_mpeg12_vlc_dc_lum_bits, ff_mpeg12_vlc_dc_lum_code_reversed, 12); - INIT_LE_VLC_STATIC(&ff_dc_lum_vlc_le, DC_VLC_BITS, 12, + INIT_LE_VLC_STATIC(&dc_lum_vlc_le, DC_VLC_BITS, 12, ff_mpeg12_vlc_dc_lum_bits, 1, 1, ff_mpeg12_vlc_dc_lum_code_reversed, 2, 2, 512); reverse_code(ff_mpeg12_vlc_dc_chroma_code, ff_mpeg12_vlc_dc_chroma_bits, ff_mpeg12_vlc_dc_chroma_code_reversed, 12); - INIT_LE_VLC_STATIC(&ff_dc_chroma_vlc_le, DC_VLC_BITS, 12, + INIT_LE_VLC_STATIC(&dc_chroma_vlc_le, DC_VLC_BITS, 12, ff_mpeg12_vlc_dc_chroma_bits, 1, 1, ff_mpeg12_vlc_dc_chroma_code_reversed, 2, 2, 514); - ff_rl_init(&ff_rl_speedhq, ff_speedhq_static_rl_table_store); - INIT_2D_VLC_RL(ff_rl_speedhq, 674, INIT_VLC_LE); + ff_rl_init(&rl_speedhq, speedhq_static_rl_table_store); + INIT_2D_VLC_RL(rl_speedhq, 674, INIT_VLC_LE); compute_alpha_vlcs(); } From patchwork Mon Oct 12 08:12:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22865 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 5D5E044B947 for ; Mon, 12 Oct 2020 11:12:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3CD7868BB89; Mon, 12 Oct 2020 11:12:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC7F268BB6D for ; Mon, 12 Oct 2020 11:12:46 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id n6so17767255wrm.13 for ; Mon, 12 Oct 2020 01:12:46 -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:reply-to :mime-version:content-transfer-encoding; bh=N8X0p4WiJjwkjPqUz4o3YmRnx7I5oUyzRyh6ou1bFbA=; b=Q65gzxksjk0inrT1VI9OYkBKsl+FIQPIVgoA+G1hp2oj+kshjZ1xaMjlM49EoMEn+o iksnf5UvkLHtXV53DrAeSty+iZ2v8W/2Tz/1C4dA43ElU9LniyJqZ+uSu9Vzxv2wAbnU vAscSeVdD5fQZ4oYIZOoU9Z8Uw4pCSCsWeHRpeypULMVQhOjqUzLZhvWz+ffjykb5wAJ DuERqogmvGOHijGD0srMn1isXF104dCjIZIbm9wywBBbyYllE0SWz3BS6kGA88JPckQZ /wjB3W2yngbEKDXQHJaNOZXrLVnYK7o1x1e09eUJapUI/wYc1wL3Hyuzn0+u20kCY4Jd GdRQ== 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=N8X0p4WiJjwkjPqUz4o3YmRnx7I5oUyzRyh6ou1bFbA=; b=JMSes4c5FYklJ5mZ3w3P6U0rY63xl1+NVQmX8FcEveGNtI3XyHVfjkL8GZRlILMF34 3Q1+qNC7saFY3k3uWwwyY2UhaJwF47rxXObvQxv9+RRVCB+MgO0DgazizrqD1Kd8TWOf l/cwr8InXWyYovUFg7iLjuJAMVusdLYyBxy0tcnuIGjwU6GDZ9DkGQUXFeepZ/ABAj7U nQ4iCAqJ3htTcBT7YSvMwuKaAP5F4lvEH1A97CZWWZOtFJA7KFqH0srJBCVe3QQPmetl o3VBycb1+LPxlv3oesJB071j+4zOZWVsHZZtuxY2codTC4NSDNf9ZLriN/pjVWU3Lriv aBBw== X-Gm-Message-State: AOAM532SJxA5AiZpoaT5Zypw9k3qgKCJ3lHjBMZJd3A/6H1w4iuC6Mya Q45ShwgPnI0ozsCPuLRbQKYk9bEosNs= X-Google-Smtp-Source: ABdhPJzGHMjjq01/OEcMlHHDUfwMKfjwk8YWcfNLf0he8HzgU3xWQGtY9ntoJ0y/vr4KxRPpM6Zqww== X-Received: by 2002:adf:c045:: with SMTP id c5mr20796902wrf.405.1602490365924; Mon, 12 Oct 2020 01:12:45 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id j7sm2247928wmc.7.2020.10.12.01.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 01:12:45 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Oct 2020 10:12:14 +0200 Message-Id: <20201012081217.1643833-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> References: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7] avcodec/vlc, bitstream: Allow to use BE codes to initialize LE VLC 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" This is easily possible because ff_init_vlc_sparse() already transforms both LE as well as BE codes to a normal form internally before processing them further. This will be used in subsequent commits. Signed-off-by: Andreas Rheinhardt --- libavcodec/bitstream.c | 6 +++--- libavcodec/vlc.h | 29 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index 95e5092b44..77c2b9ce05 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -182,7 +182,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, j = code >> (32 - table_nb_bits); nb = 1 << (table_nb_bits - n); inc = 1; - if (flags & INIT_VLC_LE) { + if (flags & INIT_VLC_OUTPUT_LE) { j = bitswap_32(code); inc = 1 << n; } @@ -217,7 +217,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, subtable_bits = FFMAX(subtable_bits, n); } subtable_bits = FFMIN(subtable_bits, table_nb_bits); - j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix; + j = (flags & INIT_VLC_OUTPUT_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix; table[j][1] = -subtable_bits; ff_dlog(NULL, "%4x: n=%d (subtable)\n", j, codes[i].bits + table_nb_bits); @@ -319,7 +319,7 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, av_free(buf); \ return AVERROR(EINVAL); \ } \ - if (flags & INIT_VLC_LE) \ + if (flags & INIT_VLC_INPUT_LE) \ buf[j].code = bitswap_32(buf[j].code); \ else \ buf[j].code <<= 32 - buf[j].bits; \ diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h index 42ccddf3fc..22d3e33485 100644 --- a/libavcodec/vlc.h +++ b/libavcodec/vlc.h @@ -51,26 +51,35 @@ int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, int flags); void ff_free_vlc(VLC *vlc); -#define INIT_VLC_LE 2 +/* If INIT_VLC_INPUT_LE is set, the LSB bit of the codes used to + * initialize the VLC table is the first bit to be read. */ +#define INIT_VLC_INPUT_LE 2 +/* If set the VLC is intended for a little endian bitstream reader. */ +#define INIT_VLC_OUTPUT_LE 8 +#define INIT_VLC_LE (INIT_VLC_INPUT_LE | INIT_VLC_OUTPUT_LE) #define INIT_VLC_USE_NEW_STATIC 4 -#define INIT_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \ +#define INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \ + h, i, j, flags, static_size) \ do { \ static VLC_TYPE table[static_size][2]; \ (vlc)->table = table; \ (vlc)->table_allocated = static_size; \ ff_init_vlc_sparse(vlc, bits, a, b, c, d, e, f, g, h, i, j, \ - INIT_VLC_USE_NEW_STATIC); \ + flags | INIT_VLC_USE_NEW_STATIC); \ } while (0) +#define INIT_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \ + INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \ + h, i, j, 0, static_size) + #define INIT_LE_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \ - do { \ - static VLC_TYPE table[static_size][2]; \ - (vlc)->table = table; \ - (vlc)->table_allocated = static_size; \ - ff_init_vlc_sparse(vlc, bits, a, b, c, d, e, f, g, h, i, j, \ - INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE); \ - } while (0) + INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \ + h, i, j, INIT_VLC_LE, static_size) + +#define INIT_CUSTOM_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, flags, static_size) \ + INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \ + NULL, 0, 0, flags, static_size) #define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \ INIT_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, NULL, 0, 0, static_size) From patchwork Mon Oct 12 08:12:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22866 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 3EE4F44B947 for ; Mon, 12 Oct 2020 11:12:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2714A68BB92; Mon, 12 Oct 2020 11:12:56 +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 251F968BB75 for ; Mon, 12 Oct 2020 11:12:48 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id z22so13239285wmi.0 for ; Mon, 12 Oct 2020 01:12:48 -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:reply-to :mime-version:content-transfer-encoding; bh=Vm5466xsqOBhrO03lAPKgauxs3rt/LKLB32ML9Kgocg=; b=RE5ca117B0Pk9jFUxp1drJblG+XpRKfi/7y1s7LUAMHF4+LGQGA/xsWD1XTlZn9rNn OaMlwQsGPFRuePyGbX3Vm4W0P7Nqs9KDtvnEZIJ60mTTSa86kHbyfeJC54lTDiez5/Nb V2krV8Ksj1J3ZS3oj1crFkniBiHc2t2mcJLzwMueHrpiGEzLtmcrdzUG/1N1hpKlgyBz 5SasSwBvok+Qx5M/nlqfrJJAXlYQmdwij6ulSKfHWNSoTNYKCfwz6FjMKlJTs1rZ/Drv g/yG5sgw7qHDulc+kdxux2xGJIumtYnLY8yKeLGX+X7X2PDCd1MpMZ3gk3LyXZ7muvwC uLGg== 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=Vm5466xsqOBhrO03lAPKgauxs3rt/LKLB32ML9Kgocg=; b=JobnwG0r4c3253VLoazTyALNmN7OuKgTOrHouyFX0WBxroc8cWByQSF1GHfsKjm3DE IpqI8Ng5WXpvPGLVaE60mtovbazdK+SzIYp6heSMC/tW7mdp+jPx2DLZbntdpmCWl5Mn uRQ33igeMFxy3Ird5aSKRnEagiGkbM4vGy/yzdWXYCcHLBrf18iaVz8voMCh2SMCr9SF x9uJkgjh5zR5lbS3QGoQ9VIr6NP/YlX5Ws1pjjTm0XHkub88TvfsoWPby6VfuXpq5EqE P0VJFNYl07wfjuLIzQhO1RuqOVz6H2sAuF8zn9U6bPzWeMwNe+d+gWVQCITr29v/i6HS e3FA== X-Gm-Message-State: AOAM531uTsD+clI2SADEBXuD59BAJ/w4wM/uYCdyIeg0zo0js/SSPjog cEFRWJ8ApisUIGu2Dk1hAZTbtOVub5w= X-Google-Smtp-Source: ABdhPJzkLc8aDvd8XMqTc151Lnj9kver48pE+POMddYGAQ9u1hO02BZXcXMAc7qpVbQpIGXviWaNnQ== X-Received: by 2002:a7b:c183:: with SMTP id y3mr9700987wmi.84.1602490367289; Mon, 12 Oct 2020 01:12:47 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id j7sm2247928wmc.7.2020.10.12.01.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 01:12:46 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Oct 2020 10:12:15 +0200 Message-Id: <20201012081217.1643833-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> References: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/7] avcodec/speedhq: Avoid reversing BE codes for LE bitstream reader 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/speedhq.c | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c index 5759cdb036..30a6924321 100644 --- a/libavcodec/speedhq.c +++ b/libavcodec/speedhq.c @@ -558,40 +558,17 @@ static av_cold void compute_alpha_vlcs(void) level_symbols, 2, 2, 288); } -static uint32_t reverse(uint32_t num, int bits) -{ - return bitswap_32(num) >> (32 - bits); -} - -static void reverse_code(const uint16_t *code, const uint8_t *bits, - uint16_t *reversed_code, int num_entries) -{ - int i; - for (i = 0; i < num_entries; i++) { - reversed_code[i] = reverse(code[i], bits[i]); - } -} - static av_cold void speedhq_static_init(void) { - uint16_t ff_mpeg12_vlc_dc_lum_code_reversed[12]; - uint16_t ff_mpeg12_vlc_dc_chroma_code_reversed[12]; - - /* Exactly the same as MPEG-2, except little-endian. */ - reverse_code(ff_mpeg12_vlc_dc_lum_code, - ff_mpeg12_vlc_dc_lum_bits, - ff_mpeg12_vlc_dc_lum_code_reversed, - 12); - INIT_LE_VLC_STATIC(&dc_lum_vlc_le, DC_VLC_BITS, 12, - ff_mpeg12_vlc_dc_lum_bits, 1, 1, - ff_mpeg12_vlc_dc_lum_code_reversed, 2, 2, 512); - reverse_code(ff_mpeg12_vlc_dc_chroma_code, - ff_mpeg12_vlc_dc_chroma_bits, - ff_mpeg12_vlc_dc_chroma_code_reversed, - 12); - INIT_LE_VLC_STATIC(&dc_chroma_vlc_le, DC_VLC_BITS, 12, - ff_mpeg12_vlc_dc_chroma_bits, 1, 1, - ff_mpeg12_vlc_dc_chroma_code_reversed, 2, 2, 514); + /* Exactly the same as MPEG-2, except for a little-endian reader. */ + INIT_CUSTOM_VLC_STATIC(&dc_lum_vlc_le, DC_VLC_BITS, 12, + ff_mpeg12_vlc_dc_lum_bits, 1, 1, + ff_mpeg12_vlc_dc_lum_code, 2, 2, + INIT_VLC_OUTPUT_LE, 512); + INIT_CUSTOM_VLC_STATIC(&dc_chroma_vlc_le, DC_VLC_BITS, 12, + ff_mpeg12_vlc_dc_chroma_bits, 1, 1, + ff_mpeg12_vlc_dc_chroma_code, 2, 2, + INIT_VLC_OUTPUT_LE, 514); ff_rl_init(&rl_speedhq, speedhq_static_rl_table_store); INIT_2D_VLC_RL(rl_speedhq, 674, INIT_VLC_LE); From patchwork Mon Oct 12 08:12:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22867 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 6268344B947 for ; Mon, 12 Oct 2020 11:12:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4454568BB97; Mon, 12 Oct 2020 11:12:57 +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 1B44D68BB75 for ; Mon, 12 Oct 2020 11:12:49 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id j136so16626275wmj.2 for ; Mon, 12 Oct 2020 01:12:49 -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:reply-to :mime-version:content-transfer-encoding; bh=t7GjuZwPLSZxoVDwGiHTzQXnSw5rnoGqRy14l26AlJw=; b=aluR0V6pvFdG2pY3IjiUuT8DtEQ+0ViBlNp/FYeNJ5KElxh2Vau/i2abhGfctNoqPa 4u7f2MFRnJfqM1+swA+275QhZKPgpvjb6WtkWBmvY2p+ZPI83fYF/b+DW63aDzFoJmCE yb0woOj9e4ThV/lfg9bo7T8JTmKUEWeWL2XbMEA659WtXeIjX/wSN9J9UQHAhPhULEhe PwcMvNzjXKfABQ+1koDNaJmQUWdrOPdm8/Ny0XvPJ09jXVwBaThvhzRRa8lj/THfUa4B fKItoN9Pc0gkJ5ZXO6SL0AfHPT32JczkQofazCwl4kIO8hrUVUdnCcxJzN9aZFIGDtrg EqPA== 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=t7GjuZwPLSZxoVDwGiHTzQXnSw5rnoGqRy14l26AlJw=; b=DC5+js0rB/VwHaHLlziUpji1NWFwRxYODloNceNlSP1RyRkd2xBIOQ6NgJ+8E376ut AlL/pBViK4kiy4jqpWPpt4yeu8HiNn7zmweNJTdVKKyvQ6KOMa34vpkJzwoi8LM62OPL i9TOiTKVK0NypB4qe5/xTH4buvGqdnGJM3gKu6B9WF/CmFVCTfu/FnswubxSeHRq8K6H nngTNz0FRbfQXPAgsj6g76LQNh7A3KFQJybmyq8UP24bXYmZ8LWM8ao6CLdNyPG52Jr9 DXQHskwPYdc52fH0WEP4jECfCDOeoRDly4iNmqNv605DdZ3S3dq5uMa44YY3DCX3gB2a pQzw== X-Gm-Message-State: AOAM530a9qrLvUk/ofeK9dm3E7ogX3nkmkCoV9Z6AeV32IT1+RciwW4+ l3JUnJ0OX7Oim3JutxC/k3eI7wPIKXA= X-Google-Smtp-Source: ABdhPJx352grqQjh7dgLgv+e7ZPpgifaxIZTbPIqxOewiB8YzgBWqDNwT4hRqosXEwjnwkR3KmzMRw== X-Received: by 2002:a05:600c:2905:: with SMTP id i5mr7306210wmd.9.1602490368249; Mon, 12 Oct 2020 01:12:48 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id j7sm2247928wmc.7.2020.10.12.01.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 01:12:47 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Oct 2020 10:12:16 +0200 Message-Id: <20201012081217.1643833-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> References: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7] avcodec/ivi: Avoid reversing BE VLC codes for LE bitstream reader 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/ivi.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/libavcodec/ivi.c b/libavcodec/ivi.c index c10984e83e..5e1180a5f0 100644 --- a/libavcodec/ivi.c +++ b/libavcodec/ivi.c @@ -35,7 +35,6 @@ #include "avcodec.h" #include "get_bits.h" #include "internal.h" -#include "mathops.h" #include "ivi.h" #include "ivi_dsp.h" @@ -115,23 +114,6 @@ static int ivi_mc(const IVIBandDesc *band, ivi_mc_func mc, ivi_mc_avg_func mc_av return 0; } -/** - * Reverse "nbits" bits of the value "val" and return the result - * in the least significant bits. - */ -static uint16_t inv_bits(uint16_t val, int nbits) -{ - uint16_t res; - - if (nbits <= 8) { - res = ff_reverse[val] >> (8 - nbits); - } else - res = ((ff_reverse[val & 0xFF] << 8) + - (ff_reverse[val >> 8])) >> (16 - nbits); - - return res; -} - /* * Generate a huffman codebook from the given descriptor * and convert it into the FFmpeg VLC table. @@ -162,7 +144,7 @@ static int ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag) if (bits[pos] > IVI_VLC_BITS) return AVERROR_INVALIDDATA; /* invalid descriptor */ - codewords[pos] = inv_bits((prefix | j), bits[pos]); + codewords[pos] = prefix | j; if (!bits[pos]) bits[pos] = 1; @@ -172,7 +154,7 @@ static int ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag) /* number of codewords = pos */ return init_vlc(vlc, IVI_VLC_BITS, pos, bits, 1, 1, codewords, 2, 2, - (flag ? INIT_VLC_USE_NEW_STATIC : 0) | INIT_VLC_LE); + (flag ? INIT_VLC_USE_NEW_STATIC : 0) | INIT_VLC_OUTPUT_LE); } av_cold void ff_ivi_init_static_vlc(void) From patchwork Mon Oct 12 08:12:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22868 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 6A1D544B947 for ; Mon, 12 Oct 2020 11:12:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 56E2268BB8E; Mon, 12 Oct 2020 11:12:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 248B668BB85 for ; Mon, 12 Oct 2020 11:12:50 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id s9so5965703wro.8 for ; Mon, 12 Oct 2020 01:12:50 -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:reply-to :mime-version:content-transfer-encoding; bh=t+IvuRi98BlTe3zBWEBQyc5hskeO1QF9cFWEfkKN06E=; b=Xa7RdBcxX/fIvdRtCXq9pVBL2fdHQI97u6eT3x5gx2ULsEJFjZ3LHIQddC/8jisHt+ bkQC1tOSO3Zpl9hQugFWYO0HlmjrM1MRpOPSungKS5iddXxhEF3xIALP+0IukQjfi8gN E0mzQVQICdxZ4ZjpfJ5f2tFCdGknE2nY1EU6OvAobFjyowS4wSm8Lf9OTDWi7fYHEmQK 0lv6h3kZEXkGaJJ9+/6DFM/LzXIPdPxN+S3MgoERy22UqDpWvAq6rkRwksIeB9bVgYQU njdrnwT/mFUFLHTSq2n2xWjRp3Jd9ieinbPRir35Xj2WVKPcAkIEMdq1mHurQwnpgQds qtfA== 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=t+IvuRi98BlTe3zBWEBQyc5hskeO1QF9cFWEfkKN06E=; b=SyYOa5UJWm7nUJklHEN53aDzus8FDi//1ZXO+S0mEaRgQhB0oV5lX3wBTM1j6qcNxC Aq0joLevNGb/Fo8JJ9b8Cw9vpGnJlGS6X8QMaOZ0WIImxTbgnVdXAZkzbKX+0RX5neBW vUOQ/sQBOyI9m8DwoLzpsBzmnJTOJsc3OSa4afCstpStYFgQnAdir6TG0ELy6P0O5mpm lKspjT+kMxgwcKnR9BfoBE0mIV6j/0xLB5a3ExDJsuF2PvDLaXyDA5r3cqD7Ghaxhq1z F1B4DiUlR5YifZjnpDIB5MCj9Xqne3qgyPT+C27gngnlSPvF4lFbfDDsWQb3SzWMQfla EfMQ== X-Gm-Message-State: AOAM530g8N9SzvR1qbIWtK5AjhIlqXalL1Ve1u3eg0eBcZ8DKiAIufUl 1qy3bIDkIComcnNcZBvOLUYAmKXVzz0= X-Google-Smtp-Source: ABdhPJzo4hSXXe1Ohlm42rA5N4gtLnaQ0ONEEVzXYv0AFr6kmMY4AJBnSoVUujzZx7/S6/BBq2rOMQ== X-Received: by 2002:a5d:5609:: with SMTP id l9mr25941572wrv.140.1602490369267; Mon, 12 Oct 2020 01:12:49 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id j7sm2247928wmc.7.2020.10.12.01.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 01:12:48 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Oct 2020 10:12:17 +0200 Message-Id: <20201012081217.1643833-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> References: <20201012081217.1643833-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] avcodec/webp: Use LE VLC table for LE bitstream reader 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 WebP format uses Huffman tables and the decoder therefore uses VLC tables. Given that WebP is a LE format, a LE bitreader is used; yet the VLC table is not created for a LE reader (the process used to create the tables puts the last bit to be read in the lowest bit) and therefore custom code for reading the VLCs that reverses the bits read is used instead of get_vlc2(). This commit changes this to use a table designed for LE bitreader which allows to use get_vlc2() directly. The necessary reversing of the codes is delegated to ff_init_vlc_sparse() (and is therefore only done during init and not when actually reading the VLCs). Signed-off-by: Andreas Rheinhardt --- libavcodec/webp.c | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index c6d0206846..6140c7ea4a 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -232,44 +232,6 @@ static void image_ctx_free(ImageContext *img) memset(img, 0, sizeof(*img)); } - -/* Differs from get_vlc2() in the following ways: - * - codes are bit-reversed - * - assumes 8-bit table to make reversal simpler - * - assumes max depth of 2 since the max code length for WebP is 15 - */ -static av_always_inline int webp_get_vlc(GetBitContext *gb, VLC_TYPE (*table)[2]) -{ - int n, nb_bits; - unsigned int index; - int code; - - OPEN_READER(re, gb); - UPDATE_CACHE(re, gb); - - index = SHOW_UBITS(re, gb, 8); - index = ff_reverse[index]; - code = table[index][0]; - n = table[index][1]; - - if (n < 0) { - LAST_SKIP_BITS(re, gb, 8); - UPDATE_CACHE(re, gb); - - nb_bits = -n; - - index = SHOW_UBITS(re, gb, nb_bits); - index = (ff_reverse[index] >> (8 - nb_bits)) + code; - code = table[index][0]; - n = table[index][1]; - } - SKIP_BITS(re, gb, n); - - CLOSE_READER(re, gb); - - return code; -} - static int huff_reader_get_symbol(HuffReader *r, GetBitContext *gb) { if (r->simple) { @@ -278,7 +240,7 @@ static int huff_reader_get_symbol(HuffReader *r, GetBitContext *gb) else return r->simple_symbols[get_bits1(gb)]; } else - return webp_get_vlc(gb, r->vlc.table); + return get_vlc2(gb, r->vlc.table, 8, 2); } static int huff_reader_build_canonical(HuffReader *r, int *code_lengths, @@ -332,7 +294,7 @@ static int huff_reader_build_canonical(HuffReader *r, int *code_lengths, ret = init_vlc(&r->vlc, 8, alphabet_size, code_lengths, sizeof(*code_lengths), sizeof(*code_lengths), - codes, sizeof(*codes), sizeof(*codes), 0); + codes, sizeof(*codes), sizeof(*codes), INIT_VLC_OUTPUT_LE); if (ret < 0) { av_free(codes); return ret;