1 //#define H264_PARSE_SPS_C
2 //#ifdef H264_PARSE_SPS_C
3 
4 #include "h264.h"
5 #include "h264parse.h"
6 
7 
8 /// SPS extension unit (unit_type = 13)
9 ///
10 #if 0
11 h264_Status h264_Parse_SeqParameterSet_Extension(void *parent,h264_Info * pInfo)
12 {
13 	/*h264_SPS_Extension_RBSP_t* SPS_ext = pInfo->p_active_SPS_ext;
14 
15 	SPS_ext->seq_parameter_set_id = h264_GetVLCElement(pInfo, false);
16 	if(SPS_ext->seq_parameter_set_id > MAX_SEQ_PARAMS-1)
17 	{
18 		return H264_SPS_ERROR;
19 	}
20 	SPS_ext->aux_format_idc = h264_GetVLCElement(pInfo, false);
21 	if(SPS_ext->aux_format_idc  > 3)
22 	{
23 		return H264_SPS_ERROR;
24 	}
25 	if(SPS_ext->aux_format_idc != 0)
26 	{
27 		SPS_ext->bit_depth_aux_minus8 = h264_GetVLCElement(pInfo, false);
28 		if(SPS_ext->bit_depth_aux_minus8 + 8 > 12)
29 		{
30 			return H264_SPS_ERROR;
31 		}
32 
33 		SPS_ext->alpha_incr_flag = h264_GetBits(pInfo, 1, "alpha_incr_flag");
34 		if(SPS_ext->alpha_incr_flag > 1)
35 		{
36 			return H264_SPS_ERROR;
37 		}
38 
39 		SPS_ext->alpha_opaque_value = h264_GetBits(pInfo,(SPS_ext->bit_depth_aux_minus8+8+1), "alpha_opaque_value");		//+8 to get the bit_depth value
40 		SPS_ext->alpha_transparent_value = h264_GetBits(pInfo,(SPS_ext->bit_depth_aux_minus8+8+1), "alpha_transparent_value");		//+8 to get the bit_depth value
41 	}
42 	SPS_ext->additional_extension_flag = h264_GetBits(pInfo, 1, "additional_extension_flag");
43 */
44 	return H264_STATUS_OK;
45 }
46 #endif
47 
48 
h264_Parse_HRD_Parameters(void * parent,h264_Info * pInfo,int nal_hrd,seq_param_set_used_ptr SPS,vui_seq_parameters_t_not_used_ptr pVUI_Seq_Not_Used)49 h264_Status h264_Parse_HRD_Parameters(void *parent, h264_Info* pInfo, int nal_hrd,seq_param_set_used_ptr SPS, vui_seq_parameters_t_not_used_ptr pVUI_Seq_Not_Used)
50 {
51 	//seq_param_set_ptr SPS = pInfo->p_active_SPS;
52 	int32_t i = 0;
53 	uint32_t code;
54 
55 
56 	if(nal_hrd)
57 	{
58 		SPS->sps_disp.vui_seq_parameters.nal_hrd_cpb_cnt_minus1 = h264_GetVLCElement(parent, pInfo, false);
59 
60 		if(SPS->sps_disp.vui_seq_parameters.nal_hrd_cpb_cnt_minus1 >= MAX_CPB_CNT)
61 		{
62 			return H264_SPS_ERROR;
63 		}
64 
65 		viddec_pm_get_bits(parent, &code, 8);
66       pVUI_Seq_Not_Used->nal_hrd_bit_rate_scale = (uint8_t)(code>>4);
67 		pVUI_Seq_Not_Used->nal_hrd_cpb_size_scale = (uint8_t)(code & 0xf);
68 
69 		for(i=0; i<=SPS->sps_disp.vui_seq_parameters.nal_hrd_cpb_cnt_minus1; i++)
70 		{
71 			pVUI_Seq_Not_Used->nal_hrd_parameters.bit_rate_value_minus1[i] = h264_GetVLCElement(parent, pInfo, false);
72 			pVUI_Seq_Not_Used->nal_hrd_parameters.cpb_size_value_minus1[i] = h264_GetVLCElement(parent, pInfo, false);
73 
74 			viddec_pm_get_bits(parent, &code, 1);
75 			pVUI_Seq_Not_Used->nal_hrd_parameters.cbr_flag[i] = (uint8_t)code;
76 		}
77 
78 		if( viddec_pm_get_bits(parent, &code, 20) == -1)
79 			return H264_SPS_ERROR;
80 
81 		SPS->sps_disp.vui_seq_parameters.nal_hrd_initial_cpb_removal_delay_length_minus1 = (uint8_t)((code>>15)&0x1f);
82 		SPS->sps_disp.vui_seq_parameters.nal_hrd_cpb_removal_delay_length_minus1 = (uint8_t)((code>>10)&0x1f);;
83 		SPS->sps_disp.vui_seq_parameters.nal_hrd_dpb_output_delay_length_minus1 = (uint8_t)((code>>5)&0x1f);;
84 		SPS->sps_disp.vui_seq_parameters.nal_hrd_time_offset_length = (uint8_t)(code&0x1f);;
85 
86 	}
87 	else
88 	{
89 		SPS->sps_disp.vui_seq_parameters.vcl_hrd_cpb_cnt_minus1 = h264_GetVLCElement(parent, pInfo, false);
90 
91 		if(SPS->sps_disp.vui_seq_parameters.vcl_hrd_cpb_cnt_minus1 >= MAX_CPB_CNT)
92 		{
93 			return H264_SPS_ERROR;
94 		}
95 
96 		viddec_pm_get_bits(parent, &code, 8);
97 		pVUI_Seq_Not_Used->vcl_hrd_bit_rate_scale = (uint8_t)(code>>4);
98 		pVUI_Seq_Not_Used->vcl_hrd_cpb_size_scale = (uint8_t)(code&0xf);
99 
100 		for(i=0; i<=SPS->sps_disp.vui_seq_parameters.vcl_hrd_cpb_cnt_minus1; i++)
101 		{
102 			pVUI_Seq_Not_Used->vcl_hrd_parameters.bit_rate_value_minus1[i] = h264_GetVLCElement(parent, pInfo, false);
103 			pVUI_Seq_Not_Used->vcl_hrd_parameters.cpb_size_value_minus1[i] = h264_GetVLCElement(parent, pInfo, false);
104 			viddec_pm_get_bits(parent, &code, 1);
105 			pVUI_Seq_Not_Used->vcl_hrd_parameters.cbr_flag[i] = (uint8_t)code;
106 		}
107 
108 		if( viddec_pm_get_bits(parent, &code, 20) == -1)
109 			return H264_SPS_ERROR;
110 
111 		SPS->sps_disp.vui_seq_parameters.vcl_hrd_initial_cpb_removal_delay_length_minus1 = (uint8_t)((code>>15)&0x1f);
112 		SPS->sps_disp.vui_seq_parameters.vcl_hrd_cpb_removal_delay_length_minus1 = (uint8_t)((code>>10)&0x1f);;
113 		SPS->sps_disp.vui_seq_parameters.vcl_hrd_dpb_output_delay_length_minus1 = (uint8_t)((code>>5)&0x1f);;
114 		SPS->sps_disp.vui_seq_parameters.vcl_hrd_time_offset_length = (uint8_t)(code&0x1f);;
115 	}
116 
117 	return H264_STATUS_OK;
118 }
119 
120 
121 
h264_Parse_Vui_Parameters(void * parent,h264_Info * pInfo,seq_param_set_used_ptr SPS,vui_seq_parameters_t_not_used_ptr pVUI_Seq_Not_Used)122 h264_Status h264_Parse_Vui_Parameters(void *parent, h264_Info* pInfo, seq_param_set_used_ptr SPS, vui_seq_parameters_t_not_used_ptr pVUI_Seq_Not_Used)
123 {
124 	h264_Status ret = H264_STATUS_OK;
125 	//seq_param_set_ptr SPS = pInfo->p_active_SPS;
126 	int32_t nal_hrd = 0;
127 	uint32_t code;
128 
129 	do {
130 		viddec_pm_get_bits(parent, &code, 1);
131 		SPS->sps_disp.vui_seq_parameters.aspect_ratio_info_present_flag = (uint8_t)code;
132 
133 
134 		if(SPS->sps_disp.vui_seq_parameters.aspect_ratio_info_present_flag)
135 		{
136 			viddec_pm_get_bits(parent, &code, 8);
137 			SPS->sps_disp.vui_seq_parameters.aspect_ratio_idc = (uint8_t)code;
138 
139 			if(SPS->sps_disp.vui_seq_parameters.aspect_ratio_idc == h264_AR_Extended_SAR)
140 			{
141 				viddec_pm_get_bits(parent, &code, 16);
142 				SPS->sps_disp.vui_seq_parameters.sar_width = (uint16_t)code;
143 
144 				viddec_pm_get_bits(parent, &code, 16);
145 				SPS->sps_disp.vui_seq_parameters.sar_height = (uint16_t)code;
146 
147 			}
148 		}
149 
150 		viddec_pm_get_bits(parent, &code, 1);
151 		pVUI_Seq_Not_Used->overscan_info_present_flag = (uint8_t)code;
152 
153 		if(pVUI_Seq_Not_Used->overscan_info_present_flag)
154 		{
155 			viddec_pm_get_bits(parent, &code, 1);
156 			pVUI_Seq_Not_Used->overscan_appropriate_flag = (uint8_t)code;
157 		}
158 
159 		viddec_pm_get_bits(parent, &code, 1);
160 		SPS->sps_disp.vui_seq_parameters.video_signal_type_present_flag = (uint8_t)code;
161 
162 		if(SPS->sps_disp.vui_seq_parameters.video_signal_type_present_flag)
163 		{
164 			viddec_pm_get_bits(parent, &code, 3);
165 			SPS->sps_disp.vui_seq_parameters.video_format = (uint8_t)code;
166 
167 			viddec_pm_get_bits(parent, &code, 1);
168 			pVUI_Seq_Not_Used->video_full_range_flag = (uint8_t)code;
169 
170 			viddec_pm_get_bits(parent, &code, 1);
171 			SPS->sps_disp.vui_seq_parameters.colour_description_present_flag = (uint8_t)code;
172 
173 			if(SPS->sps_disp.vui_seq_parameters.colour_description_present_flag)
174 			{
175 				viddec_pm_get_bits(parent, &code, 8);
176 				SPS->sps_disp.vui_seq_parameters.colour_primaries = (uint8_t)code;
177 
178 				viddec_pm_get_bits(parent, &code, 8);
179 				SPS->sps_disp.vui_seq_parameters.transfer_characteristics = (uint8_t)code;
180 
181 				viddec_pm_get_bits(parent, &code, 8);
182 				pVUI_Seq_Not_Used->matrix_coefficients = (uint8_t)code;
183 			}
184 		}
185 
186 		viddec_pm_get_bits(parent, &code, 1);
187 		pVUI_Seq_Not_Used->chroma_location_info_present_flag = (uint8_t)code;
188 
189 		if(pVUI_Seq_Not_Used->chroma_location_info_present_flag)
190 		{
191 			pVUI_Seq_Not_Used->chroma_sample_loc_type_top_field = h264_GetVLCElement(parent, pInfo, false);
192 			pVUI_Seq_Not_Used->chroma_sample_loc_type_bottom_field = h264_GetVLCElement(parent, pInfo, false);
193 		}
194 
195 		viddec_pm_get_bits(parent, &code, 1);
196 		SPS->sps_disp.vui_seq_parameters.timing_info_present_flag = (uint8_t)code;
197 
198 		if(SPS->sps_disp.vui_seq_parameters.timing_info_present_flag == 1)
199 		{
200 			viddec_pm_get_bits(parent, &code, 32);
201 			SPS->sps_disp.vui_seq_parameters.num_units_in_tick = (uint32_t)code;
202 
203 			viddec_pm_get_bits(parent, &code, 32);
204 			SPS->sps_disp.vui_seq_parameters.time_scale = (uint32_t)code;
205 
206 			viddec_pm_get_bits(parent, &code, 1);
207 			SPS->sps_disp.vui_seq_parameters.fixed_frame_rate_flag = (uint8_t)code;
208 		}
209 
210 		viddec_pm_get_bits(parent, &code, 1);
211 		SPS->sps_disp.vui_seq_parameters.nal_hrd_parameters_present_flag = (uint8_t)code;
212 
213 		if(SPS->sps_disp.vui_seq_parameters.nal_hrd_parameters_present_flag == 1)
214 		{
215 			nal_hrd = 1;
216 			ret |= h264_Parse_HRD_Parameters(parent,pInfo, nal_hrd,SPS, pVUI_Seq_Not_Used);
217 		}
218 
219 		viddec_pm_get_bits(parent, &code, 1);
220 		SPS->sps_disp.vui_seq_parameters.vcl_hrd_parameters_present_flag = (uint8_t)code;
221 
222 		if(SPS->sps_disp.vui_seq_parameters.vcl_hrd_parameters_present_flag == 1)
223 		{
224 			nal_hrd = 0;
225 			ret |= h264_Parse_HRD_Parameters(parent,pInfo, nal_hrd,SPS, pVUI_Seq_Not_Used);
226 		}
227 
228 		if((SPS->sps_disp.vui_seq_parameters.nal_hrd_parameters_present_flag == 1) || (SPS->sps_disp.vui_seq_parameters.vcl_hrd_parameters_present_flag == 1))
229 		{
230 			viddec_pm_get_bits(parent, &code, 1);
231 			SPS->sps_disp.vui_seq_parameters.low_delay_hrd_flag = (uint8_t)code;
232 		}
233 
234 		viddec_pm_get_bits(parent, &code, 1);
235 		SPS->sps_disp.vui_seq_parameters.pic_struct_present_flag = (uint8_t)code;
236 
237 		if(viddec_pm_get_bits(parent, &code, 1) == -1) {
238 			ret = H264_STATUS_ERROR;
239 			break;
240 		}
241 		SPS->sps_disp.vui_seq_parameters.bitstream_restriction_flag = (uint8_t)code;
242 
243 		if(SPS->sps_disp.vui_seq_parameters.bitstream_restriction_flag)
244 		{
245 			viddec_pm_get_bits(parent, &code, 1);
246 			pVUI_Seq_Not_Used->motion_vectors_over_pic_boundaries_flag = (uint8_t)code;
247 
248 			pVUI_Seq_Not_Used->max_bytes_per_pic_denom = h264_GetVLCElement(parent, pInfo, false);
249 			pVUI_Seq_Not_Used->max_bits_per_mb_denom = h264_GetVLCElement(parent, pInfo, false);
250 			pVUI_Seq_Not_Used->log2_max_mv_length_horizontal = h264_GetVLCElement(parent, pInfo, false);
251 			pVUI_Seq_Not_Used->log2_max_mv_length_vertical = h264_GetVLCElement(parent, pInfo, false);
252 			SPS->sps_disp.vui_seq_parameters.num_reorder_frames = h264_GetVLCElement(parent, pInfo, false);
253 			SPS->sps_disp.vui_seq_parameters.max_dec_frame_buffering = h264_GetVLCElement(parent, pInfo, false);
254 
255 			if(SPS->sps_disp.vui_seq_parameters.max_dec_frame_buffering == MAX_INT32_VALUE)
256 				ret = H264_STATUS_ERROR;
257 		}
258 	}while (0);
259 
260 	return ret;
261 }
262 
263 
h264_Parse_SeqParameterSet(void * parent,h264_Info * pInfo,seq_param_set_used_ptr SPS,vui_seq_parameters_t_not_used_ptr pVUI_Seq_Not_Used,int32_t * pOffset_ref_frame)264 h264_Status h264_Parse_SeqParameterSet(void *parent,h264_Info * pInfo, seq_param_set_used_ptr SPS, vui_seq_parameters_t_not_used_ptr pVUI_Seq_Not_Used, int32_t* pOffset_ref_frame)
265 {
266 	h264_Status ret = H264_SPS_ERROR;
267 
268 	int32_t i = 0, tmp = 0;
269    int32_t PicWidthInMbs, PicHeightInMapUnits, FrameHeightInMbs;
270 	uint32_t code = 0;
271    uint32_t data = 0;
272 
273 	//SPS->profile_idc = h264_GetBits(pInfo, 8, "Profile");
274 	viddec_pm_get_bits(parent, &code, 8);
275 	SPS->profile_idc = (uint8_t)code;
276 
277  	switch(SPS->profile_idc)
278 	{
279 		case h264_ProfileBaseline:
280 		case h264_ProfileMain:
281 		case h264_ProfileExtended:
282 		case h264_ProfileHigh10:
283 		case h264_ProfileHigh422:
284 		case h264_ProfileHigh444:
285 		case h264_ProfileHigh:
286 			break;
287 		default:
288 			return H264_SPS_INVALID_PROFILE;
289 			break;
290 	}
291 
292 	//SPS->constraint_set0_flag = h264_GetBits(pInfo, 1, "constraint_set0_flag");
293 	//SPS->constraint_set1_flag = h264_GetBits(pInfo, 1, "constraint_set1_flag");		//should be 1
294 	//SPS->constraint_set2_flag = h264_GetBits(pInfo, 1, "constraint_set2_flag");
295 	//SPS->constraint_set3_flag = h264_GetBits(pInfo, 1, "constraint_set3_flag");
296 
297 	viddec_pm_get_bits(parent, &code, 4);
298 	SPS->constraint_set_flags = (uint8_t)code;
299 
300 	//// reserved_zero_4bits
301 	viddec_pm_get_bits(parent, (uint32_t *)&code, 4);
302 
303 	viddec_pm_get_bits(parent, &code, 8);
304 	SPS->level_idc = (uint8_t)code;
305 
306 	switch(SPS->level_idc)
307 	{
308 		case h264_Level1b:
309 		case h264_Level1:
310 		case h264_Level11:
311 		case h264_Level12:
312 		case h264_Level13:
313 		case h264_Level2:
314 		case h264_Level21:
315 		case h264_Level22:
316 		case h264_Level3:
317 		case h264_Level31:
318 		case h264_Level32:
319 		case h264_Level4:
320 		case h264_Level41:
321 		case h264_Level42:
322 		case h264_Level5:
323 		case h264_Level51:
324 			break;
325 		default:
326 			return H264_SPS_INVALID_LEVEL;
327 	}
328 
329 	do {
330 		SPS->seq_parameter_set_id = h264_GetVLCElement(parent, pInfo, false);
331 
332 		//// seq_parameter_set_id ---[0,31]
333 		if(SPS->seq_parameter_set_id > MAX_NUM_SPS -1)
334 			break;
335 
336 		if((SPS->profile_idc == h264_ProfileHigh) || (SPS->profile_idc == h264_ProfileHigh10) ||
337 	        (SPS->profile_idc == h264_ProfileHigh422) || (SPS->profile_idc == h264_ProfileHigh444)   )
338 		{
339 			//// chroma_format_idc ---[0,3], currently we don't support 444, so [0,2]
340 			data = h264_GetVLCElement(parent, pInfo, false);
341 			if( data > H264_CHROMA_422)
342 				break;
343 			SPS->sps_disp.chroma_format_idc = (uint8_t)data;
344 			//if(SPS->sps_disp.chroma_format_idc == H264_CHROMA_444) {}
345 
346 			//// bit_depth_luma_minus8 ---[0,4], -----only support 8-bit pixel
347 			data = h264_GetVLCElement(parent, pInfo, false);
348 			if( data)
349 				break;
350 			SPS->bit_depth_luma_minus8 = (uint8_t)data;
351 
352 			//// bit_depth_chroma_minus8 ---[0,4]
353 			data = h264_GetVLCElement(parent, pInfo, false);
354 			if( data )
355 				break;
356 			SPS->bit_depth_chroma_minus8 = (uint8_t)data;
357 
358 
359 			viddec_pm_get_bits(parent, &code, 1);
360 			SPS->lossless_qpprime_y_zero_flag = (uint8_t)code;
361 
362 			viddec_pm_get_bits(parent, &code, 1);
363 			SPS->seq_scaling_matrix_present_flag = (uint8_t)code;
364 
365 			if(SPS->seq_scaling_matrix_present_flag == 1)
366 			{
367 				//int n_ScalingList = (SPS->sps_disp.chroma_format_idc != H264_CHROMA_444) ? 8 : 12;
368 				int n_ScalingList = 8;				/// We do not support 444 currrently
369 
370 				for(i=0; i<n_ScalingList; i++)
371 				{
372 					viddec_pm_get_bits(parent, &code, 1);
373 					SPS->seq_scaling_list_present_flag[i] = (uint8_t)code;
374 
375 					if(SPS->seq_scaling_list_present_flag[i])
376 					{
377 					  	if(i<6)
378 							h264_Scaling_List(parent, SPS->ScalingList4x4[i], 16, &SPS->UseDefaultScalingMatrix4x4Flag[i], pInfo);
379 						else
380 							h264_Scaling_List(parent, SPS->ScalingList8x8[i-6], 64, &SPS->UseDefaultScalingMatrix8x8Flag[i-6], pInfo);
381 					}
382 				}
383 			}
384 		}
385 		else
386 		{
387 			SPS->sps_disp.chroma_format_idc = 1;
388 			SPS->seq_scaling_matrix_present_flag = 0;
389 
390 			SPS->bit_depth_luma_minus8 = 0;
391 			SPS->bit_depth_chroma_minus8 = 0;
392 			//h264_SetDefaultScalingLists(pInfo);
393 		}
394 
395 	   //// log2_max_frame_num_minus4 ---[0,12]
396 	  	data = (h264_GetVLCElement(parent, pInfo, false));
397 		if( data > 12)
398 			break;
399 		SPS->log2_max_frame_num_minus4 = (uint8_t)data;
400 
401 		//// pic_order_cnt_type ---- [0,2]
402 		data = h264_GetVLCElement(parent, pInfo, false);
403 		if( data > 2)
404 			break;
405 		SPS->pic_order_cnt_type = (uint8_t)data;
406 
407 
408 		SPS->expectedDeltaPerPOCCycle = 0;
409 		if(SPS->pic_order_cnt_type == 0)	{
410 			SPS->log2_max_pic_order_cnt_lsb_minus4 = h264_GetVLCElement(parent, pInfo, false);
411 		} else if(SPS->pic_order_cnt_type == 1){
412 			viddec_pm_get_bits(parent, &code, 1);
413 			SPS->delta_pic_order_always_zero_flag = (uint8_t)code;
414 
415 			SPS->offset_for_non_ref_pic = h264_GetVLCElement(parent, pInfo, true);
416 			SPS->offset_for_top_to_bottom_field = h264_GetVLCElement(parent, pInfo, true);
417 
418 			//// num_ref_frames_in_pic_order_cnt_cycle ---- [0,255]
419 	      data = h264_GetVLCElement(parent, pInfo, false);
420 			if( data > 255)
421 				break;
422 			SPS->num_ref_frames_in_pic_order_cnt_cycle = (uint8_t)data;
423 
424 
425 			//Alloc memory for frame offset -- FIXME
426 			for(i=0; i< SPS->num_ref_frames_in_pic_order_cnt_cycle; i++)
427 			{
428 				/////SPS->offset_for_ref_frame[i] could be removed from SPS
429 #ifndef USER_MODE
430 				tmp = h264_GetVLCElement(parent, pInfo, true);
431 				pOffset_ref_frame[i]=tmp;
432 				SPS->expectedDeltaPerPOCCycle += tmp;
433 #else
434 				tmp = h264_GetVLCElement(parent, pInfo, true);
435 				SPS->offset_for_ref_frame[i]=tmp;
436 				SPS->expectedDeltaPerPOCCycle += tmp;
437 #endif
438 			}
439 		}
440 
441 		//// num_ref_frames ---[0,16]
442 		data = h264_GetVLCElement(parent, pInfo, false);
443 		if( data > 16)
444 			break;
445 		SPS->num_ref_frames = (uint8_t)data;
446 
447 		viddec_pm_get_bits(parent, &code, 1);
448 		SPS->gaps_in_frame_num_value_allowed_flag = (uint8_t)code;
449 
450 
451 		SPS->sps_disp.pic_width_in_mbs_minus1 = h264_GetVLCElement(parent, pInfo, false);
452 		SPS->sps_disp.pic_height_in_map_units_minus1 = h264_GetVLCElement(parent, pInfo, false);
453 		viddec_pm_get_bits(parent, &code, 1);
454 		SPS->sps_disp.frame_mbs_only_flag = (uint8_t)code;
455 
456 		/// err check for size
457 		PicWidthInMbs       = (SPS->sps_disp.pic_width_in_mbs_minus1 + 1);
458 		PicHeightInMapUnits = (SPS->sps_disp.pic_height_in_map_units_minus1 + 1);
459 		FrameHeightInMbs    = SPS->sps_disp.frame_mbs_only_flag? PicHeightInMapUnits: (PicHeightInMapUnits<<1);
460 		if((PicWidthInMbs < 2) || (PicWidthInMbs > 128) || (FrameHeightInMbs < 2) || (FrameHeightInMbs>128))
461 			break;
462 
463 		if(!SPS->sps_disp.frame_mbs_only_flag)
464 		{
465 			viddec_pm_get_bits(parent, &code, 1);
466 			SPS->sps_disp.mb_adaptive_frame_field_flag = (uint8_t)code;
467 		}
468 
469 		//SPS->frame_height_in_mbs = (2-SPS->sps_disp.frame_mbs_only_flag)*(SPS->sps_disp.pic_height_in_map_units_minus1+1);
470 		//SPS->pic_size_in_map_units = (SPS->sps_disp.pic_width_in_mbs_minus1+1)*SPS->sps_disp.frame_height_in_mbs;
471 
472 		viddec_pm_get_bits(parent, &code, 1);
473 		SPS->sps_disp.direct_8x8_inference_flag = (uint8_t)code;
474 
475 		viddec_pm_get_bits(parent, &code, 1);
476 		SPS->sps_disp.frame_cropping_flag = (uint8_t)code;
477 
478 		if(SPS->sps_disp.frame_cropping_flag)
479 		{
480 			SPS->sps_disp.frame_crop_rect_left_offset = h264_GetVLCElement(parent, pInfo, false);
481 			SPS->sps_disp.frame_crop_rect_right_offset = h264_GetVLCElement(parent, pInfo, false);
482 			SPS->sps_disp.frame_crop_rect_top_offset = h264_GetVLCElement(parent, pInfo, false);
483 			SPS->sps_disp.frame_crop_rect_bottom_offset = h264_GetVLCElement(parent, pInfo, false);
484 		}
485 
486 		//// when frame_mbs_only_flag is equal to 0, direct_8x8_inference_flag shall be equal to 1
487 		if (SPS->sps_disp.frame_mbs_only_flag == 0 && SPS->sps_disp.direct_8x8_inference_flag == 0){
488 			break;
489 		}
490 
491 		////// vui_parameters
492 		if(viddec_pm_get_bits(parent, &code, 1) == -1)
493 			break;
494 		SPS->sps_disp.vui_parameters_present_flag = (uint8_t)code;
495 		ret = H264_STATUS_OK;
496 
497 		if(SPS->sps_disp.vui_parameters_present_flag)
498 		{
499 #ifndef VBP		// Ignore VUI parsing result
500 			ret =
501 #endif
502 			h264_Parse_Vui_Parameters(parent, pInfo, SPS, pVUI_Seq_Not_Used);
503 		}
504 
505 	}while(0);
506 
507 	//h264_Parse_rbsp_trailing_bits(pInfo);
508 
509 	return ret;
510 }
511 
512 //#endif
513 
514