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.

652 lines
22KB

  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 int 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. if (vp6_build_huff_tree(s, model->coeff_dccv[pt],
  245. vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]))
  246. return -1;
  247. if (vp6_build_huff_tree(s, model->coeff_runv[pt],
  248. vp6_huff_run_map, 9, &s->runv_vlc[pt]))
  249. return -1;
  250. for (ct=0; ct<3; ct++)
  251. for (cg = 0; cg < 6; cg++)
  252. if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
  253. vp6_huff_coeff_map, 12,
  254. &s->ract_vlc[pt][ct][cg]))
  255. return -1;
  256. }
  257. memset(s->nb_null, 0, sizeof(s->nb_null));
  258. } else {
  259. /* coeff_dcct is a linear combination of coeff_dccv */
  260. for (pt=0; pt<2; pt++)
  261. for (ctx=0; ctx<3; ctx++)
  262. for (node=0; node<5; node++)
  263. 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);
  264. }
  265. return 0;
  266. }
  267. static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
  268. {
  269. VP56RangeCoder *c = &s->c;
  270. VP56Model *model = s->modelp;
  271. int comp;
  272. *vect = (VP56mv) {0,0};
  273. if (s->vector_candidate_pos < 2)
  274. *vect = s->vector_candidate[0];
  275. for (comp=0; comp<2; comp++) {
  276. int i, delta = 0;
  277. if (vp56_rac_get_prob(c, model->vector_dct[comp])) {
  278. static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
  279. for (i=0; i<sizeof(prob_order); i++) {
  280. int j = prob_order[i];
  281. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][j])<<j;
  282. }
  283. if (delta & 0xF0)
  284. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3;
  285. else
  286. delta |= 8;
  287. } else {
  288. delta = vp56_rac_get_tree(c, vp56_pva_tree,
  289. model->vector_pdv[comp]);
  290. }
  291. if (delta && vp56_rac_get_prob(c, model->vector_sig[comp]))
  292. delta = -delta;
  293. if (!comp)
  294. vect->x += delta;
  295. else
  296. vect->y += delta;
  297. }
  298. }
  299. /**
  300. * Read number of consecutive blocks with null DC or AC.
  301. * This value is < 74.
  302. */
  303. static unsigned vp6_get_nb_null(VP56Context *s)
  304. {
  305. unsigned val = get_bits(&s->gb, 2);
  306. if (val == 2)
  307. val += get_bits(&s->gb, 2);
  308. else if (val == 3) {
  309. val = get_bits1(&s->gb) << 2;
  310. val = 6+val + get_bits(&s->gb, 2+val);
  311. }
  312. return val;
  313. }
  314. static void vp6_parse_coeff_huffman(VP56Context *s)
  315. {
  316. VP56Model *model = s->modelp;
  317. uint8_t *permute = s->scantable.permutated;
  318. VLC *vlc_coeff;
  319. int coeff, sign, coeff_idx;
  320. int b, cg, idx;
  321. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  322. for (b=0; b<6; b++) {
  323. int ct = 0; /* code type */
  324. if (b > 3) pt = 1;
  325. vlc_coeff = &s->dccv_vlc[pt];
  326. for (coeff_idx=0; coeff_idx<64; ) {
  327. int run = 1;
  328. if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) {
  329. s->nb_null[coeff_idx][pt]--;
  330. if (coeff_idx)
  331. break;
  332. } else {
  333. if (get_bits_count(&s->gb) >= s->gb.size_in_bits)
  334. return;
  335. coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3);
  336. if (coeff == 0) {
  337. if (coeff_idx) {
  338. int pt = (coeff_idx >= 6);
  339. run += get_vlc2(&s->gb, s->runv_vlc[pt].table, 9, 3);
  340. if (run >= 9)
  341. run += get_bits(&s->gb, 6);
  342. } else
  343. s->nb_null[0][pt] = vp6_get_nb_null(s);
  344. ct = 0;
  345. } else if (coeff == 11) { /* end of block */
  346. if (coeff_idx == 1) /* first AC coeff ? */
  347. s->nb_null[1][pt] = vp6_get_nb_null(s);
  348. break;
  349. } else {
  350. int coeff2 = vp56_coeff_bias[coeff];
  351. if (coeff > 4)
  352. coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11);
  353. ct = 1 + (coeff2 > 1);
  354. sign = get_bits1(&s->gb);
  355. coeff2 = (coeff2 ^ -sign) + sign;
  356. if (coeff_idx)
  357. coeff2 *= s->dequant_ac;
  358. idx = model->coeff_index_to_pos[coeff_idx];
  359. s->block_coeff[b][permute[idx]] = coeff2;
  360. }
  361. }
  362. coeff_idx+=run;
  363. cg = FFMIN(vp6_coeff_groups[coeff_idx], 3);
  364. vlc_coeff = &s->ract_vlc[pt][ct][cg];
  365. }
  366. }
  367. }
  368. static void vp6_parse_coeff(VP56Context *s)
  369. {
  370. VP56RangeCoder *c = s->ccp;
  371. VP56Model *model = s->modelp;
  372. uint8_t *permute = s->scantable.permutated;
  373. uint8_t *model1, *model2, *model3;
  374. int coeff, sign, coeff_idx;
  375. int b, i, cg, idx, ctx;
  376. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  377. for (b=0; b<6; b++) {
  378. int ct = 1; /* code type */
  379. int run = 1;
  380. if (b > 3) pt = 1;
  381. ctx = s->left_block[vp56_b6to4[b]].not_null_dc
  382. + s->above_blocks[s->above_block_idx[b]].not_null_dc;
  383. model1 = model->coeff_dccv[pt];
  384. model2 = model->coeff_dcct[pt][ctx];
  385. for (coeff_idx=0; coeff_idx<64; ) {
  386. if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
  387. /* parse a coeff */
  388. if (vp56_rac_get_prob(c, model2[2])) {
  389. if (vp56_rac_get_prob(c, model2[3])) {
  390. idx = vp56_rac_get_tree(c, vp56_pc_tree, model1);
  391. coeff = vp56_coeff_bias[idx+5];
  392. for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
  393. coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
  394. } else {
  395. if (vp56_rac_get_prob(c, model2[4]))
  396. coeff = 3 + vp56_rac_get_prob(c, model1[5]);
  397. else
  398. coeff = 2;
  399. }
  400. ct = 2;
  401. } else {
  402. ct = 1;
  403. coeff = 1;
  404. }
  405. sign = vp56_rac_get(c);
  406. coeff = (coeff ^ -sign) + sign;
  407. if (coeff_idx)
  408. coeff *= s->dequant_ac;
  409. idx = model->coeff_index_to_pos[coeff_idx];
  410. s->block_coeff[b][permute[idx]] = coeff;
  411. run = 1;
  412. } else {
  413. /* parse a run */
  414. ct = 0;
  415. if (coeff_idx > 0) {
  416. if (!vp56_rac_get_prob(c, model2[1]))
  417. break;
  418. model3 = model->coeff_runv[coeff_idx >= 6];
  419. run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
  420. if (!run)
  421. for (run=9, i=0; i<6; i++)
  422. run += vp56_rac_get_prob(c, model3[i+8]) << i;
  423. }
  424. }
  425. cg = vp6_coeff_groups[coeff_idx+=run];
  426. model1 = model2 = model->coeff_ract[pt][ct][cg];
  427. }
  428. s->left_block[vp56_b6to4[b]].not_null_dc =
  429. s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0];
  430. }
  431. }
  432. static int vp6_block_variance(uint8_t *src, int stride)
  433. {
  434. int sum = 0, square_sum = 0;
  435. int y, x;
  436. for (y=0; y<8; y+=2) {
  437. for (x=0; x<8; x+=2) {
  438. sum += src[x];
  439. square_sum += src[x]*src[x];
  440. }
  441. src += 2*stride;
  442. }
  443. return (16*square_sum - sum*sum) >> 8;
  444. }
  445. static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride,
  446. int delta, const int16_t *weights)
  447. {
  448. int x, y;
  449. for (y=0; y<8; y++) {
  450. for (x=0; x<8; x++) {
  451. dst[x] = av_clip_uint8(( src[x-delta ] * weights[0]
  452. + src[x ] * weights[1]
  453. + src[x+delta ] * weights[2]
  454. + src[x+2*delta] * weights[3] + 64) >> 7);
  455. }
  456. src += stride;
  457. dst += stride;
  458. }
  459. }
  460. static void vp6_filter_diag2(VP56Context *s, uint8_t *dst, uint8_t *src,
  461. int stride, int h_weight, int v_weight)
  462. {
  463. uint8_t *tmp = s->edge_emu_buffer+16;
  464. s->dsp.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0);
  465. s->dsp.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);
  466. }
  467. static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src,
  468. int offset1, int offset2, int stride,
  469. VP56mv mv, int mask, int select, int luma)
  470. {
  471. int filter4 = 0;
  472. int x8 = mv.x & mask;
  473. int y8 = mv.y & mask;
  474. if (luma) {
  475. x8 *= 2;
  476. y8 *= 2;
  477. filter4 = s->filter_mode;
  478. if (filter4 == 2) {
  479. if (s->max_vector_length &&
  480. (FFABS(mv.x) > s->max_vector_length ||
  481. FFABS(mv.y) > s->max_vector_length)) {
  482. filter4 = 0;
  483. } else if (s->sample_variance_threshold
  484. && (vp6_block_variance(src+offset1, stride)
  485. < s->sample_variance_threshold)) {
  486. filter4 = 0;
  487. }
  488. }
  489. }
  490. if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
  491. offset1 = offset2;
  492. }
  493. if (filter4) {
  494. if (!y8) { /* left or right combine */
  495. vp6_filter_hv4(dst, src+offset1, stride, 1,
  496. vp6_block_copy_filter[select][x8]);
  497. } else if (!x8) { /* above or below combine */
  498. vp6_filter_hv4(dst, src+offset1, stride, stride,
  499. vp6_block_copy_filter[select][y8]);
  500. } else {
  501. s->vp56dsp.vp6_filter_diag4(dst, src+offset1+((mv.x^mv.y)>>31), stride,
  502. vp6_block_copy_filter[select][x8],
  503. vp6_block_copy_filter[select][y8]);
  504. }
  505. } else {
  506. if (!x8 || !y8) {
  507. s->dsp.put_h264_chroma_pixels_tab[0](dst, src+offset1, stride, 8, x8, y8);
  508. } else {
  509. vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8);
  510. }
  511. }
  512. }
  513. static av_cold int vp6_decode_init(AVCodecContext *avctx)
  514. {
  515. VP56Context *s = avctx->priv_data;
  516. ff_vp56_init(avctx, avctx->codec->id == CODEC_ID_VP6,
  517. avctx->codec->id == CODEC_ID_VP6A);
  518. s->vp56_coord_div = vp6_coord_div;
  519. s->parse_vector_adjustment = vp6_parse_vector_adjustment;
  520. s->filter = vp6_filter;
  521. s->default_models_init = vp6_default_models_init;
  522. s->parse_vector_models = vp6_parse_vector_models;
  523. s->parse_coeff_models = vp6_parse_coeff_models;
  524. s->parse_header = vp6_parse_header;
  525. return 0;
  526. }
  527. static av_cold int vp6_decode_free(AVCodecContext *avctx)
  528. {
  529. VP56Context *s = avctx->priv_data;
  530. int pt, ct, cg;
  531. ff_vp56_free(avctx);
  532. for (pt=0; pt<2; pt++) {
  533. free_vlc(&s->dccv_vlc[pt]);
  534. free_vlc(&s->runv_vlc[pt]);
  535. for (ct=0; ct<3; ct++)
  536. for (cg=0; cg<6; cg++)
  537. free_vlc(&s->ract_vlc[pt][ct][cg]);
  538. }
  539. return 0;
  540. }
  541. AVCodec ff_vp6_decoder = {
  542. .name = "vp6",
  543. .type = AVMEDIA_TYPE_VIDEO,
  544. .id = CODEC_ID_VP6,
  545. .priv_data_size = sizeof(VP56Context),
  546. .init = vp6_decode_init,
  547. .close = vp6_decode_free,
  548. .decode = ff_vp56_decode_frame,
  549. .capabilities = CODEC_CAP_DR1,
  550. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6"),
  551. };
  552. /* flash version, not flipped upside-down */
  553. AVCodec ff_vp6f_decoder = {
  554. .name = "vp6f",
  555. .type = AVMEDIA_TYPE_VIDEO,
  556. .id = CODEC_ID_VP6F,
  557. .priv_data_size = sizeof(VP56Context),
  558. .init = vp6_decode_init,
  559. .close = vp6_decode_free,
  560. .decode = ff_vp56_decode_frame,
  561. .capabilities = CODEC_CAP_DR1,
  562. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"),
  563. };
  564. /* flash version, not flipped upside-down, with alpha channel */
  565. AVCodec ff_vp6a_decoder = {
  566. .name = "vp6a",
  567. .type = AVMEDIA_TYPE_VIDEO,
  568. .id = CODEC_ID_VP6A,
  569. .priv_data_size = sizeof(VP56Context),
  570. .init = vp6_decode_init,
  571. .close = vp6_decode_free,
  572. .decode = ff_vp56_decode_frame,
  573. .capabilities = CODEC_CAP_DR1,
  574. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"),
  575. };