From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 5/8] avcodec/get_bits: add get_leb() Date: Thu, 14 Dec 2023 17:14:30 -0300 Message-ID: <20231214201433.4608-6-jamrial@gmail.com> (raw) In-Reply-To: <20231214201433.4608-1-jamrial@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com> --- 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".
next prev parent reply other threads:[~2023-12-14 20:16 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-14 20:14 [FFmpeg-devel] [PATCH v7 0/8] avformat: introduce AVStreamGroup James Almer 2023-12-14 20:14 ` [FFmpeg-devel] [PATCH 1/8] avutil: introduce an Immersive Audio Model and Formats API James Almer 2023-12-18 11:04 ` Anton Khirnov 2023-12-18 18:10 ` James Almer 2023-12-14 20:14 ` [FFmpeg-devel] [PATCH 2/8] avformat: introduce AVStreamGroup James Almer 2023-12-14 20:14 ` [FFmpeg-devel] [PATCH 3/8] ffmpeg: add support for muxing AVStreamGroups James Almer 2023-12-15 21:28 ` James Almer 2023-12-14 20:14 ` [FFmpeg-devel] [PATCH 4/8] avcodec/packet: add IAMF Parameters side data types James Almer 2023-12-14 20:14 ` James Almer [this message] 2023-12-14 20:14 ` [FFmpeg-devel] [PATCH 6/8] avformat/aviobuf: add ffio_read_leb() and ffio_write_leb() James Almer 2023-12-14 20:14 ` [FFmpeg-devel] [PATCH 7/8] avformat: Immersive Audio Model and Formats demuxer James Almer 2023-12-14 20:14 ` [FFmpeg-devel] [PATCH 8/8] avformat: Immersive Audio Model and Formats muxer James Almer -- strict thread matches above, loose matches on Subject: below -- 2023-12-05 22:43 [FFmpeg-devel] [PATCH v6 0/8] avformat: introduce AVStreamGroup James Almer 2023-12-05 22:43 ` [FFmpeg-devel] [PATCH 5/8] avcodec/get_bits: add get_leb() James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231214201433.4608-6-jamrial@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git