From patchwork Fri Nov 20 07:32:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23872 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 2CBFF449167 for ; Fri, 20 Nov 2020 09:48:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6FC0068BD0D; Fri, 20 Nov 2020 09:34:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D2D8F68B5E3 for ; Fri, 20 Nov 2020 09:34:28 +0200 (EET) Received: by mail-ej1-f68.google.com with SMTP id 7so11547768ejm.0 for ; Thu, 19 Nov 2020 23:34:28 -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=+zRZFIDMkewC+lFjAg3BWPmxtEKZeeb5pfrz1660cwM=; b=jahOLrLGXMwec2vQTTp+7yep9iNYYH5SfCUruQEgcWsEJB51DXyKJazG2wR6esSmX7 F4GgfNbexWAknVd7uhVgaOA8aL83Kwh5k/HBc9CtNO3X1aFPhc7omoCv5SehSEr6etBi DUZMov/miKDDLz8xJc6MK63YWxTuZyIEx9OK+5T0FZqzi5ARrtloWfiZh0vqyiJdBR7w h3XmaU8oq3c5Rv2LE04lnMZsEKUllvNZHRDLwGv8qkBhls5LkwSOpbIfwf6ytS2TsnYd wBSjG/YeFriEsBdAKU09YVjoAjHWCaTuupRRq+2zHrcILlbUn19zi6Pp0+JqW8uva8Kx Q+0g== 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=+zRZFIDMkewC+lFjAg3BWPmxtEKZeeb5pfrz1660cwM=; b=dw2zPMc4RO8I3wWTSn3Gnwn8HuX7QtSD5JZS1/gvJLsbq99sQsYiazNcMraOxxsTEt WXNDuqFYhS320FSCy21QoN/oqGy7Xk2S21+2ox6W+8n2fkWe9dYylGnam+iuP01Upim+ beHsvFNmNvZDJI205hLw/amS6HZkNtg2MLAY017Lw4VFxRYi/B9S+IXVsN+bp+4mbA2O q+BjI7b5SnGKZFd2FfrR4KF4Uv3VDBQ6NtzJcqXUcWha4QtM3miYxW19Qusow3MXjDGx SStYDknEzrIJeiTpRVuzmgDgOJns7i9lcrc7NgCjZtyJEfofuozswAmBedom8uBIVrvS dBWw== X-Gm-Message-State: AOAM533CHoEC71/3inYxdUMwfJtH3SVbkHk1cDS2+Rxve25XNtJd8fCu syPqoNpKfgFRtqHn3khfi0nvxTs5rTVK3w== X-Google-Smtp-Source: ABdhPJyDpvUMLYAX86K/vtANEsIvF8xH8zNp0iZBVYDvPMEqewoSlALBUHKCO1rwwTp3RHsLVbmmEg== X-Received: by 2002:a17:906:2857:: with SMTP id s23mr21994117ejc.218.1605857667892; Thu, 19 Nov 2020 23:34:27 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id i13sm769110ejv.84.2020.11.19.23.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:34:27 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:32:49 +0100 Message-Id: <20201120073327.820745-25-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 124/162] avcodec/vp3: Use symbols table for VP3 motion vectors 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" Expressions like array[get_vlc2()] can be optimized by using a symbols table if the array is always the same for a given VLC. This requirement is fulfilled for the VLC used for VP3 motion vectors. The reason it hasn't been done before is probably that the array in this case contained entries in the range -31..31; but this is no problem with ff_init_vlc_from_lengths(): Just apply an offset of 31 to the symbols before storing them in the table used to initialize VP3 motion vectors and apply an offset of -31 when initializing the actual VLC. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp3.c | 21 +++++++++++++------- libavcodec/vp3data.h | 46 +++++++++++--------------------------------- 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 7d1d2411ab..2f43de757e 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -48,6 +48,7 @@ #include "vp3dsp.h" #include "xiph.h" +#define VP3_MV_VLC_BITS 6 #define VP4_MV_VLC_BITS 6 #define SUPERBLOCK_VLC_BITS 6 @@ -946,8 +947,10 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) case MODE_INTER_PLUS_MV: /* all 6 fragments use the same motion vector */ if (coding_mode == 0) { - motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; - motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; + motion_x[0] = get_vlc2(gb, s->motion_vector_vlc.table, + VP3_MV_VLC_BITS, 2); + motion_y[0] = get_vlc2(gb, s->motion_vector_vlc.table, + VP3_MV_VLC_BITS, 2); } else if (coding_mode == 1) { motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)]; motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)]; @@ -976,8 +979,10 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) current_fragment = BLOCK_Y * s->fragment_width[0] + BLOCK_X; if (s->all_fragments[current_fragment].coding_method != MODE_COPY) { if (coding_mode == 0) { - motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; - motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; + motion_x[k] = get_vlc2(gb, s->motion_vector_vlc.table, + VP3_MV_VLC_BITS, 2); + motion_y[k] = get_vlc2(gb, s->motion_vector_vlc.table, + VP3_MV_VLC_BITS, 2); } else if (coding_mode == 1) { motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)]; motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)]; @@ -2479,9 +2484,11 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; - if ((ret = init_vlc(&s->motion_vector_vlc, 6, 63, - &motion_vector_vlc_table[0][1], 2, 1, - &motion_vector_vlc_table[0][0], 2, 1, 0)) < 0) + ret = ff_init_vlc_from_lengths(&s->motion_vector_vlc, VP3_MV_VLC_BITS, 63, + &motion_vector_vlc_table[0][1], 2, + &motion_vector_vlc_table[0][0], 2, 1, + -31, 0, avctx); + if (ret < 0) return ret; #if CONFIG_VP4_DECODER diff --git a/libavcodec/vp3data.h b/libavcodec/vp3data.h index ae2b44f533..1fbeac731b 100644 --- a/libavcodec/vp3data.h +++ b/libavcodec/vp3data.h @@ -112,41 +112,17 @@ static const uint8_t mode_code_vlc_len[8] = { }; static const uint8_t motion_vector_vlc_table[63][2] = { - { 0, 3 }, - { 1, 3 }, - { 2, 3 }, - - { 6, 4 }, { 7, 4 }, - - { 8, 4 }, { 9, 4 }, - - { 40, 6 }, { 41, 6 }, { 42, 6 }, { 43, 6 }, - { 44, 6 }, { 45, 6 }, { 46, 6 }, { 47, 6 }, - - { 96, 7 }, { 97, 7 }, { 98, 7 }, { 99, 7 }, - { 100, 7 }, { 101, 7 }, { 102, 7 }, { 103, 7 }, - { 104, 7 }, { 105, 7 }, { 106, 7 }, { 107, 7 }, - { 108, 7 }, { 109, 7 }, { 110, 7 }, { 111, 7 }, - - { 0xE0, 8 }, { 0xE1, 8 }, { 0xE2, 8 }, { 0xE3, 8 }, - { 0xE4, 8 }, { 0xE5, 8 }, { 0xE6, 8 }, { 0xE7, 8 }, - { 0xE8, 8 }, { 0xE9, 8 }, { 0xEA, 8 }, { 0xEB, 8 }, - { 0xEC, 8 }, { 0xED, 8 }, { 0xEE, 8 }, { 0xEF, 8 }, - - { 0xF0, 8 }, { 0xF1, 8 }, { 0xF2, 8 }, { 0xF3, 8 }, - { 0xF4, 8 }, { 0xF5, 8 }, { 0xF6, 8 }, { 0xF7, 8 }, - { 0xF8, 8 }, { 0xF9, 8 }, { 0xFA, 8 }, { 0xFB, 8 }, - { 0xFC, 8 }, { 0xFD, 8 }, { 0xFE, 8 }, { 0xFF, 8 } -}; - -static const int8_t motion_vector_table[63] = { - 0, 1, -1, - 2, -2, - 3, -3, - 4, -4, 5, -5, 6, -6, 7, -7, - 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, - 16, -16, 17, -17, 18, -18, 19, -19, 20, -20, 21, -21, 22, -22, 23, -23, - 24, -24, 25, -25, 26, -26, 27, -27, 28, -28, 29, -29, 30, -30, 31, -31 + { 31, 3 }, { 32, 3 }, { 30, 3 }, { 33, 4 }, { 29, 4 }, { 34, 4 }, + { 28, 4 }, { 35, 6 }, { 27, 6 }, { 36, 6 }, { 26, 6 }, { 37, 6 }, + { 25, 6 }, { 38, 6 }, { 24, 6 }, { 39, 7 }, { 23, 7 }, { 40, 7 }, + { 22, 7 }, { 41, 7 }, { 21, 7 }, { 42, 7 }, { 20, 7 }, { 43, 7 }, + { 19, 7 }, { 44, 7 }, { 18, 7 }, { 45, 7 }, { 17, 7 }, { 46, 7 }, + { 16, 7 }, { 47, 8 }, { 15, 8 }, { 48, 8 }, { 14, 8 }, { 49, 8 }, + { 13, 8 }, { 50, 8 }, { 12, 8 }, { 51, 8 }, { 11, 8 }, { 52, 8 }, + { 10, 8 }, { 53, 8 }, { 9, 8 }, { 54, 8 }, { 8, 8 }, { 55, 8 }, + { 7, 8 }, { 56, 8 }, { 6, 8 }, { 57, 8 }, { 5, 8 }, { 58, 8 }, + { 4, 8 }, { 59, 8 }, { 3, 8 }, { 60, 8 }, { 2, 8 }, { 61, 8 }, + { 1, 8 }, { 62, 8 }, { 0, 8 }, }; static const int8_t fixed_motion_vector_table[64] = {