Ejemplo n.º 1
0
 public void Read(BitReader bitReader)
 {
     if (_bEntropyCodingModeFlag)
     ResidualBlock = ResidualBlockCABAC;
       else
     ResidualBlock = ResidualBlockCAVLC;
 }
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader); // read-in the NALU

              Header.Read(bitReader);
              Data.Read(bitReader);
        }
Ejemplo n.º 3
0
 public void Read(BitReader bitReader)
 {
     if ((_mbLayer.MbPartPredMode(_mbType, 0) == MacroBlockPartitionMode.Intra_4x4) ||
     (_mbLayer.MbPartPredMode(_mbType, 0) == MacroBlockPartitionMode.Intra_16x16))
       {
     if (_mbLayer.MbPartPredMode(_mbType, 0) == MacroBlockPartitionMode.Intra_4x4)
     {
       for (int luma4x4ids = 0; luma4x4ids < 16; luma4x4ids++)
       {
     PrevIntra4x4PredModeFlag[luma4x4ids] = bitReader.GetNextBit();
     if (!PrevIntra4x4PredModeFlag[luma4x4ids])
     {
       RemIntra4x4PredMode[luma4x4ids] = bitReader.GetByteFromNBits(3);
     }
       }
     }
     IntraChromaPredMode = (byte)bitReader.DecodeUnsignedExpGolomb();
       }
       else if (_mbLayer.MbPartPredMode(_mbType, 0) != MacroBlockPartitionMode.Direct)
       {
     int numPart = (int)_mbLayer.NumMbPart(_mbType);
     for (int mbPartIdx = 0; mbPartIdx < numPart; mbPartIdx++)
     {
     }
     for (int mbPartIdx = 0; mbPartIdx < numPart; mbPartIdx++)
     {
     }
     for (int mbPartIdx = 0; mbPartIdx < numPart; mbPartIdx++)
     {
     }
     for (int mbPartIdx = 0; mbPartIdx < numPart; mbPartIdx++)
     {
     }
       }
 }
Ejemplo n.º 4
0
 public override void Read(BitReader bitReader)
 {
     base.Read(bitReader);
       PrimaryPicType = (PictureType)bitReader.GetByteFromNBits(3);
       bitReader.DiscardTrailingBits(); // complete the byte
       while (MoreRBSPData(bitReader))
     bitReader.ReadByte();
 }
Ejemplo n.º 5
0
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader);

              // FIXME: SliceData above is not complete, so for now let's just skip the rest of data
              Nalu.SkipToEndOfNALU(bitReader);

              Nalu.CheckSize(bitReader);
        }
Ejemplo n.º 6
0
 public int GetMBQPDelta(BitReader bitReader)
 {
     if (_pps.EntropyCodingModeFlag)
       {
     return 0;  // FIXME: incomplete
       }
       else
       {
     return _bitReader.DecodeSignedExpGolomb();
       }
 }
Ejemplo n.º 7
0
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader); // read-in the NALU
              Header.Read(bitReader);
              SliceID = bitReader.DecodeUnsignedExpGolomb(); // this is not in base class
              Data.Read(bitReader);

              // FIXME: SliceData above is not complete, so for now let's just skip the rest of data
              Nalu.SkipToEndOfNALU(bitReader);

              Nalu.CheckSize(bitReader);
        }
Ejemplo n.º 8
0
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader);

              Profile = bitReader.ReadByte();
              Constraints = bitReader.ReadByte();
              Level = bitReader.ReadByte();
              gSPSID = bitReader.DecodeUnsignedExpGolomb();
              gLog2MaxFrameNumMinus4 = bitReader.DecodeUnsignedExpGolomb();
              gPicOrderCntType = bitReader.DecodeUnsignedExpGolomb();
              if (gPicOrderCntType == 0)
            gMaxPicOrderCntLsbMinus4 = bitReader.DecodeUnsignedExpGolomb();
              else if (gPicOrderCntType == 1)
              {
            DeltaPicOrderAlwaysZero = bitReader.GetNextBit();
            gOffsetForNonRefPic = bitReader.DecodeSignedExpGolomb();
            gOffsetForTopToBottomField = bitReader.DecodeSignedExpGolomb();
            gNumRefFramesInPicOrderCntCycle = bitReader.DecodeUnsignedExpGolomb();
            gOffsetsForRefFrames = new int[gNumRefFramesInPicOrderCntCycle];
            for (int i = 0; i < gNumRefFramesInPicOrderCntCycle; i++)
              gOffsetsForRefFrames[i] = bitReader.DecodeSignedExpGolomb();
              }
              gNumRefFrames = bitReader.DecodeUnsignedExpGolomb();
              GapsInFrameNumValueAllowed = bitReader.GetNextBit();
              gPicWidthInMBsMinus1 = bitReader.DecodeUnsignedExpGolomb();
              Width = gPicWidthInMBsMinus1 + 1;
              gPicHeightInMBsMinus1 = bitReader.DecodeUnsignedExpGolomb();
              Height = gPicHeightInMBsMinus1 + 1;
              PicSizeInMBs = Height * Width;
              FrameMBSOnly = bitReader.GetNextBit();
              uint interlaceFactor = (FrameMBSOnly) ? 1U : 2U;
              Width *= 16;
              Height *= (16 * interlaceFactor);
              if (!FrameMBSOnly)
            MBAdaptiveFrameField = bitReader.GetNextBit();
              Direct8x8Inference = bitReader.GetNextBit();
              FrameCropping = bitReader.GetNextBit();
              if (FrameCropping)
              {
            FrameCropLeftOffset = bitReader.DecodeUnsignedExpGolomb();
            FrameCropRightOffset = bitReader.DecodeUnsignedExpGolomb();
            FrameCropTopOffset = bitReader.DecodeUnsignedExpGolomb();
            FrameCropBottomOffset = bitReader.DecodeUnsignedExpGolomb();
              }
              VUIParametersPresent = bitReader.GetNextBit();
              if (VUIParametersPresent)
              {
            vuiParams = new VUIParams();
            vuiParams.Read(bitReader);
              }
        }
Ejemplo n.º 9
0
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader); // read-in the NALU

              // NOTE: this coded slice has no Header (it should remain null)
              SliceID = bitReader.DecodeUnsignedExpGolomb();
              if (_pps.RedundantPICCountPresentFlag)
            RedundantPictureCount = bitReader.DecodeUnsignedExpGolomb();
              Data.Read(bitReader);

              // FIXME: SliceData above is not complete, so for now let's just skip the rest of data
              Nalu.SkipToEndOfNALU(bitReader);

              Nalu.CheckSize(bitReader);
        }
Ejemplo n.º 10
0
 public uint GetMacroBlockType(BitReader bitReader)
 {
     MainInit(bitReader);
       if (_pps.EntropyCodingModeFlag)
     switch (_header.SliceType)
     {
       case SliceTypes.SI:
     maxBinIdxCtx_p = 0; // prefix
     ctxIdxOffset_p = 0; // prefix
     maxBinIdxCtx_s = 6; // suffix
     ctxIdxOffset_s = 3; // suffix
     return GetSIMacroBlockType();
       case SliceTypes.I:
     maxBinIdxCtx_p = 0; // prefix
     ctxIdxOffset_p = 0; // prefix
     maxBinIdxCtx_s = 6; // suffix only
     ctxIdxOffset_s = 3; // suffix only
     return GetIMacroBlockType();
       case SliceTypes.P:
       case SliceTypes.SP:
     maxBinIdxCtx_p = 2; // prefix
     ctxIdxOffset_p = 14; // prefix
     maxBinIdxCtx_s = 5; // suffix
     ctxIdxOffset_s = 17; // suffix
     return GetPnSPMacroBlockType();
       case SliceTypes.B:
     maxBinIdxCtx_p = 3; // prefix
     ctxIdxOffset_p = 27; // prefix
     maxBinIdxCtx_s = 5; // suffix
     ctxIdxOffset_s = 32; // suffix
     return GetBMacroBlockType();
       default:
     throw new Exception("MacroBlockLayer: bad slice type"); ;
     }
       else
     return _bitReader.DecodeUnsignedExpGolomb();
 }
 public bool MoreRBSPData(BitReader bitReader)
 {
     long end = _positionInStream + NumBytes - 1;
       if (bitReader.Position < end)
     return true;
       return false;
 }
Ejemplo n.º 12
0
        public void Read(BitReader bitReader)
        {
            AspectRatioInfoPresent = bitReader.GetNextBit();
              if (AspectRatioInfoPresent)
              {
            AspectRatio = bitReader.GetByteFromNBits(8);
            if (AspectRatio == Extended_SAR)
            {
              SARWidth = (ushort)bitReader.GetUIntFromNBits(16);
              SARHeight = (ushort)bitReader.GetUIntFromNBits(16);
            }
              }
              OverscanInfoPresent = bitReader.GetNextBit();
              if (OverscanInfoPresent)
            OverscanAppropriate = bitReader.GetNextBit();
              VideoSignalTypePresent = bitReader.GetNextBit();
              if (VideoSignalTypePresent)
              {
            VideoFormat = bitReader.GetByteFromNBits(3);
            VideoFullRange = bitReader.GetNextBit();
            ColourDescriptionPresent = bitReader.GetNextBit();
            if (ColourDescriptionPresent)
            {
              ColourPrimaries = bitReader.GetByteFromNBits(8);
              TransferCharacteristics = bitReader.GetByteFromNBits(8);
              MatrixCoefficients = bitReader.GetByteFromNBits(8);
            }
              }
              ChromaLocInfoPresent = bitReader.GetNextBit();
              if (ChromaLocInfoPresent)
              {
            ChromaSampleLocTypeTopField = bitReader.DecodeUnsignedExpGolomb();
            ChromaSampleLocTypeBottomField = bitReader.DecodeUnsignedExpGolomb();
              }
              TimingInfoPresent = bitReader.GetNextBit();
              if (TimingInfoPresent)
              {
            NumUnitsInTick = bitReader.GetUIntFromNBits(32);
            TimeScale = bitReader.GetUIntFromNBits(32);
            FixedFrameRate = bitReader.GetNextBit();
              }
              NALHRDParametersPresent = bitReader.GetNextBit();
              if (NALHRDParametersPresent)
              {
            NalHRDParams = new HRDParams();
            NalHRDParams.Read(bitReader);
              }
              VclHRDParametersPresent = bitReader.GetNextBit();
              if (VclHRDParametersPresent)
              {
            VclHRDParams = new HRDParams();
            VclHRDParams.Read(bitReader);
              }
              if (NALHRDParametersPresent || VclHRDParametersPresent)
            LowDelayHRDFlag = bitReader.GetNextBit();
              PicStructPresent = bitReader.GetNextBit();
              BitstreamRestriction = bitReader.GetNextBit();
              if (BitstreamRestriction)
              {
            MotionVectorsOverPicBoundaries = bitReader.GetNextBit();
            MaxBytesPerPicDenom = bitReader.DecodeUnsignedExpGolomb();
            MaxBitsPerMBDenom = bitReader.DecodeUnsignedExpGolomb();
            Log2MaxMVLengthHorizontal = bitReader.DecodeUnsignedExpGolomb();
            Log2MaxMVLengthVertical = bitReader.DecodeUnsignedExpGolomb();
            NumReorderFrames = bitReader.DecodeUnsignedExpGolomb();
            MaxDecFrameBuffering = bitReader.DecodeUnsignedExpGolomb();
              }

              if ((AspectRatio > 0) && (AspectRatio < 17))
              {
            AspectRatioX = vui_aspect_x[AspectRatio];
            AspectRatioY = vui_aspect_y[AspectRatio];
              }
              //      gWidth = (uint)(gWidth * ((double)vui_aspect_x[vuiParams.AspectRatio]) / ((double)vui_aspect_y[vuiParams.AspectRatio]));
        }
Ejemplo n.º 13
0
 public void Read(BitReader bitReader)
 {
     _bitReader = bitReader;
       MBType = _mbTypeParser.GetMacroBlockType(_bitReader);
       if (MBType > 48)
     throw new Exception("MacroBlockLayer: bad macro block type");
       I_MacroBlockType mbt = (I_MacroBlockType)MBType;
       if (mbt == I_MacroBlockType.I_PCM)
       {
     while (!bitReader.ByteAligned)
     {
       if (bitReader.GetNextBit())
     throw new Exception("MacroBlockLayer: bad alignment");
     }
     bitReader.Position += (long)(256 * ChromaFormatFactor); // skip data (don't need it)
       }
       else
       {
     byte mbtype = (byte)MBType;
     if ((MbPartPredMode(mbtype, 0) != MacroBlockPartitionMode.Intra_4x4) &&
       (MbPartPredMode(mbtype, 0) != MacroBlockPartitionMode.Intra_16x16) &&
       (NumMbPart(mbtype) == 4))
     {
       SubMacroBlockPrediction smbp = new SubMacroBlockPrediction(mbtype);
     }
     else
     {
       MacroBlockPrediction mbpred = new MacroBlockPrediction(mbtype, this);
       mbpred.Read(bitReader);
     }
     if (MbPartPredMode(mbtype, 0) != MacroBlockPartitionMode.Intra_16x16)
       CodedBlockPattern = _cbp.GetCodedBlockPattern(bitReader);
     if ((CodedBlockPatternLuma > 0) || (CodedBlockPatternChroma > 0) ||
       (MbPartPredMode(mbtype, 0) == MacroBlockPartitionMode.Intra_16x16))
     {
       MBQPDelta = _mbQPD.GetMBQPDelta(bitReader);
       ResidualData residual = new ResidualData(_pps.EntropyCodingModeFlag);
       residual.Read(bitReader);
     }
       }
 }
Ejemplo n.º 14
0
 private void DecodedReferencePictureMarking(BitReader bitReader)
 {
     if (_nalu.NALUType == NALUnitType.IDRSlice)
       {
     NoOutputOfPriorPicsFlag = bitReader.GetNextBit();
     LongTermReferenceFlag = bitReader.GetNextBit();
       }
       else
       {
     AdaptiveRefPicMarkingModeFlag = bitReader.GetNextBit();
     if (AdaptiveRefPicMarkingModeFlag)
     {
       do
       {
     MemoryManagementControlOperation = bitReader.DecodeUnsignedExpGolomb();
     if ((MemoryManagementControlOperation == 1) || (MemoryManagementControlOperation == 3))
       DifferenceOfPicNumsMinus1 = bitReader.DecodeUnsignedExpGolomb();
     if (MemoryManagementControlOperation == 2)
       LongTermPicNum = bitReader.DecodeUnsignedExpGolomb();
     if ((MemoryManagementControlOperation == 3) || (MemoryManagementControlOperation == 6))
       LongTermFrameIdx = bitReader.DecodeUnsignedExpGolomb();
     if (MemoryManagementControlOperation == 4)
       MaxLongTermFrameIdxPlus1 = bitReader.DecodeUnsignedExpGolomb();
       } while (MemoryManagementControlOperation != 0);
     }
       }
 }
Ejemplo n.º 15
0
 private void MainInit(BitReader bitReader)
 {
     _bitReader = bitReader;
       if (_firstMacroBlock)
       {
     InitContextVariables(276);
     InitDecodeEngine();
       }
 }
 public void CheckSize(BitReader bitReader)
 {
     if (NumBytes != (uint)(bitReader.Position - _positionInStream))
     throw new Exception("NALU: CheckSize NOT ok");
 }
Ejemplo n.º 17
0
        void ParseThreadProc(object buffer)
        {
            byte[]    sliceBytes = buffer as byte[];
            BitReader br         = new BitReader(new MemoryStream(sliceBytes));
            int       totalSize  = _totalSize;
            int       offset     = 0;
            int       state      = 0;

            while (totalSize > 4)
            {
                int naluLen = (int)br.GetUIntFromNBits(32);
                if (naluLen > totalSize)
                {
                    throw new Exception("H264 parsing: wrong byte count encountered");
                }
                if (naluLen > 0)
                {
                    byte        b        = br.PeekByte();
                    byte        refIDC   = (byte)(b >> 5);
                    NALUnitType naluType = (NALUnitType)(b & 0x1F);
                    switch (state)
                    {
                    case 0:
                        AccessUnitDelimiter aud = new AccessUnitDelimiter((uint)naluLen);
                        aud.Read(br);
                        state = 1;
                        break;

                    case 1:
                        // either SEI or SPS (if it's an SEI, don't change state)
                        if (naluType == NALUnitType.SupplementalEnhancementInfo)
                        {
                            SupplementatlEnhancementMessage sei = new SupplementatlEnhancementMessage(_sps, (uint)naluLen);
                            sei.Read(br);
                        }
                        else if (naluType == NALUnitType.SequenceParamSet)
                        {
                            // replace _sps
                            _sps = new SequenceParameterSet((uint)naluLen);
                            _sps.Read(br);
                        }
                        else if (naluType == NALUnitType.PictureParamSet)
                        {
                            // replace _pps
                            _pps = new PictureParameterSet((uint)naluLen);
                            _pps.Read(br);
                        }
                        else if (naluType == NALUnitType.IDRSlice)
                        {
                            CodedSliceIDR idr = new CodedSliceIDR(_sps, _pps, (uint)naluLen);
                            idr.Read(br);
                            SliceType = idr.Header.SliceType;
                            FrameNum  = idr.Header.FrameNum;
                            state     = 2; // next should be zero or more redundant coded pictures
                        }
                        else if (naluType == NALUnitType.NonIDRSlice)
                        {
                            CodedSliceNonIDR nonIdr = new CodedSliceNonIDR(_sps, _pps, GetIDC(refIDC), (uint)naluLen);
                            nonIdr.Read(br);
                            SliceType = nonIdr.Header.SliceType;
                            FrameNum  = nonIdr.Header.FrameNum;
                            state     = 2; // next should be zero or more redundant coded pictures
                        }
                        else if (naluType == NALUnitType.SlicePartitionA)
                        {
                            CodedSlicePartitionA partA = new CodedSlicePartitionA(_sps, _pps, GetIDC(refIDC), (uint)naluLen);
                            partA.Read(br);
                            SliceType = partA.Header.SliceType;
                            FrameNum  = partA.Header.FrameNum;
                            state     = 2; // next should be zero or more redundant coded pictures
                        }
                        else if ((naluType == NALUnitType.SlicePartitionB) || (naluType == NALUnitType.SlicePartitionC))
                        {
                            CodedSlicePartitionBorC partBC = new CodedSlicePartitionBorC(_sps, _pps, GetIDC(refIDC), naluType, (uint)naluLen);
                            partBC.Read(br);
                            // FIXME: check that SliceType and FrameNum are set at this point
                            state = 2; // next should be zero or more redundant coded pictures
                        }
                        break;

                    case 2:
                        // either coded picture or end of sequence
                        break;

                    default:
                        break;
                    }
                    offset    += naluLen;
                    totalSize -= (naluLen + 4);
                }
                else
                {
                    naluLen = 0; // debugging break point
                }
            }

            if (SampleDoneEvent != null)
            {
                SampleDoneEvent(this);
            }
        }
Ejemplo n.º 18
0
 public virtual void Read(BitReader bitReader)
 {
     Nalu.Read(bitReader);
 }
Ejemplo n.º 19
0
        public void Read(BitReader bitReader)
        {
            if (_pps.EntropyCodingModeFlag)
            {
                while (!bitReader.ByteAligned)
                {
                    if ((CABACAlignmentOneBit = bitReader.GetNextBit()) == false)
                    {
                        throw new Exception("Invalid entropy coding start for slice data");
                    }
                }
            }

            CurrMbAddr    = _header.FirstMBInSlice * (1u + (_header.MBaffFrameFlag ? 1u : 0u));
            moreDataFlag  = true;
            prevMbSkipped = false;
            do
            {
                if ((_header.SliceType != SliceTypes.I) && (_header.SliceType != SliceTypes.SI))
                {
                    if (!_pps.EntropyCodingModeFlag)
                    {
                        MBSkipRun     = bitReader.DecodeUnsignedExpGolomb();
                        prevMbSkipped = (MBSkipRun > 0);
                        for (int i = 0; i < MBSkipRun; i++)
                        {
                            CurrMbAddr = NextMBAddress(CurrMbAddr);
                        }
                        moreDataFlag = _nalu.MoreRBSPData(bitReader);
                    }
                    else
                    {
                        mbSkipFlag   = false; // FIXME: CABAC value bitReader.GetNextBit();
                        moreDataFlag = !mbSkipFlag;
                    }
                }

                if (moreDataFlag)
                {
                    if (_header.MBaffFrameFlag && (CurrMbAddr % 2 == 0 || (CurrMbAddr % 2 == 1 && prevMbSkipped)))
                    {
                        mbFieldDecodingFlag = false; // FIXME: CABAC value bitReader.GetNextBit();
                    }
                    MacroBlockLayer mbLayer = new MacroBlockLayer(_sps, _pps, _header, this);
                    mbLayer.Read(bitReader);
                }

                if (!_pps.EntropyCodingModeFlag)
                {
                    moreDataFlag = _nalu.MoreRBSPData(bitReader);
                }
                else
                {
                    if (_header.SliceType != SliceTypes.I && _header.SliceType != SliceTypes.SI)
                    {
                        prevMbSkipped = mbSkipFlag;
                    }
                    if (_header.MBaffFrameFlag && CurrMbAddr % 2 == 0)
                    {
                        moreDataFlag = true;
                    }
                    else
                    {
                        endOfSliceFlag = bitReader.GetNextBit(); // FIXME: random bit bec. residual is not read
                        moreDataFlag   = !endOfSliceFlag;
                    }
                }

                CurrMbAddr = NextMBAddress(CurrMbAddr);
            } while (moreDataFlag);
        }
Ejemplo n.º 20
0
        private void ReferencePictureListReordering(BitReader bitReader)
        {
            if ((SliceType != SliceTypes.I) && (SliceType != SliceTypes.SI))
              {
            RefPicListReorderingFlagI0 = bitReader.GetNextBit();
            if (RefPicListReorderingFlagI0)
              do
              {
            ReorderingOfPicNumsIDC = bitReader.DecodeUnsignedExpGolomb();
            if (ReorderingOfPicNumsIDC > 3)
              throw new Exception("SliceHeader: ReferencePictureListReordering 1, invalid pic nums IDC");
            if ((ReorderingOfPicNumsIDC == 0) || (ReorderingOfPicNumsIDC == 1))
              AbsDiffPicNumMinus1 = bitReader.DecodeUnsignedExpGolomb();
            else if (ReorderingOfPicNumsIDC == 2)
              LongTermPicNum = bitReader.DecodeUnsignedExpGolomb();
              } while (ReorderingOfPicNumsIDC != 3);
              }

              if (SliceType == SliceTypes.B)
              {
            RefPicListReorderingFlagI1 = bitReader.GetNextBit();
            if (RefPicListReorderingFlagI1)
              do
              {
            ReorderingOfPicNumsIDC = bitReader.DecodeUnsignedExpGolomb();
            if (ReorderingOfPicNumsIDC > 3)
              throw new Exception("SliceHeader: ReferencePictureListReordering 2, invalid pic nums IDC");
            if ((ReorderingOfPicNumsIDC == 0) || (ReorderingOfPicNumsIDC == 1))
              AbsDiffPicNumMinus1 = bitReader.DecodeUnsignedExpGolomb();
            else if (ReorderingOfPicNumsIDC == 2)
              LongTermPicNum = bitReader.DecodeUnsignedExpGolomb();
              } while (ReorderingOfPicNumsIDC != 3);
              }
        }
Ejemplo n.º 21
0
 private SliceTypes ReadSliceType(BitReader bitReader)
 {
     uint st = bitReader.DecodeUnsignedExpGolomb();
       if (st > 4)
       {
     if (_pps.SliceTypeVal == st)
       _pps.SameCount++;
     else
     {
       _pps.SliceTypeVal = st;
       _pps.SameCount = 0;
     }
     st = st - 5;
       }
       else
       {
     if ((_pps.SliceTypeVal > 4) && (st == (_pps.SliceTypeVal - 5)))
       _pps.SameCount++;
     else
       _pps.SliceTypeVal = 0;
       }
       return (SliceTypes)st;
 }
Ejemplo n.º 22
0
        private void PredictionWeightTable(BitReader bitReader)
        {
            LumaLog2WeightDenominator = bitReader.DecodeUnsignedExpGolomb();
              ChromaLog2WeightDenominator = bitReader.DecodeUnsignedExpGolomb();
              uint cnt = (NumRefIdx10ActiveMinus1 + 1);
              if (cnt > 0)
              {
            LumaWeightI0 = new int[cnt];
            LumaOffsetI0 = new int[cnt];
            ChromaWeightI0 = new int[cnt][];
            ChromaOffsetI0 = new int[cnt][];
            for (int i = 0; i < cnt; i++)
            {
              LumaWeightI0Flag = bitReader.GetNextBit();
              if (LumaWeightI0Flag)
              {
            LumaWeightI0[i] = bitReader.DecodeSignedExpGolomb();
            LumaOffsetI0[i] = bitReader.DecodeSignedExpGolomb();
              }
              ChromaWeightI0Flag = bitReader.GetNextBit();
              if (ChromaWeightI0Flag)
              {
            ChromaWeightI0[i] = new int[2];
            ChromaOffsetI0[i] = new int[2];
            for (int j = 0; j < 2; j++)
            {
              ChromaWeightI0[i][j] = bitReader.DecodeSignedExpGolomb();
              ChromaOffsetI0[i][j] = bitReader.DecodeSignedExpGolomb();
            }
              }
            }
              }

              if (SliceType == SliceTypes.B)
              {
            cnt = (NumRefIdx11ActiveMinus1 + 1);
            if (cnt > 0)
            {
              LumaWeightI1 = new int[cnt];
              LumaOffsetI1 = new int[cnt];
              ChromaWeightI1 = new int[cnt][];
              ChromaOffsetI1 = new int[cnt][];
              for (int i = 0; i < cnt; i++)
              {
            LumaWeightI1Flag = bitReader.GetNextBit();
            if (LumaWeightI1Flag)
            {
              LumaWeightI1[i] = bitReader.DecodeSignedExpGolomb();
              LumaOffsetI1[i] = bitReader.DecodeSignedExpGolomb();
            }
            ChromaWeightI1Flag = bitReader.GetNextBit();
            if (ChromaWeightI1Flag)
            {
              ChromaWeightI1[i] = new int[2];
              ChromaOffsetI1[i] = new int[2];
              for (int j = 0; j < 2; j++)
              {
                ChromaWeightI1[i][j] = bitReader.DecodeSignedExpGolomb();
                ChromaOffsetI1[i][j] = bitReader.DecodeSignedExpGolomb();
              }
            }
              }
            }
              }
        }
 // start reading at a byte boundary
 public virtual void Read(BitReader bitReader)
 {
     _positionInStream = bitReader.Position;
       Byte firstByte = bitReader.ReadByte();
       Byte idc = (Byte)(firstByte >> 5);
       if ((idc > 0) != (NALRefIDC > 0)) // if it's not as expected, then throw exception
     throw new Exception("NALU base class: unexpected Ref IDC");
       NALUnitType naluType = (NALUnitType)(firstByte & 0x1F);
       if (naluType != NALUType)
     throw new Exception("NALU base class: unexpected NALU type");
 }
 public void SkipToEndOfNALU(BitReader bitReader)
 {
     bitReader.Position = _positionInStream + NumBytes;
 }
Ejemplo n.º 25
0
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader);
              _bitReader = bitReader;

              do
              {
            SEIMessage(bitReader);
              } while (MoreRBSPData(bitReader));
              SkipToEndOfNALU(bitReader);
        }
Ejemplo n.º 26
0
 public virtual void Read(BitReader bitReader)
 {
     Nalu.Read(bitReader);
 }
Ejemplo n.º 27
0
        public void Read(BitReader bitReader)
        {
            if (_pps.EntropyCodingModeFlag)
              {
            while (!bitReader.ByteAligned)
              if ((CABACAlignmentOneBit = bitReader.GetNextBit()) == false)
            throw new Exception("Invalid entropy coding start for slice data");
              }

              CurrMbAddr = _header.FirstMBInSlice * (1u + (_header.MBaffFrameFlag ? 1u : 0u));
              moreDataFlag = true;
              prevMbSkipped = false;
              do
              {
            if ((_header.SliceType != SliceTypes.I) && (_header.SliceType != SliceTypes.SI))
            {
              if (!_pps.EntropyCodingModeFlag)
              {
            MBSkipRun = bitReader.DecodeUnsignedExpGolomb();
            prevMbSkipped = (MBSkipRun > 0);
            for (int i = 0; i < MBSkipRun; i++)
            {
              CurrMbAddr = NextMBAddress(CurrMbAddr);
            }
            moreDataFlag = _nalu.MoreRBSPData(bitReader);
              }
              else
              {
            mbSkipFlag = false; // FIXME: CABAC value bitReader.GetNextBit();
            moreDataFlag = !mbSkipFlag;
              }
            }

            if (moreDataFlag)
            {
              if (_header.MBaffFrameFlag && (CurrMbAddr % 2 == 0 || (CurrMbAddr % 2 == 1 && prevMbSkipped)))
              {
            mbFieldDecodingFlag = false; // FIXME: CABAC value bitReader.GetNextBit();
              }
              MacroBlockLayer mbLayer = new MacroBlockLayer(_sps, _pps, _header, this);
              mbLayer.Read(bitReader);
            }

            if (!_pps.EntropyCodingModeFlag)
              moreDataFlag = _nalu.MoreRBSPData(bitReader);
            else
            {
              if (_header.SliceType != SliceTypes.I && _header.SliceType != SliceTypes.SI)
            prevMbSkipped = mbSkipFlag;
              if (_header.MBaffFrameFlag && CurrMbAddr % 2 == 0)
            moreDataFlag = true;
              else
              {
            endOfSliceFlag = bitReader.GetNextBit(); // FIXME: random bit bec. residual is not read
            moreDataFlag = !endOfSliceFlag;
              }
            }

            CurrMbAddr = NextMBAddress(CurrMbAddr);

              } while (moreDataFlag);
        }
Ejemplo n.º 28
0
 public void Read(BitReader bitReader)
 {
 }
Ejemplo n.º 29
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();
        }
Ejemplo n.º 30
0
        private void SEIMessage(BitReader bitReader)
        {
            byte lastTypeByte;
              PayloadType = 0;
              while (0xFF == (lastTypeByte = bitReader.ReadByte()))
            PayloadType += 255;
              PayloadType += lastTypeByte;

              byte lastSizeByte;
              PayloadSize = 0;
              while (0xFF == (lastSizeByte = bitReader.ReadByte()))
            PayloadSize += 255;
              PayloadSize += lastSizeByte;

              SEIPayload();
        }
Ejemplo n.º 31
0
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader);

            PICParamSetID         = bitReader.DecodeUnsignedExpGolomb();
            SEQParamSetID         = bitReader.DecodeUnsignedExpGolomb();
            EntropyCodingModeFlag = bitReader.GetNextBit();
            PICOrderPresentFlag   = bitReader.GetNextBit();
            NumSliceGroupsMinus1  = bitReader.DecodeUnsignedExpGolomb();
            if (NumSliceGroupsMinus1 > 0)
            {
                SliceGroupMapType = bitReader.DecodeUnsignedExpGolomb();
                switch (SliceGroupMapType)
                {
                case 0:
                    RunLengthMinus1 = new uint[NumSliceGroupsMinus1 + 1];
                    for (int grp = 0; grp <= NumSliceGroupsMinus1; grp++)
                    {
                        RunLengthMinus1[grp] = bitReader.DecodeUnsignedExpGolomb();
                    }
                    break;

                case 1:
                    break;

                case 2:
                    TopLeft     = new uint[NumSliceGroupsMinus1 + 1];
                    BottomRight = new uint[NumSliceGroupsMinus1 + 1];
                    for (int grp = 0; grp <= NumSliceGroupsMinus1; grp++) // standards doc, this reads grp < NumSliceGroupsMinus1
                    {
                        TopLeft[grp]     = bitReader.DecodeUnsignedExpGolomb();
                        BottomRight[grp] = bitReader.DecodeUnsignedExpGolomb();
                    }
                    break;

                case 3:
                case 4:
                case 5:
                    SliceGroupChangeDirectionFlag = bitReader.GetNextBit();
                    SliceGroupChangeRateMinus1    = bitReader.DecodeUnsignedExpGolomb();
                    break;

                case 6:
                    PICSizeInMapUnitsMinus1 = bitReader.DecodeUnsignedExpGolomb();
                    SliceGroupID            = new uint[PICSizeInMapUnitsMinus1 + 1];
                    ushort bitCount = BitReader.CalcBitsNeededToRepresent(NumSliceGroupsMinus1 + 1);
                    for (int grp = 0; grp <= PICSizeInMapUnitsMinus1; grp++)
                    {
                        SliceGroupID[grp] = bitReader.GetUIntFromNBits(bitCount);
                    }
                    break;

                default:
                    throw new Exception("BitReader: bad slice group map type");
                }
            }
            NumRefIDx10ActiveMinus1            = bitReader.DecodeUnsignedExpGolomb();
            NumRefIDx11ActiveMinus1            = bitReader.DecodeUnsignedExpGolomb();
            WeightedPredFlag                   = bitReader.GetNextBit();
            WeightedBiPredIDC                  = (ushort)bitReader.GetUIntFromNBits(2);
            PICInitQPMinus26                   = bitReader.DecodeSignedExpGolomb();
            PICInitQSMinus26                   = bitReader.DecodeSignedExpGolomb();
            ChromaQPIndexOffset                = bitReader.DecodeSignedExpGolomb();
            DeblockingFilterControlPresentFlag = bitReader.GetNextBit();
            ConstrainedIntraPredFlag           = bitReader.GetNextBit();
            RedundantPICCountPresentFlag       = bitReader.GetNextBit();
            bitReader.DiscardTrailingBits();
        }
Ejemplo n.º 32
0
 public uint GetCodedBlockPattern(BitReader bitReader)
 {
     return 0;
 }
Ejemplo n.º 33
0
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader);

              PICParamSetID = bitReader.DecodeUnsignedExpGolomb();
              SEQParamSetID = bitReader.DecodeUnsignedExpGolomb();
              EntropyCodingModeFlag = bitReader.GetNextBit();
              PICOrderPresentFlag = bitReader.GetNextBit();
              NumSliceGroupsMinus1 = bitReader.DecodeUnsignedExpGolomb();
              if (NumSliceGroupsMinus1 > 0)
              {
            SliceGroupMapType = bitReader.DecodeUnsignedExpGolomb();
            switch (SliceGroupMapType)
            {
              case 0:
            RunLengthMinus1 = new uint[NumSliceGroupsMinus1 + 1];
            for (int grp = 0; grp <= NumSliceGroupsMinus1; grp++)
            {
              RunLengthMinus1[grp] = bitReader.DecodeUnsignedExpGolomb();
            }
            break;
              case 1:
            break;
              case 2:
            TopLeft = new uint[NumSliceGroupsMinus1 + 1];
            BottomRight = new uint[NumSliceGroupsMinus1 + 1];
            for (int grp = 0; grp <= NumSliceGroupsMinus1; grp++) // standards doc, this reads grp < NumSliceGroupsMinus1
            {
              TopLeft[grp] = bitReader.DecodeUnsignedExpGolomb();
              BottomRight[grp] = bitReader.DecodeUnsignedExpGolomb();
            }
            break;
              case 3:
              case 4:
              case 5:
            SliceGroupChangeDirectionFlag = bitReader.GetNextBit();
            SliceGroupChangeRateMinus1 = bitReader.DecodeUnsignedExpGolomb();
            break;
              case 6:
            PICSizeInMapUnitsMinus1 = bitReader.DecodeUnsignedExpGolomb();
            SliceGroupID = new uint[PICSizeInMapUnitsMinus1 + 1];
            ushort bitCount = BitReader.CalcBitsNeededToRepresent(NumSliceGroupsMinus1 + 1);
            for (int grp = 0; grp <= PICSizeInMapUnitsMinus1; grp++)
            {
              SliceGroupID[grp] = bitReader.GetUIntFromNBits(bitCount);
            }
            break;
              default:
            throw new Exception("BitReader: bad slice group map type");
            }
              }
              NumRefIDx10ActiveMinus1 = bitReader.DecodeUnsignedExpGolomb();
              NumRefIDx11ActiveMinus1 = bitReader.DecodeUnsignedExpGolomb();
              WeightedPredFlag = bitReader.GetNextBit();
              WeightedBiPredIDC = (ushort)bitReader.GetUIntFromNBits(2);
              PICInitQPMinus26 = bitReader.DecodeSignedExpGolomb();
              PICInitQSMinus26 = bitReader.DecodeSignedExpGolomb();
              ChromaQPIndexOffset = bitReader.DecodeSignedExpGolomb();
              DeblockingFilterControlPresentFlag = bitReader.GetNextBit();
              ConstrainedIntraPredFlag = bitReader.GetNextBit();
              RedundantPICCountPresentFlag = bitReader.GetNextBit();
              bitReader.DiscardTrailingBits();
        }