FFmpeg
Loading...
Searching...
No Matches
prores_raw.c
Go to the documentation of this file.
1/*
2 * ProRes RAW decoder
3 * Copyright (c) 2023-2025 Paul B Mahol
4 * Copyright (c) 2025 Lynne
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#include "libavutil/avassert.h"
24#include "libavutil/intfloat.h"
27#include "libavutil/mem.h"
29#include "libavutil/rational.h"
30
31#define CACHED_BITSTREAM_READER !ARCH_X86_32
32
33#include "config_components.h"
34#include "avcodec.h"
35#include "bytestream.h"
36#include "codec_internal.h"
37#include "decode.h"
38#include "get_bits.h"
39#include "proresdata.h"
40#include "thread.h"
41#include "hwconfig.h"
42#include "hwaccel_internal.h"
43
44#include "prores_raw.h"
45
47{
49
50 /* The codec outputs linear data, with the transfer function of the
51 * camera and any adjustments built into an 8-point linearization curve */
52 avctx->bits_per_raw_sample = 16;
56
57 s->pix_fmt = AV_PIX_FMT_NONE;
58
59 ff_blockdsp_init(&s->bdsp);
60 ff_proresdsp_init(&s->prodsp, 12);
61
62 return 0;
63}
64
65/* Decodes a symbol from the next 32 bits, zero-filled past the end of the
66 * data. Returns a negative value once those are all zero, which is where
67 * the reference decoder stops decoding a component. */
69{
70 const int switch_bits = codebook >> 8;
71 const int rice_order = codebook & 0xf;
72 const int exp_order = (codebook >> 4) & 0xf;
73 int left = get_bits_left(gb);
74 uint32_t b;
75 int q, bits;
76
77 b = show_bits_long(gb, 32);
78 if (left < 32) {
79 /* The reader has read past the end of the data; mask that off */
80 if (left <= 0)
81 return -1;
82 b &= 0xFFFFFFFFu << (32 - left);
83 }
84 if (!b)
85 return -1;
86
87 q = ff_clz(b);
88
89 if (b & 0x80000000) {
90 skip_bits_long(gb, 1 + rice_order);
91 return (b & 0x7FFFFFFF) >> (31 - rice_order);
92 }
93
94 if (q <= switch_bits) {
95 skip_bits_long(gb, 1 + rice_order + q);
96 return (q << rice_order) +
97 (((b << (q + 1)) >> 1) >> (31 - rice_order));
98 }
99
100 /* No valid code is longer than the window */
101 bits = exp_order + (q << 1) - switch_bits;
102 if (bits > 32)
103 return -1;
104 skip_bits_long(gb, bits);
105 return (b >> (32 - bits)) +
106 ((switch_bits + 1) << rice_order) -
107 (1 << exp_order);
108}
109
110#define TODCCODEBOOK(x) ((x + 1) >> 1)
111
112#define DC_CB_MAX 12
113const uint8_t ff_prores_raw_dc_cb[DC_CB_MAX + 1] = {
114 0x010, 0x021, 0x032, 0x033, 0x033, 0x033, 0x044, 0x044, 0x044, 0x044, 0x044, 0x044, 0x076,
115};
116
117#define AC_CB_MAX 94
118const int16_t ff_prores_raw_ac_cb[AC_CB_MAX + 1] = {
119 0x000, 0x211, 0x111, 0x111, 0x222, 0x222, 0x222, 0x122, 0x122, 0x122,
120 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x133, 0x133,
121 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244,
122 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244, 0x244,
123 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355,
124 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355,
125 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355,
126 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x355, 0x166,
127};
128
129#define RN_CB_MAX 27
130const int16_t ff_prores_raw_rn_cb[RN_CB_MAX + 1] = {
131 0x200, 0x100, 0x000, 0x000, 0x211, 0x211, 0x111, 0x111, 0x011, 0x011, 0x021, 0x021, 0x222, 0x022,
132 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x022, 0x032, 0x032, 0x044
133};
134
135#define LN_CB_MAX 14
136const int16_t ff_prores_raw_ln_cb[LN_CB_MAX + 1] = {
137 0x100, 0x111, 0x222, 0x222, 0x122, 0x122, 0x433, 0x433, 0x233, 0x233, 0x233, 0x233, 0x233, 0x233, 0x033,
138};
139
141 AVFrame *frame, const uint8_t *data, int size,
142 int component, int16_t *qmat)
143{
144 int ret;
145 ProResRAWContext *s = avctx->priv_data;
146 const ptrdiff_t linesize = frame->linesize[0] >> 1;
147 uint16_t *dst = (uint16_t *)(frame->data[0] + tile->y*frame->linesize[0] + 2*tile->x);
148
149 int idx;
150 const int log2_nb_blocks = tile->log2_nb_blocks;
151 const int nb_blocks = 1 << log2_nb_blocks;
152 const int block_mask = nb_blocks - 1;
153 const int nb_codes = 64 * nb_blocks;
154
155 LOCAL_ALIGNED_32(int32_t, block, [64*16]);
156
157 int sign = 0;
158 int dc_add = 0;
159 int16_t dc_codebook;
160
161 int ac, rn, ln;
162 int16_t ac_codebook = 49;
163 int16_t rn_codebook = 0;
164 int16_t ln_codebook = 66;
165
166 const uint8_t *scan = ff_prores_interlaced_scan;
167 GetBitContext gb;
168
169 if (component > 1)
170 dst += linesize;
171 dst += component & 1;
172
173 if ((ret = init_get_bits8(&gb, data, size)) < 0)
174 return ret;
175
176 memset(block, 0, nb_blocks * 64 * sizeof(*block));
177
178 /* Special handling for first block */
179 int dc = get_value(&gb, 700);
180 if (dc < 0)
181 goto end;
182 int prev_dc = (dc >> 1) ^ -(dc & 1);
183 block[0] = prev_dc;
184
185 for (int n = 1; n < nb_blocks; n++) {
186 if ((n & 15) == 1)
187 dc_codebook = 100;
188 else
190
191 dc = get_value(&gb, dc_codebook);
192 if (dc < 0)
193 goto end;
194
195 sign = sign ^ dc & 1;
196 dc_add = (-sign ^ TODCCODEBOOK(dc)) + sign;
197 sign = dc_add < 0;
198 prev_dc += dc_add;
199
200 block[n*64] = prev_dc;
201 }
202
203 for (int n = nb_blocks; n < nb_codes;) {
204 ln = get_value(&gb, ln_codebook);
205 if (ln < 0)
206 goto end;
207
208 for (int i = 0; i < ln; i++) {
209 ac = get_value(&gb, ac_codebook);
210 if (ac < 0)
211 goto end;
212 ac_codebook = ff_prores_raw_ac_cb[FFMIN(ac, AC_CB_MAX)];
213 sign = -get_bits1(&gb);
214
215 idx = scan[n >> log2_nb_blocks] + ((n & block_mask) << 6);
216 block[idx] = ((ac + 1) ^ sign) - sign;
217
218 if (++n == nb_codes)
219 goto end;
220 }
221
222 rn = get_value(&gb, rn_codebook);
223 if (rn < 0)
224 goto end;
225 rn_codebook = ff_prores_raw_rn_cb[FFMIN(rn, RN_CB_MAX)];
226
227 n += rn + 1;
228 if (n >= nb_codes)
229 break;
230
231 ac = get_value(&gb, ac_codebook);
232 if (ac < 0)
233 goto end;
234 ac_codebook = ff_prores_raw_ac_cb[FFMIN(ac, AC_CB_MAX)];
235 ln_codebook = ff_prores_raw_ln_cb[FFMIN(ac, LN_CB_MAX)];
236 sign = -get_bits1(&gb);
237
238 idx = scan[n >> log2_nb_blocks] + ((n & block_mask) << 6);
239 block[idx] = ((ac + 1) ^ sign) - sign;
240
241 n++;
242 }
243
244end:
245 for (int n = 0; n < nb_blocks; n++) {
246 uint16_t *ptr = dst + n*16;
247 s->prodsp.idct_put_bayer(ptr, linesize, block + n*64, qmat, s->lin_curve);
248 }
249
250 return 0;
251}
252
254 AVFrame *frame)
255{
256 int ret;
257 ProResRAWContext *s = avctx->priv_data;
258
259 GetByteContext *gb = &tile->gb;
260 LOCAL_ALIGNED_32(int16_t, qmat, [64]);
261
262 if (tile->x >= avctx->width)
263 return 0;
264
265 /* Tile header */
266 int header_len = bytestream2_get_byteu(gb) >> 3;
267 int16_t scale = bytestream2_get_byteu(gb);
268
269 int size[4];
270 size[0] = bytestream2_get_be16(gb);
271 size[1] = bytestream2_get_be16(gb);
272 size[2] = bytestream2_get_be16(gb);
273 size[3] = bytestream2_size(gb) - size[0] - size[1] - size[2] - header_len;
274 if (size[3] < 0)
275 return AVERROR_INVALIDDATA;
276
277 for (int i = 0; i < 64; i++)
278 qmat[i] = s->qmat[i] * scale;
279
280 const uint8_t *comp_start = gb->buffer_start + header_len;
281
282 ret = decode_comp(avctx, tile, frame, comp_start,
283 size[0], 2, qmat);
284 if (ret < 0)
285 goto fail;
286
287 ret = decode_comp(avctx, tile, frame, comp_start + size[0],
288 size[1], 1, qmat);
289 if (ret < 0)
290 goto fail;
291
292 ret = decode_comp(avctx, tile, frame, comp_start + size[0] + size[1],
293 size[2], 3, qmat);
294 if (ret < 0)
295 goto fail;
296
297 ret = decode_comp(avctx, tile, frame, comp_start + size[0] + size[1] + size[2],
298 size[3], 0, qmat);
299 if (ret < 0)
300 goto fail;
301
302 return 0;
303fail:
304 av_log(avctx, AV_LOG_ERROR, "tile %d/%d decoding error\n", tile->x, tile->y);
305 return ret;
306}
307
308static int decode_tiles(AVCodecContext *avctx, void *arg,
309 int n, int thread_nb)
310{
311 ProResRAWContext *s = avctx->priv_data;
312 TileContext *tile = &s->tiles[n];
313 AVFrame *frame = arg;
314
315 return decode_tile(avctx, tile, frame);
316}
317
320{
321 enum AVPixelFormat pix_fmts[] = {
322#if CONFIG_PRORES_RAW_VULKAN_HWACCEL
324#endif
325#if CONFIG_PRORES_RAW_VIDEOTOOLBOX_HWACCEL
327#endif
328 pix_fmt,
330 };
331
332 return ff_get_format(avctx, pix_fmts);
333}
334
335static int decode_frame(AVCodecContext *avctx,
336 AVFrame *frame, int *got_frame_ptr,
337 AVPacket *avpkt)
338{
339 ProResRAWContext *s = avctx->priv_data;
340 int ret, dimensions_changed = 0, old_version = s->version;
341 DECLARE_ALIGNED(32, uint8_t, qmat)[64];
342 memset(qmat, 1, 64);
343
344 switch (avctx->codec_tag) {
345 case 0:
346 break;
347 case MKTAG('a','p','r','n'):
349 break;
350 case MKTAG('a','p','r','h'):
352 break;
353 default:
354 avpriv_request_sample(avctx, "Profile %d", avctx->codec_tag);
356 break;
357 }
358
360 bytestream2_init(&gb, avpkt->data, avpkt->size);
361 if (bytestream2_get_be32(&gb) != avpkt->size)
362 return AVERROR_INVALIDDATA;
363
364 /* ProRes RAW frame */
365 if (bytestream2_get_be32(&gb) != MKBETAG('p','r','r','f'))
366 return AVERROR_INVALIDDATA;
367
368 int header_len = bytestream2_get_be16(&gb);
369 if (header_len < 62 || bytestream2_get_bytes_left(&gb) < header_len - 2)
370 return AVERROR_INVALIDDATA;
371
372 GetByteContext gb_hdr;
373 bytestream2_init(&gb_hdr, gb.buffer, header_len - 2);
374 bytestream2_skip(&gb, header_len - 2);
375
376 bytestream2_skip(&gb_hdr, 1); /* 1 reserved byte */
377 s->version = bytestream2_get_byte(&gb_hdr);
378 if (s->version > 1) {
379 avpriv_request_sample(avctx, "Version %d", s->version);
381 }
382
383 /* Vendor header (e.g. "peac" for Panasonic or "atm0" for Atmos) */
384 bytestream2_skip(&gb_hdr, 4);
385
386 /* Width and height must always be even */
387 int w = bytestream2_get_be16(&gb_hdr);
388 int h = bytestream2_get_be16(&gb_hdr);
389 if ((w & 1) || (h & 1))
390 return AVERROR_INVALIDDATA;
391
392 if (w != avctx->width || h != avctx->height) {
393 av_log(avctx, AV_LOG_WARNING, "picture resolution change: %ix%i -> %ix%i\n",
394 avctx->width, avctx->height, w, h);
395 if ((ret = ff_set_dimensions(avctx, w, h)) < 0)
396 return ret;
397 dimensions_changed = 1;
398 }
399
400 avctx->coded_width = FFALIGN(w, 16);
401 avctx->coded_height = FFALIGN(h, 16);
402
404 if (pix_fmt != s->pix_fmt || dimensions_changed ||
405 s->version != old_version) {
406 s->pix_fmt = pix_fmt;
407
408 ret = get_pixel_format(avctx, pix_fmt);
409 if (ret < 0)
410 return ret;
411
412 avctx->pix_fmt = ret;
413 }
414
415 /* RecommendedCrop: pixel margins to discard after debayer. Order is
416 * left/right/top/bottom */
417 uint8_t crop_l = bytestream2_get_byte(&gb_hdr);
418 uint8_t crop_r = bytestream2_get_byte(&gb_hdr);
419 uint8_t crop_t = bytestream2_get_byte(&gb_hdr);
420 uint8_t crop_b = bytestream2_get_byte(&gb_hdr);
421
422 /* BayerPattern: 0=RGGB, 1/2/3 = alternates */
423 int bayer_pattern = bytestream2_get_be16(&gb_hdr) & 0x3;
424 if (bayer_pattern != 0) {
425 avpriv_request_sample(avctx, "Bayer pattern %d", bayer_pattern);
427 }
428
429 /* senselValueRange: black_level is hardcoded to 0x100,
430 * white_level = senselValueRange + 0x100 */
431 uint16_t black_level = 0x100;
432 uint16_t white_level = bytestream2_get_be16(&gb_hdr) + 0x100;
433
434 float wb_red = av_int2float(bytestream2_get_be32(&gb_hdr)); /* WhiteBalanceRedFactor */
435 float wb_blue = av_int2float(bytestream2_get_be32(&gb_hdr)); /* WhiteBalanceBlueFactor */
436
437 /* ColorMatrix (3x3 float, camera RGB -> CIE 1931 XYZ D65, row-major) */
438 float color_matrix[3][3];
439 for (int r = 0; r < 3; r++)
440 for (int c = 0; c < 3; c++)
441 color_matrix[r][c] = av_int2float(bytestream2_get_be32(&gb_hdr));
442
443 float gain = av_int2float(bytestream2_get_be32(&gb_hdr)); /* GainFactor (post-matrix mult) */
444 uint16_t wb_cct = bytestream2_get_be16(&gb_hdr); /* WhiteBalanceCCT (Kelvin, informational) */
445
446 /* Flags */
447 int flags = bytestream2_get_be16(&gb_hdr);
448 int align = (flags >> 1) & 0x7;
449 if (align > 4) {
450 av_log(avctx, AV_LOG_ERROR,
451 "Invalid tile alignment %d (max 4)\n", align);
452 return AVERROR_INVALIDDATA;
453 }
454
455 /* Quantization matrix */
456 if (flags & 1)
457 bytestream2_get_buffer(&gb_hdr, qmat, 64);
458
459 if ((flags >> 4) & 1) {
460 /* 8-poing 16-bit control points, defining the combined linearization
461 * curve (inv. transfer fn + encoder-defined shaping) */
462 for (int i = 0; i < 8; i++)
463 s->lin_curve[i] = bytestream2_get_be16(&gb_hdr);
464 } else {
465 /* default curve: ptwos */
466 static const uint16_t default_lin_curve[8] =
467 { 0, 512, 1024, 2048, 4096, 8192, 16384, 32768 };
468 memcpy(s->lin_curve, default_lin_curve, sizeof(s->lin_curve));
469 }
470
471 memcpy(s->qmat, qmat, sizeof(s->qmat));
472
473 int tw16 = (w + 15) >> 4;
474 s->nb_tw = (tw16 >> align) + av_popcount(~(-1 * (1 << align)) & tw16);
475 s->nb_th = (h + 15) >> 4;
476 s->nb_tiles = s->nb_tw * s->nb_th;
477 av_log(avctx, AV_LOG_DEBUG, "%dx%d | nb_tiles: %d\n", s->nb_tw, s->nb_th, s->nb_tiles);
478
479 s->th = 16;
480
481 av_fast_mallocz(&s->tiles, &s->tiles_size, s->nb_tiles * sizeof(*s->tiles));
482 if (!s->tiles)
483 return AVERROR(ENOMEM);
484
485 if (bytestream2_get_bytes_left(&gb) < s->nb_tiles * 2)
486 return AVERROR_INVALIDDATA;
487
488 /* First tile that extends past the right edge gets halved in width,
489 * next one gets quartered, and so on */
490 int offset = bytestream2_tell(&gb) + s->nb_tiles * 2;
491 int n = 0;
492 for (int ty = 0; ty < s->nb_th; ty++) {
493 unsigned tx = 0;
494 int rem = tw16;
495 for (int e = align; rem > 0; e--) {
496 int unit = 1 << e;
497 while (unit <= rem) {
498 TileContext *tile = &s->tiles[n++];
499 int size = bytestream2_get_be16(&gb);
500
501 if (offset >= avpkt->size)
502 return AVERROR_INVALIDDATA;
503 if (size >= avpkt->size)
504 return AVERROR_INVALIDDATA;
505 if (offset > avpkt->size - size)
506 return AVERROR_INVALIDDATA;
507
508 bytestream2_init(&tile->gb, avpkt->data + offset, size);
509 tile->x = tx * 16;
510 tile->y = ty * s->th;
511 tile->log2_nb_blocks = e;
512 offset += size;
513
514 tx += unit;
515 rem -= unit;
516 }
517 }
518 }
519 av_assert1(n == s->nb_tiles);
520
521 /* The stream parameters are all set by now, which is all that probing
522 * with frames skipped needs */
523 if (avctx->skip_frame >= AVDISCARD_ALL)
524 return avpkt->size;
525
526 /**
527 * Any data between last tile and frame end is vendor-specific metadata:
528 * [psim record] 4 be32 size + "psim" + pascal string + payload
529 * <more records, if any>, or:
530 * [eomd] 4 be32 size=8 + "eomd" fourcc (end of metadata)
531 * [padding] zero-fill to next-frame alignment
532 *
533 * Known records (feel free to extend):
534 * com.panasonic.Semi-Pro.optical_correction (IEEE doubles):
535 * R - radial polynomial? + padding: [ k0, k1, k2, k3, pad0, pad1 ]
536 * G, B: same
537 * Trailer: optical center in normalized frame coords: [ x, y ]
538 */
539
540 ret = ff_thread_get_buffer(avctx, frame, 0);
541 if (ret < 0)
542 return ret;
543
544 s->frame = frame;
545
546 av_refstruct_unref(&s->hwaccel_picture_private);
547 ret = ff_hwaccel_frame_priv_alloc(avctx, &s->hwaccel_picture_private);
548 if (ret < 0)
549 return ret;
550
551 /* Everything the next frame thread needs is known, let it start */
553
554 /* Start */
555 if (avctx->hwaccel) {
556 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
557
558 ret = hwaccel->start_frame(avctx, avpkt->buf, avpkt->data, avpkt->size);
559 if (ret < 0)
560 return ret;
561
562 for (int n = 0; n < s->nb_tiles; n++) {
563 TileContext *tile = &s->tiles[n];
564 ret = hwaccel->decode_slice(avctx, tile->gb.buffer,
565 tile->gb.buffer_end - tile->gb.buffer);
566 if (ret < 0)
567 return ret;
568 }
569
570 ret = hwaccel->end_frame(avctx);
571 if (ret < 0)
572 return ret;
573
574 av_refstruct_unref(&s->hwaccel_picture_private);
575 } else {
576 avctx->execute2(avctx, decode_tiles, frame, NULL, s->nb_tiles);
577 }
578
579 frame->pict_type = AV_PICTURE_TYPE_I;
580 frame->flags |= AV_FRAME_FLAG_KEY;
581 frame->crop_left = crop_l;
582 frame->crop_right = crop_r;
583 frame->crop_top = crop_t;
584 frame->crop_bottom = crop_b;
585
587 if (!rcp)
588 return AVERROR(ENOMEM);
590 rcp->black_level = av_make_q(black_level, 65535);
591 rcp->white_level = av_make_q(white_level, 65535);
592 rcp->wb_cct = wb_cct;
593
595 pr->wb_red = av_d2q(wb_red, INT_MAX);
596 pr->wb_blue = av_d2q(wb_blue, INT_MAX);
597 pr->gain = av_d2q(gain, INT_MAX);
598 for (int r = 0; r < 3; r++)
599 for (int c = 0; c < 3; c++)
600 pr->color_matrix[r][c] = av_d2q(color_matrix[r][c], INT_MAX);
601
602 *got_frame_ptr = 1;
603
604 return avpkt->size;
605}
606
608{
609 ProResRAWContext *s = avctx->priv_data;
610 av_refstruct_unref(&s->hwaccel_picture_private);
611 av_freep(&s->tiles);
612 return 0;
613}
614
615#if HAVE_THREADS
616static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
617{
618 ProResRAWContext *rsrc = src->priv_data;
619 ProResRAWContext *rdst = dst->priv_data;
620
621 rdst->pix_fmt = rsrc->pix_fmt;
622 rdst->version = rsrc->version;
623
624 return 0;
625}
626#endif
627
629 .p.name = "prores_raw",
630 CODEC_LONG_NAME("Apple ProRes RAW"),
631 .p.type = AVMEDIA_TYPE_VIDEO,
633 .priv_data_size = sizeof(ProResRAWContext),
634 .init = decode_init,
635 .close = decode_end,
637 UPDATE_THREAD_CONTEXT(update_thread_context),
638 .p.capabilities = AV_CODEC_CAP_DR1 |
641 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
643 .hw_configs = (const AVCodecHWConfigInternal *const []) {
644#if CONFIG_PRORES_RAW_VULKAN_HWACCEL
645 HWACCEL_VULKAN(prores_raw),
646#endif
647#if CONFIG_PRORES_RAW_VIDEOTOOLBOX_HWACCEL
648 HWACCEL_VIDEOTOOLBOX(prores_raw),
649#endif
650 NULL
651 },
652};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
const FFCodec ff_prores_raw_decoder
Definition prores_raw.c:628
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
Libavcodec external API header.
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition bytestream.h:267
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition bytestream.h:137
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition bytestream.h:168
static av_always_inline int bytestream2_tell(const GetByteContext *g)
Definition bytestream.h:192
static av_always_inline int bytestream2_size(const GetByteContext *g)
Definition bytestream.h:202
static int FUNC tile(CodedBitstreamContext *ctx, RWContext *rw, APVRawTile *current, int tile_idx, uint32_t tile_size)
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static const unsigned codebook[256][2]
Definition cfhdenc.c:41
#define UPDATE_THREAD_CONTEXT(func)
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters if all frames are skipped due to the skip_frame setting...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define av_popcount
Definition common.h:154
#define NULL
Definition coverity.c:32
static int16_t block[64]
Definition dct.c:125
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition decode.c:1248
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
Definition decode.c:2383
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
#define AV_PROFILE_PRORES_RAW_HQ
Definition defs.h:203
#define AV_PROFILE_PRORES_RAW
Definition defs.h:202
static enum AVPixelFormat pix_fmt
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
static const uint8_t bits[8]
Definition fastaudio.c:100
static const char * hwaccel
Definition ffplay.c:406
int ret
Definition ffplay.c:391
bitstream reader API header.
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition get_bits.h:498
static int get_bits_left(GetBitContext *gb)
Definition get_bits.h:688
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition get_bits.h:280
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
#define fail
Definition test.h:479
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition codec.h:102
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_PRORES_RAW
Definition codec_id.h:324
@ AVDISCARD_ALL
discard all
Definition defs.h:248
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition frame.h:694
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition rational.c:110
#define ff_clz
Definition intmath.h:141
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
Allocate and clear a buffer, reusing the given one if large enough.
Definition mem.c:666
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
#define HWACCEL_VULKAN(codec)
Definition hwconfig.h:78
#define HWACCEL_VIDEOTOOLBOX(codec)
Definition hwconfig.h:76
#define r
Definition input.c:42
#define b
Definition input.c:43
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
Definition intfloat.h:40
unsigned offset
Definition libaomenc.c:812
static av_cold int decode_init(AVCodecContext *avctx)
Definition 4xm.c:1000
static av_cold int decode_end(AVCodecContext *avctx)
Definition 4xm.c:982
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition 4xm.c:839
av_cold void ff_blockdsp_init(BlockDSPContext *c)
Definition blockdsp.c:58
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition cbs.c:118
const char * arg
Definition jacosubdec.c:66
av_cold void ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample)
Definition proresdsp.c:172
Multithreading API for decoders.
#define av_always_inline
Definition attributes.h:72
#define av_cold
Definition attributes.h:117
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
uint8_t w
Definition llvidencdsp.c:39
#define FFMIN(a, b)
Definition macros.h:49
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define MKBETAG(a, b, c, d)
Definition macros.h:56
#define FFALIGN(x, a)
Definition macros.h:78
Memory handling functions.
#define LOCAL_ALIGNED_32(t, v,...)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
const char data[16]
Definition mxf.c:155
#define AV_PIX_FMT_BAYER_RGGB16
Definition pixfmt.h:581
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition pixfmt.h:379
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition pixfmt.h:305
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:650
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition pixfmt.h:686
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:714
#define TODCCODEBOOK(x)
Definition prores_raw.c:110
const int16_t ff_prores_raw_rn_cb[RN_CB_MAX+1]
Definition prores_raw.c:130
const int16_t ff_prores_raw_ac_cb[AC_CB_MAX+1]
Definition prores_raw.c:118
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition prores_raw.c:335
static int decode_comp(AVCodecContext *avctx, TileContext *tile, AVFrame *frame, const uint8_t *data, int size, int component, int16_t *qmat)
Definition prores_raw.c:140
#define AC_CB_MAX
Definition prores_raw.c:117
static enum AVPixelFormat get_pixel_format(AVCodecContext *avctx, enum AVPixelFormat pix_fmt)
Definition prores_raw.c:318
static av_cold int decode_init(AVCodecContext *avctx)
Definition prores_raw.c:46
static int decode_tile(AVCodecContext *avctx, TileContext *tile, AVFrame *frame)
Definition prores_raw.c:253
static av_cold int decode_end(AVCodecContext *avctx)
Definition prores_raw.c:607
#define RN_CB_MAX
Definition prores_raw.c:129
const int16_t ff_prores_raw_ln_cb[LN_CB_MAX+1]
Definition prores_raw.c:136
#define DC_CB_MAX
Definition prores_raw.c:112
const uint8_t ff_prores_raw_dc_cb[DC_CB_MAX+1]
Definition prores_raw.c:113
static int decode_tiles(AVCodecContext *avctx, void *arg, int n, int thread_nb)
Definition prores_raw.c:308
#define LN_CB_MAX
Definition prores_raw.c:135
static av_always_inline int get_value(GetBitContext *gb, int16_t codebook)
Definition prores_raw.c:68
const uint8_t ff_prores_interlaced_scan[64]
Definition proresdata.c:36
static const uint8_t dc_codebook[7]
Definition proresdec.c:479
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
Utilities for rational number calculation.
AVRawColorParams * av_raw_color_params_create_side_data(AVFrame *frame)
Allocate and add an AVRawColorParams structure to an existing AVFrame as AV_FRAME_DATA_RAW_COLOR_PARA...
@ AV_RAW_COLOR_PARAMS_PRORES_RAW
The union is valid when interpreted as AVProResRawColorParams (codec.prores_raw).
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:121
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:644
int width
picture width / height.
Definition avcodec.h:605
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition avcodec.h:468
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:658
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition avcodec.h:1429
int profile
profile
Definition avcodec.h:1646
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1581
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:672
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:665
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:1638
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition avcodec.h:620
void * priv_data
Definition avcodec.h:470
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition avcodec.h:1677
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
This structure stores compressed data.
Definition packet.h:587
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition packet.h:593
int size
Definition packet.h:611
uint8_t * data
Definition packet.h:610
ProRes RAW per-frame color transform, parsed from the prrf frame header.
AVRational wb_red
White balance multiplier for the red channel, applied pre-debayer.
AVRational color_matrix[3][3]
3x3 row-major color matrix from camera RGB to linear-light CIE 1931 XYZ relative to the D65 illuminan...
AVRational wb_blue
White balance multiplier for the blue channel, applied pre-debayer.
AVRational gain
Post-matrix scene-linear scaling factor.
Per-frame color information for a RAW camera codec.
AVProResRawColorParams prores_raw
AVRational black_level
Lowest valid raw sample code (sensor black point)
enum AVRawColorParamsType type
Selects which member of codec is valid.
union AVRawColorParams::@064000052037250306123267111255172234366153040136 codec
Additional codec-specific fields.
AVRational white_level
Highest valid raw sample code (sensor white point)
uint32_t wb_cct
Color temperature in Kelvin from with the camera's white balance.
const uint8_t * buffer_start
Definition bytestream.h:34
const uint8_t * buffer
Definition bytestream.h:34
enum AVPixelFormat pix_fmt
Definition prores_raw.h:49
#define avpriv_request_sample(...)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
int size
static double c[64]