FFmpeg
proresdec2.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2011 Maxim Poliakovski
3  * Copyright (c) 2010-2011 Elvis Presley
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Known FOURCCs: 'apch' (HQ), 'apcn' (SD), 'apcs' (LT), 'apco' (Proxy), 'ap4h' (4444), 'ap4x' (4444 XQ)
25  */
26 
27 //#define DEBUG
28 
29 #define LONG_BITSTREAM_READER
30 
31 #include "config_components.h"
32 
33 #include "libavutil/internal.h"
34 #include "libavutil/mem_internal.h"
35 
36 #include "avcodec.h"
37 #include "codec_internal.h"
38 #include "decode.h"
39 #include "get_bits.h"
40 #include "hwaccel_internal.h"
41 #include "hwconfig.h"
42 #include "idctdsp.h"
43 #include "profiles.h"
44 #include "proresdec.h"
45 #include "proresdata.h"
46 #include "thread.h"
47 
48 #define ALPHA_SHIFT_16_TO_10(alpha_val) (alpha_val >> 6)
49 #define ALPHA_SHIFT_8_TO_10(alpha_val) ((alpha_val << 2) | (alpha_val >> 6))
50 #define ALPHA_SHIFT_16_TO_12(alpha_val) (alpha_val >> 4)
51 #define ALPHA_SHIFT_8_TO_12(alpha_val) ((alpha_val << 4) | (alpha_val >> 4))
52 
53 static void inline unpack_alpha(GetBitContext *gb, uint16_t *dst, int num_coeffs,
54  const int num_bits, const int decode_precision) {
55  const int mask = (1 << num_bits) - 1;
56  int i, idx, val, alpha_val;
57 
58  idx = 0;
59  alpha_val = mask;
60  do {
61  do {
62  if (get_bits1(gb)) {
63  val = get_bits(gb, num_bits);
64  } else {
65  int sign;
66  val = get_bits(gb, num_bits == 16 ? 7 : 4);
67  sign = val & 1;
68  val = (val + 2) >> 1;
69  if (sign)
70  val = -val;
71  }
72  alpha_val = (alpha_val + val) & mask;
73  if (num_bits == 16) {
74  if (decode_precision == 10) {
75  dst[idx++] = ALPHA_SHIFT_16_TO_10(alpha_val);
76  } else { /* 12b */
77  dst[idx++] = ALPHA_SHIFT_16_TO_12(alpha_val);
78  }
79  } else {
80  if (decode_precision == 10) {
81  dst[idx++] = ALPHA_SHIFT_8_TO_10(alpha_val);
82  } else { /* 12b */
83  dst[idx++] = ALPHA_SHIFT_8_TO_12(alpha_val);
84  }
85  }
86  if (idx >= num_coeffs)
87  break;
88  } while (get_bits_left(gb)>0 && get_bits1(gb));
89  val = get_bits(gb, 4);
90  if (!val)
91  val = get_bits(gb, 11);
92  if (idx + val > num_coeffs)
93  val = num_coeffs - idx;
94  if (num_bits == 16) {
95  for (i = 0; i < val; i++) {
96  if (decode_precision == 10) {
97  dst[idx++] = ALPHA_SHIFT_16_TO_10(alpha_val);
98  } else { /* 12b */
99  dst[idx++] = ALPHA_SHIFT_16_TO_12(alpha_val);
100  }
101  }
102  } else {
103  for (i = 0; i < val; i++) {
104  if (decode_precision == 10) {
105  dst[idx++] = ALPHA_SHIFT_8_TO_10(alpha_val);
106  } else { /* 12b */
107  dst[idx++] = ALPHA_SHIFT_8_TO_12(alpha_val);
108  }
109  }
110  }
111  } while (idx < num_coeffs);
112 }
113 
114 static void unpack_alpha_10(GetBitContext *gb, uint16_t *dst, int num_coeffs,
115  const int num_bits)
116 {
117  if (num_bits == 16) {
118  unpack_alpha(gb, dst, num_coeffs, 16, 10);
119  } else { /* 8 bits alpha */
120  unpack_alpha(gb, dst, num_coeffs, 8, 10);
121  }
122 }
123 
124 static void unpack_alpha_12(GetBitContext *gb, uint16_t *dst, int num_coeffs,
125  const int num_bits)
126 {
127  if (num_bits == 16) {
128  unpack_alpha(gb, dst, num_coeffs, 16, 12);
129  } else { /* 8 bits alpha */
130  unpack_alpha(gb, dst, num_coeffs, 8, 12);
131  }
132 }
133 
135 {
136  int ret = 0;
137  ProresContext *ctx = avctx->priv_data;
138  uint8_t idct_permutation[64];
139 
140  avctx->bits_per_raw_sample = 10;
141 
142  switch (avctx->codec_tag) {
143  case MKTAG('a','p','c','o'):
145  break;
146  case MKTAG('a','p','c','s'):
147  avctx->profile = AV_PROFILE_PRORES_LT;
148  break;
149  case MKTAG('a','p','c','n'):
151  break;
152  case MKTAG('a','p','c','h'):
153  avctx->profile = AV_PROFILE_PRORES_HQ;
154  break;
155  case MKTAG('a','p','4','h'):
157  avctx->bits_per_raw_sample = 12;
158  break;
159  case MKTAG('a','p','4','x'):
160  avctx->profile = AV_PROFILE_PRORES_XQ;
161  avctx->bits_per_raw_sample = 12;
162  break;
163  default:
164  avctx->profile = AV_PROFILE_UNKNOWN;
165  av_log(avctx, AV_LOG_WARNING, "Unknown prores profile %d\n", avctx->codec_tag);
166  }
167 
168  if (avctx->bits_per_raw_sample == 10) {
169  av_log(avctx, AV_LOG_DEBUG, "Auto bitdepth precision. Use 10b decoding based on codec tag.\n");
170  } else { /* 12b */
171  av_log(avctx, AV_LOG_DEBUG, "Auto bitdepth precision. Use 12b decoding based on codec tag.\n");
172  }
173 
174  ff_blockdsp_init(&ctx->bdsp);
175  ret = ff_proresdsp_init(&ctx->prodsp, avctx->bits_per_raw_sample);
176  if (ret < 0) {
177  av_log(avctx, AV_LOG_ERROR, "Fail to init proresdsp for bits per raw sample %d\n", avctx->bits_per_raw_sample);
178  return ret;
179  }
180 
181  ff_init_scantable_permutation(idct_permutation,
182  ctx->prodsp.idct_permutation_type);
183 
184  ff_permute_scantable(ctx->progressive_scan, ff_prores_progressive_scan, idct_permutation);
185  ff_permute_scantable(ctx->interlaced_scan, ff_prores_interlaced_scan, idct_permutation);
186 
187  ctx->pix_fmt = AV_PIX_FMT_NONE;
188 
189  if (avctx->bits_per_raw_sample == 10){
190  ctx->unpack_alpha = unpack_alpha_10;
191  } else if (avctx->bits_per_raw_sample == 12){
192  ctx->unpack_alpha = unpack_alpha_12;
193  } else {
194  av_log(avctx, AV_LOG_ERROR, "Fail to set unpack_alpha for bits per raw sample %d\n", avctx->bits_per_raw_sample);
195  return AVERROR_BUG;
196  }
197  return ret;
198 }
199 
200 static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
201  const int data_size, AVCodecContext *avctx)
202 {
203  int hdr_size, width, height, flags;
204  int version;
205  const uint8_t *ptr;
206  enum AVPixelFormat pix_fmt;
207 
208  hdr_size = AV_RB16(buf);
209  ff_dlog(avctx, "header size %d\n", hdr_size);
210  if (hdr_size > data_size) {
211  av_log(avctx, AV_LOG_ERROR, "error, wrong header size\n");
212  return AVERROR_INVALIDDATA;
213  }
214 
215  version = AV_RB16(buf + 2);
216  ff_dlog(avctx, "%.4s version %d\n", buf+4, version);
217  if (version > 1) {
218  av_log(avctx, AV_LOG_ERROR, "unsupported version: %d\n", version);
219  return AVERROR_PATCHWELCOME;
220  }
221 
222  width = AV_RB16(buf + 8);
223  height = AV_RB16(buf + 10);
224 
225  if (width != avctx->width || height != avctx->height) {
226  int ret;
227 
228  av_log(avctx, AV_LOG_WARNING, "picture resolution change: %dx%d -> %dx%d\n",
229  avctx->width, avctx->height, width, height);
230  if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
231  return ret;
232  }
233 
234  ctx->frame_type = (buf[12] >> 2) & 3;
235  ctx->alpha_info = buf[17] & 0xf;
236 
237  if (ctx->alpha_info > 2) {
238  av_log(avctx, AV_LOG_ERROR, "Invalid alpha mode %d\n", ctx->alpha_info);
239  return AVERROR_INVALIDDATA;
240  }
241  if (avctx->skip_alpha) ctx->alpha_info = 0;
242 
243  ff_dlog(avctx, "frame type %d\n", ctx->frame_type);
244 
245  if (ctx->frame_type == 0) {
246  ctx->scan = ctx->progressive_scan; // permuted
247  } else {
248  ctx->scan = ctx->interlaced_scan; // permuted
250  if (ctx->frame_type == 1)
252  }
253 
254  if (ctx->alpha_info) {
255  if (avctx->bits_per_raw_sample == 10) {
256  pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUVA444P10 : AV_PIX_FMT_YUVA422P10;
257  } else { /* 12b */
258  pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUVA444P12 : AV_PIX_FMT_YUVA422P12;
259  }
260  } else {
261  if (avctx->bits_per_raw_sample == 10) {
262  pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUV444P10 : AV_PIX_FMT_YUV422P10;
263  } else { /* 12b */
264  pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUV444P12 : AV_PIX_FMT_YUV422P12;
265  }
266  }
267 
268  if (pix_fmt != ctx->pix_fmt) {
269 #define HWACCEL_MAX (CONFIG_PRORES_VIDEOTOOLBOX_HWACCEL)
270  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
271  int ret;
272 
273  ctx->pix_fmt = pix_fmt;
274 
275 #if CONFIG_PRORES_VIDEOTOOLBOX_HWACCEL
276  *fmtp++ = AV_PIX_FMT_VIDEOTOOLBOX;
277 #endif
278  *fmtp++ = ctx->pix_fmt;
279  *fmtp = AV_PIX_FMT_NONE;
280 
281  if ((ret = ff_get_format(avctx, pix_fmts)) < 0)
282  return ret;
283 
284  avctx->pix_fmt = ret;
285  }
286 
287  ctx->frame->color_primaries = buf[14];
288  ctx->frame->color_trc = buf[15];
289  ctx->frame->colorspace = buf[16];
290  ctx->frame->color_range = AVCOL_RANGE_MPEG;
291 
292  ptr = buf + 20;
293  flags = buf[19];
294  ff_dlog(avctx, "flags %x\n", flags);
295 
296  if (flags & 2) {
297  if(buf + data_size - ptr < 64) {
298  av_log(avctx, AV_LOG_ERROR, "Header truncated\n");
299  return AVERROR_INVALIDDATA;
300  }
301  ff_permute_scantable(ctx->qmat_luma, ctx->prodsp.idct_permutation, ptr);
302  ptr += 64;
303  } else {
304  memset(ctx->qmat_luma, 4, 64);
305  }
306 
307  if (flags & 1) {
308  if(buf + data_size - ptr < 64) {
309  av_log(avctx, AV_LOG_ERROR, "Header truncated\n");
310  return AVERROR_INVALIDDATA;
311  }
312  ff_permute_scantable(ctx->qmat_chroma, ctx->prodsp.idct_permutation, ptr);
313  } else {
314  memcpy(ctx->qmat_chroma, ctx->qmat_luma, 64);
315  }
316 
317  return hdr_size;
318 }
319 
320 static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, const int buf_size)
321 {
322  ProresContext *ctx = avctx->priv_data;
323  int i, hdr_size, slice_count;
324  unsigned pic_data_size;
325  int log2_slice_mb_width, log2_slice_mb_height;
326  int slice_mb_count, mb_x, mb_y;
327  const uint8_t *data_ptr, *index_ptr;
328 
329  hdr_size = buf[0] >> 3;
330  if (hdr_size < 8 || hdr_size > buf_size) {
331  av_log(avctx, AV_LOG_ERROR, "error, wrong picture header size\n");
332  return AVERROR_INVALIDDATA;
333  }
334 
335  pic_data_size = AV_RB32(buf + 1);
336  if (pic_data_size > buf_size) {
337  av_log(avctx, AV_LOG_ERROR, "error, wrong picture data size\n");
338  return AVERROR_INVALIDDATA;
339  }
340 
341  log2_slice_mb_width = buf[7] >> 4;
342  log2_slice_mb_height = buf[7] & 0xF;
343  if (log2_slice_mb_width > 3 || log2_slice_mb_height) {
344  av_log(avctx, AV_LOG_ERROR, "unsupported slice resolution: %dx%d\n",
345  1 << log2_slice_mb_width, 1 << log2_slice_mb_height);
346  return AVERROR_INVALIDDATA;
347  }
348 
349  ctx->mb_width = (avctx->width + 15) >> 4;
350  if (ctx->frame_type)
351  ctx->mb_height = (avctx->height + 31) >> 5;
352  else
353  ctx->mb_height = (avctx->height + 15) >> 4;
354 
355  // QT ignores the written value
356  // slice_count = AV_RB16(buf + 5);
357  slice_count = ctx->mb_height * ((ctx->mb_width >> log2_slice_mb_width) +
358  av_popcount(ctx->mb_width & (1 << log2_slice_mb_width) - 1));
359 
360  if (ctx->slice_count != slice_count || !ctx->slices) {
361  av_freep(&ctx->slices);
362  ctx->slice_count = 0;
363  ctx->slices = av_calloc(slice_count, sizeof(*ctx->slices));
364  if (!ctx->slices)
365  return AVERROR(ENOMEM);
366  ctx->slice_count = slice_count;
367  }
368 
369  if (!slice_count)
370  return AVERROR(EINVAL);
371 
372  if (hdr_size + slice_count*2 > buf_size) {
373  av_log(avctx, AV_LOG_ERROR, "error, wrong slice count\n");
374  return AVERROR_INVALIDDATA;
375  }
376 
377  // parse slice information
378  index_ptr = buf + hdr_size;
379  data_ptr = index_ptr + slice_count*2;
380 
381  slice_mb_count = 1 << log2_slice_mb_width;
382  mb_x = 0;
383  mb_y = 0;
384 
385  for (i = 0; i < slice_count; i++) {
386  SliceContext *slice = &ctx->slices[i];
387 
388  slice->data = data_ptr;
389  data_ptr += AV_RB16(index_ptr + i*2);
390 
391  while (ctx->mb_width - mb_x < slice_mb_count)
392  slice_mb_count >>= 1;
393 
394  slice->mb_x = mb_x;
395  slice->mb_y = mb_y;
396  slice->mb_count = slice_mb_count;
397  slice->data_size = data_ptr - slice->data;
398 
399  if (slice->data_size < 6) {
400  av_log(avctx, AV_LOG_ERROR, "error, wrong slice data size\n");
401  return AVERROR_INVALIDDATA;
402  }
403 
404  mb_x += slice_mb_count;
405  if (mb_x == ctx->mb_width) {
406  slice_mb_count = 1 << log2_slice_mb_width;
407  mb_x = 0;
408  mb_y++;
409  }
410  if (data_ptr > buf + buf_size) {
411  av_log(avctx, AV_LOG_ERROR, "error, slice out of bounds\n");
412  return AVERROR_INVALIDDATA;
413  }
414  }
415 
416  if (mb_x || mb_y != ctx->mb_height) {
417  av_log(avctx, AV_LOG_ERROR, "error wrong mb count y %d h %d\n",
418  mb_y, ctx->mb_height);
419  return AVERROR_INVALIDDATA;
420  }
421 
422  return pic_data_size;
423 }
424 
425 #define DECODE_CODEWORD(val, codebook, SKIP) \
426  do { \
427  unsigned int rice_order, exp_order, switch_bits; \
428  unsigned int q, buf, bits; \
429  \
430  UPDATE_CACHE(re, gb); \
431  buf = GET_CACHE(re, gb); \
432  \
433  /* number of bits to switch between rice and exp golomb */ \
434  switch_bits = codebook & 3; \
435  rice_order = codebook >> 5; \
436  exp_order = (codebook >> 2) & 7; \
437  \
438  q = 31 - av_log2(buf); \
439  \
440  if (q > switch_bits) { /* exp golomb */ \
441  bits = exp_order - switch_bits + (q<<1); \
442  if (bits > FFMIN(MIN_CACHE_BITS, 31)) \
443  return AVERROR_INVALIDDATA; \
444  val = SHOW_UBITS(re, gb, bits) - (1 << exp_order) + \
445  ((switch_bits + 1) << rice_order); \
446  SKIP(re, gb, bits); \
447  } else if (rice_order) { \
448  SKIP_BITS(re, gb, q+1); \
449  val = (q << rice_order) + SHOW_UBITS(re, gb, rice_order); \
450  SKIP(re, gb, rice_order); \
451  } else { \
452  val = q; \
453  SKIP(re, gb, q+1); \
454  } \
455  } while (0)
456 
457 #define TOSIGNED(x) (((x) >> 1) ^ (-((x) & 1)))
458 
459 #define FIRST_DC_CB 0xB8
460 
461 static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70};
462 
464  int blocks_per_slice)
465 {
466  int16_t prev_dc;
467  int code, i, sign;
468 
469  OPEN_READER(re, gb);
470 
472  prev_dc = TOSIGNED(code);
473  out[0] = prev_dc;
474 
475  out += 64; // dc coeff for the next block
476 
477  code = 5;
478  sign = 0;
479  for (i = 1; i < blocks_per_slice; i++, out += 64) {
481  if(code) sign ^= -(code & 1);
482  else sign = 0;
483  prev_dc += (((code + 1) >> 1) ^ sign) - sign;
484  out[0] = prev_dc;
485  }
486  CLOSE_READER(re, gb);
487  return 0;
488 }
489 
490 // adaptive codebook switching lut according to previous run/level values
491 static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };
492 static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };
493 
495  int16_t *out, int blocks_per_slice)
496 {
497  const ProresContext *ctx = avctx->priv_data;
498  int block_mask, sign;
499  unsigned pos, run, level;
500  int max_coeffs, i, bits_left;
501  int log2_block_count = av_log2(blocks_per_slice);
502 
503  OPEN_READER(re, gb);
504  UPDATE_CACHE(re, gb); \
505  run = 4;
506  level = 2;
507 
508  max_coeffs = 64 << log2_block_count;
509  block_mask = blocks_per_slice - 1;
510 
511  for (pos = block_mask;;) {
512  bits_left = gb->size_in_bits - re_index;
513  if (!bits_left || (bits_left < 32 && !SHOW_UBITS(re, gb, bits_left)))
514  break;
515 
517  pos += run + 1;
518  if (pos >= max_coeffs) {
519  av_log(avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", pos, max_coeffs);
520  return AVERROR_INVALIDDATA;
521  }
522 
524  level += 1;
525 
526  i = pos >> log2_block_count;
527 
528  sign = SHOW_SBITS(re, gb, 1);
529  SKIP_BITS(re, gb, 1);
530  out[((pos & block_mask) << 6) + ctx->scan[i]] = ((level ^ sign) - sign);
531  }
532 
533  CLOSE_READER(re, gb);
534  return 0;
535 }
536 
538  uint16_t *dst, int dst_stride,
539  const uint8_t *buf, unsigned buf_size,
540  const int16_t *qmat)
541 {
542  const ProresContext *ctx = avctx->priv_data;
543  LOCAL_ALIGNED_32(int16_t, blocks, [8*4*64]);
544  int16_t *block;
545  GetBitContext gb;
546  int i, blocks_per_slice = slice->mb_count<<2;
547  int ret;
548 
549  for (i = 0; i < blocks_per_slice; i++)
550  ctx->bdsp.clear_block(blocks+(i<<6));
551 
552  init_get_bits(&gb, buf, buf_size << 3);
553 
554  if ((ret = decode_dc_coeffs(&gb, blocks, blocks_per_slice)) < 0)
555  return ret;
556  if ((ret = decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice)) < 0)
557  return ret;
558 
559  block = blocks;
560  for (i = 0; i < slice->mb_count; i++) {
561  ctx->prodsp.idct_put(dst, dst_stride, block+(0<<6), qmat);
562  ctx->prodsp.idct_put(dst +8, dst_stride, block+(1<<6), qmat);
563  ctx->prodsp.idct_put(dst+4*dst_stride , dst_stride, block+(2<<6), qmat);
564  ctx->prodsp.idct_put(dst+4*dst_stride+8, dst_stride, block+(3<<6), qmat);
565  block += 4*64;
566  dst += 16;
567  }
568  return 0;
569 }
570 
572  uint16_t *dst, int dst_stride,
573  const uint8_t *buf, unsigned buf_size,
574  const int16_t *qmat, int log2_blocks_per_mb)
575 {
576  ProresContext *ctx = avctx->priv_data;
577  LOCAL_ALIGNED_32(int16_t, blocks, [8*4*64]);
578  int16_t *block;
579  GetBitContext gb;
580  int i, j, blocks_per_slice = slice->mb_count << log2_blocks_per_mb;
581  int ret;
582 
583  for (i = 0; i < blocks_per_slice; i++)
584  ctx->bdsp.clear_block(blocks+(i<<6));
585 
586  init_get_bits(&gb, buf, buf_size << 3);
587 
588  if ((ret = decode_dc_coeffs(&gb, blocks, blocks_per_slice)) < 0)
589  return ret;
590  if ((ret = decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice)) < 0)
591  return ret;
592 
593  block = blocks;
594  for (i = 0; i < slice->mb_count; i++) {
595  for (j = 0; j < log2_blocks_per_mb; j++) {
596  ctx->prodsp.idct_put(dst, dst_stride, block+(0<<6), qmat);
597  ctx->prodsp.idct_put(dst+4*dst_stride, dst_stride, block+(1<<6), qmat);
598  block += 2*64;
599  dst += 8;
600  }
601  }
602  return 0;
603 }
604 
605 /**
606  * Decode alpha slice plane.
607  */
609  uint16_t *dst, int dst_stride,
610  const uint8_t *buf, int buf_size,
611  int blocks_per_slice)
612 {
613  GetBitContext gb;
614  int i;
615  LOCAL_ALIGNED_32(int16_t, blocks, [8*4*64]);
616  int16_t *block;
617 
618  for (i = 0; i < blocks_per_slice<<2; i++)
619  ctx->bdsp.clear_block(blocks+(i<<6));
620 
621  init_get_bits(&gb, buf, buf_size << 3);
622 
623  if (ctx->alpha_info == 2) {
624  ctx->unpack_alpha(&gb, blocks, blocks_per_slice * 4 * 64, 16);
625  } else {
626  ctx->unpack_alpha(&gb, blocks, blocks_per_slice * 4 * 64, 8);
627  }
628 
629  block = blocks;
630 
631  for (i = 0; i < 16; i++) {
632  memcpy(dst, block, 16 * blocks_per_slice * sizeof(*dst));
633  dst += dst_stride >> 1;
634  block += 16 * blocks_per_slice;
635  }
636 }
637 
638 static int decode_slice_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
639 {
640  const ProresContext *ctx = avctx->priv_data;
641  SliceContext *slice = &ctx->slices[jobnr];
642  const uint8_t *buf = slice->data;
643  AVFrame *pic = ctx->frame;
644  int i, hdr_size, qscale, log2_chroma_blocks_per_mb;
645  int luma_stride, chroma_stride;
646  int y_data_size, u_data_size, v_data_size, a_data_size, offset;
647  uint8_t *dest_y, *dest_u, *dest_v;
648  LOCAL_ALIGNED_16(int16_t, qmat_luma_scaled, [64]);
649  LOCAL_ALIGNED_16(int16_t, qmat_chroma_scaled,[64]);
650  int mb_x_shift;
651  int ret;
652  uint16_t val_no_chroma;
653 
654  slice->ret = -1;
655  //av_log(avctx, AV_LOG_INFO, "slice %d mb width %d mb x %d y %d\n",
656  // jobnr, slice->mb_count, slice->mb_x, slice->mb_y);
657 
658  // slice header
659  hdr_size = buf[0] >> 3;
660  qscale = av_clip(buf[1], 1, 224);
661  qscale = qscale > 128 ? qscale - 96 << 2: qscale;
662  y_data_size = AV_RB16(buf + 2);
663  u_data_size = AV_RB16(buf + 4);
664  v_data_size = slice->data_size - y_data_size - u_data_size - hdr_size;
665  if (hdr_size > 7) v_data_size = AV_RB16(buf + 6);
666  a_data_size = slice->data_size - y_data_size - u_data_size -
667  v_data_size - hdr_size;
668 
669  if (y_data_size < 0 || u_data_size < 0 || v_data_size < 0
670  || hdr_size+y_data_size+u_data_size+v_data_size > slice->data_size){
671  av_log(avctx, AV_LOG_ERROR, "invalid plane data size\n");
672  return AVERROR_INVALIDDATA;
673  }
674 
675  buf += hdr_size;
676 
677  for (i = 0; i < 64; i++) {
678  qmat_luma_scaled [i] = ctx->qmat_luma [i] * qscale;
679  qmat_chroma_scaled[i] = ctx->qmat_chroma[i] * qscale;
680  }
681 
682  if (ctx->frame_type == 0) {
683  luma_stride = pic->linesize[0];
684  chroma_stride = pic->linesize[1];
685  } else {
686  luma_stride = pic->linesize[0] << 1;
687  chroma_stride = pic->linesize[1] << 1;
688  }
689 
690  if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10 || avctx->pix_fmt == AV_PIX_FMT_YUVA444P10 ||
692  mb_x_shift = 5;
693  log2_chroma_blocks_per_mb = 2;
694  } else {
695  mb_x_shift = 4;
696  log2_chroma_blocks_per_mb = 1;
697  }
698 
699  offset = (slice->mb_y << 4) * luma_stride + (slice->mb_x << 5);
700  dest_y = pic->data[0] + offset;
701  dest_u = pic->data[1] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << mb_x_shift);
702  dest_v = pic->data[2] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << mb_x_shift);
703 
704  if (ctx->frame_type && ctx->first_field ^ !!(ctx->frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST)) {
705  dest_y += pic->linesize[0];
706  dest_u += pic->linesize[1];
707  dest_v += pic->linesize[2];
708  offset += pic->linesize[3];
709  }
710 
711  ret = decode_slice_luma(avctx, slice, (uint16_t*)dest_y, luma_stride,
712  buf, y_data_size, qmat_luma_scaled);
713  if (ret < 0)
714  return ret;
715 
716  if (!(avctx->flags & AV_CODEC_FLAG_GRAY) && (u_data_size + v_data_size) > 0) {
717  ret = decode_slice_chroma(avctx, slice, (uint16_t*)dest_u, chroma_stride,
718  buf + y_data_size, u_data_size,
719  qmat_chroma_scaled, log2_chroma_blocks_per_mb);
720  if (ret < 0)
721  return ret;
722 
723  ret = decode_slice_chroma(avctx, slice, (uint16_t*)dest_v, chroma_stride,
724  buf + y_data_size + u_data_size, v_data_size,
725  qmat_chroma_scaled, log2_chroma_blocks_per_mb);
726  if (ret < 0)
727  return ret;
728  }
729  else {
730  size_t mb_max_x = slice->mb_count << (mb_x_shift - 1);
731  size_t i, j;
732  if (avctx->bits_per_raw_sample == 10) {
733  val_no_chroma = 511;
734  } else { /* 12b */
735  val_no_chroma = 511 * 4;
736  }
737  for (i = 0; i < 16; ++i)
738  for (j = 0; j < mb_max_x; ++j) {
739  *(uint16_t*)(dest_u + (i * chroma_stride) + (j << 1)) = val_no_chroma;
740  *(uint16_t*)(dest_v + (i * chroma_stride) + (j << 1)) = val_no_chroma;
741  }
742  }
743 
744  /* decode alpha plane if available */
745  if (ctx->alpha_info && pic->data[3] && a_data_size) {
746  uint8_t *dest_a = pic->data[3] + offset;
747  decode_slice_alpha(ctx, (uint16_t*)dest_a, luma_stride,
748  buf + y_data_size + u_data_size + v_data_size,
749  a_data_size, slice->mb_count);
750  }
751 
752  slice->ret = 0;
753  return 0;
754 }
755 
756 static int decode_picture(AVCodecContext *avctx)
757 {
758  ProresContext *ctx = avctx->priv_data;
759  int i;
760  int error = 0;
761 
762  avctx->execute2(avctx, decode_slice_thread, NULL, NULL, ctx->slice_count);
763 
764  for (i = 0; i < ctx->slice_count; i++)
765  error += ctx->slices[i].ret < 0;
766 
767  if (error)
768  ctx->frame->decode_error_flags = FF_DECODE_ERROR_INVALID_BITSTREAM;
769  if (error < ctx->slice_count)
770  return 0;
771 
772  return ctx->slices[0].ret;
773 }
774 
776  int *got_frame, AVPacket *avpkt)
777 {
778  ProresContext *ctx = avctx->priv_data;
779  const uint8_t *buf = avpkt->data;
780  int buf_size = avpkt->size;
781  int frame_hdr_size, pic_size, ret;
782 
783  if (buf_size < 28 || AV_RL32(buf + 4) != AV_RL32("icpf")) {
784  av_log(avctx, AV_LOG_ERROR, "invalid frame header\n");
785  return AVERROR_INVALIDDATA;
786  }
787 
788  ctx->frame = frame;
789  ctx->frame->pict_type = AV_PICTURE_TYPE_I;
790  ctx->frame->flags |= AV_FRAME_FLAG_KEY;
791  ctx->first_field = 1;
792 
793  buf += 8;
794  buf_size -= 8;
795 
796  frame_hdr_size = decode_frame_header(ctx, buf, buf_size, avctx);
797  if (frame_hdr_size < 0)
798  return frame_hdr_size;
799 
800  buf += frame_hdr_size;
801  buf_size -= frame_hdr_size;
802 
803  if ((ret = ff_thread_get_buffer(avctx, frame, 0)) < 0)
804  return ret;
805  ff_thread_finish_setup(avctx);
806 
807  if (avctx->hwaccel) {
808  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
809  ret = hwaccel->start_frame(avctx, NULL, 0);
810  if (ret < 0)
811  return ret;
812  ret = hwaccel->decode_slice(avctx, avpkt->data, avpkt->size);
813  if (ret < 0)
814  return ret;
815  ret = hwaccel->end_frame(avctx);
816  if (ret < 0)
817  return ret;
818  goto finish;
819  }
820 
822  pic_size = decode_picture_header(avctx, buf, buf_size);
823  if (pic_size < 0) {
824  av_log(avctx, AV_LOG_ERROR, "error decoding picture header\n");
825  return pic_size;
826  }
827 
828  if ((ret = decode_picture(avctx)) < 0) {
829  av_log(avctx, AV_LOG_ERROR, "error decoding picture\n");
830  return ret;
831  }
832 
833  buf += pic_size;
834  buf_size -= pic_size;
835 
836  if (ctx->frame_type && buf_size > 0 && ctx->first_field) {
837  ctx->first_field = 0;
838  goto decode_picture;
839  }
840 
841 finish:
842  *got_frame = 1;
843 
844  return avpkt->size;
845 }
846 
848 {
849  ProresContext *ctx = avctx->priv_data;
850 
851  av_freep(&ctx->slices);
852 
853  return 0;
854 }
855 
856 #if HAVE_THREADS
858 {
859  ProresContext *csrc = src->priv_data;
860  ProresContext *cdst = dst->priv_data;
861 
862  cdst->pix_fmt = csrc->pix_fmt;
863 
864  return 0;
865 }
866 #endif
867 
869  .p.name = "prores",
870  CODEC_LONG_NAME("Apple ProRes (iCodec Pro)"),
871  .p.type = AVMEDIA_TYPE_VIDEO,
872  .p.id = AV_CODEC_ID_PRORES,
873  .priv_data_size = sizeof(ProresContext),
874  .init = decode_init,
875  .close = decode_close,
880  .hw_configs = (const AVCodecHWConfigInternal *const []) {
881 #if CONFIG_PRORES_VIDEOTOOLBOX_HWACCEL
882  HWACCEL_VIDEOTOOLBOX(prores),
883 #endif
884  NULL
885  },
886 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
hwconfig.h
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1435
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
DECODE_CODEWORD
#define DECODE_CODEWORD(val, codebook, SKIP)
Definition: proresdec2.c:425
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
level
uint8_t level
Definition: svq3.c:204
av_clip
#define av_clip
Definition: common.h:96
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
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
mem_internal.h
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1264
out
FILE * out
Definition: movenc.c:54
ff_prores_profiles
const AVProfile ff_prores_profiles[]
Definition: profiles.c:172
GetBitContext::size_in_bits
int size_in_bits
Definition: get_bits.h:111
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVPacket::data
uint8_t * data
Definition: packet.h:491
ProresContext
Definition: proresdec.h:43
TOSIGNED
#define TOSIGNED(x)
Definition: proresdec2.c:457
SliceContext::mb_x
unsigned mb_x
Definition: proresdec.h:36
FFCodec
Definition: codec_internal.h:127
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:225
av_popcount
#define av_popcount
Definition: common.h:150
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:94
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:507
ff_prores_progressive_scan
const uint8_t ff_prores_progressive_scan[64]
Definition: proresdata.c:25
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:514
thread.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
ff_thread_get_buffer
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 so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in FFCodec caps_internal and use ff_thread_get_buffer() to allocate frames. Otherwise decode directly into the user-supplied frames. Call ff_thread_report_progress() 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
AV_PROFILE_PRORES_STANDARD
#define AV_PROFILE_PRORES_STANDARD
Definition: defs.h:181
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:641
ff_permute_scantable
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
Definition: idctdsp.c:30
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
AV_PROFILE_PRORES_HQ
#define AV_PROFILE_PRORES_HQ
Definition: defs.h:182
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
finish
static void finish(void)
Definition: movenc.c:342
FFHWAccel
Definition: hwaccel_internal.h:34
ProresContext::pix_fmt
enum AVPixelFormat pix_fmt
Definition: proresdec.h:60
GetBitContext
Definition: get_bits.h:108
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:521
FFHWAccel::end_frame
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
Definition: hwaccel_internal.h:97
proresdec.h
val
static double val(void *priv, double ch)
Definition: aeval.c:78
ALPHA_SHIFT_8_TO_10
#define ALPHA_SHIFT_8_TO_10(alpha_val)
Definition: proresdec2.c:49
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:471
FFHWAccel::start_frame
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
Definition: hwaccel_internal.h:59
unpack_alpha
static void unpack_alpha(GetBitContext *gb, uint16_t *dst, int num_coeffs, const int num_bits, const int decode_precision)
Definition: proresdec2.c:53
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
ff_prores_decoder
const FFCodec ff_prores_decoder
Definition: proresdec2.c:868
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
FIRST_DC_CB
#define FIRST_DC_CB
Definition: proresdec2.c:459
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:628
mask
static const uint16_t mask[17]
Definition: lzw.c:38
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:188
decode_picture_header
static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, const int buf_size)
Definition: proresdec2.c:320
width
#define width
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
ff_blockdsp_init
av_cold void ff_blockdsp_init(BlockDSPContext *c)
Definition: blockdsp.c:58
SliceContext::data_size
unsigned data_size
Definition: proresdec.h:39
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1233
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
decode_picture
static int decode_picture(AVCodecContext *avctx)
Definition: proresdec2.c:756
SHOW_SBITS
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:260
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:129
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:510
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1517
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
decode.h
get_bits.h
SKIP_BITS
#define SKIP_BITS(name, gb, num)
Definition: get_bits.h:241
ff_prores_interlaced_scan
const uint8_t ff_prores_interlaced_scan[64]
Definition: proresdata.c:36
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
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
ff_proresdsp_init
av_cold int ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample)
Definition: proresdsp.c:79
NULL
#define NULL
Definition: coverity.c:32
FF_DECODE_ERROR_INVALID_BITSTREAM
#define FF_DECODE_ERROR_INVALID_BITSTREAM
Definition: frame.h:718
bits_left
#define bits_left
Definition: bitstream.h:114
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:135
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
run
uint8_t run
Definition: svq3.c:203
hwaccel_internal.h
decode_ac_coeffs
static av_always_inline int decode_ac_coeffs(AVCodecContext *avctx, GetBitContext *gb, int16_t *out, int blocks_per_slice)
Definition: proresdec2.c:494
SliceContext::ret
int ret
Definition: proresdec.h:40
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
run_to_cb
static const uint8_t run_to_cb[16]
Definition: proresdec2.c:491
profiles.h
SliceContext::mb_y
unsigned mb_y
Definition: proresdec.h:37
LAST_SKIP_BITS
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:247
UPDATE_THREAD_CONTEXT
#define UPDATE_THREAD_CONTEXT(func)
Definition: codec_internal.h:281
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:469
decode_slice_chroma
static int decode_slice_chroma(AVCodecContext *avctx, SliceContext *slice, uint16_t *dst, int dst_stride, const uint8_t *buf, unsigned buf_size, const int16_t *qmat, int log2_blocks_per_mb)
Definition: proresdec2.c:571
AV_PROFILE_PRORES_LT
#define AV_PROFILE_PRORES_LT
Definition: defs.h:180
SliceContext
Definition: mss12.h:70
decode_slice_luma
static int decode_slice_luma(AVCodecContext *avctx, SliceContext *slice, uint16_t *dst, int dst_stride, const uint8_t *buf, unsigned buf_size, const int16_t *qmat)
Definition: proresdec2.c:537
dc_codebook
static const uint8_t dc_codebook[7]
Definition: proresdec2.c:461
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
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
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:318
AVPacket::size
int size
Definition: packet.h:492
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
codec_internal.h
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:473
SliceContext::mb_count
unsigned mb_count
Definition: proresdec.h:38
ALPHA_SHIFT_16_TO_12
#define ALPHA_SHIFT_16_TO_12(alpha_val)
Definition: proresdec2.c:50
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
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:475
proresdata.h
ALPHA_SHIFT_8_TO_12
#define ALPHA_SHIFT_8_TO_12(alpha_val)
Definition: proresdec2.c:51
AVCodecContext::skip_alpha
int skip_alpha
Skip processing alpha if supported by codec.
Definition: avcodec.h:1867
decode_close
static av_cold int decode_close(AVCodecContext *avctx)
Definition: proresdec2.c:847
AVCodecHWConfigInternal
Definition: hwconfig.h:25
decode_frame_header
static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, const int data_size, AVCodecContext *avctx)
Definition: proresdec2.c:200
OPEN_READER
#define OPEN_READER(name, gb)
Definition: get_bits.h:177
AV_PROFILE_PRORES_4444
#define AV_PROFILE_PRORES_4444
Definition: defs.h:183
height
#define height
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:114
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:508
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
version
version
Definition: libkvazaar.c:321
AV_PROFILE_PRORES_PROXY
#define AV_PROFILE_PRORES_PROXY
Definition: defs.h:179
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:302
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
internal.h
SliceContext::data
const uint8_t * data
Definition: proresdec.h:35
HWACCEL_MAX
#define HWACCEL_MAX
av_always_inline
#define av_always_inline
Definition: attributes.h:49
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: proresdec2.c:775
decode_slice_alpha
static void decode_slice_alpha(const ProresContext *ctx, uint16_t *dst, int dst_stride, const uint8_t *buf, int buf_size, int blocks_per_slice)
Decode alpha slice plane.
Definition: proresdec2.c:608
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
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. If there are inter-frame dependencies
AVCodecContext::height
int height
Definition: avcodec.h:621
lev_to_cb
static const uint8_t lev_to_cb[10]
Definition: proresdec2.c:492
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:658
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:636
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:656
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
HWACCEL_VIDEOTOOLBOX
#define HWACCEL_VIDEOTOOLBOX(codec)
Definition: hwconfig.h:74
idctdsp.h
avcodec.h
ret
ret
Definition: filter_design.txt:187
unpack_alpha_10
static void unpack_alpha_10(GetBitContext *gb, uint16_t *dst, int num_coeffs, const int num_bits)
Definition: proresdec2.c:114
pos
unsigned int pos
Definition: spdifenc.c:413
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
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
AVCodecContext
main external API structure.
Definition: avcodec.h:441
ALPHA_SHIFT_16_TO_10
#define ALPHA_SHIFT_16_TO_10(alpha_val)
Definition: proresdec2.c:48
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:259
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:509
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1596
ffhwaccel
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
Definition: hwaccel_internal.h:166
FFHWAccel::decode_slice
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
Definition: hwaccel_internal.h:86
decode_dc_coeffs
static av_always_inline int decode_dc_coeffs(GetBitContext *gb, int16_t *out, int blocks_per_slice)
Definition: proresdec2.c:463
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
decode_slice_thread
static int decode_slice_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
Definition: proresdec2.c:638
ff_init_scantable_permutation
av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation, enum idct_permutation_type perm_type)
Definition: idctdsp.c:39
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: proresdec2.c:134
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:466
AVPacket
This structure stores compressed data.
Definition: packet.h:468
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:468
unpack_alpha_12
static void unpack_alpha_12(GetBitContext *gb, uint16_t *dst, int num_coeffs, const int num_bits)
Definition: proresdec2.c:124
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
AV_PROFILE_PRORES_XQ
#define AV_PROFILE_PRORES_XQ
Definition: defs.h:184
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
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:385
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
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
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
AVCodecContext::execute2
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
Definition: avcodec.h:1581
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
AV_CODEC_ID_PRORES
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:200
AV_RB16
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_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:98