Newer
Older

Karsten Suehring
committed
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_AC0096
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:
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
#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());
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
// 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);
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
#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();
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
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
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
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;
}
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
if (POCIndex == m_RPLList0[extraNum].m_POC)
{
rpl0Idx = extraNum;
rpl1Idx = extraNum;
extraNum++;
}
}
}
const ReferencePictureList *rpl0 = sps->getRPLList0()->getReferencePictureList(rpl0Idx);
*activeL0 = rpl0->getNumberOfActivePictures();
const ReferencePictureList *rpl1 = sps->getRPLList1()->getReferencePictureList(rpl1Idx);
*activeL1 = rpl1->getNumberOfActivePictures();
}
void EncLib::selectReferencePictureList(Slice* slice, int POCCurr, int GOPid, int ltPoc)
{
bool isEncodeLtRef = (POCCurr == ltPoc);
if (m_compositeRefEnabled && isEncodeLtRef)
{
POCCurr++;
}
slice->setRPL0idx(GOPid);
slice->setRPL1idx(GOPid);
int fullListNum = m_iGOPSize;
int partialListNum = getRPLCandidateSize(0) - m_iGOPSize;
int extraNum = fullListNum;
if( rplPeriod < 0 ) //Need to check if it is low delay or RA but with no RAP
{
if( slice->getSPS()->getRPLList0()->getReferencePictureList(1)->getRefPicIdentifier(0) * slice->getSPS()->getRPLList1()->getReferencePictureList(1)->getRefPicIdentifier(0) < 0)
{
rplPeriod = m_iGOPSize * 2;
}
}
if (rplPeriod < 0)
int candidateIdx = (POCCurr + m_iGOPSize - 1 >= fullListNum + partialListNum) ? GOPid : POCCurr + m_iGOPSize - 1;
slice->setRPL0idx(candidateIdx);
slice->setRPL1idx(candidateIdx);
}
else
{
slice->setRPL0idx((POCCurr%m_iGOPSize == 0) ? m_iGOPSize - 1 : POCCurr%m_iGOPSize - 1);
slice->setRPL1idx((POCCurr%m_iGOPSize == 0) ? m_iGOPSize - 1 : POCCurr%m_iGOPSize - 1);
}
extraNum = fullListNum + partialListNum;
}
for (; extraNum < fullListNum + partialListNum; extraNum++)
{
if (POCIndex == m_RPLList0[extraNum].m_POC)
{
slice->setRPL0idx(extraNum);
slice->setRPL1idx(extraNum);
extraNum++;
}
}
}
if (slice->getPic()->fieldPic)
{
// To set RPL index of POC1 (first bottom field)
if (POCCurr == 1)
{
slice->setRPL0idx(getRPLCandidateSize(0));
slice->setRPL1idx(getRPLCandidateSize(0));
}
{
// To set RPL indexes for LD
int numRPLCandidates = getRPLCandidateSize(0);
if (POCCurr < numRPLCandidates - m_iGOPSize + 2)
{
slice->setRPL0idx(POCCurr + m_iGOPSize - 2);
slice->setRPL1idx(POCCurr + m_iGOPSize - 2);
}
else
{
if (POCCurr%m_iGOPSize == 0)
{
slice->setRPL0idx(m_iGOPSize - 2);
slice->setRPL1idx(m_iGOPSize - 2);
}
else if (POCCurr%m_iGOPSize == 1)
{
slice->setRPL0idx(m_iGOPSize - 1);