[x265] [PATCH 21 of 24] sao: move sao apply function into encode loop

Min Chen chenm003 at 163.com
Tue Dec 8 00:54:58 CET 2015


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1449511603 21600
# Node ID 64cc11dff87ca95418e8812acdfe69ed3f93006f
# Parent  690f1e3baab270884b3f00bd56006738ad4a5314
sao: move sao apply function into encode loop
---
 source/encoder/frameencoder.cpp |   15 +++++++++++
 source/encoder/framefilter.cpp  |   51 +++++++++++++++++++++++++++++++-------
 source/encoder/framefilter.h    |    7 ++++-
 3 files changed, 62 insertions(+), 11 deletions(-)

diff -r 690f1e3baab2 -r 64cc11dff87c source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Mon Dec 07 12:06:41 2015 -0600
+++ b/source/encoder/frameencoder.cpp	Mon Dec 07 12:06:43 2015 -0600
@@ -1234,6 +1234,21 @@
             m_frameFilter.m_parallelFilter[row].waitForExit();
             m_frameFilter.m_parallelFilter[row].m_allowedCol.set(numCols);
             m_frameFilter.m_parallelFilter[row].processTasks(-1);
+
+            /* Apply SAO on last row of CUs */
+            if (m_param->bEnableSAO)
+            {
+                FrameData* encData = m_frameFilter.m_parallelFilter[row].m_encData;
+                SAOParam* saoParam = encData->m_saoParam;
+                for(uint32_t col = 0; col < numCols; col++)
+                {
+                    if (saoParam->bSaoFlag[0])
+                        m_frameFilter.m_parallelFilter[row].m_sao.processSaoUnitCuLuma(saoParam->ctuParam[0], row, col);
+
+                    if (saoParam->bSaoFlag[1])
+                        m_frameFilter.m_parallelFilter[row].m_sao.processSaoUnitCuChroma(saoParam->ctuParam, row, col);
+                }
+            }
         }
     }
 
diff -r 690f1e3baab2 -r 64cc11dff87c source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp	Mon Dec 07 12:06:41 2015 -0600
+++ b/source/encoder/framefilter.cpp	Mon Dec 07 12:06:43 2015 -0600
@@ -36,6 +36,7 @@
 static float calculateSSIM(pixel *pix1, intptr_t stride1, pixel *pix2, intptr_t stride2, uint32_t width, uint32_t height, void *buf, uint32_t& cnt);
 
 uint32_t FrameFilter::ParallelFilter::numCols = 0;
+uint32_t FrameFilter::ParallelFilter::numRows = 0;
 
 void FrameFilter::destroy()
 {
@@ -92,13 +93,18 @@
         for(int row = 0; row < numRows; row++)
         {
             m_parallelFilter[row].m_param = m_param;
+            m_parallelFilter[row].m_row = row;
             m_parallelFilter[row].m_rowAddr = row * numCols;
             m_parallelFilter[row].m_frameEncoder = m_frameEncoder;
+
+            if (row > 0)
+                m_parallelFilter[row].m_prevRow = &m_parallelFilter[row - 1];
         }
     }
 
     // Setting maximum columns
     ParallelFilter::numCols = numCols;
+    ParallelFilter::numRows = numRows;
 }
 
 void FrameFilter::start(Frame *frame, Entropy& initState, int qp)
@@ -192,6 +198,16 @@
                     //       ..S H V |
                     m_sao.rdoSaoUnitCu(saoParam, m_rowAddr, col - 2, cuAddr - 2);
                 }
+
+                // Process Previous Row SAO CU
+                if (m_row >= 1 && col >= 3)
+                {
+                    if (saoParam->bSaoFlag[0])
+                        m_prevRow->m_sao.processSaoUnitCuLuma(saoParam->ctuParam[0], m_row - 1, col - 3);
+
+                    if (saoParam->bSaoFlag[1])
+                        m_prevRow->m_sao.processSaoUnitCuChroma(saoParam->ctuParam, m_row - 1, col - 3);
+                }
             }
 
             m_lastDeblocked.set(col - 1);
@@ -221,6 +237,31 @@
 
             if (numCols >= 1)
                 m_sao.rdoSaoUnitCu(saoParam, m_rowAddr, numCols - 1, cuAddr);
+
+            // Process Previous Row SAO CU
+            if (saoParam->bSaoFlag[0])
+            {
+                if (m_row >= 1 && numCols >= 3)
+                    m_prevRow->m_sao.processSaoUnitCuLuma(saoParam->ctuParam[0], m_row - 1, numCols - 3);
+
+                if (m_row >= 1 && numCols >= 2)
+                    m_prevRow->m_sao.processSaoUnitCuLuma(saoParam->ctuParam[0], m_row - 1, numCols - 2);
+
+                if (m_row >= 1 && numCols >= 1)
+                    m_prevRow->m_sao.processSaoUnitCuLuma(saoParam->ctuParam[0], m_row - 1, numCols - 1);
+            }
+
+            if (saoParam->bSaoFlag[1])
+            {
+                if (m_row >= 1 && numCols >= 3)
+                    m_prevRow->m_sao.processSaoUnitCuChroma(saoParam->ctuParam, m_row - 1, numCols - 3);
+
+                if (m_row >= 1 && numCols >= 2)
+                    m_prevRow->m_sao.processSaoUnitCuChroma(saoParam->ctuParam, m_row - 1, numCols - 2);
+
+                if (m_row >= 1 && numCols >= 1)
+                    m_prevRow->m_sao.processSaoUnitCuChroma(saoParam->ctuParam, m_row - 1, numCols - 1);
+            }
         }
         m_lastDeblocked.set(numCols - 1);
     }
@@ -573,18 +614,8 @@
 void FrameFilter::processSao(int row)
 {
     FrameData& encData = *m_frame->m_encData;
-    SAOParam* saoParam = encData.m_saoParam;
     uint32_t numCols = encData.m_slice->m_sps->numCuInWidth;
 
-    for(uint32_t col = 0; col < numCols; col++)
-    {
-        if (saoParam->bSaoFlag[0])
-            m_parallelFilter[row].m_sao.processSaoUnitCuLuma(saoParam->ctuParam[0], row, col);
-
-        if (saoParam->bSaoFlag[1])
-            m_parallelFilter[row].m_sao.processSaoUnitCuChroma(saoParam->ctuParam, row, col);
-    }
-
     if (encData.m_slice->m_pps->bTransquantBypassEnabled)
     {
         uint32_t lineStartCUAddr = row * numCols;
diff -r 690f1e3baab2 -r 64cc11dff87c source/encoder/framefilter.h
--- a/source/encoder/framefilter.h	Mon Dec 07 12:06:41 2015 -0600
+++ b/source/encoder/framefilter.h	Mon Dec 07 12:06:43 2015 -0600
@@ -62,20 +62,25 @@
     {
     public:
         static uint32_t     numCols;
+        static uint32_t     numRows;
+        uint32_t            m_row;
         uint32_t            m_rowAddr;
         x265_param*         m_param;
         FrameEncoder*       m_frameEncoder;
         FrameData*          m_encData;
+        ParallelFilter*     m_prevRow;
         SAO                 m_sao;
         ThreadSafeInteger   m_lastCol;          /* The column that next to process */
         ThreadSafeInteger   m_allowedCol;       /* The column that processed from Encode pipeline */
         ThreadSafeInteger   m_lastDeblocked;   /* The column that finished all of Deblock stages  */
 
         ParallelFilter()
-            : m_rowAddr(0)
+            : m_row(0)
+            , m_rowAddr(0)
             , m_param(NULL)
             , m_frameEncoder(NULL)
             , m_encData(NULL)
+            , m_prevRow(NULL)
         {
         }
 



More information about the x265-devel mailing list