[FFmpeg-devel] atrac1 decoder and aea demuxer rev 6

Benjamin Larsson banan
Thu Sep 10 10:27:21 CEST 2009


Michael Niedermayer wrote:
>> +    /* low band */
>> +    bsm_tmp = get_bits(gb, 2);
>> +    if (bsm_tmp & 1)
>> +        return -1;
>> +    bsm[IDX_LOW_BAND] = 2 - bsm_tmp;
>> +
>> +    /* middle band */
>> +    bsm_tmp = get_bits(gb, 2);
>> +    if (bsm_tmp & 1)
>> +        return -1;
>> +    bsm[IDX_MID_BAND] = 2 - bsm_tmp;
>>     
>
> for(2)
>
>   
IMO this makes the code less clear but I'll change it if you insist.

>   
>> +
>> +    /* high band */
>> +    bsm_tmp = get_bits(gb, 2);
>> +    if (bsm_tmp != 0 && bsm_tmp != 3)
>> +        return -1;
>> +    bsm[IDX_HIGH_BAND] = 3 - bsm_tmp;
>> +
>> +    skip_bits(gb, 2);
>> +    return 0;
>> +}
>> +
>>     
>
>   
>   
>> +
>> +    /* get word length index (idwl) for each BFU */
>> +    for (i=0 ; i<su->num_bfus ; i++)
>> +        su->idwls[i] = get_bits(gb, 4);
>> +
>> +    /* get scalefactor index (idsf) for each BFU */
>> +    for (i=0 ; i<su->num_bfus ; i++)
>> +        su->idsfs[i] = get_bits(gb, 6);
>> +
>> +    /* zero idwl/idsf for empty BFUs */
>> +    for (i = su->num_bfus; i < AT1_MAX_BFU; i++)
>> +        su->idwls[i] = su->idsfs[i] = 0;
>> +
>> +    /* read in the spectral data and reconstruct MDCT spectrum of this channel */
>> +    for (band_num=0 ; band_num<AT1_QMF_BANDS ; band_num++) {
>> +        for (bfu_num=bfu_bands_t[band_num] ; bfu_num<bfu_bands_t[band_num+1] ; bfu_num++) {
>> +            int pos;
>> +
>> +            int num_specs = specs_per_bfu[bfu_num];
>> +            int word_len  = !!su->idwls[bfu_num] + su->idwls[bfu_num];
>> +            bits_used    += word_len * num_specs; /* add number of bits consumed by current BFU */
>> +
>> +            /* check for bitstream overflow */
>> +            if (bits_used > AT1_SU_MAX_BITS)
>> +                return -1;
>> +
>> +            /* get the position of the 1st spec according to the block size mode */
>> +            pos = su->bsm[band_num] ? bfu_start_short[bfu_num] : bfu_start_long[bfu_num];
>> +
>> +            if (word_len) {
>> +                float   max_quant = 1.0/(float)((1 << (word_len - 1)) - 1);
>> +
>>     
>
>   
>> +                for (i=0 ; i<num_specs ; i++) {
>> +                    /* read in a quantized spec and convert it to
>> +                     * signed int and then inverse quantization
>> +                     */
>> +                    spec[pos+i] = get_sbits(gb, word_len) *
>> +                                            sf_tab[su->idsfs[bfu_num]] * max_quant;
>>     
>
> sf_tab[su->idsfs[bfu_num]] can be factored out
>
>   

Sorry about that one. I have alot of dev trees and I missed this. I know 
you mentioned this before.

>   
>> +                }
>> +            } else { /* word_len = 0 -> empty BFU, zero all specs in the emty BFU */
>> +                memset(&spec[pos], 0, num_specs*sizeof(float));
>> +            }
>> +        }
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>>     
>
> [...]
>   
>> +static int aea_read_probe(AVProbeData *p)
>> +{
>> +    if (p->buf_size <= 2048+212)
>> +        return 0;
>> +
>> +    /* Magic is '00 08 00 00' in Little Endian*/
>> +    if(AV_RL32(p->buf)==0x800) {
>> +        int bsm_s, bsm_e, inb_s, inb_e;
>> +        bsm_s = p->buf[2048];
>> +        inb_s = p->buf[2048+1];
>> +        inb_e = p->buf[2048+210];
>> +        bsm_e = p->buf[2048+211];
>> +
>> +
>> +        /* Check so that the redundant bsm bytes and info bytes are valid
>> +         * the block size mode bytes have to be the same
>> +         * the info bytes have to be the same
>> +         * the block size mode and info byte can't be the same
>> +         */
>> +        if ((bsm_s == bsm_e) && (inb_s == inb_e) && (bsm_s != inb_s))
>>     
>
> the () are useless
> also this can be simplified to
> a= AV_RL16()
> b= AV_RL16()
> if(a == bswap16(b) && a != b)
>   

Well IMO that is obfuscation. But if you insist.

MvH
Benjamin Larsson





More information about the ffmpeg-devel mailing list