Newer
Older

Karsten Suehring
committed
bool testGbi;
uint8_t gbiIdx;
#if JVET_M0246_AFFINE_AMVR
bool affineAmvrEanbledFlag = cu.slice->getSPS()->getAffineAmvrEnabledFlag();
#endif

Karsten Suehring
committed
if( pcCUInfo2Reuse != nullptr )
{
// reuse the motion info from pcCUInfo2Reuse
CU::resetMVDandMV2Int( cu, m_pcInterSearch );
CHECK(cu.GBiIdx < 0 || cu.GBiIdx >= GBI_NUM, "cu.GBiIdx < 0 || cu.GBiIdx >= GBI_NUM");
gbiIdx = CU::getValidGbiIdx(cu);
testGbi = (gbiIdx != GBI_DEFAULT);
#if JVET_M0246_AFFINE_AMVR
if ( !CU::hasSubCUNonZeroMVd( cu ) && !CU::hasSubCUNonZeroAffineMVd( cu ) )
#else

Karsten Suehring
committed
if( !CU::hasSubCUNonZeroMVd( cu ) )

Karsten Suehring
committed
{
if (m_modeCtrl->useModeResult(encTestModeBase, tempCS, partitioner))
{
std::swap(tempCS, bestCS);
// store temp best CI for next CU coding
m_CurrCtx->best = m_CABACEstimator->getCtx();
}
#if JVET_M0246_AFFINE_AMVR
if ( affineAmvrEanbledFlag )
{
tempCS->initStructData( encTestMode.qp, encTestMode.lossless );
continue;
}
else
{
return false;
}
#else

Karsten Suehring
committed
return false;

Karsten Suehring
committed
}
else
{
m_pcInterSearch->motionCompensation( cu );
}
}
else
{
cu.GBiIdx = g_GbiSearchOrder[gbiLoopIdx];
gbiIdx = cu.GBiIdx;
testGbi = (gbiIdx != GBI_DEFAULT);
#if JVET_M0246_AFFINE_AMVR
cu.firstPU->interDir = 10;
#endif

Karsten Suehring
committed
m_pcInterSearch->predInterSearch( cu, partitioner );
#if JVET_M0246_AFFINE_AMVR
if ( cu.firstPU->interDir <= 3 )
{
gbiIdx = CU::getValidGbiIdx(cu);
}
else
{
return false;
}
#else
gbiIdx = CU::getValidGbiIdx(cu);

Karsten Suehring
committed
}
if( testGbi && gbiIdx == GBI_DEFAULT ) // Enabled GBi but the search results is uni.
{
tempCS->initStructData(encTestMode.qp, encTestMode.lossless);
continue;
}
CHECK(!(testGbi || (!testGbi && gbiIdx == GBI_DEFAULT)), " !( bTestGbi || (!bTestGbi && gbiIdx == GBI_DEFAULT ) )");
bool isEqualUni = false;
if( m_pcEncCfg->getUseGBiFast() )
{
if( cu.firstPU->interDir != 3 && testGbi == 0 )
{
isEqualUni = true;
}
}
#if JVET_M0246_AFFINE_AMVR
if ( !CU::hasSubCUNonZeroMVd( cu ) && !CU::hasSubCUNonZeroAffineMVd( cu ) )
#else

Karsten Suehring
committed
if( !CU::hasSubCUNonZeroMVd( cu ) )

Karsten Suehring
committed
{
if (m_modeCtrl->useModeResult(encTestModeBase, tempCS, partitioner))
{
std::swap(tempCS, bestCS);
// store temp best CI for next CU coding
m_CurrCtx->best = m_CABACEstimator->getCtx();
}
#if JVET_M0246_AFFINE_AMVR
if ( affineAmvrEanbledFlag )
{
tempCS->initStructData( encTestMode.qp, encTestMode.lossless );
continue;
}
else
{
return false;
}
#else

Karsten Suehring
committed
return false;

Karsten Suehring
committed
}
#if JVET_M0464_UNI_MTS
xEncodeInterResidual( tempCS, bestCS, partitioner, encTestModeBase, 0
, NULL
, 0
, &equGBiCost
#else
xEncodeInterResidual( tempCS, bestCS, partitioner, encTestModeBase, 0
, NULL
, true
, 0

Karsten Suehring
committed
tempCS->initStructData(encTestMode.qp, encTestMode.lossless);
double skipTH = MAX_DOUBLE;
skipTH = (m_pcEncCfg->getUseGBiFast() ? 1.05 : MAX_DOUBLE);
if( equGBiCost > curBestCost * skipTH )
{
break;
}
if( m_pcEncCfg->getUseGBiFast() )
{
if( isEqualUni == true && m_pcEncCfg->getIntraPeriod() == -1 )
{
break;
}
}
if( g_GbiSearchOrder[gbiLoopIdx] == GBI_DEFAULT && xIsGBiSkip(cu) && m_pcEncCfg->getUseGBiFast() )
{
break;
}
#if JVET_M0246_AFFINE_AMVR
validMode = true;
#endif
} // for( UChar gbiLoopIdx = 0; gbiLoopIdx < gbiLoopNum; gbiLoopIdx++ )
#if JVET_M0246_AFFINE_AMVR
return tempCS->slice->getSPS()->getAffineAmvrEnabledFlag() ? validMode : true;
#else

Karsten Suehring
committed
return true;

Karsten Suehring
committed
}
#if JVET_M0464_UNI_MTS
void EncCu::xEncodeInterResidual( CodingStructure *&tempCS
, CodingStructure *&bestCS
, Partitioner &partitioner
, const EncTestMode& encTestMode
, int residualPass
, CodingStructure* imvCS
, bool* bestHasNonResi
, double* equGBiCost
#else
void EncCu::xEncodeInterResidual( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode, int residualPass
, CodingStructure* imvCS
, int emtMode
, bool* bestHasNonResi

Karsten Suehring
committed
{
if( residualPass == 1 && encTestMode.lossless )
{
return;
}
CodingUnit* cu = tempCS->getCU( partitioner.chType );
double bestCostInternal = MAX_DOUBLE;
double bestCost = bestCS->cost;
#if JVET_M0140_SBT
double bestCostBegin = bestCS->cost;
CodingUnit* prevBestCU = bestCS->getCU( partitioner.chType );
uint8_t prevBestSbt = ( prevBestCU == nullptr ) ? 0 : prevBestCU->sbtInfo;
#endif
const SPS& sps = *tempCS->sps;
const int maxSizeEMT = EMT_INTER_MAX_CU_WITH_QTBT;
bool swapped = false; // avoid unwanted data copy
bool reloadCU = false;
const bool considerEmtSecondPass = emtMode && sps.getSpsNext().getUseInterEMT() && partitioner.currArea().lwidth() <= maxSizeEMT && partitioner.currArea().lheight() <= maxSizeEMT;
int minEMTMode = 0;
int maxEMTMode = (considerEmtSecondPass?1:0);

Karsten Suehring
committed
// Not allow very big |MVd| to avoid CABAC crash caused by too large MVd. Normally no impact on coding performance.
const int maxMvd = 1 << 15;
const PredictionUnit& pu = *cu->firstPU;
if (!cu->affine)
{
if ((pu.refIdx[0] >= 0 && (pu.mvd[0].getAbsHor() >= maxMvd || pu.mvd[0].getAbsVer() >= maxMvd))
|| (pu.refIdx[1] >= 0 && (pu.mvd[1].getAbsHor() >= maxMvd || pu.mvd[1].getAbsVer() >= maxMvd)))
{
return;
}
}
Xiang Li
committed
else
{
for (int refList = 0; refList < NUM_REF_PIC_LIST_01; refList++)
{
if (pu.refIdx[refList] >= 0)
{
for (int ctrlP = 1 + (cu->affineType == AFFINEMODEL_6PARAM); ctrlP >= 0; ctrlP--)
{
if (pu.mvdAffi[refList][ctrlP].getAbsHor() >= maxMvd || pu.mvdAffi[refList][ctrlP].getAbsVer() >= maxMvd)
{
return;
}
}
}
}
}
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
#if JVET_M0140_SBT
const bool mtsAllowed = tempCS->sps->getSpsNext().getUseInterMTS() && partitioner.currArea().lwidth() <= MTS_INTER_MAX_CU_SIZE && partitioner.currArea().lheight() <= MTS_INTER_MAX_CU_SIZE;
uint8_t sbtAllowed = cu->checkAllowedSbt();
uint8_t numRDOTried = 0;
Distortion sbtOffDist = 0;
bool sbtOffRootCbf = 0;
double sbtOffCost = MAX_DOUBLE;
double currBestCost = MAX_DOUBLE;
bool doPreAnalyzeResi = ( sbtAllowed || mtsAllowed ) && residualPass == 0;
m_pcInterSearch->initTuAnalyzer();
if( doPreAnalyzeResi )
{
m_pcInterSearch->calcMinDistSbt( *tempCS, *cu, sbtAllowed );
}
auto slsSbt = dynamic_cast<SaveLoadEncInfoSbt*>( m_modeCtrl );
int slShift = 4 + std::min( (int)gp_sizeIdxInfo->idxFrom( cu->lwidth() ) + (int)gp_sizeIdxInfo->idxFrom( cu->lheight() ), 9 );
Distortion curPuSse = m_pcInterSearch->getEstDistSbt( NUMBER_SBT_MODE );
uint8_t currBestSbt = 0;
uint8_t currBestTrs = MAX_UCHAR;
uint8_t histBestSbt = MAX_UCHAR;
uint8_t histBestTrs = MAX_UCHAR;
m_pcInterSearch->setHistBestTrs( MAX_UCHAR, MAX_UCHAR );
if( doPreAnalyzeResi )
{
if( m_pcInterSearch->getSkipSbtAll() && !mtsAllowed ) //emt is off
{
histBestSbt = 0; //try DCT2
m_pcInterSearch->setHistBestTrs( histBestSbt, histBestTrs );
}
else
{
assert( curPuSse != std::numeric_limits<uint64_t>::max() );
uint16_t compositeSbtTrs = slsSbt->findBestSbt( cu->cs->area, (uint32_t)( curPuSse >> slShift ) );
histBestSbt = ( compositeSbtTrs >> 0 ) & 0xff;
histBestTrs = ( compositeSbtTrs >> 8 ) & 0xff;
if( m_pcInterSearch->getSkipSbtAll() && CU::isSbtMode( histBestSbt ) ) //special case, skip SBT when loading SBT
{
histBestSbt = 0; //try DCT2
}
m_pcInterSearch->setHistBestTrs( histBestSbt, histBestTrs );
}
}
#endif
if( emtMode == 2 )
{
minEMTMode = maxEMTMode = (cu->emtFlag?1:0);
}

Karsten Suehring
committed
for( int curEmtMode = minEMTMode; curEmtMode <= maxEMTMode; curEmtMode++ )

Karsten Suehring
committed
{
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
if( reloadCU )
{
if( bestCost == bestCS->cost ) //The first EMT pass didn't become the bestCS, so we clear the TUs generated
{
tempCS->clearTUs();
}
else if( false == swapped )
{
tempCS->initStructData( encTestMode.qp, encTestMode.lossless );
tempCS->copyStructure( *bestCS, partitioner.chType );
tempCS->getPredBuf().copyFrom( bestCS->getPredBuf() );
bestCost = bestCS->cost;
cu = tempCS->getCU( partitioner.chType );
swapped = true;
}
else
{
tempCS->clearTUs();
bestCost = bestCS->cost;
cu = tempCS->getCU( partitioner.chType );
}
//we need to restart the distortion for the new tempCS, the bit count and the cost
tempCS->dist = 0;
tempCS->fracBits = 0;
tempCS->cost = MAX_DOUBLE;
}
reloadCU = true; // enable cu reloading

Karsten Suehring
committed
cu->skip = false;
cu->emtFlag = curEmtMode;
#if JVET_M0140_SBT
cu->sbtInfo = 0;
#endif

Karsten Suehring
committed
const bool skipResidual = residualPass == 1;
#if JVET_M0140_SBT // skip DCT-2 and EMT if historical best transform mode is SBT
if( skipResidual || histBestSbt == MAX_UCHAR || !CU::isSbtMode( histBestSbt ) )
{
#endif

Karsten Suehring
committed
m_pcInterSearch->encodeResAndCalcRdInterCU( *tempCS, partitioner, skipResidual );
#if JVET_M0140_SBT
numRDOTried += mtsAllowed ? 2 : 1;
#endif

Karsten Suehring
committed
xEncodeDontSplit( *tempCS, partitioner );
xCheckDQP( *tempCS, partitioner );
#if !JVET_M0140_SBT //harmonize with GBI fast algorithm (move the code to the end of this function)
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
if( ETM_INTER_ME == encTestMode.type )
{
if( equGBiCost != NULL )
{
if( tempCS->cost < (*equGBiCost) && cu->GBiIdx == GBI_DEFAULT )
{
(*equGBiCost) = tempCS->cost;
}
}
else
{
CHECK(equGBiCost == NULL, "equGBiCost == NULL");
}
if( tempCS->slice->getCheckLDC() && !cu->imv && cu->GBiIdx != GBI_DEFAULT && tempCS->cost < m_bestGbiCost[1] )
{
if( tempCS->cost < m_bestGbiCost[0] )
{
m_bestGbiCost[1] = m_bestGbiCost[0];
m_bestGbiCost[0] = tempCS->cost;
m_bestGbiIdx[1] = m_bestGbiIdx[0];
m_bestGbiIdx[0] = cu->GBiIdx;
}
else
{
m_bestGbiCost[1] = tempCS->cost;
m_bestGbiIdx[1] = cu->GBiIdx;
}
}
}
double emtFirstPassCost = tempCS->cost;

Karsten Suehring
committed
if( imvCS && (tempCS->cost < imvCS->cost) )
{
if( imvCS->cost != MAX_DOUBLE )
{
imvCS->initStructData( encTestMode.qp, encTestMode.lossless );
}
imvCS->copyStructure( *tempCS, partitioner.chType );
}
if( NULL != bestHasNonResi && (bestCostInternal > tempCS->cost) )
{
bestCostInternal = tempCS->cost;
if (!(tempCS->getPU(partitioner.chType)->mhIntraFlag))

Karsten Suehring
committed
*bestHasNonResi = !cu->rootCbf;
}
if (cu->rootCbf == false)
{
if (tempCS->getPU(partitioner.chType)->mhIntraFlag)
{
tempCS->cost = MAX_DOUBLE;
return;
}
}
#if JVET_M0140_SBT
currBestCost = tempCS->cost;
sbtOffCost = tempCS->cost;
sbtOffDist = tempCS->dist;
sbtOffRootCbf = cu->rootCbf;
currBestSbt = CU::getSbtInfo( cu->firstTU->mtsIdx > 1 ? SBT_OFF_MTS : SBT_OFF_DCT, 0 );
currBestTrs = cu->firstTU->mtsIdx;
if( cu->lwidth() <= MAX_TU_SIZE_FOR_PROFILE && cu->lheight() <= MAX_TU_SIZE_FOR_PROFILE )
{
CHECK( tempCS->tus.size() != 1, "tu must be only one" );
}
#endif

Karsten Suehring
committed
#if WCG_EXT
DTRACE_MODE_COST( *tempCS, m_pcRdCost->getLambda( true ) );
#else
DTRACE_MODE_COST( *tempCS, m_pcRdCost->getLambda() );
#endif
xCheckBestMode( tempCS, bestCS, partitioner, encTestMode );
//now we check whether the second pass should be skipped or not
if( !curEmtMode && maxEMTMode )
{
const double thresholdToSkipEmtSecondPass = 1.1; // Skip checking EMT transforms
const bool bCond1 = !cu->firstTU->cbf[COMPONENT_Y];

Karsten Suehring
committed
const bool bCond3 = emtFirstPassCost > ( bestCost * thresholdToSkipEmtSecondPass );
if( m_pcEncCfg->getFastInterEMT() && (bCond1 || bCond3 ) )
{
maxEMTMode = 0; // do not test EMT
}
}
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
#endif
#if JVET_M0140_SBT // skip DCT-2 and EMT
}
#endif
#if JVET_M0140_SBT //RDO for SBT
uint8_t numSbtRdo = CU::numSbtModeRdo( sbtAllowed );
//early termination if all SBT modes are not allowed
//normative
if( !sbtAllowed || skipResidual )
{
numSbtRdo = 0;
}
//fast algorithm
if( ( histBestSbt != MAX_UCHAR && !CU::isSbtMode( histBestSbt ) ) || m_pcInterSearch->getSkipSbtAll() )
{
numSbtRdo = 0;
}
if( bestCost != MAX_DOUBLE && sbtOffCost != MAX_DOUBLE )
{
double th = 1.07;
if( !( prevBestSbt == 0 || m_sbtCostSave[0] == MAX_DOUBLE ) )
{
assert( m_sbtCostSave[1] <= m_sbtCostSave[0] );
th *= ( m_sbtCostSave[0] / m_sbtCostSave[1] );
}
if( sbtOffCost > bestCost * th )
{
numSbtRdo = 0;
}
}
if( !sbtOffRootCbf && sbtOffCost != MAX_DOUBLE )
{
double th = Clip3( 0.05, 0.55, ( 27 - cu->qp ) * 0.02 + 0.35 );
if( sbtOffCost < m_pcRdCost->calcRdCost( ( cu->lwidth() * cu->lheight() ) << SCALE_BITS, 0 ) * th )
{
numSbtRdo = 0;
}
}
if( histBestSbt != MAX_UCHAR && numSbtRdo != 0 )
{
numSbtRdo = 1;
m_pcInterSearch->initSbtRdoOrder( CU::getSbtMode( CU::getSbtIdx( histBestSbt ), CU::getSbtPos( histBestSbt ) ) );
}
for( int sbtModeIdx = 0; sbtModeIdx < numSbtRdo; sbtModeIdx++ )
{
uint8_t sbtMode = m_pcInterSearch->getSbtRdoOrder( sbtModeIdx );
uint8_t sbtIdx = CU::getSbtIdxFromSbtMode( sbtMode );
uint8_t sbtPos = CU::getSbtPosFromSbtMode( sbtMode );
//fast algorithm (early skip, save & load)
if( histBestSbt == MAX_UCHAR )
{
uint8_t skipCode = m_pcInterSearch->skipSbtByRDCost( cu->lwidth(), cu->lheight(), cu->mtDepth, sbtIdx, sbtPos, bestCS->cost, sbtOffDist, sbtOffCost, sbtOffRootCbf );
if( skipCode != MAX_UCHAR )
{
continue;
}
if( sbtModeIdx > 0 )
{
uint8_t prevSbtMode = m_pcInterSearch->getSbtRdoOrder( sbtModeIdx - 1 );
//make sure the prevSbtMode is the same size as the current SBT mode (otherwise the estimated dist may not be comparable)
if( CU::isSameSbtSize( prevSbtMode, sbtMode ) )
{
Distortion currEstDist = m_pcInterSearch->getEstDistSbt( sbtMode );
Distortion prevEstDist = m_pcInterSearch->getEstDistSbt( prevSbtMode );
if( currEstDist > prevEstDist * 1.15 )
{
continue;
}
}
}
}
//init tempCS and TU
if( bestCost == bestCS->cost ) //The first EMT pass didn't become the bestCS, so we clear the TUs generated
{
tempCS->clearTUs();
}
else if( false == swapped )
{
tempCS->initStructData( encTestMode.qp, encTestMode.lossless );
tempCS->copyStructure( *bestCS, partitioner.chType );
tempCS->getPredBuf().copyFrom( bestCS->getPredBuf() );
bestCost = bestCS->cost;
cu = tempCS->getCU( partitioner.chType );
swapped = true;
}
else
{
tempCS->clearTUs();
bestCost = bestCS->cost;
cu = tempCS->getCU( partitioner.chType );
}
//we need to restart the distortion for the new tempCS, the bit count and the cost
tempCS->dist = 0;
tempCS->fracBits = 0;
tempCS->cost = MAX_DOUBLE;
cu->skip = false;
//set SBT info
cu->setSbtIdx( sbtIdx );
cu->setSbtPos( sbtPos );
//try residual coding
m_pcInterSearch->encodeResAndCalcRdInterCU( *tempCS, partitioner, skipResidual );
numRDOTried++;
xEncodeDontSplit( *tempCS, partitioner );
xCheckDQP( *tempCS, partitioner );
if( imvCS && ( tempCS->cost < imvCS->cost ) )
{
if( imvCS->cost != MAX_DOUBLE )
{
imvCS->initStructData( encTestMode.qp, encTestMode.lossless );
}
imvCS->copyStructure( *tempCS, partitioner.chType );
}
if( NULL != bestHasNonResi && ( bestCostInternal > tempCS->cost ) )
{
bestCostInternal = tempCS->cost;
if( !( tempCS->getPU( partitioner.chType )->mhIntraFlag ) )
*bestHasNonResi = !cu->rootCbf;
}
if( tempCS->cost < currBestCost )
{
currBestSbt = cu->sbtInfo;
currBestTrs = tempCS->tus[cu->sbtInfo ? cu->getSbtPos() : 0]->mtsIdx;
assert( currBestTrs == 0 || currBestTrs == 1 );
currBestCost = tempCS->cost;
}
#if WCG_EXT
DTRACE_MODE_COST( *tempCS, m_pcRdCost->getLambda( true ) );
#else
DTRACE_MODE_COST( *tempCS, m_pcRdCost->getLambda() );
#endif
xCheckBestMode( tempCS, bestCS, partitioner, encTestMode );
}
if( bestCostBegin != bestCS->cost )
{
m_sbtCostSave[0] = sbtOffCost;
m_sbtCostSave[1] = currBestCost;
}
} //end emt loop
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
#if JVET_M0140_SBT
if( histBestSbt == MAX_UCHAR && doPreAnalyzeResi && numRDOTried > 1 )
{
slsSbt->saveBestSbt( cu->cs->area, (uint32_t)( curPuSse >> slShift ), currBestSbt, currBestTrs );
}
#endif
#if JVET_M0140_SBT //harmonize with GBI fast algorithm (move the code here)
tempCS->cost = currBestCost;
if( ETM_INTER_ME == encTestMode.type )
{
if( equGBiCost != NULL )
{
if( tempCS->cost < ( *equGBiCost ) && cu->GBiIdx == GBI_DEFAULT )
{
( *equGBiCost ) = tempCS->cost;
}
}
else
{
CHECK( equGBiCost == NULL, "equGBiCost == NULL" );
}
if( tempCS->slice->getCheckLDC() && !cu->imv && cu->GBiIdx != GBI_DEFAULT && tempCS->cost < m_bestGbiCost[1] )
{
if( tempCS->cost < m_bestGbiCost[0] )
{
m_bestGbiCost[1] = m_bestGbiCost[0];
m_bestGbiCost[0] = tempCS->cost;
m_bestGbiIdx[1] = m_bestGbiIdx[0];
m_bestGbiIdx[0] = cu->GBiIdx;
}
else
{
m_bestGbiCost[1] = tempCS->cost;
m_bestGbiIdx[1] = cu->GBiIdx;
}
}
}
#endif

Karsten Suehring
committed
}
void EncCu::xEncodeDontSplit( CodingStructure &cs, Partitioner &partitioner )
{
m_CABACEstimator->resetBits();
#if JVET_M0421_SPLIT_SIG
m_CABACEstimator->split_cu_mode( CU_DONT_SPLIT, cs, partitioner );
#else

Karsten Suehring
committed
{
if( partitioner.canSplit( CU_QUAD_SPLIT, cs ) )
{
m_CABACEstimator->split_cu_flag( false, cs, partitioner );
}
if( partitioner.canSplit( CU_MT_SPLIT, cs ) )
{
m_CABACEstimator->split_cu_mode_mt( CU_DONT_SPLIT, cs, partitioner );
}
}

Karsten Suehring
committed
cs.fracBits += m_CABACEstimator->getEstFracBits(); // split bits
cs.cost = m_pcRdCost->calcRdCost( cs.fracBits, cs.dist );
}
#if REUSE_CU_RESULTS
void EncCu::xReuseCachedResult( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner )
{
const SPS &sps = *tempCS->sps;
BestEncInfoCache* bestEncCache = dynamic_cast<BestEncInfoCache*>( m_modeCtrl );
CHECK( !bestEncCache, "If this mode is chosen, mode controller has to implement the mode caching capabilities" );
EncTestMode cachedMode;
if( bestEncCache->setCsFrom( *tempCS, cachedMode, partitioner ) )
{
CodingUnit& cu = *tempCS->cus.front();
#if JVET_M0170_MRG_SHARELIST
cu.shareParentPos = tempCS->sharedBndPos;
cu.shareParentSize = tempCS->sharedBndSize;
#endif

Karsten Suehring
committed
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
partitioner.setCUData( cu );
if( CU::isIntra( cu ) )
{
xReconIntraQT( cu );
}
else
{
xDeriveCUMV( cu );
xReconInter( cu );
}
Distortion finalDistortion = 0;
const int numValidComponents = getNumberValidComponents( tempCS->area.chromaFormat );
for( int comp = 0; comp < numValidComponents; comp++ )
{
const ComponentID compID = ComponentID( comp );
if( CS::isDualITree( *tempCS ) && toChannelType( compID ) != partitioner.chType )
{
continue;
}
CPelBuf reco = tempCS->getRecoBuf( compID );
CPelBuf org = tempCS->getOrgBuf ( compID );
#if WCG_EXT
#if JVET_M0427_INLOOP_RESHAPER
if (m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() || (
m_pcEncCfg->getReshaper() && (tempCS->slice->getReshapeInfo().getUseSliceReshaper() && m_pcReshape->getCTUFlag())))
#else

Karsten Suehring
committed
if( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() )

Karsten Suehring
committed
{
const CPelBuf orgLuma = tempCS->getOrgBuf(tempCS->area.blocks[COMPONENT_Y]);
if (compID == COMPONENT_Y && (tempCS->slice->getReshapeInfo().getUseSliceReshaper() && m_pcReshape->getCTUFlag()))
{
const CompArea &area = cu.blocks[COMPONENT_Y];
CompArea tmpArea(COMPONENT_Y, area.chromaFormat, Position(0, 0), area.size());
PelBuf tmpRecLuma = m_tmpStorageLCU->getBuf(tmpArea);
tmpRecLuma.copyFrom(reco);
tmpRecLuma.rspSignal(m_pcReshape->getInvLUT());
finalDistortion += m_pcRdCost->getDistPart(org, tmpRecLuma, sps.getBitDepth(toChannelType(compID)), compID, DF_SSE_WTD, &orgLuma);
}
else
#endif

Karsten Suehring
committed
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
finalDistortion += m_pcRdCost->getDistPart( org, reco, sps.getBitDepth( toChannelType( compID ) ), compID, DF_SSE_WTD, &orgLuma );
}
else
#endif
finalDistortion += m_pcRdCost->getDistPart( org, reco, sps.getBitDepth( toChannelType( compID ) ), compID, DF_SSE );
}
m_CABACEstimator->getCtx() = m_CurrCtx->start;
m_CABACEstimator->resetBits();
CUCtx cuCtx;
cuCtx.isDQPCoded = true;
cuCtx.isChromaQpAdjCoded = true;
m_CABACEstimator->coding_unit( cu, partitioner, cuCtx );
tempCS->dist = finalDistortion;
tempCS->fracBits = m_CABACEstimator->getEstFracBits();
tempCS->cost = m_pcRdCost->calcRdCost( tempCS->fracBits, tempCS->dist );
xEncodeDontSplit( *tempCS, partitioner );
xCheckDQP ( *tempCS, partitioner );
xCheckBestMode ( tempCS, bestCS, partitioner, cachedMode );
}
else
{
THROW( "Should never happen!" );
}
}
#endif