Newer
Older

Karsten Suehring
committed
pu = encInfo.pu;
#if REUSE_CU_RESULTS_WITH_MULTIPLE_TUS
CHECKD( !( encInfo.numTus > 0 ), "Empty tus array" );
for( int i = 0; i < encInfo.numTus; i++ )
{
TransformUnit &tu = cs.addTU( encInfo.tus[i], partitioner.chType );
for( auto &blk : tu.blocks )
{
if( blk.valid() ) tu.copyComponentFrom( encInfo.tus[i], blk.compID );
}
}
#else

Karsten Suehring
committed
for( auto &blk : tu.blocks )
{
if( blk.valid() ) tu.copyComponentFrom( encInfo.tu, blk.compID );
}

Karsten Suehring
committed
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
testMode = encInfo.testMode;
return true;
}
#endif
static bool interHadActive( const ComprCUCtx& ctx )
{
return ctx.interHad != 0;
}
//////////////////////////////////////////////////////////////////////////
// EncModeCtrlQTBT
//////////////////////////////////////////////////////////////////////////
EncModeCtrlMTnoRQT::EncModeCtrlMTnoRQT()
{
#if !REUSE_CU_RESULTS
CacheBlkInfoCtrl::create();
#endif
}
EncModeCtrlMTnoRQT::~EncModeCtrlMTnoRQT()
{
#if !REUSE_CU_RESULTS
CacheBlkInfoCtrl::destroy();
#endif
}
#if REUSE_CU_RESULTS
void EncModeCtrlMTnoRQT::create( const EncCfg& cfg )
{
CacheBlkInfoCtrl::create();
BestEncInfoCache::create( cfg.getChromaFormatIdc() );
#if JVET_M0140_SBT
SaveLoadEncInfoSbt::create();
#endif

Karsten Suehring
committed
}
void EncModeCtrlMTnoRQT::destroy()
{
CacheBlkInfoCtrl::destroy();
BestEncInfoCache::destroy();
#if JVET_M0140_SBT
SaveLoadEncInfoSbt::destroy();
#endif

Karsten Suehring
committed
}
#endif
void EncModeCtrlMTnoRQT::initCTUEncoding( const Slice &slice )
{
CacheBlkInfoCtrl::init( slice );
#if REUSE_CU_RESULTS
BestEncInfoCache::init( slice );
#endif
#if JVET_M0140_SBT
SaveLoadEncInfoSbt::init( slice );
#endif

Karsten Suehring
committed
CHECK( !m_ComprCUCtxList.empty(), "Mode list is not empty at the beginning of a CTU" );
m_slice = &slice;
#if ENABLE_SPLIT_PARALLELISM
m_runNextInParallel = false;
#endif
if( m_pcEncCfg->getUseE0023FastEnc() )
{
if (m_pcEncCfg->getUseCompositeRef())
m_skipThreshold = ( ( slice.getMinPictureDistance() <= PICTURE_DISTANCE_TH * 2 ) ? FAST_SKIP_DEPTH : SKIP_DEPTH );
else
m_skipThreshold = ((slice.getMinPictureDistance() <= PICTURE_DISTANCE_TH) ? FAST_SKIP_DEPTH : SKIP_DEPTH);

Karsten Suehring
committed
}
else
{
m_skipThreshold = SKIP_DEPTH;
}
}
void EncModeCtrlMTnoRQT::initCULevel( Partitioner &partitioner, const CodingStructure& cs )
{
// Min/max depth
unsigned minDepth = 0;
unsigned maxDepth = g_aucLog2[cs.sps->getCTUSize()] - g_aucLog2[cs.sps->getMinQTSize( m_slice->getSliceType(), partitioner.chType )];

Karsten Suehring
committed
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
if( m_pcEncCfg->getUseFastLCTU() )
{
if( auto adPartitioner = dynamic_cast<AdaptiveDepthPartitioner*>( &partitioner ) )
{
// LARGE CTU
adPartitioner->setMaxMinDepth( minDepth, maxDepth, cs );
}
}
m_ComprCUCtxList.push_back( ComprCUCtx( cs, minDepth, maxDepth, NUM_EXTRA_FEATURES ) );
#if ENABLE_SPLIT_PARALLELISM
if( m_runNextInParallel )
{
for( auto &level : m_ComprCUCtxList )
{
CHECK( level.isLevelSplitParallel, "Tring to parallelize a level within parallel execution!" );
}
CHECK( cs.picture->scheduler.getSplitJobId() == 0, "Trying to run a parallel level although jobId is 0!" );
m_runNextInParallel = false;
m_ComprCUCtxList.back().isLevelSplitParallel = true;
}
#endif
const CodingUnit* cuLeft = cs.getCU( cs.area.blocks[partitioner.chType].pos().offset( -1, 0 ), partitioner.chType );
const CodingUnit* cuAbove = cs.getCU( cs.area.blocks[partitioner.chType].pos().offset( 0, -1 ), partitioner.chType );
const bool qtBeforeBt = ( ( cuLeft && cuAbove && cuLeft ->qtDepth > partitioner.currQtDepth && cuAbove->qtDepth > partitioner.currQtDepth )
|| ( cuLeft && !cuAbove && cuLeft ->qtDepth > partitioner.currQtDepth )
|| ( !cuLeft && cuAbove && cuAbove->qtDepth > partitioner.currQtDepth )
|| ( !cuAbove && !cuLeft && cs.area.lwidth() >= ( 32 << cs.slice->getDepth() ) ) )
&& ( cs.area.lwidth() > ( cs.pcv->getMinQtSize( *cs.slice, partitioner.chType ) << 1 ) );
// set features
ComprCUCtx &cuECtx = m_ComprCUCtxList.back();
cuECtx.set( BEST_NON_SPLIT_COST, MAX_DOUBLE );
cuECtx.set( BEST_VERT_SPLIT_COST, MAX_DOUBLE );
cuECtx.set( BEST_HORZ_SPLIT_COST, MAX_DOUBLE );
cuECtx.set( BEST_TRIH_SPLIT_COST, MAX_DOUBLE );
cuECtx.set( BEST_TRIV_SPLIT_COST, MAX_DOUBLE );
cuECtx.set( DO_TRIH_SPLIT, cs.sps->getMTTMode() & 1 );
cuECtx.set( DO_TRIV_SPLIT, cs.sps->getMTTMode() & 1 );

Karsten Suehring
committed
cuECtx.set( BEST_IMV_COST, MAX_DOUBLE * .5 );
cuECtx.set( BEST_NO_IMV_COST, MAX_DOUBLE * .5 );
cuECtx.set( QT_BEFORE_BT, qtBeforeBt );
cuECtx.set( DID_QUAD_SPLIT, false );
cuECtx.set( IS_BEST_NOSPLIT_SKIP, false );
cuECtx.set( MAX_QT_SUB_DEPTH, 0 );
// QP
int baseQP = cs.baseQP;
if( m_pcEncCfg->getUseAdaptiveQP() )
{

Christian Helmrich
committed
if (!CS::isDualITree(cs) || isLuma(partitioner.chType))
{
baseQP = Clip3(-cs.sps->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, baseQP + xComputeDQP(cs, partitioner));
}

Karsten Suehring
committed
}

Christian Helmrich
committed

Karsten Suehring
committed
int minQP = baseQP;
int maxQP = baseQP;
#if SHARP_LUMA_DELTA_QP
if( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() )
{
if( partitioner.currDepth <= cs.pps->getMaxCuDQPDepth() )
{
CompArea clipedArea = clipArea( cs.area.Y(), cs.picture->Y() );
// keep using the same m_QP_LUMA_OFFSET in the same CTU
m_lumaQPOffset = calculateLumaDQP( cs.getOrgBuf( clipedArea ) );
}
}
#endif
xGetMinMaxQP( minQP, maxQP, cs, partitioner, baseQP, *cs.sps, *cs.pps, true );
IbcLumaCoverage ibcLumaCoverage = cs.getIbcLumaCoverage(cs.area.Cb());
switch (ibcLumaCoverage)
case IBC_LUMA_COVERAGE_PARTIAL:
// do not check IBC
checkIbc = false;
case IBC_LUMA_COVERAGE_NONE:
// do not check IBC
checkIbc = false;

Karsten Suehring
committed
// Add coding modes here
// NOTE: Working back to front, as a stack, which is more efficient with the container
// NOTE: First added modes will be processed at the end.
//////////////////////////////////////////////////////////////////////////
// Add unit split modes
if( !cuECtx.get<bool>( QT_BEFORE_BT ) )
{
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_QT, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
}
if( partitioner.canSplit( CU_TRIV_SPLIT, cs ) )
{
// add split modes
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_TT_V, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
}
if( partitioner.canSplit( CU_TRIH_SPLIT, cs ) )
{
// add split modes
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_TT_H, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
}
if( partitioner.canSplit( CU_VERT_SPLIT, cs ) )
{
// add split modes
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_BT_V, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
m_ComprCUCtxList.back().set( DID_VERT_SPLIT, true );
}
else
{
m_ComprCUCtxList.back().set( DID_VERT_SPLIT, false );
}
if( partitioner.canSplit( CU_HORZ_SPLIT, cs ) )
{
// add split modes
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_BT_H, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
m_ComprCUCtxList.back().set( DID_HORZ_SPLIT, true );
}
else
{
m_ComprCUCtxList.back().set( DID_HORZ_SPLIT, false );
}
if( cuECtx.get<bool>( QT_BEFORE_BT ) )
{
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_QT, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
}
}
m_ComprCUCtxList.back().testModes.push_back( { ETM_POST_DONT_SPLIT } );
xGetMinMaxQP( minQP, maxQP, cs, partitioner, baseQP, *cs.sps, *cs.pps, false );
bool useLossless = false;
int lowestQP = minQP;
if( cs.pps->getTransquantBypassEnabledFlag() )
{
useLossless = true; // mark that the first iteration is to cost TQB mode.
minQP = minQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs
if( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
{
maxQP = minQP;
}
}
//////////////////////////////////////////////////////////////////////////
// Add unit coding modes: Intra, InterME, InterMerge ...
for( int qpLoop = maxQP; qpLoop >= minQP; qpLoop-- )
{
const int qp = std::max( qpLoop, lowestQP );
const bool lossless = useLossless && qpLoop == minQP;
const bool isReusingCu = isValid( cs, partitioner, qp );
cuECtx.set( IS_REUSING_CU, isReusingCu );
if( isReusingCu )
{
m_ComprCUCtxList.back().testModes.push_back( {ETM_RECO_CACHED, ETO_STANDARD, qp, lossless} );
}
#endif

Karsten Suehring
committed
// add intra modes
m_ComprCUCtxList.back().testModes.push_back( { ETM_IPCM, ETO_STANDARD, qp, lossless } );
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTRA, ETO_STANDARD, qp, lossless } );
#if JVET_M0483_IBC
if (cs.sps->getIBCFlag() && checkIbc)
#else
if (cs.sps->getIBCMode() && checkIbc )
m_ComprCUCtxList.back().testModes.push_back({ ETM_IBC, ETO_STANDARD, qp, lossless });
m_ComprCUCtxList.back().testModes.push_back({ ETM_IBC_MERGE, ETO_STANDARD, qp, lossless });

Karsten Suehring
committed
}
// add first pass modes

Karsten Suehring
committed
{
for( int qpLoop = maxQP; qpLoop >= minQP; qpLoop-- )
{
const int qp = std::max( qpLoop, lowestQP );
const bool lossless = useLossless && qpLoop == minQP;
#if JVET_M0246_AFFINE_AMVR
if( m_pcEncCfg->getIMV() || m_pcEncCfg->getUseAffineAmvr() )
#else

Karsten Suehring
committed
if( m_pcEncCfg->getIMV() )

Karsten Suehring
committed
{
#if JVET_M0246_AFFINE_AMVR
if( m_pcEncCfg->getIMV() == IMV_4PEL || m_pcEncCfg->getUseAffineAmvr() )
#else

Karsten Suehring
committed
if( m_pcEncCfg->getIMV() == IMV_4PEL )

Karsten Suehring
committed
{
int imv = m_pcEncCfg->getIMV4PelFast() ? 3 : 2;
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTER_ME, EncTestModeOpts( imv << ETO_IMV_SHIFT ), qp, lossless } );

Karsten Suehring
committed
}
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTER_ME, EncTestModeOpts( 1 << ETO_IMV_SHIFT ), qp, lossless } );

Karsten Suehring
committed
}
// add inter modes
if( m_pcEncCfg->getUseEarlySkipDetection() )
{
if( cs.sps->getUseTriangle() && cs.slice->isInterB() )
m_ComprCUCtxList.back().testModes.push_back( { ETM_MERGE_TRIANGLE, ETO_STANDARD, qp, lossless } );
m_ComprCUCtxList.back().testModes.push_back( { ETM_MERGE_SKIP, ETO_STANDARD, qp, lossless } );
if ( cs.sps->getUseAffine() || cs.sps->getSBTMVPEnabledFlag() )

Karsten Suehring
committed
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_AFFINE, ETO_STANDARD, qp, lossless } );

Karsten Suehring
committed
}
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTER_ME, ETO_STANDARD, qp, lossless } );

Karsten Suehring
committed
}
else
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTER_ME, ETO_STANDARD, qp, lossless } );
if( cs.sps->getUseTriangle() && cs.slice->isInterB() )
m_ComprCUCtxList.back().testModes.push_back( { ETM_MERGE_TRIANGLE, ETO_STANDARD, qp, lossless } );
m_ComprCUCtxList.back().testModes.push_back( { ETM_MERGE_SKIP, ETO_STANDARD, qp, lossless } );
if ( cs.sps->getUseAffine() || cs.sps->getSBTMVPEnabledFlag() )

Karsten Suehring
committed
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_AFFINE, ETO_STANDARD, qp, lossless } );

Karsten Suehring
committed
}
}
#if JVET_M0253_HASH_ME
if (m_pcEncCfg->getUseHashME())
{
if ((cs.area.lwidth() == cs.area.lheight() && cs.area.lwidth() <= 64 && cs.area.lwidth() >= 4) || (cs.area.lwidth() == 4 && cs.area.lheight() == 8) || (cs.area.lwidth() == 8 && cs.area.lheight() == 4))
{
m_ComprCUCtxList.back().testModes.push_back({ ETM_HASH_INTER, ETO_STANDARD, qp, lossless });
}
}
#endif

Karsten Suehring
committed
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
}
}
// ensure to skip unprobable modes
if( !tryModeMaster( m_ComprCUCtxList.back().testModes.back(), cs, partitioner ) )
{
nextMode( cs, partitioner );
}
m_ComprCUCtxList.back().lastTestMode = EncTestMode();
}
void EncModeCtrlMTnoRQT::finishCULevel( Partitioner &partitioner )
{
m_ComprCUCtxList.pop_back();
}
bool EncModeCtrlMTnoRQT::tryMode( const EncTestMode& encTestmode, const CodingStructure &cs, Partitioner& partitioner )
{
ComprCUCtx& cuECtx = m_ComprCUCtxList.back();
// Fast checks, partitioning depended
#if JVET_M0253_HASH_ME
if (cuECtx.isHashPerfectMatch && encTestmode.type != ETM_MERGE_SKIP && encTestmode.type != ETM_AFFINE && encTestmode.type != ETM_MERGE_TRIANGLE)
{
return false;
}
#endif

Karsten Suehring
committed
// if early skip detected, skip all modes checking but the splits
if( cuECtx.earlySkip && m_pcEncCfg->getUseEarlySkipDetection() && !isModeSplit( encTestmode ) && !( isModeInter( encTestmode ) ) )

Karsten Suehring
committed
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
{
return false;
}
const PartSplit implicitSplit = partitioner.getImplicitSplit( cs );
const bool isBoundary = implicitSplit != CU_DONT_SPLIT;
if( isBoundary && encTestmode.type != ETM_SPLIT_QT )
{
return getPartSplit( encTestmode ) == implicitSplit;
}
else if( isBoundary && encTestmode.type == ETM_SPLIT_QT )
{
return partitioner.canSplit( CU_QUAD_SPLIT, cs );
}
#if REUSE_CU_RESULTS
if( cuECtx.get<bool>( IS_REUSING_CU ) )
{
if( encTestmode.type == ETM_RECO_CACHED )
{
return true;
}
if( isModeNoSplit( encTestmode ) )
{
return false;
}
}
#endif
const Slice& slice = *m_slice;
const SPS& sps = *slice.getSPS();
const uint32_t numComp = getNumberValidComponents( slice.getSPS()->getChromaFormatIdc() );
const uint32_t width = partitioner.currArea().lumaSize().width;
const CodingStructure *bestCS = cuECtx.bestCS;
const CodingUnit *bestCU = cuECtx.bestCU;
const EncTestMode bestMode = bestCS ? getCSEncMode( *bestCS ) : EncTestMode();
CodedCUInfo &relatedCU = getBlkInfo( partitioner.currArea() );
if( cuECtx.minDepth > partitioner.currQtDepth && partitioner.canSplit( CU_QUAD_SPLIT, cs ) )
{
// enforce QT
return encTestmode.type == ETM_SPLIT_QT;
}
else if( encTestmode.type == ETM_SPLIT_QT && cuECtx.maxDepth <= partitioner.currQtDepth )
{
// don't check this QT depth
return false;
}
if( bestCS && bestCS->cus.size() == 1 )
{
// update the best non-split cost
cuECtx.set( BEST_NON_SPLIT_COST, bestCS->cost );
}
if( encTestmode.type == ETM_INTRA )
{
if( getFastDeltaQp() )
{
if( cs.area.lumaSize().width > cs.pcv->fastDeltaQPCuMaxSize )
{
return false; // only check necessary 2Nx2N Intra in fast delta-QP mode
}
}
if( m_pcEncCfg->getUseFastLCTU() && partitioner.currArea().lumaSize().area() > 4096 )
{
return false;
}
if (CS::isDualITree(cs) && (partitioner.currArea().lumaSize().width > 64 || partitioner.currArea().lumaSize().height > 64))
{
return false;
}
if (m_pcEncCfg->getUsePbIntraFast() && (!cs.slice->isIntra() || cs.slice->getSPS()->getIBCFlag()) && !interHadActive(cuECtx) && cuECtx.bestCU && !CU::isIntra(*cuECtx.bestCU))

Karsten Suehring
committed
if( m_pcEncCfg->getUsePbIntraFast() && !cs.slice->isIntra() && !interHadActive( cuECtx ) && cuECtx.bestCU && CU::isInter( *cuECtx.bestCU ) )

Karsten Suehring
committed
{
return false;
}
// INTRA MODES
#if JVET_M0483_IBC
if (cs.sps->getIBCFlag() && !cuECtx.bestTU)
#else
if (cs.sps->getIBCMode() && !cuECtx.bestTU)

Karsten Suehring
committed
CHECK( !slice.isIntra() && !cuECtx.bestTU, "No possible non-intra encoding for a P- or B-slice found" );
if( !( slice.isIRAP() || bestMode.type == ETM_INTRA ||
((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && (!relatedCU.isInter || !relatedCU.isIBC) && (
( ( !m_pcEncCfg->getDisableIntraPUsInInterSlices() ) && !relatedCU.isInter && (
#endif

Karsten Suehring
committed
( cuECtx.bestTU->cbf[0] != 0 ) ||
( ( numComp > COMPONENT_Cb ) && cuECtx.bestTU->cbf[1] != 0 ) ||
( ( numComp > COMPONENT_Cr ) && cuECtx.bestTU->cbf[2] != 0 ) // avoid very complex intra if it is unlikely
) ) ) )
{
return false;
}
if ((m_pcEncCfg->getIBCFastMethod() & IBC_FAST_METHOD_NOINTRA_IBCCBF0)
&& (bestMode.type == ETM_IBC || bestMode.type == ETM_IBC_MERGE)
&& (!cuECtx.bestCU->Y().valid() || cuECtx.bestTU->cbf[0] == 0)
&& (!cuECtx.bestCU->Cb().valid() || cuECtx.bestTU->cbf[1] == 0)
&& (!cuECtx.bestCU->Cr().valid() || cuECtx.bestTU->cbf[2] == 0))
{
return false;
}

Karsten Suehring
committed
if( lastTestMode().type != ETM_INTRA && cuECtx.bestCS && cuECtx.bestCU && interHadActive( cuECtx ) )
{
// Get SATD threshold from best Inter-CU
if( !cs.slice->isIRAP() && m_pcEncCfg->getUsePbIntraFast() )

Karsten Suehring
committed
{
CodingUnit* bestCU = cuECtx.bestCU;

Karsten Suehring
committed
if( bestCU && CU::isInter( *bestCU ) )

Karsten Suehring
committed
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
{
DistParam distParam;
const bool useHad = !bestCU->transQuantBypass;
m_pcRdCost->setDistParam( distParam, cs.getOrgBuf( COMPONENT_Y ), cuECtx.bestCS->getPredBuf( COMPONENT_Y ), cs.sps->getBitDepth( CHANNEL_TYPE_LUMA ), COMPONENT_Y, useHad );
cuECtx.interHad = distParam.distFunc( distParam );
}
}
}
return true;
}
else if( encTestmode.type == ETM_IPCM )
{
if( getFastDeltaQp() )
{
const SPS &sps = *cs.sps;
const uint32_t fastDeltaQPCuMaxPCMSize = Clip3( ( uint32_t ) 1 << sps.getPCMLog2MinSize(), ( uint32_t ) 1 << sps.getPCMLog2MaxSize(), 32u );
if( cs.area.lumaSize().width > fastDeltaQPCuMaxPCMSize )
{
return false; // only check necessary PCM in fast deltaqp mode
}
}
// PCM MODES
return sps.getPCMEnabledFlag() && width <= ( 1 << sps.getPCMLog2MaxSize() ) && width >= ( 1 << sps.getPCMLog2MinSize() );

Karsten Suehring
committed
}
else if (encTestmode.type == ETM_IBC || encTestmode.type == ETM_IBC_MERGE)
#if JVET_M0483_IBC
return sps.getIBCFlag() && width <= IBC_MAX_CAND_SIZE && partitioner.currArea().lumaSize().height <= IBC_MAX_CAND_SIZE;
#else
return sps.getIBCMode() && width <= IBC_MAX_CAND_SIZE && partitioner.currArea().lumaSize().height <= IBC_MAX_CAND_SIZE;

Karsten Suehring
committed
else if( isModeInter( encTestmode ) )
{
// INTER MODES (ME + MERGE/SKIP)
CHECK( slice.isIntra(), "Inter-mode should not be in the I-Slice mode list!" );
if( getFastDeltaQp() )
{
if( encTestmode.type == ETM_MERGE_SKIP )
{
return false;
}
if( cs.area.lumaSize().width > cs.pcv->fastDeltaQPCuMaxSize )

Karsten Suehring
committed
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
{
return false; // only check necessary 2Nx2N Inter in fast deltaqp mode
}
}
// --- Check if we can quit current mode using SAVE/LOAD coding history
if( encTestmode.type == ETM_INTER_ME )
{
if( encTestmode.opts == ETO_STANDARD )
{
// NOTE: ETO_STANDARD is always done when early SKIP mode detection is enabled
if( !m_pcEncCfg->getUseEarlySkipDetection() )
{
if( relatedCU.isSkip || relatedCU.isIntra )
{
return false;
}
}
}
else if ((encTestmode.opts & ETO_IMV) != 0)
{
int imvOpt = (encTestmode.opts & ETO_IMV) >> ETO_IMV_SHIFT;
if (imvOpt == 3 && cuECtx.get<double>(BEST_NO_IMV_COST) * 1.06 < cuECtx.get<double>(BEST_IMV_COST))
{
#if JVET_M0246_AFFINE_AMVR
if ( !m_pcEncCfg->getUseAffineAmvr() )
#endif

Karsten Suehring
committed
return false;
}
}
}
if ( encTestmode.type == ETM_AFFINE && relatedCU.isIntra )
{
return false;
}
if( encTestmode.type == ETM_MERGE_TRIANGLE && ( partitioner.currArea().lumaSize().area() < TRIANGLE_MIN_SIZE || relatedCU.isIntra ) )
return false;
}

Karsten Suehring
committed
return true;
}
else if( isModeSplit( encTestmode ) )
{
//////////////////////////////////////////////////////////////////////////
// skip-history rule - don't split further if at least for three past levels
// in the split tree it was found that skip is the best mode
//////////////////////////////////////////////////////////////////////////
int skipScore = 0;
if ((!slice.isIntra() || slice.getSPS()->getIBCFlag()) && cuECtx.get<bool>(IS_BEST_NOSPLIT_SKIP))

Karsten Suehring
committed
if( !slice.isIntra() && cuECtx.get<bool>( IS_BEST_NOSPLIT_SKIP ) )

Karsten Suehring
committed
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
{
for( int i = 2; i < m_ComprCUCtxList.size(); i++ )
{
if( ( m_ComprCUCtxList.end() - i )->get<bool>( IS_BEST_NOSPLIT_SKIP ) )
{
skipScore += 1;
}
else
{
break;
}
}
}
const PartSplit split = getPartSplit( encTestmode );
if( !partitioner.canSplit( split, cs ) || skipScore >= 2 )
{
if( split == CU_HORZ_SPLIT ) cuECtx.set( DID_HORZ_SPLIT, false );
if( split == CU_VERT_SPLIT ) cuECtx.set( DID_VERT_SPLIT, false );
if( split == CU_QUAD_SPLIT ) cuECtx.set( DID_QUAD_SPLIT, false );
return false;
}
if( m_pcEncCfg->getUseContentBasedFastQtbt() )
{
const CompArea& currArea = partitioner.currArea().Y();
int cuHeight = currArea.height;
int cuWidth = currArea.width;
const bool condIntraInter = m_pcEncCfg->getIntraPeriod() == 1 ? ( partitioner.currBtDepth == 0 ) : ( cuHeight > 32 && cuWidth > 32 );
if( cuWidth == cuHeight && condIntraInter && getPartSplit( encTestmode ) != CU_QUAD_SPLIT )
{
const CPelBuf bufCurrArea = cs.getOrgBuf( partitioner.currArea().block( COMPONENT_Y ) );
double horVal = 0;
double verVal = 0;
double dupVal = 0;
double dowVal = 0;
const double th = m_pcEncCfg->getIntraPeriod() == 1 ? 1.2 : 1.0;
unsigned j, k;
for( j = 0; j < cuWidth - 1; j++ )
{
for( k = 0; k < cuHeight - 1; k++ )
{
horVal += abs( bufCurrArea.at( j + 1, k ) - bufCurrArea.at( j, k ) );
verVal += abs( bufCurrArea.at( j , k + 1 ) - bufCurrArea.at( j, k ) );
dowVal += abs( bufCurrArea.at( j + 1, k ) - bufCurrArea.at( j, k + 1 ) );
dupVal += abs( bufCurrArea.at( j + 1, k + 1 ) - bufCurrArea.at( j, k ) );
}
}
if( horVal > th * verVal && sqrt( 2 ) * horVal > th * dowVal && sqrt( 2 ) * horVal > th * dupVal && ( getPartSplit( encTestmode ) == CU_HORZ_SPLIT || getPartSplit( encTestmode ) == CU_TRIH_SPLIT ) )
{
return false;
}
if( th * dupVal < sqrt( 2 ) * verVal && th * dowVal < sqrt( 2 ) * verVal && th * horVal < verVal && ( getPartSplit( encTestmode ) == CU_VERT_SPLIT || getPartSplit( encTestmode ) == CU_TRIV_SPLIT ) )
{
return false;
}
}
if( m_pcEncCfg->getIntraPeriod() == 1 && cuWidth <= 32 && cuHeight <= 32 && bestCS && bestCS->tus.size() == 1 && bestCU && bestCU->depth == partitioner.currDepth && partitioner.currBtDepth > 1 && isLuma( partitioner.chType ) )
{
if( !bestCU->rootCbf )
{
return false;
}
}
}
if( bestCU && bestCU->skip && bestCU->mtDepth >= m_skipThreshold && !isModeSplit( cuECtx.lastTestMode ) )
{
return false;
}
int featureToSet = -1;
switch( getPartSplit( encTestmode ) )
{
case CU_QUAD_SPLIT:
{
#if ENABLE_SPLIT_PARALLELISM
if( !cuECtx.isLevelSplitParallel )
#endif
if( !cuECtx.get<bool>( QT_BEFORE_BT ) && bestCU )
{
unsigned maxBTD = cs.pcv->getMaxBtDepth( slice, partitioner.chType );
const CodingUnit *cuBR = bestCS->cus.back();
unsigned height = partitioner.currArea().lumaSize().height;

Karsten Suehring
committed
if (bestCU && ((bestCU->btDepth == 0 && maxBTD >= ((slice.isIntra() && !slice.getSPS()->getIBCFlag()) ? 3 : 2))
|| (bestCU->btDepth == 1 && cuBR && cuBR->btDepth == 1 && maxBTD >= ((slice.isIntra() && !slice.getSPS()->getIBCFlag()) ? 4 : 3)))
&& (width <= MAX_TU_SIZE_FOR_PROFILE && height <= MAX_TU_SIZE_FOR_PROFILE)
&& cuECtx.get<bool>(DID_HORZ_SPLIT) && cuECtx.get<bool>(DID_VERT_SPLIT))
{
return false;
}
#else

Karsten Suehring
committed
if( bestCU && ( ( bestCU->btDepth == 0 && maxBTD >= ( slice.isIntra() ? 3 : 2 ) )
|| ( bestCU->btDepth == 1 && cuBR && cuBR->btDepth == 1 && maxBTD >= ( slice.isIntra() ? 4 : 3 ) ) )
Xiang Li
committed
&& ( width <= MAX_TU_SIZE_FOR_PROFILE && height <= MAX_TU_SIZE_FOR_PROFILE )

Karsten Suehring
committed
&& cuECtx.get<bool>( DID_HORZ_SPLIT ) && cuECtx.get<bool>( DID_VERT_SPLIT ) )
{
return false;
}

Karsten Suehring
committed
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
}
if( m_pcEncCfg->getUseEarlyCU() && bestCS->cost != MAX_DOUBLE && bestCU && bestCU->skip )
{
return false;
}
if( getFastDeltaQp() && width <= slice.getPPS()->pcv->fastDeltaQPCuMaxSize )
{
return false;
}
}
break;
case CU_HORZ_SPLIT:
featureToSet = DID_HORZ_SPLIT;
break;
case CU_VERT_SPLIT:
featureToSet = DID_VERT_SPLIT;
break;
case CU_TRIH_SPLIT:
if( cuECtx.get<bool>( DID_HORZ_SPLIT ) && bestCU && bestCU->btDepth == partitioner.currBtDepth && !bestCU->rootCbf )
{
return false;
}
if( !cuECtx.get<bool>( DO_TRIH_SPLIT ) )
{
return false;
}
break;
case CU_TRIV_SPLIT:
if( cuECtx.get<bool>( DID_VERT_SPLIT ) && bestCU && bestCU->btDepth == partitioner.currBtDepth && !bestCU->rootCbf )
{
return false;
}
if( !cuECtx.get<bool>( DO_TRIV_SPLIT ) )
{
return false;
}
break;
default:
THROW( "Only CU split modes are governed by the EncModeCtrl" );
return false;
break;
}
switch( split )
{
case CU_HORZ_SPLIT:
case CU_TRIH_SPLIT:
if( cuECtx.get<bool>( QT_BEFORE_BT ) && cuECtx.get<bool>( DID_QUAD_SPLIT ) )
{
if( cuECtx.get<int>( MAX_QT_SUB_DEPTH ) > partitioner.currQtDepth + 1 )
{
if( featureToSet >= 0 ) cuECtx.set( featureToSet, false );
return false;
}
}
break;
case CU_VERT_SPLIT:
case CU_TRIV_SPLIT:
if( cuECtx.get<bool>( QT_BEFORE_BT ) && cuECtx.get<bool>( DID_QUAD_SPLIT ) )
{
if( cuECtx.get<int>( MAX_QT_SUB_DEPTH ) > partitioner.currQtDepth + 1 )
{
if( featureToSet >= 0 ) cuECtx.set( featureToSet, false );
return false;
}
}
break;
default:
break;
}
if( split == CU_QUAD_SPLIT ) cuECtx.set( DID_QUAD_SPLIT, true );
return true;
}
else
{
CHECK( encTestmode.type != ETM_POST_DONT_SPLIT, "Unknown mode" );
if( !bestCS || ( bestCS && isModeSplit( bestMode ) ) )
{
return false;
}
else
{
#if REUSE_CU_RESULTS
setFromCs( *bestCS, partitioner );
#endif
// assume the non-split modes are done and set the marks for the best found mode
if( bestCS && bestCU )
{
if( CU::isInter( *bestCU ) )
{
relatedCU.isInter = true;
#if HM_CODED_CU_INFO
relatedCU.isSkip |= bestCU->skip;
relatedCU.isMMVDSkip |= bestCU->mmvdSkip;

Karsten Suehring
committed
#else
relatedCU.isSkip = bestCU->skip;
#endif
relatedCU.GBiIdx = bestCU->GBiIdx;

Karsten Suehring
committed
}
else if (CU::isIBC(*bestCU))
{
relatedCU.isIBC = true;
#if HM_CODED_CU_INFO
relatedCU.isSkip |= bestCU->skip;
#endif
}
#endif

Karsten Suehring
committed
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
else if( CU::isIntra( *bestCU ) )
{
relatedCU.isIntra = true;
}
#if ENABLE_SPLIT_PARALLELISM
touch( partitioner.currArea() );
#endif
cuECtx.set( IS_BEST_NOSPLIT_SKIP, bestCU->skip );
}
}
return false;
}
}
bool EncModeCtrlMTnoRQT::useModeResult( const EncTestMode& encTestmode, CodingStructure*& tempCS, Partitioner& partitioner )
{
xExtractFeatures( encTestmode, *tempCS );
ComprCUCtx& cuECtx = m_ComprCUCtxList.back();
if( encTestmode.type == ETM_SPLIT_BT_H )
{
cuECtx.set( BEST_HORZ_SPLIT_COST, tempCS->cost );
}
else if( encTestmode.type == ETM_SPLIT_BT_V )
{
cuECtx.set( BEST_VERT_SPLIT_COST, tempCS->cost );
}
else if( encTestmode.type == ETM_SPLIT_TT_H )
{
cuECtx.set( BEST_TRIH_SPLIT_COST, tempCS->cost );
}
else if( encTestmode.type == ETM_SPLIT_TT_V )
{
cuECtx.set( BEST_TRIV_SPLIT_COST, tempCS->cost );
}

Karsten Suehring
committed
{
const CodingUnit cu = *tempCS->getCU( partitioner.chType );
if( !cu.emtFlag )
{
cuECtx.bestEmtSize2Nx2N1stPass = tempCS->cost;
}
#if JVET_M0102_INTRA_SUBPARTITIONS
if (!cu.ispMode)
{
cuECtx.bestCostEmtFirstPassNoIsp = tempCS->cost;
}
#endif

Karsten Suehring
committed
}

Karsten Suehring
committed
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
if( m_pcEncCfg->getIMV4PelFast() && m_pcEncCfg->getIMV() && encTestmode.type == ETM_INTER_ME )
{
int imvMode = ( encTestmode.opts & ETO_IMV ) >> ETO_IMV_SHIFT;
if( imvMode == 1 )
{
if( tempCS->cost < cuECtx.get<double>( BEST_IMV_COST ) )
{
cuECtx.set( BEST_IMV_COST, tempCS->cost );
}
}
else if( imvMode == 0 )
{
if( tempCS->cost < cuECtx.get<double>( BEST_NO_IMV_COST ) )
{
cuECtx.set( BEST_NO_IMV_COST, tempCS->cost );
}
}
}
if( encTestmode.type == ETM_SPLIT_QT )
{
int maxQtD = 0;
for( const auto& cu : tempCS->cus )
{
maxQtD = std::max<int>( maxQtD, cu->qtDepth );
}
cuECtx.set( MAX_QT_SUB_DEPTH, maxQtD );
}
if( ( tempCS->sps->getMTTMode() & 1 ) == 1 )

Karsten Suehring
committed
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
{
int maxMtD = tempCS->pcv->getMaxBtDepth( *tempCS->slice, partitioner.chType ) + partitioner.currImplicitBtDepth;
if( encTestmode.type == ETM_SPLIT_BT_H )
{
if( tempCS->cus.size() > 2 )
{
int h_2 = tempCS->area.blocks[partitioner.chType].height / 2;
int cu1_h = tempCS->cus.front()->blocks[partitioner.chType].height;
int cu2_h = tempCS->cus.back() ->blocks[partitioner.chType].height;
cuECtx.set( DO_TRIH_SPLIT, cu1_h < h_2 || cu2_h < h_2 || partitioner.currMtDepth + 1 == maxMtD );
}
}
else if( encTestmode.type == ETM_SPLIT_BT_V )
{
if( tempCS->cus.size() > 2 )
{
int w_2 = tempCS->area.blocks[partitioner.chType].width / 2;
int cu1_w = tempCS->cus.front()->blocks[partitioner.chType].width;
int cu2_w = tempCS->cus.back() ->blocks[partitioner.chType].width;
cuECtx.set( DO_TRIV_SPLIT, cu1_w < w_2 || cu2_w < w_2 || partitioner.currMtDepth + 1 == maxMtD );
}
}
}
// for now just a simple decision based on RD-cost or choose tempCS if bestCS is not yet coded
if( !cuECtx.bestCS || tempCS->features[ENC_FT_RD_COST] < cuECtx.bestCS->features[ENC_FT_RD_COST] )
{
cuECtx.bestCS = tempCS;
cuECtx.bestCU = tempCS->cus[0];
cuECtx.bestTU = cuECtx.bestCU->firstTU;
if( isModeInter( encTestmode ) )
{
//Here we take the best cost of both inter modes. We are assuming only the inter modes (and all of them) have come before the intra modes!!!
cuECtx.bestInterCost = cuECtx.bestCS->cost;
}
return true;
}
else