From patchwork Fri Nov 20 07:19:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23786 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 40A2944AF11 for ; Fri, 20 Nov 2020 09:30:41 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C2C3868BAB9; Fri, 20 Nov 2020 09:24:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 539D468BA66 for ; Fri, 20 Nov 2020 09:24:46 +0200 (EET) Received: by mail-ej1-f65.google.com with SMTP id oq3so11473090ejb.7 for ; Thu, 19 Nov 2020 23:24:46 -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=eqNa9Wh/gCNFDpvPb6UQIBhKQtTk99WAwB63GZU3M3E=; b=vPhUnSBAwum5m3eKsO0cB9xlmTCrfQf6wp0T9BBfewPif6j3MOffVB4tH/91vXmmXd /7zdMKP2pUI6PaNxdNcEwaZ68TT32RaaivLHwrak52yGEsjPqIqE42nO9O8MjV36ZVlP WbV8pXjbZjzzT3gim0s+8KT5AGS+m079QPeAjwpc6MxVzw3JjPzt/kvaxVMDisBQt7Xi MSqahXg+RuV/Kdg5CdkLXpaZW1fUoJjwy+xqC7we534WVcwpdkK/pIICCYCiwpfjh4Rx Yyf+4GDXP7eirk54OW7DSpY4qvh/i11ipoenWhIS4sTL3c9Hv0GbFQoab8zus43JLsjh TcEw== 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=eqNa9Wh/gCNFDpvPb6UQIBhKQtTk99WAwB63GZU3M3E=; b=Gtc6TB4IU8XiG35U516+VxWe7I7mVL9HIMdPQpWAaOG/DpDRFBDXVvNPIePymxnD+Q MXizCjmO72u0B7L83k2WQiaeR0oZyVE4oGaw1sKhluIHFx9NRTWtH1PmQeDrROJRp/V3 K/eSZGag8iG1M+K/9diuzXd8h5Tvmlebw5xNyd1FeTRwrQ4Be/UI86UmQhjXgLdSBt6u G+wL/YaUgigxFAWuhu9QeA8jGm6q6TUGWOXjHneNtSSaHGJO8PN0mmdnVhTIl5I9ME1B jeALnXb2v1KpN8n4TCnkb7SlJ0gXeEzcLLGUl3MFbdsDXd+KCgmeACJokTr1ZrG6SVnL R7hA== X-Gm-Message-State: AOAM531nCuOy6EDkekiQ2koEoJoeFu0xDXBomdhuwzfQAA8dPV8hPEsE Y/rrjDRkUgOsfqn8yALF+uOBDJwm0yzxQQ== X-Google-Smtp-Source: ABdhPJxTtCMeXTEGuFnl5zL4YgVGtN5yNXxe1ro9sRsMNbB28PxeNiwFKl68FUTOKRu4K1Ygy1Ge+w== X-Received: by 2002:a17:907:9d0:: with SMTP id bx16mr32734236ejc.426.1605857085519; Thu, 19 Nov 2020 23:24:45 -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.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:24:44 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:19:08 +0100 Message-Id: <20201120072116.818090-36-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 035/162] avcodec/rv10: Simplify handling of skip VLC entries 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 VLC tables to be used for parsing RealVideo 1.0 DC coefficients are weird: The luma table contains a block of 2^11 codes beginning with the same prefix and length that all have the same symbol (i.e. value only depends upon the prefix); the same goes for the chroma block (except it's only 2^9 codes). Up until now, these entries (which generally could be parsed like ordinary entries with subtables) have been treated specially: They have been treated like open ends of the tree, so that get_vlc2() returned a value < 0 upon encountering them; afterwards it was checked whether the right prefix was used and if so, the appropriate number of bytes was skipped. But there is actually an easy albeit slightly hacky way to support them directly without pointless subtables: Just modify the VLC table so that all the entries sharing the right prefix have a length that equals the length of the whole entry. Signed-off-by: Andreas Rheinhardt --- libavcodec/rv10.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 0727899337..d118515c3b 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -84,22 +84,11 @@ int ff_rv_decode_dc(MpegEncContext *s, int n) if (n < 4) { code = get_vlc2(&s->gb, rv_dc_lum.table, DC_VLC_BITS, 2); - if (code < 0) { - /* Skip entry - no error. */ - skip_bits(&s->gb, 18); - code = 255; - } } else { code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2); if (code < 0) { - if (show_bits(&s->gb, 9) == 0x1FE) { - /* Skip entry - no error. */ - skip_bits(&s->gb, 18); - code = 255; - } else { - av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n"); - return -1; - } + av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n"); + return -1; } } return code; @@ -352,10 +341,21 @@ static av_cold void rv10_init_static(void) rv_dc_lum.table_allocated = 1472; rv10_build_vlc(&rv_dc_lum, rv_lum_len_count, rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len)); + for (int i = 0; i < 1 << (DC_VLC_BITS - 7 /* Length of skip prefix */); i++) { + /* All codes beginning with 0x7F have the same length and value. + * Modifying the table directly saves us the useless subtables. */ + rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i][0] = 255; + rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i][1] = 18; + } rv_dc_chrom.table = &table[1472]; rv_dc_chrom.table_allocated = 992; rv10_build_vlc(&rv_dc_chrom, rv_chrom_len_count, rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len) - 2); + for (int i = 0; i < 1 << (DC_VLC_BITS - 9 /* Length of skip prefix */); i++) { + /* Same as above. */ + rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i][0] = 255; + rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i][1] = 18; + } ff_h263_decode_init_vlc(); }