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.

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