private static HRDParameters readHRDParameters(BitReader inb) { HRDParameters hrd = new HRDParameters(); hrd.cpb_cnt_minus1 = CAVLCReader.readUE(inb, "SPS: cpb_cnt_minus1"); hrd.bit_rate_scale = (int)CAVLCReader.readNBit(inb, 4, "HRD: bit_rate_scale"); hrd.cpb_size_scale = (int)CAVLCReader.readNBit(inb, 4, "HRD: cpb_size_scale"); hrd.bit_rate_value_minus1 = new int[hrd.cpb_cnt_minus1 + 1]; hrd.cpb_size_value_minus1 = new int[hrd.cpb_cnt_minus1 + 1]; hrd.cbr_flag = new bool[hrd.cpb_cnt_minus1 + 1]; for (int SchedSelIdx = 0; SchedSelIdx <= hrd.cpb_cnt_minus1; SchedSelIdx++) { hrd.bit_rate_value_minus1[SchedSelIdx] = CAVLCReader.readUE(inb, "HRD: bit_rate_value_minus1"); hrd.cpb_size_value_minus1[SchedSelIdx] = CAVLCReader.readUE(inb, "HRD: cpb_size_value_minus1"); hrd.cbr_flag[SchedSelIdx] = CAVLCReader.readBool(inb, "HRD: cbr_flag"); } hrd.initial_cpb_removal_delay_length_minus1 = (int)CAVLCReader.readNBit(inb, 5, "HRD: initial_cpb_removal_delay_length_minus1"); hrd.cpb_removal_delay_length_minus1 = (int)CAVLCReader.readNBit(inb, 5, "HRD: cpb_removal_delay_length_minus1"); hrd.dpb_output_delay_length_minus1 = (int)CAVLCReader.readNBit(inb, 5, "HRD: dpb_output_delay_length_minus1"); hrd.time_offset_length = (int)CAVLCReader.readNBit(inb, 5, "HRD: time_offset_length"); return(hrd); }
public static SeqParameterSet read(MemoryStream isb) { BitReader inb = new BitReader(isb); SeqParameterSet sps = new SeqParameterSet(); sps.profile_idc = CAVLCReader.readNBit(inb, 8, "SPS: profile_idc"); sps.constraint_set_0_flag = CAVLCReader.readBool(inb, "SPS: constraint_set_0_flag"); sps.constraint_set_1_flag = CAVLCReader.readBool(inb, "SPS: constraint_set_1_flag"); sps.constraint_set_2_flag = CAVLCReader.readBool(inb, "SPS: constraint_set_2_flag"); sps.constraint_set_3_flag = CAVLCReader.readBool(inb, "SPS: constraint_set_3_flag"); CAVLCReader.readNBit(inb, 4, "SPS: reserved_zero_4bits"); sps.level_idc = (int)CAVLCReader.readNBit(inb, 8, "SPS: level_idc"); sps.seq_parameter_set_id = CAVLCReader.readUE(inb, "SPS: seq_parameter_set_id"); if (sps.profile_idc == 100 || sps.profile_idc == 110 || sps.profile_idc == 122 || sps.profile_idc == 144) { sps.chroma_format_idc = getColor(CAVLCReader.readUE(inb, "SPS: chroma_format_idc")); if (sps.chroma_format_idc == ColorSpace.YUV444) { sps.residual_color_transform_flag = CAVLCReader.readBool(inb, "SPS: residual_color_transform_flag"); } sps.bit_depth_luma_minus8 = CAVLCReader.readUE(inb, "SPS: bit_depth_luma_minus8"); sps.bit_depth_chroma_minus8 = CAVLCReader.readUE(inb, "SPS: bit_depth_chroma_minus8"); sps.qpprime_y_zero_transform_bypass_flag = CAVLCReader.readBool(inb, "SPS: qpprime_y_zero_transform_bypass_flag"); bool seqScalingMatrixPresent = CAVLCReader.readBool(inb, "SPS: seq_scaling_matrix_present_lag"); if (seqScalingMatrixPresent) { readScalingListMatrix(inb, sps); } } else { sps.chroma_format_idc = ColorSpace.YUV420; } sps.log2_max_frame_num_minus4 = CAVLCReader.readUE(inb, "SPS: log2_max_frame_num_minus4"); sps.pic_order_cnt_type = CAVLCReader.readUE(inb, "SPS: pic_order_cnt_type"); if (sps.pic_order_cnt_type == 0) { sps.log2_max_pic_order_cnt_lsb_minus4 = CAVLCReader.readUE(inb, "SPS: log2_max_pic_order_cnt_lsb_minus4"); } else if (sps.pic_order_cnt_type == 1) { sps.delta_pic_order_always_zero_flag = CAVLCReader.readBool(inb, "SPS: delta_pic_order_always_zero_flag"); sps.offset_for_non_ref_pic = CAVLCReader.readSE(inb, "SPS: offset_for_non_ref_pic"); sps.offset_for_top_to_bottom_field = CAVLCReader.readSE(inb, "SPS: offset_for_top_to_bottom_field"); sps.num_ref_frames_in_pic_order_cnt_cycle = CAVLCReader.readUE(inb, "SPS: num_ref_frames_in_pic_order_cnt_cycle"); sps.offsetForRefFrame = new int[sps.num_ref_frames_in_pic_order_cnt_cycle]; for (int i = 0; i < sps.num_ref_frames_in_pic_order_cnt_cycle; i++) { sps.offsetForRefFrame[i] = CAVLCReader.readSE(inb, "SPS: offsetForRefFrame [" + i + "]"); } } sps.num_ref_frames = CAVLCReader.readUE(inb, "SPS: num_ref_frames"); sps.gaps_in_frame_num_value_allowed_flag = CAVLCReader.readBool(inb, "SPS: gaps_in_frame_num_value_allowed_flag"); sps.pic_width_in_mbs_minus1 = CAVLCReader.readUE(inb, "SPS: pic_width_in_mbs_minus1"); sps.pic_height_in_map_units_minus1 = CAVLCReader.readUE(inb, "SPS: pic_height_in_map_units_minus1"); sps.frame_mbs_only_flag = CAVLCReader.readBool(inb, "SPS: frame_mbs_only_flag"); if (!sps.frame_mbs_only_flag) { sps.mb_adaptive_frame_field_flag = CAVLCReader.readBool(inb, "SPS: mb_adaptive_frame_field_flag"); } sps.direct_8x8_inference_flag = CAVLCReader.readBool(inb, "SPS: direct_8x8_inference_flag"); sps.frame_cropping_flag = CAVLCReader.readBool(inb, "SPS: frame_cropping_flag"); if (sps.frame_cropping_flag) { sps.frame_crop_left_offset = CAVLCReader.readUE(inb, "SPS: frame_crop_left_offset"); sps.frame_crop_right_offset = CAVLCReader.readUE(inb, "SPS: frame_crop_right_offset"); sps.frame_crop_top_offset = CAVLCReader.readUE(inb, "SPS: frame_crop_top_offset"); sps.frame_crop_bottom_offset = CAVLCReader.readUE(inb, "SPS: frame_crop_bottom_offset"); } bool vui_parameters_present_flag = CAVLCReader.readBool(inb, "SPS: vui_parameters_present_flag"); if (vui_parameters_present_flag) { sps.vuiParams = readVUIParameters(inb); } return(sps); }
private static VUIParameters readVUIParameters(BitReader inb) { VUIParameters vuip = new VUIParameters(); vuip.aspect_ratio_info_present_flag = CAVLCReader.readBool(inb, "VUI: aspect_ratio_info_present_flag"); if (vuip.aspect_ratio_info_present_flag) { vuip.aspect_ratio = AspectRatio.fromValue((int)CAVLCReader.readNBit(inb, 8, "VUI: aspect_ratio")); if (vuip.aspect_ratio == AspectRatio.Extended_SAR) { vuip.sar_width = (int)CAVLCReader.readNBit(inb, 16, "VUI: sar_width"); vuip.sar_height = (int)CAVLCReader.readNBit(inb, 16, "VUI: sar_height"); } } vuip.overscan_info_present_flag = CAVLCReader.readBool(inb, "VUI: overscan_info_present_flag"); if (vuip.overscan_info_present_flag) { vuip.overscan_appropriate_flag = CAVLCReader.readBool(inb, "VUI: overscan_appropriate_flag"); } vuip.video_signal_type_present_flag = CAVLCReader.readBool(inb, "VUI: video_signal_type_present_flag"); if (vuip.video_signal_type_present_flag) { vuip.video_format = (int)CAVLCReader.readNBit(inb, 3, "VUI: video_format"); vuip.video_full_range_flag = CAVLCReader.readBool(inb, "VUI: video_full_range_flag"); vuip.colour_description_present_flag = CAVLCReader.readBool(inb, "VUI: colour_description_present_flag"); if (vuip.colour_description_present_flag) { vuip.colour_primaries = (int)CAVLCReader.readNBit(inb, 8, "VUI: colour_primaries"); vuip.transfer_characteristics = (int)CAVLCReader.readNBit(inb, 8, "VUI: transfer_characteristics"); vuip.matrix_coefficients = (int)CAVLCReader.readNBit(inb, 8, "VUI: matrix_coefficients"); } } vuip.chroma_loc_info_present_flag = CAVLCReader.readBool(inb, "VUI: chroma_loc_info_present_flag"); if (vuip.chroma_loc_info_present_flag) { vuip.chroma_sample_loc_type_top_field = CAVLCReader.readUE(inb, "VUI chroma_sample_loc_type_top_field"); vuip.chroma_sample_loc_type_bottom_field = CAVLCReader.readUE(inb, "VUI chroma_sample_loc_type_bottom_field"); } vuip.timing_info_present_flag = CAVLCReader.readBool(inb, "VUI: timing_info_present_flag"); if (vuip.timing_info_present_flag) { vuip.num_units_in_tick = (int)CAVLCReader.readNBit(inb, 32, "VUI: num_units_in_tick"); vuip.time_scale = (int)CAVLCReader.readNBit(inb, 32, "VUI: time_scale"); vuip.fixed_frame_rate_flag = CAVLCReader.readBool(inb, "VUI: fixed_frame_rate_flag"); } bool nal_hrd_parameters_present_flag = CAVLCReader.readBool(inb, "VUI: nal_hrd_parameters_present_flag"); if (nal_hrd_parameters_present_flag) { vuip.nalHRDParams = readHRDParameters(inb); } bool vcl_hrd_parameters_present_flag = CAVLCReader.readBool(inb, "VUI: vcl_hrd_parameters_present_flag"); if (vcl_hrd_parameters_present_flag) { vuip.vclHRDParams = readHRDParameters(inb); } if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag) { vuip.low_delay_hrd_flag = CAVLCReader.readBool(inb, "VUI: low_delay_hrd_flag"); } vuip.pic_struct_present_flag = CAVLCReader.readBool(inb, "VUI: pic_struct_present_flag"); bool bitstream_restriction_flag = CAVLCReader.readBool(inb, "VUI: bitstream_restriction_flag"); if (bitstream_restriction_flag) { vuip.bitstreamRestriction = new VUIParameters.BitstreamRestriction(); vuip.bitstreamRestriction.motion_vectors_over_pic_boundaries_flag = CAVLCReader.readBool(inb, "VUI: motion_vectors_over_pic_boundaries_flag"); vuip.bitstreamRestriction.max_bytes_per_pic_denom = CAVLCReader.readUE(inb, "VUI max_bytes_per_pic_denom"); vuip.bitstreamRestriction.max_bits_per_mb_denom = CAVLCReader.readUE(inb, "VUI max_bits_per_mb_denom"); vuip.bitstreamRestriction.log2_max_mv_length_horizontal = CAVLCReader.readUE(inb, "VUI log2_max_mv_length_horizontal"); vuip.bitstreamRestriction.log2_max_mv_length_vertical = CAVLCReader.readUE(inb, "VUI log2_max_mv_length_vertical"); vuip.bitstreamRestriction.num_reorder_frames = CAVLCReader.readUE(inb, "VUI num_reorder_frames"); vuip.bitstreamRestriction.max_dec_frame_buffering = CAVLCReader.readUE(inb, "VUI max_dec_frame_buffering"); } return(vuip); }
public static PictureParameterSet read(MemoryStream iss) { BitReader inb = new BitReader(iss); PictureParameterSet pps = new PictureParameterSet(); pps.pic_parameter_set_id = CAVLCReader.readUE(inb, "PPS: pic_parameter_set_id"); pps.seq_parameter_set_id = CAVLCReader.readUE(inb, "PPS: seq_parameter_set_id"); pps.entropy_coding_mode_flag = CAVLCReader.readBool(inb, "PPS: entropy_coding_mode_flag"); pps.pic_order_present_flag = CAVLCReader.readBool(inb, "PPS: pic_order_present_flag"); pps.num_slice_groups_minus1 = CAVLCReader.readUE(inb, "PPS: num_slice_groups_minus1"); if (pps.num_slice_groups_minus1 > 0) { pps.slice_group_map_type = CAVLCReader.readUE(inb, "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] = CAVLCReader.readUE(inb, "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] = CAVLCReader.readUE(inb, "PPS: top_left"); pps.bottom_right[iGroup] = CAVLCReader.readUE(inb, "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 = CAVLCReader.readBool(inb, "PPS: slice_group_change_direction_flag"); pps.slice_group_change_rate_minus1 = CAVLCReader.readUE(inb, "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 = CAVLCReader.readUE(inb, "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] = CAVLCReader.readU(inb, NumberBitsPerSliceGroupId, "PPS: slice_group_id [" + i + "]f"); } } } pps.num_ref_idx_active_minus1 = new int[] { CAVLCReader.readUE(inb, "PPS: num_ref_idx_l0_active_minus1"), CAVLCReader.readUE(inb, "PPS: num_ref_idx_l1_active_minus1") }; pps.weighted_pred_flag = CAVLCReader.readBool(inb, "PPS: weighted_pred_flag"); pps.weighted_bipred_idc = CAVLCReader.readNBit(inb, 2, "PPS: weighted_bipred_idc"); pps.pic_init_qp_minus26 = CAVLCReader.readSE(inb, "PPS: pic_init_qp_minus26"); pps.pic_init_qs_minus26 = CAVLCReader.readSE(inb, "PPS: pic_init_qs_minus26"); pps.chroma_qp_index_offset = CAVLCReader.readSE(inb, "PPS: chroma_qp_index_offset"); pps.deblocking_filter_control_present_flag = CAVLCReader.readBool(inb, "PPS: deblocking_filter_control_present_flag"); pps.constrained_intra_pred_flag = CAVLCReader.readBool(inb, "PPS: constrained_intra_pred_flag"); pps.redundant_pic_cnt_present_flag = CAVLCReader.readBool(inb, "PPS: redundant_pic_cnt_present_flag"); if (CAVLCReader.moreRBSPData(inb)) { pps.extended = new PictureParameterSet.PPSExt(); pps.extended.transform_8x8_mode_flag = CAVLCReader.readBool(inb, "PPS: transform_8x8_mode_flag"); bool pic_scaling_matrix_present_flag = CAVLCReader.readBool(inb, "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 = CAVLCReader.readBool(inb, "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(inb, 16); } else { pps.extended.scalindMatrix.ScalingList8x8[i - 6] = ScalingList.read(inb, 64); } } } } pps.extended.second_chroma_qp_index_offset = CAVLCReader.readSE(inb, "PPS: second_chroma_qp_index_offset"); } return(pps); }