FFmpeg
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/mem.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/pixdesc.h"
33 #include "avcodec.h"
34 #include "codec_internal.h"
35 #include "get_bits.h"
36 #include "rangecoder.h"
37 #include "golomb.h"
38 #include "mathops.h"
39 #include "ffv1.h"
40 #include "progressframe.h"
41 #include "libavutil/refstruct.h"
42 #include "thread.h"
43 #include "decode.h"
44 
45 static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state,
46  int bits)
47 {
48  int k, i, v, ret;
49 
50  i = state->count;
51  k = 0;
52  while (i < state->error_sum) { // FIXME: optimize
53  k++;
54  i += i;
55  }
56 
57  v = get_sr_golomb(gb, k, 12, bits);
58  ff_dlog(NULL, "v:%d bias:%d error:%d drift:%d count:%d k:%d",
59  v, state->bias, state->error_sum, state->drift, state->count, k);
60 
61  v ^= ((2 * state->drift + state->count) >> 31);
62 
63  ret = fold(v + state->bias, bits);
64 
66 
67  return ret;
68 }
69 
70 static int is_input_end(RangeCoder *c, GetBitContext *gb, int ac)
71 {
72  if (ac != AC_GOLOMB_RICE) {
73  if (c->overread > MAX_OVERREAD)
74  return AVERROR_INVALIDDATA;
75  } else {
76  if (get_bits_left(gb) < 1)
77  return AVERROR_INVALIDDATA;
78  }
79  return 0;
80 }
81 
82 #define TYPE int16_t
83 #define RENAME(name) name
84 #include "ffv1dec_template.c"
85 #undef TYPE
86 #undef RENAME
87 
88 #define TYPE int32_t
89 #define RENAME(name) name ## 32
90 #include "ffv1dec_template.c"
91 
93  GetBitContext *gb,
94  uint8_t *src, int w, int h, int stride, int plane_index,
95  int pixel_stride, int ac)
96 {
97  int x, y;
98  int16_t *sample[2];
99  sample[0] = sc->sample_buffer + 3;
100  sample[1] = sc->sample_buffer + w + 6 + 3;
101 
102  sc->run_index = 0;
103 
104  memset(sc->sample_buffer, 0, 2 * (w + 6) * sizeof(*sc->sample_buffer));
105 
106  for (y = 0; y < h; y++) {
107  int16_t *temp = sample[0]; // FIXME: try a normal buffer
108 
109  sample[0] = sample[1];
110  sample[1] = temp;
111 
112  sample[1][-1] = sample[0][0];
113  sample[0][w] = sample[0][w - 1];
114 
115  if (f->avctx->bits_per_raw_sample <= 8) {
116  int ret = decode_line(f, sc, gb, w, sample, plane_index, 8, ac);
117  if (ret < 0)
118  return ret;
119  for (x = 0; x < w; x++)
120  src[x*pixel_stride + stride * y] = sample[1][x];
121  } else {
122  int ret = decode_line(f, sc, gb, w, sample, plane_index, f->avctx->bits_per_raw_sample, ac);
123  if (ret < 0)
124  return ret;
125  if (f->packed_at_lsb) {
126  for (x = 0; x < w; x++) {
127  ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x];
128  }
129  } else {
130  for (x = 0; x < w; x++) {
131  ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x] << (16 - f->avctx->bits_per_raw_sample) | ((uint16_t **)sample)[1][x] >> (2 * f->avctx->bits_per_raw_sample - 16);
132  }
133  }
134  }
135  }
136  return 0;
137 }
138 
141 {
142  RangeCoder *c = &sc->c;
143  uint8_t state[CONTEXT_SIZE];
144  unsigned ps, context_count;
145  int sx, sy, sw, sh;
146 
147  memset(state, 128, sizeof(state));
148  sx = ff_ffv1_get_symbol(c, state, 0);
149  sy = ff_ffv1_get_symbol(c, state, 0);
150  sw = ff_ffv1_get_symbol(c, state, 0) + 1U;
151  sh = ff_ffv1_get_symbol(c, state, 0) + 1U;
152 
153  av_assert0(f->version > 2);
154 
155 
156  if (sx < 0 || sy < 0 || sw <= 0 || sh <= 0)
157  return AVERROR_INVALIDDATA;
158  if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh)
159  return AVERROR_INVALIDDATA;
160 
161  sc->slice_x = ff_slice_coord(f, f->width , sx , f->num_h_slices, f->chroma_h_shift);
162  sc->slice_y = ff_slice_coord(f, f->height, sy , f->num_v_slices, f->chroma_v_shift);
163  sc->slice_width = ff_slice_coord(f, f->width , sx + sw, f->num_h_slices, f->chroma_h_shift) - sc->slice_x;
164  sc->slice_height = ff_slice_coord(f, f->height, sy + sh, f->num_v_slices, f->chroma_v_shift) - sc->slice_y;
165 
166  av_assert0((unsigned)sc->slice_width <= f->width &&
167  (unsigned)sc->slice_height <= f->height);
168  av_assert0 ( (unsigned)sc->slice_x + (uint64_t)sc->slice_width <= f->width
169  && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height);
170 
171  if (f->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23))
172  return AVERROR_INVALIDDATA;
173 
174  for (unsigned i = 0; i < f->plane_count; i++) {
175  PlaneContext * const p = &sc->plane[i];
176  int idx = ff_ffv1_get_symbol(c, state, 0);
177  if (idx >= (unsigned)f->quant_table_count) {
178  av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n");
179  return -1;
180  }
181  p->quant_table_index = idx;
182  context_count = f->context_count[idx];
183 
184  if (p->context_count < context_count) {
185  av_freep(&p->state);
186  av_freep(&p->vlc_state);
187  }
188  p->context_count = context_count;
189  }
190 
191  ps = ff_ffv1_get_symbol(c, state, 0);
192  if (ps == 1) {
195  } else if (ps == 2) {
198  } else if (ps == 3) {
199  frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
200  }
201  frame->sample_aspect_ratio.num = ff_ffv1_get_symbol(c, state, 0);
202  frame->sample_aspect_ratio.den = ff_ffv1_get_symbol(c, state, 0);
203 
204  if (av_image_check_sar(f->width, f->height,
205  frame->sample_aspect_ratio) < 0) {
206  av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
207  frame->sample_aspect_ratio.num,
208  frame->sample_aspect_ratio.den);
209  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
210  }
211 
212  if (f->version > 3) {
215  if (sc->slice_coding_mode != 1 && f->colorspace == 1) {
218  if ((uint64_t)sc->slice_rct_by_coef + (uint64_t)sc->slice_rct_ry_coef > 4) {
219  av_log(f->avctx, AV_LOG_ERROR, "slice_rct_y_coef out of range\n");
220  return AVERROR_INVALIDDATA;
221  }
222  }
223  if (f->combined_version >= 0x40004) {
224  sc->remap = ff_ffv1_get_symbol(c, state, 0);
225  if (sc->remap > 2U ||
226  sc->remap && !f->flt) {
227  av_log(f->avctx, AV_LOG_ERROR, "unsupported remap %d\n", sc->remap);
228  return AVERROR_INVALIDDATA;
229  }
230  }
231  }
232 
233  return 0;
234 }
235 
237 {
238  sc->slice_damaged = 1;
239 
240  // only set this for frame threading, as for slice threading its value is
241  // not used and setting it would be a race
242  if (f->avctx->active_thread_type & FF_THREAD_FRAME)
243  f->frame_damaged = 1;
244 }
245 
247 {
248  int transparency = f->transparency;
249  int flip = sc->remap == 2 ? 0x7FFF : 0;
250 
251  for (int p= 0; p<3 + transparency; p++) {
252  int j = 0;
253  int lu = 0;
254  uint8_t state[2][32];
255  memset(state, 128, sizeof(state));
256 
257  for (int i= 0; i<65536; i++) {
258  int run = get_symbol_inline(&sc->c, state[lu], 0);
259  if (run > 65536U - i)
260  return AVERROR_INVALIDDATA;
261  if (lu) {
262  lu ^= !run;
263  while (run--) {
264  sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : flip);
265  i++;
266  }
267  } else {
268  i += run;
269  if (i != 65536)
270  sc->fltmap[p][j++] = i ^ ((i&0x8000) ? 0 : flip);
271  lu ^= !run;
272  }
273  }
274  }
275  return 0;
276 }
277 
278 static int decode_slice(AVCodecContext *c, void *arg)
279 {
280  FFV1Context *f = c->priv_data;
281  FFV1SliceContext *sc = arg;
282  int width, height, x, y, ret;
283  const int ps = av_pix_fmt_desc_get(f->pix_fmt)->comp[0].step;
284  AVFrame * const p = f->picture.f;
285  const int si = sc - f->slices;
286  GetBitContext gb;
287  int ac = f->ac || sc->slice_coding_mode == 1;
288 
289  if (!(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
290  ff_progress_frame_await(&f->last_picture, si);
291 
292  if (f->slice_damaged[si])
293  slice_set_damaged(f, sc);
294 
295  sc->slice_rct_by_coef = 1;
296  sc->slice_rct_ry_coef = 1;
297 
298  if (f->version > 2) {
299  if (ff_ffv1_init_slice_state(f, sc) < 0)
300  return AVERROR(ENOMEM);
301  if (decode_slice_header(f, sc, p) < 0) {
302  sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0;
303  slice_set_damaged(f, sc);
304  return AVERROR_INVALIDDATA;
305  }
306  }
307  if ((ret = ff_ffv1_init_slice_state(f, sc)) < 0)
308  return ret;
309  if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) {
311  } else if (sc->slice_damaged) {
312  return AVERROR_INVALIDDATA;
313  }
314 
315  width = sc->slice_width;
316  height = sc->slice_height;
317  x = sc->slice_x;
318  y = sc->slice_y;
319 
320  if (sc->remap) {
321  ret = decode_remap(f, sc);
322  if (ret < 0)
323  return ret;
324  }
325 
326  if (ac == AC_GOLOMB_RICE) {
327  if (f->combined_version >= 0x30002)
328  get_rac(&sc->c, (uint8_t[]) { 129 });
329  sc->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0;
330  init_get_bits(&gb,
331  sc->c.bytestream_start + sc->ac_byte_count,
332  (sc->c.bytestream_end - sc->c.bytestream_start - sc->ac_byte_count) * 8);
333  }
334 
335  av_assert1(width && height);
336  if (f->colorspace == 0 && (f->chroma_planes || !f->transparency)) {
337  const int chroma_width = AV_CEIL_RSHIFT(width, f->chroma_h_shift);
338  const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
339  const int cx = x >> f->chroma_h_shift;
340  const int cy = y >> f->chroma_v_shift;
341  decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1, ac);
342 
343  if (f->chroma_planes) {
344  decode_plane(f, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1, ac);
345  decode_plane(f, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1, ac);
346  }
347  if (f->transparency)
348  decode_plane(f, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1, ac);
349  } else if (f->colorspace == 0) {
350  decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2, ac);
351  decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2, ac);
352  } else if (f->use32bit) {
353  uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
354  p->data[1] + ps * x + y * p->linesize[1],
355  p->data[2] + ps * x + y * p->linesize[2],
356  p->data[3] + ps * x + y * p->linesize[3] };
357  decode_rgb_frame32(f, sc, &gb, planes, width, height, p->linesize);
358  } else {
359  uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
360  p->data[1] + ps * x + y * p->linesize[1],
361  p->data[2] + ps * x + y * p->linesize[2],
362  p->data[3] + ps * x + y * p->linesize[3] };
363  decode_rgb_frame(f, sc, &gb, planes, width, height, p->linesize);
364  }
365  if (ac != AC_GOLOMB_RICE && f->version > 2) {
366  int v;
367  get_rac(&sc->c, (uint8_t[]) { 129 });
368  v = sc->c.bytestream_end - sc->c.bytestream - 2 - 5*!!f->ec;
369  if (v) {
370  av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v);
371  slice_set_damaged(f, sc);
372  }
373  }
374 
375  if (sc->slice_damaged && (f->avctx->err_recognition & AV_EF_EXPLODE))
376  return AVERROR_INVALIDDATA;
377 
378  if ((c->active_thread_type & FF_THREAD_FRAME) && !f->frame_damaged)
379  ff_progress_frame_report(&f->picture, si);
380 
381  return 0;
382 }
383 
385 {
386  enum AVPixelFormat pix_fmts[] = {
387  f->pix_fmt,
389  };
390 
391  return ff_get_format(f->avctx, pix_fmts);
392 }
393 
395 {
396  uint8_t state[CONTEXT_SIZE];
397  int context_count = -1; //-1 to avoid warning
398  int ret;
399 
400  memset(state, 128, sizeof(state));
401 
403  if (ret < 0)
404  return ret;
405 
406  f->avctx->pix_fmt = get_pixel_format(f);
407  if (f->avctx->pix_fmt < 0)
408  return AVERROR(EINVAL);
409 
410  ff_dlog(f->avctx, "%d %d %d\n",
411  f->chroma_h_shift, f->chroma_v_shift, f->pix_fmt);
412  if (f->version < 2) {
413  context_count = ff_ffv1_read_quant_tables(c, f->quant_tables[0]);
414  if (context_count < 0) {
415  av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
416  return AVERROR_INVALIDDATA;
417  }
418  f->slice_count = f->max_slice_count;
419  } else if (f->version < 3) {
420  f->slice_count = ff_ffv1_get_symbol(c, state, 0);
421  } else {
422  const uint8_t *p = c->bytestream_end;
423  for (f->slice_count = 0;
424  f->slice_count < MAX_SLICES && 3 + 5*!!f->ec < p - c->bytestream_start;
425  f->slice_count++) {
426  int trailer = 3 + 5*!!f->ec;
427  int size = AV_RB24(p-trailer);
428  if (size + trailer > p - c->bytestream_start)
429  break;
430  p -= size + trailer;
431  }
432  }
433  if (f->slice_count > (unsigned)MAX_SLICES || f->slice_count <= 0 || f->slice_count > f->max_slice_count) {
434  av_log(f->avctx, AV_LOG_ERROR, "slice count %d is invalid (max=%d)\n", f->slice_count, f->max_slice_count);
435  return AVERROR_INVALIDDATA;
436  }
437 
438  av_refstruct_unref(&f->slice_damaged);
439  f->slice_damaged = av_refstruct_allocz(f->slice_count * sizeof(*f->slice_damaged));
440  if (!f->slice_damaged)
441  return AVERROR(ENOMEM);
442 
443  for (int j = 0; j < f->slice_count; j++) {
444  FFV1SliceContext *sc = &f->slices[j];
445 
446  if (f->version == 2) {
447  int sx = ff_ffv1_get_symbol(c, state, 0);
448  int sy = ff_ffv1_get_symbol(c, state, 0);
449  int sw = ff_ffv1_get_symbol(c, state, 0) + 1U;
450  int sh = ff_ffv1_get_symbol(c, state, 0) + 1U;
451 
452  if (sx < 0 || sy < 0 || sw <= 0 || sh <= 0)
453  return AVERROR_INVALIDDATA;
454  if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh)
455  return AVERROR_INVALIDDATA;
456 
457  sc->slice_x = sx * (int64_t)f->width / f->num_h_slices;
458  sc->slice_y = sy * (int64_t)f->height / f->num_v_slices;
459  sc->slice_width = (sx + sw) * (int64_t)f->width / f->num_h_slices - sc->slice_x;
460  sc->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - sc->slice_y;
461 
462  av_assert0((unsigned)sc->slice_width <= f->width &&
463  (unsigned)sc->slice_height <= f->height);
464  av_assert0 ( (unsigned)sc->slice_x + (uint64_t)sc->slice_width <= f->width
465  && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height);
466  }
467 
469  sc->plane = ff_ffv1_planes_alloc();
470  if (!sc->plane)
471  return AVERROR(ENOMEM);
472 
473  for (int i = 0; i < f->plane_count; i++) {
474  PlaneContext *const p = &sc->plane[i];
475 
476  if (f->version == 2) {
477  int idx = ff_ffv1_get_symbol(c, state, 0);
478  if (idx >= (unsigned)f->quant_table_count) {
479  av_log(f->avctx, AV_LOG_ERROR,
480  "quant_table_index out of range\n");
481  return AVERROR_INVALIDDATA;
482  }
483  p->quant_table_index = idx;
484  context_count = f->context_count[idx];
485  }
486 
487  if (f->version <= 2) {
488  av_assert0(context_count >= 0);
489  p->context_count = context_count;
490  }
491  }
492  }
493  return 0;
494 }
495 
497 {
498  FFV1Context *f = avctx->priv_data;
499  int ret;
500 
501  if ((ret = ff_ffv1_common_init(avctx, f)) < 0)
502  return ret;
503 
504  if (avctx->extradata_size > 0 && (ret = ff_ffv1_read_extra_header(f)) < 0)
505  return ret;
506 
507  if ((ret = ff_ffv1_init_slice_contexts(f)) < 0)
508  return ret;
509 
510  return 0;
511 }
512 
513 static int find_next_slice(AVCodecContext *avctx,
514  uint8_t *buf, uint8_t *buf_end, int idx,
515  uint8_t **pos, uint32_t *len)
516 {
517  FFV1Context *f = avctx->priv_data;
518 
519  /* Length field */
520  uint32_t v = buf_end - buf;
521  if (idx || f->version > 2) {
522  /* Three bytes of length, plus flush bit + CRC */
523  uint32_t trailer = 3 + 5*!!f->ec;
524  if (trailer > buf_end - buf)
525  v = INT_MAX;
526  else
527  v = AV_RB24(buf_end - trailer) + trailer;
528  }
529 
530  if (buf_end - buf < v) {
531  av_log(avctx, AV_LOG_ERROR, "Slice pointer chain broken\n");
532  ff_progress_frame_report(&f->picture, INT_MAX);
533  return AVERROR_INVALIDDATA;
534  }
535 
536  *len = v;
537  if (idx)
538  *pos = buf_end - v;
539  else
540  *pos = buf;
541 
542  return 0;
543 }
544 
546  uint8_t *buf, size_t buf_size)
547 {
548  int ret;
549  FFV1Context *f = avctx->priv_data;
550 
551  uint8_t keystate = 128;
552  ff_init_range_decoder(c, buf, buf_size);
553  ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);
554 
555  if (get_rac(c, &keystate)) {
556  f->key_frame = AV_FRAME_FLAG_KEY;
557  f->key_frame_ok = 0;
558  if ((ret = read_header(f, c)) < 0)
559  return ret;
560  f->key_frame_ok = 1;
561  } else {
562  if (!f->key_frame_ok) {
563  av_log(avctx, AV_LOG_ERROR,
564  "Cannot decode non-keyframe without valid keyframe\n");
565  return AVERROR_INVALIDDATA;
566  }
567  f->key_frame = 0;
568  }
569 
570  if (f->ac != AC_GOLOMB_RICE) {
571  if (buf_size < avctx->width * avctx->height / (128*8))
572  return AVERROR_INVALIDDATA;
573  } else {
574  int w = avctx->width;
575  int s = 1 + w / (1<<23);
576  int i;
577 
578  w /= s;
579 
580  for (i = 0; w > (1<<ff_log2_run[i]); i++)
581  w -= ff_log2_run[i];
582  if (buf_size < (avctx->height + i + 6) / 8 * s)
583  return AVERROR_INVALIDDATA;
584  }
585 
586  return 0;
587 }
588 
590  AVPacket *avpkt)
591 {
592  FFV1Context *f = avctx->priv_data;
593  AVFrame *p = f->picture.f;
594 
595  uint8_t *buf = avpkt->data;
596  size_t buf_size = avpkt->size;
597  uint8_t *buf_end = buf + buf_size;
598 
599  for (int i = f->slice_count - 1; i >= 0; i--) {
600  FFV1SliceContext *sc = &f->slices[i];
601 
602  uint8_t *pos;
603  uint32_t len;
604  int err = find_next_slice(avctx, buf, buf_end, i,
605  &pos, &len);
606  if (err < 0)
607  return err;
608 
609  buf_end -= len;
610 
611  sc->slice_damaged = 0;
612 
613  if (f->ec) {
614  unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, pos, len);
615  if (crc != f->crcref) {
616  int64_t ts = avpkt->pts != AV_NOPTS_VALUE ? avpkt->pts : avpkt->dts;
617  av_log(f->avctx, AV_LOG_ERROR, "slice CRC mismatch %X!", crc);
618  if (ts != AV_NOPTS_VALUE && avctx->pkt_timebase.num) {
619  av_log(f->avctx, AV_LOG_ERROR, "at %f seconds\n", ts*av_q2d(avctx->pkt_timebase));
620  } else if (ts != AV_NOPTS_VALUE) {
621  av_log(f->avctx, AV_LOG_ERROR, "at %"PRId64"\n", ts);
622  } else {
623  av_log(f->avctx, AV_LOG_ERROR, "\n");
624  }
625  slice_set_damaged(f, sc);
626  }
627  if (avctx->debug & FF_DEBUG_PICT_INFO) {
628  av_log(avctx, AV_LOG_DEBUG, "slice %d, CRC: 0x%08"PRIX32"\n", i, AV_RB32(pos + len - 4));
629  }
630  }
631 
632  if (i) {
633  ff_init_range_decoder(&sc->c, pos, len);
634  ff_build_rac_states(&sc->c, 0.05 * (1LL << 32), 256 - 8);
635  } else {
636  sc->c = c;
637  sc->c.bytestream_end = pos + len;
638  }
639  }
640 
641  avctx->execute(avctx,
642  decode_slice,
643  f->slices,
644  NULL,
645  f->slice_count,
646  sizeof(*f->slices));
647 
648  for (int i = f->slice_count - 1; i >= 0; i--) {
649  FFV1SliceContext *sc = &f->slices[i];
650  if (sc->slice_damaged && f->last_picture.f) {
651  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(f->pix_fmt);
652  const uint8_t *src[4];
653  uint8_t *dst[4];
654  ff_progress_frame_await(&f->last_picture, INT_MAX);
655  for (int j = 0; j < desc->nb_components; j++) {
656  int pixshift = desc->comp[j].depth > 8;
657  int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0;
658  int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0;
659  dst[j] = p->data[j] + p->linesize[j] *
660  (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift);
661  src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] *
662  (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift);
663 
664  }
665 
667  f->last_picture.f->linesize,
668  f->pix_fmt,
669  sc->slice_width,
670  sc->slice_height);
671 
672  f->slice_damaged[i] = 1;
673  }
674  }
675 
676  return 0;
677 }
678 
679 static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
680  int *got_frame, AVPacket *avpkt)
681 {
682  FFV1Context *f = avctx->priv_data;
683  int ret;
684  AVFrame *p;
685 
686  /* This is copied onto the first slice's range coder context */
687  RangeCoder c;
688 
689  ff_progress_frame_unref(&f->last_picture);
690  FFSWAP(ProgressFrame, f->picture, f->last_picture);
691 
692 
693  f->avctx = avctx;
694  f->frame_damaged = 0;
695 
696  ret = decode_header(avctx, &c, avpkt->data, avpkt->size);
697  if (ret < 0)
698  return ret;
699 
700  ret = ff_progress_frame_get_buffer(avctx, &f->picture,
702  if (ret < 0)
703  return ret;
704 
705  p = f->picture.f;
706 
707  p->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P
708  p->flags = (p->flags & ~AV_FRAME_FLAG_KEY) | f->key_frame;
709 
710  if (f->version < 3 && avctx->field_order > AV_FIELD_PROGRESSIVE) {
711  /* we have interlaced material flagged in container */
713  if (avctx->field_order == AV_FIELD_TT || avctx->field_order == AV_FIELD_TB)
715  }
716 
717  if (avctx->debug & FF_DEBUG_PICT_INFO)
718  av_log(avctx, AV_LOG_DEBUG, "ver:%d keyframe:%d coder:%d ec:%d slices:%d bps:%d\n",
719  f->version, !!(p->flags & AV_FRAME_FLAG_KEY), f->ac, f->ec, f->slice_count, f->avctx->bits_per_raw_sample);
720 
721  ff_thread_finish_setup(avctx);
722 
723  ret = decode_slices(avctx, c, avpkt);
724  if (ret < 0)
725  return ret;
726 
727  ff_progress_frame_report(&f->picture, INT_MAX);
728 
729  ff_progress_frame_unref(&f->last_picture);
730  if ((ret = av_frame_ref(rframe, f->picture.f)) < 0)
731  return ret;
732 
733  *got_frame = 1;
734 
735  return avpkt->size;
736 }
737 
738 #if HAVE_THREADS
740 {
741  FFV1Context *fsrc = src->priv_data;
742  FFV1Context *fdst = dst->priv_data;
743 
744  if (dst == src)
745  return 0;
746 
747  fdst->version = fsrc->version;
748  fdst->micro_version = fsrc->micro_version;
749  fdst->combined_version = fsrc->combined_version;
750  fdst->chroma_planes = fsrc->chroma_planes;
751  fdst->chroma_h_shift = fsrc->chroma_h_shift;
752  fdst->chroma_v_shift = fsrc->chroma_v_shift;
753  fdst->transparency = fsrc->transparency;
754  fdst->plane_count = fsrc->plane_count;
755  fdst->ac = fsrc->ac;
756  fdst->colorspace = fsrc->colorspace;
757  fdst->pix_fmt = fsrc->pix_fmt;
758 
759  fdst->ec = fsrc->ec;
760  fdst->intra = fsrc->intra;
761  fdst->key_frame_ok = fsrc->key_frame_ok;
762 
763  fdst->packed_at_lsb = fsrc->packed_at_lsb;
764  fdst->slice_count = fsrc->slice_count;
765  fdst->use32bit = fsrc->use32bit;
766  memcpy(fdst->state_transition, fsrc->state_transition,
767  sizeof(fdst->state_transition));
768 
769  // in version 1 there is a single per-keyframe quant table, so
770  // we need to propagate it between threads
771  if (fsrc->version < 2)
772  memcpy(fdst->quant_tables[0], fsrc->quant_tables[0], sizeof(fsrc->quant_tables[0]));
773 
774  for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) {
775  FFV1SliceContext *sc = &fdst->slices[i];
776  const FFV1SliceContext *sc0 = &fsrc->slices[i];
777 
778  av_refstruct_replace(&sc->plane, sc0->plane);
779 
780  if (fsrc->version < 3) {
781  sc->slice_x = sc0->slice_x;
782  sc->slice_y = sc0->slice_y;
783  sc->slice_width = sc0->slice_width;
784  sc->slice_height = sc0->slice_height;
785  }
786  }
787 
789 
791 
792  ff_progress_frame_replace(&fdst->picture, &fsrc->picture);
793 
794  return 0;
795 }
796 #endif
797 
799 {
800  FFV1Context *const s = avctx->priv_data;
801 
802  ff_progress_frame_unref(&s->picture);
803  ff_progress_frame_unref(&s->last_picture);
804  av_freep(&avctx->stats_out);
805 
806  ff_ffv1_close(s);
807 
808  return 0;
809 }
810 
812  .p.name = "ffv1",
813  CODEC_LONG_NAME("FFmpeg video codec #1"),
814  .p.type = AVMEDIA_TYPE_VIDEO,
815  .p.id = AV_CODEC_ID_FFV1,
816  .priv_data_size = sizeof(FFV1Context),
817  .init = decode_init,
818  .close = ffv1_decode_close,
821  .p.capabilities = AV_CODEC_CAP_DR1 |
823  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
825 };
ff_progress_frame_report
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
Definition: decode.c:1899
FFV1Context::chroma_v_shift
int chroma_v_shift
Definition: ffv1.h:122
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
FFV1SliceContext::slice_height
int slice_height
Definition: ffv1.h:78
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
FFV1Context::key_frame_ok
int key_frame_ok
Definition: ffv1.h:147
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
update_vlc_state
static void update_vlc_state(VlcState *const state, const int v)
Definition: ffv1.h:209
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:678
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
decode_slice
static int decode_slice(AVCodecContext *c, void *arg)
Definition: ffv1dec.c:278
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1274
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3313
MAX_OVERREAD
#define MAX_OVERREAD
Definition: lagarithrac.h:49
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: defs.h:202
FFV1SliceContext::plane
PlaneContext * plane
Definition: ffv1.h:90
planes
static const struct @475 planes[]
FFV1Context::ec
int ec
Definition: ffv1.h:145
int64_t
long long int64_t
Definition: coverity.c:34
get_sr_golomb
static int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len)
read signed golomb rice code (ffv1).
Definition: golomb.h:532
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
decode_header
static int decode_header(AVCodecContext *avctx, RangeCoder *c, uint8_t *buf, size_t buf_size)
Definition: ffv1dec.c:545
AVPacket::data
uint8_t * data
Definition: packet.h:539
AVCodecContext::field_order
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:722
decode_plane
static int decode_plane(FFV1Context *f, FFV1SliceContext *sc, GetBitContext *gb, uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride, int ac)
Definition: ffv1dec.c:92
ff_progress_frame_get_buffer
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
This function sets up the ProgressFrame, i.e.
Definition: decode.c:1854
rangecoder.h
AVComponentDescriptor::step
int step
Number of elements between 2 horizontally consecutive pixels.
Definition: pixdesc.h:40
PlaneContext::state
uint8_t(* state)[CONTEXT_SIZE]
Definition: ffv1.h:67
FFCodec
Definition: codec_internal.h:127
decode_remap
static int decode_remap(FFV1Context *f, FFV1SliceContext *sc)
Definition: ffv1dec.c:246
FFV1Context::num_h_slices
int num_h_slices
Definition: ffv1.h:160
RangeCoder::bytestream_end
uint8_t * bytestream_end
Definition: rangecoder.h:44
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:690
decode_line
static av_always_inline int RENAME() decode_line(FFV1Context *f, FFV1SliceContext *sc, GetBitContext *gb, int w, TYPE *sample[2], int plane_index, int bits, int ac)
Definition: ffv1dec_template.c:26
FFV1Context::quant_tables
int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE]
Definition: ffv1.h:134
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:497
thread.h
FFV1Context::chroma_h_shift
int chroma_h_shift
Definition: ffv1.h:122
FFV1SliceContext::slice_x
int slice_x
Definition: ffv1.h:79
ff_ffv1_read_extra_header
int ff_ffv1_read_extra_header(FFV1Context *f)
Definition: ffv1_parse.c:70
ff_ffv1_clear_slice_state
void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc)
Definition: ffv1.c:198
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1415
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:431
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:674
crc.h
golomb.h
exp golomb vlc stuff
AV_FIELD_TT
@ AV_FIELD_TT
Top coded_first, top displayed first.
Definition: defs.h:203
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
FFV1Context::combined_version
int combined_version
Definition: ffv1.h:119
ffv1_decode_close
static av_cold int ffv1_decode_close(AVCodecContext *avctx)
Definition: ffv1dec.c:798
GetBitContext
Definition: get_bits.h:108
MAX_SLICES
#define MAX_SLICES
Definition: d3d12va_hevc.c:33
CONTEXT_SIZE
#define CONTEXT_SIZE
Definition: ffv1.h:45
FFV1Context::chroma_planes
int chroma_planes
Definition: ffv1.h:121
PlaneContext::context_count
int context_count
Definition: ffv1.h:66
AVRational::num
int num
Numerator.
Definition: rational.h:59
progressframe.h
AV_FIELD_TB
@ AV_FIELD_TB
Top coded first, bottom displayed first.
Definition: defs.h:205
refstruct.h
decode_rgb_frame
static int RENAME() decode_rgb_frame(FFV1Context *f, FFV1SliceContext *sc, GetBitContext *gb, uint8_t *src[4], int w, int h, int stride[4])
Definition: ffv1dec_template.c:134
av_refstruct_allocz
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition: refstruct.h:105
avassert.h
FF_CODEC_CAP_USES_PROGRESSFRAMES
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
Definition: codec_internal.h:68
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:661
FFV1SliceContext::sample_buffer
int16_t * sample_buffer
Definition: ffv1.h:74
FFV1Context::use32bit
int use32bit
Definition: ffv1.h:143
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:538
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:341
s
#define s(width, name)
Definition: cbs_vp9.c:198
FFV1Context::slice_count
int slice_count
Definition: ffv1.h:157
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:431
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
Definition: ffv1dec.c:679
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
FFV1Context::max_slice_count
int max_slice_count
Definition: ffv1.h:158
bits
uint8_t bits
Definition: vp3data.h:128
FFV1Context::intra
int intra
Definition: ffv1.h:146
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
is_input_end
static int is_input_end(RangeCoder *c, GetBitContext *gb, int ac)
Definition: ffv1dec.c:70
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
ff_progress_frame_unref
void ff_progress_frame_unref(ProgressFrame *f)
Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame,...
Definition: decode.c:1882
ff_progress_frame_await
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before ff_progress_frame_await() has been called on them. reget_buffer() and buffer age optimizations no longer work. *The contents of buffers must not be written to after ff_progress_frame_report() has been called on them. This includes draw_edges(). Porting codecs to frame threading
decode.h
get_bits.h
fold
static av_always_inline int fold(int diff, int bits)
Definition: ffv1.h:198
FFV1Context::ac
int ac
1=range coder <-> 0=golomb rice
Definition: ffv1.h:133
get_vlc_symbol
static int get_vlc_symbol(GetBitContext *gb, VlcState *const state, int bits)
Definition: ffv1dec.c:45
FFV1Context::plane_count
int plane_count
Definition: ffv1.h:132
FFV1Context::slice_damaged
uint8_t * slice_damaged
Definition: ffv1.h:170
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:326
arg
const char * arg
Definition: jacosubdec.c:67
if
if(ret)
Definition: filter_design.txt:179
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:110
NULL
#define NULL
Definition: coverity.c:32
PlaneContext::vlc_state
VlcState * vlc_state
Definition: ffv1.h:68
AC_GOLOMB_RICE
#define AC_GOLOMB_RICE
Definition: ffv1.h:52
run
uint8_t run
Definition: svq3.c:204
FFV1Context::num_v_slices
int num_v_slices
Definition: ffv1.h:159
FFV1Context::colorspace
int colorspace
Definition: ffv1.h:138
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
ff_ffv1_decoder
const FFCodec ff_ffv1_decoder
Definition: ffv1dec.c:811
FFV1Context::slices
FFV1SliceContext * slices
Definition: ffv1.h:162
FFV1Context::state_transition
uint8_t state_transition[256]
Definition: ffv1.h:136
mathops.h
ff_ffv1_get_symbol
int ff_ffv1_get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
Definition: ffv1.c:222
PlaneContext
Definition: ffv1.h:64
UPDATE_THREAD_CONTEXT
#define UPDATE_THREAD_CONTEXT(func)
Definition: codec_internal.h:335
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
decode_slices
static int decode_slices(AVCodecContext *avctx, RangeCoder c, AVPacket *avpkt)
Definition: ffv1dec.c:589
VlcState
Definition: ffv1.h:57
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
FFV1SliceContext::slice_width
int slice_width
Definition: ffv1.h:77
ff_init_range_decoder
av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size)
Definition: rangecoder.c:53
AVCodecContext::stats_out
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:1352
AV_CODEC_ID_FFV1
@ AV_CODEC_ID_FFV1
Definition: codec_id.h:85
f
f
Definition: af_crystalizer.c:122
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:512
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
get_pixel_format
static enum AVPixelFormat get_pixel_format(FFV1Context *f)
Definition: ffv1dec.c:384
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
flip
static void flip(AVCodecContext *avctx, AVFrame *frame)
Definition: rawdec.c:131
AVPacket::size
int size
Definition: packet.h:540
height
#define height
Definition: dsp.h:85
state
static struct @474 state
av_frame_ref
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:308
codec_internal.h
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:565
sample
#define sample
Definition: flacdsp_template.c:44
size
int size
Definition: twinvq_data.h:10344
ff_build_rac_states
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
Definition: rangecoder.c:68
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
slice_set_damaged
static void slice_set_damaged(FFV1Context *f, FFV1SliceContext *sc)
Definition: ffv1dec.c:236
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
get_symbol_inline
static av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, int is_signed)
Definition: ffv1.h:238
RangeCoder::bytestream
uint8_t * bytestream
Definition: rangecoder.h:43
FFV1Context::picture
ProgressFrame picture
Definition: ffv1.h:127
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:538
FFV1SliceContext::slice_rct_by_coef
int slice_rct_by_coef
Definition: ffv1.h:85
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:114
ff_ffv1_init_slice_state
av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1SliceContext *sc)
Definition: ffv1.c:72
read_header
static int read_header(FFV1Context *f, RangeCoder *c)
Definition: ffv1dec.c:394
PlaneContext::quant_table_index
int quant_table_index
Definition: ffv1.h:65
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1612
FFV1SliceContext::c
RangeCoder c
Definition: ffv1.h:92
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
FFV1SliceContext::slice_rct_ry_coef
int slice_rct_ry_coef
Definition: ffv1.h:86
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
ff_ffv1_common_init
av_cold int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s)
Definition: ffv1.c:36
ffv1.h
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
FFV1SliceContext
Definition: ffv1.h:73
len
int len
Definition: vorbis_enc_data.h:426
get_rac
static int get_rac(RangeCoder *c, uint8_t *const state)
Definition: rangecoder.h:118
AV_CRC_32_IEEE
@ AV_CRC_32_IEEE
Definition: crc.h:52
AVCodecContext::height
int height
Definition: avcodec.h:632
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:669
FFV1Context::packed_at_lsb
int packed_at_lsb
Definition: ffv1.h:152
ff_ffv1_read_quant_tables
int ff_ffv1_read_quant_tables(RangeCoder *c, int16_t quant_table[MAX_CONTEXT_INPUTS][256])
Definition: ffv1_parse.c:52
avcodec.h
stride
#define stride
Definition: h264pred_template.c:536
ret
ret
Definition: filter_design.txt:187
find_next_slice
static int find_next_slice(AVCodecContext *avctx, uint8_t *buf, uint8_t *buf_end, int idx, uint8_t **pos, uint32_t *len)
Definition: ffv1dec.c:513
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
decode_slice_header
static int decode_slice_header(const FFV1Context *f, FFV1SliceContext *sc, AVFrame *frame)
Definition: ffv1dec.c:139
FFV1SliceContext::slice_y
int slice_y
Definition: ffv1.h:80
pos
unsigned int pos
Definition: spdifenc.c:414
ff_ffv1_close
av_cold void ff_ffv1_close(FFV1Context *s)
Definition: ffv1.c:227
ff_thread_finish_setup
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call ff_thread_finish_setup() afterwards. If some code can 't be moved
ff_slice_coord
int ff_slice_coord(const FFV1Context *f, int width, int sx, int num_h_slices, int chroma_shift)
This is intended for both width and height.
Definition: ffv1.c:127
U
#define U(x)
Definition: vpx_arith.h:37
ff_ffv1_planes_alloc
PlaneContext * ff_ffv1_planes_alloc(void)
Definition: ffv1.c:66
ff_progress_frame_replace
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is ...
Definition: decode.c:1889
FFV1Context::pix_fmt
enum AVPixelFormat pix_fmt
Definition: ffv1.h:129
AVCodecContext
main external API structure.
Definition: avcodec.h:451
RangeCoder::bytestream_start
uint8_t * bytestream_start
Definition: rangecoder.h:42
AVCodecContext::execute
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:1631
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: ffv1dec.c:496
av_crc
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:392
av_refstruct_replace
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
update_thread_context
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have update_thread_context() run it in the next thread. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. Use ff_thread_get_buffer()(or ff_progress_frame_get_buffer() in case you have inter-frame dependencies and use the ProgressFrame API) to allocate frame buffers. Call ff_progress_frame_report() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
FFV1SliceContext::remap
int remap
Definition: ffv1.h:87
FFV1SliceContext::fltmap
uint16_t fltmap[4][65536]
Definition: ffv1.h:109
ff_ffv1_parse_header
int ff_ffv1_parse_header(FFV1Context *f, RangeCoder *c, uint8_t *state)
Definition: ffv1_parse.c:208
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
temp
else temp
Definition: vf_mcdeint.c:263
AVCodecContext::debug
int debug
debug
Definition: avcodec.h:1414
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
FFV1Context
Definition: ffv1.h:112
FFV1Context::transparency
int transparency
Definition: ffv1.h:123
ProgressFrame
The ProgressFrame structure.
Definition: progressframe.h:73
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
FFV1SliceContext::run_index
int run_index
Definition: ffv1.h:83
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
ffv1dec_template.c
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:632
ff_ffv1_init_slice_contexts
av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
Definition: ffv1.c:140
ff_log2_run
const uint8_t ff_log2_run[41]
Definition: mathtables.c:116
imgutils.h
FFV1SliceContext::slice_reset_contexts
int slice_reset_contexts
Definition: ffv1.h:99
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:455
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
FFV1Context::micro_version
int micro_version
Definition: ffv1.h:118
h
h
Definition: vp9dsp_template.c:2070
RangeCoder
Definition: mss3.c:63
av_image_check_sar
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:323
width
#define width
Definition: dsp.h:85
av_image_copy
void av_image_copy(uint8_t *const dst_data[4], const int dst_linesizes[4], const uint8_t *const 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:422
FFV1SliceContext::ac_byte_count
int ac_byte_count
number of bytes used for AC coding
Definition: ffv1.h:94
AV_RB24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
Definition: bytestream.h:97
FFV1SliceContext::slice_damaged
int slice_damaged
Definition: ffv1.h:100
FFV1SliceContext::slice_coding_mode
int slice_coding_mode
Definition: ffv1.h:84
src
#define src
Definition: vp8dsp.c:248
FFV1Context::version
int version
Definition: ffv1.h:117