/src/libhevc/encoder/ihevce_encode_header_sei_vui.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2018 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | |
21 | | /** |
22 | | ****************************************************************************** |
23 | | * @file ihevce_encode_header_sei_vui.c |
24 | | * |
25 | | * @brief |
26 | | * This file contains function definitions related to header vui/sei encoding |
27 | | * |
28 | | * @author |
29 | | * ittiam |
30 | | * |
31 | | * List of Functions |
32 | | * ihevce_generate_sub_layer_hrd_params() |
33 | | * ihevce_generate_hrd_params() |
34 | | * ihevce_generate_vui() |
35 | | * ihevce_put_buf_period_sei_params() |
36 | | * ihevce_put_active_parameter_set_sei_params() |
37 | | * ihevce_put_mastering_disp_col_vol_sei_params() |
38 | | * ihevce_put_mastering_disp_col_vol_sei_params() |
39 | | * ihevce_put_sei_params() |
40 | | * ihevce_put_cll_info_sei_params() |
41 | | * ihevce_put_recovery_point_sei_params() |
42 | | * ihevce_put_pic_timing_sei_params() |
43 | | * ihevce_put_hash_sei_params() |
44 | | * ihevce_put_sei_msg() |
45 | | * ihevce_generate_sei() |
46 | | * ihevce_populate_mastering_disp_col_vol_sei() |
47 | | * ihevce_populate_recovery_point_sei() |
48 | | * ihevce_populate_picture_timing_sei() |
49 | | * ihevce_populate_buffering_period_sei() |
50 | | * ihevce_populate_active_parameter_set_sei() |
51 | | * ihevce_calc_CRC() |
52 | | * ihevce_calc_checksum() |
53 | | * ihevce_populate_hash_sei() |
54 | | * ihevce_populate_vui() |
55 | | * |
56 | | ****************************************************************************** |
57 | | */ |
58 | | |
59 | | /*****************************************************************************/ |
60 | | /* File Includes */ |
61 | | /*****************************************************************************/ |
62 | | /* System include files */ |
63 | | #include <stdio.h> |
64 | | #include <string.h> |
65 | | #include <stdlib.h> |
66 | | #include <assert.h> |
67 | | #include <stdarg.h> |
68 | | #include <math.h> |
69 | | |
70 | | /* User include files */ |
71 | | #include "ihevc_typedefs.h" |
72 | | #include "itt_video_api.h" |
73 | | #include "ihevce_api.h" |
74 | | |
75 | | #include "rc_cntrl_param.h" |
76 | | #include "rc_frame_info_collector.h" |
77 | | #include "rc_look_ahead_params.h" |
78 | | |
79 | | #include "ihevc_defs.h" |
80 | | #include "ihevc_macros.h" |
81 | | #include "ihevc_debug.h" |
82 | | #include "ihevc_structs.h" |
83 | | #include "ihevc_platform_macros.h" |
84 | | #include "ihevc_deblk.h" |
85 | | #include "ihevc_itrans_recon.h" |
86 | | #include "ihevc_chroma_itrans_recon.h" |
87 | | #include "ihevc_chroma_intra_pred.h" |
88 | | #include "ihevc_intra_pred.h" |
89 | | #include "ihevc_inter_pred.h" |
90 | | #include "ihevc_mem_fns.h" |
91 | | #include "ihevc_padding.h" |
92 | | #include "ihevc_weighted_pred.h" |
93 | | #include "ihevc_sao.h" |
94 | | #include "ihevc_resi_trans.h" |
95 | | #include "ihevc_quant_iquant_ssd.h" |
96 | | #include "ihevc_cabac_tables.h" |
97 | | #include "ihevc_trans_tables.h" |
98 | | #include "ihevc_trans_macros.h" |
99 | | |
100 | | #include "ihevce_defs.h" |
101 | | #include "ihevce_lap_enc_structs.h" |
102 | | #include "ihevce_multi_thrd_structs.h" |
103 | | #include "ihevce_multi_thrd_funcs.h" |
104 | | #include "ihevce_me_common_defs.h" |
105 | | #include "ihevce_had_satd.h" |
106 | | #include "ihevce_error_codes.h" |
107 | | #include "ihevce_error_checks.h" |
108 | | #include "ihevce_bitstream.h" |
109 | | #include "ihevce_cabac.h" |
110 | | #include "ihevce_rdoq_macros.h" |
111 | | #include "ihevce_function_selector.h" |
112 | | #include "ihevce_enc_structs.h" |
113 | | #include "ihevce_global_tables.h" |
114 | | #include "ihevce_encode_header.h" |
115 | | #include "ihevce_encode_header_sei_vui.h" |
116 | | #include "ihevce_trace.h" |
117 | | |
118 | | /*****************************************************************************/ |
119 | | /* Function Definitions */ |
120 | | /*****************************************************************************/ |
121 | | |
122 | | /** |
123 | | ****************************************************************************** |
124 | | * |
125 | | * @brief Generates sub-layer hrd parameters of VUI (Video Usability Info Set) |
126 | | * |
127 | | * @par Description |
128 | | * Parse Video Usability Info as per ANNEX E.2 |
129 | | * |
130 | | * @param[in] ps_bitstrm |
131 | | * pointer to bitstream context (handle) |
132 | | * |
133 | | * @param[in] ps_hrd_params |
134 | | * pointer to structure containing sub-layer hrd params of VUI data |
135 | | * |
136 | | * @return success or failure error code |
137 | | * |
138 | | ****************************************************************************** |
139 | | */ |
140 | | WORD32 ihevce_generate_sub_layer_hrd_params( |
141 | | bitstrm_t *ps_bitstrm, |
142 | | sub_lyr_hrd_params_t *ps_sub_lyr_hrd_params, |
143 | | hrd_params_t *ps_hrd_params, |
144 | | WORD32 cpb_cnt_minus1) |
145 | 0 | { |
146 | 0 | WORD32 j; |
147 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
148 | |
|
149 | 0 | for(j = 0; j <= cpb_cnt_minus1; j++) |
150 | 0 | { |
151 | | /* au4_bit_rate_value_minus1 */ |
152 | 0 | PUT_BITS_UEV( |
153 | 0 | ps_bitstrm, ps_sub_lyr_hrd_params->au4_bit_rate_value_minus1[j], return_status); |
154 | 0 | ENTROPY_TRACE("bit_rate_value_minus1", ps_sub_lyr_hrd_params->au4_bit_rate_value_minus1[j]); |
155 | | |
156 | | /* au4_cpb_size_value_minus1 */ |
157 | 0 | PUT_BITS_UEV( |
158 | 0 | ps_bitstrm, ps_sub_lyr_hrd_params->au4_cpb_size_value_minus1[j], return_status); |
159 | 0 | ENTROPY_TRACE("cpb_size_value_minus1", ps_sub_lyr_hrd_params->au4_cpb_size_value_minus1[j]); |
160 | |
|
161 | 0 | if(ps_hrd_params->u1_sub_pic_cpb_params_present_flag) |
162 | 0 | { |
163 | | /* au4_cpb_size_du_value_minus1 */ |
164 | 0 | PUT_BITS_UEV( |
165 | 0 | ps_bitstrm, ps_sub_lyr_hrd_params->au4_cpb_size_du_value_minus1[j], return_status); |
166 | 0 | ENTROPY_TRACE( |
167 | 0 | "cpb_size_du_value_minus1", ps_sub_lyr_hrd_params->au4_cpb_size_du_value_minus1[j]); |
168 | | |
169 | | /* au4_bit_rate_du_value_minus1 */ |
170 | 0 | PUT_BITS_UEV( |
171 | 0 | ps_bitstrm, ps_sub_lyr_hrd_params->au4_bit_rate_du_value_minus1[j], return_status); |
172 | 0 | ENTROPY_TRACE( |
173 | 0 | "bit_rate_du_value_minus1", ps_sub_lyr_hrd_params->au4_bit_rate_du_value_minus1[j]); |
174 | 0 | } |
175 | | |
176 | | /* au1_cbr_flag */ |
177 | 0 | PUT_BITS(ps_bitstrm, ps_sub_lyr_hrd_params->au1_cbr_flag[j], 1, return_status); |
178 | 0 | ENTROPY_TRACE("cbr_flag", ps_sub_lyr_hrd_params->au1_cbr_flag[j]); |
179 | 0 | } |
180 | 0 | return return_status; |
181 | 0 | } |
182 | | |
183 | | /** |
184 | | ****************************************************************************** |
185 | | * |
186 | | * @brief Generates hrd parameters of VUI (Video Usability Info Set) |
187 | | * |
188 | | * @par Description |
189 | | * Parse Video Usability Info as per ANNEX E.2 |
190 | | * |
191 | | * @param[in] ps_bitstrm |
192 | | * pointer to bitstream context (handle) |
193 | | * |
194 | | * @param[in] ps_sps |
195 | | * pointer to structure containing SPS data |
196 | | * |
197 | | * @param[in] ps_hrd_params |
198 | | * pointer to structure containing hrd params of VUI data |
199 | | * |
200 | | * @return success or failure error code |
201 | | * |
202 | | ****************************************************************************** |
203 | | */ |
204 | | WORD32 ihevce_generate_hrd_params(bitstrm_t *ps_bitstrm, hrd_params_t *ps_hrd_params, sps_t *ps_sps) |
205 | 0 | { |
206 | 0 | WORD32 i; |
207 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
208 | 0 | UWORD8 u1_common_info_present_flag = 1; |
209 | |
|
210 | 0 | if(u1_common_info_present_flag) |
211 | 0 | { |
212 | | /* u1_nal_hrd_parameters_present_flag */ |
213 | 0 | PUT_BITS(ps_bitstrm, ps_hrd_params->u1_nal_hrd_parameters_present_flag, 1, return_status); |
214 | 0 | ENTROPY_TRACE( |
215 | 0 | "nal_hrd_parameters_present_flag", ps_hrd_params->u1_nal_hrd_parameters_present_flag); |
216 | | |
217 | | /* u1_vcl_hrd_parameters_present_flag */ |
218 | 0 | PUT_BITS(ps_bitstrm, ps_hrd_params->u1_vcl_hrd_parameters_present_flag, 1, return_status); |
219 | 0 | ENTROPY_TRACE( |
220 | 0 | "vcl_hrd_parameters_present_flag", ps_hrd_params->u1_vcl_hrd_parameters_present_flag); |
221 | |
|
222 | 0 | if(ps_hrd_params->u1_vcl_hrd_parameters_present_flag || |
223 | 0 | ps_hrd_params->u1_nal_hrd_parameters_present_flag) |
224 | 0 | { |
225 | | /* u1_sub_pic_cpb_params_present_flag */ |
226 | 0 | PUT_BITS( |
227 | 0 | ps_bitstrm, ps_hrd_params->u1_sub_pic_cpb_params_present_flag, 1, return_status); |
228 | 0 | ENTROPY_TRACE( |
229 | 0 | "sub_pic_Cpb_params_present_flag", |
230 | 0 | ps_hrd_params->u1_sub_pic_cpb_params_present_flag); |
231 | |
|
232 | 0 | if(ps_hrd_params->u1_sub_pic_cpb_params_present_flag) |
233 | 0 | { |
234 | | /* u1_tick_divisor_minus2 */ |
235 | 0 | PUT_BITS(ps_bitstrm, ps_hrd_params->u1_tick_divisor_minus2, 8, return_status); |
236 | 0 | ENTROPY_TRACE("tick_divisor_minus2", ps_hrd_params->u1_tick_divisor_minus2); |
237 | | |
238 | | /* u1_du_cpb_removal_delay_increment_length_minus1 */ |
239 | 0 | PUT_BITS( |
240 | 0 | ps_bitstrm, |
241 | 0 | ps_hrd_params->u1_du_cpb_removal_delay_increment_length_minus1, |
242 | 0 | 5, |
243 | 0 | return_status); |
244 | 0 | ENTROPY_TRACE( |
245 | 0 | "du_cpb_removal_delay_increment_length_minus1", |
246 | 0 | ps_hrd_params->u1_du_cpb_removal_delay_increment_length_minus1); |
247 | | |
248 | | /* u1_sub_pic_cpb_params_in_pic_timing_sei_flag */ |
249 | 0 | PUT_BITS( |
250 | 0 | ps_bitstrm, |
251 | 0 | ps_hrd_params->u1_sub_pic_cpb_params_in_pic_timing_sei_flag, |
252 | 0 | 1, |
253 | 0 | return_status); |
254 | 0 | ENTROPY_TRACE( |
255 | 0 | "sub_pic_cpb_params_in_pic_timing_sei_flag", |
256 | 0 | ps_hrd_params->u1_sub_pic_cpb_params_in_pic_timing_sei_flag); |
257 | | |
258 | | /* u1_dpb_output_delay_du_length_minus1 */ |
259 | 0 | PUT_BITS( |
260 | 0 | ps_bitstrm, |
261 | 0 | ps_hrd_params->u1_dpb_output_delay_du_length_minus1, |
262 | 0 | 5, |
263 | 0 | return_status); |
264 | 0 | ENTROPY_TRACE( |
265 | 0 | "dpb_output_delay_du_length_minus1", |
266 | 0 | ps_hrd_params->u1_dpb_output_delay_du_length_minus1); |
267 | 0 | } |
268 | | |
269 | | /* u4_bit_rate_scale */ |
270 | 0 | PUT_BITS(ps_bitstrm, ps_hrd_params->u4_bit_rate_scale, 4, return_status); |
271 | 0 | ENTROPY_TRACE("bit_rate_scale", ps_hrd_params->u4_bit_rate_scale); |
272 | | |
273 | | /* u4_cpb_size_scale */ |
274 | 0 | PUT_BITS(ps_bitstrm, ps_hrd_params->u4_cpb_size_scale, 4, return_status); |
275 | 0 | ENTROPY_TRACE("cpb_size_scale", ps_hrd_params->u4_cpb_size_scale); |
276 | |
|
277 | 0 | if(ps_hrd_params->u1_sub_pic_cpb_params_present_flag) |
278 | 0 | { |
279 | | /* u4_cpb_size_du_scale */ |
280 | 0 | PUT_BITS(ps_bitstrm, ps_hrd_params->u4_cpb_size_du_scale, 4, return_status); |
281 | 0 | ENTROPY_TRACE("cpb_size_du_scale", ps_hrd_params->u4_cpb_size_du_scale); |
282 | 0 | } |
283 | | |
284 | | /* u1_initial_cpb_removal_delay_length_minus1 */ |
285 | 0 | PUT_BITS( |
286 | 0 | ps_bitstrm, |
287 | 0 | ps_hrd_params->u1_initial_cpb_removal_delay_length_minus1, |
288 | 0 | 5, |
289 | 0 | return_status); |
290 | 0 | ENTROPY_TRACE( |
291 | 0 | "initial_cpb_removal_delay_length_minus1", |
292 | 0 | ps_hrd_params->u1_initial_cpb_removal_delay_length_minus1); |
293 | | |
294 | | /* u1_au_cpb_removal_delay_length_minus1 */ |
295 | 0 | PUT_BITS( |
296 | 0 | ps_bitstrm, ps_hrd_params->u1_au_cpb_removal_delay_length_minus1, 5, return_status); |
297 | 0 | ENTROPY_TRACE( |
298 | 0 | "cpb_removal_delay_length_minus1", |
299 | 0 | ps_hrd_params->u1_au_cpb_removal_delay_length_minus1); |
300 | | |
301 | | /* u1_dpb_output_delay_length_minus1 */ |
302 | 0 | PUT_BITS( |
303 | 0 | ps_bitstrm, ps_hrd_params->u1_dpb_output_delay_length_minus1, 5, return_status); |
304 | 0 | ENTROPY_TRACE( |
305 | 0 | "dpb_output_delay_length_minus1", ps_hrd_params->u1_dpb_output_delay_length_minus1); |
306 | 0 | } |
307 | 0 | } |
308 | |
|
309 | 0 | for(i = 0; i < (ps_sps->i1_sps_max_sub_layers); i++) |
310 | 0 | { |
311 | | /* au1_fixed_pic_rate_general_flag */ |
312 | 0 | PUT_BITS(ps_bitstrm, ps_hrd_params->au1_fixed_pic_rate_general_flag[i], 1, return_status); |
313 | 0 | ENTROPY_TRACE( |
314 | 0 | "fixed_pic_rate_general_flag", ps_hrd_params->au1_fixed_pic_rate_general_flag[i]); |
315 | |
|
316 | 0 | if(!ps_hrd_params->au1_fixed_pic_rate_general_flag[i]) |
317 | 0 | { |
318 | | /* au1_fixed_pic_rate_within_cvs_flag */ |
319 | 0 | PUT_BITS( |
320 | 0 | ps_bitstrm, ps_hrd_params->au1_fixed_pic_rate_within_cvs_flag[i], 1, return_status); |
321 | 0 | ENTROPY_TRACE( |
322 | 0 | "fixed_pic_rate_within_cvs_flag", |
323 | 0 | ps_hrd_params->au1_fixed_pic_rate_within_cvs_flag[i]); |
324 | 0 | } |
325 | |
|
326 | 0 | if(ps_hrd_params->au1_fixed_pic_rate_within_cvs_flag[i]) |
327 | 0 | { |
328 | | /* au2_elemental_duration_in_tc_minus1 */ |
329 | 0 | PUT_BITS_UEV( |
330 | 0 | ps_bitstrm, ps_hrd_params->au2_elemental_duration_in_tc_minus1[i], return_status); |
331 | 0 | ENTROPY_TRACE( |
332 | 0 | "elemental_duration_in_tc_minus1", |
333 | 0 | ps_hrd_params->au2_elemental_duration_in_tc_minus1[i]); |
334 | 0 | } |
335 | 0 | else |
336 | 0 | { |
337 | | /* au1_low_delay_hrd_flag */ |
338 | 0 | PUT_BITS(ps_bitstrm, ps_hrd_params->au1_low_delay_hrd_flag[i], 1, return_status); |
339 | 0 | ENTROPY_TRACE("low_delay_hrd_flag", ps_hrd_params->au1_low_delay_hrd_flag[i]); |
340 | 0 | } |
341 | |
|
342 | 0 | if(!ps_hrd_params->au1_low_delay_hrd_flag[i]) |
343 | 0 | { |
344 | | /* au1_cpb_cnt_minus1 */ |
345 | 0 | PUT_BITS_UEV(ps_bitstrm, ps_hrd_params->au1_cpb_cnt_minus1[i], return_status); |
346 | 0 | ENTROPY_TRACE("cpb_cnt_minus1", ps_hrd_params->au1_cpb_cnt_minus1[i]); |
347 | 0 | } |
348 | |
|
349 | 0 | if(ps_hrd_params->u1_nal_hrd_parameters_present_flag) |
350 | 0 | { |
351 | 0 | sub_lyr_hrd_params_t *ps_sub_lyr_hrd_params = |
352 | 0 | &ps_hrd_params->as_sub_layer_hrd_params[i]; |
353 | 0 | return_status |= ihevce_generate_sub_layer_hrd_params( |
354 | 0 | ps_bitstrm, |
355 | 0 | ps_sub_lyr_hrd_params, |
356 | 0 | ps_hrd_params, |
357 | 0 | ps_hrd_params->au1_cpb_cnt_minus1[i]); |
358 | 0 | } |
359 | |
|
360 | 0 | if(ps_hrd_params->u1_vcl_hrd_parameters_present_flag) |
361 | 0 | { |
362 | 0 | sub_lyr_hrd_params_t *ps_sub_lyr_hrd_params = |
363 | 0 | &ps_hrd_params->as_sub_layer_hrd_params[i]; |
364 | 0 | return_status |= ihevce_generate_sub_layer_hrd_params( |
365 | 0 | ps_bitstrm, |
366 | 0 | ps_sub_lyr_hrd_params, |
367 | 0 | ps_hrd_params, |
368 | 0 | ps_hrd_params->au1_cpb_cnt_minus1[i]); |
369 | 0 | } |
370 | 0 | } |
371 | |
|
372 | 0 | return return_status; |
373 | 0 | } |
374 | | |
375 | | /** |
376 | | ****************************************************************************** |
377 | | * |
378 | | * @brief Generates VUI (Video Usability Info Set) |
379 | | * |
380 | | * @par Description |
381 | | * Parse Video Usability Info as per ANNEX E.2 |
382 | | * |
383 | | * @param[in] ps_bitstrm |
384 | | * pointer to bitstream context (handle) |
385 | | * |
386 | | * @param[in] ps_sps |
387 | | * pointer to structure containing SPS data |
388 | | * |
389 | | * @param[in] ps_vui |
390 | | * pointer to structure containing VUI data |
391 | | * |
392 | | * @return success or failure error code |
393 | | * |
394 | | ****************************************************************************** |
395 | | */ |
396 | | WORD32 ihevce_generate_vui(bitstrm_t *ps_bitstrm, sps_t *ps_sps, vui_t s_vui) |
397 | 13.8k | { |
398 | 13.8k | WORD32 return_status = IHEVCE_SUCCESS; |
399 | | |
400 | | /* aspect_ratio_info_present_flag */ |
401 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_aspect_ratio_info_present_flag, 1, return_status); |
402 | 13.8k | ENTROPY_TRACE("aspect_ratio_info_present_flag", s_vui.u1_aspect_ratio_info_present_flag); |
403 | | |
404 | 13.8k | if(s_vui.u1_aspect_ratio_info_present_flag) |
405 | 0 | { |
406 | | /* aspect_ratio_idc */ |
407 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_aspect_ratio_idc, 8, return_status); |
408 | 0 | ENTROPY_TRACE("aspect_ratio_idc", s_vui.u1_aspect_ratio_idc); |
409 | 0 | if(s_vui.u1_aspect_ratio_idc == IHEVCE_EXTENDED_SAR) |
410 | 0 | { |
411 | | /* SAR_width */ |
412 | 0 | PUT_BITS(ps_bitstrm, s_vui.u2_sar_width, 16, return_status); |
413 | 0 | ENTROPY_TRACE("sar_width", s_vui.u2_sar_width); |
414 | | |
415 | | /* SAR_hieght */ |
416 | 0 | PUT_BITS(ps_bitstrm, s_vui.u2_sar_height, 16, return_status); |
417 | 0 | ENTROPY_TRACE("sar_height", s_vui.u2_sar_height); |
418 | 0 | } |
419 | 0 | } |
420 | | |
421 | | /* overscan_info_present_flag */ |
422 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_overscan_info_present_flag, 1, return_status); |
423 | 13.8k | ENTROPY_TRACE("overscan_info_present_flag", s_vui.u1_overscan_info_present_flag); |
424 | | |
425 | 13.8k | if(s_vui.u1_overscan_info_present_flag) |
426 | 0 | { |
427 | | /* u1_overscan_appropriate_flag */ |
428 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_overscan_appropriate_flag, 1, return_status); |
429 | 0 | ENTROPY_TRACE("overscan_appropriate_flag", s_vui.u1_overscan_appropriate_flag); |
430 | 0 | } |
431 | | |
432 | | /* video_signal_type_present_flag */ |
433 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_video_signal_type_present_flag, 1, return_status); |
434 | 13.8k | ENTROPY_TRACE("video_signal_type_present_flag", s_vui.u1_video_signal_type_present_flag); |
435 | | |
436 | 13.8k | if(s_vui.u1_video_signal_type_present_flag) |
437 | 13.8k | { |
438 | | /* u1_video_format */ |
439 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_video_format, 3, return_status); |
440 | 13.8k | ENTROPY_TRACE("video_format", s_vui.u1_video_format); |
441 | | |
442 | | /* u1_video_full_range_flag */ |
443 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_video_full_range_flag, 1, return_status); |
444 | 13.8k | ENTROPY_TRACE("video_full_range_flag", s_vui.u1_video_full_range_flag); |
445 | | |
446 | | /* u1_colour_description_present_flag */ |
447 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_colour_description_present_flag, 1, return_status); |
448 | 13.8k | ENTROPY_TRACE("colour_description_present_flag", s_vui.u1_colour_description_present_flag); |
449 | | |
450 | 13.8k | if(s_vui.u1_colour_description_present_flag) |
451 | 0 | { |
452 | | /* u1_colour_primaries */ |
453 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_colour_primaries, 8, return_status); |
454 | 0 | ENTROPY_TRACE("colour_primaries", s_vui.u1_colour_primaries); |
455 | | |
456 | | /* u1_transfer_characteristics */ |
457 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_transfer_characteristics, 8, return_status); |
458 | 0 | ENTROPY_TRACE("transfer_characteristics", s_vui.u1_transfer_characteristics); |
459 | | |
460 | | /* u1_matrix_coefficients */ |
461 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_matrix_coefficients, 8, return_status); |
462 | 0 | ENTROPY_TRACE("matrix_coefficients", s_vui.u1_matrix_coefficients); |
463 | 0 | } |
464 | 13.8k | } |
465 | | |
466 | | /* u1_chroma_loc_info_present_flag */ |
467 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_chroma_loc_info_present_flag, 1, return_status); |
468 | 13.8k | ENTROPY_TRACE("chroma_loc_info_present_flag", s_vui.u1_chroma_loc_info_present_flag); |
469 | | |
470 | 13.8k | if(s_vui.u1_chroma_loc_info_present_flag) |
471 | 0 | { |
472 | | /* u1_chroma_sample_loc_type_top_field */ |
473 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u1_chroma_sample_loc_type_top_field, return_status); |
474 | 0 | ENTROPY_TRACE( |
475 | 0 | "chroma_sample_loc_type_top_field", s_vui.u1_chroma_sample_loc_type_top_field); |
476 | | |
477 | | /* u1_chroma_sample_loc_type_bottom_field */ |
478 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u1_chroma_sample_loc_type_bottom_field, return_status); |
479 | 0 | ENTROPY_TRACE( |
480 | 0 | "chroma_sample_loc_type_bottom_field", s_vui.u1_chroma_sample_loc_type_bottom_field); |
481 | 0 | } |
482 | | |
483 | | /* u1_neutral_chroma_indication_flag */ |
484 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_neutral_chroma_indication_flag, 1, return_status); |
485 | 13.8k | ENTROPY_TRACE("neutral_chroma_indication_flag", s_vui.u1_neutral_chroma_indication_flag); |
486 | | |
487 | | /* u1_field_seq_flag */ |
488 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_field_seq_flag, 1, return_status); |
489 | 13.8k | ENTROPY_TRACE("field_seq_flag", s_vui.u1_field_seq_flag); |
490 | | |
491 | | /* HM CURRENTLY NOT SUPPOSTED */ |
492 | | /* u1_frame_field_info_present_flag */ |
493 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_frame_field_info_present_flag, 1, return_status); |
494 | 13.8k | ENTROPY_TRACE("frame_field_info_present_flag", s_vui.u1_frame_field_info_present_flag); |
495 | | |
496 | | /* u1_default_display_window_flag */ |
497 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_default_display_window_flag, 1, return_status); |
498 | 13.8k | ENTROPY_TRACE("default_display_window_flag", s_vui.u1_default_display_window_flag); |
499 | | |
500 | 13.8k | if(s_vui.u1_default_display_window_flag) |
501 | 0 | { |
502 | | /* u4_def_disp_win_left_offset */ |
503 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u4_def_disp_win_left_offset, return_status); |
504 | 0 | ENTROPY_TRACE("def_disp_win_left_offset", s_vui.u4_def_disp_win_left_offset); |
505 | | |
506 | | /* u4_def_disp_win_right_offset */ |
507 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u4_def_disp_win_right_offset, return_status); |
508 | 0 | ENTROPY_TRACE("def_disp_win_right_offset", s_vui.u4_def_disp_win_right_offset); |
509 | | |
510 | | /* u4_def_disp_win_top_offset */ |
511 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u4_def_disp_win_top_offset, return_status); |
512 | 0 | ENTROPY_TRACE("def_disp_win_top_offset", s_vui.u4_def_disp_win_top_offset); |
513 | | |
514 | | /* u4_def_disp_win_bottom_offset */ |
515 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u4_def_disp_win_bottom_offset, return_status); |
516 | 0 | ENTROPY_TRACE("def_disp_win_bottom_offset", s_vui.u4_def_disp_win_bottom_offset); |
517 | 0 | } |
518 | | |
519 | | /* u1_vui_timing_info_present_flag */ |
520 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_vui_timing_info_present_flag, 1, return_status); |
521 | 13.8k | ENTROPY_TRACE("vui_timing_info_present_flag", s_vui.u1_vui_timing_info_present_flag); |
522 | | |
523 | 13.8k | if(s_vui.u1_vui_timing_info_present_flag) |
524 | 0 | { |
525 | | /* u4_num_units_in_tick */ |
526 | 0 | PUT_BITS(ps_bitstrm, s_vui.u4_vui_num_units_in_tick, 32, return_status); |
527 | 0 | ENTROPY_TRACE("num_units_in_tick", s_vui.u4_vui_num_units_in_tick); |
528 | | |
529 | | /* u4_time_scale */ |
530 | 0 | PUT_BITS(ps_bitstrm, s_vui.u4_vui_time_scale, 32, return_status); |
531 | 0 | ENTROPY_TRACE("time_scale", s_vui.u4_vui_time_scale); |
532 | | |
533 | | /* u1_poc_proportional_to_timing_flag */ |
534 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_poc_proportional_to_timing_flag, 1, return_status); |
535 | 0 | ENTROPY_TRACE("poc_proportional_to_timing_flag", s_vui.u1_poc_proportional_to_timing_flag); |
536 | | |
537 | | /* u1_num_ticks_poc_diff_one_minus1 */ |
538 | 0 | if(s_vui.u1_poc_proportional_to_timing_flag) |
539 | 0 | { |
540 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u4_num_ticks_poc_diff_one_minus1, return_status); |
541 | 0 | ENTROPY_TRACE("num_ticks_poc_diff_one_minus1", s_vui.u4_num_ticks_poc_diff_one_minus1); |
542 | 0 | } |
543 | | |
544 | | /* u1_vui_hrd_parameters_present_flag */ |
545 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_vui_hrd_parameters_present_flag, 1, return_status); |
546 | 0 | ENTROPY_TRACE("vui_hrd_parameters_present_flag", s_vui.u1_vui_hrd_parameters_present_flag); |
547 | |
|
548 | 0 | if(s_vui.u1_vui_hrd_parameters_present_flag) |
549 | 0 | { |
550 | 0 | return_status |= |
551 | 0 | ihevce_generate_hrd_params(ps_bitstrm, &(s_vui.s_vui_hrd_parameters), ps_sps); |
552 | 0 | } |
553 | 0 | } |
554 | | |
555 | | /* u1_bitstream_restriction_flag */ |
556 | 13.8k | PUT_BITS(ps_bitstrm, s_vui.u1_bitstream_restriction_flag, 1, return_status); |
557 | 13.8k | ENTROPY_TRACE("bitstream_restriction_flag", s_vui.u1_bitstream_restriction_flag); |
558 | | |
559 | 13.8k | if(s_vui.u1_bitstream_restriction_flag) |
560 | 0 | { |
561 | | /* u1_tiles_fixed_structure_flag */ |
562 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_tiles_fixed_structure_flag, 1, return_status); |
563 | 0 | ENTROPY_TRACE("tiles_fixed_structure_flag", s_vui.u1_tiles_fixed_structure_flag); |
564 | | |
565 | | /* u1_motion_vectors_over_pic_boundaries_flag */ |
566 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_motion_vectors_over_pic_boundaries_flag, 1, return_status); |
567 | 0 | ENTROPY_TRACE( |
568 | 0 | "motion_vectors_over_pic_boundaries_flag", |
569 | 0 | s_vui.u1_motion_vectors_over_pic_boundaries_flag); |
570 | | |
571 | | /* u1_restricted_ref_pic_lists_flag */ |
572 | 0 | PUT_BITS(ps_bitstrm, s_vui.u1_restricted_ref_pic_lists_flag, 1, return_status); |
573 | 0 | ENTROPY_TRACE("restricted_ref_pic_lists_flag", s_vui.u1_restricted_ref_pic_lists_flag); |
574 | | |
575 | | /* u4_min_spatial_segmentation_idc */ |
576 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u4_min_spatial_segmentation_idc, return_status); |
577 | 0 | ENTROPY_TRACE("min_spatial_segmentation_idc", s_vui.u4_min_spatial_segmentation_idc); |
578 | | |
579 | | /* u1_max_bytes_per_pic_denom */ |
580 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u1_max_bytes_per_pic_denom, return_status); |
581 | 0 | ENTROPY_TRACE("max_bytes_per_pic_denom", s_vui.u1_max_bytes_per_pic_denom); |
582 | | |
583 | | /* u1_max_bits_per_mincu_denom */ |
584 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u1_max_bits_per_mincu_denom, return_status); |
585 | 0 | ENTROPY_TRACE("max_bits_per_mincu_denom", s_vui.u1_max_bits_per_mincu_denom); |
586 | | |
587 | | /* u1_log2_max_mv_length_horizontal */ |
588 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u1_log2_max_mv_length_horizontal, return_status); |
589 | 0 | ENTROPY_TRACE("log2_max_mv_length_horizontal", s_vui.u1_log2_max_mv_length_horizontal); |
590 | | |
591 | | /* u1_log2_max_mv_length_vertical */ |
592 | 0 | PUT_BITS_UEV(ps_bitstrm, s_vui.u1_log2_max_mv_length_vertical, return_status); |
593 | 0 | ENTROPY_TRACE("log2_max_mv_length_vertical", s_vui.u1_log2_max_mv_length_vertical); |
594 | 0 | } |
595 | 13.8k | return return_status; |
596 | 13.8k | } |
597 | | |
598 | | #ifndef DISABLE_SEI |
599 | | /** |
600 | | ****************************************************************************** |
601 | | * |
602 | | * @brief Generates Buffering Period (Supplemental Enhancement Information ) |
603 | | * |
604 | | * @par Description |
605 | | * Parse Supplemental Enhancement Information as per Section 7.3.2.4 |
606 | | * |
607 | | * @param[in] ps_bitstrm |
608 | | * pointer to bitstream context (handle) |
609 | | * |
610 | | * @param[in] ps_pt_sei |
611 | | * pointer to structure containing buffering period SEI data |
612 | | * |
613 | | * @param[in] ps_vui_params |
614 | | * pointer to structure containing VUI data |
615 | | * |
616 | | * @return success or failure error code |
617 | | * |
618 | | ****************************************************************************** |
619 | | */ |
620 | | WORD32 ihevce_put_buf_period_sei_params( |
621 | | buf_period_sei_params_t *ps_bp_sei, vui_t *ps_vui_params, bitstrm_t *ps_bitstrm) |
622 | 0 | { |
623 | 0 | UWORD32 i; |
624 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
625 | 0 | UWORD8 u1_payload_size = 0; |
626 | 0 | UWORD8 u1_sub_pic_cpb_params_present_flag = |
627 | 0 | ps_vui_params->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag; |
628 | |
|
629 | 0 | { |
630 | | //UWORD32 range; |
631 | | //UWORD32 sps_id = ps_bp_sei->u1_bp_seq_parameter_set_id; |
632 | | |
633 | | //range = 0; |
634 | | //GETRANGE(range, sps_id); |
635 | 0 | u1_payload_size += 1; //(((range - 1) << 1) + 1); |
636 | |
|
637 | 0 | if(!u1_sub_pic_cpb_params_present_flag) |
638 | 0 | u1_payload_size += 1; |
639 | 0 | u1_payload_size += 1; |
640 | 0 | u1_payload_size += |
641 | 0 | ps_vui_params->s_vui_hrd_parameters.u1_au_cpb_removal_delay_length_minus1 + 1; |
642 | 0 | if(1 == ps_vui_params->s_vui_hrd_parameters.u1_nal_hrd_parameters_present_flag) |
643 | 0 | { |
644 | 0 | for(i = 0; i <= ps_bp_sei->u4_cpb_cnt; i++) |
645 | 0 | { |
646 | 0 | u1_payload_size += ps_bp_sei->u4_initial_cpb_removal_delay_length << 1; |
647 | 0 | if(u1_sub_pic_cpb_params_present_flag || ps_bp_sei->u1_rap_cpb_params_present_flag) |
648 | 0 | u1_payload_size += ps_bp_sei->u4_initial_cpb_removal_delay_length << 1; |
649 | 0 | } |
650 | 0 | } |
651 | 0 | if(1 == ps_vui_params->s_vui_hrd_parameters.u1_vcl_hrd_parameters_present_flag) |
652 | 0 | { |
653 | 0 | for(i = 0; i <= ps_bp_sei->u4_cpb_cnt; i++) |
654 | 0 | { |
655 | 0 | u1_payload_size += ps_bp_sei->u4_initial_cpb_removal_delay_length << 1; |
656 | 0 | if(u1_sub_pic_cpb_params_present_flag || ps_bp_sei->u1_rap_cpb_params_present_flag) |
657 | 0 | u1_payload_size += ps_bp_sei->u4_initial_cpb_removal_delay_length << 1; |
658 | 0 | } |
659 | 0 | } |
660 | 0 | } |
661 | |
|
662 | 0 | u1_payload_size = (u1_payload_size + 7) >> 3; |
663 | | |
664 | | /************************************************************************************************/ |
665 | | /* Calculating the cbp removal delay and cbp removal delay offset based on the */ |
666 | | /* buffer level information from Rate control */ |
667 | | /* NOTE : Buffer fullness level for Rate control is updated using Approximate */ |
668 | | /* number of bits from RDOPT stage rather than from accurate number of bits from ENTROPY coding */ |
669 | | /************************************************************************************************/ |
670 | |
|
671 | 0 | { |
672 | 0 | ULWORD64 u8_temp; |
673 | 0 | UWORD32 u4_buffer_size, u4_dbf; |
674 | |
|
675 | 0 | u4_buffer_size = ps_bp_sei->u4_buffer_size_sei; |
676 | 0 | u4_dbf = ps_bp_sei->u4_dbf_sei; |
677 | 0 | for(i = 0; i <= ps_bp_sei->u4_cpb_cnt; i++) |
678 | 0 | { |
679 | 0 | u8_temp = ((ULWORD64)(u4_dbf)*90000); |
680 | 0 | u8_temp = u8_temp / ps_bp_sei->u4_target_bit_rate_sei; |
681 | 0 | ps_bp_sei->au4_nal_initial_cpb_removal_delay[i] = (UWORD32)u8_temp; |
682 | |
|
683 | 0 | u8_temp = ((ULWORD64)(u4_buffer_size - u4_dbf) * 90000); |
684 | 0 | u8_temp = u8_temp / ps_bp_sei->u4_target_bit_rate_sei; |
685 | 0 | ps_bp_sei->au4_nal_initial_cpb_removal_delay_offset[i] = (UWORD32)u8_temp; |
686 | |
|
687 | 0 | if(ps_bp_sei->au4_nal_initial_cpb_removal_delay[i] < 1) |
688 | 0 | ps_bp_sei->au4_nal_initial_cpb_removal_delay[i] = |
689 | 0 | 1; /* ps_bp_sei->au4_nal_initial_cpb_removal_delay[i] should be always greater than 0 */ |
690 | 0 | } |
691 | 0 | } |
692 | | |
693 | | /************************************************************************/ |
694 | | /* PayloadSize : This is the size of the payload in bytes */ |
695 | | /************************************************************************/ |
696 | 0 | PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status); |
697 | 0 | ENTROPY_TRACE("payload_size", u1_payload_size); |
698 | | |
699 | | /************************************************************************/ |
700 | | /* Put the buffering period SEI parameters into the bitstream. For */ |
701 | | /* details refer to section D.1.1 of the standard */ |
702 | | /************************************************************************/ |
703 | | |
704 | | /* seq_parameter_set_id */ |
705 | 0 | PUT_BITS_UEV(ps_bitstrm, ps_bp_sei->u1_bp_seq_parameter_set_id, return_status); |
706 | 0 | ENTROPY_TRACE("seq_parameter_set_id", ps_bp_sei->u1_bp_seq_parameter_set_id); |
707 | | |
708 | | //PUT_BITS(ps_bitstrm, u1_sub_pic_cpb_params_present_flag, 1, return_status); |
709 | | //ENTROPY_TRACE("sub_pic_cpb_params_present_flag", u1_sub_pic_cpb_params_present_flag); |
710 | |
|
711 | 0 | if(!u1_sub_pic_cpb_params_present_flag) |
712 | 0 | { |
713 | | /* u1_rap_cpb_params_present_flag */ |
714 | 0 | PUT_BITS(ps_bitstrm, ps_bp_sei->u1_rap_cpb_params_present_flag, 1, return_status); |
715 | 0 | ENTROPY_TRACE("rap_cpb_params_present_flag", ps_bp_sei->u1_rap_cpb_params_present_flag); |
716 | 0 | } |
717 | |
|
718 | 0 | if(ps_bp_sei->u1_rap_cpb_params_present_flag) |
719 | 0 | { |
720 | 0 | PUT_BITS( |
721 | 0 | ps_bitstrm, |
722 | 0 | ps_bp_sei->u4_cpb_delay_offset, |
723 | 0 | (ps_vui_params->s_vui_hrd_parameters.u1_au_cpb_removal_delay_length_minus1 + 1), |
724 | 0 | return_status); |
725 | 0 | ENTROPY_TRACE("cpb_delay_offset", ps_bp_sei->cpb_delay_offset); |
726 | |
|
727 | 0 | PUT_BITS( |
728 | 0 | ps_bitstrm, |
729 | 0 | ps_bp_sei->u4_dpb_delay_offset, |
730 | 0 | (ps_vui_params->s_vui_hrd_parameters.u1_dpb_output_delay_length_minus1 + 1), |
731 | 0 | return_status); |
732 | 0 | ENTROPY_TRACE("dpb_delay_offset", ps_bp_sei->dpb_delay_offset); |
733 | 0 | } |
734 | |
|
735 | 0 | PUT_BITS(ps_bitstrm, ps_bp_sei->u1_concatenation_flag, 1, return_status); |
736 | 0 | ENTROPY_TRACE("concatenation_flag", ps_bp_sei->concatenation_flag); |
737 | |
|
738 | 0 | PUT_BITS( |
739 | 0 | ps_bitstrm, |
740 | 0 | ps_bp_sei->u4_au_cpb_removal_delay_delta_minus1, |
741 | 0 | (ps_vui_params->s_vui_hrd_parameters.u1_au_cpb_removal_delay_length_minus1 + 1), |
742 | 0 | return_status); |
743 | |
|
744 | 0 | ENTROPY_TRACE( |
745 | 0 | "au_cpb_removal_delay_delta_minus1", ps_bp_sei->au_cpb_removal_delay_delta_minus1); |
746 | |
|
747 | 0 | if(1 == ps_vui_params->s_vui_hrd_parameters.u1_nal_hrd_parameters_present_flag) |
748 | 0 | { |
749 | 0 | for(i = 0; i <= ps_bp_sei->u4_cpb_cnt; i++) |
750 | 0 | { |
751 | 0 | PUT_BITS( |
752 | 0 | ps_bitstrm, |
753 | 0 | ps_bp_sei->au4_nal_initial_cpb_removal_delay[i], |
754 | 0 | ps_bp_sei->u4_initial_cpb_removal_delay_length, |
755 | 0 | return_status); |
756 | 0 | ENTROPY_TRACE( |
757 | 0 | "nal_initial_cpb_removal_delay", ps_bp_sei->au4_nal_initial_cpb_removal_delay[i]); |
758 | |
|
759 | 0 | PUT_BITS( |
760 | 0 | ps_bitstrm, |
761 | 0 | ps_bp_sei->au4_nal_initial_cpb_removal_delay_offset[i], |
762 | 0 | ps_bp_sei->u4_initial_cpb_removal_delay_length, |
763 | 0 | return_status); |
764 | 0 | ENTROPY_TRACE( |
765 | 0 | "nal_initial_cpb_removal_delay_offset", |
766 | 0 | ps_bp_sei->au4_nal_initial_cpb_removal_delay_offset[i]); |
767 | |
|
768 | 0 | if(u1_sub_pic_cpb_params_present_flag || ps_bp_sei->u1_rap_cpb_params_present_flag) |
769 | 0 | { |
770 | 0 | PUT_BITS( |
771 | 0 | ps_bitstrm, |
772 | 0 | ps_bp_sei->au4_nal_initial_alt_cpb_removal_delay[i], |
773 | 0 | ps_bp_sei->u4_initial_cpb_removal_delay_length, |
774 | 0 | return_status); |
775 | 0 | ENTROPY_TRACE( |
776 | 0 | "nal_initial_alt_cpb_removal_delay", |
777 | 0 | ps_bp_sei->au4_nal_initial_alt_cpb_removal_delay[i]); |
778 | |
|
779 | 0 | PUT_BITS( |
780 | 0 | ps_bitstrm, |
781 | 0 | ps_bp_sei->au4_nal_initial_alt_cpb_removal_delay_offset[i], |
782 | 0 | ps_bp_sei->u4_initial_cpb_removal_delay_length, |
783 | 0 | return_status); |
784 | 0 | ENTROPY_TRACE( |
785 | 0 | "nal_initial_alt_cpb_removal_delay_offset", |
786 | 0 | ps_bp_sei->au4_nal_initial_alt_cpb_removal_delay_offset[i]); |
787 | 0 | } |
788 | 0 | } |
789 | 0 | } |
790 | |
|
791 | 0 | if(1 == ps_vui_params->s_vui_hrd_parameters.u1_vcl_hrd_parameters_present_flag) |
792 | 0 | { |
793 | 0 | for(i = 0; i <= ps_bp_sei->u4_cpb_cnt; i++) |
794 | 0 | { |
795 | 0 | PUT_BITS( |
796 | 0 | ps_bitstrm, |
797 | 0 | ps_bp_sei->au4_vcl_initial_cpb_removal_delay[i], |
798 | 0 | ps_bp_sei->u4_initial_cpb_removal_delay_length, |
799 | 0 | return_status); |
800 | 0 | ENTROPY_TRACE( |
801 | 0 | "vcl_initial_cpb_removal_delay", ps_bp_sei->au4_vcl_initial_cpb_removal_delay[i]); |
802 | |
|
803 | 0 | PUT_BITS( |
804 | 0 | ps_bitstrm, |
805 | 0 | ps_bp_sei->au4_vcl_initial_cpb_removal_delay_offset[i], |
806 | 0 | ps_bp_sei->u4_initial_cpb_removal_delay_length, |
807 | 0 | return_status); |
808 | 0 | ENTROPY_TRACE( |
809 | 0 | "vcl_initial_cpb_removal_delay_offset", |
810 | 0 | ps_bp_sei->au4_vcl_initial_cpb_removal_delay_offset[i]); |
811 | |
|
812 | 0 | if(u1_sub_pic_cpb_params_present_flag || ps_bp_sei->u1_rap_cpb_params_present_flag) |
813 | 0 | { |
814 | 0 | PUT_BITS( |
815 | 0 | ps_bitstrm, |
816 | 0 | ps_bp_sei->au4_vcl_initial_alt_cpb_removal_delay[i], |
817 | 0 | ps_bp_sei->u4_initial_cpb_removal_delay_length, |
818 | 0 | return_status); |
819 | 0 | ENTROPY_TRACE( |
820 | 0 | "vcl_initial_alt_cpb_removal_delay", |
821 | 0 | ps_bp_sei->au4_vcl_initial_alt_cpb_removal_delay[i]); |
822 | |
|
823 | 0 | PUT_BITS( |
824 | 0 | ps_bitstrm, |
825 | 0 | ps_bp_sei->au4_vcl_initial_alt_cpb_removal_delay_offset[i], |
826 | 0 | ps_bp_sei->u4_initial_cpb_removal_delay_length, |
827 | 0 | return_status); |
828 | 0 | ENTROPY_TRACE( |
829 | 0 | "vcl_initial_alt_cpb_removal_delay_offset", |
830 | 0 | ps_bp_sei->au4_vcl_initial_alt_cpb_removal_delay_offset[i]); |
831 | 0 | } |
832 | 0 | } |
833 | 0 | } |
834 | |
|
835 | 0 | return (return_status); |
836 | 0 | } |
837 | | |
838 | | /** |
839 | | ****************************************************************************** |
840 | | * |
841 | | * @brief Generates active parameter set (Supplemental Enhancement Information ) |
842 | | * |
843 | | * @par Description |
844 | | * Parse Supplemental Enhancement Information as per Section 7.3.2.4 |
845 | | * |
846 | | * @param[in] ps_bitstrm |
847 | | * pointer to bitstream context (handle) |
848 | | * |
849 | | * @param[in] ps_act_sei |
850 | | * pointer to structure containing active parameter set SEI data |
851 | | * |
852 | | * @return success or failure error code |
853 | | * |
854 | | ***************************************************************************** |
855 | | */ |
856 | | WORD32 ihevce_put_active_parameter_set_sei_params( |
857 | | active_parameter_set_sei_param_t *ps_act_sei, bitstrm_t *ps_bitstrm) |
858 | | |
859 | 0 | { |
860 | 0 | UWORD8 u1_payload_size = 0, i; |
861 | 0 | UWORD8 u1_range = 0, u1_act_sps_id; |
862 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
863 | |
|
864 | 0 | u1_payload_size += 4; |
865 | 0 | u1_payload_size += 1; |
866 | 0 | u1_payload_size += 1; |
867 | 0 | u1_payload_size += 1; // num_sps_ids_minus1 ahould be zero as per the standard |
868 | |
|
869 | 0 | u1_act_sps_id = ps_act_sei->u1_active_video_parameter_set_id; |
870 | |
|
871 | 0 | GETRANGE(u1_range, u1_act_sps_id); |
872 | |
|
873 | 0 | u1_payload_size += (((u1_range - 1) << 1) + 1); |
874 | |
|
875 | 0 | u1_payload_size = (u1_payload_size + 7) >> 3; |
876 | |
|
877 | 0 | PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status); |
878 | 0 | ENTROPY_TRACE("payload_size", u1_payload_size); |
879 | |
|
880 | 0 | PUT_BITS(ps_bitstrm, ps_act_sei->u1_active_video_parameter_set_id, 4, return_status); |
881 | 0 | ENTROPY_TRACE("active_video_parameter_set_id", ps_act_sei->u1_active_video_parameter_set_id); |
882 | |
|
883 | 0 | PUT_BITS(ps_bitstrm, ps_act_sei->u1_self_contained_cvs_flag, 1, return_status); |
884 | 0 | ENTROPY_TRACE("self_contained_cvs_flag", ps_act_sei->u1_self_contained_cvs_flag); |
885 | |
|
886 | 0 | PUT_BITS(ps_bitstrm, ps_act_sei->u1_no_parameter_set_update_flag, 1, return_status); |
887 | 0 | ENTROPY_TRACE("no_parameter_set_update_flag", ps_act_sei->u1_no_parameter_set_update_flag); |
888 | |
|
889 | 0 | PUT_BITS_UEV(ps_bitstrm, ps_act_sei->u1_num_sps_ids_minus1, return_status); |
890 | |
|
891 | 0 | ENTROPY_TRACE("num_sps_ids_minus1", ps_act_sei->u1_num_sps_ids_minus1); |
892 | |
|
893 | 0 | for(i = 0; i <= ps_act_sei->u1_num_sps_ids_minus1; i++) |
894 | 0 | { |
895 | 0 | PUT_BITS_UEV(ps_bitstrm, ps_act_sei->au1_active_seq_parameter_set_id[i], return_status); |
896 | 0 | ENTROPY_TRACE( |
897 | 0 | "active_video_parameter_set_id", ps_act_sei->au1_active_seq_parameter_set_id[i]); |
898 | 0 | } |
899 | 0 | return (return_status); |
900 | 0 | } |
901 | | |
902 | | /** |
903 | | ****************************************************************************** |
904 | | * |
905 | | * @brief Generates Mastering Display Colour Volume (Supplemental Enhancement Information ) |
906 | | * |
907 | | * @par Description |
908 | | * Parse Supplemental Enhancement Information as per Section 7.3.2.4 |
909 | | * |
910 | | * @param[in] ps_bitstrm |
911 | | * pointer to bitstream context (handle) |
912 | | * |
913 | | * @param[in] ps_rp_sei |
914 | | * pointer to structure containing recovery point SEI data |
915 | | * |
916 | | * @param[in] ps_vui_params |
917 | | * pointer to structure containing VUI data |
918 | | * |
919 | | * @return success or failure error code |
920 | | * |
921 | | ****************************************************************************** |
922 | | */ |
923 | | WORD32 ihevce_put_mastering_disp_col_vol_sei_params( |
924 | | mastering_dis_col_vol_sei_params_t *ps_mdcl_sei, bitstrm_t *ps_bitstrm) |
925 | 0 | { |
926 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
927 | 0 | UWORD8 u1_payload_size = 0; |
928 | 0 | WORD32 c; |
929 | |
|
930 | 0 | u1_payload_size += 6; /* display primaries x */ |
931 | 0 | u1_payload_size += 6; /* display primaries y */ |
932 | 0 | u1_payload_size += 2; /* white point x */ |
933 | 0 | u1_payload_size += 2; /* white point y */ |
934 | 0 | u1_payload_size += 4; /* max display mastering luminance */ |
935 | 0 | u1_payload_size += 4; /* min display mastering luminance */ |
936 | | |
937 | | /************************************************************************/ |
938 | | /* PayloadSize : This is the size of the payload in bytes */ |
939 | | /************************************************************************/ |
940 | 0 | PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status); |
941 | 0 | ENTROPY_TRACE("u1_payload_size", u1_payload_size); |
942 | |
|
943 | 0 | ASSERT(ps_mdcl_sei->u2_white_point_x <= 50000); |
944 | | |
945 | 0 | ASSERT(ps_mdcl_sei->u2_white_point_y <= 50000); |
946 | | |
947 | 0 | ASSERT( |
948 | 0 | ps_mdcl_sei->u4_max_display_mastering_luminance > |
949 | 0 | ps_mdcl_sei->u4_min_display_mastering_luminance); |
950 | | |
951 | | /*******************************************************************************/ |
952 | | /* Put the mastering display colour volume SEI parameters into the bitstream. */ |
953 | | /* For details refer to section D.1.1 of the standard */ |
954 | | /*******************************************************************************/ |
955 | | |
956 | | /* display primaries x */ |
957 | 0 | for(c = 0; c < 3; c++) |
958 | 0 | { |
959 | 0 | ASSERT(ps_mdcl_sei->au2_display_primaries_x[c] <= 50000); |
960 | | |
961 | 0 | PUT_BITS(ps_bitstrm, ps_mdcl_sei->au2_display_primaries_x[c], 16, return_status); |
962 | 0 | ENTROPY_TRACE("u2_display_primaries_x", ps_mdcl_sei->au2_display_primaries_x[c]); |
963 | |
|
964 | 0 | ASSERT(ps_mdcl_sei->au2_display_primaries_y[c] <= 50000); |
965 | | |
966 | 0 | PUT_BITS(ps_bitstrm, ps_mdcl_sei->au2_display_primaries_y[c], 16, return_status); |
967 | 0 | ENTROPY_TRACE("u2_display_primaries_y", ps_mdcl_sei->au2_display_primaries_y[c]); |
968 | 0 | } |
969 | | |
970 | | /* white point x */ |
971 | 0 | PUT_BITS(ps_bitstrm, ps_mdcl_sei->u2_white_point_x, 16, return_status); |
972 | 0 | ENTROPY_TRACE("u2_white point x", ps_mdcl_sei->u2_white_point_x); |
973 | | |
974 | | /* white point y */ |
975 | 0 | PUT_BITS(ps_bitstrm, ps_mdcl_sei->u2_white_point_y, 16, return_status); |
976 | 0 | ENTROPY_TRACE("u2_white point y", ps_mdcl_sei->u2_white_point_y); |
977 | | |
978 | | /* max display mastering luminance */ |
979 | 0 | PUT_BITS(ps_bitstrm, ps_mdcl_sei->u4_max_display_mastering_luminance, 32, return_status); |
980 | 0 | ENTROPY_TRACE( |
981 | 0 | "u4_max_display_mastering_luminance", ps_mdcl_sei->u4_max_display_mastering_luminance); |
982 | | |
983 | | /* min display mastering luminance */ |
984 | 0 | PUT_BITS(ps_bitstrm, ps_mdcl_sei->u4_min_display_mastering_luminance, 32, return_status); |
985 | 0 | ENTROPY_TRACE( |
986 | 0 | "u4_max_display_mastering_luminance", ps_mdcl_sei->u4_min_display_mastering_luminance); |
987 | |
|
988 | 0 | return (return_status); |
989 | 0 | } |
990 | | |
991 | | /** |
992 | | ****************************************************************************** |
993 | | * |
994 | | * @brief Stores user data in bitstream |
995 | | * |
996 | | * @par Description |
997 | | * Parse Supplemental Enhancement Information as per Section 7.3.2.4 |
998 | | * |
999 | | * @param[in] ps_bitstrm |
1000 | | * pointer to bitstream context (handle) |
1001 | | * |
1002 | | * @param[in] u4_sei_payload_length |
1003 | | * SEI Payload Length |
1004 | | * |
1005 | | * @param[in] pu1_sei_payload |
1006 | | * pointer to SEI Payload |
1007 | | * |
1008 | | * @return success or failure error code |
1009 | | * |
1010 | | ****************************************************************************** |
1011 | | */ |
1012 | | WORD32 ihevce_put_sei_params( |
1013 | | UWORD32 u4_sei_payload_length, UWORD8 *pu1_sei_payload, bitstrm_t *ps_bitstrm) |
1014 | 0 | { |
1015 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
1016 | 0 | UWORD32 i, u4_length = 0; |
1017 | |
|
1018 | 0 | u4_length = u4_sei_payload_length; |
1019 | 0 | while(u4_sei_payload_length >= 0xFF) |
1020 | 0 | { |
1021 | 0 | PUT_BITS(ps_bitstrm, (UWORD32)0xFF, 8, return_status); |
1022 | 0 | u4_sei_payload_length -= 0xFF; |
1023 | 0 | } |
1024 | 0 | PUT_BITS(ps_bitstrm, (UWORD32)u4_sei_payload_length, 8, return_status); |
1025 | |
|
1026 | 0 | for(i = 0; i < u4_length; i++) |
1027 | 0 | { |
1028 | 0 | PUT_BITS(ps_bitstrm, (UWORD32)*pu1_sei_payload, 8, return_status); |
1029 | 0 | pu1_sei_payload++; |
1030 | 0 | } |
1031 | |
|
1032 | 0 | return (return_status); |
1033 | 0 | } |
1034 | | |
1035 | | /** |
1036 | | ****************************************************************************** |
1037 | | * |
1038 | | * @brief Stores content light level info in bitstream |
1039 | | * |
1040 | | * @par Description |
1041 | | * Parse Supplemental Enhancement Information as per Section 7.3.2.4 |
1042 | | * |
1043 | | * @param[in] ps_bitstrm |
1044 | | * pointer to bitstream context (handle) |
1045 | | * |
1046 | | * @param[in] |
1047 | | * |
1048 | | * |
1049 | | * @param[in] |
1050 | | * |
1051 | | * |
1052 | | * @return success or failure error code |
1053 | | * |
1054 | | ****************************************************************************** |
1055 | | */ |
1056 | | WORD32 ihevce_put_cll_info_sei_params(UWORD16 u2_avg_cll, UWORD16 u2_max_cll, bitstrm_t *ps_bitstrm) |
1057 | 0 | { |
1058 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
1059 | 0 | UWORD8 u1_payload_size; |
1060 | |
|
1061 | 0 | u1_payload_size = 4; |
1062 | | /************************************************************************/ |
1063 | | /* PayloadSize : This is the size of the payload in bytes */ |
1064 | | /************************************************************************/ |
1065 | 0 | PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status); |
1066 | 0 | ENTROPY_TRACE("u1_payload_size", u1_payload_size); |
1067 | |
|
1068 | 0 | PUT_BITS(ps_bitstrm, (UWORD32)u2_avg_cll, 16, return_status); |
1069 | 0 | PUT_BITS(ps_bitstrm, (UWORD32)u2_max_cll, 16, return_status); |
1070 | |
|
1071 | 0 | return (return_status); |
1072 | 0 | } |
1073 | | |
1074 | | /** |
1075 | | ****************************************************************************** |
1076 | | * |
1077 | | * @brief Generates Recovery Point (Supplemental Enhancement Information ) |
1078 | | * |
1079 | | * @par Description |
1080 | | * Parse Supplemental Enhancement Information as per Section 7.3.2.4 |
1081 | | * |
1082 | | * @param[in] ps_bitstrm |
1083 | | * pointer to bitstream context (handle) |
1084 | | * |
1085 | | * @param[in] ps_rp_sei |
1086 | | * pointer to structure containing recovery point SEI data |
1087 | | * |
1088 | | * @param[in] ps_vui_params |
1089 | | * pointer to structure containing VUI data |
1090 | | * |
1091 | | * @return success or failure error code |
1092 | | * |
1093 | | ****************************************************************************** |
1094 | | */ |
1095 | | WORD32 ihevce_put_recovery_point_sei_params( |
1096 | | recovery_point_sei_params_t *ps_rp_sei, bitstrm_t *ps_bitstrm) |
1097 | 0 | { |
1098 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
1099 | 0 | UWORD8 u1_payload_size = 0; |
1100 | |
|
1101 | 0 | { |
1102 | 0 | UWORD32 range, val; |
1103 | 0 | WORD32 recov_point = ps_rp_sei->i4_recovery_poc_cnt; |
1104 | 0 | val = 0; |
1105 | 0 | range = 0; |
1106 | |
|
1107 | 0 | if(recov_point <= 0) |
1108 | 0 | val = ((-recov_point) << 1); |
1109 | 0 | else |
1110 | 0 | val = (recov_point << 1) - 1; |
1111 | |
|
1112 | 0 | GETRANGE(range, val); |
1113 | |
|
1114 | 0 | u1_payload_size += (((range - 1) << 1) + 1); |
1115 | |
|
1116 | 0 | u1_payload_size += 1; |
1117 | 0 | u1_payload_size += 1; |
1118 | 0 | } |
1119 | |
|
1120 | 0 | u1_payload_size = (u1_payload_size + 7) >> 3; |
1121 | | /************************************************************************/ |
1122 | | /* PayloadSize : This is the size of the payload in bytes */ |
1123 | | /************************************************************************/ |
1124 | 0 | PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status); |
1125 | 0 | ENTROPY_TRACE("u1_payload_size", u1_payload_size); |
1126 | | /************************************************************************/ |
1127 | | /* Put the recovery point SEI parameters into the bitstream. For */ |
1128 | | /* details refer to section D.1.1 of the standard */ |
1129 | | /************************************************************************/ |
1130 | | |
1131 | | /* i4_recovery_poc_cnt */ |
1132 | 0 | PUT_BITS_SEV(ps_bitstrm, ps_rp_sei->i4_recovery_poc_cnt, return_status); |
1133 | 0 | ENTROPY_TRACE("i4_recovery_poc_cnt", ps_rp_sei->i4_recovery_poc_cnt); |
1134 | | |
1135 | | /* u1_exact_match_flag */ |
1136 | 0 | PUT_BITS(ps_bitstrm, ps_rp_sei->u1_exact_match_flag, 1, return_status); |
1137 | 0 | ENTROPY_TRACE("exact_match_flag", ps_rp_sei->u1_exact_match_flag); |
1138 | | |
1139 | | /* u1_broken_link_flag */ |
1140 | 0 | PUT_BITS(ps_bitstrm, ps_rp_sei->u1_broken_link_flag, 1, return_status); |
1141 | 0 | ENTROPY_TRACE("broken_link_flag", ps_rp_sei->u1_broken_link_flag); |
1142 | |
|
1143 | 0 | return (return_status); |
1144 | 0 | } |
1145 | | |
1146 | | /** |
1147 | | ****************************************************************************** |
1148 | | * |
1149 | | * @brief Generates Picture timing (Supplemental Enhancement Information ) |
1150 | | * |
1151 | | * @par Description |
1152 | | * Parse Supplemental Enhancement Information as per Section 7.3.2.4 |
1153 | | * |
1154 | | * @param[in] ps_bitstrm |
1155 | | * pointer to bitstream context (handle) |
1156 | | * |
1157 | | * @param[in] ps_pt_sei |
1158 | | * pointer to structure containing oicture timing SEI data |
1159 | | * |
1160 | | * @param[in] ps_vui_params |
1161 | | * pointer to structure containing VUI data |
1162 | | * |
1163 | | * @return success or failure error code |
1164 | | * |
1165 | | ****************************************************************************** |
1166 | | */ |
1167 | | WORD32 ihevce_put_pic_timing_sei_params( |
1168 | | pic_timing_sei_params_t *ps_pt_sei, vui_t *ps_vui_params, bitstrm_t *ps_bitstrm) |
1169 | 0 | { |
1170 | 0 | UWORD32 i; |
1171 | 0 | UWORD8 u1_payload_size = 0; |
1172 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
1173 | 0 | UWORD8 u1_au_cpb_removal_delay_length = |
1174 | 0 | ps_vui_params->s_vui_hrd_parameters.u1_au_cpb_removal_delay_length_minus1 + 1; |
1175 | |
|
1176 | 0 | UWORD8 u1_dpb_output_delay_length = |
1177 | 0 | ps_vui_params->s_vui_hrd_parameters.u1_dpb_output_delay_length_minus1 + 1; |
1178 | |
|
1179 | 0 | UWORD8 u1_du_cpb_removal_delay_increment_length = |
1180 | 0 | ps_vui_params->s_vui_hrd_parameters.u1_du_cpb_removal_delay_increment_length_minus1 + 1; |
1181 | |
|
1182 | 0 | UWORD8 u1_sub_pic_cpb_params_present_flag = |
1183 | 0 | ps_vui_params->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag; |
1184 | |
|
1185 | 0 | UWORD8 u1_sub_pic_cpb_params_in_pt_sei_flag = |
1186 | 0 | ps_vui_params->s_vui_hrd_parameters.u1_sub_pic_cpb_params_in_pic_timing_sei_flag; |
1187 | |
|
1188 | 0 | { |
1189 | 0 | if(1 == ps_vui_params->u1_frame_field_info_present_flag) |
1190 | 0 | { |
1191 | 0 | u1_payload_size += 4; |
1192 | 0 | u1_payload_size += 2; |
1193 | 0 | u1_payload_size += 1; |
1194 | 0 | } |
1195 | |
|
1196 | 0 | if(ps_vui_params->s_vui_hrd_parameters.u1_nal_hrd_parameters_present_flag || |
1197 | 0 | ps_vui_params->s_vui_hrd_parameters.u1_vcl_hrd_parameters_present_flag) |
1198 | 0 | { |
1199 | 0 | u1_payload_size += u1_au_cpb_removal_delay_length; |
1200 | 0 | u1_payload_size += u1_dpb_output_delay_length; |
1201 | 0 | } |
1202 | |
|
1203 | 0 | if(u1_sub_pic_cpb_params_in_pt_sei_flag && u1_sub_pic_cpb_params_present_flag) |
1204 | 0 | { |
1205 | 0 | UWORD32 range, val = ps_pt_sei->u4_num_decoding_units_minus1; |
1206 | 0 | range = 0; |
1207 | |
|
1208 | 0 | GETRANGE(range, val); |
1209 | 0 | u1_payload_size += (((range - 1) << 1) + 1); |
1210 | |
|
1211 | 0 | u1_payload_size += 1; |
1212 | 0 | if(1 == ps_pt_sei->u1_du_common_cpb_removal_delay_flag) |
1213 | 0 | { |
1214 | 0 | u1_payload_size += u1_du_cpb_removal_delay_increment_length; |
1215 | |
|
1216 | 0 | for(i = 0; i <= ps_pt_sei->u4_num_decoding_units_minus1; i++) |
1217 | 0 | { |
1218 | 0 | val = ps_pt_sei->au4_num_nalus_in_du_minus1[0]; |
1219 | 0 | range = 0; |
1220 | |
|
1221 | 0 | GETRANGE(range, val); |
1222 | 0 | u1_payload_size += (((range - 1) << 1) + 1); |
1223 | |
|
1224 | 0 | if((1 != ps_pt_sei->u1_du_common_cpb_removal_delay_flag) && |
1225 | 0 | (i < ps_pt_sei->u4_num_decoding_units_minus1)) |
1226 | 0 | { |
1227 | 0 | u1_payload_size += u1_du_cpb_removal_delay_increment_length; |
1228 | 0 | } |
1229 | 0 | } |
1230 | 0 | } |
1231 | 0 | } |
1232 | 0 | } |
1233 | |
|
1234 | 0 | ASSERT((ps_pt_sei->u4_au_cpb_removal_delay_minus1 < (1 << u1_au_cpb_removal_delay_length))); |
1235 | | |
1236 | 0 | u1_payload_size = (u1_payload_size + 7) >> 3; |
1237 | | /************************************************************************/ |
1238 | | /* PayloadSize : This is the size of the payload in bytes */ |
1239 | | /************************************************************************/ |
1240 | 0 | PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status); |
1241 | 0 | ENTROPY_TRACE("u1_payload_size", u1_payload_size); |
1242 | | |
1243 | | /************************************************************************/ |
1244 | | /* Put the picture timing SEI parameters into the bitstream. For */ |
1245 | | /* details refer to section D.1.2 of the standard */ |
1246 | | /************************************************************************/ |
1247 | |
|
1248 | 0 | if(1 == ps_vui_params->u1_frame_field_info_present_flag) |
1249 | 0 | { |
1250 | 0 | PUT_BITS(ps_bitstrm, ps_pt_sei->u4_pic_struct, 4, return_status); |
1251 | 0 | ENTROPY_TRACE("pic_struct", ps_pt_sei->u4_pic_struct); |
1252 | |
|
1253 | 0 | PUT_BITS(ps_bitstrm, ps_pt_sei->u4_source_scan_type, 2, return_status); |
1254 | 0 | ENTROPY_TRACE("source_scan_type", ps_pt_sei->u4_source_scan_type); |
1255 | |
|
1256 | 0 | PUT_BITS(ps_bitstrm, ps_pt_sei->u1_duplicate_flag, 1, return_status); |
1257 | 0 | ENTROPY_TRACE("duplicate_flag", ps_pt_sei->u1_duplicate_flag); |
1258 | 0 | } |
1259 | |
|
1260 | 0 | if(ps_vui_params->s_vui_hrd_parameters.u1_nal_hrd_parameters_present_flag || |
1261 | 0 | ps_vui_params->s_vui_hrd_parameters |
1262 | 0 | .u1_vcl_hrd_parameters_present_flag) // condition from standard when CpbDpbDelaysPresentFlag flag will be present |
1263 | 0 | { |
1264 | 0 | PUT_BITS( |
1265 | 0 | ps_bitstrm, |
1266 | 0 | ps_pt_sei->u4_au_cpb_removal_delay_minus1, |
1267 | 0 | u1_au_cpb_removal_delay_length, |
1268 | 0 | return_status); |
1269 | 0 | ENTROPY_TRACE("cpb_removal_delay_minus1", ps_pt_sei->u4_au_cpb_removal_delay_minus1); |
1270 | |
|
1271 | 0 | PUT_BITS( |
1272 | 0 | ps_bitstrm, |
1273 | 0 | ps_pt_sei->u4_pic_dpb_output_delay, |
1274 | 0 | u1_dpb_output_delay_length, |
1275 | 0 | return_status); |
1276 | 0 | ENTROPY_TRACE("pic_dpb_output_delay", ps_pt_sei->u4_pic_dpb_output_delay); |
1277 | |
|
1278 | 0 | if(u1_sub_pic_cpb_params_present_flag) |
1279 | 0 | { |
1280 | 0 | PUT_BITS( |
1281 | 0 | ps_bitstrm, |
1282 | 0 | ps_pt_sei->u4_pic_dpb_output_du_delay, |
1283 | 0 | ps_vui_params->s_vui_hrd_parameters.u1_dpb_output_delay_du_length_minus1, |
1284 | 0 | return_status); |
1285 | 0 | ENTROPY_TRACE("pic_dpb_output_du_delay", ps_pt_sei->u4_pic_dpb_output_delay); |
1286 | 0 | } |
1287 | |
|
1288 | 0 | if(u1_sub_pic_cpb_params_in_pt_sei_flag && u1_sub_pic_cpb_params_present_flag) |
1289 | 0 | { |
1290 | 0 | PUT_BITS_UEV(ps_bitstrm, ps_pt_sei->u4_num_decoding_units_minus1, return_status); |
1291 | 0 | ENTROPY_TRACE("num_decoding_units_minus1", ps_pt_sei->u4_num_decoding_units_minus1); |
1292 | |
|
1293 | 0 | PUT_BITS(ps_bitstrm, ps_pt_sei->u1_du_common_cpb_removal_delay_flag, 1, return_status); |
1294 | 0 | ENTROPY_TRACE( |
1295 | 0 | "du_common_cpb_removal_delay_flag", ps_pt_sei->u4_du_common_cpb_removal_delay_flag); |
1296 | |
|
1297 | 0 | if(1 == ps_pt_sei->u1_du_common_cpb_removal_delay_flag) |
1298 | 0 | { |
1299 | 0 | PUT_BITS( |
1300 | 0 | ps_bitstrm, |
1301 | 0 | ps_pt_sei->u4_du_common_cpb_removal_delay_increment_minus1, |
1302 | 0 | u1_du_cpb_removal_delay_increment_length, |
1303 | 0 | return_status); |
1304 | 0 | ENTROPY_TRACE( |
1305 | 0 | "du_common_cpb_removal_delay_increment_minus1", |
1306 | 0 | ps_pt_sei->u4_du_common_cpb_removal_delay_increment_minus1); |
1307 | 0 | } |
1308 | |
|
1309 | 0 | for(i = 0; i <= ps_pt_sei->u4_num_decoding_units_minus1; i++) |
1310 | 0 | { |
1311 | 0 | PUT_BITS_UEV(ps_bitstrm, ps_pt_sei->au4_num_nalus_in_du_minus1[0], return_status); |
1312 | 0 | ENTROPY_TRACE("num_nalus_in_du_minus1", ps_pt_sei->u4_num_nalus_in_du_minus1); |
1313 | |
|
1314 | 0 | if((1 != ps_pt_sei->u1_du_common_cpb_removal_delay_flag) && |
1315 | 0 | (i < ps_pt_sei->u4_num_decoding_units_minus1)) |
1316 | 0 | { |
1317 | 0 | PUT_BITS( |
1318 | 0 | ps_bitstrm, |
1319 | 0 | ps_pt_sei->au4_du_cpb_removal_delay_increment_minus1[0], |
1320 | 0 | u1_du_cpb_removal_delay_increment_length, |
1321 | 0 | return_status); |
1322 | 0 | ENTROPY_TRACE( |
1323 | 0 | "du_cpb_removal_delay_increment_minus1", |
1324 | 0 | ps_pt_sei->u4_du_cpb_removal_delay_increment_minus1); |
1325 | 0 | } |
1326 | 0 | } |
1327 | 0 | } |
1328 | 0 | } |
1329 | |
|
1330 | 0 | return (return_status); |
1331 | 0 | } |
1332 | | |
1333 | | /** |
1334 | | ****************************************************************************** |
1335 | | * |
1336 | | * @brief Generates Hash (Supplemental Enhancement Information ) |
1337 | | * |
1338 | | * @par Description |
1339 | | * Put hash sei params |
1340 | | * |
1341 | | * @param[in] ps_hash_sei_params |
1342 | | * pointer to structure containing hash SEI data |
1343 | | * |
1344 | | * @param[in] i1_decoded_pic_hash_sei_flag |
1345 | | * flag saying the hash SEI type |
1346 | | * |
1347 | | * @param[in] ps_bitstrm |
1348 | | * pointer to bitstream context (handle) |
1349 | | * |
1350 | | * @return success or failure error code |
1351 | | * |
1352 | | ****************************************************************************** |
1353 | | */ |
1354 | | WORD32 ihevce_put_hash_sei_params( |
1355 | | hash_sei_param_t *ps_hash_sei_params, WORD8 i1_decoded_pic_hash_sei_flag, bitstrm_t *ps_bitstrm) |
1356 | 0 | { |
1357 | 0 | UWORD32 i, c_idx, val; |
1358 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
1359 | 0 | UWORD8 u1_payload_size = 0; |
1360 | |
|
1361 | 0 | u1_payload_size += 1; /* hash_type */ |
1362 | |
|
1363 | 0 | if(1 == i1_decoded_pic_hash_sei_flag) |
1364 | 0 | { |
1365 | | /* MD5 : 3 color planes * 16 byte values */ |
1366 | 0 | u1_payload_size += (16 * 3); |
1367 | 0 | } |
1368 | 0 | else if(2 == i1_decoded_pic_hash_sei_flag) |
1369 | 0 | { |
1370 | | /* CRC : 3 color planes * 2 byte values */ |
1371 | 0 | u1_payload_size += (2 * 3); |
1372 | 0 | } |
1373 | 0 | else if(3 == i1_decoded_pic_hash_sei_flag) |
1374 | 0 | { |
1375 | | /* Checksum : 3 color planes * 4 byte values */ |
1376 | 0 | u1_payload_size += (4 * 3); |
1377 | 0 | } |
1378 | 0 | else |
1379 | 0 | { |
1380 | 0 | ASSERT(0); |
1381 | 0 | } |
1382 | | |
1383 | | /************************************************************************/ |
1384 | | /* PayloadSize : This is the size of the payload in bytes */ |
1385 | | /************************************************************************/ |
1386 | 0 | PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status); |
1387 | 0 | ENTROPY_TRACE("payload_size", u1_payload_size); |
1388 | | |
1389 | | /************************************************************************/ |
1390 | | /* Put the hash SEI parameters into the bitstream. For */ |
1391 | | /* details refer to section D.2.19 of the standard */ |
1392 | | /************************************************************************/ |
1393 | |
|
1394 | 0 | PUT_BITS(ps_bitstrm, (i1_decoded_pic_hash_sei_flag - 1), 8, return_status); |
1395 | 0 | ENTROPY_TRACE("hash_type", (i1_decoded_pic_hash_sei_flag - 1)); |
1396 | |
|
1397 | 0 | if(1 == i1_decoded_pic_hash_sei_flag) |
1398 | 0 | { |
1399 | 0 | for(c_idx = 0; c_idx < 3; c_idx++) |
1400 | 0 | { |
1401 | 0 | for(i = 0; i < 16; i++) |
1402 | 0 | { |
1403 | 0 | PUT_BITS(ps_bitstrm, ps_hash_sei_params->au1_sei_hash[c_idx][i], 8, return_status); |
1404 | 0 | ENTROPY_TRACE("picture_md5", ps_hash_sei_params->au1_sei_hash[c_idx][i]); |
1405 | 0 | } |
1406 | 0 | } |
1407 | 0 | } |
1408 | 0 | else if(2 == i1_decoded_pic_hash_sei_flag) |
1409 | 0 | { |
1410 | 0 | for(c_idx = 0; c_idx < 3; c_idx++) |
1411 | 0 | { |
1412 | 0 | val = (ps_hash_sei_params->au1_sei_hash[c_idx][0] << 8) + |
1413 | 0 | ps_hash_sei_params->au1_sei_hash[c_idx][1]; |
1414 | 0 | PUT_BITS(ps_bitstrm, val, 16, return_status); |
1415 | 0 | ENTROPY_TRACE("picture_crc", val); |
1416 | 0 | } |
1417 | 0 | } |
1418 | 0 | else if(3 == i1_decoded_pic_hash_sei_flag) |
1419 | 0 | { |
1420 | 0 | for(c_idx = 0; c_idx < 3; c_idx++) |
1421 | 0 | { |
1422 | 0 | val = (ps_hash_sei_params->au1_sei_hash[c_idx][0] << 24) + |
1423 | 0 | (ps_hash_sei_params->au1_sei_hash[c_idx][1] << 16) + |
1424 | 0 | (ps_hash_sei_params->au1_sei_hash[c_idx][2] << 8) + |
1425 | 0 | (ps_hash_sei_params->au1_sei_hash[c_idx][3]); |
1426 | |
|
1427 | 0 | PUT_BITS(ps_bitstrm, val, 32, return_status); |
1428 | 0 | ENTROPY_TRACE("picture_checksum", val); |
1429 | 0 | } |
1430 | 0 | } |
1431 | 0 | else |
1432 | 0 | { |
1433 | 0 | ASSERT(0); |
1434 | 0 | } |
1435 | | |
1436 | 0 | return (return_status); |
1437 | 0 | } |
1438 | | |
1439 | | /** |
1440 | | ****************************************************************************** |
1441 | | * |
1442 | | * @brief Generates SEI (Supplemental Enhancement Information ) |
1443 | | * |
1444 | | * @par Description |
1445 | | * Parse Supplemental Enhancement Information as per Section 7.3.2.4 |
1446 | | * |
1447 | | * @param[in] e_payload_type |
1448 | | * Determines the type of SEI msg |
1449 | | * |
1450 | | * @param[in] ps_bitstrm |
1451 | | * pointer to bitstream context (handle) |
1452 | | * |
1453 | | * @param[in] ps_sei_params |
1454 | | * pointer to structure containing SEI data |
1455 | | * buffer period, recovery point, picture timing |
1456 | | * |
1457 | | * @param[in] ps_vui_params |
1458 | | * pointer to structure containing VUI data |
1459 | | * |
1460 | | * @return success or failure error code |
1461 | | * |
1462 | | ****************************************************************************** |
1463 | | */ |
1464 | | WORD32 ihevce_put_sei_msg( |
1465 | | IHEVCE_SEI_TYPE e_payload_type, |
1466 | | sei_params_t *ps_sei_params, |
1467 | | vui_t *ps_vui_params, |
1468 | | bitstrm_t *ps_bitstrm, |
1469 | | UWORD32 i4_sei_payload_length, |
1470 | | UWORD8 *pu1_sei_payload) |
1471 | 0 | { |
1472 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
1473 | | /************************************************************************/ |
1474 | | /* PayloadType : Send in the SEI type in the stream */ |
1475 | | /************************************************************************/ |
1476 | 0 | UWORD32 u4_payload_type = e_payload_type; |
1477 | 0 | while(u4_payload_type > 0xFF) |
1478 | 0 | { |
1479 | 0 | PUT_BITS(ps_bitstrm, 0xFF, 8, return_status); |
1480 | 0 | u4_payload_type -= 0xFF; |
1481 | 0 | } |
1482 | 0 | PUT_BITS(ps_bitstrm, (UWORD32)u4_payload_type, 8, return_status); |
1483 | 0 | ENTROPY_TRACE("e_payload_type", e_payload_type); |
1484 | | |
1485 | | /************************************************************************/ |
1486 | | /* PayloadSize : This is sent from within the type specific functions */ |
1487 | | /************************************************************************/ |
1488 | |
|
1489 | 0 | switch(e_payload_type) |
1490 | 0 | { |
1491 | 0 | case IHEVCE_SEI_BUF_PERIOD_T: |
1492 | 0 | return_status |= ihevce_put_buf_period_sei_params( |
1493 | 0 | &(ps_sei_params->s_buf_period_sei_params), ps_vui_params, ps_bitstrm); |
1494 | 0 | break; |
1495 | | |
1496 | 0 | case IHEVCE_SEI_PIC_TIMING_T: |
1497 | 0 | return_status |= ihevce_put_pic_timing_sei_params( |
1498 | 0 | &(ps_sei_params->s_pic_timing_sei_params), ps_vui_params, ps_bitstrm); |
1499 | 0 | break; |
1500 | | |
1501 | 0 | case IHEVCE_SEI_RECOVERY_POINT_T: |
1502 | 0 | return_status |= ihevce_put_recovery_point_sei_params( |
1503 | 0 | &(ps_sei_params->s_recovery_point_params), ps_bitstrm); |
1504 | 0 | break; |
1505 | 0 | case IHEVCE_SEI_ACTIVE_PARAMETER_SETS_T: |
1506 | 0 | return_status |= ihevce_put_active_parameter_set_sei_params( |
1507 | 0 | &(ps_sei_params->s_active_parameter_set_sei_params), ps_bitstrm); |
1508 | 0 | break; |
1509 | 0 | case IHEVCE_SEI_DECODED_PICTURE_HASH_T: |
1510 | 0 | return_status |= ihevce_put_hash_sei_params( |
1511 | 0 | &(ps_sei_params->s_hash_sei_params), |
1512 | 0 | ps_sei_params->i1_decoded_pic_hash_sei_flag, |
1513 | 0 | ps_bitstrm); |
1514 | 0 | break; |
1515 | 0 | case IHEVCE_SEI_MASTERING_DISP_COL_VOL_T: |
1516 | 0 | return_status |= ihevce_put_mastering_disp_col_vol_sei_params( |
1517 | 0 | &(ps_sei_params->s_mastering_dis_col_vol_sei_params), ps_bitstrm); |
1518 | 0 | break; |
1519 | 0 | case IHEVCE_SEI_CONTENT_LIGHT_LEVEL_DATA_T: |
1520 | 0 | return_status |= ihevce_put_cll_info_sei_params( |
1521 | 0 | ps_sei_params->s_cll_info_sei_params.u2_sei_avg_cll, |
1522 | 0 | ps_sei_params->s_cll_info_sei_params.u2_sei_max_cll, |
1523 | 0 | ps_bitstrm); |
1524 | 0 | break; |
1525 | | //case IHEVCE_SEI_USER_DATA_REGISTERED_ITU_T_T35_T: |
1526 | | //return_status |= ihevce_put_sei_params(i4_sei_payload_length, pu1_sei_payload, ps_bitstrm); |
1527 | | //break; |
1528 | 0 | default: |
1529 | | //Any Payload type other than the above cases will entred hereand be added to the bitstream |
1530 | 0 | return_status |= ihevce_put_sei_params(i4_sei_payload_length, pu1_sei_payload, ps_bitstrm); |
1531 | | //return_status = IHEVCE_FAIL; |
1532 | 0 | } |
1533 | | |
1534 | 0 | ASSERT(IHEVCE_SUCCESS == return_status); |
1535 | | |
1536 | | /* rbsp trailing bits */ |
1537 | 0 | if((IHEVCE_SUCCESS == return_status) && (ps_bitstrm->i4_bits_left_in_cw & 0x7)) |
1538 | 0 | ihevce_put_rbsp_trailing_bits(ps_bitstrm); |
1539 | |
|
1540 | 0 | return (return_status); |
1541 | 0 | } |
1542 | | |
1543 | | /** |
1544 | | ****************************************************************************** |
1545 | | * |
1546 | | * @brief Generates SEI (Supplemental Enhancement Information ) |
1547 | | * |
1548 | | * @par Description |
1549 | | * Parse Supplemental Enhancement Information as per Section 7.3.2.4 |
1550 | | * |
1551 | | * @param[in] ps_bitstrm |
1552 | | * pointer to bitstream context (handle) |
1553 | | * |
1554 | | * @param[in] ps_sei_params |
1555 | | * pointer to structure containing SEI data |
1556 | | * buffer period, recovery point, picture timing |
1557 | | * |
1558 | | * @param[in] ps_vui_params |
1559 | | * pointer to structure containing VUI data |
1560 | | * |
1561 | | * @param[in] nal_unit_header |
1562 | | * NAL_PREFIX_SEI / NAL_SUFFIX_SEI |
1563 | | * |
1564 | | * @param[in] u4_num_sei_payloads |
1565 | | * Number of SEI payloads |
1566 | | * |
1567 | | * @param[in] ps_sei_payload |
1568 | | * pointer to structure containing SEI payload data |
1569 | | * |
1570 | | * @return success or failure error code |
1571 | | * |
1572 | | ****************************************************************************** |
1573 | | */ |
1574 | | WORD32 ihevce_generate_sei( |
1575 | | bitstrm_t *ps_bitstrm, |
1576 | | sei_params_t *ps_sei_params, |
1577 | | vui_t *ps_vui_params, |
1578 | | WORD32 insert_per_cra, |
1579 | | WORD32 nal_unit_header, |
1580 | | UWORD32 u4_num_sei_payloads, |
1581 | | sei_payload_t *ps_sei_payload) |
1582 | 0 | { |
1583 | 0 | UWORD32 u4_i; |
1584 | 0 | WORD32 return_status = IHEVCE_SUCCESS; |
1585 | |
|
1586 | 0 | (void)insert_per_cra; |
1587 | | /* Insert Start Code */ |
1588 | 0 | return_status = ihevce_put_nal_start_code_prefix(ps_bitstrm, 1); |
1589 | |
|
1590 | 0 | ASSERT((NAL_PREFIX_SEI == nal_unit_header) || (NAL_SUFFIX_SEI == nal_unit_header)); |
1591 | | /* Insert Nal Unit Header */ |
1592 | 0 | return_status |= ihevce_generate_nal_unit_header(ps_bitstrm, nal_unit_header, 0); |
1593 | |
|
1594 | 0 | if(NAL_PREFIX_SEI == nal_unit_header) |
1595 | 0 | { |
1596 | | /* Active Parameter and Buffering period insertion */ |
1597 | |
|
1598 | 0 | if(ps_sei_params->i1_buf_period_params_present_flag) |
1599 | 0 | { |
1600 | | /* insert active_parameter_set SEI required if buffering period SEI messages are inserted */ |
1601 | 0 | return_status |= ihevce_put_sei_msg( |
1602 | 0 | IHEVCE_SEI_ACTIVE_PARAMETER_SETS_T, |
1603 | 0 | ps_sei_params, |
1604 | 0 | ps_vui_params, |
1605 | 0 | ps_bitstrm, |
1606 | 0 | 0, |
1607 | 0 | NULL); |
1608 | | |
1609 | | /*************************************************************************************************/ |
1610 | | /* NOTE: Need to terminate and start new SEI message after active parameter set SEI */ |
1611 | | /* Buffering period/pic timing SEI refering to active SPS cannot be embedded in same SEI message */ |
1612 | | /* This is because SPS is activated in HM decoder after completely parsing full SEI message. */ |
1613 | | /*************************************************************************************************/ |
1614 | 0 | if(1) /* Insert New SEI for buffering period after active parameter set SEI */ |
1615 | 0 | { |
1616 | 0 | ihevce_put_rbsp_trailing_bits(ps_bitstrm); |
1617 | | |
1618 | | /* Insert Next SEI Start Code */ |
1619 | 0 | return_status = ihevce_put_nal_start_code_prefix(ps_bitstrm, 1); |
1620 | | |
1621 | | /* Insert Next SEI Nal Unit Header */ |
1622 | 0 | return_status |= ihevce_generate_nal_unit_header(ps_bitstrm, nal_unit_header, 0); |
1623 | 0 | } |
1624 | | |
1625 | | /* Buffering Period SEI meassage for all IDR, CRA pics */ |
1626 | 0 | return_status |= ihevce_put_sei_msg( |
1627 | 0 | IHEVCE_SEI_BUF_PERIOD_T, ps_sei_params, ps_vui_params, ps_bitstrm, 0, NULL); |
1628 | 0 | } |
1629 | | |
1630 | | /* Pic timing SEI meassage for non IDR, non CRA pics */ |
1631 | 0 | if(ps_sei_params->i1_pic_timing_params_present_flag) |
1632 | 0 | { |
1633 | 0 | return_status |= ihevce_put_sei_msg( |
1634 | 0 | IHEVCE_SEI_PIC_TIMING_T, ps_sei_params, ps_vui_params, ps_bitstrm, 0, NULL); |
1635 | 0 | } |
1636 | | |
1637 | | /* Recovery point SEI meassage for all IDR, CRA pics */ |
1638 | 0 | if(ps_sei_params->i1_recovery_point_params_present_flag) |
1639 | 0 | { |
1640 | 0 | return_status |= ihevce_put_sei_msg( |
1641 | 0 | IHEVCE_SEI_RECOVERY_POINT_T, ps_sei_params, ps_vui_params, ps_bitstrm, 0, NULL); |
1642 | 0 | } |
1643 | | |
1644 | | /* Mastering Display Colour SEI for all IDR, CRA pics */ |
1645 | 0 | if(ps_sei_params->i4_sei_mastering_disp_colour_vol_params_present_flags) |
1646 | 0 | { |
1647 | 0 | return_status |= ihevce_put_sei_msg( |
1648 | 0 | IHEVCE_SEI_MASTERING_DISP_COL_VOL_T, |
1649 | 0 | ps_sei_params, |
1650 | 0 | ps_vui_params, |
1651 | 0 | ps_bitstrm, |
1652 | 0 | 0, |
1653 | 0 | NULL); |
1654 | 0 | } |
1655 | | /*Registered User Data*/ |
1656 | 0 | for(u4_i = 0; u4_i < u4_num_sei_payloads; u4_i++) |
1657 | 0 | { |
1658 | 0 | return_status |= ihevce_put_sei_msg( |
1659 | 0 | (IHEVCE_SEI_TYPE)(ps_sei_payload[u4_i].u4_payload_type), |
1660 | 0 | ps_sei_params, |
1661 | 0 | ps_vui_params, |
1662 | 0 | ps_bitstrm, |
1663 | 0 | ps_sei_payload[u4_i].u4_payload_length, |
1664 | 0 | ps_sei_payload[u4_i].pu1_sei_payload); |
1665 | 0 | } |
1666 | | /* Content Light Level Information*/ |
1667 | 0 | if(ps_sei_params->i1_sei_cll_enable) |
1668 | 0 | { |
1669 | 0 | return_status |= ihevce_put_sei_msg( |
1670 | 0 | IHEVCE_SEI_CONTENT_LIGHT_LEVEL_DATA_T, |
1671 | 0 | ps_sei_params, |
1672 | 0 | ps_vui_params, |
1673 | 0 | ps_bitstrm, |
1674 | 0 | 0, |
1675 | 0 | NULL); |
1676 | 0 | } |
1677 | 0 | } |
1678 | 0 | else if(NAL_SUFFIX_SEI == nal_unit_header) |
1679 | 0 | { |
1680 | | /* Insert hash SEI */ |
1681 | 0 | if(ps_sei_params->i1_decoded_pic_hash_sei_flag) |
1682 | 0 | { |
1683 | 0 | return_status |= ihevce_put_sei_msg( |
1684 | 0 | IHEVCE_SEI_DECODED_PICTURE_HASH_T, |
1685 | 0 | ps_sei_params, |
1686 | 0 | ps_vui_params, |
1687 | 0 | ps_bitstrm, |
1688 | 0 | 0, |
1689 | 0 | NULL); |
1690 | 0 | } |
1691 | 0 | } |
1692 | | |
1693 | | /*put trailing bits to indicate end of sei*/ |
1694 | 0 | ihevce_put_rbsp_trailing_bits(ps_bitstrm); |
1695 | |
|
1696 | 0 | return return_status; |
1697 | 0 | } |
1698 | | |
1699 | | /** |
1700 | | ****************************************************************************** |
1701 | | * |
1702 | | * @brief Populates ihevce_populate_mastering_disp_col_vol_sei of SEI structure |
1703 | | * |
1704 | | * @par Description |
1705 | | * Populates mastering display colour volume sei structure |
1706 | | * |
1707 | | * @param[in] ps_sei |
1708 | | * pointer to sei params that needs to be populated |
1709 | | * |
1710 | | * @param[in] ps_out_strm_prms |
1711 | | * pointer to output stream params |
1712 | | * |
1713 | | * @return success or failure error code |
1714 | | * |
1715 | | ****************************************************************************** |
1716 | | */ |
1717 | | WORD32 ihevce_populate_mastering_disp_col_vol_sei( |
1718 | | sei_params_t *ps_sei, ihevce_out_strm_params_t *ps_out_strm_prms) |
1719 | 0 | { |
1720 | 0 | WORD32 i; |
1721 | |
|
1722 | 0 | mastering_dis_col_vol_sei_params_t *ps_mastering_dis_col_vol_sei_params = |
1723 | 0 | &ps_sei->s_mastering_dis_col_vol_sei_params; |
1724 | |
|
1725 | 0 | for(i = 0; i < 3; i++) |
1726 | 0 | { |
1727 | 0 | ps_mastering_dis_col_vol_sei_params->au2_display_primaries_x[i] = |
1728 | 0 | ps_out_strm_prms->au2_display_primaries_x[i]; |
1729 | 0 | ps_mastering_dis_col_vol_sei_params->au2_display_primaries_y[i] = |
1730 | 0 | ps_out_strm_prms->au2_display_primaries_y[i]; |
1731 | 0 | } |
1732 | |
|
1733 | 0 | ps_mastering_dis_col_vol_sei_params->u2_white_point_x = ps_out_strm_prms->u2_white_point_x; |
1734 | 0 | ps_mastering_dis_col_vol_sei_params->u2_white_point_y = ps_out_strm_prms->u2_white_point_y; |
1735 | |
|
1736 | 0 | ps_mastering_dis_col_vol_sei_params->u4_max_display_mastering_luminance = |
1737 | 0 | ps_out_strm_prms->u4_max_display_mastering_luminance; |
1738 | 0 | ps_mastering_dis_col_vol_sei_params->u4_min_display_mastering_luminance = |
1739 | 0 | ps_out_strm_prms->u4_min_display_mastering_luminance; |
1740 | |
|
1741 | 0 | return IHEVCE_SUCCESS; |
1742 | 0 | } |
1743 | | |
1744 | | /** |
1745 | | ****************************************************************************** |
1746 | | * |
1747 | | * @brief Populates ihevce_populate_recovery_point_sei of SEI structure |
1748 | | * |
1749 | | * @par Description |
1750 | | * Populates vui structure for its use in header generation |
1751 | | * |
1752 | | * @param[out] ps_sei |
1753 | | * pointer to sei params that needs to be populated |
1754 | | * |
1755 | | * @param[out] ps_vui |
1756 | | * pointer to vui params referred by sei |
1757 | | * |
1758 | | * @param[out] ps_sps |
1759 | | * pointer to sps params referred by sei |
1760 | | * |
1761 | | * @param[in] ps_src_params |
1762 | | * pointer to source config params; resolution, frame rate etc |
1763 | | * |
1764 | | * @param[in] ps_config_prms |
1765 | | * pointer to configuration params like bitrate, HRD buffer sizes, cu, tu sizes |
1766 | | * |
1767 | | * @return success or failure error code |
1768 | | * |
1769 | | ****************************************************************************** |
1770 | | */ |
1771 | | WORD32 ihevce_populate_recovery_point_sei( |
1772 | | sei_params_t *ps_sei, ihevce_vui_sei_params_t *ps_vui_sei_prms) |
1773 | 0 | { |
1774 | 0 | recovery_point_sei_params_t *ps_rec_point_params = &ps_sei->s_recovery_point_params; |
1775 | |
|
1776 | 0 | (void)ps_vui_sei_prms; |
1777 | 0 | ps_rec_point_params->i4_recovery_poc_cnt = 0; |
1778 | 0 | ps_rec_point_params->u1_broken_link_flag = 0; |
1779 | 0 | ps_rec_point_params->u1_exact_match_flag = 1; |
1780 | |
|
1781 | 0 | return IHEVCE_SUCCESS; |
1782 | 0 | } |
1783 | | |
1784 | | /** |
1785 | | ****************************************************************************** |
1786 | | * |
1787 | | * @brief Populates picture timing of SEI structure |
1788 | | * |
1789 | | * @par Description |
1790 | | * Populates vui structure for its use in header generation |
1791 | | * |
1792 | | * @param[out] ps_sei |
1793 | | * pointer to sei params that needs to be populated |
1794 | | * |
1795 | | * @param[out] ps_vui |
1796 | | * pointer to vui params referred by sei |
1797 | | * |
1798 | | * @param[in] ps_src_params |
1799 | | * pointer to source config params; resolution, frame rate etc |
1800 | | * |
1801 | | * @param[in] u4_bottom_field_flag |
1802 | | * Used only for interlaced field coding. 0:top field, 1:bottom field |
1803 | | * |
1804 | | * @return success or failure error code |
1805 | | * |
1806 | | ****************************************************************************** |
1807 | | */ |
1808 | | WORD32 ihevce_populate_picture_timing_sei( |
1809 | | sei_params_t *ps_sei, |
1810 | | vui_t *ps_vui, |
1811 | | ihevce_src_params_t *ps_src_params, |
1812 | | WORD32 u4_bottom_field_flag) |
1813 | 0 | { |
1814 | 0 | pic_timing_sei_params_t *ps_pic_timing_params = &ps_sei->s_pic_timing_sei_params; |
1815 | 0 | UWORD8 u1_prog_seq = !ps_src_params->i4_field_pic; |
1816 | 0 | UWORD8 u1_top_field_first = 1; //ps_curr_inp->s_input_buf.i4_topfield_first; |
1817 | |
|
1818 | 0 | UWORD8 u1_repeat_first_field = 0; |
1819 | 0 | WORD32 field_seq_flag = ps_vui->u1_field_seq_flag; |
1820 | |
|
1821 | 0 | if(ps_vui->u1_frame_field_info_present_flag) |
1822 | 0 | { |
1823 | | /**************************************************************************/ |
1824 | | /* Refer Table D-1 */ |
1825 | | /**************************************************************************/ |
1826 | 0 | if(0 == u1_prog_seq) |
1827 | 0 | { |
1828 | 0 | if(field_seq_flag) |
1829 | 0 | { |
1830 | 0 | ASSERT((u4_bottom_field_flag == 0) || (u4_bottom_field_flag == 1)); |
1831 | | |
1832 | | /* 1 => top field pic */ |
1833 | | /* 2 => bottom field pic */ |
1834 | 0 | ps_pic_timing_params->u4_pic_struct = 1 + u4_bottom_field_flag; |
1835 | 0 | } |
1836 | 0 | else if(0 == u1_repeat_first_field) |
1837 | 0 | { |
1838 | | /******************************************************************/ |
1839 | | /* [PROGRESSIVE SEQ] = 0; */ |
1840 | | /* [MPEG2 PIC STRUCT] = FIELD_PICTURE */ |
1841 | | /* [REPEAT_FIRST_FIELD] = 0 */ |
1842 | | /* u1_pic_struct = 3 => top - bottom field pic */ |
1843 | | /* u1_pic_struct = 4 => bottom - top */ |
1844 | | /******************************************************************/ |
1845 | 0 | ps_pic_timing_params->u4_pic_struct = 4 - u1_top_field_first; |
1846 | 0 | } |
1847 | 0 | else |
1848 | 0 | { |
1849 | | /******************************************************************/ |
1850 | | /* [PROGRESSIVE SEQ] = 0; */ |
1851 | | /* [MPEG2 PIC STRUCT] = FIELD_PICTURE */ |
1852 | | /* [REPEAT_FIRST_FIELD] = 1 */ |
1853 | | /* u1_pic_struct = 5 => top - bottom - top */ |
1854 | | /* u1_pic_struct = 6 => bottom - top - bottom */ |
1855 | | /******************************************************************/ |
1856 | 0 | ps_pic_timing_params->u4_pic_struct = 6 - u1_top_field_first; |
1857 | 0 | } |
1858 | 0 | } |
1859 | 0 | else |
1860 | 0 | { |
1861 | 0 | if(0 == u1_repeat_first_field) |
1862 | 0 | { |
1863 | | /******************************************************************/ |
1864 | | /* [PROGRESSIVE SEQ] = 1; */ |
1865 | | /* [MPEG2 PIC STRUCT] = FRAME_PICTURE */ |
1866 | | /* u1_pic_struct = 0 => frame picture (no repeat) */ |
1867 | | /******************************************************************/ |
1868 | 0 | ps_pic_timing_params->u4_pic_struct = 0; |
1869 | 0 | } |
1870 | 0 | else |
1871 | 0 | { |
1872 | | /******************************************************************/ |
1873 | | /* [PROGRESSIVE SEQ] = 1; */ |
1874 | | /* [MPEG2 PIC STRUCT] = FRAME_PICTURE */ |
1875 | | /* u1_pic_struct = 7 => frame picture (repeat once) */ |
1876 | | /* u1_pic_struct = 8 => frame picture (repeat twice) */ |
1877 | | /******************************************************************/ |
1878 | 0 | ps_pic_timing_params->u4_pic_struct = 7 + u1_top_field_first; |
1879 | 0 | } |
1880 | 0 | } |
1881 | | /* Porogressive frame - 1 ; Interlace - 0 */ |
1882 | 0 | ps_pic_timing_params->u4_source_scan_type = !ps_src_params->i4_field_pic; |
1883 | |
|
1884 | 0 | ps_pic_timing_params->u1_duplicate_flag = 0; |
1885 | 0 | } |
1886 | 0 | ps_pic_timing_params->u4_pic_dpb_output_du_delay = 0; |
1887 | |
|
1888 | 0 | ps_pic_timing_params->u4_num_decoding_units_minus1 = 1; |
1889 | |
|
1890 | 0 | ps_pic_timing_params->u1_du_common_cpb_removal_delay_flag = 1; |
1891 | |
|
1892 | 0 | ps_pic_timing_params->u4_du_common_cpb_removal_delay_increment_minus1 = 1; |
1893 | |
|
1894 | 0 | ps_pic_timing_params->au4_num_nalus_in_du_minus1[0] = 1; |
1895 | |
|
1896 | 0 | ps_pic_timing_params->au4_du_cpb_removal_delay_increment_minus1[0] = 1; |
1897 | |
|
1898 | 0 | return IHEVCE_SUCCESS; |
1899 | 0 | } |
1900 | | |
1901 | | /** |
1902 | | ****************************************************************************** |
1903 | | * |
1904 | | * @brief Populates buffer period of sei structure |
1905 | | * |
1906 | | * @par Description |
1907 | | * Populates vui structure for its use in header generation |
1908 | | * |
1909 | | * @param[out] ps_sei |
1910 | | * pointer to sei params that needs to be populated |
1911 | | * |
1912 | | * @param[out] ps_vui |
1913 | | * pointer to vui params referred by sei |
1914 | | * |
1915 | | * @param[out] ps_sps |
1916 | | * pointer to sps params referred by sei |
1917 | | * |
1918 | | * @param[out] ps_vui_sei_prms |
1919 | | * pointer to sps params referred by application |
1920 | | * |
1921 | | * @return success or failure error code |
1922 | | * |
1923 | | ****************************************************************************** |
1924 | | */ |
1925 | | WORD32 ihevce_populate_buffering_period_sei( |
1926 | | sei_params_t *ps_sei, vui_t *ps_vui, sps_t *ps_sps, ihevce_vui_sei_params_t *ps_vui_sei_prms) |
1927 | 0 | { |
1928 | 0 | WORD32 i; |
1929 | |
|
1930 | 0 | buf_period_sei_params_t *ps_bp_sei = &ps_sei->s_buf_period_sei_params; |
1931 | |
|
1932 | 0 | WORD32 i1_sps_max_sub_layersminus1 = ps_sps->i1_sps_max_sub_layers - 1; |
1933 | |
|
1934 | 0 | hrd_params_t *ps_vui_hrd_parameters = &ps_vui->s_vui_hrd_parameters; |
1935 | |
|
1936 | 0 | sub_lyr_hrd_params_t *ps_sub_layer_hrd_params = |
1937 | 0 | &ps_vui_hrd_parameters->as_sub_layer_hrd_params[i1_sps_max_sub_layersminus1]; |
1938 | |
|
1939 | 0 | WORD32 cpb_cnt = ps_vui_hrd_parameters->au1_cpb_cnt_minus1[i1_sps_max_sub_layersminus1]; |
1940 | |
|
1941 | 0 | WORD32 cpb_size, bit_rate; |
1942 | |
|
1943 | 0 | (void)ps_vui_sei_prms; |
1944 | 0 | ps_bp_sei->u1_bp_seq_parameter_set_id = ps_sps->i1_sps_id; |
1945 | |
|
1946 | 0 | ps_bp_sei->u4_initial_cpb_removal_delay_length = |
1947 | 0 | ps_vui->s_vui_hrd_parameters.u1_initial_cpb_removal_delay_length_minus1 + 1; |
1948 | |
|
1949 | 0 | ps_bp_sei->u1_sub_pic_cpb_params_present_flag = |
1950 | 0 | ps_vui_hrd_parameters->u1_sub_pic_cpb_params_present_flag; |
1951 | |
|
1952 | 0 | ps_bp_sei->u1_rap_cpb_params_present_flag = 0; //DEFAULT value |
1953 | |
|
1954 | 0 | ps_bp_sei->u4_cpb_delay_offset = 0; //DEFAULT value |
1955 | 0 | ps_bp_sei->u4_dpb_delay_offset = 0; //DEFAULT value |
1956 | |
|
1957 | 0 | ps_bp_sei->u1_concatenation_flag = 0; //DEFAULT value ??? |
1958 | 0 | ps_bp_sei->u4_au_cpb_removal_delay_delta_minus1 = 0; //DEFAULT value ??? |
1959 | |
|
1960 | 0 | ps_bp_sei->u4_cpb_cnt = cpb_cnt; |
1961 | |
|
1962 | 0 | if(ps_vui->s_vui_hrd_parameters.u1_nal_hrd_parameters_present_flag) |
1963 | 0 | { |
1964 | 0 | for(i = 0; i <= cpb_cnt; i++) |
1965 | 0 | { |
1966 | 0 | ULWORD64 u8_temp; |
1967 | 0 | if(1 == ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag) |
1968 | 0 | { |
1969 | 0 | ASSERT(1 == ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag); |
1970 | | |
1971 | 0 | cpb_size = (ps_sub_layer_hrd_params->au4_cpb_size_du_value_minus1[i] + 1) * |
1972 | 0 | (1 << (4 + ps_vui_hrd_parameters->u4_cpb_size_du_scale)); |
1973 | |
|
1974 | 0 | bit_rate = (ps_sub_layer_hrd_params->au4_bit_rate_du_value_minus1[i] + 1) * |
1975 | 0 | (1 << (6 + ps_vui_hrd_parameters->u4_bit_rate_scale)); |
1976 | 0 | } |
1977 | 0 | else |
1978 | 0 | { |
1979 | 0 | cpb_size = (ps_sub_layer_hrd_params->au4_cpb_size_value_minus1[i] + 1) * |
1980 | 0 | (1 << (4 + ps_vui_hrd_parameters->u4_cpb_size_scale)); |
1981 | |
|
1982 | 0 | bit_rate = (ps_sub_layer_hrd_params->au4_bit_rate_value_minus1[i] + 1) * |
1983 | 0 | (1 << (6 + ps_vui_hrd_parameters->u4_bit_rate_scale)); |
1984 | 0 | } |
1985 | | |
1986 | 0 | u8_temp = (ULWORD64)(90000 * (ULWORD64)cpb_size); |
1987 | 0 | ps_bp_sei->au4_nal_initial_cpb_removal_delay[i] = (UWORD32)(u8_temp / bit_rate); |
1988 | |
|
1989 | 0 | ps_bp_sei->au4_nal_initial_cpb_removal_delay_offset[i] = 0; |
1990 | |
|
1991 | 0 | if(ps_bp_sei->u1_rap_cpb_params_present_flag || |
1992 | 0 | ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag) |
1993 | 0 | { |
1994 | 0 | ps_bp_sei->au4_nal_initial_alt_cpb_removal_delay[i] = (UWORD32)(u8_temp / bit_rate); |
1995 | 0 | ps_bp_sei->au4_nal_initial_cpb_removal_delay_offset[i] = 0; |
1996 | 0 | } |
1997 | 0 | } |
1998 | 0 | } |
1999 | | |
2000 | 0 | if(ps_vui->s_vui_hrd_parameters.u1_vcl_hrd_parameters_present_flag) |
2001 | 0 | { |
2002 | 0 | for(i = 0; i <= cpb_cnt; i++) |
2003 | 0 | { |
2004 | 0 | if(1 == ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag) |
2005 | 0 | { |
2006 | 0 | ASSERT(1 == ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag); |
2007 | 0 | cpb_size = (ps_sub_layer_hrd_params->au4_cpb_size_du_value_minus1[i] + 1) * |
2008 | 0 | (1 << (4 + ps_vui_hrd_parameters->u4_cpb_size_du_scale)); |
2009 | |
|
2010 | 0 | bit_rate = (ps_sub_layer_hrd_params->au4_bit_rate_du_value_minus1[i] + 1) * |
2011 | 0 | (1 << (6 + ps_vui_hrd_parameters->u4_bit_rate_scale)); |
2012 | 0 | } |
2013 | 0 | else |
2014 | 0 | { |
2015 | 0 | cpb_size = (ps_sub_layer_hrd_params->au4_cpb_size_value_minus1[i] + 1) * |
2016 | 0 | (1 << (4 + ps_vui_hrd_parameters->u4_cpb_size_scale)); |
2017 | |
|
2018 | 0 | bit_rate = (ps_sub_layer_hrd_params->au4_bit_rate_value_minus1[i] + 1) * |
2019 | 0 | (1 << (6 + ps_vui_hrd_parameters->u4_bit_rate_scale)); |
2020 | 0 | } |
2021 | | |
2022 | 0 | ps_bp_sei->au4_vcl_initial_cpb_removal_delay[i] = 90000 * (cpb_size / bit_rate); |
2023 | |
|
2024 | 0 | ps_bp_sei->au4_vcl_initial_cpb_removal_delay_offset[i] = 0; |
2025 | |
|
2026 | 0 | if(ps_bp_sei->u1_rap_cpb_params_present_flag || |
2027 | 0 | ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag) |
2028 | 0 | { |
2029 | 0 | ps_bp_sei->au4_vcl_initial_alt_cpb_removal_delay[i] = 90000 * (cpb_size / bit_rate); |
2030 | 0 | ps_bp_sei->au4_vcl_initial_cpb_removal_delay_offset[i] = 0; |
2031 | 0 | } |
2032 | 0 | } |
2033 | 0 | } |
2034 | | |
2035 | | /* Reset picture timing cbp removal delay at every insertion Buffering period SEI */ |
2036 | | //ps_sei->s_pic_timing_sei_params.u4_au_cpb_removal_delay_minus1 = 0; |
2037 | | |
2038 | 0 | return IHEVCE_SUCCESS; |
2039 | 0 | } |
2040 | | |
2041 | | /** |
2042 | | ****************************************************************************** |
2043 | | * |
2044 | | * @brief Populates active parameter set sei structure |
2045 | | * |
2046 | | * @par Description |
2047 | | * |
2048 | | * @param[out] ps_sei |
2049 | | * pointer to sei params that needs to be populated |
2050 | | * |
2051 | | * @param[in] ps_vps |
2052 | | * pointer to configuration vps_t. |
2053 | | * |
2054 | | * @return success or failure error code |
2055 | | * |
2056 | | ***************************************************************************** |
2057 | | */ |
2058 | | WORD32 ihevce_populate_active_parameter_set_sei(sei_params_t *ps_sei, vps_t *ps_vps, sps_t *ps_sps) |
2059 | 0 | { |
2060 | 0 | UWORD8 i; |
2061 | 0 | active_parameter_set_sei_param_t *ps_act_sei = &ps_sei->s_active_parameter_set_sei_params; |
2062 | |
|
2063 | 0 | (void)ps_sps; |
2064 | 0 | ps_act_sei->u1_active_video_parameter_set_id = ps_vps->i1_vps_id; |
2065 | 0 | ps_act_sei->u1_self_contained_cvs_flag = 0; |
2066 | 0 | ps_act_sei->u1_no_parameter_set_update_flag = 1; |
2067 | 0 | ps_act_sei->u1_num_sps_ids_minus1 = 0; |
2068 | 0 | for(i = 0; i <= ps_act_sei->u1_num_sps_ids_minus1; i++) |
2069 | 0 | { |
2070 | 0 | ps_act_sei->au1_active_seq_parameter_set_id[i] = 0; |
2071 | 0 | } |
2072 | |
|
2073 | 0 | return IHEVCE_SUCCESS; |
2074 | 0 | } |
2075 | | |
2076 | | /** |
2077 | | ****************************************************************************** |
2078 | | * |
2079 | | * @brief Populates Hash SEI values for CRC Hash |
2080 | | * |
2081 | | * @par Description |
2082 | | * |
2083 | | * @param[out] ps_hash_sei_params |
2084 | | * pointer to hash sei params that needs to be populated |
2085 | | * |
2086 | | * @param[in] bit_depth |
2087 | | * i4_internal_bit_depth value. Assume same for Luma & Chroma |
2088 | | * |
2089 | | * @param[in] pv_y_buf |
2090 | | * Pointer to decoded/recon Luma buffer |
2091 | | * |
2092 | | * @param[in] y_wd |
2093 | | * pic width in luma samples |
2094 | | * |
2095 | | * @param[in] y_ht |
2096 | | * pic height in luma samples |
2097 | | * |
2098 | | * @param[in] y_strd |
2099 | | * Stride of luma buffer |
2100 | | * |
2101 | | * @param[in] pv_u_buf |
2102 | | * Pointer to decoded/recon Chroma buffer |
2103 | | * |
2104 | | * @param[in] uv_wd |
2105 | | * pic width in luma samples / SubWidthC |
2106 | | * |
2107 | | * @param[in] uv_ht |
2108 | | * pic height in luma samples / SubHeightC |
2109 | | * |
2110 | | * @param[in] uv_strd |
2111 | | * Stride of chroma buffer |
2112 | | * |
2113 | | * @return None |
2114 | | * |
2115 | | ***************************************************************************** |
2116 | | */ |
2117 | | static void ihevce_calc_CRC( |
2118 | | hash_sei_param_t *ps_hash_sei_params, |
2119 | | WORD32 bit_depth, |
2120 | | void *pv_y_buf, |
2121 | | WORD32 y_wd, |
2122 | | WORD32 y_ht, |
2123 | | WORD32 y_strd, |
2124 | | void *pv_u_buf, |
2125 | | WORD32 uv_wd, |
2126 | | WORD32 uv_ht, |
2127 | | WORD32 uv_strd) |
2128 | 0 | { |
2129 | 0 | WORD32 x, y, bit_idx, is_gt8bit = 0, gt8bit_mul; |
2130 | 0 | UWORD8 *pu_buf; |
2131 | | |
2132 | | /* For this to work, assumes little endian in case of HBD */ |
2133 | 0 | if(bit_depth > 8) |
2134 | 0 | is_gt8bit = 1; |
2135 | 0 | gt8bit_mul = 1 + is_gt8bit; |
2136 | | |
2137 | | /* Luma CRC */ |
2138 | 0 | { |
2139 | 0 | UWORD32 u4_crc_val = 0xffff; |
2140 | |
|
2141 | 0 | pu_buf = (UWORD8 *)pv_y_buf; |
2142 | |
|
2143 | 0 | for(y = 0; y < y_ht; y++) |
2144 | 0 | { |
2145 | 0 | for(x = 0; x < y_wd; x++) |
2146 | 0 | { |
2147 | | // take CRC of first pictureData byte |
2148 | 0 | for(bit_idx = 0; bit_idx < 8; bit_idx++) |
2149 | 0 | { |
2150 | 0 | CALC_CRC_BIT_LEVEL( |
2151 | 0 | u4_crc_val, pu_buf[y * (y_strd * gt8bit_mul) + (x * gt8bit_mul)], bit_idx); |
2152 | 0 | } |
2153 | | // take CRC of second pictureData byte if bit depth is greater than 8-bits |
2154 | 0 | if(bit_depth > 8) |
2155 | 0 | { |
2156 | 0 | for(bit_idx = 0; bit_idx < 8; bit_idx++) |
2157 | 0 | { |
2158 | 0 | CALC_CRC_BIT_LEVEL( |
2159 | 0 | u4_crc_val, |
2160 | 0 | pu_buf[y * (y_strd * gt8bit_mul) + (x * gt8bit_mul + 1)], |
2161 | 0 | bit_idx); |
2162 | 0 | } |
2163 | 0 | } |
2164 | 0 | } |
2165 | 0 | } |
2166 | |
|
2167 | 0 | for(bit_idx = 0; bit_idx < 16; bit_idx++) |
2168 | 0 | { |
2169 | 0 | UWORD32 u4_crc_msb = (u4_crc_val >> 15) & 1; |
2170 | 0 | u4_crc_val = ((u4_crc_val << 1) & 0xffff) ^ (u4_crc_msb * 0x1021); |
2171 | 0 | } |
2172 | |
|
2173 | 0 | ps_hash_sei_params->au1_sei_hash[0][0] = (u4_crc_val >> 8) & 0xff; |
2174 | 0 | ps_hash_sei_params->au1_sei_hash[0][1] = u4_crc_val & 0xff; |
2175 | 0 | } |
2176 | | |
2177 | | /* Cb & Cr CRC */ |
2178 | 0 | { |
2179 | 0 | UWORD32 u4_crc_val_u = 0xffff, u4_crc_val_v = 0xffff; |
2180 | |
|
2181 | 0 | pu_buf = (UWORD8 *)pv_u_buf; |
2182 | |
|
2183 | 0 | for(y = 0; y < uv_ht; y++) |
2184 | 0 | { |
2185 | 0 | for(x = 0; x < uv_wd; x += 2) |
2186 | 0 | { |
2187 | | // take CRC of first pictureData byte |
2188 | 0 | for(bit_idx = 0; bit_idx < 8; bit_idx++) |
2189 | 0 | { |
2190 | 0 | CALC_CRC_BIT_LEVEL( |
2191 | 0 | u4_crc_val_u, |
2192 | 0 | pu_buf[y * (uv_strd * gt8bit_mul) + (x * gt8bit_mul)], |
2193 | 0 | bit_idx); |
2194 | 0 | CALC_CRC_BIT_LEVEL( |
2195 | 0 | u4_crc_val_v, |
2196 | 0 | pu_buf[y * (uv_strd * gt8bit_mul) + ((x + 1) * gt8bit_mul)], |
2197 | 0 | bit_idx); |
2198 | 0 | } |
2199 | | // take CRC of second pictureData byte if bit depth is greater than 8-bits |
2200 | 0 | if(bit_depth > 8) |
2201 | 0 | { |
2202 | 0 | for(bit_idx = 0; bit_idx < 8; bit_idx++) |
2203 | 0 | { |
2204 | 0 | CALC_CRC_BIT_LEVEL( |
2205 | 0 | u4_crc_val_u, |
2206 | 0 | pu_buf[y * (uv_strd * gt8bit_mul) + (x * gt8bit_mul) + 1], |
2207 | 0 | bit_idx); |
2208 | 0 | CALC_CRC_BIT_LEVEL( |
2209 | 0 | u4_crc_val_v, |
2210 | 0 | pu_buf[y * (uv_strd * gt8bit_mul) + ((x + 1) * gt8bit_mul) + 1], |
2211 | 0 | bit_idx); |
2212 | 0 | } |
2213 | 0 | } |
2214 | 0 | } |
2215 | 0 | } |
2216 | |
|
2217 | 0 | for(bit_idx = 0; bit_idx < 16; bit_idx++) |
2218 | 0 | { |
2219 | 0 | UWORD32 u4_crc_msb = (u4_crc_val_u >> 15) & 1; |
2220 | 0 | u4_crc_val_u = ((u4_crc_val_u << 1) & 0xffff) ^ (u4_crc_msb * 0x1021); |
2221 | |
|
2222 | 0 | u4_crc_msb = (u4_crc_val_v >> 15) & 1; |
2223 | 0 | u4_crc_val_v = ((u4_crc_val_v << 1) & 0xffff) ^ (u4_crc_msb * 0x1021); |
2224 | 0 | } |
2225 | |
|
2226 | 0 | ps_hash_sei_params->au1_sei_hash[1][0] = (u4_crc_val_u >> 8) & 0xff; |
2227 | 0 | ps_hash_sei_params->au1_sei_hash[1][1] = u4_crc_val_u & 0xff; |
2228 | |
|
2229 | 0 | ps_hash_sei_params->au1_sei_hash[2][0] = (u4_crc_val_v >> 8) & 0xff; |
2230 | 0 | ps_hash_sei_params->au1_sei_hash[2][1] = u4_crc_val_v & 0xff; |
2231 | 0 | } |
2232 | 0 | } |
2233 | | |
2234 | | /** |
2235 | | ****************************************************************************** |
2236 | | * |
2237 | | * @brief Populates Hash SEI values for Checksum Hash |
2238 | | * |
2239 | | * @par Description |
2240 | | * |
2241 | | * @param[out] ps_hash_sei_params |
2242 | | * pointer to hash sei params that needs to be populated |
2243 | | * |
2244 | | * @param[in] bit_depth |
2245 | | * i4_internal_bit_depth value. Assume same for Luma & Chroma |
2246 | | * |
2247 | | * @param[in] pv_y_buf |
2248 | | * Pointer to decoded/recon Luma buffer |
2249 | | * |
2250 | | * @param[in] y_wd |
2251 | | * pic width in luma samples |
2252 | | * |
2253 | | * @param[in] y_ht |
2254 | | * pic height in luma samples |
2255 | | * |
2256 | | * @param[in] y_strd |
2257 | | * Stride of luma buffer |
2258 | | * |
2259 | | * @param[in] pv_u_buf |
2260 | | * Pointer to decoded/recon Chroma buffer |
2261 | | * |
2262 | | * @param[in] uv_wd |
2263 | | * pic width in luma samples / SubWidthC |
2264 | | * |
2265 | | * @param[in] uv_ht |
2266 | | * pic height in luma samples / SubHeightC |
2267 | | * |
2268 | | * @param[in] uv_strd |
2269 | | * Stride of chroma buffer |
2270 | | * |
2271 | | * @return None |
2272 | | * |
2273 | | ***************************************************************************** |
2274 | | */ |
2275 | | static void ihevce_calc_checksum( |
2276 | | hash_sei_param_t *ps_hash_sei_params, |
2277 | | WORD32 bit_depth, |
2278 | | void *pv_y_buf, |
2279 | | WORD32 y_wd, |
2280 | | WORD32 y_ht, |
2281 | | WORD32 y_strd, |
2282 | | void *pv_u_buf, |
2283 | | WORD32 uv_wd, |
2284 | | WORD32 uv_ht, |
2285 | | WORD32 uv_strd, |
2286 | | WORD32 i4_frame_pos_x, |
2287 | | WORD32 i4_frame_pos_y) |
2288 | 0 | { |
2289 | 0 | WORD32 x, y; |
2290 | 0 | UWORD8 *pu_buf; |
2291 | 0 | WORD32 row, col; |
2292 | 0 | UWORD32 u4_xor_mask; |
2293 | 0 | UWORD32 gt8bit_mul = 1; |
2294 | |
|
2295 | 0 | if(bit_depth > 8) |
2296 | 0 | gt8bit_mul++; |
2297 | | |
2298 | | /* Luma Checksum */ |
2299 | 0 | { |
2300 | 0 | UWORD32 u4_sum_luma = 0; |
2301 | |
|
2302 | 0 | pu_buf = (UWORD8 *)pv_y_buf; |
2303 | |
|
2304 | 0 | for(y = i4_frame_pos_y, row = 0; row < y_ht; y++, row++) |
2305 | 0 | { |
2306 | 0 | for(x = i4_frame_pos_x, col = 0; col < y_wd; x++, col++) |
2307 | 0 | { |
2308 | | // take checksum of first pictureData byte |
2309 | 0 | u4_xor_mask = (x & 0xFF) ^ (y & 0xFF) ^ (x >> 8) ^ (y >> 8); |
2310 | 0 | u4_sum_luma = |
2311 | 0 | (u4_sum_luma + ((pu_buf[(row * y_strd + col) * gt8bit_mul]) ^ u4_xor_mask)) & |
2312 | 0 | 0xFFFFFFFF; |
2313 | | |
2314 | | // take checksum of second pictureData byte if bit depth is greater than 8-bits |
2315 | 0 | if(bit_depth > 8) |
2316 | 0 | { |
2317 | 0 | u4_sum_luma = (u4_sum_luma + ((pu_buf[(row * y_strd + col) * gt8bit_mul + 1]) ^ |
2318 | 0 | u4_xor_mask)) & |
2319 | 0 | 0xFFFFFFFF; |
2320 | 0 | } |
2321 | 0 | } |
2322 | 0 | } |
2323 | |
|
2324 | 0 | ps_hash_sei_params->au1_sei_hash[0][0] = (u4_sum_luma >> 24) & 0xff; |
2325 | 0 | ps_hash_sei_params->au1_sei_hash[0][1] = (u4_sum_luma >> 16) & 0xff; |
2326 | 0 | ps_hash_sei_params->au1_sei_hash[0][2] = (u4_sum_luma >> 8) & 0xff; |
2327 | 0 | ps_hash_sei_params->au1_sei_hash[0][3] = (u4_sum_luma)&0xff; |
2328 | 0 | } |
2329 | | |
2330 | | /* Cb & Cr checksum */ |
2331 | 0 | { |
2332 | 0 | UWORD32 u4_sum_cb = 0, u4_sum_cr = 0; |
2333 | 0 | pu_buf = (UWORD8 *)pv_u_buf; |
2334 | |
|
2335 | 0 | for(y = (i4_frame_pos_y / 2), row = 0; row < uv_ht; y++, row++) |
2336 | 0 | { |
2337 | 0 | for(x = (i4_frame_pos_x / 2), col = 0; col < uv_wd; x++, col += 2) |
2338 | 0 | { |
2339 | | // take checksum of first pictureData byte |
2340 | 0 | u4_xor_mask = (x & 0xFF) ^ (y & 0xFF) ^ (x >> 8) ^ (y >> 8); |
2341 | 0 | u4_sum_cb = |
2342 | 0 | (u4_sum_cb + ((pu_buf[(row * uv_strd + (col)) * gt8bit_mul]) ^ u4_xor_mask)) & |
2343 | 0 | 0xFFFFFFFF; |
2344 | 0 | u4_sum_cr = (u4_sum_cr + |
2345 | 0 | ((pu_buf[(row * uv_strd + (col + 1)) * gt8bit_mul]) ^ u4_xor_mask)) & |
2346 | 0 | 0xFFFFFFFF; |
2347 | | |
2348 | | // take checksum of second pictureData byte if bit depth is greater than 8-bits |
2349 | 0 | if(bit_depth > 8) |
2350 | 0 | { |
2351 | 0 | u4_sum_cb = (u4_sum_cb + ((pu_buf[(row * uv_strd + (col)) * gt8bit_mul + 1]) ^ |
2352 | 0 | u4_xor_mask)) & |
2353 | 0 | 0xFFFFFFFF; |
2354 | 0 | u4_sum_cr = |
2355 | 0 | (u4_sum_cr + |
2356 | 0 | ((pu_buf[(row * uv_strd + (col + 1)) * gt8bit_mul + 1]) ^ u4_xor_mask)) & |
2357 | 0 | 0xFFFFFFFF; |
2358 | 0 | } |
2359 | 0 | } |
2360 | 0 | } |
2361 | |
|
2362 | 0 | ps_hash_sei_params->au1_sei_hash[1][0] = (u4_sum_cb >> 24) & 0xff; |
2363 | 0 | ps_hash_sei_params->au1_sei_hash[1][1] = (u4_sum_cb >> 16) & 0xff; |
2364 | 0 | ps_hash_sei_params->au1_sei_hash[1][2] = (u4_sum_cb >> 8) & 0xff; |
2365 | 0 | ps_hash_sei_params->au1_sei_hash[1][3] = (u4_sum_cb)&0xff; |
2366 | |
|
2367 | 0 | ps_hash_sei_params->au1_sei_hash[2][0] = (u4_sum_cr >> 24) & 0xff; |
2368 | 0 | ps_hash_sei_params->au1_sei_hash[2][1] = (u4_sum_cr >> 16) & 0xff; |
2369 | 0 | ps_hash_sei_params->au1_sei_hash[2][2] = (u4_sum_cr >> 8) & 0xff; |
2370 | 0 | ps_hash_sei_params->au1_sei_hash[2][3] = (u4_sum_cr)&0xff; |
2371 | 0 | } |
2372 | 0 | } |
2373 | | |
2374 | | /** |
2375 | | ****************************************************************************** |
2376 | | * |
2377 | | * @brief Populates Hash SEI values |
2378 | | * |
2379 | | * @par Description |
2380 | | * |
2381 | | * @param[out] ps_sei |
2382 | | * pointer to sei params that needs to be populated |
2383 | | * |
2384 | | * @param[in] bit_depth |
2385 | | * i4_internal_bit_depth value. Assume same for Luma & Chroma |
2386 | | * |
2387 | | * @param[in] pv_y_buf |
2388 | | * Pointer to decoded/recon Luma buffer |
2389 | | * |
2390 | | * @param[in] y_wd |
2391 | | * pic width in luma samples |
2392 | | * |
2393 | | * @param[in] y_ht |
2394 | | * pic height in luma samples |
2395 | | * |
2396 | | * @param[in] y_strd |
2397 | | * Stride of luma buffer |
2398 | | * |
2399 | | * @param[in] pv_u_buf |
2400 | | * Pointer to decoded/recon Chroma buffer |
2401 | | * |
2402 | | * @param[in] uv_wd |
2403 | | * pic width in luma samples / SubWidthC |
2404 | | * |
2405 | | * @param[in] uv_ht |
2406 | | * pic height in luma samples / SubHeightC |
2407 | | * |
2408 | | * @param[in] uv_strd |
2409 | | * Stride of chroma buffer |
2410 | | * |
2411 | | * @return success or failure error code |
2412 | | * |
2413 | | ***************************************************************************** |
2414 | | */ |
2415 | | WORD32 ihevce_populate_hash_sei( |
2416 | | sei_params_t *ps_sei, |
2417 | | WORD32 bit_depth, |
2418 | | void *pv_y_buf, |
2419 | | WORD32 y_wd, |
2420 | | WORD32 y_ht, |
2421 | | WORD32 y_strd, |
2422 | | void *pv_u_buf, |
2423 | | WORD32 uv_wd, |
2424 | | WORD32 uv_ht, |
2425 | | WORD32 uv_strd, |
2426 | | WORD32 i4_frame_pos_x, |
2427 | | WORD32 i4_frame_pos_y) |
2428 | 0 | { |
2429 | 0 | hash_sei_param_t *ps_hash_sei_params = &ps_sei->s_hash_sei_params; |
2430 | |
|
2431 | 0 | if(1 == ps_sei->i1_decoded_pic_hash_sei_flag) |
2432 | 0 | { |
2433 | 0 | ASSERT(0); // Not supported now! |
2434 | 0 | } |
2435 | 0 | else if(2 == ps_sei->i1_decoded_pic_hash_sei_flag) |
2436 | 0 | { |
2437 | | /* calculate CRC for entire reconstructed picture */ |
2438 | 0 | ihevce_calc_CRC( |
2439 | 0 | ps_hash_sei_params, |
2440 | 0 | bit_depth, |
2441 | 0 | pv_y_buf, |
2442 | 0 | y_wd, |
2443 | 0 | y_ht, |
2444 | 0 | y_strd, |
2445 | 0 | pv_u_buf, |
2446 | 0 | uv_wd, |
2447 | 0 | uv_ht, |
2448 | 0 | uv_strd); |
2449 | 0 | } |
2450 | 0 | else if(3 == ps_sei->i1_decoded_pic_hash_sei_flag) |
2451 | 0 | { |
2452 | | /* calculate Checksum for entire reconstructed picture */ |
2453 | 0 | ihevce_calc_checksum( |
2454 | 0 | ps_hash_sei_params, |
2455 | 0 | bit_depth, |
2456 | 0 | pv_y_buf, |
2457 | 0 | y_wd, |
2458 | 0 | y_ht, |
2459 | 0 | y_strd, |
2460 | 0 | pv_u_buf, |
2461 | 0 | uv_wd, |
2462 | 0 | uv_ht, |
2463 | 0 | uv_strd, |
2464 | 0 | i4_frame_pos_x, |
2465 | 0 | i4_frame_pos_y); |
2466 | 0 | } |
2467 | 0 | else |
2468 | 0 | { |
2469 | 0 | ASSERT(0); |
2470 | 0 | } |
2471 | | |
2472 | 0 | return IHEVCE_SUCCESS; |
2473 | 0 | } |
2474 | | #endif |
2475 | | |
2476 | | /** |
2477 | | ****************************************************************************** |
2478 | | * |
2479 | | * @brief Populates vui structure |
2480 | | * |
2481 | | * @par Description |
2482 | | * Populates vui structure for its use in header generation |
2483 | | * |
2484 | | * @param[out] ps_vui |
2485 | | * pointer to vui params that needs to be populated |
2486 | | * |
2487 | | * @param[out] ps_sps |
2488 | | * pointer to sps params referred by vui |
2489 | | * |
2490 | | * @param[in] ps_src_params |
2491 | | * pointer to source config params; resolution, frame rate etc |
2492 | | * |
2493 | | * @param[out] ps_vui_sei_prms |
2494 | | * pointer to sps params referred by application |
2495 | | * |
2496 | | * @return success or failure error code |
2497 | | * |
2498 | | ****************************************************************************** |
2499 | | */ |
2500 | | WORD32 ihevce_populate_vui( |
2501 | | vui_t *ps_vui, |
2502 | | sps_t *ps_sps, |
2503 | | ihevce_src_params_t *ps_src_params, |
2504 | | ihevce_vui_sei_params_t *ps_vui_sei_prms, |
2505 | | WORD32 i4_resolution_id, |
2506 | | ihevce_tgt_params_t *ps_tgt_params, |
2507 | | ihevce_static_cfg_params_t *ps_stat_prms, |
2508 | | WORD32 i4_bitrate_instance_id) |
2509 | 8.92k | { |
2510 | 8.92k | WORD32 i, j, i4_range_idr, i4_range_cdr; |
2511 | 8.92k | ULWORD64 max_vbv_size; |
2512 | | |
2513 | 8.92k | ps_vui->u1_aspect_ratio_info_present_flag = ps_vui_sei_prms->u1_aspect_ratio_info_present_flag; |
2514 | | |
2515 | 8.92k | ps_vui->u1_aspect_ratio_idc = ps_vui_sei_prms->au1_aspect_ratio_idc[i4_resolution_id]; |
2516 | | |
2517 | 8.92k | ps_vui->u2_sar_height = ps_vui_sei_prms->au2_sar_height[i4_resolution_id]; |
2518 | | |
2519 | 8.92k | ps_vui->u2_sar_width = ps_vui_sei_prms->au2_sar_width[i4_resolution_id]; |
2520 | | |
2521 | 8.92k | ps_vui->u1_overscan_info_present_flag = ps_vui_sei_prms->u1_overscan_info_present_flag; |
2522 | | |
2523 | 8.92k | ps_vui->u1_overscan_appropriate_flag = ps_vui_sei_prms->u1_overscan_appropriate_flag; |
2524 | | |
2525 | 8.92k | ps_vui->u1_video_signal_type_present_flag = ps_vui_sei_prms->u1_video_signal_type_present_flag; |
2526 | | |
2527 | 8.92k | ps_vui->u1_video_format = ps_vui_sei_prms->u1_video_format; |
2528 | | |
2529 | 8.92k | ps_vui->u1_video_full_range_flag = ps_vui_sei_prms->u1_video_full_range_flag; |
2530 | | |
2531 | 8.92k | ps_vui->u1_colour_description_present_flag = |
2532 | 8.92k | ps_vui_sei_prms->u1_colour_description_present_flag; |
2533 | | |
2534 | 8.92k | ps_vui->u1_colour_primaries = ps_vui_sei_prms->u1_colour_primaries; |
2535 | | |
2536 | 8.92k | ps_vui->u1_transfer_characteristics = ps_vui_sei_prms->u1_transfer_characteristics; |
2537 | | |
2538 | 8.92k | ps_vui->u1_matrix_coefficients = ps_vui_sei_prms->u1_matrix_coefficients; |
2539 | | |
2540 | 8.92k | ps_vui->u1_chroma_loc_info_present_flag = ps_vui_sei_prms->u1_chroma_loc_info_present_flag; |
2541 | | |
2542 | 8.92k | ps_vui->u1_chroma_sample_loc_type_top_field = |
2543 | 8.92k | ps_vui_sei_prms->u1_chroma_sample_loc_type_top_field; |
2544 | | |
2545 | 8.92k | ps_vui->u1_chroma_sample_loc_type_bottom_field = |
2546 | 8.92k | ps_vui_sei_prms->u1_chroma_sample_loc_type_bottom_field; |
2547 | | |
2548 | 8.92k | ps_vui->u1_neutral_chroma_indication_flag = 0; |
2549 | | |
2550 | 8.92k | ps_vui->u1_default_display_window_flag = 0; |
2551 | | |
2552 | | /* Default Values for display offset added */ |
2553 | 8.92k | if(ps_vui->u1_default_display_window_flag) |
2554 | 0 | { |
2555 | 0 | ps_vui->u4_def_disp_win_bottom_offset = 0; |
2556 | |
|
2557 | 0 | ps_vui->u4_def_disp_win_left_offset = 0; |
2558 | |
|
2559 | 0 | ps_vui->u4_def_disp_win_right_offset = 0; |
2560 | |
|
2561 | 0 | ps_vui->u4_def_disp_win_top_offset = 0; |
2562 | 0 | } |
2563 | | |
2564 | 8.92k | ps_vui->u1_vui_hrd_parameters_present_flag = |
2565 | 8.92k | ps_vui_sei_prms->u1_vui_hrd_parameters_present_flag; |
2566 | | |
2567 | 8.92k | ps_vui->u1_field_seq_flag = ps_src_params->i4_field_pic; |
2568 | | |
2569 | 8.92k | ps_vui->u1_frame_field_info_present_flag = 1; |
2570 | | |
2571 | 8.92k | ps_vui->u1_vui_timing_info_present_flag = ps_vui_sei_prms->u1_timing_info_present_flag; |
2572 | | |
2573 | | //if(ps_vui->u1_vui_timing_info_present_flag) |
2574 | 8.92k | { |
2575 | | /* NumUnits in tick is same as the frame rate denominator assuming delta poc as 1 */ |
2576 | 8.92k | ps_vui->u4_vui_num_units_in_tick = ps_src_params->i4_frm_rate_denom; |
2577 | | |
2578 | | /* TimeScale is the same as the frame rate numerator assuming delta poc as 1 */ |
2579 | 8.92k | ps_vui->u4_vui_time_scale = |
2580 | 8.92k | (ps_src_params->i4_frm_rate_num / ps_tgt_params->i4_frm_rate_scale_factor); |
2581 | 8.92k | } |
2582 | | |
2583 | 8.92k | ps_vui->u1_poc_proportional_to_timing_flag = 1; |
2584 | | |
2585 | 8.92k | if(ps_vui->u1_poc_proportional_to_timing_flag && ps_vui->u1_vui_timing_info_present_flag) |
2586 | 0 | ps_vui->u4_num_ticks_poc_diff_one_minus1 = 0; |
2587 | | |
2588 | | //if (ps_vui->u1_vui_hrd_parameters_present_flag) |
2589 | 8.92k | { |
2590 | 8.92k | ps_vui->s_vui_hrd_parameters.u1_initial_cpb_removal_delay_length_minus1 = 23; |
2591 | 8.92k | ps_vui->s_vui_hrd_parameters.u1_au_cpb_removal_delay_length_minus1 = 23; /* Default value */ |
2592 | | |
2593 | 8.92k | ps_vui->s_vui_hrd_parameters.u1_dpb_output_delay_length_minus1 = |
2594 | 8.92k | 4; // max num of B pics are 7. So the max delay can go up to 5 and a maximun 10 is allowed for initial removal dalay. |
2595 | | |
2596 | 8.92k | ps_vui->s_vui_hrd_parameters.u1_nal_hrd_parameters_present_flag = |
2597 | 8.92k | ps_vui_sei_prms->u1_nal_hrd_parameters_present_flag; |
2598 | | |
2599 | 8.92k | ps_vui->s_vui_hrd_parameters.u1_vcl_hrd_parameters_present_flag = |
2600 | 8.92k | 0; //ps_vui_sei_prms->u1_vcl_hrd_parameters_present_flag; |
2601 | 8.92k | ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag = 0; |
2602 | | |
2603 | 8.92k | if(ps_vui->s_vui_hrd_parameters.u1_nal_hrd_parameters_present_flag || |
2604 | 8.92k | ps_vui->s_vui_hrd_parameters.u1_vcl_hrd_parameters_present_flag) |
2605 | 0 | { |
2606 | | /* Initialize u1_au_cpb_removal_delay_length_minus1 based on configured intra periods */ |
2607 | 0 | ps_vui->s_vui_hrd_parameters.u1_au_cpb_removal_delay_length_minus1 = |
2608 | 0 | 8; /* Default value when HRD params are enabled */ |
2609 | 0 | if(ps_stat_prms->s_coding_tools_prms.i4_max_cra_open_gop_period || |
2610 | 0 | ps_stat_prms->s_coding_tools_prms.i4_max_closed_gop_period) |
2611 | 0 | { |
2612 | 0 | GETRANGE( |
2613 | 0 | i4_range_cdr, ps_stat_prms->s_coding_tools_prms.i4_max_cra_open_gop_period); |
2614 | |
|
2615 | 0 | GETRANGE(i4_range_idr, ps_stat_prms->s_coding_tools_prms.i4_max_closed_gop_period); |
2616 | |
|
2617 | 0 | ps_vui->s_vui_hrd_parameters.u1_au_cpb_removal_delay_length_minus1 = |
2618 | 0 | MAX(i4_range_cdr, i4_range_idr); |
2619 | 0 | } |
2620 | | /*BLU_RAY Default set to 0 */ |
2621 | 0 | ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag = 0; |
2622 | 0 | if(ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag) |
2623 | 0 | { |
2624 | 0 | ps_vui->s_vui_hrd_parameters.u1_tick_divisor_minus2 = 1; |
2625 | 0 | ps_vui->s_vui_hrd_parameters.u1_du_cpb_removal_delay_increment_length_minus1 = 23; |
2626 | 0 | ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_in_pic_timing_sei_flag = 1; |
2627 | 0 | ps_vui->s_vui_hrd_parameters.u1_dpb_output_delay_du_length_minus1 = 0; |
2628 | 0 | } |
2629 | 0 | } |
2630 | | |
2631 | 8.92k | ps_vui->s_vui_hrd_parameters.u4_bit_rate_scale = VUI_BIT_RATE_SCALE; |
2632 | 8.92k | ps_vui->s_vui_hrd_parameters.u4_cpb_size_scale = VUI_CPB_SIZE_SCALE; |
2633 | 8.92k | if(ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag) |
2634 | 0 | { |
2635 | 0 | ps_vui->s_vui_hrd_parameters.u4_cpb_size_du_scale = 0; |
2636 | 0 | } |
2637 | | |
2638 | 17.8k | for(i = 0; i <= (ps_sps->i1_sps_max_sub_layers - 1); i++) |
2639 | 8.92k | { |
2640 | 8.92k | ps_vui->s_vui_hrd_parameters.au1_fixed_pic_rate_general_flag[i] = |
2641 | 8.92k | 1; /*BLU_RAY specific change already done */ |
2642 | 8.92k | ps_vui->s_vui_hrd_parameters.au1_fixed_pic_rate_within_cvs_flag[i] = 1; |
2643 | 8.92k | ps_vui->s_vui_hrd_parameters.au2_elemental_duration_in_tc_minus1[i] = 0; |
2644 | | |
2645 | | /*BLU_RAY low_delay_hrd_flag is always set to 0*/ |
2646 | 8.92k | ps_vui->s_vui_hrd_parameters.au1_low_delay_hrd_flag[i] = 0; |
2647 | | |
2648 | | /************************************************************************/ |
2649 | | /* cpb_cnt_minus1 is set to zero because we assume that the decoder */ |
2650 | | /* can work with just one CPB specification */ |
2651 | | /************************************************************************/ |
2652 | 8.92k | ps_vui->s_vui_hrd_parameters.au1_cpb_cnt_minus1[i] = 0; |
2653 | | |
2654 | 8.92k | max_vbv_size = ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id] |
2655 | 8.92k | .ai4_max_vbv_buffer_size[i4_bitrate_instance_id]; |
2656 | 17.8k | for(j = 0; j <= ps_vui->s_vui_hrd_parameters.au1_cpb_cnt_minus1[i]; j++) |
2657 | 8.92k | { |
2658 | 8.92k | ULWORD64 u8_bit_rate_val = |
2659 | 8.92k | (ULWORD64)ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id] |
2660 | 8.92k | .ai4_tgt_bitrate[i4_bitrate_instance_id]; |
2661 | 8.92k | ULWORD64 u8_max_cpb_size; |
2662 | 8.92k | if((ps_stat_prms->s_config_prms.i4_rate_control_mode == 2) || |
2663 | 8.92k | (ps_stat_prms->s_config_prms.i4_rate_control_mode == |
2664 | 5.97k | 1)) // VBR/Capped VBR rate control mode |
2665 | 2.94k | u8_bit_rate_val = |
2666 | 2.94k | (ULWORD64)(ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id] |
2667 | 2.94k | .ai4_peak_bitrate[i4_bitrate_instance_id]); |
2668 | 8.92k | u8_max_cpb_size = |
2669 | 8.92k | max_vbv_size; //((ULWORD64)(max_vbv_size * u8_bit_rate_val)/1000); |
2670 | | |
2671 | 8.92k | if(3 == ps_stat_prms->s_config_prms.i4_rate_control_mode) |
2672 | 3.89k | { |
2673 | | /* For CQP mode, assume Level specified max rate and buffer size */ |
2674 | 3.89k | WORD32 codec_level_index = ihevce_get_level_index( |
2675 | 3.89k | ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_codec_level); |
2676 | 3.89k | WORD32 codec_tier = ps_stat_prms->s_out_strm_prms.i4_codec_tier; |
2677 | | |
2678 | | /* Bitrate as per level and tier limits */ |
2679 | 3.89k | u8_bit_rate_val = |
2680 | 3.89k | g_as_level_data[codec_level_index].i4_max_bit_rate[codec_tier] * |
2681 | 3.89k | CBP_VCL_FACTOR; |
2682 | 3.89k | u8_max_cpb_size = |
2683 | 3.89k | g_as_level_data[codec_level_index].i4_max_cpb[codec_tier] * CBP_VCL_FACTOR; |
2684 | 3.89k | } |
2685 | | |
2686 | 8.92k | u8_bit_rate_val >>= (6 + ps_vui->s_vui_hrd_parameters.u4_bit_rate_scale); |
2687 | | /************************************************************************/ |
2688 | | /* u8_bit_rate_value forced >= 4096 as the shift is always of 12 */ |
2689 | | /* because u4_bit_rate_scale = 6. */ |
2690 | | /************************************************************************/ |
2691 | 8.92k | if (u8_bit_rate_val == 0) |
2692 | 0 | { |
2693 | 0 | return IHEVCE_BITRATE_NOT_SUPPORTED; |
2694 | 0 | } |
2695 | | |
2696 | 8.92k | u8_max_cpb_size >>= (4 + ps_vui->s_vui_hrd_parameters.u4_cpb_size_scale); |
2697 | | |
2698 | 8.92k | ps_vui->s_vui_hrd_parameters.as_sub_layer_hrd_params[i] |
2699 | 8.92k | .au4_bit_rate_value_minus1[j] = (UWORD32)(u8_bit_rate_val - 1); |
2700 | 8.92k | ps_vui->s_vui_hrd_parameters.as_sub_layer_hrd_params[i] |
2701 | 8.92k | .au4_cpb_size_value_minus1[j] = (UWORD32)(u8_max_cpb_size - 1); |
2702 | | |
2703 | 8.92k | if(ps_vui->s_vui_hrd_parameters.u1_sub_pic_cpb_params_present_flag) |
2704 | 0 | { |
2705 | 0 | ps_vui->s_vui_hrd_parameters.as_sub_layer_hrd_params[i] |
2706 | 0 | .au4_cpb_size_value_minus1[j] = 0; |
2707 | 0 | } |
2708 | | |
2709 | | /************************************************************************/ |
2710 | | /* CBR flag is set as per the RATE_CONTROL macro */ |
2711 | | /************************************************************************/ |
2712 | | |
2713 | | /* Default cbr falg setting. will discard Decoder buffer overflows ( No stuffing required)*/ |
2714 | | |
2715 | 8.92k | ps_vui->s_vui_hrd_parameters.as_sub_layer_hrd_params[i].au1_cbr_flag[j] = 0; |
2716 | 8.92k | } |
2717 | 8.92k | } |
2718 | 8.92k | } |
2719 | | |
2720 | 8.92k | ps_vui->u1_bitstream_restriction_flag = 0; |
2721 | | |
2722 | 8.92k | if(ps_vui->u1_bitstream_restriction_flag) |
2723 | 0 | { |
2724 | 0 | ps_vui->u1_tiles_fixed_structure_flag = 1; |
2725 | |
|
2726 | 0 | ps_vui->u1_motion_vectors_over_pic_boundaries_flag = 1; |
2727 | |
|
2728 | 0 | ps_vui->u4_min_spatial_segmentation_idc = 0; |
2729 | |
|
2730 | 0 | ps_vui->u1_restricted_ref_pic_lists_flag = 0; |
2731 | |
|
2732 | 0 | ps_vui->u1_max_bytes_per_pic_denom = 2; |
2733 | |
|
2734 | 0 | ps_vui->u1_max_bits_per_mincu_denom = 1; |
2735 | |
|
2736 | 0 | ps_vui->u1_log2_max_mv_length_horizontal = 15; |
2737 | |
|
2738 | 0 | ps_vui->u1_log2_max_mv_length_vertical = 15; |
2739 | 0 | } |
2740 | | |
2741 | 8.92k | return IHEVCE_SUCCESS; |
2742 | 8.92k | } |