mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/get_bits: add get_leb()
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
12eac23637
commit
0cc0d8c0b5
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue