Пример #1
0
        private IMacroblockType GetMacroBlockType()
        {
            //Table 7-10,7-11,..
            switch (_sliceState.SliceType)
            {
            case SliceType.I:
                uint mbTypeI = _reader.GetExpGolombCoded(25);
                return(MacroblockType.GetMbTypeI(mbTypeI));

            case SliceType.Si:
                uint mbTypeSi = _reader.GetExpGolombCoded(26);
                return(MacroblockType.GetMbTypeSi(mbTypeSi));

            case SliceType.P:
            case SliceType.Sp:
                uint mbTypeP = _reader.GetExpGolombCoded(30);
                return(MacroblockType.GetMbTypeP(mbTypeP));

            case SliceType.B:
                uint mbTypeB = _reader.GetExpGolombCoded(48);
                return(MacroblockType.GetMbTypeB(mbTypeB));
            }

            throw new InvalidOperationException("Current type not set");
        }
        private IMacroblockType GetMbTypeB()
        {
            const uint ctxOffsetPrefix = 27;

            if (_arithmeticDecoder.DecodeDecision(ctxOffsetPrefix + _mbFlags.GetMbTypeCtxIdxInc()) == 0)
            {
                return(MacroblockType.GetMbTypeB(0));
            }

            _mbFlags.SetMbTypeNotZero();

            if (_arithmeticDecoder.DecodeDecision(ctxOffsetPrefix + 3) == 0)
            {
                return(MacroblockType.GetMbTypeB(1U + _arithmeticDecoder.DecodeDecision(ctxOffsetPrefix + 5)));
            }
            if (_arithmeticDecoder.DecodeDecision(ctxOffsetPrefix + 4) == 0)
            {
                return(MacroblockType.GetMbTypeB(3U + GetFixedLength((ctxOffsetPrefix + 5), 3)));
            }
            if (_arithmeticDecoder.DecodeDecision(ctxOffsetPrefix + 5) == 0)
            {
                return(MacroblockType.GetMbTypeB(12U + GetFixedLength((ctxOffsetPrefix + 5), 3)));
            }
            if (_arithmeticDecoder.DecodeDecision(ctxOffsetPrefix + 5) == 1)
            {
                return(MacroblockType.GetMbTypeB(11U + (11U * _arithmeticDecoder.DecodeDecision(ctxOffsetPrefix + 5))));
            }
            if (_arithmeticDecoder.DecodeDecision(ctxOffsetPrefix + 5) == 0)
            {
                return(MacroblockType.GetMbTypeB(20U + _arithmeticDecoder.DecodeDecision(ctxOffsetPrefix + 5)));
            }

            const uint ctxOffsetSuffix = 32;

            if (_arithmeticDecoder.DecodeDecision(ctxOffsetSuffix) == 0)
            {
                return(MacroblockType.GetMbTypeI(0));
            }

            return(GetMbTypeIntra(ctxOffsetSuffix, MbTypeIntraCtxIdxIncInterSlice));
        }