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.

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