FFmpeg  2.6.3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ffv1dec.c
Go to the documentation of this file.
1 /*
2  * FFV1 decoder
3  *
4  * Copyright (c) 2003-2013 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * FF Video Codec 1 (a lossless codec) decoder
26  */
27 
28 #include "libavutil/avassert.h"
29 #include "libavutil/crc.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/pixdesc.h"
33 #include "libavutil/timer.h"
34 #include "avcodec.h"
35 #include "internal.h"
36 #include "get_bits.h"
37 #include "rangecoder.h"
38 #include "golomb.h"
39 #include "mathops.h"
40 #include "ffv1.h"
41 
43  int is_signed)
44 {
45  if (get_rac(c, state + 0))
46  return 0;
47  else {
48  int i, e, a;
49  e = 0;
50  while (get_rac(c, state + 1 + FFMIN(e, 9))) // 1..10
51  e++;
52 
53  a = 1;
54  for (i = e - 1; i >= 0; i--)
55  a += a + get_rac(c, state + 22 + FFMIN(i, 9)); // 22..31
56 
57  e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); // 11..21
58  return (a ^ e) - e;
59  }
60 }
61 
62 static av_noinline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
63 {
64  return get_symbol_inline(c, state, is_signed);
65 }
66 
67 static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state,
68  int bits)
69 {
70  int k, i, v, ret;
71 
72  i = state->count;
73  k = 0;
74  while (i < state->error_sum) { // FIXME: optimize
75  k++;
76  i += i;
77  }
78 
79  v = get_sr_golomb(gb, k, 12, bits);
80  av_dlog(NULL, "v:%d bias:%d error:%d drift:%d count:%d k:%d",
81  v, state->bias, state->error_sum, state->drift, state->count, k);
82 
83 #if 0 // JPEG LS
84  if (k == 0 && 2 * state->drift <= -state->count)
85  v ^= (-1);
86 #else
87  v ^= ((2 * state->drift + state->count) >> 31);
88 #endif
89 
90  ret = fold(v + state->bias, bits);
91 
92  update_vlc_state(state, v);
93 
94  return ret;
95 }
96 
98  int16_t *sample[2],
99  int plane_index, int bits)
100 {
101  PlaneContext *const p = &s->plane[plane_index];
102  RangeCoder *const c = &s->c;
103  int x;
104  int run_count = 0;
105  int run_mode = 0;
106  int run_index = s->run_index;
107 
108  if (s->slice_coding_mode == 1) {
109  int i;
110  for (x = 0; x < w; x++) {
111  int v = 0;
112  for (i=0; i<bits; i++) {
113  uint8_t state = 128;
114  v += v + get_rac(c, &state);
115  }
116  sample[1][x] = v;
117  }
118  return;
119  }
120 
121  for (x = 0; x < w; x++) {
122  int diff, context, sign;
123 
124  context = get_context(p, sample[1] + x, sample[0] + x, sample[1] + x);
125  if (context < 0) {
126  context = -context;
127  sign = 1;
128  } else
129  sign = 0;
130 
131  av_assert2(context < p->context_count);
132 
133  if (s->ac) {
134  diff = get_symbol_inline(c, p->state[context], 1);
135  } else {
136  if (context == 0 && run_mode == 0)
137  run_mode = 1;
138 
139  if (run_mode) {
140  if (run_count == 0 && run_mode == 1) {
141  if (get_bits1(&s->gb)) {
142  run_count = 1 << ff_log2_run[run_index];
143  if (x + run_count <= w)
144  run_index++;
145  } else {
146  if (ff_log2_run[run_index])
147  run_count = get_bits(&s->gb, ff_log2_run[run_index]);
148  else
149  run_count = 0;
150  if (run_index)
151  run_index--;
152  run_mode = 2;
153  }
154  }
155  run_count--;
156  if (run_count < 0) {
157  run_mode = 0;
158  run_count = 0;
159  diff = get_vlc_symbol(&s->gb, &p->vlc_state[context],
160  bits);
161  if (diff >= 0)
162  diff++;
163  } else
164  diff = 0;
165  } else
166  diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
167 
168  av_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
169  run_count, run_index, run_mode, x, get_bits_count(&s->gb));
170  }
171 
172  if (sign)
173  diff = -diff;
174 
175  sample[1][x] = (predict(sample[1] + x, sample[0] + x) + diff) &
176  ((1 << bits) - 1);
177  }
178  s->run_index = run_index;
179 }
180 
182  int w, int h, int stride, int plane_index)
183 {
184  int x, y;
185  int16_t *sample[2];
186  sample[0] = s->sample_buffer + 3;
187  sample[1] = s->sample_buffer + w + 6 + 3;
188 
189  s->run_index = 0;
190 
191  memset(s->sample_buffer, 0, 2 * (w + 6) * sizeof(*s->sample_buffer));
192 
193  for (y = 0; y < h; y++) {
194  int16_t *temp = sample[0]; // FIXME: try a normal buffer
195 
196  sample[0] = sample[1];
197  sample[1] = temp;
198 
199  sample[1][-1] = sample[0][0];
200  sample[0][w] = sample[0][w - 1];
201 
202 // { START_TIMER
203  if (s->avctx->bits_per_raw_sample <= 8) {
204  decode_line(s, w, sample, plane_index, 8);
205  for (x = 0; x < w; x++)
206  src[x + stride * y] = sample[1][x];
207  } else {
208  decode_line(s, w, sample, plane_index, s->avctx->bits_per_raw_sample);
209  if (s->packed_at_lsb) {
210  for (x = 0; x < w; x++) {
211  ((uint16_t*)(src + stride*y))[x] = sample[1][x];
212  }
213  } else {
214  for (x = 0; x < w; x++) {
215  ((uint16_t*)(src + stride*y))[x] = sample[1][x] << (16 - s->avctx->bits_per_raw_sample);
216  }
217  }
218  }
219 // STOP_TIMER("decode-line") }
220  }
221 }
222 
223 static void decode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, int stride[3])
224 {
225  int x, y, p;
226  int16_t *sample[4][2];
227  int lbd = s->avctx->bits_per_raw_sample <= 8;
228  int bits = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8;
229  int offset = 1 << bits;
230 
231  for (x = 0; x < 4; x++) {
232  sample[x][0] = s->sample_buffer + x * 2 * (w + 6) + 3;
233  sample[x][1] = s->sample_buffer + (x * 2 + 1) * (w + 6) + 3;
234  }
235 
236  s->run_index = 0;
237 
238  memset(s->sample_buffer, 0, 8 * (w + 6) * sizeof(*s->sample_buffer));
239 
240  for (y = 0; y < h; y++) {
241  for (p = 0; p < 3 + s->transparency; p++) {
242  int16_t *temp = sample[p][0]; // FIXME: try a normal buffer
243 
244  sample[p][0] = sample[p][1];
245  sample[p][1] = temp;
246 
247  sample[p][1][-1]= sample[p][0][0 ];
248  sample[p][0][ w]= sample[p][0][w-1];
249  if (lbd && s->slice_coding_mode == 0)
250  decode_line(s, w, sample[p], (p + 1)/2, 9);
251  else
252  decode_line(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
253  }
254  for (x = 0; x < w; x++) {
255  int g = sample[0][1][x];
256  int b = sample[1][1][x];
257  int r = sample[2][1][x];
258  int a = sample[3][1][x];
259 
260  if (s->slice_coding_mode != 1) {
261  b -= offset;
262  r -= offset;
263  g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2;
264  b += g;
265  r += g;
266  }
267 
268  if (lbd)
269  *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + (g<<8) + (r<<16) + (a<<24);
270  else {
271  *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b;
272  *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g;
273  *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
274  }
275  }
276  }
277 }
278 
280 {
281  RangeCoder *c = &fs->c;
283  unsigned ps, i, context_count;
284  memset(state, 128, sizeof(state));
285 
286  av_assert0(f->version > 2);
287 
288  fs->slice_x = get_symbol(c, state, 0) * f->width ;
289  fs->slice_y = get_symbol(c, state, 0) * f->height;
290  fs->slice_width = (get_symbol(c, state, 0) + 1) * f->width + fs->slice_x;
291  fs->slice_height = (get_symbol(c, state, 0) + 1) * f->height + fs->slice_y;
292 
293  fs->slice_x /= f->num_h_slices;
294  fs->slice_y /= f->num_v_slices;
295  fs->slice_width = fs->slice_width /f->num_h_slices - fs->slice_x;
296  fs->slice_height = fs->slice_height/f->num_v_slices - fs->slice_y;
297  if ((unsigned)fs->slice_width > f->width || (unsigned)fs->slice_height > f->height)
298  return -1;
299  if ( (unsigned)fs->slice_x + (uint64_t)fs->slice_width > f->width
300  || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height)
301  return -1;
302 
303  for (i = 0; i < f->plane_count; i++) {
304  PlaneContext * const p = &fs->plane[i];
305  int idx = get_symbol(c, state, 0);
306  if (idx > (unsigned)f->quant_table_count) {
307  av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n");
308  return -1;
309  }
310  p->quant_table_index = idx;
311  memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table));
312  context_count = f->context_count[idx];
313 
314  if (p->context_count < context_count) {
315  av_freep(&p->state);
316  av_freep(&p->vlc_state);
317  }
319  }
320 
321  ps = get_symbol(c, state, 0);
322  if (ps == 1) {
323  f->cur->interlaced_frame = 1;
324  f->cur->top_field_first = 1;
325  } else if (ps == 2) {
326  f->cur->interlaced_frame = 1;
327  f->cur->top_field_first = 0;
328  } else if (ps == 3) {
329  f->cur->interlaced_frame = 0;
330  }
331  f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0);
332  f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0);
333 
334  if (av_image_check_sar(f->width, f->height,
335  f->cur->sample_aspect_ratio) < 0) {
336  av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
339  f->cur->sample_aspect_ratio = (AVRational){ 0, 1 };
340  }
341 
342  if (fs->version > 3) {
343  fs->slice_reset_contexts = get_rac(c, state);
344  fs->slice_coding_mode = get_symbol(c, state, 0);
345  if (fs->slice_coding_mode != 1) {
346  fs->slice_rct_by_coef = get_symbol(c, state, 0);
347  fs->slice_rct_ry_coef = get_symbol(c, state, 0);
348  if ((uint64_t)fs->slice_rct_by_coef + (uint64_t)fs->slice_rct_ry_coef > 4) {
349  av_log(f->avctx, AV_LOG_ERROR, "slice_rct_y_coef out of range\n");
350  return AVERROR_INVALIDDATA;
351  }
352  }
353  }
354 
355  return 0;
356 }
357 
358 static int decode_slice(AVCodecContext *c, void *arg)
359 {
360  FFV1Context *fs = *(void **)arg;
361  FFV1Context *f = fs->avctx->priv_data;
362  int width, height, x, y, ret;
363  const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step_minus1 + 1;
364  AVFrame * const p = f->cur;
365  int i, si;
366 
367  for( si=0; fs != f->slice_context[si]; si ++)
368  ;
369 
370  if(f->fsrc && !p->key_frame)
372 
373  if(f->fsrc && !p->key_frame) {
374  FFV1Context *fssrc = f->fsrc->slice_context[si];
375  FFV1Context *fsdst = f->slice_context[si];
376  av_assert1(fsdst->plane_count == fssrc->plane_count);
377  av_assert1(fsdst == fs);
378 
379  if (!p->key_frame)
380  fsdst->slice_damaged |= fssrc->slice_damaged;
381 
382  for (i = 0; i < f->plane_count; i++) {
383  PlaneContext *psrc = &fssrc->plane[i];
384  PlaneContext *pdst = &fsdst->plane[i];
385 
386  av_free(pdst->state);
387  av_free(pdst->vlc_state);
388  memcpy(pdst, psrc, sizeof(*pdst));
389  pdst->state = NULL;
390  pdst->vlc_state = NULL;
391 
392  if (fssrc->ac) {
394  memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count);
395  } else {
396  pdst->vlc_state = av_malloc_array(sizeof(*pdst->vlc_state), psrc->context_count);
397  memcpy(pdst->vlc_state, psrc->vlc_state, sizeof(*pdst->vlc_state) * psrc->context_count);
398  }
399  }
400  }
401 
402  fs->slice_rct_by_coef = 1;
403  fs->slice_rct_ry_coef = 1;
404 
405  if (f->version > 2) {
406  if (ffv1_init_slice_state(f, fs) < 0)
407  return AVERROR(ENOMEM);
408  if (decode_slice_header(f, fs) < 0) {
409  fs->slice_damaged = 1;
410  return AVERROR_INVALIDDATA;
411  }
412  }
413  if ((ret = ffv1_init_slice_state(f, fs)) < 0)
414  return ret;
415  if (f->cur->key_frame || fs->slice_reset_contexts)
416  ffv1_clear_slice_state(f, fs);
417 
418  width = fs->slice_width;
419  height = fs->slice_height;
420  x = fs->slice_x;
421  y = fs->slice_y;
422 
423  if (!fs->ac) {
424  if (f->version == 3 && f->micro_version > 1 || f->version > 3)
425  get_rac(&fs->c, (uint8_t[]) { 129 });
426  fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0;
427  init_get_bits(&fs->gb,
428  fs->c.bytestream_start + fs->ac_byte_count,
429  (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8);
430  }
431 
432  av_assert1(width && height);
433  if (f->colorspace == 0) {
434  const int chroma_width = FF_CEIL_RSHIFT(width, f->chroma_h_shift);
435  const int chroma_height = FF_CEIL_RSHIFT(height, f->chroma_v_shift);
436  const int cx = x >> f->chroma_h_shift;
437  const int cy = y >> f->chroma_v_shift;
438  decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0);
439 
440  if (f->chroma_planes) {
441  decode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);
442  decode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1);
443  }
444  if (fs->transparency)
445  decode_plane(fs, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2);
446  } else {
447  uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0],
448  p->data[1] + ps * x + y * p->linesize[1],
449  p->data[2] + ps * x + y * p->linesize[2] };
450  decode_rgb_frame(fs, planes, width, height, p->linesize);
451  }
452  if (fs->ac && f->version > 2) {
453  int v;
454  get_rac(&fs->c, (uint8_t[]) { 129 });
455  v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec;
456  if (v) {
457  av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v);
458  fs->slice_damaged = 1;
459  }
460  }
461 
462  emms_c();
463 
465 
466  return 0;
467 }
468 
469 static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale)
470 {
471  int v;
472  int i = 0;
474 
475  memset(state, 128, sizeof(state));
476 
477  for (v = 0; i < 128; v++) {
478  unsigned len = get_symbol(c, state, 0) + 1;
479 
480  if (len > 128 - i)
481  return AVERROR_INVALIDDATA;
482 
483  while (len--) {
484  quant_table[i] = scale * v;
485  i++;
486  }
487  }
488 
489  for (i = 1; i < 128; i++)
490  quant_table[256 - i] = -quant_table[i];
491  quant_table[128] = -quant_table[127];
492 
493  return 2 * v - 1;
494 }
495 
497  int16_t quant_table[MAX_CONTEXT_INPUTS][256])
498 {
499  int i;
500  int context_count = 1;
501 
502  for (i = 0; i < 5; i++) {
503  context_count *= read_quant_table(c, quant_table[i], context_count);
504  if (context_count > 32768U) {
505  return AVERROR_INVALIDDATA;
506  }
507  }
508  return (context_count + 1) / 2;
509 }
510 
512 {
513  RangeCoder *const c = &f->c;
515  int i, j, k, ret;
516  uint8_t state2[32][CONTEXT_SIZE];
517 
518  memset(state2, 128, sizeof(state2));
519  memset(state, 128, sizeof(state));
520 
522  ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);
523 
524  f->version = get_symbol(c, state, 0);
525  if (f->version < 2) {
526  av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n");
527  return AVERROR_INVALIDDATA;
528  }
529  if (f->version > 2) {
530  c->bytestream_end -= 4;
531  f->micro_version = get_symbol(c, state, 0);
532  }
533  f->ac = f->avctx->coder_type = get_symbol(c, state, 0);
534  if (f->ac > 1) {
535  for (i = 1; i < 256; i++)
536  f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i];
537  }
538 
539  f->colorspace = get_symbol(c, state, 0); //YUV cs type
540  f->avctx->bits_per_raw_sample = get_symbol(c, state, 0);
541  f->chroma_planes = get_rac(c, state);
542  f->chroma_h_shift = get_symbol(c, state, 0);
543  f->chroma_v_shift = get_symbol(c, state, 0);
544  f->transparency = get_rac(c, state);
545  f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency;
546  f->num_h_slices = 1 + get_symbol(c, state, 0);
547  f->num_v_slices = 1 + get_symbol(c, state, 0);
548 
549  if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) {
550  av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n",
552  return AVERROR_INVALIDDATA;
553  }
554 
555  if (f->num_h_slices > (unsigned)f->width || !f->num_h_slices ||
556  f->num_v_slices > (unsigned)f->height || !f->num_v_slices
557  ) {
558  av_log(f->avctx, AV_LOG_ERROR, "slice count invalid\n");
559  return AVERROR_INVALIDDATA;
560  }
561 
562  f->quant_table_count = get_symbol(c, state, 0);
563  if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES)
564  return AVERROR_INVALIDDATA;
565 
566  for (i = 0; i < f->quant_table_count; i++) {
567  f->context_count[i] = read_quant_tables(c, f->quant_tables[i]);
568  if (f->context_count[i] < 0) {
569  av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
570  return AVERROR_INVALIDDATA;
571  }
572  }
573  if ((ret = ffv1_allocate_initial_states(f)) < 0)
574  return ret;
575 
576  for (i = 0; i < f->quant_table_count; i++)
577  if (get_rac(c, state)) {
578  for (j = 0; j < f->context_count[i]; j++)
579  for (k = 0; k < CONTEXT_SIZE; k++) {
580  int pred = j ? f->initial_states[i][j - 1][k] : 128;
581  f->initial_states[i][j][k] =
582  (pred + get_symbol(c, state2[k], 1)) & 0xFF;
583  }
584  }
585 
586  if (f->version > 2) {
587  f->ec = get_symbol(c, state, 0);
588  if (f->micro_version > 2)
589  f->intra = get_symbol(c, state, 0);
590  }
591 
592  if (f->version > 2) {
593  unsigned v;
596  if (v) {
597  av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v);
598  return AVERROR_INVALIDDATA;
599  }
600  }
601 
602  if (f->avctx->debug & FF_DEBUG_PICT_INFO)
604  "global: ver:%d.%d, coder:%d, colorspace: %d bpr:%d chroma:%d(%d:%d), alpha:%d slices:%dx%d qtabs:%d ec:%d intra:%d\n",
605  f->version, f->micro_version,
606  f->ac,
607  f->colorspace,
610  f->transparency,
611  f->num_h_slices, f->num_v_slices,
613  f->ec,
614  f->intra
615  );
616  return 0;
617 }
618 
619 static int read_header(FFV1Context *f)
620 {
622  int i, j, context_count = -1; //-1 to avoid warning
623  RangeCoder *const c = &f->slice_context[0]->c;
624 
625  memset(state, 128, sizeof(state));
626 
627  if (f->version < 2) {
629  unsigned v= get_symbol(c, state, 0);
630  if (v >= 2) {
631  av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v);
632  return AVERROR_INVALIDDATA;
633  }
634  f->version = v;
635  f->ac = f->avctx->coder_type = get_symbol(c, state, 0);
636  if (f->ac > 1) {
637  for (i = 1; i < 256; i++)
638  f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i];
639  }
640 
641  colorspace = get_symbol(c, state, 0); //YUV cs type
642  bits_per_raw_sample = f->version > 0 ? get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample;
643  chroma_planes = get_rac(c, state);
644  chroma_h_shift = get_symbol(c, state, 0);
645  chroma_v_shift = get_symbol(c, state, 0);
646  transparency = get_rac(c, state);
647 
648  if (f->plane_count) {
649  if (colorspace != f->colorspace ||
650  bits_per_raw_sample != f->avctx->bits_per_raw_sample ||
651  chroma_planes != f->chroma_planes ||
652  chroma_h_shift != f->chroma_h_shift ||
653  chroma_v_shift != f->chroma_v_shift ||
654  transparency != f->transparency) {
655  av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n");
656  return AVERROR_INVALIDDATA;
657  }
658  }
659 
660  if (chroma_h_shift > 4U || chroma_v_shift > 4U) {
661  av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n",
662  chroma_h_shift, chroma_v_shift);
663  return AVERROR_INVALIDDATA;
664  }
665 
666  f->colorspace = colorspace;
672 
673  f->plane_count = 2 + f->transparency;
674  }
675 
676  if (f->colorspace == 0) {
677  if (f->avctx->skip_alpha) f->transparency = 0;
678  if (!f->transparency && !f->chroma_planes) {
679  if (f->avctx->bits_per_raw_sample <= 8)
681  else
683  } else if (f->avctx->bits_per_raw_sample<=8 && !f->transparency) {
684  switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
685  case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P; break;
686  case 0x01: f->avctx->pix_fmt = AV_PIX_FMT_YUV440P; break;
687  case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P; break;
688  case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P; break;
689  case 0x20: f->avctx->pix_fmt = AV_PIX_FMT_YUV411P; break;
690  case 0x22: f->avctx->pix_fmt = AV_PIX_FMT_YUV410P; break;
691  }
692  } else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency) {
693  switch(16*f->chroma_h_shift + f->chroma_v_shift) {
694  case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P; break;
695  case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P; break;
696  case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P; break;
697  }
698  } else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency) {
699  f->packed_at_lsb = 1;
700  switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
701  case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P9; break;
702  case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P9; break;
703  case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P9; break;
704  }
705  } else if (f->avctx->bits_per_raw_sample == 9 && f->transparency) {
706  f->packed_at_lsb = 1;
707  switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
708  case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P9; break;
709  case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P9; break;
710  case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P9; break;
711  }
712  } else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency) {
713  f->packed_at_lsb = 1;
714  switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
715  case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P10; break;
716  case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P10; break;
717  case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P10; break;
718  }
719  } else if (f->avctx->bits_per_raw_sample == 10 && f->transparency) {
720  f->packed_at_lsb = 1;
721  switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
722  case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P10; break;
723  case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P10; break;
724  case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P10; break;
725  }
726  } else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency){
727  switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
728  case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P16; break;
729  case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P16; break;
730  case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P16; break;
731  }
732  } else if (f->avctx->bits_per_raw_sample == 16 && f->transparency){
733  switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
734  case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P16; break;
735  case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P16; break;
736  case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P16; break;
737  }
738  }
739  } else if (f->colorspace == 1) {
740  if (f->chroma_h_shift || f->chroma_v_shift) {
742  "chroma subsampling not supported in this colorspace\n");
743  return AVERROR(ENOSYS);
744  }
745  if ( f->avctx->bits_per_raw_sample == 9)
747  else if (f->avctx->bits_per_raw_sample == 10)
749  else if (f->avctx->bits_per_raw_sample == 12)
751  else if (f->avctx->bits_per_raw_sample == 14)
753  else
755  else f->avctx->pix_fmt = AV_PIX_FMT_0RGB32;
756  } else {
757  av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n");
758  return AVERROR(ENOSYS);
759  }
760  if (f->avctx->pix_fmt == AV_PIX_FMT_NONE) {
761  av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");
762  return AVERROR(ENOSYS);
763  }
764 
765  av_dlog(f->avctx, "%d %d %d\n",
767  if (f->version < 2) {
768  context_count = read_quant_tables(c, f->quant_table);
769  if (context_count < 0) {
770  av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
771  return AVERROR_INVALIDDATA;
772  }
773  } else if (f->version < 3) {
774  f->slice_count = get_symbol(c, state, 0);
775  } else {
776  const uint8_t *p = c->bytestream_end;
777  for (f->slice_count = 0;
778  f->slice_count < MAX_SLICES && 3 < p - c->bytestream_start;
779  f->slice_count++) {
780  int trailer = 3 + 5*!!f->ec;
781  int size = AV_RB24(p-trailer);
782  if (size + trailer > p - c->bytestream_start)
783  break;
784  p -= size + trailer;
785  }
786  }
787  if (f->slice_count > (unsigned)MAX_SLICES || f->slice_count <= 0) {
788  av_log(f->avctx, AV_LOG_ERROR, "slice count %d is invalid\n", f->slice_count);
789  return AVERROR_INVALIDDATA;
790  }
791 
792  for (j = 0; j < f->slice_count; j++) {
793  FFV1Context *fs = f->slice_context[j];
794  fs->ac = f->ac;
795  fs->packed_at_lsb = f->packed_at_lsb;
796 
797  fs->slice_damaged = 0;
798 
799  if (f->version == 2) {
800  fs->slice_x = get_symbol(c, state, 0) * f->width ;
801  fs->slice_y = get_symbol(c, state, 0) * f->height;
802  fs->slice_width = (get_symbol(c, state, 0) + 1) * f->width + fs->slice_x;
803  fs->slice_height = (get_symbol(c, state, 0) + 1) * f->height + fs->slice_y;
804 
805  fs->slice_x /= f->num_h_slices;
806  fs->slice_y /= f->num_v_slices;
807  fs->slice_width = fs->slice_width / f->num_h_slices - fs->slice_x;
808  fs->slice_height = fs->slice_height / f->num_v_slices - fs->slice_y;
809  if ((unsigned)fs->slice_width > f->width ||
810  (unsigned)fs->slice_height > f->height)
811  return AVERROR_INVALIDDATA;
812  if ( (unsigned)fs->slice_x + (uint64_t)fs->slice_width > f->width
813  || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height)
814  return AVERROR_INVALIDDATA;
815  }
816 
817  for (i = 0; i < f->plane_count; i++) {
818  PlaneContext *const p = &fs->plane[i];
819 
820  if (f->version == 2) {
821  int idx = get_symbol(c, state, 0);
822  if (idx > (unsigned)f->quant_table_count) {
824  "quant_table_index out of range\n");
825  return AVERROR_INVALIDDATA;
826  }
827  p->quant_table_index = idx;
828  memcpy(p->quant_table, f->quant_tables[idx],
829  sizeof(p->quant_table));
830  context_count = f->context_count[idx];
831  } else {
832  memcpy(p->quant_table, f->quant_table, sizeof(p->quant_table));
833  }
834 
835  if (f->version <= 2) {
836  av_assert0(context_count >= 0);
837  if (p->context_count < context_count) {
838  av_freep(&p->state);
839  av_freep(&p->vlc_state);
840  }
842  }
843  }
844  }
845  return 0;
846 }
847 
849 {
850  FFV1Context *f = avctx->priv_data;
851  int ret;
852 
853  if ((ret = ffv1_common_init(avctx)) < 0)
854  return ret;
855 
856  if (avctx->extradata && (ret = read_extra_header(f)) < 0)
857  return ret;
858 
859  if ((ret = ffv1_init_slice_contexts(f)) < 0)
860  return ret;
861 
862  avctx->internal->allocate_progress = 1;
863 
864  return 0;
865 }
866 
867 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
868 {
869  uint8_t *buf = avpkt->data;
870  int buf_size = avpkt->size;
871  FFV1Context *f = avctx->priv_data;
872  RangeCoder *const c = &f->slice_context[0]->c;
873  int i, ret;
874  uint8_t keystate = 128;
875  uint8_t *buf_p;
876  AVFrame *p;
877 
878  if (f->last_picture.f)
881 
882  f->cur = p = f->picture.f;
883 
884  if (f->version < 3 && avctx->field_order > AV_FIELD_PROGRESSIVE) {
885  /* we have interlaced material flagged in container */
886  p->interlaced_frame = 1;
887  if (avctx->field_order == AV_FIELD_TT || avctx->field_order == AV_FIELD_TB)
888  p->top_field_first = 1;
889  }
890 
891  f->avctx = avctx;
892  ff_init_range_decoder(c, buf, buf_size);
893  ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);
894 
895  p->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P
896  if (get_rac(c, &keystate)) {
897  p->key_frame = 1;
898  f->key_frame_ok = 0;
899  if ((ret = read_header(f)) < 0)
900  return ret;
901  f->key_frame_ok = 1;
902  } else {
903  if (!f->key_frame_ok) {
904  av_log(avctx, AV_LOG_ERROR,
905  "Cannot decode non-keyframe without valid keyframe\n");
906  return AVERROR_INVALIDDATA;
907  }
908  p->key_frame = 0;
909  }
910 
911  if ((ret = ff_thread_get_buffer(avctx, &f->picture, AV_GET_BUFFER_FLAG_REF)) < 0)
912  return ret;
913 
914  if (avctx->debug & FF_DEBUG_PICT_INFO)
915  av_log(avctx, AV_LOG_DEBUG, "ver:%d keyframe:%d coder:%d ec:%d slices:%d bps:%d\n",
916  f->version, p->key_frame, f->ac, f->ec, f->slice_count, f->avctx->bits_per_raw_sample);
917 
918  ff_thread_finish_setup(avctx);
919 
920  buf_p = buf + buf_size;
921  for (i = f->slice_count - 1; i >= 0; i--) {
922  FFV1Context *fs = f->slice_context[i];
923  int trailer = 3 + 5*!!f->ec;
924  int v;
925 
926  if (i || f->version > 2) v = AV_RB24(buf_p-trailer) + trailer;
927  else v = buf_p - c->bytestream_start;
928  if (buf_p - c->bytestream_start < v) {
929  av_log(avctx, AV_LOG_ERROR, "Slice pointer chain broken\n");
930  return AVERROR_INVALIDDATA;
931  }
932  buf_p -= v;
933 
934  if (f->ec) {
935  unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, v);
936  if (crc) {
937  int64_t ts = avpkt->pts != AV_NOPTS_VALUE ? avpkt->pts : avpkt->dts;
938  av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!", crc);
939  if (ts != AV_NOPTS_VALUE && avctx->pkt_timebase.num) {
940  av_log(f->avctx, AV_LOG_ERROR, "at %f seconds\n", ts*av_q2d(avctx->pkt_timebase));
941  } else if (ts != AV_NOPTS_VALUE) {
942  av_log(f->avctx, AV_LOG_ERROR, "at %"PRId64"\n", ts);
943  } else {
944  av_log(f->avctx, AV_LOG_ERROR, "\n");
945  }
946  fs->slice_damaged = 1;
947  }
948  }
949 
950  if (i) {
951  ff_init_range_decoder(&fs->c, buf_p, v);
952  } else
953  fs->c.bytestream_end = buf_p + v;
954 
955  fs->avctx = avctx;
956  fs->cur = p;
957  }
958 
959  avctx->execute(avctx,
960  decode_slice,
961  &f->slice_context[0],
962  NULL,
963  f->slice_count,
964  sizeof(void*));
965 
966  for (i = f->slice_count - 1; i >= 0; i--) {
967  FFV1Context *fs = f->slice_context[i];
968  int j;
969  if (fs->slice_damaged && f->last_picture.f->data[0]) {
970  const uint8_t *src[4];
971  uint8_t *dst[4];
972  ff_thread_await_progress(&f->last_picture, INT_MAX, 0);
973  for (j = 0; j < 4; j++) {
974  int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0;
975  int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0;
976  dst[j] = p->data[j] + p->linesize[j] *
977  (fs->slice_y >> sv) + (fs->slice_x >> sh);
978  src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] *
979  (fs->slice_y >> sv) + (fs->slice_x >> sh);
980  }
981  av_image_copy(dst, p->linesize, src,
982  f->last_picture.f->linesize,
983  avctx->pix_fmt,
984  fs->slice_width,
985  fs->slice_height);
986  }
987  }
988  ff_thread_report_progress(&f->picture, INT_MAX, 0);
989 
990  f->picture_number++;
991 
992  if (f->last_picture.f)
994  f->cur = NULL;
995  if ((ret = av_frame_ref(data, f->picture.f)) < 0)
996  return ret;
997 
998  *got_frame = 1;
999 
1000  return buf_size;
1001 }
1002 
1004 {
1005  FFV1Context *f = avctx->priv_data;
1006  int i, ret;
1007 
1008  f->picture.f = NULL;
1009  f->last_picture.f = NULL;
1010  f->sample_buffer = NULL;
1011  f->slice_count = 0;
1012 
1013  for (i = 0; i < f->quant_table_count; i++) {
1014  av_assert0(f->version > 1);
1015  f->initial_states[i] = av_memdup(f->initial_states[i],
1016  f->context_count[i] * sizeof(*f->initial_states[i]));
1017  }
1018 
1019  f->picture.f = av_frame_alloc();
1020  f->last_picture.f = av_frame_alloc();
1021 
1022  if ((ret = ffv1_init_slice_contexts(f)) < 0)
1023  return ret;
1024 
1025  return 0;
1026 }
1027 
1028 static void copy_fields(FFV1Context *fsdst, FFV1Context *fssrc, FFV1Context *fsrc)
1029 {
1030  fsdst->version = fsrc->version;
1031  fsdst->micro_version = fsrc->micro_version;
1032  fsdst->chroma_planes = fsrc->chroma_planes;
1033  fsdst->chroma_h_shift = fsrc->chroma_h_shift;
1034  fsdst->chroma_v_shift = fsrc->chroma_v_shift;
1035  fsdst->transparency = fsrc->transparency;
1036  fsdst->plane_count = fsrc->plane_count;
1037  fsdst->ac = fsrc->ac;
1038  fsdst->colorspace = fsrc->colorspace;
1039 
1040  fsdst->ec = fsrc->ec;
1041  fsdst->intra = fsrc->intra;
1042  fsdst->slice_damaged = fssrc->slice_damaged;
1043  fsdst->key_frame_ok = fsrc->key_frame_ok;
1044 
1046  fsdst->packed_at_lsb = fsrc->packed_at_lsb;
1047  fsdst->slice_count = fsrc->slice_count;
1048  if (fsrc->version<3){
1049  fsdst->slice_x = fssrc->slice_x;
1050  fsdst->slice_y = fssrc->slice_y;
1051  fsdst->slice_width = fssrc->slice_width;
1052  fsdst->slice_height = fssrc->slice_height;
1053  }
1054 }
1055 
1057 {
1058  FFV1Context *fsrc = src->priv_data;
1059  FFV1Context *fdst = dst->priv_data;
1060  int i, ret;
1061 
1062  if (dst == src)
1063  return 0;
1064 
1065  {
1069  memcpy(initial_states, fdst->initial_states, sizeof(fdst->initial_states));
1070  memcpy(slice_context, fdst->slice_context , sizeof(fdst->slice_context));
1071 
1072  memcpy(fdst, fsrc, sizeof(*fdst));
1073  memcpy(fdst->initial_states, initial_states, sizeof(fdst->initial_states));
1074  memcpy(fdst->slice_context, slice_context , sizeof(fdst->slice_context));
1075  fdst->picture = picture;
1076  fdst->last_picture = last_picture;
1077  for (i = 0; i<fdst->num_h_slices * fdst->num_v_slices; i++) {
1078  FFV1Context *fssrc = fsrc->slice_context[i];
1079  FFV1Context *fsdst = fdst->slice_context[i];
1080  copy_fields(fsdst, fssrc, fsrc);
1081  }
1082  av_assert0(!fdst->plane[0].state);
1083  av_assert0(!fdst->sample_buffer);
1084  }
1085 
1086  av_assert1(fdst->slice_count == fsrc->slice_count);
1087 
1088 
1089  ff_thread_release_buffer(dst, &fdst->picture);
1090  if (fsrc->picture.f->data[0]) {
1091  if ((ret = ff_thread_ref_frame(&fdst->picture, &fsrc->picture)) < 0)
1092  return ret;
1093  }
1094 
1095  fdst->fsrc = fsrc;
1096 
1097  return 0;
1098 }
1099 
1101  .name = "ffv1",
1102  .long_name = NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"),
1103  .type = AVMEDIA_TYPE_VIDEO,
1104  .id = AV_CODEC_ID_FFV1,
1105  .priv_data_size = sizeof(FFV1Context),
1106  .init = decode_init,
1107  .close = ffv1_close,
1108  .decode = decode_frame,
1110  .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
1111  .capabilities = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/ |
1113 };
static av_always_inline int fold(int diff, int bits)
Definition: ffv1.h:140
int ffv1_allocate_initial_states(FFV1Context *f)
Definition: ffv1.c:148
#define NULL
Definition: coverity.c:32
const uint8_t ff_log2_run[41]
Definition: bitstream.c:38
float v
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:391
const char * s
Definition: avisynth_c.h:669
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:385
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2029
This structure describes decoded (raw) audio or video data.
Definition: frame.h:163
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:387
av_cold int ffv1_common_init(AVCodecContext *avctx)
Definition: ffv1.c:42
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:388
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:73
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:260
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:181
AVFrame * f
Definition: thread.h:36
int16_t quant_table[MAX_CONTEXT_INPUTS][256]
Definition: ffv1.h:64
int quant_table_count
Definition: ffv1.h:116
else temp
Definition: vf_mcdeint.c:257
const char * g
Definition: vf_curves.c:108
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int decode_slice(AVCodecContext *c, void *arg)
Definition: ffv1dec.c:358
int slice_height
Definition: ffv1.h:123
#define MAX_CONTEXT_INPUTS
Definition: ffv1.h:54
int16_t * sample_buffer
Definition: ffv1.h:105
int version
Definition: ffv1.h:82
int micro_version
Definition: ffv1.h:83
Range coder.
uint8_t * bytestream_end
Definition: rangecoder.h:44
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:1161
const char * b
Definition: vf_curves.c:109
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:372
static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale)
Definition: ffv1dec.c:469
#define AV_RB24
Definition: intreadwrite.h:64
static av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, int is_signed)
Definition: ffv1dec.c:42
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1442
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: ffv1dec.c:867
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:2725
FF Video Codec 1 (a lossless codec)
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
Definition: aacdec.c:1855
#define sample
int height
Definition: ffv1.h:84
AVCodec.
Definition: avcodec.h:3173
uint8_t one_state[256]
Definition: rangecoder.h:41
int slice_reset_contexts
Definition: ffv1.h:126
int slice_rct_by_coef
Definition: ffv1.h:128
int plane_count
Definition: ffv1.h:94
int slice_damaged
Definition: ffv1.h:109
ThreadFrame picture
Definition: ffv1.h:90
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
static int read_quant_tables(RangeCoder *c, int16_t quant_table[MAX_CONTEXT_INPUTS][256])
Definition: ffv1dec.c:496
if()
Definition: avfilter.c:975
uint8_t bits
Definition: crc.c:295
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:100
uint8_t
#define av_cold
Definition: attributes.h:74
static int get_rac(RangeCoder *c, uint8_t *const state)
Definition: rangecoder.h:115
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:135
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:63
AVOptions.
int8_t bias
Definition: ffv1.h:59
RangeCoder c
Definition: ffv1.h:77
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:278
#define emms_c()
Definition: internal.h:50
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1353
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:384
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:371
int slice_y
Definition: ffv1.h:125
uint8_t(*[MAX_QUANT_TABLES] initial_states)[32]
Definition: ffv1.h:102
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:787
ThreadFrame last_picture
Definition: ffv1.h:90
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar)
Check if the given sample aspect ratio of an image is valid.
Definition: imgutils.c:252
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:80
int coder_type
coder type
Definition: avcodec.h:2378
uint8_t * data
Definition: avcodec.h:1160
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:212
uint8_t count
Definition: ffv1.h:60
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:3656
bitstream reader API header.
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:369
static void decode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, int stride[3])
Definition: ffv1dec.c:223
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:359
VlcState * vlc_state
Definition: ffv1.h:68
ptrdiff_t size
Definition: opengl_enc.c:101
av_cold int ffv1_init_slice_state(FFV1Context *f, FFV1Context *fs)
Definition: ffv1.c:67
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:390
high precision timer, useful to profile code
#define av_log(a,...)
int bits_per_raw_sample
Definition: ffv1.h:112
int slice_width
Definition: ffv1.h:122
GetBitContext gb
Definition: ffv1.h:78
#define U(x)
Definition: vp56_arith.h:37
AVFrame * cur
Definition: ffv1.h:93
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:3031
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:267
static int init_thread_copy(AVCodecContext *avctx)
Definition: ffv1dec.c:1003
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:175
static int decode_slice_header(FFV1Context *f, FFV1Context *fs)
Definition: ffv1dec.c:279
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256]
Definition: ffv1.h:99
#define AVERROR(e)
Definition: error.h:43
int skip_alpha
Skip processing alpha if supported by codec.
Definition: avcodec.h:3094
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:180
const char * r
Definition: vf_curves.c:107
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:196
int context_count
Definition: ffv1.h:66
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:392
const char * arg
Definition: jacosubdec.c:66
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: avcodec.h:3180
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:360
#define MAX_SLICES
Definition: dxva2_hevc.c:28
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
Libavcodec external API header.
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:288
static int get_vlc_symbol(GetBitContext *gb, VlcState *const state, int bits)
Definition: ffv1dec.c:67
uint8_t * bytestream
Definition: rangecoder.h:43
static void decode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index)
Definition: ffv1dec.c:181
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:72
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:219
int ac
1=range coder <-> 0=golomb rice
Definition: ffv1.h:95
static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Definition: ffv1dec.c:1056
int16_t quant_table[MAX_CONTEXT_INPUTS][256]
Definition: ffv1.h:98
int run_index
Definition: ffv1.h:103
Definition: ffv1.h:56
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:356
#define av_flatten
Definition: attributes.h:80
static av_noinline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
Definition: ffv1dec.c:62
uint8_t state_transition[256]
Definition: ffv1.h:101
static void copy_fields(FFV1Context *fsdst, FFV1Context *fssrc, FFV1Context *fsrc)
Definition: ffv1dec.c:1028
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:234
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:342
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define FFMIN(a, b)
Definition: common.h:66
float y
int num_h_slices
Definition: ffv1.h:121
ret
Definition: avfilter.c:974
#define MAX_QUANT_TABLES
Definition: ffv1.h:53
int colorspace
Definition: ffv1.h:104
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
static float quant_table[96]
Definition: binkaudio.c:41
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
static int get_context(PlaneContext *p, int16_t *src, int16_t *last, int16_t *last2)
Definition: ffv1.h:162
static void update_vlc_state(VlcState *const state, const int v)
Definition: ffv1.h:184
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:356
int slice_count
Definition: ffv1.h:119
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
Definition: rangecoder.c:62
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:389
int ac_byte_count
number of bytes used for AC coding
Definition: ffv1.h:96
static av_always_inline void decode_line(FFV1Context *s, int w, int16_t *sample[2], int plane_index, int bits)
Definition: ffv1dec.c:97
int16_t drift
Definition: ffv1.h:57
int packed_at_lsb
Definition: ffv1.h:113
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:357
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:374
av_cold int ffv1_init_slice_contexts(FFV1Context *f)
Definition: ffv1.c:112
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:619
static const float pred[4]
Definition: siprdata.h:259
void * av_memdup(const void *p, size_t size)
Duplicate the buffer p.
Definition: mem.c:297
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:367
int context_count[MAX_QUANT_TABLES]
Definition: ffv1.h:100
AVS_Value src
Definition: avisynth_c.h:524
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:191
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:266
int debug
debug
Definition: avcodec.h:2563
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
Definition: avcodec.h:1239
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:335
int intra
Definition: ffv1.h:108
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:244
void * buf
Definition: avisynth_c.h:595
int extradata_size
Definition: avcodec.h:1354
void ffv1_clear_slice_state(FFV1Context *f, FFV1Context *fs)
Definition: ffv1.c:163
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:304
BYTE int const BYTE int int int height
Definition: avisynth_c.h:714
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:358
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:74
rational number numerator/denominator
Definition: rational.h:43
av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size)
Definition: rangecoder.c:53
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:410
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
Definition: pixdesc.h:40
int picture_number
Definition: ffv1.h:89
uint16_t error_sum
Definition: ffv1.h:58
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:355
int allocate_progress
Whether to allocate progress for frame threading.
Definition: internal.h:89
int key_frame_ok
Definition: ffv1.h:110
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:373
static uint32_t state
Definition: trasher.c:27
#define CONTEXT_SIZE
Definition: ffv1.h:51
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:359
int quant_table_index
Definition: ffv1.h:65
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:174
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:2564
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:342
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:520
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:68
Y , 8bpp.
Definition: pixfmt.h:76
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:868
common internal api header.
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:864
static double c[64]
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:386
uint8_t(* state)[CONTEXT_SIZE]
Definition: ffv1.h:67
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:75
int den
denominator
Definition: rational.h:45
int slice_coding_mode
Definition: ffv1.h:127
uint8_t * bytestream_start
Definition: rangecoder.h:42
static av_cold int decode_init(AVCodecContext *avctx)
Definition: ffv1dec.c:848
void * priv_data
Definition: avcodec.h:1281
int chroma_h_shift
Definition: ffv1.h:86
PlaneContext plane[MAX_PLANES]
Definition: ffv1.h:97
int transparency
Definition: ffv1.h:87
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define av_free(p)
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
Definition: avcodec.h:2791
struct FFV1Context * fsrc
Definition: ffv1.h:91
int chroma_v_shift
Definition: ffv1.h:86
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:364
int len
int chroma_planes
Definition: ffv1.h:85
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1289
av_cold int ffv1_close(AVCodecContext *avctx)
Definition: ffv1.c:191
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:229
struct FFV1Context * slice_context[MAX_SLICES]
Definition: ffv1.h:118
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1159
#define av_noinline
Definition: attributes.h:54
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:1980
#define av_always_inline
Definition: attributes.h:37
#define av_malloc_array(a, b)
#define FFSWAP(type, a, b)
Definition: common.h:69
int ec
Definition: ffv1.h:107
enum AVColorSpace colorspace
Definition: dirac.c:102
static int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len)
read signed golomb rice code (ffv1).
Definition: golomb.h:362
int num_v_slices
Definition: ffv1.h:120
exp golomb vlc stuff
This structure stores compressed data.
Definition: avcodec.h:1137
static int read_extra_header(FFV1Context *f)
Definition: ffv1dec.c:511
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:967
AVCodecContext * avctx
Definition: ffv1.h:76
int slice_x
Definition: ffv1.h:124
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:368
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1153
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:241
AVCodec ff_ffv1_decoder
Definition: ffv1dec.c:1100
int width
Definition: ffv1.h:84
#define AV_PIX_FMT_0RGB32
Definition: pixfmt.h:339
static int width
int slice_rct_ry_coef
Definition: ffv1.h:129