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 24CBA48226 for ; Thu, 14 Dec 2023 20:16:06 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BF76F68D2C0; Thu, 14 Dec 2023 22:15:26 +0200 (EET) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A520068D2B3 for ; Thu, 14 Dec 2023 22:15:19 +0200 (EET) Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-5ca0b968d8dso2385611a12.1 for ; Thu, 14 Dec 2023 12:15:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702584917; x=1703189717; 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=cEre2hyD9ojGMij0qbQDHRu7PbnvozCZL3oxUK/2eKH8UE52YZGnBngWVrfRZddPkW zNrKycu422Eu5I67kPYvsEX59O0Q26tXyryhK2lij9iOl6MUBwHsTVb2FfrYN0X+nEdD 86zP/BrinS0R9UZqLFweS56vMmrusiqt79WKhycv8cbMrkEoqcQCMzUAKQyCztkBJolv EFCJRSWB8LB0g3zK0yGdeBVtci3qZCna8pMDabSObGSITpAFBQ8yPMVPouLHjrL/ztgL Q/HvD2/edD2kKBg7DxO5orbb2wv+qdUXXgIvcNtaINTsei+nTTw0yCub5Y7Ro35+5zdO X5dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702584917; x=1703189717; 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=bJ6acBZZ7PBJvoCFJrrHbteeNwBCpumxubFa95K05xA3mvvvC8ZS5X/PFduR/ayHpc 4P8+wxuqFfMKJ/eRH80tN9efqR5tT7AwtPo0e3ayJx7nqtXMPSMLZGucNFtT80AnzqSe oSZD09wC2frrZ3KtemgZc1Ix3V4i6pFsEP3r57Zv/dCbD9DsCZwi11Srta5vSsAGtXT0 zGC2yzTNT0uOqIEB2U9J0u2oZuexxA08Nw8e42P2n0nyIkcFMkZBuNU0dZozP3xa4c/O FZA8XMtLDLMYOQ/UMW3dQQRx/v7e/p/sfHnPpwZdAFuoQzwwwHb0G3NMC81sf8dtJnUA 9Jvw== X-Gm-Message-State: AOJu0Yz1191LfJOtYwB1WD8rgHRwg/7ltkeDFNpKgvgMpYnaL7F70/Z+ zd+jmeuTDoUU7fgzXhFl8JrBIKGKsdE= X-Google-Smtp-Source: AGHT+IEIEp0M/aJOCTi+cuczN/dlsH8iEEVZJSeQhDHOHcx9bY73b+hHEUYmSgz0Pa5/E6+K+UO/Rw== X-Received: by 2002:a05:6a20:da9f:b0:190:ecc9:2a8b with SMTP id iy31-20020a056a20da9f00b00190ecc92a8bmr4810843pzb.42.1702584917062; Thu, 14 Dec 2023 12:15:17 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id h12-20020a62b40c000000b006d0d4bafe31sm3352885pfn.6.2023.12.14.12.15.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:15:16 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 Dec 2023 17:14:30 -0300 Message-ID: <20231214201433.4608-6-jamrial@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214201433.4608-1-jamrial@gmail.com> References: <20231214201433.4608-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".