private static void readScalingListMatrix(CAVLCReader reader, SeqParameterSet sps) { sps.ScalingMatrix = new ScalingMatrix(); for (int i = 0; i < 8; i++) { bool seqScalingListPresentFlag = reader.ReadBool("SPS: seqScalingListPresentFlag"); if (seqScalingListPresentFlag) { sps.ScalingMatrix.ScalingList4x4 = new ScalingList[8]; sps.ScalingMatrix.ScalingList8x8 = new ScalingList[8]; if (i < 6) { sps.ScalingMatrix.ScalingList4x4[i] = ScalingList.read(reader, 16); } else { sps.ScalingMatrix.ScalingList8x8[i - 6] = ScalingList.read(reader, 64); } } } }
public static PictureParameterSet read(Stream @is) { var reader = new CAVLCReader(@is); PictureParameterSet pps = new PictureParameterSet { pic_parameter_set_id = reader.ReadUE("PPS: pic_parameter_set_id"), seq_parameter_set_id = reader.ReadUE("PPS: seq_parameter_set_id"), entropy_coding_mode_flag = reader.ReadBool("PPS: entropy_coding_mode_flag"), pic_order_present_flag = reader.ReadBool("PPS: pic_order_present_flag"), num_slice_groups_minus1 = reader.ReadUE("PPS: num_slice_groups_minus1") }; if (pps.num_slice_groups_minus1 > 0) { pps.slice_group_map_type = reader.ReadUE("PPS: slice_group_map_type"); pps.top_left = new int[pps.num_slice_groups_minus1 + 1]; pps.bottom_right = new int[pps.num_slice_groups_minus1 + 1]; pps.run_length_minus1 = new int[pps.num_slice_groups_minus1 + 1]; if (pps.slice_group_map_type == 0) { for (int iGroup = 0; iGroup <= pps.num_slice_groups_minus1; iGroup++) { pps.run_length_minus1[iGroup] = reader.ReadUE("PPS: run_length_minus1"); } } else if (pps.slice_group_map_type == 2) { for (int iGroup = 0; iGroup < pps.num_slice_groups_minus1; iGroup++) { pps.top_left[iGroup] = reader.ReadUE("PPS: top_left"); pps.bottom_right[iGroup] = reader.ReadUE("PPS: bottom_right"); } } else if (pps.slice_group_map_type == 3 || pps.slice_group_map_type == 4 || pps.slice_group_map_type == 5) { pps.slice_group_change_direction_flag = reader.ReadBool("PPS: slice_group_change_direction_flag"); pps.slice_group_change_rate_minus1 = reader.ReadUE("PPS: slice_group_change_rate_minus1"); } else if (pps.slice_group_map_type == 6) { int NumberBitsPerSliceGroupId; if (pps.num_slice_groups_minus1 + 1 > 4) { NumberBitsPerSliceGroupId = 3; } else if (pps.num_slice_groups_minus1 + 1 > 2) { NumberBitsPerSliceGroupId = 2; } else { NumberBitsPerSliceGroupId = 1; } int pic_size_in_map_units_minus1 = reader.ReadUE("PPS: pic_size_in_map_units_minus1"); pps.slice_group_id = new int[pic_size_in_map_units_minus1 + 1]; for (int i = 0; i <= pic_size_in_map_units_minus1; i++) { pps.slice_group_id[i] = reader.ReadU(NumberBitsPerSliceGroupId, "PPS: slice_group_id [" + i + "]f"); } } } pps.num_ref_idx_l0_active_minus1 = reader.ReadUE("PPS: num_ref_idx_l0_active_minus1"); pps.num_ref_idx_l1_active_minus1 = reader.ReadUE("PPS: num_ref_idx_l1_active_minus1"); pps.weighted_pred_flag = reader.ReadBool("PPS: weighted_pred_flag"); pps.weighted_bipred_idc = (int)reader.ReadNBit(2, "PPS: weighted_bipred_idc"); pps.pic_init_qp_minus26 = reader.ReadSE("PPS: pic_init_qp_minus26"); pps.pic_init_qs_minus26 = reader.ReadSE("PPS: pic_init_qs_minus26"); pps.chroma_qp_index_offset = reader.ReadSE("PPS: chroma_qp_index_offset"); pps.deblocking_filter_control_present_flag = reader.ReadBool("PPS: deblocking_filter_control_present_flag"); pps.constrained_intra_pred_flag = reader.ReadBool("PPS: constrained_intra_pred_flag"); pps.redundant_pic_cnt_present_flag = reader.ReadBool("PPS: redundant_pic_cnt_present_flag"); if (reader.moreRBSPData()) { pps.extended = new PictureParameterSet.PPSExt(); pps.extended.transform_8x8_mode_flag = reader.ReadBool("PPS: transform_8x8_mode_flag"); bool pic_scaling_matrix_present_flag = reader.ReadBool("PPS: pic_scaling_matrix_present_flag"); if (pic_scaling_matrix_present_flag) { for (int i = 0; i < 6 + 2 * (pps.extended.transform_8x8_mode_flag ? 1 : 0); i++) { bool pic_scaling_list_present_flag = reader.ReadBool("PPS: pic_scaling_list_present_flag"); if (pic_scaling_list_present_flag) { pps.extended.scalindMatrix.ScalingList4x4 = new ScalingList[8]; pps.extended.scalindMatrix.ScalingList8x8 = new ScalingList[8]; if (i < 6) { pps.extended.scalindMatrix.ScalingList4x4[i] = ScalingList.read(reader, 16); } else { pps.extended.scalindMatrix.ScalingList8x8[i - 6] = ScalingList.read(reader, 64); } } } } pps.extended.second_chroma_qp_index_offset = reader.ReadSE("PPS: second_chroma_qp_index_offset"); } reader.ReadTrailingBits(); return(pps); }