[FFmpeg-devel] [PATCH 6/7] avcodec/put_bits: add put_leb()

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Jan 30 23:53:49 EET 2024


James Almer:
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>  libavcodec/put_bits.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
> index 4561dc131a..04dedd3342 100644
> --- a/libavcodec/put_bits.h
> +++ b/libavcodec/put_bits.h
> @@ -370,6 +370,22 @@ static inline void put_sbits63(PutBitContext *pb, int n, int64_t value)
>      put_bits64(pb, n, (uint64_t)(value) & (~(UINT64_MAX << n)));
>  }
>  
> +static inline void put_leb(PutBitContext *s, unsigned value)
> +{
> +    int len;
> +    uint8_t byte;
> +
> +    len = (av_log2(value) + 7) / 7;
> +
> +    for (int i = 0; i < len; i++) {
> +        byte = value >> (7 * i) & 0x7f;
> +        if (i < len - 1)
> +            byte |= 0x80;
> +
> +        put_bits_no_assert(s, 8, byte);
> +    }
> +}
> +
>  /**
>   * Return the pointer to the byte where the bitstream writer will put
>   * the next bit.

This function does use any internals of PutBitContext and should
therefore be in user-code. In fact, get_leb() should not exist in
get_bits.h.

- Andreas



More information about the ffmpeg-devel mailing list