x264-dsp
set.h
1 /*****************************************************************************
2  * set.h: quantization init
3  *****************************************************************************/
4 
5 #ifndef X264_SET_H
6 #define X264_SET_H
7 
8 enum profile_e {
9  /* Baseline Profile (BP)
10  * x264 implements as Constrained Baseline Profile (CBP), which corresponds to
11  * the subset of features that are in common between the Baseline, Main, and High Profiles.
12  * CBP was defined in 2009, these two profiles share the same profile identifier code value.
13  */
14  PROFILE_BASELINE = 66,
15  /* Main Profile (MP)
16  * This profile is used for standard-definition digital TV broadcasts that use the MPEG-4
17  * format as defined in the DVB standard. It is not, however, used for high-definition
18  * television broadcasts, as the importance of this profile faded when the High Profile
19  * was developed in 2004 for that application.
20  */
21  PROFILE_MAIN = 77,
22  /* High Profile (HiP)
23  * The primary profile for broadcast and disc storage applications, particularly for high-definition
24  * television applications (for example, this is the profile adopted by the Blu-ray Disc storage
25  * format and the DVB HDTV broadcast service).
26  */
27  PROFILE_HIGH = 100,
28  /* High 10 Profile (Hi10P)
29  * this profile builds on top of the High Profile,
30  * adding support for up to 10 bits per sample of decoded picture precision.
31  */
32  PROFILE_HIGH10 = 110,
33  /* High 4:2:2 Profile (Hi422P)
34  * Primarily targeting professional applications that use interlaced video, this profile builds on top of
35  * the High 10 Profile, adding support for the 4:2:2 chroma subsampling format while using up to 10 bits
36  * per sample of decoded picture precision.
37  */
38  PROFILE_HIGH422 = 122,
39  /* High 4:4:4 Predictive Profile (Hi444PP)
40  * This profile builds on top of the High 4:2:2 Profile, supporting up to 4:4:4 chroma sampling, up to 14 bits
41  * per sample, and additionally supporting efficient lossless region coding and the coding of each picture as
42  * three separate color planes.
43  * For camcorders, editing, and professional applications, the standard contains four additional Intra-frame-only
44  * profiles, which are defined as simple subsets of other corresponding profiles. These are mostly for professional
45  * (e.g., camera and editing system) applications.
46  */
47  PROFILE_HIGH444_PREDICTIVE = 244,
48 };
49 
50 enum chroma_format_e {
51  CHROMA_400 = 0,
52  CHROMA_420 = 1,
53  CHROMA_422 = 2,
54  CHROMA_444 = 3,
55 };
56 
57 enum cqm4_e {
58  CQM_4IY = 0, /* Intra_4x4_LUMA */
59  CQM_4PY = 1, /* Inter_4x4_LUMA */
60  CQM_4IC = 2, /* Intra_4x4_CHROMA */
61  CQM_4PC = 3 /* Inter_4x4_CHROMA */
62 };
63 enum cqm8_e {
64  CQM_8IY = 0, /* Intra_8x8_LUMA */
65  CQM_8PY = 1, /* Inter_8x8_LUMA */
66  CQM_8IC = 2, /* Intra_8x8_CHROMA */
67  CQM_8PC = 3, /* Inter_8x8_CHROMA */
68 };
69 
70 typedef struct
71 {
72  /* SPS id, range: [0, 31] */
73  int i_id;
74 
75  /* profile indication */
76  int i_profile_idc;
77  /* level indication */
78  int i_level_idc;
79 
80  /* profile compatibility */
81  int b_constraint_set0;
82  int b_constraint_set1;
83  int b_constraint_set2;
84  int b_constraint_set3;
85 
86  /* maximum frame number */
87  int i_log2_max_frame_num;
88 
89  /* picture-order-count type */
90  int i_poc_type;
91  /* poc 0 */
92  int i_log2_max_poc_lsb;
93 
94  /* maximum reference frames */
95  int i_num_ref_frames;
96  int b_gaps_in_frame_num_value_allowed;
97  /* macro-blocks in width */
98  int i_mb_width;
99  /* macro-blocks in height */
100  int i_mb_height;
101  /* frame/filed encoding mode flag */
102  int b_frame_mbs_only;
103  int b_mb_adaptive_frame_field;
104  /* predict mode of direct or skip in B-slice */
105  int b_direct8x8_inference;
106 
107  /* crop flag for video output */
108  int b_crop;
109  struct
110  {
111  int i_left;
112  int i_right;
113  int i_top;
114  int i_bottom;
115  } crop;
116 
117  /* video usability information flag */
118  int b_vui;
119  struct
120  {
121  int b_aspect_ratio_info_present;
122  int i_sar_width;
123  int i_sar_height;
124 
125  int b_overscan_info_present;
126  int b_overscan_info;
127 
128  int b_signal_type_present;
129  int i_vidformat;
130  int b_fullrange;
131  int b_color_description_present;
132  int i_colorprim;
133  int i_transfer;
134  int i_colmatrix;
135 
136  int b_chroma_loc_info_present;
137  int i_chroma_loc_top;
138  int i_chroma_loc_bottom;
139 
140  int b_timing_info_present; /* whether present time base in sps. default: on */
141  uint32_t i_num_units_in_tick;
142  uint32_t i_time_scale;
143  int b_fixed_frame_rate;
144 
145  int b_nal_hrd_parameters_present; /* we don't use NAL HRD unless user indicated (param->i_nal_hrd). default: off */
146  int b_vcl_hrd_parameters_present; /* we don't support VCL HRD. default: off */
147 
148  struct
149  {
150  int i_cpb_cnt;
151  int i_bit_rate_scale;
152  int i_cpb_size_scale;
153  int i_bit_rate_value;
154  int i_cpb_size_value;
155  int i_bit_rate_unscaled;
156  int i_cpb_size_unscaled;
157  int b_cbr_hrd; /* CBR HRD. Set 1 only if (h->param.i_nal_hrd == X264_NAL_HRD_CBR). default: off */
158 
159  int i_initial_cpb_removal_delay_length;
160  int i_cpb_removal_delay_length;
161  int i_dpb_output_delay_length;
162  int i_time_offset_length;
163  } hrd;
164 
165  int b_pic_struct_present; /* we don't present picture struct unless user indicated (param->b_pic_struct). default: off */
166  int b_bitstream_restriction;
167  int b_motion_vectors_over_pic_boundaries;
168  int i_max_bytes_per_pic_denom;
169  int i_max_bits_per_mb_denom;
170  int i_log2_max_mv_length_horizontal;
171  int i_log2_max_mv_length_vertical;
172  int i_num_reorder_frames;
173  int i_max_dec_frame_buffering;
174 
175  /* FIXME to complete */
176  } vui;
177 
178  /* Set 1 in lossless of High profile. Ignored in Baseline/Main profile. */
179  int b_qpprime_y_zero_transform_bypass;
180  /* Chroma format indication, default: 1 (4:2:0 chroma format). Ignored in Baseline/Main profile. */
181  int i_chroma_format_idc;
182 
183 } x264_sps_t;
184 
185 typedef struct
186 {
187  /* PPS id, range: [0-255] */
188  int i_id;
189  /* SPS id, range: [0-31] */
190  int i_sps_id;
191 
192  /* entropy coding mode flag, 0: CAVLC, 1: CABAC */
193  int b_cabac;
194 
195  /* picture order present flag */
196  int b_pic_order;
197  /* number of slice groups */
198  int i_num_slice_groups;
199 
200  /* number of reference frames in list 0 */
201  int i_num_ref_idx_l0_default_active;
202  /* number of reference frames in list 1 */
203  int i_num_ref_idx_l1_default_active;
204 
205  /* weighted predict flag for P-slice */
206  int b_weighted_pred;
207  /* weighted predict flag for B-slice */
208  int b_weighted_bipred;
209 
210  /* initial value of quantization parameters of luma */
211  int i_pic_init_qp;
212  /* initial value of quantization parameters of luma for SP/SI-slice */
213  int i_pic_init_qs;
214 
215  /* offset of quantization parameters of chroma. default: 0 */
216  int i_chroma_qp_index_offset;
217 
218  /* deblocking-filter control flag */
219  int b_deblocking_filter_control;
220  /* constrained-intra-predict flag */
221  int b_constrained_intra_pred;
222  /* redundant-picture-present flag */
223  int b_redundant_pic_cnt;
224 
225  /* 8x8 transform mode flag. depends on x264_param_t.analyse.b_transform_8x8 */
226  int b_transform_8x8_mode;
227 
228  int i_cqm_preset;
229  /********************************************************
230  * quantization matrices *
231  * low 4 matrices for 4x4 quant: 4IY, 4PY, 4IC, 4PC *
232  * high 4 matrices for 8x8 quant: 8IY, 8PY, 8IC, 8PC *
233  * could be 12, but we don't allow separate Cb/Cr lists *
234  * default value: x264_cqm_flat16 *
235  ********************************************************/
236  const uint8_t *scaling_list[8];
237 
238 } x264_pps_t;
239 
240 /* default quant matrices of jvt mode */
241 /****************************************************************************
242  * Page 94 of <ITU-T-REC-H.264-201201.pdf> *
243  * Table 7-3 – Specification of default scaling lists *
244  * Default_4x4_Intra and Default_4x4_Inter *
245  * idx 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 *
246  * Default_4x4_Intra[idx] 6 13 13 20 20 20 28 28 28 28 32 32 32 37 37 42 *
247  * Default_4x4_Inter[idx] 10 14 14 20 20 20 24 24 24 24 27 27 27 30 30 34 *
248  ****************************************************************************/
249 static const uint8_t x264_cqm_jvt4i[16] =
250  {
251  6, 13, 20, 28,
252  13, 20, 28, 32,
253  20, 28, 32, 37,
254  28, 32, 37, 42};
255 static const uint8_t x264_cqm_jvt4p[16] =
256  {
257  10, 14, 20, 24,
258  14, 20, 24, 27,
259  20, 24, 27, 30,
260  24, 27, 30, 34};
261 
262 /****************************************************************************
263  * Page 95 of <ITU-T-REC-H.264-201201.pdf> *
264  * Table 7-4 – Specification of default scaling lists *
265  * Default_8x8_Intra and Default_8x8_Inter *
266  * idx 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 *
267  * Default_8x8_Intra[idx] 6 10 10 13 11 13 16 16 16 16 18 18 18 18 18 23 *
268  * Default_8x8_Inter[idx] 9 13 13 15 13 15 17 17 17 17 19 19 19 19 19 21 *
269  * *
270  * idx 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 *
271  * Default_8x8_Intra[idx] 23 23 23 23 23 25 25 25 25 25 25 25 27 27 27 27 *
272  * Default_8x8_Inter[idx] 21 21 21 21 21 22 22 22 22 22 22 22 24 24 24 24 *
273  * *
274  * idx 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 *
275  * Default_8x8_Intra[idx] 27 27 27 27 29 29 29 29 29 29 29 31 31 31 31 31 *
276  * Default_8x8_Inter[idx] 24 24 24 24 25 25 25 25 25 25 25 27 27 27 27 27 *
277  * *
278  * idx 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 *
279  * Default_8x8_Intra[idx] 31 33 33 33 33 33 36 36 36 36 38 38 38 40 40 42 *
280  * Default_8x8_Inter[idx] 27 28 28 28 28 28 30 30 30 30 32 32 32 33 33 35 *
281  ****************************************************************************/
282 static const uint8_t x264_cqm_jvt8i[64] =
283  {
284  6, 10, 13, 16, 18, 23, 25, 27,
285  10, 11, 16, 18, 23, 25, 27, 29,
286  13, 16, 18, 23, 25, 27, 29, 31,
287  16, 18, 23, 25, 27, 29, 31, 33,
288  18, 23, 25, 27, 29, 31, 33, 36,
289  23, 25, 27, 29, 31, 33, 36, 38,
290  25, 27, 29, 31, 33, 36, 38, 40,
291  27, 29, 31, 33, 36, 38, 40, 42};
292 static const uint8_t x264_cqm_jvt8p[64] =
293  {
294  9, 13, 15, 17, 19, 21, 22, 24,
295  13, 13, 17, 19, 21, 22, 24, 25,
296  15, 17, 19, 21, 22, 24, 25, 27,
297  17, 19, 21, 22, 24, 25, 27, 28,
298  19, 21, 22, 24, 25, 27, 28, 30,
299  21, 22, 24, 25, 27, 28, 30, 32,
300  22, 24, 25, 27, 28, 30, 32, 33,
301  24, 25, 27, 28, 30, 32, 33, 35};
302 /* custom-quantization-matrix of flat mode */
303 static const uint8_t x264_cqm_flat16[64] =
304  {
305  16, 16, 16, 16, 16, 16, 16, 16,
306  16, 16, 16, 16, 16, 16, 16, 16,
307  16, 16, 16, 16, 16, 16, 16, 16,
308  16, 16, 16, 16, 16, 16, 16, 16,
309  16, 16, 16, 16, 16, 16, 16, 16,
310  16, 16, 16, 16, 16, 16, 16, 16,
311  16, 16, 16, 16, 16, 16, 16, 16,
312  16, 16, 16, 16, 16, 16, 16, 16};
313 /* custom-quantization-matrix of jvt mode */
314 static const uint8_t *const x264_cqm_jvt[8] =
315  {
316  x264_cqm_jvt4i, x264_cqm_jvt4p,
317  x264_cqm_jvt4i, x264_cqm_jvt4p,
318  x264_cqm_jvt8i, x264_cqm_jvt8p,
319  x264_cqm_jvt8i, x264_cqm_jvt8p};
320 
321 int x264_cqm_init(x264_t *h);
322 void x264_cqm_delete(x264_t *h);
323 
324 #endif
Definition: set.h:186
Definition: set.h:71
Definition: common.h:499