3
* VP6 compatible video decoder
5
2
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
7
* The VP6F decoder accepts an optional 1 byte extradata. It is composed of:
8
* - upper 4bits: difference between encoded width and visible width
9
* - lower 4bits: difference between encoded height and visible height
11
4
* This file is part of Libav.
13
6
* Libav is free software; you can redistribute it and/or
25
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
* VP6 compatible video decoder
25
* The VP6F decoder accepts an optional 1 byte extradata. It is composed of:
26
* - upper 4 bits: difference between encoded width and visible width
27
* - lower 4 bits: difference between encoded height and visible height
28
30
#include <stdlib.h>
30
32
#include "avcodec.h"
137
139
if (coeff_offset) {
138
140
buf += coeff_offset;
139
141
buf_size -= coeff_offset;
143
if (s->framep[VP56_FRAME_CURRENT]->key_frame)
144
avcodec_set_dimensions(s->avctx, 0, 0);
142
147
if (s->use_huffman) {
143
148
s->parse_coeff = vp6_parse_coeff_huffman;
144
149
init_get_bits(&s->gb, buf, buf_size<<3);
213
218
return (a->count - b->count)*16 + (b->sym - a->sym);
216
static void vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
217
const uint8_t *map, unsigned size, VLC *vlc)
221
static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
222
const uint8_t *map, unsigned size, VLC *vlc)
219
224
Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];
232
/* then build the huffman tree accodring to probabilities */
233
ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
234
FF_HUFFMAN_FLAG_HNODE_FIRST);
237
/* then build the huffman tree according to probabilities */
238
return ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
239
FF_HUFFMAN_FLAG_HNODE_FIRST);
237
static void vp6_parse_coeff_models(VP56Context *s)
242
static int vp6_parse_coeff_models(VP56Context *s)
239
244
VP56RangeCoder *c = &s->c;
240
245
VP56Model *model = s->modelp;
280
285
if (s->use_huffman) {
281
286
for (pt=0; pt<2; pt++) {
282
vp6_build_huff_tree(s, model->coeff_dccv[pt],
283
vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]);
284
vp6_build_huff_tree(s, model->coeff_runv[pt],
285
vp6_huff_run_map, 9, &s->runv_vlc[pt]);
287
if (vp6_build_huff_tree(s, model->coeff_dccv[pt],
288
vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]))
290
if (vp6_build_huff_tree(s, model->coeff_runv[pt],
291
vp6_huff_run_map, 9, &s->runv_vlc[pt]))
286
293
for (ct=0; ct<3; ct++)
287
294
for (cg = 0; cg < 6; cg++)
288
vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
289
vp6_huff_coeff_map, 12,
290
&s->ract_vlc[pt][ct][cg]);
295
if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
296
vp6_huff_coeff_map, 12,
297
&s->ract_vlc[pt][ct][cg]))
292
300
memset(s->nb_null, 0, sizeof(s->nb_null));
297
305
for (node=0; node<5; node++)
298
306
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);
302
311
static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
431
442
model1 = model->coeff_dccv[pt];
432
443
model2 = model->coeff_dcct[pt][ctx];
434
for (coeff_idx=0; coeff_idx<64; ) {
435
447
if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
436
448
/* parse a coeff */
437
449
if (vp56_rac_get_prob(c, model2[2])) {
472
484
run += vp56_rac_get_prob(c, model3[i+8]) << i;
476
cg = vp6_coeff_groups[coeff_idx+=run];
490
cg = vp6_coeff_groups[coeff_idx];
477
491
model1 = model2 = model->coeff_ract[pt][ct][cg];
609
623
AVCodec ff_vp6_decoder = {
617
ff_vp56_decode_frame,
625
.type = AVMEDIA_TYPE_VIDEO,
627
.priv_data_size = sizeof(VP56Context),
628
.init = vp6_decode_init,
629
.close = vp6_decode_free,
630
.decode = ff_vp56_decode_frame,
631
.capabilities = CODEC_CAP_DR1,
619
632
.long_name = NULL_IF_CONFIG_SMALL("On2 VP6"),
622
635
/* flash version, not flipped upside-down */
623
636
AVCodec ff_vp6f_decoder = {
631
ff_vp56_decode_frame,
638
.type = AVMEDIA_TYPE_VIDEO,
640
.priv_data_size = sizeof(VP56Context),
641
.init = vp6_decode_init,
642
.close = vp6_decode_free,
643
.decode = ff_vp56_decode_frame,
644
.capabilities = CODEC_CAP_DR1,
633
645
.long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"),
636
648
/* flash version, not flipped upside-down, with alpha channel */
637
649
AVCodec ff_vp6a_decoder = {
645
ff_vp56_decode_frame,
651
.type = AVMEDIA_TYPE_VIDEO,
653
.priv_data_size = sizeof(VP56Context),
654
.init = vp6_decode_init,
655
.close = vp6_decode_free,
656
.decode = ff_vp56_decode_frame,
657
.capabilities = CODEC_CAP_DR1,
647
658
.long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"),