31 #define LONG_BITSTREAM_READER // some ProRes vlc codes require up to 28 bits to be read at once
56 uint8_t qmat_luma[64];
57 uint8_t qmat_chroma[64];
79 0, 1, 8, 9, 2, 3, 10, 11,
80 16, 17, 24, 25, 18, 19, 26, 27,
81 4, 5, 12, 20, 13, 6, 7, 14,
82 21, 28, 29, 22, 15, 23, 30, 31,
83 32, 33, 40, 48, 41, 34, 35, 42,
84 49, 56, 57, 50, 43, 36, 37, 44,
85 51, 58, 59, 52, 45, 38, 39, 46,
86 53, 60, 61, 54, 47, 55, 62, 63
90 0, 8, 1, 9, 16, 24, 17, 25,
91 2, 10, 3, 11, 18, 26, 19, 27,
92 32, 40, 33, 34, 41, 48, 56, 49,
93 42, 35, 43, 50, 57, 58, 51, 59,
94 4, 12, 5, 6, 13, 20, 28, 21,
95 14, 7, 15, 22, 29, 36, 44, 37,
96 30, 23, 31, 38, 45, 52, 60, 53,
97 46, 39, 47, 54, 61, 62, 55, 63
132 if (hdr_size > data_size) {
140 "unsupported header version: %d\n", version);
146 if (width != avctx->
width || height != avctx->
height) {
148 "picture dimension changed: old: %d x %d, new: %d x %d\n",
156 "unsupported frame type: %d\n", ctx->
frame_type);
172 "unsupported picture format: %d\n", ctx->
pic_format);
201 if (ptr - buf > hdr_size - 64) {
216 if (ptr - buf > hdr_size - 64) {
236 int i, hdr_size, pic_data_size, num_slices;
237 int slice_width_factor, slice_height_factor;
238 int remainder, num_x_slices;
239 const uint8_t *data_ptr, *index_ptr;
241 hdr_size = data_size > 0 ? buf[0] >> 3 : 0;
242 if (hdr_size < 8 || hdr_size > data_size) {
247 pic_data_size =
AV_RB32(buf + 1);
248 if (pic_data_size > data_size) {
253 slice_width_factor = buf[7] >> 4;
254 slice_height_factor = buf[7] & 0xF;
255 if (slice_width_factor > 3 || slice_height_factor) {
257 "unsupported slice dimension: %d x %d\n",
258 1 << slice_width_factor, 1 << slice_height_factor);
270 remainder = ctx->
num_x_mbs & ((1 << slice_width_factor) - 1);
271 num_x_slices = (ctx->
num_x_mbs >> slice_width_factor) + (remainder & 1) +
272 ((remainder >> 1) & 1) + ((remainder >> 2) & 1);
274 num_slices = num_x_slices * ctx->
num_y_mbs;
275 if (num_slices !=
AV_RB16(buf + 5)) {
288 if (hdr_size + num_slices * 2 > data_size) {
294 index_ptr = buf + hdr_size;
295 data_ptr = index_ptr + num_slices * 2;
297 for (i = 0; i < num_slices; i++) {
299 data_ptr +=
AV_RB16(index_ptr + i * 2);
303 if (data_ptr > buf + data_size) {
308 return pic_data_size;
317 unsigned int rice_order, exp_order, switch_bits;
318 unsigned int buf, code;
319 int log, prefix_len,
len;
326 switch_bits = (codebook & 3) + 1;
327 rice_order = codebook >> 5;
328 exp_order = (codebook >> 2) & 7;
330 log = 31 - av_log2(buf);
332 if (log < switch_bits) {
338 prefix_len = log + 1;
339 code = (log << rice_order) +
NEG_USR32(buf << prefix_len, rice_order);
343 len = (log << 1) - switch_bits + exp_order + 1;
344 code =
NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order);
353 #define LSB2SIGN(x) (-((x) & 1))
354 #define TOSIGNED(x) (((x) >> 1) ^ LSB2SIGN(x))
356 #define FIRST_DC_CB 0xB8 // rice_order = 5, exp_golomb_order = 6, switch_bits = 0
383 for (i = 1; i < nblocks; i++, out += 64) {
386 sign = -(((delta >> 15) & 1) ^ (code & 1));
387 delta = (((code + 1) >> 1) ^ sign) - sign;
409 { 5, 5, 3, 3, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2 };
418 int blocks_per_slice,
419 int plane_size_factor,
422 int pos, block_mask,
run,
level, sign, run_cb_index, lev_cb_index;
423 int max_coeffs, bits_left;
429 max_coeffs = blocks_per_slice << 6;
430 block_mask = blocks_per_slice - 1;
432 for (pos = blocks_per_slice - 1; pos < max_coeffs;) {
437 if (bits_left <= 0 || (bits_left <= 8 && !
show_bits(gb, bits_left)))
443 if (bits_left <= 0 || (bits_left <= 8 && !
show_bits(gb, bits_left)))
449 if (pos >= max_coeffs)
453 out[((pos & block_mask) << 6) + scan[pos >> plane_size_factor]] =
454 (level ^ sign) - sign;
464 int data_size, uint16_t *out_ptr,
465 int linesize,
int mbs_per_slice,
466 int blocks_per_mb,
int plane_size_factor,
471 int mb_num, blocks_per_slice;
473 blocks_per_slice = mbs_per_slice * blocks_per_mb;
475 memset(td->
blocks, 0, 8 * 4 * 64 *
sizeof(*td->
blocks));
487 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
488 ctx->
dsp.
idct_put(out_ptr, linesize, block_ptr, qmat);
490 if (blocks_per_mb > 2) {
491 ctx->
dsp.
idct_put(out_ptr + 8, linesize, block_ptr, qmat);
494 ctx->
dsp.
idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
496 if (blocks_per_mb > 2) {
497 ctx->
dsp.
idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
508 int mb_x_pos = td->
x_pos;
509 int mb_y_pos = td->
y_pos;
514 uint8_t *y_data, *u_data, *v_data;
516 int i, sf, slice_width_factor;
517 int slice_data_size, hdr_size, y_data_size, u_data_size, v_data_size;
518 int y_linesize, u_linesize, v_linesize;
523 slice_width_factor = av_log2(mbs_per_slice);
525 y_data = pic->
data[0];
526 u_data = pic->
data[1];
527 v_data = pic->
data[2];
534 y_data += y_linesize;
535 u_data += u_linesize;
536 v_data += v_linesize;
543 if (slice_data_size < 6) {
549 hdr_size = buf[0] >> 3;
550 y_data_size =
AV_RB16(buf + 2);
551 u_data_size =
AV_RB16(buf + 4);
552 v_data_size = hdr_size > 7 ?
AV_RB16(buf + 6) :
553 slice_data_size - y_data_size - u_data_size - hdr_size;
555 if (hdr_size + y_data_size + u_data_size + v_data_size > slice_data_size ||
556 v_data_size < 0 || hdr_size < 6) {
561 sf = av_clip(buf[1], 1, 224);
562 sf = sf > 128 ? (sf - 96) << 2 : sf;
568 for (i = 0; i < 64; i++) {
576 (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize +
577 (mb_x_pos << 5)), y_linesize,
578 mbs_per_slice, 4, slice_width_factor + 2,
583 (uint16_t*) (u_data + (mb_y_pos << 4) * u_linesize +
592 (uint16_t*) (v_data + (mb_y_pos << 4) * v_linesize +
605 int slice_num, slice_width, x_pos, y_pos;
610 for (y_pos = 0; y_pos < ctx->
num_y_mbs; y_pos++) {
613 for (x_pos = 0; x_pos < ctx->
num_x_mbs && slice_width;
614 x_pos += slice_width) {
615 while (ctx->
num_x_mbs - x_pos < slice_width)
633 #define FRAME_ID MKBETAG('i', 'c', 'p', 'f')
634 #define MOVE_DATA_PTR(nbytes) buf += (nbytes); buf_size -= (nbytes)
641 const uint8_t *buf = avpkt->
data;
642 int buf_size = avpkt->
size;
643 int frame_hdr_size, pic_num, pic_data_size;
646 if (buf_size < 28 || buf_size <
AV_RB32(buf) ||
655 if (frame_hdr_size < 0)
660 if (picture->
data[0])
669 if (pic_data_size < 0)
int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_WB24 AV_RB16
static uint8_t ac_codebook[7]
AV_WL32 AV_WL24 AV_WL16 AV_RB32
uint8_t qmat_luma[64]
dequantization matrix for luma
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
#define MOVE_DATA_PTR(nbytes)
static void 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)
Decode a slice plane (luma or chroma).
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
int prev_slice_sf
scalefactor of the previous decoded slice
AVFrame * coded_frame
the picture in the bitstream
#define DECLARE_ALIGNED(n, t, v)
static av_cold int decode_init(AVCodecContext *avctx)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static int decode_picture_header(ProresContext *ctx, const uint8_t *buf, const int data_size, AVCodecContext *avctx)
int scantable_type
-1 = uninitialized, 0 = progressive, 1/2 = interlaced
static int get_sbits(GetBitContext *s, int n)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const uint8_t * index
pointers to the data of this slice
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
static uint8_t dc_codebook[4]
int16_t qmat_luma_scaled[64]
void(* idct_put)(uint16_t *out, int linesize, DCTELEM *block, const int16_t *qmat)
bitstream reader API header.
int interlaced_frame
The content of the picture is interlaced.
static int init(AVCodecParserContext *s)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
ProresThreadData * slice_data
static int get_bits_left(GetBitContext *gb)
#define UPDATE_CACHE(name, gb)
static int decode_slice(AVCodecContext *avctx, void *tdata)
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.
static av_cold int decode_close(AVCodecContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int16_t qmat_chroma_scaled[64]
#define CLOSE_READER(name, gb)
int num_chroma_blocks
number of chrominance blocks in a macroblock
int width
picture width / height.
int type
type of the buffer (to keep track of who has to deallocate data[*])
uint8_t idct_permutation[64]
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define LAST_SKIP_BITS(name, gb, num)
int total_slices
total number of slices in a picture
static void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out, int nblocks)
Decode DC coefficients for all blocks in a slice.
static void 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.
static uint8_t lev_to_cb_index[10]
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
#define PIX_FMT_YUV422P10
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
struct AVPicture AVPicture
four components are given, that's all.
#define OPEN_READER(name, gb)
static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, const int data_size, AVCodecContext *avctx)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define GET_CACHE(name, gb)
AVCodec ff_prores_decoder
static int decode_vlc_codeword(GetBitContext *gb, uint8_t codebook)
Read an unsigned rice/exp golomb codeword.
static int decode_picture(ProresContext *ctx, int pic_num, AVCodecContext *avctx)
void ff_proresdsp_init(ProresDSPContext *dsp)
int pic_format
2 = 422, 3 = 444
static uint8_t run_to_cb_index[16]
Lookup tables for adaptive switching between codebooks according with previous run/level value...
static const uint8_t interlaced_scan[64]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int qmat_changed
1 - global quantization matrices changed
#define PRORES_BITS_PER_SAMPLE
output precision of prores decoder
static const uint8_t progressive_scan[64]
#define PIX_FMT_YUV444P10
uint8_t qmat_chroma[64]
dequantization matrix for chroma
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.
int top_field_first
If the content is interlaced, is top field displayed first.
void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
int key_frame
1 -> keyframe, 0-> not
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
int frame_type
0 = progressive, 1 = top-field first, 2 = bottom-field first