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

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Jan 31 00:10:09 EET 2024


James Almer:
> On 1/30/2024 6:53 PM, Andreas Rheinhardt wrote:
>> 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.
> 
> You could say the same about skip_1stop_8data_bits(), decode210(),
> decode012() and get_vlc_multi().

Old errors do not justify new errors.
(skip_1stop_8data_bits() is mostly mpegvideodec and if it were not for
SVQ3 it would have been moved there already.)

> 
> And the idea is to have these be reusable. leb is evidently going to be
> used by anything AOMedia will make.

Then it should be in some AOMedia header. If it should exist at all:
Byte-aligned lebs should not use a GetBitContext at all. And all current
users are byte-aligned.

- Andreas



More information about the ffmpeg-devel mailing list