[x265] [PATCH] rc: generate cutree offsets for 2nd pass from stats

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Fri Jul 18 07:31:46 CEST 2014


# HG changeset patch
# User Aarthi Thirumalai<aarthi at multicorewareinc.com>
# Date 1405661493 -19800
#      Fri Jul 18 11:01:33 2014 +0530
# Node ID 98b829645cf9a656838bbb712b85aac0cb2559b6
# Parent  fb653ec12832e487fdd4d00f80ff85a302e7cf69
rc: generate cutree offsets for 2nd pass from stats

diff -r fb653ec12832 -r 98b829645cf9 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Jul 17 18:28:42 2014 +0530
+++ b/source/encoder/encoder.cpp	Fri Jul 18 11:01:33 2014 +0530
@@ -309,7 +309,18 @@
         ATOMIC_INC(&pic->m_countRefEncoders);
         bool bEnableWP = m_param->bEnableWeightedPred || m_param->bEnableWeightedBiPred;
         if (m_param->rc.aqMode || bEnableWP)
-            m_rateControl->calcAdaptiveQuantFrame(pic);
+        {
+            if (m_param->rc.cuTree && m_param->rc.bStatRead)
+            {
+                if (!m_rateControl->cuTreeReadFor2Pass(pic))
+                {
+                    m_aborted = 1;
+                    return -1;
+                }
+            }
+            else
+                m_rateControl->calcAdaptiveQuantFrame(pic);
+        }
         m_lookahead->addPicture(pic, pic_in->sliceType);
         m_numDelayedPic++;
     }
diff -r fb653ec12832 -r 98b829645cf9 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Thu Jul 17 18:28:42 2014 +0530
+++ b/source/encoder/ratecontrol.cpp	Fri Jul 18 11:01:33 2014 +0530
@@ -1250,6 +1250,46 @@
     return adjusted;
 }
 
+bool RateControl::cuTreeReadFor2Pass(Frame* frame)
+{
+    uint8_t sliceTypeActual = m_rce2Pass[frame->m_POC].sliceType;
+
+    if (m_rce2Pass[frame->m_POC].keptAsRef)
+    {
+        uint8_t type;
+        if (m_cuTreeStats.qpBufPos < 0)
+        {
+            do
+            {
+                m_cuTreeStats.qpBufPos++;
+
+                if (!fread(&type, 1, 1, m_cutreeStatFileIn))
+                    goto fail;
+                if (fread(m_cuTreeStats.qpBuffer[m_cuTreeStats.qpBufPos], sizeof(uint16_t), m_ncu, m_cutreeStatFileIn) != m_ncu)
+                    goto fail;
+
+                if (type != sliceTypeActual && m_cuTreeStats.qpBufPos == 1)
+                {
+                    x265_log(m_param, X265_LOG_ERROR, "CU-tree frametype %d doesn't match actual frametype %d.\n", type, sliceTypeActual);
+                    return false;
+                }
+            } while(type != sliceTypeActual);
+        }
+        for (int i = 0; i < m_ncu; i++)
+        {
+            frame->m_lowres.qpCuTreeOffset[i] = (double)(m_cuTreeStats.qpBuffer[m_cuTreeStats.qpBufPos][i]);
+            frame->m_lowres.invQscaleFactor[i] = x265_exp2fix8(frame->m_lowres.qpCuTreeOffset[i]);
+        }
+        m_cuTreeStats.qpBufPos--;
+    }
+    else
+        calcAdaptiveQuantFrame(frame);
+    return true;
+fail:
+   x265_log(m_param, X265_LOG_ERROR, "Incomplete CU-tree stats file.\n" );
+    return false;
+}
+
 double RateControl::rateEstimateQscale(Frame* pic, RateControlEntry *rce)
 {
     double q;
diff -r fb653ec12832 -r 98b829645cf9 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Thu Jul 17 18:28:42 2014 +0530
+++ b/source/encoder/ratecontrol.h	Fri Jul 18 11:01:33 2014 +0530
@@ -181,6 +181,7 @@
     bool init(const TComSPS* sps);
     void initHRD(TComSPS* sps);
     int rateControlSliceType(int frameNum);
+    bool cuTreeReadFor2Pass(Frame* frame);
 protected:
 
     static const double s_amortizeFraction;


More information about the x265-devel mailing list