[x265] [PATCH] rc: compute inter, intra and skip cus per frame for the first pass

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Wed Jul 2 20:03:02 CEST 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1403785166 -19800
#      Thu Jun 26 17:49:26 2014 +0530
# Node ID 97150d9a406f9a40a240fcf6417385bc4b788b00
# Parent  f62d90e934084689c2a13b85f66cb87a074a01a9
rc: compute inter, intra and skip cus per frame for the first pass

diff -r f62d90e93408 -r 97150d9a406f source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Tue Jul 01 14:28:25 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Thu Jun 26 17:49:26 2014 +0530
@@ -343,6 +343,7 @@
                 m_log->totalCu++;
                 part = cu->getDepth(i);
                 int next = numPartition >> (part * 2);
+                m_log->qTreeIntraCnt[part]++;
                 if (part == g_maxCUDepth - 1 && cu->getPartitionSize(i) != SIZE_2Nx2N)
                 {
                     m_log->cntIntraNxN++;
@@ -383,6 +384,7 @@
                 if (cu->isSkipped(i))
                 {
                     m_log->cntSkipCu[part]++;
+                    m_log->qTreeSkipCnt[part]++;
                 }
                 else
                 {
@@ -390,6 +392,7 @@
                     if (cu->getPredictionMode(0) == MODE_INTER)
                     {
                         m_log->cntInter[part]++;
+                        m_log->qTreeInterCnt[part]++;
                         if (cu->getPartitionSize(0) < AMP_ID)
                             m_log->cuInterDistribution[part][cu->getPartitionSize(0)]++;
                         else
@@ -397,6 +400,7 @@
                     }
                     else if (cu->getPredictionMode(0) == MODE_INTRA)
                     {
+                        m_log->qTreeIntraCnt[part]++;
                         if (part == g_maxCUDepth - 1 && cu->getPartitionSize(0) == SIZE_NxN)
                         {
                             m_log->cntIntraNxN++;
diff -r f62d90e93408 -r 97150d9a406f source/Lib/TLibEncoder/TEncCu.h
--- a/source/Lib/TLibEncoder/TEncCu.h	Tue Jul 01 14:28:25 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncCu.h	Thu Jun 26 17:49:26 2014 +0530
@@ -66,6 +66,10 @@
     uint64_t cntTotalCu[4];
     uint64_t totalCu;
 
+    /* These states store the count of inter,intra and skip ctus within quad tree structure of each CU */
+    uint32_t qTreeInterCnt[4];
+    uint32_t qTreeIntraCnt[4];
+    uint32_t qTreeSkipCnt[4];
     StatisticLog()
     {
         memset(this, 0, sizeof(StatisticLog));
diff -r f62d90e93408 -r 97150d9a406f source/encoder/cturow.h
--- a/source/encoder/cturow.h	Tue Jul 01 14:28:25 2014 +0530
+++ b/source/encoder/cturow.h	Thu Jun 26 17:49:26 2014 +0530
@@ -73,6 +73,11 @@
     TEncSbac            ***m_rdSbacCoders;
     TEncBinCABAC        ***m_binCodersCABAC;
 
+    // to compute stats for 2 pass
+    double                 m_iCuCnt;
+    double                 m_pCuCnt;
+    double                 m_skipCuCnt;
+
     bool create();
 
     void destroy();
@@ -94,6 +99,7 @@
 
         m_rdGoOnSbacCoder.setSlice(slice);
         m_rdGoOnSbacCoder.resetEntropy();
+        m_iCuCnt = m_pCuCnt = m_skipCuCnt = 0;
     }
 
     void setThreadLocalData(ThreadLocalData& tld);
diff -r f62d90e93408 -r 97150d9a406f source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Tue Jul 01 14:28:25 2014 +0530
+++ b/source/encoder/frameencoder.cpp	Thu Jun 26 17:49:26 2014 +0530
@@ -538,6 +538,14 @@
     {
         m_rows[i].m_entropyCoder.setEntropyCoder(&m_rows[i].m_sbacCoder, slice);
         m_rows[i].m_entropyCoder.resetEntropy();
+
+        // accumulate intra,inter,skip cu count per frame for 2 pass
+        if (m_param->rc.bStatWrite)
+        {
+            m_frameStats.cuCount_i += m_rows[i].m_iCuCnt;
+            m_frameStats.cuCount_p += m_rows[i].m_pCuCnt;
+            m_frameStats.cuCount_skip += m_rows[i].m_skipCuCnt;
+        }
     }
     encodeSlice(m_outStreams);
 
@@ -744,6 +752,7 @@
     m_ssim = 0;
     m_ssimCnt = 0;
     m_frameFilter.start(m_frame);
+    memset(&m_frameStats, 0, sizeof(m_frameStats));
 
     m_rows[0].m_active = true;
     if (m_pool && m_param->bEnableWavefront)
@@ -912,6 +921,21 @@
         // Completed CU processing
         curRow.m_completed++;
 
+        // copy no. of intra, inter Cu cnt per row into frame stats for 2 pass
+        if (m_param->rc.bStatWrite)
+        {
+            double scale = pow(2, g_maxCUSize / 16);
+            for (int part = 0; part < g_maxCUDepth ; part++, scale /= 4)
+            {
+                curRow.m_iCuCnt += scale * tld.m_cuCoder.m_log->qTreeIntraCnt[part];
+                curRow.m_pCuCnt += scale * tld.m_cuCoder.m_log->qTreeInterCnt[part];
+                curRow.m_skipCuCnt += scale * tld.m_cuCoder.m_log->qTreeSkipCnt[part];
+
+                //clear the row cu data from thread local object
+                tld.m_cuCoder.m_log->qTreeIntraCnt[part] = tld.m_cuCoder.m_log->qTreeInterCnt[part] = tld.m_cuCoder.m_log->qTreeSkipCnt[part] = 0;
+            }
+        }
+
         if (bIsVbv)
         {
             // Update encoded bits, satdCost, baseQP for each CU
@@ -974,6 +998,7 @@
                         }
 
                         stopRow.m_completed = 0;
+                        stopRow.m_iCuCnt = stopRow.m_pCuCnt = stopRow.m_skipCuCnt = 0;
                         if (m_frame->m_qpaAq)
                             m_frame->m_qpaAq[r] = 0;
                         m_frame->m_qpaRc[r] = 0;
@@ -1040,6 +1065,7 @@
             enableRowFilter(i);
         }
     }
+
     m_totalTime += x265_mdate() - startTime;
     curRow.m_busy = false;
 }
diff -r f62d90e93408 -r 97150d9a406f source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h	Tue Jul 01 14:28:25 2014 +0530
+++ b/source/encoder/frameencoder.h	Thu Jun 26 17:49:26 2014 +0530
@@ -63,9 +63,9 @@
     int         coeffBits;
     int         miscBits;
     /* CU type counts */
-    int         cuCount_i;
-    int         cuCount_p;
-    int         cuCount_skip;
+    double      cuCount_i;
+    double      cuCount_p;
+    double      cuCount_skip;
 };
 
 // Manages the wave-front processing of a single encoding frame


More information about the x265-devel mailing list