static s32 gf_media_hevc_read_pps_bs(GF_BitStream *bs, HEVCState *hevc)
{
	u32 i;
	s32 pps_id = -1;
	HEVC_PPS *pps;

	//NAL header already read
	pps_id = bs_get_ue(bs);

	if ((pps_id<0) || (pps_id>=64)) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_CODING, ("[HEVC] wrong PPS ID %d in PPS\n", pps_id));
		return -1;
	}
	pps = &hevc->pps[pps_id];

	if (!pps->state) {
		pps->id = pps_id;
		pps->state = 1;
	}
	pps->sps_id = bs_get_ue(bs);
	if (pps->sps_id>16) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_CODING, ("[HEVC] wrong SPS ID %d in PPS\n", pps->sps_id));
		return -1;
	}
	hevc->sps_active_idx = pps->sps_id; /*set active sps*/
	pps->dependent_slice_segments_enabled_flag = gf_bs_read_int(bs, 1);

	pps->output_flag_present_flag = gf_bs_read_int(bs, 1);
	pps->num_extra_slice_header_bits = gf_bs_read_int(bs, 3);
	/*sign_data_hiding_flag = */gf_bs_read_int(bs, 1);
	pps->cabac_init_present_flag = gf_bs_read_int(bs, 1);
	pps->num_ref_idx_l0_default_active = 1 + bs_get_ue(bs);
	pps->num_ref_idx_l1_default_active = 1 + bs_get_ue(bs);
	/*pic_init_qp_minus26 = */bs_get_se(bs);
	/*constrained_intra_pred_flag = */gf_bs_read_int(bs, 1);
	/*transform_skip_enabled_flag = */gf_bs_read_int(bs, 1);
	if (/*cu_qp_delta_enabled_flag = */gf_bs_read_int(bs, 1) )
		/*diff_cu_qp_delta_depth = */bs_get_ue(bs);

	/*pic_cb_qp_offset = */bs_get_se(bs);
	/*pic_cr_qp_offset = */bs_get_se(bs);
	pps->slice_chroma_qp_offsets_present_flag = gf_bs_read_int(bs, 1);
	pps->weighted_pred_flag = gf_bs_read_int(bs, 1);
	pps->weighted_bipred_flag = gf_bs_read_int(bs, 1);
	/*transquant_bypass_enable_flag = */gf_bs_read_int(bs, 1);
	pps->tiles_enabled_flag = gf_bs_read_int(bs, 1);
	pps->entropy_coding_sync_enabled_flag = gf_bs_read_int(bs, 1);
	if (pps->tiles_enabled_flag) {
		pps->num_tile_columns = 1 + bs_get_ue(bs);
		pps->num_tile_rows = 1 + bs_get_ue(bs);
		pps->uniform_spacing_flag = gf_bs_read_int(bs, 1);
		if (!pps->uniform_spacing_flag ) {
			for (i=0; i<pps->num_tile_columns-1; i++) {
				pps->column_width[i] = 1 + bs_get_ue(bs);
			}
			for (i=0; i<pps->num_tile_rows-1; i++) {
				pps->row_height[i] = 1+bs_get_ue(bs);
			}
		}
		pps->loop_filter_across_tiles_enabled_flag = gf_bs_read_int(bs, 1);
	}
	pps->loop_filter_across_slices_enabled_flag = gf_bs_read_int(bs, 1);
	if( /*deblocking_filter_control_present_flag = */gf_bs_read_int(bs, 1)  ) {
		pps->deblocking_filter_override_enabled_flag = gf_bs_read_int(bs, 1);
		if (! /*pic_disable_deblocking_filter_flag= */gf_bs_read_int(bs, 1) ) {
			/*beta_offset_div2 = */bs_get_se(bs);
			/*tc_offset_div2 = */bs_get_se(bs);
		}
	}
	if (/*pic_scaling_list_data_present_flag	= */gf_bs_read_int(bs, 1) ) {
		hevc_scaling_list_data(bs);
	}
	pps->lists_modification_present_flag = gf_bs_read_int(bs, 1);
	/*log2_parallel_merge_level_minus2 = */bs_get_ue(bs);
	pps->slice_segment_header_extension_present_flag = gf_bs_read_int(bs, 1);
	if ( /*pps_extension_flag= */gf_bs_read_int(bs, 1) ) {
		while (gf_bs_available(bs) ) {
			/*pps_extension_data_flag */ gf_bs_read_int(bs, 1);
		}
	}
	return pps_id;
}
static s32 gf_media_hevc_read_pps_bs(GF_BitStream *bs, HEVCState *hevc)
{
	u32 i;
	s32 pps_id = -1;
	HEVC_PPS *pps;

	 
	pps_id = bs_get_ue(bs);

	if ((pps_id<0) || (pps_id>=64)) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_CODING, ("[HEVC] wrong PPS ID %d in PPS\n", pps_id));
		return -1;
	}
	pps = &hevc->pps[pps_id];

	if (!pps->state) {
		pps->id = pps_id;
		pps->state = 1;
	}
	pps->sps_id = bs_get_ue(bs);
	if (pps->sps_id>16) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_CODING, ("[HEVC] wrong SPS ID %d in PPS\n", pps->sps_id));
		return -1;
	}
	hevc->sps_active_idx = pps->sps_id;  
	pps->dependent_slice_segments_enabled_flag = gf_bs_read_int(bs, 1);

	pps->output_flag_present_flag = gf_bs_read_int(bs, 1);
	pps->num_extra_slice_header_bits = gf_bs_read_int(bs, 3);
	 gf_bs_read_int(bs, 1);
	pps->cabac_init_present_flag = gf_bs_read_int(bs, 1);
	pps->num_ref_idx_l0_default_active = 1 + bs_get_ue(bs);
	pps->num_ref_idx_l1_default_active = 1 + bs_get_ue(bs);
	 bs_get_se(bs);
	 gf_bs_read_int(bs, 1);
	 gf_bs_read_int(bs, 1);
	if ( gf_bs_read_int(bs, 1) )
		 bs_get_ue(bs);

	 bs_get_se(bs);
	 bs_get_se(bs);
	pps->slice_chroma_qp_offsets_present_flag = gf_bs_read_int(bs, 1);
	pps->weighted_pred_flag = gf_bs_read_int(bs, 1);
	pps->weighted_bipred_flag = gf_bs_read_int(bs, 1);
	 gf_bs_read_int(bs, 1);
	pps->tiles_enabled_flag = gf_bs_read_int(bs, 1);
	pps->entropy_coding_sync_enabled_flag = gf_bs_read_int(bs, 1);
	if (pps->tiles_enabled_flag) {
		pps->num_tile_columns = 1 + bs_get_ue(bs);
		pps->num_tile_rows = 1 + bs_get_ue(bs);
		pps->uniform_spacing_flag = gf_bs_read_int(bs, 1);
		if (!pps->uniform_spacing_flag ) {
			for (i=0; i<pps->num_tile_columns-1; i++) {
				pps->column_width[i] = 1 + bs_get_ue(bs);
			}
			for (i=0; i<pps->num_tile_rows-1; i++) {
				pps->row_height[i] = 1+bs_get_ue(bs);
			}
		}
		pps->loop_filter_across_tiles_enabled_flag = gf_bs_read_int(bs, 1);
	}
	pps->loop_filter_across_slices_enabled_flag = gf_bs_read_int(bs, 1);
	if(  gf_bs_read_int(bs, 1)  ) {
		pps->deblocking_filter_override_enabled_flag = gf_bs_read_int(bs, 1);
		if (!  gf_bs_read_int(bs, 1) ) {
			 bs_get_se(bs);
			 bs_get_se(bs);
		}
	}
	if ( gf_bs_read_int(bs, 1) ) {
		hevc_scaling_list_data(bs);
	}
	pps->lists_modification_present_flag = gf_bs_read_int(bs, 1);
	 bs_get_ue(bs);
	pps->slice_segment_header_extension_present_flag = gf_bs_read_int(bs, 1);
	if (  gf_bs_read_int(bs, 1) ) {
		while (gf_bs_available(bs) ) {
			  gf_bs_read_int(bs, 1);
		}
	}
	return pps_id;
}