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.

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