Newer
Older
|| partitioner.currQgEnable() || cs.currQP[partitioner.chType] != encInfo.cu.qp
#else
|| partitioner.currDepth <= cs.pps->getMaxCuDQPDepth() || cs.currQP[partitioner.chType] != encInfo.cu.qp

Karsten Suehring
committed
{
return false;
}
else
{
return true;
}
}
bool BestEncInfoCache::setCsFrom( CodingStructure& cs, EncTestMode& testMode, const Partitioner& partitioner ) const
{
unsigned idx1, idx2, idx3, idx4;
getAreaIdx( cs.area.Y(), *m_slice_bencinf->getPPS()->pcv, idx1, idx2, idx3, idx4 );
BestEncodingInfo& encInfo = *m_bestEncInfo[idx1][idx2][idx3][idx4];
if( cs.picture->poc != encInfo.poc || CS::getArea( cs, cs.area, partitioner.chType ) != CS::getArea( cs, encInfo.cu, partitioner.chType ) || !isTheSameNbHood( encInfo.cu, cs, partitioner
#if JVET_M0170_MRG_SHARELIST
, encInfo.pu, (cs.picture->Y().width), (cs.picture->Y().height)
#endif
#if JVET_M0113_M0188_QG_SIZE
|| partitioner.currQgEnable() || cs.currQP[partitioner.chType] != encInfo.cu.qp
#else
|| partitioner.currDepth <= cs.pps->getMaxCuDQPDepth() || cs.currQP[partitioner.chType] != encInfo.cu.qp

Karsten Suehring
committed
{
return false;
}
CodingUnit &cu = cs.addCU( CS::getArea( cs, cs.area, partitioner.chType ), partitioner.chType );
PredictionUnit &pu = cs.addPU( CS::getArea( cs, cs.area, partitioner.chType ), partitioner.chType );
#if !REUSE_CU_RESULTS_WITH_MULTIPLE_TUS

Karsten Suehring
committed
TransformUnit &tu = cs.addTU( CS::getArea( cs, cs.area, partitioner.chType ), partitioner.chType );

Karsten Suehring
committed
cu .repositionTo( encInfo.cu );
pu .repositionTo( encInfo.pu );
#if !REUSE_CU_RESULTS_WITH_MULTIPLE_TUS

Karsten Suehring
committed
tu .repositionTo( encInfo.tu );

Karsten Suehring
committed
cu = encInfo.cu;
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
testMode = encInfo.testMode;
return true;
}
#endif
static bool interHadActive( const ComprCUCtx& ctx )
{
return ctx.interHad != 0;
}
//////////////////////////////////////////////////////////////////////////
// EncModeCtrlQTBT
//////////////////////////////////////////////////////////////////////////
void EncModeCtrlMTnoRQT::create( const EncCfg& cfg )
{
CacheBlkInfoCtrl::create();

Karsten Suehring
committed
BestEncInfoCache::create( cfg.getChromaFormatIdc() );
#if JVET_M0140_SBT
SaveLoadEncInfoSbt::create();
#endif

Karsten Suehring
committed
}
void EncModeCtrlMTnoRQT::destroy()
{
CacheBlkInfoCtrl::destroy();

Karsten Suehring
committed
BestEncInfoCache::destroy();
#if JVET_M0140_SBT
SaveLoadEncInfoSbt::destroy();
#endif

Karsten Suehring
committed
}
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;
}
}

Christian Helmrich
committed
#if ENABLE_QPA_SUB_CTU
static Position getMaxLumaDQPDepthPos (const CodingStructure &cs, const Partitioner &partitioner)
{
if (partitioner.currDepth <= cs.pps->getMaxCuDQPDepth())
{
return partitioner.currArea().lumaPos();
}
const PartLevel splitAtMaxDepth = partitioner.getPartStack().at (cs.pps->getMaxCuDQPDepth());
// the parent node of qtDepth + mttDepth == maxDqpDepth
return splitAtMaxDepth.parts[splitAtMaxDepth.idx].lumaPos();
}
#endif

Karsten Suehring
committed
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
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
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, 1 );
cuECtx.set( DO_TRIV_SPLIT, 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;

Christian Helmrich
committed
if (!CS::isDualITree (cs) || isLuma (partitioner.chType))

Karsten Suehring
committed
{

Christian Helmrich
committed
if (m_pcEncCfg->getUseAdaptiveQP())
{
baseQP = Clip3(-cs.sps->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, baseQP + xComputeDQP(cs, partitioner));
}

Christian Helmrich
committed
#if ENABLE_QPA_SUB_CTU
else if (m_pcEncCfg->getUsePerceptQPA() && !m_pcEncCfg->getUseRateCtrl() && cs.pps->getUseDQP() && cs.pps->getMaxCuDQPDepth() > 0)
{
const PreCalcValues &pcv = *cs.pcv;

Christian Helmrich
committed

Christian Helmrich
committed
if ((partitioner.currArea().lwidth() < pcv.maxCUWidth) && (partitioner.currArea().lheight() < pcv.maxCUHeight) && cs.picture)
{
const Position &pos = getMaxLumaDQPDepthPos (cs, partitioner);
#if MAX_TB_SIZE_SIGNALLING
const unsigned mtsLog2 = (unsigned)g_aucLog2[std::min (cs.sps->getMaxTbSize(), pcv.maxCUWidth)];
#else
const unsigned mtsLog2 = (unsigned)g_aucLog2[std::min<uint32_t> (MAX_TB_SIZEY, pcv.maxCUWidth)];
#endif

Christian Helmrich
committed
const unsigned stride = pcv.maxCUWidth >> mtsLog2;

Karsten Suehring
committed

Christian Helmrich
committed
baseQP = cs.picture->m_subCtuQP[((pos.x & pcv.maxCUWidthMask) >> mtsLog2) + stride * ((pos.y & pcv.maxCUHeightMask) >> mtsLog2)];
}
}
#endif

Karsten Suehring
committed
#if SHARP_LUMA_DELTA_QP
#if JVET_M0113_M0188_QG_SIZE
if (m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && partitioner.currQgEnable())
#else

Christian Helmrich
committed
if (m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && partitioner.currDepth <= cs.pps->getMaxCuDQPDepth())

Karsten Suehring
committed
{
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

Christian Helmrich
committed
}
int minQP = baseQP;
int maxQP = baseQP;

Karsten Suehring
committed
#if JVET_M0113_M0188_QG_SIZE
xGetMinMaxQP( minQP, maxQP, cs, partitioner, baseQP, *cs.sps, *cs.pps, CU_QUAD_SPLIT );
#else

Karsten Suehring
committed
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 JVET_M0113_M0188_QG_SIZE
int minQPq = minQP;
int maxQPq = maxQP;
xGetMinMaxQP( minQP, maxQP, cs, partitioner, baseQP, *cs.sps, *cs.pps, CU_BT_SPLIT );
#endif

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 ) )
{
#if JVET_M0113_M0188_QG_SIZE
for( int qp = maxQPq; qp >= minQPq; qp-- )
#else

Karsten Suehring
committed
for( int qp = maxQP; qp >= minQP; qp-- )

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

Karsten Suehring
committed
}
}
m_ComprCUCtxList.back().testModes.push_back( { ETM_POST_DONT_SPLIT } );
#if JVET_M0113_M0188_QG_SIZE
xGetMinMaxQP( minQP, maxQP, cs, partitioner, baseQP, *cs.sps, *cs.pps, CU_DONT_SPLIT );
#else

Karsten Suehring
committed
xGetMinMaxQP( minQP, maxQP, cs, partitioner, baseQP, *cs.sps, *cs.pps, false );

Karsten Suehring
committed
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
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
{
int imv = m_pcEncCfg->getIMV4PelFast() ? 3 : 2;
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTER_ME, EncTestModeOpts( imv << ETO_IMV_SHIFT ), qp, lossless } );
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
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
}
}
// 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
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
{
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;
#if FIX_PCM
const uint32_t height = partitioner.currArea().lumaSize().height;
#endif

Karsten Suehring
committed
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
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
1567
1568
1569
1570
1571
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 ||
#else
if( !( slice.isIRAP() || bestMode.type == ETM_INTRA || !cuECtx.bestTU ||
#endif
((!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
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
{
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
#if FIX_PCM
return sps.getPCMEnabledFlag() && width <= ( 1 << sps.getPCMLog2MaxSize() ) && width >= ( 1 << sps.getPCMLog2MinSize() )
&& height <= ( 1 << sps.getPCMLog2MaxSize() ) && height >= ( 1 << sps.getPCMLog2MinSize() );
#else
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
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
{
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
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
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
{
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_TB_SIZEY && height <= MAX_TB_SIZEY)
&& 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 ) ) )
&& ( width <= MAX_TB_SIZEY && height <= MAX_TB_SIZEY )

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

Karsten Suehring
committed
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
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
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
}
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
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
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 );
}