[x265] [PATCH] frameencoder: store the reference state of the picture to FrameEncoder Member variable(m_keptAsRef)

gopu at multicorewareinc.com gopu at multicorewareinc.com
Thu Apr 3 11:41:38 CEST 2014


# HG changeset patch
# User Gopu Govindaswamy
# Date 1396518087 -19800
#      Thu Apr 03 15:11:27 2014 +0530
# Node ID 1e2071d1631fed08d76d794d36c579c076f37473
# Parent  c0362b478e23777120ee2cf3c286ca1f2e740018
frameencoder: store the reference state of the picture to FrameEncoder Member variable(m_keptAsRef)

We find that reference state of the reference frame changed during the encode when we use frame-thread > 1
this cause the CU level QP for the frame is non-deterministic, this is leading the non-deterministic
encoded output for the frame, to avoid this store the reference state of the frame to FrameEncoder->m_keptAsRef and
when the QP is calculate for CU, refer the reference state of the frame from FrameEncoder->m_keptAsRef
this stat will never change during the encode

Moved slice reference state initialization from dpb to FrameEncoder initSlice() method

diff -r c0362b478e23 -r 1e2071d1631f source/encoder/dpb.cpp
--- a/source/encoder/dpb.cpp	Wed Apr 02 22:52:19 2014 -0500
+++ b/source/encoder/dpb.cpp	Thu Apr 03 15:11:27 2014 +0530
@@ -79,17 +79,6 @@
         m_lastIDR = pocCurr;
     }
     slice->setLastIDR(m_lastIDR);
-
-    if (slice->getSliceType() != B_SLICE)
-        slice->setReferenced(true);
-    else
-    {
-        if (pic->m_lowres.sliceType == X265_TYPE_BREF)
-            slice->setReferenced(true);
-        else
-            slice->setReferenced(false);
-    }
-
     slice->setTemporalLayerNonReferenceFlag(!slice->isReferenced());
     // Set the nal unit type
     slice->setNalUnitType(getNalUnitType(pocCurr, m_lastIDR, pic));
diff -r c0362b478e23 -r 1e2071d1631f source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Wed Apr 02 22:52:19 2014 -0500
+++ b/source/encoder/frameencoder.cpp	Thu Apr 03 15:11:27 2014 +0530
@@ -265,7 +265,18 @@
     int type = pic->m_lowres.sliceType;
     SliceType sliceType = IS_X265_TYPE_B(type) ? B_SLICE : ((type == X265_TYPE_P) ? P_SLICE : I_SLICE);
     slice->setSliceType(sliceType);
-    slice->setReferenced(true);
+
+    if (sliceType != B_SLICE)
+        m_keptAsRef = true;
+    else
+    {
+        if (pic->m_lowres.sliceType == X265_TYPE_BREF)
+            m_keptAsRef = true;
+        else
+            m_keptAsRef = false;
+    }
+    slice->setReferenced(m_keptAsRef);
+
     slice->setScalingList(m_top->getScalingList());
     slice->getScalingList()->setUseTransformSkip(m_pps.getUseTransformSkip());
 #if LOG_CU_STATISTICS
@@ -1229,9 +1240,8 @@
     int block_x = (cuAddr * noOfBlocks) - block_y * m_pic->getPicSym()->getFrameWidthInCU();
 
     /* Use cuTree offsets in m_pic->m_lowres.qpOffset if cuTree enabled and
-     * frame is referenced (if P, ignore ref state). Else use AQ offsets */
-    double *qpoffs = ((m_pic->getSlice()->isReferenced() || m_pic->getSlice()->getSliceType() == P_SLICE) && m_cfg->param->rc.cuTree) ?
-                     m_pic->m_lowres.qpOffset : m_pic->m_lowres.qpAqOffset;
+     * frame is referenced Else use AQ offsets */
+    double *qpoffs = (m_keptAsRef && m_cfg->param->rc.cuTree) ? m_pic->m_lowres.qpOffset : m_pic->m_lowres.qpAqOffset;
 
     int cnt = 0, idx = 0;
     for (int h = 0; h < noOfBlocks && block_y < maxBlockRows; h++, block_y++)
diff -r c0362b478e23 -r 1e2071d1631f source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h	Wed Apr 02 22:52:19 2014 -0500
+++ b/source/encoder/frameencoder.h	Thu Apr 03 15:11:27 2014 +0530
@@ -190,6 +190,7 @@
     int                      m_filterRowDelay;
     Event                    m_completionEvent;
     int64_t                  m_totalTime;
+    bool                     m_keptAsRef;
 };
 }
 


More information about the x265-devel mailing list