From patchwork Tue Nov 10 10:47:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23501 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 1FB4444B922 for ; Tue, 10 Nov 2020 12:56:24 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 645EF68BDE3; Tue, 10 Nov 2020 12:50:03 +0200 (EET) 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 0DF3768BD8F for ; Tue, 10 Nov 2020 12:49:51 +0200 (EET) Received: by mail-wm1-f68.google.com with SMTP id h62so2533867wme.3 for ; Tue, 10 Nov 2020 02:49:51 -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=f1V/QiPYNd54j+T7qWdbV53gSyskEMuNDLLEhJ2D5eQ=; b=Afx5fsgI8eXJ5KeHlvxPnaP23N9O7xICeUp47SYQqgaqNWjIO0tKzJUWfrXfkHI3vg /eMjYYl4qpP8wBEkySfwL0ady+1btBPJaoLnIYRGmjWGj7mIyk5hGAUhNk9g6QFeWBIe HJIgVzQOl5Nh1cVxLWIuguA08b4YMjwtwthG9B8AhhfhLeKxhbih4IeyqFHfFjmE0/gX UjBnlovD8FFNl/h6m7xapQA89ZkXWZ7NOKCWI/5wM0FCuzkvPcdYljVfj50lgPq5Otwz DwywRnKbjXxAaWu29FfaVQDK5K7W3mB4q6eC3Ss1xSCdQz3pjHG+li3D42iUjs/L9HBn jA7Q== 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=f1V/QiPYNd54j+T7qWdbV53gSyskEMuNDLLEhJ2D5eQ=; b=e8cyWIJ7kWznCNbOJ4+G2D92HBdrAO0BxZgU1dHNRtK1ubQj44MyuJtYLdgyXB9Hgq z1yXBmZbp6aWMq4bUoUv/POWmKqUzrt4kZSrdaiq1G6ymBoCkpn9JxygVCxb3vSVpmgQ LeQoaFlCYsbG9Dnbn5+5oT4F/8Y2RMcr0ltCSNnbXV+n0rgoEsecr5+ljxLCevTQC/6s mMYq0n7dx4UkA8HlcaQSO/hlv9GDRfEfHDxkn30cE0eEzC7RbUVXoJnbVWfx52a2tfPQ vFRmDZBkqH/Nj95+Q0e1cxus7CLcJN6Epl0dSHlxpZysDU/cVTliNv5vSrsv3PusBR32 jwew== X-Gm-Message-State: AOAM532hvvjj+imIrFZz4Bu3gDcy0DCENJy58o7WLIVDiljXXLPfS9y2 LJojUIEB4cE3tNF/stixb3UqBPsQisU= X-Google-Smtp-Source: ABdhPJwHPvGwbLq42d21vQ5s0J19sSnneDq6/FQv9AeHS4l/q2810PRIB1vQHUw8So9I3omv8LGJGw== X-Received: by 2002:a7b:c937:: with SMTP id h23mr3931765wml.19.1605005390476; Tue, 10 Nov 2020 02:49:50 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id l24sm2572543wmi.7.2020.11.10.02.49.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 02:49:49 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Nov 2020 11:47:27 +0100 Message-Id: <20201110104851.321029-31-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201110104851.321029-1-andreas.rheinhardt@gmail.com> References: <20201110104851.321029-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 030/114] 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 a7cb8118e5..52e862f1b9 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -83,22 +83,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; @@ -415,10 +404,21 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) 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; + } done = 1; }