FFmpeg
Data Structures | Macros | Functions | Variables
dvenc.c File Reference
#include "config.h"
#include "libavutil/attributes.h"
#include "libavutil/internal.h"
#include "libavutil/mem_internal.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/thread.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "dv.h"
#include "dv_profile_internal.h"
#include "dv_tablegen.h"
#include "encode.h"
#include "fdctdsp.h"
#include "mathops.h"
#include "me_cmp.h"
#include "pixblockdsp.h"
#include "put_bits.h"

Go to the source code of this file.

Data Structures

struct  EncBlockInfo
 

Macros

#define DV100_SACRIFICE_QUALITY_FOR_SPEED   1
 
#define DV100_ENABLE_FINER   1
 
#define DV100_MAKE_QLEVEL(qno, cno)   ((qno<<2) | (cno))
 
#define DV100_QLEVEL_QNO(qlevel)   (qlevel>>2)
 
#define DV100_QLEVEL_CNO(qlevel)   (qlevel&0x3)
 
#define DV100_NUM_QLEVELS   31
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
#define OFFSET(x)   offsetof(DVVideoContext, x)
 

Functions

static av_cold int dvvideo_encode_init (AVCodecContext *avctx)
 
static av_always_inline int dv_rl2vlc (int run, int l, int sign, uint32_t *vlc)
 
static av_always_inline int dv_rl2vlc_size (int run, int l)
 
static av_always_inline PutBitContextdv_encode_ac (EncBlockInfo *bi, PutBitContext *pb_pool, PutBitContext *pb_end)
 
static av_always_inline int dv_guess_dct_mode (DVVideoContext *s, uint8_t *data, ptrdiff_t linesize)
 
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 void dv_set_class_number_hd (DVVideoContext *s, int16_t *blk, EncBlockInfo *bi, const uint8_t *zigzag_scan, const int *weight, int bias)
 
static av_always_inline int dv_init_enc_block (EncBlockInfo *bi, uint8_t *data, int linesize, DVVideoContext *s, int chroma)
 
static av_always_inline int dv100_quantize (int level, int qsinv)
 
static int dv100_actual_quantize (EncBlockInfo *b, int qlevel)
 
static void dv_guess_qnos_hd (EncBlockInfo *blks, int *qnos)
 
static void dv_guess_qnos (EncBlockInfo *blks, int *qnos)
 
static void dv_revise_cnos (uint8_t *dif, EncBlockInfo *blk, const AVDVProfile *profile)
 
static int dv_encode_video_segment (AVCodecContext *avctx, void *arg)
 
static int dv_write_pack (enum dv_pack_type pack_id, DVVideoContext *c, uint8_t *buf)
 
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 int dv_write_ssyb_id (uint8_t syb_num, uint8_t fr, uint8_t *buf)
 
static void dv_format_frame (DVVideoContext *c, uint8_t *buf)
 
static int dvvideo_encode_frame (AVCodecContext *c, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 

Variables

static const int vs_total_ac_bits_hd = (68 * 6 + 52*2) * 5
 
static const int vs_total_ac_bits = (100 * 4 + 68 * 2) * 5
 
static const int mb_area_start [5] = { 1, 6, 21, 43, 64 }
 
static const int dv_weight_bits = 18
 
static const int dv_weight_88 [64]
 
static const int dv_weight_248 [64]
 
static const uint8_t dv100_qlevels [DV100_NUM_QLEVELS]
 
static const int dv100_min_bias = 0
 
static const int dv100_chroma_bias = 0
 
static const int dv100_starting_qno = 1
 
static const int dv100_qlevel_inc = 4
 
static const int dv100_qstep_bits = 16
 
static const int dv100_qstep_inv [16]
 
static const int dv_weight_1080 [2][64]
 
static const int dv_weight_720 [2][64]
 
static const AVOption dv_options []
 
static const AVClass dvvideo_encode_class
 
const FFCodec ff_dvvideo_encoder
 

Detailed Description

DV encoder

Definition in file dvenc.c.

Macro Definition Documentation

◆ DV100_SACRIFICE_QUALITY_FOR_SPEED

#define DV100_SACRIFICE_QUALITY_FOR_SPEED   1

Definition at line 259 of file dvenc.c.

◆ DV100_ENABLE_FINER

#define DV100_ENABLE_FINER   1

Definition at line 260 of file dvenc.c.

◆ DV100_MAKE_QLEVEL

#define DV100_MAKE_QLEVEL (   qno,
  cno 
)    ((qno<<2) | (cno))

Definition at line 263 of file dvenc.c.

◆ DV100_QLEVEL_QNO

#define DV100_QLEVEL_QNO (   qlevel)    (qlevel>>2)

Definition at line 264 of file dvenc.c.

◆ DV100_QLEVEL_CNO

#define DV100_QLEVEL_CNO (   qlevel)    (qlevel&0x3)

Definition at line 265 of file dvenc.c.

◆ DV100_NUM_QLEVELS

#define DV100_NUM_QLEVELS   31

Definition at line 267 of file dvenc.c.

◆ VE

Definition at line 1195 of file dvenc.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(DVVideoContext, x)

Definition at line 1196 of file dvenc.c.

Function Documentation

◆ dvvideo_encode_init()

static av_cold int dvvideo_encode_init ( AVCodecContext avctx)
static

Definition at line 50 of file dvenc.c.

◆ dv_rl2vlc()

static av_always_inline int dv_rl2vlc ( int  run,
int  l,
int  sign,
uint32_t *  vlc 
)
static

Definition at line 143 of file dvenc.c.

Referenced by dv_encode_ac().

◆ dv_rl2vlc_size()

static av_always_inline int dv_rl2vlc_size ( int  run,
int  l 
)
static

Definition at line 149 of file dvenc.c.

Referenced by dv100_actual_quantize(), dv_guess_qnos(), and dv_set_class_number_sd().

◆ dv_encode_ac()

static av_always_inline PutBitContext* dv_encode_ac ( EncBlockInfo bi,
PutBitContext pb_pool,
PutBitContext pb_end 
)
static

Definition at line 174 of file dvenc.c.

Referenced by dv_encode_video_segment().

◆ dv_guess_dct_mode()

static av_always_inline int dv_guess_dct_mode ( DVVideoContext s,
uint8_t *  data,
ptrdiff_t  linesize 
)
static

Definition at line 220 of file dvenc.c.

Referenced by dv_encode_video_segment(), and dv_init_enc_block().

◆ dv_set_class_number_sd()

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

Definition at line 368 of file dvenc.c.

Referenced by dv_init_enc_block().

◆ dv_set_class_number_hd()

static void dv_set_class_number_hd ( DVVideoContext s,
int16_t *  blk,
EncBlockInfo bi,
const uint8_t *  zigzag_scan,
const int weight,
int  bias 
)
inlinestatic

Definition at line 452 of file dvenc.c.

Referenced by dv_init_enc_block().

◆ dv_init_enc_block()

static av_always_inline int dv_init_enc_block ( EncBlockInfo bi,
uint8_t *  data,
int  linesize,
DVVideoContext s,
int  chroma 
)
static

Definition at line 509 of file dvenc.c.

Referenced by dv_encode_video_segment().

◆ dv100_quantize()

static av_always_inline int dv100_quantize ( int  level,
int  qsinv 
)
static

Definition at line 560 of file dvenc.c.

Referenced by dv100_actual_quantize().

◆ dv100_actual_quantize()

static int dv100_actual_quantize ( EncBlockInfo b,
int  qlevel 
)
static

Definition at line 573 of file dvenc.c.

Referenced by dv_guess_qnos_hd().

◆ dv_guess_qnos_hd()

static void dv_guess_qnos_hd ( EncBlockInfo blks,
int qnos 
)
inlinestatic

Definition at line 611 of file dvenc.c.

Referenced by dv_encode_video_segment().

◆ dv_guess_qnos()

static void dv_guess_qnos ( EncBlockInfo blks,
int qnos 
)
inlinestatic

Definition at line 753 of file dvenc.c.

Referenced by dv_encode_video_segment().

◆ dv_revise_cnos()

static void dv_revise_cnos ( uint8_t *  dif,
EncBlockInfo blk,
const AVDVProfile profile 
)
inlinestatic

Definition at line 827 of file dvenc.c.

Referenced by dv_encode_video_segment().

◆ dv_encode_video_segment()

static int dv_encode_video_segment ( AVCodecContext avctx,
void *  arg 
)
static

Definition at line 845 of file dvenc.c.

Referenced by dvvideo_encode_frame().

◆ dv_write_pack()

static int dv_write_pack ( enum dv_pack_type  pack_id,
DVVideoContext c,
uint8_t *  buf 
)
inlinestatic

Definition at line 996 of file dvenc.c.

Referenced by dv_format_frame().

◆ dv_write_dif_id()

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 
)
inlinestatic

Definition at line 1080 of file dvenc.c.

Referenced by dv_format_frame().

◆ dv_write_ssyb_id()

static int dv_write_ssyb_id ( uint8_t  syb_num,
uint8_t  fr,
uint8_t *  buf 
)
inlinestatic

Definition at line 1096 of file dvenc.c.

Referenced by dv_format_frame().

◆ dv_format_frame()

static void dv_format_frame ( DVVideoContext c,
uint8_t *  buf 
)
static

Definition at line 1116 of file dvenc.c.

Referenced by dvvideo_encode_frame().

◆ dvvideo_encode_frame()

static int dvvideo_encode_frame ( AVCodecContext c,
AVPacket pkt,
const AVFrame frame,
int got_packet 
)
static

Definition at line 1168 of file dvenc.c.

Variable Documentation

◆ vs_total_ac_bits_hd

const int vs_total_ac_bits_hd = (68 * 6 + 52*2) * 5
static

Definition at line 98 of file dvenc.c.

Referenced by dv_guess_qnos_hd().

◆ vs_total_ac_bits

const int vs_total_ac_bits = (100 * 4 + 68 * 2) * 5
static

Definition at line 99 of file dvenc.c.

Referenced by dv_encode_video_segment(), and dv_guess_qnos().

◆ mb_area_start

const int mb_area_start[5] = { 1, 6, 21, 43, 64 }
static

Definition at line 100 of file dvenc.c.

Referenced by dv_guess_qnos(), and dv_set_class_number_sd().

◆ dv_weight_bits

const int dv_weight_bits = 18
static

Definition at line 235 of file dvenc.c.

Referenced by dv_set_class_number_sd().

◆ dv_weight_88

const int dv_weight_88[64]
static
Initial value:
= {
131072, 257107, 257107, 242189, 252167, 242189, 235923, 237536,
237536, 235923, 229376, 231390, 223754, 231390, 229376, 222935,
224969, 217965, 217965, 224969, 222935, 200636, 218652, 211916,
212325, 211916, 218652, 200636, 188995, 196781, 205965, 206433,
206433, 205965, 196781, 188995, 185364, 185364, 200636, 200704,
200636, 185364, 185364, 174609, 180568, 195068, 195068, 180568,
174609, 170091, 175557, 189591, 175557, 170091, 165371, 170627,
170627, 165371, 160727, 153560, 160727, 144651, 144651, 136258,
}

Definition at line 236 of file dvenc.c.

Referenced by dv_init_enc_block().

◆ dv_weight_248

const int dv_weight_248[64]
static
Initial value:
= {
131072, 262144, 257107, 257107, 242189, 242189, 242189, 242189,
237536, 237536, 229376, 229376, 200636, 200636, 224973, 224973,
223754, 223754, 235923, 235923, 229376, 229376, 217965, 217965,
211916, 211916, 196781, 196781, 185364, 185364, 206433, 206433,
211916, 211916, 222935, 222935, 200636, 200636, 205964, 205964,
200704, 200704, 180568, 180568, 175557, 175557, 195068, 195068,
185364, 185364, 188995, 188995, 174606, 174606, 175557, 175557,
170627, 170627, 153560, 153560, 165371, 165371, 144651, 144651,
}

Definition at line 246 of file dvenc.c.

Referenced by dv_init_enc_block().

◆ dv100_qlevels

const uint8_t dv100_qlevels[DV100_NUM_QLEVELS]
static

Definition at line 277 of file dvenc.c.

Referenced by dv100_actual_quantize(), and dv_guess_qnos_hd().

◆ dv100_min_bias

const int dv100_min_bias = 0
static

Definition at line 312 of file dvenc.c.

Referenced by dv_init_enc_block().

◆ dv100_chroma_bias

const int dv100_chroma_bias = 0
static

Definition at line 313 of file dvenc.c.

Referenced by dv_init_enc_block().

◆ dv100_starting_qno

const int dv100_starting_qno = 1
static

Definition at line 314 of file dvenc.c.

Referenced by dv_guess_qnos_hd().

◆ dv100_qlevel_inc

const int dv100_qlevel_inc = 4
static

Definition at line 317 of file dvenc.c.

Referenced by dv_guess_qnos_hd().

◆ dv100_qstep_bits

const int dv100_qstep_bits = 16
static

Definition at line 323 of file dvenc.c.

Referenced by dv100_quantize().

◆ dv100_qstep_inv

const int dv100_qstep_inv[16]
static
Initial value:
= {
65536, 65536, 32768, 21845, 16384, 13107, 10923, 9362, 8192, 4096, 3641, 3277, 2979, 2731, 2341, 1260,
}

Definition at line 324 of file dvenc.c.

Referenced by dv100_actual_quantize().

◆ dv_weight_1080

const int dv_weight_1080[2][64]
static
Initial value:
= {
{ 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
25575, 25575, 24385, 23831, 23302, 23302, 24966, 24966,
24966, 23302, 23302, 21845, 22795, 24385, 24385, 22795,
21845, 21400, 21845, 23831, 21845, 21400, 10382, 10700,
10700, 10382, 10082, 9620, 10082, 9039, 9039, 8525, },
{ 8192, 65536, 65536, 61681, 61681, 61681, 41943, 41943,
41943, 41943, 40330, 41943, 40330, 41943, 40330, 40330,
40330, 38836, 38836, 40330, 40330, 24966, 27594, 26214,
26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
25575, 25575, 24385, 23831, 11523, 11523, 12483, 12483,
12483, 11523, 11523, 10923, 11275, 12193, 12193, 11275,
10923, 5323, 5490, 5924, 5490, 5323, 5165, 5323,
5323, 5165, 5017, 4788, 5017, 4520, 4520, 4263, }
}

Definition at line 330 of file dvenc.c.

Referenced by dv_init_enc_block().

◆ dv_weight_720

const int dv_weight_720[2][64]
static
Initial value:
= {
{ 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
25575, 25575, 24385, 23831, 15420, 15420, 16644, 16644,
16644, 15420, 15420, 10923, 11398, 12193, 12193, 11398,
10923, 10700, 10923, 11916, 10923, 10700, 5191, 5350,
5350, 5191, 5041, 4810, 5041, 4520, 4520, 4263, },
{ 8192, 43691, 43691, 40330, 40330, 40330, 29127, 29127,
29127, 29127, 29127, 29127, 27594, 29127, 29127, 27594,
27594, 27594, 27594, 27594, 27594, 12483, 13797, 13107,
13107, 13107, 13797, 12483, 11916, 12193, 12788, 12788,
12788, 12788, 12193, 11916, 5761, 5761, 6242, 6242,
6242, 5761, 5761, 5461, 5638, 5461, 6096, 5638,
5461, 2661, 2745, 2962, 2745, 2661, 2583, 2661,
2661, 2583, 2509, 2394, 2509, 2260, 2260, 2131, }
}

Definition at line 349 of file dvenc.c.

Referenced by dv_init_enc_block().

◆ dv_options

const AVOption dv_options[]
static
Initial value:
= {
{ "quant_deadzone", "Quantizer dead zone", OFFSET(quant_deadzone), AV_OPT_TYPE_INT, { .i64 = 7 }, 0, 1024, VE },
{ NULL },
}

Definition at line 1197 of file dvenc.c.

◆ dvvideo_encode_class

const AVClass dvvideo_encode_class
static
Initial value:
= {
.class_name = "dvvideo encoder",
.item_name = av_default_item_name,
.option = dv_options,
}

Definition at line 1202 of file dvenc.c.

◆ ff_dvvideo_encoder

const FFCodec ff_dvvideo_encoder
Initial value:
= {
.p.name = "dvvideo",
.p.long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(DVVideoContext),
.p.pix_fmts = (const enum AVPixelFormat[]) {
},
.p.priv_class = &dvvideo_encode_class,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
}

Definition at line 1209 of file dvenc.c.

AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
init
static int init
Definition: av_tx.c:47
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:263
dvvideo_encode_class
static const AVClass dvvideo_encode_class
Definition: dvenc.c:1202
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:113
OFFSET
#define OFFSET(x)
Definition: dvenc.c:1196
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
DVVideoContext
Definition: dv.h:40
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
dvvideo_encode_init
static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
Definition: dvenc.c:50
dvvideo_encode_frame
static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: dvenc.c:1168
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:117
VE
#define VE
Definition: dvenc.c:1195
dv_options
static const AVOption dv_options[]
Definition: dvenc.c:1197
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: codec_internal.h:31
AV_CODEC_ID_DVVIDEO
@ AV_CODEC_ID_DVVIDEO
Definition: codec_id.h:74
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73