vp6.c
Go to the documentation of this file.
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 /**
22  * @file
23  * VP6 compatible video decoder
24  *
25  * The VP6F decoder accepts an optional 1 byte extradata. It is composed of:
26  * - upper 4 bits: difference between encoded width and visible width
27  * - lower 4 bits: difference between encoded height and visible height
28  */
29 
30 #include <stdlib.h>
31 
32 #include "avcodec.h"
33 #include "get_bits.h"
34 #include "huffman.h"
35 
36 #include "vp56.h"
37 #include "vp56data.h"
38 #include "vp6data.h"
39 
40 #define VP6_MAX_HUFF_SIZE 12
41 
42 static void vp6_parse_coeff(VP56Context *s);
44 
45 static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
46 {
47  VP56RangeCoder *c = &s->c;
48  int parse_filter_info = 0;
49  int coeff_offset = 0;
50  int vrt_shift = 0;
51  int sub_version;
52  int rows, cols;
53  int res = 0;
54  int separated_coeff = buf[0] & 1;
55 
56  s->frames[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80);
57  ff_vp56_init_dequant(s, (buf[0] >> 1) & 0x3F);
58 
60  sub_version = buf[1] >> 3;
61  if (sub_version > 8)
62  return AVERROR_INVALIDDATA;
63  s->filter_header = buf[1] & 0x06;
64  if (buf[1] & 1) {
65  avpriv_report_missing_feature(s->avctx, "Interlacing");
66  return AVERROR_PATCHWELCOME;
67  }
68  if (separated_coeff || !s->filter_header) {
69  coeff_offset = AV_RB16(buf+2) - 2;
70  buf += 2;
71  buf_size -= 2;
72  }
73 
74  rows = buf[2]; /* number of stored macroblock rows */
75  cols = buf[3]; /* number of stored macroblock cols */
76  /* buf[4] is number of displayed macroblock rows */
77  /* buf[5] is number of displayed macroblock cols */
78  if (!rows || !cols) {
79  av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n", cols << 4, rows << 4);
80  return AVERROR_INVALIDDATA;
81  }
82 
83  if (!s->macroblocks || /* first frame */
84  16*cols != s->avctx->coded_width ||
85  16*rows != s->avctx->coded_height) {
86  avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
87  if (s->avctx->extradata_size == 1) {
88  s->avctx->width -= s->avctx->extradata[0] >> 4;
89  s->avctx->height -= s->avctx->extradata[0] & 0x0F;
90  }
91  res = VP56_SIZE_CHANGE;
92  }
93 
94  ff_vp56_init_range_decoder(c, buf+6, buf_size-6);
95  vp56_rac_gets(c, 2);
96 
97  parse_filter_info = s->filter_header;
98  if (sub_version < 8)
99  vrt_shift = 5;
100  s->sub_version = sub_version;
101  s->golden_frame = 0;
102  } else {
103  if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height)
104  return AVERROR_INVALIDDATA;
105 
106  if (separated_coeff || !s->filter_header) {
107  coeff_offset = AV_RB16(buf+1) - 2;
108  buf += 2;
109  buf_size -= 2;
110  }
111  ff_vp56_init_range_decoder(c, buf+1, buf_size-1);
112 
113  s->golden_frame = vp56_rac_get(c);
114  if (s->filter_header) {
116  if (s->deblock_filtering)
117  vp56_rac_get(c);
118  if (s->sub_version > 7)
119  parse_filter_info = vp56_rac_get(c);
120  }
121  }
122 
123  if (parse_filter_info) {
124  if (vp56_rac_get(c)) {
125  s->filter_mode = 2;
126  s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift;
127  s->max_vector_length = 2 << vp56_rac_gets(c, 3);
128  } else if (vp56_rac_get(c)) {
129  s->filter_mode = 1;
130  } else {
131  s->filter_mode = 0;
132  }
133  if (s->sub_version > 7)
134  s->filter_selection = vp56_rac_gets(c, 4);
135  else
136  s->filter_selection = 16;
137  }
138 
139  s->use_huffman = vp56_rac_get(c);
140 
142  if (coeff_offset) {
143  buf += coeff_offset;
144  buf_size -= coeff_offset;
145  if (buf_size < 0) {
147  avcodec_set_dimensions(s->avctx, 0, 0);
148  return AVERROR_INVALIDDATA;
149  }
150  if (s->use_huffman) {
152  init_get_bits(&s->gb, buf, buf_size<<3);
153  } else {
154  ff_vp56_init_range_decoder(&s->cc, buf, buf_size);
155  s->ccp = &s->cc;
156  }
157  } else {
158  s->ccp = &s->c;
159  }
160 
161  return res;
162 }
163 
165 {
166  int i, pos, idx = 1;
167 
168  s->modelp->coeff_index_to_pos[0] = 0;
169  for (i=0; i<16; i++)
170  for (pos=1; pos<64; pos++)
171  if (s->modelp->coeff_reorder[pos] == i)
172  s->modelp->coeff_index_to_pos[idx++] = pos;
173 }
174 
176 {
177  VP56Model *model = s->modelp;
178 
179  model->vector_dct[0] = 0xA2;
180  model->vector_dct[1] = 0xA4;
181  model->vector_sig[0] = 0x80;
182  model->vector_sig[1] = 0x80;
183 
184  memcpy(model->mb_types_stats, ff_vp56_def_mb_types_stats, sizeof(model->mb_types_stats));
185  memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv));
186  memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv));
187  memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv));
188  memcpy(model->coeff_reorder, vp6_def_coeff_reorder, sizeof(model->coeff_reorder));
189 
191 }
192 
194 {
195  VP56RangeCoder *c = &s->c;
196  VP56Model *model = s->modelp;
197  int comp, node;
198 
199  for (comp=0; comp<2; comp++) {
200  if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0]))
201  model->vector_dct[comp] = vp56_rac_gets_nn(c, 7);
202  if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1]))
203  model->vector_sig[comp] = vp56_rac_gets_nn(c, 7);
204  }
205 
206  for (comp=0; comp<2; comp++)
207  for (node=0; node<7; node++)
208  if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node]))
209  model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
210 
211  for (comp=0; comp<2; comp++)
212  for (node=0; node<8; node++)
213  if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node]))
214  model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
215 }
216 
217 /* nodes must ascend by count, but with descending symbol order */
218 static int vp6_huff_cmp(const void *va, const void *vb)
219 {
220  const Node *a = va, *b = vb;
221  return (a->count - b->count)*16 + (b->sym - a->sym);
222 }
223 
224 static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
225  const uint8_t *map, unsigned size, VLC *vlc)
226 {
227  Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];
228  int a, b, i;
229 
230  /* first compute probabilities from model */
231  tmp[0].count = 256;
232  for (i=0; i<size-1; i++) {
233  a = tmp[i].count * coeff_model[i] >> 8;
234  b = tmp[i].count * (255 - coeff_model[i]) >> 8;
235  nodes[map[2*i ]].count = a + !a;
236  nodes[map[2*i+1]].count = b + !b;
237  }
238 
239  ff_free_vlc(vlc);
240  /* then build the huffman tree according to probabilities */
241  return ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
243 }
244 
246 {
247  VP56RangeCoder *c = &s->c;
248  VP56Model *model = s->modelp;
249  int def_prob[11];
250  int node, cg, ctx, pos;
251  int ct; /* code type */
252  int pt; /* plane type (0 for Y, 1 for U or V) */
253 
254  memset(def_prob, 0x80, sizeof(def_prob));
255 
256  for (pt=0; pt<2; pt++)
257  for (node=0; node<11; node++)
258  if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {
259  def_prob[node] = vp56_rac_gets_nn(c, 7);
260  model->coeff_dccv[pt][node] = def_prob[node];
261  } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
262  model->coeff_dccv[pt][node] = def_prob[node];
263  }
264 
265  if (vp56_rac_get(c)) {
266  for (pos=1; pos<64; pos++)
268  model->coeff_reorder[pos] = vp56_rac_gets(c, 4);
270  }
271 
272  for (cg=0; cg<2; cg++)
273  for (node=0; node<14; node++)
274  if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))
275  model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7);
276 
277  for (ct=0; ct<3; ct++)
278  for (pt=0; pt<2; pt++)
279  for (cg=0; cg<6; cg++)
280  for (node=0; node<11; node++)
281  if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {
282  def_prob[node] = vp56_rac_gets_nn(c, 7);
283  model->coeff_ract[pt][ct][cg][node] = def_prob[node];
284  } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
285  model->coeff_ract[pt][ct][cg][node] = def_prob[node];
286  }
287 
288  if (s->use_huffman) {
289  for (pt=0; pt<2; pt++) {
290  if (vp6_build_huff_tree(s, model->coeff_dccv[pt],
291  vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]))
292  return -1;
293  if (vp6_build_huff_tree(s, model->coeff_runv[pt],
294  vp6_huff_run_map, 9, &s->runv_vlc[pt]))
295  return -1;
296  for (ct=0; ct<3; ct++)
297  for (cg = 0; cg < 6; cg++)
298  if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
299  vp6_huff_coeff_map, 12,
300  &s->ract_vlc[pt][ct][cg]))
301  return -1;
302  }
303  memset(s->nb_null, 0, sizeof(s->nb_null));
304  } else {
305  /* coeff_dcct is a linear combination of coeff_dccv */
306  for (pt=0; pt<2; pt++)
307  for (ctx=0; ctx<3; ctx++)
308  for (node=0; node<5; node++)
309  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);
310  }
311  return 0;
312 }
313 
315 {
316  VP56RangeCoder *c = &s->c;
317  VP56Model *model = s->modelp;
318  int comp;
319 
320  *vect = (VP56mv) {0,0};
321  if (s->vector_candidate_pos < 2)
322  *vect = s->vector_candidate[0];
323 
324  for (comp=0; comp<2; comp++) {
325  int i, delta = 0;
326 
327  if (vp56_rac_get_prob(c, model->vector_dct[comp])) {
328  static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
329  for (i=0; i<sizeof(prob_order); i++) {
330  int j = prob_order[i];
331  delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][j])<<j;
332  }
333  if (delta & 0xF0)
334  delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3;
335  else
336  delta |= 8;
337  } else {
339  model->vector_pdv[comp]);
340  }
341 
342  if (delta && vp56_rac_get_prob(c, model->vector_sig[comp]))
343  delta = -delta;
344 
345  if (!comp)
346  vect->x += delta;
347  else
348  vect->y += delta;
349  }
350 }
351 
352 /**
353  * Read number of consecutive blocks with null DC or AC.
354  * This value is < 74.
355  */
356 static unsigned vp6_get_nb_null(VP56Context *s)
357 {
358  unsigned val = get_bits(&s->gb, 2);
359  if (val == 2)
360  val += get_bits(&s->gb, 2);
361  else if (val == 3) {
362  val = get_bits1(&s->gb) << 2;
363  val = 6+val + get_bits(&s->gb, 2+val);
364  }
365  return val;
366 }
367 
369 {
370  VP56Model *model = s->modelp;
372  VLC *vlc_coeff;
373  int coeff, sign, coeff_idx;
374  int b, cg, idx;
375  int pt = 0; /* plane type (0 for Y, 1 for U or V) */
376 
377  for (b=0; b<6; b++) {
378  int ct = 0; /* code type */
379  if (b > 3) pt = 1;
380  vlc_coeff = &s->dccv_vlc[pt];
381 
382  for (coeff_idx = 0;;) {
383  int run = 1;
384  if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) {
385  s->nb_null[coeff_idx][pt]--;
386  if (coeff_idx)
387  break;
388  } else {
389  if (get_bits_left(&s->gb) <= 0)
390  return;
391  coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3);
392  if (coeff == 0) {
393  if (coeff_idx) {
394  int pt = (coeff_idx >= 6);
395  run += get_vlc2(&s->gb, s->runv_vlc[pt].table, 9, 3);
396  if (run >= 9)
397  run += get_bits(&s->gb, 6);
398  } else
399  s->nb_null[0][pt] = vp6_get_nb_null(s);
400  ct = 0;
401  } else if (coeff == 11) { /* end of block */
402  if (coeff_idx == 1) /* first AC coeff ? */
403  s->nb_null[1][pt] = vp6_get_nb_null(s);
404  break;
405  } else {
406  int coeff2 = ff_vp56_coeff_bias[coeff];
407  if (coeff > 4)
408  coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11);
409  ct = 1 + (coeff2 > 1);
410  sign = get_bits1(&s->gb);
411  coeff2 = (coeff2 ^ -sign) + sign;
412  if (coeff_idx)
413  coeff2 *= s->dequant_ac;
414  idx = model->coeff_index_to_pos[coeff_idx];
415  s->block_coeff[b][permute[idx]] = coeff2;
416  }
417  }
418  coeff_idx+=run;
419  if (coeff_idx >= 64)
420  break;
421  cg = FFMIN(vp6_coeff_groups[coeff_idx], 3);
422  vlc_coeff = &s->ract_vlc[pt][ct][cg];
423  }
424  }
425 }
426 
428 {
429  VP56RangeCoder *c = s->ccp;
430  VP56Model *model = s->modelp;
432  uint8_t *model1, *model2, *model3;
433  int coeff, sign, coeff_idx;
434  int b, i, cg, idx, ctx;
435  int pt = 0; /* plane type (0 for Y, 1 for U or V) */
436 
437  for (b=0; b<6; b++) {
438  int ct = 1; /* code type */
439  int run = 1;
440 
441  if (b > 3) pt = 1;
442 
445  model1 = model->coeff_dccv[pt];
446  model2 = model->coeff_dcct[pt][ctx];
447 
448  coeff_idx = 0;
449  for (;;) {
450  if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
451  /* parse a coeff */
452  if (vp56_rac_get_prob(c, model2[2])) {
453  if (vp56_rac_get_prob(c, model2[3])) {
454  idx = vp56_rac_get_tree(c, ff_vp56_pc_tree, model1);
455  coeff = ff_vp56_coeff_bias[idx+5];
456  for (i=ff_vp56_coeff_bit_length[idx]; i>=0; i--)
457  coeff += vp56_rac_get_prob(c, ff_vp56_coeff_parse_table[idx][i]) << i;
458  } else {
459  if (vp56_rac_get_prob(c, model2[4]))
460  coeff = 3 + vp56_rac_get_prob(c, model1[5]);
461  else
462  coeff = 2;
463  }
464  ct = 2;
465  } else {
466  ct = 1;
467  coeff = 1;
468  }
469  sign = vp56_rac_get(c);
470  coeff = (coeff ^ -sign) + sign;
471  if (coeff_idx)
472  coeff *= s->dequant_ac;
473  idx = model->coeff_index_to_pos[coeff_idx];
474  s->block_coeff[b][permute[idx]] = coeff;
475  run = 1;
476  } else {
477  /* parse a run */
478  ct = 0;
479  if (coeff_idx > 0) {
480  if (!vp56_rac_get_prob(c, model2[1]))
481  break;
482 
483  model3 = model->coeff_runv[coeff_idx >= 6];
484  run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
485  if (!run)
486  for (run=9, i=0; i<6; i++)
487  run += vp56_rac_get_prob(c, model3[i+8]) << i;
488  }
489  }
490  coeff_idx += run;
491  if (coeff_idx >= 64)
492  break;
493  cg = vp6_coeff_groups[coeff_idx];
494  model1 = model2 = model->coeff_ract[pt][ct][cg];
495  }
496 
498  s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0];
499  }
500 }
501 
503 {
504  int sum = 0, square_sum = 0;
505  int y, x;
506 
507  for (y=0; y<8; y+=2) {
508  for (x=0; x<8; x+=2) {
509  sum += src[x];
510  square_sum += src[x]*src[x];
511  }
512  src += 2*stride;
513  }
514  return (16*square_sum - sum*sum) >> 8;
515 }
516 
518  int delta, const int16_t *weights)
519 {
520  int x, y;
521 
522  for (y=0; y<8; y++) {
523  for (x=0; x<8; x++) {
524  dst[x] = av_clip_uint8(( src[x-delta ] * weights[0]
525  + src[x ] * weights[1]
526  + src[x+delta ] * weights[2]
527  + src[x+2*delta] * weights[3] + 64) >> 7);
528  }
529  src += stride;
530  dst += stride;
531  }
532 }
533 
535  int stride, int h_weight, int v_weight)
536 {
537  uint8_t *tmp = s->edge_emu_buffer+16;
538  s->h264chroma.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0);
539  s->h264chroma.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);
540 }
541 
543  int offset1, int offset2, int stride,
544  VP56mv mv, int mask, int select, int luma)
545 {
546  int filter4 = 0;
547  int x8 = mv.x & mask;
548  int y8 = mv.y & mask;
549 
550  if (luma) {
551  x8 *= 2;
552  y8 *= 2;
553  filter4 = s->filter_mode;
554  if (filter4 == 2) {
555  if (s->max_vector_length &&
556  (FFABS(mv.x) > s->max_vector_length ||
557  FFABS(mv.y) > s->max_vector_length)) {
558  filter4 = 0;
559  } else if (s->sample_variance_threshold
560  && (vp6_block_variance(src+offset1, stride)
562  filter4 = 0;
563  }
564  }
565  }
566 
567  if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
568  offset1 = offset2;
569  }
570 
571  if (filter4) {
572  if (!y8) { /* left or right combine */
573  vp6_filter_hv4(dst, src+offset1, stride, 1,
574  vp6_block_copy_filter[select][x8]);
575  } else if (!x8) { /* above or below combine */
576  vp6_filter_hv4(dst, src+offset1, stride, stride,
577  vp6_block_copy_filter[select][y8]);
578  } else {
579  s->vp56dsp.vp6_filter_diag4(dst, src+offset1+((mv.x^mv.y)>>31), stride,
580  vp6_block_copy_filter[select][x8],
581  vp6_block_copy_filter[select][y8]);
582  }
583  } else {
584  if (!x8 || !y8) {
585  s->h264chroma.put_h264_chroma_pixels_tab[0](dst, src + offset1, stride, 8, x8, y8);
586  } else {
587  vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8);
588  }
589  }
590 }
591 
593 
595 {
596  VP56Context *s = avctx->priv_data;
597  int ret;
598 
599  if ((ret = ff_vp56_init(avctx, avctx->codec->id == AV_CODEC_ID_VP6,
600  avctx->codec->id == AV_CODEC_ID_VP6A)) < 0)
601  return ret;
602 
604 
605  if (s->has_alpha) {
606  s->alpha_context = av_mallocz(sizeof(VP56Context));
608  s->flip == -1, s->has_alpha);
610  }
611 
612  return 0;
613 }
614 
616 {
617  s->deblock_filtering = 0;
620  s->filter = vp6_filter;
625 }
626 
628 
630 {
631  VP56Context *s = avctx->priv_data;
632 
633  ff_vp56_free(avctx);
635 
636  if (s->alpha_context) {
640  }
641 
642  return 0;
643 }
644 
646 {
647  int pt, ct, cg;
648 
649  for (pt=0; pt<2; pt++) {
650  ff_free_vlc(&s->dccv_vlc[pt]);
651  ff_free_vlc(&s->runv_vlc[pt]);
652  for (ct=0; ct<3; ct++)
653  for (cg=0; cg<6; cg++)
654  ff_free_vlc(&s->ract_vlc[pt][ct][cg]);
655  }
656 }
657 
659  .name = "vp6",
660  .type = AVMEDIA_TYPE_VIDEO,
661  .id = AV_CODEC_ID_VP6,
662  .priv_data_size = sizeof(VP56Context),
666  .capabilities = CODEC_CAP_DR1,
667  .long_name = NULL_IF_CONFIG_SMALL("On2 VP6"),
668 };
669 
670 /* flash version, not flipped upside-down */
672  .name = "vp6f",
673  .type = AVMEDIA_TYPE_VIDEO,
674  .id = AV_CODEC_ID_VP6F,
675  .priv_data_size = sizeof(VP56Context),
679  .capabilities = CODEC_CAP_DR1,
680  .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"),
681 };
682 
683 /* flash version, not flipped upside-down, with alpha channel */
685  .name = "vp6a",
686  .type = AVMEDIA_TYPE_VIDEO,
687  .id = AV_CODEC_ID_VP6A,
688  .priv_data_size = sizeof(VP56Context),
692  .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS,
693  .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"),
694 };
av_cold int ff_vp56_free(AVCodecContext *avctx)
Definition: vp56.c:737
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
const struct AVCodec * codec
static void vp6_coeff_order_table_init(VP56Context *s)
Definition: vp6.c:164
uint8_t coeff_ract[2][3][6][11]
Definition: vp56.h:89
static const uint8_t vp6_ract_pct[3][2][6][11]
Definition: vp6data.h:93
const char * s
Definition: avisynth_c.h:668
static av_cold int vp6_decode_init(AVCodecContext *avctx)
Definition: vp6.c:594
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define FF_HUFFMAN_FLAG_HNODE_FIRST
Definition: huffman.h:38
static const uint8_t vp6_runv_pct[2][14]
Definition: vp6data.h:88
static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], const uint8_t *map, unsigned size, VLC *vlc)
Definition: vp6.c:224
uint8_t coeff_index_to_pos[64]
Definition: vp56.h:82
VP5 and VP6 compatible video decoder (common features)
int coded_width
Bitstream width / height, may be different from width/height e.g.
static const int16_t vp6_block_copy_filter[17][8][4]
Definition: vp6data.h:149
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
static const uint8_t vp6_def_fdv_vector_model[2][8]
Definition: vp6data.h:31
const uint8_t ff_vp56_coeff_bias[]
Definition: vp56data.c:67
uint8_t coeff_dccv[2][11]
Definition: vp56.h:88
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
uint8_t mb_types_stats[3][10][2]
Definition: vp56.h:94
uint8_t vector_sig[2]
Definition: vp56.h:83
VP56ParseCoeffModels parse_coeff_models
Definition: vp56.h:166
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
VP56mv vector_candidate[2]
Definition: vp56.h:138
uint8_t vector_fdv[2][8]
Definition: vp56.h:87
int filter_header
Definition: vp56.h:142
#define VP56_SIZE_CHANGE
Definition: vp56.h:46
uint8_t run
Definition: svq3.c:136
static const uint8_t vp6_huff_coeff_map[]
Definition: vp6data.h:302
void(* vp6_filter_diag4)(uint8_t *dst, uint8_t *src, int stride, const int16_t *h_weights, const int16_t *v_weights)
Definition: vp56dsp.h:31
int stride
Definition: mace.c:144
av_cold int ff_vp56_init(AVCodecContext *avctx, int flip, int has_alpha)
Definition: vp56.c:678
int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes, Node *nodes, HuffCmp cmp, int flags)
nodes size must be 2*nb_codes first nb_codes nodes.count must be set
Definition: huffman.c:133
static av_cold void vp6_decode_free_context(VP56Context *s)
Definition: vp6.c:645
VP56RangeCoder c
Definition: vp56.h:108
struct vp56_context VP56Context
Definition: vp56.h:39
static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src, int offset1, int offset2, int stride, VP56mv mv, int mask, int select, int luma)
Definition: vp6.c:542
Definition: huffman.h:32
static const uint8_t vp6_def_runv_coeff_model[2][14]
Definition: vp6data.h:52
int16_t y
Definition: vp56.h:43
VP56Context * alpha_context
Definition: vp56.h:170
uint8_t
#define av_cold
Definition: attributes.h:78
float delta
#define b
Definition: input.c:42
static const uint8_t vp6_def_coeff_reorder[]
Definition: vp6data.h:41
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static int vp6_parse_coeff_models(VP56Context *s)
Definition: vp6.c:245
av_cold int ff_vp56_init_context(AVCodecContext *avctx, VP56Context *s, int flip, int has_alpha)
Definition: vp56.c:684
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define VP6_MAX_HUFF_SIZE
Definition: vp6.c:40
int pt
Definition: rtp.c:34
VP56ParseCoeff parse_coeff
Definition: vp56.h:163
bitstream reader API header.
static const uint8_t vp6_dccv_pct[2][11]
Definition: vp6data.h:72
static av_always_inline int vp56_rac_get_tree(VP56RangeCoder *c, const VP56Tree *tree, const uint8_t *probs)
Definition: vp56.h:337
int filter_mode
Definition: vp56.h:145
uint8_t coeff_reorder[64]
Definition: vp56.h:81
VP56ParseVectorAdjustment parse_vector_adjustment
Definition: vp56.h:161
Discrete Time axis x
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:557
enum AVCodecID id
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
static const uint16_t mask[17]
Definition: lzw.c:37
#define AV_RB16
AVCodecContext * avctx
Definition: vp56.h:98
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
Definition: vp56.h:261
VLC ract_vlc[2][3][6]
Definition: vp56.h:180
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
VP56RefDc * above_blocks
Definition: vp56.h:126
const char * name
Name of the codec implementation.
void ff_vp56_init_dequant(VP56Context *s, int quantizer)
Definition: vp56.c:34
AVCodec ff_vp6_decoder
Definition: vp6.c:658
VP56Macroblock * macroblocks
Definition: vp56.h:133
const uint8_t ff_vp56_b6to4[]
Definition: vp56data.c:29
VP56RangeCoder cc
Definition: vp56.h:109
VP56ParseVectorModels parse_vector_models
Definition: vp56.h:165
external API header
VLC dccv_vlc[2]
Definition: vp56.h:178
int size
Definition: get_bits.h:63
int deblock_filtering
Definition: vp56.h:143
static int vp6_huff_cmp(const void *va, const void *vb)
Definition: vp6.c:218
int above_block_idx[6]
Definition: vp56.h:128
const uint8_t * vp56_coord_div
Definition: vp56.h:160
static void vp6_parse_vector_models(VP56Context *s)
Definition: vp6.c:193
VP5 and VP6 compatible video decoder (common data)
static av_unused int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
Definition: vp56.h:324
static void vp6_filter_diag2(VP56Context *s, uint8_t *dst, uint8_t *src, int stride, int h_weight, int v_weight)
Definition: vp6.c:534
static av_cold void vp6_decode_init_context(VP56Context *s)
Definition: vp6.c:615
H264ChromaContext h264chroma
Definition: vp56.h:99
AVCodec ff_vp6f_decoder
Definition: vp6.c:671
int vector_candidate_pos
Definition: vp56.h:139
#define FFMIN(a, b)
Definition: common.h:58
VP6 compatible video decoder.
static void vp6_default_models_init(VP56Context *s)
Definition: vp6.c:175
static const uint8_t vp6_huff_run_map[]
Definition: vp6data.h:306
ret
Definition: avfilter.c:821
int width
picture width / height.
static void vp6_parse_coeff_huffman(VP56Context *s)
Definition: vp6.c:368
struct VP56mv VP56mv
uint8_t idct_scantable[64]
Definition: vp56.h:104
int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: vp56.c:496
const uint8_t ff_vp56_coeff_bit_length[]
Definition: vp56data.c:68
#define FFABS(a)
Definition: common.h:53
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:524
int sample_variance_threshold
Definition: vp56.h:147
VP56DefaultModelsInit default_models_init
Definition: vp56.h:164
GetBitContext gb
Definition: vp56.h:177
#define vp56_rac_get_prob
Definition: vp56.h:226
static const VP56Tree vp6_pcr_tree[]
Definition: vp6data.h:288
static void permute(int16_t dst[64], const int16_t src[64], int perm)
Definition: dct-test.c:223
int golden_frame
Definition: vp56.h:114
static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride, int delta, const int16_t *weights)
Definition: vp6.c:517
uint8_t coeff_runv[2][14]
Definition: vp56.h:92
VP56Model * modelp
Definition: vp56.h:172
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static const int8_t mv[256][2]
int has_alpha
Definition: vp56.h:152
int sub_version
Definition: vp56.h:111
AVS_Value src
Definition: avisynth_c.h:523
static const uint8_t vp6_coeff_reorder_pct[]
Definition: vp6data.h:77
AVFrame * frames[4]
Definition: vp56.h:105
const VP56Tree ff_vp56_pc_tree[]
Definition: vp56data.c:59
main external API structure.
VP56RangeCoder * ccp
Definition: vp56.h:110
static void vp6_parse_coeff(VP56Context *s)
Definition: vp6.c:427
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
static const uint8_t vp6_fdv_pct[2][8]
Definition: vp6data.h:67
static const uint8_t vp6_coord_div[]
Definition: vp6data.h:300
uint8_t not_null_dc
Definition: vp56.h:70
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static unsigned vp6_get_nb_null(VP56Context *s)
Read number of consecutive blocks with null DC or AC.
Definition: vp6.c:356
static const uint8_t vp6_sig_dct_pct[2][2]
Definition: vp6data.h:57
void * buf
Definition: avisynth_c.h:594
const uint8_t ff_vp56_coeff_parse_table[6][11]
Definition: vp56data.c:31
uint8_t coeff_dcct[2][36][5]
Definition: vp56.h:91
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:273
static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
Definition: vp6.c:45
synthesis window for stochastic i
static av_cold int vp6_decode_free(AVCodecContext *avctx)
Definition: vp6.c:629
int filter_selection
Definition: vp56.h:144
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:379
int max_vector_length
Definition: vp56.h:146
huffman tree builder and VLC generator
static const double coeff[2][5]
Definition: vf_ow.c:64
VP56DSPContext vp56dsp
Definition: vp56.h:103
VP56ParseHeader parse_header
Definition: vp56.h:167
int16_t sym
Definition: huffman.h:33
int flip
Definition: vp56.h:155
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
Definition: vp56rac.c:40
int use_huffman
Definition: vp56.h:176
Definition: vp56.h:41
VP56RefDc left_block[4]
Definition: vp56.h:127
av_cold int ff_vp56_free_context(VP56Context *s)
Definition: vp56.c:743
static const int vp6_dccv_lc[3][5][2]
Definition: vp6data.h:132
const VP56Tree ff_vp56_pva_tree[]
Definition: vp56data.c:49
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
uint16_t dequant_ac
Definition: vp56.h:123
static double c[64]
uint8_t * edge_emu_buffer
Definition: vp56.h:107
static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
Definition: vp6.c:314
function y
Definition: D.m:1
VP56Filter filter
Definition: vp56.h:162
static const uint8_t vp6_coeff_groups[]
Definition: vp6data.h:138
static av_unused int vp56_rac_gets(VP56RangeCoder *c, int bits)
Definition: vp56.h:285
h264_chroma_mc_func put_h264_chroma_pixels_tab[3]
Definition: h264chroma.h:27
static const uint8_t vp6_def_pdv_vector_model[2][7]
Definition: vp6data.h:36
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:65
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
uint8_t vector_pdv[2][7]
Definition: vp56.h:86
uint32_t count
Definition: huffman.h:35
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:71
unsigned int nb_null[2][2]
Definition: vp56.h:181
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
Definition: vp56.h:80
const uint8_t ff_vp56_def_mb_types_stats[3][10][2]
Definition: vp56data.c:40
VLC runv_vlc[2]
Definition: vp56.h:179
AVCodec ff_vp6a_decoder
Definition: vp6.c:684
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:344
static const uint8_t vp6_pdv_pct[2][7]
Definition: vp6data.h:62
uint8_t vector_dct[2]
Definition: vp56.h:84
static int vp6_block_variance(uint8_t *src, int stride)
Definition: vp6.c:502