You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

656 lines
21KB

  1. /**
  2. * @file
  3. * VP6 compatible video decoder
  4. *
  5. * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
  6. *
  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
  10. *
  11. * This file is part of Libav.
  12. *
  13. * Libav is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Lesser General Public
  15. * License as published by the Free Software Foundation; either
  16. * version 2.1 of the License, or (at your option) any later version.
  17. *
  18. * Libav is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with Libav; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. */
  27. #include <stdlib.h>
  28. #include "avcodec.h"
  29. #include "dsputil.h"
  30. #include "get_bits.h"
  31. #include "huffman.h"
  32. #include "vp56.h"
  33. #include "vp56data.h"
  34. #include "vp6data.h"
  35. #define VP6_MAX_HUFF_SIZE 12
  36. static void vp6_parse_coeff(VP56Context *s);
  37. static void vp6_parse_coeff_huffman(VP56Context *s);
  38. static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
  39. int *golden_frame)
  40. {
  41. VP56RangeCoder *c = &s->c;
  42. int parse_filter_info = 0;
  43. int coeff_offset = 0;
  44. int vrt_shift = 0;
  45. int sub_version;
  46. int rows, cols;
  47. int res = 1;
  48. int separated_coeff = buf[0] & 1;
  49. s->framep[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80);
  50. ff_vp56_init_dequant(s, (buf[0] >> 1) & 0x3F);
  51. if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
  52. sub_version = buf[1] >> 3;
  53. if (sub_version > 8)
  54. return 0;
  55. s->filter_header = buf[1] & 0x06;
  56. if (buf[1] & 1) {
  57. av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n");
  58. return 0;
  59. }
  60. if (separated_coeff || !s->filter_header) {
  61. coeff_offset = AV_RB16(buf+2) - 2;
  62. buf += 2;
  63. buf_size -= 2;
  64. }
  65. rows = buf[2]; /* number of stored macroblock rows */
  66. cols = buf[3]; /* number of stored macroblock cols */
  67. /* buf[4] is number of displayed macroblock rows */
  68. /* buf[5] is number of displayed macroblock cols */
  69. if (!s->macroblocks || /* first frame */
  70. 16*cols != s->avctx->coded_width ||
  71. 16*rows != s->avctx->coded_height) {
  72. avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
  73. if (s->avctx->extradata_size == 1) {
  74. s->avctx->width -= s->avctx->extradata[0] >> 4;
  75. s->avctx->height -= s->avctx->extradata[0] & 0x0F;
  76. }
  77. res = 2;
  78. }
  79. ff_vp56_init_range_decoder(c, buf+6, buf_size-6);
  80. vp56_rac_gets(c, 2);
  81. parse_filter_info = s->filter_header;
  82. if (sub_version < 8)
  83. vrt_shift = 5;
  84. s->sub_version = sub_version;
  85. } else {
  86. if (!s->sub_version)
  87. return 0;
  88. if (separated_coeff || !s->filter_header) {
  89. coeff_offset = AV_RB16(buf+1) - 2;
  90. buf += 2;
  91. buf_size -= 2;
  92. }
  93. ff_vp56_init_range_decoder(c, buf+1, buf_size-1);
  94. *golden_frame = vp56_rac_get(c);
  95. if (s->filter_header) {
  96. s->deblock_filtering = vp56_rac_get(c);
  97. if (s->deblock_filtering)
  98. vp56_rac_get(c);
  99. if (s->sub_version > 7)
  100. parse_filter_info = vp56_rac_get(c);
  101. }
  102. }
  103. if (parse_filter_info) {
  104. if (vp56_rac_get(c)) {
  105. s->filter_mode = 2;
  106. s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift;
  107. s->max_vector_length = 2 << vp56_rac_gets(c, 3);
  108. } else if (vp56_rac_get(c)) {
  109. s->filter_mode = 1;
  110. } else {
  111. s->filter_mode = 0;
  112. }
  113. if (s->sub_version > 7)
  114. s->filter_selection = vp56_rac_gets(c, 4);
  115. else
  116. s->filter_selection = 16;
  117. }
  118. s->use_huffman = vp56_rac_get(c);
  119. s->parse_coeff = vp6_parse_coeff;
  120. if (coeff_offset) {
  121. buf += coeff_offset;
  122. buf_size -= coeff_offset;
  123. if (buf_size < 0) {
  124. if (s->framep[VP56_FRAME_CURRENT]->key_frame)
  125. avcodec_set_dimensions(s->avctx, 0, 0);
  126. return 0;
  127. }
  128. if (s->use_huffman) {
  129. s->parse_coeff = vp6_parse_coeff_huffman;
  130. init_get_bits(&s->gb, buf, buf_size<<3);
  131. } else {
  132. ff_vp56_init_range_decoder(&s->cc, buf, buf_size);
  133. s->ccp = &s->cc;
  134. }
  135. } else {
  136. s->ccp = &s->c;
  137. }
  138. return res;
  139. }
  140. static void vp6_coeff_order_table_init(VP56Context *s)
  141. {
  142. int i, pos, idx = 1;
  143. s->modelp->coeff_index_to_pos[0] = 0;
  144. for (i=0; i<16; i++)
  145. for (pos=1; pos<64; pos++)
  146. if (s->modelp->coeff_reorder[pos] == i)
  147. s->modelp->coeff_index_to_pos[idx++] = pos;
  148. }
  149. static void vp6_default_models_init(VP56Context *s)
  150. {
  151. VP56Model *model = s->modelp;
  152. model->vector_dct[0] = 0xA2;
  153. model->vector_dct[1] = 0xA4;
  154. model->vector_sig[0] = 0x80;
  155. model->vector_sig[1] = 0x80;
  156. memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats));
  157. memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv));
  158. memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv));
  159. memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv));
  160. memcpy(model->coeff_reorder, vp6_def_coeff_reorder, sizeof(model->coeff_reorder));
  161. vp6_coeff_order_table_init(s);
  162. }
  163. static void vp6_parse_vector_models(VP56Context *s)
  164. {
  165. VP56RangeCoder *c = &s->c;
  166. VP56Model *model = s->modelp;
  167. int comp, node;
  168. for (comp=0; comp<2; comp++) {
  169. if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0]))
  170. model->vector_dct[comp] = vp56_rac_gets_nn(c, 7);
  171. if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1]))
  172. model->vector_sig[comp] = vp56_rac_gets_nn(c, 7);
  173. }
  174. for (comp=0; comp<2; comp++)
  175. for (node=0; node<7; node++)
  176. if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node]))
  177. model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
  178. for (comp=0; comp<2; comp++)
  179. for (node=0; node<8; node++)
  180. if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node]))
  181. model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
  182. }
  183. /* nodes must ascend by count, but with descending symbol order */
  184. static int vp6_huff_cmp(const void *va, const void *vb)
  185. {
  186. const Node *a = va, *b = vb;
  187. return (a->count - b->count)*16 + (b->sym - a->sym);
  188. }
  189. static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
  190. const uint8_t *map, unsigned size, VLC *vlc)
  191. {
  192. Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];
  193. int a, b, i;
  194. /* first compute probabilities from model */
  195. tmp[0].count = 256;
  196. for (i=0; i<size-1; i++) {
  197. a = tmp[i].count * coeff_model[i] >> 8;
  198. b = tmp[i].count * (255 - coeff_model[i]) >> 8;
  199. nodes[map[2*i ]].count = a + !a;
  200. nodes[map[2*i+1]].count = b + !b;
  201. }
  202. free_vlc(vlc);
  203. /* then build the huffman tree according to probabilities */
  204. return ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
  205. FF_HUFFMAN_FLAG_HNODE_FIRST);
  206. }
  207. static int vp6_parse_coeff_models(VP56Context *s)
  208. {
  209. VP56RangeCoder *c = &s->c;
  210. VP56Model *model = s->modelp;
  211. int def_prob[11];
  212. int node, cg, ctx, pos;
  213. int ct; /* code type */
  214. int pt; /* plane type (0 for Y, 1 for U or V) */
  215. memset(def_prob, 0x80, sizeof(def_prob));
  216. for (pt=0; pt<2; pt++)
  217. for (node=0; node<11; node++)
  218. if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {
  219. def_prob[node] = vp56_rac_gets_nn(c, 7);
  220. model->coeff_dccv[pt][node] = def_prob[node];
  221. } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
  222. model->coeff_dccv[pt][node] = def_prob[node];
  223. }
  224. if (vp56_rac_get(c)) {
  225. for (pos=1; pos<64; pos++)
  226. if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))
  227. model->coeff_reorder[pos] = vp56_rac_gets(c, 4);
  228. vp6_coeff_order_table_init(s);
  229. }
  230. for (cg=0; cg<2; cg++)
  231. for (node=0; node<14; node++)
  232. if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))
  233. model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7);
  234. for (ct=0; ct<3; ct++)
  235. for (pt=0; pt<2; pt++)
  236. for (cg=0; cg<6; cg++)
  237. for (node=0; node<11; node++)
  238. if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {
  239. def_prob[node] = vp56_rac_gets_nn(c, 7);
  240. model->coeff_ract[pt][ct][cg][node] = def_prob[node];
  241. } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
  242. model->coeff_ract[pt][ct][cg][node] = def_prob[node];
  243. }
  244. if (s->use_huffman) {
  245. for (pt=0; pt<2; pt++) {
  246. if (vp6_build_huff_tree(s, model->coeff_dccv[pt],
  247. vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]))
  248. return -1;
  249. if (vp6_build_huff_tree(s, model->coeff_runv[pt],
  250. vp6_huff_run_map, 9, &s->runv_vlc[pt]))
  251. return -1;
  252. for (ct=0; ct<3; ct++)
  253. for (cg = 0; cg < 6; cg++)
  254. if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
  255. vp6_huff_coeff_map, 12,
  256. &s->ract_vlc[pt][ct][cg]))
  257. return -1;
  258. }
  259. memset(s->nb_null, 0, sizeof(s->nb_null));
  260. } else {
  261. /* coeff_dcct is a linear combination of coeff_dccv */
  262. for (pt=0; pt<2; pt++)
  263. for (ctx=0; ctx<3; ctx++)
  264. for (node=0; node<5; node++)
  265. 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);
  266. }
  267. return 0;
  268. }
  269. static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
  270. {
  271. VP56RangeCoder *c = &s->c;
  272. VP56Model *model = s->modelp;
  273. int comp;
  274. *vect = (VP56mv) {0,0};
  275. if (s->vector_candidate_pos < 2)
  276. *vect = s->vector_candidate[0];
  277. for (comp=0; comp<2; comp++) {
  278. int i, delta = 0;
  279. if (vp56_rac_get_prob(c, model->vector_dct[comp])) {
  280. static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
  281. for (i=0; i<sizeof(prob_order); i++) {
  282. int j = prob_order[i];
  283. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][j])<<j;
  284. }
  285. if (delta & 0xF0)
  286. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3;
  287. else
  288. delta |= 8;
  289. } else {
  290. delta = vp56_rac_get_tree(c, vp56_pva_tree,
  291. model->vector_pdv[comp]);
  292. }
  293. if (delta && vp56_rac_get_prob(c, model->vector_sig[comp]))
  294. delta = -delta;
  295. if (!comp)
  296. vect->x += delta;
  297. else
  298. vect->y += delta;
  299. }
  300. }
  301. /**
  302. * Read number of consecutive blocks with null DC or AC.
  303. * This value is < 74.
  304. */
  305. static unsigned vp6_get_nb_null(VP56Context *s)
  306. {
  307. unsigned val = get_bits(&s->gb, 2);
  308. if (val == 2)
  309. val += get_bits(&s->gb, 2);
  310. else if (val == 3) {
  311. val = get_bits1(&s->gb) << 2;
  312. val = 6+val + get_bits(&s->gb, 2+val);
  313. }
  314. return val;
  315. }
  316. static void vp6_parse_coeff_huffman(VP56Context *s)
  317. {
  318. VP56Model *model = s->modelp;
  319. uint8_t *permute = s->scantable.permutated;
  320. VLC *vlc_coeff;
  321. int coeff, sign, coeff_idx;
  322. int b, cg, idx;
  323. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  324. for (b=0; b<6; b++) {
  325. int ct = 0; /* code type */
  326. if (b > 3) pt = 1;
  327. vlc_coeff = &s->dccv_vlc[pt];
  328. for (coeff_idx=0; coeff_idx<64; ) {
  329. int run = 1;
  330. if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) {
  331. s->nb_null[coeff_idx][pt]--;
  332. if (coeff_idx)
  333. break;
  334. } else {
  335. if (get_bits_count(&s->gb) >= s->gb.size_in_bits)
  336. return;
  337. coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3);
  338. if (coeff == 0) {
  339. if (coeff_idx) {
  340. int pt = (coeff_idx >= 6);
  341. run += get_vlc2(&s->gb, s->runv_vlc[pt].table, 9, 3);
  342. if (run >= 9)
  343. run += get_bits(&s->gb, 6);
  344. } else
  345. s->nb_null[0][pt] = vp6_get_nb_null(s);
  346. ct = 0;
  347. } else if (coeff == 11) { /* end of block */
  348. if (coeff_idx == 1) /* first AC coeff ? */
  349. s->nb_null[1][pt] = vp6_get_nb_null(s);
  350. break;
  351. } else {
  352. int coeff2 = vp56_coeff_bias[coeff];
  353. if (coeff > 4)
  354. coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11);
  355. ct = 1 + (coeff2 > 1);
  356. sign = get_bits1(&s->gb);
  357. coeff2 = (coeff2 ^ -sign) + sign;
  358. if (coeff_idx)
  359. coeff2 *= s->dequant_ac;
  360. idx = model->coeff_index_to_pos[coeff_idx];
  361. s->block_coeff[b][permute[idx]] = coeff2;
  362. }
  363. }
  364. coeff_idx+=run;
  365. cg = FFMIN(vp6_coeff_groups[coeff_idx], 3);
  366. vlc_coeff = &s->ract_vlc[pt][ct][cg];
  367. }
  368. }
  369. }
  370. static void vp6_parse_coeff(VP56Context *s)
  371. {
  372. VP56RangeCoder *c = s->ccp;
  373. VP56Model *model = s->modelp;
  374. uint8_t *permute = s->scantable.permutated;
  375. uint8_t *model1, *model2, *model3;
  376. int coeff, sign, coeff_idx;
  377. int b, i, cg, idx, ctx;
  378. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  379. for (b=0; b<6; b++) {
  380. int ct = 1; /* code type */
  381. int run = 1;
  382. if (b > 3) pt = 1;
  383. ctx = s->left_block[vp56_b6to4[b]].not_null_dc
  384. + s->above_blocks[s->above_block_idx[b]].not_null_dc;
  385. model1 = model->coeff_dccv[pt];
  386. model2 = model->coeff_dcct[pt][ctx];
  387. for (coeff_idx=0; coeff_idx<64; ) {
  388. if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
  389. /* parse a coeff */
  390. if (vp56_rac_get_prob(c, model2[2])) {
  391. if (vp56_rac_get_prob(c, model2[3])) {
  392. idx = vp56_rac_get_tree(c, vp56_pc_tree, model1);
  393. coeff = vp56_coeff_bias[idx+5];
  394. for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
  395. coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
  396. } else {
  397. if (vp56_rac_get_prob(c, model2[4]))
  398. coeff = 3 + vp56_rac_get_prob(c, model1[5]);
  399. else
  400. coeff = 2;
  401. }
  402. ct = 2;
  403. } else {
  404. ct = 1;
  405. coeff = 1;
  406. }
  407. sign = vp56_rac_get(c);
  408. coeff = (coeff ^ -sign) + sign;
  409. if (coeff_idx)
  410. coeff *= s->dequant_ac;
  411. idx = model->coeff_index_to_pos[coeff_idx];
  412. s->block_coeff[b][permute[idx]] = coeff;
  413. run = 1;
  414. } else {
  415. /* parse a run */
  416. ct = 0;
  417. if (coeff_idx > 0) {
  418. if (!vp56_rac_get_prob(c, model2[1]))
  419. break;
  420. model3 = model->coeff_runv[coeff_idx >= 6];
  421. run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
  422. if (!run)
  423. for (run=9, i=0; i<6; i++)
  424. run += vp56_rac_get_prob(c, model3[i+8]) << i;
  425. }
  426. }
  427. cg = vp6_coeff_groups[coeff_idx+=run];
  428. model1 = model2 = model->coeff_ract[pt][ct][cg];
  429. }
  430. s->left_block[vp56_b6to4[b]].not_null_dc =
  431. s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0];
  432. }
  433. }
  434. static int vp6_block_variance(uint8_t *src, int stride)
  435. {
  436. int sum = 0, square_sum = 0;
  437. int y, x;
  438. for (y=0; y<8; y+=2) {
  439. for (x=0; x<8; x+=2) {
  440. sum += src[x];
  441. square_sum += src[x]*src[x];
  442. }
  443. src += 2*stride;
  444. }
  445. return (16*square_sum - sum*sum) >> 8;
  446. }
  447. static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride,
  448. int delta, const int16_t *weights)
  449. {
  450. int x, y;
  451. for (y=0; y<8; y++) {
  452. for (x=0; x<8; x++) {
  453. dst[x] = av_clip_uint8(( src[x-delta ] * weights[0]
  454. + src[x ] * weights[1]
  455. + src[x+delta ] * weights[2]
  456. + src[x+2*delta] * weights[3] + 64) >> 7);
  457. }
  458. src += stride;
  459. dst += stride;
  460. }
  461. }
  462. static void vp6_filter_diag2(VP56Context *s, uint8_t *dst, uint8_t *src,
  463. int stride, int h_weight, int v_weight)
  464. {
  465. uint8_t *tmp = s->edge_emu_buffer+16;
  466. s->dsp.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0);
  467. s->dsp.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);
  468. }
  469. static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src,
  470. int offset1, int offset2, int stride,
  471. VP56mv mv, int mask, int select, int luma)
  472. {
  473. int filter4 = 0;
  474. int x8 = mv.x & mask;
  475. int y8 = mv.y & mask;
  476. if (luma) {
  477. x8 *= 2;
  478. y8 *= 2;
  479. filter4 = s->filter_mode;
  480. if (filter4 == 2) {
  481. if (s->max_vector_length &&
  482. (FFABS(mv.x) > s->max_vector_length ||
  483. FFABS(mv.y) > s->max_vector_length)) {
  484. filter4 = 0;
  485. } else if (s->sample_variance_threshold
  486. && (vp6_block_variance(src+offset1, stride)
  487. < s->sample_variance_threshold)) {
  488. filter4 = 0;
  489. }
  490. }
  491. }
  492. if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
  493. offset1 = offset2;
  494. }
  495. if (filter4) {
  496. if (!y8) { /* left or right combine */
  497. vp6_filter_hv4(dst, src+offset1, stride, 1,
  498. vp6_block_copy_filter[select][x8]);
  499. } else if (!x8) { /* above or below combine */
  500. vp6_filter_hv4(dst, src+offset1, stride, stride,
  501. vp6_block_copy_filter[select][y8]);
  502. } else {
  503. s->vp56dsp.vp6_filter_diag4(dst, src+offset1+((mv.x^mv.y)>>31), stride,
  504. vp6_block_copy_filter[select][x8],
  505. vp6_block_copy_filter[select][y8]);
  506. }
  507. } else {
  508. if (!x8 || !y8) {
  509. s->dsp.put_h264_chroma_pixels_tab[0](dst, src+offset1, stride, 8, x8, y8);
  510. } else {
  511. vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8);
  512. }
  513. }
  514. }
  515. static av_cold int vp6_decode_init(AVCodecContext *avctx)
  516. {
  517. VP56Context *s = avctx->priv_data;
  518. ff_vp56_init(avctx, avctx->codec->id == CODEC_ID_VP6,
  519. avctx->codec->id == CODEC_ID_VP6A);
  520. s->vp56_coord_div = vp6_coord_div;
  521. s->parse_vector_adjustment = vp6_parse_vector_adjustment;
  522. s->filter = vp6_filter;
  523. s->default_models_init = vp6_default_models_init;
  524. s->parse_vector_models = vp6_parse_vector_models;
  525. s->parse_coeff_models = vp6_parse_coeff_models;
  526. s->parse_header = vp6_parse_header;
  527. return 0;
  528. }
  529. static av_cold int vp6_decode_free(AVCodecContext *avctx)
  530. {
  531. VP56Context *s = avctx->priv_data;
  532. int pt, ct, cg;
  533. ff_vp56_free(avctx);
  534. for (pt=0; pt<2; pt++) {
  535. free_vlc(&s->dccv_vlc[pt]);
  536. free_vlc(&s->runv_vlc[pt]);
  537. for (ct=0; ct<3; ct++)
  538. for (cg=0; cg<6; cg++)
  539. free_vlc(&s->ract_vlc[pt][ct][cg]);
  540. }
  541. return 0;
  542. }
  543. AVCodec ff_vp6_decoder = {
  544. "vp6",
  545. AVMEDIA_TYPE_VIDEO,
  546. CODEC_ID_VP6,
  547. sizeof(VP56Context),
  548. vp6_decode_init,
  549. NULL,
  550. vp6_decode_free,
  551. ff_vp56_decode_frame,
  552. CODEC_CAP_DR1,
  553. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6"),
  554. };
  555. /* flash version, not flipped upside-down */
  556. AVCodec ff_vp6f_decoder = {
  557. "vp6f",
  558. AVMEDIA_TYPE_VIDEO,
  559. CODEC_ID_VP6F,
  560. sizeof(VP56Context),
  561. vp6_decode_init,
  562. NULL,
  563. vp6_decode_free,
  564. ff_vp56_decode_frame,
  565. CODEC_CAP_DR1,
  566. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"),
  567. };
  568. /* flash version, not flipped upside-down, with alpha channel */
  569. AVCodec ff_vp6a_decoder = {
  570. "vp6a",
  571. AVMEDIA_TYPE_VIDEO,
  572. CODEC_ID_VP6A,
  573. sizeof(VP56Context),
  574. vp6_decode_init,
  575. NULL,
  576. vp6_decode_free,
  577. ff_vp56_decode_frame,
  578. CODEC_CAP_DR1,
  579. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"),
  580. };