[FFmpeg-devel] [PATCH 1/2] Bink version 'b' video decoder

Vitor Sessak vitor1001
Fri Feb 11 21:57:21 CET 2011


On 02/11/2011 12:45 PM, Peter Ross wrote:
> On Thu, Feb 10, 2011 at 08:16:18PM +0100, Vitor Sessak wrote:
>> On 02/10/2011 05:26 AM, Peter Ross wrote:
>>> On Wed, Feb 09, 2011 at 09:54:00PM +0100, Vitor Sessak wrote:
>>>> On 02/09/2011 01:04 PM, Peter Ross wrote:
>>>>> Based on original patch by Kostya Shishkov
>>>>> ---
>>>>>   libavcodec/bink.c     |  340 ++++++++++++++++++++++++++++++++++++++++++++++---
>>>>>   libavcodec/binkdata.h |   41 ++++++
>>>>>   2 files changed, 364 insertions(+), 17 deletions(-)
>>>>>
>>>>> diff --git a/libavcodec/bink.c b/libavcodec/bink.c
>>>>> index 64a10b7..32330fe 100644
>>>>
>>>> [...]
>>>>
>>>>> +/**
>>>>> + * Caclulate quantization tables for version b
>>>>> + */
>>>>> +static av_cold void binkb_calc_quant()
>>>>> +{
>>>>> +    float s[64];
>>>>> +    int i, j;
>>>>> +
>>>>> +    for (j = 0; j<    8; j++) {
>>>>> +        for (i = 0; i<    8; i++) {
>>>>> +            if (j&&    j != 4)
>>>>> +               if (i&&    i != 4)
>>>>> +                   s[j*8 + i] = cos(j * M_PI/16.0f) * cos(i * M_PI/16.0f) * 2.0f;
>>>>> +               else
>>>>> +                   s[j*8 + i] = cos(j * M_PI/16.0f) * sqrt(2.0f);
>>>>> +            else
>>>>> +               if (i&&    i != 4)
>>>>> +                   s[j*8 + i] = cos(i * M_PI/16.0f) * sqrt(2.0f);
>>>>> +               else
>>>>> +                   s[j*8 + i] = 1.0f;
>>>>> +        }
>>>>> +    }
>>>>> +
>>>>> +    for (j = 0; j<    16; j++) {
>>>>> +        for (i = 0; i<    64; i++) {
>>>>> +            binkb_intra_quant[j][i] = (1L<<12) * binkb_intra_seed[i] * binkb_num[j]/(float)binkb_den[j] * s[i];
>>>>> +            binkb_inter_quant[j][i] = (1L<<12) * binkb_inter_seed[i] * binkb_num[j]/(float)binkb_den[j] * s[i];
>>>>> +        }
>>>>> +    }
>>>>> +}
>>>>
>>>> Can you run the following test:
>>>>
>>>>
>>>>      for (j = 0; j<    16; j++) {
>>>>          for (i = 0; i<    64; i++) {
>>>>              int x = ( 1 + (1<<20))/((float)(1<<20))) * (1L<<12) *
>>>> binkb_intra_seed[i] * binkb_num[j]/(float)binkb_den[j] * s[i];
>>>>              int y = (-1 + (1<<20))/((float)(1<<20))) * (1L<<12) *
>>>> binkb_intra_seed[i] * binkb_num[j]/(float)binkb_den[j] * s[i];
>>>>              if (i != y)
>>>>                  av_log(NULL, "%d %d\n", i, j);
>>>>          }
>>>>     }
>>>>
>>>> and analogously for binkb_inter_quant? If there are any values that
>>>> are not stable to fp rounding, it is enough to hardcode them...
>>>
>>> Hard coding the quant tables will add 8k to libavcodec. Anyway heres the output:
>>
>> I was thinking more of hardcoding only the values that were printed,
>> but I didn't expect them to be so many.
>>
>>> av_log(0,0, "intra\n");
>>> for (j = 0; j<   16; j++) {
>>>      for (i = 0; i<   64; i++) {
>>>          int x = ( 1 + (1<<20))/((float)(1<<20)) * (1L<<12) * binkb_intra_seed[i] * binkb_num[j]/(float)binkb_den[j] * s[i];
>>>          int y = (-1 + (1<<20))/((float)(1<<20)) * (1L<<12) * binkb_intra_seed[i] * binkb_num[j]/(float)binkb_den[j] * s[i];
>>>          if (x != y)
>>>              av_log(0, 0, "%d %d\n", i, j);
>>>      }
>>> }
>>>
>>> av_log(0,0, "inter\n");
>>> for (j = 0; j<   16; j++) {
>>>      for (i = 0; i<   64; i++) {
>>>          int x = ( 1 + (1<<20))/((float)(1<<20)) * (1L<<12) * binkb_inter_seed[i] * binkb_num[j]/(float)binkb_den[j] * s[i];
>>>          int y = (-1 + (1<<20))/((float)(1<<20)) * (1L<<12) * binkb_inter_seed[i] * binkb_num[j]/(float)binkb_den[j] * s[i];
>>>          if (x != y)
>>>              av_log(0, 0, "%d %d\n", i, j);
>>>      }
>>> }
>>
>> What if you use doubles and replace 1<<20 by 1<<48?
>
> There are less.
>
> intra
> 0 0 (x:65536 y:65535)
> 4 0 (x:65536 y:65535)
> 32 0 (x:118784 y:118783)
> 36 0 (x:151552 y:151551)
> 0 3 (x:131072 y:131071)
> 4 3 (x:131072 y:131071)
> 32 3 (x:237568 y:237567)
> 36 3 (x:303104 y:303103)

Looks like the only problem is with i == 0, 4, 32 or 36, which is when 
s[i] == 1.0. Thus I propose the attached patches.

-Vitor



More information about the ffmpeg-devel mailing list