/src/libde265/libde265/sps.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * H.265 video codec. |
3 | | * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de> |
4 | | * |
5 | | * This file is part of libde265. |
6 | | * |
7 | | * libde265 is free software: you can redistribute it and/or modify |
8 | | * it under the terms of the GNU Lesser General Public License as |
9 | | * published by the Free Software Foundation, either version 3 of |
10 | | * the License, or (at your option) any later version. |
11 | | * |
12 | | * libde265 is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with libde265. If not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | #ifndef DE265_SPS_H |
22 | | #define DE265_SPS_H |
23 | | |
24 | | #include "libde265/vps.h" |
25 | | #include "libde265/vui.h" |
26 | | #include "libde265/bitstream.h" |
27 | | #include "libde265/refpic.h" |
28 | | #include "libde265/de265.h" |
29 | | #include "libde265/cabac.h" |
30 | | |
31 | | #include <vector> |
32 | | |
33 | | class error_queue; |
34 | | |
35 | | // #define MAX_REF_PIC_SETS 64 // maximum according to standard |
36 | 4.59k | #define MAX_NUM_LT_REF_PICS_SPS 32 |
37 | | |
38 | | // This is just a safety range. It is chosen such that width/height fits into 16bit integers and the total number of pixels in 32bit integers. |
39 | 16.7k | #define MAX_PICTURE_WIDTH 65535 |
40 | 8.35k | #define MAX_PICTURE_HEIGHT 65535 |
41 | | |
42 | | enum { |
43 | | CHROMA_MONO = 0, |
44 | | CHROMA_420 = 1, |
45 | | CHROMA_422 = 2, |
46 | | CHROMA_444 = 3, |
47 | | CHROMA_444_SEPARATE |
48 | | }; |
49 | | |
50 | | |
51 | | typedef struct scaling_list_data { |
52 | | // structure size: approx. 4 kB |
53 | | |
54 | | uint8_t ScalingFactor_Size0[6][4][4]; |
55 | | uint8_t ScalingFactor_Size1[6][8][8]; |
56 | | uint8_t ScalingFactor_Size2[6][16][16]; |
57 | | uint8_t ScalingFactor_Size3[6][32][32]; |
58 | | } scaling_list_data; |
59 | | |
60 | | |
61 | | enum PresetSet { |
62 | | Preset_Default |
63 | | }; |
64 | | |
65 | | |
66 | | class sps_range_extension |
67 | | { |
68 | | public: |
69 | | sps_range_extension(); |
70 | | |
71 | | uint8_t transform_skip_rotation_enabled_flag; |
72 | | uint8_t transform_skip_context_enabled_flag; |
73 | | uint8_t implicit_rdpcm_enabled_flag; |
74 | | uint8_t explicit_rdpcm_enabled_flag; |
75 | | uint8_t extended_precision_processing_flag; |
76 | | uint8_t intra_smoothing_disabled_flag; |
77 | | uint8_t high_precision_offsets_enabled_flag; |
78 | | uint8_t persistent_rice_adaptation_enabled_flag; |
79 | | uint8_t cabac_bypass_alignment_enabled_flag; |
80 | | |
81 | | de265_error read(error_queue*, bitreader*); |
82 | | void dump(int fd) const; |
83 | | }; |
84 | | |
85 | | |
86 | | class seq_parameter_set { |
87 | | public: |
88 | | seq_parameter_set(); |
89 | | ~seq_parameter_set(); |
90 | | |
91 | | de265_error read(error_queue*, bitreader*); |
92 | | de265_error write(error_queue*, CABAC_encoder&); |
93 | | |
94 | | void dump(int fd) const; |
95 | | |
96 | | void set_defaults(enum PresetSet = Preset_Default); |
97 | | void set_CB_log2size_range(int mini,int maxi); |
98 | | void set_TB_log2size_range(int mini,int maxi); |
99 | | void set_resolution(int w,int h); |
100 | | |
101 | | bool sps_read; // whether the sps has been read from the bitstream |
102 | | |
103 | | |
104 | | char video_parameter_set_id; |
105 | | char sps_max_sub_layers; // [1;7] |
106 | | char sps_temporal_id_nesting_flag; |
107 | | |
108 | | profile_tier_level profile_tier_level_; |
109 | | |
110 | | int seq_parameter_set_id; |
111 | | int chroma_format_idc; |
112 | | |
113 | | char separate_colour_plane_flag; |
114 | | int pic_width_in_luma_samples; |
115 | | int pic_height_in_luma_samples; |
116 | | char conformance_window_flag; |
117 | | |
118 | | int conf_win_left_offset; |
119 | | int conf_win_right_offset; |
120 | | int conf_win_top_offset; |
121 | | int conf_win_bottom_offset; |
122 | | |
123 | | int bit_depth_luma; |
124 | | int bit_depth_chroma; |
125 | | |
126 | | int log2_max_pic_order_cnt_lsb; |
127 | | char sps_sub_layer_ordering_info_present_flag; |
128 | | |
129 | | int sps_max_dec_pic_buffering[7]; // for each temporal layer |
130 | | int sps_max_num_reorder_pics[7]; |
131 | | int sps_max_latency_increase_plus1[7]; |
132 | | |
133 | | int log2_min_luma_coding_block_size; // smallest CB size [3;6] |
134 | | int log2_diff_max_min_luma_coding_block_size; // largest CB size |
135 | | int log2_min_transform_block_size; // smallest TB size [2;5] |
136 | | int log2_diff_max_min_transform_block_size; // largest TB size |
137 | | int max_transform_hierarchy_depth_inter; |
138 | | int max_transform_hierarchy_depth_intra; |
139 | | |
140 | | char scaling_list_enable_flag; |
141 | | char sps_scaling_list_data_present_flag; /* if not set, the default scaling lists will be set |
142 | | in scaling_list */ |
143 | | |
144 | | struct scaling_list_data scaling_list; |
145 | | |
146 | | char amp_enabled_flag; |
147 | | char sample_adaptive_offset_enabled_flag; |
148 | | char pcm_enabled_flag; |
149 | | |
150 | | char pcm_sample_bit_depth_luma; |
151 | | char pcm_sample_bit_depth_chroma; |
152 | | int log2_min_pcm_luma_coding_block_size; |
153 | | int log2_diff_max_min_pcm_luma_coding_block_size; |
154 | | char pcm_loop_filter_disable_flag; |
155 | | |
156 | 13.6k | int num_short_term_ref_pic_sets() const { return ref_pic_sets.size(); } |
157 | | std::vector<ref_pic_set> ref_pic_sets; // [0 ; num_short_term_ref_pic_set (<=MAX_REF_PIC_SETS) ) |
158 | | |
159 | | char long_term_ref_pics_present_flag; |
160 | | |
161 | | int num_long_term_ref_pics_sps; |
162 | | |
163 | | int lt_ref_pic_poc_lsb_sps[MAX_NUM_LT_REF_PICS_SPS]; |
164 | | char used_by_curr_pic_lt_sps_flag[MAX_NUM_LT_REF_PICS_SPS]; |
165 | | |
166 | | char sps_temporal_mvp_enabled_flag; |
167 | | char strong_intra_smoothing_enable_flag; |
168 | | |
169 | | char vui_parameters_present_flag; |
170 | | video_usability_information vui; |
171 | | |
172 | | char sps_extension_present_flag; |
173 | | char sps_range_extension_flag; |
174 | | char sps_multilayer_extension_flag; |
175 | | char sps_extension_6bits; |
176 | | |
177 | | sps_range_extension range_extension; |
178 | | |
179 | | /* |
180 | | if( sps_extension_flag ) |
181 | | while( more_rbsp_data() ) |
182 | | sps_extension_data_flag |
183 | | u(1) |
184 | | rbsp_trailing_bits() |
185 | | */ |
186 | | |
187 | | |
188 | | // --- derived values --- |
189 | | |
190 | | de265_error compute_derived_values(bool sanitize_values = false); |
191 | | |
192 | | int BitDepth_Y; |
193 | | int QpBdOffset_Y; |
194 | | int BitDepth_C; |
195 | | int QpBdOffset_C; |
196 | | |
197 | | int ChromaArrayType; |
198 | | int SubWidthC, SubHeightC; |
199 | | int WinUnitX, WinUnitY; |
200 | | |
201 | | int MaxPicOrderCntLsb; |
202 | | |
203 | | int Log2MinCbSizeY; |
204 | | int Log2CtbSizeY; |
205 | | int MinCbSizeY; |
206 | | int CtbSizeY; |
207 | | int PicWidthInMinCbsY; |
208 | | int PicWidthInCtbsY; |
209 | | int PicHeightInMinCbsY; |
210 | | int PicHeightInCtbsY; |
211 | | int PicSizeInMinCbsY; |
212 | | int PicSizeInCtbsY; |
213 | | uint32_t PicSizeInSamplesY; |
214 | | |
215 | | int CtbWidthC, CtbHeightC; |
216 | | |
217 | | int PicWidthInTbsY; // not in standard |
218 | | int PicHeightInTbsY; // not in standard |
219 | | int PicSizeInTbsY; // not in standard |
220 | | |
221 | | int Log2MinTrafoSize; |
222 | | int Log2MaxTrafoSize; |
223 | | |
224 | | int Log2MinPUSize; |
225 | | int PicWidthInMinPUs; // might be rounded up |
226 | | int PicHeightInMinPUs; // might be rounded up |
227 | | |
228 | | int Log2MinIpcmCbSizeY; |
229 | | int Log2MaxIpcmCbSizeY; |
230 | | |
231 | | int SpsMaxLatencyPictures[7]; // [temporal layer] |
232 | | |
233 | | uint8_t WpOffsetBdShiftY; |
234 | | uint8_t WpOffsetBdShiftC; |
235 | | int32_t WpOffsetHalfRangeY; |
236 | | int32_t WpOffsetHalfRangeC; |
237 | | |
238 | | |
239 | 0 | int getPUIndexRS(int pixelX,int pixelY) const { |
240 | 0 | return (pixelX>>Log2MinPUSize) + (pixelY>>Log2MinPUSize)*PicWidthInMinPUs; |
241 | 0 | } |
242 | | |
243 | 4.39M | int get_bit_depth(int cIdx) const { |
244 | 4.39M | if (cIdx==0) return BitDepth_Y; |
245 | 1.31M | else return BitDepth_C; |
246 | 4.39M | } |
247 | | |
248 | 616k | int get_chroma_shift_W(int cIdx) const { return cIdx ? SubWidthC -1 : 0; } |
249 | 616k | int get_chroma_shift_H(int cIdx) const { return cIdx ? SubHeightC-1 : 0; } |
250 | | }; |
251 | | |
252 | | de265_error read_scaling_list(bitreader*, const seq_parameter_set*, scaling_list_data*, bool inPPS); |
253 | | de265_error write_scaling_list(CABAC_encoder& out, const seq_parameter_set* sps, |
254 | | scaling_list_data* sclist, bool inPPS); |
255 | | void set_default_scaling_lists(scaling_list_data*); |
256 | | |
257 | | #endif |