59 "Valid DV profiles are:\n",
73 memset(&fdsp,0,
sizeof(fdsp));
74 memset(&mecc,0,
sizeof(mecc));
75 memset(&pdsp,0,
sizeof(pdsp));
109 *vlc = 0xfe00 | (
level << 1) | sign;
183 put_bits(pb, bits_left, vlc >> size);
186 if (pb + 1 >= pb_end) {
230 131072, 257107, 257107, 242189, 252167, 242189, 235923, 237536,
231 237536, 235923, 229376, 231390, 223754, 231390, 229376, 222935,
232 224969, 217965, 217965, 224969, 222935, 200636, 218652, 211916,
233 212325, 211916, 218652, 200636, 188995, 196781, 205965, 206433,
234 206433, 205965, 196781, 188995, 185364, 185364, 200636, 200704,
235 200636, 185364, 185364, 174609, 180568, 195068, 195068, 180568,
236 174609, 170091, 175557, 189591, 175557, 170091, 165371, 170627,
237 170627, 165371, 160727, 153560, 160727, 144651, 144651, 136258,
240 131072, 262144, 257107, 257107, 242189, 242189, 242189, 242189,
241 237536, 237536, 229376, 229376, 200636, 200636, 224973, 224973,
242 223754, 223754, 235923, 235923, 229376, 229376, 217965, 217965,
243 211916, 211916, 196781, 196781, 185364, 185364, 206433, 206433,
244 211916, 211916, 222935, 222935, 200636, 200636, 205964, 205964,
245 200704, 200704, 180568, 180568, 175557, 175557, 195068, 195068,
246 185364, 185364, 188995, 188995, 174606, 174606, 175557, 175557,
247 170627, 170627, 153560, 153560, 165371, 165371, 144651, 144651,
252 #define DV100_SACRIFICE_QUALITY_FOR_SPEED 1 253 #define DV100_ENABLE_FINER 1 256 #define DV100_MAKE_QLEVEL(qno,cno) ((qno<<2) | (cno)) 257 #define DV100_QLEVEL_QNO(qlevel) (qlevel>>2) 258 #define DV100_QLEVEL_CNO(qlevel) (qlevel&0x3) 260 #define DV100_NUM_QLEVELS 31 309 #if DV100_SACRIFICE_QUALITY_FOR_SPEED 318 65536, 65536, 32768, 21845, 16384, 13107, 10923, 9362, 8192, 4096, 3641, 3277, 2979, 2731, 2341, 1260,
324 { 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
325 58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
326 55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
327 26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
328 25575, 25575, 24385, 23831, 23302, 23302, 24966, 24966,
329 24966, 23302, 23302, 21845, 22795, 24385, 24385, 22795,
330 21845, 21400, 21845, 23831, 21845, 21400, 10382, 10700,
331 10700, 10382, 10082, 9620, 10082, 9039, 9039, 8525, },
332 { 8192, 65536, 65536, 61681, 61681, 61681, 41943, 41943,
333 41943, 41943, 40330, 41943, 40330, 41943, 40330, 40330,
334 40330, 38836, 38836, 40330, 40330, 24966, 27594, 26214,
335 26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
336 25575, 25575, 24385, 23831, 11523, 11523, 12483, 12483,
337 12483, 11523, 11523, 10923, 11275, 12193, 12193, 11275,
338 10923, 5323, 5490, 5924, 5490, 5323, 5165, 5323,
339 5323, 5165, 5017, 4788, 5017, 4520, 4520, 4263, }
343 { 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
344 58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
345 55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
346 26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
347 25575, 25575, 24385, 23831, 15420, 15420, 16644, 16644,
348 16644, 15420, 15420, 10923, 11398, 12193, 12193, 11398,
349 10923, 10700, 10923, 11916, 10923, 10700, 5191, 5350,
350 5350, 5191, 5041, 4810, 5041, 4520, 4520, 4263, },
351 { 8192, 43691, 43691, 40330, 40330, 40330, 29127, 29127,
352 29127, 29127, 29127, 29127, 27594, 29127, 29127, 27594,
353 27594, 27594, 27594, 27594, 27594, 12483, 13797, 13107,
354 13107, 13107, 13797, 12483, 11916, 12193, 12788, 12788,
355 12788, 12788, 12193, 11916, 5761, 5761, 6242, 6242,
356 6242, 5761, 5761, 5461, 5638, 5461, 6096, 5638,
357 5461, 2661, 2745, 2962, 2745, 2661, 2583, 2661,
358 2661, 2583, 2509, 2394, 2509, 2260, 2260, 2131, }
364 const int *
weight,
int bias)
378 static const int classes[] = { 12, 24, 36, 0xffff };
380 static const int classes[] = { -1, -1, 255, 0xffff };
382 int max = classes[0];
385 const unsigned threshold = 2 * deadzone;
389 for (area = 0; area < 4; area++) {
393 int level = blk[zigzag_scan[
i]];
395 if (level + deadzone > threshold) {
396 bi->
sign[
i] = (level >> 31) & 1;
414 for (bi->
cno = 0; max > classes[bi->
cno]; bi->
cno++)
423 for (area = 0; area < 4; area++) {
448 const int *
weight,
int bias)
458 for (i = 0; i < 64; i += 2) {
462 level0 = blk[zigzag_scan[i+0]];
463 level1 = blk[zigzag_scan[i+1]];
466 bi->
sign[i+0] = (level0>>31)&1;
467 bi->
sign[i+1] = (level1>>31)&1;
470 level0 =
FFABS(level0);
471 level1 =
FFABS(level1);
474 level0 = (level0*weight[i+0] + 4096 + (1<<17)) >> 18;
475 level1 = (level1*weight[i+1] + 4096 + (1<<17)) >> 18;
478 bi->
save[i+0] = level0;
479 bi->
save[i+1] = level1;
482 if (bi->
save[i+0] > max)
484 if (bi->
save[i+1] > max)
524 memset(
blk, 0, 64*
sizeof(*
blk));
573 if (b->
area_q[0] == qno && b->
cno == cno)
587 for (k = 1; k < 64; k++) {
615 for (i = 0; i < 5; i++) {
617 for (j = 0; j < 8; j++) {
618 if (blks[8*i+j].min_qlevel > min_qlevel[i])
624 for (i = 0; i < 5; i++) {
626 if (qlevels[i] < min_qlevel[i])
627 qlevels[
i] = min_qlevel[
i];
631 for (j = 0; j < 8; j++) {
633 size[
i] += size_cache[8*i+j][qlevels[
i]];
639 int largest = size[0] % 5;
640 int qlevels_done = 0;
644 for (i = 0; i < 5; i++) {
645 if (qlevels[i] < qlevels[largest])
651 largest = (largest+1) % 5;
665 for (j = 0; j < 8; j++, b++) {
667 if(size_cache[8*i+j][qlevels[i]] == 0) {
672 size[
i] += size_cache[8*i+j][qlevels[
i]];
675 }
while (
vs_total_ac_bits_hd < size[0] + size[1] + size[2] + size[3] + size[4] && qlevels_done < 5);
681 int largest = size[0] % 5;
683 while (qlevels[0] > min_qlevel[0] ||
684 qlevels[1] > min_qlevel[1] ||
685 qlevels[2] > min_qlevel[2] ||
686 qlevels[3] > min_qlevel[3] ||
687 qlevels[4] > min_qlevel[4]) {
690 for (i = 0; i < 5; i++) {
691 if (qlevels[i] > min_qlevel[i] && qlevels[i] > qlevels[largest])
698 largest = (largest+1) % 5;
700 if (qlevels[i] <= min_qlevel[i]) {
705 save_qlevel = qlevels[
i];
707 if (qlevels[i] < min_qlevel[i])
708 qlevels[
i] = min_qlevel[
i];
716 for (j = 0; j < 8; j++, b++) {
718 if(size_cache[8*i+j][qlevels[i]] == 0) {
721 size[
i] += size_cache[8*i+j][qlevels[
i]];
727 qlevels[
i] = save_qlevel;
735 for (i = 0; i < 5; i++) {
739 for (j = 0; j < 8; j++, b++) {
759 for (i = 0; i < 5; i++) {
765 for (j = 0; j < 6; j++, b++) {
766 for (a = 0; a < 4; a++) {
799 }
while (qnos[0] | qnos[1] | qnos[2] | qnos[3] | qnos[4]);
804 for (j = 0; j < 6 * 5; j++, b++) {
806 for (k = b->
next[prev]; k < 64; k = b->
next[k]) {
807 if (b->
mb[k] < a && b->
mb[k] > -a) {
825 for (mb_index = 0; mb_index < 5; mb_index++) {
826 data = dif + mb_index*80 + 4;
827 for (i = 0; i < profile->
bpm; i++) {
831 data[1] |= blk[profile->
bpm*mb_index+
i].
cno << 4;
843 int mb_x, mb_y, c_offset;
844 ptrdiff_t linesize, y_stride;
854 int *qnosp = &qnos[0];
857 enc_blk = &enc_blks[0];
858 for (mb_index = 0; mb_index < 5; mb_index++) {
866 if (s->
sys->
height == 1080 && mb_y < 134)
870 for (i = 1; i < 8; i++)
876 (s->
sys->
height >= 720 && mb_y != 134)) {
903 for (j = 2; j; j--) {
910 for (i = 0; i < 8; i++) {
911 d = c_ptr + linesize * 8;
942 for (j = 0; j < 5 * s->
sys->
bpm;) {
949 for (i = 0; i < s->
sys->
bpm; i++, j++) {
953 put_sbits(&pbs[j], 9, ((enc_blks[j].
mb[0] >> 3) - 1024 + 2) >> 2);
963 for (i = 0; i < s->
sys->
bpm; i++)
966 &pbs[start_mb + s->
sys->
bpm]);
971 for (j = 0; j < 5 * s->
sys->
bpm; j++) {
974 if (enc_blks[j].partial_bit_count)
978 for (j = 0; j < 5 * s->
sys->
bpm; j++) {
985 "bitstream written beyond buffer size\n");
988 memset(pbs[j].buf + pos, 0xff, size - pos);
1085 int fsc = chan_num & 1;
1086 int fsp = 1 - (chan_num >> 1);
1089 buf[1] = (seq_num << 4) |
1099 if (syb_num == 0 || syb_num == 6) {
1100 buf[0] = (fr << 7) |
1103 }
else if (syb_num == 11) {
1104 buf[0] = (fr << 7) |
1107 buf[0] = (fr << 7) |
1125 memset(buf, 0xff, 80 * 6);
1134 for (j = 0; j < 2; j++) {
1136 for (k = 0; k < 6; k++)
1142 for (j = 0; j < 3; j++) {
1153 for (j = 0; j < 135; j++) {
1155 memset(buf, 0xff, 80);
1180 #if FF_API_CODED_FRAME 1201 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM 1202 #define OFFSET(x) offsetof(DVVideoContext, x) 1204 {
"quant_deadzone",
"Quantizer dead zone",
OFFSET(quant_deadzone),
AV_OPT_TYPE_INT, { .i64 = 7 }, 0, 1024,
VE },
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
static void dv_guess_qnos_hd(EncBlockInfo *blks, int *qnos)
This structure describes decoded (raw) audio or video data.
void(* get_pixels)(int16_t *block, const uint8_t *pixels, ptrdiff_t linesize)
ptrdiff_t const GLvoid * data
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static const AVOption dv_options[]
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
const uint8_t * block_sizes
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
static int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t *buf)
static const int dv_weight_720[2][64]
const char * av_default_item_name(void *ptr)
Return the context name.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int ildct_cmp
interlaced DCT comparison function
const uint8_t ff_dv_quant_offset[4]
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
Macro definitions for various function/variable attributes.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static const int dv100_qlevel_inc
static av_always_inline int dv_guess_dct_mode(DVVideoContext *s, uint8_t *data, ptrdiff_t linesize)
#define LOCAL_ALIGNED_16(t, v,...)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
void ff_dv_print_profiles(void *logctx, int loglevel)
Print all allowed DV profiles into logctx at specified logging level.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static const int dv_weight_1080[2][64]
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static av_always_inline int dv_init_enc_block(EncBlockInfo *bi, uint8_t *data, int linesize, DVVideoContext *s, int chroma)
#define fs(width, name, subs,...)
static void dv_revise_cnos(uint8_t *dif, EncBlockInfo *blk, const AVDVProfile *profile)
static const int dv100_qstep_bits
const uint8_t ff_dv_zigzag248_direct[64]
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static av_cold void dv_vlc_map_tableinit(void)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
enum AVPixelFormat pix_fmt
static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
static const int dv_weight_bits
#define DV100_NUM_QLEVELS
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static const int dv_weight_88[64]
DVwork_chunk work_chunks[4 *12 *27]
static const int dv100_starting_qno
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVCodec ff_dvvideo_encoder
uint8_t partial_bit_count
static int put_bits_left(PutBitContext *s)
static const int weights[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int dv_work_pool_size(const AVDVProfile *d)
int flags
AV_CODEC_FLAG_*.
uint32_t partial_bit_buffer
const char * name
Name of the codec implementation.
av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx)
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
int flags
A combination of AV_PKT_FLAG values.
#define DV100_ENABLE_FINER
static int put_bits_count(PutBitContext *s)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static int dv100_actual_quantize(EncBlockInfo *b, int qlevel)
common internal API header
static const int vs_total_ac_bits
static const int dv100_chroma_bias
enum AVPictureType pict_type
Picture type of the frame.
#define DV100_MAKE_QLEVEL(qno, cno)
static int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c, uint8_t *buf)
#define DV_VLC_MAP_RUN_SIZE
#define DV_MAX_BPM
maximum number of blocks per macroblock in any DV format
int width
picture width / height.
static const int dv100_min_bias
#define DV_PROFILE_IS_HD(p)
static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t *vlc)
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
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define DV100_QLEVEL_QNO(qlevel)
void(* fdct)(int16_t *block)
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static const int mb_area_start[5]
void(* fdct[2])(int16_t *block)
static void dv_guess_qnos(EncBlockInfo *blks, int *qnos)
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)
Libavcodec external API header.
static const int dv100_qstep_inv[16]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_always_inline int dv100_quantize(int level, int qsinv)
void ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
#define LOCAL_ALIGNED_8(t, v,...)
main external API structure.
#define DV_VLC_MAP_LEV_SIZE
static const int vs_total_ac_bits_hd
Describe the class of an AVClass context structure.
static void dv_format_frame(DVVideoContext *c, uint8_t *buf)
#define DV100_QLEVEL_CNO(qlevel)
av_cold int ff_dvvideo_init(AVCodecContext *avctx)
const uint8_t ff_zigzag_direct[64]
void(* fdct248)(int16_t *block)
static int weight(int i, int blen, int offset)
static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
static enum AVPixelFormat pix_fmts[]
void(* get_pixels)(int16_t *av_restrict block, const uint8_t *pixels, ptrdiff_t stride)
static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt, const AVFrame *frame, int *got_packet)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_always_inline PutBitContext * dv_encode_ac(EncBlockInfo *bi, PutBitContext *pb_pool, PutBitContext *pb_end)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
const uint8_t ff_dv_quant_shifts[22][4]
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
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 void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
int ff_dv_init_dynamic_tables(DVVideoContext *ctx, const AVDVProfile *d)
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.
#define xf(width, name, var, range_min, range_max, subs,...)
#define FF_ENABLE_DEPRECATION_WARNINGS
int top_field_first
If the content is interlaced, is top field displayed first.
static void dv_calculate_mb_xy(DVVideoContext *s, DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y)
The official guide to swscale for confused that is
static const int dv_weight_248[64]
int key_frame
1 -> keyframe, 0-> not
static const AVClass dvvideo_encode_class
static const uint8_t dv100_qlevels[DV100_NUM_QLEVELS]
int frame_number
Frame counter, set by libavcodec.
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.
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
static struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]
static av_always_inline int dv_rl2vlc_size(int run, int l)
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.
AVPixelFormat
Pixel format.
This structure stores compressed data.
static void dv_set_class_number_hd(DVVideoContext *s, int16_t *blk, EncBlockInfo *bi, const uint8_t *zigzag_scan, const int *weight, int bias)