Commit 72a8f0ee authored by Frank Bossen's avatar Frank Bossen
Browse files

Cleanup CABAC contexts

Remove unused contexts and split intra mode contexts into luma and
chroma sets to align with text description
parent 22c80346
......@@ -557,10 +557,8 @@ const CtxSet ContextSetCfg::MultiRefLineIdx = ContextSetCfg::addCtxSet
#endif
});
const CtxSet ContextSetCfg::IPredMode[] =
{
ContextSetCfg::addCtxSet
({
const CtxSet ContextSetCfg::IntraLumaMpmFlag = ContextSetCfg::addCtxSet
({
#if JVET_M0453_CABAC_ENGINE
{ 169,},
{ 169,},
......@@ -571,29 +569,19 @@ const CtxSet ContextSetCfg::IPredMode[] =
{ 154, },
{ 156, },
#endif
}),
ContextSetCfg::addCtxSet
({
#if JVET_M0453_CABAC_ENGINE
{ CNU, 137, 139, 140, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU,},
{ CNU, 138, 139, 169, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU,},
{ CNU, 154, 139, 154, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU,},
{ DWS, 5, 8, 9, DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, },
#else
{ CNU, 152, 139, 154, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
{ CNU, 138, 139, 169, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
{ CNU, 109, 139, 154, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
#endif
}),
};
});
const CtxSet ContextSetCfg::PdpcFlag = ContextSetCfg::addCtxSet
const CtxSet ContextSetCfg::IntraChromaPredMode = ContextSetCfg::addCtxSet
({
{ 107,},
{ 107,},
{ 139,},
#if JVET_M0453_CABAC_ENGINE
{ DWS, }
{ 137, 139, 140,},
{ 138, 139, 169,},
{ 154, 139, 154,},
{ 5, 8, 9,},
#else
{ 152, 139, 154,},
{ 138, 139, 169,},
{ 109, 139, 154,},
#endif
});
......@@ -719,16 +707,6 @@ const CtxSet ContextSetCfg::Mvd = ContextSetCfg::addCtxSet
#endif
});
const CtxSet ContextSetCfg::TransSubdivFlag = ContextSetCfg::addCtxSet
({
{ 224, 167, 122, 122, 122},
{ 124, 138, 94, 94, 94},
{ 153, 138, 138, 138, 138},
#if JVET_M0453_CABAC_ENGINE
{ DWS, DWS, DWS, DWS, DWS, }
#endif
});
const CtxSet ContextSetCfg::QtRootCbf = ContextSetCfg::addCtxSet
({
#if JVET_M0453_CABAC_ENGINE
......
......@@ -258,8 +258,8 @@ public:
static const CtxSet PartSize;
static const CtxSet PredMode;
static const CtxSet MultiRefLineIdx;
static const CtxSet IPredMode [2]; // [ ChannelType ]
static const CtxSet PdpcFlag;
static const CtxSet IntraLumaMpmFlag;
static const CtxSet IntraChromaPredMode;
static const CtxSet DeltaQP;
static const CtxSet InterDir;
static const CtxSet RefPic;
......@@ -270,7 +270,6 @@ public:
static const CtxSet AffineType;
static const CtxSet AffMergeIdx;
static const CtxSet Mvd;
static const CtxSet TransSubdivFlag;
static const CtxSet QtRootCbf;
static const CtxSet QtCbf [3]; // [ channel ]
static const CtxSet SigCoeffGroup [4]; // [ ChannelType ]
......
......@@ -1355,7 +1355,9 @@ void CABACReader::intra_luma_pred_modes( CodingUnit &cu )
mpmFlag[0] = true;
}
else
mpmFlag[k] = m_BinDecoder.decodeBin( Ctx::IPredMode[0]() );
{
mpmFlag[k] = m_BinDecoder.decodeBin(Ctx::IntraLumaMpmFlag());
}
}
PredictionUnit *pu = cu.firstPU;
......@@ -1430,7 +1432,7 @@ bool CABACReader::intra_chroma_lmc_mode( PredictionUnit& pu )
{
int lmModeList[10];
int maxSymbol = PU::getLMSymbolList(pu, lmModeList);
int symbol = unary_max_symbol( Ctx::IPredMode[1]( 2 ), Ctx::IPredMode[1]( 3 ), maxSymbol - 1 );
int symbol = unary_max_symbol(Ctx::IntraChromaPredMode(1), Ctx::IntraChromaPredMode(2), maxSymbol - 1);
if ( lmModeList[ symbol ] != -1 )
{
pu.intraDir[1] = lmModeList[ symbol ];
......@@ -1444,7 +1446,7 @@ void CABACReader::intra_chroma_pred_mode( PredictionUnit& pu )
RExt__DECODER_DEBUG_BIT_STATISTICS_CREATE_SET_SIZE2( STATS__CABAC_BITS__INTRA_DIR_ANG, pu.cu->blocks[pu.chType].lumaSize(), CHANNEL_TYPE_CHROMA );
{
if( m_BinDecoder.decodeBin( Ctx::IPredMode[1]( 1 ) ) == 0 )
if (m_BinDecoder.decodeBin(Ctx::IntraChromaPredMode(0)) == 0)
{
pu.intraDir[1] = DM_CHROMA_IDX;
return;
......
......@@ -1099,7 +1099,9 @@ void CABACWriter::intra_luma_pred_modes( const CodingUnit& cu )
CHECK(mpm_idx >= numMPMs, "use of non-MPM");
}
else
m_BinEncoder.encodeBin( mpm_idx < numMPMs, Ctx::IPredMode[0]() );
{
m_BinEncoder.encodeBin(mpm_idx < numMPMs, Ctx::IntraLumaMpmFlag());
}
pu = pu->next;
}
......@@ -1188,7 +1190,9 @@ void CABACWriter::intra_luma_pred_mode( const PredictionUnit& pu )
CHECK(mpm_idx >= numMPMs, "use of non-MPM");
}
else
m_BinEncoder.encodeBin( mpm_idx < numMPMs, Ctx::IPredMode[0]() );
{
m_BinEncoder.encodeBin(mpm_idx < numMPMs, Ctx::IntraLumaMpmFlag());
}
// mpm_idx / rem_intra_luma_pred_mode
if( mpm_idx < numMPMs )
......@@ -1258,20 +1262,20 @@ void CABACWriter::intra_chroma_lmc_mode( const PredictionUnit& pu )
}
CHECK( symbol < 0, "invalid symbol found" );
unary_max_symbol( symbol, Ctx::IPredMode[1]( 2 ), Ctx::IPredMode[1]( 3 ), maxSymbol - 1 );
unary_max_symbol(symbol, Ctx::IntraChromaPredMode(1), Ctx::IntraChromaPredMode(2), maxSymbol - 1);
}
void CABACWriter::intra_chroma_pred_mode( const PredictionUnit& pu )
{
const unsigned intraDir = pu.intraDir[1];
const bool isDerivedMode = intraDir == DM_CHROMA_IDX;
m_BinEncoder.encodeBin(isDerivedMode ? 0 : 1, Ctx::IntraChromaPredMode(0));
if (isDerivedMode)
{
if( intraDir == DM_CHROMA_IDX )
{
m_BinEncoder.encodeBin( 0, Ctx::IPredMode[1]( 1 ) );
return;
}
m_BinEncoder.encodeBin( 1, Ctx::IPredMode[1]( 1 ) );
return;
}
// LM chroma mode
......
......@@ -294,7 +294,7 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner )
//===== loop over partitions =====
const TempCtx ctxStart ( m_CtxCache, m_CABACEstimator->getCtx() );
const TempCtx ctxStartIntraMode ( m_CtxCache, SubCtx( Ctx::IPredMode[CHANNEL_TYPE_LUMA], m_CABACEstimator->getCtx() ) );
const TempCtx ctxStartIntraMode(m_CtxCache, SubCtx(Ctx::IntraLumaMpmFlag, m_CABACEstimator->getCtx()));
const TempCtx ctxStartMHIntraMode ( m_CtxCache, SubCtx( Ctx::MHIntraPredMode, m_CABACEstimator->getCtx() ) );
const TempCtx ctxStartMrlIdx ( m_CtxCache, SubCtx( Ctx::MultiRefLineIdx, m_CABACEstimator->getCtx() ) );
......@@ -485,7 +485,7 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner )
uiSad += distParam.distFunc(distParam);
// NB xFracModeBitsIntra will not affect the mode for chroma that may have already been pre-estimated.
m_CABACEstimator->getCtx() = SubCtx( Ctx::IPredMode[CHANNEL_TYPE_LUMA], ctxStartIntraMode );
m_CABACEstimator->getCtx() = SubCtx(Ctx::IntraLumaMpmFlag, ctxStartIntraMode);
m_CABACEstimator->getCtx() = SubCtx( Ctx::MHIntraPredMode, ctxStartMHIntraMode );
m_CABACEstimator->getCtx() = SubCtx( Ctx::MultiRefLineIdx, ctxStartMrlIdx );
......@@ -539,7 +539,7 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner )
Distortion sad = distParam.distFunc(distParam);
// NB xFracModeBitsIntra will not affect the mode for chroma that may have already been pre-estimated.
m_CABACEstimator->getCtx() = SubCtx( Ctx::IPredMode[CHANNEL_TYPE_LUMA], ctxStartIntraMode );
m_CABACEstimator->getCtx() = SubCtx(Ctx::IntraLumaMpmFlag, ctxStartIntraMode);
m_CABACEstimator->getCtx() = SubCtx( Ctx::MHIntraPredMode, ctxStartMHIntraMode );
m_CABACEstimator->getCtx() = SubCtx( Ctx::MultiRefLineIdx, ctxStartMrlIdx );
......@@ -598,7 +598,7 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner )
Distortion sad = distParam.distFunc(distParam);
// NB xFracModeBitsIntra will not affect the mode for chroma that may have already been pre-estimated.
m_CABACEstimator->getCtx() = SubCtx( Ctx::IPredMode[CHANNEL_TYPE_LUMA], ctxStartIntraMode );
m_CABACEstimator->getCtx() = SubCtx(Ctx::IntraLumaMpmFlag, ctxStartIntraMode);
m_CABACEstimator->getCtx() = SubCtx( Ctx::MHIntraPredMode, ctxStartMHIntraMode );
m_CABACEstimator->getCtx() = SubCtx( Ctx::MultiRefLineIdx, ctxStartMrlIdx );
......@@ -797,7 +797,7 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner )
cs.interHad = 0;
//===== reset context models =====
m_CABACEstimator->getCtx() = SubCtx( Ctx::IPredMode[CHANNEL_TYPE_LUMA], ctxStartIntraMode );
m_CABACEstimator->getCtx() = SubCtx(Ctx::IntraLumaMpmFlag, ctxStartIntraMode);
m_CABACEstimator->getCtx() = SubCtx( Ctx::MHIntraPredMode, ctxStartMHIntraMode );
m_CABACEstimator->getCtx() = SubCtx( Ctx::MultiRefLineIdx, ctxStartMrlIdx );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment