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.

648 lines
21KB

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