31 #define LONG_BITSTREAM_READER // some ProRes vlc codes require up to 28 bits to be read at once
110 if (hdr_size > data_size) {
118 "unsupported header version: %d\n", version);
124 if (width != avctx->
width || height != avctx->
height) {
126 "picture dimension changed: old: %d x %d, new: %d x %d\n",
134 "unsupported frame type: %d\n", ctx->
frame_type);
150 "unsupported picture format: %d\n", ctx->
pic_format);
183 if (ptr - buf > hdr_size - 64) {
198 if (ptr - buf > hdr_size - 64) {
218 int i, hdr_size, pic_data_size, num_slices;
219 int slice_width_factor, slice_height_factor;
220 int remainder, num_x_slices;
221 const uint8_t *data_ptr, *index_ptr;
223 hdr_size = data_size > 0 ? buf[0] >> 3 : 0;
224 if (hdr_size < 8 || hdr_size > data_size) {
229 pic_data_size =
AV_RB32(buf + 1);
230 if (pic_data_size > data_size) {
235 slice_width_factor = buf[7] >> 4;
236 slice_height_factor = buf[7] & 0xF;
237 if (slice_width_factor > 3 || slice_height_factor) {
239 "unsupported slice dimension: %d x %d\n",
240 1 << slice_width_factor, 1 << slice_height_factor);
252 remainder = ctx->
num_x_mbs & ((1 << slice_width_factor) - 1);
253 num_x_slices = (ctx->
num_x_mbs >> slice_width_factor) + (remainder & 1) +
254 ((remainder >> 1) & 1) + ((remainder >> 2) & 1);
256 num_slices = num_x_slices * ctx->
num_y_mbs;
257 if (num_slices !=
AV_RB16(buf + 5)) {
270 if (hdr_size + num_slices * 2 > data_size) {
276 index_ptr = buf + hdr_size;
277 data_ptr = index_ptr + num_slices * 2;
279 for (i = 0; i < num_slices; i++) {
282 data_ptr +=
AV_RB16(index_ptr + i * 2);
287 if (data_ptr > buf + data_size) {
292 return pic_data_size;
301 unsigned int rice_order, exp_order, switch_bits;
302 unsigned int buf, code;
303 int log, prefix_len,
len;
310 switch_bits = (codebook & 3) + 1;
311 rice_order = codebook >> 5;
312 exp_order = (codebook >> 2) & 7;
316 if (log < switch_bits) {
322 prefix_len = log + 1;
323 code = (log << rice_order) +
NEG_USR32(buf << prefix_len, rice_order);
327 len = (log << 1) - switch_bits + exp_order + 1;
328 code =
NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order);
337 #define LSB2SIGN(x) (-((x) & 1))
338 #define TOSIGNED(x) (((x) >> 1) ^ LSB2SIGN(x))
357 for (i = 1; i < nblocks; i++, out += 64) {
360 sign = -(((delta >> 15) & 1) ^ (code & 1));
361 delta = (((code + 1) >> 1) ^ sign) - sign;
372 int blocks_per_slice,
373 int plane_size_factor,
376 int pos, block_mask,
run,
level, sign, run_cb_index, lev_cb_index;
377 int max_coeffs, bits_left;
383 max_coeffs = blocks_per_slice << 6;
384 block_mask = blocks_per_slice - 1;
386 for (pos = blocks_per_slice - 1; pos < max_coeffs;) {
391 if (bits_left <= 0 || (bits_left <= 8 && !
show_bits(gb, bits_left)))
399 if (bits_left <= 0 || (bits_left <= 8 && !
show_bits(gb, bits_left)))
407 if (pos >= max_coeffs)
411 out[((pos & block_mask) << 6) + scan[pos >> plane_size_factor]] =
412 (level ^ sign) - sign;
424 int data_size, uint16_t *out_ptr,
425 int linesize,
int mbs_per_slice,
426 int blocks_per_mb,
int plane_size_factor,
427 const int16_t *qmat,
int is_chroma)
431 int mb_num, blocks_per_slice, ret;
433 blocks_per_slice = mbs_per_slice * blocks_per_mb;
435 memset(td->
blocks, 0, 8 * 4 * 64 *
sizeof(*td->
blocks));
450 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
451 ctx->
dsp.
idct_put(out_ptr, linesize, block_ptr, qmat);
453 if (blocks_per_mb > 2) {
454 ctx->
dsp.
idct_put(out_ptr + 8, linesize, block_ptr, qmat);
457 ctx->
dsp.
idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
459 if (blocks_per_mb > 2) {
460 ctx->
dsp.
idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
465 for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
466 ctx->
dsp.
idct_put(out_ptr, linesize, block_ptr, qmat);
468 ctx->
dsp.
idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
470 if (blocks_per_mb > 2) {
471 ctx->
dsp.
idct_put(out_ptr + 8, linesize, block_ptr, qmat);
473 ctx->
dsp.
idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
486 int mb_x_pos = td->
x_pos;
487 int mb_y_pos = td->
y_pos;
492 uint8_t *y_data, *u_data, *v_data;
494 int i, sf, slice_width_factor;
495 int slice_data_size, hdr_size, y_data_size, u_data_size, v_data_size;
496 int y_linesize, u_linesize, v_linesize;
502 slice_width_factor =
av_log2(mbs_per_slice);
504 y_data = pic->
data[0];
505 u_data = pic->
data[1];
506 v_data = pic->
data[2];
513 y_data += y_linesize;
514 u_data += u_linesize;
515 v_data += v_linesize;
522 if (slice_data_size < 6) {
528 hdr_size = buf[0] >> 3;
529 y_data_size =
AV_RB16(buf + 2);
530 u_data_size =
AV_RB16(buf + 4);
531 v_data_size = hdr_size > 7 ?
AV_RB16(buf + 6) :
532 slice_data_size - y_data_size - u_data_size - hdr_size;
534 if (hdr_size + y_data_size + u_data_size + v_data_size > slice_data_size ||
535 v_data_size < 0 || hdr_size < 6) {
540 sf = av_clip(buf[1], 1, 224);
541 sf = sf > 128 ? (sf - 96) << 2 : sf;
547 for (i = 0; i < 64; i++) {
555 (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize +
556 (mb_x_pos << 5)), y_linesize,
557 mbs_per_slice, 4, slice_width_factor + 2,
564 (uint16_t*) (u_data + (mb_y_pos << 4) * u_linesize +
575 (uint16_t*) (v_data + (mb_y_pos << 4) * v_linesize +
590 int slice_num, slice_width, x_pos, y_pos;
595 for (y_pos = 0; y_pos < ctx->
num_y_mbs; y_pos++) {
598 for (x_pos = 0; x_pos < ctx->
num_x_mbs && slice_width;
599 x_pos += slice_width) {
600 while (ctx->
num_x_mbs - x_pos < slice_width)
618 #define MOVE_DATA_PTR(nbytes) buf += (nbytes); buf_size -= (nbytes)
626 int buf_size = avpkt->
size;
627 int frame_hdr_size, pic_num, pic_data_size;
630 if (buf_size < 28 || buf_size <
AV_RB32(buf) ||
639 if (frame_hdr_size < 0)
644 if (picture->
data[0])
653 if (pic_data_size < 0)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
This structure describes decoded (raw) audio or video data.
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)
const uint8_t ff_prores_ac_codebook[7]
AVFrame * coded_frame
the picture in the bitstream
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
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
#define AV_PIX_FMT_YUV444P10
static int get_sbits(GetBitContext *s, int n)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
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)
void(* idct_put)(uint16_t *out, int linesize, DCTELEM *block, const int16_t *qmat)
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 init(AVCodecParserContext *s)
ProresThreadData * slice_data
int16_t qmat_chroma_scaled[64]
static int get_bits_left(GetBitContext *gb)
struct ProresContext ProresContext
#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.
struct ProresThreadData ProresThreadData
#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 int decode_ac_coeffs(GetBitContext *gb, DCTELEM *out, int blocks_per_slice, int plane_size_factor, const uint8_t *scan)
Decode AC coefficients for all blocks in a slice.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
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 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 int decode_vlc_codeword(GetBitContext *gb, unsigned codebook)
Read an unsigned rice/exp golomb codeword.
const uint8_t ff_prores_interlaced_scan[64]
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
const uint8_t ff_prores_progressive_scan[64]
#define OPEN_READER(name, gb)
static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, const int data_size, AVCodecContext *avctx)
void avcodec_get_frame_defaults(AVFrame *frame)
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.
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)
AVCodec ff_prores_decoder
static int decode_picture(ProresContext *ctx, int pic_num, AVCodecContext *avctx)
void ff_proresdsp_init(ProresDSPContext *dsp)
#define CODEC_CAP_SLICE_THREADS
int pic_format
2 = 422, 3 = 444
#define DECLARE_ALIGNED(n, t, v)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_PIX_FMT_YUV422P10
int prev_slice_sf
scalefactor of the previous decoded slice
common internal api header.
#define AVERROR_INVALIDDATA
int qmat_changed
1 - global quantization matrices changed
#define PRORES_BITS_PER_SAMPLE
output precision of prores decoder
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)
int key_frame
1 -> keyframe, 0-> not
int frame_type
0 = progressive, 1 = top-field first, 2 = bottom-field first
This structure stores compressed data.
int16_t qmat_luma_scaled[64]
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).