📄 umc_h264_pack.cpp
字号:
Ipp32s condTermFlagB = 0;
if (block_b.mb_num >= 0)
{
Ipp8u tval = (Ipp8u) (pGetMBFieldDecodingFlag(cur_mb.GlobalMacroblockInfo) <
GetMBFieldDecodingFlag(m_pCurrentFrame->m_mbinfo.mbs[block_b.mb_num]));
MBTypeValue mb_type = m_pCurrentFrame->m_mbinfo.mbs[block_b.mb_num].mbtype;
Ipp32s ref_idx = m_pCurrentFrame->m_mbinfo.RefIdxs[list_num][block_b.mb_num].RefIdxs[block_b.block_num];
Ipp32s refIdxZeroFlag = ref_idx > tval ? 0 : 1; // predModeEqualFlag here
Ipp32s block_8x8 = block_subblock_mapping[block_b.block_num] / 4;
SBTypeValue sbtype = m_pCurrentFrame->m_mbinfo.mbs[block_b.mb_num].sbtype[block_8x8];
condTermFlagB = (IS_SKIP_MBTYPE(mb_type)
|| IS_INTRA_MBTYPE(mb_type)
|| (sbtype == SBTYPE_DIRECT)
|| refIdxZeroFlag) ? 0 : 1;
}
ref_idx_ctxIdxInc = condTermFlagA + 2*condTermFlagB;
return ref_idx_ctxIdxInc;
}
// Encodes ref_idx_lX of a list num.
template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::Encode_ref_idx(H264EncoderThreadPrivateSlice<PixType, CoeffsType> *curr_slice,
Ipp32s block_idx, Ipp32s listNum)
{
CH264pBs<PixType,CoeffsType> *pBitstream = curr_slice->m_pbitstream;
Ipp32s ref_idx_val = curr_slice->m_cur_mb.RefIdxs[listNum]->RefIdxs[block_idx];
if(m_PicParamSet.entropy_coding_mode) // CABAC
{
Ipp32s list_cabac = (listNum == LIST_0) ? REF_IDX_L0 : REF_IDX_L1;
Ipp32s ref_idx_ctxIdxInc = Derive_ctxIdxInc_CABAC(curr_slice, listNum, block_idx);
bool curr_bit = (ref_idx_val != 0);
pBitstream->EncodeSingleBin_CABAC(ctxIdxOffset[list_cabac] + ref_idx_ctxIdxInc, curr_bit);
ref_idx_ctxIdxInc = 3;
while(curr_bit)
{
ref_idx_val--;
ref_idx_ctxIdxInc = (ref_idx_ctxIdxInc < 5)? ref_idx_ctxIdxInc + 1: ref_idx_ctxIdxInc;
curr_bit = (ref_idx_val != 0);
pBitstream->EncodeSingleBin_CABAC(ctxIdxOffset[list_cabac] + ref_idx_ctxIdxInc, curr_bit);
}
} else { // CAVLC
Ipp32s num_ref_idx_active = (listNum == LIST_0)?
curr_slice->num_ref_idx_l0_active<<pGetMBFieldDecodingFlag(curr_slice->m_cur_mb.GlobalMacroblockInfo)
: curr_slice->num_ref_idx_l1_active<<pGetMBFieldDecodingFlag(curr_slice->m_cur_mb.GlobalMacroblockInfo);
if(num_ref_idx_active > 2) {
pBitstream->PutVLCCode(ref_idx_val);
} else {
// range == [0; 1]
pBitstream->PutBit(1 - ref_idx_val);
}
}
return;
} // Encode_ref_idx
typedef struct{
Ipp32s list_num;
Ipp32s block_idx;
Ipp32s block_w;
Ipp32s block_h;
} BlocksInfo;
static BlocksInfo blocks_infos[] =
{
{0, 0, 4, 4}, // 0 - MBTYPE_INTER
{1, 0, 4, 4}, // 1 - MBTYPE_BACKWARD
{0, 0, 4, 2}, // 2 - MBTYPE_FWD_FWD_16x8, MBTYPE_INTER_16x8
{0, 8, 4, 2}, // 3 - MBTYPE_FWD_FWD_16x8, MBTYPE_INTER_16x8
{0, 0, 2, 4}, // 4 - MBTYPE_FWD_FWD_8x16, MBTYPE_INTER_8x16
{0, 2, 2, 4}, // 5 - MBTYPE_FWD_FWD_8x16, MBTYPE_INTER_8x16
{1, 0, 4, 2}, // 6 - MBTYPE_BWD_BWD_16x8
{1, 8, 4, 2}, // 7 - MBTYPE_BWD_BWD_16x8
{1, 0, 2, 4}, // 8 - MBTYPE_BWD_BWD_8x16
{1, 2, 2, 4}, // 9 - MBTYPE_BWD_BWD_8x16
{0, 0, 4, 2}, // 10 - MBTYPE_FWD_BWD_16x8
{1, 8, 4, 2}, // 11 - MBTYPE_FWD_BWD_16x8
{0, 0, 2, 4}, // 12 - MBTYPE_FWD_BWD_8x16
{1, 2, 2, 4}, // 13 - MBTYPE_FWD_BWD_8x16
{0, 8, 4, 2}, // 14 - MBTYPE_BWD_FWD_16x8
{1, 0, 4, 2}, // 15 - MBTYPE_BWD_FWD_16x8
{0, 2, 2, 4}, // 16 - MBTYPE_BWD_FWD_8x16
{1, 0, 2, 4}, // 17 - MBTYPE_BWD_FWD_8x16
{0, 0, 4, 2}, // 18 - MBTYPE_BIDIR_FWD_16x8
{0, 8, 4, 2}, // 19 - MBTYPE_BIDIR_FWD_16x8
{1, 0, 4, 2}, // 20 - MBTYPE_BIDIR_FWD_16x8
{0, 0, 4, 2}, // 21 - MBTYPE_FWD_BIDIR_16x8
{0, 8, 4, 2}, // 22 - MBTYPE_FWD_BIDIR_16x8
{1, 8, 4, 2}, // 23 - MBTYPE_FWD_BIDIR_16x8
{0, 0, 4, 2}, // 24 - MBTYPE_BIDIR_BWD_16x8
{1, 0, 4, 2}, // 25 - MBTYPE_BIDIR_BWD_16x8
{1, 8, 4, 2}, // 26 - MBTYPE_BIDIR_BWD_16x8
{0, 8, 4, 2}, // 27 - MBTYPE_BWD_BIDIR_16x8
{1, 0, 4, 2}, // 28 - MBTYPE_BWD_BIDIR_16x8
{1, 8, 4, 2}, // 29 - MBTYPE_BWD_BIDIR_16x8
{0, 0, 4, 2}, // 30 - MBTYPE_BIDIR_BIDIR_16x8
{0, 8, 4, 2}, // 31 - MBTYPE_BIDIR_BIDIR_16x8
{1, 0, 4, 2}, // 32 - MBTYPE_BIDIR_BIDIR_16x8
{1, 8, 4, 2}, // 33 - MBTYPE_BIDIR_BIDIR_16x8
{0, 0, 2, 4}, // 34 - MBTYPE_BIDIR_FWD_8x16
{0, 2, 2, 4}, // 35 - MBTYPE_BIDIR_FWD_8x16
{1, 0, 2, 4}, // 36 - MBTYPE_BIDIR_FWD_8x16
{0, 0, 2, 4}, // 37 - MBTYPE_FWD_BIDIR_8x16
{0, 2, 2, 4}, // 38 - MBTYPE_FWD_BIDIR_8x16
{1, 2, 2, 4}, // 39 - MBTYPE_FWD_BIDIR_8x16
{0, 0, 2, 4}, // 40 - MBTYPE_BIDIR_BWD_8x16
{1, 0, 2, 4}, // 41 - MBTYPE_BIDIR_BWD_8x16
{1, 2, 2, 4}, // 42 - MBTYPE_BIDIR_BWD_8x16
{0, 2, 2, 4}, // 43 - MBTYPE_BWD_BIDIR_8x16
{1, 0, 2, 4}, // 44 - MBTYPE_BWD_BIDIR_8x16
{1, 2, 2, 4}, // 45 - MBTYPE_BWD_BIDIR_8x16
{0, 0, 2, 4}, // 46 - MBTYPE_BIDIR_BIDIR_8x16
{0, 2, 2, 4}, // 47 - MBTYPE_BIDIR_BIDIR_8x16
{1, 0, 2, 4}, // 48 - MBTYPE_BIDIR_BIDIR_8x16
{1, 2, 2, 4}, // 49 - MBTYPE_BIDIR_BIDIR_8x16
{0, 0, 4, 4}, // 50 - MBTYPE_BIDIR
{1, 0, 4, 4}, // 51 - MBTYPE_BIDIR
{0, 0, 2, 2}, // 52 - MBTYPE_INTER_8x8 / SBTYPE_8x8
{0, 0, 2, 1}, // 53 - MBTYPE_INTER_8x8 / SBTYPE_8x4
{0, 0, 1, 2}, // 54 - MBTYPE_INTER_8x8 / SBTYPE_4x8
{0, 0, 1, 1}, // 55 - MBTYPE_INTER_8x8 / SBTYPE_4x4
{0, 0, 2, 2}, // 56 - MBTYPE_B_8x8 / SBTYPE_FORWARD_8x8
{0, 0, 2, 1}, // 57 - MBTYPE_B_8x8 / SBTYPE_FORWARD_8x4
{0, 0, 1, 2}, // 58 - MBTYPE_B_8x8 / SBTYPE_FORWARD_4x8
{0, 0, 1, 1}, // 59 - MBTYPE_B_8x8 / SBTYPE_FORWARD_4x4
{1, 0, 2, 2}, // 60 - MBTYPE_B_8x8 / SBTYPE_BACKWARD_8x8
{1, 0, 2, 1}, // 61 - MBTYPE_B_8x8 / SBTYPE_BACKWARD_8x4
{1, 0, 1, 2}, // 62 - MBTYPE_B_8x8 / SBTYPE_BACKWARD_4x8
{1, 0, 1, 1}, // 63 - MBTYPE_B_8x8 / SBTYPE_BACKWARD_4x4
};
typedef struct {
BlocksInfo *mv_blocks;
Ipp32s size_mv;
Ipp32s mvs_l0_cnt;
BlocksInfo *ref_blocks;
Ipp32s size_ref;
Ipp32s ref_l0_cnt;
} MV_Ref_Info;
void get_blocks_info(MBTypeValue mb_type, SBTypeValue *sub_type, MV_Ref_Info & mv_ref_info)
{
const Ipp32s blockpos[4] = {0, 2, 8, 10};
mv_ref_info.mvs_l0_cnt = 0;
mv_ref_info.ref_l0_cnt = 0;
switch (mb_type)
{
case MBTYPE_DIRECT:
mv_ref_info.size_mv = mv_ref_info.size_ref = 0;
break;
case MBTYPE_INTER:
case MBTYPE_SKIPPED:
case MBTYPE_FORWARD:
mv_ref_info.size_mv = mv_ref_info.mvs_l0_cnt =
mv_ref_info.size_ref = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = &blocks_infos[0];
mv_ref_info.ref_blocks = &blocks_infos[0];
break;
case MBTYPE_BACKWARD:
mv_ref_info.size_mv =
mv_ref_info.size_ref = 1;
mv_ref_info.mv_blocks = &blocks_infos[1];
mv_ref_info.ref_blocks = &blocks_infos[1];
break;
case MBTYPE_FWD_FWD_16x8:
case MBTYPE_INTER_16x8:
mv_ref_info.size_mv = mv_ref_info.mvs_l0_cnt =
mv_ref_info.size_ref = mv_ref_info.ref_l0_cnt = 2;
mv_ref_info.mv_blocks = &blocks_infos[2];
mv_ref_info.ref_blocks = &blocks_infos[2];
break;
case MBTYPE_FWD_FWD_8x16:
case MBTYPE_INTER_8x16:
mv_ref_info.size_mv = mv_ref_info.mvs_l0_cnt =
mv_ref_info.size_ref = mv_ref_info.ref_l0_cnt = 2;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[4];
break;
case MBTYPE_BWD_BWD_16x8:
mv_ref_info.size_mv =
mv_ref_info.size_ref = 2;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[6];
break;
case MBTYPE_BWD_BWD_8x16:
mv_ref_info.size_mv =
mv_ref_info.size_ref = 2;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[8];
break;
case MBTYPE_FWD_BWD_16x8:
mv_ref_info.size_mv = mv_ref_info.size_ref = 2;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[10];
break;
case MBTYPE_FWD_BWD_8x16:
mv_ref_info.size_mv = mv_ref_info.size_ref = 2;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[12];
break;
case MBTYPE_BWD_FWD_16x8:
mv_ref_info.size_mv = mv_ref_info.size_ref = 2;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[14];
break;
case MBTYPE_BWD_FWD_8x16:
mv_ref_info.size_mv = mv_ref_info.size_ref = 2;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[16];
break;
case MBTYPE_BIDIR_FWD_16x8:
mv_ref_info.size_mv = mv_ref_info.size_ref = 3;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 2;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[18];
break;
case MBTYPE_FWD_BIDIR_16x8:
mv_ref_info.size_mv = mv_ref_info.size_ref = 3;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 2;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[21];
break;
case MBTYPE_BIDIR_BWD_16x8:
mv_ref_info.size_mv = mv_ref_info.size_ref = 3;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[24];
break;
case MBTYPE_BWD_BIDIR_16x8:
mv_ref_info.size_mv = mv_ref_info.size_ref = 3;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[27];
break;
case MBTYPE_BIDIR_BIDIR_16x8:
mv_ref_info.size_mv = mv_ref_info.size_ref = 4;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 2;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[30];
break;
case MBTYPE_BIDIR_FWD_8x16:
mv_ref_info.size_mv = mv_ref_info.size_ref = 3;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 2;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[34];
break;
case MBTYPE_FWD_BIDIR_8x16:
mv_ref_info.size_mv = mv_ref_info.size_ref = 3;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 2;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[37];
break;
case MBTYPE_BIDIR_BWD_8x16:
mv_ref_info.size_mv = mv_ref_info.size_ref = 3;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[40];
break;
case MBTYPE_BWD_BIDIR_8x16:
mv_ref_info.size_mv = mv_ref_info.size_ref = 3;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[43];
break;
case MBTYPE_BIDIR_BIDIR_8x16:
mv_ref_info.size_mv = mv_ref_info.size_ref = 4;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 2;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[46];
break;
case MBTYPE_BIDIR:
mv_ref_info.size_mv = mv_ref_info.size_ref = 2;
mv_ref_info.mvs_l0_cnt = mv_ref_info.ref_l0_cnt = 1;
mv_ref_info.mv_blocks = mv_ref_info.ref_blocks = &blocks_infos[50];
break;
case MBTYPE_INTER_8x8_REF0:
case MBTYPE_INTER_8x8:
{
BlocksInfo *mv_inf = mv_ref_info.mv_blocks;
BlocksInfo *ref_inf = mv_ref_info.ref_blocks;
mv_ref_info.size_mv = mv_ref_info.size_ref = 0;
for (Ipp32s block = 0; block < 4; block++)
{
switch (*sub_type)
{
case SBTYPE_8x8:
mv_ref_info.mvs_l0_cnt++;
mv_ref_info.ref_l0_cnt++;
*mv_inf = blocks_infos[52];
mv_inf->block_idx = blockpos[block];
*ref_inf = *mv_inf;
mv_inf++;
ref_inf++;
mv_ref_info.size_mv++;
mv_ref_info.size_ref++;
break;
case SBTYPE_8x4:
*mv_inf = blocks_infos[53];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -