57 "Valid DV profiles are:\n",
74 memset(&mecc,0,
sizeof(mecc));
84 memset(&fdsp,0,
sizeof(fdsp));
86 s->fdct[0] = fdsp.
fdct;
112 *vlc = 0xfe00 | (
level << 1) | sign;
189 if (pb + 1 >= pb_end) {
233 131072, 257107, 257107, 242189, 252167, 242189, 235923, 237536,
234 237536, 235923, 229376, 231390, 223754, 231390, 229376, 222935,
235 224969, 217965, 217965, 224969, 222935, 200636, 218652, 211916,
236 212325, 211916, 218652, 200636, 188995, 196781, 205965, 206433,
237 206433, 205965, 196781, 188995, 185364, 185364, 200636, 200704,
238 200636, 185364, 185364, 174609, 180568, 195068, 195068, 180568,
239 174609, 170091, 175557, 189591, 175557, 170091, 165371, 170627,
240 170627, 165371, 160727, 153560, 160727, 144651, 144651, 136258,
243 131072, 262144, 257107, 257107, 242189, 242189, 242189, 242189,
244 237536, 237536, 229376, 229376, 200636, 200636, 224973, 224973,
245 223754, 223754, 235923, 235923, 229376, 229376, 217965, 217965,
246 211916, 211916, 196781, 196781, 185364, 185364, 206433, 206433,
247 211916, 211916, 222935, 222935, 200636, 200636, 205964, 205964,
248 200704, 200704, 180568, 180568, 175557, 175557, 195068, 195068,
249 185364, 185364, 188995, 188995, 174606, 174606, 175557, 175557,
250 170627, 170627, 153560, 153560, 165371, 165371, 144651, 144651,
255 #define DV100_SACRIFICE_QUALITY_FOR_SPEED 1
256 #define DV100_ENABLE_FINER 1
259 #define DV100_MAKE_QLEVEL(qno,cno) ((qno<<2) | (cno))
260 #define DV100_QLEVEL_QNO(qlevel) (qlevel>>2)
261 #define DV100_QLEVEL_CNO(qlevel) (qlevel&0x3)
263 #define DV100_NUM_QLEVELS 31
312 #if DV100_SACRIFICE_QUALITY_FOR_SPEED
321 65536, 65536, 32768, 21845, 16384, 13107, 10923, 9362, 8192, 4096, 3641, 3277, 2979, 2731, 2341, 1260,
327 { 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
328 58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
329 55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
330 26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
331 25575, 25575, 24385, 23831, 23302, 23302, 24966, 24966,
332 24966, 23302, 23302, 21845, 22795, 24385, 24385, 22795,
333 21845, 21400, 21845, 23831, 21845, 21400, 10382, 10700,
334 10700, 10382, 10082, 9620, 10082, 9039, 9039, 8525, },
335 { 8192, 65536, 65536, 61681, 61681, 61681, 41943, 41943,
336 41943, 41943, 40330, 41943, 40330, 41943, 40330, 40330,
337 40330, 38836, 38836, 40330, 40330, 24966, 27594, 26214,
338 26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
339 25575, 25575, 24385, 23831, 11523, 11523, 12483, 12483,
340 12483, 11523, 11523, 10923, 11275, 12193, 12193, 11275,
341 10923, 5323, 5490, 5924, 5490, 5323, 5165, 5323,
342 5323, 5165, 5017, 4788, 5017, 4520, 4520, 4263, }
346 { 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
347 58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
348 55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
349 26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
350 25575, 25575, 24385, 23831, 15420, 15420, 16644, 16644,
351 16644, 15420, 15420, 10923, 11398, 12193, 12193, 11398,
352 10923, 10700, 10923, 11916, 10923, 10700, 5191, 5350,
353 5350, 5191, 5041, 4810, 5041, 4520, 4520, 4263, },
354 { 8192, 43691, 43691, 40330, 40330, 40330, 29127, 29127,
355 29127, 29127, 29127, 29127, 27594, 29127, 29127, 27594,
356 27594, 27594, 27594, 27594, 27594, 12483, 13797, 13107,
357 13107, 13107, 13797, 12483, 11916, 12193, 12788, 12788,
358 12788, 12788, 12193, 11916, 5761, 5761, 6242, 6242,
359 6242, 5761, 5761, 5461, 5638, 5461, 6096, 5638,
360 5461, 2661, 2745, 2962, 2745, 2661, 2583, 2661,
361 2661, 2583, 2509, 2394, 2509, 2260, 2260, 2131, }
367 const int *
weight,
int bias)
381 static const int classes[] = { 12, 24, 36, 0xffff };
383 static const int classes[] = { -1, -1, 255, 0xffff };
385 int max = classes[0];
387 const unsigned deadzone =
s->quant_deadzone;
388 const unsigned threshold = 2 * deadzone;
392 for (area = 0; area < 4; area++) {
393 bi->
prev[area] = prev;
398 if (
level + deadzone > threshold) {
426 for (area = 0; area < 4; area++) {
427 bi->
prev[area] = prev;
451 const int *
weight,
int bias)
461 for (
i = 0;
i < 64;
i += 2) {
465 level0 =
blk[zigzag_scan[
i+0]];
466 level1 =
blk[zigzag_scan[
i+1]];
469 bi->
sign[
i+0] = (level0>>31)&1;
470 bi->
sign[
i+1] = (level1>>31)&1;
473 level0 =
FFABS(level0);
474 level1 =
FFABS(level1);
477 level0 = (level0*
weight[
i+0] + 4096 + (1<<17)) >> 18;
478 level1 = (level1*
weight[
i+1] + 4096 + (1<<17)) >> 18;
481 bi->
save[
i+0] = level0;
482 bi->
save[
i+1] = level1;
527 memset(
blk, 0, 64*
sizeof(*
blk));
533 if (
s->sys->height == 1080) {
576 if (
b->area_q[0] == qno &&
b->cno == cno)
577 return b->bit_size[0];
590 for (k = 1; k < 64; k++) {
604 return b->bit_size[0];
618 for (
i = 0;
i < 5;
i++) {
620 for (j = 0; j < 8; j++) {
621 if (blks[8*
i+j].min_qlevel > min_qlevel[
i])
627 for (
i = 0;
i < 5;
i++) {
629 if (qlevels[
i] < min_qlevel[
i])
630 qlevels[
i] = min_qlevel[
i];
634 for (j = 0; j < 8; j++) {
636 size[
i] += size_cache[8*
i+j][qlevels[
i]];
642 int largest =
size[0] % 5;
643 int qlevels_done = 0;
647 for (
i = 0;
i < 5;
i++) {
648 if (qlevels[
i] < qlevels[largest])
654 largest = (largest+1) % 5;
668 for (j = 0; j < 8; j++,
b++) {
670 if(size_cache[8*
i+j][qlevels[
i]] == 0) {
675 size[
i] += size_cache[8*
i+j][qlevels[
i]];
684 int largest =
size[0] % 5;
686 while (qlevels[0] > min_qlevel[0] ||
687 qlevels[1] > min_qlevel[1] ||
688 qlevels[2] > min_qlevel[2] ||
689 qlevels[3] > min_qlevel[3] ||
690 qlevels[4] > min_qlevel[4]) {
693 for (
i = 0;
i < 5;
i++) {
694 if (qlevels[
i] > min_qlevel[
i] && qlevels[
i] > qlevels[largest])
701 largest = (largest+1) % 5;
703 if (qlevels[
i] <= min_qlevel[
i]) {
708 save_qlevel = qlevels[
i];
710 if (qlevels[
i] < min_qlevel[
i])
711 qlevels[
i] = min_qlevel[
i];
719 for (j = 0; j < 8; j++,
b++) {
721 if(size_cache[8*
i+j][qlevels[
i]] == 0) {
724 size[
i] += size_cache[8*
i+j][qlevels[
i]];
730 qlevels[
i] = save_qlevel;
738 for (
i = 0;
i < 5;
i++) {
742 for (j = 0; j < 8; j++,
b++) {
752 int i, j, k,
a, prev,
a2;
762 for (
i = 0;
i < 5;
i++) {
768 for (j = 0; j < 6; j++,
b++) {
769 for (
a = 0;
a < 4;
a++) {
791 b->next[prev] =
b->next[k];
794 b->prev[
a + 1] = prev;
802 }
while (qnos[0] | qnos[1] | qnos[2] | qnos[3] | qnos[4]);
807 for (j = 0; j < 6 * 5; j++,
b++) {
809 for (k =
b->next[prev]; k < 64; k = b->next[k]) {
810 if (
b->mb[k] <
a &&
b->mb[k] > -
a) {
811 b->next[prev] =
b->next[k];
828 for (mb_index = 0; mb_index < 5; mb_index++) {
829 data = dif + mb_index*80 + 4;
846 int mb_x, mb_y, c_offset;
847 ptrdiff_t linesize, y_stride;
857 int *qnosp = &qnos[0];
860 enc_blk = &enc_blks[0];
861 for (mb_index = 0; mb_index < 5; mb_index++) {
866 y_ptr =
s->frame->data[0] + (mb_y *
s->frame->linesize[0] + mb_x) * 8;
867 linesize =
s->frame->linesize[0];
869 if (
s->sys->height == 1080 && mb_y < 134)
873 for (
i = 1;
i < 8;
i++)
879 (
s->sys->height >= 720 && mb_y != 134)) {
880 y_stride =
s->frame->linesize[0] * (1 << (3*!enc_blk->
dct_mode));
884 y_ptr =
s->frame->data[0] +
885 (mb_y *
s->frame->linesize[0] + mb_x) * 8;
886 linesize =
s->frame->linesize[0];
888 if (
s->sys->video_stype == 4) {
906 for (j = 2; j; j--) {
907 uint8_t *c_ptr =
s->frame->data[j] + c_offset;
908 linesize =
s->frame->linesize[j];
909 y_stride = (mb_y == 134) ? 8 : (
s->frame->linesize[j] * (1 << (3*!enc_blk->
dct_mode)));
913 for (
i = 0;
i < 8;
i++) {
914 d = c_ptr + linesize * 8;
931 if (
s->sys->bpm == 8)
945 for (j = 0; j < 5 *
s->sys->bpm;) {
952 for (
i = 0;
i <
s->sys->bpm;
i++, j++) {
953 int sz =
s->sys->block_sizes[
i] >> 3;
956 put_sbits(&pbs[j], 9, ((enc_blks[j].
mb[0] >> 3) - 1024 + 2) >> 2);
958 put_bits(&pbs[j], 2, enc_blks[j].cno);
966 for (
i = 0;
i <
s->sys->bpm;
i++)
967 if (enc_blks[start_mb +
i].partial_bit_count)
969 &pbs[start_mb +
s->sys->bpm]);
974 for (j = 0; j < 5 *
s->sys->bpm; j++) {
975 if (enc_blks[j].partial_bit_count)
977 if (enc_blks[j].partial_bit_count)
981 for (j = 0; j < 5 *
s->sys->bpm; j++) {
988 "bitstream written beyond buffer size\n");
1025 if (
c->avctx->height >= 720)
1026 fs =
c->avctx->height == 720 ||
c->frame->top_field_first ? 0x40 : 0x00;
1028 fs =
c->frame->top_field_first ? 0x00 : 0x40;
1031 (
int)(
av_q2d(
c->avctx->sample_aspect_ratio) *
1032 c->avctx->width /
c->avctx->height * 10) >= 17)
1059 (
c->sys->dsf << 5) |
1060 c->sys->video_stype;
1088 int fsc = chan_num & 1;
1089 int fsp = 1 - (chan_num >> 1);
1092 buf[1] = (seq_num << 4) |
1102 if (syb_num == 0 || syb_num == 6) {
1103 buf[0] = (fr << 7) |
1106 }
else if (syb_num == 11) {
1107 buf[0] = (fr << 7) |
1110 buf[0] = (fr << 7) |
1124 int chan_offset = 2*(
c->sys->height == 720 &&
c->avctx->frame_number & 1);
1126 for (chan = 0; chan <
c->sys->n_difchan; chan++) {
1127 for (
i = 0;
i <
c->sys->difseg_size;
i++) {
1128 memset(buf, 0xff, 80 * 6);
1137 for (j = 0; j < 2; j++) {
1139 for (k = 0; k < 6; k++)
1145 for (j = 0; j < 3; j++) {
1156 for (j = 0; j < 135; j++) {
1158 memset(buf, 0xff, 80);
1181 s->get_pixels =
s->pdsp.get_pixels_unaligned;
1183 s->get_pixels =
s->pdsp.get_pixels;
1188 c->pix_fmt =
s->sys->pix_fmt;
1190 #if FF_API_CODED_FRAME
1192 c->coded_frame->key_frame = 1;
1211 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1212 #define OFFSET(x) offsetof(DVVideoContext, x)
1214 {
"quant_deadzone",
"Quantizer dead zone",
OFFSET(quant_deadzone),
AV_OPT_TYPE_INT, { .i64 = 7 }, 0, 1024,
VE },
Macro definitions for various function/variable attributes.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
#define is(width, name, range_min, range_max, subs,...)
#define fs(width, name, subs,...)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
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_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
#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_PKT_FLAG_KEY
The packet contains a keyframe.
#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.
@ AV_PICTURE_TYPE_I
Intra.
#define LIBAVUTIL_VERSION_INT
static const int weights[]
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static int weight(int i, int blen, int offset)
av_cold int ff_dvvideo_init(AVCodecContext *avctx)
int ff_dv_init_dynamic_tables(DVVideoContext *ctx, const AVDVProfile *d)
static void dv_calculate_mb_xy(DVVideoContext *s, DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y)
#define DV_MAX_BPM
maximum number of blocks per macroblock in any DV format
static int dv_work_pool_size(const AVDVProfile *d)
#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 int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t *buf)
static av_always_inline int dv_set_class_number_sd(DVVideoContext *s, int16_t *blk, EncBlockInfo *bi, const uint8_t *zigzag_scan, const int *weight, int bias)
static int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num, uint8_t seq_num, uint8_t dif_num, uint8_t *buf)
static av_always_inline PutBitContext * dv_encode_ac(EncBlockInfo *bi, PutBitContext *pb_pool, PutBitContext *pb_end)
static const int dv100_qstep_inv[16]
static const int dv100_starting_qno
static av_always_inline int dv_init_enc_block(EncBlockInfo *bi, uint8_t *data, int linesize, DVVideoContext *s, int chroma)
static void dv_set_class_number_hd(DVVideoContext *s, int16_t *blk, EncBlockInfo *bi, const uint8_t *zigzag_scan, const int *weight, int bias)
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 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)
#define DV100_QLEVEL_CNO(qlevel)
#define DV100_NUM_QLEVELS
static const int dv100_min_bias
static const int dv_weight_248[64]
AVCodec ff_dvvideo_encoder
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 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 av_always_inline int dv_guess_dct_mode(DVVideoContext *s, uint8_t *data, ptrdiff_t linesize)
static void dv_format_frame(DVVideoContext *c, uint8_t *buf)
static int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c, uint8_t *buf)
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_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
static enum AVPixelFormat pix_fmts[]
const uint8_t ff_zigzag_direct[64]
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
int ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
#define LOCAL_ALIGNED_16(t, v,...)
#define LOCAL_ALIGNED_8(t, v,...)
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.
AVPixelFormat
Pixel format.
@ 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 int put_bits_count(PutBitContext *s)
static int put_bits_left(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
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_*.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
uint32_t partial_bit_buffer
uint8_t partial_bit_count
void(* fdct248)(int16_t *block)
void(* fdct)(int16_t *block)