Пример #1
0
 public MacroBlockLayer(SequenceParameterSet sps, PictureParameterSet pps, SliceHeader header, SliceData data)
 {
     _sliceType = header.SliceType;
       _sps = sps;
       _pps = pps;
       _header = header;
       _data = data;
       _mbTypeParser = _data.MBTypeParser;
       _cbp = _data.CBP;
       _mbQPD = _data.MBQPD;
 }
Пример #2
0
 public MacroBlockLayer(SequenceParameterSet sps, PictureParameterSet pps, SliceHeader header, SliceData data)
 {
     _sliceType    = header.SliceType;
     _sps          = sps;
     _pps          = pps;
     _header       = header;
     _data         = data;
     _mbTypeParser = _data.MBTypeParser;
     _cbp          = _data.CBP;
     _mbQPD        = _data.MBQPD;
 }
Пример #3
0
        public void Read(BitReader bitReader)
        {
            FirstMBInSlice    = bitReader.DecodeUnsignedExpGolomb();
            SliceType         = ReadSliceType(bitReader);
            PICParameterSetID = bitReader.DecodeUnsignedExpGolomb();
            FrameNum          = bitReader.GetUIntFromNBits(_frameNumBits);

            if (!_sps.FrameMBSOnly)
            {
                FieldPicFlag = bitReader.GetNextBit();
                if (FieldPicFlag)
                {
                    BottomFieldFlag = bitReader.GetNextBit();
                }
            }

            if (_nalu.NALUType == NALUnitType.IDRSlice)
            {
                IDRPictureID    = bitReader.DecodeUnsignedExpGolomb();
                PrevRefFrameNum = 0;
            }

            if (_sps.gPicOrderCntType == 0)
            {
                PictureOrderCountLSB = bitReader.GetUIntFromNBits((ushort)(_sps.gMaxPicOrderCntLsbMinus4 + 4u));
                if (_pps.PICOrderPresentFlag && !FieldPicFlag)
                {
                    DeltaPictureOrderCountBottom = bitReader.DecodeSignedExpGolomb();
                }
            }

            if ((_sps.gPicOrderCntType == 1) && !_sps.DeltaPicOrderAlwaysZero)
            {
                DeltaPictureOrderCount    = new int[2];
                DeltaPictureOrderCount[0] = bitReader.DecodeSignedExpGolomb();
                if (_pps.PICOrderPresentFlag && !FieldPicFlag)
                {
                    DeltaPictureOrderCount[1] = bitReader.DecodeSignedExpGolomb();
                }
            }

            if (_pps.RedundantPICCountPresentFlag)
            {
                RedundantPictureCount = bitReader.DecodeUnsignedExpGolomb();
            }

            if (SliceType == SliceTypes.B)
            {
                DirectSpatialMVPredFlag = bitReader.GetNextBit();
            }

            if ((SliceType == SliceTypes.P) || (SliceType == SliceTypes.SP) || (SliceType == SliceTypes.B))
            {
                NumRefIdxActiveOverrideFlag = bitReader.GetNextBit();
                if (NumRefIdxActiveOverrideFlag)
                {
                    NumRefIdx10ActiveMinus1 = bitReader.DecodeUnsignedExpGolomb();
                    if (SliceType == SliceTypes.B)
                    {
                        NumRefIdx11ActiveMinus1 = bitReader.DecodeUnsignedExpGolomb();
                    }
                }
            }

            ReferencePictureListReordering(bitReader);

            if ((_pps.WeightedPredFlag && ((SliceType == SliceTypes.P) || (SliceType == SliceTypes.SP))) ||
                ((_pps.WeightedBiPredIDC == 1) && (SliceType == SliceTypes.B)))
            {
                PredictionWeightTable(bitReader);
            }

            if (_nalu.NALRefIDC != 0)
            {
                DecodedReferencePictureMarking(bitReader);
            }

            if (_pps.EntropyCodingModeFlag && (SliceType != SliceTypes.I) && (SliceType != SliceTypes.SI))
            {
                uint initIdc = bitReader.DecodeUnsignedExpGolomb();
                if (initIdc < 4)
                {
                    CABACInitIDC = (byte)initIdc;
                }
                else
                {
                    throw new Exception("SliceHeader: bad CABACInitIDC");
                }
            }

            SliceQPDelta = bitReader.DecodeSignedExpGolomb();
            SliceQPy     = 26 + _pps.PICInitQPMinus26 + SliceQPDelta;

            if ((SliceType == SliceTypes.SP) || (SliceType == SliceTypes.SI))
            {
                if (SliceType == SliceTypes.SP)
                {
                    SP4SwitchFlag = bitReader.GetNextBit();
                }
                SliceQSDelta = bitReader.DecodeSignedExpGolomb();
                SliceQSy     = 26 + _pps.PICInitQSMinus26 + SliceQSDelta;
            }

            if (_pps.DeblockingFilterControlPresentFlag)
            {
                DisableDeblockingFilterIDC = bitReader.DecodeUnsignedExpGolomb();
                if (DisableDeblockingFilterIDC != 1)
                {
                    SliceAlphaC0OffsetDiv2 = bitReader.DecodeSignedExpGolomb();
                    SliceBetaOffsetDiv2    = bitReader.DecodeSignedExpGolomb();
                }
            }

            if ((_pps.NumSliceGroupsMinus1 > 0) && (_pps.SliceGroupMapType >= 3) && (_pps.SliceGroupMapType <= 5))
            {
                SliceGroupChangeCycle = bitReader.GetUIntFromNBits(BitReader.CalcBitsNeededToRepresent(_pps.NumSliceGroupsMinus1 + 1));
            }

            // once the header is read, we can derive the MacroBlock to SliceGroup mapping (Section 8.2.2 of H264 Spec)
            if (_pps.NumSliceGroupsMinus1 > 0)
            {
                MbToSliceGroupMap = DeriveMB2SliceGroupMap();
            }
        }
Пример #4
0
        public void Read(BitReader bitReader)
        {
            FirstMBInSlice = bitReader.DecodeUnsignedExpGolomb();
              SliceType = ReadSliceType(bitReader);
              PICParameterSetID = bitReader.DecodeUnsignedExpGolomb();
              FrameNum = bitReader.GetUIntFromNBits(_frameNumBits);

              if (!_sps.FrameMBSOnly)
              {
            FieldPicFlag = bitReader.GetNextBit();
            if (FieldPicFlag)
              BottomFieldFlag = bitReader.GetNextBit();
              }

              if (_nalu.NALUType == NALUnitType.IDRSlice)
              {
            IDRPictureID = bitReader.DecodeUnsignedExpGolomb();
            PrevRefFrameNum = 0;
              }

              if (_sps.gPicOrderCntType == 0)
              {
            PictureOrderCountLSB = bitReader.GetUIntFromNBits((ushort)(_sps.gMaxPicOrderCntLsbMinus4 + 4u));
            if (_pps.PICOrderPresentFlag && !FieldPicFlag)
              DeltaPictureOrderCountBottom = bitReader.DecodeSignedExpGolomb();
              }

              if ((_sps.gPicOrderCntType == 1) && !_sps.DeltaPicOrderAlwaysZero)
              {
            DeltaPictureOrderCount = new int[2];
            DeltaPictureOrderCount[0] = bitReader.DecodeSignedExpGolomb();
            if (_pps.PICOrderPresentFlag && !FieldPicFlag)
              DeltaPictureOrderCount[1] = bitReader.DecodeSignedExpGolomb();
              }

              if (_pps.RedundantPICCountPresentFlag)
            RedundantPictureCount = bitReader.DecodeUnsignedExpGolomb();

              if (SliceType == SliceTypes.B)
            DirectSpatialMVPredFlag = bitReader.GetNextBit();

              if ((SliceType == SliceTypes.P) || (SliceType == SliceTypes.SP) || (SliceType == SliceTypes.B))
              {
            NumRefIdxActiveOverrideFlag = bitReader.GetNextBit();
            if (NumRefIdxActiveOverrideFlag)
            {
              NumRefIdx10ActiveMinus1 = bitReader.DecodeUnsignedExpGolomb();
              if (SliceType == SliceTypes.B)
            NumRefIdx11ActiveMinus1 = bitReader.DecodeUnsignedExpGolomb();
            }
              }

              ReferencePictureListReordering(bitReader);

              if ((_pps.WeightedPredFlag && ((SliceType == SliceTypes.P) || (SliceType == SliceTypes.SP))) ||
            ((_pps.WeightedBiPredIDC == 1) && (SliceType == SliceTypes.B)))
              {
            PredictionWeightTable(bitReader);
              }

              if (_nalu.NALRefIDC != 0)
            DecodedReferencePictureMarking(bitReader);

              if (_pps.EntropyCodingModeFlag && (SliceType != SliceTypes.I) && (SliceType != SliceTypes.SI))
              {
            uint initIdc = bitReader.DecodeUnsignedExpGolomb();
            if (initIdc < 4)
              CABACInitIDC = (byte)initIdc;
            else
              throw new Exception("SliceHeader: bad CABACInitIDC");
              }

              SliceQPDelta = bitReader.DecodeSignedExpGolomb();
              SliceQPy = 26 + _pps.PICInitQPMinus26 + SliceQPDelta;

              if ((SliceType == SliceTypes.SP) || (SliceType == SliceTypes.SI))
              {
            if (SliceType == SliceTypes.SP)
              SP4SwitchFlag = bitReader.GetNextBit();
            SliceQSDelta = bitReader.DecodeSignedExpGolomb();
            SliceQSy = 26 + _pps.PICInitQSMinus26 + SliceQSDelta;
              }

              if (_pps.DeblockingFilterControlPresentFlag)
              {
            DisableDeblockingFilterIDC = bitReader.DecodeUnsignedExpGolomb();
            if (DisableDeblockingFilterIDC != 1)
            {
              SliceAlphaC0OffsetDiv2 = bitReader.DecodeSignedExpGolomb();
              SliceBetaOffsetDiv2 = bitReader.DecodeSignedExpGolomb();
            }
              }

              if ((_pps.NumSliceGroupsMinus1 > 0) && (_pps.SliceGroupMapType >= 3) && (_pps.SliceGroupMapType <= 5))
            SliceGroupChangeCycle = bitReader.GetUIntFromNBits(BitReader.CalcBitsNeededToRepresent(_pps.NumSliceGroupsMinus1 + 1));

              // once the header is read, we can derive the MacroBlock to SliceGroup mapping (Section 8.2.2 of H264 Spec)
              if (_pps.NumSliceGroupsMinus1 > 0)
            MbToSliceGroupMap = DeriveMB2SliceGroupMap();
        }