Esempio n. 1
0
        public static SeqParameterSetExt read(MemoryStream iss)
        {
            BitReader inb = new BitReader(iss);

            SeqParameterSetExt spse = new SeqParameterSetExt();

            spse.seq_parameter_set_id = CAVLCReader.readUE(inb, "SPSE: seq_parameter_set_id");
            spse.aux_format_idc       = CAVLCReader.readUE(inb, "SPSE: aux_format_idc");
            if (spse.aux_format_idc != 0)
            {
                spse.bit_depth_aux_minus8    = CAVLCReader.readUE(inb, "SPSE: bit_depth_aux_minus8");
                spse.alpha_incr_flag         = CAVLCReader.readBool(inb, "SPSE: alpha_incr_flag");
                spse.alpha_opaque_value      = CAVLCReader.readU(inb, spse.bit_depth_aux_minus8 + 9, "SPSE: alpha_opaque_value");
                spse.alpha_transparent_value = CAVLCReader.readU(inb, spse.bit_depth_aux_minus8 + 9, "SPSE: alpha_transparent_value");
            }
            spse.additional_extension_flag = CAVLCReader.readBool(inb, "SPSE: additional_extension_flag");

            return(spse);
        }
Esempio n. 2
0
 private static void readScalingListMatrix(BitReader inb, SeqParameterSet sps)
 {
     sps.scalingMatrix = new ScalingMatrix();
     for (int i = 0; i < 8; i++)
     {
         bool seqScalingListPresentFlag = CAVLCReader.readBool(inb, "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(inb, 16);
             }
             else
             {
                 sps.scalingMatrix.ScalingList8x8[i - 6] = ScalingList.read(inb, 64);
             }
         }
     }
 }
Esempio n. 3
0
 private static void readRefPicListReorderinbg(SliceHeader sh, BitReader inb)
 {
     sh.refPicReordering = new int[2][][];
     // System.out.println(i++);
     if (sh.slice_type.isInter())
     {
         bool ref_pic_list_reorderinbg_flag_l0 = CAVLCReader.readBool(inb, "SH: ref_pic_list_reorderinbg_flag_l0");
         if (ref_pic_list_reorderinbg_flag_l0)
         {
             sh.refPicReordering[0] = readReorderinbgEntries(inb);
         }
     }
     if (sh.slice_type == SliceType.B)
     {
         bool ref_pic_list_reorderinbg_flag_l1 = CAVLCReader.readBool(inb, "SH: ref_pic_list_reorderinbg_flag_l1");
         if (ref_pic_list_reorderinbg_flag_l1)
         {
             sh.refPicReordering[1] = readReorderinbgEntries(inb);
         }
     }
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 private static void readWeightOffset(SeqParameterSet sps, PictureParameterSet pps, SliceHeader sh, BitReader inb,
                                      int[] numRefs, int list)
 {
     for (int i = 0; i < numRefs[list]; i++)
     {
         bool luma_weight_l0_flag = CAVLCReader.readBool(inb, "SH: luma_weight_l0_flag");
         if (luma_weight_l0_flag)
         {
             sh.pred_weight_table.luma_weight[list][i] = CAVLCReader.readSE(inb, "SH: weight");
             sh.pred_weight_table.luma_offset[list][i] = CAVLCReader.readSE(inb, "SH: offset");
         }
         if (sps.chroma_format_idc != ColorSpace.MONO)
         {
             bool chroma_weight_l0_flag = CAVLCReader.readBool(inb, "SH: chroma_weight_l0_flag");
             if (chroma_weight_l0_flag)
             {
                 sh.pred_weight_table.chroma_weight[list][0][i] = CAVLCReader.readSE(inb, "SH: weight");
                 sh.pred_weight_table.chroma_offset[list][0][i] = CAVLCReader.readSE(inb, "SH: offset");
                 sh.pred_weight_table.chroma_weight[list][1][i] = CAVLCReader.readSE(inb, "SH: weight");
                 sh.pred_weight_table.chroma_offset[list][1][i] = CAVLCReader.readSE(inb, "SH: offset");
             }
         }
     }
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        public SliceHeader readPart2(SliceHeader sh, NALUnit nalUnit, SeqParameterSet sps, PictureParameterSet pps,
                                     BitReader inb)
        {
            sh.pps = pps;
            sh.sps = sps;

            sh.frame_num = CAVLCReader.readU(inb, sps.log2_max_frame_num_minus4 + 4, "SH: frame_num");
            if (!sps.frame_mbs_only_flag)
            {
                sh.field_pic_flag = CAVLCReader.readBool(inb, "SH: field_pic_flag");
                if (sh.field_pic_flag)
                {
                    sh.bottom_field_flag = CAVLCReader.readBool(inb, "SH: bottom_field_flag");
                }
            }
            if (nalUnit.type == NALUnitType.IDR_SLICE)
            {
                sh.idr_pic_id = CAVLCReader.readUE(inb, "SH: idr_pic_id");
            }
            if (sps.pic_order_cnt_type == 0)
            {
                sh.pic_order_cnt_lsb = CAVLCReader.readU(inb, sps.log2_max_pic_order_cnt_lsb_minus4 + 4, "SH: pic_order_cnt_lsb");
                if (pps.pic_order_present_flag && !sps.field_pic_flag)
                {
                    sh.delta_pic_order_cnt_bottom = CAVLCReader.readSE(inb, "SH: delta_pic_order_cnt_bottom");
                }
            }
            sh.delta_pic_order_cnt = new int[2];
            if (sps.pic_order_cnt_type == 1 && !sps.delta_pic_order_always_zero_flag)
            {
                sh.delta_pic_order_cnt[0] = CAVLCReader.readSE(inb, "SH: delta_pic_order_cnt[0]");
                if (pps.pic_order_present_flag && !sps.field_pic_flag)
                {
                    sh.delta_pic_order_cnt[1] = CAVLCReader.readSE(inb, "SH: delta_pic_order_cnt[1]");
                }
            }
            if (pps.redundant_pic_cnt_present_flag)
            {
                sh.redundant_pic_cnt = CAVLCReader.readUE(inb, "SH: redundant_pic_cnt");
            }
            if (sh.slice_type == SliceType.B)
            {
                sh.direct_spatial_mv_pred_flag = CAVLCReader.readBool(inb, "SH: direct_spatial_mv_pred_flag");
            }
            if (sh.slice_type == SliceType.P || sh.slice_type == SliceType.SP || sh.slice_type == SliceType.B)
            {
                sh.num_ref_idx_active_override_flag = CAVLCReader.readBool(inb, "SH: num_ref_idx_active_override_flag");
                if (sh.num_ref_idx_active_override_flag)
                {
                    sh.num_ref_idx_active_minus1[0] = CAVLCReader.readUE(inb, "SH: num_ref_idx_l0_active_minus1");
                    if (sh.slice_type == SliceType.B)
                    {
                        sh.num_ref_idx_active_minus1[1] = CAVLCReader.readUE(inb, "SH: num_ref_idx_l1_active_minus1");
                    }
                }
            }
            readRefPicListReorderinbg(sh, inb);
            if ((pps.weighted_pred_flag && (sh.slice_type == SliceType.P || sh.slice_type == SliceType.SP)) ||
                (pps.weighted_bipred_idc == 1 && sh.slice_type == SliceType.B))
            {
                readPredWeightTable(sps, pps, sh, inb);
            }
            if (nalUnit.nal_ref_idc != 0)
            {
                readDecoderPicMarkinbg(nalUnit, sh, inb);
            }
            if (pps.entropy_coding_mode_flag && sh.slice_type.isInter())
            {
                sh.cabac_init_idc = CAVLCReader.readUE(inb, "SH: cabac_inbit_idc");
            }
            sh.slice_qp_delta = CAVLCReader.readSE(inb, "SH: slice_qp_delta");
            if (sh.slice_type == SliceType.SP || sh.slice_type == SliceType.SI)
            {
                if (sh.slice_type == SliceType.SP)
                {
                    sh.sp_for_switch_flag = CAVLCReader.readBool(inb, "SH: sp_for_switch_flag");
                }
                sh.slice_qs_delta = CAVLCReader.readSE(inb, "SH: slice_qs_delta");
            }
            if (pps.deblocking_filter_control_present_flag)
            {
                sh.disable_deblocking_filter_idc = CAVLCReader.readUE(inb, "SH: disable_deblockinbg_filter_idc");
                if (sh.disable_deblocking_filter_idc != 1)
                {
                    sh.slice_alpha_c0_offset_div2 = CAVLCReader.readSE(inb, "SH: slice_alpha_c0_offset_div2");
                    sh.slice_beta_offset_div2     = CAVLCReader.readSE(inb, "SH: slice_beta_offset_div2");
                }
            }
            if (pps.num_slice_groups_minus1 > 0 && pps.slice_group_map_type >= 3 && pps.slice_group_map_type <= 5)
            {
                int len = Utility.getPicHeightInMbs(sps) * (sps.pic_width_in_mbs_minus1 + 1)
                          / (pps.slice_group_change_rate_minus1 + 1);
                if ((Utility.getPicHeightInMbs(sps) * (sps.pic_width_in_mbs_minus1 + 1))
                    % (pps.slice_group_change_rate_minus1 + 1) > 0)
                {
                    len += 1;
                }

                len = CeilLog2(len + 1);
                sh.slice_group_change_cycle = CAVLCReader.readU(inb, len, "SH: slice_group_change_cycle");
            }

            return(sh);
        }
Esempio n. 10
0
        // static int i = 0;

        private static void readDecoderPicMarkinbg(NALUnit nalUnit, SliceHeader sh, BitReader inb)
        {
            if (nalUnit.type == NALUnitType.IDR_SLICE)
            {
                bool no_output_of_prior_pics_flag = CAVLCReader.readBool(inb, "SH: no_output_of_prior_pics_flag");
                bool long_term_reference_flag     = CAVLCReader.readBool(inb, "SH: long_term_reference_flag");
                sh.refPicMarkingIDR = new nVideo.Codecs.H264.RefPicMarkingIDR(no_output_of_prior_pics_flag, long_term_reference_flag);
            }
            else
            {
                bool adaptive_ref_pic_markinbg_mode_flag = CAVLCReader.readBool(inb, "SH: adaptive_ref_pic_markinbg_mode_flag");
                if (adaptive_ref_pic_markinbg_mode_flag)
                {
                    List <nVideo.Codecs.H264.RefPicMarking.Instruction> mmops = new List <nVideo.Codecs.H264.RefPicMarking.Instruction>();
                    int memory_management_control_operation;
                    do
                    {
                        memory_management_control_operation = CAVLCReader.readUE(inb, "SH: memory_management_control_operation");

                        nVideo.Codecs.H264.RefPicMarking.Instruction inbstr = null;



                        switch (memory_management_control_operation)
                        {
                        case 1:
                            inbstr = new nVideo.Codecs.H264.RefPicMarking.Instruction(nVideo.Codecs.H264.RefPicMarking.InstrType.REMOVE_SHORT, CAVLCReader.readUE(inb,
                                                                                                                                                                  "SH: difference_of_pic_nums_minus1") + 1, 0);
                            break;

                        case 2:
                            inbstr = new nVideo.Codecs.H264.RefPicMarking.Instruction(nVideo.Codecs.H264.RefPicMarking.InstrType.REMOVE_LONG,
                                                                                      CAVLCReader.readUE(inb, "SH: long_term_pic_num"), 0);
                            break;

                        case 3:
                            inbstr = new nVideo.Codecs.H264.RefPicMarking.Instruction(nVideo.Codecs.H264.RefPicMarking.InstrType.CONVERT_INTO_LONG, CAVLCReader.readUE(inb,
                                                                                                                                                                       "SH: difference_of_pic_nums_minus1") + 1, CAVLCReader.readUE(inb, "SH: long_term_frame_idx"));
                            break;

                        case 4:
                            inbstr = new nVideo.Codecs.H264.RefPicMarking.Instruction(nVideo.Codecs.H264.RefPicMarking.InstrType.TRUNK_LONG, CAVLCReader.readUE(inb,
                                                                                                                                                                "SH: max_long_term_frame_idx_plus1") - 1, 0);
                            break;

                        case 5:
                            inbstr = new nVideo.Codecs.H264.RefPicMarking.Instruction(nVideo.Codecs.H264.RefPicMarking.InstrType.CLEAR, 0, 0);
                            break;

                        case 6:
                            inbstr = new nVideo.Codecs.H264.RefPicMarking.Instruction(nVideo.Codecs.H264.RefPicMarking.InstrType.MARK_LONG,
                                                                                      CAVLCReader.readUE(inb, "SH: long_term_frame_idx"), 0);
                            break;
                        }
                        if (inbstr != null)
                        {
                            mmops.Add(inbstr);
                        }
                    } while (memory_management_control_operation != 0);
                    sh.refPicMarkingNonIDR = new RefPicMarking(mmops.ToArray());
                }
            }
        }