From patchwork Thu Mar 31 17:23:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Avison X-Patchwork-Id: 35110 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp230164pzb; Thu, 31 Mar 2022 10:25:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2xRpo7fN6a31F7OE0TT7DjGQbiwHt3l3o6W4bmLfGH4XGQPD95G4MwCAXgLG+shLJ5glF X-Received: by 2002:a17:907:7899:b0:6e0:f285:a860 with SMTP id ku25-20020a170907789900b006e0f285a860mr5817640ejc.261.1648747522749; Thu, 31 Mar 2022 10:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648747522; cv=none; d=google.com; s=arc-20160816; b=ipR01UViBYIg0D9xPJfzR9dxUqP03/YxlC3JIAp3FhYOroyv0SbhPhTmvRg5GQOquK mj8fvGRWEuQ3HkMrpCYJOtyqRGFTFtMxttoYyTiTWRcuwYFC2Ne1Z7N681VsW3UCEX0+ IuAirzSCuv/8QshZ7tx51F4vEai95/SZ67FeFL5B6oAfZNxeOg3E50+hCCLlVz7wh9F2 8glRji14yEdPW/Jz6t0IejYC+atsHRv1zT36ebEFOJozb03jTx20X4VLcMftGCesJzQo upi4A2Xrn/LHVId/3TupP32vUIHJ0yIwcRE42sjbHhBR5wg2aKaj+z6pmU0BjPdEtW9U LmEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=LUYrzAgwJZmPnTLYTgD7nju71kfIH7ifhD16nQW1Mso=; b=SmzOLR5ALWA4wH3AvVxaCRjFuieTdOMQMnHiSdOCO6WEadclYxgi+z7pUipYOam1mU wF0v7qE008z8h9Q+v3qkA+prnv4fmXpVTtYX3qj8mME+/pb/zbi+Yu1BKuXphtXemHhm wAJL4x83Uyw3aKtjMeC+8syBD3/AG5aBG2O7d+bLQGzTkruVeFKZHmjq3JwhIqfAlnc4 kSAWvdzKgfyvF1ZfJfAel1slNwM7ouv1Cy6Wt7CZruzvLIH/vmfIaK1EGWExLwakk//S EJtUq2cyTPo/zpks7+o9EIYMyI+DNPIgW1j7wnw4gicdalm1UVokDxhYRunER/O55FmO P6Vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f13-20020a170906824d00b006df76385f4csi53995ejx.1004.2022.03.31.10.25.21; Thu, 31 Mar 2022 10:25:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8EDB468B2AE; Thu, 31 Mar 2022 20:24:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from outmail148106.authsmtp.co.uk (outmail148106.authsmtp.co.uk [62.13.148.106]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D5F9168B281 for ; Thu, 31 Mar 2022 20:24:11 +0300 (EEST) Received: from mail-c233.authsmtp.com (mail-c233.authsmtp.com [62.13.128.233]) by punt16.authsmtp.com. (8.15.2/8.15.2) with ESMTP id 22VHOB6i011191; Thu, 31 Mar 2022 18:24:11 +0100 (BST) (envelope-from bavison@riscosopen.org) Received: from rpi2021 (237.63.9.51.dyn.plus.net [51.9.63.237]) (authenticated bits=0) by mail.authsmtp.com (8.15.2/8.15.2) with ESMTPSA id 22VHO80e062360 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 31 Mar 2022 18:24:09 +0100 (BST) (envelope-from bavison@riscosopen.org) Received: by rpi2021 (sSMTP sendmail emulation); Thu, 31 Mar 2022 18:24:08 +0100 From: Ben Avison To: ffmpeg-devel@ffmpeg.org Date: Thu, 31 Mar 2022 18:23:45 +0100 Message-Id: <20220331172351.550818-5-bavison@riscosopen.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220331172351.550818-1-bavison@riscosopen.org> References: <20220331172351.550818-1-bavison@riscosopen.org> MIME-Version: 1.0 X-Server-Quench: 607f0363-b117-11ec-a0f2-84349711df28 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCd1YggXA1ZfRRob ESQCJDVBUg4iPRpU DBlFKhFVNl8UURhQ KkJXbgASJgZFAnRQ QXkJW1ZWQFx5U2Fx YQtRIwBcfENQWQZ0 UktOXVBXFgB3AFID BHhmLRFyIgVAen12 ZQhjV3lfWgp8dUEr Qk1SFnBUZGZndWEe BRNFJgMCch5CehxB Y1d+VSdbY21JDRoR IyQTdy5qdW0Db30N d0kEM1kVTUsAWSA3 HkJKPDMzB0oJWi4+ ZxIvMUJUBE8NMg08 NkFpRFQVKBQbEgxY EAlHATNCO0MMTi9j Bx5UU0MEeAAA X-Authentic-SMTP: 61633632303230.1021:7600 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 51.9.63.237/2525 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. Subject: [FFmpeg-devel] [PATCH v3 04/10] avcodec/vc1: Introduce fast path for unescaping bitstream buffer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Ben Avison Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: YEGCWLElPmTr Includes a checkasm test. Signed-off-by: Ben Avison --- libavcodec/vc1dec.c | 20 ++++++------ libavcodec/vc1dsp.c | 2 ++ libavcodec/vc1dsp.h | 3 ++ tests/checkasm/vc1dsp.c | 67 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 10 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index e279ffd1c1..0426e8a752 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -491,7 +491,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) size = next - start - 4; if (size <= 0) continue; - buf2_size = vc1_unescape_buffer(start + 4, size, buf2); + buf2_size = v->vc1dsp.vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&gb, buf2, buf2_size * 8); switch (AV_RB32(start)) { case VC1_CODE_SEQHDR: @@ -681,7 +681,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, case VC1_CODE_FRAME: if (avctx->hwaccel) buf_start = start; - buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); + buf_size2 = v->vc1dsp.vc1_unescape_buffer(start + 4, size, buf2); break; case VC1_CODE_FIELD: { int buf_size3; @@ -698,8 +698,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, ret = AVERROR(ENOMEM); goto err; } - buf_size3 = vc1_unescape_buffer(start + 4, size, - slices[n_slices].buf); + buf_size3 = v->vc1dsp.vc1_unescape_buffer(start + 4, size, + slices[n_slices].buf); init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); slices[n_slices].mby_start = avctx->coded_height + 31 >> 5; @@ -710,7 +710,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, break; } case VC1_CODE_ENTRYPOINT: /* it should be before frame data */ - buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); + buf_size2 = v->vc1dsp.vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&s->gb, buf2, buf_size2 * 8); ff_vc1_decode_entry_point(avctx, v, &s->gb); break; @@ -727,8 +727,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, ret = AVERROR(ENOMEM); goto err; } - buf_size3 = vc1_unescape_buffer(start + 4, size, - slices[n_slices].buf); + buf_size3 = v->vc1dsp.vc1_unescape_buffer(start + 4, size, + slices[n_slices].buf); init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9); @@ -762,7 +762,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, ret = AVERROR(ENOMEM); goto err; } - buf_size3 = vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf); + buf_size3 = v->vc1dsp.vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf); init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); slices[n_slices].mby_start = s->mb_height + 1 >> 1; @@ -771,9 +771,9 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, n_slices1 = n_slices - 1; n_slices++; } - buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2); + buf_size2 = v->vc1dsp.vc1_unescape_buffer(buf, divider - buf, buf2); } else { - buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2); + buf_size2 = v->vc1dsp.vc1_unescape_buffer(buf, buf_size, buf2); } init_get_bits(&s->gb, buf2, buf_size2*8); } else{ diff --git a/libavcodec/vc1dsp.c b/libavcodec/vc1dsp.c index f651d7d461..f1b7bb2397 100644 --- a/libavcodec/vc1dsp.c +++ b/libavcodec/vc1dsp.c @@ -34,6 +34,7 @@ #include "rnd_avg.h" #include "vc1dsp.h" #include "startcode.h" +#include "vc1_common.h" /* Apply overlap transform to horizontal edge */ static void vc1_v_overlap_c(uint8_t *src, ptrdiff_t stride) @@ -1030,6 +1031,7 @@ av_cold void ff_vc1dsp_init(VC1DSPContext *dsp) #endif /* CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER */ dsp->startcode_find_candidate = ff_startcode_find_candidate_c; + dsp->vc1_unescape_buffer = vc1_unescape_buffer; if (ARCH_AARCH64) ff_vc1dsp_init_aarch64(dsp); diff --git a/libavcodec/vc1dsp.h b/libavcodec/vc1dsp.h index fe60025a2a..7ed1776ca7 100644 --- a/libavcodec/vc1dsp.h +++ b/libavcodec/vc1dsp.h @@ -80,6 +80,9 @@ typedef struct VC1DSPContext { * one or more further zero bytes and a one byte. */ int (*startcode_find_candidate)(const uint8_t *buf, int size); + + /* Copy a buffer, removing startcode emulation escape bytes as we go */ + int (*vc1_unescape_buffer)(const uint8_t *src, int size, uint8_t *dst); } VC1DSPContext; void ff_vc1dsp_init(VC1DSPContext* c); diff --git a/tests/checkasm/vc1dsp.c b/tests/checkasm/vc1dsp.c index 7d4457306f..52628d15e4 100644 --- a/tests/checkasm/vc1dsp.c +++ b/tests/checkasm/vc1dsp.c @@ -374,6 +374,70 @@ static void check_loop_filter(void) } } +#define TEST_UNESCAPE \ + do { \ + for (int count = 100; count > 0; --count) { \ + escaped_offset = rnd() & 7; \ + unescaped_offset = rnd() & 7; \ + escaped_len = (1u << (rnd() % 8) + 3) - (rnd() & 7); \ + RANDOMIZE_BUFFER8(unescaped, UNESCAPE_BUF_SIZE); \ + len0 = call_ref(escaped0 + escaped_offset, escaped_len, unescaped0 + unescaped_offset); \ + len1 = call_new(escaped1 + escaped_offset, escaped_len, unescaped1 + unescaped_offset); \ + if (len0 != len1 || memcmp(unescaped0, unescaped1, UNESCAPE_BUF_SIZE)) \ + fail(); \ + } \ + } while (0) + +static void check_unescape(void) +{ + /* This appears to be a typical length of buffer in use */ +#define LOG2_UNESCAPE_BUF_SIZE 17 +#define UNESCAPE_BUF_SIZE (1u<