<div dir="ltr">From 5f5359c8d5e9fdfd121347aa7185d552b1c3ded2 Mon Sep 17 00:00:00 2001<br>From: Kirithika <<a href="mailto:kirithika@multicorewareinc.com">kirithika@multicorewareinc.com</a>><br>Date: Mon, 6 May 2024 13:58:25 +0530<br>Subject: [PATCH] Add support to access DPB based on scalable layerID<br><br>---<br> source/encoder/dpb.cpp | 46 ++++++++++++++++++++++--------------------<br> source/encoder/dpb.h   | 14 ++++++-------<br> 2 files changed, 31 insertions(+), 29 deletions(-)<br><br>diff --git a/source/encoder/dpb.cpp b/source/encoder/dpb.cpp<br>index 52ef91af0..eeb2a5cb8 100644<br>--- a/source/encoder/dpb.cpp<br>+++ b/source/encoder/dpb.cpp<br>@@ -75,7 +75,7 @@ void DPB::recycleUnreferenced()<br>         if (curFrame->m_param->bEnableTemporalFilter)<br>             isMCSTFReferenced =!!(curFrame->m_refPicCnt[1]);<br> <br>-        if (!curFrame->m_encData->m_bHasReferences && !curFrame->m_countRefEncoders && !isMCSTFReferenced)<br>+        if (curFrame->m_valid && !curFrame->m_encData->m_bHasReferences && !curFrame->m_countRefEncoders && !isMCSTFReferenced)<br>         {<br>             curFrame->m_bChromaExtended = false;<br> <br>@@ -175,9 +175,11 @@ void DPB::prepareEncode(Frame *newFrame)<br>         newFrame->m_encData->m_bHasReferences = true;<br>     }<br> <br>-    m_picList.pushFront(*newFrame);<br>+    //Non base view pictures are already present in the list<br>+    if(newFrame->m_sLayerId == 0)<br>+        m_picList.pushFront(*newFrame);<br> <br>-    if (m_bTemporalSublayer && getTemporalLayerNonReferenceFlag())<br>+    if (m_bTemporalSublayer && getTemporalLayerNonReferenceFlag(newFrame->m_sLayerId))<br>     {<br>         switch (slice->m_nalUnitType)<br>         {<br>@@ -195,12 +197,12 @@ void DPB::prepareEncode(Frame *newFrame)<br>         }<br>     }<br>     // Do decoding refresh marking if any<br>-    decodingRefreshMarking(pocCurr, slice->m_nalUnitType);<br>+    decodingRefreshMarking(pocCurr, slice->m_nalUnitType, newFrame->m_sLayerId);<br> <br>-    computeRPS(pocCurr, newFrame->m_tempLayer, slice->isIRAP(), &slice->m_rps, slice->m_sps->maxDecPicBuffering[newFrame->m_tempLayer]);<br>+    computeRPS(pocCurr, newFrame->m_tempLayer, slice->isIRAP(), &slice->m_rps, slice->m_sps->maxDecPicBuffering[newFrame->m_tempLayer], newFrame->m_sLayerId);<br>     bool isTSAPic = ((slice->m_nalUnitType == 2) || (slice->m_nalUnitType == 3)) ? true : false;<br>     // Mark pictures in m_piclist as unreferenced if they are not included in RPS<br>-    applyReferencePictureSet(&slice->m_rps, pocCurr, newFrame->m_tempLayer, isTSAPic);<br>+    applyReferencePictureSet(&slice->m_rps, pocCurr, newFrame->m_tempLayer, isTSAPic, newFrame->m_sLayerId);<br> <br> <br>     if (m_bTemporalSublayer && newFrame->m_tempLayer > 0<br>@@ -221,7 +223,7 @@ void DPB::prepareEncode(Frame *newFrame)<br>                 slice->m_nalUnitType = NAL_UNIT_CODED_SLICE_TSA_R;<br>             }<br>         }<br>-        else if (isStepwiseTemporalLayerSwitchingPoint(&slice->m_rps, pocCurr, newFrame->m_tempLayer))<br>+        else if (isStepwiseTemporalLayerSwitchingPoint(&slice->m_rps, pocCurr, newFrame->m_tempLayer, newFrame->m_sLayerId))<br>         {<br>             bool isSTSA = true;<br>             int id = newFrame->m_gopOffset % x265_gop_ra_length[newFrame->m_gopId];<br>@@ -254,7 +256,7 @@ void DPB::prepareEncode(Frame *newFrame)<br>             }<br>             if (isSTSA == true)<br>             {<br>-                if (getTemporalLayerNonReferenceFlag())<br>+                if (getTemporalLayerNonReferenceFlag(newFrame->m_sLayerId))<br>                 {<br>                     slice->m_nalUnitType = NAL_UNIT_CODED_SLICE_STSA_N;<br>                 }<br>@@ -308,7 +310,7 @@ void DPB::prepareEncode(Frame *newFrame)<br>     }<br> }<br> <br>-void DPB::computeRPS(int curPoc, int tempId, bool isRAP, RPS * rps, unsigned int maxDecPicBuffer)<br>+void DPB::computeRPS(int curPoc, int tempId, bool isRAP, RPS * rps, unsigned int maxDecPicBuffer, int scalableLayerId)<br> {<br>     unsigned int poci = 0, numNeg = 0, numPos = 0;<br> <br>@@ -316,7 +318,7 @@ void DPB::computeRPS(int curPoc, int tempId, bool isRAP, RPS * rps, unsigned int<br> <br>     while (iterPic && (poci < maxDecPicBuffer - 1))<br>     {<br>-        if ((iterPic->m_poc != curPoc) && iterPic->m_encData->m_bHasReferences)<br>+        if (iterPic->m_valid && (iterPic->m_poc != curPoc) && iterPic->m_encData->m_bHasReferences && iterPic->m_sLayerId == scalableLayerId)<br>         {<br>             if ((!m_bTemporalSublayer || (iterPic->m_tempLayer <= tempId)) && ((m_lastIDR >= curPoc) || (m_lastIDR <= iterPic->m_poc)))<br>             {<br>@@ -337,10 +339,10 @@ void DPB::computeRPS(int curPoc, int tempId, bool isRAP, RPS * rps, unsigned int<br>     rps->sortDeltaPOC();<br> }<br> <br>-bool DPB::getTemporalLayerNonReferenceFlag()<br>+bool DPB::getTemporalLayerNonReferenceFlag(int scalableLayerId)<br> {<br>     Frame* curFrame = m_picList.first();<br>-    if (curFrame->m_encData->m_bHasReferences)<br>+    if (curFrame->m_valid && curFrame->m_encData->m_bHasReferences && curFrame->m_sLayerId == scalableLayerId)<br>     {<br>         curFrame->m_sameLayerRefPic = true;<br>         return false;<br>@@ -350,7 +352,7 @@ bool DPB::getTemporalLayerNonReferenceFlag()<br> }<br> <br> /* Marking reference pictures when an IDR/CRA is encountered. */<br>-void DPB::decodingRefreshMarking(int pocCurr, NalUnitType nalUnitType)<br>+void DPB::decodingRefreshMarking(int pocCurr, NalUnitType nalUnitType, int scalableLayerId)<br> {<br>     if (nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL || nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP)<br>     {<br>@@ -359,7 +361,7 @@ void DPB::decodingRefreshMarking(int pocCurr, NalUnitType nalUnitType)<br>         Frame* iterFrame = m_picList.first();<br>         while (iterFrame)<br>         {<br>-            if (iterFrame->m_poc != pocCurr)<br>+            if (iterFrame->m_valid && iterFrame->m_poc != pocCurr && iterFrame->m_sLayerId == scalableLayerId)<br>                 iterFrame->m_encData->m_bHasReferences = false;<br>             iterFrame = iterFrame->m_next;<br>         }<br>@@ -376,7 +378,7 @@ void DPB::decodingRefreshMarking(int pocCurr, NalUnitType nalUnitType)<br>             Frame* iterFrame = m_picList.first();<br>             while (iterFrame)<br>             {<br>-                if (iterFrame->m_poc != pocCurr && iterFrame->m_poc != m_pocCRA)<br>+                if (iterFrame->m_valid && iterFrame->m_poc != pocCurr && iterFrame->m_poc != m_pocCRA && iterFrame->m_sLayerId == scalableLayerId)<br>                     iterFrame->m_encData->m_bHasReferences = false;<br>                 iterFrame = iterFrame->m_next;<br>             }<br>@@ -398,13 +400,13 @@ void DPB::decodingRefreshMarking(int pocCurr, NalUnitType nalUnitType)<br> }<br> <br> /** Function for applying picture marking based on the Reference Picture Set */<br>-void DPB::applyReferencePictureSet(RPS *rps, int curPoc, int tempId, bool isTSAPicture)<br>+void DPB::applyReferencePictureSet(RPS *rps, int curPoc, int tempId, bool isTSAPicture, int scalableLayerId)<br> {<br>     // loop through all pictures in the reference picture buffer<br>     Frame* iterFrame = m_picList.first();<br>     while (iterFrame)<br>     {<br>-        if (iterFrame->m_poc != curPoc && iterFrame->m_encData->m_bHasReferences)<br>+        if (iterFrame->m_valid && iterFrame->m_poc != curPoc && iterFrame->m_encData->m_bHasReferences && iterFrame->m_sLayerId == scalableLayerId)<br>         {<br>             // loop through all pictures in the Reference Picture Set<br>             // to see if the picture should be kept as reference picture<br>@@ -441,13 +443,13 @@ void DPB::applyReferencePictureSet(RPS *rps, int curPoc, int tempId, bool isTSAP<br>     }<br> }<br> <br>-bool DPB::isTemporalLayerSwitchingPoint(int curPoc, int tempId)<br>+bool DPB::isTemporalLayerSwitchingPoint(int curPoc, int tempId, int scalableLayerId)<br> {<br>     // loop through all pictures in the reference picture buffer<br>     Frame* iterFrame = m_picList.first();<br>     while (iterFrame)<br>     {<br>-        if (iterFrame->m_poc != curPoc && iterFrame->m_encData->m_bHasReferences)<br>+        if (iterFrame->m_valid && iterFrame->m_poc != curPoc && iterFrame->m_encData->m_bHasReferences && iterFrame->m_sLayerId == scalableLayerId)<br>         {<br>             if (iterFrame->m_tempLayer >= tempId)<br>             {<br>@@ -459,13 +461,13 @@ bool DPB::isTemporalLayerSwitchingPoint(int curPoc, int tempId)<br>     return true;<br> }<br> <br>-bool DPB::isStepwiseTemporalLayerSwitchingPoint(RPS *rps, int curPoc, int tempId)<br>+bool DPB::isStepwiseTemporalLayerSwitchingPoint(RPS *rps, int curPoc, int tempId, int scalableLayerId)<br> {<br>     // loop through all pictures in the reference picture buffer<br>     Frame* iterFrame = m_picList.first();<br>     while (iterFrame)<br>     {<br>-        if (iterFrame->m_poc != curPoc && iterFrame->m_encData->m_bHasReferences)<br>+        if (iterFrame->m_valid && iterFrame->m_poc != curPoc && iterFrame->m_encData->m_bHasReferences && iterFrame->m_sLayerId == scalableLayerId)<br>         {<br>             for (int i = 0; i < rps->numberOfPositivePictures + rps->numberOfNegativePictures; i++)<br>             {<br>@@ -484,7 +486,7 @@ bool DPB::isStepwiseTemporalLayerSwitchingPoint(RPS *rps, int curPoc, int tempId<br> }<br> <br> /* deciding the nal_unit_type */<br>-NalUnitType DPB::getNalUnitType(int curPOC, bool bIsKeyFrame)<br>+NalUnitType DPB::getNalUnitType(int curPOC, bool bIsKeyFrame, int viewId)<br> {<br>     if (!curPOC)<br>         return NAL_UNIT_CODED_SLICE_IDR_N_LP;<br>diff --git a/source/encoder/dpb.h b/source/encoder/dpb.h<br>index a9543fc69..fcb19a203 100644<br>--- a/source/encoder/dpb.h<br>+++ b/source/encoder/dpb.h<br>@@ -79,15 +79,15 @@ public:<br> <br> protected:<br> <br>-    void computeRPS(int curPoc,int tempId, bool isRAP, RPS * rps, unsigned int maxDecPicBuffer);<br>+    void computeRPS(int curPoc,int tempId, bool isRAP, RPS * rps, unsigned int maxDecPicBuffer, int viewId);<br> <br>-    void applyReferencePictureSet(RPS *rps, int curPoc, int tempId, bool isTSAPicture);<br>-    bool getTemporalLayerNonReferenceFlag();<br>-    void decodingRefreshMarking(int pocCurr, NalUnitType nalUnitType);<br>-    bool isTemporalLayerSwitchingPoint(int curPoc, int tempId);<br>-    bool isStepwiseTemporalLayerSwitchingPoint(RPS *rps, int curPoc, int tempId);<br>+    void applyReferencePictureSet(RPS *rps, int curPoc, int tempId, bool isTSAPicture, int viewId);<br>+    bool getTemporalLayerNonReferenceFlag(int viewId);<br>+    void decodingRefreshMarking(int pocCurr, NalUnitType nalUnitType, int viewId);<br>+    bool isTemporalLayerSwitchingPoint(int curPoc, int tempId, int viewId);<br>+    bool isStepwiseTemporalLayerSwitchingPoint(RPS *rps, int curPoc, int tempId, int viewId);<br> <br>-    NalUnitType getNalUnitType(int curPoc, bool bIsKeyFrame);<br>+    NalUnitType getNalUnitType(int curPoc, bool bIsKeyFrame, int viewId);<br> };<br> }<br> <br>-- <br>2.36.0.windows.1<br><br></div>