Example #1
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);
        }
Example #2
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());
                }
            }
        }