// 9.3.3.1.1.7 Derivation process of ctxIdxInc for the syntax elements mvd_l0 and mvd_l1 public uint GetCtxIdxInc(uint mbAddr, MacroblockPartition mbPart, uint compIdx) { uint absMvdCompA; if (mbPart.SubMbPartIdxA < 16) { absMvdCompA = _motionVectors[mbAddr, mbPart.SubMbPartIdxA, compIdx]; } else { uint mbAddrA = _sliceState.GetMbAddrA(mbAddr); absMvdCompA = (mbAddrA == uint.MaxValue) ? 0U : _motionVectors[mbAddrA, (mbPart.SubMbPartIdxA & 15), compIdx]; } uint absMvdCompB; if (mbPart.SubMbPartIdxB < 16) { absMvdCompB = _motionVectors[mbAddr, mbPart.SubMbPartIdxB, compIdx]; } else { uint mbAddrB = _sliceState.GetMbAddrB(mbAddr); absMvdCompB = (mbAddrB == uint.MaxValue) ? 0U : _motionVectors[mbAddrB, (mbPart.SubMbPartIdxB & 15), compIdx]; } uint absMvdComp = (absMvdCompA + absMvdCompB); return((absMvdComp < 3) ? 0U : ((absMvdComp > 32) ? 2U : 1U)); }
// Retrieves the TotalCoeff of the subblock above the provided one (one row up) private int GetTopNumberCoeff(uint mbIndex, uint subBlockIndex) { if (!_subBlockPartition.IsTopMostSubBlock(subBlockIndex)) { return(_totalCoeffs[mbIndex, _subBlockPartition.GetSubBlockIndexAbove(subBlockIndex)]); } uint mbAddrB = _sliceState.GetMbAddrB(mbIndex); if (mbAddrB == uint.MaxValue) { return(TotalCoeffUnavailable); // 'TotalCoeff' information not available! } return(_totalCoeffs[mbAddrB, _subBlockPartition.GetSubBlockIndexAbove(subBlockIndex)]); }
public void Parse() { InitializeCabac(); _currMbAddr = _sliceState.FirstMacroBlockInSlice * (MbAffFrameFlag ? 2U : 1U); MbFieldDecodingFlag = _sliceState.FieldPicFlag; // The default for non-MBAFF frames bool moreDataFlag = true; bool prevMbSkipped = false; while (_readerState.Valid && moreDataFlag) { _currMbState = new MacroblockState(); _mbQpDeltaNotZero = 0; // Load macroblock states for block A (left) and B (top) _mbStateA = GetMacroblockState(_sliceState.GetMbAddrA(_currMbAddr)); _mbStateB = GetMacroblockState(_sliceState.GetMbAddrB(_currMbAddr)); _mbFlags = new MacroblockFlags(_mbStateA.Flags, _mbStateB.Flags); bool mbSkipFlag = false; if (!_sliceState.IntraCoded) { mbSkipFlag = GetMbSkipFlag(); // mb_skip_flag } if (!mbSkipFlag) { _mbFlags.SetCodedBlockFlag(); if (MbAffFrameFlag && (IsFirstMacroblockInPair() || prevMbSkipped)) { MbFieldDecodingFlag = GetMbFieldDecodingFlag(); // is field macro block } MacroBlockLayer(); } if (MbFieldDecodingFlag && (!MbAffFrameFlag || IsLastMacroblockInPair())) { _mbFlags.SetFieldDecodingMode(); } _currMbState.Flags = _mbFlags.Bits; _macroblockStates[_currMbAddr] = _currMbState; _prevMbQpDeltaNotZero = _mbQpDeltaNotZero; if (!_sliceState.IntraCoded) { prevMbSkipped = mbSkipFlag; } if (!MbAffFrameFlag || IsLastMacroblockInPair()) { moreDataFlag = !GetEndOfSliceFlag(); } if (moreDataFlag) { NextMbAddress(); } } #if DEBUG H264Debug.WriteLine(" - Terminated ({4}) at {0} of {1} ({2}), nextBits(16)={3}", _reader.Position, _reader.Length, _currMbAddr, ToBitString(_reader.ShowBits(16), 16), _sliceState.SliceType.ToString()); #endif }