xEncodeInterResidual在merge和inter_ME中都会被调用,xCheckRDCostMerge2Nx2N函数和xCheckRDCostInter函数,都会在函数末尾根据预测得到的运动信息进行运动补偿MC,来获取预测像素信息。MC之后就会调用xEncodeInterResidual函数,根据预测像素计算失真和cost,最后将最优模式信息赋给bestCS。
xEncodeInterResidual函数计算inter预测模式的失真和cost,之后赋给bestCS最优模式信息。
tempCS中存储有当前inter_ME或merge模式的最优mv和预测信息,bestCS存储之前test过的各种模式中的最优模式信息。
函数中调用encodeResAndCalcRdInterCU函数根据得到的预测像素计算当前inter模式的cost,函数最后调用xCheckBestMode函数将最优模式信息赋给bestCS。
void EncCu::xEncodeInterResidual( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode, int residualPass, bool* bestHasNonResi )
{
if( residualPass == 1 && encTestMode.lossless )
{
return;
}
CodingUnit* cu = tempCS->getCU( partitioner.chType );
double bestCostInternal = MAX_DOUBLE;
{
cu->skip = false;
const bool skipResidual = residualPass == 1; //是否为skip模式,没有残差
m_pcInterSearch->encodeResAndCalcRdInterCU( *tempCS, partitioner, skipResidual );
//计算当前模式的最优运动信息下的cost
xCheckDQP( *tempCS, partitioner );
if( NULL != bestHasNonResi && (bestCostInternal > tempCS->cost) )
{
bestCostInternal = tempCS->cost;
*bestHasNonResi = !cu->rootCbf;
}
DTRACE_MODE_COST( *tempCS, m_pcRdCost->getLambda() );
//根据cost,将最优模式信息赋给bestCS
xCheckBestMode( tempCS, bestCS, partitioner, encTestMode );
}//end emt loop
}
encodeResAndCalcRdInterCU函数计算当前inter模式的最优运动信息下的cost,
函数中分别对skip模式和有残差的inter模式,进行cost的计算。
Void InterSearch::encodeResAndCalcRdInterCU(CodingStructure &cs, Partitioner &partitioner, const Bool &skipResidual)
{
CodingUnit &cu = *cs.getCU( partitioner.chType );
const ChromaFormat format = cs.area.chromaFormat;;
const Int numValidComponents = getNumberValidComponents(format);
const SPS &