public static ScalingList Read(BitStreamReader bitReader, int sizeOfScalingList) { ScalingList sl = new ScalingList(); sl.scalingList = new int[sizeOfScalingList]; int lastScale = 8; int nextScale = 8; for (int j = 0; j < sizeOfScalingList; j++) { if (nextScale != 0) { int deltaScale = bitReader.ReadSE(); nextScale = (lastScale + deltaScale + 256) % 256; sl.useDefaultScalingMatrixFlag = (j == 0 && nextScale == 0); } sl.scalingList[j] = nextScale == 0 ? lastScale : nextScale; lastScale = sl.scalingList[j]; } return(sl); }
public static SeqParameterSet Read(byte[] NALData) { BitStreamReader bitReader = new BitStreamReader(NALData); SeqParameterSet sps = new SeqParameterSet(); sps.profile_idc = bitReader.ReadNBit(8); sps.constraint_set_0_flag = bitReader.ReadBool(); sps.constraint_set_1_flag = bitReader.ReadBool(); sps.constraint_set_2_flag = bitReader.ReadBool(); sps.constraint_set_3_flag = bitReader.ReadBool(); bitReader.ReadNBit(4); //reserved_zero_4bits sps.level_idc = bitReader.ReadNBit(8); sps.seq_parameter_set_id = bitReader.ReadUE(); sps.chroma_format_idc = ChromaFormat.Yuv420; if (sps.profile_idc == 100 || sps.profile_idc == 110 || sps.profile_idc == 122 || sps.profile_idc == 244 || sps.profile_idc == 44) { sps.chroma_format_idc = (ChromaFormat)bitReader.ReadUE(); if (sps.chroma_format_idc == ChromaFormat.Yuv444) { sps.residual_color_transform_flag = bitReader.ReadBool(); } sps.bit_depth_luma_minus8 = bitReader.ReadUE(); sps.bit_depth_chroma_minus8 = bitReader.ReadUE(); sps.qpprime_y_zero_transform_bypass_flag = bitReader.ReadBool(); bool seqScalingMatrixPresent = bitReader.ReadBool(); if (seqScalingMatrixPresent) { ReadScalingListMatrix(bitReader, ref sps.scalingMatrix); } } sps.log2_max_frame_num_minus4 = bitReader.ReadUE(); sps.pic_order_cnt_type = bitReader.ReadUE(); if (sps.pic_order_cnt_type == 0) { sps.log2_max_pic_order_cnt_lsb_minus4 = bitReader.ReadUE(); } else if (sps.pic_order_cnt_type == 1) { sps.delta_pic_order_always_zero_flag = bitReader.ReadBool(); sps.offset_for_non_ref_pic = bitReader.ReadSE(); sps.offset_for_top_to_bottom_field = bitReader.ReadSE(); sps.num_ref_frames_in_pic_order_cnt_cycle = bitReader.ReadUE(); 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] = bitReader.ReadSE(); } } sps.num_ref_frames = bitReader.ReadUE(); sps.gaps_in_frame_num_value_allowed_flag = bitReader.ReadBool(); sps.pic_width_in_mbs_minus1 = bitReader.ReadUE(); sps.pic_height_in_map_units_minus1 = bitReader.ReadUE(); sps.frame_mbs_only_flag = bitReader.ReadBool(); if (!sps.frame_mbs_only_flag) { sps.mb_adaptive_frame_field_flag = bitReader.ReadBool(); } sps.direct_8x8_inference_flag = bitReader.ReadBool(); sps.frame_cropping_flag = bitReader.ReadBool(); if (sps.frame_cropping_flag) { sps.frame_crop_left_offset = bitReader.ReadUE(); sps.frame_crop_right_offset = bitReader.ReadUE(); sps.frame_crop_top_offset = bitReader.ReadUE(); sps.frame_crop_bottom_offset = bitReader.ReadUE(); } bool vui_parameters_present_flag = bitReader.ReadBool(); if (vui_parameters_present_flag) { ReadVUIParameters(bitReader, ref sps.vuiParams); } return(sps); }