[FFmpeg-devel] [PATCH v3] add put_bits_long to avoid undefined behaviour in put_bits

Måns Rullgård mans
Mon Sep 14 22:03:53 CEST 2009


matthieu castet <castet.matthieu at free.fr> writes:

> Michael Niedermayer wrote:
>> On Sun, Sep 13, 2009 at 03:17:01PM +0200, matthieu castet wrote:
>>> Hi,
>>>
>>>  +static inline void put_bits_long(PutBitContext *s, int n,
>>> unsigned int value)
>>> +{
>>> +    if(n <= 31) {
>>> +        put_bits(s, n, value);
>>> +    } else {
>>> +#ifdef ALT_BITSTREAM_READER_LE
>>> +        put_bits(s, 16, value & 0xffff);
>>> +        put_bits(s, 16, value >> 16);
>>> +#else
>>> +        put_bits(s, 16, value >> 16);
>>> +        put_bits(s, 16, value & 0xffff);
>>> +#endif
>>> +    }
>>> +
>>> +}
>>> +
>> i dont think this should be static inline or where is it speed
>> critical?
>>
> Why not but :
> - the equivalent "get_bits_long" is static inline.
> - most of time it is called with const n/value arguments and the function will be optimised

It will still increase the code size compared to a called function.
You need to look at where it is used.  If it called less frequently
than once per frame, it should probably not be inlined.

> - should we create a put_bits.c for putting only this function ?

bitstream.c seems fine to me.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list