diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp index 3bf06398eb079f23e22f33c22346461781352e97..cc0889a13e3c3925a83d36470c5746066558541f 100644 --- a/source/App/EncoderApp/EncApp.cpp +++ b/source/App/EncoderApp/EncApp.cpp @@ -904,7 +904,7 @@ void EncApp::rateStatsAccum(const AccessUnit& au, const std::vector<uint32_t>& a #endif case NAL_UNIT_SPS: case NAL_UNIT_PPS: -#if JVET_M0132 +#if JVET_M0132_APS case NAL_UNIT_APS: #endif m_essentialBytes += *it_stats; @@ -923,7 +923,7 @@ void EncApp::printRateSummary() msg( DETAILS,"Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time ); if (m_summaryVerboseness > 0) { -#if JVET_M0132 +#if JVET_M0132_APS msg(DETAILS, "Bytes for SPS/PPS/APS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time); #else msg( DETAILS,"Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time ); diff --git a/source/Lib/CommonLib/AdaptiveLoopFilter.cpp b/source/Lib/CommonLib/AdaptiveLoopFilter.cpp index 1fc64272eda9e93356e11ef50545e50cf177dff8..83c0f1bce2f6152bf89beb603df0329c41d50e66 100644 --- a/source/Lib/CommonLib/AdaptiveLoopFilter.cpp +++ b/source/Lib/CommonLib/AdaptiveLoopFilter.cpp @@ -174,7 +174,7 @@ void AdaptiveLoopFilter::reconstructCoeff( AlfSliceParam& alfSliceParam, Channel for( int classIdx = 0; classIdx < numClasses; classIdx++ ) { int filterIdx = alfSliceParam.filterCoeffDeltaIdx[classIdx]; - memcpy( m_coeffFinal + classIdx * MAX_NUM_ALF_LUMA_COEFF, coeff + filterIdx * MAX_NUM_ALF_LUMA_COEFF, sizeof( int16_t ) * numCoeff ); + memcpy( m_coeffFinal + classIdx * MAX_NUM_ALF_LUMA_COEFF, coeff + filterIdx * MAX_NUM_ALF_LUMA_COEFF, sizeof( short ) * numCoeff ); } if( bRedo && alfSliceParam.alfLumaCoeffDeltaPredictionFlag ) diff --git a/source/Lib/CommonLib/CodingStructure.cpp b/source/Lib/CommonLib/CodingStructure.cpp index fd23247455d97ee38630170b3116e5c4386b0d5b..8778f356730801a1d382b7ed078a20a2374a4733 100644 --- a/source/Lib/CommonLib/CodingStructure.cpp +++ b/source/Lib/CommonLib/CodingStructure.cpp @@ -802,6 +802,9 @@ void CodingStructure::initSubStructure( CodingStructure& subStruct, const Channe subStruct.vps = vps; #endif subStruct.pps = pps; +#if JVET_M0132_APS + subStruct.aps = aps; +#endif subStruct.slice = slice; subStruct.baseQP = baseQP; subStruct.prevQP[_chType] diff --git a/source/Lib/CommonLib/CodingStructure.h b/source/Lib/CommonLib/CodingStructure.h index 69f265d051f1beab6b764084e55a27616a5b6bbf..5846477d8d44e14c0009e94f70687474fe937f85 100644 --- a/source/Lib/CommonLib/CodingStructure.h +++ b/source/Lib/CommonLib/CodingStructure.h @@ -101,7 +101,7 @@ public: bool isLossless; const SPS *sps; const PPS *pps; -#if JVET_M0132 +#if JVET_M0132_APS APS * aps; #endif #if HEVC_VPS diff --git a/source/Lib/CommonLib/CommonDef.h b/source/Lib/CommonLib/CommonDef.h index d00a9c0e68ac065b823410941fe1774e84b4eae5..b6c92dc11ccedeedca3376f62810b99b7b2fee93 100644 --- a/source/Lib/CommonLib/CommonDef.h +++ b/source/Lib/CommonLib/CommonDef.h @@ -192,7 +192,7 @@ static const int C2FLAG_NUMBER = 1; ///< maxi static const int MAX_NUM_VPS = 16; static const int MAX_NUM_SPS = 16; static const int MAX_NUM_PPS = 64; -#if JVET_M0132 +#if JVET_M0132_APS static const int MAX_NUM_APS = 32; //Currently APS ID has 5 bits #endif diff --git a/source/Lib/CommonLib/Picture.cpp b/source/Lib/CommonLib/Picture.cpp index 286810db34d7c2fbc60ffd3463b0ee56201a63fe..d5ee0c4956c2bf31bacb5887aadbe87f0b7d3ecf 100644 --- a/source/Lib/CommonLib/Picture.cpp +++ b/source/Lib/CommonLib/Picture.cpp @@ -881,7 +881,7 @@ const CPelUnitBuf Picture::getRecoBuf(const UnitArea &unit) const { return g PelUnitBuf Picture::getRecoBuf() { return M_BUFS(scheduler.getSplitPicId(), PIC_RECONSTRUCTION); } const CPelUnitBuf Picture::getRecoBuf() const { return M_BUFS(scheduler.getSplitPicId(), PIC_RECONSTRUCTION); } -#if JVET_M0132 +#if JVET_M0132_APS void Picture::finalInit(const SPS& sps, const PPS& pps, APS& aps) #else void Picture::finalInit( const SPS& sps, const PPS& pps ) @@ -921,7 +921,7 @@ void Picture::finalInit( const SPS& sps, const PPS& pps ) cs->picture = this; cs->slice = nullptr; // the slices for this picture have not been set at this point. update cs->slice after swapSliceObject() cs->pps = &pps; -#if JVET_M0132 +#if JVET_M0132_APS cs->aps = &aps; #endif #if HEVC_VPS @@ -946,7 +946,7 @@ void Picture::allocateNewSlice() slices.push_back(new Slice); Slice& slice = *slices.back(); -#if JVET_M0132 +#if JVET_M0132_APS slice.setAPS(cs->aps); #endif slice.setPPS( cs->pps); @@ -962,7 +962,7 @@ Slice *Picture::swapSliceObject(Slice * p, uint32_t i) { p->setSPS(cs->sps); p->setPPS(cs->pps); -#if JVET_M0132 +#if JVET_M0132_APS p->setAPS(cs->aps); #endif @@ -970,7 +970,7 @@ Slice *Picture::swapSliceObject(Slice * p, uint32_t i) slices[i] = p; pTmp->setSPS(0); pTmp->setPPS(0); -#if JVET_M0132 +#if JVET_M0132_APS pTmp->setAPS(0); #endif return pTmp; diff --git a/source/Lib/CommonLib/Picture.h b/source/Lib/CommonLib/Picture.h index e9c3a2c625141c8dc15f8e270bd00eee1d7c555d..2b7088258926294ee371a01ba9d2278a33137782 100644 --- a/source/Lib/CommonLib/Picture.h +++ b/source/Lib/CommonLib/Picture.h @@ -233,7 +233,7 @@ struct Picture : public UnitArea const CPelUnitBuf getBuf(const UnitArea &unit, const PictureType &type) const; void extendPicBorder(); -#if JVET_M0132 +#if JVET_M0132_APS void finalInit(const SPS& sps, const PPS& pps, APS& aps); #else void finalInit( const SPS& sps, const PPS& pps ); diff --git a/source/Lib/CommonLib/Rom.cpp b/source/Lib/CommonLib/Rom.cpp index 76d36f27f48ebf3f75a89a67881600aba5bf372b..54d0ef78809c3c2909dad60e1bda5a047b76a2b5 100644 --- a/source/Lib/CommonLib/Rom.cpp +++ b/source/Lib/CommonLib/Rom.cpp @@ -86,7 +86,7 @@ const char* nalUnitTypeToString(NalUnitType type) #endif case NAL_UNIT_SPS: return "SPS"; case NAL_UNIT_PPS: return "PPS"; -#if JVET_M0132 +#if JVET_M0132_APS case NAL_UNIT_APS: return "APS"; #endif case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD"; diff --git a/source/Lib/CommonLib/Slice.cpp b/source/Lib/CommonLib/Slice.cpp index 4279429f0c8e4525dcdc70ebf6cae6d5c660cc00..92d43a1deb448055c43980ce8df2e0904a31ddd3 100644 --- a/source/Lib/CommonLib/Slice.cpp +++ b/source/Lib/CommonLib/Slice.cpp @@ -138,7 +138,7 @@ Slice::Slice() , m_uiMaxBTSizeIChroma ( 0 ) , m_uiMaxTTSizeIChroma ( 0 ) , m_uiMaxBTSize ( 0 ) -#if JVET_M0132 +#if JVET_M0132_APS , m_apsId ( -1 ) , m_aps (NULL) #endif @@ -1936,7 +1936,7 @@ PPS::~PPS() delete pcv; } -#if JVET_M0132 +#if JVET_M0132_APS APS::APS() : m_APSId(0) { @@ -2424,7 +2424,7 @@ ParameterSetManager::ParameterSetManager() : m_spsMap(MAX_NUM_SPS) #endif , m_ppsMap(MAX_NUM_PPS) -#if JVET_M0132 +#if JVET_M0132_APS , m_apsMap(MAX_NUM_APS) #endif #if HEVC_VPS @@ -2537,7 +2537,7 @@ bool ParameterSetManager::activatePPS(int ppsId, bool isIRAP) return false; } -#if JVET_M0132 +#if JVET_M0132_APS bool ParameterSetManager::activateAPS(int apsId) { APS *aps = m_apsMap.getPS(apsId); @@ -2684,7 +2684,7 @@ void xTracePPSHeader() DTRACE( g_trace_ctx, D_HEADER, "=========== Picture Parameter Set ===========\n" ); } -#if JVET_M0132 +#if JVET_M0132_APS void xTraceAPSHeader() { DTRACE(g_trace_ctx, D_HEADER, "=========== Adaptation Parameter Set ===========\n"); diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h index 00133d319b2883453a4f73f11d12ba18854187f1..8de58feca27b9dc7bdaaf50f327b4c5fad6272e5 100644 --- a/source/Lib/CommonLib/Slice.h +++ b/source/Lib/CommonLib/Slice.h @@ -1563,7 +1563,7 @@ public: PPSRExt& getPpsRangeExtension() { return m_ppsRangeExtension; } }; -#if JVET_M0132 +#if JVET_M0132_APS class APS { private: @@ -1578,7 +1578,7 @@ public: void setAPSId(int i) { m_APSId = i; } void setAlfAPSParam(AlfSliceParam& alfAPSParam) { m_alfAPSParam = alfAPSParam; } - AlfSliceParam getAlfAPSParam() { return m_alfAPSParam; } + const AlfSliceParam& getAlfAPSParam() const { return m_alfAPSParam; } }; #endif struct WPScalingParam @@ -1737,11 +1737,15 @@ private: uint32_t m_uiMaxTTSizeIChroma; uint32_t m_uiMaxBTSize; -#if JVET_M0132 +#if JVET_M0132_APS int m_apsId; APS* m_aps; #endif +#if !JVET_M0132_APS AlfSliceParam m_alfSliceParam; +#else + bool m_tileGroupAlfEnabledFlag; +#endif #if JVET_M0427_INLOOP_RESHAPER SliceReshapeInfo m_sliceReshapeInfo; #endif @@ -1762,7 +1766,7 @@ public: void setPPSId( int PPSId ) { m_iPPSId = PPSId; } int getPPSId() const { return m_iPPSId; } -#if JVET_M0132 +#if JVET_M0132_APS void setAPS(APS* aps) { m_aps = aps; m_apsId = (aps) ? aps->getAPSId() : -1; } APS* getAPS() { return m_aps; } void setAPSId(int apsId) { m_apsId = apsId; } @@ -2027,8 +2031,13 @@ public: void resetProcessingTime() { m_dProcessingTime = m_iProcessingStartTime = 0; } double getProcessingTime() const { return m_dProcessingTime; } +#if !JVET_M0132_APS void setAlfSliceParam( AlfSliceParam& alfSliceParam ) { m_alfSliceParam = alfSliceParam; } AlfSliceParam& getAlfSliceParam() { return m_alfSliceParam; } +#else + bool getTileGroupAlfEnabledFlag() const { return m_tileGroupAlfEnabledFlag; } + void setTileGroupAlfEnabledFlag(bool b) { m_tileGroupAlfEnabledFlag = b; } +#endif #if JVET_M0427_INLOOP_RESHAPER const SliceReshapeInfo& getReshapeInfo() const { return m_sliceReshapeInfo; } @@ -2225,7 +2234,7 @@ public: //! \returns true, if activation is successful bool activatePPS(int ppsId, bool isIRAP); -#if JVET_M0132 +#if JVET_M0132_APS void storeAPS(APS *aps, const std::vector<uint8_t> &naluData) { m_apsMap.storePS(aps->getAPSId(), aps, &naluData); }; APS* getAPS(int apsId) { return m_apsMap.getPS(apsId); }; bool getAPSChangedFlag(int apsId) const { return m_apsMap.getChangedFlag(apsId); } @@ -2244,7 +2253,7 @@ protected: #endif ParameterSetMap<SPS> m_spsMap; ParameterSetMap<PPS> m_ppsMap; -#if JVET_M0132 +#if JVET_M0132_APS ParameterSetMap<APS> m_apsMap; #endif @@ -2341,7 +2350,7 @@ void xTraceVPSHeader(); #endif void xTraceSPSHeader(); void xTracePPSHeader(); -#if JVET_M0132 +#if JVET_M0132_APS void xTraceAPSHeader(); #endif void xTraceSliceHeader(); diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index 64da37c58ff250291d083dadef6877493bc6f2f9..cae1666fd61af04e39fcb3caed1d0945bf41669d 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -278,6 +278,8 @@ typedef std::pair<int, int> TrCost; #endif #endif +#define JVET_M0132_APS 1 // APS + #define KEEP_PRED_AND_RESI_SIGNALS 0 @@ -332,7 +334,6 @@ typedef std::pair<int, int> TrCost; #define X0038_LAMBDA_FROM_QP_CAPABILITY 1 ///< This approach derives lambda from QP+QPoffset+QPoffset2. QPoffset2 is derived from QP+QPoffset using a linear model that is clipped between 0 and 3. // To use this capability enable config parameter LambdaFromQpEnable -#define JVET_M0132 1 // ==================================================================================================================== // Tool Switches // ==================================================================================================================== @@ -978,7 +979,7 @@ enum NalUnitType #endif NAL_UNIT_SPS, // 33 NAL_UNIT_PPS, // 34 -#if JVET_M0132 +#if JVET_M0132_APS NAL_UNIT_APS, //NAL unit type number needs to be reaaranged. #endif NAL_UNIT_ACCESS_UNIT_DELIMITER, // 35 @@ -1644,6 +1645,11 @@ struct AlfSliceParam bool alfLumaCoeffDeltaPredictionFlag; // alf_luma_coeff_delta_prediction_flag std::vector<AlfFilterShape>* filterShapes; + AlfSliceParam() + { + reset(); + } + void reset() { std::memset( enabledFlag, false, sizeof( enabledFlag ) ); diff --git a/source/Lib/DecoderLib/CABACReader.cpp b/source/Lib/DecoderLib/CABACReader.cpp index 92f87e1fcd70e4a1d62dd494a0a0f698be37701e..75d82428e38f7f48eb6ed60b8db0e19e5df9404c 100644 --- a/source/Lib/DecoderLib/CABACReader.cpp +++ b/source/Lib/DecoderLib/CABACReader.cpp @@ -143,10 +143,16 @@ bool CABACReader::coding_tree_unit( CodingStructure& cs, const UnitArea& area, i sao( cs, ctuRsAddr ); +#if !JVET_M0132_APS AlfSliceParam& alfSliceParam = cs.slice->getAlfSliceParam(); - - if( cs.sps->getALFEnabledFlag() && ( alfSliceParam.enabledFlag[COMPONENT_Y] || alfSliceParam.enabledFlag[COMPONENT_Cb] || alfSliceParam.enabledFlag[COMPONENT_Cr] ) ) + if (cs.sps->getALFEnabledFlag() && (alfSliceParam.enabledFlag[COMPONENT_Y] || alfSliceParam.enabledFlag[COMPONENT_Cb] || alfSliceParam.enabledFlag[COMPONENT_Cr])) + { +#else + if (cs.sps->getALFEnabledFlag() && (cs.slice->getTileGroupAlfEnabledFlag())) { + CHECK(cs.aps == nullptr, "APS not initialized"); + const AlfSliceParam& alfSliceParam = cs.aps->getAlfAPSParam(); +#endif const PreCalcValues& pcv = *cs.pcv; int frame_width_in_ctus = pcv.widthInCtus; diff --git a/source/Lib/DecoderLib/DecLib.cpp b/source/Lib/DecoderLib/DecLib.cpp index 977b832307c0edcc3c0c9ef326dc496c4ed89a04..4e08b972379c6fa3880efa7092e980347649be49 100644 --- a/source/Lib/DecoderLib/DecLib.cpp +++ b/source/Lib/DecoderLib/DecLib.cpp @@ -220,7 +220,13 @@ bool tryDecodePicture( Picture* pcEncPic, const int expectedPoc, const std::stri for( int i = 0; i < pic->slices.size(); i++ ) { +#if JVET_M0132_APS + pcEncPic->slices[i]->setAPSId(pic->slices[i]->getAPSId()); + pcEncPic->slices[i]->setAPS( pic->slices[i]->getAPS()); + pcEncPic->slices[i]->setTileGroupAlfEnabledFlag( pic->slices[i]->getTileGroupAlfEnabledFlag()); +#else pcEncPic->slices[i]->getAlfSliceParam() = pic->slices[i]->getAlfSliceParam(); +#endif } } @@ -581,7 +587,20 @@ void DecLib::executeLoopFilters() if( cs.sps->getALFEnabledFlag() ) { +#if JVET_M0132_APS + if (cs.slice->getTileGroupAlfEnabledFlag()) + { + // ALF decodes the differentially coded coefficients and stores them in the parameters structure. + // Code could be restructured to do directly after parsing. So far we just pass a fresh non-const + // copy in case the APS gets used more than once. + + AlfSliceParam alfParamCopy = cs.aps->getAlfAPSParam(); + m_cALF.ALFProcess(cs, alfParamCopy); + } +#else m_cALF.ALFProcess( cs, cs.slice->getAlfSliceParam() ); +#endif + } } @@ -738,7 +757,7 @@ void DecLib::xActivateParameterSets() { if (m_bFirstSliceInPicture) { -#if JVET_M0132 +#if JVET_M0132_APS APS *aps = m_parameterSetManager.getAPS(m_apcSlicePilot->getAPSId()); // this is a temporary APS object. Do not store this value if (m_apcSlicePilot->getAPSId() != -1) { @@ -758,16 +777,22 @@ void DecLib::xActivateParameterSets() m_parameterSetManager.clearSPSChangedFlag(sps->getSPSId()); m_parameterSetManager.clearPPSChangedFlag(pps->getPPSId()); -#if JVET_M0132 //Hendry - if (aps != 0) - m_parameterSetManager.clearAPSChangedFlag(aps->getAPSId()); -#endif - if (false == m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP())) { THROW("Parameter set activation failed!"); } +#if JVET_M0132_APS + if (aps) + { + m_parameterSetManager.clearAPSChangedFlag(aps->getAPSId()); + if (false == m_parameterSetManager.activateAPS(m_apcSlicePilot->getAPSId())) + { + THROW("APS activation failed!"); + } + } +#endif + xParsePrefixSEImessages(); #if RExt__HIGH_BIT_DEPTH_SUPPORT==0 @@ -782,7 +807,7 @@ void DecLib::xActivateParameterSets() m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS()); -#if JVET_M0132 +#if JVET_M0132_APS m_pcPic->finalInit(*sps, *pps, *aps); #else m_pcPic->finalInit( *sps, *pps ); @@ -800,7 +825,7 @@ void DecLib::xActivateParameterSets() Slice *pSlice = m_pcPic->slices[m_uiSliceSegmentIdx]; // Update the PPS and SPS pointers with the ones of the picture. -#if JVET_M0132 +#if JVET_M0132_APS aps= pSlice->getAPS(); #endif pps=pSlice->getPPS(); @@ -810,7 +835,7 @@ void DecLib::xActivateParameterSets() m_pcPic->cs->slice = pSlice; m_pcPic->cs->sps = sps; m_pcPic->cs->pps = pps; -#if JVET_M0132 +#if JVET_M0132_APS m_pcPic->cs->aps = aps; #endif #if HEVC_VPS @@ -888,14 +913,14 @@ void DecLib::xActivateParameterSets() const SPS *sps = pSlice->getSPS(); const PPS *pps = pSlice->getPPS(); -#if JVET_M0132 +#if JVET_M0132_APS APS *aps = pSlice->getAPS(); #endif // fix Parameter Sets, now that we have the real slice m_pcPic->cs->slice = pSlice; m_pcPic->cs->sps = sps; m_pcPic->cs->pps = pps; -#if JVET_M0132 +#if JVET_M0132_APS m_pcPic->cs->aps = aps; #endif #if HEVC_VPS @@ -912,7 +937,7 @@ void DecLib::xActivateParameterSets() { EXIT("Error - a new PPS has been decoded while processing a picture"); } -#if JVET_M0132 +#if JVET_M0132_APS if (aps && m_parameterSetManager.getAPSChangedFlag(aps->getAPSId())) { EXIT("Error - a new APS has been decoded while processing a picture"); @@ -1082,7 +1107,7 @@ bool DecLib::xDecodeSlice(InputNALUnit &nalu, int &iSkipFrame, int iPOCLastDispl int iMaxPOClsb = 1 << sps->getBitsForPOC(); m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) ); xUpdatePreviousTid0POC(m_apcSlicePilot); -#if JVET_M0132 +#if JVET_M0132_APS if (m_apcSlicePilot->getAPSId() != -1) { APS *aps = m_parameterSetManager.getAPS(m_apcSlicePilot->getAPSId()); @@ -1443,7 +1468,7 @@ void DecLib::xDecodePPS( InputNALUnit& nalu ) m_parameterSetManager.storePPS( pps, nalu.getBitstream().getFifo() ); } -#if JVET_M0132 +#if JVET_M0132_APS void DecLib::xDecodeAPS(InputNALUnit& nalu) { APS* aps = new APS(); @@ -1477,7 +1502,7 @@ bool DecLib::decode(InputNALUnit& nalu, int& iSkipFrame, int& iPOCLastDisplay) case NAL_UNIT_PPS: xDecodePPS( nalu ); return false; -#if JVET_M0132 +#if JVET_M0132_APS case NAL_UNIT_APS: xDecodeAPS(nalu); return false; diff --git a/source/Lib/DecoderLib/DecLib.h b/source/Lib/DecoderLib/DecLib.h index 9eea5fb986d367da97528a3547482fceaa4e5b68..d64b2f48f3df8392ebde4589c88dc872ee3cf7eb 100644 --- a/source/Lib/DecoderLib/DecLib.h +++ b/source/Lib/DecoderLib/DecLib.h @@ -184,7 +184,7 @@ protected: #endif void xDecodeSPS( InputNALUnit& nalu ); void xDecodePPS( InputNALUnit& nalu ); -#if JVET_M0132 +#if JVET_M0132_APS void xDecodeAPS(InputNALUnit& nalu); #endif void xUpdatePreviousTid0POC( Slice *pSlice ) { if ((pSlice->getTLayer()==0) && (pSlice->isReferenceNalu() && (pSlice->getNalUnitType()!=NAL_UNIT_CODED_SLICE_RASL_R)&& (pSlice->getNalUnitType()!=NAL_UNIT_CODED_SLICE_RADL_R))) { m_prevTid0POC=pSlice->getPOC(); } } diff --git a/source/Lib/DecoderLib/DecSlice.cpp b/source/Lib/DecoderLib/DecSlice.cpp index 0ffac78e941435d56b0731ab19c2a50981553872..de211649ddd3426dbf20c3475d003fe71ff8ca3e 100644 --- a/source/Lib/DecoderLib/DecSlice.cpp +++ b/source/Lib/DecoderLib/DecSlice.cpp @@ -91,7 +91,7 @@ void DecSlice::decompressSlice( Slice* slice, InputBitstream* bitstream ) cs.slice = slice; cs.sps = sps; cs.pps = slice->getPPS(); -#if JVET_M0132 +#if JVET_M0132_APS cs.aps = slice->getAPS(); #endif #if HEVC_VPS diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp index 99118d9270cd188d238d9689a539bc97797d3a45..dc527fb0856c8ce16c5006fbff3f088ee0a3dbfa 100644 --- a/source/Lib/DecoderLib/VLCReader.cpp +++ b/source/Lib/DecoderLib/VLCReader.cpp @@ -607,7 +607,7 @@ void HLSyntaxReader::parsePPS( PPS* pcPPS ) xReadRbspTrailingBits(); } -#if JVET_M0132 +#if JVET_M0132_APS void HLSyntaxReader::parseAPS(APS* aps) { #if ENABLE_TRACING @@ -1647,22 +1647,20 @@ void HLSyntaxReader::parseSliceHeader (Slice* pcSlice, ParameterSetManager *para if( sps->getALFEnabledFlag() ) { -#if JVET_M0132 +#if JVET_M0132_APS READ_FLAG(uiCode, "tile_group_alf_enabled_flag"); if (uiCode) { READ_CODE(5, uiCode, "tile_group_aps_id"); pcSlice->setAPSId(uiCode); pcSlice->setAPS(parameterSetManager->getAPS(uiCode)); - AlfSliceParam alfParam = pcSlice->getAPS()->getAlfAPSParam(); - pcSlice->setAlfSliceParam(alfParam); - pcSlice->getAlfSliceParam().enabledFlag[COMPONENT_Y] = true; + pcSlice->setTileGroupAlfEnabledFlag(true); } else { - pcSlice->getAlfSliceParam().enabledFlag[COMPONENT_Y] = false; - pcSlice->getAlfSliceParam().enabledFlag[COMPONENT_Cb] = false; - pcSlice->getAlfSliceParam().enabledFlag[COMPONENT_Cr] = false; + pcSlice->setTileGroupAlfEnabledFlag(false); + pcSlice->setAPSId(-1); + pcSlice->setAPS(nullptr); } #else alf( pcSlice->getAlfSliceParam() ); @@ -2491,7 +2489,7 @@ bool HLSyntaxReader::xMoreRbspData() return (cnt>0); } -#if !JVET_M0132 +#if !JVET_M0132_APS void HLSyntaxReader::alf( AlfSliceParam& alfSliceParam ) { uint32_t code; diff --git a/source/Lib/DecoderLib/VLCReader.h b/source/Lib/DecoderLib/VLCReader.h index a7d47899b2511823fd7e0e01dcad6e99b4236160..ac4a6bed11a401db99f75ca525dd9fbac4fb2471 100644 --- a/source/Lib/DecoderLib/VLCReader.h +++ b/source/Lib/DecoderLib/VLCReader.h @@ -149,7 +149,7 @@ public: #endif void parseSPS ( SPS* pcSPS ); void parsePPS ( PPS* pcPPS ); -#if JVET_M0132 +#if JVET_M0132_APS void parseAPS ( APS* pcAPS); #endif void parseVUI ( VUI* pcVUI, SPS* pcSPS ); @@ -168,7 +168,7 @@ public: #if JVET_M0427_INLOOP_RESHAPER void parseReshaper ( SliceReshapeInfo& sliceReshaperInfo, const SPS* pcSPS, const bool isIntra ); #endif -#if !JVET_M0132 +#if !JVET_M0132_APS void alf( AlfSliceParam& alfSliceParam ); #endif void alfFilter( AlfSliceParam& alfSliceParam, const bool isChroma ); diff --git a/source/Lib/EncoderLib/CABACWriter.cpp b/source/Lib/EncoderLib/CABACWriter.cpp index 513f6a35a7a545440323438b34ccfb116d43d75e..75dad855b7859a138a3642a20e3acb3e872856c3 100644 --- a/source/Lib/EncoderLib/CABACWriter.cpp +++ b/source/Lib/EncoderLib/CABACWriter.cpp @@ -3416,7 +3416,11 @@ void CABACWriter::codeAlfCtuEnableFlags( CodingStructure& cs, ComponentID compID void CABACWriter::codeAlfCtuEnableFlag( CodingStructure& cs, uint32_t ctuRsAddr, const int compIdx, AlfSliceParam* alfParam) { +#if JVET_M0132_APS + const AlfSliceParam& alfSliceParam = alfParam ? (*alfParam) : cs.aps->getAlfAPSParam(); +#else AlfSliceParam& alfSliceParam = alfParam ? (*alfParam) : cs.slice->getAlfSliceParam(); +#endif if( cs.sps->getALFEnabledFlag() && alfSliceParam.enabledFlag[compIdx] ) { diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp index 850f0148f875035e4d7e8ae6acb55d545d1fd6eb..f0a82a4ef7e68d5731314eb81e065b774c21050a 100644 --- a/source/Lib/EncoderLib/EncGOP.cpp +++ b/source/Lib/EncoderLib/EncGOP.cpp @@ -237,7 +237,7 @@ int EncGOP::xWritePPS (AccessUnit &accessUnit, const PPS *pps) return (int)(accessUnit.back()->m_nalUnitData.str().size()) * 8; } -#if JVET_M0132 +#if JVET_M0132_APS int EncGOP::xWriteAPS(AccessUnit &accessUnit, APS *aps) { OutputNALUnit nalu(NAL_UNIT_APS); @@ -2213,7 +2213,13 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, if( pcSlice->getSPS()->getALFEnabledFlag() ) { pcPic->resizeAlfCtuEnableFlag( numberOfCtusInFrame ); +#if JVET_M0132_APS + // reset the APS ALF parameters + AlfSliceParam newALFParam; + pcSlice->getAPS()->setAlfAPSParam(newALFParam); +#else std::memset( pcSlice->getAlfSliceParam().enabledFlag, false, sizeof( pcSlice->getAlfSliceParam().enabledFlag ) ); +#endif } bool decPic = false; @@ -2484,10 +2490,14 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, #endif alfSliceParam ); //assign ALF slice header +#if JVET_M0132_APS + pcPic->cs->aps->setAlfAPSParam(alfSliceParam); +#else for( int s = 0; s< uiNumSliceSegments; s++ ) { pcPic->slices[s]->setAlfSliceParam( alfSliceParam ); } +#endif } if (m_pcCfg->getUseCompositeRef() && getPrepareLTRef()) { @@ -2559,13 +2569,17 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, { xWriteAccessUnitDelimiter(accessUnit, pcSlice); } -#if JVET_M0132 - if (pcSlice->getSPS()->getALFEnabledFlag() && pcSlice->getAlfSliceParam().enabledFlag[COMPONENT_Y]) +#if JVET_M0132_APS + if (pcSlice->getSPS()->getALFEnabledFlag() && pcSlice->getAPS()->getAlfAPSParam().enabledFlag[COMPONENT_Y]) { + pcSlice->setTileGroupAlfEnabledFlag(true); pcSlice->setAPSId(pcSlice->getAPS()->getAPSId()); - pcSlice->getAPS()->setAlfAPSParam(pcSlice->getAlfSliceParam()); actualTotalBits += xWriteAPS(accessUnit, pcSlice->getAPS()); } + else + { + pcSlice->setTileGroupAlfEnabledFlag(false); + } #endif // reset presence of BP SEI indication diff --git a/source/Lib/EncoderLib/EncGOP.h b/source/Lib/EncoderLib/EncGOP.h index 975609f7b29f92a5dded3f48bada224ae0565a0e..29af605d641e8a2f8e8afe978d1d2ad2f23d777d 100644 --- a/source/Lib/EncoderLib/EncGOP.h +++ b/source/Lib/EncoderLib/EncGOP.h @@ -281,7 +281,7 @@ protected: #endif int xWriteSPS (AccessUnit &accessUnit, const SPS *sps); int xWritePPS (AccessUnit &accessUnit, const PPS *pps); -#if JVET_M0132 +#if JVET_M0132_APS int xWriteAPS(AccessUnit &accessUnit, APS *aps); #endif int xWriteParameterSets (AccessUnit &accessUnit, Slice *slice, const bool bSeqFirst); diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp index 51b54e0632ff493eaf0625e3af963efe2c0aea5c..b9eaad406f32eaaaa0fd1ae315e641bc5916f199 100644 --- a/source/Lib/EncoderLib/EncLib.cpp +++ b/source/Lib/EncoderLib/EncLib.cpp @@ -60,7 +60,7 @@ EncLib::EncLib() : m_spsMap( MAX_NUM_SPS ) , m_ppsMap( MAX_NUM_PPS ) -#if JVET_M0132 +#if JVET_M0132_APS , m_apsMap( MAX_NUM_APS ) #endif , m_AUWriterIf( nullptr ) @@ -217,7 +217,7 @@ void EncLib::init( bool isFieldCoding, AUWriterIf* auWriterIf ) SPS &sps0=*(m_spsMap.allocatePS(0)); // NOTE: implementations that use more than 1 SPS need to be aware of activation issues. PPS &pps0=*(m_ppsMap.allocatePS(0)); -#if JVET_M0132 +#if JVET_M0132_APS APS &aps0=*(m_apsMap.allocatePS(0)); #endif @@ -257,7 +257,7 @@ void EncLib::init( bool isFieldCoding, AUWriterIf* auWriterIf ) // initialize PPS xInitPPS(pps0, sps0); -#if JVET_M0132 +#if JVET_M0132_APS // initialize APS xInitAPS(aps0); #endif @@ -395,7 +395,7 @@ void EncLib::init( bool isFieldCoding, AUWriterIf* auWriterIf ) Picture *picBg = new Picture; picBg->create(sps0.getChromaFormatIdc(), Size(sps0.getPicWidthInLumaSamples(), sps0.getPicHeightInLumaSamples()), sps0.getMaxCUWidth(), sps0.getMaxCUWidth() + 16, false); picBg->getRecoBuf().fill(0); -#if JVET_M0132 +#if JVET_M0132_APS picBg->finalInit(sps0, pps0, aps0); #else picBg->finalInit(sps0, pps0); @@ -550,7 +550,7 @@ void EncLib::encode( bool flush, PelStorage* pcPicYuvOrg, PelStorage* cPicYuvTru const SPS *sps = m_spsMap.getPS(pps->getSPSId()); picCurr->M_BUFS(0, PIC_ORIGINAL).copyFrom(m_cGOPEncoder.getPicBg()->getRecoBuf()); -#if JVET_M0132 +#if JVET_M0132_APS APS *aps = m_apsMap.getPS(0); picCurr->finalInit(*sps, *pps, *aps); #else @@ -606,7 +606,7 @@ void EncLib::encode( bool flush, PelStorage* pcPicYuvOrg, PelStorage* cPicYuvTru pcPicCurr->M_BUFS( 0, PIC_TRUE_ORIGINAL).swap(*cPicYuvTrueOrg); #endif -#if JVET_M0132 +#if JVET_M0132_APS APS *pAPS = m_apsMap.getPS(0); pcPicCurr->finalInit(*pSPS, *pPPS, *pAPS); #else @@ -706,7 +706,7 @@ void EncLib::encode( bool flush, PelStorage* pcPicYuvOrg, PelStorage* pcPicYuvTr const PPS *pPPS=(ppsID<0) ? m_ppsMap.getFirstPS() : m_ppsMap.getPS(ppsID); const SPS *pSPS=m_spsMap.getPS(pPPS->getSPSId()); -#if JVET_M0132 +#if JVET_M0132_APS APS *pAPS = m_apsMap.getPS(0); pcField->finalInit(*pSPS, *pPPS, *pAPS); #else @@ -1516,7 +1516,7 @@ void EncLib::xInitPPS(PPS &pps, const SPS &sps) pps.pcv = new PreCalcValues( sps, pps, true ); } -#if JVET_M0132 +#if JVET_M0132_APS void EncLib::xInitAPS(APS &aps) { //Do nothing now @@ -1894,7 +1894,7 @@ void EncLib::setParamSetChanged(int spsId, int ppsId) m_spsMap.setChangedFlag(spsId); } #endif -#if JVET_M0132 +#if JVET_M0132_APS bool EncLib::APSNeedsWriting(int apsId) { bool isChanged = m_apsMap.getChangedFlag(apsId); diff --git a/source/Lib/EncoderLib/EncLib.h b/source/Lib/EncoderLib/EncLib.h index 9d70ff9db60e626c5eea678933a4bde13fd6eb84..d7f52bf87ca9456104649d3f77f5110d71e5bfbf 100644 --- a/source/Lib/EncoderLib/EncLib.h +++ b/source/Lib/EncoderLib/EncLib.h @@ -116,7 +116,7 @@ private: // SPS ParameterSetMap<SPS> m_spsMap; ///< SPS. This is the base value. This is copied to PicSym ParameterSetMap<PPS> m_ppsMap; ///< PPS. This is the base value. This is copied to PicSym -#if JVET_M0132 +#if JVET_M0132_APS ParameterSetMap<APS> m_apsMap; ///< APS. This is the base value. This is copied to PicSym #endif // RD cost computation @@ -153,7 +153,7 @@ protected: #endif void xInitSPS (SPS &sps); ///< initialize SPS from encoder options void xInitPPS (PPS &pps, const SPS &sps); ///< initialize PPS from encoder options -#if JVET_M0132 +#if JVET_M0132_APS void xInitAPS (APS &aps); ///< initialize APS from encoder options #endif #if HEVC_USE_SCALING_LISTS @@ -226,13 +226,13 @@ public: #if JCTVC_Y0038_PARAMS void setParamSetChanged(int spsId, int ppsId); #endif -#if JVET_M0132 +#if JVET_M0132_APS bool APSNeedsWriting(int apsId); #endif bool PPSNeedsWriting(int ppsId); bool SPSNeedsWriting(int spsId); const PPS* getPPS( int Id ) { return m_ppsMap.getPS( Id); } -#if JVET_M0132 +#if JVET_M0132_APS const APS* getAPS(int Id) { return m_apsMap.getPS(Id); } #endif diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp index 1affff3383d009e4173123cbd7142a8fc0522985..3b3cd4e8513ff11cfc478fbe74073aae1a35f329 100644 --- a/source/Lib/EncoderLib/VLCWriter.cpp +++ b/source/Lib/EncoderLib/VLCWriter.cpp @@ -365,7 +365,7 @@ void HLSWriter::codePPS( const PPS* pcPPS ) xWriteRbspTrailingBits(); } -#if JVET_M0132 +#if JVET_M0132_APS void HLSWriter::codeAPS( APS* pcAPS) { #if ENABLE_TRACING @@ -1210,9 +1210,10 @@ void HLSWriter::codeSliceHeader ( Slice* pcSlice ) if( pcSlice->getSPS()->getALFEnabledFlag() ) { -#if JVET_M0132 - WRITE_FLAG(pcSlice->getAlfSliceParam().enabledFlag[COMPONENT_Y], "tile_group_alf_enabled_flag"); - if (pcSlice->getAlfSliceParam().enabledFlag[COMPONENT_Y]) +#if JVET_M0132_APS + const int alfEnabled = pcSlice->getAPS()->getAlfAPSParam().enabledFlag[COMPONENT_Y] ? 1 : 0; + WRITE_FLAG( alfEnabled, "tile_group_alf_enabled_flag"); + if (alfEnabled) { WRITE_CODE(pcSlice->getAPSId(), 5, "tile_group_aps_id"); } @@ -1768,7 +1769,7 @@ bool HLSWriter::xFindMatchingLTRP(Slice* pcSlice, uint32_t *ltrpsIndex, int ltrp return false; } -#if !JVET_M0132 +#if !JVET_M0132_APS void HLSWriter::alf( const AlfSliceParam& alfSliceParam ) { WRITE_FLAG( alfSliceParam.enabledFlag[COMPONENT_Y], "tile_group_alf_enabled_flag" ); diff --git a/source/Lib/EncoderLib/VLCWriter.h b/source/Lib/EncoderLib/VLCWriter.h index e1e3fd853e7c866b0306e94b1cf4785f03198bd2..5470e805d1fa86e0b6675781616b2b28cdfdfac2 100644 --- a/source/Lib/EncoderLib/VLCWriter.h +++ b/source/Lib/EncoderLib/VLCWriter.h @@ -122,7 +122,7 @@ public: void codeVUI ( const VUI *pcVUI, const SPS* pcSPS ); void codeSPS ( const SPS* pcSPS ); void codePPS ( const PPS* pcPPS ); -#if JVET_M0132 +#if JVET_M0132_APS void codeAPS ( APS* pcAPS); #endif #if HEVC_VPS @@ -139,7 +139,7 @@ public: void codeScalingList ( const ScalingList &scalingList ); #endif -#if !JVET_M0132 +#if !JVET_M0132_APS void alf( const AlfSliceParam& alfSliceParam ); #endif void alfFilter( const AlfSliceParam& alfSliceParam, const bool isChroma );