Go to the documentation of this file.
34 #define UNCHECKED_BITSTREAM_READER 1
80 #define DNXHD_VLC_BITS 9
81 #define DNXHD_DC_VLC_BITS 7
138 ctx->cid_table->ac_bits, 1, 1,
139 ctx->cid_table->ac_codes, 2, 2, 0)) < 0)
142 ctx->cid_table->dc_bits, 1, 1,
143 ctx->cid_table->dc_codes, 1, 1, 0)) < 0)
146 ctx->cid_table->run_bits, 1, 1,
147 ctx->cid_table->run_codes, 2, 2,
148 ctx->cid_table->run, 1, 1, 0)) < 0)
182 int old_bit_depth =
ctx->bit_depth, bitdepth;
183 uint64_t header_prefix;
186 "buffer too small (%d < 640).\n",
buf_size);
191 if (header_prefix == 0) {
193 "unknown header 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
203 "interlaced %d, cur field %d\n",
buf[5] & 3,
ctx->cur_field);
207 ctx->mbaff = (
buf[0x6] >> 5) & 1;
208 ctx->alpha =
buf[0x7] & 1;
209 ctx->lla = (
buf[0x7] >> 1) & 1;
216 switch(
buf[0x21] >> 5) {
217 case 1: bitdepth = 8;
break;
218 case 2: bitdepth = 10;
break;
219 case 3: bitdepth = 12;
break;
222 "Unknown bitdepth indicator (%d)\n",
buf[0x21] >> 5);
232 if (
ctx->mbaff &&
ctx->cid_table->cid != 1260)
234 "Adaptive MB interlace flag in an unsupported profile.\n");
236 switch ((
buf[0x2C] >> 1) & 3) {
244 if (
ctx->act &&
ctx->cid_table->cid != 1256 &&
ctx->cid_table->cid != 1270)
246 "Adaptive color transform in an unsupported profile.\n");
248 ctx->is_444 = (
buf[0x2C] >> 6) & 1;
253 }
else if (bitdepth == 10) {
262 }
else if (bitdepth == 12) {
265 }
else if (bitdepth == 10) {
276 ctx->avctx->bits_per_raw_sample =
ctx->bit_depth = bitdepth;
277 if (
ctx->bit_depth != old_bit_depth) {
281 ctx->idsp.idct_permutation);
286 if (
ctx->width !=
ctx->cid_table->width &&
289 &
ctx->avctx->sample_aspect_ratio.den,
290 ctx->width,
ctx->cid_table->width, 255);
291 ctx->width =
ctx->cid_table->width;
300 ctx->mb_width = (
ctx->width + 15)>> 4;
307 ctx->width,
ctx->height,
ctx->is_444 ?
"4:4" :
"2:2",
312 ctx->data_offset = 0x170 + (
ctx->mb_height << 2);
314 if (
ctx->mb_height > 68) {
316 "mb height too big: %d\n",
ctx->mb_height);
319 ctx->data_offset = 0x280;
323 "mb height too big: %d\n",
ctx->mb_height);
329 "buffer too small (%d < %d).\n",
buf_size,
ctx->data_offset);
339 for (
i = 0;
i <
ctx->mb_height;
i++) {
341 ff_dlog(
ctx->avctx,
"mb scan index %d, pos %d: %"PRIu32
"\n",
342 i, 0x170 + (
i << 2),
ctx->mb_scan_index[
i]);
345 "invalid mb scan index (%"PRIu32
" vs %u).\n",
363 int level, component, sign;
365 const uint8_t *weight_matrix;
366 const uint8_t *ac_info =
ctx->cid_table->ac_info;
368 const int eob_index =
ctx->cid_table->eob_index;
376 component = 1 + (n & 1);
378 weight_matrix =
ctx->cid_table->chroma_weight;
382 weight_matrix =
ctx->cid_table->luma_weight;
385 component = (n >> 1) % 3;
388 weight_matrix =
ctx->cid_table->chroma_weight;
391 weight_matrix =
ctx->cid_table->luma_weight;
416 while (index1 != eob_index) {
417 level = ac_info[2*index1+0];
418 flags = ac_info[2*index1+1];
442 j =
ctx->permutated_scantable[
i];
445 if (level_bias < 32 || weight_matrix[
i] != level_bias)
447 level >>= level_shift;
496 uint8_t *dest_y, *dest_u, *dest_v;
497 int dct_y_offset, dct_x_offset;
499 int interlaced_mb = 0;
510 static int act_warned;
514 "ACT flag set, in violation of frame header.\n");
516 }
else if (row->
format == -1) {
524 for (
i = 0;
i < 64;
i++) {
531 for (
i = 0;
i < 8 + 4 *
ctx->is_444;
i++) {
532 if (
ctx->decode_dct_block(
ctx, row,
i) < 0)
537 dct_linesize_luma <<= 1;
538 dct_linesize_chroma <<= 1;
541 dest_y =
frame->
data[0] + ((y * dct_linesize_luma) << 4) + (x << (4 +
shift1));
542 dest_u =
frame->
data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 +
shift1 +
ctx->is_444));
543 dest_v =
frame->
data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 +
shift1 +
ctx->is_444));
551 dct_linesize_luma <<= 1;
552 dct_linesize_chroma <<= 1;
555 dct_y_offset = interlaced_mb ?
frame->
linesize[0] : (dct_linesize_luma << 3);
556 dct_x_offset = 8 <<
shift1;
558 ctx->idsp.idct_put(dest_y, dct_linesize_luma, row->
blocks[0]);
559 ctx->idsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, row->
blocks[1]);
560 ctx->idsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, row->
blocks[4]);
561 ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->
blocks[5]);
564 dct_y_offset = interlaced_mb ?
frame->
linesize[1] : (dct_linesize_chroma << 3);
565 ctx->idsp.idct_put(dest_u, dct_linesize_chroma, row->
blocks[2]);
566 ctx->idsp.idct_put(dest_v, dct_linesize_chroma, row->
blocks[3]);
567 ctx->idsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, row->
blocks[6]);
568 ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, row->
blocks[7]);
571 ctx->idsp.idct_put(dest_y, dct_linesize_luma, row->
blocks[0]);
572 ctx->idsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, row->
blocks[1]);
573 ctx->idsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, row->
blocks[6]);
574 ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->
blocks[7]);
577 dct_y_offset = interlaced_mb ?
frame->
linesize[1] : (dct_linesize_chroma << 3);
578 ctx->idsp.idct_put(dest_u, dct_linesize_chroma, row->
blocks[2]);
579 ctx->idsp.idct_put(dest_u + dct_x_offset, dct_linesize_chroma, row->
blocks[3]);
580 ctx->idsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, row->
blocks[8]);
581 ctx->idsp.idct_put(dest_u + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->
blocks[9]);
582 ctx->idsp.idct_put(dest_v, dct_linesize_chroma, row->
blocks[4]);
583 ctx->idsp.idct_put(dest_v + dct_x_offset, dct_linesize_chroma, row->
blocks[5]);
584 ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, row->
blocks[10]);
585 ctx->idsp.idct_put(dest_v + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->
blocks[11]);
593 int rownb,
int threadnb)
596 uint32_t
offset =
ctx->mb_scan_index[rownb];
608 for (x = 0; x <
ctx->mb_width; x++) {
622 const uint8_t *
buf = avpkt->
data;
631 ctx->rows[
i].format = -1;
666 buf +=
ctx->cid_table->coding_unit_size;
669 goto decode_coding_unit;
675 ctx->rows[
i].errors = 0;
679 static int act_warned;
683 ctx->rows[
i].format != -1 ) {
694 "Unsupported: variable ACT flag.\n");
698 ctx->pix_fmt =
ctx->bit_depth==10
702 ctx->pix_fmt =
ctx->bit_depth==10
static void error(const char *err)
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
static av_always_inline uint64_t ff_dnxhd_check_header_prefix_hr(uint64_t prefix)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVColorSpace colorspace
YUV colorspace type.
#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.
enum AVColorSpace colorspace
YUV colorspace type.
This structure describes decoded (raw) audio or video data.
#define AV_PROFILE_DNXHR_444
#define AV_LOG_VERBOSE
Detailed information.
#define UPDATE_CACHE(name, gb)
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
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.
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame, const uint8_t *buf, int buf_size, int first_field)
unsigned int coding_unit_size
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in FFCodec caps_internal and use ff_thread_get_buffer() to allocate frames. Otherwise decode directly into the user-supplied frames. Call ff_thread_report_progress() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
uint32_t mb_scan_index[512]
#define GET_CACHE(name, gb)
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVCodec p
The public AVCodec.
int cur_field
current interlaced field
static int dnxhd_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
#define AV_PIX_FMT_GBRP10
static av_always_inline float scale(float x, float s)
#define AV_PROFILE_DNXHR_SQ
const FFCodec ff_dnxhd_decoder
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define AV_PIX_FMT_YUV444P10
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define AV_PROFILE_DNXHR_LB
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#define CLOSE_READER(name, gb)
static av_cold int dnxhd_decode_close(AVCodecContext *avctx)
static int dnxhd_get_profile(int cid)
#define AV_PROFILE_DNXHR_HQ
#define FF_CODEC_DECODE_CB(func)
av_cold void ff_blockdsp_init(BlockDSPContext *c)
int flags
Flags modifying the (de)muxer behaviour.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
#define SHOW_SBITS(name, gb, num)
int(* init)(AVBSFContext *ctx)
#define DNXHD_DC_VLC_BITS
#define AV_PROFILE_DNXHR_HQX
#define vlc_init(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define SKIP_BITS(name, gb, num)
#define CODEC_LONG_NAME(str)
const AVProfile ff_dnxhd_profiles[]
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
static int dnxhd_decode_dct_block_12_444(const DNXHDContext *ctx, RowContext *row, int n)
#define DNXHD_VARIABLE
Indicate that a CIDEntry value must be read in the bitstream.
@ AV_PICTURE_TYPE_I
Intra.
static unsigned int get_bits1(GetBitContext *s)
#define LAST_SKIP_BITS(name, gb, num)
#define AV_PIX_FMT_YUV422P10
static av_cold int dnxhd_decode_init(AVCodecContext *avctx)
int format
-1:not set yet 0:off=RGB 1:on=YUV 2:variable
enum AVPictureType pict_type
Picture type of the frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
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)
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define DECLARE_ALIGNED(n, t, v)
#define AV_PIX_FMT_YUV422P12
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#define AV_PIX_FMT_YUV444P12
#define OPEN_READER(name, gb)
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int ff_vlc_init_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Build VLC decoding tables suitable for use with get_vlc2().
uint8_t permutated_scantable[64]
const CIDEntry * ff_dnxhd_get_cid_table(int cid)
int64_t cid
compression id
int(* decode_dct_block)(const struct DNXHDContext *ctx, RowContext *row, int n)
#define i(width, name, range_min, range_max)
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
#define AV_PIX_FMT_GBRP12
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
enum AVPixelFormat pix_fmt
void * av_calloc(size_t nmemb, size_t size)
const uint8_t ff_zigzag_direct[64]
void ff_vlc_free(VLC *vlc)
static av_always_inline uint64_t ff_dnxhd_parse_header_prefix(const uint8_t *buf)
main external API structure.
#define SHOW_UBITS(name, gb, num)
static int dnxhd_init_vlc(DNXHDContext *ctx, uint32_t cid, int bitdepth)
int coded_width
Bitstream width / height, may be different from width/height e.g.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define avpriv_request_sample(...)
This structure stores compressed data.
static int dnxhd_decode_macroblock(const DNXHDContext *ctx, RowContext *row, AVFrame *frame, int x, int y)
int width
picture width / height.
static int dnxhd_decode_dct_block_10_444(const DNXHDContext *ctx, RowContext *row, int n)
#define flags(name, subs,...)
static int dnxhd_decode_row(AVCodecContext *avctx, void *data, int rownb, int threadnb)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
The exact code depends on how similar the blocks are and how related they are to the block
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
static int first_field(const struct video_data *s)
static int dnxhd_decode_dct_block_8(const DNXHDContext *ctx, RowContext *row, int n)
static const uint8_t shift1[6]
const CIDEntry * cid_table
static int dnxhd_decode_dct_block_10(const DNXHDContext *ctx, RowContext *row, int n)
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.
static int dnxhd_decode_dct_block_12(const DNXHDContext *ctx, RowContext *row, int n)
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.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16