[Ffmpeg-devel] [PATCH] DTS decoder

Michael Niedermayer michaelni
Tue Feb 27 01:10:13 CET 2007


Hi

On Sat, Feb 24, 2007 at 03:29:18PM +0200, Kostya wrote:
[...]
> +/** indexes for samples VLC select */
> +static BitAlloc dca_bitalloc_index;
> +/** transition mode VLCs */
> +static BitAlloc dca_tmode;
> +/** scalefactor VLCs */
> +static BitAlloc dca_scalefactor;
> +/** samples VLCs */
> +static BitAlloc dca_smpl_bitalloc[11];

it would be more readable if the comments where at the right or if there
where some well placed blank lines between these


[...]

> +    /* Pre-calculated cosine modulation coefs for the QMF */
> +    float cos_mod[544];

comment is not doxygen compatible and the table is not instance specific
it could be a shared static table


[...]
> +static void dca_init_vlcs()
> +{
> +    static int vlcs_inited = 0;
> +    int i, j;
> +
> +    if (vlcs_inited)
> +        return;

you could check some pointer in a table which gets initalized which would
remove the need for this variable


[...]
> +    s->frame_type = get_bits(&s->gb, 1);
> +    s->samples_deficit = get_bits(&s->gb, 5) + 1;
> +    s->crc_present = get_bits(&s->gb, 1);
> +    s->sample_blocks = get_bits(&s->gb, 7) + 1;
> +    s->frame_size = get_bits(&s->gb, 14) + 1;
> +    if (s->frame_size < 95)
> +        return -1;
> +    s->amode = get_bits(&s->gb, 6);
> +    s->sample_rate = dca_sample_rates[get_bits(&s->gb, 4)];
> +    if (!s->sample_rate)
> +        return -1;
> +    s->bit_rate = dca_bit_rates[get_bits(&s->gb, 5)];
> +    if (!s->bit_rate)
> +        return -1;
> +
> +    s->downmix = get_bits(&s->gb, 1);
> +    s->dynrange = get_bits(&s->gb, 1);
> +    s->timestamp = get_bits(&s->gb, 1);
> +    s->aux_data = get_bits(&s->gb, 1);
> +    s->hdcd = get_bits(&s->gb, 1);
> +    s->ext_descr = get_bits(&s->gb, 3);
> +    s->ext_coding = get_bits(&s->gb, 1);
> +    s->aspf = get_bits(&s->gb, 1);
> +    s->lfe = get_bits(&s->gb, 2);
> +    s->predictor_history = get_bits(&s->gb, 1);
> +
> +    /* TODO: check CRC */
> +    if (s->crc_present)
> +        s->header_crc = get_bits(&s->gb, 16);
> +
> +    s->multirate_inter = get_bits(&s->gb, 1);
> +    s->version = get_bits(&s->gb, 4);
> +    s->copy_history = get_bits(&s->gb, 2);
> +    s->source_pcm_res = get_bits(&s->gb, 3);
> +    s->front_sum = get_bits(&s->gb, 1);
> +    s->surround_sum = get_bits(&s->gb, 1);
> +    s->dialog_norm = get_bits(&s->gb, 4);

this could be aligned vertically, like

s->multirate_inter = get_bits(&s->gb, 1);
s->version         = get_bits(&s->gb, 4);
s->copy_history    = get_bits(&s->gb, 2);
s->source_pcm_res  = get_bits(&s->gb, 3);
s->front_sum       = get_bits(&s->gb, 1);
s->surround_sum    = get_bits(&s->gb, 1);
s->dialog_norm     = get_bits(&s->gb, 4);



[...]
> +        /* Load in one sample from each subband and clear inactive subbands */
> +        for (i = 0; i < s->subband_activity[chans]; i++)
> +            raXin[i] = samples_in[i][subindex];
> +        for (; i < 32; i++)
> +            raXin[i] = 0.0;
> +
> +        /* Multiply by cosine modulation coefficients and
> +         * create temporary arrays SUM and DIFF */
> +        for (j = 0, k = 0; k < 16; k++) {
> +            t1 = 0.0;
> +            t2 = 0.0;
> +            for (i = 0; i < 16; i++, j++){
> +                t1 += (raXin[2 * i] + raXin[2 * i + 1]) * s->cos_mod[j];
> +                t2 += (raXin[2 * i] + raXin[2 * i - 1]) * s->cos_mod[j + 256];
> +            }
> +            sum[k] = t1 + t2;
> +            diff[k] = t1 - t2;
> +        }

last=0
for(i = 0; i < s->subband_activity[chans]; i++){
    float t= samples_in[i][subindex];
    praXin[i]= last + t;
    last= t;
}
praXin[i++]= last;
for (; i < 32; i++)
    raXin[i] = 0.0;

for (j = 0, k = 0; k < 16; k++) {
    t1 = 0.0;
    t2 = 0.0;
    for (i = 0; i < 32; i+=2, j++){
        t1 += praXin[i + 1] * s->cos_mod[j];
        t2 += praXin[i    ] * s->cos_mod[j + 256];
    }
    sum [k] = t1 + t2;
    diff[k] = t1 - t2;
}



[...]
> +            /* Determine its type */
> +            int q_type = 1;     /* (Assume Huffman type by default) */
> +            if (abits >= 11 || !abits
> +                || !dca_smpl_bitalloc[abits].vlc[sel].table) {
> +                /* Not Huffman type */
> +                if (abits <= 7)
> +                    q_type = 3; /* Block code */
> +                else
> +                    q_type = 2; /* No further encoding */
> +            }
> +
> +            if (abits == 0)
> +                q_type = 0;     /* No bits allocated */

q_type is unused


> +
> +            /*
> +             * Extract bits from the bit stream
> +             */
> +            if(!abits){
> +                memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0]));
> +            }else if(abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){
> +                if(abits <= 7){
> +                    /* Block code */
> +                    int block_code1, block_code2, size, levels;
> +                    int block[8];
> +
> +                    if(abits >  6){
> +                        size = abits_sizes[6];
> +                        levels = abits_levels[6];
> +                    }else{
> +                        size = abits_sizes[abits-1];
> +                        levels = abits_levels[abits-1];
> +                    }

size   = abits_sizes [abits-1];
levels = abits_levels[abits-1];

should do due to if(abits <= 7){


[...]
> +static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf,
> +                              int buf_size)
> +{
> +    int start_found, i;
> +    uint32_t state;
> +    ParseContext *pc = &pc1->pc;
> +
> +    start_found = pc->frame_start_found;
> +    state = pc->state;
> +
> +    i = 0;
> +    if (!start_found) {
> +        for (i = 0; i < buf_size; i++) {
> +            state = (state << 8) | buf[i];
> +            if (IS_MARKER(state, i, buf, buf_size)) {
> +                if (pc1->lastmarker && state == pc1->lastmarker) {

the pc1->lastmarker check is useless state == pc1->lastmarker is enough


> +                    start_found = 1;
> +                    break;
> +                } else if (!pc1->lastmarker) {
> +                    start_found = 1;
> +                    pc1->lastmarker = state;
> +                    break;
> +                }
> +            }
> +        }
> +    }
> +    if (start_found) {
> +        for (; i < buf_size; i++) {
> +            state = (state << 8) | buf[i];
> +            if (IS_MARKER(state, i, buf, buf_size)
> +                && state == pc1->lastmarker) {
> +                pc->frame_start_found = 0;
> +                pc->state = -1;
> +                return i - 3;
> +            }

wont if(state == pc1->lastmarker) do?
exceuting the whole IS_MARKER() check per byte is slow

besides these iam fine with the patch

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you really think that XML is the answer, then you definitly missunderstood
the question -- Attila Kinali
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070227/7ffec915/attachment.pgp>



More information about the ffmpeg-devel mailing list