From patchwork Tue Nov 10 10:47:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23499 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 94AD744B823 for ; Tue, 10 Nov 2020 12:55:55 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3B98A68BE60; Tue, 10 Nov 2020 12:50:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F249A68BD43 for ; Tue, 10 Nov 2020 12:49:49 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id k2so8765841wrx.2 for ; Tue, 10 Nov 2020 02:49:49 -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=5uuVmzBDKpIN7BuaGalKlztVPCWtly6/7GekjHb2xFU=; b=rLR3VhLQVNVMswZkRJ8pfacRHrJB/xqC+S42ZSPTkeFw9KcC4ikNE/hayU8ZdN0xHY 0+ALrc1A07yvZkX4oV/+9k8ykFJL06qVmk/2zWaslBitPqiq7d5+ff3SVnQDkj9tx5RG gZqqKMAevFx8a90CWWtif3yogyk7RMJfTGa+ZPiCCEH4DxgpcQgfUDQwY/qpbkbwf4ta OveGu1yZ4SgsqM2TLyOoUEOSGTf/dDzTuDw0DUazWffECgSdUHy0sZT0u+mE3qeqQCkb u4WNHCTpUPnrMO97vqiXkvi/uwkmJ8VLU/jXZJSKa0CqoLp7ho0fD+SasAYk0+S6RZ23 CpEg== 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=5uuVmzBDKpIN7BuaGalKlztVPCWtly6/7GekjHb2xFU=; b=Ey+PBT9J3cNBn6c0uyAeU9g3j8RXmt4I98hm5hQ3LGHZEai8gaMfebB/XOSY+W6ZlC rspzve3bDyv5nhlPxDMVbzg39L89mE+20x5OPxA6JgoAbaHudf/QAocA+HlGVVKJSAzC 9+4DgTFbZ47Xa5DKHl1YYQ2F5ovwjI02VTE2uP7McP1L+gqpRNidqFuVmmlw0ipSdT7U BbGWewqNudNB0CEasK2JBqktuAD5vwSf4aeSVwtUPOM92dq4wz++cL8I58aYao4ZRwkO I+jTo0kBD+B7SvDMCy91yxP0ireN/FPjwYLQWw1pJHURo4JnXUh0v0WW9rzg8E8t6Fya IEDw== X-Gm-Message-State: AOAM532sS0YhthKkiOkQDMpIVna7HeYDborG3Jp9uuTmHE9cQq7lKqVE 6B5rjJ7dECHfIUjPT/LpEpvh6oV9kCo= X-Google-Smtp-Source: ABdhPJxvdSCdo2u+JliCwqM+03HonoZgccoT3jGMDQ87jxD7YbMWRHLiT9xx+0if2cJwz6+5pDtUwQ== X-Received: by 2002:adf:eb47:: with SMTP id u7mr22905566wrn.163.1605005388316; Tue, 10 Nov 2020 02:49:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 02:49:47 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Nov 2020 11:47:25 +0100 Message-Id: <20201110104851.321029-29-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 028/114] avcodec/rv10: Use symbol table more effectively 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 RealVideo 1.0 decoder uses VLCs to parse DC coefficients. But the values returned from get_vlc2() are not directly used; instead -(val - 128) (which is in the range -127..128) is. This transformation is unnecessary as it can effectively be done when initializing the VLC by modifying the symbols table used. There is just one minor complication: The chroma table is incomplete and in order to distinguish an error from get_vlc2() (due to an invalid code) the ordinary return range is modified to 0..255. This is possible because the only caller of this function is (on success) only interested in the return value modulo 256. Signed-off-by: Andreas Rheinhardt --- libavcodec/ituh263dec.c | 2 +- libavcodec/rv10.c | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c index c1005b0994..ced7fa52ee 100644 --- a/libavcodec/ituh263dec.c +++ b/libavcodec/ituh263dec.c @@ -467,7 +467,7 @@ static int h263_decode_block(MpegEncContext * s, int16_t * block, level = s->last_dc[component]; if (s->rv10_first_dc_coded[component]) { diff = ff_rv_decode_dc(s, n); - if (diff == 0xffff) + if (diff < 0) return -1; level += diff; level = level & 0xff; /* handle wrap round */ diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 370d2c7dd4..08887c121b 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -55,14 +55,14 @@ typedef struct RVDecContext { } RVDecContext; /* (run, length) encoded value for the symbols table. The actual symbols - * are run..run + length (mod 256). + * are run..run - length (mod 256). * The last two entries in the following table apply to luma only. * The skip values are not included in this list. */ static const uint8_t rv_sym_run_len[][2] = { - { 128, 0 }, { 127, 0 }, { 129, 0 }, { 125, 1 }, { 130, 1 }, - { 121, 3 }, { 132, 3 }, { 113, 7 }, { 136, 7 }, { 97, 15 }, - { 144, 15 }, { 65, 31 }, { 160, 31 }, { 1, 63 }, { 192, 63 }, - { 129, 127 }, { 0, 127 }, { 1, 255 }, { 0, 255 }, + { 0, 0 }, { 1, 0 }, { 255, 0 }, { 3, 1 }, { 254, 1 }, + { 7, 3 }, { 252, 3 }, { 15, 7 }, { 248, 7 }, { 31, 15 }, + { 240, 15 }, { 63, 31 }, { 224, 31 }, { 127, 63 }, { 192, 63 }, + { 255, 127 }, { 128, 127 }, { 127, 255 }, { 128, 255 }, }; /* entry[i] of the following tables gives @@ -86,9 +86,7 @@ int ff_rv_decode_dc(MpegEncContext *s, int n) if (code < 0) { /* Skip entry - no error. */ skip_bits(&s->gb, 18); - code = 1; - } else { - code -= 128; + code = 255; } } else { code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2); @@ -96,16 +94,14 @@ int ff_rv_decode_dc(MpegEncContext *s, int n) if (show_bits(&s->gb, 9) == 0x1FE) { /* Skip entry - no error. */ skip_bits(&s->gb, 18); - code = 1; + code = 255; } else { av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n"); - return 0xffff; + return -1; } - } else { - code -= 128; } } - return -code; + return code; } /* read RV 1.0 compatible frame header */ @@ -336,7 +332,7 @@ static av_cold void rv10_build_vlc(VLC *vlc, const uint16_t len_count[15], for (unsigned i = 0; i < sym_rl_elems; i++) { unsigned cur_sym = sym_rl[i][0]; for (unsigned tmp = nb_syms + sym_rl[i][1]; nb_syms <= tmp; nb_syms++) - syms[nb_syms] = 0xFF & cur_sym++; + syms[nb_syms] = 0xFF & cur_sym--; } for (unsigned i = 0; i < 15; i++)