private void writeHRDParameters(HRDParameters hrd, BitWriter writer) { CAVLCWriter.writeUE(writer, hrd.cpb_cnt_minus1, "HRD: cpb_cnt_minus1"); CAVLCWriter.writeNBit(writer, hrd.bit_rate_scale, 4, "HRD: bit_rate_scale"); CAVLCWriter.writeNBit(writer, hrd.cpb_size_scale, 4, "HRD: cpb_size_scale"); for (int SchedSelIdx = 0; SchedSelIdx <= hrd.cpb_cnt_minus1; SchedSelIdx++) { CAVLCWriter.writeUE(writer, hrd.bit_rate_value_minus1[SchedSelIdx], "HRD: "); CAVLCWriter.writeUE(writer, hrd.cpb_size_value_minus1[SchedSelIdx], "HRD: "); CAVLCWriter.writeBool(writer, hrd.cbr_flag[SchedSelIdx], "HRD: "); } CAVLCWriter.writeNBit(writer, hrd.initial_cpb_removal_delay_length_minus1, 5, "HRD: initial_cpb_removal_delay_length_minus1"); CAVLCWriter.writeNBit(writer, hrd.cpb_removal_delay_length_minus1, 5, "HRD: cpb_removal_delay_length_minus1"); CAVLCWriter.writeNBit(writer, hrd.dpb_output_delay_length_minus1, 5, "HRD: dpb_output_delay_length_minus1"); CAVLCWriter.writeNBit(writer, hrd.time_offset_length, 5, "HRD: time_offset_length"); }
public void write(MemoryStream outb) { BitWriter writer = new BitWriter(outb); CAVLCWriter.writeNBit(writer, profile_idc, 8, "SPS: profile_idc"); CAVLCWriter.writeBool(writer, constraint_set_0_flag, "SPS: constraint_set_0_flag"); CAVLCWriter.writeBool(writer, constraint_set_1_flag, "SPS: constraint_set_1_flag"); CAVLCWriter.writeBool(writer, constraint_set_2_flag, "SPS: constraint_set_2_flag"); CAVLCWriter.writeBool(writer, constraint_set_3_flag, "SPS: constraint_set_3_flag"); CAVLCWriter.writeNBit(writer, 0, 4, "SPS: reserved"); CAVLCWriter.writeNBit(writer, level_idc, 8, "SPS: level_idc"); CAVLCWriter.writeUE(writer, seq_parameter_set_id, "SPS: seq_parameter_set_id"); if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 144) { CAVLCWriter.writeUE(writer, fromColor(chroma_format_idc), "SPS: chroma_format_idc"); if (chroma_format_idc == ColorSpace.YUV444) { CAVLCWriter.writeBool(writer, residual_color_transform_flag, "SPS: residual_color_transform_flag"); } CAVLCWriter.writeUE(writer, bit_depth_luma_minus8, "SPS: "); CAVLCWriter.writeUE(writer, bit_depth_chroma_minus8, "SPS: "); CAVLCWriter.writeBool(writer, qpprime_y_zero_transform_bypass_flag, "SPS: qpprime_y_zero_transform_bypass_flag"); CAVLCWriter.writeBool(writer, scalingMatrix != null, "SPS: "); if (scalingMatrix != null) { for (int i = 0; i < 8; i++) { if (i < 6) { CAVLCWriter.writeBool(writer, (scalingMatrix.ScalingList4x4[i] != null), "SPS: "); if (scalingMatrix.ScalingList4x4[i] != null) { scalingMatrix.ScalingList4x4[i].write(writer); } } else { CAVLCWriter.writeBool(writer, (scalingMatrix.ScalingList8x8[i - 6] != null), "SPS: "); if (scalingMatrix.ScalingList8x8[i - 6] != null) { scalingMatrix.ScalingList8x8[i - 6].write(writer); } } } } } CAVLCWriter.writeUE(writer, log2_max_frame_num_minus4, "SPS: log2_max_frame_num_minus4"); CAVLCWriter.writeUE(writer, pic_order_cnt_type, "SPS: pic_order_cnt_type"); if (pic_order_cnt_type == 0) { CAVLCWriter.writeUE(writer, log2_max_pic_order_cnt_lsb_minus4, "SPS: log2_max_pic_order_cnt_lsb_minus4"); } else if (pic_order_cnt_type == 1) { CAVLCWriter.writeBool(writer, delta_pic_order_always_zero_flag, "SPS: delta_pic_order_always_zero_flag"); CAVLCWriter.writeSE(writer, offset_for_non_ref_pic, "SPS: offset_for_non_ref_pic"); CAVLCWriter.writeSE(writer, offset_for_top_to_bottom_field, "SPS: offset_for_top_to_bottom_field"); CAVLCWriter.writeUE(writer, offsetForRefFrame.Length, "SPS: "); for (int i = 0; i < offsetForRefFrame.Length; i++) { CAVLCWriter.writeSE(writer, offsetForRefFrame[i], "SPS: "); } } CAVLCWriter.writeUE(writer, num_ref_frames, "SPS: num_ref_frames"); CAVLCWriter.writeBool(writer, gaps_in_frame_num_value_allowed_flag, "SPS: gaps_in_frame_num_value_allowed_flag"); CAVLCWriter.writeUE(writer, pic_width_in_mbs_minus1, "SPS: pic_width_in_mbs_minus1"); CAVLCWriter.writeUE(writer, pic_height_in_map_units_minus1, "SPS: pic_height_in_map_units_minus1"); CAVLCWriter.writeBool(writer, frame_mbs_only_flag, "SPS: frame_mbs_only_flag"); if (!frame_mbs_only_flag) { CAVLCWriter.writeBool(writer, mb_adaptive_frame_field_flag, "SPS: mb_adaptive_frame_field_flag"); } CAVLCWriter.writeBool(writer, direct_8x8_inference_flag, "SPS: direct_8x8_inference_flag"); CAVLCWriter.writeBool(writer, frame_cropping_flag, "SPS: frame_cropping_flag"); if (frame_cropping_flag) { CAVLCWriter.writeUE(writer, frame_crop_left_offset, "SPS: frame_crop_left_offset"); CAVLCWriter.writeUE(writer, frame_crop_right_offset, "SPS: frame_crop_right_offset"); CAVLCWriter.writeUE(writer, frame_crop_top_offset, "SPS: frame_crop_top_offset"); CAVLCWriter.writeUE(writer, frame_crop_bottom_offset, "SPS: frame_crop_bottom_offset"); } CAVLCWriter.writeBool(writer, vuiParams != null, "SPS: "); if (vuiParams != null) { writeVUIParameters(vuiParams, writer); } CAVLCWriter.writeTrailingBits(writer); }
private void writeVUIParameters(VUIParameters vuip, BitWriter writer) { CAVLCWriter.writeBool(writer, vuip.aspect_ratio_info_present_flag, "VUI: aspect_ratio_info_present_flag"); if (vuip.aspect_ratio_info_present_flag) { CAVLCWriter.writeNBit(writer, vuip.aspect_ratio.getValue(), 8, "VUI: aspect_ratio"); if (vuip.aspect_ratio == AspectRatio.Extended_SAR) { CAVLCWriter.writeNBit(writer, vuip.sar_width, 16, "VUI: sar_width"); CAVLCWriter.writeNBit(writer, vuip.sar_height, 16, "VUI: sar_height"); } } CAVLCWriter.writeBool(writer, vuip.overscan_info_present_flag, "VUI: overscan_info_present_flag"); if (vuip.overscan_info_present_flag) { CAVLCWriter.writeBool(writer, vuip.overscan_appropriate_flag, "VUI: overscan_appropriate_flag"); } CAVLCWriter.writeBool(writer, vuip.video_signal_type_present_flag, "VUI: video_signal_type_present_flag"); if (vuip.video_signal_type_present_flag) { CAVLCWriter.writeNBit(writer, vuip.video_format, 3, "VUI: video_format"); CAVLCWriter.writeBool(writer, vuip.video_full_range_flag, "VUI: video_full_range_flag"); CAVLCWriter.writeBool(writer, vuip.colour_description_present_flag, "VUI: colour_description_present_flag"); if (vuip.colour_description_present_flag) { CAVLCWriter.writeNBit(writer, vuip.colour_primaries, 8, "VUI: colour_primaries"); CAVLCWriter.writeNBit(writer, vuip.transfer_characteristics, 8, "VUI: transfer_characteristics"); CAVLCWriter.writeNBit(writer, vuip.matrix_coefficients, 8, "VUI: matrix_coefficients"); } } CAVLCWriter.writeBool(writer, vuip.chroma_loc_info_present_flag, "VUI: chroma_loc_info_present_flag"); if (vuip.chroma_loc_info_present_flag) { CAVLCWriter.writeUE(writer, vuip.chroma_sample_loc_type_top_field, "VUI: chroma_sample_loc_type_top_field"); CAVLCWriter.writeUE(writer, vuip.chroma_sample_loc_type_bottom_field, "VUI: chroma_sample_loc_type_bottom_field"); } CAVLCWriter.writeBool(writer, vuip.timing_info_present_flag, "VUI: timing_info_present_flag"); if (vuip.timing_info_present_flag) { CAVLCWriter.writeNBit(writer, vuip.num_units_in_tick, 32, "VUI: num_units_in_tick"); CAVLCWriter.writeNBit(writer, vuip.time_scale, 32, "VUI: time_scale"); CAVLCWriter.writeBool(writer, vuip.fixed_frame_rate_flag, "VUI: fixed_frame_rate_flag"); } CAVLCWriter.writeBool(writer, vuip.nalHRDParams != null, "VUI: "); if (vuip.nalHRDParams != null) { writeHRDParameters(vuip.nalHRDParams, writer); } CAVLCWriter.writeBool(writer, vuip.vclHRDParams != null, "VUI: "); if (vuip.vclHRDParams != null) { writeHRDParameters(vuip.vclHRDParams, writer); } if (vuip.nalHRDParams != null || vuip.vclHRDParams != null) { CAVLCWriter.writeBool(writer, vuip.low_delay_hrd_flag, "VUI: low_delay_hrd_flag"); } CAVLCWriter.writeBool(writer, vuip.pic_struct_present_flag, "VUI: pic_struct_present_flag"); CAVLCWriter.writeBool(writer, vuip.bitstreamRestriction != null, "VUI: "); if (vuip.bitstreamRestriction != null) { CAVLCWriter.writeBool(writer, vuip.bitstreamRestriction.motion_vectors_over_pic_boundaries_flag, "VUI: motion_vectors_over_pic_boundaries_flag"); CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.max_bytes_per_pic_denom, "VUI: max_bytes_per_pic_denom"); CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.max_bits_per_mb_denom, "VUI: max_bits_per_mb_denom"); CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.log2_max_mv_length_horizontal, "VUI: log2_max_mv_length_horizontal"); CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.log2_max_mv_length_vertical, "VUI: log2_max_mv_length_vertical"); CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.num_reorder_frames, "VUI: num_reorder_frames"); CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.max_dec_frame_buffering, "VUI: max_dec_frame_buffering"); } }
public void write(MemoryStream outb) { BitWriter writer = new BitWriter(outb); CAVLCWriter.writeUE(writer, pic_parameter_set_id, "PPS: pic_parameter_set_id"); CAVLCWriter.writeUE(writer, seq_parameter_set_id, "PPS: seq_parameter_set_id"); CAVLCWriter.writeBool(writer, entropy_coding_mode_flag, "PPS: entropy_coding_mode_flag"); CAVLCWriter.writeBool(writer, pic_order_present_flag, "PPS: pic_order_present_flag"); CAVLCWriter.writeUE(writer, num_slice_groups_minus1, "PPS: num_slice_groups_minus1"); if (num_slice_groups_minus1 > 0) { CAVLCWriter.writeUE(writer, slice_group_map_type, "PPS: slice_group_map_type"); int[] top_left = new int[1]; int[] bottom_right = new int[1]; int[] run_length_minus1 = new int[1]; if (slice_group_map_type == 0) { for (int iGroup = 0; iGroup <= num_slice_groups_minus1; iGroup++) { CAVLCWriter.writeUE(writer, run_length_minus1[iGroup], "PPS: "); } } else if (slice_group_map_type == 2) { for (int iGroup = 0; iGroup < num_slice_groups_minus1; iGroup++) { CAVLCWriter.writeUE(writer, top_left[iGroup], "PPS: "); CAVLCWriter.writeUE(writer, bottom_right[iGroup], "PPS: "); } } else if (slice_group_map_type == 3 || slice_group_map_type == 4 || slice_group_map_type == 5) { CAVLCWriter.writeBool(writer, slice_group_change_direction_flag, "PPS: slice_group_change_direction_flag"); CAVLCWriter.writeUE(writer, slice_group_change_rate_minus1, "PPS: slice_group_change_rate_minus1"); } else if (slice_group_map_type == 6) { int NumberBitsPerSliceGroupId; if (num_slice_groups_minus1 + 1 > 4) { NumberBitsPerSliceGroupId = 3; } else if (num_slice_groups_minus1 + 1 > 2) { NumberBitsPerSliceGroupId = 2; } else { NumberBitsPerSliceGroupId = 1; } CAVLCWriter.writeUE(writer, slice_group_id.Length, "PPS: "); for (int i = 0; i <= slice_group_id.Length; i++) { CAVLCWriter.writeU(writer, slice_group_id[i], NumberBitsPerSliceGroupId); } } } CAVLCWriter.writeUE(writer, num_ref_idx_active_minus1[0], "PPS: num_ref_idx_l0_active_minus1"); CAVLCWriter.writeUE(writer, num_ref_idx_active_minus1[1], "PPS: num_ref_idx_l1_active_minus1"); CAVLCWriter.writeBool(writer, weighted_pred_flag, "PPS: weighted_pred_flag"); CAVLCWriter.writeNBit(writer, weighted_bipred_idc, 2, "PPS: weighted_bipred_idc"); CAVLCWriter.writeSE(writer, pic_init_qp_minus26, "PPS: pic_init_qp_minus26"); CAVLCWriter.writeSE(writer, pic_init_qs_minus26, "PPS: pic_init_qs_minus26"); CAVLCWriter.writeSE(writer, chroma_qp_index_offset, "PPS: chroma_qp_index_offset"); CAVLCWriter.writeBool(writer, deblocking_filter_control_present_flag, "PPS: deblocking_filter_control_present_flag"); CAVLCWriter.writeBool(writer, constrained_intra_pred_flag, "PPS: constrained_intra_pred_flag"); CAVLCWriter.writeBool(writer, redundant_pic_cnt_present_flag, "PPS: redundant_pic_cnt_present_flag"); if (extended != null) { CAVLCWriter.writeBool(writer, extended.transform_8x8_mode_flag, "PPS: transform_8x8_mode_flag"); CAVLCWriter.writeBool(writer, extended.scalindMatrix != null, "PPS: scalindMatrix"); if (extended.scalindMatrix != null) { for (int i = 0; i < 6 + 2 * (extended.transform_8x8_mode_flag ? 1 : 0); i++) { if (i < 6) { CAVLCWriter.writeBool(writer, extended.scalindMatrix.ScalingList4x4[i] != null, "PPS: "); if (extended.scalindMatrix.ScalingList4x4[i] != null) { extended.scalindMatrix.ScalingList4x4[i].write(writer); } } else { CAVLCWriter.writeBool(writer, extended.scalindMatrix.ScalingList8x8[i - 6] != null, "PPS: "); if (extended.scalindMatrix.ScalingList8x8[i - 6] != null) { extended.scalindMatrix.ScalingList8x8[i - 6].write(writer); } } } } CAVLCWriter.writeSE(writer, extended.second_chroma_qp_index_offset, "PPS: "); } CAVLCWriter.writeTrailingBits(writer); }