1 
2 
3 #include "h264.h"
4 #include "h264parse.h"
5 
6 /*---------------------------------------------*/
7 /*---------------------------------------------*/
8 /*---------------------------------------------*/
h264_Parse_PicParameterSet(void * parent,h264_Info * pInfo,h264_PicParameterSet_t * PictureParameterSet)9 h264_Status h264_Parse_PicParameterSet(void *parent,h264_Info * pInfo,h264_PicParameterSet_t* PictureParameterSet)
10 {
11 	h264_Status ret = H264_PPS_ERROR;
12 
13 	//h264_PicParameterSet_t* PictureParameterSet = &pInfo->PictureParameterSet;
14 	uint32_t code=0, i = 0;
15 
16 	do {
17 		///// PPS par1: pic_parameter_set_id & seq_parameter_set_id
18 	   code = h264_GetVLCElement(parent, pInfo, false);
19 		if(code > MAX_PIC_PARAMS) {
20 			break;
21 		}
22 		PictureParameterSet->pic_parameter_set_id = (uint8_t)code;
23 
24 
25 		code = h264_GetVLCElement(parent, pInfo, false);
26 		if(code > MAX_NUM_SPS-1) {
27 			break;
28 		}
29 	   PictureParameterSet->seq_parameter_set_id = (uint8_t)code;
30 
31 		///// entropy_coding_mode_flag
32 		viddec_pm_get_bits(parent, &code, 1);
33 		PictureParameterSet->entropy_coding_mode_flag = (uint8_t)code;
34 		///// pic_order_present_flag
35 		viddec_pm_get_bits(parent, &code, 1);
36 		PictureParameterSet->pic_order_present_flag = (uint8_t)code;
37 
38 		PictureParameterSet->num_slice_groups_minus1 = h264_GetVLCElement(parent, pInfo, false);
39 
40 		//
41 		// In main profile, FMO is excluded and num_slice_groups_minus1 should be 0
42 		//
43 		if(PictureParameterSet->num_slice_groups_minus1 > 0) //MAX_NUM_SLICE_GRPS)
44 			break;
45 
46 		PictureParameterSet->num_ref_idx_l0_active = h264_GetVLCElement(parent, pInfo, false)+1;
47 		PictureParameterSet->num_ref_idx_l1_active = h264_GetVLCElement(parent, pInfo, false)+1;
48 
49 		//// PPS->num_ref_idx_l0_active --- [0,32]
50 		if(((PictureParameterSet->num_ref_idx_l0_active) > MAX_NUM_REF_FRAMES) || ((PictureParameterSet->num_ref_idx_l1_active) > MAX_NUM_REF_FRAMES))
51 		{
52 			break;
53 		}
54 
55 		//// weighting prediction
56 		viddec_pm_get_bits(parent, &code, 1);
57 		PictureParameterSet->weighted_pred_flag = (uint8_t)code;
58 
59 		viddec_pm_get_bits(parent, &code, 2);
60 		PictureParameterSet->weighted_bipred_idc = (uint8_t)code;
61 
62 		//// QP
63 		PictureParameterSet->pic_init_qp_minus26 = h264_GetVLCElement(parent, pInfo, true);
64 		PictureParameterSet->pic_init_qs_minus26 = h264_GetVLCElement(parent, pInfo, true);
65 		if(((PictureParameterSet->pic_init_qp_minus26+26) > MAX_QP) || ((PictureParameterSet->pic_init_qs_minus26+26) > MAX_QP))
66 			break;
67 		PictureParameterSet->chroma_qp_index_offset = h264_GetVLCElement(parent, pInfo, true);
68 
69 		//// Deblocking ctl parameters
70 		viddec_pm_get_bits(parent, &code, 1);
71 		PictureParameterSet->deblocking_filter_control_present_flag = (uint8_t)code;
72 
73 		viddec_pm_get_bits(parent, &code, 1);
74 		PictureParameterSet->constrained_intra_pred_flag = (uint8_t)code;
75 
76 		if( viddec_pm_get_bits(parent, &code, 1) == -1)
77 			break;
78 		PictureParameterSet->redundant_pic_cnt_present_flag = (uint8_t)code;
79 
80 		//// Check if have more RBSP Data for additional parameters
81 		if(h264_More_RBSP_Data(parent, pInfo))
82 		{
83 			viddec_pm_get_bits(parent,  &code, 1);
84 			PictureParameterSet->transform_8x8_mode_flag = (uint8_t)code;
85 
86 			if( viddec_pm_get_bits(parent, &code, 1) == -1)
87 				break;
88 			PictureParameterSet->pic_scaling_matrix_present_flag = (uint8_t)code;
89 
90 			if(PictureParameterSet->pic_scaling_matrix_present_flag)
91 	    	{
92 				uint32_t n_ScalingList = 6 + (PictureParameterSet->transform_8x8_mode_flag << 1);
93 	      		for(i=0; i<n_ScalingList; i++)
94 	      		{
95 						if( viddec_pm_get_bits(parent, &code, 1) == -1)
96 							break;
97 						PictureParameterSet->pic_scaling_list_present_flag[i] = (uint8_t)code;
98 
99 						if(PictureParameterSet->pic_scaling_list_present_flag[i])
100 		        		{
101 	          			if(i<6)
102 				            h264_Scaling_List(parent, PictureParameterSet->ScalingList4x4[i], 16, &PictureParameterSet->UseDefaultScalingMatrix4x4Flag[i], pInfo);
103 	          			else
104 				            h264_Scaling_List(parent, PictureParameterSet->ScalingList8x8[i-6], 64, &PictureParameterSet->UseDefaultScalingMatrix8x8Flag[i-6], pInfo);
105 		        		}
106 	      		}
107 	    	}
108 
109 			PictureParameterSet->second_chroma_qp_index_offset = h264_GetVLCElement(parent, pInfo, true); //fix
110 			//if((PictureParameterSet->second_chroma_qp_index_offset>12) || (PictureParameterSet->second_chroma_qp_index_offset < -12))
111 			//	break;
112 		}
113 	 	else
114 		{
115 			PictureParameterSet->transform_8x8_mode_flag = 0;
116 			PictureParameterSet->pic_scaling_matrix_present_flag = 0;
117 			PictureParameterSet->second_chroma_qp_index_offset = PictureParameterSet->chroma_qp_index_offset;
118 		}
119 
120 		ret = H264_STATUS_OK;
121 	}while(0);
122 
123 	//h264_Parse_rbsp_trailing_bits(pInfo);
124 	return ret;
125 }
126 
127 ////////// EOF///////////////
128 
129