/work/libde265/libde265/sps.cc
Line | Count | Source |
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 | | #include "sps.h" |
22 | | #include "util.h" |
23 | | #include "scan.h" |
24 | | #include "decctx.h" |
25 | | |
26 | | #include <assert.h> |
27 | | #include <stdlib.h> |
28 | | #include <string.h> |
29 | | |
30 | 25 | #define D 0 |
31 | | |
32 | | #define READ_VLC(variable, vlctype) \ |
33 | 194 | if ((vlc = br->get_ ## vlctype()) == UVLC_ERROR) { \ |
34 | 2 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); \ |
35 | 2 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; \ |
36 | 2 | } \ |
37 | 194 | variable = vlc; |
38 | | |
39 | | |
40 | | static int SubWidthC_tab[] = { 1,2,2,1 }; |
41 | | static int SubHeightC_tab[] = { 1,2,1,1 }; |
42 | | |
43 | | |
44 | | // TODO if (!check_high(ctx, vlc, 15)) return false; |
45 | | // TODO if (!check_ulvc(ctx, vlc)) return false; |
46 | | |
47 | | |
48 | | // TODO: should be in some header-file of refpic.c |
49 | | extern bool read_short_term_ref_pic_set(error_queue* errqueue, |
50 | | const seq_parameter_set* sps, |
51 | | bitreader* br, |
52 | | ref_pic_set* out_set, |
53 | | uint32_t idxRps, // index of the set to be read |
54 | | const std::vector<ref_pic_set>& sets, |
55 | | bool sliceRefPicSet); |
56 | | |
57 | | extern bool write_short_term_ref_pic_set(error_queue* errqueue, |
58 | | const seq_parameter_set* sps, |
59 | | CABAC_encoder& out, |
60 | | const ref_pic_set* in_set, // which set to write |
61 | | uint32_t idxRps, // index of the set to be read |
62 | | const std::vector<ref_pic_set>& sets, // previously read sets |
63 | | bool sliceRefPicSet); // is this in the slice header? |
64 | | |
65 | | |
66 | 162 | sps_range_extension::sps_range_extension() = default; |
67 | | |
68 | | |
69 | 162 | seq_parameter_set::seq_parameter_set() = default; |
70 | | |
71 | | |
72 | | seq_parameter_set::~seq_parameter_set() |
73 | 162 | { |
74 | | //free(ref_pic_sets); |
75 | 162 | } |
76 | | |
77 | | |
78 | | void seq_parameter_set::set_defaults(enum PresetSet) |
79 | 0 | { |
80 | 0 | video_parameter_set_id = 0; |
81 | 0 | sps_max_sub_layers = 1; |
82 | 0 | sps_temporal_id_nesting_flag = 1; |
83 | |
|
84 | 0 | profile_tier_level_.general.set_defaults(Profile_Main, 6,2); // TODO |
85 | |
|
86 | 0 | seq_parameter_set_id = 0; |
87 | 0 | chroma_format_idc = 1; |
88 | 0 | ChromaArrayType = chroma_format_idc; |
89 | |
|
90 | 0 | separate_colour_plane_flag = 0; |
91 | 0 | pic_width_in_luma_samples = 0; |
92 | 0 | pic_height_in_luma_samples = 0; |
93 | 0 | conformance_window_flag = 0; |
94 | |
|
95 | 0 | conf_win_left_offset = 0; |
96 | 0 | conf_win_right_offset = 0; |
97 | 0 | conf_win_top_offset = 0; |
98 | 0 | conf_win_bottom_offset = 0; |
99 | |
|
100 | 0 | bit_depth_luma =8; |
101 | 0 | bit_depth_chroma=8; |
102 | |
|
103 | 0 | log2_max_pic_order_cnt_lsb = 8; |
104 | 0 | sps_sub_layer_ordering_info_present_flag = 0; |
105 | |
|
106 | 0 | sps_max_dec_pic_buffering[0] = 1; |
107 | 0 | sps_max_num_reorder_pics[0] = 0; |
108 | 0 | sps_max_latency_increase_plus1[0] = 0; |
109 | |
|
110 | 0 | set_CB_log2size_range(4,4); |
111 | 0 | set_TB_log2size_range(3,4); |
112 | 0 | max_transform_hierarchy_depth_inter = 1; |
113 | 0 | max_transform_hierarchy_depth_intra = 1; |
114 | |
|
115 | 0 | scaling_list_enable_flag = 0; |
116 | 0 | sps_scaling_list_data_present_flag = 0; |
117 | | |
118 | | // TODO struct scaling_list_data scaling_list; |
119 | |
|
120 | 0 | amp_enabled_flag = 0; |
121 | 0 | sample_adaptive_offset_enabled_flag = 0; |
122 | 0 | pcm_enabled_flag = 0; |
123 | |
|
124 | 0 | pcm_sample_bit_depth_luma = 8; |
125 | 0 | pcm_sample_bit_depth_chroma = 8; |
126 | | // TODO log2_min_pcm_luma_coding_block_size; |
127 | | // TODO log2_diff_max_min_pcm_luma_coding_block_size; |
128 | 0 | pcm_loop_filter_disable_flag = 1; |
129 | | |
130 | | // num_short_term_ref_pic_sets = 0; |
131 | | // std::vector<ref_pic_set> ref_pic_sets; // [0 ; num_short_term_ref_pic_set (<=MAX_REF_PIC_SETS) ) |
132 | 0 | ref_pic_sets.clear(); |
133 | |
|
134 | 0 | long_term_ref_pics_present_flag = 0; |
135 | |
|
136 | 0 | num_long_term_ref_pics_sps = 0; |
137 | | |
138 | | /* TODO |
139 | | int lt_ref_pic_poc_lsb_sps[MAX_NUM_LT_REF_PICS_SPS]; |
140 | | char used_by_curr_pic_lt_sps_flag[MAX_NUM_LT_REF_PICS_SPS]; |
141 | | */ |
142 | |
|
143 | 0 | sps_temporal_mvp_enabled_flag = 0; |
144 | 0 | strong_intra_smoothing_enable_flag = 0; |
145 | 0 | vui_parameters_present_flag = 0; |
146 | | |
147 | | /* |
148 | | if( vui_parameters_present_flag ) |
149 | | vui_parameters() |
150 | | */ |
151 | |
|
152 | 0 | sps_extension_present_flag = 0; |
153 | 0 | sps_range_extension_flag = 0; |
154 | 0 | sps_multilayer_extension_flag = 0; |
155 | 0 | sps_extension_6bits = 0; |
156 | 0 | } |
157 | | |
158 | | |
159 | | void seq_parameter_set::set_CB_log2size_range(int mini,int maxi) |
160 | 0 | { |
161 | 0 | log2_min_luma_coding_block_size = mini; |
162 | 0 | log2_diff_max_min_luma_coding_block_size = maxi-mini; |
163 | 0 | } |
164 | | |
165 | | |
166 | | void seq_parameter_set::set_TB_log2size_range(int mini,int maxi) |
167 | 0 | { |
168 | 0 | log2_min_transform_block_size = mini; |
169 | 0 | log2_diff_max_min_transform_block_size = maxi-mini; |
170 | 0 | } |
171 | | |
172 | | |
173 | | void seq_parameter_set::set_resolution(int w,int h) |
174 | 0 | { |
175 | 0 | pic_width_in_luma_samples = w; |
176 | 0 | pic_height_in_luma_samples = h; |
177 | 0 | } |
178 | | |
179 | | |
180 | | de265_error seq_parameter_set::read(error_queue* errqueue, bitreader* br) |
181 | 162 | { |
182 | 162 | uint32_t vlc; |
183 | | |
184 | 162 | video_parameter_set_id = br->get_bits(4); |
185 | 162 | sps_max_sub_layers = br->get_bits(3) +1; |
186 | 162 | if (sps_max_sub_layers>7) { |
187 | 3 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
188 | 3 | } |
189 | | |
190 | 159 | sps_temporal_id_nesting_flag = br->get_bits(1); |
191 | | |
192 | 159 | profile_tier_level_.read(br, sps_max_sub_layers); |
193 | | |
194 | 159 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc >= DE265_MAX_SPS_SETS) { |
195 | 11 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
196 | 11 | } |
197 | 148 | seq_parameter_set_id = vlc; |
198 | | |
199 | | |
200 | | // --- decode chroma type --- |
201 | | |
202 | 148 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > 3) { |
203 | 2 | errqueue->add_warning(DE265_WARNING_INVALID_CHROMA_FORMAT, false); |
204 | 2 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
205 | 2 | } |
206 | 146 | chroma_format_idc = vlc; |
207 | | |
208 | 146 | if (chroma_format_idc == 3) { |
209 | 5 | separate_colour_plane_flag = br->get_bits(1); |
210 | 5 | } |
211 | 141 | else { |
212 | 141 | separate_colour_plane_flag = 0; |
213 | 141 | } |
214 | | |
215 | | |
216 | | // --- picture size --- |
217 | | |
218 | 146 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc == 0 || vlc > MAX_PICTURE_WIDTH) { |
219 | 4 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
220 | 4 | } |
221 | 142 | pic_width_in_luma_samples = vlc; |
222 | | |
223 | 142 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc == 0 || vlc > MAX_PICTURE_HEIGHT) { |
224 | 3 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
225 | 3 | } |
226 | 139 | pic_height_in_luma_samples = vlc; |
227 | | |
228 | 139 | conformance_window_flag = br->get_bits(1); |
229 | | |
230 | 139 | if (conformance_window_flag) { |
231 | 25 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc >= static_cast<uint32_t>(pic_width_in_luma_samples)) { |
232 | 5 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
233 | 5 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
234 | 5 | } |
235 | 20 | conf_win_left_offset = vlc; |
236 | | |
237 | 20 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || |
238 | 19 | vlc + conf_win_left_offset >= static_cast<uint32_t>(pic_width_in_luma_samples)) { |
239 | 3 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
240 | 3 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
241 | 3 | } |
242 | 17 | conf_win_right_offset = vlc; |
243 | | |
244 | 17 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc >= static_cast<uint32_t>(pic_height_in_luma_samples)) { |
245 | 3 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
246 | 3 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
247 | 3 | } |
248 | 14 | conf_win_top_offset = vlc; |
249 | | |
250 | 14 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || |
251 | 14 | vlc + conf_win_top_offset >= static_cast<uint32_t>(pic_height_in_luma_samples)) { |
252 | 1 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
253 | 1 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
254 | 1 | } |
255 | 13 | conf_win_bottom_offset = vlc; |
256 | 13 | } |
257 | 114 | else { |
258 | 114 | conf_win_left_offset = 0; |
259 | 114 | conf_win_right_offset = 0; |
260 | 114 | conf_win_top_offset = 0; |
261 | 114 | conf_win_bottom_offset= 0; |
262 | 114 | } |
263 | | |
264 | 127 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > 8) { |
265 | 2 | errqueue->add_warning(DE265_WARNING_SPS_HEADER_INVALID, false); |
266 | 2 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
267 | 2 | } |
268 | 125 | bit_depth_luma = vlc + 8; |
269 | | |
270 | 125 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > 8) { |
271 | 2 | errqueue->add_warning(DE265_WARNING_SPS_HEADER_INVALID, false); |
272 | 2 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
273 | 2 | } |
274 | 123 | bit_depth_chroma = vlc + 8; |
275 | | |
276 | 123 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > 12) { |
277 | 2 | errqueue->add_warning(DE265_WARNING_SPS_HEADER_INVALID, false); |
278 | 2 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
279 | 2 | } |
280 | 121 | log2_max_pic_order_cnt_lsb = vlc + 4; |
281 | 121 | MaxPicOrderCntLsb = 1<<(log2_max_pic_order_cnt_lsb); |
282 | | |
283 | | |
284 | | // --- sub_layer_ordering_info --- |
285 | | |
286 | 121 | sps_sub_layer_ordering_info_present_flag = br->get_bits(1); |
287 | | |
288 | 121 | int firstLayer = (sps_sub_layer_ordering_info_present_flag ? |
289 | 109 | 0 : sps_max_sub_layers-1 ); |
290 | | |
291 | 245 | for (int i=firstLayer ; i <= sps_max_sub_layers-1; i++ ) { |
292 | | |
293 | | // sps_max_dec_pic_buffering[i] |
294 | | |
295 | 132 | vlc=br->get_uvlc(); |
296 | 132 | if (vlc == UVLC_ERROR || |
297 | 130 | vlc+1 > MAX_NUM_REF_PICS) { |
298 | 3 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
299 | 3 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
300 | 3 | } |
301 | | |
302 | 129 | sps_max_dec_pic_buffering[i] = vlc+1; |
303 | | |
304 | | // sps_max_num_reorder_pics[i] |
305 | | |
306 | 129 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > sps_max_dec_pic_buffering[i]) { |
307 | 4 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
308 | 4 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
309 | 4 | } |
310 | 125 | sps_max_num_reorder_pics[i] = vlc; |
311 | | |
312 | | |
313 | | // sps_max_latency_increase[i] |
314 | | |
315 | 125 | READ_VLC(sps_max_latency_increase_plus1[i], uvlc); |
316 | | |
317 | 124 | sps_max_latency_increase_present[i] = (sps_max_latency_increase_plus1[i] != 0); |
318 | 124 | if (sps_max_latency_increase_present[i]) { |
319 | 11 | SpsMaxLatencyPictures[i] = (sps_max_num_reorder_pics[i] + |
320 | 11 | sps_max_latency_increase_plus1[i] - 1); |
321 | 11 | } |
322 | 124 | } |
323 | | |
324 | | // copy info to all layers if only specified once |
325 | | |
326 | 113 | if (sps_sub_layer_ordering_info_present_flag) { |
327 | 105 | int ref = sps_max_sub_layers-1; |
328 | 105 | assert(ref<7); |
329 | | |
330 | 109 | for (int i=0 ; i < sps_max_sub_layers-1; i++ ) { |
331 | 4 | sps_max_dec_pic_buffering[i] = sps_max_dec_pic_buffering[ref]; |
332 | 4 | sps_max_num_reorder_pics[i] = sps_max_num_reorder_pics[ref]; |
333 | 4 | sps_max_latency_increase_plus1[i] = sps_max_latency_increase_plus1[ref]; |
334 | 4 | sps_max_latency_increase_present[i] = sps_max_latency_increase_present[ref]; |
335 | 4 | SpsMaxLatencyPictures[i] = SpsMaxLatencyPictures[ref]; |
336 | 4 | } |
337 | 105 | } |
338 | | |
339 | | |
340 | 113 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > 3) { |
341 | 4 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
342 | 4 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
343 | 4 | } |
344 | 109 | log2_min_luma_coding_block_size = vlc + 3; |
345 | | |
346 | 109 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > static_cast<uint32_t>(6 - log2_min_luma_coding_block_size)) { |
347 | 3 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
348 | 3 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
349 | 3 | } |
350 | 106 | log2_diff_max_min_luma_coding_block_size = vlc; |
351 | | |
352 | 106 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > 3) { |
353 | 2 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
354 | 2 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
355 | 2 | } |
356 | 104 | log2_min_transform_block_size = vlc + 2; |
357 | | |
358 | 104 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > static_cast<uint32_t>(5 - log2_min_transform_block_size)) { |
359 | 2 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
360 | 2 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
361 | 2 | } |
362 | 102 | log2_diff_max_min_transform_block_size = vlc; |
363 | | |
364 | | // log2_min_transform_block_size must not exceed the max coding block size (Log2CtbSizeY) |
365 | 102 | if (log2_min_transform_block_size > log2_min_luma_coding_block_size + log2_diff_max_min_luma_coding_block_size) { |
366 | 0 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
367 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
368 | 0 | } |
369 | | |
370 | 102 | uint32_t maxDepth = log2_min_luma_coding_block_size + log2_diff_max_min_luma_coding_block_size |
371 | 102 | - log2_min_transform_block_size; |
372 | | |
373 | 102 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > maxDepth) { |
374 | 6 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
375 | 6 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
376 | 6 | } |
377 | 96 | max_transform_hierarchy_depth_inter = vlc; |
378 | | |
379 | 96 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > maxDepth) { |
380 | 2 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
381 | 2 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
382 | 2 | } |
383 | 94 | max_transform_hierarchy_depth_intra = vlc; |
384 | | |
385 | 94 | scaling_list_enable_flag = br->get_bits(1); |
386 | | |
387 | 94 | if (scaling_list_enable_flag) { |
388 | | |
389 | 61 | sps_scaling_list_data_present_flag = br->get_bits(1); |
390 | 61 | if (sps_scaling_list_data_present_flag) { |
391 | | |
392 | 21 | de265_error err; |
393 | 21 | if ((err=read_scaling_list(br,this, &scaling_list, false)) != DE265_OK) { |
394 | 21 | return err; |
395 | 21 | } |
396 | 21 | } |
397 | 40 | else { |
398 | 40 | set_default_scaling_lists(&scaling_list); |
399 | 40 | } |
400 | 61 | } |
401 | | |
402 | 73 | amp_enabled_flag = br->get_bits(1); |
403 | 73 | sample_adaptive_offset_enabled_flag = br->get_bits(1); |
404 | 73 | pcm_enabled_flag = br->get_bits(1); |
405 | 73 | if (pcm_enabled_flag) { |
406 | 6 | pcm_sample_bit_depth_luma = br->get_bits(4)+1; |
407 | 6 | pcm_sample_bit_depth_chroma = br->get_bits(4)+1; |
408 | 6 | int log2PcmCbSizeMax = std::min(static_cast<int>(log2_min_luma_coding_block_size + |
409 | 6 | log2_diff_max_min_luma_coding_block_size), 5); |
410 | | |
411 | 6 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc + 3 > static_cast<uint32_t>(log2PcmCbSizeMax)) { |
412 | 1 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
413 | 1 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
414 | 1 | } |
415 | 5 | log2_min_pcm_luma_coding_block_size = vlc + 3; |
416 | | |
417 | 5 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > static_cast<uint32_t>(log2PcmCbSizeMax - log2_min_pcm_luma_coding_block_size)) { |
418 | 1 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
419 | 1 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
420 | 1 | } |
421 | 4 | log2_diff_max_min_pcm_luma_coding_block_size = vlc; |
422 | 4 | pcm_loop_filter_disable_flag = br->get_bits(1); |
423 | | |
424 | 4 | if (pcm_sample_bit_depth_luma > bit_depth_luma) { |
425 | 1 | errqueue->add_warning(DE265_WARNING_PCM_BITDEPTH_TOO_LARGE, false); |
426 | 1 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
427 | 1 | } |
428 | | |
429 | 3 | if (pcm_sample_bit_depth_chroma > bit_depth_chroma) { |
430 | 1 | errqueue->add_warning(DE265_WARNING_PCM_BITDEPTH_TOO_LARGE, false); |
431 | 1 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
432 | 1 | } |
433 | 3 | } |
434 | 67 | else { |
435 | 67 | pcm_sample_bit_depth_luma = 0; |
436 | 67 | pcm_sample_bit_depth_chroma = 0; |
437 | 67 | log2_min_pcm_luma_coding_block_size = 0; |
438 | 67 | log2_diff_max_min_pcm_luma_coding_block_size = 0; |
439 | 67 | pcm_loop_filter_disable_flag = 0; |
440 | 67 | } |
441 | | |
442 | 69 | int num_short_term_ref_pic_sets; |
443 | 69 | READ_VLC(num_short_term_ref_pic_sets, uvlc); |
444 | 68 | if (num_short_term_ref_pic_sets < 0 || |
445 | 68 | num_short_term_ref_pic_sets > 64) { |
446 | 1 | errqueue->add_warning(DE265_WARNING_NUMBER_OF_SHORT_TERM_REF_PIC_SETS_OUT_OF_RANGE, false); |
447 | 1 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
448 | 1 | } |
449 | | |
450 | | // --- allocate reference pic set --- |
451 | | |
452 | | // we do not allocate the ref-pic-set for the slice header here, but in the slice header itself |
453 | | |
454 | 67 | ref_pic_sets.resize(num_short_term_ref_pic_sets); |
455 | | |
456 | 205 | for (int i = 0; i < num_short_term_ref_pic_sets; i++) { |
457 | | |
458 | 167 | bool success = read_short_term_ref_pic_set(errqueue,this,br, |
459 | 167 | &ref_pic_sets[i], i, |
460 | 167 | ref_pic_sets, |
461 | 167 | false); |
462 | | |
463 | 167 | if (!success) { |
464 | 29 | return DE265_WARNING_SPS_HEADER_INVALID; |
465 | 29 | } |
466 | | |
467 | | // dump_short_term_ref_pic_set(&(*ref_pic_sets)[i], fh); |
468 | 167 | } |
469 | | |
470 | 38 | long_term_ref_pics_present_flag = br->get_bits(1); |
471 | | |
472 | 38 | if (long_term_ref_pics_present_flag) { |
473 | | |
474 | 11 | if ((vlc = br->get_uvlc()) == UVLC_ERROR || vlc > MAX_NUM_LT_REF_PICS_SPS) { |
475 | 1 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
476 | 1 | } |
477 | 10 | num_long_term_ref_pics_sps = vlc; |
478 | | |
479 | 22 | for (int i = 0; i < num_long_term_ref_pics_sps; i++ ) { |
480 | 12 | lt_ref_pic_poc_lsb_sps[i] = br->get_bits(log2_max_pic_order_cnt_lsb); |
481 | 12 | used_by_curr_pic_lt_sps_flag[i] = br->get_bits(1); |
482 | 12 | } |
483 | 10 | } |
484 | 27 | else { |
485 | 27 | num_long_term_ref_pics_sps = 0; // NOTE: missing definition in standard ! |
486 | 27 | } |
487 | | |
488 | 37 | sps_temporal_mvp_enabled_flag = br->get_bits(1); |
489 | 37 | strong_intra_smoothing_enable_flag = br->get_bits(1); |
490 | | |
491 | 37 | vui_parameters_present_flag = br->get_bits(1); |
492 | 37 | if (vui_parameters_present_flag) { |
493 | 21 | de265_error err = vui.read(errqueue, br, this); |
494 | 21 | if (err) { |
495 | 12 | return err; |
496 | 12 | } |
497 | 21 | } |
498 | | |
499 | | |
500 | 25 | sps_extension_present_flag = br->get_bits(1); |
501 | 25 | if (sps_extension_present_flag) { |
502 | 2 | sps_range_extension_flag = br->get_bits(1); |
503 | 2 | sps_multilayer_extension_flag = br->get_bits(1); |
504 | 2 | sps_extension_6bits = br->get_bits(6); |
505 | 2 | } |
506 | 23 | else { |
507 | 23 | sps_range_extension_flag = 0; |
508 | 23 | } |
509 | | |
510 | 25 | if (sps_range_extension_flag) { |
511 | 1 | de265_error err = range_extension.read(errqueue, br); |
512 | 1 | if (err != DE265_OK) { return err; } |
513 | 1 | } |
514 | | |
515 | | /* |
516 | | sps_extension_flag = br->get_bits(1); |
517 | | if (sps_extension_flag) { |
518 | | assert(false); |
519 | | } |
520 | | */ |
521 | | |
522 | | |
523 | 25 | de265_error err = compute_derived_values(); |
524 | 25 | if (err != DE265_OK) { return err; } |
525 | | |
526 | 0 | sps_read = true; |
527 | |
|
528 | 0 | return DE265_OK; |
529 | 25 | } |
530 | | |
531 | | |
532 | | de265_error seq_parameter_set::compute_derived_values(bool sanitize_values) |
533 | 25 | { |
534 | | // --- compute derived values --- |
535 | | |
536 | 25 | SubWidthC = SubWidthC_tab [chroma_format_idc]; |
537 | 25 | SubHeightC = SubHeightC_tab[chroma_format_idc]; |
538 | | |
539 | 25 | if (separate_colour_plane_flag) { |
540 | 0 | ChromaArrayType = 0; |
541 | 0 | } |
542 | 25 | else { |
543 | 25 | ChromaArrayType = chroma_format_idc; |
544 | 25 | } |
545 | | |
546 | 25 | if (ChromaArrayType==0) { |
547 | 2 | WinUnitX = 1; |
548 | 2 | WinUnitY = 1; |
549 | 2 | } |
550 | 23 | else { |
551 | 23 | WinUnitX = SubWidthC_tab [chroma_format_idc]; |
552 | 23 | WinUnitY = SubHeightC_tab[chroma_format_idc]; |
553 | 23 | } |
554 | | |
555 | | |
556 | | |
557 | 25 | BitDepth_Y = bit_depth_luma; |
558 | 25 | QpBdOffset_Y = 6*(bit_depth_luma-8); |
559 | 25 | BitDepth_C = bit_depth_chroma; |
560 | 25 | QpBdOffset_C = 6*(bit_depth_chroma-8); |
561 | | |
562 | 25 | Log2MinCbSizeY = log2_min_luma_coding_block_size; |
563 | 25 | Log2CtbSizeY = Log2MinCbSizeY + log2_diff_max_min_luma_coding_block_size; |
564 | 25 | MinCbSizeY = 1 << Log2MinCbSizeY; |
565 | 25 | CtbSizeY = 1 << Log2CtbSizeY; |
566 | | |
567 | 25 | PicWidthInMinCbsY = ceil_div(pic_width_in_luma_samples, MinCbSizeY); |
568 | 25 | PicWidthInCtbsY = ceil_div(pic_width_in_luma_samples, CtbSizeY); |
569 | 25 | PicHeightInMinCbsY = ceil_div(pic_height_in_luma_samples, MinCbSizeY); |
570 | 25 | PicHeightInCtbsY = ceil_div(pic_height_in_luma_samples,CtbSizeY); |
571 | 25 | PicSizeInMinCbsY = PicWidthInMinCbsY * PicHeightInMinCbsY; |
572 | 25 | PicSizeInCtbsY = PicWidthInCtbsY * PicHeightInCtbsY; |
573 | 25 | PicSizeInSamplesY = static_cast<uint32_t>(pic_width_in_luma_samples) * pic_height_in_luma_samples; |
574 | | |
575 | 25 | if (chroma_format_idc==0 || separate_colour_plane_flag) { |
576 | 2 | CtbWidthC = 0; |
577 | 2 | CtbHeightC = 0; |
578 | 2 | } |
579 | 23 | else { |
580 | 23 | CtbWidthC = CtbSizeY / SubWidthC; |
581 | 23 | CtbHeightC = CtbSizeY / SubHeightC; |
582 | 23 | } |
583 | | |
584 | 25 | Log2MinTrafoSize = log2_min_transform_block_size; |
585 | 25 | Log2MaxTrafoSize = log2_min_transform_block_size + log2_diff_max_min_transform_block_size; |
586 | 25 | assert(Log2MaxTrafoSize >= 2); // log2_min_transform_block_size >= 2 by spec; relied on by pps.cc |
587 | | |
588 | 25 | if (max_transform_hierarchy_depth_inter > Log2CtbSizeY - Log2MinTrafoSize) { |
589 | 0 | if (sanitize_values) { |
590 | 0 | max_transform_hierarchy_depth_inter = Log2CtbSizeY - Log2MinTrafoSize; |
591 | 0 | } else { |
592 | 0 | if (D) fprintf(stderr,"SPS error: transform hierarchy depth (inter) > CTB size - min TB size\n"); |
593 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
594 | 0 | } |
595 | 0 | } |
596 | | |
597 | 25 | if (max_transform_hierarchy_depth_intra > Log2CtbSizeY - Log2MinTrafoSize) { |
598 | 0 | if (sanitize_values) { |
599 | 0 | max_transform_hierarchy_depth_intra = Log2CtbSizeY - Log2MinTrafoSize; |
600 | 0 | } else { |
601 | 0 | if (D) fprintf(stderr,"SPS error: transform hierarchy depth (intra) > CTB size - min TB size\n"); |
602 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
603 | 0 | } |
604 | 0 | } |
605 | | |
606 | | |
607 | 25 | if (sanitize_values) { |
608 | 0 | if (max_transform_hierarchy_depth_inter < Log2CtbSizeY - Log2MaxTrafoSize) { |
609 | 0 | max_transform_hierarchy_depth_inter = Log2CtbSizeY - Log2MaxTrafoSize; |
610 | 0 | } |
611 | |
|
612 | 0 | if (max_transform_hierarchy_depth_intra < Log2CtbSizeY - Log2MaxTrafoSize) { |
613 | 0 | max_transform_hierarchy_depth_intra = Log2CtbSizeY - Log2MaxTrafoSize; |
614 | 0 | } |
615 | 0 | } |
616 | | |
617 | | |
618 | 25 | Log2MinPUSize = Log2MinCbSizeY-1; |
619 | 25 | PicWidthInMinPUs = PicWidthInCtbsY << (Log2CtbSizeY - Log2MinPUSize); |
620 | 25 | PicHeightInMinPUs = PicHeightInCtbsY << (Log2CtbSizeY - Log2MinPUSize); |
621 | | |
622 | 25 | Log2MinIpcmCbSizeY = log2_min_pcm_luma_coding_block_size; |
623 | 25 | Log2MaxIpcmCbSizeY = (log2_min_pcm_luma_coding_block_size + |
624 | 25 | log2_diff_max_min_pcm_luma_coding_block_size); |
625 | | |
626 | | // the following are not in the standard |
627 | 25 | PicWidthInTbsY = PicWidthInCtbsY << (Log2CtbSizeY - Log2MinTrafoSize); |
628 | 25 | PicHeightInTbsY = PicHeightInCtbsY << (Log2CtbSizeY - Log2MinTrafoSize); |
629 | 25 | PicSizeInTbsY = PicWidthInTbsY * PicHeightInTbsY; |
630 | | |
631 | | |
632 | 25 | if (range_extension.high_precision_offsets_enabled_flag) { |
633 | 0 | WpOffsetBdShiftY = 0; |
634 | 0 | WpOffsetBdShiftC = 0; |
635 | 0 | WpOffsetHalfRangeY = 1 << (BitDepth_Y - 1); |
636 | 0 | WpOffsetHalfRangeC = 1 << (BitDepth_C - 1); |
637 | 0 | } |
638 | 25 | else { |
639 | 25 | WpOffsetBdShiftY = ( BitDepth_Y - 8 ); |
640 | 25 | WpOffsetBdShiftC = ( BitDepth_C - 8 ); |
641 | 25 | WpOffsetHalfRangeY = 1 << 7; |
642 | 25 | WpOffsetHalfRangeC = 1 << 7; |
643 | 25 | } |
644 | | |
645 | | |
646 | | // --- check SPS sanity --- |
647 | | |
648 | 25 | if (pic_width_in_luma_samples % MinCbSizeY != 0 || |
649 | 25 | pic_height_in_luma_samples % MinCbSizeY != 0) { |
650 | | // TODO: warn that image size is coded wrong in bitstream (must be multiple of MinCbSizeY) |
651 | 25 | if (D) fprintf(stderr,"SPS error: CB alignment\n"); |
652 | 25 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
653 | 25 | } |
654 | | |
655 | 0 | if (Log2MinTrafoSize > Log2MinCbSizeY) { |
656 | 0 | if (D) fprintf(stderr,"SPS error: TB > CB\n"); |
657 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
658 | 0 | } |
659 | | |
660 | 0 | if (Log2MaxTrafoSize > std::min((int)Log2CtbSizeY,5)) { |
661 | 0 | if (D) fprintf(stderr,"SPS error: TB_max > 32 or CTB\n"); |
662 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
663 | 0 | } |
664 | | |
665 | | |
666 | 0 | if (BitDepth_Y < 8 || BitDepth_Y > 16) { |
667 | 0 | if (D) fprintf(stderr,"SPS error: bitdepth Y not in [8;16]\n"); |
668 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
669 | 0 | } |
670 | | |
671 | 0 | if (BitDepth_C < 8 || BitDepth_C > 16) { |
672 | 0 | if (D) fprintf(stderr,"SPS error: bitdepth C not in [8;16]\n"); |
673 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
674 | 0 | } |
675 | | |
676 | | |
677 | 0 | sps_read = true; |
678 | |
|
679 | 0 | return DE265_OK; |
680 | 0 | } |
681 | | |
682 | | |
683 | | |
684 | | void seq_parameter_set::dump(int fd) const |
685 | 0 | { |
686 | | //#if (_MSC_VER >= 1500) |
687 | | //#define LOG0(t) loginfo(LogHeaders, t) |
688 | | //#define LOG1(t,d) loginfo(LogHeaders, t,d) |
689 | | //#define LOG2(t,d1,d2) loginfo(LogHeaders, t,d1,d2) |
690 | | //#define LOG3(t,d1,d2,d3) loginfo(LogHeaders, t,d1,d2,d3) |
691 | |
|
692 | 0 | FILE* fh; |
693 | 0 | if (fd==1) fh=stdout; |
694 | 0 | else if (fd==2) fh=stderr; |
695 | 0 | else { return; } |
696 | | |
697 | 0 | #define LOG0(t) log2fh(fh, t) |
698 | 0 | #define LOG1(t,d) log2fh(fh, t,d) |
699 | 0 | #define LOG2(t,d1,d2) log2fh(fh, t,d1,d2) |
700 | 0 | #define LOG3(t,d1,d2,d3) log2fh(fh, t,d1,d2,d3) |
701 | | |
702 | | |
703 | 0 | LOG0("----------------- SPS -----------------\n"); |
704 | 0 | LOG1("video_parameter_set_id : %d\n", video_parameter_set_id); |
705 | 0 | LOG1("sps_max_sub_layers : %d\n", sps_max_sub_layers); |
706 | 0 | LOG1("sps_temporal_id_nesting_flag : %d\n", sps_temporal_id_nesting_flag); |
707 | |
|
708 | 0 | profile_tier_level_.dump(sps_max_sub_layers, fh); |
709 | |
|
710 | 0 | LOG1("seq_parameter_set_id : %d\n", seq_parameter_set_id); |
711 | 0 | LOG2("chroma_format_idc : %d (%s)\n", chroma_format_idc, |
712 | 0 | chroma_format_idc == 0 ? "monochrome" : |
713 | 0 | chroma_format_idc == 1 ? "4:2:0" : |
714 | 0 | chroma_format_idc == 2 ? "4:2:2" : |
715 | 0 | chroma_format_idc == 3 ? "4:4:4" : "unknown"); |
716 | |
|
717 | 0 | if (chroma_format_idc == 3) { |
718 | 0 | LOG1("separate_colour_plane_flag : %d\n", separate_colour_plane_flag); |
719 | 0 | } |
720 | |
|
721 | 0 | LOG1("pic_width_in_luma_samples : %d\n", pic_width_in_luma_samples); |
722 | 0 | LOG1("pic_height_in_luma_samples : %d\n", pic_height_in_luma_samples); |
723 | 0 | LOG1("conformance_window_flag : %d\n", conformance_window_flag); |
724 | |
|
725 | 0 | if (conformance_window_flag) { |
726 | 0 | LOG1("conf_win_left_offset : %d\n", conf_win_left_offset); |
727 | 0 | LOG1("conf_win_right_offset : %d\n", conf_win_right_offset); |
728 | 0 | LOG1("conf_win_top_offset : %d\n", conf_win_top_offset); |
729 | 0 | LOG1("conf_win_bottom_offset: %d\n", conf_win_bottom_offset); |
730 | 0 | } |
731 | |
|
732 | 0 | LOG1("bit_depth_luma : %d\n", bit_depth_luma); |
733 | 0 | LOG1("bit_depth_chroma : %d\n", bit_depth_chroma); |
734 | |
|
735 | 0 | LOG1("log2_max_pic_order_cnt_lsb : %d\n", log2_max_pic_order_cnt_lsb); |
736 | 0 | LOG1("sps_sub_layer_ordering_info_present_flag : %d\n", sps_sub_layer_ordering_info_present_flag); |
737 | |
|
738 | 0 | int firstLayer = (sps_sub_layer_ordering_info_present_flag ? |
739 | 0 | 0 : sps_max_sub_layers-1 ); |
740 | |
|
741 | 0 | for (int i=firstLayer ; i <= sps_max_sub_layers-1; i++ ) { |
742 | 0 | LOG1("Layer %d\n",i); |
743 | 0 | LOG1(" sps_max_dec_pic_buffering : %d\n", sps_max_dec_pic_buffering[i]); |
744 | 0 | LOG1(" sps_max_num_reorder_pics : %d\n", sps_max_num_reorder_pics[i]); |
745 | 0 | LOG1(" sps_max_latency_increase_plus1 : %d\n", sps_max_latency_increase_plus1[i]); |
746 | 0 | } |
747 | |
|
748 | 0 | LOG1("log2_min_luma_coding_block_size : %d\n", log2_min_luma_coding_block_size); |
749 | 0 | LOG1("log2_diff_max_min_luma_coding_block_size : %d\n",log2_diff_max_min_luma_coding_block_size); |
750 | 0 | LOG1("log2_min_transform_block_size : %d\n", log2_min_transform_block_size); |
751 | 0 | LOG1("log2_diff_max_min_transform_block_size : %d\n", log2_diff_max_min_transform_block_size); |
752 | 0 | LOG1("max_transform_hierarchy_depth_inter : %d\n", max_transform_hierarchy_depth_inter); |
753 | 0 | LOG1("max_transform_hierarchy_depth_intra : %d\n", max_transform_hierarchy_depth_intra); |
754 | 0 | LOG1("scaling_list_enable_flag : %d\n", scaling_list_enable_flag); |
755 | |
|
756 | 0 | if (scaling_list_enable_flag) { |
757 | |
|
758 | 0 | LOG1("sps_scaling_list_data_present_flag : %d\n", sps_scaling_list_data_present_flag); |
759 | 0 | if (sps_scaling_list_data_present_flag) { |
760 | |
|
761 | 0 | LOG0("scaling list logging output not implemented"); |
762 | | //assert(0); |
763 | | //scaling_list_data() |
764 | 0 | } |
765 | 0 | } |
766 | |
|
767 | 0 | LOG1("amp_enabled_flag : %d\n", amp_enabled_flag); |
768 | 0 | LOG1("sample_adaptive_offset_enabled_flag : %d\n", sample_adaptive_offset_enabled_flag); |
769 | 0 | LOG1("pcm_enabled_flag : %d\n", pcm_enabled_flag); |
770 | |
|
771 | 0 | if (pcm_enabled_flag) { |
772 | 0 | LOG1("pcm_sample_bit_depth_luma : %d\n", pcm_sample_bit_depth_luma); |
773 | 0 | LOG1("pcm_sample_bit_depth_chroma : %d\n", pcm_sample_bit_depth_chroma); |
774 | 0 | LOG1("log2_min_pcm_luma_coding_block_size : %d\n", log2_min_pcm_luma_coding_block_size); |
775 | 0 | LOG1("log2_diff_max_min_pcm_luma_coding_block_size : %d\n", log2_diff_max_min_pcm_luma_coding_block_size); |
776 | 0 | LOG1("pcm_loop_filter_disable_flag : %d\n", pcm_loop_filter_disable_flag); |
777 | 0 | } |
778 | |
|
779 | 0 | LOG1("num_short_term_ref_pic_sets : %d\n", ref_pic_sets.size()); |
780 | |
|
781 | 0 | for (size_t i = 0; i < ref_pic_sets.size(); i++) { |
782 | 0 | LOG1("ref_pic_set[ %2d ]: ",i); |
783 | 0 | dump_compact_short_term_ref_pic_set(&ref_pic_sets[i], 16, fh); |
784 | 0 | } |
785 | |
|
786 | 0 | LOG1("long_term_ref_pics_present_flag : %d\n", long_term_ref_pics_present_flag); |
787 | |
|
788 | 0 | if (long_term_ref_pics_present_flag) { |
789 | |
|
790 | 0 | LOG1("num_long_term_ref_pics_sps : %d\n", num_long_term_ref_pics_sps); |
791 | |
|
792 | 0 | for (int i = 0; i < num_long_term_ref_pics_sps; i++ ) { |
793 | 0 | LOG3("lt_ref_pic_poc_lsb_sps[%d] : %d (used_by_curr_pic_lt_sps_flag=%d)\n", |
794 | 0 | i, lt_ref_pic_poc_lsb_sps[i], used_by_curr_pic_lt_sps_flag[i]); |
795 | 0 | } |
796 | 0 | } |
797 | |
|
798 | 0 | LOG1("sps_temporal_mvp_enabled_flag : %d\n", sps_temporal_mvp_enabled_flag); |
799 | 0 | LOG1("strong_intra_smoothing_enable_flag : %d\n", strong_intra_smoothing_enable_flag); |
800 | 0 | LOG1("vui_parameters_present_flag : %d\n", vui_parameters_present_flag); |
801 | |
|
802 | 0 | LOG1("sps_extension_present_flag : %d\n", sps_extension_present_flag); |
803 | 0 | LOG1("sps_range_extension_flag : %d\n", sps_range_extension_flag); |
804 | 0 | LOG1("sps_multilayer_extension_flag : %d\n", sps_multilayer_extension_flag); |
805 | 0 | LOG1("sps_extension_6bits : %d\n", sps_extension_6bits); |
806 | |
|
807 | 0 | LOG1("CtbSizeY : %d\n", CtbSizeY); |
808 | 0 | LOG1("MinCbSizeY : %d\n", MinCbSizeY); |
809 | 0 | LOG1("MaxCbSizeY : %d\n", 1<<(log2_min_luma_coding_block_size + log2_diff_max_min_luma_coding_block_size)); |
810 | 0 | LOG1("MinTBSizeY : %d\n", 1<<log2_min_transform_block_size); |
811 | 0 | LOG1("MaxTBSizeY : %d\n", 1<<(log2_min_transform_block_size + log2_diff_max_min_transform_block_size)); |
812 | |
|
813 | 0 | LOG1("PicWidthInCtbsY : %d\n", PicWidthInCtbsY); |
814 | 0 | LOG1("PicHeightInCtbsY : %d\n", PicHeightInCtbsY); |
815 | 0 | LOG1("SubWidthC : %d\n", SubWidthC); |
816 | 0 | LOG1("SubHeightC : %d\n", SubHeightC); |
817 | |
|
818 | 0 | if (sps_range_extension_flag) { |
819 | 0 | range_extension.dump(fd); |
820 | 0 | } |
821 | |
|
822 | 0 | if (vui_parameters_present_flag) { |
823 | 0 | vui.dump(fd); |
824 | 0 | } |
825 | 0 | #undef LOG0 |
826 | 0 | #undef LOG1 |
827 | 0 | #undef LOG2 |
828 | 0 | #undef LOG3 |
829 | | //#endif |
830 | 0 | } |
831 | | |
832 | | |
833 | | static uint8_t default_ScalingList_4x4[16] = { |
834 | | 16,16,16,16,16,16,16,16, |
835 | | 16,16,16,16,16,16,16,16 |
836 | | }; |
837 | | |
838 | | static uint8_t default_ScalingList_8x8_intra[64] = { |
839 | | 16,16,16,16,16,16,16,16, |
840 | | 16,16,17,16,17,16,17,18, |
841 | | 17,18,18,17,18,21,19,20, |
842 | | 21,20,19,21,24,22,22,24, |
843 | | 24,22,22,24,25,25,27,30, |
844 | | 27,25,25,29,31,35,35,31, |
845 | | 29,36,41,44,41,36,47,54, |
846 | | 54,47,65,70,65,88,88,115 |
847 | | }; |
848 | | |
849 | | static uint8_t default_ScalingList_8x8_inter[64] = { |
850 | | 16,16,16,16,16,16,16,16, |
851 | | 16,16,17,17,17,17,17,18, |
852 | | 18,18,18,18,18,20,20,20, |
853 | | 20,20,20,20,24,24,24,24, |
854 | | 24,24,24,24,25,25,25,25, |
855 | | 25,25,25,28,28,28,28,28, |
856 | | 28,33,33,33,33,33,41,41, |
857 | | 41,41,54,54,54,71,71,91 |
858 | | }; |
859 | | |
860 | | |
861 | | void fill_scaling_factor(uint8_t* scalingFactors, const uint8_t* sclist, int sizeId) |
862 | 813 | { |
863 | 813 | const position* scan; |
864 | 813 | int width; |
865 | 813 | int subWidth; |
866 | | |
867 | 813 | switch (sizeId) { |
868 | 253 | case 0: |
869 | 253 | width=4; |
870 | 253 | subWidth=1; |
871 | 253 | scan = get_scan_order(2, 0 /* diag */); |
872 | | |
873 | 4.30k | for (int i=0;i<4*4;i++) { |
874 | 4.04k | scalingFactors[scan[i].x + width*scan[i].y] = sclist[i]; |
875 | 4.04k | } |
876 | 253 | break; |
877 | | |
878 | 240 | case 1: |
879 | 240 | width=8; |
880 | 240 | subWidth=1; |
881 | 240 | scan = get_scan_order(3, 0 /* diag */); |
882 | | |
883 | 15.6k | for (int i=0;i<8*8;i++) { |
884 | 15.3k | scalingFactors[scan[i].x + width*scan[i].y] = sclist[i]; |
885 | 15.3k | } |
886 | 240 | break; |
887 | | |
888 | 240 | case 2: |
889 | 240 | width=8; |
890 | 240 | subWidth=2; |
891 | 240 | scan = get_scan_order(3, 0 /* diag */); |
892 | | |
893 | 15.6k | for (int i=0;i<8*8;i++) { |
894 | 46.0k | for (int dy=0;dy<2;dy++) |
895 | 92.1k | for (int dx=0;dx<2;dx++) |
896 | 61.4k | { |
897 | 61.4k | int x = 2*scan[i].x+dx; |
898 | 61.4k | int y = 2*scan[i].y+dy; |
899 | 61.4k | scalingFactors[x+width*subWidth*y] = sclist[i]; |
900 | 61.4k | } |
901 | 15.3k | } |
902 | 240 | break; |
903 | | |
904 | 80 | case 3: |
905 | 80 | width=8; |
906 | 80 | subWidth=4; |
907 | 80 | scan = get_scan_order(3, 0 /* diag */); |
908 | | |
909 | 5.20k | for (int i=0;i<8*8;i++) { |
910 | 25.6k | for (int dy=0;dy<4;dy++) |
911 | 102k | for (int dx=0;dx<4;dx++) |
912 | 81.9k | { |
913 | 81.9k | int x = 4*scan[i].x+dx; |
914 | 81.9k | int y = 4*scan[i].y+dy; |
915 | 81.9k | scalingFactors[x+width*subWidth*y] = sclist[i]; |
916 | 81.9k | } |
917 | 5.12k | } |
918 | 80 | break; |
919 | | |
920 | 0 | default: |
921 | 0 | assert(0); |
922 | 0 | break; |
923 | 813 | } |
924 | | |
925 | | |
926 | | // --- dump matrix --- |
927 | | |
928 | | #if 0 |
929 | | for (int y=0;y<width;y++) { |
930 | | for (int x=0;x<width;x++) |
931 | | printf("%d,",scalingFactors[x*subWidth + width*subWidth*subWidth*y]); |
932 | | |
933 | | printf("\n"); |
934 | | } |
935 | | #endif |
936 | 813 | } |
937 | | |
938 | | |
939 | | de265_error read_scaling_list(bitreader* br, const seq_parameter_set* sps, |
940 | | scaling_list_data* sclist, bool inPPS) |
941 | 21 | { |
942 | 21 | int dc_coeff[4][6]; |
943 | | |
944 | 21 | for (int sizeId=0;sizeId<4;sizeId++) { |
945 | | //int n = ((sizeId==3) ? 2 : 6); |
946 | 21 | uint8_t scaling_list[6][32*32]; |
947 | | |
948 | | // Note: we use a different matrixId for the second matrix of size 3 (we use '3' instead of '1'). |
949 | 34 | for (int matrixId=0 ; matrixId<6 ; matrixId += (sizeId==3 ? 3 : 1)) { |
950 | 34 | uint8_t* curr_scaling_list = scaling_list[matrixId]; |
951 | 34 | int scaling_list_dc_coef; |
952 | | |
953 | | |
954 | | //printf("----- matrix %d\n",matrixId); |
955 | | |
956 | 34 | char scaling_list_pred_mode_flag = br->get_bits(1); |
957 | 34 | if (!scaling_list_pred_mode_flag) { |
958 | 10 | uint32_t scaling_list_pred_matrix_id_delta = br->get_uvlc(); |
959 | | |
960 | 10 | if (scaling_list_pred_matrix_id_delta == UVLC_ERROR) { |
961 | 3 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
962 | 3 | } |
963 | | |
964 | 7 | if (sizeId == 3) { |
965 | | // adapt to our changed matrixId for size 3 |
966 | 0 | scaling_list_pred_matrix_id_delta *= 3; |
967 | 0 | } |
968 | | |
969 | 7 | if (scaling_list_pred_matrix_id_delta > (uint32_t)matrixId) { |
970 | 1 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
971 | 1 | } |
972 | | |
973 | | //printf("scaling_list_pred_matrix_id_delta=%d\n", scaling_list_pred_matrix_id_delta); |
974 | | |
975 | 6 | dc_coeff[sizeId][matrixId] = 16; |
976 | 6 | scaling_list_dc_coef = 16; |
977 | | |
978 | 6 | if (scaling_list_pred_matrix_id_delta==0) { |
979 | 4 | if (sizeId==0) { |
980 | 4 | memcpy(curr_scaling_list, default_ScalingList_4x4, 16); |
981 | 4 | } |
982 | 0 | else { |
983 | 0 | if (matrixId<3) |
984 | 0 | { memcpy(curr_scaling_list, default_ScalingList_8x8_intra,64); } |
985 | 0 | else |
986 | 0 | { memcpy(curr_scaling_list, default_ScalingList_8x8_inter,64); } |
987 | 0 | } |
988 | 4 | } |
989 | 2 | else { |
990 | 2 | if (sizeId==3) { assert(scaling_list_pred_matrix_id_delta==3); } |
991 | | |
992 | 2 | int mID = matrixId - scaling_list_pred_matrix_id_delta; |
993 | | |
994 | 2 | int len = (sizeId == 0 ? 16 : 64); |
995 | 2 | memcpy(curr_scaling_list, scaling_list[mID], len); |
996 | | |
997 | 2 | scaling_list_dc_coef = dc_coeff[sizeId][mID]; |
998 | 2 | dc_coeff[sizeId][matrixId] = dc_coeff[sizeId][mID]; |
999 | 2 | } |
1000 | 6 | } |
1001 | 24 | else { |
1002 | 24 | int nextCoef=8; |
1003 | 24 | int coefNum = (sizeId==0 ? 16 : 64); |
1004 | 24 | if (sizeId>1) { |
1005 | 0 | scaling_list_dc_coef = br->get_svlc(); |
1006 | 0 | if (scaling_list_dc_coef < -7 || |
1007 | 0 | scaling_list_dc_coef > 247) { |
1008 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
1009 | 0 | } |
1010 | | |
1011 | 0 | scaling_list_dc_coef += 8; |
1012 | 0 | nextCoef=scaling_list_dc_coef; |
1013 | 0 | dc_coeff[sizeId][matrixId] = scaling_list_dc_coef; |
1014 | 0 | } |
1015 | 24 | else { |
1016 | 24 | scaling_list_dc_coef = 16; |
1017 | 24 | } |
1018 | | //printf("DC = %d\n",scaling_list_dc_coef); |
1019 | | |
1020 | 201 | for (int i=0;i<coefNum;i++) { |
1021 | 194 | int scaling_list_delta_coef = br->get_svlc(); |
1022 | 194 | if (scaling_list_delta_coef < -128 || |
1023 | 180 | scaling_list_delta_coef > 127) { |
1024 | 17 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
1025 | 17 | } |
1026 | | |
1027 | 177 | nextCoef = (nextCoef + scaling_list_delta_coef + 256) % 256; |
1028 | 177 | curr_scaling_list[i] = nextCoef; |
1029 | | //printf("curr %d = %d\n",i,nextCoef); |
1030 | 177 | } |
1031 | 24 | } |
1032 | | |
1033 | | |
1034 | | // --- generate ScalingFactor arrays --- |
1035 | | |
1036 | 13 | switch (sizeId) { |
1037 | 13 | case 0: |
1038 | 13 | fill_scaling_factor(&sclist->ScalingFactor_Size0[matrixId][0][0], curr_scaling_list, 0); |
1039 | 13 | break; |
1040 | | |
1041 | 0 | case 1: |
1042 | 0 | fill_scaling_factor(&sclist->ScalingFactor_Size1[matrixId][0][0], curr_scaling_list, 1); |
1043 | 0 | break; |
1044 | | |
1045 | 0 | case 2: |
1046 | 0 | fill_scaling_factor(&sclist->ScalingFactor_Size2[matrixId][0][0], curr_scaling_list, 2); |
1047 | 0 | sclist->ScalingFactor_Size2[matrixId][0][0] = scaling_list_dc_coef; |
1048 | | //printf("DC coeff: %d\n", scaling_list_dc_coef); |
1049 | 0 | break; |
1050 | | |
1051 | 0 | case 3: |
1052 | 0 | fill_scaling_factor(&sclist->ScalingFactor_Size3[matrixId][0][0], curr_scaling_list, 3); |
1053 | 0 | sclist->ScalingFactor_Size3[matrixId][0][0] = scaling_list_dc_coef; |
1054 | | //printf("DC coeff: %d\n", scaling_list_dc_coef); |
1055 | 0 | break; |
1056 | 13 | } |
1057 | 13 | } |
1058 | 21 | } |
1059 | | |
1060 | | |
1061 | | // --- fill 32x32 matrices for chroma |
1062 | | |
1063 | 0 | const position* scan = get_scan_order(3, 0 /* diag */); |
1064 | | |
1065 | 0 | for (int matrixId=0;matrixId<6;matrixId++) |
1066 | 0 | if (matrixId!=0 && matrixId!=3) { |
1067 | 0 | for (int i=0;i<64;i++) { |
1068 | 0 | int x = scan[i].x; |
1069 | 0 | int y = scan[i].y; |
1070 | 0 | int v = sclist->ScalingFactor_Size1[matrixId][y][x]; |
1071 | |
|
1072 | 0 | for (int dy=0;dy<4;dy++) |
1073 | 0 | for (int dx=0;dx<4;dx++) { |
1074 | 0 | sclist->ScalingFactor_Size3[matrixId][4*y+dy][4*x+dx] = v; |
1075 | 0 | } |
1076 | 0 | } |
1077 | |
|
1078 | 0 | sclist->ScalingFactor_Size3[matrixId][0][0] = sclist->ScalingFactor_Size1[matrixId][0][0]; |
1079 | 0 | } |
1080 | | |
1081 | 0 | return DE265_OK; |
1082 | 21 | } |
1083 | | |
1084 | | |
1085 | | de265_error write_scaling_list(CABAC_encoder& out, const seq_parameter_set* sps, |
1086 | | scaling_list_data* sclist, bool inPPS) |
1087 | 0 | { |
1088 | 0 | assert(false); |
1089 | | // TODO |
1090 | | |
1091 | 0 | return DE265_OK; |
1092 | 0 | } |
1093 | | |
1094 | | |
1095 | | void set_default_scaling_lists(scaling_list_data* sclist) |
1096 | 40 | { |
1097 | | // 4x4 |
1098 | | |
1099 | 280 | for (int matrixId=0;matrixId<6;matrixId++) { |
1100 | 240 | fill_scaling_factor(&sclist->ScalingFactor_Size0[matrixId][0][0], |
1101 | 240 | default_ScalingList_4x4, 0); |
1102 | 240 | } |
1103 | | |
1104 | | // 8x8 |
1105 | | |
1106 | 160 | for (int matrixId=0;matrixId<3;matrixId++) { |
1107 | 120 | fill_scaling_factor(&sclist->ScalingFactor_Size1[matrixId+0][0][0], |
1108 | 120 | default_ScalingList_8x8_intra, 1); |
1109 | 120 | fill_scaling_factor(&sclist->ScalingFactor_Size1[matrixId+3][0][0], |
1110 | 120 | default_ScalingList_8x8_inter, 1); |
1111 | 120 | } |
1112 | | |
1113 | | // 16x16 |
1114 | | |
1115 | 160 | for (int matrixId=0;matrixId<3;matrixId++) { |
1116 | 120 | fill_scaling_factor(&sclist->ScalingFactor_Size2[matrixId+0][0][0], |
1117 | 120 | default_ScalingList_8x8_intra, 2); |
1118 | 120 | fill_scaling_factor(&sclist->ScalingFactor_Size2[matrixId+3][0][0], |
1119 | 120 | default_ScalingList_8x8_inter, 2); |
1120 | 120 | } |
1121 | | |
1122 | | // 32x32 |
1123 | | |
1124 | 40 | fill_scaling_factor(&sclist->ScalingFactor_Size3[0][0][0], |
1125 | 40 | default_ScalingList_8x8_intra, 3); |
1126 | 40 | fill_scaling_factor(&sclist->ScalingFactor_Size3[1][0][0], |
1127 | 40 | default_ScalingList_8x8_inter, 3); |
1128 | 40 | } |
1129 | | |
1130 | | |
1131 | | de265_error seq_parameter_set::write(error_queue* errqueue, CABAC_encoder& out) |
1132 | 0 | { |
1133 | 0 | out.write_bits(video_parameter_set_id, 4); |
1134 | 0 | if (sps_max_sub_layers>7) { |
1135 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
1136 | 0 | } |
1137 | 0 | out.write_bits(sps_max_sub_layers-1, 3); |
1138 | |
|
1139 | 0 | out.write_bit(sps_temporal_id_nesting_flag); |
1140 | |
|
1141 | 0 | profile_tier_level_.write(out, sps_max_sub_layers); |
1142 | |
|
1143 | 0 | out.write_uvlc(seq_parameter_set_id); |
1144 | | |
1145 | | |
1146 | | // --- encode chroma type --- |
1147 | |
|
1148 | 0 | out.write_uvlc(chroma_format_idc); |
1149 | |
|
1150 | 0 | if (chroma_format_idc>3) { |
1151 | 0 | errqueue->add_warning(DE265_WARNING_INVALID_CHROMA_FORMAT, false); |
1152 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
1153 | 0 | } |
1154 | | |
1155 | 0 | if (chroma_format_idc == 3) { |
1156 | 0 | out.write_bit(separate_colour_plane_flag); |
1157 | 0 | } |
1158 | | |
1159 | | |
1160 | | // --- picture size --- |
1161 | |
|
1162 | 0 | out.write_uvlc(pic_width_in_luma_samples); |
1163 | 0 | out.write_uvlc(pic_height_in_luma_samples); |
1164 | |
|
1165 | 0 | out.write_bit(conformance_window_flag); |
1166 | |
|
1167 | 0 | if (conformance_window_flag) { |
1168 | 0 | out.write_uvlc(conf_win_left_offset); |
1169 | 0 | out.write_uvlc(conf_win_right_offset); |
1170 | 0 | out.write_uvlc(conf_win_top_offset); |
1171 | 0 | out.write_uvlc(conf_win_bottom_offset); |
1172 | 0 | } |
1173 | | |
1174 | |
|
1175 | 0 | out.write_uvlc(bit_depth_luma-8); |
1176 | 0 | out.write_uvlc(bit_depth_chroma-8); |
1177 | |
|
1178 | 0 | out.write_uvlc(log2_max_pic_order_cnt_lsb-4); |
1179 | | |
1180 | | |
1181 | | // --- sub_layer_ordering_info --- |
1182 | |
|
1183 | 0 | out.write_bit(sps_sub_layer_ordering_info_present_flag); |
1184 | |
|
1185 | 0 | int firstLayer = (sps_sub_layer_ordering_info_present_flag ? |
1186 | 0 | 0 : sps_max_sub_layers-1 ); |
1187 | |
|
1188 | 0 | for (int i=firstLayer ; i <= sps_max_sub_layers-1; i++ ) { |
1189 | | |
1190 | | // sps_max_dec_pic_buffering[i] |
1191 | |
|
1192 | 0 | if (sps_max_dec_pic_buffering[i] > MAX_NUM_REF_PICS) { |
1193 | 0 | errqueue->add_warning(DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE, false); |
1194 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
1195 | 0 | } |
1196 | | |
1197 | 0 | out.write_uvlc(sps_max_dec_pic_buffering[i]-1); |
1198 | | |
1199 | | // sps_max_num_reorder_pics[i] |
1200 | |
|
1201 | 0 | out.write_uvlc(sps_max_num_reorder_pics[i]); |
1202 | | |
1203 | | |
1204 | | // sps_max_latency_increase[i] |
1205 | |
|
1206 | 0 | out.write_uvlc(sps_max_latency_increase_plus1[i]); |
1207 | 0 | } |
1208 | | |
1209 | | |
1210 | 0 | out.write_uvlc(log2_min_luma_coding_block_size-3); |
1211 | 0 | out.write_uvlc(log2_diff_max_min_luma_coding_block_size); |
1212 | 0 | out.write_uvlc(log2_min_transform_block_size-2); |
1213 | 0 | out.write_uvlc(log2_diff_max_min_transform_block_size); |
1214 | 0 | out.write_uvlc(max_transform_hierarchy_depth_inter); |
1215 | 0 | out.write_uvlc(max_transform_hierarchy_depth_intra); |
1216 | 0 | out.write_bit(scaling_list_enable_flag); |
1217 | |
|
1218 | 0 | if (scaling_list_enable_flag) { |
1219 | |
|
1220 | 0 | out.write_bit(sps_scaling_list_data_present_flag); |
1221 | 0 | if (sps_scaling_list_data_present_flag) { |
1222 | |
|
1223 | 0 | de265_error err; |
1224 | 0 | if ((err=write_scaling_list(out,this, &scaling_list, false)) != DE265_OK) { |
1225 | 0 | return err; |
1226 | 0 | } |
1227 | 0 | } |
1228 | 0 | } |
1229 | | |
1230 | 0 | out.write_bit(amp_enabled_flag); |
1231 | 0 | out.write_bit(sample_adaptive_offset_enabled_flag); |
1232 | 0 | out.write_bit(pcm_enabled_flag); |
1233 | 0 | if (pcm_enabled_flag) { |
1234 | 0 | out.write_bits(pcm_sample_bit_depth_luma -1,4); |
1235 | 0 | out.write_bits(pcm_sample_bit_depth_chroma-1,4); |
1236 | 0 | out.write_uvlc(log2_min_pcm_luma_coding_block_size-3); |
1237 | 0 | out.write_uvlc(log2_diff_max_min_pcm_luma_coding_block_size); |
1238 | 0 | out.write_bit(pcm_loop_filter_disable_flag); |
1239 | 0 | } |
1240 | |
|
1241 | 0 | int num_short_term_ref_pic_sets = ref_pic_sets.size(); |
1242 | 0 | if (num_short_term_ref_pic_sets < 0 || |
1243 | 0 | num_short_term_ref_pic_sets > 64) { |
1244 | 0 | errqueue->add_warning(DE265_WARNING_NUMBER_OF_SHORT_TERM_REF_PIC_SETS_OUT_OF_RANGE, false); |
1245 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
1246 | 0 | } |
1247 | 0 | out.write_uvlc(num_short_term_ref_pic_sets); |
1248 | | |
1249 | | // --- allocate reference pic set --- |
1250 | | |
1251 | | // we do not allocate the ref-pic-set for the slice header here, but in the slice header itself |
1252 | |
|
1253 | 0 | for (int i = 0; i < num_short_term_ref_pic_sets; i++) { |
1254 | |
|
1255 | 0 | bool success = write_short_term_ref_pic_set(errqueue,this,out, |
1256 | 0 | &ref_pic_sets[i], i, |
1257 | 0 | ref_pic_sets, |
1258 | 0 | false); |
1259 | |
|
1260 | 0 | if (!success) { |
1261 | 0 | return DE265_WARNING_SPS_HEADER_INVALID; |
1262 | 0 | } |
1263 | | |
1264 | | // dump_short_term_ref_pic_set(&(*ref_pic_sets)[i], fh); |
1265 | 0 | } |
1266 | | |
1267 | 0 | out.write_bit(long_term_ref_pics_present_flag); |
1268 | |
|
1269 | 0 | if (long_term_ref_pics_present_flag) { |
1270 | |
|
1271 | 0 | if (num_long_term_ref_pics_sps > MAX_NUM_LT_REF_PICS_SPS) { |
1272 | 0 | return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; |
1273 | 0 | } |
1274 | 0 | out.write_uvlc(num_long_term_ref_pics_sps); |
1275 | |
|
1276 | 0 | for (int i = 0; i < num_long_term_ref_pics_sps; i++ ) { |
1277 | 0 | out.write_bits(lt_ref_pic_poc_lsb_sps[i], log2_max_pic_order_cnt_lsb); |
1278 | 0 | out.write_bit (used_by_curr_pic_lt_sps_flag[i]); |
1279 | 0 | } |
1280 | 0 | } |
1281 | | |
1282 | 0 | out.write_bit(sps_temporal_mvp_enabled_flag); |
1283 | 0 | out.write_bit(strong_intra_smoothing_enable_flag); |
1284 | 0 | out.write_bit(vui_parameters_present_flag); |
1285 | |
|
1286 | | #if 0 |
1287 | | if (vui_parameters_present_flag) { |
1288 | | assert(false); |
1289 | | /* |
1290 | | vui_parameters() |
1291 | | sps_extension_flag |
1292 | | u(1) |
1293 | | if( sps_extension_flag ) |
1294 | | while( more_rbsp_data() ) |
1295 | | sps_extension_data_flag |
1296 | | u(1) |
1297 | | rbsp_trailing_bits() |
1298 | | */ |
1299 | | } |
1300 | | #endif |
1301 | |
|
1302 | 0 | out.write_bit(sps_extension_present_flag); |
1303 | |
|
1304 | | #if 0 |
1305 | | if (sps_extension_flag) { |
1306 | | assert(false); |
1307 | | } |
1308 | | br->check_rbsp_trailing_bits(); |
1309 | | #endif |
1310 | | |
1311 | | // --- compute derived values --- |
1312 | |
|
1313 | | #if 0 |
1314 | | BitDepth_Y = bit_depth_luma; |
1315 | | QpBdOffset_Y = 6*(bit_depth_luma-8); |
1316 | | BitDepth_C = bit_depth_chroma; |
1317 | | QpBdOffset_C = 6*(bit_depth_chroma-8); |
1318 | | Log2MinCbSizeY = log2_min_luma_coding_block_size; |
1319 | | Log2CtbSizeY = Log2MinCbSizeY + log2_diff_max_min_luma_coding_block_size; |
1320 | | MinCbSizeY = 1 << Log2MinCbSizeY; |
1321 | | CtbSizeY = 1 << Log2CtbSizeY; |
1322 | | PicWidthInMinCbsY = pic_width_in_luma_samples / MinCbSizeY; |
1323 | | PicWidthInCtbsY = ceil_div(pic_width_in_luma_samples, CtbSizeY); |
1324 | | PicHeightInMinCbsY = pic_height_in_luma_samples / MinCbSizeY; |
1325 | | PicHeightInCtbsY = ceil_div(pic_height_in_luma_samples,CtbSizeY); |
1326 | | PicSizeInMinCbsY = PicWidthInMinCbsY * PicHeightInMinCbsY; |
1327 | | PicSizeInCtbsY = PicWidthInCtbsY * PicHeightInCtbsY; |
1328 | | PicSizeInSamplesY = static_cast<uint32_t>(pic_width_in_luma_samples) * pic_height_in_luma_samples; |
1329 | | if (chroma_format_idc==0 || separate_colour_plane_flag) { |
1330 | | CtbWidthC = 0; |
1331 | | CtbHeightC = 0; |
1332 | | } |
1333 | | else { |
1334 | | CtbWidthC = CtbSizeY / SubWidthC; |
1335 | | CtbHeightC = CtbSizeY / SubHeightC; |
1336 | | } |
1337 | | Log2MinTrafoSize = log2_min_transform_block_size; |
1338 | | Log2MaxTrafoSize = log2_min_transform_block_size + log2_diff_max_min_transform_block_size; |
1339 | | assert(Log2MaxTrafoSize >= 2); // log2_min_transform_block_size >= 2 by spec; relied on by pps.cc |
1340 | | Log2MinPUSize = Log2MinCbSizeY-1; |
1341 | | PicWidthInMinPUs = PicWidthInCtbsY << (Log2CtbSizeY - Log2MinPUSize); |
1342 | | PicHeightInMinPUs = PicHeightInCtbsY << (Log2CtbSizeY - Log2MinPUSize); |
1343 | | Log2MinIpcmCbSizeY = log2_min_pcm_luma_coding_block_size; |
1344 | | Log2MaxIpcmCbSizeY = (log2_min_pcm_luma_coding_block_size + |
1345 | | log2_diff_max_min_pcm_luma_coding_block_size); |
1346 | | // the following are not in the standard |
1347 | | PicWidthInTbsY = PicWidthInCtbsY << (Log2CtbSizeY - Log2MinTrafoSize); |
1348 | | PicHeightInTbsY = PicHeightInCtbsY << (Log2CtbSizeY - Log2MinTrafoSize); |
1349 | | PicSizeInTbsY = PicWidthInTbsY * PicHeightInTbsY; |
1350 | | sps_read = true; |
1351 | | #endif |
1352 | |
|
1353 | 0 | return DE265_OK; |
1354 | 0 | } |
1355 | | |
1356 | | |
1357 | | de265_error sps_range_extension::read(error_queue* errqueue, bitreader* br) |
1358 | 1 | { |
1359 | 1 | transform_skip_rotation_enabled_flag = br->get_bits(1); |
1360 | 1 | transform_skip_context_enabled_flag = br->get_bits(1); |
1361 | 1 | implicit_rdpcm_enabled_flag = br->get_bits(1); |
1362 | 1 | explicit_rdpcm_enabled_flag = br->get_bits(1); |
1363 | 1 | extended_precision_processing_flag = br->get_bits(1); |
1364 | 1 | intra_smoothing_disabled_flag = br->get_bits(1); |
1365 | 1 | high_precision_offsets_enabled_flag = br->get_bits(1); |
1366 | 1 | persistent_rice_adaptation_enabled_flag = br->get_bits(1); |
1367 | 1 | cabac_bypass_alignment_enabled_flag = br->get_bits(1); |
1368 | | |
1369 | 1 | return DE265_OK; |
1370 | 1 | } |
1371 | | |
1372 | | |
1373 | 0 | #define LOG0(t) log2fh(fh, t) |
1374 | 0 | #define LOG1(t,d) log2fh(fh, t,d) |
1375 | | void sps_range_extension::dump(int fd) const |
1376 | 0 | { |
1377 | 0 | FILE* fh; |
1378 | 0 | if (fd==1) fh=stdout; |
1379 | 0 | else if (fd==2) fh=stderr; |
1380 | 0 | else { return; } |
1381 | | |
1382 | 0 | LOG0("----------------- SPS-range-extension -----------------\n"); |
1383 | 0 | LOG1("transform_skip_rotation_enabled_flag : %d\n", transform_skip_rotation_enabled_flag); |
1384 | 0 | LOG1("transform_skip_context_enabled_flag : %d\n", transform_skip_context_enabled_flag); |
1385 | 0 | LOG1("implicit_rdpcm_enabled_flag : %d\n", implicit_rdpcm_enabled_flag); |
1386 | 0 | LOG1("explicit_rdpcm_enabled_flag : %d\n", explicit_rdpcm_enabled_flag); |
1387 | 0 | LOG1("extended_precision_processing_flag : %d\n", extended_precision_processing_flag); |
1388 | 0 | LOG1("intra_smoothing_disabled_flag : %d\n", intra_smoothing_disabled_flag); |
1389 | 0 | LOG1("high_precision_offsets_enabled_flag : %d\n", high_precision_offsets_enabled_flag); |
1390 | 0 | LOG1("persistent_rice_adaptation_enabled_flag : %d\n", persistent_rice_adaptation_enabled_flag); |
1391 | 0 | LOG1("cabac_bypass_alignment_enabled_flag : %d\n", cabac_bypass_alignment_enabled_flag); |
1392 | 0 | } |
1393 | | #undef LOG1 |
1394 | | #undef LOG0 |