82 32768, 16705, 16705, 17734, 17032, 17734, 18205, 18081,
83 18081, 18205, 18725, 18562, 19195, 18562, 18725, 19266,
84 19091, 19705, 19705, 19091, 19266, 21407, 19643, 20267,
85 20228, 20267, 19643, 21407, 22725, 21826, 20853, 20806,
86 20806, 20853, 21826, 22725, 23170, 23170, 21407, 21400,
87 21407, 23170, 23170, 24598, 23786, 22018, 22018, 23786,
88 24598, 25251, 24465, 22654, 24465, 25251, 25972, 25172,
89 25172, 25972, 26722, 27969, 26722, 29692, 29692, 31521,
92 32768, 16384, 16705, 16705, 17734, 17734, 17734, 17734,
93 18081, 18081, 18725, 18725, 21407, 21407, 19091, 19091,
94 19195, 19195, 18205, 18205, 18725, 18725, 19705, 19705,
95 20267, 20267, 21826, 21826, 23170, 23170, 20806, 20806,
96 20267, 20267, 19266, 19266, 21407, 21407, 20853, 20853,
97 21400, 21400, 23786, 23786, 24465, 24465, 22018, 22018,
98 23170, 23170, 22725, 22725, 24598, 24598, 24465, 24465,
99 25172, 25172, 27969, 27969, 25972, 25972, 29692, 29692
106 128, 16, 16, 17, 17, 17, 18, 18,
107 18, 18, 18, 18, 19, 18, 18, 19,
108 19, 19, 19, 19, 19, 42, 38, 40,
109 40, 40, 38, 42, 44, 43, 41, 41,
110 41, 41, 43, 44, 45, 45, 42, 42,
111 42, 45, 45, 48, 46, 43, 43, 46,
112 48, 49, 48, 44, 48, 49, 101, 98,
113 98, 101, 104, 109, 104, 116, 116, 123,
116 128, 16, 16, 17, 17, 17, 25, 25,
117 25, 25, 26, 25, 26, 25, 26, 26,
118 26, 27, 27, 26, 26, 42, 38, 40,
119 40, 40, 38, 42, 44, 43, 41, 41,
120 41, 41, 43, 44, 91, 91, 84, 84,
121 84, 91, 91, 96, 93, 86, 86, 93,
122 96, 197, 191, 177, 191, 197, 203, 197,
123 197, 203, 209, 219, 209, 232, 232, 246,
126 128, 16, 16, 17, 17, 17, 18, 18,
127 18, 18, 18, 18, 19, 18, 18, 19,
128 19, 19, 19, 19, 19, 42, 38, 40,
129 40, 40, 38, 42, 44, 43, 41, 41,
130 41, 41, 43, 44, 68, 68, 63, 63,
131 63, 68, 68, 96, 92, 86, 86, 92,
132 96, 98, 96, 88, 96, 98, 202, 196,
133 196, 202, 208, 218, 208, 232, 232, 246,
136 128, 24, 24, 26, 26, 26, 36, 36,
137 36, 36, 36, 36, 38, 36, 36, 38,
138 38, 38, 38, 38, 38, 84, 76, 80,
139 80, 80, 76, 84, 88, 86, 82, 82,
140 82, 82, 86, 88, 182, 182, 168, 168,
141 168, 182, 182, 192, 186, 192, 172, 186,
142 192, 394, 382, 354, 382, 394, 406, 394,
143 394, 406, 418, 438, 418, 464, 464, 492,
146#define TEX_VLC_BITS 10
178 &
tmp[0].len8,
sizeof(
tmp[0]),
204 uint32_t *factor1 = &
ctx->idct_factor[0],
209 static const uint8_t dv100_qstep[16] = {
212 2, 3, 4, 5, 6, 7, 8, 16, 18, 20, 22, 24, 28, 52
214 const uint16_t *iweight1, *iweight2;
223 for (
c = 0;
c < 4;
c++) {
224 for (
s = 0;
s < 16;
s++) {
225 for (
i = 0;
i < 64;
i++) {
226 *factor1++ = (dv100_qstep[
s] << (
c + 9)) * iweight1[
i];
227 *factor2++ = (dv100_qstep[
s] << (
c + 9)) * iweight2[
i];
232 static const uint8_t dv_quant_areas[4] = { 6, 21, 43, 64 };
235 for (
s = 0;
s < 22;
s++) {
236 for (
i =
c = 0;
c < 4;
c++) {
237 for (;
i < dv_quant_areas[
c];
i++) {
239 *factor2++ = (*factor1++) << 1;
257 for (
i = 0;
i < 64;
i++)
261 for (
i = 0;
i < 64;
i++){
263 s->dv_zigzag[1][
i] =
s->idsp.idct_permutation[(j & 7) + (j & 8) * 4 + (j & 48) / 2];
268 s->idct_put[0] =
s->idsp.idct_put;
280 const uint8_t *scan_table =
mb->scan_table;
281 const uint32_t *factor_table =
mb->factor_table;
283 int partial_bit_count =
mb->partial_bit_count;
290 if (partial_bit_count > 0) {
291 re_cache = re_cache >> partial_bit_count |
292 mb->partial_bit_buffer;
293 re_index -= partial_bit_count;
294 mb->partial_bit_count = 0;
313 if (re_index + vlc_len > last_index) {
315 mb->partial_bit_count = last_index - re_index;
316 mb->partial_bit_buffer = re_cache & ~(-1u >>
mb->partial_bit_count);
317 re_index = last_index;
352 for (
i = 0;
i < 4;
i++) {
353 for (j = 0; j < 8; j++)
361 int stride, int16_t *blocks)
363 s->idsp.idct(blocks + 0*64);
364 s->idsp.idct(blocks + 1*64);
373 int stride, int16_t *blocks)
375 s->idsp.idct(blocks + 0*64);
376 s->idsp.idct(blocks + 1*64);
377 s->idsp.idct(blocks + 2*64);
378 s->idsp.idct(blocks + 3*64);
395 int quant, dc, dct_mode, class1, j;
396 int mb_index, mb_x, mb_y, last_index;
397 int y_stride, linesize;
401 const uint8_t *buf_ptr;
408 const int log2_blocksize = 3 - avctx->
lowres;
409 int is_field_mode[5];
410 int vs_bit_buffer_damaged = 0;
411 int mb_bit_buffer_damaged[5] = {0};
415 av_assert1((((uintptr_t) mb_bit_buffer) & 7) == 0);
416 av_assert1((((uintptr_t) vs_bit_buffer) & 7) == 0);
420 memset(sblock, 0, 5 *
DV_MAX_BPM *
sizeof(*sblock));
427 for (mb_index = 0; mb_index < 5; mb_index++, mb1 +=
s->sys->bpm,
block1 +=
s->sys->bpm * 64) {
429 quant = buf_ptr[3] & 0x0f;
431 if ((buf_ptr[3] >> 4) == 0x0E)
432 vs_bit_buffer_damaged = 1;
434 sta = buf_ptr[3] >> 4;
435 }
else if (sta != (buf_ptr[3] >> 4))
436 vs_bit_buffer_damaged = 1;
442 is_field_mode[mb_index] = 0;
443 for (j = 0; j <
s->sys->bpm; j++) {
444 last_index =
s->sys->block_sizes[j];
452 mb->idct_put =
s->idct_put[0];
453 mb->scan_table =
s->dv_zigzag[0];
454 mb->factor_table = &
s->idct_factor[(j >= 4) * 4 * 16 * 64 +
457 is_field_mode[mb_index] |= !j && dct_mode;
459 mb->idct_put =
s->idct_put[dct_mode && log2_blocksize == 3];
460 mb->scan_table =
s->dv_zigzag[dct_mode];
462 &
s->idct_factor[(class1 == 3) * 2 * 22 * 64 +
471 buf_ptr += last_index >> 3;
473 mb->partial_bit_count = 0;
475 ff_dlog(avctx,
"MB block: %d, %d ", mb_index, j);
482 if (
mb->pos >= 64 &&
mb->pos < 127)
483 vs_bit_buffer_damaged = mb_bit_buffer_damaged[mb_index] = 1;
489 if (mb_bit_buffer_damaged[mb_index] > 0)
499 for (j = 0; j <
s->sys->bpm; j++,
block += 64,
mb++) {
506 vs_bit_buffer_damaged = mb_bit_buffer_damaged[mb_index] = 1;
511 if (j >=
s->sys->bpm)
517 block = &sblock[0][0];
522 for (mb_index = 0; mb_index < 5; mb_index++) {
523 for (j = 0; j <
s->sys->bpm; j++) {
524 if (
mb->pos < 64 &&
get_bits_left(&gb) > 0 && !vs_bit_buffer_damaged) {
525 ff_dlog(avctx,
"start %d:%d\n", mb_index, j);
529 if (
mb->pos >= 64 &&
mb->pos < 127) {
531 "AC EOB marker is absent pos=%d\n",
mb->pos);
532 vs_bit_buffer_damaged = 1;
538 if (vs_bit_buffer_damaged && !retried) {
545 block = &sblock[0][0];
547 for (mb_index = 0; mb_index < 5; mb_index++) {
553 (
s->sys->height >= 720 && mb_y != 134)) {
554 y_stride = (
s->frame->linesize[0] <<
555 ((!is_field_mode[mb_index]) * log2_blocksize));
557 y_stride = (2 << log2_blocksize);
559 y_ptr =
s->frame->data[0] +
560 ((mb_y *
s->frame->linesize[0] + mb_x) << log2_blocksize);
561 if (mb_y == 134 && is_field_mode[mb_index]) {
564 linesize =
s->frame->linesize[0] << is_field_mode[mb_index];
565 mb[0].idct_put(y_ptr, linesize,
block + 0 * 64);
566 if (
s->sys->video_stype == 4) {
567 mb[2].idct_put(y_ptr + (1 << log2_blocksize), linesize,
block + 2 * 64);
569 mb[1].idct_put(y_ptr + (1 << log2_blocksize), linesize,
block + 1 * 64);
570 mb[2].idct_put(y_ptr + y_stride, linesize,
block + 2 * 64);
571 mb[3].idct_put(y_ptr + (1 << log2_blocksize) + y_stride, linesize,
block + 3 * 64);
580 for (j = 2; j; j--) {
581 uint8_t *c_ptr =
s->frame->data[j] + c_offset;
583 uint64_t aligned_pixels[64 / 8];
584 uint8_t *pixels = (uint8_t *) aligned_pixels;
585 uint8_t *c_ptr1, *ptr1;
587 mb->idct_put(pixels, 8,
block);
588 for (y = 0; y < (1 << log2_blocksize); y++, c_ptr +=
s->frame->linesize[j], pixels += 8) {
589 ptr1 = pixels + ((1 << (log2_blocksize))>>1);
590 c_ptr1 = c_ptr + (
s->frame->linesize[j] << log2_blocksize);
591 for (x = 0; x < (1 <<
FFMAX(log2_blocksize - 1, 0)); x++) {
592 c_ptr[x] = pixels[x];
599 y_stride = (mb_y == 134) ? (1 << log2_blocksize) :
600 s->frame->linesize[j] << ((!is_field_mode[mb_index]) * log2_blocksize);
601 if (mb_y == 134 && is_field_mode[mb_index]) {
606 linesize =
s->frame->linesize[j] << is_field_mode[mb_index];
609 if (
s->sys->bpm == 8) {
625 uint8_t *buf = avpkt->
data;
626 int buf_size = avpkt->
size;
628 const uint8_t *vsc_pack;
629 int apt, is16_9, ret;
656 vsc_pack = buf + 80 * 5 + 48 + 5;
659 is16_9 = (vsc_pack[2] & 0x07) == 0x02 ||
660 (!apt && (vsc_pack[2] & 0x07) == 0x07);
669 if (avctx->
height == 720) {
672 }
else if (avctx->
height == 1080) {
688 return s->sys->frame_size;
const FFCodec ff_dvvideo_decoder
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
static int16_t block1[64]
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
static int dv_work_pool_size(const AVDVProfile *d)
static void dv_calculate_mb_xy(const AVDVProfile *sys, const uint8_t *buf, const DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y)
const AVDVProfile * ff_dv_frame_profile(AVCodecContext *codec, const AVDVProfile *sys, const uint8_t *frame, unsigned buf_size)
Get a DV profile for the provided compressed frame.
const uint8_t ff_dv_quant_offset[4]
const uint8_t ff_dv_zigzag248_direct[64]
const uint8_t ff_dv_vlc_len[NB_DV_VLC]
const uint8_t ff_dv_quant_shifts[22][4]
const uint8_t ff_dv_vlc_run[NB_DV_VLC]
const uint8_t ff_dv_vlc_level[NB_DV_VLC]
#define NB_DV_ZERO_LEVEL_ENTRIES
static void dv100_idct_put_last_row_field_chroma(const DVDecContext *s, uint8_t *data, int stride, int16_t *blocks)
static const uint16_t dv_iweight_1080_y[64]
The "inverse" DV100 weights are actually just the spec weights (zig-zagged).
static av_cold void dv_init_static(void)
static av_always_inline void put_block_8x4(int16_t *block, uint8_t *restrict p, int stride)
static const uint16_t dv_iweight_720_c[64]
static av_cold int dvvideo_decode_init(AVCodecContext *avctx)
static const uint16_t dv_iweight_248[64]
static void dv100_idct_put_last_row_field_luma(const DVDecContext *s, uint8_t *data, int stride, int16_t *blocks)
static void bit_copy(PutBitContext *pb, GetBitContext *gb)
static const uint16_t dv_iweight_720_y[64]
static void dv_init_weight_tables(DVDecContext *ctx, const AVDVProfile *d)
static const uint16_t dv_iweight_88[64]
static const int dv_iweight_bits
static int dvvideo_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static const uint16_t dv_iweight_1080_c[64]
static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
static RL_VLC_ELEM dv_rl_vlc[1664]
static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, int16_t *block)
static const uint8_t frame_size[4]
bitstream reader API header.
static int get_sbits(GetBitContext *s, int n)
#define CLOSE_READER(name, gb)
static int get_bits_left(GetBitContext *gb)
#define SHOW_UBITS(name, gb, num)
static unsigned int get_bits1(GetBitContext *s)
#define OPEN_READER_NOSIZE(name, gb)
#define UPDATE_CACHE(name, gb)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#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 AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static void idct_put(FourXContext *f, int x, int y)
void ff_dv_init_dynamic_tables(DVwork_chunk *work_chunks, const AVDVProfile *d)
#define DV_MAX_BPM
maximum number of blocks per macroblock in any DV format
#define DV_PROFILE_IS_HD(p)
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
Multithreading API for decoders.
common internal API header
static int ff_thread_once(char *control, void(*routine)(void))
const uint8_t ff_zigzag_direct[64]
#define LOCAL_ALIGNED_16(t, v,...)
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
void ff_simple_idct248_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int error_concealment
error concealment flags
int64_t bit_rate
the average bitrate
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.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
void(* idct_put)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
uint32_t partial_bit_buffer
const uint32_t * factor_table
const uint8_t * scan_table
uint8_t partial_bit_count
DVwork_chunk work_chunks[4 *12 *27]
uint32_t idct_factor[2 *4 *16 *64]
void(* idct_put[2])(uint8_t *dest, ptrdiff_t stride, int16_t *block)
static AVFormatContext * ctx
int ff_vlc_init_from_lengths(VLC *vlc, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
#define VLC_INIT_USE_STATIC
static const uint8_t quant[64]