[x265] [PATCH 24 of 24] sao: correct counter control logic on m_lastDeblocked & fix bug in lossless mode on latest row

Min Chen chenm003 at 163.com
Tue Dec 8 00:55:01 CET 2015


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1449532442 21600
# Node ID bc3da6a276cc043ca8034d7ff00dcafb9dcd17d4
# Parent  a2d20844f461fcd91c1bd966f59b6cfb08358e33
sao: correct counter control logic on m_lastDeblocked & fix bug in lossless mode on latest row
---
 source/encoder/frameencoder.cpp |   15 ++++++---------
 source/encoder/framefilter.cpp  |   13 ++++++++-----
 2 files changed, 14 insertions(+), 14 deletions(-)

diff -r a2d20844f461 -r bc3da6a276cc source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Mon Dec 07 12:06:48 2015 -0600
+++ b/source/encoder/frameencoder.cpp	Mon Dec 07 17:54:02 2015 -0600
@@ -1205,7 +1205,7 @@
         if (row >= 2)
         {
             int prevCol = m_frameFilter.m_parallelFilter[row - 2].m_lastDeblocked.get();
-            while(prevCol != (int)numCols - 1)
+            while(prevCol != (int)numCols)
                 prevCol = m_frameFilter.m_parallelFilter[row - 2].m_lastDeblocked.waitForChange(prevCol);
         }
         m_frameFilter.m_parallelFilter[row - 1].waitForExit();
@@ -1219,14 +1219,14 @@
         /* TODO: Early start last row */
         if (m_param->bEnableLoopFilter | m_param->bEnableSAO)
         {
-            if (m_frameFilter.m_parallelFilter[row - 1].m_lastDeblocked.get() != (int)numCols - 1)
+            if (m_frameFilter.m_parallelFilter[row - 1].m_lastDeblocked.get() != (int)numCols)
                 x265_log(m_param, X265_LOG_WARNING, "detected ParallelFilter race condition on last row\n");
 
             // avoid race on last row and last column
             if (row >= 1)
             {
                 int prevCol = m_frameFilter.m_parallelFilter[row - 1].m_lastDeblocked.get();
-                while(prevCol != (int)numCols - 1)
+                while(prevCol != (int)numCols)
                     prevCol = m_frameFilter.m_parallelFilter[row - 1].m_lastDeblocked.waitForChange(prevCol);
             }
 
@@ -1235,18 +1235,15 @@
             m_frameFilter.m_parallelFilter[row].m_allowedCol.set(numCols);
             m_frameFilter.m_parallelFilter[row].processTasks(-1);
 
-            /* Apply SAO on last row of CUs */
+            /* Apply SAO on last row of CUs, because we always apply SAO on row[X-1] */
             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);
+                    // NOTE: must use processSaoUnitCu(), it include TQBypass logic
+                    m_frameFilter.m_parallelFilter[row].processSaoUnitCu(saoParam, col);
                 }
             }
         }
diff -r a2d20844f461 -r bc3da6a276cc source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp	Mon Dec 07 12:06:48 2015 -0600
+++ b/source/encoder/framefilter.cpp	Mon Dec 07 17:54:02 2015 -0600
@@ -134,8 +134,8 @@
 /* restore original YUV samples to recon after SAO (if lossless) */
 static void restoreOrigLosslessYuv(const CUData* cu, Frame& frame, uint32_t absPartIdx)
 {
-    int size = cu->m_log2CUSize[absPartIdx] - 2;
-    uint32_t cuAddr = cu->m_cuAddr;
+    const int size = cu->m_log2CUSize[absPartIdx] - 2;
+    const uint32_t cuAddr = cu->m_cuAddr;
 
     PicYuv* reconPic = frame.m_reconPic;
     PicYuv* fencPic  = frame.m_fencPic;
@@ -151,7 +151,7 @@
     pixel* dstCr = reconPic->getCrAddr(cuAddr, absPartIdx);
     pixel* srcCr = fencPic->getCrAddr(cuAddr, absPartIdx);
 
-    int csp = fencPic->m_picCsp;
+    const int csp = fencPic->m_picCsp;
     primitives.chroma[csp].cu[size].copy_pp(dstCb, reconPic->m_strideC, srcCb, fencPic->m_strideC);
     primitives.chroma[csp].cu[size].copy_pp(dstCr, reconPic->m_strideC, srcCr, fencPic->m_strideC);
 }
@@ -213,6 +213,7 @@
 
         uint32_t cuAddr = m_rowAddr + col;
         const CUData* ctu = m_encData->getPicCTU(cuAddr);
+        assert(m_frameEncoder->m_frame->m_reconPic == m_encData->m_reconPic);
         origCUSampleRestoration(ctu, cuGeoms[ctuGeomMap[cuAddr]], *m_frameEncoder->m_frame);
     }
 }
@@ -272,7 +273,7 @@
                 }
             }
 
-            m_lastDeblocked.set(col - 1);
+            m_lastDeblocked.set(col);
         }
         m_lastCol.incr();
     }
@@ -303,12 +304,14 @@
             // Process Previous Rows SAO CU
             if (m_row >= 1 && numCols >= 3)
                 m_prevRow->processSaoUnitCu(saoParam, numCols - 3);
+
             if (m_row >= 1 && numCols >= 2)
                 m_prevRow->processSaoUnitCu(saoParam, numCols - 2);
+
             if (m_row >= 1 && numCols >= 1)
                 m_prevRow->processSaoUnitCu(saoParam, numCols - 1);
         }
-        m_lastDeblocked.set(numCols - 1);
+        m_lastDeblocked.set(numCols);
     }
 }
 



More information about the x265-devel mailing list