xCompressCU()是帧内编码的核心函数,它把从上层函数compressCtu()得到的基本编码单元CTU递归地用函数xCheckModeSplit()进行宏块划分。在此过程中,xCheckModeSplit()会调用xCompressCU ()。
xCompressCU()函数
xCompressCU()函数的主要流程如下:
1、初始化:设置各种可用模式,上下文模型等;
2、遍历各种帧内模式,遍历完成后,调用xCheckModeSplit()函数递归进行宏块划分,调用xCheckRDCostIntra()函数进行帧内模式的遍历,进行帧内预测;
3、结束,设置状态,记录最优CU信息;
代码如下:
void EncCu::xCompressCU( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner )
{
if (m_shareState == NO_SHARE)
{
tempCS->sharedBndPos = tempCS->area.Y().lumaPos();
tempCS->sharedBndSize.width = tempCS->area.lwidth();
tempCS->sharedBndSize.height = tempCS->area.lheight();
bestCS->sharedBndPos = bestCS->area.Y().lumaPos();
bestCS->sharedBndSize.width = bestCS->area.lwidth();
bestCS->sharedBndSize.height = bestCS->area.lheight();
}
#if ENABLE_SPLIT_PARALLELISM
CHECK( m_dataId != tempCS->picture->scheduler.getDataId(), "Working in the wrong dataId!" );
if( m_pcEncCfg->getNumSplitThreads() != 1 && tempCS->picture->scheduler.getSplitJobId() == 0 )
{
if( m_modeCtrl->isParallelSplit( *tempCS, partitioner ) )
{
m_modeCtrl->setParallelSplit( true );
xCompressCUParallel( tempCS, bestCS, partitioner );
return;
}
}
#endif
Slice& slice = *tempCS->slice; //当前所处的slice
const PPS &pps = *tempCS->pps; //当前所处的pps
const SPS &sps = *tempCS->sps; //当前所处的sps
const uint32_t uiLPelX = tempCS->area.Y().lumaPos().x;//左上x
const uint32_t uiTPelY = tempCS->area.Y().lumaPos().y;//左上y
const UnitArea currCsArea = clipArea( CS::getArea( *bestCS, bestCS->area, partitioner.chType ), *tempCS->picture );
tempCS->chType = partitioner.chType;
bestCS->chType = partitioner.chType;
m_modeCtrl->initCULevel( partitioner, *tempCS );
if( partitioner.currQtDepth == 0 && partitioner.currMtDepth == 0 && !tempCS->