Go to the documentation of this file.
31 #define UNCHECKED_BITSTREAM_READER 1
78 #define DNXHD_VLC_BITS 9
79 #define DNXHD_DC_VLC_BITS 7
135 ctx->cid_table->ac_bits, 1, 1,
136 ctx->cid_table->ac_codes, 2, 2, 0)) < 0)
139 ctx->cid_table->dc_bits, 1, 1,
140 ctx->cid_table->dc_codes, 1, 1, 0)) < 0)
143 ctx->cid_table->run_bits, 1, 1,
144 ctx->cid_table->run_codes, 2, 2, 0)) < 0)
193 int old_bit_depth =
ctx->bit_depth, bitdepth;
194 uint64_t header_prefix;
197 "buffer too small (%d < 640).\n",
buf_size);
202 if (header_prefix == 0) {
204 "unknown header 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
209 ctx->cur_field =
buf[5] & 1;
210 frame->interlaced_frame = 1;
213 "interlaced %d, cur field %d\n",
buf[5] & 3,
ctx->cur_field);
217 ctx->mbaff = (
buf[0x6] >> 5) & 1;
218 ctx->alpha =
buf[0x7] & 1;
219 ctx->lla = (
buf[0x7] >> 1) & 1;
226 switch(
buf[0x21] >> 5) {
227 case 1: bitdepth = 8;
break;
228 case 2: bitdepth = 10;
break;
229 case 3: bitdepth = 12;
break;
232 "Unknown bitdepth indicator (%d)\n",
buf[0x21] >> 5);
242 if (
ctx->mbaff &&
ctx->cid_table->cid != 1260)
244 "Adaptive MB interlace flag in an unsupported profile.\n");
247 if (
ctx->act &&
ctx->cid_table->cid != 1256 &&
ctx->cid_table->cid != 1270)
249 "Adaptive color transform in an unsupported profile.\n");
251 ctx->is_444 = (
buf[0x2C] >> 6) & 1;
256 }
else if (bitdepth == 10) {
265 }
else if (bitdepth == 12) {
268 }
else if (bitdepth == 10) {
279 ctx->avctx->bits_per_raw_sample =
ctx->bit_depth = bitdepth;
280 if (
ctx->bit_depth != old_bit_depth) {
289 if (
ctx->width !=
ctx->cid_table->width &&
292 &
ctx->avctx->sample_aspect_ratio.den,
293 ctx->width,
ctx->cid_table->width, 255);
294 ctx->width =
ctx->cid_table->width;
303 ctx->mb_width = (
ctx->width + 15)>> 4;
306 if ((
ctx->height + 15) >> 4 ==
ctx->mb_height &&
frame->interlaced_frame)
310 ctx->width,
ctx->height,
ctx->is_444 ?
"4:4" :
"2:2",
315 ctx->data_offset = 0x170 + (
ctx->mb_height << 2);
317 if (
ctx->mb_height > 68) {
319 "mb height too big: %d\n",
ctx->mb_height);
322 ctx->data_offset = 0x280;
324 if ((
ctx->mb_height <<
frame->interlaced_frame) > (
ctx->height + 15) >> 4) {
326 "mb height too big: %d\n",
ctx->mb_height);
332 "buffer too small (%d < %d).\n",
buf_size,
ctx->data_offset);
342 for (
i = 0;
i <
ctx->mb_height;
i++) {
344 ff_dlog(
ctx->avctx,
"mb scan index %d, pos %d: %"PRIu32
"\n",
345 i, 0x170 + (
i << 2),
ctx->mb_scan_index[
i]);
348 "invalid mb scan index (%"PRIu32
" vs %u).\n",
366 int level, component, sign;
369 const uint8_t *ac_info =
ctx->cid_table->ac_info;
371 const int eob_index =
ctx->cid_table->eob_index;
379 component = 1 + (
n & 1);
381 weight_matrix =
ctx->cid_table->chroma_weight;
385 weight_matrix =
ctx->cid_table->luma_weight;
388 component = (
n >> 1) % 3;
391 weight_matrix =
ctx->cid_table->chroma_weight;
394 weight_matrix =
ctx->cid_table->luma_weight;
419 while (index1 != eob_index) {
420 level = ac_info[2*index1+0];
421 flags = ac_info[2*index1+1];
435 i +=
ctx->cid_table->run[index2];
444 j =
ctx->scantable.permutated[
i];
447 if (level_bias < 32 || weight_matrix[
i] != level_bias)
449 level >>= level_shift;
496 int dct_linesize_luma =
frame->linesize[0];
497 int dct_linesize_chroma =
frame->linesize[1];
498 uint8_t *dest_y, *dest_u, *dest_v;
499 int dct_y_offset, dct_x_offset;
501 int interlaced_mb = 0;
512 static int act_warned;
516 "ACT flag set, in violation of frame header.\n");
518 }
else if (row->
format == -1) {
526 for (
i = 0;
i < 64;
i++) {
533 for (
i = 0;
i < 8 + 4 *
ctx->is_444;
i++) {
534 if (
ctx->decode_dct_block(
ctx, row,
i) < 0)
538 if (
frame->interlaced_frame) {
539 dct_linesize_luma <<= 1;
540 dct_linesize_chroma <<= 1;
543 dest_y =
frame->data[0] + ((y * dct_linesize_luma) << 4) + (x << (4 +
shift1));
544 dest_u =
frame->data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 +
shift1 +
ctx->is_444));
545 dest_v =
frame->data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 +
shift1 +
ctx->is_444));
547 if (
frame->interlaced_frame &&
ctx->cur_field) {
548 dest_y +=
frame->linesize[0];
549 dest_u +=
frame->linesize[1];
550 dest_v +=
frame->linesize[2];
553 dct_linesize_luma <<= 1;
554 dct_linesize_chroma <<= 1;
557 dct_y_offset = interlaced_mb ?
frame->linesize[0] : (dct_linesize_luma << 3);
558 dct_x_offset = 8 <<
shift1;
560 ctx->idsp.idct_put(dest_y, dct_linesize_luma, row->
blocks[0]);
561 ctx->idsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, row->
blocks[1]);
562 ctx->idsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, row->
blocks[4]);
563 ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->
blocks[5]);
566 dct_y_offset = interlaced_mb ?
frame->linesize[1] : (dct_linesize_chroma << 3);
567 ctx->idsp.idct_put(dest_u, dct_linesize_chroma, row->
blocks[2]);
568 ctx->idsp.idct_put(dest_v, dct_linesize_chroma, row->
blocks[3]);
569 ctx->idsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, row->
blocks[6]);
570 ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, row->
blocks[7]);
573 ctx->idsp.idct_put(dest_y, dct_linesize_luma, row->
blocks[0]);
574 ctx->idsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, row->
blocks[1]);
575 ctx->idsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, row->
blocks[6]);
576 ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->
blocks[7]);
579 dct_y_offset = interlaced_mb ?
frame->linesize[1] : (dct_linesize_chroma << 3);
580 ctx->idsp.idct_put(dest_u, dct_linesize_chroma, row->
blocks[2]);
581 ctx->idsp.idct_put(dest_u + dct_x_offset, dct_linesize_chroma, row->
blocks[3]);
582 ctx->idsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, row->
blocks[8]);
583 ctx->idsp.idct_put(dest_u + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->
blocks[9]);
584 ctx->idsp.idct_put(dest_v, dct_linesize_chroma, row->
blocks[4]);
585 ctx->idsp.idct_put(dest_v + dct_x_offset, dct_linesize_chroma, row->
blocks[5]);
586 ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, row->
blocks[10]);
587 ctx->idsp.idct_put(dest_v + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->
blocks[11]);
595 int rownb,
int threadnb)
598 uint32_t
offset =
ctx->mb_scan_index[rownb];
610 for (x = 0; x <
ctx->mb_width; x++) {
637 ctx->rows[
i].format = -1;
672 buf +=
ctx->cid_table->coding_unit_size;
675 goto decode_coding_unit;
681 ctx->rows[
i].errors = 0;
685 static int act_warned;
689 ctx->rows[
i].format != -1 ) {
700 "Unsupported: variable ACT flag.\n");
704 ctx->pix_fmt =
ctx->bit_depth==10
708 ctx->pix_fmt =
ctx->bit_depth==10
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
#define AV_LOG_WARNING
Something somehow does not look correct.
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
AVPixelFormat
Pixel format.
static av_always_inline uint64_t ff_dnxhd_check_header_prefix_hr(uint64_t prefix)
static av_cold int init(AVCodecContext *avctx)
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.
This structure describes decoded (raw) audio or video data.
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
void * av_mallocz_array(size_t nmemb, size_t size)
#define AV_LOG_VERBOSE
Detailed information.
#define UPDATE_CACHE(name, gb)
static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame, const uint8_t *buf, int buf_size, int first_field)
unsigned int coding_unit_size
uint32_t mb_scan_index[512]
#define GET_CACHE(name, gb)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int cur_field
current interlaced field
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
#define AV_PIX_FMT_GBRP10
int key_frame
1 -> keyframe, 0-> not
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define FF_PROFILE_DNXHR_LB
#define AV_PIX_FMT_YUV444P10
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define CLOSE_READER(name, gb)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static av_cold int dnxhd_decode_close(AVCodecContext *avctx)
static int dnxhd_get_profile(int cid)
static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
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)
#define DNXHD_DC_VLC_BITS
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define SKIP_BITS(name, gb, num)
void ff_free_vlc(VLC *vlc)
const AVProfile ff_dnxhd_profiles[]
#define FF_PROFILE_DNXHR_HQ
const CIDEntry ff_dnxhd_cid_table[]
#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)
static av_cold int dnxhd_decode_init_thread_copy(AVCodecContext *avctx)
#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 ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
#define AV_PIX_FMT_YUV422P10
int ff_dnxhd_get_cid_table(int cid)
static av_cold int dnxhd_decode_init(AVCodecContext *avctx)
int format
-1:not set yet 0:off=RGB 1:on=YUV 2:variable
static void error(const char *err)
static const int shift1[6]
enum AVPictureType pict_type
Picture type of the frame.
#define AV_CODEC_CAP_DR1
Codec uses get_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 AV_PIX_FMT_YUV422P12
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 add an init_thread_copy() which re-allocates them for other threads. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. If there are inter-frame dependencies
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
int64_t cid
compression id
#define DECLARE_ALIGNED(n, t, v)
int interlaced_frame
The content of the picture is interlaced.
int(* decode_dct_block)(const struct DNXHDContext *ctx, RowContext *row, int n)
#define FF_PROFILE_DNXHR_SQ
#define i(width, name, range_min, range_max)
#define AV_PIX_FMT_GBRP12
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
enum AVPixelFormat pix_fmt
const uint8_t ff_zigzag_direct[64]
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static av_always_inline uint64_t ff_dnxhd_parse_header_prefix(const uint8_t *buf)
#define FF_ARRAY_ELEMS(a)
main external API structure.
#define SHOW_UBITS(name, gb, num)
static int dnxhd_init_vlc(DNXHDContext *ctx, uint32_t cid, int bitdepth)
#define FF_PROFILE_DNXHR_HQX
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)
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.
#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)
#define FF_PROFILE_DNXHR_444
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)
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.
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 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)
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