public ReadExpGolomb ( string name = "" ) : ulong | ||
name | string | |
Résultat | ulong |
private bool ReadPPS(BitReader ppsReader, Variant ppsInfo) { //7.3.2.2 Picture parameter set RBSP syntax //14496-10.pdf 44/280 ppsInfo["pic_parameter_set_id"] = ppsReader.ReadExpGolomb("pic_parameter_set_id"); ppsInfo["seq_parameter_set_id"] = ppsReader.ReadExpGolomb("seq_parameter_set_id"); ppsInfo["entropy_coding_mode_flag"] = ppsReader.ReadBool(); ppsInfo["pic_order_present_flag"] = ppsReader.ReadBool(); ppsInfo["num_slice_groups_minus1"] = ppsReader.ReadExpGolomb("num_slice_groups_minus1"); if (ppsInfo["num_slice_groups_minus1"] > 0) { long sliceGroupMapType = ppsInfo["slice_group_map_type"] = ppsReader.ReadExpGolomb("slice_group_map_type"); switch (sliceGroupMapType) { case 0: ppsInfo["run_length_minus1"] = Variant.Get(); for (var i = 0; i < ppsInfo["num_slice_groups_minus1"]; i++) { var val = ppsReader.ReadExpGolomb("run_length_minus1"); ppsInfo["run_length_minus1"].Add(val); } break; case 2: ppsInfo["top_left"] = Variant.Get(); ppsInfo["bottom_right"] = Variant.Get(); for (var i = 0; i < ppsInfo["num_slice_groups_minus1"]; i++) { ppsInfo["top_left"].Add(ppsReader.ReadExpGolomb("top_left")); ppsInfo["bottom_right"].Add(ppsReader.ReadExpGolomb("bottom_right")); } break; case 3: case 4: case 5: ppsInfo["slice_group_change_direction_flag"] = ppsReader.ReadBool(); ppsInfo["slice_group_change_rate_minus1"] = ppsReader.ReadExpGolomb("slice_group_change_rate_minus1"); break; case 6: ppsInfo["pic_size_in_map_units_minus1"] = ppsReader.ReadExpGolomb("pic_size_in_map_units_minus1"); ppsInfo["slice_group_id"] = Variant.Get(); for (var i = 0; i <= ppsInfo["pic_size_in_map_units_minus1"]; i++) { ppsInfo["slice_group_id"].Add(ppsReader.ReadExpGolomb("slice_group_id")); } break; } } ppsInfo["num_ref_idx_l0_active_minus1"] = ppsReader.ReadExpGolomb("num_ref_idx_l0_active_minus1"); ppsInfo["num_ref_idx_l1_active_minus1"] = ppsReader.ReadExpGolomb("num_ref_idx_l1_active_minus1"); ppsInfo["weighted_pred_flag"] = ppsReader.ReadBool(); ppsInfo["weighted_bipred_idc"] = ppsReader.ReadBitsToInt(2); ppsInfo["pic_init_qp_minus26"] = ppsReader.ReadExpGolomb("pic_init_qp_minus26"); ppsInfo["pic_init_qs_minus26"] = ppsReader.ReadExpGolomb("pic_init_qs_minus26"); ppsInfo["chromqp_index_offset"] = ppsReader.ReadExpGolomb("chromqp_index_offset"); ppsInfo["deblocking_filter_control_present_flag"] = ppsReader.ReadBool(); ppsInfo["constrained_intrpred_flag"] = ppsReader.ReadBool(); ppsInfo["redundant_pic_cnt_present_flag"] = ppsReader.ReadBool(); return true; }
private static bool scaling_list(BitReader spsReader, byte sizeOfScalingList) { uint nextScale = 8; uint lastScale = 8; for (byte j = 0; j < sizeOfScalingList; j++) { if (nextScale != 0) { var deltscale = spsReader.ReadExpGolomb(); nextScale = (uint)((lastScale + deltscale + 256) % 256); } lastScale = (nextScale == 0) ? lastScale : nextScale; } return true; }
private bool ReadSPSVUI(BitReader spsReader, Variant v) { //E.1.1 VUI parameters syntax //14496-10.pdf 267/280 v["aspect_ratio_info_present_flag"] = spsReader.ReadBool(); if (v["aspect_ratio_info_present_flag"]) { v["aspect_ratio_idc"] = spsReader.ReadBitsToByte(); if ((byte)v["aspect_ratio_idc"] == 255) { v["sar_width"] = (ushort)spsReader.ReadBitsToShort(); v["sar_height"] = (ushort)spsReader.ReadBitsToShort(); } } v["overscan_info_present_flag"] = spsReader.ReadBool(); if (v["overscan_info_present_flag"]) v["overscan_appropriate_flag"] = spsReader.ReadBool(); v["video_signal_type_present_flag"] = spsReader.ReadBool(); if (v["video_signal_type_present_flag"]) { v["video_format"] = spsReader.ReadBitsToByte(3); v["video_full_range_flag"] = spsReader.ReadBool(); v["colour_description_present_flag"] = spsReader.ReadBool(); if (v["colour_description_present_flag"]) { v["colour_primaries"] = spsReader.ReadBitsToByte(); v["transfer_characteristics"] = spsReader.ReadBitsToByte(); v["matrix_coefficients"] = spsReader.ReadBitsToByte(); } } v["chromloc_info_present_flag"] = spsReader.ReadBool(); if (v["chromloc_info_present_flag"]) { v["chromsample_loc_type_top_field"] = spsReader.ReadExpGolomb("chromsample_loc_type_top_field"); v["chromsample_loc_type_bottom_field"] = spsReader.ReadExpGolomb("chromsample_loc_type_bottom_field"); } v["timing_info_present_flag"] = spsReader.ReadBool(); if (v["timing_info_present_flag"]) { v["num_units_in_tick"] = spsReader.ReadBitsToInt(); v["time_scale"] = spsReader.ReadBitsToInt(); v["fixed_frame_rate_flag"] = spsReader.ReadBool(); } v["nal_hrd_parameters_present_flag"] = spsReader.ReadBool(); if (v["nal_hrd_parameters_present_flag"]) { if (!ReadSPSVUIHRD(spsReader, v["nal_hrd"] = Variant.Get())) { Logger.FATAL("Unable to read VUIHRD"); return false; } } v["vcl_hrd_parameters_present_flag"] = spsReader.ReadBool(); if (v["vcl_hrd_parameters_present_flag"]) { if (!ReadSPSVUIHRD(spsReader, v["vcl_hrd"] = Variant.Get())) { Logger.FATAL("Unable to read VUIHRD"); return false; } } if (v["nal_hrd_parameters_present_flag"] || v["vcl_hrd_parameters_present_flag"]) v["low_delay_hrd_flag"] = spsReader.ReadBool(); v["pic_struct_present_flag"] = spsReader.ReadBool(); v["bitstream_restriction_flag"] = spsReader.ReadBool(); if (v["bitstream_restriction_flag"]) { v["motion_vectors_over_pic_boundaries_flag"] = spsReader.ReadBool(); v["max_bytes_per_pic_denom"] = spsReader.ReadExpGolomb("max_bytes_per_pic_denom"); v["max_bits_per_mb_denom"] = spsReader.ReadExpGolomb("max_bits_per_mb_denom"); v["log2_max_mv_length_horizontal"] = spsReader.ReadExpGolomb("log2_max_mv_length_horizontal"); v["log2_max_mv_length_vertical"] = spsReader.ReadExpGolomb("log2_max_mv_length_vertical"); v["num_reorder_frames"] = spsReader.ReadExpGolomb("num_reorder_frames"); v["max_dec_frame_buffering"] = spsReader.ReadExpGolomb("max_dec_frame_buffering"); } return true; }
private bool ReadSPSVUIHRD(BitReader spsReader, Variant v) { //E.1.2 HRD parameters syntax //14496-10.pdf 268/280 v["cpb_cnt_minus1"] = spsReader.ReadExpGolomb("cpb_cnt_minus1"); v["bit_rate_scale"] = spsReader.ReadBitsToByte(4); v["cpb_size_scale"] = spsReader.ReadBitsToByte(4); v["bit_rate_value_minus1"] = Variant.Get(); v["cpb_size_value_minus1"] = Variant.Get(); v["cbr_flag"] = Variant.Get(); for (ulong i = 0; i <= v["cpb_cnt_minus1"]; i++) { var val = spsReader.ReadExpGolomb("bit_rate_value_minus1"); v["bit_rate_value_minus1"].Add(val); val = spsReader.ReadExpGolomb("cpb_size_value_minus1"); v["cpb_size_value_minus1"].Add(val); if (spsReader.AvailableBits < 1) { Logger.FATAL("not enough data"); return false; } v["cbr_flag"].Add(spsReader.ReadBool()); } v["initial_cpb_removal_delay_length_minus1"] = spsReader.ReadBitsToByte(5); v["cpb_removal_delay_length_minus1"] = spsReader.ReadBitsToByte(5); v["dpb_output_delay_length_minus1"] = spsReader.ReadBitsToByte(5); v["time_offset_length"] = spsReader.ReadBitsToByte(5); return true; }
private bool ReadSPS(BitReader spsReader, Variant spsInfo) { //7.3.2.1 Sequence parameter set RBSP syntax //14496-10.pdf 43/280 spsInfo["profile_idc"] = spsReader.ReadBitsToByte(); spsInfo["constraint_set0_flag"] = spsReader.ReadBool(); spsInfo["constraint_set1_flag"] = spsReader.ReadBool(); spsInfo["constraint_set2_flag"] = spsReader.ReadBool(); spsInfo["reserved_zero_5bits"] = spsReader.ReadBitsToByte(5); spsInfo["level_idc"] = spsReader.ReadBitsToByte(); spsInfo["seq_parameter_set_id"] = spsReader.ReadExpGolomb("seq_parameter_set_id"); if (spsInfo["profile_idc"] >= 100) { spsInfo["chromformat_idc"] = spsReader.ReadExpGolomb("chromformat_idc"); if (spsInfo["chromformat_idc"] == 3) spsInfo["residual_colour_transform_flag"] = spsReader.ReadBool(); spsInfo["bit_depth_lumminus8"] = spsReader.ReadExpGolomb("bit_depth_lumminus8"); spsInfo["bit_depth_chromminus8"] = spsReader.ReadExpGolomb("bit_depth_chromminus8"); spsInfo["qpprime_y_zero_transform_bypass_flag"] = spsReader.ReadBool(); spsInfo["seq_scaling_matrix_present_flag"] = spsReader.ReadBool(); if (spsInfo["seq_scaling_matrix_present_flag"]) { for (byte i = 0; i < 8; i++) { if (spsReader.AvailableBits < 1) { Logger.FATAL("unable to read seq_scaling_list_present_flag not enought bits "); return false; } if (spsReader.ReadBool()) { if (i < 6) { if (scaling_list(spsReader, 16)) continue; Logger.FATAL("scaling_list failed"); return false; } if (scaling_list(spsReader, 64)) continue; Logger.FATAL("scaling_list failed"); return false; } } } } spsInfo["log2_max_frame_num_minus4"] = spsReader.ReadExpGolomb("log2_max_frame_num_minus4"); spsInfo["pic_order_cnt_type"] = spsReader.ReadExpGolomb("pic_order_cnt_type"); if ((ulong)spsInfo["pic_order_cnt_type"] == 0) { spsInfo["log2_max_pic_order_cnt_lsb_minus4"] = spsReader.ReadExpGolomb("log2_max_pic_order_cnt_lsb_minus4"); } else if ((ulong)spsInfo["pic_order_cnt_type"] == 1) { spsInfo["deltpic_order_always_zero_flag"] = spsReader.ReadBool(); spsInfo["offset_for_non_ref_pic"] = (long)spsReader.ReadExpGolomb("offset_for_non_ref_pic"); spsInfo["offset_for_top_to_bottom_field"] = (long)spsReader.ReadExpGolomb("offset_for_top_to_bottom_field"); spsInfo["num_ref_frames_in_pic_order_cnt_cycle"] = spsReader.ReadExpGolomb("num_ref_frames_in_pic_order_cnt_cycle"); for (ulong i = 0; i < (ulong)spsInfo["num_ref_frames_in_pic_order_cnt_cycle"]; i++) { var val = spsReader.ReadExpGolomb("offset_for_ref_frame value"); spsInfo["offset_for_ref_frame"].Add((long)val); } } spsInfo["num_ref_frames"] = spsReader.ReadExpGolomb("num_ref_frames"); spsInfo["gaps_in_frame_num_value_allowed_flag"] = spsReader.ReadBool(); spsInfo["pic_width_in_mbs_minus1"] = spsReader.ReadExpGolomb("pic_width_in_mbs_minus1"); spsInfo["pic_height_in_map_units_minus1"] = spsReader.ReadExpGolomb("pic_height_in_map_units_minus1"); spsInfo["frame_mbs_only_flag"] = spsReader.ReadBool(); if (!spsInfo["frame_mbs_only_flag"]) spsInfo["mb_adaptive_frame_field_flag"] = spsReader.ReadBool(); spsInfo["direct_8x8_inference_flag"] = spsReader.ReadBool(); spsInfo["frame_cropping_flag"] = spsReader.ReadBool(); if (spsInfo["frame_cropping_flag"]) { spsInfo["frame_crop_left_offset"] = spsReader.ReadExpGolomb("frame_crop_left_offset"); spsInfo["frame_crop_right_offset"] = spsReader.ReadExpGolomb("frame_crop_right_offset"); spsInfo["frame_crop_top_offset"] = spsReader.ReadExpGolomb("frame_crop_top_offset"); spsInfo["frame_crop_bottom_offset"] = spsReader.ReadExpGolomb("frame_crop_bottom_offset"); } spsInfo["vui_parameters_present_flag"] = spsReader.ReadBool(); if (!spsInfo["vui_parameters_present_flag"]) return true; if (ReadSPSVUI(spsReader, spsInfo["vui_parameters"]= Variant.Get())) return true; Logger.FATAL("Unable to read VUI"); return false; }