diff --git a/source/Lib/CommonLib/Slice.cpp b/source/Lib/CommonLib/Slice.cpp index 108d535e1f5b3cae506bb73795e2f94b2fbea323..92194a48127c8b4fa183b3cb937dfa4ee593c9ff 100644 --- a/source/Lib/CommonLib/Slice.cpp +++ b/source/Lib/CommonLib/Slice.cpp @@ -421,6 +421,30 @@ Picture* Slice::xGetLongTermRefPic( PicList& rcListPic, const int poc, const boo return refPic; } +Picture* Slice::xGetLongTermRefPicCandidate( PicList& rcListPic, const int poc, const bool pocHasMsb, const int layerId ) +{ + // return a nullptr, if picture is not found (might be a short-term or a long-term) + Picture* refPic = nullptr; + const int pocCycle = 1 << getSPS()->getBitsForPOC(); + + const int refPoc = pocHasMsb ? poc : (poc & (pocCycle - 1)); + + for ( auto &currPic : rcListPic ) + { + if( currPic->getPOC() != this->getPOC() && currPic->referenced && currPic->layerId == layerId ) + { + int currPicPoc = pocHasMsb ? currPic->getPOC() : (currPic->getPOC() & (pocCycle - 1)); + if (refPoc == currPicPoc) + { + refPic = currPic; + break; + } + } + } + + return refPic; +} + void Slice::setRefPOCList () { for (int iDir = 0; iDir < NUM_REF_PIC_LIST_01; iDir++) @@ -496,7 +520,7 @@ void Slice::constructRefPicList(PicList& rcListPic) { ltrpPoc += getPOC() - m_localRPL0.getDeltaPocMSBCycleLT(ii) * (pocMask + 1) - (getPOC() & pocMask); } - pcRefPic = xGetLongTermRefPic( rcListPic, ltrpPoc, m_localRPL0.getDeltaPocMSBPresentFlag( ii ), m_pcPic->layerId ); + pcRefPic = xGetLongTermRefPicCandidate( rcListPic, ltrpPoc, m_localRPL0.getDeltaPocMSBPresentFlag( ii ), m_pcPic->layerId ); pcRefPic->longTerm = true; } pcRefPic->extendPicBorder( getPPS() ); @@ -536,7 +560,7 @@ void Slice::constructRefPicList(PicList& rcListPic) { ltrpPoc += getPOC() - m_localRPL1.getDeltaPocMSBCycleLT(ii) * (pocMask + 1) - (getPOC() & pocMask); } - pcRefPic = xGetLongTermRefPic( rcListPic, ltrpPoc, m_localRPL1.getDeltaPocMSBPresentFlag( ii ), m_pcPic->layerId ); + pcRefPic = xGetLongTermRefPicCandidate( rcListPic, ltrpPoc, m_localRPL1.getDeltaPocMSBPresentFlag( ii ), m_pcPic->layerId ); pcRefPic->longTerm = true; } pcRefPic->extendPicBorder( getPPS() ); diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h index 57a45f06eae636b28e2b6f9e88eaf4ae52c1d3b3..84df6e13445d30947a97124d2d8d81cc4c84651c 100644 --- a/source/Lib/CommonLib/Slice.h +++ b/source/Lib/CommonLib/Slice.h @@ -3205,6 +3205,7 @@ public: protected: Picture* xGetRefPic( PicList& rcListPic, const int poc, const int layerId ); Picture* xGetLongTermRefPic( PicList& rcListPic, const int poc, const bool pocHasMsb, const int layerId ); + Picture* xGetLongTermRefPicCandidate( PicList& rcListPic, const int poc, const bool pocHasMsb, const int layerId ); public: std::unordered_map< Position, std::unordered_map< Size, double> > m_mapPltCost[2]; private: