58 void (*
get_pixels)(int16_t *restrict
block,
const uint8_t *pixels, ptrdiff_t linesize);
81 "in DV, input value is: %s\n",
name ?
name :
"unknown");
89 "Valid DV profiles are:\n",
107 s->ildct_cmp = ildct_cmp[5];
110 memset(&fdsp,0,
sizeof(fdsp));
112 s->fdct[0] = fdsp.
fdct;
116#if !CONFIG_HARDCODED_TABLES
145 *vlc = 0xfe00 | (
level << 1) | sign;
222 if (pb + 1 >= pb_end) {
266 131072, 257107, 257107, 242189, 252167, 242189, 235923, 237536,
267 237536, 235923, 229376, 231390, 223754, 231390, 229376, 222935,
268 224969, 217965, 217965, 224969, 222935, 200636, 218652, 211916,
269 212325, 211916, 218652, 200636, 188995, 196781, 205965, 206433,
270 206433, 205965, 196781, 188995, 185364, 185364, 200636, 200704,
271 200636, 185364, 185364, 174609, 180568, 195068, 195068, 180568,
272 174609, 170091, 175557, 189591, 175557, 170091, 165371, 170627,
273 170627, 165371, 160727, 153560, 160727, 144651, 144651, 136258,
276 131072, 262144, 257107, 257107, 242189, 242189, 242189, 242189,
277 237536, 237536, 229376, 229376, 200636, 200636, 224973, 224973,
278 223754, 223754, 235923, 235923, 229376, 229376, 217965, 217965,
279 211916, 211916, 196781, 196781, 185364, 185364, 206433, 206433,
280 211916, 211916, 222935, 222935, 200636, 200636, 205964, 205964,
281 200704, 200704, 180568, 180568, 175557, 175557, 195068, 195068,
282 185364, 185364, 188995, 188995, 174606, 174606, 175557, 175557,
283 170627, 170627, 153560, 153560, 165371, 165371, 144651, 144651,
288#define DV100_SACRIFICE_QUALITY_FOR_SPEED 1
289#define DV100_ENABLE_FINER 1
292#define DV100_MAKE_QLEVEL(qno,cno) ((qno<<2) | (cno))
293#define DV100_QLEVEL_QNO(qlevel) (qlevel>>2)
294#define DV100_QLEVEL_CNO(qlevel) (qlevel&0x3)
296#define DV100_NUM_QLEVELS 31
345#if DV100_SACRIFICE_QUALITY_FOR_SPEED
354 65536, 65536, 32768, 21845, 16384, 13107, 10923, 9362, 8192, 4096, 3641, 3277, 2979, 2731, 2341, 1260,
360 { 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
361 58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
362 55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
363 26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
364 25575, 25575, 24385, 23831, 23302, 23302, 24966, 24966,
365 24966, 23302, 23302, 21845, 22795, 24385, 24385, 22795,
366 21845, 21400, 21845, 23831, 21845, 21400, 10382, 10700,
367 10700, 10382, 10082, 9620, 10082, 9039, 9039, 8525, },
368 { 8192, 65536, 65536, 61681, 61681, 61681, 41943, 41943,
369 41943, 41943, 40330, 41943, 40330, 41943, 40330, 40330,
370 40330, 38836, 38836, 40330, 40330, 24966, 27594, 26214,
371 26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
372 25575, 25575, 24385, 23831, 11523, 11523, 12483, 12483,
373 12483, 11523, 11523, 10923, 11275, 12193, 12193, 11275,
374 10923, 5323, 5490, 5924, 5490, 5323, 5165, 5323,
375 5323, 5165, 5017, 4788, 5017, 4520, 4520, 4263, }
379 { 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
380 58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
381 55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
382 26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
383 25575, 25575, 24385, 23831, 15420, 15420, 16644, 16644,
384 16644, 15420, 15420, 10923, 11398, 12193, 12193, 11398,
385 10923, 10700, 10923, 11916, 10923, 10700, 5191, 5350,
386 5350, 5191, 5041, 4810, 5041, 4520, 4520, 4263, },
387 { 8192, 43691, 43691, 40330, 40330, 40330, 29127, 29127,
388 29127, 29127, 29127, 29127, 27594, 29127, 29127, 27594,
389 27594, 27594, 27594, 27594, 27594, 12483, 13797, 13107,
390 13107, 13107, 13797, 12483, 11916, 12193, 12788, 12788,
391 12788, 12788, 12193, 11916, 5761, 5761, 6242, 6242,
392 6242, 5761, 5761, 5461, 5638, 5461, 6096, 5638,
393 5461, 2661, 2745, 2962, 2745, 2661, 2583, 2661,
394 2661, 2583, 2509, 2394, 2509, 2260, 2260, 2131, }
399 const uint8_t *zigzag_scan,
414 static const int classes[] = { 12, 24, 36, 0xffff };
416 static const int classes[] = { -1, -1, 255, 0xffff };
418 int max = classes[0];
420 const unsigned deadzone =
s->quant_deadzone;
421 const unsigned threshold = 2 * deadzone;
431 if (
level + deadzone > threshold) {
483 const uint8_t *zigzag_scan,
494 for (
i = 0;
i < 64;
i += 2) {
498 level0 =
blk[zigzag_scan[
i+0]];
499 level1 =
blk[zigzag_scan[
i+1]];
502 bi->
sign[
i+0] = (level0>>31)&1;
503 bi->
sign[
i+1] = (level1>>31)&1;
506 level0 =
FFABS(level0);
507 level1 =
FFABS(level1);
510 level0 = (level0*
weight[
i+0] + 4096 + (1<<17)) >> 18;
511 level1 = (level1*
weight[
i+1] + 4096 + (1<<17)) >> 18;
514 bi->
save[
i+0] = level0;
515 bi->
save[
i+1] = level1;
560 memset(
blk, 0, 64*
sizeof(*
blk));
566 if (
s->sys->height == 1080) {
609 if (
b->area_q[0] == qno &&
b->cno == cno)
610 return b->bit_size[0];
623 for (k = 1; k < 64; k++) {
637 return b->bit_size[0];
651 for (
i = 0;
i < 5;
i++) {
653 for (j = 0; j < 8; j++) {
654 if (blks[8*
i+j].min_qlevel > min_qlevel[
i])
660 for (
i = 0;
i < 5;
i++) {
662 if (qlevels[
i] < min_qlevel[
i])
663 qlevels[
i] = min_qlevel[
i];
667 for (j = 0; j < 8; j++) {
669 size[
i] += size_cache[8*
i+j][qlevels[
i]];
675 int largest =
size[0] % 5;
676 int qlevels_done = 0;
680 for (
i = 0;
i < 5;
i++) {
681 if (qlevels[
i] < qlevels[largest])
687 largest = (largest+1) % 5;
701 for (j = 0; j < 8; j++,
b++) {
703 if(size_cache[8*
i+j][qlevels[
i]] == 0) {
708 size[
i] += size_cache[8*
i+j][qlevels[
i]];
717 int largest =
size[0] % 5;
719 while (qlevels[0] > min_qlevel[0] ||
720 qlevels[1] > min_qlevel[1] ||
721 qlevels[2] > min_qlevel[2] ||
722 qlevels[3] > min_qlevel[3] ||
723 qlevels[4] > min_qlevel[4]) {
726 for (
i = 0;
i < 5;
i++) {
727 if (qlevels[
i] > min_qlevel[
i] && qlevels[
i] > qlevels[largest])
734 largest = (largest+1) % 5;
736 if (qlevels[
i] <= min_qlevel[
i]) {
741 save_qlevel = qlevels[
i];
743 if (qlevels[
i] < min_qlevel[
i])
744 qlevels[
i] = min_qlevel[
i];
752 for (j = 0; j < 8; j++,
b++) {
754 if(size_cache[8*
i+j][qlevels[
i]] == 0) {
757 size[
i] += size_cache[8*
i+j][qlevels[
i]];
763 qlevels[
i] = save_qlevel;
771 for (
i = 0;
i < 5;
i++) {
775 for (j = 0; j < 8; j++,
b++) {
785 int i, j, k,
a, prev,
a2;
795 for (
i = 0;
i < 5;
i++) {
801 for (j = 0; j < 6; j++,
b++) {
802 for (
a = 0;
a < 4;
a++) {
824 b->next[prev] =
b->next[k];
827 b->prev[
a + 1] = prev;
835 }
while (qnos[0] | qnos[1] | qnos[2] | qnos[3] | qnos[4]);
840 for (j = 0; j < 6 * 5; j++,
b++) {
842 for (k =
b->next[prev]; k < 64; k = b->next[k]) {
843 if (
b->mb[k] <
a &&
b->mb[k] > -
a) {
844 b->next[prev] =
b->next[k];
861 for (mb_index = 0; mb_index < 5; mb_index++) {
862 data = dif + mb_index*80 + 4;
879 int mb_x, mb_y, c_offset;
880 ptrdiff_t linesize, y_stride;
881 const uint8_t *y_ptr;
890 int *qnosp = &qnos[0];
893 enc_blk = &enc_blks[0];
894 for (mb_index = 0; mb_index < 5; mb_index++) {
899 y_ptr =
s->frame->data[0] + (mb_y *
s->frame->linesize[0] + mb_x) * 8;
900 linesize =
s->frame->linesize[0];
902 if (
s->sys->height == 1080 && mb_y < 134)
906 for (
i = 1;
i < 8;
i++)
912 (
s->sys->height >= 720 && mb_y != 134)) {
913 y_stride =
s->frame->linesize[0] * (1 << (3*!enc_blk->
dct_mode));
917 y_ptr =
s->frame->data[0] +
918 (mb_y *
s->frame->linesize[0] + mb_x) * 8;
919 linesize =
s->frame->linesize[0];
921 if (
s->sys->video_stype == 4) {
939 for (j = 2; j; j--) {
940 const uint8_t *c_ptr =
s->frame->data[j] + c_offset;
941 linesize =
s->frame->linesize[j];
942 y_stride = (mb_y == 134) ? 8 : (
s->frame->linesize[j] * (1 << (3*!enc_blk->
dct_mode)));
944 uint8_t *
b = scratch;
945 for (
i = 0;
i < 8;
i++) {
946 const uint8_t *d = c_ptr + linesize * 8;
963 if (
s->sys->bpm == 8)
977 for (j = 0; j < 5 *
s->sys->bpm;) {
984 for (
i = 0;
i <
s->sys->bpm;
i++, j++) {
985 int sz =
s->sys->block_sizes[
i] >> 3;
988 put_sbits(&pbs[j], 9, ((enc_blks[j].
mb[0] >> 3) - 1024 + 2) >> 2);
990 put_bits(&pbs[j], 2, enc_blks[j].cno);
998 for (
i = 0;
i <
s->sys->bpm;
i++)
999 if (enc_blks[start_mb +
i].partial_bit_count)
1001 &pbs[start_mb +
s->sys->bpm]);
1006 for (j = 0; j < 5 *
s->sys->bpm; j++) {
1007 if (enc_blks[j].partial_bit_count)
1009 if (enc_blks[j].partial_bit_count)
1013 for (j = 0; j < 5 *
s->sys->bpm; j++) {
1049 if (
c->avctx->height >= 720)
1055 (
int)(
av_q2d(
c->avctx->sample_aspect_ratio) *
1056 c->avctx->width /
c->avctx->height * 10) >= 17)
1060 buf[0] = (uint8_t) pack_id;
1083 (
c->sys->dsf << 5) |
1084 c->sys->video_stype;
1109 uint8_t seq_num, uint8_t dif_num,
1112 int fsc = chan_num & 1;
1113 int fsp = 1 - (chan_num >> 1);
1115 buf[0] = (uint8_t) t;
1116 buf[1] = (seq_num << 4) |
1126 if (syb_num == 0 || syb_num == 6) {
1127 buf[0] = (fr << 7) |
1130 }
else if (syb_num == 11) {
1131 buf[0] = (fr << 7) |
1134 buf[0] = (fr << 7) |
1148 int chan_offset = 2*(
c->sys->height == 720 &&
c->avctx->frame_num & 1);
1150 for (chan = 0; chan <
c->sys->n_difchan; chan++) {
1151 for (
i = 0;
i <
c->sys->difseg_size;
i++) {
1152 memset(buf, 0xff, 80 * 6);
1161 for (j = 0; j < 2; j++) {
1163 for (k = 0; k < 6; k++)
1169 for (j = 0; j < 3; j++) {
1180 for (j = 0; j < 135; j++) {
1182 memset(buf, 0xff, 80);
1203 ((uintptr_t)
frame->data[0] & 7 ||
frame->linesize[0] & 7 ||
1204 (uintptr_t)
frame->data[1] & 7 ||
frame->linesize[1] & 7 ||
1205 (uintptr_t)
frame->data[2] & 7 ||
frame->linesize[2] & 7))
1206 s->get_pixels =
s->pdsp.get_pixels_unaligned;
1208 s->get_pixels =
s->pdsp.get_pixels;
1213 memset(
pkt->data, 0,
pkt->size);
1215 c->pix_fmt =
s->sys->pix_fmt;
1229#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1230#define OFFSET(x) offsetof(DVEncContext, x)
1232 {
"quant_deadzone",
"Quantizer dead zone",
OFFSET(quant_deadzone),
AV_OPT_TYPE_INT, { .i64 = 7 }, 0, 1024,
VE },
1237 .class_name =
"dvvideo encoder",
1244 .p.name =
"dvvideo",
const FFCodec ff_dvvideo_encoder
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Libavcodec external API header.
#define is(width, name, range_min, range_max, subs,...)
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
#define CODEC_PIXFMTS(...)
#define CODEC_CHROMA_LOCS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define FF_COMPLIANCE_NORMAL
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 * av_dv_codec_profile2(int width, int height, enum AVPixelFormat pix_fmt, AVRational frame_rate)
Get a DV profile for the provided stream parameters.
void ff_dv_print_profiles(void *logctx, int loglevel)
Print all allowed DV profiles into logctx at specified logging level.
static av_cold void dv_vlc_map_tableinit(void)
#define DV_VLC_MAP_RUN_SIZE
#define DV_VLC_MAP_LEV_SIZE
static struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]
const uint8_t ff_dv_quant_offset[4]
const uint8_t ff_dv_zigzag248_direct[64]
const uint8_t ff_dv_quant_shifts[22][4]
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static double area(double x, const double *params)
Overlap between a destination pixel (unit box) and a source pixel of width params[0] <= 1,...
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
#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_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_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define LIBAVUTIL_VERSION_INT
static const int weights[]
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
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)
#define DV100_ENABLE_FINER
static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
static av_always_inline int dv100_quantize(int level, int qsinv)
static int dv100_actual_quantize(EncBlockInfo *b, int qlevel)
static void dv_set_class_number_hd(DVEncContext *s, int16_t *blk, EncBlockInfo *bi, const uint8_t *zigzag_scan, const int *weight, int bias)
static int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t *buf)
static int dv_write_dif_id(enum DVSectionType t, uint8_t chan_num, uint8_t seq_num, uint8_t dif_num, uint8_t *buf)
static av_always_inline int dv_guess_dct_mode(DVEncContext *s, const uint8_t *data, ptrdiff_t linesize)
static const int dv100_qstep_inv[16]
static const int dv100_starting_qno
static av_always_inline int dv_init_enc_block(EncBlockInfo *bi, const uint8_t *data, int linesize, DVEncContext *s, int chroma)
static const AVClass dvvideo_encode_class
static av_always_inline int dv_rl2vlc_size(int run, int l)
static const int vs_total_ac_bits
static const int vs_total_ac_bits_hd
static const int dv100_chroma_bias
static av_always_inline int dv_set_class_number_sd(DVEncContext *s, int16_t *blk, EncBlockInfo *bi, const uint8_t *zigzag_scan, const int *weight, int bias)
static void dv_format_frame(DVEncContext *c, uint8_t *buf)
static const uint8_t dv100_qlevels[DV100_NUM_QLEVELS]
static void dv_revise_cnos(uint8_t *dif, EncBlockInfo *blk, const AVDVProfile *profile)
#define DV100_MAKE_QLEVEL(qno, cno)
static int dv_write_pack(enum DVPackType pack_id, DVEncContext *c, uint8_t *buf)
#define DV100_QLEVEL_CNO(qlevel)
#define DV100_NUM_QLEVELS
static const int dv100_min_bias
static const int dv_weight_248[64]
static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
static const int dv_weight_88[64]
static const AVOption dv_options[]
static const int dv_weight_1080[2][64]
static av_always_inline PutBitContext * dv_encode_ac(EncBlockInfo *bi, PutBitContext *pb_pool, PutBitContext *pb_end)
static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t *vlc)
static const int dv100_qstep_bits
static void dv_guess_qnos(EncBlockInfo *blks, int *qnos)
static const int dv100_qlevel_inc
static const int dv_weight_720[2][64]
static void dv_guess_qnos_hd(EncBlockInfo *blks, int *qnos)
#define DV100_QLEVEL_QNO(qlevel)
static const int mb_area_start[5]
static const int dv_weight_bits
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, int bits_per_raw_sample)
Macro definitions for various function/variable attributes.
common internal API header
static int ff_thread_once(char *control, void(*routine)(void))
const uint8_t ff_zigzag_direct[64]
av_cold int ff_set_cmp(const MECmpContext *c, me_cmp_func *cmp, int type, int mpvenc)
Fill the function pointer array cmp[6] with me_cmp_funcs from c based upon type.
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
int(* me_cmp_func)(MPVEncContext *c, const uint8_t *blk1, const uint8_t *blk2, ptrdiff_t stride, int h)
#define LOCAL_ALIGNED_16(t, v,...)
#define LOCAL_ALIGNED_8(t, v,...)
#define PIXBLOCKDSP_8BPP_GET_PIXELS_SUPPORTS_UNALIGNED
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.
const char * av_chroma_location_name(enum AVChromaLocation location)
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static int put_bits_left(PutBitContext *s)
static int put_bytes_left(const PutBitContext *s, int round_up)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
const h264_weight_func weight
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
int ildct_cmp
interlaced DCT comparison function
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
void(* get_pixels)(int16_t *restrict block, const uint8_t *pixels, ptrdiff_t linesize)
DVwork_chunk work_chunks[4 *12 *27]
void(* fdct[2])(int16_t *block)
uint32_t partial_bit_buffer
uint8_t partial_bit_count
void(* fdct248)(int16_t *block)
void(* fdct)(int16_t *block)
static double a2(void *priv, double x, double y)
static int bias(int x, int c)