Revision f28b1048

View differences:

libavcodec/Makefile
195 195
OBJS-$(CONFIG_VORBIS_ENCODER)          += vorbis_enc.o vorbis.o vorbis_data.o mdct.o fft.o
196 196
OBJS-$(CONFIG_VP3_DECODER)             += vp3.o vp3dsp.o
197 197
OBJS-$(CONFIG_VP5_DECODER)             += vp5.o vp56.o vp56data.o vp3dsp.o
198
OBJS-$(CONFIG_VP6_DECODER)             += vp6.o vp56.o vp56data.o vp3dsp.o
199
OBJS-$(CONFIG_VP6A_DECODER)            += vp6.o vp56.o vp56data.o vp3dsp.o
200
OBJS-$(CONFIG_VP6F_DECODER)            += vp6.o vp56.o vp56data.o vp3dsp.o
198
OBJS-$(CONFIG_VP6_DECODER)             += vp6.o vp56.o vp56data.o vp3dsp.o huffman.o
199
OBJS-$(CONFIG_VP6A_DECODER)            += vp6.o vp56.o vp56data.o vp3dsp.o huffman.o
200
OBJS-$(CONFIG_VP6F_DECODER)            += vp6.o vp56.o vp56data.o vp3dsp.o huffman.o
201 201
OBJS-$(CONFIG_VQA_DECODER)             += vqavideo.o
202 202
OBJS-$(CONFIG_WAVPACK_DECODER)         += wavpack.o
203 203
OBJS-$(CONFIG_WMAV1_DECODER)           += wmadec.o wma.o mdct.o fft.o
libavcodec/vp5.c
205 205
                        s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 4;
206 206
                        idx = vp56_rac_get_tree(c, vp56_pc_tree, model1);
207 207
                        sign = vp56_rac_get(c);
208
                        coeff = vp56_coeff_bias[idx];
208
                        coeff = vp56_coeff_bias[idx+5];
209 209
                        for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
210 210
                            coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
211 211
                    } else {
libavcodec/vp56.h
157 157

  
158 158
    vp56_model_t *modelp;
159 159
    vp56_model_t models[2];
160

  
161
    /* huffman decoding */
162
    int use_huffman;
163
    GetBitContext gb;
164
    VLC dccv_vlc[2];
165
    VLC runv_vlc[2];
166
    VLC ract_vlc[2][3][6];
167
    unsigned int nb_null[2][2];       /* number of consecutive NULL DC/AC */
160 168
};
161 169

  
162 170

  
libavcodec/vp56data.c
62 62
    { 2,10}, {-4}, {-5},
63 63
};
64 64

  
65
const uint8_t vp56_coeff_bias[] = { 5, 7, 11, 19, 35, 67 };
65
const uint8_t vp56_coeff_bias[] = { 0, 1, 2, 3, 4, 5, 7, 11, 19, 35, 67 };
66 66
const uint8_t vp56_coeff_bit_length[] = { 0, 1, 2, 3, 4, 10 };
libavcodec/vp6.c
30 30
#include "avcodec.h"
31 31
#include "dsputil.h"
32 32
#include "bitstream.h"
33
#include "huffman.h"
33 34
#include "mpegvideo.h"
34 35

  
35 36
#include "vp56.h"
......
37 38
#include "vp6data.h"
38 39

  
39 40

  
41
static void vp6_parse_coeff(vp56_context_t *s);
42
static void vp6_parse_coeff_huffman(vp56_context_t *s);
43

  
40 44
static int vp6_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size,
41 45
                            int *golden_frame)
42 46
{
......
126 130
            s->filter_selection = 16;
127 131
    }
128 132

  
129
    if (vp56_rac_get(c))
130
        av_log(s->avctx, AV_LOG_WARNING,
131
               "alternative entropy decoding not supported\n");
133
    s->use_huffman = vp56_rac_get(c);
132 134

  
135
    s->parse_coeff = vp6_parse_coeff;
133 136
    if (coeff_offset) {
134
        vp56_init_range_decoder(&s->cc, buf+coeff_offset,
135
                                buf_size-coeff_offset);
136
        s->ccp = &s->cc;
137
        buf      += coeff_offset;
138
        buf_size -= coeff_offset;
139
        if (s->use_huffman) {
140
            s->parse_coeff = vp6_parse_coeff_huffman;
141
            init_get_bits(&s->gb, buf, buf_size);
142
        } else {
143
            vp56_init_range_decoder(&s->cc, buf, buf_size);
144
            s->ccp = &s->cc;
145
        }
137 146
    } else {
138 147
        s->ccp = &s->c;
139 148
    }
......
194 203
                model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
195 204
}
196 205

  
206
static int vp6_huff_cmp(const void *va, const void *vb)
207
{
208
    const Node *a = va, *b = vb;
209
    return a->count >= b->count;
210
}
211

  
212
static void vp6_build_huff_tree(vp56_context_t *s, uint8_t coeff_model[],
213
                                const uint8_t *map, unsigned size, VLC *vlc)
214
{
215
    Node nodes[2*size], *tmp = &nodes[size];
216
    int a, b, i;
217

  
218
    /* first compute probabilities from model */
219
    tmp[0].count = 256;
220
    for (i=0; i<size-1; i++) {
221
        a = tmp[i].count *        coeff_model[i]  >> 8;
222
        b = tmp[i].count * (255 - coeff_model[i]) >> 8;
223
        nodes[map[2*i  ]].count = a + !a;
224
        nodes[map[2*i+1]].count = b + !b;
225
    }
226

  
227
    /* then build the huffman tree accodring to probabilities */
228
    ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp, 1);
229
}
230

  
197 231
static void vp6_parse_coeff_models(vp56_context_t *s)
198 232
{
199 233
    vp56_range_coder_t *c = &s->c;
......
237 271
                        model->coeff_ract[pt][ct][cg][node] = def_prob[node];
238 272
                    }
239 273

  
274
    if (s->use_huffman) {
275
        for (pt=0; pt<2; pt++) {
276
            vp6_build_huff_tree(s, model->coeff_dccv[pt],
277
                                vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]);
278
            vp6_build_huff_tree(s, model->coeff_runv[pt],
279
                                vp6_huff_run_map, 9, &s->runv_vlc[pt]);
280
            for (ct=0; ct<3; ct++)
281
                for (cg = 0; cg < 6; cg++)
282
                    vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
283
                                        vp6_huff_coeff_map, 12,
284
                                        &s->ract_vlc[pt][ct][cg]);
285
        }
286
        memset(s->nb_null, 0, sizeof(s->nb_null));
287
    } else {
240 288
    /* coeff_dcct is a linear combination of coeff_dccv */
241 289
    for (pt=0; pt<2; pt++)
242 290
        for (ctx=0; ctx<3; ctx++)
243 291
            for (node=0; node<5; node++)
244 292
                model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255);
293
    }
245 294
}
246 295

  
247 296
static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect)
......
282 331
    }
283 332
}
284 333

  
334
/**
335
 * Read number of consecutive blocks with null DC or AC.
336
 * This value is < 74.
337
 */
338
static unsigned vp6_get_nb_null(vp56_context_t *s)
339
{
340
    unsigned val = get_bits(&s->gb, 2);
341
    if (val == 2)
342
        val += get_bits(&s->gb, 2);
343
    else if (val == 3) {
344
        val = get_bits1(&s->gb) << 2;
345
        val = 6+val + get_bits(&s->gb, 2+val);
346
    }
347
    return val;
348
}
349

  
350
static void vp6_parse_coeff_huffman(vp56_context_t *s)
351
{
352
    vp56_model_t *model = s->modelp;
353
    uint8_t *permute = s->scantable.permutated;
354
    VLC *vlc_coeff;
355
    int coeff, sign, coeff_idx;
356
    int b, cg, idx;
357
    int pt = 0;    /* plane type (0 for Y, 1 for U or V) */
358

  
359
    for (b=0; b<6; b++) {
360
        int ct = 0;    /* code type */
361
        if (b > 3) pt = 1;
362
        vlc_coeff = &s->dccv_vlc[pt];
363

  
364
        for (coeff_idx=0; coeff_idx<64; ) {
365
            int run = 1;
366
            if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) {
367
                s->nb_null[coeff_idx][pt]--;
368
                if (coeff_idx)
369
                    break;
370
            } else {
371
                coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3);
372
                if (coeff == 0) {
373
                    if (coeff_idx) {
374
                        int pt = (coeff_idx >= 6);
375
                        run += get_vlc2(&s->gb, s->runv_vlc[pt].table, 9, 3);
376
                        if (run >= 9)
377
                            run += get_bits(&s->gb, 6);
378
                    } else
379
                        s->nb_null[0][pt] = vp6_get_nb_null(s);
380
                    ct = 0;
381
                } else if (coeff == 11) {  /* end of block */
382
                    if (coeff_idx == 1)    /* first AC coeff ? */
383
                        s->nb_null[1][pt] = vp6_get_nb_null(s);
384
                    break;
385
                } else {
386
                    int coeff2 = vp56_coeff_bias[coeff];
387
                    if (coeff > 4)
388
                        coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11);
389
                    ct = 1 + (coeff2 > 1);
390
                    sign = get_bits1(&s->gb);
391
                    coeff2 = (coeff2 ^ -sign) + sign;
392
                    if (coeff_idx)
393
                        coeff2 *= s->dequant_ac;
394
                    idx = model->coeff_index_to_pos[coeff_idx];
395
                    s->block_coeff[b][permute[idx]] = coeff2;
396
                }
397
            }
398
            coeff_idx+=run;
399
            cg = FFMIN(vp6_coeff_groups[coeff_idx], 3);
400
            vlc_coeff = &s->ract_vlc[pt][ct][cg];
401
        }
402
    }
403
}
404

  
285 405
static void vp6_parse_coeff(vp56_context_t *s)
286 406
{
287 407
    vp56_range_coder_t *c = s->ccp;
......
309 429
                if (vp56_rac_get_prob(c, model2[2])) {
310 430
                    if (vp56_rac_get_prob(c, model2[3])) {
311 431
                        idx = vp56_rac_get_tree(c, vp56_pc_tree, model1);
312
                        coeff = vp56_coeff_bias[idx];
432
                        coeff = vp56_coeff_bias[idx+5];
313 433
                        for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
314 434
                            coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
315 435
                    } else {
......
500 620
    s->parse_vector_adjustment = vp6_parse_vector_adjustment;
501 621
    s->adjust = vp6_adjust;
502 622
    s->filter = vp6_filter;
503
    s->parse_coeff = vp6_parse_coeff;
504 623
    s->default_models_init = vp6_default_models_init;
505 624
    s->parse_vector_models = vp6_parse_vector_models;
506 625
    s->parse_coeff_models = vp6_parse_coeff_models;
libavcodec/vp6data.h
297 297

  
298 298
static const uint8_t vp6_coord_div[] = { 4, 4, 4, 4, 8, 8 };
299 299

  
300
static const uint8_t vp6_huff_coeff_map[] = {
301
    13, 14, 11, 0, 1, 15, 16, 18, 2, 17, 3, 4, 19, 20, 5, 6, 21, 22, 7, 8, 9, 10
302
};
303

  
304
static const uint8_t vp6_huff_run_map[] = {
305
    10, 13, 11, 12, 0, 1, 2, 3, 14, 8, 15, 16, 4, 5, 6, 7
306
};
307

  
300 308
#endif /* VP6DATA_H */

Also available in: Unified diff