proresdec.c
Go to the documentation of this file.
1 /*
2  * Apple ProRes compatible decoder
3  *
4  * Copyright (c) 2010-2011 Maxim Poliakovski
5  *
6  * This file is part of Libav.
7  *
8  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
31 #define LONG_BITSTREAM_READER // some ProRes vlc codes require up to 28 bits to be read at once
32 
33 #include <stdint.h>
34 
35 #include "libavutil/intmath.h"
36 #include "avcodec.h"
37 #include "internal.h"
38 #include "proresdata.h"
39 #include "proresdsp.h"
40 #include "get_bits.h"
41 
42 typedef struct {
43  const uint8_t *index;
44  int slice_num;
45  int x_pos, y_pos;
48  DECLARE_ALIGNED(16, DCTELEM, blocks)[8 * 4 * 64];
49  DECLARE_ALIGNED(16, int16_t, qmat_luma_scaled)[64];
50  DECLARE_ALIGNED(16, int16_t, qmat_chroma_scaled)[64];
52 
53 typedef struct {
58 
59  int frame_type;
60  int pic_format;
61  uint8_t qmat_luma[64];
62  uint8_t qmat_chroma[64];
66  int pic_num;
74  int num_x_mbs;
75  int num_y_mbs;
78 
79 
81 {
82  ProresContext *ctx = avctx->priv_data;
83 
84  ctx->total_slices = 0;
85  ctx->slice_data = NULL;
86 
88  ff_proresdsp_init(&ctx->dsp);
89 
90  avctx->coded_frame = &ctx->picture;
93  ctx->picture.key_frame = 1;
94 
95  ctx->scantable_type = -1; // set scantable type to uninitialized
96  memset(ctx->qmat_luma, 4, 64);
97  memset(ctx->qmat_chroma, 4, 64);
98 
99  return 0;
100 }
101 
102 
103 static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
104  const int data_size, AVCodecContext *avctx)
105 {
106  int hdr_size, version, width, height, flags;
107  const uint8_t *ptr;
108 
109  hdr_size = AV_RB16(buf);
110  if (hdr_size > data_size) {
111  av_log(avctx, AV_LOG_ERROR, "frame data too small\n");
112  return AVERROR_INVALIDDATA;
113  }
114 
115  version = AV_RB16(buf + 2);
116  if (version >= 2) {
117  av_log(avctx, AV_LOG_ERROR,
118  "unsupported header version: %d\n", version);
119  return AVERROR_INVALIDDATA;
120  }
121 
122  width = AV_RB16(buf + 8);
123  height = AV_RB16(buf + 10);
124  if (width != avctx->width || height != avctx->height) {
125  av_log(avctx, AV_LOG_ERROR,
126  "picture dimension changed: old: %d x %d, new: %d x %d\n",
127  avctx->width, avctx->height, width, height);
128  return AVERROR_INVALIDDATA;
129  }
130 
131  ctx->frame_type = (buf[12] >> 2) & 3;
132  if (ctx->frame_type > 2) {
133  av_log(avctx, AV_LOG_ERROR,
134  "unsupported frame type: %d\n", ctx->frame_type);
135  return AVERROR_INVALIDDATA;
136  }
137 
138  ctx->chroma_factor = (buf[12] >> 6) & 3;
139  ctx->mb_chroma_factor = ctx->chroma_factor + 2;
140  ctx->num_chroma_blocks = (1 << ctx->chroma_factor) >> 1;
141  switch (ctx->chroma_factor) {
142  case 2:
143  avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
144  break;
145  case 3:
146  avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
147  break;
148  default:
149  av_log(avctx, AV_LOG_ERROR,
150  "unsupported picture format: %d\n", ctx->pic_format);
151  return AVERROR_INVALIDDATA;
152  }
153 
154  if (ctx->scantable_type != ctx->frame_type) {
155  if (!ctx->frame_type)
158  else
161  ctx->scantable_type = ctx->frame_type;
162  }
163 
164  if (ctx->frame_type) { /* if interlaced */
165  ctx->picture.interlaced_frame = 1;
166  ctx->picture.top_field_first = ctx->frame_type & 1;
167  } else {
168  ctx->picture.interlaced_frame = 0;
169  }
170 
171  avctx->color_primaries = buf[14];
172  avctx->color_trc = buf[15];
173  avctx->colorspace = buf[16];
174 
175  ctx->alpha_info = buf[17] & 0xf;
176  if (ctx->alpha_info)
177  av_log_missing_feature(avctx, "Alpha channel", 0);
178 
179  ctx->qmat_changed = 0;
180  ptr = buf + 20;
181  flags = buf[19];
182  if (flags & 2) {
183  if (ptr - buf > hdr_size - 64) {
184  av_log(avctx, AV_LOG_ERROR, "header data too small\n");
185  return AVERROR_INVALIDDATA;
186  }
187  if (memcmp(ctx->qmat_luma, ptr, 64)) {
188  memcpy(ctx->qmat_luma, ptr, 64);
189  ctx->qmat_changed = 1;
190  }
191  ptr += 64;
192  } else {
193  memset(ctx->qmat_luma, 4, 64);
194  ctx->qmat_changed = 1;
195  }
196 
197  if (flags & 1) {
198  if (ptr - buf > hdr_size - 64) {
199  av_log(avctx, AV_LOG_ERROR, "header data too small\n");
200  return -1;
201  }
202  if (memcmp(ctx->qmat_chroma, ptr, 64)) {
203  memcpy(ctx->qmat_chroma, ptr, 64);
204  ctx->qmat_changed = 1;
205  }
206  } else {
207  memset(ctx->qmat_chroma, 4, 64);
208  ctx->qmat_changed = 1;
209  }
210 
211  return hdr_size;
212 }
213 
214 
215 static int decode_picture_header(ProresContext *ctx, const uint8_t *buf,
216  const int data_size, AVCodecContext *avctx)
217 {
218  int i, hdr_size, pic_data_size, num_slices;
219  int slice_width_factor, slice_height_factor;
220  int remainder, num_x_slices;
221  const uint8_t *data_ptr, *index_ptr;
222 
223  hdr_size = data_size > 0 ? buf[0] >> 3 : 0;
224  if (hdr_size < 8 || hdr_size > data_size) {
225  av_log(avctx, AV_LOG_ERROR, "picture header too small\n");
226  return AVERROR_INVALIDDATA;
227  }
228 
229  pic_data_size = AV_RB32(buf + 1);
230  if (pic_data_size > data_size) {
231  av_log(avctx, AV_LOG_ERROR, "picture data too small\n");
232  return AVERROR_INVALIDDATA;
233  }
234 
235  slice_width_factor = buf[7] >> 4;
236  slice_height_factor = buf[7] & 0xF;
237  if (slice_width_factor > 3 || slice_height_factor) {
238  av_log(avctx, AV_LOG_ERROR,
239  "unsupported slice dimension: %d x %d\n",
240  1 << slice_width_factor, 1 << slice_height_factor);
241  return AVERROR_INVALIDDATA;
242  }
243 
244  ctx->slice_width_factor = slice_width_factor;
245  ctx->slice_height_factor = slice_height_factor;
246 
247  ctx->num_x_mbs = (avctx->width + 15) >> 4;
248  ctx->num_y_mbs = (avctx->height +
249  (1 << (4 + ctx->picture.interlaced_frame)) - 1) >>
250  (4 + ctx->picture.interlaced_frame);
251 
252  remainder = ctx->num_x_mbs & ((1 << slice_width_factor) - 1);
253  num_x_slices = (ctx->num_x_mbs >> slice_width_factor) + (remainder & 1) +
254  ((remainder >> 1) & 1) + ((remainder >> 2) & 1);
255 
256  num_slices = num_x_slices * ctx->num_y_mbs;
257  if (num_slices != AV_RB16(buf + 5)) {
258  av_log(avctx, AV_LOG_ERROR, "invalid number of slices\n");
259  return AVERROR_INVALIDDATA;
260  }
261 
262  if (ctx->total_slices != num_slices) {
263  av_freep(&ctx->slice_data);
264  ctx->slice_data = av_malloc((num_slices + 1) * sizeof(ctx->slice_data[0]));
265  if (!ctx->slice_data)
266  return AVERROR(ENOMEM);
267  ctx->total_slices = num_slices;
268  }
269 
270  if (hdr_size + num_slices * 2 > data_size) {
271  av_log(avctx, AV_LOG_ERROR, "slice table too small\n");
272  return AVERROR_INVALIDDATA;
273  }
274 
275  /* parse slice table allowing quick access to the slice data */
276  index_ptr = buf + hdr_size;
277  data_ptr = index_ptr + num_slices * 2;
278 
279  for (i = 0; i < num_slices; i++) {
280  ctx->slice_data[i].index = data_ptr;
281  ctx->slice_data[i].prev_slice_sf = 0;
282  data_ptr += AV_RB16(index_ptr + i * 2);
283  }
284  ctx->slice_data[i].index = data_ptr;
285  ctx->slice_data[i].prev_slice_sf = 0;
286 
287  if (data_ptr > buf + data_size) {
288  av_log(avctx, AV_LOG_ERROR, "out of slice data\n");
289  return -1;
290  }
291 
292  return pic_data_size;
293 }
294 
295 
299 static inline int decode_vlc_codeword(GetBitContext *gb, unsigned codebook)
300 {
301  unsigned int rice_order, exp_order, switch_bits;
302  unsigned int buf, code;
303  int log, prefix_len, len;
304 
305  OPEN_READER(re, gb);
306  UPDATE_CACHE(re, gb);
307  buf = GET_CACHE(re, gb);
308 
309  /* number of prefix bits to switch between Rice and expGolomb */
310  switch_bits = (codebook & 3) + 1;
311  rice_order = codebook >> 5; /* rice code order */
312  exp_order = (codebook >> 2) & 7; /* exp golomb code order */
313 
314  log = 31 - av_log2(buf); /* count prefix bits (zeroes) */
315 
316  if (log < switch_bits) { /* ok, we got a rice code */
317  if (!rice_order) {
318  /* shortcut for faster decoding of rice codes without remainder */
319  code = log;
320  LAST_SKIP_BITS(re, gb, log + 1);
321  } else {
322  prefix_len = log + 1;
323  code = (log << rice_order) + NEG_USR32(buf << prefix_len, rice_order);
324  LAST_SKIP_BITS(re, gb, prefix_len + rice_order);
325  }
326  } else { /* otherwise we got a exp golomb code */
327  len = (log << 1) - switch_bits + exp_order + 1;
328  code = NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order);
329  LAST_SKIP_BITS(re, gb, len);
330  }
331 
332  CLOSE_READER(re, gb);
333 
334  return code;
335 }
336 
337 #define LSB2SIGN(x) (-((x) & 1))
338 #define TOSIGNED(x) (((x) >> 1) ^ LSB2SIGN(x))
339 
343 static inline void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out,
344  int nblocks)
345 {
346  DCTELEM prev_dc;
347  int i, sign;
348  int16_t delta;
349  unsigned int code;
350 
351  code = decode_vlc_codeword(gb, FIRST_DC_CB);
352  out[0] = prev_dc = TOSIGNED(code);
353 
354  out += 64; /* move to the DC coeff of the next block */
355  delta = 3;
356 
357  for (i = 1; i < nblocks; i++, out += 64) {
358  code = decode_vlc_codeword(gb, ff_prores_dc_codebook[FFMIN(FFABS(delta), 3)]);
359 
360  sign = -(((delta >> 15) & 1) ^ (code & 1));
361  delta = (((code + 1) >> 1) ^ sign) - sign;
362  prev_dc += delta;
363  out[0] = prev_dc;
364  }
365 }
366 
367 
371 static inline int decode_ac_coeffs(GetBitContext *gb, DCTELEM *out,
372  int blocks_per_slice,
373  int plane_size_factor,
374  const uint8_t *scan)
375 {
376  int pos, block_mask, run, level, sign, run_cb_index, lev_cb_index;
377  int max_coeffs, bits_left;
378 
379  /* set initial prediction values */
380  run = 4;
381  level = 2;
382 
383  max_coeffs = blocks_per_slice << 6;
384  block_mask = blocks_per_slice - 1;
385 
386  for (pos = blocks_per_slice - 1; pos < max_coeffs;) {
387  run_cb_index = ff_prores_run_to_cb_index[FFMIN(run, 15)];
388  lev_cb_index = ff_prores_lev_to_cb_index[FFMIN(level, 9)];
389 
390  bits_left = get_bits_left(gb);
391  if (bits_left <= 0 || (bits_left <= 8 && !show_bits(gb, bits_left)))
392  return 0;
393 
394  run = decode_vlc_codeword(gb, ff_prores_ac_codebook[run_cb_index]);
395  if (run < 0)
396  return AVERROR_INVALIDDATA;
397 
398  bits_left = get_bits_left(gb);
399  if (bits_left <= 0 || (bits_left <= 8 && !show_bits(gb, bits_left)))
400  return AVERROR_INVALIDDATA;
401 
402  level = decode_vlc_codeword(gb, ff_prores_ac_codebook[lev_cb_index]) + 1;
403  if (level < 0)
404  return AVERROR_INVALIDDATA;
405 
406  pos += run + 1;
407  if (pos >= max_coeffs)
408  break;
409 
410  sign = get_sbits(gb, 1);
411  out[((pos & block_mask) << 6) + scan[pos >> plane_size_factor]] =
412  (level ^ sign) - sign;
413  }
414 
415  return 0;
416 }
417 
418 
423  const uint8_t *buf,
424  int data_size, uint16_t *out_ptr,
425  int linesize, int mbs_per_slice,
426  int blocks_per_mb, int plane_size_factor,
427  const int16_t *qmat, int is_chroma)
428 {
429  GetBitContext gb;
430  DCTELEM *block_ptr;
431  int mb_num, blocks_per_slice, ret;
432 
433  blocks_per_slice = mbs_per_slice * blocks_per_mb;
434 
435  memset(td->blocks, 0, 8 * 4 * 64 * sizeof(*td->blocks));
436 
437  init_get_bits(&gb, buf, data_size << 3);
438 
439  decode_dc_coeffs(&gb, td->blocks, blocks_per_slice);
440 
441  ret = decode_ac_coeffs(&gb, td->blocks, blocks_per_slice,
442  plane_size_factor, ctx->scantable.permutated);
443  if (ret < 0)
444  return ret;
445 
446  /* inverse quantization, inverse transform and output */
447  block_ptr = td->blocks;
448 
449  if (!is_chroma) {
450  for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
451  ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);
452  block_ptr += 64;
453  if (blocks_per_mb > 2) {
454  ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);
455  block_ptr += 64;
456  }
457  ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
458  block_ptr += 64;
459  if (blocks_per_mb > 2) {
460  ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
461  block_ptr += 64;
462  }
463  }
464  } else {
465  for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
466  ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);
467  block_ptr += 64;
468  ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
469  block_ptr += 64;
470  if (blocks_per_mb > 2) {
471  ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);
472  block_ptr += 64;
473  ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
474  block_ptr += 64;
475  }
476  }
477  }
478  return 0;
479 }
480 
481 
482 static int decode_slice(AVCodecContext *avctx, void *tdata)
483 {
484  ProresThreadData *td = tdata;
485  ProresContext *ctx = avctx->priv_data;
486  int mb_x_pos = td->x_pos;
487  int mb_y_pos = td->y_pos;
488  int pic_num = ctx->pic_num;
489  int slice_num = td->slice_num;
490  int mbs_per_slice = td->slice_width;
491  const uint8_t *buf;
492  uint8_t *y_data, *u_data, *v_data;
493  AVFrame *pic = avctx->coded_frame;
494  int i, sf, slice_width_factor;
495  int slice_data_size, hdr_size, y_data_size, u_data_size, v_data_size;
496  int y_linesize, u_linesize, v_linesize;
497  int ret;
498 
499  buf = ctx->slice_data[slice_num].index;
500  slice_data_size = ctx->slice_data[slice_num + 1].index - buf;
501 
502  slice_width_factor = av_log2(mbs_per_slice);
503 
504  y_data = pic->data[0];
505  u_data = pic->data[1];
506  v_data = pic->data[2];
507  y_linesize = pic->linesize[0];
508  u_linesize = pic->linesize[1];
509  v_linesize = pic->linesize[2];
510 
511  if (pic->interlaced_frame) {
512  if (!(pic_num ^ pic->top_field_first)) {
513  y_data += y_linesize;
514  u_data += u_linesize;
515  v_data += v_linesize;
516  }
517  y_linesize <<= 1;
518  u_linesize <<= 1;
519  v_linesize <<= 1;
520  }
521 
522  if (slice_data_size < 6) {
523  av_log(avctx, AV_LOG_ERROR, "slice data too small\n");
524  return AVERROR_INVALIDDATA;
525  }
526 
527  /* parse slice header */
528  hdr_size = buf[0] >> 3;
529  y_data_size = AV_RB16(buf + 2);
530  u_data_size = AV_RB16(buf + 4);
531  v_data_size = hdr_size > 7 ? AV_RB16(buf + 6) :
532  slice_data_size - y_data_size - u_data_size - hdr_size;
533 
534  if (hdr_size + y_data_size + u_data_size + v_data_size > slice_data_size ||
535  v_data_size < 0 || hdr_size < 6) {
536  av_log(avctx, AV_LOG_ERROR, "invalid data size\n");
537  return AVERROR_INVALIDDATA;
538  }
539 
540  sf = av_clip(buf[1], 1, 224);
541  sf = sf > 128 ? (sf - 96) << 2 : sf;
542 
543  /* scale quantization matrixes according with slice's scale factor */
544  /* TODO: this can be SIMD-optimized a lot */
545  if (ctx->qmat_changed || sf != td->prev_slice_sf) {
546  td->prev_slice_sf = sf;
547  for (i = 0; i < 64; i++) {
548  td->qmat_luma_scaled[ctx->dsp.idct_permutation[i]] = ctx->qmat_luma[i] * sf;
549  td->qmat_chroma_scaled[ctx->dsp.idct_permutation[i]] = ctx->qmat_chroma[i] * sf;
550  }
551  }
552 
553  /* decode luma plane */
554  ret = decode_slice_plane(ctx, td, buf + hdr_size, y_data_size,
555  (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize +
556  (mb_x_pos << 5)), y_linesize,
557  mbs_per_slice, 4, slice_width_factor + 2,
558  td->qmat_luma_scaled, 0);
559  if (ret < 0)
560  return ret;
561 
562  /* decode U chroma plane */
563  ret = decode_slice_plane(ctx, td, buf + hdr_size + y_data_size, u_data_size,
564  (uint16_t*) (u_data + (mb_y_pos << 4) * u_linesize +
565  (mb_x_pos << ctx->mb_chroma_factor)),
566  u_linesize, mbs_per_slice, ctx->num_chroma_blocks,
567  slice_width_factor + ctx->chroma_factor - 1,
568  td->qmat_chroma_scaled, 1);
569  if (ret < 0)
570  return ret;
571 
572  /* decode V chroma plane */
573  ret = decode_slice_plane(ctx, td, buf + hdr_size + y_data_size + u_data_size,
574  v_data_size,
575  (uint16_t*) (v_data + (mb_y_pos << 4) * v_linesize +
576  (mb_x_pos << ctx->mb_chroma_factor)),
577  v_linesize, mbs_per_slice, ctx->num_chroma_blocks,
578  slice_width_factor + ctx->chroma_factor - 1,
579  td->qmat_chroma_scaled, 1);
580  if (ret < 0)
581  return ret;
582 
583  return 0;
584 }
585 
586 
587 static int decode_picture(ProresContext *ctx, int pic_num,
588  AVCodecContext *avctx)
589 {
590  int slice_num, slice_width, x_pos, y_pos;
591 
592  slice_num = 0;
593 
594  ctx->pic_num = pic_num;
595  for (y_pos = 0; y_pos < ctx->num_y_mbs; y_pos++) {
596  slice_width = 1 << ctx->slice_width_factor;
597 
598  for (x_pos = 0; x_pos < ctx->num_x_mbs && slice_width;
599  x_pos += slice_width) {
600  while (ctx->num_x_mbs - x_pos < slice_width)
601  slice_width >>= 1;
602 
603  ctx->slice_data[slice_num].slice_num = slice_num;
604  ctx->slice_data[slice_num].x_pos = x_pos;
605  ctx->slice_data[slice_num].y_pos = y_pos;
606  ctx->slice_data[slice_num].slice_width = slice_width;
607 
608  slice_num++;
609  }
610  }
611 
612  return avctx->execute(avctx, decode_slice,
613  ctx->slice_data, NULL, slice_num,
614  sizeof(ctx->slice_data[0]));
615 }
616 
617 
618 #define MOVE_DATA_PTR(nbytes) buf += (nbytes); buf_size -= (nbytes)
619 
620 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
621  AVPacket *avpkt)
622 {
623  ProresContext *ctx = avctx->priv_data;
624  AVFrame *picture = avctx->coded_frame;
625  const uint8_t *buf = avpkt->data;
626  int buf_size = avpkt->size;
627  int frame_hdr_size, pic_num, pic_data_size;
628 
629  /* check frame atom container */
630  if (buf_size < 28 || buf_size < AV_RB32(buf) ||
631  AV_RB32(buf + 4) != FRAME_ID) {
632  av_log(avctx, AV_LOG_ERROR, "invalid frame\n");
633  return AVERROR_INVALIDDATA;
634  }
635 
636  MOVE_DATA_PTR(8);
637 
638  frame_hdr_size = decode_frame_header(ctx, buf, buf_size, avctx);
639  if (frame_hdr_size < 0)
640  return AVERROR_INVALIDDATA;
641 
642  MOVE_DATA_PTR(frame_hdr_size);
643 
644  if (picture->data[0])
645  avctx->release_buffer(avctx, picture);
646 
647  picture->reference = 0;
648  if (ff_get_buffer(avctx, picture) < 0)
649  return -1;
650 
651  for (pic_num = 0; ctx->picture.interlaced_frame - pic_num + 1; pic_num++) {
652  pic_data_size = decode_picture_header(ctx, buf, buf_size, avctx);
653  if (pic_data_size < 0)
654  return AVERROR_INVALIDDATA;
655 
656  if (decode_picture(ctx, pic_num, avctx))
657  return -1;
658 
659  MOVE_DATA_PTR(pic_data_size);
660  }
661 
662  *got_frame = 1;
663  *(AVFrame*) data = *avctx->coded_frame;
664 
665  return avpkt->size;
666 }
667 
668 
670 {
671  ProresContext *ctx = avctx->priv_data;
672 
673  if (ctx->picture.data[0])
674  avctx->release_buffer(avctx, &ctx->picture);
675 
676  av_freep(&ctx->slice_data);
677 
678  return 0;
679 }
680 
681 
683  .name = "prores",
684  .type = AVMEDIA_TYPE_VIDEO,
685  .id = AV_CODEC_ID_PRORES,
686  .priv_data_size = sizeof(ProresContext),
687  .init = decode_init,
688  .close = decode_close,
689  .decode = decode_frame,
690  .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS,
691  .long_name = NULL_IF_CONFIG_SMALL("Apple ProRes (iCodec Pro)")
692 };
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:61
DCTELEM blocks[8 *4 *64]
Definition: proresdec.c:48
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
uint8_t qmat_luma[64]
dequantization matrix for luma
Definition: proresdec.c:61
#define TOSIGNED(x)
Definition: proresdec.c:338
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:2259
#define MOVE_DATA_PTR(nbytes)
Definition: proresdec.c:618
const uint8_t ff_prores_ac_codebook[7]
Definition: proresdata.c:55
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
Scantable.
Definition: dsputil.h:181
int size
Definition: avcodec.h:916
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
static av_cold int decode_init(AVCodecContext *avctx)
Definition: proresdec.c:80
uint8_t permutated[64]
Definition: dsputil.h:183
uint8_t run
Definition: svq3.c:124
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:2711
static int decode_picture_header(ProresContext *ctx, const uint8_t *buf, const int data_size, AVCodecContext *avctx)
Definition: proresdec.c:215
int scantable_type
-1 = uninitialized, 0 = progressive, 1/2 = interlaced
Definition: proresdec.c:57
AVCodec.
Definition: avcodec.h:2960
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:223
int slice_height_factor
Definition: proresdec.c:73
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: proresdec.c:620
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:151
const uint8_t * index
pointers to the data of this slice
Definition: proresdec.c:43
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
uint8_t
float delta
#define AV_RB32
Definition: intreadwrite.h:130
const char data[16]
Definition: mxf.c:66
void(* idct_put)(uint16_t *out, int linesize, DCTELEM *block, const int16_t *qmat)
Definition: proresdsp.h:35
uint8_t * data
Definition: avcodec.h:915
const uint8_t ff_prores_run_to_cb_index[16]
Lookup tables for adaptive switching between codebooks according with previous run/level value...
Definition: proresdata.c:69
static int flags
Definition: log.c:42
const uint8_t ff_prores_lev_to_cb_index[10]
Definition: proresdata.c:72
bitstream reader API header.
int interlaced_frame
The content of the picture is interlaced.
Definition: avcodec.h:1232
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:335
ProresThreadData * slice_data
Definition: proresdec.c:65
int16_t qmat_chroma_scaled[64]
Definition: proresdec.c:50
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:547
struct ProresContext ProresContext
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:160
static int decode_slice(AVCodecContext *avctx, void *tdata)
Definition: proresdec.c:482
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
Definition: avcodec.h:1132
#define AV_RB16
Definition: intreadwrite.h:53
int mb_chroma_factor
Definition: proresdec.c:68
int num_y_slices
Definition: proresdec.c:71
static av_cold int decode_close(AVCodecContext *avctx)
Definition: proresdec.c:669
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
struct ProresThreadData ProresThreadData
#define CLOSE_READER(name, gb)
Definition: get_bits.h:140
static AVFrame * picture
int num_chroma_blocks
number of chrominance blocks in a macroblock
Definition: proresdec.c:69
int width
picture width / height.
Definition: avcodec.h:1508
#define NEG_USR32(a, s)
Definition: mathops.h:159
int type
type of the buffer (to keep track of who has to deallocate data[*])
Definition: avcodec.h:1217
uint8_t idct_permutation[64]
Definition: proresdsp.h:32
static int decode_ac_coeffs(GetBitContext *gb, DCTELEM *out, int blocks_per_slice, int plane_size_factor, const uint8_t *scan)
Decode AC coefficients for all blocks in a slice.
Definition: proresdec.c:371
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
const uint8_t ff_prores_dc_codebook[4]
Definition: proresdata.c:48
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:2058
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:251
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:180
int total_slices
total number of slices in a picture
Definition: proresdec.c:64
static void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out, int nblocks)
Decode DC coefficients for all blocks in a slice.
Definition: proresdec.c:343
static int decode_vlc_codeword(GetBitContext *gb, unsigned codebook)
Read an unsigned rice/exp golomb codeword.
Definition: proresdec.c:299
ProresDSPContext dsp
Definition: proresdec.c:54
int alpha_info
Definition: proresdec.c:76
#define FIRST_DC_CB
Definition: proresdata.h:33
NULL
Definition: eval.c:52
int chroma_factor
Definition: proresdec.c:67
static int width
Definition: utils.c:156
const uint8_t ff_prores_interlaced_scan[64]
Definition: proresdata.c:36
external API header
int slice_width_factor
Definition: proresdec.c:72
int num_x_slices
Definition: proresdec.c:70
ScanTable scantable
Definition: proresdec.c:56
version
Definition: ffv1enc.c:1069
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
main external API structure.
Definition: avcodec.h:1339
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:326
const uint8_t ff_prores_progressive_scan[64]
Definition: proresdata.c:25
#define OPEN_READER(name, gb)
Definition: get_bits.h:124
static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, const int data_size, AVCodecContext *avctx)
Definition: proresdec.c:103
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:604
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
Definition: utils.c:2007
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:2072
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:2065
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:372
#define GET_CACHE(name, gb)
Definition: get_bits.h:190
AVFrame picture
Definition: proresdec.c:55
AVCodec ff_prores_decoder
Definition: proresdec.c:682
static int decode_picture(ProresContext *ctx, int pic_num, AVCodecContext *avctx)
Definition: proresdec.c:587
short DCTELEM
Definition: dsputil.h:39
void ff_proresdsp_init(ProresDSPContext *dsp)
Definition: proresdsp.c:72
int pic_format
2 = 422, 3 = 444
Definition: proresdec.c:60
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
uint8_t level
Definition: svq3.c:125
int prev_slice_sf
scalefactor of the previous decoded slice
Definition: proresdec.c:47
int height
Definition: gxfenc.c:72
common internal api header.
int qmat_changed
1 - global quantization matrices changed
Definition: proresdec.c:63
#define PRORES_BITS_PER_SAMPLE
output precision of prores decoder
Definition: proresdsp.h:28
void * priv_data
Definition: avcodec.h:1382
float re
Definition: fft-test.c:64
uint8_t qmat_chroma[64]
dequantization matrix for chroma
Definition: proresdec.c:62
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:2773
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: avcodec.h:1239
int len
void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
Definition: dsputil.c:122
#define av_log2
Definition: intmath.h:85
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1058
#define FRAME_ID
Definition: proresdata.h:28
int frame_type
0 = progressive, 1 = top-field first, 2 = bottom-field first
Definition: proresdec.c:59
This structure stores compressed data.
Definition: avcodec.h:898
int16_t qmat_luma_scaled[64]
Definition: proresdec.c:49
static int decode_slice_plane(ProresContext *ctx, ProresThreadData *td, const uint8_t *buf, int data_size, uint16_t *out_ptr, int linesize, int mbs_per_slice, int blocks_per_mb, int plane_size_factor, const int16_t *qmat, int is_chroma)
Decode a slice plane (luma or chroma).
Definition: proresdec.c:422