From patchwork Fri Jun 17 13:32:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36307 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp135545pzb; Fri, 17 Jun 2022 06:32:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vbhb2GEL+XQCR0NNcfP/JrBVjA8U10DlYiXiW2dr/tDZCNlJAhI0kZW5emzRKZTMR44CTl X-Received: by 2002:a17:906:739a:b0:713:3ac7:976f with SMTP id f26-20020a170906739a00b007133ac7976fmr9038238ejl.22.1655472751840; Fri, 17 Jun 2022 06:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655472751; cv=none; d=google.com; s=arc-20160816; b=AZ4MHVY6EdSf52yN5qIvS5dRpbalq2a2zqOG11zVD+myMTj+55CwxLIbtLO6yi6ulp sv0ybeaTy8BuSAhoxvETWYm3I5Z9qX8hkS/+SqLy3qyhr9QwKvNDpCNzYrHMTfWVW5SK 5y2i3Olv16oaw1O2QKyrwvbtjCKzUeDlMH6dGI/AuhwnQMxcZd25hfCpzolbG4kk7RMk htyZ8hKuiniglARa4fMQhIH9xAGYO5a/yv/bw/y1H0ghWInBAZ9fYZVyCiyR58QBfwKw 5TvyAeAeAJQrj1IpSJq1uI4A6XP8kWgYjF9UtHS34kgXFJWNI/k7XrN7cW2h/+0kGuLC 0KPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=SbxtBQ4vHdEMvbi1nYcPu6NjUSs1+L8eqRrRUGGZDHE=; b=xAPXmwtF/rdlnRp2E5e/WqO4f6P3A1MxI4FkvSnVXxFm0p1plKNw1nfYYntHABgc2+ eU8AncENl7WMfpwyWVAYcAGBjb87fv5+VzbqICUJA/5wqFHQuNSgxhjvrZitpvQ9LSzT 6YSNU58qTU93MgVffuwuP23mnl1yXZy0aUOVNATOJsEGQ4KeOrXnzw/wO4Rp/XoCa+Gy TnRk9ohoBCWkXUgD9tosxPUMDreCU6lssFhx+ICJ957qc2IV57EGlqUxYulrwLEBhqxT Ci8jfJDJqsQyCa9iYU6wxyumQHDzwCvVDcTbFYVSCy6BItQ4/LhwPttBC7ItdVz9+oAC 2Uiw== 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 m15-20020a170906720f00b0070a5f5366b9si4372645ejk.389.2022.06.17.06.32.31; Fri, 17 Jun 2022 06:32:31 -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 A71A068B8E4; Fri, 17 Jun 2022 16:32:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1CA0068B8B8 for ; Fri, 17 Jun 2022 16:32:11 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A1F5A240175 for ; Fri, 17 Jun 2022 15:32:10 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Go9dPUUtE6_c for ; Fri, 17 Jun 2022 15:32:08 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id E51512400F5 for ; Fri, 17 Jun 2022 15:32:08 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id E857F3A127F; Fri, 17 Jun 2022 15:32:08 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 Jun 2022 15:32:05 +0200 Message-Id: <20220617133206.23643-4-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220617133206.23643-1-anton@khirnov.net> References: <20220617133206.23643-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] lavc/bitstream: make skip_remaining() public 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WiXLuIM4q8EV Also rename it to bitstream_skip_cache(), which is more descriptive and follows the naming conventions of tis API. --- libavcodec/bitstream.h | 1 + libavcodec/bitstream_template.h | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libavcodec/bitstream.h b/libavcodec/bitstream.h index 3fa63695d3..364245453b 100644 --- a/libavcodec/bitstream.h +++ b/libavcodec/bitstream.h @@ -116,6 +116,7 @@ static inline void bitstream_unget(BitstreamContext *bc, uint64_t value, #define bitstream_peek bitstream_peek_be #define bitstream_peek_signed bitstream_peek_signed_be #define bitstream_skip bitstream_skip_be +#define bitstream_skip_cache bitstream_skip_cache_be #define bitstream_seek bitstream_seek_be #define bitstream_align bitstream_align_be #define bitstream_read_xbits bitstream_read_xbits_be diff --git a/libavcodec/bitstream_template.h b/libavcodec/bitstream_template.h index 14a420139c..717473ca40 100644 --- a/libavcodec/bitstream_template.h +++ b/libavcodec/bitstream_template.h @@ -225,7 +225,12 @@ static inline int BS_FUNC(bitstream_peek_signed)(BitstreamContext *bc, unsigned return sign_extend(BS_FUNC(bitstream_peek)(bc, n), n); } -static inline void BS_FUNC(skip_remaining)(BitstreamContext *bc, unsigned int n) +/** + * Skip n bits from the cache. This may only be called if at least n bits are + * guaranteed to be in the cache, e.g. right after bitstream_peek(n). + * Otherwise use bitstream_skip(). + */ +static inline void BS_FUNC(bitstream_skip_cache)(BitstreamContext *bc, unsigned int n) { #ifdef BITSTREAM_LE bc->bits >>= n; @@ -241,7 +246,7 @@ static inline void BS_FUNC(skip_remaining)(BitstreamContext *bc, unsigned int n) static inline void BS_FUNC(bitstream_skip)(BitstreamContext *bc, unsigned int n) { if (n < bc->bits_left) - BS_FUNC(skip_remaining)(bc, n); + BS_FUNC(bitstream_skip_cache)(bc, n); else { n -= bc->bits_left; bc->bits = 0; @@ -255,7 +260,7 @@ static inline void BS_FUNC(bitstream_skip)(BitstreamContext *bc, unsigned int n) } BS_FUNC(refill_64)(bc); if (n) - BS_FUNC(skip_remaining)(bc, n); + BS_FUNC(bitstream_skip_cache)(bc, n); } } @@ -291,7 +296,7 @@ static inline int BS_FUNC(bitstream_read_xbits)(BitstreamContext *bc, unsigned i { int32_t cache = BS_FUNC(bitstream_peek)(bc, 32); int sign = ~cache >> 31; - BS_FUNC(skip_remaining)(bc, n); + BS_FUNC(bitstream_skip_cache)(bc, n); return ((((uint32_t)(sign ^ cache)) >> (32 - n)) ^ sign) - sign; } @@ -374,14 +379,14 @@ static inline int BS_FUNC(bitstream_read_vlc)(BitstreamContext *bc, VLC_TYPE (*t int n = table[idx][1]; if (max_depth > 1 && n < 0) { - BS_FUNC(skip_remaining)(bc, bits); + BS_FUNC(bitstream_skip_cache)(bc, bits); code = BS_FUNC(set_idx)(bc, code, &n, &nb_bits, table); if (max_depth > 2 && n < 0) { - BS_FUNC(skip_remaining)(bc, nb_bits); + BS_FUNC(bitstream_skip_cache)(bc, nb_bits); code = BS_FUNC(set_idx)(bc, code, &n, &nb_bits, table); } } - BS_FUNC(skip_remaining)(bc, n); + BS_FUNC(bitstream_skip_cache)(bc, n); return code; }