31 #define LONG_BITSTREAM_READER // some ProRes vlc codes require up to 28 bits to be read at once 106 if (hdr_size > data_size) {
114 "unsupported header version: %d\n", version);
120 if (width != avctx->
width || height != avctx->
height) {
122 "picture dimension changed: old: %d x %d, new: %d x %d\n",
130 "unsupported frame type: %d\n", ctx->
frame_type);
156 "unsupported picture format: %d\n", ctx->
pic_format);
186 if (ptr - buf > hdr_size - 64) {
201 if (ptr - buf > hdr_size - 64) {
221 int i, hdr_size, pic_data_size, num_slices;
222 int slice_width_factor, slice_height_factor;
223 int remainder, num_x_slices;
224 const uint8_t *data_ptr, *index_ptr;
226 hdr_size = data_size > 0 ? buf[0] >> 3 : 0;
227 if (hdr_size < 8 || hdr_size > data_size) {
232 pic_data_size =
AV_RB32(buf + 1);
233 if (pic_data_size > data_size) {
238 slice_width_factor = buf[7] >> 4;
239 slice_height_factor = buf[7] & 0xF;
240 if (slice_width_factor > 3 || slice_height_factor) {
242 "unsupported slice dimension: %d x %d\n",
243 1 << slice_width_factor, 1 << slice_height_factor);
255 remainder = av_mod_uintp2(ctx->
num_x_mbs, slice_width_factor);
256 num_x_slices = (ctx->
num_x_mbs >> slice_width_factor) + (remainder & 1) +
257 ((remainder >> 1) & 1) + ((remainder >> 2) & 1);
259 num_slices = num_x_slices * ctx->
num_y_mbs;
260 if (num_slices !=
AV_RB16(buf + 5)) {
273 if (hdr_size + num_slices * 2 > data_size) {
279 index_ptr = buf + hdr_size;
280 data_ptr = index_ptr + num_slices * 2;
282 for (i = 0; i < num_slices; i++) {
285 data_ptr +=
AV_RB16(index_ptr + i * 2);
290 if (data_ptr > buf + data_size) {
295 return pic_data_size;
304 unsigned int rice_order, exp_order, switch_bits;
305 unsigned int buf, code;
306 int log, prefix_len,
len;
313 switch_bits = (codebook & 3) + 1;
314 rice_order = codebook >> 5;
315 exp_order = (codebook >> 2) & 7;
319 if (log < switch_bits) {
325 prefix_len = log + 1;
326 code = (log << rice_order) +
NEG_USR32(buf << prefix_len, rice_order);
330 len = (log << 1) - switch_bits + exp_order + 1;
331 code =
NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order);
340 #define LSB2SIGN(x) (-((x) & 1)) 341 #define TOSIGNED(x) (((x) >> 1) ^ LSB2SIGN(x)) 360 for (i = 1; i < nblocks; i++, out += 64) {
363 sign = -(((delta >> 15) & 1) ^ (code & 1));
364 delta = (((code + 1) >> 1) ^ sign) - sign;
370 #define MAX_PADDING 16 376 int blocks_per_slice,
377 int plane_size_factor,
380 int pos, block_mask,
run,
level, sign, run_cb_index, lev_cb_index;
381 int max_coeffs, bits_left;
387 max_coeffs = blocks_per_slice << 6;
388 block_mask = blocks_per_slice - 1;
390 for (pos = blocks_per_slice - 1; pos < max_coeffs;) {
411 if (pos >= max_coeffs)
415 out[((pos & block_mask) << 6) + scan[pos >> plane_size_factor]] =
416 (level ^ sign) - sign;
428 int data_size, uint16_t *out_ptr,
429 int linesize,
int mbs_per_slice,
430 int blocks_per_mb,
int plane_size_factor,
431 const int16_t *qmat,
int is_chroma)
435 int mb_num, blocks_per_slice, ret;
437 blocks_per_slice = mbs_per_slice * blocks_per_mb;
439 memset(td->
blocks, 0, 8 * 4 * 64 *
sizeof(*td->
blocks));
454 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
455 ctx->
dsp.
idct_put(out_ptr, linesize, block_ptr, qmat);
457 if (blocks_per_mb > 2) {
458 ctx->
dsp.
idct_put(out_ptr + 8, linesize, block_ptr, qmat);
461 ctx->
dsp.
idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
463 if (blocks_per_mb > 2) {
464 ctx->
dsp.
idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
469 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
470 ctx->
dsp.
idct_put(out_ptr, linesize, block_ptr, qmat);
472 ctx->
dsp.
idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
474 if (blocks_per_mb > 2) {
475 ctx->
dsp.
idct_put(out_ptr + 8, linesize, block_ptr, qmat);
477 ctx->
dsp.
idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
489 const int mask = (1 << num_bits) - 1;
490 int i, idx,
val, alpha_val;
500 val =
get_bits(gb, num_bits == 16 ? 7 : 4);
502 val = (val + 2) >> 1;
506 alpha_val = (alpha_val +
val) & mask;
508 dst[idx++] = alpha_val >> 6;
510 dst[idx++] = (alpha_val << 2) | (alpha_val >> 6);
511 if (idx >= num_coeffs) {
518 if (idx + val > num_coeffs)
519 val = num_coeffs - idx;
521 for (i = 0; i <
val; i++)
522 dst[idx++] = alpha_val >> 6;
524 for (i = 0; i <
val; i++)
525 dst[idx++] = (alpha_val << 2) | (alpha_val >> 6);
526 }
while (idx < num_coeffs);
534 uint16_t *out_ptr,
int linesize,
541 memset(td->
blocks, 0, 8 * 4 * 64 *
sizeof(*td->
blocks));
552 for (i = 0; i < 16; i++) {
553 memcpy(out_ptr, block_ptr, 16 * mbs_per_slice *
sizeof(*out_ptr));
554 out_ptr += linesize >> 1;
555 block_ptr += 16 * mbs_per_slice;
563 int mb_x_pos = td->
x_pos;
564 int mb_y_pos = td->
y_pos;
569 uint8_t *y_data, *u_data, *v_data, *a_data;
571 int i, sf, slice_width_factor;
572 int slice_data_size, hdr_size;
573 int y_data_size, u_data_size, v_data_size, a_data_size;
574 int y_linesize, u_linesize, v_linesize, a_linesize;
581 slice_width_factor =
av_log2(mbs_per_slice);
583 y_data = pic->
data[0];
584 u_data = pic->
data[1];
585 v_data = pic->
data[2];
586 a_data = pic->
data[3];
594 y_data += y_linesize;
595 u_data += u_linesize;
596 v_data += v_linesize;
598 a_data += a_linesize;
605 y_data += (mb_y_pos << 4) * y_linesize + (mb_x_pos << 5);
606 u_data += (mb_y_pos << 4) * u_linesize + (mb_x_pos << ctx->
mb_chroma_factor);
607 v_data += (mb_y_pos << 4) * v_linesize + (mb_x_pos << ctx->
mb_chroma_factor);
609 a_data += (mb_y_pos << 4) * a_linesize + (mb_x_pos << 5);
611 if (slice_data_size < 6) {
617 hdr_size = buf[0] >> 3;
619 y_data_size =
AV_RB16(buf + 2);
620 coff[1] = coff[0] + y_data_size;
621 u_data_size =
AV_RB16(buf + 4);
622 coff[2] = coff[1] + u_data_size;
623 v_data_size = hdr_size > 7 ?
AV_RB16(buf + 6) : slice_data_size - coff[2];
624 coff[3] = coff[2] + v_data_size;
625 a_data_size = ctx->
alpha_info ? slice_data_size - coff[3] : 0;
629 if (v_data_size < 0 || a_data_size < 0 || hdr_size < 6 || coff[3] > slice_data_size) {
634 sf = av_clip(buf[1], 1, 224);
635 sf = sf > 128 ? (sf - 96) << 2 : sf;
641 for (i = 0; i < 64; i++) {
649 (uint16_t*) y_data, y_linesize,
650 mbs_per_slice, 4, slice_width_factor + 2,
658 (uint16_t*) u_data, u_linesize,
667 (uint16_t*) v_data, v_linesize,
675 if (a_data && a_data_size)
677 (uint16_t*) a_data, a_linesize,
692 for (y_pos = 0; y_pos < ctx->
num_y_mbs; y_pos++) {
697 while (ctx->
num_x_mbs - x_pos < slice_width)
715 #define MOVE_DATA_PTR(nbytes) buf += (nbytes); buf_size -= (nbytes) 722 int buf_size = avpkt->
size;
723 int frame_hdr_size, pic_num, pic_data_size;
730 if (buf_size < 28 || buf_size <
AV_RB32(buf) ||
739 if (frame_hdr_size < 0)
749 if (pic_data_size < 0)
776 .
name =
"prores_lgpl",
static int decode_picture_header(ProresContext *ctx, const uint8_t *buf, const int data_size, AVCodecContext *avctx)
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, const int data_size, AVCodecContext *avctx)
#define AV_PIX_FMT_YUVA422P10
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
const uint8_t ff_prores_ac_codebook[7]
static av_cold int init(AVCodecContext *avctx)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
uint8_t qmat_chroma[64]
dequantization matrix for chroma
av_cold void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static int decode_picture(ProresContext *ctx, int pic_num, AVCodecContext *avctx)
int scantable_type
-1 = uninitialized, 0 = progressive, 1/2 = interlaced
#define MOVE_DATA_PTR(nbytes)
static int get_sbits(GetBitContext *s, int n)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
const uint8_t * index
pointers to the data of this slice
AVCodec ff_prores_lgpl_decoder
static int decode_slice(AVCodecContext *avctx, void *tdata)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
const uint8_t ff_prores_run_to_cb_index[16]
Lookup tables for adaptive switching between codebooks according with previous run/level value...
const uint8_t ff_prores_lev_to_cb_index[10]
bitstream reader API header.
int interlaced_frame
The content of the picture is interlaced.
static int decode_ac_coeffs(GetBitContext *gb, int16_t *out, int blocks_per_slice, int plane_size_factor, const uint8_t *scan)
Decode AC coefficients for all blocks in a slice.
ProresThreadData * slice_data
int16_t qmat_chroma_scaled[64]
static int get_bits_left(GetBitContext *gb)
#define UPDATE_CACHE(name, gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
int skip_alpha
Skip processing alpha if supported by codec.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
#define AV_PIX_FMT_YUV444P10
#define CLOSE_READER(name, gb)
static av_cold int decode_close(AVCodecContext *avctx)
enum AVPictureType pict_type
Picture type of the frame.
static void decode_dc_coeffs(GetBitContext *gb, int16_t *out, int nblocks)
Decode DC coefficients for all blocks in a slice.
int num_chroma_blocks
number of chrominance blocks in a macroblock
int width
picture width / height.
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).
uint8_t idct_permutation[64]
const uint8_t ff_prores_dc_codebook[4]
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define LAST_SKIP_BITS(name, gb, num)
static av_cold int decode_init(AVCodecContext *avctx)
int total_slices
total number of slices in a picture
#define AV_PIX_FMT_YUVA444P10
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static int decode_vlc_codeword(GetBitContext *gb, unsigned codebook)
Read an unsigned rice/exp golomb codeword.
const uint8_t ff_prores_interlaced_scan[64]
Libavcodec external API header.
static void decode_alpha_plane(ProresContext *ctx, ProresThreadData *td, const uint8_t *buf, int data_size, uint16_t *out_ptr, int linesize, int mbs_per_slice)
Decode alpha slice plane.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
const uint8_t ff_prores_progressive_scan[64]
#define OPEN_READER(name, gb)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static unsigned int get_bits1(GetBitContext *s)
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define GET_CACHE(name, gb)
static void unpack_alpha(GetBitContext *gb, uint16_t *dst, int num_coeffs, const int num_bits)
int pic_format
2 = 422, 3 = 444
#define AV_PIX_FMT_YUV422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the normal 219*2^(n-8) "MPEG" YUV ranges
int prev_slice_sf
scalefactor of the previous decoded slice
common internal api header.
int qmat_changed
1 - global quantization matrices changed
#define PRORES_BITS_PER_SAMPLE
output precision of prores decoder
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
int top_field_first
If the content is interlaced, is top field displayed first.
int key_frame
1 -> keyframe, 0-> not
#define av_malloc_array(a, b)
uint8_t qmat_luma[64]
dequantization matrix for luma
int frame_type
0 = progressive, 1 = tff, 2 = bff
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.
This structure stores compressed data.
int16_t qmat_luma_scaled[64]
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void(* idct_put)(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat)