32 #define UNCHECKED_BITSTREAM_READER 1
79 #define DNXHD_VLC_BITS 9
80 #define DNXHD_DC_VLC_BITS 7
136 ctx->cid_table->ac_bits, 1, 1,
137 ctx->cid_table->ac_codes, 2, 2, 0);
139 ctx->cid_table->dc_bits, 1, 1,
140 ctx->cid_table->dc_codes, 1, 1, 0);
142 ctx->cid_table->run_bits, 1, 1,
143 ctx->cid_table->run_codes, 2, 2, 0);
172 int old_bit_depth =
ctx->bit_depth, bitdepth;
173 uint64_t header_prefix;
176 "buffer too small (%d < 640).\n",
buf_size);
181 if (header_prefix == 0) {
183 "unknown header 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
188 ctx->cur_field =
buf[5] & 1;
192 "interlaced %d, cur field %d\n",
buf[5] & 3,
ctx->cur_field);
196 ctx->mbaff = (
buf[0x6] >> 5) & 1;
197 ctx->alpha =
buf[0x7] & 1;
198 ctx->lla = (
buf[0x7] >> 1) & 1;
205 switch(
buf[0x21] >> 5) {
206 case 1: bitdepth = 8;
break;
207 case 2: bitdepth = 10;
break;
208 case 3: bitdepth = 12;
break;
211 "Unknown bitdepth indicator (%d)\n",
buf[0x21] >> 5);
221 if (
ctx->mbaff &&
ctx->cid_table->cid != 1260)
223 "Adaptive MB interlace flag in an unsupported profile.\n");
225 switch ((
buf[0x2C] >> 1) & 3) {
233 if (
ctx->act &&
ctx->cid_table->cid != 1256 &&
ctx->cid_table->cid != 1270)
235 "Adaptive color transform in an unsupported profile.\n");
237 ctx->is_444 = (
buf[0x2C] >> 6) & 1;
242 }
else if (bitdepth == 10) {
251 }
else if (bitdepth == 12) {
254 }
else if (bitdepth == 10) {
265 ctx->avctx->bits_per_raw_sample =
ctx->bit_depth = bitdepth;
266 if (
ctx->bit_depth != old_bit_depth) {
275 if (
ctx->width !=
ctx->cid_table->width &&
278 &
ctx->avctx->sample_aspect_ratio.den,
279 ctx->width,
ctx->cid_table->width, 255);
280 ctx->width =
ctx->cid_table->width;
289 ctx->mb_width = (
ctx->width + 15)>> 4;
296 ctx->width,
ctx->height,
ctx->is_444 ?
"4:4" :
"2:2",
301 ctx->data_offset = 0x170 + (
ctx->mb_height << 2);
303 if (
ctx->mb_height > 68) {
305 "mb height too big: %d\n",
ctx->mb_height);
308 ctx->data_offset = 0x280;
312 "mb height too big: %d\n",
ctx->mb_height);
318 "buffer too small (%d < %d).\n",
buf_size,
ctx->data_offset);
328 for (
i = 0;
i <
ctx->mb_height;
i++) {
330 ff_dlog(
ctx->avctx,
"mb scan index %d, pos %d: %"PRIu32
"\n",
331 i, 0x170 + (
i << 2),
ctx->mb_scan_index[
i]);
334 "invalid mb scan index (%"PRIu32
" vs %u).\n",
352 int level, component, sign;
355 const uint8_t *ac_info =
ctx->cid_table->ac_info;
357 const int eob_index =
ctx->cid_table->eob_index;
365 component = 1 + (n & 1);
367 weight_matrix =
ctx->cid_table->chroma_weight;
371 weight_matrix =
ctx->cid_table->luma_weight;
374 component = (n >> 1) % 3;
377 weight_matrix =
ctx->cid_table->chroma_weight;
380 weight_matrix =
ctx->cid_table->luma_weight;
405 while (index1 != eob_index) {
406 level = ac_info[2*index1+0];
407 flags = ac_info[2*index1+1];
421 i +=
ctx->cid_table->run[index2];
430 j =
ctx->scantable.permutated[
i];
433 if (level_bias < 32 || weight_matrix[
i] != level_bias)
435 level >>= level_shift;
484 uint8_t *dest_y, *dest_u, *dest_v;
485 int dct_y_offset, dct_x_offset;
487 int interlaced_mb = 0;
498 static int act_warned;
502 "ACT flag set, in violation of frame header.\n");
504 }
else if (row->
format == -1) {
512 for (
i = 0;
i < 64;
i++) {
519 for (
i = 0;
i < 8 + 4 *
ctx->is_444;
i++) {
520 if (
ctx->decode_dct_block(
ctx, row,
i) < 0)
525 dct_linesize_luma <<= 1;
526 dct_linesize_chroma <<= 1;
529 dest_y =
frame->
data[0] + ((y * dct_linesize_luma) << 4) + (x << (4 +
shift1));
530 dest_u =
frame->
data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 +
shift1 +
ctx->is_444));
531 dest_v =
frame->
data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 +
shift1 +
ctx->is_444));
539 dct_linesize_luma <<= 1;
540 dct_linesize_chroma <<= 1;
543 dct_y_offset = interlaced_mb ?
frame->
linesize[0] : (dct_linesize_luma << 3);
544 dct_x_offset = 8 <<
shift1;
546 ctx->idsp.idct_put(dest_y, dct_linesize_luma, row->
blocks[0]);
547 ctx->idsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, row->
blocks[1]);
548 ctx->idsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, row->
blocks[4]);
549 ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->
blocks[5]);
552 dct_y_offset = interlaced_mb ?
frame->
linesize[1] : (dct_linesize_chroma << 3);
553 ctx->idsp.idct_put(dest_u, dct_linesize_chroma, row->
blocks[2]);
554 ctx->idsp.idct_put(dest_v, dct_linesize_chroma, row->
blocks[3]);
555 ctx->idsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, row->
blocks[6]);
556 ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, row->
blocks[7]);
559 ctx->idsp.idct_put(dest_y, dct_linesize_luma, row->
blocks[0]);
560 ctx->idsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, row->
blocks[1]);
561 ctx->idsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, row->
blocks[6]);
562 ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->
blocks[7]);
565 dct_y_offset = interlaced_mb ?
frame->
linesize[1] : (dct_linesize_chroma << 3);
566 ctx->idsp.idct_put(dest_u, dct_linesize_chroma, row->
blocks[2]);
567 ctx->idsp.idct_put(dest_u + dct_x_offset, dct_linesize_chroma, row->
blocks[3]);
568 ctx->idsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, row->
blocks[8]);
569 ctx->idsp.idct_put(dest_u + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->
blocks[9]);
570 ctx->idsp.idct_put(dest_v, dct_linesize_chroma, row->
blocks[4]);
571 ctx->idsp.idct_put(dest_v + dct_x_offset, dct_linesize_chroma, row->
blocks[5]);
572 ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, row->
blocks[10]);
573 ctx->idsp.idct_put(dest_v + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->
blocks[11]);
581 int rownb,
int threadnb)
584 uint32_t
offset =
ctx->mb_scan_index[rownb];
596 for (x = 0; x <
ctx->mb_width; x++) {
621 ctx->rows[
i].format = -1;
656 buf +=
ctx->cid_table->coding_unit_size;
659 goto decode_coding_unit;
664 ret +=
ctx->rows[
i].errors;
665 ctx->rows[
i].errors = 0;
669 static int act_warned;
673 ctx->rows[
i].format != -1 ) {
684 "Unsupported: variable ACT flag.\n");
688 ctx->pix_fmt =
ctx->bit_depth==10
692 ctx->pix_fmt =
ctx->bit_depth==10
static const char *const format[]
Libavcodec external API header.
#define FF_PROFILE_DNXHR_444
#define FF_PROFILE_DNXHR_LB
#define FF_PROFILE_DNXHR_HQ
#define FF_PROFILE_DNXHR_SQ
#define FF_PROFILE_DNXHR_HQX
static av_cold int init(AVCodecContext *avctx)
void ff_free_vlc(VLC *vlc)
#define flags(name, subs,...)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
const CIDEntry * ff_dnxhd_get_cid_table(int cid)
static av_always_inline uint64_t ff_dnxhd_check_header_prefix_hr(uint64_t prefix)
#define DNXHD_VARIABLE
Indicate that a CIDEntry value must be read in the bitstream.
static av_always_inline uint64_t ff_dnxhd_parse_header_prefix(const uint8_t *buf)
bitstream reader API header.
#define GET_VLC(code, name, gb, table, bits, max_depth)
If the vlc code is invalid and max_depth=1, then no bits will be removed.
#define GET_CACHE(name, gb)
#define CLOSE_READER(name, gb)
#define SHOW_UBITS(name, gb, num)
static unsigned int get_bits1(GetBitContext *s)
#define SHOW_SBITS(name, gb, num)
#define OPEN_READER(name, gb)
#define SKIP_BITS(name, gb, num)
#define UPDATE_CACHE(name, gb)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define LAST_SKIP_BITS(name, gb, num)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
@ AV_PICTURE_TYPE_I
Intra.
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
static int dnxhd_decode_dct_block_10(const DNXHDContext *ctx, RowContext *row, int n)
static int dnxhd_decode_dct_block_12_444(const DNXHDContext *ctx, RowContext *row, int n)
static int dnxhd_init_vlc(DNXHDContext *ctx, uint32_t cid, int bitdepth)
static int dnxhd_decode_row(AVCodecContext *avctx, void *data, int rownb, int threadnb)
static int dnxhd_decode_macroblock(const DNXHDContext *ctx, RowContext *row, AVFrame *frame, int x, int y)
static int dnxhd_get_profile(int cid)
static av_cold int dnxhd_decode_init(AVCodecContext *avctx)
static av_always_inline int dnxhd_decode_dct_block(const DNXHDContext *ctx, RowContext *row, int n, int index_bits, int level_bias, int level_shift, int dc_shift)
static int dnxhd_decode_dct_block_10_444(const DNXHDContext *ctx, RowContext *row, int n)
static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int dnxhd_decode_dct_block_8(const DNXHDContext *ctx, RowContext *row, int n)
#define DNXHD_DC_VLC_BITS
static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame, const uint8_t *buf, int buf_size, int first_field)
static int dnxhd_decode_dct_block_12(const DNXHDContext *ctx, RowContext *row, int n)
static av_cold int dnxhd_decode_close(AVCodecContext *avctx)
static const int shift1[6]
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.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const AVProfile profiles[]
const uint8_t ff_zigzag_direct[64]
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GBRP12
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define AV_PIX_FMT_YUV444P10
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
const AVProfile ff_dnxhd_profiles[]
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
enum AVColorSpace colorspace
YUV colorspace type.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
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.
int coded_width
Bitstream width / height, may be different from width/height e.g.
const char * name
Name of the codec implementation.
int flags
Flags modifying the (de)muxer behaviour.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int top_field_first
If the content is interlaced, is top field displayed first.
int interlaced_frame
The content of the picture is interlaced.
enum AVColorSpace colorspace
YUV colorspace type.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
unsigned int coding_unit_size
int64_t cid
compression id
uint32_t mb_scan_index[512]
const CIDEntry * cid_table
int(* decode_dct_block)(const struct DNXHDContext *ctx, RowContext *row, int n)
int cur_field
current interlaced field
enum AVPixelFormat pix_fmt
int format
-1:not set yet 0:off=RGB 1:on=YUV 2:variable
#define avpriv_request_sample(...)
static void error(const char *err)
static int first_field(const struct video_data *s)
static const uint8_t offset[127][2]
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)