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.

666 lines
22KB

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