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.

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