[FFmpeg-devel] [PATCH] Arithmetic decoding in ALS

Thilo Borgmann thilo.borgmann
Tue Jan 19 17:30:01 CET 2010


Am 19.01.10 16:38, schrieb Thilo Borgmann:
> Am 19.01.10 00:21, schrieb Thilo Borgmann:
>> Am 18.01.10 23:38, schrieb Michael Niedermayer:
>>> On Thu, Jan 14, 2010 at 03:20:04PM +0100, Thilo Borgmann wrote:
>>>> Am 13.01.10 00:00, schrieb Michael Niedermayer:
>>>>> On Tue, Jan 12, 2010 at 08:50:27PM +0100, Thilo Borgmann wrote:
>>>>>> Am 12.01.10 00:33, schrieb Michael Niedermayer:
>>>>>>> On Mon, Jan 11, 2010 at 09:15:05PM +0100, Thilo Borgmann wrote:
>>>>>>>> ...
>>
>>>> +/** Initializes a given lookup table using a given delta
>>>> + */
>>>> +static void bgmc_lut_fill(unsigned int lut, unsigned int delta)
>>>> +{
>>>> +    unsigned int sx, i;
>>>> +
>>>> +    for (sx = 0; sx < 16; sx++)
>>>> +        for (i = 0; i < LUT_SIZE; i++) {
>>>> +            unsigned int target = (i + 1) << (FREQ_BITS - LUT_BITS);
>>>> +            unsigned int symbol = 1 << delta;
>>>> +
>>>> +            while (cf_table[sx][symbol] > target)
>>>> +                symbol += 1 << delta;
>>>> +
>>>> +            cf_lut[lut][sx][i] = symbol;
>>>> +        }
>>>> +
>>>> +    cf_lut_status[lut] = delta;
>>>> +}
>>>> +
>>>> +
>>>> +/** Retunes the index of a suitable lookup table for a given delta
>>>> + */
>>>> +static unsigned int bgmc_lut_get(unsigned int delta)
>>>> +{
>>>> +    unsigned int lut = delta < LUT_BUFF ? delta : LUT_BUFF;
>>>> +
>>>> +    if (cf_lut_status[lut] != delta)
>>>> +        bgmc_lut_fill(lut, delta);
>>>
>>> this doesnt look thread safe
>>
>> I agree for delta >= LUT_BUFF. To be sure, I don't see that for the
>> other ones, right?
>>
>> So whether all cases or just the delta >= LUT_BUFF cases affected, do
>> return a new malloc'd buffer and free it at the end of bgmc_decode()?
>> Otherwise just locking comes into my mind which is for sure worse...
> 
> Still unanswered and thought about again. Either a malloc'd buffer for
> delta >= LUT_BUFF or just making cf_lut[_status] non-static is still in
> my mind. What about that?

For ALS there is a maximum of 36 needed luts. If such a number would not
require too much memory (36 * 16 * LUT_SIZE * sizeof(unsigned int)) it
might also make sense to keep all possible luts in a buffer allocated in
another bgmc_init_buffers() function...

-Thilo



More information about the ffmpeg-devel mailing list