From patchwork Fri Nov 20 07:19:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23784 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 5F5BE44AF11 for ; Fri, 20 Nov 2020 09:30:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0FBAD68BAB4; Fri, 20 Nov 2020 09:24:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 82E2E68BA51 for ; Fri, 20 Nov 2020 09:24:44 +0200 (EET) Received: by mail-ed1-f68.google.com with SMTP id v22so8463416edt.9 for ; Thu, 19 Nov 2020 23:24:44 -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=26/AMtD+E3oH9sxGhNSLM/kb5pTpREeSUzZ4RgWKk2o=; b=JztTtDFWCol6Gm7K9jwVHTvfx0ZJIsM5GEBf/eYYdPkfDgwioE6DrOoS6tGdYhJK40 VxcwWoPCb4kzEa/CF1O9D1OgU5ZyPsE9hxPVTLNMKY+EOWaKErdka2sIICFfcZnh4k4E BdqZq+AYuw2gUk9SrJpVwPA4iCXOhYLMn9BljfHFMzaY9pGnOZefV9gqOKORgZ6Ao8Dr +OhsoT9rDoCHSS2juiKJOVSfKqpgI21gtw+KX/54zJCKTRQtxRm4kM8vzeFehlHK79HZ 5LHK3mTQ10EOu1vDljaARl5aVnIBqOG4fb4u9IUkrHfKWO15KDRupqTIsXGS+MZmmT1D oC9Q== 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=26/AMtD+E3oH9sxGhNSLM/kb5pTpREeSUzZ4RgWKk2o=; b=a6+44efoRG76OXt5fQ4ayqyTXVsjiypGfsZQzFtmqPm30hPRcCeSbjvDw6qWzJnGcx PYm7VP0TZxm1HRdHEaiToUIYoeTlmEL7iVCPc05+dsTt2wLYDdtphgjGW6XIv9uBSv8W /wk55GSJZVmzseSfkIyurIM4Vi+QFZf6mMZuJGHvHrj2RR044gPANGrb8p0Lmd8mCKQi 0giA50ALd19BN0QkLViYeLOlzsAb4r0yLWNc/ZLsIIIk6SqPwtnVRx2QTzRRuAQjRyhH C4S2c/Sc2GCfMn7ZmEOYJ6/paw87seE4GfJVi8BdoWOCoHWeca8DOJWWBP8k9YZ8LQH3 L3ug== X-Gm-Message-State: AOAM533lI8hAgezu11qVJhZ4wkrNNYOl3G01qZo9FnLqGT8N3cAeSEZb yDwXHWdWtNZxVcpjD6xBiCGEHi24Kwq5/Q== X-Google-Smtp-Source: ABdhPJzFDP+W9GT/kgVMFRchhYscVRGBMRfTElYRTCDdSRtDSwDropaBx2YKgGzEohXsAbATa85uTg== X-Received: by 2002:a05:6402:1245:: with SMTP id l5mr34093220edw.68.1605857083691; Thu, 19 Nov 2020 23:24:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:24:43 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:19:06 +0100 Message-Id: <20201120072116.818090-34-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 033/162] 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 eaabb99e69..4d4c2b0f2e 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -56,14 +56,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 @@ -87,9 +87,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); @@ -97,16 +95,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 */ @@ -337,7 +333,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++)