Newer
Older

Karsten Suehring
committed
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2019, ITU/ISO/IEC

Karsten Suehring
committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file EncCu.cpp
\brief Coding Unit (CU) encoder class
*/
#include "EncCu.h"
#include "EncLib.h"
#include "Analyze.h"
#include "AQp.h"
#include "CommonLib/dtrace_codingstruct.h"
#include "CommonLib/Picture.h"
#include "CommonLib/UnitTools.h"
#include "CommonLib/dtrace_buffer.h"
#include <stdio.h>
#include <cmath>
#include <algorithm>
#if ENABLE_WPP_PARALLELISM
#include <mutex>
extern std::recursive_mutex g_cache_mutex;
#endif
//! \ingroup EncoderLib
//! \{
// ====================================================================================================================
// Constructor / destructor / create / destroy
// ====================================================================================================================
#if JVET_M0883_TRIANGLE_SIGNALING
const TriangleMotionInfo EncCu::m_triangleModeTest[TRIANGLE_MAX_NUM_CANDS] =
{
TriangleMotionInfo( 0, 1, 0 ), TriangleMotionInfo( 1, 0, 1 ), TriangleMotionInfo( 1, 0, 2 ), TriangleMotionInfo( 0, 0, 1 ), TriangleMotionInfo( 0, 2, 0 ),
TriangleMotionInfo( 1, 0, 3 ), TriangleMotionInfo( 1, 0, 4 ), TriangleMotionInfo( 1, 1, 0 ), TriangleMotionInfo( 0, 3, 0 ), TriangleMotionInfo( 0, 4, 0 ),
TriangleMotionInfo( 0, 0, 2 ), TriangleMotionInfo( 0, 1, 2 ), TriangleMotionInfo( 1, 1, 2 ), TriangleMotionInfo( 0, 0, 4 ), TriangleMotionInfo( 0, 0, 3 ),
TriangleMotionInfo( 0, 1, 3 ), TriangleMotionInfo( 0, 1, 4 ), TriangleMotionInfo( 1, 1, 4 ), TriangleMotionInfo( 1, 1, 3 ), TriangleMotionInfo( 1, 2, 1 ),
TriangleMotionInfo( 1, 2, 0 ), TriangleMotionInfo( 0, 2, 1 ), TriangleMotionInfo( 0, 4, 3 ), TriangleMotionInfo( 1, 3, 0 ), TriangleMotionInfo( 1, 3, 2 ),
TriangleMotionInfo( 1, 3, 4 ), TriangleMotionInfo( 1, 4, 0 ), TriangleMotionInfo( 1, 3, 1 ), TriangleMotionInfo( 1, 2, 3 ), TriangleMotionInfo( 1, 4, 1 ),
TriangleMotionInfo( 0, 4, 1 ), TriangleMotionInfo( 0, 2, 3 ), TriangleMotionInfo( 1, 4, 2 ), TriangleMotionInfo( 0, 3, 2 ), TriangleMotionInfo( 1, 4, 3 ),
TriangleMotionInfo( 0, 3, 1 ), TriangleMotionInfo( 0, 2, 4 ), TriangleMotionInfo( 1, 2, 4 ), TriangleMotionInfo( 0, 4, 2 ), TriangleMotionInfo( 0, 3, 4 ),
};
#endif

Karsten Suehring
committed
void EncCu::create( EncCfg* encCfg )
{
unsigned uiMaxWidth = encCfg->getMaxCUWidth();
unsigned uiMaxHeight = encCfg->getMaxCUHeight();
ChromaFormat chromaFormat = encCfg->getChromaFormatIdc();
unsigned numWidths = gp_sizeIdxInfo->numWidths();
unsigned numHeights = gp_sizeIdxInfo->numHeights();
m_pTempCS = new CodingStructure** [numWidths];
m_pBestCS = new CodingStructure** [numWidths];
m_pTempMotLUTs = new LutMotionCand**[numWidths];
m_pBestMotLUTs = new LutMotionCand**[numWidths];
m_pSplitTempMotLUTs = new LutMotionCand**[numWidths];

Karsten Suehring
committed
for( unsigned w = 0; w < numWidths; w++ )
{
m_pTempCS[w] = new CodingStructure* [numHeights];
m_pBestCS[w] = new CodingStructure* [numHeights];
m_pTempMotLUTs[w] = new LutMotionCand*[numHeights];
m_pBestMotLUTs[w] = new LutMotionCand*[numHeights];
m_pSplitTempMotLUTs[w] = new LutMotionCand*[numHeights];

Karsten Suehring
committed
for( unsigned h = 0; h < numHeights; h++ )
{
unsigned width = gp_sizeIdxInfo->sizeFrom( w );
unsigned height = gp_sizeIdxInfo->sizeFrom( h );
if( gp_sizeIdxInfo->isCuSize( width ) && gp_sizeIdxInfo->isCuSize( height ) )

Karsten Suehring
committed
{
m_pTempCS[w][h] = new CodingStructure( m_unitCache.cuCache, m_unitCache.puCache, m_unitCache.tuCache );
m_pBestCS[w][h] = new CodingStructure( m_unitCache.cuCache, m_unitCache.puCache, m_unitCache.tuCache );
m_pTempCS[w][h]->create( chromaFormat, Area( 0, 0, width, height ), false );
m_pBestCS[w][h]->create( chromaFormat, Area( 0, 0, width, height ), false );
m_pTempMotLUTs[w][h] = new LutMotionCand ;
m_pBestMotLUTs[w][h] = new LutMotionCand ;
m_pSplitTempMotLUTs[w][h] = new LutMotionCand;
m_pSplitTempMotLUTs[w][h]->currCnt = 0;
m_pSplitTempMotLUTs[w][h]->currCntIBC = 0;
m_pSplitTempMotLUTs[w][h]->motionCand = nullptr;
m_pSplitTempMotLUTs[w][h]->motionCand = new MotionInfo[MAX_NUM_HMVP_CANDS * 2];
m_pTempMotLUTs[w][h]->currCnt = 0;
m_pTempMotLUTs[w][h]->currCntIBC = 0;
m_pTempMotLUTs[w][h]->motionCand = nullptr;
m_pTempMotLUTs[w][h]->motionCand = new MotionInfo[MAX_NUM_HMVP_CANDS * 2];
m_pBestMotLUTs[w][h]->currCnt = 0;
m_pBestMotLUTs[w][h]->currCntIBC = 0;
m_pBestMotLUTs[w][h]->motionCand = nullptr;
m_pBestMotLUTs[w][h]->motionCand = new MotionInfo[MAX_NUM_HMVP_CANDS * 2];
#else
m_pSplitTempMotLUTs[w][h]->currCnt = 0;
m_pSplitTempMotLUTs[w][h]->motionCand = nullptr;
m_pSplitTempMotLUTs[w][h]->motionCand = new MotionInfo[MAX_NUM_HMVP_CANDS];
m_pTempMotLUTs[w][h]->currCnt = 0;
m_pTempMotLUTs[w][h]->motionCand = nullptr;
m_pTempMotLUTs[w][h]->motionCand = new MotionInfo[MAX_NUM_HMVP_CANDS];
m_pBestMotLUTs[w][h]->currCnt = 0;
m_pBestMotLUTs[w][h]->motionCand = nullptr;
m_pBestMotLUTs[w][h]->motionCand = new MotionInfo[MAX_NUM_HMVP_CANDS];

Karsten Suehring
committed
}
else
{
m_pTempCS[w][h] = nullptr;
m_pBestCS[w][h] = nullptr;
m_pTempMotLUTs[w][h] = nullptr;
m_pBestMotLUTs[w][h] = nullptr;
m_pSplitTempMotLUTs[w][h] = nullptr;

Karsten Suehring
committed
}
}
}
// WIA: only the weight==height case is relevant without QTBT
m_pImvTempCS = nullptr;
m_cuChromaQpOffsetIdxPlus1 = 0;
unsigned maxDepth = numWidths + numHeights;

Karsten Suehring
committed
m_modeCtrl->create( *encCfg );
for (unsigned ui = 0; ui < MMVD_MRG_MAX_RD_BUF_NUM; ui++)

Karsten Suehring
committed
{
m_acMergeBuffer[ui].create( chromaFormat, Area( 0, 0, uiMaxWidth, uiMaxHeight ) );
}
for (unsigned ui = 0; ui < MRG_MAX_NUM_CANDS; ui++)
{
m_acRealMergeBuffer[ui].create(chromaFormat, Area(0, 0, uiMaxWidth, uiMaxHeight));
}
#if JVET_M0883_TRIANGLE_SIGNALING
for( unsigned ui = 0; ui < TRIANGLE_MAX_NUM_UNI_CANDS; ui++ )
{
for( unsigned uj = 0; uj < TRIANGLE_MAX_NUM_UNI_CANDS; uj++ )
{
if(ui == uj)
continue;
uint8_t idxBits0 = ui + (ui == TRIANGLE_MAX_NUM_UNI_CANDS - 1 ? 0 : 1);
uint8_t candIdx1Enc = uj - (uj > ui ? 1 : 0);
uint8_t idxBits1 = candIdx1Enc + (candIdx1Enc == TRIANGLE_MAX_NUM_UNI_CANDS - 2 ? 0 : 1);
m_triangleIdxBins[1][ui][uj] = m_triangleIdxBins[0][ui][uj] = 1 + idxBits0 + idxBits1;
}
}
#endif
for( unsigned ui = 0; ui < TRIANGLE_MAX_NUM_CANDS; ui++ )
{
m_acTriangleWeightedBuffer[ui].create( chromaFormat, Area( 0, 0, uiMaxWidth, uiMaxHeight ) );

Karsten Suehring
committed
m_CtxBuffer.resize( maxDepth );
m_CurrCtx = 0;
}

Karsten Suehring
committed
void EncCu::destroy()
{
unsigned numWidths = gp_sizeIdxInfo->numWidths();
unsigned numHeights = gp_sizeIdxInfo->numHeights();
for( unsigned w = 0; w < numWidths; w++ )
{
for( unsigned h = 0; h < numHeights; h++ )
{
if( m_pBestCS[w][h] ) m_pBestCS[w][h]->destroy();
if( m_pTempCS[w][h] ) m_pTempCS[w][h]->destroy();

Karsten Suehring
committed
delete m_pBestCS[w][h];
delete m_pTempCS[w][h];
if (m_pTempMotLUTs[w][h])
{
delete[] m_pTempMotLUTs[w][h]->motionCand;
m_pTempMotLUTs[w][h]->motionCand = nullptr;
}
if (m_pBestMotLUTs[w][h])
{
delete[] m_pBestMotLUTs[w][h]->motionCand;
m_pBestMotLUTs[w][h]->motionCand = nullptr;
if (m_pSplitTempMotLUTs[w][h])
{
delete[] m_pSplitTempMotLUTs[w][h]->motionCand;
m_pSplitTempMotLUTs[w][h]->motionCand = nullptr;

Karsten Suehring
committed
}
}
delete[] m_pTempCS[w];
delete[] m_pBestCS[w];
delete[] m_pBestMotLUTs[w];
delete[] m_pTempMotLUTs[w];
delete[] m_pSplitTempMotLUTs[w];

Karsten Suehring
committed
}
delete[] m_pBestCS; m_pBestCS = nullptr;
delete[] m_pTempCS; m_pTempCS = nullptr;
delete[] m_pSplitTempMotLUTs; m_pSplitTempMotLUTs = nullptr;
delete[] m_pBestMotLUTs; m_pBestMotLUTs = nullptr;
delete[] m_pTempMotLUTs; m_pTempMotLUTs = nullptr;

Karsten Suehring
committed
#if JVET_M0427_INLOOP_RESHAPER && REUSE_CU_RESULTS
if (m_tmpStorageLCU)
{
m_tmpStorageLCU->destroy();
delete m_tmpStorageLCU; m_tmpStorageLCU = nullptr;
}
#endif

Karsten Suehring
committed
#if REUSE_CU_RESULTS
m_modeCtrl->destroy();
#endif
delete m_modeCtrl;
m_modeCtrl = nullptr;
// WIA: only the weight==height case is relevant without QTBT
if( m_pImvTempCS )
{
for( unsigned w = 0; w < numWidths; w++ )
{

Karsten Suehring
committed
{
m_pImvTempCS[w]->destroy();
delete[] m_pImvTempCS[w];

Karsten Suehring
committed
}
}
delete[] m_pImvTempCS;
m_pImvTempCS = nullptr;
}
for (unsigned ui = 0; ui < MMVD_MRG_MAX_RD_BUF_NUM; ui++)

Karsten Suehring
committed
{
m_acMergeBuffer[ui].destroy();
}
for (unsigned ui = 0; ui < MRG_MAX_NUM_CANDS; ui++)
{
m_acRealMergeBuffer[ui].destroy();
}
for( unsigned ui = 0; ui < TRIANGLE_MAX_NUM_CANDS; ui++ )
{

Karsten Suehring
committed
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
}
EncCu::~EncCu()
{
}
/** \param pcEncLib pointer of encoder class
*/
void EncCu::init( EncLib* pcEncLib, const SPS& sps PARL_PARAM( const int tId ) )
{
m_pcEncCfg = pcEncLib;
m_pcIntraSearch = pcEncLib->getIntraSearch( PARL_PARAM0( tId ) );
m_pcInterSearch = pcEncLib->getInterSearch( PARL_PARAM0( tId ) );
m_pcTrQuant = pcEncLib->getTrQuant( PARL_PARAM0( tId ) );
m_pcRdCost = pcEncLib->getRdCost ( PARL_PARAM0( tId ) );
m_CABACEstimator = pcEncLib->getCABACEncoder( PARL_PARAM0( tId ) )->getCABACEstimator( &sps );
m_CABACEstimator->setEncCu(this);
m_CtxCache = pcEncLib->getCtxCache( PARL_PARAM0( tId ) );
m_pcRateCtrl = pcEncLib->getRateCtrl();
m_pcSliceEncoder = pcEncLib->getSliceEncoder();
#if ENABLE_SPLIT_PARALLELISM || ENABLE_WPP_PARALLELISM
m_pcEncLib = pcEncLib;
m_dataId = tId;
#endif
#if JVET_M0428_ENC_DB_OPT
m_pcLoopFilter = pcEncLib->getLoopFilter();
#endif
#if JVET_M0170_MRG_SHARELIST
m_shareState = NO_SHARE;
m_pcInterSearch->setShareState(0);
setShareStateDec(0);
#endif
#if JVET_M0170_MRG_SHARELIST
m_shareBndPosX = -1;
m_shareBndPosY = -1;
m_shareBndSizeW = 0;
m_shareBndSizeH = 0;
#endif

Karsten Suehring
committed
#if REUSE_CU_RESULTS || JVET_M0170_MRG_SHARELIST || JVET_M0427_INLOOP_RESHAPER

Karsten Suehring
committed
DecCu::init( m_pcTrQuant, m_pcIntraSearch, m_pcInterSearch );
#endif
m_modeCtrl->init( m_pcEncCfg, m_pcRateCtrl, m_pcRdCost );
m_pcInterSearch->setModeCtrl( m_modeCtrl );
#if JVET_M0102_INTRA_SUBPARTITIONS
m_pcIntraSearch->setModeCtrl( m_modeCtrl );
#endif

Karsten Suehring
committed
::memset(m_subMergeBlkSize, 0, sizeof(m_subMergeBlkSize));
::memset(m_subMergeBlkNum, 0, sizeof(m_subMergeBlkNum));
m_prevPOC = MAX_UINT;
#if JVET_M0255_FRACMMVD_SWITCH
if ( ( m_pcEncCfg->getIBCHashSearch() && m_pcEncCfg->getIBCMode() ) || m_pcEncCfg->getAllowDisFracMMVD() )
if (m_pcEncCfg->getIBCHashSearch() && m_pcEncCfg->getIBCMode())
m_ibcHashMap.init(m_pcEncCfg->getSourceWidth(), m_pcEncCfg->getSourceHeight());

Karsten Suehring
committed
}
// ====================================================================================================================
// Public member functions
// ====================================================================================================================
void EncCu::compressCtu( CodingStructure& cs, const UnitArea& area, const unsigned ctuRsAddr, const int prevQP[], const int currQP[] )
{
#if !JVET_M0255_FRACMMVD_SWITCH
if (m_pcEncCfg->getIBCHashSearch() && ctuRsAddr == 0 && cs.slice->getSPS()->getIBCMode())
#if JVET_M0427_INLOOP_RESHAPER
if (cs.slice->getSPS()->getUseReshaper() && m_pcReshape->getCTUFlag())
cs.picture->getOrigBuf(COMPONENT_Y).rspSignal(m_pcReshape->getFwdLUT());
#endif
m_ibcHashMap.rebuildPicHashMap(cs.picture->getOrigBuf());
#if JVET_M0427_INLOOP_RESHAPER
if (cs.slice->getSPS()->getUseReshaper() && m_pcReshape->getCTUFlag())
cs.picture->getOrigBuf().copyFrom(cs.picture->getTrueOrigBuf());
#endif

Karsten Suehring
committed
m_modeCtrl->initCTUEncoding( *cs.slice );
#if ENABLE_SPLIT_PARALLELISM
if( m_pcEncCfg->getNumSplitThreads() > 1 )
{
for( int jId = 1; jId < NUM_RESERVERD_SPLIT_JOBS; jId++ )
{
EncCu* jobEncCu = m_pcEncLib->getCuEncoder( cs.picture->scheduler.getSplitDataId( jId ) );
CacheBlkInfoCtrl* cacheCtrl = dynamic_cast< CacheBlkInfoCtrl* >( jobEncCu->m_modeCtrl );
if( cacheCtrl )
{
cacheCtrl->init( *cs.slice );
}
}
}
if( auto* cacheCtrl = dynamic_cast<CacheBlkInfoCtrl*>( m_modeCtrl ) ) { cacheCtrl->tick(); }
#endif
// init the partitioning manager
Partitioner *partitioner = PartitionerFactory::get( *cs.slice );
partitioner->initCtu( area, CH_L, *cs.slice );
if (area.lx() == 0 && area.ly() == 0)
{
m_pcInterSearch->resetIbcSearch();
}
m_ctuIbcSearchRangeX = m_pcEncCfg->getIBCLocalSearchRangeX();
m_ctuIbcSearchRangeY = m_pcEncCfg->getIBCLocalSearchRangeY();
if (m_pcEncCfg->getIBCMode() && m_pcEncCfg->getIBCHashSearch() && (m_pcEncCfg->getIBCFastMethod() & IBC_FAST_METHOD_ADAPTIVE_SEARCHRANGE))
const int hashHitRatio = m_ibcHashMap.getHashHitRatio(area.Y()); // in percent
m_ctuIbcSearchRangeX >>= 1;
m_ctuIbcSearchRangeY >>= 1;
if (cs.slice->getNumRefIdx(REF_PIC_LIST_0) > 0)
#else
m_ctuIbcSearchRangeX >>= 1;
m_ctuIbcSearchRangeY >>= 1;

Karsten Suehring
committed
// init current context pointer
m_CurrCtx = m_CtxBuffer.data();
CodingStructure *tempCS = m_pTempCS[gp_sizeIdxInfo->idxFrom( area.lumaSize().width )][gp_sizeIdxInfo->idxFrom( area.lumaSize().height )];
CodingStructure *bestCS = m_pBestCS[gp_sizeIdxInfo->idxFrom( area.lumaSize().width )][gp_sizeIdxInfo->idxFrom( area.lumaSize().height )];
LutMotionCand *tempMotCandLUTs = m_pTempMotLUTs[gp_sizeIdxInfo->idxFrom(area.lumaSize().width)][gp_sizeIdxInfo->idxFrom(area.lumaSize().height)];
LutMotionCand *bestMotCandLUTs = m_pBestMotLUTs[gp_sizeIdxInfo->idxFrom(area.lumaSize().width)][gp_sizeIdxInfo->idxFrom(area.lumaSize().height)];
cs.slice->copyMotionLUTs(cs.slice->getMotionLUTs(), tempMotCandLUTs);
cs.slice->copyMotionLUTs(cs.slice->getMotionLUTs(), bestMotCandLUTs);

Karsten Suehring
committed
cs.initSubStructure( *tempCS, partitioner->chType, partitioner->currArea(), false );
cs.initSubStructure( *bestCS, partitioner->chType, partitioner->currArea(), false );
tempCS->currQP[CH_L] = bestCS->currQP[CH_L] =
tempCS->baseQP = bestCS->baseQP = currQP[CH_L];
tempCS->prevQP[CH_L] = bestCS->prevQP[CH_L] = prevQP[CH_L];
xCompressCU( tempCS, bestCS, *partitioner
, tempMotCandLUTs
, bestMotCandLUTs
);

Karsten Suehring
committed
// all signals were already copied during compression if the CTU was split - at this point only the structures are copied to the top level CS
#if JVET_M0427_INLOOP_RESHAPER
const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1;
#else

Karsten Suehring
committed
const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1 && KEEP_PRED_AND_RESI_SIGNALS;

Karsten Suehring
committed
cs.useSubStructure( *bestCS, partitioner->chType, CS::getArea( *bestCS, area, partitioner->chType ), copyUnsplitCTUSignals, false, false, copyUnsplitCTUSignals );
cs.slice->copyMotionLUTs(bestMotCandLUTs, cs.slice->getMotionLUTs());

Karsten Suehring
committed

Christian Helmrich
committed
if (CS::isDualITree (cs) && isChromaEnabled (cs.pcv->chrFormat))

Karsten Suehring
committed
{
m_CABACEstimator->getCtx() = m_CurrCtx->start;
partitioner->initCtu( area, CH_C, *cs.slice );
cs.initSubStructure( *tempCS, partitioner->chType, partitioner->currArea(), false );
cs.initSubStructure( *bestCS, partitioner->chType, partitioner->currArea(), false );
tempCS->currQP[CH_C] = bestCS->currQP[CH_C] =
tempCS->baseQP = bestCS->baseQP = currQP[CH_C];
tempCS->prevQP[CH_C] = bestCS->prevQP[CH_C] = prevQP[CH_C];
xCompressCU( tempCS, bestCS, *partitioner
, tempMotCandLUTs
, bestMotCandLUTs
);

Karsten Suehring
committed
#if JVET_M0427_INLOOP_RESHAPER
const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1;
#else

Karsten Suehring
committed
const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1 && KEEP_PRED_AND_RESI_SIGNALS;

Karsten Suehring
committed
cs.useSubStructure( *bestCS, partitioner->chType, CS::getArea( *bestCS, area, partitioner->chType ), copyUnsplitCTUSignals, false, false, copyUnsplitCTUSignals );
}
if (m_pcEncCfg->getUseRateCtrl())
{
(m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr)).m_actualMSE = (double)bestCS->dist / (double)m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr).m_numberOfPixel;
}

Karsten Suehring
committed
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
// reset context states and uninit context pointer
m_CABACEstimator->getCtx() = m_CurrCtx->start;
m_CurrCtx = 0;
delete partitioner;
#if ENABLE_SPLIT_PARALLELISM && ENABLE_WPP_PARALLELISM
if( m_pcEncCfg->getNumSplitThreads() > 1 && m_pcEncCfg->getNumWppThreads() > 1 )
{
cs.picture->finishCtuPart( area );
}
#endif
// Ensure that a coding was found
// Selected mode's RD-cost must be not MAX_DOUBLE.
CHECK( bestCS->cus.empty() , "No possible encoding found" );
CHECK( bestCS->cus[0]->predMode == NUMBER_OF_PREDICTION_MODES, "No possible encoding found" );
CHECK( bestCS->cost == MAX_DOUBLE , "No possible encoding found" );
}
// ====================================================================================================================
// Protected member functions
// ====================================================================================================================
static int xCalcHADs8x8_ISlice(const Pel *piOrg, const int iStrideOrg)
{
int k, i, j, jj;
int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0;
for (k = 0; k < 64; k += 8)
{
diff[k + 0] = piOrg[0];
diff[k + 1] = piOrg[1];
diff[k + 2] = piOrg[2];
diff[k + 3] = piOrg[3];
diff[k + 4] = piOrg[4];
diff[k + 5] = piOrg[5];
diff[k + 6] = piOrg[6];
diff[k + 7] = piOrg[7];
piOrg += iStrideOrg;
}
//horizontal
for (j = 0; j < 8; j++)
{
jj = j << 3;
m2[j][0] = diff[jj ] + diff[jj + 4];
m2[j][1] = diff[jj + 1] + diff[jj + 5];
m2[j][2] = diff[jj + 2] + diff[jj + 6];
m2[j][3] = diff[jj + 3] + diff[jj + 7];
m2[j][4] = diff[jj ] - diff[jj + 4];
m2[j][5] = diff[jj + 1] - diff[jj + 5];
m2[j][6] = diff[jj + 2] - diff[jj + 6];
m2[j][7] = diff[jj + 3] - diff[jj + 7];
m1[j][0] = m2[j][0] + m2[j][2];
m1[j][1] = m2[j][1] + m2[j][3];
m1[j][2] = m2[j][0] - m2[j][2];
m1[j][3] = m2[j][1] - m2[j][3];
m1[j][4] = m2[j][4] + m2[j][6];
m1[j][5] = m2[j][5] + m2[j][7];
m1[j][6] = m2[j][4] - m2[j][6];
m1[j][7] = m2[j][5] - m2[j][7];
m2[j][0] = m1[j][0] + m1[j][1];
m2[j][1] = m1[j][0] - m1[j][1];
m2[j][2] = m1[j][2] + m1[j][3];
m2[j][3] = m1[j][2] - m1[j][3];
m2[j][4] = m1[j][4] + m1[j][5];
m2[j][5] = m1[j][4] - m1[j][5];
m2[j][6] = m1[j][6] + m1[j][7];
m2[j][7] = m1[j][6] - m1[j][7];
}
//vertical
for (i = 0; i < 8; i++)
{
m3[0][i] = m2[0][i] + m2[4][i];
m3[1][i] = m2[1][i] + m2[5][i];
m3[2][i] = m2[2][i] + m2[6][i];
m3[3][i] = m2[3][i] + m2[7][i];
m3[4][i] = m2[0][i] - m2[4][i];
m3[5][i] = m2[1][i] - m2[5][i];
m3[6][i] = m2[2][i] - m2[6][i];
m3[7][i] = m2[3][i] - m2[7][i];
m1[0][i] = m3[0][i] + m3[2][i];
m1[1][i] = m3[1][i] + m3[3][i];
m1[2][i] = m3[0][i] - m3[2][i];
m1[3][i] = m3[1][i] - m3[3][i];
m1[4][i] = m3[4][i] + m3[6][i];
m1[5][i] = m3[5][i] + m3[7][i];
m1[6][i] = m3[4][i] - m3[6][i];
m1[7][i] = m3[5][i] - m3[7][i];
m2[0][i] = m1[0][i] + m1[1][i];
m2[1][i] = m1[0][i] - m1[1][i];
m2[2][i] = m1[2][i] + m1[3][i];
m2[3][i] = m1[2][i] - m1[3][i];
m2[4][i] = m1[4][i] + m1[5][i];
m2[5][i] = m1[4][i] - m1[5][i];
m2[6][i] = m1[6][i] + m1[7][i];
m2[7][i] = m1[6][i] - m1[7][i];
}
for (i = 0; i < 8; i++)
{
for (j = 0; j < 8; j++)
{
iSumHad += abs(m2[i][j]);
}
}
iSumHad -= abs(m2[0][0]);
iSumHad = (iSumHad + 2) >> 2;
return(iSumHad);
}
int EncCu::updateCtuDataISlice(const CPelBuf buf)
{
int xBl, yBl;
const int iBlkSize = 8;
const Pel* pOrgInit = buf.buf;
int iStrideOrig = buf.stride;
int iSumHad = 0;
for( yBl = 0; ( yBl + iBlkSize ) <= buf.height; yBl += iBlkSize )
{
for( xBl = 0; ( xBl + iBlkSize ) <= buf.width; xBl += iBlkSize )
{
const Pel* pOrg = pOrgInit + iStrideOrig*yBl + xBl;
iSumHad += xCalcHADs8x8_ISlice( pOrg, iStrideOrig );
}
}
return( iSumHad );
}
bool EncCu::xCheckBestMode( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode )

Karsten Suehring
committed
{

Karsten Suehring
committed
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
if( !tempCS->cus.empty() )
{
if( tempCS->cus.size() == 1 )
{
const CodingUnit& cu = *tempCS->cus.front();
CHECK( cu.skip && !cu.firstPU->mergeFlag, "Skip flag without a merge flag is not allowed!" );
}
#if WCG_EXT
DTRACE_BEST_MODE( tempCS, bestCS, m_pcRdCost->getLambda( true ) );
#else
DTRACE_BEST_MODE( tempCS, bestCS, m_pcRdCost->getLambda() );
#endif
if( m_modeCtrl->useModeResult( encTestMode, tempCS, partitioner ) )
{
if( tempCS->cus.size() == 1 )
{
// if tempCS is not a split-mode
CodingUnit &cu = *tempCS->cus.front();
if( CU::isLosslessCoded( cu ) && !cu.ipcm )
{
xFillPCMBuffer( cu );
}
}
std::swap( tempCS, bestCS );
// store temp best CI for next CU coding
m_CurrCtx->best = m_CABACEstimator->getCtx();

Karsten Suehring
committed
}
}
// reset context states
m_CABACEstimator->getCtx() = m_CurrCtx->start;

Karsten Suehring
committed
}
void EncCu::xCompressCU( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner
, LutMotionCand *&tempMotCandLUTs
, LutMotionCand *&bestMotCandLUTs

Karsten Suehring
committed
{
#if JVET_M0170_MRG_SHARELIST
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();
}
#endif

Karsten Suehring
committed
#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;
const PPS &pps = *tempCS->pps;
const SPS &sps = *tempCS->sps;
const uint32_t uiLPelX = tempCS->area.Y().lumaPos().x;
const uint32_t uiTPelY = tempCS->area.Y().lumaPos().y;
const unsigned wIdx = gp_sizeIdxInfo->idxFrom( partitioner.currArea().lwidth() );
const UnitArea currCsArea = clipArea( CS::getArea( *bestCS, bestCS->area, partitioner.chType ), *tempCS->picture );
if (m_pImvTempCS && (!slice.isIntra() || slice.getSPS()->getIBCFlag()))

Karsten Suehring
committed
if( m_pImvTempCS && !slice.isIntra() )

Karsten Suehring
committed
{
tempCS->initSubStructure( *m_pImvTempCS[wIdx], partitioner.chType, partitioner.currArea(), false );

Karsten Suehring
committed
}
tempCS->chType = partitioner.chType;
bestCS->chType = partitioner.chType;

Karsten Suehring
committed
m_modeCtrl->initCULevel( partitioner, *tempCS );
Yin Zhao
committed
#if JVET_M0464_UNI_MTS
if( partitioner.currQtDepth == 0 && partitioner.currMtDepth == 0 && !tempCS->slice->isIntra() && ( sps.getUseSBT() || sps.getUseInterMTS() ) )
Yin Zhao
committed
#else
if( partitioner.currQtDepth == 0 && partitioner.currMtDepth == 0 && !tempCS->slice->isIntra() && ( sps.getUseSBT() || sps.getUseInterEMT() ) )
#endif
{
auto slsSbt = dynamic_cast<SaveLoadEncInfoSbt*>( m_modeCtrl );
Yin Zhao
committed
#if JVET_M0464_UNI_MTS
Yin Zhao
committed
int maxSLSize = sps.getUseSBT() ? tempCS->slice->getSPS()->getMaxSbtSize() : MTS_INTER_MAX_CU_SIZE;
Yin Zhao
committed
#else
int maxSLSize = sps.getUseSBT() ? tempCS->slice->getSPS()->getMaxSbtSize() : EMT_INTER_MAX_CU_WITH_QTBT;
#endif
slsSbt->resetSaveloadSbt( maxSLSize );
}
m_sbtCostSave[0] = m_sbtCostSave[1] = MAX_DOUBLE;
#endif

Karsten Suehring
committed
m_CurrCtx->start = m_CABACEstimator->getCtx();
m_cuChromaQpOffsetIdxPlus1 = 0;
if( slice.getUseChromaQpAdj() )
{
int lgMinCuSize = sps.getLog2MinCodingBlockSize() +
std::max<int>( 0, sps.getLog2DiffMaxMinCodingBlockSize() - int( pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() ) );
m_cuChromaQpOffsetIdxPlus1 = ( ( uiLPelX >> lgMinCuSize ) + ( uiTPelY >> lgMinCuSize ) ) % ( pps.getPpsRangeExtension().getChromaQpOffsetListLen() + 1 );
}
if( !m_modeCtrl->anyMode() )
{
m_modeCtrl->finishCULevel( partitioner );
return;
}
if ((!slice.isIntra() || slice.getSPS()->getIBCFlag())
{
tempCS->slice->copyMotionLUTs(tempMotCandLUTs, tempCS->slice->getMotionLUTs());
}

Karsten Suehring
committed
DTRACE_UPDATE( g_trace_ctx, std::make_pair( "cux", uiLPelX ) );
DTRACE_UPDATE( g_trace_ctx, std::make_pair( "cuy", uiTPelY ) );
DTRACE_UPDATE( g_trace_ctx, std::make_pair( "cuw", tempCS->area.lwidth() ) );
DTRACE_UPDATE( g_trace_ctx, std::make_pair( "cuh", tempCS->area.lheight() ) );
DTRACE( g_trace_ctx, D_COMMON, "@(%4d,%4d) [%2dx%2d]\n", tempCS->area.lx(), tempCS->area.ly(), tempCS->area.lwidth(), tempCS->area.lheight() );
#if JVET_M0170_MRG_SHARELIST
int startShareThisLevel = 0;
#endif
m_pcInterSearch->resetSavedAffineMotion();
#endif

Karsten Suehring
committed
do
{
EncTestMode currTestMode = m_modeCtrl->currTestMode();

Christian Helmrich
committed
if (pps.getUseDQP() && CS::isDualITree(*tempCS) && isChroma(partitioner.chType))
{
const Position chromaCentral(tempCS->area.Cb().chromaPos().offset(tempCS->area.Cb().chromaSize().width >> 1, tempCS->area.Cb().chromaSize().height >> 1));
const Position lumaRefPos(chromaCentral.x << getComponentScaleX(COMPONENT_Cb, tempCS->area.chromaFormat), chromaCentral.y << getComponentScaleY(COMPONENT_Cb, tempCS->area.chromaFormat));
const CodingStructure* baseCS = bestCS->picture->cs;
const CodingUnit* colLumaCu = baseCS->getCU(lumaRefPos, CHANNEL_TYPE_LUMA);
Santiago de Luxán Hernández
committed
if (colLumaCu)
{
currTestMode.qp = colLumaCu->qp;
}
}

Karsten Suehring
committed

Christian Helmrich
committed
#if SHARP_LUMA_DELTA_QP || ENABLE_QPA_SUB_CTU
if (partitioner.currDepth <= pps.getMaxCuDQPDepth() && (

Karsten Suehring
committed
#if SHARP_LUMA_DELTA_QP

Christian Helmrich
committed
(m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled()) ||
#endif
#if ENABLE_QPA_SUB_CTU
(m_pcEncCfg->getUsePerceptQPA() && !m_pcEncCfg->getUseRateCtrl() && pps.getUseDQP())
#else
false
#endif
))

Karsten Suehring
committed
{
#if ENABLE_SPLIT_PARALLELISM
CHECK( tempCS->picture->scheduler.getSplitJobId() > 0, "Changing lambda is only allowed in the master thread!" );
#endif
if (currTestMode.qp >= 0)
{

Christian Helmrich
committed
updateLambda (&slice, currTestMode.qp, CS::isDualITree (*tempCS) || (partitioner.currDepth == 0));

Karsten Suehring
committed
}
}
#endif
if( currTestMode.type == ETM_INTER_ME )
{
if( ( currTestMode.opts & ETO_IMV ) != 0 )
{
#if JVET_M0246_AFFINE_AMVR
tempCS->bestCS = bestCS;
xCheckRDCostInterIMV( tempCS, bestCS, partitioner, currTestMode );
tempCS->bestCS = nullptr;
#else

Karsten Suehring
committed
xCheckRDCostInterIMV(tempCS, bestCS, partitioner, currTestMode);

Karsten Suehring
committed
}
else
{
#if JVET_M0246_AFFINE_AMVR
tempCS->bestCS = bestCS;

Karsten Suehring
committed
xCheckRDCostInter( tempCS, bestCS, partitioner, currTestMode );
tempCS->bestCS = nullptr;
#else
xCheckRDCostInter( tempCS, bestCS, partitioner, currTestMode );
#endif

Karsten Suehring
committed
}
}
#if JVET_M0253_HASH_ME
else if (currTestMode.type == ETM_HASH_INTER)
{
xCheckRDCostHashInter( tempCS, bestCS, partitioner, currTestMode );
}
#endif

Karsten Suehring
committed
else if( currTestMode.type == ETM_AFFINE )
{
xCheckRDCostAffineMerge2Nx2N( tempCS, bestCS, partitioner, currTestMode );
}
#if REUSE_CU_RESULTS
else if( currTestMode.type == ETM_RECO_CACHED )
{
xReuseCachedResult( tempCS, bestCS, partitioner );
}
#endif
else if( currTestMode.type == ETM_MERGE_SKIP )
{
xCheckRDCostMerge2Nx2N( tempCS, bestCS, partitioner, currTestMode );
CodingUnit* cu = bestCS->getCU(partitioner.chType);
cu->mmvdSkip = cu->skip == false ? false : cu->mmvdSkip;

Karsten Suehring
committed
}
else if( currTestMode.type == ETM_MERGE_TRIANGLE )
{
xCheckRDCostMergeTriangle2Nx2N( tempCS, bestCS, partitioner, currTestMode );
}

Karsten Suehring
committed
else if( currTestMode.type == ETM_INTRA )
{
xCheckRDCostIntra( tempCS, bestCS, partitioner, currTestMode );
}
else if( currTestMode.type == ETM_IPCM )
{
xCheckIntraPCM( tempCS, bestCS, partitioner, currTestMode );
}
xCheckRDCostIBCMode(tempCS, bestCS, partitioner, currTestMode);
xCheckRDCostIBCModeMerge2Nx2N(tempCS, bestCS, partitioner, currTestMode);

Karsten Suehring
committed
else if( isModeSplit( currTestMode ) )
{
xCheckModeSplit( tempCS, bestCS, partitioner, currTestMode
, tempMotCandLUTs
, bestMotCandLUTs
, partitioner.currArea()
);

Karsten Suehring
committed
}
else
{
THROW( "Don't know how to handle mode: type = " << currTestMode.type << ", options = " << currTestMode.opts );

Karsten Suehring
committed
}
} while( m_modeCtrl->nextMode( *tempCS, partitioner ) );
#if JVET_M0170_MRG_SHARELIST
if(startShareThisLevel == 1)
{
m_shareState = NO_SHARE;
m_pcInterSearch->setShareState(m_shareState);
setShareStateDec(m_shareState);
}
#endif

Karsten Suehring
committed
//////////////////////////////////////////////////////////////////////////
// Finishing CU
#if ENABLE_SPLIT_PARALLELISM
if( bestCS->cus.empty() )
{
CHECK( bestCS->cost != MAX_DOUBLE, "Cost should be maximal if no encoding found" );
CHECK( bestCS->picture->scheduler.getSplitJobId() == 0, "Should always get a result in serial case" );
m_modeCtrl->finishCULevel( partitioner );
return;
}
#endif
// set context states
m_CABACEstimator->getCtx() = m_CurrCtx->best;
// QP from last processed CU for further processing
bestCS->prevQP[partitioner.chType] = bestCS->cus.back()->qp;
if ((!slice.isIntra() || slice.getSPS()->getIBCFlag())
&& bestCS->cus.size() == 1 && (bestCS->cus.back()->predMode == MODE_INTER || bestCS->cus.back()->predMode == MODE_IBC)
#else
&& bestCS->cus.size() == 1 && bestCS->cus.back()->predMode == MODE_INTER
{
bestCS->slice->updateMotionLUTs(bestMotCandLUTs, (*bestCS->cus.back()));
}
#if JVET_M0427_INLOOP_RESHAPER
bestCS->picture->getPredBuf(currCsArea).copyFrom(bestCS->getPredBuf(currCsArea));
#endif

Karsten Suehring
committed
bestCS->picture->getRecoBuf( currCsArea ).copyFrom( bestCS->getRecoBuf( currCsArea ) );
m_modeCtrl->finishCULevel( partitioner );
#if ENABLE_SPLIT_PARALLELISM
if( tempCS->picture->scheduler.getSplitJobId() == 0 && m_pcEncCfg->getNumSplitThreads() != 1 )
{
tempCS->picture->finishParallelPart( currCsArea );
}
#endif
// Assert if Best prediction mode is NONE
// Selected mode's RD-cost must be not MAX_DOUBLE.
CHECK( bestCS->cus.empty() , "No possible encoding found" );
CHECK( bestCS->cus[0]->predMode == NUMBER_OF_PREDICTION_MODES, "No possible encoding found" );
CHECK( bestCS->cost == MAX_DOUBLE , "No possible encoding found" );
}

Christian Helmrich
committed
#if SHARP_LUMA_DELTA_QP || ENABLE_QPA_SUB_CTU
void EncCu::updateLambda (Slice* slice, const int dQP, const bool updateRdCostLambda)

Karsten Suehring
committed
{
#if WCG_EXT
int NumberBFrames = ( m_pcEncCfg->getGOPSize() - 1 );
int SHIFT_QP = 12;
double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(double)(slice->getPic()->fieldPic ? NumberBFrames/2 : NumberBFrames) );
int bitdepth_luma_qp_scale = 6
* (slice->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) - 8
- DISTORTION_PRECISION_ADJUSTMENT(slice->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA)));
double qp_temp = (double) dQP + bitdepth_luma_qp_scale - SHIFT_QP;

Karsten Suehring
committed
double dQPFactor = m_pcEncCfg->getGOPEntry( m_pcSliceEncoder->getGopId() ).m_QPFactor;

Karsten Suehring
committed
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
if( slice->getSliceType() == I_SLICE )
{
if( m_pcEncCfg->getIntraQpFactor() >= 0.0 /*&& m_pcEncCfg->getGOPEntry( m_pcSliceEncoder->getGopId() ).m_sliceType != I_SLICE*/ )
{
dQPFactor = m_pcEncCfg->getIntraQpFactor();
}
else
{
if( m_pcEncCfg->getLambdaFromQPEnable() )
{
dQPFactor = 0.57;
}
else
{
dQPFactor = 0.57*dLambda_scale;
}
}
}
else if( m_pcEncCfg->getLambdaFromQPEnable() )
{
dQPFactor = 0.57*dQPFactor;
}
double dLambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
int depth = slice->getDepth();
if( !m_pcEncCfg->getLambdaFromQPEnable() && depth>0 )
{
int qp_temp_slice = slice->getSliceQp() + bitdepth_luma_qp_scale - SHIFT_QP; // avoid lambda over adjustment, use slice_qp here
dLambda *= Clip3( 2.00, 4.00, (qp_temp_slice / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
}
if( !m_pcEncCfg->getUseHADME() && slice->getSliceType( ) != I_SLICE )
{
dLambda *= 0.95;
}
const int temporalId = m_pcEncCfg->getGOPEntry( m_pcSliceEncoder->getGopId() ).m_temporalId;
const std::vector<double> &intraLambdaModifiers = m_pcEncCfg->getIntraLambdaModifier();
double lambdaModifier;
if( slice->getSliceType( ) != I_SLICE || intraLambdaModifiers.empty())
{
lambdaModifier = m_pcEncCfg->getLambdaModifier(temporalId);
}
else
{
lambdaModifier = intraLambdaModifiers[(temporalId < intraLambdaModifiers.size()) ? temporalId : (intraLambdaModifiers.size() - 1)];
}
dLambda *= lambdaModifier;
int qpBDoffset = slice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);

Christian Helmrich
committed
int iQP = Clip3(-qpBDoffset, MAX_QP, (int)floor((double)dQP + 0.5));

Karsten Suehring
committed
m_pcSliceEncoder->setUpLambda(slice, dLambda, iQP);
#else

Christian Helmrich
committed
int iQP = dQP;

Karsten Suehring
committed
const double oldQP = (double)slice->getSliceQpBase();

Christian Helmrich
committed
#if ENABLE_QPA_SUB_CTU
const double oldLambda = (m_pcEncCfg->getUsePerceptQPA() && !m_pcEncCfg->getUseRateCtrl() && slice->getPPS()->getUseDQP()) ? slice->getLambdas()[0] :
m_pcSliceEncoder->calculateLambda (slice, m_pcSliceEncoder->getGopId(), slice->getDepth(), oldQP, oldQP, iQP);
#else

Karsten Suehring
committed
const double oldLambda = m_pcSliceEncoder->calculateLambda (slice, m_pcSliceEncoder->getGopId(), slice->getDepth(), oldQP, oldQP, iQP);

Christian Helmrich
committed
#endif
const double newLambda = oldLambda * pow (2.0, ((double)dQP - oldQP) / 3.0);

Karsten Suehring
committed
#if RDOQ_CHROMA_LAMBDA
const double chromaLambda = newLambda / m_pcRdCost->getChromaWeight();
const double lambdaArray[MAX_NUM_COMPONENT] = {newLambda, chromaLambda, chromaLambda};
m_pcTrQuant->setLambdas (lambdaArray);
#else
m_pcTrQuant->setLambda (newLambda);
#endif
if (updateRdCostLambda)
{
m_pcRdCost->setLambda (newLambda, slice->getSPS()->getBitDepths());
}

Karsten Suehring
committed
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
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
1147
1148
1149
1150
1151
1152
1153
1154
1155
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
1196
1197
1198
1199
1200
1201
1202
1203
#endif
}
#endif
#if ENABLE_SPLIT_PARALLELISM
//#undef DEBUG_PARALLEL_TIMINGS
//#define DEBUG_PARALLEL_TIMINGS 1
void EncCu::xCompressCUParallel( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner )
{
const unsigned wIdx = gp_sizeIdxInfo->idxFrom( partitioner.currArea().lwidth() );
const unsigned hIdx = gp_sizeIdxInfo->idxFrom( partitioner.currArea().lheight() );
Picture* picture = tempCS->picture;
int numJobs = m_modeCtrl->getNumParallelJobs( *bestCS, partitioner );
bool jobUsed [NUM_RESERVERD_SPLIT_JOBS];
std::fill( jobUsed, jobUsed + NUM_RESERVERD_SPLIT_JOBS, false );
const UnitArea currArea = CS::getArea( *tempCS, partitioner.currArea(), partitioner.chType );
#if ENABLE_WPP_PARALLELISM
const int wppTId = picture->scheduler.getWppThreadId();
#endif
const bool doParallel = !m_pcEncCfg->getForceSingleSplitThread();
#if _MSC_VER && ENABLE_WPP_PARALLELISM
#pragma omp parallel for schedule(dynamic,1) num_threads(NUM_SPLIT_THREADS_IF_MSVC) if(doParallel)
#else
omp_set_num_threads( m_pcEncCfg->getNumSplitThreads() );
#pragma omp parallel for schedule(dynamic,1) if(doParallel)
#endif
for( int jId = 1; jId <= numJobs; jId++ )
{
// thread start
#if ENABLE_WPP_PARALLELISM
picture->scheduler.setWppThreadId( wppTId );
#endif
picture->scheduler.setSplitThreadId();
picture->scheduler.setSplitJobId( jId );
Partitioner* jobPartitioner = PartitionerFactory::get( *tempCS->slice );
EncCu* jobCuEnc = m_pcEncLib->getCuEncoder( picture->scheduler.getSplitDataId( jId ) );
auto* jobBlkCache = dynamic_cast<CacheBlkInfoCtrl*>( jobCuEnc->m_modeCtrl );
jobPartitioner->copyState( partitioner );
jobCuEnc ->copyState( this, *jobPartitioner, currArea, true );
if( jobBlkCache )
{
jobBlkCache->tick();
}
CodingStructure *&jobBest = jobCuEnc->m_pBestCS[wIdx][hIdx];
CodingStructure *&jobTemp = jobCuEnc->m_pTempCS[wIdx][hIdx];
jobUsed[jId] = true;
jobCuEnc->xCompressCU( jobTemp, jobBest, *jobPartitioner );
delete jobPartitioner;
picture->scheduler.setSplitJobId( 0 );
// thread stop
}
picture->scheduler.setSplitThreadId( 0 );
int bestJId = 0;
double bestCost = bestCS->cost;
for( int jId = 1; jId <= numJobs; jId++ )
{
EncCu* jobCuEnc = m_pcEncLib->getCuEncoder( picture->scheduler.getSplitDataId( jId ) );
if( jobUsed[jId] && jobCuEnc->m_pBestCS[wIdx][hIdx]->cost < bestCost )
{
bestCost = jobCuEnc->m_pBestCS[wIdx][hIdx]->cost;
bestJId = jId;
}
}
if( bestJId > 0 )
{
copyState( m_pcEncLib->getCuEncoder( picture->scheduler.getSplitDataId( bestJId ) ), partitioner, currArea, false );
m_CurrCtx->best = m_CABACEstimator->getCtx();
tempCS = m_pTempCS[wIdx][hIdx];
bestCS = m_pBestCS[wIdx][hIdx];
}
const int bitDepthY = tempCS->sps->getBitDepth( CH_L );
const UnitArea clipdArea = clipArea( currArea, *picture );
CHECK( calcCheckSum( picture->getRecoBuf( clipdArea.Y() ), bitDepthY ) != calcCheckSum( bestCS->getRecoBuf( clipdArea.Y() ), bitDepthY ), "Data copied incorrectly!" );
picture->finishParallelPart( currArea );
if( auto *blkCache = dynamic_cast<CacheBlkInfoCtrl*>( m_modeCtrl ) )
{
for( int jId = 1; jId <= numJobs; jId++ )
{
if( !jobUsed[jId] || jId == bestJId ) continue;
auto *jobBlkCache = dynamic_cast<CacheBlkInfoCtrl*>( m_pcEncLib->getCuEncoder( picture->scheduler.getSplitDataId( jId ) )->m_modeCtrl );
CHECK( !jobBlkCache, "If own mode controller has blk info cache capability so should all other mode controllers!" );
blkCache->CacheBlkInfoCtrl::copyState( *jobBlkCache, partitioner.currArea() );
}
blkCache->tick();
}
}
void EncCu::copyState( EncCu* other, Partitioner& partitioner, const UnitArea& currArea, const bool isDist )
{
const unsigned wIdx = gp_sizeIdxInfo->idxFrom( partitioner.currArea().lwidth () );
const unsigned hIdx = gp_sizeIdxInfo->idxFrom( partitioner.currArea().lheight() );
if( isDist )
{
other->m_pBestCS[wIdx][hIdx]->initSubStructure( *m_pBestCS[wIdx][hIdx], partitioner.chType, partitioner.currArea(), false );
other->m_pTempCS[wIdx][hIdx]->initSubStructure( *m_pTempCS[wIdx][hIdx], partitioner.chType, partitioner.currArea(), false );
}
else
{
CodingStructure* dst = m_pBestCS[wIdx][hIdx];
const CodingStructure *src = other->m_pBestCS[wIdx][hIdx];
bool keepResi = KEEP_PRED_AND_RESI_SIGNALS;
dst->useSubStructure( *src, partitioner.chType, currArea, KEEP_PRED_AND_RESI_SIGNALS, true, keepResi, keepResi );
dst->cost = src->cost;
dst->dist = src->dist;
dst->fracBits = src->fracBits;
dst->features = src->features;
}
if( isDist )
{
m_CurrCtx = m_CtxBuffer.data();
}
m_pcInterSearch->copyState( *other->m_pcInterSearch );
m_modeCtrl ->copyState( *other->m_modeCtrl, partitioner.currArea() );
m_pcRdCost ->copyState( *other->m_pcRdCost );
m_pcTrQuant ->copyState( *other->m_pcTrQuant );
m_CABACEstimator->getCtx() = other->m_CABACEstimator->getCtx();
}
#endif
void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode
, LutMotionCand* &tempMotCandLUTs
, LutMotionCand* &bestMotCandLUTs
, UnitArea parArea
)

Karsten Suehring
committed
{
const int qp = encTestMode.qp;
const PPS &pps = *tempCS->pps;
const Slice &slice = *tempCS->slice;
const bool bIsLosslessMode = false; // False at this level. Next level down may set it to true.
const int oldPrevQp = tempCS->prevQP[partitioner.chType];
const uint32_t currDepth = partitioner.currDepth;
const unsigned wParIdx = gp_sizeIdxInfo->idxFrom(parArea.lwidth());
const unsigned hParIdx = gp_sizeIdxInfo->idxFrom(parArea.lheight());
tempCS->slice->copyMotionLUTs(tempMotCandLUTs, m_pSplitTempMotLUTs[wParIdx][hParIdx]);

Karsten Suehring
committed
const PartSplit split = getPartSplit( encTestMode );
CHECK( split == CU_DONT_SPLIT, "No proper split provided!" );
tempCS->initStructData( qp, bIsLosslessMode );
m_CABACEstimator->getCtx() = m_CurrCtx->start;
const TempCtx ctxStartSP( m_CtxCache, SubCtx( Ctx::SplitFlag, m_CABACEstimator->getCtx() ) );
#if JVET_M0421_SPLIT_SIG
const TempCtx ctxStartQt( m_CtxCache, SubCtx( Ctx::SplitQtFlag, m_CABACEstimator->getCtx() ) );
const TempCtx ctxStartHv( m_CtxCache, SubCtx( Ctx::SplitHvFlag, m_CABACEstimator->getCtx() ) );
const TempCtx ctxStart12( m_CtxCache, SubCtx( Ctx::Split12Flag, m_CABACEstimator->getCtx() ) );
#else
const TempCtx ctxStartBT( m_CtxCache, SubCtx( Ctx::BTSplitFlag, m_CABACEstimator->getCtx() ) );

Karsten Suehring
committed

Karsten Suehring
committed
#if JVET_M0421_SPLIT_SIG
m_CABACEstimator->split_cu_mode( split, *tempCS, partitioner );
#else
if( partitioner.getImplicitSplit( *tempCS ) != CU_QUAD_SPLIT )
{
if( partitioner.canSplit( CU_QUAD_SPLIT, *tempCS ) )

Karsten Suehring
committed
{
m_CABACEstimator->split_cu_flag( split == CU_QUAD_SPLIT, *tempCS, partitioner );
}
if( split != CU_QUAD_SPLIT )
{
m_CABACEstimator->split_cu_mode_mt( split, *tempCS, partitioner );

Karsten Suehring
committed
}

Karsten Suehring
committed
const double factor = ( tempCS->currQP[partitioner.chType] > 30 ? 1.1 : 1.075 );
#if JVET_M0428_ENC_DB_OPT
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
if (!tempCS->useDbCost)
CHECK(bestCS->costDbOffset != 0, "error");
const double cost = m_pcRdCost->calcRdCost( uint64_t( m_CABACEstimator->getEstFracBits() + ( ( bestCS->fracBits ) / factor ) ), Distortion( bestCS->dist / factor ) ) + bestCS->costDbOffset / factor;
#else
const double cost = m_pcRdCost->calcRdCost( uint64_t( m_CABACEstimator->getEstFracBits() + ( ( bestCS->fracBits ) / factor ) ), Distortion( bestCS->dist / factor ) );

Karsten Suehring
committed
m_CABACEstimator->getCtx() = SubCtx( Ctx::SplitFlag, ctxStartSP );
#if JVET_M0421_SPLIT_SIG
m_CABACEstimator->getCtx() = SubCtx( Ctx::SplitQtFlag, ctxStartQt );
m_CABACEstimator->getCtx() = SubCtx( Ctx::SplitHvFlag, ctxStartHv );
m_CABACEstimator->getCtx() = SubCtx( Ctx::Split12Flag, ctxStart12 );
#else
m_CABACEstimator->getCtx() = SubCtx( Ctx::BTSplitFlag, ctxStartBT );

Karsten Suehring
committed
if (cost > bestCS->cost + bestCS->costDbOffset

Christian Helmrich
committed
#if ENABLE_QPA_SUB_CTU
|| (m_pcEncCfg->getUsePerceptQPA() && !m_pcEncCfg->getUseRateCtrl() && pps.getUseDQP() && (pps.getMaxCuDQPDepth() > 0) && (split == CU_HORZ_SPLIT || split == CU_VERT_SPLIT) &&
(partitioner.currArea().lwidth() == tempCS->pcv->maxCUWidth) && (partitioner.currArea().lheight() == tempCS->pcv->maxCUHeight)) // force quad-split or no split at CTU level
#endif
)
{
xCheckBestMode( tempCS, bestCS, partitioner, encTestMode );
return;

Karsten Suehring
committed
}
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
#if JVET_M0170_MRG_SHARELIST
if (!slice.isIntra()
&& tempCS->chType == CHANNEL_TYPE_LUMA
)
{
tempCS->slice->copyMotionLUTs(tempMotCandLUTs, tempCS->slice->getMotionLUTs());
}
int startShareThisLevel = 0;
const uint32_t uiLPelX = tempCS->area.Y().lumaPos().x;
const uint32_t uiTPelY = tempCS->area.Y().lumaPos().y;
int splitRatio = 1;
CHECK(!(split == CU_QUAD_SPLIT || split == CU_HORZ_SPLIT || split == CU_VERT_SPLIT
|| split == CU_TRIH_SPLIT || split == CU_TRIV_SPLIT), "invalid split type");
splitRatio = (split == CU_HORZ_SPLIT || split == CU_VERT_SPLIT) ? 1 : 2;
bool isOneChildSmall = ((tempCS->area.lwidth())*(tempCS->area.lheight()) >> splitRatio) < MRG_SHARELIST_SHARSIZE;
if ((((tempCS->area.lwidth())*(tempCS->area.lheight())) > (MRG_SHARELIST_SHARSIZE * 1)))
{
m_shareState = NO_SHARE;
}
if (m_shareState == NO_SHARE)//init state
{
if (isOneChildSmall)
{
m_shareState = GEN_ON_SHARED_BOUND;//share start state
startShareThisLevel = 1;
}
}
#if JVET_M0483_IBC
if ((m_shareState == GEN_ON_SHARED_BOUND) && (!slice.isIntra() || slice.getSPS()->getIBCFlag()))
#else
if ((m_shareState == GEN_ON_SHARED_BOUND) && (!slice.isIntra()))
{
#if JVET_M0170_MRG_SHARELIST
tempCS->slice->copyMotionLUTs(tempCS->slice->getMotionLUTs(), tempCS->slice->m_MotionCandLuTsBkup);
m_shareBndPosX = uiLPelX;
m_shareBndPosY = uiTPelY;
m_shareBndSizeW = tempCS->area.lwidth();
m_shareBndSizeH = tempCS->area.lheight();
m_shareState = SHARING;
#endif
}
m_pcInterSearch->setShareState(m_shareState);
setShareStateDec(m_shareState);
#endif

Karsten Suehring
committed
partitioner.splitCurrArea( split, *tempCS );
m_CurrCtx++;
tempCS->getRecoBuf().fill( 0 );
#if JVET_M0427_INLOOP_RESHAPER
tempCS->getPredBuf().fill(0);
#endif
AffineMVInfo tmpMVInfo;
bool isAffMVInfoSaved;
m_pcInterSearch->savePrevAffMVInfo(0, tmpMVInfo, isAffMVInfoSaved);

Karsten Suehring
committed
do
{
const auto &subCUArea = partitioner.currArea();
if( tempCS->picture->Y().contains( subCUArea.lumaPos() ) )
{
const unsigned wIdx = gp_sizeIdxInfo->idxFrom( subCUArea.lwidth () );
const unsigned hIdx = gp_sizeIdxInfo->idxFrom( subCUArea.lheight() );
CodingStructure *tempSubCS = m_pTempCS[wIdx][hIdx];
CodingStructure *bestSubCS = m_pBestCS[wIdx][hIdx];
tempCS->initSubStructure( *tempSubCS, partitioner.chType, subCUArea, false );
tempCS->initSubStructure( *bestSubCS, partitioner.chType, subCUArea, false );
LutMotionCand *tempSubMotCandLUTs = m_pTempMotLUTs[wIdx][hIdx];
LutMotionCand *bestSubMotCandLUTs = m_pBestMotLUTs[wIdx][hIdx];
if (tempCS->chType == CHANNEL_TYPE_LUMA)
{
tempCS->slice->copyMotionLUTs(tempMotCandLUTs, tempSubMotCandLUTs);
tempCS->slice->copyMotionLUTs(tempMotCandLUTs, bestSubMotCandLUTs);
}
#if JVET_M0170_MRG_SHARELIST
tempSubCS->sharedBndPos.x = (m_shareState == SHARING) ? m_shareBndPosX : tempSubCS->area.Y().lumaPos().x;
tempSubCS->sharedBndPos.y = (m_shareState == SHARING) ? m_shareBndPosY : tempSubCS->area.Y().lumaPos().y;
tempSubCS->sharedBndSize.width = (m_shareState == SHARING) ? m_shareBndSizeW : tempSubCS->area.lwidth();
tempSubCS->sharedBndSize.height = (m_shareState == SHARING) ? m_shareBndSizeH : tempSubCS->area.lheight();
bestSubCS->sharedBndPos.x = (m_shareState == SHARING) ? m_shareBndPosX : tempSubCS->area.Y().lumaPos().x;
bestSubCS->sharedBndPos.y = (m_shareState == SHARING) ? m_shareBndPosY : tempSubCS->area.Y().lumaPos().y;
bestSubCS->sharedBndSize.width = (m_shareState == SHARING) ? m_shareBndSizeW : tempSubCS->area.lwidth();
bestSubCS->sharedBndSize.height = (m_shareState == SHARING) ? m_shareBndSizeH : tempSubCS->area.lheight();
#endif
xCompressCU( tempSubCS, bestSubCS, partitioner
, tempSubMotCandLUTs
, bestSubMotCandLUTs
);

Karsten Suehring
committed
if( bestSubCS->cost == MAX_DOUBLE )
{
CHECK( split == CU_QUAD_SPLIT, "Split decision reusing cannot skip quad split" );
tempCS->cost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
tempCS->costDbOffset = 0;
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
#endif

Karsten Suehring
committed
m_CurrCtx--;
partitioner.exitCurrSplit();

Karsten Suehring
committed
xCheckBestMode( tempCS, bestCS, partitioner, encTestMode );
{
std::swap(tempMotCandLUTs, bestMotCandLUTs);
}

Karsten Suehring
committed
return;
}
bool keepResi = KEEP_PRED_AND_RESI_SIGNALS;
tempCS->useSubStructure( *bestSubCS, partitioner.chType, CS::getArea( *tempCS, subCUArea, partitioner.chType ), KEEP_PRED_AND_RESI_SIGNALS, true, keepResi, keepResi );
tempCS->slice->copyMotionLUTs(bestSubMotCandLUTs, tempMotCandLUTs);

Karsten Suehring
committed
if(currDepth < pps.getMaxCuDQPDepth())
{
tempCS->prevQP[partitioner.chType] = bestSubCS->prevQP[partitioner.chType];
}
tempSubCS->releaseIntermediateData();
bestSubCS->releaseIntermediateData();
}
} while( partitioner.nextPart( *tempCS ) );
partitioner.exitCurrSplit();
if (startShareThisLevel == 1)
{
m_shareState = NO_SHARE;
m_pcInterSearch->setShareState(m_shareState);
setShareStateDec(m_shareState);
}
#endif

Karsten Suehring
committed
m_CurrCtx--;
// Finally, generate split-signaling bits for RD-cost check
const PartSplit implicitSplit = partitioner.getImplicitSplit( *tempCS );
{
bool enforceQT = implicitSplit == CU_QUAD_SPLIT;
#if HM_QTBT_REPRODUCE_FAST_LCTU_BUG
// LARGE CTU bug

Karsten Suehring
committed
{
unsigned minDepth = 0;
unsigned maxDepth = g_aucLog2[tempCS->sps->getCTUSize()] - g_aucLog2[tempCS->sps->getMinQTSize(slice.getSliceType(), partitioner.chType)];

Karsten Suehring
committed
if( auto ad = dynamic_cast<AdaptiveDepthPartitioner*>( &partitioner ) )
{
ad->setMaxMinDepth( minDepth, maxDepth, *tempCS );
}
if( minDepth > partitioner.currQtDepth )
{
// enforce QT
enforceQT = true;
}
}
#endif
if( !enforceQT )
{
m_CABACEstimator->resetBits();
#if JVET_M0421_SPLIT_SIG
m_CABACEstimator->split_cu_mode( split, *tempCS, partitioner );
#else

Karsten Suehring
committed
if( partitioner.canSplit( CU_QUAD_SPLIT, *tempCS ) )
{
m_CABACEstimator->split_cu_flag( split == CU_QUAD_SPLIT, *tempCS, partitioner );
}
if( split != CU_QUAD_SPLIT )
{
m_CABACEstimator->split_cu_mode_mt( split, *tempCS, partitioner );
}

Karsten Suehring
committed
1484
1485
1486
1487
1488
1489
1490
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
1526
1527
1528
tempCS->fracBits += m_CABACEstimator->getEstFracBits(); // split bits
}
}
tempCS->cost = m_pcRdCost->calcRdCost( tempCS->fracBits, tempCS->dist );
// Check Delta QP bits for splitted structure
xCheckDQP( *tempCS, partitioner, true );
// If the configuration being tested exceeds the maximum number of bytes for a slice / slice-segment, then
// a proper RD evaluation cannot be performed. Therefore, termination of the
// slice/slice-segment must be made prior to this CTU.
// This can be achieved by forcing the decision to be that of the rpcTempCU.
// The exception is each slice / slice-segment must have at least one CTU.
if (bestCS->cost != MAX_DOUBLE)
{
#if HEVC_TILES_WPP
const TileMap& tileMap = *tempCS->picture->tileMap;
#endif
#if HEVC_TILES_WPP || HEVC_DEPENDENT_SLICES
const uint32_t CtuAddr = CU::getCtuAddr( *bestCS->getCU( partitioner.chType ) );
#endif
const bool isEndOfSlice = slice.getSliceMode() == FIXED_NUMBER_OF_BYTES
&& ((slice.getSliceBits() + CS::getEstBits(*bestCS)) > slice.getSliceArgument() << 3)
#if HEVC_TILES_WPP
&& CtuAddr != tileMap.getCtuTsToRsAddrMap(slice.getSliceCurStartCtuTsAddr())
#endif
#if HEVC_DEPENDENT_SLICES
&& CtuAddr != tileMap.getCtuTsToRsAddrMap(slice.getSliceSegmentCurStartCtuTsAddr());
#else
;
#endif
#if HEVC_DEPENDENT_SLICES
const bool isEndOfSliceSegment = slice.getSliceSegmentMode() == FIXED_NUMBER_OF_BYTES
&& ((slice.getSliceSegmentBits() + CS::getEstBits(*bestCS)) > slice.getSliceSegmentArgument() << 3)
&& CtuAddr != tileMap.getCtuTsToRsAddrMap(slice.getSliceSegmentCurStartCtuTsAddr());
// Do not need to check slice condition for slice-segment since a slice-segment is a subset of a slice.
if (isEndOfSlice || isEndOfSliceSegment)
#else
if(isEndOfSlice)
#endif
{
bestCS->cost = MAX_DOUBLE;

Karsten Suehring
committed
}
}
#if JVET_M0428_ENC_DB_OPT
else
{
bestCS->costDbOffset = 0;
}
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
#endif

Karsten Suehring
committed
// RD check for sub partitioned coding structure.

Karsten Suehring
committed
xCheckBestMode( tempCS, bestCS, partitioner, encTestMode );
if (isAffMVInfoSaved)
m_pcInterSearch->addAffMVInfo(tmpMVInfo);
if ((!slice.isIntra() || slice.getSPS()->getIBCFlag())
{
std::swap(tempMotCandLUTs, bestMotCandLUTs);
}
tempCS->slice->copyMotionLUTs(m_pSplitTempMotLUTs[wParIdx][hParIdx], tempMotCandLUTs);
}

Karsten Suehring
committed
tempCS->releaseIntermediateData();
tempCS->prevQP[partitioner.chType] = oldPrevQp;
}
void EncCu::xCheckRDCostIntra( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode )
{

Karsten Suehring
committed
double bestInterCost = m_modeCtrl->getBestInterCost();
double costSize2Nx2NemtFirstPass = m_modeCtrl->getEmtSize2Nx2NFirstPassCost();
bool skipSecondEmtPass = m_modeCtrl->getSkipSecondEMTPass();
const SPS &sps = *tempCS->sps;
#endif
const PPS &pps = *tempCS->pps;
#if !JVET_M0464_UNI_MTS

Karsten Suehring
committed
const CodingUnit *bestCU = bestCS->getCU( partitioner.chType );
const int maxSizeEMT = EMT_INTRA_MAX_CU_WITH_QTBT;
uint8_t considerEmtSecondPass = ( sps.getUseIntraEMT() && isLuma( partitioner.chType ) && partitioner.currArea().lwidth() <= maxSizeEMT && partitioner.currArea().lheight() <= maxSizeEMT ) ? 1 : 0;

Karsten Suehring
committed
#if JVET_M0102_INTRA_SUBPARTITIONS
bool useIntraSubPartitions = false;
double maxCostAllowedForChroma = MAX_DOUBLE;
#if JVET_M0464_UNI_MTS
const CodingUnit *bestCU = bestCS->getCU( partitioner.chType );
#endif
#endif

Karsten Suehring
committed
Distortion interHad = m_modeCtrl->getInterHad();

Karsten Suehring
committed
for( uint8_t emtCuFlag = 0; emtCuFlag <= considerEmtSecondPass; emtCuFlag++ )
{
//Possible early EMT tests interruptions
//2) Second EMT pass. This "if clause" is necessary because of the NSST and PDPC "for loops".
if( emtCuFlag && skipSecondEmtPass )
{
continue;
}
//3) if interHad is 0, only try further modes if some intra mode was already better than inter
if( m_pcEncCfg->getUsePbIntraFast() && !tempCS->slice->isIntra() && bestCU && CU::isInter( *bestCS->getCU( partitioner.chType ) ) && interHad == 0 )
{
continue;
}

Karsten Suehring
committed
tempCS->initStructData( encTestMode.qp, encTestMode.lossless );
CodingUnit &cu = tempCS->addCU( CS::getArea( *tempCS, tempCS->area, partitioner.chType ), partitioner.chType );
partitioner.setCUData( cu );
cu.slice = tempCS->slice;
#if HEVC_TILES_WPP
cu.tileIdx = tempCS->picture->tileMap->getTileIdxMap( tempCS->area.lumaPos() );
#endif
cu.skip = false;
cu.mmvdSkip = false;

Karsten Suehring
committed
cu.predMode = MODE_INTRA;
cu.transQuantBypass = encTestMode.lossless;
cu.chromaQpAdj = cu.transQuantBypass ? 0 : m_cuChromaQpOffsetIdxPlus1;
cu.qp = encTestMode.qp;
//cu.ipcm = false;

Karsten Suehring
committed
cu.emtFlag = emtCuFlag;
#if JVET_M0102_INTRA_SUBPARTITIONS
cu.ispMode = NOT_INTRA_SUBPARTITIONS;
#endif

Karsten Suehring
committed
CU::addPUs( cu );
tempCS->interHad = interHad;
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif

Karsten Suehring
committed
if( isLuma( partitioner.chType ) )
{
#if JVET_M0102_INTRA_SUBPARTITIONS
//the Intra SubPartitions mode uses the value of the best cost so far (luma if it is the fast version) to avoid test non-necessary lines
const double bestCostSoFar = CS::isDualITree( *tempCS ) ? m_modeCtrl->getBestCostWithoutSplitFlags() : bestCU && bestCU->predMode == MODE_INTRA ? bestCS->lumaCost : bestCS->cost;
m_pcIntraSearch->estIntraPredLumaQT( cu, partitioner, bestCostSoFar );
useIntraSubPartitions = cu.ispMode != NOT_INTRA_SUBPARTITIONS;
if( !CS::isDualITree( *tempCS ) )
{
tempCS->lumaCost = m_pcRdCost->calcRdCost( tempCS->fracBits, tempCS->dist );
if( useIntraSubPartitions )
{
//the difference between the best cost so far and the current luma cost is stored to avoid testing the Cr component if the cost of luma + Cb is larger than the best cost
maxCostAllowedForChroma = bestCS->cost < MAX_DOUBLE ? bestCS->cost - tempCS->lumaCost : MAX_DOUBLE;
}
}
#else

Karsten Suehring
committed
m_pcIntraSearch->estIntraPredLumaQT( cu, partitioner );

Karsten Suehring
committed
if (m_pcEncCfg->getUsePbIntraFast() && tempCS->dist == std::numeric_limits<Distortion>::max()
&& tempCS->interHad == 0)
{
interHad = 0;
// JEM assumes only perfect reconstructions can from now on beat the inter mode
m_modeCtrl->enforceInterHad( 0 );

Karsten Suehring
committed
continue;

Karsten Suehring
committed
}
if( !CS::isDualITree( *tempCS ) )
{
cu.cs->picture->getRecoBuf( cu.Y() ).copyFrom( cu.cs->getRecoBuf( COMPONENT_Y ) );
#if JVET_M0427_INLOOP_RESHAPER
cu.cs->picture->getPredBuf(cu.Y()).copyFrom(cu.cs->getPredBuf(COMPONENT_Y));
#endif

Karsten Suehring
committed
}
}
if( tempCS->area.chromaFormat != CHROMA_400 && ( partitioner.chType == CHANNEL_TYPE_CHROMA || !CS::isDualITree( *tempCS ) ) )
{
#if JVET_M0102_INTRA_SUBPARTITIONS
TUIntraSubPartitioner subTuPartitioner( partitioner );
m_pcIntraSearch->estIntraPredChromaQT( cu, ( !useIntraSubPartitions || ( CS::isDualITree( *cu.cs ) && !isLuma( CHANNEL_TYPE_CHROMA ) ) ) ? partitioner : subTuPartitioner, maxCostAllowedForChroma );
if( useIntraSubPartitions && !cu.ispMode )
{
//At this point the temp cost is larger than the best cost. Therefore, we can already skip the remaining calculations
#if JVET_M0464_UNI_MTS
return;
#else
continue;
#endif
}
#else

Karsten Suehring
committed
m_pcIntraSearch->estIntraPredChromaQT( cu, partitioner );

Karsten Suehring
committed
}
cu.rootCbf = false;
for( uint32_t t = 0; t < getNumberValidTBlocks( *cu.cs->pcv ); t++ )
{
cu.rootCbf |= cu.firstTU->cbf[t] != 0;
}
// Get total bits for current mode: encode CU
m_CABACEstimator->resetBits();
if( pps.getTransquantBypassEnabledFlag() )
{
m_CABACEstimator->cu_transquant_bypass_flag( cu );
}
if ((!cu.cs->slice->isIntra() || cu.cs->slice->getSPS()->getIBCFlag())

Karsten Suehring
committed
{
m_CABACEstimator->cu_skip_flag ( cu );
}
m_CABACEstimator->pred_mode ( cu );
m_CABACEstimator->extend_ref_line( cu );
#if JVET_M0102_INTRA_SUBPARTITIONS
m_CABACEstimator->isp_mode ( cu );
#endif

Karsten Suehring
committed
m_CABACEstimator->cu_pred_data ( cu );
m_CABACEstimator->pcm_data ( cu, partitioner );

Karsten Suehring
committed
// Encode Coefficients
CUCtx cuCtx;
cuCtx.isDQPCoded = true;
cuCtx.isChromaQpAdjCoded = true;
m_CABACEstimator->cu_residual( cu, partitioner, cuCtx );
tempCS->fracBits = m_CABACEstimator->getEstFracBits();
tempCS->cost = m_pcRdCost->calcRdCost(tempCS->fracBits, tempCS->dist);
#if JVET_M0102_INTRA_SUBPARTITIONS
#if !JVET_M0464_UNI_MTS
double bestIspCost = cu.ispMode ? CS::isDualITree(*tempCS) ? tempCS->cost : tempCS->lumaCost : MAX_DOUBLE;
#endif
const double tmpCostWithoutSplitFlags = tempCS->cost;
#endif

Karsten Suehring
committed
xEncodeDontSplit( *tempCS, partitioner );
xCheckDQP( *tempCS, partitioner );
#if JVET_M0102_INTRA_SUBPARTITIONS
if( tempCS->cost < bestCS->cost )
{
m_modeCtrl->setBestCostWithoutSplitFlags( tmpCostWithoutSplitFlags );
}
#endif

Karsten Suehring
committed
// we save the cost of the modes for the first EMT pass
if( !emtCuFlag ) static_cast< double& >( costSize2Nx2NemtFirstPass ) = tempCS->cost;

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 );
#if JVET_M0102_INTRA_SUBPARTITIONS
//we decide to skip the second emt pass or not according to the ISP results
if (considerEmtSecondPass && cu.ispMode && !emtCuFlag && tempCS->slice->isIntra())
{
double bestCostDct2NoIsp = m_modeCtrl->getEmtFirstPassNoIspCost();
CHECKD(bestCostDct2NoIsp <= bestIspCost, "wrong cost!");
double nSamples = (double)(cu.lwidth() << g_aucLog2[cu.lheight()]);
double threshold = 1 + 1.4 / sqrt(nSamples);
if (bestCostDct2NoIsp > bestIspCost*threshold)
{
skipSecondEmtPass = true;
m_modeCtrl->setSkipSecondEMTPass(true);
break;
}
}
#endif

Karsten Suehring
committed
//now we check whether the second pass of SIZE_2Nx2N and the whole Intra SIZE_NxN should be skipped or not
if( !emtCuFlag && !tempCS->slice->isIntra() && bestCU && bestCU->predMode != MODE_INTRA && m_pcEncCfg->getFastInterEMT() )

Karsten Suehring
committed
{
const double thEmtInterFastSkipIntra = 1.4; // Skip checking Intra if "2Nx2N using DCT2" is worse than best Inter mode
if( costSize2Nx2NemtFirstPass > thEmtInterFastSkipIntra * bestInterCost )
{
skipSecondEmtPass = true;
m_modeCtrl->setSkipSecondEMTPass( true );
break;
}
}

Karsten Suehring
committed
} //for emtCuFlag
}
void EncCu::xCheckIntraPCM(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode )
{
tempCS->initStructData( encTestMode.qp, encTestMode.lossless );
CodingUnit &cu = tempCS->addCU( CS::getArea( *tempCS, tempCS->area, partitioner.chType ), partitioner.chType );

Karsten Suehring
committed
partitioner.setCUData( cu );
cu.slice = tempCS->slice;
#if HEVC_TILES_WPP
cu.tileIdx = tempCS->picture->tileMap->getTileIdxMap( tempCS->area.lumaPos() );
#endif
cu.skip = false;
cu.mmvdSkip = false;

Karsten Suehring
committed
cu.predMode = MODE_INTRA;
cu.transQuantBypass = encTestMode.lossless;
cu.chromaQpAdj = cu.transQuantBypass ? 0 : m_cuChromaQpOffsetIdxPlus1;
cu.qp = encTestMode.qp;
cu.ipcm = true;
tempCS->addPU( CS::getArea( *tempCS, tempCS->area, partitioner.chType ), partitioner.chType );
tempCS->addTU( CS::getArea( *tempCS, tempCS->area, partitioner.chType ), partitioner.chType );

Karsten Suehring
committed
m_pcIntraSearch->IPCMSearch(*tempCS, partitioner);
m_CABACEstimator->getCtx() = m_CurrCtx->start;
m_CABACEstimator->resetBits();
if( tempCS->pps->getTransquantBypassEnabledFlag() )
{
m_CABACEstimator->cu_transquant_bypass_flag( cu );
}
if ((!cu.cs->slice->isIntra() || cu.cs->slice->getSPS()->getIBCFlag())

Karsten Suehring
committed
{
m_CABACEstimator->cu_skip_flag ( cu );
}
m_CABACEstimator->pred_mode ( cu );
m_CABACEstimator->pcm_data ( cu, partitioner );

Karsten Suehring
committed
tempCS->fracBits = m_CABACEstimator->getEstFracBits();
tempCS->cost = m_pcRdCost->calcRdCost(tempCS->fracBits, tempCS->dist);
xEncodeDontSplit( *tempCS, partitioner );
xCheckDQP( *tempCS, partitioner );

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 );
}
void EncCu::xCheckDQP( CodingStructure& cs, Partitioner& partitioner, bool bKeepCtx )
{
CHECK( bKeepCtx && cs.cus.size() <= 1 && partitioner.getImplicitSplit( cs ) == CU_DONT_SPLIT, "bKeepCtx should only be set in split case" );
CHECK( !bKeepCtx && cs.cus.size() > 1, "bKeepCtx should never be set for non-split case" );
if( !cs.pps->getUseDQP() )
{
return;
}

Christian Helmrich
committed
if (CS::isDualITree(cs) && isChroma(partitioner.chType))
{
return;
}

Karsten Suehring
committed
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
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
if( bKeepCtx && partitioner.currDepth != cs.pps->getMaxCuDQPDepth() )
{
return;
}
if( !bKeepCtx && partitioner.currDepth > cs.pps->getMaxCuDQPDepth() )
{
return;
}
CodingUnit* cuFirst = cs.getCU( partitioner.chType );
CHECK( !cuFirst, "No CU available" );
bool hasResidual = false;
for( const auto &cu : cs.cus )
{
if( cu->rootCbf )
{
hasResidual = true;
break;
}
}
int predQP = CU::predictQP( *cuFirst, cs.prevQP[partitioner.chType] );
if( hasResidual )
{
TempCtx ctxTemp( m_CtxCache );
if( !bKeepCtx ) ctxTemp = SubCtx( Ctx::DeltaQP, m_CABACEstimator->getCtx() );
m_CABACEstimator->resetBits();
m_CABACEstimator->cu_qp_delta( *cuFirst, predQP, cuFirst->qp );
cs.fracBits += m_CABACEstimator->getEstFracBits(); // dQP bits
cs.cost = m_pcRdCost->calcRdCost(cs.fracBits, cs.dist);
if( !bKeepCtx ) m_CABACEstimator->getCtx() = SubCtx( Ctx::DeltaQP, ctxTemp );
// NOTE: reset QPs for CUs without residuals up to first coded CU
for( const auto &cu : cs.cus )
{
if( cu->rootCbf )
{
break;
}
cu->qp = predQP;
}
}
else
{
// No residuals: reset CU QP to predicted value
for( const auto &cu : cs.cus )
{
cu->qp = predQP;
}
}
}
void EncCu::xFillPCMBuffer( CodingUnit &cu )
{
const ChromaFormat format = cu.chromaFormat;
const uint32_t numberValidComponents = getNumberValidComponents(format);
for( auto &tu : CU::traverseTUs( cu ) )
{
for( uint32_t ch = 0; ch < numberValidComponents; ch++ )
{
const ComponentID compID = ComponentID( ch );
const CompArea &compArea = tu.blocks[ compID ];
const CPelBuf source = tu.cs->getOrgBuf( compArea );
PelBuf destination = tu.getPcmbuf( compID );
destination.copyFrom( source );
}
}
}
#if JVET_M0253_HASH_ME
void EncCu::xCheckRDCostHashInter( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode )
{
bool isPerfectMatch = false;
tempCS->initStructData(encTestMode.qp, encTestMode.lossless);
m_pcInterSearch->resetBufferedUniMotions();
m_pcInterSearch->setAffineModeSelected(false);
CodingUnit &cu = tempCS->addCU(tempCS->area, partitioner.chType);

Karsten Suehring
committed
partitioner.setCUData(cu);
cu.slice = tempCS->slice;
cu.skip = false;
cu.predMode = MODE_INTER;
cu.transQuantBypass = encTestMode.lossless;
cu.chromaQpAdj = cu.transQuantBypass ? 0 : m_cuChromaQpOffsetIdxPlus1;
cu.qp = encTestMode.qp;
CU::addPUs(cu);
cu.mmvdSkip = false;
cu.firstPU->mmvdMergeFlag = false;
if (m_pcInterSearch->predInterHashSearch(cu, partitioner, isPerfectMatch))
{
const unsigned wIdx = gp_sizeIdxInfo->idxFrom(tempCS->area.lwidth());
double equGBiCost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
#if JVET_M0464_UNI_MTS
xEncodeInterResidual(tempCS, bestCS, partitioner, encTestMode, 0
, m_pImvTempCS ? m_pImvTempCS[wIdx] : NULL
, 0
, &equGBiCost
#else
xEncodeInterResidual(tempCS, bestCS, partitioner, encTestMode, 0
, m_pImvTempCS ? m_pImvTempCS[wIdx] : NULL
, 1
, 0
, &equGBiCost
#endif
);
if ( m_bestModeUpdated && bestCS->cost != MAX_DOUBLE )
{
xCalDebCost( *bestCS, partitioner );
}
}
tempCS->initStructData(encTestMode.qp, encTestMode.lossless);

Karsten Suehring
committed
if (cu.lwidth() != 64)
{
isPerfectMatch = false;
}
m_modeCtrl->setIsHashPerfectMatch(isPerfectMatch);
}
#endif

Karsten Suehring
committed
void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode )
{
const Slice &slice = *tempCS->slice;
CHECK( slice.getSliceType() == I_SLICE, "Merge modes not available for I-slices" );
tempCS->initStructData( encTestMode.qp, encTestMode.lossless );
MergeCtx mergeCtx;
const SPS &sps = *tempCS->sps;
if( sps.getSBTMVPEnabledFlag() )

Karsten Suehring
committed
{
Size bufSize = g_miScaling.scale( tempCS->area.lumaSize() );
mergeCtx.subPuMvpMiBuf = MotionBuf( m_SubPuMiBuf, bufSize );
}
#if JVET_M0147_DMVR
Mv refinedMvdL0[MAX_NUM_PARTS_IN_CTU][MRG_MAX_NUM_CANDS];
#endif
setMergeBestSATDCost( MAX_DOUBLE );

Karsten Suehring
committed
{
// first get merge candidates
CodingUnit cu( tempCS->area );
cu.cs = tempCS;
cu.predMode = MODE_INTER;
cu.slice = tempCS->slice;
#if HEVC_TILES_WPP
cu.tileIdx = tempCS->picture->tileMap->getTileIdxMap(tempCS->area.lumaPos());
#endif
PredictionUnit pu( tempCS->area );
pu.cu = &cu;
pu.cs = tempCS;
#if JVET_M0170_MRG_SHARELIST
pu.shareParentPos = tempCS->sharedBndPos;
pu.shareParentSize = tempCS->sharedBndSize;
#endif
PU::getInterMergeCandidates(pu, mergeCtx
, 0
);
PU::restrictBiPredMergeCands(pu, mergeCtx);
PU::getInterMMVDMergeCandidates(pu, mergeCtx);

Karsten Suehring
committed
}
bool candHasNoResidual[MRG_MAX_NUM_CANDS + MMVD_ADD_NUM];
for (uint32_t ui = 0; ui < MRG_MAX_NUM_CANDS + MMVD_ADD_NUM; ui++)
{
candHasNoResidual[ui] = false;
}

Karsten Suehring
committed
bool bestIsSkip = false;
bool bestIsMMVDSkip = true;
PelUnitBuf acMergeBuffer[MRG_MAX_NUM_CANDS];
PelUnitBuf acMergeRealBuffer[MMVD_MRG_MAX_RD_BUF_NUM];
PelUnitBuf * acMergeTempBuffer[MMVD_MRG_MAX_RD_NUM];
PelUnitBuf * singleMergeTempBuffer;
int insertPos;
unsigned uiNumMrgSATDCand = mergeCtx.numValidMergeCand + MMVD_ADD_NUM;
static_vector<unsigned, MRG_MAX_NUM_CANDS + MMVD_ADD_NUM> RdModeList;
bool mrgTempBufSet = false;
for (unsigned i = 0; i < MRG_MAX_NUM_CANDS + MMVD_ADD_NUM; i++)
{
RdModeList.push_back(i);
}

Karsten Suehring
committed
const UnitArea localUnitArea(tempCS->area.chromaFormat, Area(0, 0, tempCS->area.Y().width, tempCS->area.Y().height));
for (unsigned i = 0; i < MMVD_MRG_MAX_RD_BUF_NUM; i++)
{
acMergeRealBuffer[i] = m_acMergeBuffer[i].getBuf(localUnitArea);
if (i < MMVD_MRG_MAX_RD_NUM)
{
acMergeTempBuffer[i] = acMergeRealBuffer + i;
}
else
{
singleMergeTempBuffer = acMergeRealBuffer + i;
}
}
static_vector<unsigned, MRG_MAX_NUM_CANDS + MMVD_ADD_NUM> RdModeList2; // store the Intra mode for Intrainter
RdModeList2.clear();
bool isIntrainterEnabled = sps.getUseMHIntra();
if (bestCS->area.lwidth() * bestCS->area.lheight() < 64 || bestCS->area.lwidth() >= MAX_CU_SIZE || bestCS->area.lheight() >= MAX_CU_SIZE)
{
isIntrainterEnabled = false;
}
bool isTestSkipMerge[MRG_MAX_NUM_CANDS]; // record if the merge candidate has tried skip mode
for (uint32_t idx = 0; idx < MRG_MAX_NUM_CANDS; idx++)
{
isTestSkipMerge[idx] = false;
}
if( m_pcEncCfg->getUseFastMerge() || isIntrainterEnabled)

Karsten Suehring
committed
{
uiNumMrgSATDCand = NUM_MRG_SATD_CAND;
if (isIntrainterEnabled)
{
uiNumMrgSATDCand += 1;
}

Karsten Suehring
committed
bestIsSkip = false;
if( auto blkCache = dynamic_cast< CacheBlkInfoCtrl* >( m_modeCtrl ) )
{
#if JVET_M0483_IBC
if (slice.getSPS()->getIBCFlag())
#else
if (slice.getSPS()->getIBCMode())
{
ComprCUCtx cuECtx = m_modeCtrl->getComprCUCtx();
bestIsSkip = blkCache->isSkip(tempCS->area) && cuECtx.bestCU;
}
else

Karsten Suehring
committed
bestIsSkip = blkCache->isSkip( tempCS->area );
bestIsMMVDSkip = blkCache->isMMVDSkip(tempCS->area);

Karsten Suehring
committed
}
if (isIntrainterEnabled) // always perform low complexity check
{
bestIsSkip = false;
}
static_vector<double, MRG_MAX_NUM_CANDS + MMVD_ADD_NUM> candCostList;

Karsten Suehring
committed
// 1. Pass: get SATD-cost for selected candidates and reduce their count
if( !bestIsSkip )
{
RdModeList.clear();
mrgTempBufSet = true;
const double sqrtLambdaForFirstPass = m_pcRdCost->getMotionLambda( encTestMode.lossless );
CodingUnit &cu = tempCS->addCU( tempCS->area, partitioner.chType );
const double sqrtLambdaForFirstPassIntra = m_pcRdCost->getMotionLambda(cu.transQuantBypass) / double(1 << SCALE_BITS);

Karsten Suehring
committed
partitioner.setCUData( cu );
cu.slice = tempCS->slice;
#if HEVC_TILES_WPP
cu.tileIdx = tempCS->picture->tileMap->getTileIdxMap( tempCS->area.lumaPos() );
#endif
cu.skip = false;
cu.mmvdSkip = false;
cu.triangle = false;

Karsten Suehring
committed
//cu.affine
cu.predMode = MODE_INTER;
//cu.LICFlag
cu.transQuantBypass = encTestMode.lossless;
cu.chromaQpAdj = cu.transQuantBypass ? 0 : m_cuChromaQpOffsetIdxPlus1;
cu.qp = encTestMode.qp;
//cu.emtFlag is set below
PredictionUnit &pu = tempCS->addPU( cu, partitioner.chType );
DistParam distParam;
const bool bUseHadamard= !encTestMode.lossless;
m_pcRdCost->setDistParam (distParam, tempCS->getOrgBuf().Y(), m_acMergeBuffer[0].Y(), sps.getBitDepth (CHANNEL_TYPE_LUMA), COMPONENT_Y, bUseHadamard);
Loading
Loading full blame...