From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 72169484DA for ; Tue, 5 Dec 2023 22:44:42 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2BB4A68CF30; Wed, 6 Dec 2023 00:43:59 +0200 (EET) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 49A9268CEF5 for ; Wed, 6 Dec 2023 00:43:52 +0200 (EET) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6ce7632b032so911831b3a.1 for ; Tue, 05 Dec 2023 14:43:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701816230; x=1702421030; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QxUS7vp0JdGrHnyRk3Y/VWtRAl3/pjEkbskQJyLXrnU=; b=WJzR/FjhBT2WGpPayRlTP+sL0RABONXltDm9MKTBSa5YKKfe5oiQwjlMzZhobEpXCY 1yQoODBsVbcxeg71YHou1OjqjpSBxJVWk0PK7Mr5e8VxY3d1Wi4mAABgI27+ogqnu6wF 4eRu/nOE5wB3+GOmUHyk0X3FvERui597mXYG26vI0PGZx1SHth8Mg0tBGqpgvDfNv5Qe j1NVNYcxxbvXDu7iPmnNcHw1W15R/ZonzxVs7vg1cW+1FS15XUmozj0PnsSVTquIF/ME 3Bo8vvipYFgTtYs8d1sMLVr9qRqDjMEAd9Xb7qQr8wPufDg6trz/dN+UygdLfsgQCtsY TDXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701816230; x=1702421030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QxUS7vp0JdGrHnyRk3Y/VWtRAl3/pjEkbskQJyLXrnU=; b=TpIkQ8m4od20c3uLu17lZXPVVu1EwHxa2SoK02oo2lb/uVVKumzNbKuUspc49estI9 kwQg1ME1jxQZGyaTncIoJ2mex3tD2C3nKiiyvbQ1dQPF24+RNDjy1jWjy+vqD9TRRxTT a7z9cMVjFJ891IMntODAHl0tHuwfwRR7DUIQQgn4luZ+hwhMTwjVOkcZOAnLGhOfXoAH XhPReZ9WhBJJ2V5qQuuqL8XJWlmfGtA5MkvX7g0VRRdeGsbzUPOTy/jUNCid0SK7Zq/C lgpN73YX7BC/++6zB8aIvYC7cEUfMLIWFWJejZ3Rdgv7Vy9i0Md/f25eQcpdP5f8Yc2/ ipqw== X-Gm-Message-State: AOJu0Yy5qI7eYag2SXQp7SVKY3iKVpARBLP6qT4d/CRyGgCi5wpx+S4c y0cOxsy6SUGMFvAegZTHXme4x65bLd8= X-Google-Smtp-Source: AGHT+IH4yoPw4Fr3e8sMwnorvveyTaKw3Ab6jm9clBr2FTy6qc0tWt44310A8H4RjxUAbkVX/Ps5dQ== X-Received: by 2002:a05:6a00:150e:b0:6ce:81e9:1e2 with SMTP id q14-20020a056a00150e00b006ce81e901e2mr239552pfu.64.1701816229722; Tue, 05 Dec 2023 14:43:49 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id hq25-20020a056a00681900b0064fd4a6b306sm2037688pfb.76.2023.12.05.14.43.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 14:43:49 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 5 Dec 2023 19:43:59 -0300 Message-ID: <20231205224402.14540-6-jamrial@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205224402.14540-1-jamrial@gmail.com> References: <20231205224402.14540-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/8] avcodec/get_bits: add get_leb() 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: James Almer --- libavcodec/bitstream.h | 2 ++ libavcodec/bitstream_template.h | 23 +++++++++++++++++++++++ libavcodec/get_bits.h | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/libavcodec/bitstream.h b/libavcodec/bitstream.h index 35b7873b9c..17f8a5da83 100644 --- a/libavcodec/bitstream.h +++ b/libavcodec/bitstream.h @@ -103,6 +103,7 @@ # define bits_apply_sign bits_apply_sign_le # define bits_read_vlc bits_read_vlc_le # define bits_read_vlc_multi bits_read_vlc_multi_le +# define bits_read_leb bits_read_leb_le #elif defined(BITS_DEFAULT_BE) @@ -132,6 +133,7 @@ # define bits_apply_sign bits_apply_sign_be # define bits_read_vlc bits_read_vlc_be # define bits_read_vlc_multi bits_read_vlc_multi_be +# define bits_read_leb bits_read_leb_be #endif diff --git a/libavcodec/bitstream_template.h b/libavcodec/bitstream_template.h index 4f3d07275f..4c7101632f 100644 --- a/libavcodec/bitstream_template.h +++ b/libavcodec/bitstream_template.h @@ -562,6 +562,29 @@ static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8], return ret; } +/** + * Read a unsigned integer coded as a variable number of up to eight + * little-endian bytes, where the MSB in a byte signals another byte + * must be read. + * Values > UINT_MAX are truncated, but all coded bits are read. + */ +static inline unsigned BS_FUNC(read_leb)(BSCTX *bc) { + int more, i = 0; + unsigned leb = 0; + + do { + int byte = BS_FUNC(read)(bc, 8); + unsigned bits = byte & 0x7f; + more = byte & 0x80; + if (i <= 4) + leb |= bits << (i * 7); + if (++i == 8) + break; + } while (more); + + return leb; +} + #undef BSCTX #undef BS_FUNC #undef BS_JOIN3 diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index cfcf97c021..9e19d2a439 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -94,6 +94,7 @@ typedef BitstreamContext GetBitContext; #define align_get_bits bits_align #define get_vlc2 bits_read_vlc #define get_vlc_multi bits_read_vlc_multi +#define get_leb bits_read_leb #define init_get_bits8_le(s, buffer, byte_size) bits_init8_le((BitstreamContextLE*)s, buffer, byte_size) #define get_bits_le(s, n) bits_read_le((BitstreamContextLE*)s, n) @@ -710,6 +711,29 @@ static inline int skip_1stop_8data_bits(GetBitContext *gb) return 0; } +/** + * Read a unsigned integer coded as a variable number of up to eight + * little-endian bytes, where the MSB in a byte signals another byte + * must be read. + * All coded bits are read, but values > UINT_MAX are truncated. + */ +static inline unsigned get_leb(GetBitContext *s) { + int more, i = 0; + unsigned leb = 0; + + do { + int byte = get_bits(s, 8); + unsigned bits = byte & 0x7f; + more = byte & 0x80; + if (i <= 4) + leb |= bits << (i * 7); + if (++i == 8) + break; + } while (more); + + return leb; +} + #endif // CACHED_BITSTREAM_READER #endif /* AVCODEC_GET_BITS_H */ -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".