📄 umc_h264_segment_decoder_decode_mb_types_cabac.cpp
字号:
/*
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright (c) 2003-2007 Intel Corporation. All Rights Reserved.
//
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_H264_VIDEO_DECODER)
#include "umc_h264_segment_decoder.h"
#include "umc_h264_dec.h"
#include "umc_h264_bitstream_inlines.h"
#include "umc_h264_dec_internal_cabac.h"
#include "vm_debug.h"
namespace UMC
{
static
Ipp32s MBTYPETBL[] =
{
0-31, 1-31, 2-31, 3-31,
4-31, 5-31, 6-31, 7-31,
8-31, 9-31, 10-31, 11-31,
12-31, 13-31, 14-31, 15-31,
16-31, 17-31, 18-31, 19-31,
20-31, 21-31, 22-31, 23-31,
24-31, 25-31, 26-31, 27-31,
28-31, 29-31, 30-31, 31-31,
32-31, 33-31, 34-31, 35-31,
36-27, 37-27, 38-27, 39-27,
40-27, 41-27, 42-27, 43-27,
44-67, 45-67, 46-67, 47-67,
48-67, 49-67, 50-67, 51-67,
52-67, 53-67, 54-67, 55-67,
56-67, 57-67, 58-67, 59-67,
60-67, 61-67, 62-67, 63-67,
64-67, 65-67, 66-67, 67-67,
68-67, 69-67, 70-67, 71-67,
72-67, 73-67, 74-67, 75-67,
76-67, 77-67, 78-67, 79-67,
80-71, 81-71, 82-71, 83-71,
84-71, 85-71, 86-71, 87-71,
88-71, 89-71, 90-71, 91-71,
92-71, 93-71, 94-71, 95-71,
};
static
Ipp32s PMBTYPETBL[] =
{
0, 3, 2, 1
};
void H264SegmentDecoder::DecodeMBFieldDecodingFlag_CABAC(void)
{
Ipp32s condTermFlagA = 0, condTermFlagB = 0;
Ipp32s mbAddr, ctxIdxInc;
// get left MB pair info
mbAddr = m_CurMBAddr - 2;
if ((m_pSliceHeader->first_mb_in_slice <= mbAddr) &&
(m_CurMB_X))
condTermFlagA = GetMBFieldDecodingFlag(m_gmbinfo->mbs[mbAddr]);
// get above MB pair info
mbAddr = m_CurMBAddr - mb_width * 2;
if ((m_pSliceHeader->first_mb_in_slice <= mbAddr) &&
(m_CurMB_Y))
condTermFlagB = GetMBFieldDecodingFlag(m_gmbinfo->mbs[mbAddr]);
// decode flag
ctxIdxInc = condTermFlagA + condTermFlagB;
{
Ipp32s binVal = m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[MB_FIELD_DECODING_FLAG] +
ctxIdxInc);
pSetPairMBFieldDecodingFlag(m_cur_mb.GlobalMacroblockInfo,
m_cur_mb.GlobalMacroblockPairInfo,
binVal);
}
} // void H264SegmentDecoder::DecodeMBFieldDecodingFlag_CABAC(void)
static
Ipp8u block4_block8[16] =
{
0, 0, 1, 1,
0, 0, 1, 1,
2, 2, 3, 3,
2, 2, 3, 3
};
static
Ipp32s bit_mask[] =
{
1<<0,1<<1,1<<2,1<<3,
1<<4,1<<5,1<<6,1<<7,
1<<8,1<<9,1<<10,1<<11,
1<<12,1<<13,1<<14,1<<15,
1<<16,1<<17,1<<18,1<<19,
1<<20,1<<21,1<<22,1<<23,
1<<24,1<<25,1<<26,1<<27,
1<<28,1<<29,1<<30,1<<31,
};
Ipp32u H264SegmentDecoder::DecodeCBP_CABAC(Ipp32u color_format)
{
H264DecoderMacroblockLocalInfo *pTop, *pLeft[2];
H264DecoderMacroblockGlobalInfo *pGTop, *pGLeft[2];
Ipp32u cbp = 0;
bool bOk = true;
// obtain pointers to neighbouring MBs
{
Ipp32s nNum;
nNum = m_cur_mb.CurrentBlockNeighbours.mb_above.mb_num;
if (0 <= nNum)
{
pTop = &m_mbinfo.mbs[nNum];
pGTop = &m_gmbinfo->mbs[nNum];
}
else
{
pTop = 0;
pGTop = 0;
bOk = false;
}
nNum = m_cur_mb.CurrentBlockNeighbours.mbs_left[0].mb_num;
if (0 <= nNum)
{
pLeft[0] = &m_mbinfo.mbs[nNum];
pGLeft[0] = &m_gmbinfo->mbs[nNum];
}
else
{
pLeft[0] = 0;
pGLeft[0] = 0;
bOk = false;
}
nNum = m_cur_mb.CurrentBlockNeighbours.mbs_left[2].mb_num;
if (0 <= nNum)
{
pLeft[1] = &m_mbinfo.mbs[nNum];
pGLeft[1] = &m_gmbinfo->mbs[nNum];
}
else
{
pLeft[1] = 0;
pGLeft[1] = 0;
bOk = false;
}
}
// neightbouring MBs are present
if ((bOk) &&
(MBTYPE_PCM != pGTop->mbtype) &&
(MBTYPE_PCM != pGLeft[0]->mbtype) &&
(MBTYPE_PCM != pGLeft[1]->mbtype))
{
Ipp32u condTermFlagA, condTermFlagB;
Ipp32u ctxIdxInc;
Ipp32u mask;
// decode first luma bit
mask = (m_cur_mb.CurrentBlockNeighbours.mbs_left[0].block_num <= 7) ? (2) : (8);
condTermFlagA = (pLeft[0]->cbp & mask) ? (0) : (1);
condTermFlagB = (pTop->cbp & 4) ? (0) : (1);
ctxIdxInc = condTermFlagA + 2 * condTermFlagB;
cbp |= m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_LUMA] +
ctxIdxInc);
// decode second luma bit
condTermFlagA = cbp ^ 1;
condTermFlagB = (pTop->cbp & 8) ? (0) : (1);
ctxIdxInc = condTermFlagA + 2 * condTermFlagB;
cbp |= 2 * (m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_LUMA] +
ctxIdxInc));
// decode third luma bit
mask = (m_cur_mb.CurrentBlockNeighbours.mbs_left[2].block_num <= 7) ? (2) : (8);
condTermFlagA = (pLeft[1]->cbp & mask) ? (0) : (1);
condTermFlagB = (cbp & 1) ^ 1;
ctxIdxInc = condTermFlagA + 2 * condTermFlagB;
cbp |= 4 * (m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_LUMA] +
ctxIdxInc));
// decode fourth luma bit
condTermFlagA = ((cbp & 4) >> 2) ^ 1;
condTermFlagB = (cbp & 2) ^ 2;
// condTermFlagB has been already multiplyed on 2
ctxIdxInc = condTermFlagA + condTermFlagB;
cbp |= 8 * (m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_LUMA] +
ctxIdxInc));
// decode chroma CBP
if (color_format)
{
Ipp32u bin;
condTermFlagA = (pLeft[0]->cbp & 0x30) ? (1) : (0);
condTermFlagB = (pTop->cbp & 0x30) ? (1) : (0);
ctxIdxInc = condTermFlagA + 2 * condTermFlagB;
bin = m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_CHROMA] +
ctxIdxInc);
if (bin)
{
condTermFlagA = (pLeft[0]->cbp >> 5);
condTermFlagB = (pTop->cbp >> 5);
ctxIdxInc = condTermFlagA + 2 * condTermFlagB + 4;
bin = m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_CHROMA] +
ctxIdxInc);
cbp |= (bin + 1) << 4;
}
}
}
// some of macroblocks may be absent or have I_PCM type
else
{
Ipp32u condTermFlagA, condTermFlagB;
Ipp32u ctxIdxInc;
// decode first luma bit
if (pLeft[0])
{
Ipp32u mask;
mask = (m_cur_mb.CurrentBlockNeighbours.mbs_left[0].block_num <= 7) ? (2) : (8);
condTermFlagA = (pLeft[0]->cbp & mask) ? (0) : (MBTYPE_PCM != pGLeft[0]->mbtype);
}
else
condTermFlagA = 0;
if (pTop)
condTermFlagB = (pTop->cbp & 4) ? (0) : (MBTYPE_PCM != pGTop->mbtype);
else
condTermFlagB = 0;
ctxIdxInc = condTermFlagA + 2 * condTermFlagB;
cbp |= m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_LUMA] +
ctxIdxInc);
// decode second luma bit
condTermFlagA = cbp ^ 1;
if (pTop)
condTermFlagB = (pTop->cbp & 8) ? (0) : (MBTYPE_PCM != pGTop->mbtype);
else
condTermFlagB = 0;
ctxIdxInc = condTermFlagA + 2 * condTermFlagB;
cbp |= 2 * (m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_LUMA] +
ctxIdxInc));
// decode third luma bit
if (pLeft[1])
{
Ipp32u mask;
mask = (m_cur_mb.CurrentBlockNeighbours.mbs_left[2].block_num <= 7) ? (2) : (8);
condTermFlagA = (pLeft[1]->cbp & mask) ? (0) : (MBTYPE_PCM != pGLeft[1]->mbtype);
}
else
condTermFlagA = 0;
condTermFlagB = (cbp & 1) ^ 1;
ctxIdxInc = condTermFlagA + 2 * condTermFlagB;
cbp |= 4 * (m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_LUMA] +
ctxIdxInc));
// decode fourth luma bit
condTermFlagA = ((cbp & 4) >> 2) ^ 1;
condTermFlagB = (cbp & 2) ^ 2;
// condTermFlagB has been already multiplyed on 2
ctxIdxInc = condTermFlagA + condTermFlagB;
cbp |= 8 * (m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_LUMA] +
ctxIdxInc));
// decode chroma CBP
if (color_format)
{
Ipp32u bin;
if (pLeft[0])
condTermFlagA = (pLeft[0]->cbp & 0x30) ? (1) : (MBTYPE_PCM == pGLeft[0]->mbtype);
else
condTermFlagA = 0;
if (pTop)
condTermFlagB = (pTop->cbp & 0x30) ? (1) : (MBTYPE_PCM == pGTop->mbtype);
else
condTermFlagB = 0;
ctxIdxInc = condTermFlagA + 2 * condTermFlagB;
bin = m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_CHROMA] +
ctxIdxInc);
if (bin)
{
if (pLeft[0])
condTermFlagA = (pLeft[0]->cbp & 0x20) ? (1) : (MBTYPE_PCM == pGLeft[0]->mbtype);
else
condTermFlagA = 0;
if (pTop)
condTermFlagB = (pTop->cbp & 0x20) ? (1) : (MBTYPE_PCM == pGTop->mbtype);
else
condTermFlagB = 0;
ctxIdxInc = condTermFlagA + 2 * condTermFlagB + 4;
bin = m_pBitStream->DecodeSingleBin_CABAC(ctxIdxOffset[CODED_BLOCK_PATTERN_CHROMA] +
ctxIdxInc);
cbp |= (bin + 1) << 4;
}
}
}
return cbp;
} // Ipp32u H264SegmentDecoder::DecodeCBP_CABAC(Ipp32u color_format)
void H264SegmentDecoder::DecodeIntraTypes4x4_CABAC(IntraType *pMBIntraTypes, bool bUseConstrainedIntra)
{
Ipp32u block;
// Temp arrays for modes from above and left, initially filled from
// outside the MB, then updated with modes within the MB
Ipp32s uModeAbove[4];
Ipp32s uModeLeft[4];
Ipp32s uPredMode; // predicted mode for current 4x4 block
IntraType *pRefIntraTypes;
Ipp32u uLeftIndex; // indexes into mode arrays, dependent on 8x8 block
Ipp32u uAboveIndex;
H264DecoderMacroblockGlobalInfo *gmbinfo=m_gmbinfo->mbs;
// Get modes of blocks above and to the left, substituting 0
// when above or to left is outside this MB slice. Substitute mode 2
// when the adjacent macroblock is not 4x4 INTRA. Add 1 to actual
// modes, so mode range is 1..9.
if ((m_cur_mb.CurrentBlockNeighbours.mb_above.mb_num<0) ||
((!IS_INTRA_MBTYPE(gmbinfo[m_cur_mb.CurrentBlockNeighbours.mb_above.mb_num].mbtype)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -