Newer
Older
sps.setUseIbcMbvdAdSearch ( m_ibcMbvdAdSearch );
#endif
#endif
#if JVET_AC0112_IBC_CIIP
sps.setUseIbcCiip ( m_ibcCiip );
#endif
#if JVET_AC0112_IBC_GPM
sps.setUseIbcGpm ( m_ibcGpm );
#endif
#if JVET_AC0112_IBC_LIC
sps.setUseIbcLic ( m_ibcLic );
#if JVET_AE0159_FIBC
sps.setUseIbcFilter ( m_ibcFilter );
#endif
#if JVET_AE0094_IBC_NONADJACENT_SPATIAL_CANDIDATES
sps.setUseIbcNonAdjCand ( m_ibcNonAdjCand );
sps.setWrapAroundEnabledFlag ( m_wrapAround );
#if MULTI_HYP_PRED
sps.setMaxNumAddHyps(m_maxNumAddHyps);
sps.setNumAddHypWeights(m_numAddHypWeights);
sps.setMaxNumAddHypRefFrames(m_maxNumAddHypRefFrames);
#if JVET_V0130_INTRA_TMP
sps.setUseIntraTMP(m_intraTMP);
sps.setIntraTMPMaxSize(m_intraTmpMaxSize);
#if JVET_AE0100_BVGCCCM
sps.setUseBvgCccm(m_bvgCccm);
#endif
#if JVET_AC0071_DBV
sps.setUseIntraDBV(m_intraDBV);
Pekka Astola
committed
#endif
#if JVET_AE0059_INTER_CCCM
sps.setUseInterCccm(m_interCccm);
#endif
#if JVET_AF0073_INTER_CCP_MERGE
sps.setUseInterCcpMerge(m_interCcpMerge);

Karsten Suehring
committed
// ADD_NEW_TOOL : (encoder lib) set tool enabling flags and associated parameters here
sps.setUseISP ( m_ISP );
sps.setUseLmcs ( m_lmcsEnabled );
sps.setUseMIP ( m_MIP );
CHECK(m_log2MinCUSize > std::min(6, floorLog2(sps.getMaxCUWidth())), "log2_min_luma_coding_block_size_minus2 shall be in the range of 0 to min (4, log2_ctu_size - 2)");
CHECK(m_uiMaxMTTHierarchyDepth > 2 * (floorLog2(sps.getCTUSize()) - sps.getLog2MinCodingBlockSize()), "sps_max_mtt_hierarchy_depth_inter_slice shall be in the range 0 to 2*(ctbLog2SizeY - log2MinCUSize)");
CHECK(m_uiMaxMTTHierarchyDepthI > 2 * (floorLog2(sps.getCTUSize()) - sps.getLog2MinCodingBlockSize()), "sps_max_mtt_hierarchy_depth_intra_slice_luma shall be in the range 0 to 2*(ctbLog2SizeY - log2MinCUSize)");
CHECK(m_uiMaxMTTHierarchyDepthIChroma > 2 * (floorLog2(sps.getCTUSize()) - sps.getLog2MinCodingBlockSize()), "sps_max_mtt_hierarchy_depth_intra_slice_chroma shall be in the range 0 to 2*(ctbLog2SizeY - log2MinCUSize)");

Karsten Suehring
committed
sps.setTransformSkipEnabledFlag(m_useTransformSkip);
Shih-Ta Hsiang
committed
sps.setLog2MaxTransformSkipBlockSize(m_log2MaxTransformSkipBlockSize);
Alican Nalci
committed
sps.setBDPCMEnabledFlag(m_useBDPCM);

Karsten Suehring
committed
sps.setSPSTemporalMVPEnabledFlag((getTMVPModeId() == 2 || getTMVPModeId() == 1));
sps.setLog2MaxTbSize ( m_log2MaxTbSize );

Karsten Suehring
committed
for (uint32_t channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
{
sps.setBitDepth (ChannelType(channelType), m_bitDepth[channelType] );
sps.setQpBDOffset (ChannelType(channelType), (6 * (m_bitDepth[channelType] - 8)));
sps.setInternalMinusInputBitDepth(ChannelType(channelType), max(0, (m_bitDepth[channelType] - m_inputBitDepth[channelType])));

Karsten Suehring
committed
}
sps.setEntropyCodingSyncEnabledFlag( m_entropyCodingSyncEnabledFlag );
sps.setEntryPointsPresentFlag( m_entryPointPresentFlag );
sps.setUseWP( m_useWeightedPred );
sps.setUseWPBiPred( m_useWeightedBiPred );
sps.setSAOEnabledFlag( m_bUseSAO );
#if JVET_W0066_CCSAO
sps.setCCSAOEnabledFlag( m_CCSAO );
#endif
#if JVET_AG0158_ALF_LUMA_COEFF_PRECISION
sps.setAlfPrecisionFlag( m_alfPrecision );
sps.setJointCbCrEnabledFlag( m_JointCbCrMode );

Karsten Suehring
committed
sps.setMaxTLayers( m_maxTempLayer );
sps.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
for (int i = 0; i < std::min(sps.getMaxTLayers(), (uint32_t) MAX_TLAYER); i++ )

Karsten Suehring
committed
{
sps.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
sps.setNumReorderPics(m_numReorderPics[i], i);
}
sps.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 );
if (sps.getUseColorTrans() && sps.getScalingListFlag())
{
sps.setScalingMatrixForAlternativeColourSpaceDisabledFlag( m_disableScalingMatrixForAlternativeColourSpace );
}
else
{
sps.setScalingMatrixForAlternativeColourSpaceDisabledFlag( false );
}
if (sps.getScalingMatrixForAlternativeColourSpaceDisabledFlag())
{
sps.setScalingMatrixDesignatedColourSpaceFlag( m_scalingMatrixDesignatedColourSpace );
}
else
{
sps.setScalingMatrixDesignatedColourSpaceFlag( true );
}

Karsten Suehring
committed
sps.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
#if JVET_Z0135_TEMP_CABAC_WIN_WEIGHT
sps.setTempCabacInitMode( m_tempCabacInitMode );
#endif
if (sps.getVuiParametersPresentFlag())
{
VUI* pcVUI = sps.getVuiParameters();
pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag());
pcVUI->setAspectRatioConstantFlag(!getSampleAspectRatioInfoSEIEnabled());
pcVUI->setAspectRatioIdc(getAspectRatioIdc());
pcVUI->setSarWidth(getSarWidth());
pcVUI->setSarHeight(getSarHeight());
pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
pcVUI->setColourPrimaries(getColourPrimaries());
pcVUI->setTransferCharacteristics(getTransferCharacteristics());
pcVUI->setMatrixCoefficients(getMatrixCoefficients());
pcVUI->setProgressiveSourceFlag (getProgressiveSourceFlag());
pcVUI->setInterlacedSourceFlag (getInterlacedSourceFlag());
#if JVET_S0266_VUI_length
pcVUI->setNonPackedFlag (getNonPackedConstraintFlag());
pcVUI->setNonProjectedFlag (getNonProjectedConstraintFlag());
#endif
pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
pcVUI->setChromaSampleLocType(getChromaSampleLocType());
pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
}

Karsten Suehring
committed
sps.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS);
CHECK(!(NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS), "Unspecified error");
for (int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++)
{
sps.setLtRefPicPocLsbSps(k, 0);
sps.setUsedByCurrPicLtSPSFlag(k, 0);
}
int numQpTables = m_chromaQpMappingTableParams.getSameCQPTableForAllChromaFlag() ? 1 : (sps.getJointCbCrEnabledFlag() ? 3 : 2);
m_chromaQpMappingTableParams.setNumQpTables(numQpTables);
sps.setChromaQpMappingTableFromParams(m_chromaQpMappingTableParams, sps.getQpBDOffset(CHANNEL_TYPE_CHROMA));
Adarsh Krishnan Ramasubramonian
committed
sps.derivedChromaQPMappingTables();

Karsten Suehring
committed
#if U0132_TARGET_BITS_SATURATION
if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() || getCpbSaturationEnabled() )
#else
if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
#endif
{
xInitHrdParameters(sps);
}
if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
{
sps.setGeneralHrdParametersPresentFlag(true);

Karsten Suehring
committed
}
// Set up SPS range extension settings
sps.getSpsRangeExtension().setTransformSkipRotationEnabledFlag(m_transformSkipRotationEnabledFlag);
sps.getSpsRangeExtension().setTransformSkipContextEnabledFlag(m_transformSkipContextEnabledFlag);
sps.getSpsRangeExtension().setExtendedPrecisionProcessingFlag(m_extendedPrecisionProcessingFlag);
sps.getSpsRangeExtension().setIntraSmoothingDisabledFlag( m_intraSmoothingDisabledFlag );
sps.getSpsRangeExtension().setHighPrecisionOffsetsEnabledFlag(m_highPrecisionOffsetsEnabledFlag);
sps.getSpsRangeExtension().setPersistentRiceAdaptationEnabledFlag(m_persistentRiceAdaptationEnabledFlag);
sps.getSpsRangeExtension().setCabacBypassAlignmentEnabledFlag(m_cabacBypassAlignmentEnabledFlag);
Kui Fan
committed
sps.setSubPicInfoPresentFlag(m_subPicInfoPresentFlag);
if (m_subPicInfoPresentFlag)
LI JINGYA
committed
{
sps.setNumSubPics(m_numSubPics);
#if JVET_S0071_SAME_SIZE_SUBPIC_LAYOUT
sps.setSubPicSameSizeFlag(m_subPicSameSizeFlag);
if (m_subPicSameSizeFlag)
{
#if JVET_AA0146_WRAP_AROUND_FIX
uint32_t numSubpicCols = (m_sourceWidth + m_CTUSize - 1) / m_CTUSize / m_subPicWidth[0];
#else
uint32_t numSubpicCols = (m_iSourceWidth + m_CTUSize - 1) / m_CTUSize / m_subPicWidth[0];
for (unsigned int i = 0; i < m_numSubPics; i++)
{
sps.setSubPicCtuTopLeftX(i, (i % numSubpicCols) * m_subPicWidth[0]);
sps.setSubPicCtuTopLeftY(i, (i / numSubpicCols) * m_subPicHeight[0]);
sps.setSubPicWidth(i, m_subPicWidth[0]);
sps.setSubPicHeight(i, m_subPicHeight[0]);
}
}
else
{
sps.setSubPicCtuTopLeftX(m_subPicCtuTopLeftX);
sps.setSubPicCtuTopLeftY(m_subPicCtuTopLeftY);
sps.setSubPicWidth(m_subPicWidth);
sps.setSubPicHeight(m_subPicHeight);
}
#else
sps.setSubPicCtuTopLeftX(m_subPicCtuTopLeftX);
sps.setSubPicCtuTopLeftY(m_subPicCtuTopLeftY);
sps.setSubPicWidth(m_subPicWidth);
sps.setSubPicHeight(m_subPicHeight);
sps.setSubPicTreatedAsPicFlag(m_subPicTreatedAsPicFlag);
sps.setLoopFilterAcrossSubpicEnabledFlag(m_loopFilterAcrossSubpicEnabledFlag);
sps.setSubPicIdLen(m_subPicIdLen);

Karsten Suehring
committed
sps.setSubPicIdMappingExplicitlySignalledFlag(m_subPicIdMappingExplicitlySignalledFlag);
if (m_subPicIdMappingExplicitlySignalledFlag)
{
sps.setSubPicIdMappingInSpsFlag(m_subPicIdMappingInSpsFlag);
if (m_subPicIdMappingInSpsFlag)
{
sps.setSubPicId(m_subPicId);
}
}
else //In that case, there is only one subpicture that contains the whole picture
{
sps.setNumSubPics(1);
sps.setSubPicCtuTopLeftX(0, 0);
sps.setSubPicCtuTopLeftY(0, 0);
#if JVET_AA0146_WRAP_AROUND_FIX
sps.setSubPicWidth(0, m_sourceWidth);
sps.setSubPicHeight(0, m_sourceHeight);
#else
sps.setSubPicWidth(0, m_iSourceWidth);
sps.setSubPicHeight(0, m_iSourceHeight);
sps.setSubPicTreatedAsPicFlag(0, 1);
sps.setLoopFilterAcrossSubpicEnabledFlag(0, 0);

Karsten Suehring
committed
sps.setSubPicIdMappingExplicitlySignalledFlag(false);
#if TCQ_8STATES
sps.setDepQuantEnabledFlag( m_DepQuantEnabledIdc ? true : false );
#else
FANGJUN PU
committed
sps.setDepQuantEnabledFlag( m_DepQuantEnabledFlag );
FANGJUN PU
committed
if (!sps.getDepQuantEnabledFlag())
{
sps.setSignDataHidingEnabledFlag( m_SignDataHidingEnabledFlag );
}
else
{
sps.setSignDataHidingEnabledFlag(false);
}
sps.setVirtualBoundariesEnabledFlag( m_virtualBoundariesEnabledFlag );
if( sps.getVirtualBoundariesEnabledFlag() )
sps.setVirtualBoundariesPresentFlag( m_virtualBoundariesPresentFlag );
CHECK( sps.getSubPicInfoPresentFlag() && sps.getVirtualBoundariesPresentFlag() != 1, "When subpicture signalling if present, the signalling of virtual boundaries, is present, shall be in the SPS" );
sps.setNumVerVirtualBoundaries ( m_numVerVirtualBoundaries );
sps.setNumHorVirtualBoundaries ( m_numHorVirtualBoundaries );
for( unsigned int i = 0; i < m_numVerVirtualBoundaries; i++ )
{
sps.setVirtualBoundariesPosX ( m_virtualBoundariesPosX[i], i );
}
for( unsigned int i = 0; i < m_numHorVirtualBoundaries; i++ )
{
sps.setVirtualBoundariesPosY ( m_virtualBoundariesPosY[i], i );
}
Vadim Seregin
committed
sps.setInterLayerPresentFlag( m_layerId > 0 && m_vps->getMaxLayers() > 1 && !m_vps->getAllIndependentLayersFlag() && !m_vps->getIndependentLayerFlag( m_vps->getGeneralLayerIdx( m_layerId ) ) );
CHECK( m_vps->getIndependentLayerFlag( m_vps->getGeneralLayerIdx( m_layerId ) ) && sps.getInterLayerPresentFlag(), " When vps_independent_layer_flag[GeneralLayerIdx[nuh_layer_id ]] is equal to 1, the value of inter_layer_ref_pics_present_flag shall be equal to 0." );
sps.setResChangeInClvsEnabledFlag(m_resChangeInClvsEnabled);
Zhipin Deng
committed
#if JVET_Q0114_ASPECT5_GCI_FLAG
sps.setRprEnabledFlag(m_rprEnabledFlag);
#else
sps.setRprEnabledFlag((m_resChangeInClvsEnabled) || sps.getInterLayerPresentFlag());
Zhipin Deng
committed
#endif
sps.setLog2ParallelMergeLevelMinus2( m_log2ParallelMergeLevelMinus2 );
CHECK(sps.getResChangeInClvsEnabledFlag() && sps.getVirtualBoundariesEnabledFlag(), "when the value of res_change_in_clvs_allowed_flag is equal to 1, the value of sps_virtual_boundaries_present_flag shall be equal to 0");

Karsten Suehring
committed
}
void EncLib::xInitHrdParameters(SPS &sps)
{
m_encHRD.initHRDParameters((EncCfg*) this);
GeneralHrdParams *generalHrdParams = sps.getGeneralHrdParameters();
*generalHrdParams = m_encHRD.getGeneralHrdParameters();
OlsHrdParams *spsOlsHrdParams = sps.getOlsHrdParameters();
for(int i = 0; i < MAX_TLAYER; i++)
{
*spsOlsHrdParams = m_encHRD.getOlsHrdParameters(i);
spsOlsHrdParams++;
}

Karsten Suehring
committed
}
void EncLib::xInitPPS(PPS &pps, const SPS &sps)
{
// pps ID already initialised.
pps.setSPSId(sps.getSPSId());
Kui Fan
committed
pps.setSubPicIdMappingInPpsFlag(false);
pps.setSubPicIdLen(sps.getSubPicIdLen());
for(int picIdx=0; picIdx<pps.getNumSubPics(); picIdx++)
{
pps.setSubPicId(picIdx, sps.getSubPicId(picIdx));
}
bool bUseDQP = (getCuQpDeltaSubdiv() > 0)? true : false;

Karsten Suehring
committed
if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
{
bUseDQP = true;
}
#if JVET_AB0171_ASYMMETRIC_DB_FOR_GDR
pps.setAsymmetricILF(getAsymmetricILF());
#endif

Karsten Suehring
committed
#if SHARP_LUMA_DELTA_QP
if ( getLumaLevelToDeltaQPMapping().isEnabled() )
{
bUseDQP = true;
}
#endif
#if ENABLE_QPA
if (getUsePerceptQPA() && !bUseDQP)
{
CHECK( m_cuQpDeltaSubdiv != 0, "max. delta-QP subdiv must be zero!" );
bUseDQP = (getBaseQP() < 38) && (getSourceWidth() > 512 || getSourceHeight() > 320);

Karsten Suehring
committed
}
#endif
#if JVET_Y0240_BIM
if (m_bimEnabled)
{
bUseDQP = true;
}
#endif

Karsten Suehring
committed
if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING)
{
bUseDQP=false;
}
if ( m_RCEnableRateControl )
{
pps.setUseDQP(true);
}
else if(bUseDQP)
{
pps.setUseDQP(true);
}
else
{
pps.setUseDQP(false);
}
if ( m_cuChromaQpOffsetSubdiv >= 0 )
{
pps.clearChromaQpOffsetList();
pps.setChromaQpOffsetListEntry(1, 6, 6, 6);

Karsten Suehring
committed
/* todo, insert table entries from command line (NB, 0 should not be touched) */
}
else
{
pps.clearChromaQpOffsetList();

Karsten Suehring
committed
}
{
int baseQp = 26;
if( 16 == getGOPSize() )
{
baseQp = getBaseQP()-24;
}
else
{
baseQp = getBaseQP()-26;
}
const int maxDQP = 37;

Karsten Suehring
committed
const int minDQP = -26 + sps.getQpBDOffset(CHANNEL_TYPE_LUMA);
pps.setPicInitQPMinus26( std::min( maxDQP, std::max( minDQP, baseQp ) ));
}
if( sps.getJointCbCrEnabledFlag() == false || getChromaFormatIdc() == CHROMA_400 || m_chromaCbCrQpOffset == 0 )
{
pps.setJointCbCrQpOffsetPresentFlag(false);
}
else
{
pps.setJointCbCrQpOffsetPresentFlag(true);
}

Karsten Suehring
committed
#if ER_CHROMA_QP_WCG_PPS
if (getWCGChromaQPControl().isEnabled())
{
const int baseQp=m_iQP+pps.getPPSId();
const double chromaQp = m_wcgChromaQpControl.chromaQpScale * baseQp + m_wcgChromaQpControl.chromaQpOffset;
const double dcbQP = m_wcgChromaQpControl.chromaCbQpScale * chromaQp;
const double dcrQP = m_wcgChromaQpControl.chromaCrQpScale * chromaQp;
const int cbQP =(int)(dcbQP + ( dcbQP < 0 ? -0.5 : 0.5) );
const int crQP =(int)(dcrQP + ( dcrQP < 0 ? -0.5 : 0.5) );
pps.setQpOffset(COMPONENT_Cb, Clip3( -12, 12, min(0, cbQP) + m_chromaCbQpOffset ));
pps.setQpOffset(COMPONENT_Cr, Clip3( -12, 12, min(0, crQP) + m_chromaCrQpOffset));
if(pps.getJointCbCrQpOffsetPresentFlag())
pps.setQpOffset(JOINT_CbCr, Clip3(-12, 12, (min(0, cbQP) + min(0, crQP)) / 2 + m_chromaCbCrQpOffset));
else
pps.setQpOffset(JOINT_CbCr, 0);

Karsten Suehring
committed
}
else
{
#endif
pps.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset );
pps.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset );
if (pps.getJointCbCrQpOffsetPresentFlag())
pps.setQpOffset(JOINT_CbCr, m_chromaCbCrQpOffset);
else
pps.setQpOffset(JOINT_CbCr, 0);

Karsten Suehring
committed
#if ER_CHROMA_QP_WCG_PPS
}
#endif
#if W0038_CQP_ADJ
bool bChromaDeltaQPEnabled = false;
{
bChromaDeltaQPEnabled = ( m_sliceChromaQpOffsetIntraOrPeriodic[0] || m_sliceChromaQpOffsetIntraOrPeriodic[1] );
if( !bChromaDeltaQPEnabled )
{
for( int i=0; i<m_iGOPSize; i++ )
{
if( m_GOPList[i].m_CbQPoffset || m_GOPList[i].m_CrQPoffset )
{
bChromaDeltaQPEnabled = true;
break;
}
}
}
}
#if ENABLE_QPA
if ((getUsePerceptQPA() || getSliceChromaOffsetQpPeriodicity() > 0) && (getChromaFormatIdc() != CHROMA_400))
{
bChromaDeltaQPEnabled = true;
}
#endif

Karsten Suehring
committed
pps.setSliceChromaQpFlag(bChromaDeltaQPEnabled);
#endif
!pps.getSliceChromaQpFlag() && sps.getUseDualITree()
&& (getChromaFormatIdc() != CHROMA_400))

Karsten Suehring
committed
{
pps.setSliceChromaQpFlag(m_chromaCbQpOffsetDualTree != 0 || m_chromaCrQpOffsetDualTree != 0 || m_chromaCbCrQpOffsetDualTree != 0);

Karsten Suehring
committed
}
#if JVET_AG0116
if (m_rprFunctionalityTestingEnabledFlag || m_gopBasedRPREnabledFlag)
#else
if (m_rprFunctionalityTestingEnabledFlag)
{
if (pps.getPPSId() == ENC_PPS_ID_RPR || pps.getPPSId() == ENC_PPS_ID_RPR2 || pps.getPPSId() == ENC_PPS_ID_RPR3)
{
pps.setSliceChromaQpFlag(true);
}
}
#endif

Karsten Suehring
committed
int minCbSizeY = (1 << sps.getLog2MinCodingBlockSize());
pps.setWrapAroundEnabledFlag ( m_wrapAround );
if( m_wrapAround )
{
pps.setPicWidthMinusWrapAroundOffset ((pps.getPicWidthInLumaSamples()/minCbSizeY) - (m_wrapAroundOffset / minCbSizeY));
pps.setWrapAroundOffset (minCbSizeY *(pps.getPicWidthInLumaSamples() / minCbSizeY- pps.getPicWidthMinusWrapAroundOffset()));
pps.setPicWidthMinusWrapAroundOffset ( 0 );
pps.setWrapAroundOffset ( 0 );
}
CHECK( !sps.getWrapAroundEnabledFlag() && pps.getWrapAroundEnabledFlag(), "When sps_ref_wraparound_enabled_flag is equal to 0, the value of pps_ref_wraparound_enabled_flag shall be equal to 0.");
CHECK( (((sps.getCTUSize() / minCbSizeY) + 1) > ((pps.getPicWidthInLumaSamples() / minCbSizeY) - 1)) && pps.getWrapAroundEnabledFlag(), "When the value of CtbSizeY / MinCbSizeY + 1 is greater than pic_width_in_luma_samples / MinCbSizeY - 1, the value of pps_ref_wraparound_enabled_flag shall be equal to 0.");
pps.setNoPicPartitionFlag( m_noPicPartitionFlag );
if( m_noPicPartitionFlag == false )
{
pps.setLog2CtuSize( ceilLog2( sps.getCTUSize()) );
pps.setNumExpTileColumns( (uint32_t) m_tileColumnWidth.size() );
pps.setNumExpTileRows( (uint32_t) m_tileRowHeight.size() );
pps.setTileColumnWidths( m_tileColumnWidth );
pps.setTileRowHeights( m_tileRowHeight );
pps.initTiles();
pps.setRectSliceFlag( m_rectSliceFlag );

Karsten Suehring
committed
pps.setSingleSlicePerSubPicFlag(m_singleSlicePerSubPicFlag);
pps.setNumSlicesInPic( m_numSlicesInPic );
pps.setTileIdxDeltaPresentFlag( m_tileIdxDeltaPresentFlag );
pps.setRectSlices( m_rectSlices );

Karsten Suehring
committed
pps.initRectSliceMap(&sps);
}
else
{
pps.initRasterSliceMap( m_rasterSliceSize );
}
pps.setLoopFilterAcrossTilesEnabledFlag( m_bLFCrossTileBoundaryFlag );
pps.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
}
else
{
pps.setLog2CtuSize( ceilLog2( sps.getCTUSize()) );
pps.setNumExpTileColumns(1);
pps.setNumExpTileRows(1);
pps.addTileColumnWidth( pps.getPicWidthInCtu( ) );
pps.addTileRowHeight( pps.getPicHeightInCtu( ) );
pps.initTiles();
pps.setRectSliceFlag( 1 );
pps.setNumSlicesInPic( 1 );
pps.initRectSlices( );
pps.setTileIdxDeltaPresentFlag( 0 );
pps.setSliceTileIdx( 0, 0 );

Karsten Suehring
committed
pps.initRectSliceMap( &sps );
pps.setLoopFilterAcrossTilesEnabledFlag( true );
pps.setLoopFilterAcrossSlicesEnabledFlag( true );
}

Karsten Suehring
committed
pps.setUseWP( m_useWeightedPred );
pps.setWPBiPred( m_useWeightedBiPred );
pps.setOutputFlagPresentFlag( false );
#if JVET_AC0189_SGPM_NO_BLENDING
pps.setUseSgpmNoBlend ( m_sgpmNoBlend );
#endif
pps.setUseBIF ( m_BIF );
pps.setBIFStrength ( m_BIFStrength );
pps.setBIFQPOffset ( m_BIFQPOffset );
#endif
#if JVET_X0071_CHROMA_BILATERAL_FILTER
pps.setUseChromaBIF ( m_chromaBIF );
pps.setChromaBIFStrength ( m_chromaBIFStrength );
pps.setChromaBIFQPOffset ( m_chromaBIFQPOffset );
#endif

Karsten Suehring
committed
if ( getDeblockingFilterMetric() )
{
pps.setDeblockingFilterOverrideEnabledFlag(true);
pps.setPPSDeblockingFilterDisabledFlag(false);
}
else
{
pps.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() );
pps.setPPSDeblockingFilterDisabledFlag( getLoopFilterDisable() );
}
if (! pps.getPPSDeblockingFilterDisabledFlag())
{
pps.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() );
pps.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() );
pps.setDeblockingFilterCbBetaOffsetDiv2( getLoopFilterCbBetaOffset() );
pps.setDeblockingFilterCbTcOffsetDiv2( getLoopFilterCbTcOffset() );
pps.setDeblockingFilterCrBetaOffsetDiv2( getLoopFilterCrBetaOffset() );
pps.setDeblockingFilterCrTcOffsetDiv2( getLoopFilterCrTcOffset() );

Karsten Suehring
committed
}
else
{
#if DB_PARAM_TID
pps.setDeblockingFilterBetaOffsetDiv2(std::vector<int>(5,0));
pps.setDeblockingFilterTcOffsetDiv2(std::vector<int>(5, 0));
#else

Karsten Suehring
committed
pps.setDeblockingFilterBetaOffsetDiv2(0);
pps.setDeblockingFilterTcOffsetDiv2(0);
pps.setDeblockingFilterCbBetaOffsetDiv2(0);
pps.setDeblockingFilterCbTcOffsetDiv2(0);
pps.setDeblockingFilterCrBetaOffsetDiv2(0);
pps.setDeblockingFilterCrTcOffsetDiv2(0);

Karsten Suehring
committed
}
// deblockingFilterControlPresentFlag is true if any of the settings differ from the inferred values:
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
#if DB_PARAM_TID
bool TcAllZero = true, BetaAllZero = true;
for (int i = 0; i < pps.getDeblockingFilterBetaOffsetDiv2().size(); i++)
{
if (pps.getDeblockingFilterBetaOffsetDiv2()[i] != 0)
{
BetaAllZero = false;
break;
}
}
for (int i = 0; i < pps.getDeblockingFilterTcOffsetDiv2().size(); i++)
{
if (pps.getDeblockingFilterTcOffsetDiv2()[i] != 0)
{
TcAllZero = false;
break;
}
}
const bool deblockingFilterControlPresentFlag = pps.getDeblockingFilterOverrideEnabledFlag() ||
pps.getPPSDeblockingFilterDisabledFlag() ||
BetaAllZero == false ||
TcAllZero == false ||
pps.getDeblockingFilterCbBetaOffsetDiv2() != 0 ||
pps.getDeblockingFilterCbTcOffsetDiv2() != 0 ||
pps.getDeblockingFilterCrBetaOffsetDiv2() != 0 ||
pps.getDeblockingFilterCrTcOffsetDiv2() != 0;
#else
const bool deblockingFilterControlPresentFlag = pps.getDeblockingFilterOverrideEnabledFlag() ||
pps.getPPSDeblockingFilterDisabledFlag() ||
pps.getDeblockingFilterBetaOffsetDiv2() != 0 ||
pps.getDeblockingFilterTcOffsetDiv2() != 0 ||
pps.getDeblockingFilterCbBetaOffsetDiv2() != 0 ||
pps.getDeblockingFilterCbTcOffsetDiv2() != 0 ||
pps.getDeblockingFilterCrBetaOffsetDiv2() != 0 ||
pps.getDeblockingFilterCrTcOffsetDiv2() != 0;

Karsten Suehring
committed
pps.setDeblockingFilterControlPresentFlag(deblockingFilterControlPresentFlag);
pps.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
pps.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
bool chromaQPOffsetNotZero = false;
if( pps.getQpOffset(COMPONENT_Cb) != 0 || pps.getQpOffset(COMPONENT_Cr) != 0 || pps.getJointCbCrQpOffsetPresentFlag() || pps.getSliceChromaQpFlag() || pps.getCuChromaQpOffsetListEnabledFlag() )
{
chromaQPOffsetNotZero = true;
bool chromaDbfOffsetNotSameAsLuma = true;
if( pps.getDeblockingFilterCbBetaOffsetDiv2() == pps.getDeblockingFilterBetaOffsetDiv2() && pps.getDeblockingFilterCrBetaOffsetDiv2() == pps.getDeblockingFilterBetaOffsetDiv2()
&& pps.getDeblockingFilterCbTcOffsetDiv2() == pps.getDeblockingFilterTcOffsetDiv2() && pps.getDeblockingFilterCrTcOffsetDiv2() == pps.getDeblockingFilterTcOffsetDiv2() )
{
chromaDbfOffsetNotSameAsLuma = false;
const uint32_t chromaArrayType = (int)sps.getSeparateColourPlaneFlag() ? 0 : sps.getChromaFormatIdc();
if( ( chromaArrayType != CHROMA_400 ) && ( chromaQPOffsetNotZero || chromaDbfOffsetNotSameAsLuma ) )
if ((sps.getChromaFormatIdc() != CHROMA_400) && (chromaQPOffsetNotZero || chromaDbfOffsetNotSameAsLuma))
#endif
{
pps.setPPSChromaToolFlag(true);
}
else
{
pps.setPPSChromaToolFlag(false);
}

Karsten Suehring
committed
int histogram[MAX_NUM_REF + 1];
for( int i = 0; i <= MAX_NUM_REF; i++ )
{
histogram[i]=0;
}
for( int i = 0; i < getGOPSize(); i++)
{
CHECK(!(getRPLEntry(0, i).m_numRefPicsActive >= 0 && getRPLEntry(0, i).m_numRefPicsActive <= MAX_NUM_REF), "Unspecified error");
histogram[getRPLEntry(0, i).m_numRefPicsActive]++;

Karsten Suehring
committed
}
int maxHist=-1;
int bestPos=0;
for( int i = 0; i <= MAX_NUM_REF; i++ )
{
if(histogram[i]>maxHist)
{
maxHist=histogram[i];
bestPos=i;
}
}
CHECK(!(bestPos <= 15), "Unspecified error");
pps.setNumRefIdxL0DefaultActive(bestPos);

Karsten Suehring
committed
pps.setNumRefIdxL1DefaultActive(bestPos);
pps.setPictureHeaderExtensionPresentFlag(false);
Sheng-Yen Lin
committed
pps.setRplInfoInPhFlag(getSliceLevelRpl() ? false : true);
pps.setDbfInfoInPhFlag(getSliceLevelDblk() ? false : true);
pps.setSaoInfoInPhFlag(getSliceLevelSao() ? false : true);
pps.setAlfInfoInPhFlag(getSliceLevelAlf() ? false : true);
pps.setWpInfoInPhFlag(getSliceLevelWp() ? false : true);
pps.setQpDeltaInfoInPhFlag(getSliceLevelDeltaQp() ? false : true);

Karsten Suehring
committed
pps.pcv = new PreCalcValues( sps, pps, true );
pps.setRpl1IdxPresentFlag(sps.getRPL1IdxPresentFlag());

Karsten Suehring
committed
}
void EncLib::xInitPicHeader(PicHeader &picHeader, const SPS &sps, const PPS &pps)
{
int i;
picHeader.initPicHeader();
// parameter sets
picHeader.setSPSId( sps.getSPSId() );
picHeader.setPPSId( pps.getPPSId() );
picHeader.setMaxNumAffineMergeCand(getMaxNumAffineMergeCand());
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
// copy partitioning constraints from SPS
picHeader.setSplitConsOverrideFlag(false);
picHeader.setMinQTSizes( sps.getMinQTSizes() );
picHeader.setMaxMTTHierarchyDepths( sps.getMaxMTTHierarchyDepths() );
picHeader.setMaxBTSizes( sps.getMaxBTSizes() );
picHeader.setMaxTTSizes( sps.getMaxTTSizes() );
bool bUseDQP = (getCuQpDeltaSubdiv() > 0)? true : false;
if( (getMaxDeltaQP() != 0 )|| getUseAdaptiveQP() )
{
bUseDQP = true;
}
#if SHARP_LUMA_DELTA_QP
if( getLumaLevelToDeltaQPMapping().isEnabled() )
{
bUseDQP = true;
}
#endif
#if ENABLE_QPA
if( getUsePerceptQPA() && !bUseDQP )
{
CHECK( m_cuQpDeltaSubdiv != 0, "max. delta-QP subdiv must be zero!" );
bUseDQP = (getBaseQP() < 38) && (getSourceWidth() > 512 || getSourceHeight() > 320);
}
#endif
if( m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING )
{
bUseDQP=false;
}
if( m_RCEnableRateControl )
{
picHeader.setCuQpDeltaSubdivIntra( 0 );
picHeader.setCuQpDeltaSubdivInter( 0 );
}
else if( bUseDQP )
{
picHeader.setCuQpDeltaSubdivIntra( m_cuQpDeltaSubdiv );
picHeader.setCuQpDeltaSubdivInter( m_cuQpDeltaSubdiv );
}
else
{
picHeader.setCuQpDeltaSubdivIntra( 0 );
picHeader.setCuQpDeltaSubdivInter( 0 );
}
if( m_cuChromaQpOffsetSubdiv >= 0 )
{
picHeader.setCuChromaQpOffsetSubdivIntra(m_cuChromaQpOffsetSubdiv);
picHeader.setCuChromaQpOffsetSubdivInter(m_cuChromaQpOffsetSubdiv);
}
else
{
picHeader.setCuChromaQpOffsetSubdivIntra(0);
picHeader.setCuChromaQpOffsetSubdivInter(0);
}
if( sps.getVirtualBoundariesEnabledFlag() )
{
picHeader.setVirtualBoundariesPresentFlag( sps.getVirtualBoundariesPresentFlag() );
picHeader.setNumVerVirtualBoundaries(sps.getNumVerVirtualBoundaries());
picHeader.setNumHorVirtualBoundaries(sps.getNumHorVirtualBoundaries());
for(i=0; i<3; i++) {
picHeader.setVirtualBoundariesPosX(sps.getVirtualBoundariesPosX(i), i);
picHeader.setVirtualBoundariesPosY(sps.getVirtualBoundariesPosY(i), i);
}
picHeader.setGdrOrIrapPicFlag(false);
#endif
// gradual decoder refresh flag
picHeader.setGdrPicFlag(false);

Xuewei Meng
committed
picHeader.setDisBdofFlag(false);
picHeader.setDisDmvrFlag(false);
picHeader.setDisProfFlag(false);
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
#if JVET_W0097_GPM_MMVD_TM
if (sps.getUseGeo())
{
#if TOOLS
if (getIntraPeriod() > 0)
{
if ((getSourceWidth() * getSourceHeight()) > (1920 * 1080))
{
picHeader.setGPMMMVDTableFlag(false);
}
else
{
picHeader.setGPMMMVDTableFlag(true);
}
}
else
{
picHeader.setGPMMMVDTableFlag(true);
}
#else
picHeader.setGPMMMVDTableFlag(false);
#endif
}
#endif
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
picHeader.setDisFracMBVD(true);
if (sps.getIBCFracFlag())
{
if ((getSourceWidth() * getSourceHeight()) <= (1920 * 1080))
{
picHeader.setDisFracMBVD(false);
}
}
#endif
void EncLib::xInitAPS(APS &aps)
{
//Do nothing now
}
void EncLib::xInitRPL(SPS &sps, bool isFieldCoding)
{
ReferencePictureList* rpl;
int numRPLCandidates = getRPLCandidateSize(0);
// To allocate one additional memory for RPL of POC1 (first bottom field) which is not specified in cfg file
sps.createRPLList0(numRPLCandidates + (isFieldCoding ? 1 : 0));
sps.createRPLList1(numRPLCandidates + (isFieldCoding ? 1 : 0));
RPLList* rplList = 0;
for (int i = 0; i < 2; i++)
{
rplList = (i == 0) ? sps.getRPLList0() : sps.getRPLList1();
for (int j = 0; j < numRPLCandidates; j++)
{
const RPLEntry &ge = getRPLEntry(i, j);
rpl = rplList->getReferencePictureList(j);
rpl->setNumberOfShorttermPictures(ge.m_numRefPics);
rpl->setNumberOfLongtermPictures(0); //Hardcoded as 0 for now. need to update this when implementing LTRP
rpl->setNumberOfActivePictures(ge.m_numRefPicsActive);
Philip Cowan
committed
rpl->setLtrpInSliceHeaderFlag(ge.m_ltrp_in_slice_header_flag);
rpl->setInterLayerPresentFlag( sps.getInterLayerPresentFlag() );
// inter-layer reference picture is not signaled in SPS RPL, SPS is shared currently
rpl->setNumberOfInterLayerPictures( 0 );
for (int k = 0; k < ge.m_numRefPics; k++)
{
#if JVET_S0045_SIGN
rpl->setRefPicIdentifier(k, -ge.m_deltaRefPics[k], 0, false, 0);
#else
rpl->setRefPicIdentifier( k, ge.m_deltaRefPics[k], 0, false, 0 );
if (isFieldCoding)
{
// To set RPL of POC1 (first bottom field) which is not specified in cfg file
for (int i = 0; i < 2; i++)
{
rplList = (i == 0) ? sps.getRPLList0() : sps.getRPLList1();
rpl = rplList->getReferencePictureList(numRPLCandidates);
rpl->setNumberOfShorttermPictures(1);
rpl->setNumberOfLongtermPictures(0);
rpl->setNumberOfActivePictures(1);
rpl->setLtrpInSliceHeaderFlag(0);
#if JVET_S0045_SIGN
rpl->setRefPicIdentifier(0, -1, 0, false, 0);
#else
rpl->setRefPicIdentifier(0, 1, 0, false, 0);
rpl->setPOC(0, 0);
}
}
bool isRpl1CopiedFromRpl0 = true;
for( int i = 0; isRpl1CopiedFromRpl0 && i < numRPLCandidates; i++)
{
if( sps.getRPLList0()->getReferencePictureList(i)->getNumRefEntries() == sps.getRPLList1()->getReferencePictureList(i)->getNumRefEntries() )
{
for( int j = 0; isRpl1CopiedFromRpl0 && j < sps.getRPLList0()->getReferencePictureList(i)->getNumRefEntries(); j++ )
{
if( sps.getRPLList0()->getReferencePictureList(i)->getRefPicIdentifier(j) != sps.getRPLList1()->getReferencePictureList(i)->getRefPicIdentifier(j) )
{
isRpl1CopiedFromRpl0 = false;
}
}
}
else
{
isRpl1CopiedFromRpl0 = false;
}
}
sps.setRPL1CopyFromRPL0Flag(isRpl1CopiedFromRpl0);
//Check if all delta POC of STRP in each RPL has the same sign
//Check RPLL0 first
const RPLList* rplList0 = sps.getRPLList0();
const RPLList* rplList1 = sps.getRPLList1();
uint32_t numberOfRPL = sps.getNumRPL0();
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
bool isAllEntriesinRPLHasSameSignFlag = true;
bool isFirstEntry = true;
bool lastSign = true; //true = positive ; false = negative
for (uint32_t ii = 0; isAllEntriesinRPLHasSameSignFlag && ii < numberOfRPL; ii++)
{
const ReferencePictureList* rpl = rplList0->getReferencePictureList(ii);
for (uint32_t jj = 0; isAllEntriesinRPLHasSameSignFlag && jj < rpl->getNumberOfActivePictures(); jj++)
{
if (!rpl->isRefPicLongterm(jj) && isFirstEntry)
{
lastSign = (rpl->getRefPicIdentifier(jj) >= 0) ? true : false;
isFirstEntry = false;
}
else if (!rpl->isRefPicLongterm(jj) && (((rpl->getRefPicIdentifier(jj) - rpl->getRefPicIdentifier(jj - 1)) >= 0 && lastSign == false) || ((rpl->getRefPicIdentifier(jj) - rpl->getRefPicIdentifier(jj - 1)) < 0 && lastSign == true)))
{
isAllEntriesinRPLHasSameSignFlag = false;
}
}
}
//Check RPLL1. Skip it if it is already found out that this flag is not true for RPL0 or if RPL1 is the same as RPL0
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
isFirstEntry = true;
lastSign = true;
for (uint32_t ii = 0; isAllEntriesinRPLHasSameSignFlag && !sps.getRPL1CopyFromRPL0Flag() && ii < numberOfRPL; ii++)
{
isFirstEntry = true;
const ReferencePictureList* rpl = rplList1->getReferencePictureList(ii);
for (uint32_t jj = 0; isAllEntriesinRPLHasSameSignFlag && jj < rpl->getNumberOfActivePictures(); jj++)
{
if (!rpl->isRefPicLongterm(jj) && isFirstEntry)
{
lastSign = (rpl->getRefPicIdentifier(jj) >= 0) ? true : false;
isFirstEntry = false;
}
else if (!rpl->isRefPicLongterm(jj) && (((rpl->getRefPicIdentifier(jj) - rpl->getRefPicIdentifier(jj - 1)) >= 0 && lastSign == false) || ((rpl->getRefPicIdentifier(jj) - rpl->getRefPicIdentifier(jj - 1)) < 0 && lastSign == true)))
{
isAllEntriesinRPLHasSameSignFlag = false;
}
}
}
sps.setAllActiveRplEntriesHasSameSignFlag(isAllEntriesinRPLHasSameSignFlag);
}
void EncLib::getActiveRefPicListNumForPOC(const SPS *sps, int POCCurr, int GOPid, uint32_t *activeL0, uint32_t *activeL1)
{
{
*activeL0 = *activeL1 = 0;
return;
}
uint32_t rpl0Idx = GOPid;
uint32_t rpl1Idx = GOPid;
int fullListNum = m_iGOPSize;
int partialListNum = getRPLCandidateSize(0) - m_iGOPSize;
int extraNum = fullListNum;
int candidateIdx = (POCCurr + m_iGOPSize - 1 >= fullListNum + partialListNum) ? GOPid : POCCurr + m_iGOPSize - 1;
rpl0Idx = candidateIdx;
rpl1Idx = candidateIdx;
}
else
{
rpl0Idx = (POCCurr%m_iGOPSize == 0) ? m_iGOPSize - 1 : POCCurr%m_iGOPSize - 1;
rpl1Idx = (POCCurr%m_iGOPSize == 0) ? m_iGOPSize - 1 : POCCurr%m_iGOPSize - 1;
}
extraNum = fullListNum + partialListNum;
}
for (; extraNum<fullListNum + partialListNum; extraNum++)
{
if (m_intraPeriod > 0 && getDecodingRefreshType() > 0)
int POCIndex = POCCurr % m_intraPeriod;
{
POCIndex = m_intraPeriod;
}