Esempio n. 1
0
 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);
             }
         }
     }
 }
Esempio n. 2
0
        public static SeqParameterSet Read(Stream @is)
        {
            var reader = new CAVLCReader(@is);
            var sps    = new SeqParameterSet
            {
                profile_idc           = (int)reader.ReadNBit(8, "SPS: profile_idc"),
                constraint_set_0_flag = reader.ReadBool("SPS: constraint_set_0_flag"),
                constraint_set_1_flag = reader.ReadBool("SPS: constraint_set_1_flag"),
                constraint_set_2_flag = reader.ReadBool("SPS: constraint_set_2_flag"),
                constraint_set_3_flag = reader.ReadBool("SPS: constraint_set_3_flag"),
                constraint_set_4_flag = reader.ReadBool("SPS: constraint_set_4_flag"),
                constraint_set_5_flag = reader.ReadBool("SPS: constraint_set_5_flag")
            };

            reader.ReadNBit(2, "SPS: reserved_zero_2bits");
            sps.level_idc            = (int)reader.ReadNBit(8, "SPS: level_idc");
            sps.seq_parameter_set_id = reader.ReadUE("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 = ChromaFormat.fromId(reader.ReadUE("SPS: chroma_format_idc"));
                if (sps.chroma_format_idc == ChromaFormat.YUV_444)
                {
                    sps.residual_color_transform_flag = reader.ReadBool("SPS: residual_color_transform_flag");
                }
                sps.bit_depth_luma_minus8   = reader.ReadUE("SPS: bit_depth_luma_minus8");
                sps.bit_depth_chroma_minus8 = reader.ReadUE("SPS: bit_depth_chroma_minus8");
                sps.qpprime_y_zero_transform_bypass_flag = reader.ReadBool("SPS: qpprime_y_zero_transform_bypass_flag");
                bool seqScalingMatrixPresent = reader.ReadBool("SPS: seq_scaling_matrix_present_lag");
                if (seqScalingMatrixPresent)
                {
                    readScalingListMatrix(reader, sps);
                }
            }
            else
            {
                sps.chroma_format_idc = ChromaFormat.YUV_420;
            }
            sps.log2_max_frame_num_minus4 = reader.ReadUE("SPS: log2_max_frame_num_minus4");
            sps.pic_order_cnt_type        = reader.ReadUE("SPS: pic_order_cnt_type");
            if (sps.pic_order_cnt_type == 0)
            {
                sps.log2_max_pic_order_cnt_lsb_minus4 = reader.ReadUE("SPS: log2_max_pic_order_cnt_lsb_minus4");
            }
            else if (sps.pic_order_cnt_type == 1)
            {
                sps.delta_pic_order_always_zero_flag      = reader.ReadBool("SPS: delta_pic_order_always_zero_flag");
                sps.offset_for_non_ref_pic                = reader.ReadSE("SPS: offset_for_non_ref_pic");
                sps.offset_for_top_to_bottom_field        = reader.ReadSE("SPS: offset_for_top_to_bottom_field");
                sps.Num_ref_frames_in_pic_order_cnt_cycle = reader.ReadUE("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] = reader.ReadSE("SPS: offsetForRefFrame [" + i + "]");
                }
            }
            sps.num_ref_frames = reader.ReadUE("SPS: num_ref_frames");
            sps.gaps_in_frame_num_value_allowed_flag = reader.ReadBool("SPS: gaps_in_frame_num_value_allowed_flag");
            sps.pic_width_in_mbs_minus1        = reader.ReadUE("SPS: pic_width_in_mbs_minus1");
            sps.pic_height_in_map_units_minus1 = reader.ReadUE("SPS: pic_height_in_map_units_minus1");
            sps.frame_mbs_only_flag            = reader.ReadBool("SPS: frame_mbs_only_flag");
            if (!sps.frame_mbs_only_flag)
            {
                sps.mb_adaptive_frame_field_flag = reader.ReadBool("SPS: mb_adaptive_frame_field_flag");
            }
            sps.direct_8x8_inference_flag = reader.ReadBool("SPS: direct_8x8_inference_flag");
            sps.frame_cropping_flag       = reader.ReadBool("SPS: frame_cropping_flag");
            if (sps.frame_cropping_flag)
            {
                sps.frame_crop_left_offset   = reader.ReadUE("SPS: frame_crop_left_offset");
                sps.frame_crop_right_offset  = reader.ReadUE("SPS: frame_crop_right_offset");
                sps.frame_crop_top_offset    = reader.ReadUE("SPS: frame_crop_top_offset");
                sps.frame_crop_bottom_offset = reader.ReadUE("SPS: frame_crop_bottom_offset");
            }
            bool vui_parameters_present_flag = reader.ReadBool("SPS: vui_parameters_present_flag");

            if (vui_parameters_present_flag)
            {
                sps.VuiParams = ReadVUIParameters(reader);
            }

            reader.ReadTrailingBits();

            return(sps);
        }