Commit f83271a0 authored by Christian Helmrich's avatar Christian Helmrich

merge from master

parents ac87c3ff c81b8ade
......@@ -187,6 +187,9 @@ uint32_t DecApp::decode()
{
m_cDecLib.executeLoopFilters();
m_cDecLib.finishPicture( poc, pcListPic );
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
CodingStatistics::UpdateMaxStat(backupStats);
#endif
}
loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
if (nalu.m_nalUnitType == NAL_UNIT_EOS)
......
......@@ -43,6 +43,9 @@
#include "StreamMergeApp.h"
#include "DecoderLib/AnnexBread.h"
#include "DecoderLib/NALread.h"
#if RExt__DECODER_DEBUG_BIT_STATISTICS
#include "CommonLib/CodingStatistics.h"
#endif
//! \ingroup DecoderApp
//! \{
......@@ -171,7 +174,7 @@ _byteStreamNALUnit(
while (bs.eofBeforeNBytes(24 / 8, istream) || bs.peekBytes(24 / 8, istream) > 2)
{
#if RExt__DECODER_DEBUG_BIT_STATISTICS
uint8_t thebyte = bs.readByte(); bodyStats.bits += 8; bodyStats.count++;
uint8_t thebyte = bs.readByte(istream); bodyStats.bits += 8; bodyStats.count++;
nalUnit.push_back(thebyte);
#else
nalUnit.push_back(bs.readByte(istream));
......
......@@ -86,6 +86,14 @@ enum CodingStatisticsType
STATS__CABAC_BITS__GT2_FLAG,
STATS__CABAC_BITS__SIGN_BIT,
STATS__CABAC_BITS__ESCAPE_BITS,
#if TR_ONLY_COEFF_STATS
STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG_TS,
STATS__CABAC_BITS__PAR_FLAG_TS,
STATS__CABAC_BITS__GT1_FLAG_TS,
STATS__CABAC_BITS__GT2_FLAG_TS,
STATS__CABAC_BITS__SIGN_BIT_TS,
STATS__CABAC_BITS__ESCAPE_BITS_TS,
#endif
STATS__CABAC_BITS__SAO,
STATS__CABAC_BITS__ALF,
STATS__CABAC_TRM_BITS,
......@@ -171,6 +179,14 @@ static inline const char* getName(CodingStatisticsType name)
"CABAC_BITS__GT2_FLAG",
"CABAC_BITS__SIGN_BIT",
"CABAC_BITS__ESCAPE_BITS",
#if TR_ONLY_COEFF_STATS
"CABAC_BITS__SIG_COEFF_MAP_FLAG_TS",
"CABAC_BITS__PAR_FLAG_TS",
"CABAC_BITS__GT1_FLAG_TS",
"CABAC_BITS__GT2_FLAG_TS",
"CABAC_BITS__SIGN_BIT_TS",
"CABAC_BITS__ESCAPE_BITS_TS",
#endif
"CABAC_BITS__SAO",
"CABAC_BITS__LFNST",
"CABAC_BITS__ALF",
......@@ -309,6 +325,13 @@ public:
{
bits += src.bits; count += src.count; sum += src.sum; classCount += src.classCount; return *this;
}
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
SStat &operator-=(const SStat &src)
{
bits -= src.bits; count -= src.count; sum -= src.sum; classCount -= src.classCount; return *this;
}
#endif
};
struct StatTool
......@@ -327,12 +350,45 @@ public:
}
};
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
struct SStat_max
{
SStat max_CABAC_state;
SStat max_EP_state;
SStat trf_CABAC_state;
SStat trf_EP_state;
SStat acc_trf_CABAC_state;
SStat acc_trf_EP_state;
SStat prev_CABAC_state;
SStat prev_EP_state;
SStat prev_trf_CABAC_state;
SStat prev_trf_EP_state;
void clear()
{
max_CABAC_state.clear();
max_EP_state.clear();
trf_CABAC_state.clear();
trf_EP_state.clear();
acc_trf_CABAC_state.clear();
acc_trf_EP_state.clear();
prev_CABAC_state.clear();
prev_EP_state.clear();
prev_trf_CABAC_state.clear();
prev_trf_EP_state.clear();
}
};
#endif
class CodingStatisticsData
{
private:
SStat statistics [STATS__NUM_STATS + 1][CODING_STATS_NUM_SUBCLASSES];
SStat statistics_ep [STATS__NUM_STATS + 1][CODING_STATS_NUM_SUBCLASSES];
StatTool statistics_tool [STATS__NUM_STATS + 1][CODING_STATS_NUM_SUBCLASSES];
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
SStat_max statistics_max;
#endif
std::map<std::string, SStat> mappings_ep;
friend class CodingStatistics;
};
......@@ -429,6 +485,10 @@ private:
int64_t classCounts[STATS__NUM_STATS];
std::fill_n( classCounts, ( size_t ) STATS__NUM_STATS, 0 );
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
SStat_max &max = GetStatisticMax();
#endif
int64_t cr = 0; // CABAC remainder, which is added to "STATS__CABAC_INITIALISATION"
{
int64_t totalCABACbits = 0, roundedCABACbits = 0;
......@@ -522,6 +582,18 @@ private:
{
cabacSubTotal.classCount = classCounts[i];
OutputLine( pName, '~', "~~ST~~", "~~ST~~", "~~ST~~", cabacSubTotal, epSubTotal );
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
// For TRF
if ((i == STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG) || (i == STATS__CABAC_BITS__PAR_FLAG)
|| (i == STATS__CABAC_BITS__GT1_FLAG) || (i == STATS__CABAC_BITS__GT2_FLAG)
|| (i == STATS__CABAC_BITS__ESCAPE_BITS))
{
max.acc_trf_CABAC_state += cabacSubTotal;
max.acc_trf_EP_state += epSubTotal;
}
#endif
}
if( i == STATS__NAL_UNIT_TOTAL_BODY )
{
......@@ -604,6 +676,12 @@ private:
OutputDashedLine( "GRAND TOTAL" );
epTotalBits += cavlcTotalBits;
OutputLine ( "TOTAL", '~', "~~GT~~", "~~GT~~", "~~GT~~", cabacTotalBits, epTotalBits );
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
OutputDashedLine("");
OutputLine("CABAC MAX FRAME stat", '~', "~~ST~~", "~~ST~~", "~~ST~~", max.max_CABAC_state, max.max_EP_state);
OutputLine("CABAC MAX FRAME TRF stat", '~', "~~ST~~", "~~ST~~", "~~ST~~", max.trf_CABAC_state, max.trf_EP_state);
OutputLine("CABAC Accumulated TRF stat", '~', "~~ST~~", "~~ST~~", "~~ST~~", max.acc_trf_CABAC_state, max.acc_trf_EP_state);
#endif
}
void OutputToolStats()
......@@ -712,6 +790,10 @@ public:
static StatTool &GetStatisticTool ( const CodingStatisticsClassType &stat ) { return GetSingletonInstance().data.statistics_tool[stat.type][stat.subClass]; }
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
static SStat_max &GetStatisticMax() { return GetSingletonInstance().data.statistics_max; }
#endif
static int getNumOnes( int bins )
{
CHECK( bins < 0, "Bins should not be nagative" );
......@@ -730,7 +812,11 @@ public:
CHECK( stat.type == STATS__CABAC_BITS__INVALID, "Should never be used." );
SStat &s = GetStatisticEP( stat );
s.bits += numBits;
#if EPBINCOUNT_FIX
s.count += numBits;
#else
s.count++;
#endif
s.sum += getNumOnes( value );
}
......@@ -738,7 +824,11 @@ public:
{
SStat &s = GetStatisticEP( str );
s.bits += numBits;
#if EPBINCOUNT_FIX
s.count += numBits;
#else
s.count++;
#endif
s.sum += getNumOnes( value );
}
......@@ -746,7 +836,11 @@ public:
{
SStat &s = GetStatisticEP( pKey );
s.bits += numBits;
#if EPBINCOUNT_FIX
s.count += numBits;
#else
s.count++;
#endif
s.sum += getNumOnes( value );
}
......@@ -776,6 +870,123 @@ public:
s.count++;
s.sum += val;
}
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
static void UpdateMaxStat(CodingStatisticsData *data)
{
SStat_max & max = GetStatisticMax();
const int64_t es = CODINGSTATISTICS_ENTROPYSCALE;
int64_t countTotal = 0;
int64_t classCounts[STATS__NUM_STATS];
std::fill_n(classCounts, (size_t) STATS__NUM_STATS, 0);
int64_t cr = 0; // CABAC remainder, which is added to "STATS__CABAC_INITIALISATION"
int64_t totalCABACbits = 0, roundedCABACbits = 0;
for (int i = STATS__NAL_UNIT_PACKING; i < STATS__NUM_STATS; i++)
{
int64_t classCount = 0;
for (uint32_t c = 0; c < CODING_STATS_NUM_SUBCLASSES; c++)
{
totalCABACbits += data->statistics[i][c].bits;
roundedCABACbits += data->statistics[i][c].bits / es;
classCount += data->statistics[i][c].count;
}
for (uint32_t c = 0; c < CODING_STATS_NUM_SUBCLASSES; c++)
{
data->statistics[i][c].classCount = classCount;
}
classCounts[i] = classCount;
countTotal += classCount;
}
int64_t remainder = totalCABACbits - roundedCABACbits * es;
cr = (remainder + es / 2) / es;
classCounts[0] = countTotal;
SStat cabacTotalBits, epTotalBits, cabacTrfTotalBits, epTrfTotalBits;
cabacTotalBits.classCount = countTotal;
epTotalBits.classCount = countTotal;
cabacTrfTotalBits.classCount = countTotal;
epTrfTotalBits.classCount = countTotal;
// Calculate the actual bin and bit count
for (int i = 0; i < STATS__NUM_STATS; i++)
{
for (uint32_t c = 0; c < CODING_STATS_NUM_SUBCLASSES; c++)
{
SStat &sCABACorig = data->statistics[i][c];
SStat &sEP = data->statistics_ep[i][c];
if (sCABACorig.bits == 0 && sEP.bits == 0)
{
continue;
}
SStat sCABAC;
{
int64_t thisCABACbits = sCABACorig.bits / es;
if (i == STATS__CABAC_INITIALISATION && sCABACorig.bits != 0)
{
thisCABACbits += cr;
cr = 0;
}
sCABAC.bits = thisCABACbits;
sCABAC.count = sCABACorig.count;
sCABAC.sum = sCABACorig.sum;
sCABAC.classCount = classCounts[i];
}
if( i != STATS__NAL_UNIT_TOTAL_BODY )
{
cabacTotalBits += sCABAC;
epTotalBits += sEP;
// For TRF
if ((i == STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG) || (i == STATS__CABAC_BITS__PAR_FLAG)
|| (i == STATS__CABAC_BITS__GT1_FLAG) || (i == STATS__CABAC_BITS__GT2_FLAG)
|| (i == STATS__CABAC_BITS__ESCAPE_BITS))
{
cabacTrfTotalBits += sCABAC;
epTrfTotalBits += sEP;
}
}
}
}
SStat delta_CABAC = cabacTotalBits;
SStat delta_EP = epTotalBits;
SStat delta_trf_CABAC = cabacTrfTotalBits;
SStat delta_trf_EP = epTrfTotalBits;
delta_CABAC -= max.prev_CABAC_state;
delta_EP -= max.prev_EP_state;
delta_trf_CABAC -= max.prev_trf_CABAC_state;
delta_trf_EP -= max.prev_trf_EP_state;
int64_t max_frame_bins = EPBIN_WEIGHT_FACTOR * max.max_CABAC_state.count + max.max_EP_state.count;
int64_t cur_frame_bins = EPBIN_WEIGHT_FACTOR * delta_CABAC.count + delta_EP.count;
if (cur_frame_bins > max_frame_bins)
{
max.max_CABAC_state = delta_CABAC;
max.max_EP_state = delta_EP;
max.trf_CABAC_state = delta_trf_CABAC;
max.trf_EP_state = delta_trf_EP;
}
max.prev_CABAC_state = cabacTotalBits;
max.prev_EP_state = epTotalBits;
max.prev_trf_CABAC_state = cabacTrfTotalBits;
max.prev_trf_EP_state = epTrfTotalBits;
}
#endif
};
#endif
......@@ -330,10 +330,15 @@ static const int MMVD_ADD_NUM = (MMVD_MAX_RE
static const int MMVD_MRG_MAX_RD_NUM = MRG_MAX_NUM_CANDS;
static const int MMVD_MRG_MAX_RD_BUF_NUM = (MMVD_MRG_MAX_RD_NUM + 1);///< increase buffer size by 1
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
static const int MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_LUMA = 28;
static const int MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_CHROMA = 28;
#else
static const int MAX_NUM_REG_BINS_4x4SUBBLOCK = 32; ///< max number of context-coded bins (incl. gt2 bins) per 4x4 subblock
static const int MAX_NUM_GT2_BINS_4x4SUBBLOCK = 4; ///< max number of gt2 bins per 4x4 subblock
static const int MAX_NUM_REG_BINS_2x2SUBBLOCK = 8; ///< max number of context-coded bins (incl. gt2 bins) per 2x2 subblock (chroma)
static const int MAX_NUM_GT2_BINS_2x2SUBBLOCK = 2; ///< max number of gt2 bins per 2x2 subblock (chroma)
#endif
static const int BIO_EXTEND_SIZE = 1;
static const int BIO_TEMP_BUFFER_SIZE = (MAX_CU_SIZE + 2 * BIO_EXTEND_SIZE) * (MAX_CU_SIZE + 2 * BIO_EXTEND_SIZE);
......@@ -454,6 +459,10 @@ static const int CSCALE_FP_PREC = 11;
static const int NEIG_NUM_LOG = 6;
static const int NEIG_NUM = 1 << NEIG_NUM_LOG;
#endif
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
static const int EPBIN_WEIGHT_FACTOR = 4;
#endif
// ====================================================================================================================
// Macro functions
// ====================================================================================================================
......
......@@ -231,6 +231,10 @@ public:
return auiGoRicePars[ std::min(sum, 31) ];
}
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
int regBinLimit;
#endif
private:
// constant
const ComponentID m_compID;
......
......@@ -89,6 +89,12 @@ namespace DQIntern
int nextSbbBelow;
int posX;
int posY;
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
ChannelType chType;
int sbtInfo;
int tuWidth;
int tuHeight;
#endif
};
class Rom;
......@@ -370,6 +376,11 @@ namespace DQIntern
void TUParameters::xSetScanInfo( ScanInfo& scanInfo, int scanIdx )
{
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
scanInfo.chType = m_chType;
scanInfo.tuWidth = m_width;
scanInfo.tuHeight = m_height;
#endif
scanInfo.sbbSize = m_sbbSize;
scanInfo.numSbb = m_numSbb;
scanInfo.scanIdx = scanIdx;
......@@ -679,7 +690,11 @@ namespace DQIntern
m_QScale = g_quantScales[needsSqrt2ScaleAdjustment?1:0][ qpRem ];
const unsigned qIdxBD = std::min<unsigned>( maxLog2TrDynamicRange + 1, 8*sizeof(Intermediate_Int) + invShift - IQUANT_SHIFT - 1 );
m_maxQIdx = ( 1 << (qIdxBD-1) ) - 4;
#if JVET_O0256_ADJUST_THD_DEPQUANT
m_thresLast = TCoeff((int64_t(4) << m_QShift));
#else
m_thresLast = TCoeff((int64_t(3) << m_QShift));
#endif
m_thresSSbb = TCoeff((int64_t(3) << m_QShift));
// distortion calculation parameters
const int64_t qScale = (gValue==-1) ? m_QScale : gValue;
......@@ -1018,7 +1033,11 @@ namespace DQIntern
int64_t m_rdCost;
uint16_t m_absLevelsAndCtxInit[24]; // 16x8bit for abs levels + 16x16bit for ctx init id
int8_t m_numSigSbb;
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
int m_remRegBins;
#else
int8_t m_remRegBins;
#endif
int8_t m_refSbbCtxId;
BinFracBits m_sbbFracBits;
BinFracBits m_sigFracBits;
......@@ -1030,6 +1049,11 @@ namespace DQIntern
const CoeffFracBits*const m_gtxFracBitsArray;
const uint32_t*const m_goRiceZeroArray;
CommonCtx& m_commonCtx;
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
public:
unsigned effWidth;
unsigned effHeight;
#endif
};
......@@ -1067,6 +1091,10 @@ namespace DQIntern
{
m_numSigSbb = 1;
m_refSbbCtxId = -1;
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
int ctxBinSampleRatio = (scanInfo.chType == CHANNEL_TYPE_LUMA) ? MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_LUMA : MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_CHROMA;
m_remRegBins = (effWidth * effHeight *ctxBinSampleRatio) / 16 - (decision.absLevel < 2 ? decision.absLevel : 3);
#else
if ( scanInfo.sbbSize == 4 )
{
m_remRegBins = MAX_NUM_REG_BINS_2x2SUBBLOCK - (decision.absLevel < 2 ? decision.absLevel : 3);
......@@ -1075,6 +1103,7 @@ namespace DQIntern
{
m_remRegBins = MAX_NUM_REG_BINS_4x4SUBBLOCK - (decision.absLevel < 2 ? decision.absLevel : 3);
}
#endif
::memset( m_absLevelsAndCtxInit, 0, 48*sizeof(uint8_t) );
}
......@@ -1258,6 +1287,17 @@ namespace DQIntern
const int sigNSbb = ( ( scanInfo.nextSbbRight ? sbbFlags[ scanInfo.nextSbbRight ] : false ) || ( scanInfo.nextSbbBelow ? sbbFlags[ scanInfo.nextSbbBelow ] : false ) ? 1 : 0 );
currState.m_numSigSbb = 0;
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
if (prevState)
{
currState.m_remRegBins = prevState->m_remRegBins;
}
else
{
int ctxBinSampleRatio = (scanInfo.chType == CHANNEL_TYPE_LUMA) ? MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_LUMA : MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_CHROMA;
currState.m_remRegBins = (currState.effWidth * currState.effHeight *ctxBinSampleRatio) / 16;
}
#else
if (scanInfo.sbbSize == 4)
{
currState.m_remRegBins = MAX_NUM_REG_BINS_2x2SUBBLOCK;
......@@ -1266,6 +1306,7 @@ namespace DQIntern
{
currState.m_remRegBins = MAX_NUM_REG_BINS_4x4SUBBLOCK;
}
#endif
currState.m_goRicePar = 0;
currState.m_refSbbCtxId = currState.m_stateId;
currState.m_sbbFracBits = m_sbbFlagBits[ sigNSbb ];
......@@ -1537,6 +1578,18 @@ namespace DQIntern
m_startState.init();
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
int effectWidth = std::min(32, effWidth);
int effectHeight = std::min(32, effHeight);
for (int k = 0; k < 12; k++)
{
m_allStates[k].effWidth = effectWidth;
m_allStates[k].effHeight = effectHeight;
}
m_startState.effWidth = effectWidth;
m_startState.effHeight = effectHeight;
#endif
//===== populate trellis =====
for( int scanIdx = firstTestPos; scanIdx >= 0; scanIdx-- )
{
......
......@@ -108,7 +108,9 @@ inline uint32_t QuantRDOQ::xGetCodedLevel( double& rd64CodedCost,
const BinFracBits& fracBitsPar,
const BinFracBits& fracBitsGt1,
const BinFracBits& fracBitsGt2,
#if !JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
const int remGt2Bins,
#endif
const int remRegBins,
unsigned goRiceZero,
uint16_t ui16AbsGoRice,
......@@ -146,7 +148,11 @@ inline uint32_t QuantRDOQ::xGetCodedLevel( double& rd64CodedCost,
{
double dErr = double( lLevelDouble - ( Intermediate_Int(uiAbsLevel) << iQBits ) );
double dCurrCost = dErr * dErr * errorScale + xGetICost( xGetICRate( uiAbsLevel, fracBitsPar, fracBitsGt1, fracBitsGt2, remGt2Bins, remRegBins, goRiceZero, ui16AbsGoRice, true, maxLog2TrDynamicRange ) );
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
double dCurrCost = dErr * dErr * errorScale + xGetICost( xGetICRate( uiAbsLevel, fracBitsPar, fracBitsGt1, fracBitsGt2, remRegBins, goRiceZero, ui16AbsGoRice, true, maxLog2TrDynamicRange ) );
#else
double dCurrCost = dErr * dErr * errorScale + xGetICost( xGetICRate( uiAbsLevel, fracBitsPar, fracBitsGt1, fracBitsGt2, remGt2Bins, remRegBins, goRiceZero, ui16AbsGoRice, true, maxLog2TrDynamicRange ) );
#endif
dCurrCost += dCurrCostSig;
if( dCurrCost < rd64CodedCost )
......@@ -175,7 +181,9 @@ inline int QuantRDOQ::xGetICRate( const uint32_t uiAbsLevel,
const BinFracBits& fracBitsPar,
const BinFracBits& fracBitsGt1,
const BinFracBits& fracBitsGt2,
#if !JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
const int remGt2Bins,
#endif
const int remRegBins,
unsigned goRiceZero,
const uint16_t ui16AbsGoRice,
......@@ -639,9 +647,14 @@ void QuantRDOQ::xRateDistOptQuant(TransformUnit &tu, const ComponentID &compID,
double d64BaseCost = 0;
int iLastScanPos = -1;
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
int ctxBinSampleRatio = (compID == COMPONENT_Y) ? MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_LUMA : MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_CHROMA;
int remRegBins = (uiWidth * uiHeight * ctxBinSampleRatio) >> 4;
#else
bool is2x2subblock = ( iCGSizeM1 == 3 );
int remGt2Bins = ( is2x2subblock ? MAX_NUM_GT2_BINS_2x2SUBBLOCK : MAX_NUM_GT2_BINS_4x4SUBBLOCK );
int remRegBins = ( is2x2subblock ? MAX_NUM_REG_BINS_2x2SUBBLOCK : MAX_NUM_REG_BINS_4x4SUBBLOCK );
#endif
uint32_t goRiceParam = 0;
double *pdCostCoeffGroupSig = m_pdCostCoeffGroupSig;
......@@ -736,16 +749,26 @@ void QuantRDOQ::xRateDistOptQuant(TransformUnit &tu, const ComponentID &compID,
if( iScanPos == iLastScanPos )
{
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ],
lLevelDouble, uiMaxAbsLevel, nullptr, fracBitsPar, fracBitsGt1, fracBitsGt2, remRegBins, goRiceZero, goRiceParam, iQBits, errorScale, 1, extendedPrecision, maxLog2TrDynamicRange );
#else
uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ],
lLevelDouble, uiMaxAbsLevel, nullptr, fracBitsPar, fracBitsGt1, fracBitsGt2, remGt2Bins, remRegBins, goRiceZero, goRiceParam, iQBits, errorScale, 1, extendedPrecision, maxLog2TrDynamicRange );
#endif
}
else
{
DTRACE_COND( ( uiMaxAbsLevel != 0 ), g_trace_ctx, D_RDOQ_MORE, " uiCtxSig=%d", ctxIdSig );
const BinFracBits fracBitsSig = fracBits.getFracBitsArray( ctxIdSig );
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ],
lLevelDouble, uiMaxAbsLevel, &fracBitsSig, fracBitsPar, fracBitsGt1, fracBitsGt2, remRegBins, goRiceZero, goRiceParam, iQBits, errorScale, 0, extendedPrecision, maxLog2TrDynamicRange );
#else
uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ],
lLevelDouble, uiMaxAbsLevel, &fracBitsSig, fracBitsPar, fracBitsGt1, fracBitsGt2, remGt2Bins, remRegBins, goRiceZero, goRiceParam, iQBits, errorScale, 0, extendedPrecision, maxLog2TrDynamicRange );
#endif
sigRateDelta[ uiBlkPos ] = ( remRegBins < 4 ? 0 : fracBitsSig.intBits[1] - fracBitsSig.intBits[0] );
}
......@@ -757,16 +780,27 @@ void QuantRDOQ::xRateDistOptQuant(TransformUnit &tu, const ComponentID &compID,
if( uiLevel > 0 )
{
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
int rateNow = xGetICRate( uiLevel, fracBitsPar, fracBitsGt1, fracBitsGt2, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange );
rateIncUp [ uiBlkPos ] = xGetICRate( uiLevel+1, fracBitsPar, fracBitsGt1, fracBitsGt2, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange ) - rateNow;
rateIncDown [ uiBlkPos ] = xGetICRate( uiLevel-1, fracBitsPar, fracBitsGt1, fracBitsGt2, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange ) - rateNow;
#else
int rateNow = xGetICRate( uiLevel, fracBitsPar, fracBitsGt1, fracBitsGt2, remGt2Bins, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange );
rateIncUp [ uiBlkPos ] = xGetICRate( uiLevel+1, fracBitsPar, fracBitsGt1, fracBitsGt2, remGt2Bins, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange ) - rateNow;
rateIncDown [ uiBlkPos ] = xGetICRate( uiLevel-1, fracBitsPar, fracBitsGt1, fracBitsGt2, remGt2Bins, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange ) - rateNow;
#endif
}
else // uiLevel == 0
{
if( remRegBins < 4 )
{
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
int rateNow = xGetICRate( uiLevel, fracBitsPar, fracBitsGt1, fracBitsGt2, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange );
rateIncUp [ uiBlkPos ] = xGetICRate( uiLevel+1, fracBitsPar, fracBitsGt1, fracBitsGt2, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange ) - rateNow;
#else
int rateNow = xGetICRate( uiLevel, fracBitsPar, fracBitsGt1, fracBitsGt2, remGt2Bins, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange );
rateIncUp [ uiBlkPos ] = xGetICRate( uiLevel+1, fracBitsPar, fracBitsGt1, fracBitsGt2, remGt2Bins, remRegBins, goRiceZero, goRiceParam, extendedPrecision, maxLog2TrDynamicRange ) - rateNow;
#endif
}
else
{
......@@ -778,8 +812,10 @@ void QuantRDOQ::xRateDistOptQuant(TransformUnit &tu, const ComponentID &compID,
if( ( (iScanPos & iCGSizeM1) == 0 ) && ( iScanPos > 0 ) )
{
#if !JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
remGt2Bins = ( is2x2subblock ? MAX_NUM_GT2_BINS_2x2SUBBLOCK : MAX_NUM_GT2_BINS_4x4SUBBLOCK );
remRegBins = ( is2x2subblock ? MAX_NUM_REG_BINS_2x2SUBBLOCK : MAX_NUM_REG_BINS_4x4SUBBLOCK ) - remGt2Bins;
#endif
goRiceParam = 0;
}
else if( remRegBins >= 4 )
......
......@@ -87,7 +87,9 @@ private:
const BinFracBits& fracBitsPar,
const BinFracBits& fracBitsGt1,
const BinFracBits& fracBitsGt2,
#if !JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
const int remGt2Bins,
#endif
const int remRegBins,
unsigned goRiceZero,
uint16_t ui16AbsGoRice,
......@@ -100,7 +102,9 @@ private:
const BinFracBits& fracBitsPar,
const BinFracBits& fracBitsGt1,
const BinFracBits& fracBitsGt2,
#if !JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
const int remGt2Bins,
#endif
const int remRegBins,
unsigned goRiceZero,
const uint16_t ui16AbsGoRice,
......
......@@ -50,11 +50,15 @@
#include <assert.h>
#include <cassert>
#define JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT 1 // JVET-O0052 Method-1: TU-level context coded bin constraint
#define JVET_O0105_ICT 1 // JVET-O0105: inter-chroma transform (ICT) as extension of joint chroma coding (JCC)
#define JVET_O0543_ICT_ICU_ONLY 1 // JVET-O0543: ICT only in Intra CUs (was Intra slices, modified during adoption)
#define JVET_O0216_ALF_COEFF_EG3 1 // JVET-O0216/O0302/O0648: using EG3 for ALF coefficients coding
#define JVET_O0256_ADJUST_THD_DEPQUANT 1 // JVET-O0256: Fast encoder with adjusted threshold in dependent quantization
#define JVET_O0272_LMCS_SIMP_INVERSE_MAPPING 1 // JVET-O0272: LMCS simplified inverse mapping
#define JVET_O0247_ALF_CTB_CODING_REDUNDANCY_REMOVAL 1 // JVET-O0247: not signal APS index when number APS is 2
......@@ -102,6 +106,8 @@
#define JVET_O0078_SINGLE_HMVPLUT 1 // JVET-O0078Single HMVP table for all CUs inside the shared merge list region for IBC
#define JVET_O0126_BPWA_INDEX_CODING_FIX 1 // JVET-O0126 align BPWA index coding with specification
#define FIX_DB_MAX_TRANSFORM_SIZE 1
#define MRG_SHARELIST_SHARSIZE 32
......@@ -198,6 +204,14 @@ typedef std::pair<int, int> TrCost;
#define RExt__DECODER_DEBUG_BIT_STATISTICS 0 ///< 0 (default) = decoder reports as normal, 1 = decoder produces bit usage statistics (will impact decoder run time by up to ~10%)
#endif
#ifndef RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
#define RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS (1 && RExt__DECODER_DEBUG_BIT_STATISTICS ) ///< 0 (default) = decoder reports as normal, 1 = decoder produces max frame bit usage statistics
#if RExt__DECODER_DEBUG_TOOL_MAX_FRAME_STATS
#define TR_ONLY_COEFF_STATS 1
#define EPBINCOUNT_FIX 1
#endif
#endif
#ifndef RExt__DECODER_DEBUG_TOOL_STATISTICS
#define RExt__DECODER_DEBUG_TOOL_STATISTICS 0 ///< 0 (default) = decoder reports as normal, 1 = decoder produces tool usage statistics
#endif
......
......@@ -764,5 +764,24 @@ void TransformUnit::checkTuNoResidual( unsigned idx )
noResidual = true;
}
}
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
int TransformUnit::getTbAreaAfterCoefZeroOut(ComponentID compID) const
{
int tbArea = blocks[compID].width * blocks[compID].height;
int tbZeroOutWidth = blocks[compID].width;
int tbZeroOutHeight = blocks[compID].height;
if ((mtsIdx > MTS_SKIP || (cu->sbtInfo != 0 && blocks[compID].width <= 32 && blocks[compID].height <= 32)) && !cu->transQuantBypass && compID == COMPONENT_Y)
{
tbZeroOutWidth = (blocks[compID].width == 32) ? 16 : tbZeroOutWidth;
tbZeroOutHeight = (blocks[compID].height == 32) ? 16 : tbZeroOutHeight;
}
tbZeroOutWidth = std::min<int>(JVET_C0024_ZERO_OUT_TH, tbZeroOutWidth);
tbZeroOutHeight = std::min<int>(JVET_C0024_ZERO_OUT_TH, tbZeroOutHeight);
tbArea = tbZeroOutWidth * tbZeroOutHeight;
return tbArea;
}
#endif
int TransformUnit::getChromaAdj() const { return m_chromaResScaleInv; }
void TransformUnit::setChromaAdj(int i) { m_chromaResScaleInv = i; }
......@@ -466,6 +466,9 @@ struct TransformUnit : public UnitArea
TransformUnit& operator=(const TransformUnit& other);
void copyComponentFrom (const TransformUnit& other, const ComponentID compID);
void checkTuNoResidual( unsigned idx );
#if JVET_O0052_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT
int getTbAreaAfterCoefZeroOut(ComponentID compID) const;
#endif
CoeffBuf getCoeffs(const ComponentID id);
const CCoeffBuf getCoeffs(const ComponentID id) const;
......
......@@ -185,7 +185,7 @@ int CU::predictQP( const CodingUnit& cu, const int prevQP )
{
const CodingStructure &cs = *cu.cs;
if ( !cu.blocks[cu.chType].x && !( cu.blocks[cu.chType].y & ( cs.pcv->maxCUHeightMask >> getChannelTypeScaleY( cu.chType, cu.chromaFormat ) ) ) && ( cs.getCU( cu.blocks[cu.chType].pos().offset( 0, -1 ), cu.chType) != NULL ) )
if ( !cu.blocks[cu.chType].x && !( cu.blocks[cu.chType].y & ( cs.pcv->maxCUHeightMask >> getChannelTypeScaleY( cu.chType, cu.chromaFormat ) ) ) && ( cs.getCU( cu.blocks[cu.chType].pos().offset( 0, -1 ), cu.chType) != NULL ) && CU::isSameSliceAndTile( *cs.getCU( cu.blocks[cu.chType].pos().offset( 0, -1 ), cu.chType), cu ) )
{
return ( ( cs.getCU( cu.blocks[cu.chType].pos().offset( 0, -1 ), cu.chType ) )->qp );
}
......
......@@ -79,7 +79,11 @@ _byteStreamNALUnit(
{
uint8_t leading_zero_8bits = bs.readByte();
#if RExt__DECODER_DEBUG_BIT_STATISTICS
#if EPBINCOUNT_FIX