[x265] [PATCH] dpb: select best TMVP candidate from among all of the reference frames

gopu at multicorewareinc.com gopu at multicorewareinc.com
Tue Sep 9 06:29:32 CEST 2014


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1410236940 -19800
#      Tue Sep 09 09:59:00 2014 +0530
# Node ID 88b0307c69c39c1dc9829922d6fcf37d828bd63d
# Parent  b5f81a83940396c241d33c8f15a5ef48de9cd62e
dpb: select best TMVP candidate from among all of the reference frames

diff -r b5f81a839403 -r 88b0307c69c3 source/encoder/dpb.cpp
--- a/source/encoder/dpb.cpp	Mon Sep 08 22:40:00 2014 +0200
+++ b/source/encoder/dpb.cpp	Tue Sep 09 09:59:00 2014 +0530
@@ -87,7 +87,7 @@
     }
 }
 
-void DPB::prepareEncode(Frame *pic)
+void DPB::prepareEncode(Frame *pic, x265_param *param)
 {
     Slice* slice = pic->m_picSym->m_slice;
     slice->m_pic = pic;
@@ -142,35 +142,69 @@
 
     X265_CHECK(slice->m_sliceType != B_SLICE || slice->m_numRefIdx[1], "B slice without L1 references (non-fatal)\n");
 
-    if (slice->m_sliceType == B_SLICE)
+    if (param->bFrameAdaptive == X265_B_ADAPT_TRELLIS)
     {
-        /* TODO: the lookahead should be able to tell which reference picture
-         * had the least motion residual.  We should be able to use that here to
-         * select a colocation reference list and index */
-        slice->m_colFromL0Flag = false;
-        slice->m_colRefIdx = 0;
-        slice->m_bCheckLDC = false;
+        int64_t bestCost = MAX_INT64;
+        int32_t refIdx = 0, lIdx = 0;
+        for (int ref = 0; ref < slice->m_numRefIdx[lIdx]; ref++)
+        {
+            Frame *refpic = slice->m_refPicList[lIdx][ref];
+            int64_t cost = refpic->m_lowres.costEst[slice->m_poc - refpic->m_POC][lIdx];
+            if (bestCost > cost)
+            {
+                bestCost = cost;
+                refIdx = ref;
+            }
+            ATOMIC_INC(&refpic->m_countRefEncoders);
+        }
+        if (slice->m_sliceType == B_SLICE)
+        {
+            refIdx = 0, lIdx = 1;
+            for (int ref = 0; ref < slice->m_numRefIdx[lIdx]; ref++)
+            {
+                Frame *refpic = slice->m_refPicList[lIdx][ref];
+                int64_t cost = refpic->m_lowres.costEst[lIdx][refpic->m_POC - slice->m_poc];
+                if (bestCost > cost)
+                {
+                    bestCost = cost;
+                    refIdx = ref;
+                }
+                ATOMIC_INC(&refpic->m_countRefEncoders);
+            }
+        }
+        Frame *refpic = slice->m_refPicList[lIdx][refIdx];
+        if (refpic)
+        {
+            slice->m_colFromL0Flag = refpic->m_picSym->m_slice->m_colFromL0Flag;
+            slice->m_colRefIdx = refpic->m_picSym->m_slice->m_colRefIdx;
+        }
+        else
+        {
+            slice->m_colFromL0Flag = !B_SLICE;
+            slice->m_colRefIdx = 0;
+        }
     }
     else
     {
-        slice->m_bCheckLDC = true;
-        slice->m_colFromL0Flag = true;
+        slice->m_colFromL0Flag = !B_SLICE;
         slice->m_colRefIdx = 0;
-    }
-    slice->m_sLFaseFlag = (SLFASE_CONSTANT & (1 << (pocCurr % 31))) > 0;
 
-    /* Increment reference count of all motion-referenced frames to prevent them
-     * from being recycled. These counts are decremented at the end of
-     * compressFrame() */
-    int numPredDir = slice->isInterP() ? 1 : slice->isInterB() ? 2 : 0;
-    for (int l = 0; l < numPredDir; l++)
-    {
-        for (int ref = 0; ref < slice->m_numRefIdx[l]; ref++)
+        /* Increment reference count of all motion-referenced frames to prevent them
+         * from being recycled. These counts are decremented at the end of
+         * compressFrame() */
+        int numPredDir = slice->isInterP() ? 1 : slice->isInterB() ? 2 : 0;
+        for (int l = 0; l < numPredDir; l++)
         {
-            Frame *refpic = slice->m_refPicList[l][ref];
-            ATOMIC_INC(&refpic->m_countRefEncoders);
+            for (int ref = 0; ref < slice->m_numRefIdx[l]; ref++)
+            {
+                Frame *refpic = slice->m_refPicList[l][ref];
+                ATOMIC_INC(&refpic->m_countRefEncoders);
+            }
         }
     }
+
+    slice->m_bCheckLDC = slice->m_sliceType != B_SLICE;
+    slice->m_sLFaseFlag = (SLFASE_CONSTANT & (1 << (pocCurr % 31))) > 0;
 }
 
 void DPB::computeRPS(int curPoc, bool isRAP, RPS * rps, unsigned int maxDecPicBuffer)
diff -r b5f81a839403 -r 88b0307c69c3 source/encoder/dpb.h
--- a/source/encoder/dpb.h	Mon Sep 08 22:40:00 2014 +0200
+++ b/source/encoder/dpb.h	Tue Sep 09 09:59:00 2014 +0530
@@ -61,7 +61,7 @@
 
     ~DPB();
 
-    void prepareEncode(Frame*);
+    void prepareEncode(Frame*, x265_param*);
 
     void recycleUnreferenced();
 
diff -r b5f81a839403 -r 88b0307c69c3 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Mon Sep 08 22:40:00 2014 +0200
+++ b/source/encoder/encoder.cpp	Tue Sep 09 09:59:00 2014 +0530
@@ -460,7 +460,7 @@
             fenc->m_dts = fenc->m_reorderedPts;
 
         // determine references, setup RPS, etc
-        m_dpb->prepareEncode(fenc);
+        m_dpb->prepareEncode(fenc, m_param);
 
         if (m_param->rc.rateControlMode != X265_RC_CQP)
             m_lookahead->getEstimatedPictureCost(fenc);


More information about the x265-devel mailing list