/*****************************************************************************
* set.h: quantization init
*****************************************************************************
* Copyright (C) 2003-2017 x264 project
*
* Authors: Loren Merritt <lorenm@u.washington.edu>
* Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at licensing@x264.com.
*****************************************************************************/
#ifndef X264_SET_H
#define X264_SET_H
enum profile_e
{
PROFILE_BASELINE = 66,
PROFILE_MAIN = 77,
PROFILE_HIGH = 100,
PROFILE_HIGH10 = 110,
PROFILE_HIGH422 = 122,
PROFILE_HIGH444_PREDICTIVE = 244,
};
enum chroma_format_e
{
CHROMA_400 = 0,
CHROMA_420 = 1,
CHROMA_422 = 2,
CHROMA_444 = 3,
};
enum cqm4_e
{
CQM_4IY = 0,
CQM_4PY = 1,
CQM_4IC = 2,
CQM_4PC = 3
};
enum cqm8_e
{
CQM_8IY = 0,
CQM_8PY = 1,
CQM_8IC = 2,
CQM_8PC = 3,
};
typedef struct
{
int i_id;/*本序列参数集的id号*/
int i_profile_idc;/*指明所用的profile*/
int i_level_idc; /*指明所用的level*/
int b_constraint_set0;/*其值等于时,表示必须遵从附录A.2.1所指明的所有约束条件*/
int b_constraint_set1; /*其值等于时,表示必须遵从附录A.2.2所指明的所有约束条件*/
int b_constraint_set2; /*其值等于时,表示必须遵从附录A.2.3所指明的所有约束条件*/
int b_constraint_set3;
int i_log2_max_frame_num; //这个句法元素只要是为读取frame_num服务的, +4来表示frame_num 长度bits framenum 用来寻找参考帧。 frame_num 在slice header 里面。
int i_poc_type; /*指明poc的编码方法,poc标识图像的播放顺序*/
/* poc 0 */
int i_log2_max_poc_lsb; /*指明了变量i_poc_lsb的max值*/
int i_num_ref_frames;/*指定参考帧队列可能达到的最大长度,解码器根据这个句法元素的值开辟存储区,这个存储区用于存放已解码的参考帧*/
int b_gaps_in_frame_num_value_allowed;/*这个句法元素等于时,表示允许句法元素frame_num可以不连续;当传输信道堵塞时,允许丢弃若干帧*/
int i_mb_width;
int i_mb_height;
int b_frame_mbs_only;/*本句法元素等于1时,表示本序列中所有的图像编码模式都是帧,没有其他编码模式存在;当为时,表示本序列中图像的编码模式可能是帧,也可能是场或帧场自适应*/
int b_mb_adaptive_frame_field; /*指明本序列是否属于帧场自适应模式*/
int b_direct8x8_inference;
int b_crop;//为了长宽满足整宏块, 进行处理。
struct
{
int i_left;
int i_right;
int i_top;
int i_bottom;
} crop;
int b_vui;
struct
{
int b_aspect_ratio_info_present;//表示亮度样值的样点高宽比的取值。
//表E-1 给出代码的含义。当aspect_ratio_idc 的取值表示是Extended_SAR,
//样点高宽比由sar_width 和sar_height 描述。当aspect_ratio_idc 语法元素不存在,aspect_ratio_idc的值应被推定为0。
int i_sar_width;
int i_sar_height;
int b_overscan_info_present;
int b_overscan_info;//flag for 可以预览裁剪版解码图像?
int b_signal_type_present;//表示接下来的flag存在
int i_vidformat;//表明此视频在 编码/数字化 之前是什么格式的。可选:component pal ntsc secam mac undef
int b_fullrange;//画面颜色值范围默认为off 16-255 ,on 表示0-255. 色域范围更大
int b_color_description_present;
int i_colorprim;//原始色度格式
int i_transfer;//转换方式,默认"undef",可选项:undef/bt709/bt470m/bt470bg/linear,log100/log316/smpte170m/smpte240m
int i_colmatrix;//色度矩阵设置,默认"undef",undef/bt709/fcc/bt470bg,smpte170m/smpte240m/GBR/YCgCo
int b_chroma_loc_info_present;//both top & bottom色度样本指定,范围0~5,默认0
int i_chroma_loc_top;//
int i_chroma_loc_bottom;//
int b_timing_info_present;//framerate = time_scale/num_units_in_tick. ?????????????????? if b_fixed_frame_rate framerate /=2;
uint32_t i_num_units_in_tick;
uint32_t i_time_scale;
int b_fixed_frame_rate;//if b_fixed_frame_rate framerate /=2;
int b_nal_hrd_parameters_present;
int b_vcl_hrd_parameters_present;
/*
默认:none
说明:设置HRD信息。用于蓝光流、电视广播和其他一些特殊场合。可用选项如下:
none —— 不设置HRD信息
vbr —— 设置HRD信息
cbr —— 设置HRD信息,而且把流限制在bitrate参数定义的码率内。需要bitrate码率控制方式。
建议:none,除非你需要设置HRD。
参见:–vbv-bufsize, –vbv-maxrate和 –aud
*/
struct
{
//初始化函数名 x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init )
//#define BR_SHIFT 6
//#define CPB_SHIFT 4
int i_cpb_cnt;
int i_bit_rate_scale; //h->sps->vui.hrd.i_bit_rate_scale = x264_clip3( x264_ctz( vbv_max_bitrate ) - BR_SHIFT, 0, 15 );
int i_cpb_size_scale;//h->sps->vui.hrd.i_bit_rate_value = vbv_max_bitrate >> ( h->sps->vui.hrd.i_bit_rate_scale + BR_SHIFT );
int i_bit_rate_value;//h->sps->vui.hrd.i_bit_rate_value = vbv_max_bitrate >> ( h->sps->vui.hrd.i_bit_rate_scale + BR_SHIFT );
int i_cpb_size_value;//h->sps->vui.hrd.i_cpb_size_value = vbv_buffer_size >> ( h->sps->vui.hrd.i_cpb_size_scale + CPB_SHIFT );
int i_bit_rate_unscaled;
//h->sps->vui.hrd.i_cpb_size_unscaled = h->sps->vui.hrd.i_cpb_size_value << ( h->sps->vui.hrd.i_cpb_size_scale + CPB_SHIFT );
//h->sps->vui.hrd.i_bit_rate_unscaled = vbv_max_bitrate;
int i_cpb_size_unscaled;//h->sps->vui.hrd.i_cpb_size_unscaled = vbv_buffer_size;
int b_cbr_hrd;
int i_initial_cpb_removal_delay_length;//SEI 中initial_cpb_remove_delay 与 initial_cpb_remove_delay_offset的bit数。
int i_cpb_removal_delay_length;//SEI中cpb_removal_delay的长度 code pic buffer
int i_dpb_output_delay_length;// SEI中dpb_output_delay 的长度
int i_time_offset_length;//time_offset 的长度,没有默认24
} hrd;
int b_pic_struct_present;//SEI 消息数据
int b_bitstream_restriction;//如果为真, 后面5个参数有效。
int b_motion_vectors_over_pic_boundaries;
int i_max_bytes_per_pic_denom;
int i_max_bits_per_mb_denom;
int i_log2_max_mv_length_horizontal;
int i_log2_max_mv_length_vertical;
int i_num_reorder_frames;//是用于标示 出 显示的时候需要缓冲多少帧 以方便排序,比如IPP序列 是不需要缓冲,或者重排序的,
//如果缓冲太多帧会造成延迟。当然这个也有一个最大值,可以从 profile 算的,一般是 4 。
//IPB 序列,需要缓冲的帧数一般是 4 ,或者2 。
//H264 流里面应该指定,不过有的不标准的流不会指定,所以为了兼容,可能需要设置成最大值。
int i_max_dec_frame_buffering;//DPB的大小(帧数)为Max( 1, max_dec_frame_buffering )。
/* FIXME to complete */
} vui;
int b_qpprime_y_zero_transform_bypass;
int i_chroma_format_idc;
} x264_sps_t;
typedef struct
{
int i_id;// pps的的序号,在片头被引用
int i_sps_id;// 本图像参数集所引用的序列参数集的序号
int b_cabac;// 是否采用cabac编码,为1就是用cabac,为0则使用calvc
int b_pic_order;// poc的三种计算方法在片层还各需要用一些句法元素作为参数;
// 当等于1时,表示在片头会有句句法元素指明这些参数;
// 当不为1时,表示片头不会给出这些参数
int i_num_slice_groups;// 加1表示图像中片组的个数
int i_num_ref_idx_l0_default_active;// 指明目前参考帧队列的长度,即有多少个参考帧(短期和长期),用于list0
int i_num_ref_idx_l1_default_active;// 指明目前参考帧队列的长度,即有多少个参考帧(短期和长期),用于list1
int b_weighted_pred;//是否开启P帧和SP帧的加权预测
int b_weighted_bipred;// 是否开启B帧的加权预测
int i_pic_init_qp;// 加26后用以指明亮度分量的量化参数的初始值
int i_pic_init_qs;// 同上,只是用于SP和SI
int i_chroma_qp_index_offset;// 色度分量的量化参数是根据亮度分量的量化参数计算出来的,本句法元素用以
// 指明计算时用到的参数表示为在 QPC 值的表格中寻找 Cb色度分量而应加到 // 参数 QPY 和 QSY 上的偏移。该值应在-12 到 +12范围内(包括边界值)
int b_deblocking_filter_control;// 编码器可以通过句法元素显式地控制去块滤波的强度
int b_constrained_intra_pred;// 控制PB帧的帧内编码,在P和B帧中,帧内编码的宏块的邻近宏块可能采用帧间编码
int b_redundant_pic_cnt;// 对于那些属于基本编码图像的条带和条带数据分割块,redundant_pic_cnt等于0;
// 在冗余编码图像中的编码条带和编码条带数据分割块,redundant_pic_cnt大于0;
// 当redundant_pic_cnt 不存在时,默认值为 0;redundant_pic_cnt的值应该在0到127之间。
int b_transform_8x8_mode;
int i_cqm_preset;// 外部量化矩阵的设置
const uint8_t *scaling_list[8]; /* could be 12, but we don't allow separate Cb/Cr lists */
} x264_pps_t;
/* default quant matrices */
static const uint8_t x264_cqm_jvt4i[16] =
{
6,13,20,28,
13,20,28,32,
20,28,32,37,
28,32,37,42
};
static const uint8_t x264_cqm_jvt4p[16] =
{
10,14,20,24,
14,20,24,27,
20,24,27,30,
24,27,30,34
};
static const uint8_t x264_cqm_jvt8i[64] =
{
6,10,13,16,18,23,25,27,
10,11,16,18,23,25,27,29,
13,16,18,23,25,27,29,31,
16,18,23,25,27,29,31,33,
18,23,25,27,29,31,33,36,
23,25,27,29,31,33,36,38,
25,27,29,31,33,36,38,40,
27,29,31,33,36,38,40,42
};
static const uint8_t x264_cqm_jvt8p[64] =
{
9,13,15,17,19,21,22,24,
13,13,17,19,21,22,24,25,
15,17,19,21,22,24,25,27,
17,19,21,22,24,25,27,28,
19,21,22,24,25,27,28,30,
21,22,24,25,27,28,30,32,
22,24,25,27,28,30,32,33,
24,25,27,28,30,32,33,35
};
static const uint8_t x264_cqm_flat16[64] =
{
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16
};
static const uint8_t * const x264_cqm_jvt[8] =
{
x264_cqm_jvt4i, x264_cqm_jvt4p,
x264_cqm_jvt4i, x264_cqm_jvt4p,
x264_cqm_jvt8i, x264_cqm_jvt8p,
x264_cqm_jvt8i, x264_cqm_jvt8p
};
// 1080i25_avci50, 1080p25_avci50
static const uint8_t x264_cqm_avci50_4ic[16] =
{
16,22,28,40,
22,28,40,44,
28,40,44,48,
40,44,48,60
};
// 1080i25_avci50,
static const uint8_t x264_cqm_avci50_1080i_8iy[64] =
{
16,18,19,21,27,33,81,87,
18,19,21,24,30,33,81,87,
19,21,24,27,30,78,84,90,
21,24,27,30,33,78,84,90,
24,27,30,33,78,81,84,90,
24,27,30,33,78,81,84,93,
27,30,33,78,78,81,87,93,
30,33,33,78,81,84,87,96
};
// 1080p25_avci50, 720p25_avci50, 720p50_avci50
static const uint8_t x264_cqm_avci50_p_8iy[64] =
{
16,18,19,21,24,27,30,33,
18,19,21,24,27,30,33,78,
19,21,24,27,30,33,78,81,
21,24,27,30,33,78,81,84,
24,27,30,33,78,81,84,87,
27,30,33,78,81,84,87,90,
30,33,78,81,84,87,90,93,
33,78,81,84,87,90,93,96
};
// 1080i25_avci100, 1080p25_avci100
static const uint8_t x264_cqm_avci100_1080_4ic[16] =
{
16,20,26,32,
20,26,32,38,
26,32,38,44,
32,38,44,50
};
// 720p25_avci100, 720p50_avci100
static const uint8_t x264_cqm_avci100_720p_4ic[16] =
{
16,21,27,34,
21,27,34,41,
27,34,41,46,
34,41,46,54
};
// 1080i25_avci100,
static const uint8_t x264_cqm_avci100_1080i_8iy[64] =
{
16,19,20,23,24,26,32,42,
18,19,22,24,26,32,36,42,
18,20,23,24,26,32,36,63,
19,20,23,26,32,36,42,63,
20,22,24,26,32,36,59,63,
22,23,24,26,32,36,59,68,
22,23,24,26,32,42,59,68,
22,23,24,26,36,42,59,72
};
// 1080p25_avci100,
static const uint8_t x264_cqm_avci100_1080p_8iy[64] =
{
16,18,19,20,22,23,24,26,
18,19,20,22,23,24,26,32,
19,20,22,23,24,26,32,36,
20,22,23,24,26,32,36,42,
22,23,24,26,32,36,42,59,
23,24,26,32,36,42,59,63,
24,26,32,36,42,59,63,68,
26,32,36,42,59,63,68,72
};
// 720p25_avci100, 720p50_avci100
static const uint8_t x264_cqm_avci100_720p_8iy[64] =
{
16,18,19,21,22,24,26,32,
18,19,19,21,22,24,26,32,
19,19,21,22,22,24,26,32,
21,21,22,22,23,24,26,34,
22,22,22,23,24,25,26,34,
24,24,24,24,25,26,34,36,
26,26,26,26,26,34,36,38,
32,32,32,34,34,36,38,42
};
int x264_cqm_init( x264_t *h );
void x264_cqm_delete( x264_t *h );
int x264_cqm_parse_file( x264_t *h, const char *filename );
#endif