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); } } }
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); } }
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); } } }
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++) { } } }
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++) { } } }
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); } }
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); } } }
public byte TimeOffsetLength; // 0 u(5) //} public void Read(BitReader bitReader) { CpbCount = bitReader.DecodeUnsignedExpGolomb() + 1; BitRateScale = bitReader.GetByteFromNBits(4); CpbSizeScale = bitReader.GetByteFromNBits(4); BitRateValue = new uint[CpbCount]; CpbSizeValue = new uint[CpbCount]; Cbr = new bool[CpbCount]; for (int i = 0; i < CpbCount; i++) { BitRateValue[i] = bitReader.DecodeUnsignedExpGolomb() + 1; CpbSizeValue[i] = bitReader.DecodeUnsignedExpGolomb() + 1; Cbr[i] = bitReader.GetNextBit(); } InitialCpbRemovalDelayLength = (byte)(bitReader.GetByteFromNBits(5) + 1); CpbRemovalDelayLength = (byte)(bitReader.GetByteFromNBits(5) + 1); DpbOutputDelayLength = (byte)(bitReader.GetByteFromNBits(5) + 1); TimeOffsetLength = bitReader.GetByteFromNBits(5); }
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); }
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(); } }
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])); }
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(); } } } } } }
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); } } }
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(); }
private void SEIPayload() { switch (PayloadType) { case 0: BufferingPeriod(); break; case 1: PicTiming(); break; case 2: PanScanRect(); break; case 3: FillerPayload(); break; case 4: UserDataRegisteredITUTT35(); break; case 5: UserDataUnregistered(); break; case 6: RecoveryPoint(); break; case 7: DecRefPicMarkingRepetition(); break; case 8: SparePic(); break; case 9: SceneInfo(); break; case 10: SubSeqInfo(); break; case 11: SubSeqLayerCharacteristics(); break; case 12: SubSeqCharacteristics(); break; case 13: FullFrameFreeze(); break; case 14: FullFrameFreezeRelease(); break; case 15: FullFrameSnapshot(); break; case 16: ProgressiveRefinementSegmentStart(); break; case 17: ProgressiveReginementSegmentEnd(); break; case 18: MotionConstrainedSliceGroupSet(); break; default: ReservedSEIMessage(); break; } if (!_bitReader.ByteAligned) { while (!_bitReader.GetNextBit()) { ; // throw new Exception("Unexpected zero bit at end of SEI"); } while (!_bitReader.ByteAligned) { if (_bitReader.GetNextBit()) { throw new Exception("Unexpected non-zero bit at end of SEI"); } } } }
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); }
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(); }
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); } }
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(); } } } } } }
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])); }
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(); }
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); } } }