From b10837939a925ffcab68dd1f5a8594a95fb5c2b1 Mon Sep 17 00:00:00 2001 From: "fabrice.leleannec" <fabrice.leleannec@interdigital.com> Date: Tue, 21 Jul 2020 16:21:29 +0200 Subject: [PATCH] Integration of JVET-R0433 --- source/Lib/CommonLib/Slice.h | 3 ++ source/Lib/CommonLib/TypeDef.h | 2 + source/Lib/DecoderLib/DecLib.cpp | 15 +++++++ source/Lib/DecoderLib/VLCReader.cpp | 67 +++++++++++++++++++++++++++-- source/Lib/DecoderLib/VLCReader.h | 6 ++- source/Lib/EncoderLib/EncGOP.cpp | 9 ++++ source/Lib/EncoderLib/VLCWriter.cpp | 48 +++++++++++++++++++-- source/Lib/EncoderLib/VLCWriter.h | 5 ++- 8 files changed, 147 insertions(+), 8 deletions(-) diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h index e7cbe11f2..63e614221 100644 --- a/source/Lib/CommonLib/Slice.h +++ b/source/Lib/CommonLib/Slice.h @@ -2300,6 +2300,9 @@ public: CcAlfFilterParam& getCcAlfAPSParam() { return m_ccAlfAPSParam; } void setHasPrefixNalUnitType( bool b ) { m_hasPrefixNalUnitType = b; } bool getHasPrefixNalUnitType() const { return m_hasPrefixNalUnitType; } +#if JVET_R0433 + bool chromaPresentFlag; +#endif }; struct WPScalingParam diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index b628b1c33..8081fc0c0 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -51,6 +51,8 @@ #include <cassert> //########### place macros to be removed in next cycle below this line ############### +#define JVET_R0433 1 // JVET-R0433: APS signaling and semantics cleanup + #define JVET_S0076_ASPECT1 1 // JVET-S0076: aspect 1: Move ph_non_ref_pic_flag to earlier position #define JVET_S0133_PH_SYNTAX_OVERRIDE_ENC_FIX 1 // JVET-S0133: Encoder-only fix on the override of partition constriants in PH diff --git a/source/Lib/DecoderLib/DecLib.cpp b/source/Lib/DecoderLib/DecLib.cpp index 38fef215c..7b154b493 100644 --- a/source/Lib/DecoderLib/DecLib.cpp +++ b/source/Lib/DecoderLib/DecLib.cpp @@ -1287,6 +1287,10 @@ void activateAPS(PicHeader* picHeader, Slice* pSlice, ParameterSetManager& param CHECK( aps->getTemporalId() > pSlice->getTLayer(), "TemporalId shall be less than or equal to the TemporalId of the coded slice NAL unit" ); //ToDO: APS NAL unit containing the APS RBSP shall have nuh_layer_id either equal to the nuh_layer_id of a coded slice NAL unit that referrs it, or equal to the nuh_layer_id of a direct dependent layer of the layer containing a coded slice NAL unit that referrs it. +#if JVET_R0433 + CHECK( sps->getChromaFormatIdc() == CHROMA_400 && aps->chromaPresentFlag, "When ChromaArrayType is equal to 0, the value of aps_chroma_present_flag of an ALF_APS shall be equal to 0" ); +#endif + CHECK(((sps->getCCALFEnabledFlag() == false) && (aps->getCcAlfAPSParam().newCcAlfFilter[0] || aps->getCcAlfAPSParam().newCcAlfFilter[1])), "When sps_ccalf_enabled_flag is 0, the values of alf_cc_cb_filter_signal_flag and alf_cc_cr_filter_signal_flag shall be equal to 0"); } } @@ -1389,6 +1393,12 @@ void activateAPS(PicHeader* picHeader, Slice* pSlice, ParameterSetManager& param THROW("LMCS APS activation failed!"); } +#if JVET_R0433 + CHECK( sps->getChromaFormatIdc() == CHROMA_400 && lmcsAPS->chromaPresentFlag, "When ChromaArrayType is equal to 0, the value of aps_chroma_present_flag of an LMCS_APS shall be equal to 0"); + + CHECK( lmcsAPS->getReshaperAPSInfo().maxNbitsNeededDeltaCW - 1 < 0 || lmcsAPS->getReshaperAPSInfo().maxNbitsNeededDeltaCW - 1 > sps->getBitDepth(CHANNEL_TYPE_LUMA) - 2, "The value of lmcs_delta_cw_prec_minus1 of an LMCS_APS shall be in the range of 0 to BitDepth – 2, inclusive" ); +#endif + CHECK( lmcsAPS->getTemporalId() > pSlice->getTLayer(), "TemporalId shall be less than or equal to the TemporalId of the coded slice NAL unit" ); //ToDO: APS NAL unit containing the APS RBSP shall have nuh_layer_id either equal to the nuh_layer_id of a coded slice NAL unit that referrs it, or equal to the nuh_layer_id of a direct dependent layer of the layer containing a coded slice NAL unit that referrs it. } @@ -1407,6 +1417,11 @@ void activateAPS(PicHeader* picHeader, Slice* pSlice, ParameterSetManager& param THROW( "SCALING LIST APS activation failed!" ); } +#if JVET_R0433 + CHECK( (sps->getChromaFormatIdc() == CHROMA_400 && scalingListAPS->chromaPresentFlag) || (sps->getChromaFormatIdc() != CHROMA_400 && !scalingListAPS->chromaPresentFlag), + "The value of aps_chroma_present_flag of the APS NAL unit having aps_params_type equal to SCALING_APS and adaptation_parameter_set_id equal to ph_scaling_list_aps_id shall be equal to ChromaArrayType = = 0 ? 0 : 1" ); +#endif + CHECK( scalingListAPS->getTemporalId() > pSlice->getTLayer(), "TemporalId shall be less than or equal to the TemporalId of the coded slice NAL unit" ); //ToDO: APS NAL unit containing the APS RBSP shall have nuh_layer_id either equal to the nuh_layer_id of a coded slice NAL unit that referrs it, or equal to the nuh_layer_id of a direct dependent layer of the layer containing a coded slice NAL unit that referrs it. } diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp index 4b3cb438d..e292c7407 100644 --- a/source/Lib/DecoderLib/VLCReader.cpp +++ b/source/Lib/DecoderLib/VLCReader.cpp @@ -913,6 +913,13 @@ void HLSyntaxReader::parseAPS( APS* aps ) READ_CODE(3, code, "aps_params_type"); aps->setAPSType( ApsType(code) ); + +#if JVET_R0433 + uint32_t code_aps_chromaPresentFlag; + READ_FLAG(code_aps_chromaPresentFlag, "aps_chroma_present_flag"); + aps->chromaPresentFlag = code_aps_chromaPresentFlag; +#endif + if( code == ALF_APS ) { parseAlfAps( aps ); @@ -945,14 +952,42 @@ void HLSyntaxReader::parseAlfAps( APS* aps ) param.enabledFlag[COMPONENT_Y] = param.enabledFlag[COMPONENT_Cb] = param.enabledFlag[COMPONENT_Cr] = true; READ_FLAG(code, "alf_luma_new_filter"); param.newFilterFlag[CHANNEL_TYPE_LUMA] = code; - READ_FLAG(code, "alf_chroma_new_filter"); - param.newFilterFlag[CHANNEL_TYPE_CHROMA] = code; + + #if JVET_R0433 + if (aps->chromaPresentFlag) + { +#endif + READ_FLAG(code, "alf_chroma_new_filter"); + param.newFilterFlag[CHANNEL_TYPE_CHROMA] = code; +#if JVET_R0433 + } + else + param.newFilterFlag[CHANNEL_TYPE_CHROMA] = 0; +#endif CcAlfFilterParam ccAlfParam = aps->getCcAlfAPSParam(); +#if JVET_R0433 + if (aps->chromaPresentFlag) + { +#endif READ_FLAG(code, "alf_cc_cb_filter_signal_flag"); ccAlfParam.newCcAlfFilter[COMPONENT_Cb - 1] = code; +#if JVET_R0433 + } + else + ccAlfParam.newCcAlfFilter[COMPONENT_Cb - 1] = 0; +#endif +#if JVET_R0433 + if (aps->chromaPresentFlag) + { +#endif READ_FLAG(code, "alf_cc_cr_filter_signal_flag"); ccAlfParam.newCcAlfFilter[COMPONENT_Cr - 1] = code; +#if JVET_R0433 + } + else + ccAlfParam.newCcAlfFilter[COMPONENT_Cr - 1] = 0; +#endif CHECK(param.newFilterFlag[CHANNEL_TYPE_LUMA] == 0 && param.newFilterFlag[CHANNEL_TYPE_CHROMA] == 0 && ccAlfParam.newCcAlfFilter[COMPONENT_Cb - 1] == 0 && ccAlfParam.newCcAlfFilter[COMPONENT_Cr - 1] == 0, "bitstream conformance error: one of alf_luma_filter_signal_flag, alf_chroma_filter_signal_flag, " @@ -1074,8 +1109,17 @@ void HLSyntaxReader::parseLmcsAps( APS* aps ) int signCW = code; info.reshaperModelBinCWDelta[i] = (1 - 2 * signCW) * absCW; } +#if JVET_R0433 + if (aps->chromaPresentFlag) + { +#endif READ_CODE(3, code, "lmcs_delta_abs_crs"); +#if JVET_R0433 + } + int absCW = aps->chromaPresentFlag ? code : 0; +#else int absCW = code; +#endif if (absCW > 0) { READ_CODE(1, code, "lmcs_delta_sign_crs_flag"); @@ -1089,7 +1133,11 @@ void HLSyntaxReader::parseLmcsAps( APS* aps ) void HLSyntaxReader::parseScalingListAps( APS* aps ) { ScalingList& info = aps->getScalingList(); +#if JVET_R0433 + parseScalingList(&info, aps->chromaPresentFlag); +#else parseScalingList( &info ); +#endif } void HLSyntaxReader::parseVUI(VUI* pcVUI, SPS *pcSPS) @@ -4993,16 +5041,29 @@ void HLSyntaxReader::parsePredWeightTable(PicHeader *picHeader, const SPS *sps) /** decode quantization matrix * \param scalingList quantization matrix information */ +#if JVET_R0433 +void HLSyntaxReader::parseScalingList(ScalingList *scalingList, bool aps_chromaPrsentFlag) +#else void HLSyntaxReader::parseScalingList(ScalingList* scalingList) +#endif { uint32_t code; bool scalingListCopyModeFlag; - +#if !JVET_R0433 READ_FLAG(code, "scaling_list_chroma_present_flag"); +#endif +#if JVET_R0433 + scalingList->setChromaScalingListPresentFlag(aps_chromaPrsentFlag); +#else scalingList->setChromaScalingListPresentFlag(code ? true : false); +#endif for (int scalingListId = 0; scalingListId < 28; scalingListId++) { +#if JVET_R0433 + if (aps_chromaPrsentFlag || scalingList->isLumaScalingList(scalingListId)) +#else if(scalingList->getChromaScalingListPresentFlag()|| scalingList->isLumaScalingList(scalingListId)) +#endif { READ_FLAG(code, "scaling_list_copy_mode_flag"); scalingListCopyModeFlag = (code) ? true : false; diff --git a/source/Lib/DecoderLib/VLCReader.h b/source/Lib/DecoderLib/VLCReader.h index 33cebe969..091749fc7 100644 --- a/source/Lib/DecoderLib/VLCReader.h +++ b/source/Lib/DecoderLib/VLCReader.h @@ -178,7 +178,11 @@ public: void parsePredWeightTable( Slice* pcSlice, const SPS *sps ); void parsePredWeightTable ( PicHeader *picHeader, const SPS *sps ); - void parseScalingList ( ScalingList* scalingList ); +#if JVET_R0433 + void parseScalingList ( ScalingList *scalingList, bool aps_chromaPresentFlag ); +#else + void parseScalingList ( ScalingList *scalingList ); +#endif void decodeScalingList ( ScalingList *scalingList, uint32_t scalingListId, bool isPredictor); void parseReshaper ( SliceReshapeInfo& sliceReshaperInfo, const SPS* pcSPS, const bool isIntra ); void alfFilter( AlfParam& alfParam, const bool isChroma, const int altIdx ); diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp index 16d9fbf88..407b904fa 100644 --- a/source/Lib/EncoderLib/EncGOP.cpp +++ b/source/Lib/EncoderLib/EncGOP.cpp @@ -3180,6 +3180,9 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, bool writeAPS = aps && apsMap->getChangedFlag((apsId << NUM_APS_TYPE_LEN) + LMCS_APS); if (writeAPS) { +#if JVET_R0433 + aps->chromaPresentFlag = pcSlice->getSPS()->getChromaFormatIdc() != CHROMA_400; +#endif actualTotalBits += xWriteAPS( accessUnit, aps, m_pcEncLib->getLayerId(), true ); apsMap->clearChangedFlag((apsId << NUM_APS_TYPE_LEN) + LMCS_APS); CHECK(aps != picHeader->getLmcsAPS(), "Wrong LMCS APS pointer in compressGOP"); @@ -3195,6 +3198,9 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, bool writeAPS = aps && apsMap->getChangedFlag( ( apsId << NUM_APS_TYPE_LEN ) + SCALING_LIST_APS ); if( writeAPS ) { +#if JVET_R0433 + aps->chromaPresentFlag = pcSlice->getSPS()->getChromaFormatIdc() != CHROMA_400; +#endif actualTotalBits += xWriteAPS( accessUnit, aps, m_pcEncLib->getLayerId(), true ); apsMap->clearChangedFlag( ( apsId << NUM_APS_TYPE_LEN ) + SCALING_LIST_APS ); CHECK( aps != picHeader->getScalingListAPS(), "Wrong SCALING LIST APS pointer in compressGOP" ); @@ -3229,6 +3235,9 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, if (writeAPS ) { +#if JVET_R0433 + aps->chromaPresentFlag = pcSlice->getSPS()->getChromaFormatIdc() != CHROMA_400; +#endif actualTotalBits += xWriteAPS( accessUnit, aps, m_pcEncLib->getLayerId(), true ); apsMap->clearChangedFlag((apsId << NUM_APS_TYPE_LEN) + ALF_APS); CHECK(aps != pcSlice->getAlfAPSs()[apsId] && apsId != pcSlice->getTileGroupCcAlfCbApsId() && apsId != pcSlice->getTileGroupCcAlfCrApsId(), "Wrong APS pointer in compressGOP"); diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp index a1d1405b9..6f58f7311 100644 --- a/source/Lib/EncoderLib/VLCWriter.cpp +++ b/source/Lib/EncoderLib/VLCWriter.cpp @@ -513,6 +513,9 @@ void HLSWriter::codeAPS( APS* pcAPS ) WRITE_CODE(pcAPS->getAPSId(), 5, "adaptation_parameter_set_id"); WRITE_CODE( (int)pcAPS->getAPSType(), 3, "aps_params_type" ); +#if JVET_R0433 + WRITE_FLAG(pcAPS->chromaPresentFlag, "aps_chroma_present_flag"); +#endif if (pcAPS->getAPSType() == ALF_APS) { @@ -535,11 +538,25 @@ void HLSWriter::codeAlfAps( APS* pcAPS ) AlfParam param = pcAPS->getAlfAPSParam(); WRITE_FLAG(param.newFilterFlag[CHANNEL_TYPE_LUMA], "alf_luma_new_filter"); +#if JVET_R0433 + if (pcAPS->chromaPresentFlag) + { +#endif WRITE_FLAG(param.newFilterFlag[CHANNEL_TYPE_CHROMA], "alf_chroma_new_filter"); +#if JVET_R0433 + } +#endif CcAlfFilterParam paramCcAlf = pcAPS->getCcAlfAPSParam(); - WRITE_FLAG(paramCcAlf.newCcAlfFilter[COMPONENT_Cb - 1], "alf_cc_cb_filter_signal_flag"); - WRITE_FLAG(paramCcAlf.newCcAlfFilter[COMPONENT_Cr - 1], "alf_cc_cr_filter_signal_flag"); +#if JVET_R0433 + if (pcAPS->chromaPresentFlag) + { +#endif + WRITE_FLAG(paramCcAlf.newCcAlfFilter[COMPONENT_Cb - 1], "alf_cc_cb_filter_signal_flag"); + WRITE_FLAG(paramCcAlf.newCcAlfFilter[COMPONENT_Cr - 1], "alf_cc_cr_filter_signal_flag"); +#if JVET_R0433 + } +#endif if (param.newFilterFlag[CHANNEL_TYPE_LUMA]) { @@ -632,10 +649,21 @@ void HLSWriter::codeLmcsAps( APS* pcAPS ) WRITE_FLAG(signCW, "lmcs_delta_sign_cw_flag[ i ]"); } } +#if JVET_R0433 + int deltaCRS = pcAPS->chromaPresentFlag ? param.chrResScalingOffset : 0; +#else int deltaCRS = param.chrResScalingOffset; +#endif int signCRS = (deltaCRS < 0) ? 1 : 0; int absCRS = (deltaCRS < 0) ? (-deltaCRS) : deltaCRS; - WRITE_CODE(absCRS, 3, "lmcs_delta_abs_crs"); +#if JVET_R0433 + if (pcAPS->chromaPresentFlag) + { +#endif + WRITE_CODE(absCRS, 3, "lmcs_delta_abs_crs"); +#if JVET_R0433 + } +#endif if (absCRS > 0) { WRITE_FLAG(signCRS, "lmcs_delta_sign_crs_flag"); @@ -645,7 +673,11 @@ void HLSWriter::codeLmcsAps( APS* pcAPS ) void HLSWriter::codeScalingListAps( APS* pcAPS ) { ScalingList param = pcAPS->getScalingList(); +#if JVET_R0433 + codeScalingList(param, pcAPS->chromaPresentFlag); +#else codeScalingList( param ); +#endif } void HLSWriter::codeVUI( const VUI *pcVUI, const SPS* pcSPS ) @@ -2917,13 +2949,23 @@ void HLSWriter::xCodePredWeightTable(PicHeader *picHeader, const SPS *sps) /** code quantization matrix * \param scalingList quantization matrix information */ +#if JVET_R0433 +void HLSWriter::codeScalingList( const ScalingList &scalingList, bool aps_chromaPresentFlag ) +#else void HLSWriter::codeScalingList( const ScalingList &scalingList ) +#endif { //for each size +#if !JVET_R0433 WRITE_FLAG(scalingList.getChromaScalingListPresentFlag(), "scaling_list_chroma_present_flag"); +#endif for (uint32_t scalingListId = 0; scalingListId < 28; scalingListId++) { +#if JVET_R0433 + if (aps_chromaPresentFlag || scalingList.isLumaScalingList(scalingListId)) +#else if(scalingList.getChromaScalingListPresentFlag()|| scalingList.isLumaScalingList(scalingListId)) +#endif { bool scalingListCopyModeFlag = scalingList.getScalingListCopyModeFlag(scalingListId); WRITE_FLAG(scalingListCopyModeFlag, "scaling_list_copy_mode_flag"); //copy mode diff --git a/source/Lib/EncoderLib/VLCWriter.h b/source/Lib/EncoderLib/VLCWriter.h index c044001e6..45e7cb201 100644 --- a/source/Lib/EncoderLib/VLCWriter.h +++ b/source/Lib/EncoderLib/VLCWriter.h @@ -141,8 +141,11 @@ public: void codeGeneralHrdparameters(const GeneralHrdParams *hrd); void codeTilesWPPEntryPoint ( Slice* pSlice ); +#if JVET_R0433 + void codeScalingList(const ScalingList &scalingList, bool aps_chromaPresentFlag); +#else void codeScalingList ( const ScalingList &scalingList ); - +#endif void alfFilter( const AlfParam& alfParam, const bool isChroma, const int altIdx ); void dpb_parameters(int maxSubLayersMinus1, bool subLayerInfoFlag, const SPS *pcSPS); private: -- GitLab