1 /******************************************************************************
2 *
3 * Copyright (C) 2022 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 * @file
23 * isvcd_parse_headers.c
24 *
25 * @brief
26 * Contains High level syntax[above slice] parsing routines
27 *
28 * @author
29 * Kishore
30 *
31 * @par List of Functions:
32 * - isvcd_set_default_seq_svc_ext()
33 * - isvcd_parse_subset_sps()
34 * - isvcd_dec_ref_base_pic_marking()
35 * - isvcd_parse_nal_unit()
36 * - isvcd_parse_sps()
37 * - isvcd_parse_pps()
38 *
39 * @remarks
40 * None
41 *
42 *******************************************************************************
43 */
44
45 #include <string.h>
46 #include <assert.h>
47
48 #include "ih264_typedefs.h"
49 #include "ih264_defs.h"
50 #include "ih264_macros.h"
51 #include "ih264_platform_macros.h"
52 #include "ih264d_bitstrm.h"
53 #include "isvcd_structs.h"
54 #include "ih264d_parse_cavlc.h"
55 #include "ih264d_defs.h"
56 #include "ih264d_parse_slice.h"
57 #include "ih264d_tables.h"
58 #include "ih264d_utils.h"
59 #include "ih264d_nal.h"
60 #include "ih264d_deblocking.h"
61 #include "ih264d_mem_request.h"
62 #include "ih264d_debug.h"
63 #include "ih264_debug.h"
64 #include "ih264d_error_handler.h"
65 #include "ih264d_mb_utils.h"
66 #include "ih264d_sei.h"
67 #include "ih264d_vui.h"
68 #include "ih264d_thread_parse_decode.h"
69 #include "ih264d_thread_compute_bs.h"
70 #include "ih264d_quant_scaling.h"
71 #include "ih264d_defs.h"
72 #include "ivd.h"
73 #include "ih264d_parse_islice.h"
74 #include "isvcd_parse_slice.h"
75 #include "ih264d_process_bslice.h"
76 #include "ih264d_process_pslice.h"
77 #include "isvcd_vui.h"
78
79 WORD32 ih264d_access_unit_delimiter_rbsp(dec_struct_t *ps_dec);
80 void ih264d_get_pre_sei_params(dec_struct_t *ps_dec, UWORD8 u1_nal_unit_type);
81 UWORD32 ih264d_correct_level_idc(UWORD32 u4_level_idc, UWORD32 u4_total_mbs);
82 WORD32 ih264d_parse_filler_data(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm);
83 void ih264d_parse_end_of_stream(dec_struct_t *ps_dec);
84 WORD32 ih264d_parse_slice_partition(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm);
85 /*!
86 **************************************************************************
87 * \if Function name : isvcd_set_default_seq_svc_ext \en
88 dif
89 *
90 * \brief
91 * Sets the default values for the svc params in the SVC bitstream
92 *
93 * \return
94 **************************************************************************
95 */
isvcd_set_default_seq_svc_ext(dec_subset_seq_params_t * ps_seq_svc_ext)96 void isvcd_set_default_seq_svc_ext(dec_subset_seq_params_t *ps_seq_svc_ext)
97 {
98 ps_seq_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag = 0;
99 ps_seq_svc_ext->u1_extended_spatial_scalability_idc = 0;
100 ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag = 1;
101 ps_seq_svc_ext->u1_chroma_phase_y_plus1 = 1;
102 ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag =
103 ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag;
104 ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 = ps_seq_svc_ext->u1_chroma_phase_y_plus1;
105 ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset = 0;
106 ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset = 0;
107 ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset = 0;
108 ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset = 0;
109 ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag =
110 ps_seq_svc_ext->u1_adaptive_tcoeff_level_prediction_flag = 0;
111 ps_seq_svc_ext->u1_slice_header_restriction_flag = 0;
112 ps_seq_svc_ext->u1_svc_vui_parameters_present_flag = 0;
113 }
114 /*!
115 **************************************************************************
116 * \if Function name : isvcd_parse_subset_sps \en
117 dif
118 *
119 * \brief
120 * Decodes Sequence parameter set from the SVC bitstream
121 *
122 * \return
123 * 0 on Success and Error code otherwise
124 **************************************************************************
125 */
isvcd_parse_subset_sps(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_bit_stream_t * ps_bitstrm)126 WORD32 isvcd_parse_subset_sps(svc_dec_lyr_struct_t *ps_svc_lyr_dec, dec_bit_stream_t *ps_bitstrm)
127 {
128 dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
129 UWORD8 i;
130 dec_seq_params_t *ps_seq = NULL;
131 dec_svc_seq_params_t *ps_subset_seq = NULL;
132 dec_subset_seq_params_t *ps_seq_svc_ext;
133 UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
134 UWORD16 i2_max_frm_num;
135 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
136 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
137 UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag, uc_constraint_set2_flag;
138 WORD32 i4_cropped_ht, i4_cropped_wd;
139 UWORD32 u4_temp;
140 UWORD64 u8_temp;
141 UWORD32 u4_pic_height_in_map_units, u4_pic_width_in_mbs;
142 UWORD32 u2_pic_wd = 0;
143 UWORD32 u2_pic_ht = 0;
144 UWORD32 u2_frm_wd_y = 0;
145 UWORD32 u2_frm_ht_y = 0;
146 UWORD32 u2_frm_wd_uv = 0;
147 UWORD32 u2_frm_ht_uv = 0;
148 UWORD32 u2_crop_offset_y = 0;
149 UWORD32 u2_crop_offset_uv = 0;
150 WORD32 ret;
151 /* High profile related syntax element */
152 WORD32 i4_i;
153 /* G050 */
154 UWORD8 u1_frame_cropping_flag,
155 u1_frame_cropping_rect_left_ofst = 0, u1_frame_cropping_rect_right_ofst = 0,
156 u1_frame_cropping_rect_top_ofst = 0, u1_frame_cropping_rect_bottom_ofst = 0;
157 /* G050 */
158 /*--------------------------------------------------------------------*/
159 /* Decode seq_parameter_set_id and profile and level values */
160 /*--------------------------------------------------------------------*/
161 SWITCHONTRACE;
162 u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
163 COPYTHECONTEXT("SPS: profile_idc", u1_profile_idc);
164
165 /* G050 */
166 uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
167 uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
168 uc_constraint_set2_flag = ih264d_get_bit_h264(ps_bitstrm);
169 UNUSED(uc_constraint_set1_flag);
170 UNUSED(uc_constraint_set2_flag);
171
172 /*****************************************************/
173 /* Read 5 bits for uc_constraint_set3_flag (1 bit) */
174 /* and reserved_zero_4bits (4 bits) - Sushant */
175 /*****************************************************/
176 ih264d_get_bits_h264(ps_bitstrm, 5);
177 /* G050 */
178 u1_level_idc = (UWORD8) ih264d_get_bits_h264(ps_bitstrm, 8);
179 COPYTHECONTEXT("SPS: u4_level_idc", u1_level_idc);
180
181 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
182 if(u4_temp & MASK_ERR_SEQ_SET_ID) return ERROR_INV_SPS_PPS_T;
183 u1_seq_parameter_set_id = u4_temp;
184 COPYTHECONTEXT("SPS: seq_parameter_set_id", u1_seq_parameter_set_id);
185
186 if(u1_seq_parameter_set_id >= MAX_NUM_SEQ_PARAMS) return ERROR_INV_SPS_PPS_T;
187
188 /*--------------------------------------------------------------------*/
189 /* Find an seq param entry in seqparam array of decStruct */
190 /*--------------------------------------------------------------------*/
191 ps_subset_seq = ps_svc_lyr_dec->pv_scratch_subset_sps;
192 memset(ps_subset_seq, 0, sizeof(dec_svc_seq_params_t));
193 ps_seq = ps_dec->pv_scratch_sps_pps;
194 memset(ps_seq, 0, sizeof(dec_seq_params_t));
195
196 ps_seq->u1_profile_idc = u1_profile_idc;
197 ps_seq->u1_level_idc = u1_level_idc;
198 ps_seq->u1_seq_parameter_set_id = u1_seq_parameter_set_id;
199
200 /* subset_seq_sps_will be stored from location 32 : MAX_NUM_SEQ_PARAMS*/
201 u1_seq_parameter_set_id += MAX_NUM_SEQ_PARAMS;
202 ps_subset_seq->ps_seq = &ps_dec->ps_sps[u1_seq_parameter_set_id];
203
204 if((ps_dec->i4_header_decoded & 1) &&
205 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
206 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_profile_idc != u1_profile_idc))
207 {
208 ps_dec->u1_res_changed = 1;
209 return IVD_RES_CHANGED;
210 }
211
212 if((ps_dec->i4_header_decoded & 1) &&
213 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
214 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_level_idc != u1_level_idc))
215 {
216 ps_dec->u1_res_changed = 1;
217 return IVD_RES_CHANGED;
218 }
219 /*******************************************************************/
220 /* Initializations for high profile - Sushant */
221 /*******************************************************************/
222 ps_seq->i4_chroma_format_idc = 1;
223 ps_seq->i4_bit_depth_luma_minus8 = 0;
224 ps_seq->i4_bit_depth_chroma_minus8 = 0;
225 ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
226 ps_seq->i4_seq_scaling_matrix_present_flag = 0;
227 if(u1_profile_idc == HIGH_PROFILE_IDC || u1_profile_idc == SCALABLE_BASELINE_PROFILE_IDC ||
228 u1_profile_idc == SCALABLE_HIGH_PROFILE_IDC)
229 {
230 /* reading chroma_format_idc */
231 ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
232
233 /* Monochrome is not supported */
234 if(ps_seq->i4_chroma_format_idc != 1)
235 {
236 return ERROR_FEATURE_UNAVAIL;
237 }
238
239 /* reading bit_depth_luma_minus8 */
240 ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
241
242 if(ps_seq->i4_bit_depth_luma_minus8 != 0)
243 {
244 return ERROR_FEATURE_UNAVAIL;
245 }
246
247 /* reading bit_depth_chroma_minus8 */
248 ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
249
250 if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
251 {
252 return ERROR_FEATURE_UNAVAIL;
253 }
254
255 /* reading qpprime_y_zero_transform_bypass_flag */
256 ps_seq->i4_qpprime_y_zero_transform_bypass_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
257
258 if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
259 {
260 return ERROR_INV_SPS_PPS_T;
261 }
262
263 /* reading seq_scaling_matrix_present_flag */
264 ps_seq->i4_seq_scaling_matrix_present_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
265
266 if(ps_seq->i4_seq_scaling_matrix_present_flag)
267 {
268 for(i4_i = 0; i4_i < 8; i4_i++)
269 {
270 ps_seq->u1_seq_scaling_list_present_flag[i4_i] = ih264d_get_bit_h264(ps_bitstrm);
271
272 /* initialize u1_use_default_scaling_matrix_flag[i4_i] to zero */
273 /* before calling scaling list */
274 ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
275
276 if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
277 {
278 if(i4_i < 6)
279 {
280 ret = ih264d_scaling_list(ps_seq->i2_scalinglist4x4[i4_i], 16,
281 &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
282 ps_bitstrm);
283 }
284 else
285 {
286 ret = ih264d_scaling_list(ps_seq->i2_scalinglist8x8[i4_i - 6], 64,
287 &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
288 ps_bitstrm);
289 }
290 if(ret != OK)
291 {
292 return ret;
293 }
294 }
295 }
296 }
297 }
298 /*--------------------------------------------------------------------*/
299 /* Decode MaxFrameNum */
300 /*--------------------------------------------------------------------*/
301 u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
302 if(u8_temp > MAX_BITS_IN_FRAME_NUM)
303 {
304 return ERROR_INV_SPS_PPS_T;
305 }
306 ps_seq->u1_bits_in_frm_num = (UWORD8) u8_temp;
307 COPYTHECONTEXT("SPS: log2_max_frame_num_minus4", (ps_seq->u1_bits_in_frm_num - 4));
308
309 i2_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
310 ps_seq->u2_u4_max_pic_num_minus1 = i2_max_frm_num - 1;
311 /*--------------------------------------------------------------------*/
312 /* Decode picture order count and related values */
313 /*--------------------------------------------------------------------*/
314 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
315
316 if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
317 {
318 return ERROR_INV_POC_TYPE_T;
319 }
320 ps_seq->u1_pic_order_cnt_type = u4_temp;
321 COPYTHECONTEXT("SPS: pic_order_cnt_type", ps_seq->u1_pic_order_cnt_type);
322
323 ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
324 if(ps_seq->u1_pic_order_cnt_type == 0)
325 {
326 u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
327 if(u8_temp > MAX_BITS_IN_POC_LSB)
328 {
329 return ERROR_INV_SPS_PPS_T;
330 }
331 ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = (UWORD8) u8_temp;
332 ps_seq->i4_max_pic_order_cntLsb = (1 << u8_temp);
333 COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4", (u8_temp - 4));
334 }
335 else if(ps_seq->u1_pic_order_cnt_type == 1)
336 {
337 ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(ps_bitstrm);
338 COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
339 ps_seq->u1_delta_pic_order_always_zero_flag);
340
341 ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
342 COPYTHECONTEXT("SPS: offset_for_non_ref_pic", ps_seq->i4_ofst_for_non_ref_pic);
343
344 ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
345 COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
346 ps_seq->i4_ofst_for_top_to_bottom_field);
347
348 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
349 if(u4_temp > 255) return ERROR_INV_SPS_PPS_T;
350 ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
351 COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
352 ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
353
354 for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
355 {
356 ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
357 COPYTHECONTEXT("SPS: offset_for_ref_frame", ps_seq->i4_ofst_for_ref_frame[i]);
358 }
359 }
360
361 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
362
363 if((u4_temp > H264_MAX_REF_PICS))
364 {
365 return ERROR_NUM_REF;
366 }
367
368 /* Compare with older num_ref_frames is header is already once */
369 if((ps_dec->i4_header_decoded & 1) &&
370 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
371 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_num_ref_frames != u4_temp))
372 {
373 ps_dec->u1_res_changed = 1;
374 return IVD_RES_CHANGED;
375 }
376 ps_seq->u1_num_ref_frames = u4_temp;
377 COPYTHECONTEXT("SPS: num_ref_frames", ps_seq->u1_num_ref_frames);
378
379 ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(ps_bitstrm);
380 COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
381 ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
382 /* SVC_DEC_REVIEW */
383 ps_seq->u1_gaps_in_frame_num_value_allowed_flag = 0;
384
385 /*--------------------------------------------------------------------*/
386 /* Decode FrameWidth and FrameHeight and related values */
387 /*--------------------------------------------------------------------*/
388 u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
389 /* Check for unsupported resolutions*/
390 if(u8_temp > (H264_MAX_FRAME_WIDTH >> 4))
391 {
392 return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
393 }
394 u4_pic_width_in_mbs = (UWORD32) u8_temp;
395 COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1", u4_pic_width_in_mbs - 1);
396
397 u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
398 if(u8_temp > (H264_MAX_FRAME_HEIGHT >> 4))
399 {
400 return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
401 }
402 u4_pic_height_in_map_units = (UWORD32) u8_temp;
403
404 ps_seq->u2_frm_wd_in_mbs = u4_pic_width_in_mbs;
405 ps_seq->u2_frm_ht_in_mbs = u4_pic_height_in_map_units;
406
407 u2_pic_wd = (u4_pic_width_in_mbs << 4);
408 u2_pic_ht = (u4_pic_height_in_map_units << 4);
409 if(ps_svc_lyr_dec->pic_width < u2_pic_wd)
410 {
411 ps_svc_lyr_dec->pic_width = u2_pic_wd;
412 }
413 if(ps_svc_lyr_dec->pic_height < u2_pic_ht)
414 {
415 ps_svc_lyr_dec->pic_height = u2_pic_ht;
416 }
417
418 /*--------------------------------------------------------------------*/
419 /* Get the value of MaxMbAddress and Number of bits needed for it */
420 /*--------------------------------------------------------------------*/
421 ps_seq->u2_max_mb_addr = (ps_seq->u2_frm_wd_in_mbs * ps_seq->u2_frm_ht_in_mbs) - 1;
422
423 ps_seq->u2_total_num_of_mbs = ps_seq->u2_max_mb_addr + 1;
424
425 ps_seq->u1_level_idc = ih264d_correct_level_idc(u1_level_idc, ps_seq->u2_total_num_of_mbs);
426
427 u1_frm = ih264d_get_bit_h264(ps_bitstrm);
428
429 if((ps_dec->i4_header_decoded & 1) &&
430 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
431 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_frame_mbs_only_flag != u1_frm))
432 {
433 ps_dec->u1_res_changed = 1;
434 return IVD_RES_CHANGED;
435 }
436 ps_seq->u1_frame_mbs_only_flag = u1_frm;
437
438 COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
439
440 if(!u1_frm) u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
441 if((ps_dec->i4_header_decoded & 1) &&
442 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
443 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_mb_aff_flag != u1_mb_aff_flag))
444 {
445 ps_dec->u1_res_changed = 1;
446 return IVD_RES_CHANGED;
447 }
448 if(!u1_frm)
449 {
450 u2_pic_ht <<= 1;
451 ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
452 COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag", ps_seq->u1_mb_aff_flag);
453 }
454 else
455 ps_seq->u1_mb_aff_flag = 0;
456
457 ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
458
459 COPYTHECONTEXT("SPS: direct_8x8_inference_flag", ps_seq->u1_direct_8x8_inference_flag);
460
461 /* G050 */
462 u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
463 COPYTHECONTEXT("SPS: frame_cropping_flag", u1_frame_cropping_flag);
464
465 if(u1_frame_cropping_flag)
466 {
467 u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
468 COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset", u1_frame_cropping_rect_left_ofst);
469 u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
470 COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset", u1_frame_cropping_rect_right_ofst);
471 u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
472 COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset", u1_frame_cropping_rect_top_ofst);
473 u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
474 COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
475 u1_frame_cropping_rect_bottom_ofst);
476 }
477 /* G050 */
478 ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
479 COPYTHECONTEXT("SPS: vui_parameters_present_flag", ps_seq->u1_vui_parameters_present_flag);
480
481 u2_frm_wd_y = u2_pic_wd + (UWORD8) (PAD_LEN_Y_H << 1);
482 if(1 == ps_dec->u4_share_disp_buf)
483 {
484 if(ps_dec->u4_app_disp_width > u2_frm_wd_y) u2_frm_wd_y = ps_dec->u4_app_disp_width;
485 }
486
487 u2_frm_ht_y = u2_pic_ht + (UWORD8) (PAD_LEN_Y_V << 2);
488 u2_frm_wd_uv = u2_pic_wd + (UWORD8) (PAD_LEN_UV_H << 2);
489 u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
490
491 u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8) (PAD_LEN_UV_V << 2);
492 u2_frm_ht_uv = MAX(u2_frm_ht_uv, (u2_frm_ht_y >> 1));
493
494 /* Calculate display picture width, height and start u4_ofst from YUV420 */
495 /* pictute buffers as per cropping information parsed above */
496 {
497 UWORD16 u2_rgt_ofst = 0;
498 UWORD16 u2_lft_ofst = 0;
499 UWORD16 u2_top_ofst = 0;
500 UWORD16 u2_btm_ofst = 0;
501 UWORD8 u1_frm_mbs_flag;
502 UWORD8 u1_vert_mult_factor;
503
504 if(u1_frame_cropping_flag)
505 {
506 /* Calculate right and left u4_ofst for cropped picture */
507 u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
508 u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
509
510 /* Know frame MBs only u4_flag */
511 u1_frm_mbs_flag = (1 == ps_seq->u1_frame_mbs_only_flag);
512
513 /* Simplify the vertical u4_ofst calculation from field/frame */
514 u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
515
516 /* Calculate bottom and top u4_ofst for cropped picture */
517 u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst << u1_vert_mult_factor);
518 u2_top_ofst = (u1_frame_cropping_rect_top_ofst << u1_vert_mult_factor);
519 }
520
521 /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
522 /* cropped picture buffer */
523 u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
524 u2_crop_offset_uv =
525 (u2_frm_wd_uv * (u2_top_ofst >> 1)) + (u2_lft_ofst >> 1) * YUV420SP_FACTOR;
526 /* Calculate the display picture width and height based on crop */
527 /* information */
528 i4_cropped_ht = (WORD32) u2_pic_ht - (WORD32) (u2_btm_ofst + u2_top_ofst);
529 i4_cropped_wd = (WORD32) u2_pic_wd - (WORD32) (u2_rgt_ofst + u2_lft_ofst);
530
531 if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
532 {
533 return ERROR_INV_SPS_PPS_T;
534 }
535
536 if((ps_dec->i4_header_decoded & 1) &&
537 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
538 (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_wd != u2_pic_wd))
539 {
540 ps_dec->u1_res_changed = 1;
541 return IVD_RES_CHANGED;
542 }
543
544 if((ps_dec->i4_header_decoded & 1) &&
545 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
546 (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_width != i4_cropped_wd))
547 {
548 ps_dec->u1_res_changed = 1;
549 return IVD_RES_CHANGED;
550 }
551
552 if((ps_dec->i4_header_decoded & 1) &&
553 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
554 (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_ht != u2_pic_ht))
555 {
556 ps_dec->u1_res_changed = 1;
557 return IVD_RES_CHANGED;
558 }
559
560 if((ps_dec->i4_header_decoded & 1) &&
561 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
562 (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_height != i4_cropped_ht))
563 {
564 ps_dec->u1_res_changed = 1;
565 return IVD_RES_CHANGED;
566 }
567 /* Check again for unsupported resolutions with updated values*/
568 if((u2_pic_wd > SVCD_MAX_FRAME_WIDTH) || (u2_pic_ht > SVCD_MAX_FRAME_HEIGHT) ||
569 (u2_pic_wd < SVCD_MIN_FRAME_WIDTH) || (u2_pic_ht < SVCD_MIN_FRAME_HEIGHT) ||
570 (u2_pic_wd * (UWORD32) u2_pic_ht > SVCD_MAX_FRAME_SIZE))
571 {
572 return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
573 }
574
575 /* If MBAff is enabled, decoder support is limited to streams with
576 * width less than half of H264_MAX_FRAME_WIDTH.
577 * In case of MBAff decoder processes two rows at a time
578 */
579 if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
580 {
581 return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
582 }
583 }
584
585 if(1 == ps_seq->u1_vui_parameters_present_flag)
586 {
587 ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
588 if(ret != OK) return ret;
589 }
590 ps_seq_svc_ext = &ps_subset_seq->s_sps_svc_ext;
591
592 isvcd_set_default_seq_svc_ext(ps_seq_svc_ext);
593
594 if(SCALABLE_BASELINE_PROFILE_IDC == ps_seq->u1_profile_idc ||
595 SCALABLE_HIGH_PROFILE_IDC == ps_seq->u1_profile_idc)
596 {
597 SWITCHONTRACE;
598 ps_seq_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag =
599 ih264d_get_bit_h264(ps_bitstrm);
600 COPYTHECONTEXT("SPS_EXt: u1_inter_layer_deblocking_filter_control_present_flag",
601 ps_seq_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag);
602
603 ps_seq_svc_ext->u1_extended_spatial_scalability_idc = ih264d_get_bits_h264(ps_bitstrm, 2);
604 COPYTHECONTEXT("SPS_EXt: u1_extended_spatial_scalability_idc",
605 ps_seq_svc_ext->u1_extended_spatial_scalability_idc);
606
607 /* u1_extended_spatial_scalability_idc value 0, 1 and 2 are supported */
608 if(ps_seq_svc_ext->u1_extended_spatial_scalability_idc > 2)
609 {
610 return ERROR_SVC_INV_SUBSET_SPS;
611 }
612
613 /* ChromaArrayType = i4_chroma_format_idc if separate_colour_plane_flag =
614 * 0 for all chroma format except 4:4:4 */
615 if(1 == ps_seq->i4_chroma_format_idc || 2 == ps_seq->i4_chroma_format_idc)
616 {
617 ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag = ih264d_get_bit_h264(ps_bitstrm);
618 COPYTHECONTEXT("SPS_EXt: u1_chroma_phase_x_plus1_flag",
619 ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag);
620 }
621
622 if(1 == ps_seq->i4_chroma_format_idc)
623 {
624 ps_seq_svc_ext->u1_chroma_phase_y_plus1 = ih264d_get_bits_h264(ps_bitstrm, 2);
625 COPYTHECONTEXT("SPS_EXt: u1_chroma_phase_y_plus1",
626 ps_seq_svc_ext->u1_chroma_phase_y_plus1);
627
628 if(ps_seq_svc_ext->u1_chroma_phase_y_plus1 >= 3)
629 {
630 return ERROR_SVC_INV_SUBSET_SPS;
631 }
632 }
633
634 /* inferred values not covered in isvcd_set_default_seq_svc_ext*/
635 ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag =
636 ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag;
637 ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 =
638 ps_seq_svc_ext->u1_chroma_phase_y_plus1;
639
640 if(1 == ps_seq_svc_ext->u1_extended_spatial_scalability_idc)
641 {
642 if(ps_seq->i4_chroma_format_idc > 0)
643 {
644 ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag =
645 ih264d_get_bit_h264(ps_bitstrm);
646 COPYTHECONTEXT("SPS_EXt: u1_seq_ref_layer_chroma_phase_x_plus1_flag",
647 ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag);
648
649 ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 =
650 ih264d_get_bits_h264(ps_bitstrm, 2);
651 COPYTHECONTEXT("SPS_EXt: u1_seq_ref_layer_chroma_phase_y_plus1",
652 ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1);
653
654 if(ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 >= 3)
655 {
656 return ERROR_SVC_INV_SUBSET_SPS;
657 }
658 }
659
660 ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset =
661 ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
662 COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_left_offset",
663 ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset);
664
665 if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset != 0)
666 {
667 return ERROR_SVC_INV_SUBSET_SPS;
668 }
669
670 if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
671 ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset < MIN_SCLD_REF_LAYER_OFFSET)
672 {
673 return ERROR_SVC_INV_SUBSET_SPS;
674 }
675
676 ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset =
677 ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
678 COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_top_offset",
679 ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset);
680
681 if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset != 0)
682 {
683 return ERROR_SVC_INV_SUBSET_SPS;
684 }
685
686 if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
687 ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset < MIN_SCLD_REF_LAYER_OFFSET)
688 {
689 return ERROR_SVC_INV_SUBSET_SPS;
690 }
691
692 ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset =
693 ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
694 COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_right_offset",
695 ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset);
696
697 if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
698 ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset < MIN_SCLD_REF_LAYER_OFFSET)
699 {
700 return ERROR_SVC_INV_SUBSET_SPS;
701 }
702
703 ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset =
704 ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
705 COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_bottom_offset",
706 ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset);
707
708 if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
709 ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset < MIN_SCLD_REF_LAYER_OFFSET)
710 {
711 return ERROR_INV_SLICE_HDR_T;
712 }
713 }
714
715 ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag = ih264d_get_bit_h264(ps_bitstrm);
716 COPYTHECONTEXT("SPS_EXt: u1_seq_tcoeff_level_prediction_flag",
717 ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag);
718
719 if(1 == ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag)
720 {
721 ps_seq_svc_ext->u1_adaptive_tcoeff_level_prediction_flag =
722 ih264d_get_bit_h264(ps_bitstrm);
723 COPYTHECONTEXT("SPS_EXt: u1_adaptive_tcoeff_level_prediction_flag",
724 ps_seq_svc_ext->u1_adaptive_tcoeff_level_prediction_flag);
725 }
726
727 ps_seq_svc_ext->u1_slice_header_restriction_flag = ih264d_get_bit_h264(ps_bitstrm);
728 COPYTHECONTEXT("SPS_EXt: u1_slice_header_restriction_flag",
729 ps_seq_svc_ext->u1_slice_header_restriction_flag);
730
731 ps_seq_svc_ext->u1_svc_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
732 COPYTHECONTEXT("SPS_EXt: u1_svc_vui_parameters_present_flag",
733 ps_seq_svc_ext->u1_svc_vui_parameters_present_flag);
734
735 if(1 == ps_seq_svc_ext->u1_svc_vui_parameters_present_flag)
736 {
737 if(NULL ==
738 ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].s_sps_svc_ext.ps_svc_vui_ext)
739 {
740 void *pv_buf;
741 UWORD32 size;
742 /* Memory allocation only if VUI is enabled in a particular subset SPS*/
743 size = sizeof(svc_vui_ext_t);
744 pv_buf = ps_dec->pf_aligned_alloc(ps_dec->pv_mem_ctxt, 128, size);
745 RETURN_IF((NULL == pv_buf), IV_FAIL);
746 memset(pv_buf, 0, size);
747 ps_seq_svc_ext->ps_svc_vui_ext = pv_buf;
748 ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id]
749 .s_sps_svc_ext.ps_svc_vui_ext = pv_buf;
750 }
751 else
752 {
753 ps_seq_svc_ext->ps_svc_vui_ext =
754 ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id]
755 .s_sps_svc_ext.ps_svc_vui_ext;
756 }
757 ret = isvcd_parse_vui_ext_parametres(ps_seq_svc_ext->ps_svc_vui_ext, ps_bitstrm);
758 if(ret != OK) return ret;
759 }
760 }
761 /* Add conditions for SCALABLE BASELINE PROFILE */
762 if(SCALABLE_BASELINE_PROFILE_IDC == ps_seq->u1_profile_idc ||
763 ((SCALABLE_HIGH_PROFILE_IDC == ps_seq->u1_profile_idc) && (1 == uc_constraint_set0_flag)))
764 {
765 if(ps_seq->i4_chroma_format_idc != 1)
766 {
767 return ERROR_FEATURE_UNAVAIL;
768 }
769
770 if(ps_seq->i4_bit_depth_luma_minus8 != 0)
771 {
772 return ERROR_FEATURE_UNAVAIL;
773 }
774
775 if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
776 {
777 return ERROR_FEATURE_UNAVAIL;
778 }
779
780 if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
781 {
782 return ERROR_FEATURE_UNAVAIL;
783 }
784
785 if(ps_seq->u1_frame_mbs_only_flag != 1)
786 {
787 return ERROR_FEATURE_UNAVAIL;
788 }
789
790 if((0 != ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset % 16) &&
791 (0 != ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset % 16))
792 {
793 return ERROR_FEATURE_UNAVAIL;
794 }
795 }
796 /* Compare older num_reorder_frames with the new one if header is already
797 * decoded */
798 if((ps_dec->i4_header_decoded & 1) &&
799 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
800 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_vui_parameters_present_flag) &&
801 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].s_vui.u1_bitstream_restriction_flag))
802 {
803 ps_dec->u1_res_changed = 1;
804 return IVD_RES_CHANGED;
805 }
806 /* In case bitstream read has exceeded the filled size, then return an error */
807 if(EXCEED_OFFSET(ps_bitstrm))
808 {
809 return ERROR_INV_SPS_PPS_T;
810 }
811
812 /*--------------------------------------------------------------------*/
813 /* All initializations to ps_dec are beyond this point */
814 /*--------------------------------------------------------------------*/
815 {
816 WORD32 reorder_depth = ih264d_get_dpb_size(ps_seq);
817 if((1 == ps_seq->u1_vui_parameters_present_flag) &&
818 (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
819 {
820 reorder_depth = ps_seq->s_vui.u4_num_reorder_frames + 1;
821 }
822
823 if(reorder_depth > H264_MAX_REF_PICS)
824 {
825 return ERROR_INV_SPS_PPS_T;
826 }
827
828 if(ps_seq->u1_frame_mbs_only_flag != 1) reorder_depth *= 2;
829 ps_subset_seq->i4_reorder_depth = reorder_depth + DISPLAY_LATENCY;
830 }
831 ps_subset_seq->u2_disp_height = i4_cropped_ht;
832 ps_subset_seq->u2_disp_width = i4_cropped_wd;
833 ps_subset_seq->u2_pic_wd = u2_pic_wd;
834 ps_subset_seq->u2_pic_ht = u2_pic_ht;
835
836 /* Assuming 8k is the maximum resolution svc dec supports*/
837 if(u2_frm_wd_y > H264_MAX_FRAME_WIDTH) return (NOT_OK);
838 if(u2_frm_ht_y > H264_MAX_FRAME_HEIGHT) return (NOT_OK);
839 if(u2_frm_wd_uv > H264_MAX_FRAME_WIDTH) return (NOT_OK);
840 if(u2_frm_ht_uv > H264_MAX_FRAME_HEIGHT) return (NOT_OK);
841
842 /* Determining the Width and Height of Frame from that of Picture */
843 ps_subset_seq->u2_frm_wd_y = u2_frm_wd_y;
844 ps_subset_seq->u2_frm_ht_y = u2_frm_ht_y;
845 ps_subset_seq->u2_frm_wd_uv = u2_frm_wd_uv;
846 ps_subset_seq->u2_frm_ht_uv = u2_frm_ht_uv;
847
848 ps_subset_seq->u1_pad_len_y_v = (UWORD8) (PAD_LEN_Y_V << (1 - u1_frm));
849 ps_subset_seq->u1_pad_len_cr_v = (UWORD8) (PAD_LEN_UV_V << (1 - u1_frm));
850
851 ps_subset_seq->u2_crop_offset_y = u2_crop_offset_y;
852 ps_subset_seq->u2_crop_offset_uv = u2_crop_offset_uv;
853
854 ps_seq->u1_is_valid = TRUE;
855 ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
856 if(NULL != ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].s_sps_svc_ext.ps_svc_vui_ext)
857 {
858 ps_seq_svc_ext->ps_svc_vui_ext =
859 ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].s_sps_svc_ext.ps_svc_vui_ext;
860 }
861 ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id] = *ps_subset_seq;
862 ps_svc_lyr_dec->ps_cur_subset_sps = &ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id];
863
864 return OK;
865 }
866 /*!
867 **************************************************************************
868 * \if Function name : isvcd_dec_ref_base_pic_marking \endif
869 *
870 * \brief
871 * Decodes reference base pic marking params
872 *
873 * \return
874 * 0 on Success and error code otherwise
875 **************************************************************************
876 */
877
isvcd_dec_ref_base_pic_marking(dec_ref_base_pic_marking_params_t * ps_ref_base_pic_marking_svc_ext,dec_bit_stream_t * ps_bitstrm)878 WORD32 isvcd_dec_ref_base_pic_marking(
879 dec_ref_base_pic_marking_params_t *ps_ref_base_pic_marking_svc_ext,
880 dec_bit_stream_t *ps_bitstrm)
881 {
882 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
883 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
884
885 SWITCHONTRACE;
886
887 ps_ref_base_pic_marking_svc_ext->u1_adaptive_ref_base_pic_marking_mode_flag =
888 ih264d_get_bit_h264(ps_bitstrm);
889 COPYTHECONTEXT(
890 "Dec ref base pic marking params : "
891 "u1_adaptive_ref_base_pic_marking_mode_flag",
892 ps_ref_base_pic_marking_svc_ext->u1_adaptive_ref_base_pic_marking_mode_flag);
893
894 if(1 == ps_ref_base_pic_marking_svc_ext->u1_adaptive_ref_base_pic_marking_mode_flag)
895 {
896 do
897 {
898 ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation =
899 ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
900 COPYTHECONTEXT(
901 "Dec ref base pic marking params : "
902 "u4_memory_management_base_control_operation",
903 ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation);
904
905 if(1 == ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation)
906 {
907 ps_ref_base_pic_marking_svc_ext->u4_difference_of_base_pic_nums_minus1 =
908 ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
909 COPYTHECONTEXT(
910 "Dec ref base pic marking params : "
911 "u4_difference_of_base_pic_nums_minus1",
912 ps_ref_base_pic_marking_svc_ext->u4_difference_of_base_pic_nums_minus1);
913 }
914
915 if(2 == ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation)
916 {
917 ps_ref_base_pic_marking_svc_ext->u4_long_term_base_pic_num =
918 ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
919 COPYTHECONTEXT("Dec ref base pic marking params : u4_long_term_base_pic_num",
920 ps_ref_base_pic_marking_svc_ext->u4_long_term_base_pic_num);
921 }
922
923 } while(0 != ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation);
924 }
925 SWITCHOFFTRACE;
926
927 return OK;
928 }
929
930 /*!
931 **************************************************************************
932 * \if Function name : isvcd_parse_nal_unit \endif
933 *
934 * \brief
935 * Decodes NAL unit
936 *
937 * \return
938 * 0 on Success and error code otherwise
939 **************************************************************************
940 */
941
isvcd_parse_nal_unit(svc_dec_lyr_struct_t * dec_svc_hdl,UWORD8 u1_nal_ref_idc)942 WORD32 isvcd_parse_nal_unit(svc_dec_lyr_struct_t *dec_svc_hdl, UWORD8 u1_nal_ref_idc)
943 {
944 dec_bit_stream_t *ps_bitstrm;
945
946 dec_struct_t *ps_dec;
947 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
948 UWORD8 u1_nal_unit_type;
949 WORD32 i_status = OK;
950
951 ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) dec_svc_hdl;
952 ps_dec = &ps_svc_lyr_dec->s_dec;
953
954 {
955 SWITCHOFFTRACE;
956 u1_nal_unit_type = ps_dec->u1_nal_unit_type;
957
958 ps_bitstrm = ps_dec->ps_bitstrm;
959
960 // Skip all NALUs if SPS and PPS are not decoded
961 switch(u1_nal_unit_type)
962 {
963 case SLICE_DATA_PARTITION_A_NAL:
964 case SLICE_DATA_PARTITION_B_NAL:
965 case SLICE_DATA_PARTITION_C_NAL:
966 if(!ps_dec->i4_decode_header) ih264d_parse_slice_partition(ps_dec, ps_bitstrm);
967 break;
968
969 case IDR_SLICE_NAL:
970 case SLICE_NAL:
971
972 if(ps_svc_lyr_dec->u1_base_res_flag != 1)
973 {
974 return NOT_OK;
975 }
976 if(!ps_dec->i4_decode_header)
977 {
978 if(ps_dec->i4_header_decoded == 3)
979 {
980 /* ! */
981 DEBUG_THREADS_PRINTF("Decoding a slice NAL\n");
982 {
983 ih264d_get_pre_sei_params(ps_dec, u1_nal_unit_type);
984 /* ! */
985 ps_dec->u4_slice_start_code_found = 1;
986
987 i_status = isvcd_parse_decode_slice(
988 (UWORD8) (u1_nal_unit_type == IDR_SLICE_NAL), u1_nal_ref_idc,
989 ps_svc_lyr_dec);
990
991 if(i_status != OK)
992 {
993 return i_status;
994 }
995 }
996 }
997 }
998 break;
999
1000 case SEI_NAL:
1001 case PREFIX_UNIT_NAL:
1002 case SEQ_PARAM_NAL:
1003 case PIC_PARAM_NAL:
1004 case SUBSET_SPS_NAL:
1005 H264_DEC_DEBUG_PRINT("\nUnknown NAL type %d\n", u1_nal_unit_type);
1006 break;
1007
1008 case ACCESS_UNIT_DELIMITER_RBSP:
1009 if(!ps_dec->i4_decode_header)
1010 {
1011 ih264d_access_unit_delimiter_rbsp(ps_dec);
1012 }
1013 break;
1014 // ignore the END_OF_SEQ_RBSP NAL and decode even after this NAL
1015 case END_OF_STREAM_RBSP:
1016 if(!ps_dec->i4_decode_header)
1017 {
1018 ih264d_parse_end_of_stream(ps_dec);
1019 }
1020 break;
1021 case FILLER_DATA_NAL:
1022 if(!ps_dec->i4_decode_header)
1023 {
1024 ih264d_parse_filler_data(ps_dec, ps_bitstrm);
1025 }
1026 break;
1027 case CODED_SLICE_EXTENSION_NAL:
1028
1029 if(ps_svc_lyr_dec->u1_base_res_flag == 1)
1030 {
1031 return NOT_OK;
1032 }
1033 if(!ps_dec->i4_decode_header)
1034 {
1035 if(ps_dec->i4_header_decoded == 3)
1036 {
1037 /* ! */
1038 DEBUG_THREADS_PRINTF("Decoding an SVC slice NAL\n");
1039 {
1040 {
1041 ih264d_get_pre_sei_params(ps_dec, u1_nal_unit_type);
1042 /* ! */
1043 ps_dec->u4_slice_start_code_found = 1;
1044
1045 i_status = isvcd_parse_decode_slice_ext_nal(
1046 (UWORD8) (ps_svc_lyr_dec->ps_nal_svc_ext->u1_idr_flag),
1047 u1_nal_ref_idc, ps_svc_lyr_dec);
1048
1049 if(i_status != OK)
1050 {
1051 return i_status;
1052 }
1053 }
1054 }
1055 }
1056 }
1057 break;
1058
1059 default:
1060 H264_DEC_DEBUG_PRINT("\nUnknown NAL type %d\n", u1_nal_unit_type);
1061 break;
1062 }
1063 }
1064 return i_status;
1065 }
1066
1067 /*!
1068 **************************************************************************
1069 * \if Function name : isvcd_parse_sps \endif
1070 *
1071 * \brief
1072 * Decodes Picture Parameter set
1073 *
1074 * \return
1075 * 0 on Success and Error code otherwise
1076 **************************************************************************
1077 */
isvcd_parse_sps(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_bit_stream_t * ps_bitstrm)1078 WORD32 isvcd_parse_sps(svc_dec_lyr_struct_t *ps_svc_lyr_dec, dec_bit_stream_t *ps_bitstrm)
1079 {
1080 dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1081 UWORD8 i;
1082 dec_seq_params_t *ps_seq = NULL;
1083 dec_svc_seq_params_t *ps_subset_seq = NULL;
1084 UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
1085 UWORD16 i2_max_frm_num;
1086 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1087 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1088 UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag, uc_constraint_set2_flag;
1089 WORD32 i4_cropped_ht, i4_cropped_wd;
1090 UWORD32 u4_temp;
1091 UWORD64 u8_temp;
1092 UWORD32 u4_pic_height_in_map_units, u4_pic_width_in_mbs;
1093 UWORD32 u2_pic_wd = 0;
1094 UWORD32 u2_pic_ht = 0;
1095 UWORD32 u2_frm_wd_y = 0;
1096 UWORD32 u2_frm_ht_y = 0;
1097 UWORD32 u2_frm_wd_uv = 0;
1098 UWORD32 u2_frm_ht_uv = 0;
1099 UWORD32 u2_crop_offset_y = 0;
1100 UWORD32 u2_crop_offset_uv = 0;
1101 WORD32 ret;
1102 WORD32 num_reorder_frames;
1103 /* High profile related syntax element */
1104 WORD32 i4_i;
1105 /* G050 */
1106 UWORD8 u1_frame_cropping_flag,
1107 u1_frame_cropping_rect_left_ofst = 0, u1_frame_cropping_rect_right_ofst = 0,
1108 u1_frame_cropping_rect_top_ofst = 0, u1_frame_cropping_rect_bottom_ofst = 0;
1109 /* G050 */
1110 /*--------------------------------------------------------------------*/
1111 /* Decode seq_parameter_set_id and profile and level values */
1112 /*--------------------------------------------------------------------*/
1113 SWITCHONTRACE;
1114 u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
1115 COPYTHECONTEXT("SPS: profile_idc", u1_profile_idc);
1116
1117 /* G050 */
1118 uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
1119 uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
1120 uc_constraint_set2_flag = ih264d_get_bit_h264(ps_bitstrm);
1121 UNUSED(uc_constraint_set2_flag);
1122 /*****************************************************/
1123 /* Read 5 bits for uc_constraint_set3_flag (1 bit) */
1124 /* and reserved_zero_4bits (4 bits) - Sushant */
1125 /*****************************************************/
1126 ih264d_get_bits_h264(ps_bitstrm, 5);
1127 /* G050 */
1128 /* Check whether particular profile is suported or not */
1129 /* Check whether particular profile is suported or not */
1130 if((u1_profile_idc != MAIN_PROFILE_IDC) && (u1_profile_idc != BASE_PROFILE_IDC) &&
1131 (u1_profile_idc != HIGH_PROFILE_IDC))
1132 {
1133 /* Apart from Baseline, main and high profile,
1134 * only extended profile is supported provided
1135 * uc_constraint_set0_flag or uc_constraint_set1_flag are set to 1
1136 */
1137 if((u1_profile_idc != EXTENDED_PROFILE_IDC) ||
1138 ((uc_constraint_set1_flag != 1) && (uc_constraint_set0_flag != 1)))
1139 {
1140 return (ERROR_FEATURE_UNAVAIL);
1141 }
1142 }
1143
1144 u1_level_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
1145 COPYTHECONTEXT("SPS: u4_level_idc", u1_level_idc);
1146
1147 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1148 if(u4_temp & MASK_ERR_SEQ_SET_ID) return ERROR_INV_SPS_PPS_T;
1149 u1_seq_parameter_set_id = u4_temp;
1150 COPYTHECONTEXT("SPS: seq_parameter_set_id", u1_seq_parameter_set_id);
1151
1152 /*--------------------------------------------------------------------*/
1153 /* Find an seq param entry in seqparam array of decStruct */
1154 /*--------------------------------------------------------------------*/
1155 ps_subset_seq = ps_svc_lyr_dec->pv_scratch_subset_sps;
1156 memset(ps_subset_seq, 0, sizeof(dec_svc_seq_params_t));
1157 ps_seq = ps_dec->pv_scratch_sps_pps;
1158 memset(ps_seq, 0, sizeof(dec_seq_params_t));
1159
1160 if((ps_dec->i4_header_decoded & 1) &&
1161 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1162 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_profile_idc != u1_profile_idc))
1163 {
1164 ps_dec->u1_res_changed = 1;
1165 return IVD_RES_CHANGED;
1166 }
1167
1168 if((ps_dec->i4_header_decoded & 1) &&
1169 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1170 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_level_idc != u1_level_idc))
1171 {
1172 ps_dec->u1_res_changed = 1;
1173 return IVD_RES_CHANGED;
1174 }
1175
1176 ps_seq->u1_profile_idc = u1_profile_idc;
1177 ps_seq->u1_level_idc = u1_level_idc;
1178 ps_seq->u1_seq_parameter_set_id = u1_seq_parameter_set_id;
1179 ps_subset_seq->ps_seq = &ps_dec->ps_sps[u1_seq_parameter_set_id];
1180
1181 /*******************************************************************/
1182 /* Initializations for high profile - Sushant */
1183 /*******************************************************************/
1184 ps_seq->i4_chroma_format_idc = 1;
1185 ps_seq->i4_bit_depth_luma_minus8 = 0;
1186 ps_seq->i4_bit_depth_chroma_minus8 = 0;
1187 ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
1188 ps_seq->i4_seq_scaling_matrix_present_flag = 0;
1189 if(u1_profile_idc == HIGH_PROFILE_IDC || u1_profile_idc == SCALABLE_BASELINE_PROFILE_IDC ||
1190 u1_profile_idc == SCALABLE_HIGH_PROFILE_IDC)
1191 {
1192 /* reading chroma_format_idc */
1193 ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1194
1195 /* Monochrome is not supported */
1196 if(ps_seq->i4_chroma_format_idc != 1)
1197 {
1198 return ERROR_FEATURE_UNAVAIL;
1199 }
1200
1201 /* reading bit_depth_luma_minus8 */
1202 ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1203
1204 if(ps_seq->i4_bit_depth_luma_minus8 != 0)
1205 {
1206 return ERROR_FEATURE_UNAVAIL;
1207 }
1208
1209 /* reading bit_depth_chroma_minus8 */
1210 ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1211
1212 if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
1213 {
1214 return ERROR_FEATURE_UNAVAIL;
1215 }
1216
1217 /* reading qpprime_y_zero_transform_bypass_flag */
1218 ps_seq->i4_qpprime_y_zero_transform_bypass_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1219
1220 if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
1221 {
1222 return ERROR_INV_SPS_PPS_T;
1223 }
1224
1225 /* reading seq_scaling_matrix_present_flag */
1226 ps_seq->i4_seq_scaling_matrix_present_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1227
1228 if(ps_seq->i4_seq_scaling_matrix_present_flag)
1229 {
1230 for(i4_i = 0; i4_i < 8; i4_i++)
1231 {
1232 ps_seq->u1_seq_scaling_list_present_flag[i4_i] = ih264d_get_bit_h264(ps_bitstrm);
1233
1234 /* initialize u1_use_default_scaling_matrix_flag[i4_i] to zero */
1235 /* before calling scaling list */
1236 ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
1237
1238 if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
1239 {
1240 if(i4_i < 6)
1241 {
1242 ret = ih264d_scaling_list(ps_seq->i2_scalinglist4x4[i4_i], 16,
1243 &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
1244 ps_bitstrm);
1245 }
1246 else
1247 {
1248 ret = ih264d_scaling_list(ps_seq->i2_scalinglist8x8[i4_i - 6], 64,
1249 &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
1250 ps_bitstrm);
1251 }
1252 if(ret != OK)
1253 {
1254 return ret;
1255 }
1256 }
1257 }
1258 }
1259 }
1260 /*--------------------------------------------------------------------*/
1261 /* Decode MaxFrameNum */
1262 /*--------------------------------------------------------------------*/
1263 u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1264 if(u8_temp > MAX_BITS_IN_FRAME_NUM)
1265 {
1266 return ERROR_INV_SPS_PPS_T;
1267 }
1268 ps_seq->u1_bits_in_frm_num = (UWORD8) u8_temp;
1269 COPYTHECONTEXT("SPS: log2_max_frame_num_minus4", (ps_seq->u1_bits_in_frm_num - 4));
1270
1271 i2_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
1272 ps_seq->u2_u4_max_pic_num_minus1 = i2_max_frm_num - 1;
1273 /*--------------------------------------------------------------------*/
1274 /* Decode picture order count and related values */
1275 /*--------------------------------------------------------------------*/
1276 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1277 if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
1278 {
1279 return ERROR_INV_POC_TYPE_T;
1280 }
1281 ps_seq->u1_pic_order_cnt_type = u4_temp;
1282 COPYTHECONTEXT("SPS: pic_order_cnt_type", ps_seq->u1_pic_order_cnt_type);
1283
1284 ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
1285 if(ps_seq->u1_pic_order_cnt_type == 0)
1286 {
1287 u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1288 if(u8_temp > MAX_BITS_IN_POC_LSB)
1289 {
1290 return ERROR_INV_SPS_PPS_T;
1291 }
1292 ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = (UWORD8) u8_temp;
1293 ps_seq->i4_max_pic_order_cntLsb = (1 << u8_temp);
1294 COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4", (u8_temp - 4));
1295 }
1296 else if(ps_seq->u1_pic_order_cnt_type == 1)
1297 {
1298 ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(ps_bitstrm);
1299 COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
1300 ps_seq->u1_delta_pic_order_always_zero_flag);
1301
1302 ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1303 COPYTHECONTEXT("SPS: offset_for_non_ref_pic", ps_seq->i4_ofst_for_non_ref_pic);
1304
1305 ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1306 COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
1307 ps_seq->i4_ofst_for_top_to_bottom_field);
1308
1309 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1310 if(u4_temp > 255) return ERROR_INV_SPS_PPS_T;
1311 ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
1312 COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
1313 ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
1314
1315 for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
1316 {
1317 ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1318 COPYTHECONTEXT("SPS: offset_for_ref_frame", ps_seq->i4_ofst_for_ref_frame[i]);
1319 }
1320 }
1321
1322 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1323
1324 if((u4_temp > H264_MAX_REF_PICS))
1325 {
1326 return ERROR_NUM_REF;
1327 }
1328
1329 /* Compare with older num_ref_frames is header is already once */
1330 if((ps_dec->i4_header_decoded & 1) &&
1331 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1332 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_num_ref_frames != u4_temp))
1333 {
1334 ps_dec->u1_res_changed = 1;
1335 return IVD_RES_CHANGED;
1336 }
1337
1338 ps_seq->u1_num_ref_frames = u4_temp;
1339 COPYTHECONTEXT("SPS: num_ref_frames", ps_seq->u1_num_ref_frames);
1340
1341 ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(ps_bitstrm);
1342 COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
1343 ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
1344
1345 ps_seq->u1_gaps_in_frame_num_value_allowed_flag = 0;
1346
1347 /*--------------------------------------------------------------------*/
1348 /* Decode FrameWidth and FrameHeight and related values */
1349 /*--------------------------------------------------------------------*/
1350 u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1351 /* Check for unsupported resolutions*/
1352 if(u8_temp > (H264_MAX_FRAME_WIDTH >> 4))
1353 {
1354 return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1355 }
1356 u4_pic_width_in_mbs = (UWORD32) u8_temp;
1357 COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1", u4_pic_width_in_mbs - 1);
1358
1359 u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1360 if(u8_temp > (H264_MAX_FRAME_HEIGHT >> 4))
1361 {
1362 return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1363 }
1364 u4_pic_height_in_map_units = (UWORD32) u8_temp;
1365
1366 ps_seq->u2_frm_wd_in_mbs = u4_pic_width_in_mbs;
1367 ps_seq->u2_frm_ht_in_mbs = u4_pic_height_in_map_units;
1368 u2_pic_wd = (u4_pic_width_in_mbs << 4);
1369 u2_pic_ht = (u4_pic_height_in_map_units << 4);
1370 if(ps_svc_lyr_dec->pic_width < u2_pic_wd)
1371 {
1372 ps_svc_lyr_dec->pic_width = u2_pic_wd;
1373 }
1374 if(ps_svc_lyr_dec->pic_height < u2_pic_ht)
1375 {
1376 ps_svc_lyr_dec->pic_height = u2_pic_ht;
1377 }
1378
1379 /*--------------------------------------------------------------------*/
1380 /* Get the value of MaxMbAddress and Number of bits needed for it */
1381 /*--------------------------------------------------------------------*/
1382 ps_seq->u2_max_mb_addr = (ps_seq->u2_frm_wd_in_mbs * ps_seq->u2_frm_ht_in_mbs) - 1;
1383 ps_seq->u2_total_num_of_mbs = ps_seq->u2_max_mb_addr + 1;
1384 ps_seq->u1_level_idc = ih264d_correct_level_idc(u1_level_idc, ps_seq->u2_total_num_of_mbs);
1385
1386 u1_frm = ih264d_get_bit_h264(ps_bitstrm);
1387 if((ps_dec->i4_header_decoded & 1) &&
1388 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1389 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_frame_mbs_only_flag != u1_frm))
1390 {
1391 ps_dec->u1_res_changed = 1;
1392 return IVD_RES_CHANGED;
1393 }
1394 ps_seq->u1_frame_mbs_only_flag = u1_frm;
1395 COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
1396
1397 if(!u1_frm) u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
1398
1399 if((ps_dec->i4_header_decoded & 1) &&
1400 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1401 (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_mb_aff_flag != u1_mb_aff_flag))
1402 {
1403 ps_dec->u1_res_changed = 1;
1404 return IVD_RES_CHANGED;
1405 }
1406
1407 if(!u1_frm)
1408 {
1409 u2_pic_ht <<= 1;
1410 ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
1411 COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag", ps_seq->u1_mb_aff_flag);
1412 }
1413 else
1414 ps_seq->u1_mb_aff_flag = 0;
1415
1416 ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
1417 COPYTHECONTEXT("SPS: direct_8x8_inference_flag", ps_seq->u1_direct_8x8_inference_flag);
1418
1419 /* G050 */
1420 u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
1421 COPYTHECONTEXT("SPS: frame_cropping_flag", u1_frame_cropping_flag);
1422
1423 if(u1_frame_cropping_flag)
1424 {
1425 u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1426 COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset", u1_frame_cropping_rect_left_ofst);
1427 u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1428 COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset", u1_frame_cropping_rect_right_ofst);
1429 u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1430 COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset", u1_frame_cropping_rect_top_ofst);
1431 u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1432 COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
1433 u1_frame_cropping_rect_bottom_ofst);
1434 }
1435 /* G050 */
1436 ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1437 COPYTHECONTEXT("SPS: vui_parameters_present_flag", ps_seq->u1_vui_parameters_present_flag);
1438
1439 u2_frm_wd_y = u2_pic_wd + (UWORD8) (PAD_LEN_Y_H << 1);
1440
1441 if(1 == ps_dec->u4_share_disp_buf)
1442 {
1443 if(ps_dec->u4_app_disp_width > u2_frm_wd_y) u2_frm_wd_y = ps_dec->u4_app_disp_width;
1444 }
1445
1446 u2_frm_ht_y = u2_pic_ht + (UWORD8) (PAD_LEN_Y_V << 2);
1447 u2_frm_wd_uv = u2_pic_wd + (UWORD8) (PAD_LEN_UV_H << 2);
1448 u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
1449 u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8) (PAD_LEN_UV_V << 2);
1450 u2_frm_ht_uv = MAX(u2_frm_ht_uv, (u2_frm_ht_y >> 1));
1451
1452 /* Calculate display picture width, height and start u4_ofst from YUV420 */
1453 /* pictute buffers as per cropping information parsed above */
1454 {
1455 UWORD16 u2_rgt_ofst = 0;
1456 UWORD16 u2_lft_ofst = 0;
1457 UWORD16 u2_top_ofst = 0;
1458 UWORD16 u2_btm_ofst = 0;
1459 UWORD8 u1_frm_mbs_flag;
1460 UWORD8 u1_vert_mult_factor;
1461
1462 if(u1_frame_cropping_flag)
1463 {
1464 /* Calculate right and left u4_ofst for cropped picture */
1465 u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
1466 u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
1467
1468 /* Know frame MBs only u4_flag */
1469 u1_frm_mbs_flag = (1 == ps_seq->u1_frame_mbs_only_flag);
1470
1471 /* Simplify the vertical u4_ofst calculation from field/frame */
1472 u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
1473
1474 /* Calculate bottom and top u4_ofst for cropped picture */
1475 u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst << u1_vert_mult_factor);
1476 u2_top_ofst = (u1_frame_cropping_rect_top_ofst << u1_vert_mult_factor);
1477 }
1478
1479 /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
1480 /* cropped picture buffer */
1481 u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
1482 u2_crop_offset_uv =
1483 (u2_frm_wd_uv * (u2_top_ofst >> 1)) + (u2_lft_ofst >> 1) * YUV420SP_FACTOR;
1484 /* Calculate the display picture width and height based on crop */
1485 /* information */
1486 i4_cropped_ht = (WORD32) u2_pic_ht - (WORD32) (u2_btm_ofst + u2_top_ofst);
1487 i4_cropped_wd = (WORD32) u2_pic_wd - (WORD32) (u2_rgt_ofst + u2_lft_ofst);
1488
1489 if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
1490 {
1491 return ERROR_INV_SPS_PPS_T;
1492 }
1493
1494 if((ps_dec->i4_header_decoded & 1) &&
1495 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1496 (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_wd != u2_pic_wd))
1497 {
1498 ps_dec->u1_res_changed = 1;
1499 return IVD_RES_CHANGED;
1500 }
1501
1502 if((ps_dec->i4_header_decoded & 1) &&
1503 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1504 (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_width != i4_cropped_wd))
1505 {
1506 ps_dec->u1_res_changed = 1;
1507 return IVD_RES_CHANGED;
1508 }
1509
1510 if((ps_dec->i4_header_decoded & 1) &&
1511 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1512 (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_ht != u2_pic_ht))
1513 {
1514 ps_dec->u1_res_changed = 1;
1515 return IVD_RES_CHANGED;
1516 }
1517
1518 if((ps_dec->i4_header_decoded & 1) &&
1519 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1520 (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_height != i4_cropped_ht))
1521 {
1522 ps_dec->u1_res_changed = 1;
1523 return IVD_RES_CHANGED;
1524 }
1525 /* Check again for unsupported resolutions with updated values*/
1526 if((u2_pic_wd > SVCD_MAX_FRAME_WIDTH) || (u2_pic_ht > SVCD_MAX_FRAME_HEIGHT) ||
1527 (u2_pic_wd < SVCD_MIN_FRAME_WIDTH) || (u2_pic_ht < SVCD_MIN_FRAME_HEIGHT) ||
1528 (u2_pic_wd * (UWORD32) u2_pic_ht > SVCD_MAX_FRAME_SIZE))
1529 {
1530 return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1531 }
1532
1533 /* If MBAff is enabled, decoder support is limited to streams with
1534 * width less than half of H264_MAX_FRAME_WIDTH.
1535 * In case of MBAff decoder processes two rows at a time
1536 */
1537 if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
1538 {
1539 return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1540 }
1541 }
1542
1543 /* Backup num_reorder_frames if header is already decoded */
1544 if((ps_dec->i4_header_decoded & 1) && (1 == ps_seq->u1_vui_parameters_present_flag) &&
1545 (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1546 {
1547 num_reorder_frames = (WORD32) ps_seq->s_vui.u4_num_reorder_frames;
1548 }
1549 else
1550 {
1551 num_reorder_frames = -1;
1552 }
1553 if(1 == ps_seq->u1_vui_parameters_present_flag)
1554 {
1555 ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
1556 if(ret != OK) return ret;
1557 }
1558
1559 /* Compare older num_reorder_frames with the new one if header is already
1560 * decoded */
1561 if((ps_dec->i4_header_decoded & 1) &&
1562 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) && (-1 != num_reorder_frames) &&
1563 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_vui_parameters_present_flag) &&
1564 (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].s_vui.u1_bitstream_restriction_flag) &&
1565 ((WORD32) ps_dec->ps_sps[u1_seq_parameter_set_id].s_vui.u4_num_reorder_frames !=
1566 num_reorder_frames))
1567 {
1568 ps_dec->u1_res_changed = 1;
1569 return IVD_RES_CHANGED;
1570 }
1571
1572 /* In case bitstream read has exceeded the filled size, then return an error */
1573 if(EXCEED_OFFSET(ps_bitstrm))
1574 {
1575 return ERROR_INV_SPS_PPS_T;
1576 }
1577
1578 /*--------------------------------------------------------------------*/
1579 /* All initializations to ps_dec are beyond this point */
1580 /*--------------------------------------------------------------------*/
1581 {
1582 WORD32 reorder_depth = ih264d_get_dpb_size(ps_seq);
1583 if((1 == ps_seq->u1_vui_parameters_present_flag) &&
1584 (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1585 {
1586 reorder_depth = ps_seq->s_vui.u4_num_reorder_frames + 1;
1587 }
1588
1589 if(reorder_depth > H264_MAX_REF_PICS)
1590 {
1591 return ERROR_INV_SPS_PPS_T;
1592 }
1593
1594 if(ps_seq->u1_frame_mbs_only_flag != 1) reorder_depth *= 2;
1595 ps_subset_seq->i4_reorder_depth = reorder_depth + DISPLAY_LATENCY;
1596 }
1597 ps_subset_seq->u2_disp_height = i4_cropped_ht;
1598 ps_subset_seq->u2_disp_width = i4_cropped_wd;
1599 ps_subset_seq->u2_pic_wd = u2_pic_wd;
1600 ps_subset_seq->u2_pic_ht = u2_pic_ht;
1601
1602 /* Determining the Width and Height of Frame from that of Picture */
1603 ps_subset_seq->u2_frm_wd_y = u2_frm_wd_y;
1604 ps_subset_seq->u2_frm_ht_y = u2_frm_ht_y;
1605 ps_subset_seq->u2_frm_wd_uv = u2_frm_wd_uv;
1606 ps_subset_seq->u2_frm_ht_uv = u2_frm_ht_uv;
1607
1608 ps_subset_seq->u1_pad_len_y_v = (UWORD8) (PAD_LEN_Y_V << (1 - u1_frm));
1609 ps_subset_seq->u1_pad_len_cr_v = (UWORD8) (PAD_LEN_UV_V << (1 - u1_frm));
1610
1611 ps_subset_seq->u2_crop_offset_y = u2_crop_offset_y;
1612 ps_subset_seq->u2_crop_offset_uv = u2_crop_offset_uv;
1613
1614 ps_seq->u1_is_valid = TRUE;
1615 ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
1616 ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id] = *ps_subset_seq;
1617 ps_svc_lyr_dec->ps_cur_subset_sps = &ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id];
1618
1619 return OK;
1620 }
1621
1622 /*!
1623 **************************************************************************
1624 * \if Function name : isvcd_parse_pps \endif
1625 *
1626 * \brief
1627 * Decodes Picture Parameter set
1628 *
1629 * \return
1630 * 0 on Success and Error code otherwise
1631 **************************************************************************
1632 */
isvcd_parse_pps(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_bit_stream_t * ps_bitstrm)1633 WORD32 isvcd_parse_pps(svc_dec_lyr_struct_t *ps_svc_lyr_dec, dec_bit_stream_t *ps_bitstrm)
1634 {
1635 dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1636 UWORD8 uc_temp;
1637 dec_seq_params_t *ps_sps = NULL;
1638 dec_pic_params_t *ps_pps = NULL;
1639 UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
1640 UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
1641
1642 /* Variables used for error resilience checks */
1643 UWORD64 u8_temp;
1644 UWORD32 u4_temp;
1645 WORD32 i_temp;
1646
1647 /* For High profile related syntax elements */
1648 UWORD8 u1_more_data_flag;
1649 WORD32 i4_i;
1650
1651 /*--------------------------------------------------------------------*/
1652 /* Decode pic_parameter_set_id and find corresponding pic params */
1653 /*--------------------------------------------------------------------*/
1654 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1655 if(u4_temp & MASK_ERR_PIC_SET_ID) return ERROR_INV_SPS_PPS_T;
1656 ps_pps = ps_dec->pv_scratch_sps_pps;
1657 *ps_pps = ps_dec->ps_pps[u4_temp];
1658 ps_pps->u1_pic_parameter_set_id = (UWORD8) u4_temp;
1659 COPYTHECONTEXT("PPS: pic_parameter_set_id", ps_pps->u1_pic_parameter_set_id);
1660
1661 /************************************************/
1662 /* initilization of High profile syntax element */
1663 /************************************************/
1664 ps_pps->i4_transform_8x8_mode_flag = 0;
1665 ps_pps->i4_pic_scaling_matrix_present_flag = 0;
1666
1667 /*--------------------------------------------------------------------*/
1668 /* Decode seq_parameter_set_id and map it to a seq_parameter_set */
1669 /*--------------------------------------------------------------------*/
1670 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1671 if(u4_temp & MASK_ERR_SEQ_SET_ID) return ERROR_INV_SPS_PPS_T;
1672 COPYTHECONTEXT("PPS: seq_parameter_set_id", u4_temp);
1673 ps_sps = &ps_dec->ps_sps[u4_temp];
1674 ps_pps->ps_sps = ps_sps;
1675
1676 /*--------------------------------------------------------------------*/
1677 /* Decode entropy_coding_mode */
1678 /*--------------------------------------------------------------------*/
1679 ps_pps->u1_entropy_coding_mode = ih264d_get_bit_h264(ps_bitstrm);
1680 COPYTHECONTEXT("PPS: entropy_coding_mode_flag", ps_pps->u1_entropy_coding_mode);
1681
1682 ps_pps->u1_pic_order_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1683 COPYTHECONTEXT("PPS: pic_order_present_flag", ps_pps->u1_pic_order_present_flag);
1684
1685 /*--------------------------------------------------------------------*/
1686 /* Decode num_slice_groups_minus1 */
1687 /*--------------------------------------------------------------------*/
1688 u8_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf) + (UWORD64) 1;
1689 if(u8_temp != 1)
1690 {
1691 return ERROR_FEATURE_UNAVAIL;
1692 }
1693 ps_pps->u1_num_slice_groups = (UWORD8) u8_temp;
1694 COPYTHECONTEXT("PPS: num_slice_groups_minus1", ps_pps->u1_num_slice_groups - 1);
1695
1696 /*--------------------------------------------------------------------*/
1697 /* Other parameter set values */
1698 /*--------------------------------------------------------------------*/
1699 u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1700 if(u8_temp >= H264_MAX_REF_IDX) return ERROR_REF_IDX;
1701 ps_pps->u1_num_ref_idx_lx_active[0] = (UWORD8) u8_temp;
1702 COPYTHECONTEXT("PPS: num_ref_idx_l0_active_minus1", ps_pps->u1_num_ref_idx_lx_active[0] - 1);
1703
1704 u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1705 if(u8_temp >= H264_MAX_REF_IDX) return ERROR_REF_IDX;
1706 ps_pps->u1_num_ref_idx_lx_active[1] = (UWORD8) u8_temp;
1707 COPYTHECONTEXT("PPS: num_ref_idx_l1_active_minus1", ps_pps->u1_num_ref_idx_lx_active[1] - 1);
1708
1709 ps_pps->u1_wted_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
1710 COPYTHECONTEXT("PPS: weighted prediction u4_flag", ps_pps->u1_wted_pred_flag);
1711 uc_temp = (UWORD8) ih264d_get_bits_h264(ps_bitstrm, 2);
1712 COPYTHECONTEXT("PPS: weighted_bipred_idc", uc_temp);
1713 ps_pps->u1_wted_bipred_idc = uc_temp;
1714
1715 if(ps_pps->u1_wted_bipred_idc > MAX_WEIGHT_BIPRED_IDC) return ERROR_INV_SPS_PPS_T;
1716
1717 {
1718 WORD64 i8_temp = (WORD64) 26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1719
1720 if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP)) return ERROR_INV_RANGE_QP_T;
1721
1722 ps_pps->u1_pic_init_qp = (UWORD8) i8_temp;
1723 COPYTHECONTEXT("PPS: pic_init_qp_minus26", ps_pps->u1_pic_init_qp - 26);
1724
1725 i8_temp = (WORD64) 26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1726 if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP)) return ERROR_INV_RANGE_QP_T;
1727
1728 ps_pps->u1_pic_init_qs = (UWORD8) i8_temp;
1729 COPYTHECONTEXT("PPS: pic_init_qs_minus26", ps_pps->u1_pic_init_qs - 26);
1730 }
1731
1732 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1733 if((i_temp < -12) || (i_temp > 12)) return ERROR_INV_RANGE_QP_T;
1734 ps_pps->i1_chroma_qp_index_offset = i_temp;
1735 COPYTHECONTEXT("PPS: chroma_qp_index_offset", ps_pps->i1_chroma_qp_index_offset);
1736
1737 /***************************************************************************/
1738 /* initialize second_chroma_qp_index_offset to i1_chroma_qp_index_offset if */
1739 /* second_chroma_qp_index_offset is not present in bit-ps_bitstrm */
1740 /***************************************************************************/
1741 ps_pps->i1_second_chroma_qp_index_offset = ps_pps->i1_chroma_qp_index_offset;
1742
1743 ps_pps->u1_deblocking_filter_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1744 COPYTHECONTEXT("PPS: deblocking_filter_control_present_flag",
1745 ps_pps->u1_deblocking_filter_parameters_present_flag);
1746 ps_pps->u1_constrained_intra_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
1747 COPYTHECONTEXT("PPS: constrained_intra_pred_flag", ps_pps->u1_constrained_intra_pred_flag);
1748 ps_pps->u1_redundant_pic_cnt_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1749 COPYTHECONTEXT("PPS: redundant_pic_cnt_present_flag",
1750 ps_pps->u1_redundant_pic_cnt_present_flag);
1751
1752 /* High profile related syntax elements */
1753 u1_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
1754
1755 if(u1_more_data_flag)
1756 {
1757 /* read transform_8x8_mode_flag */
1758 ps_pps->i4_transform_8x8_mode_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1759
1760 /* read pic_scaling_matrix_present_flag */
1761 ps_pps->i4_pic_scaling_matrix_present_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1762
1763 if(ps_pps->i4_pic_scaling_matrix_present_flag)
1764 {
1765 /* read the scaling matrices */
1766 for(i4_i = 0; i4_i < (6 + (ps_pps->i4_transform_8x8_mode_flag << 1)); i4_i++)
1767 {
1768 ps_pps->u1_pic_scaling_list_present_flag[i4_i] = ih264d_get_bit_h264(ps_bitstrm);
1769
1770 if(ps_pps->u1_pic_scaling_list_present_flag[i4_i])
1771 {
1772 WORD32 ret;
1773 if(i4_i < 6)
1774 {
1775 ret = ih264d_scaling_list(
1776 ps_pps->i2_pic_scalinglist4x4[i4_i], 16,
1777 &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i], ps_bitstrm);
1778 }
1779 else
1780 {
1781 ret = ih264d_scaling_list(
1782 ps_pps->i2_pic_scalinglist8x8[i4_i - 6], 64,
1783 &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i], ps_bitstrm);
1784 }
1785
1786 if(ret != OK)
1787 {
1788 return ret;
1789 }
1790 }
1791 }
1792 }
1793
1794 /* read second_chroma_qp_index_offset syntax element */
1795 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1796 if((i_temp < -12) || (i_temp > 12)) return ERROR_INV_RANGE_QP_T;
1797
1798 ps_pps->i1_second_chroma_qp_index_offset = i_temp;
1799 }
1800
1801 if(SCALABLE_BASELINE_PROFILE_IDC == ps_sps->u1_profile_idc)
1802
1803 {
1804 if(ps_pps->u1_num_slice_groups > 7)
1805 {
1806 return ERROR_INV_SPS_PPS_T;
1807 }
1808 }
1809
1810 /* In case bitstream read has exceeded the filled size, then return an error */
1811 if(EXCEED_OFFSET(ps_bitstrm))
1812 {
1813 return ERROR_INV_SPS_PPS_T;
1814 }
1815 ps_pps->u1_is_valid = TRUE;
1816 ps_dec->ps_pps[ps_pps->u1_pic_parameter_set_id] = *ps_pps;
1817 return OK;
1818 }
1819