Example #1
0
        public override int probe(MemoryStream data)
        {
            bool avalidSps = false, avalidPps = false, avalidSh = false;

            foreach (var nalUnit in Utility.splitFrame(data.duplicate()))
            {
                NALUnit marker = NALUnit.read(nalUnit);
                if (marker.type == NALUnitType.IDR_SLICE || marker.type == NALUnitType.NON_IDR_SLICE)
                {
                    BitReader reader = new BitReader(nalUnit);
                    avalidSh = validSh(new SliceHeaderReader().readPart1(reader));
                    break;
                }
                else if (marker.type == NALUnitType.SPS)
                {
                    avalidSps = validSps(SeqParameterSet.read(nalUnit));
                }
                else if (marker.type == NALUnitType.PPS)
                {
                    avalidPps = validPps(PictureParameterSet.read(nalUnit));
                }
            }

            return((avalidSh ? 60 : 0) + (avalidSps ? 20 : 0) + (avalidPps ? 20 : 0));
        }
Example #2
0
            private SliceHeader part2(System.IO.MemoryStream iss, System.IO.MemoryStream os, NALUnit nu, SeqParameterSet sps,
                                      PictureParameterSet pps, System.IO.MemoryStream nal, BitReader reader, SliceHeader sh)
            {
                BitWriter writer = new BitWriter(os);

                shr.readPart2(sh, nu, sps, pps, reader);

                tweak(sh);

                shw.write(sh, nu.type == NALUnitType.IDR_SLICE, nu.nal_ref_idc, writer);

                if (pps.entropy_coding_mode_flag)
                {
                    copyDataCABAC(iss, os, reader, writer);
                }
                else
                {
                    copyDataCAVLC(iss, os, reader, writer);
                }

                nal.limit(os.Position);

                Utility.escapeNAL(nal);

                os.position(nal.limit());

                return(sh);
            }
Example #3
0
        public static PictureParameterSet readPPS(System.IO.MemoryStream data)
        {
            System.IO.MemoryStream input = data.duplicate();
            Utility.unescapeNAL(input);
            PictureParameterSet pps = PictureParameterSet.read(input);

            return(pps);
        }
Example #4
0
 public static System.IO.MemoryStream writePPS(PictureParameterSet pps, int approxSize)
 {
     System.IO.MemoryStream output = new System.IO.MemoryStream(approxSize + 8);
     pps.write(output);
     output.flip();
     Utility.escapeNAL(output);
     return(output);
 }
Example #5
0
 public static SampleEntry createMOVSampleEntry(SeqParameterSet initSPS, PictureParameterSet initPPS)
 {
     System.IO.MemoryStream bb1 = new System.IO.MemoryStream(512), bb2 = new System.IO.MemoryStream(512);
     initSPS.write(bb1);
     initPPS.write(bb2);
     bb1.flip();
     bb2.flip();
     return(createMOVSampleEntry(new System.IO.MemoryStream[] { bb1 }.ToList(), new System.IO.MemoryStream[] { bb2 }.ToList()));
 }
Example #6
0
 public void addPps(List <MemoryStream> ppsList)
 {
     foreach (var byteBuffer in ppsList)
     {
         MemoryStream dup = byteBuffer.duplicate();
         Utility.unescapeNAL(dup);
         PictureParameterSet p = PictureParameterSet.read(dup);
         pps.Add(p.pic_parameter_set_id, p);
     }
 }
Example #7
0
        public CAVLC(SeqParameterSet sps, PictureParameterSet pps, int mbW, int mbH)
        {
            this.color       = sps.chroma_format_idc;
            this.chromaDCVLC = codeTableChromaDC();
            this.mbWidth     = sps.pic_width_in_mbs_minus1 + 1;

            this.mbMask = (1 << mbH) - 1;

            tokensLeft = new int[4];
            tokensTop  = new int[mbWidth << mbW];
        }
Example #8
0
            public SliceHeader run(System.IO.MemoryStream iss, System.IO.MemoryStream os, NALUnit nu)
            {
                System.IO.MemoryStream nal = os.duplicate();

                Utility.unescapeNAL(iss);

                BitReader   reader = new BitReader(iss);
                SliceHeader sh     = shr.readPart1(reader);

                PictureParameterSet pp = findPPS(pps, sh.pic_parameter_set_id);

                return(part2(iss, os, nu, findSPS(sps, pp.pic_parameter_set_id), pp, nal, reader, sh));
            }
Example #9
0
            public Frame decodeFrame(List <MemoryStream> nalUnits, int[][] buffer)
            {
                Frame result = null;

                foreach (var nalUnit in nalUnits)
                {
                    NALUnit marker = NALUnit.read(nalUnit);

                    Utility.unescapeNAL(nalUnit);

                    switch (marker.type.getValue())
                    {
                    case 1:
                    case 5:
                        if (result == null)
                        {
                            result = init(buffer, nalUnit, marker);
                        }
                        decoder.decode(nalUnit, marker);
                        break;

                    case 8:
                        SeqParameterSet _sps = SeqParameterSet.read(nalUnit);
                        vdecoder.sps.Add(_sps.seq_parameter_set_id, _sps);
                        break;

                    case 7:
                        PictureParameterSet _pps = PictureParameterSet.read(nalUnit);
                        vdecoder.pps.Add(_pps.pic_parameter_set_id, _pps);
                        break;

                    default:
                        break;
                    }
                }

                filter.deblockFrame(result);

                updateReferences(result);

                return(result);
            }
Example #10
0
            private Frame init(int[][] buffer, MemoryStream segment, NALUnit marker)
            {
                firstNu = marker;

                shr = new SliceHeaderReader();
                BitReader br = new BitReader(segment.duplicate());

                firstSliceHeader = shr.readPart1(br);
                activePps        = vdecoder.pps[firstSliceHeader.pic_parameter_set_id];
                activeSps        = vdecoder.sps[activePps.seq_parameter_set_id];
                shr.readPart2(firstSliceHeader, marker, activeSps, activePps, br);
                int picWidthInMbs  = activeSps.pic_width_in_mbs_minus1 + 1;
                int picHeightInMbs = Utility.getPicHeightInMbs(activeSps);

                int[][] nCoeff = (int[][])Array.CreateInstance(typeof(int), new int[] { picHeightInMbs << 2, picWidthInMbs << 2 }); //new int[picHeightInMbs << 2][picWidthInMbs << 2];

                mvs = (int[][][][])Array.CreateInstance(typeof(int), new int[] { 2, picHeightInMbs << 2, picWidthInMbs << 2, 3 });  //new int[2][picHeightInMbs << 2][picWidthInMbs << 2][3];
                MBType[]      mbTypes   = new MBType[picHeightInMbs * picWidthInMbs];
                bool[]        tr8x8Used = new bool[picHeightInMbs * picWidthInMbs];
                int[][]       mbQps     = (int[][])Array.CreateInstance(typeof(int), new int[] { 3, picHeightInMbs * picWidthInMbs });//new int[3][picHeightInMbs * picWidthInMbs];
                SliceHeader[] shs       = new SliceHeader[picHeightInMbs * picWidthInMbs];
                Frame[][][]   refsUsed  = new Frame[picHeightInMbs * picWidthInMbs][][];

                if (vdecoder.sRefs == null)
                {
                    vdecoder.sRefs = new Frame[1 << (firstSliceHeader.sps.log2_max_frame_num_minus4 + 4)];
                    vdecoder.lRefs = new Dictionary <int, Frame>();
                }

                Frame result = createFrame(activeSps, buffer, firstSliceHeader.frame_num, mvs, refsUsed,
                                           vdecoder.poc.calcPOC(firstSliceHeader, firstNu));

                decoder = new SliceDecoder(activeSps, activePps, nCoeff, mvs, mbTypes, mbQps, shs, tr8x8Used, refsUsed,
                                           result, vdecoder.sRefs, vdecoder.lRefs);
                decoder.setDebug(vdecoder.debug);

                filter = new DeblockingFilter(picWidthInMbs, activeSps.bit_depth_chroma_minus8 + 8, nCoeff, mvs, mbTypes,
                                              mbQps, shs, tr8x8Used, refsUsed);

                return(result);
            }
Example #11
0
        private static void readPredWeightTable(SeqParameterSet sps, PictureParameterSet pps, SliceHeader sh, BitReader inb)
        {
            sh.pred_weight_table = new PredictionWeightTable();
            int[] numRefsminus1 = sh.num_ref_idx_active_override_flag ? sh.num_ref_idx_active_minus1
                    : pps.num_ref_idx_active_minus1;
            int[] nr = new int[] { numRefsminus1[0] + 1, numRefsminus1[1] + 1 };

            sh.pred_weight_table.luma_log2_weight_denom = CAVLCReader.readUE(inb, "SH: luma_log2_weight_denom");
            if (sps.chroma_format_idc != ColorSpace.MONO)
            {
                sh.pred_weight_table.chroma_log2_weight_denom = CAVLCReader.readUE(inb, "SH: chroma_log2_weight_denom");
            }
            int defaultLW = 1 << sh.pred_weight_table.luma_log2_weight_denom;
            int defaultCW = 1 << sh.pred_weight_table.chroma_log2_weight_denom;

            for (int list = 0; list < 2; list++)
            {
                sh.pred_weight_table.luma_weight[list]   = new int[nr[list]];
                sh.pred_weight_table.luma_offset[list]   = new int[nr[list]];
                sh.pred_weight_table.chroma_weight[list] = (int[][])System.Array.CreateInstance(typeof(int), new int[] { 2, nr[list] });
                sh.pred_weight_table.chroma_offset[list] = (int[][])System.Array.CreateInstance(typeof(int), new int[] { 2, nr[list] });
                for (int i = 0; i < nr[list]; i++)
                {
                    sh.pred_weight_table.luma_weight[list][i]      = defaultLW;
                    sh.pred_weight_table.luma_offset[list][i]      = 0;
                    sh.pred_weight_table.chroma_weight[list][0][i] = defaultCW;
                    sh.pred_weight_table.chroma_offset[list][0][i] = 0;
                    sh.pred_weight_table.chroma_weight[list][1][i] = defaultCW;
                    sh.pred_weight_table.chroma_offset[list][1][i] = 0;
                }
            }

            readWeightOffset(sps, pps, sh, inb, nr, 0);
            if (sh.slice_type == SliceType.B)
            {
                readWeightOffset(sps, pps, sh, inb, nr, 1);
            }
        }
Example #12
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");
             }
         }
     }
 }
Example #13
0
        public void write(SliceHeader sliceHeader, bool idrSlice, int nalRefIdc, BitWriter writer)
        {
            SeqParameterSet     sps = sliceHeader.sps;
            PictureParameterSet pps = sliceHeader.pps;

            CAVLCWriter.writeUE(writer, sliceHeader.first_mb_in_slice, "SH: first_mb_in_slice");
            CAVLCWriter.writeUE(writer, (int)sliceHeader.slice_type + (sliceHeader.slice_type_restr ? 5 : 0), "SH: slice_type");
            CAVLCWriter.writeUE(writer, sliceHeader.pic_parameter_set_id, "SH: pic_parameter_set_id");
            CAVLCWriter.writeU(writer, sliceHeader.frame_num, sps.log2_max_frame_num_minus4 + 4, "SH: frame_num");
            if (!sps.frame_mbs_only_flag)
            {
                CAVLCWriter.writeBool(writer, sliceHeader.field_pic_flag, "SH: field_pic_flag");
                if (sliceHeader.field_pic_flag)
                {
                    CAVLCWriter.writeBool(writer, sliceHeader.bottom_field_flag, "SH: bottom_field_flag");
                }
            }
            if (idrSlice)
            {
                CAVLCWriter.writeUE(writer, sliceHeader.idr_pic_id, "SH: idr_pic_id");
            }
            if (sps.pic_order_cnt_type == 0)
            {
                CAVLCWriter.writeU(writer, sliceHeader.pic_order_cnt_lsb, sps.log2_max_pic_order_cnt_lsb_minus4 + 4);
                if (pps.pic_order_present_flag && !sps.field_pic_flag)
                {
                    CAVLCWriter.writeSE(writer, sliceHeader.delta_pic_order_cnt_bottom, "SH: delta_pic_order_cnt_bottom");
                }
            }
            if (sps.pic_order_cnt_type == 1 && !sps.delta_pic_order_always_zero_flag)
            {
                CAVLCWriter.writeSE(writer, sliceHeader.delta_pic_order_cnt[0], "SH: delta_pic_order_cnt");
                if (pps.pic_order_present_flag && !sps.field_pic_flag)
                {
                    CAVLCWriter.writeSE(writer, sliceHeader.delta_pic_order_cnt[1], "SH: delta_pic_order_cnt");
                }
            }
            if (pps.redundant_pic_cnt_present_flag)
            {
                CAVLCWriter.writeUE(writer, sliceHeader.redundant_pic_cnt, "SH: redundant_pic_cnt");
            }
            if (sliceHeader.slice_type == SliceType.B)
            {
                CAVLCWriter.writeBool(writer, sliceHeader.direct_spatial_mv_pred_flag, "SH: direct_spatial_mv_pred_flag");
            }
            if (sliceHeader.slice_type == SliceType.P || sliceHeader.slice_type == SliceType.SP ||
                sliceHeader.slice_type == SliceType.B)
            {
                CAVLCWriter.writeBool(writer, sliceHeader.num_ref_idx_active_override_flag, "SH: num_ref_idx_active_override_flag");
                if (sliceHeader.num_ref_idx_active_override_flag)
                {
                    CAVLCWriter.writeUE(writer, sliceHeader.num_ref_idx_active_minus1[0], "SH: num_ref_idx_l0_active_minus1");
                    if (sliceHeader.slice_type == SliceType.B)
                    {
                        CAVLCWriter.writeUE(writer, sliceHeader.num_ref_idx_active_minus1[1], "SH: num_ref_idx_l1_active_minus1");
                    }
                }
            }
            writeRefPicListReordering(sliceHeader, writer);
            if ((pps.weighted_pred_flag && (sliceHeader.slice_type == SliceType.P || sliceHeader.slice_type == SliceType.SP)) ||
                (pps.weighted_bipred_idc == 1 && sliceHeader.slice_type == SliceType.B))
            {
                writePredWeightTable(sliceHeader, writer);
            }
            if (nalRefIdc != 0)
            {
                writeDecRefPicMarking(sliceHeader, idrSlice, writer);
            }
            if (pps.entropy_coding_mode_flag && sliceHeader.slice_type.isInter())
            {
                CAVLCWriter.writeUE(writer, sliceHeader.cabac_init_idc, "SH: cabac_init_idc");
            }
            CAVLCWriter.writeSE(writer, sliceHeader.slice_qp_delta, "SH: slice_qp_delta");
            if (sliceHeader.slice_type == SliceType.SP || sliceHeader.slice_type == SliceType.SI)
            {
                if (sliceHeader.slice_type == SliceType.SP)
                {
                    CAVLCWriter.writeBool(writer, sliceHeader.sp_for_switch_flag, "SH: sp_for_switch_flag");
                }
                CAVLCWriter.writeSE(writer, sliceHeader.slice_qs_delta, "SH: slice_qs_delta");
            }
            if (pps.deblocking_filter_control_present_flag)
            {
                CAVLCWriter.writeUE(writer, sliceHeader.disable_deblocking_filter_idc, "SH: disable_deblocking_filter_idc");
                if (sliceHeader.disable_deblocking_filter_idc != 1)
                {
                    CAVLCWriter.writeSE(writer, sliceHeader.slice_alpha_c0_offset_div2, "SH: slice_alpha_c0_offset_div2");
                    CAVLCWriter.writeSE(writer, sliceHeader.slice_beta_offset_div2, "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 = (sps.pic_height_in_map_units_minus1 + 1) * (sps.pic_width_in_mbs_minus1 + 1)
                          / (pps.slice_group_change_rate_minus1 + 1);
                if (((sps.pic_height_in_map_units_minus1 + 1) * (sps.pic_width_in_mbs_minus1 + 1))
                    % (pps.slice_group_change_rate_minus1 + 1) > 0)
                {
                    len += 1;
                }

                len = CeilLog2(len + 1);
                CAVLCWriter.writeU(writer, sliceHeader.slice_group_change_cycle, len);
            }
        }
Example #14
0
 private bool validPps(PictureParameterSet pps)
 {
     return(pps.pic_init_qp_minus26 <= 26 && pps.seq_parameter_set_id <= 2 && pps.pic_parameter_set_id <= 2);
 }
Example #15
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 #16
0
            public SliceHeader run(System.IO.MemoryStream iss, System.IO.MemoryStream os, NALUnit nu, SeqParameterSet sps, PictureParameterSet pps)
            {
                System.IO.MemoryStream nal = os.duplicate();

                Utility.unescapeNAL(iss);

                BitReader   reader = new BitReader(iss);
                SliceHeader sh     = shr.readPart1(reader);

                return(part2(iss, os, nu, sps, pps, nal, reader, sh));
            }
Example #17
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);
        }
Example #18
0
        //@Override
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            //if (getClass() != obj.getClass())
            //return false;
            PictureParameterSet other = (PictureParameterSet)obj;

            if (!(bottom_right == other.bottom_right))
            {
                return(false);
            }
            if (chroma_qp_index_offset != other.chroma_qp_index_offset)
            {
                return(false);
            }
            if (constrained_intra_pred_flag != other.constrained_intra_pred_flag)
            {
                return(false);
            }
            if (deblocking_filter_control_present_flag != other.deblocking_filter_control_present_flag)
            {
                return(false);
            }
            if (entropy_coding_mode_flag != other.entropy_coding_mode_flag)
            {
                return(false);
            }
            if (extended == null)
            {
                if (other.extended != null)
                {
                    return(false);
                }
            }
            else if (!extended.Equals(other.extended))
            {
                return(false);
            }
            if (num_ref_idx_active_minus1[0] != other.num_ref_idx_active_minus1[0])
            {
                return(false);
            }
            if (num_ref_idx_active_minus1[1] != other.num_ref_idx_active_minus1[1])
            {
                return(false);
            }
            if (num_slice_groups_minus1 != other.num_slice_groups_minus1)
            {
                return(false);
            }
            if (pic_init_qp_minus26 != other.pic_init_qp_minus26)
            {
                return(false);
            }
            if (pic_init_qs_minus26 != other.pic_init_qs_minus26)
            {
                return(false);
            }
            if (pic_order_present_flag != other.pic_order_present_flag)
            {
                return(false);
            }
            if (pic_parameter_set_id != other.pic_parameter_set_id)
            {
                return(false);
            }
            if (redundant_pic_cnt_present_flag != other.redundant_pic_cnt_present_flag)
            {
                return(false);
            }
            if (!(run_length_minus1 == other.run_length_minus1))
            {
                return(false);
            }
            if (seq_parameter_set_id != other.seq_parameter_set_id)
            {
                return(false);
            }
            if (slice_group_change_direction_flag != other.slice_group_change_direction_flag)
            {
                return(false);
            }
            if (slice_group_change_rate_minus1 != other.slice_group_change_rate_minus1)
            {
                return(false);
            }
            if (!(slice_group_id == other.slice_group_id))
            {
                return(false);
            }
            if (slice_group_map_type != other.slice_group_map_type)
            {
                return(false);
            }
            if (!(top_left == other.top_left))
            {
                return(false);
            }
            if (weighted_bipred_idc != other.weighted_bipred_idc)
            {
                return(false);
            }
            if (weighted_pred_flag != other.weighted_pred_flag)
            {
                return(false);
            }
            return(true);
        }
Example #19
0
        public void mergePrediction(int refIdxL0, int refIdxL1, nVideo.Codecs.H264.H264Const.PartPred predType, int comp, int[] pred0, int[] pred1,
                                    int off, int stride, int blkW, int blkH, int[] outs, Frame[][] refs, Frame thisFrame)
        {
            PictureParameterSet pps = sh.pps;

            if (sh.slice_type == SliceType.P)
            {
                if (pps.weighted_pred_flag && sh.pred_weight_table != null)
                {
                    PredictionWeightTable w = sh.pred_weight_table;
                    weight(pred0, stride, off, blkW, blkH, comp == 0 ? w.luma_log2_weight_denom
                            : w.chroma_log2_weight_denom, comp == 0 ? w.luma_weight[0][refIdxL0]
                            : w.chroma_weight[0][comp - 1][refIdxL0], comp == 0 ? w.luma_offset[0][refIdxL0]
                            : w.chroma_offset[0][comp - 1][refIdxL0], outs);
                }
                else
                {
                    copyPrediction(pred0, stride, off, blkW, blkH, outs);
                }
            }
            else
            {
                if (!pps.weighted_pred_flag || sh.pps.weighted_bipred_idc == 0 ||
                    (sh.pps.weighted_bipred_idc == 2 && predType != nVideo.Codecs.H264.H264Const.PartPred.Bi))
                {
                    mergeAvg(pred0, pred1, stride, predType, off, blkW, blkH, outs);
                }
                else if (sh.pps.weighted_bipred_idc == 1)
                {
                    PredictionWeightTable w = sh.pred_weight_table;
                    int w0 = refIdxL0 == -1 ? 0 : (comp == 0 ? w.luma_weight[0][refIdxL0]
                            : w.chroma_weight[0][comp - 1][refIdxL0]);
                    int w1 = refIdxL1 == -1 ? 0 : (comp == 0 ? w.luma_weight[1][refIdxL1]
                            : w.chroma_weight[1][comp - 1][refIdxL1]);
                    int o0 = refIdxL0 == -1 ? 0 : (comp == 0 ? w.luma_offset[0][refIdxL0]
                            : w.chroma_offset[0][comp - 1][refIdxL0]);
                    int o1 = refIdxL1 == -1 ? 0 : (comp == 0 ? w.luma_offset[1][refIdxL1]
                            : w.chroma_offset[1][comp - 1][refIdxL1]);
                    mergeWeight(pred0, pred1, stride, predType, off, blkW, blkH, comp == 0 ? w.luma_log2_weight_denom
                            : w.chroma_log2_weight_denom, w0, w1, o0, o1, outs);
                }
                else
                {
                    int tb = CABAC.clip(thisFrame.getPOC() - refs[0][refIdxL0].getPOC(), -128, 127);
                    int td = CABAC.clip(refs[1][refIdxL1].getPOC() - refs[0][refIdxL0].getPOC(), -128, 127);
                    int w0 = 32, w1 = 32;
                    if (td != 0 && refs[0][refIdxL0].isShortTerm() && refs[1][refIdxL1].isShortTerm())
                    {
                        int tx  = (16384 + Math.Abs(td / 2)) / td;
                        int dsf = CABAC.clip((tb * tx + 32) >> 6, -1024, 1023) >> 2;

                        if (dsf >= -64 && dsf <= 128)
                        {
                            w1 = dsf;
                            w0 = 64 - dsf;
                        }
                    }

                    mergeWeight(pred0, pred1, stride, predType, off, blkW, blkH, 5, w0, w1, 0, 0, outs);
                }
            }
        }