[x265] [PATCH 2 of 6] framepp: simplify FrameFilter control logic

Min Chen chenm003 at 163.com
Tue Aug 20 08:18:40 CEST 2013


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1376979230 -28800
# Node ID 3f9e6edef9a5e662646904002f3dc860bd5a988c
# Parent  942d33e2d30dc5328f6394308839cd384b97065d
framepp: simplify FrameFilter control logic

diff -r 942d33e2d30d -r 3f9e6edef9a5 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Tue Aug 20 14:13:33 2013 +0800
+++ b/source/encoder/frameencoder.cpp	Tue Aug 20 14:13:50 2013 +0800
@@ -978,6 +978,7 @@
     // this row of CTUs has been encoded
     if (row == m_numRows - 1)
     {
+        m_frameFilter.enqueueRow(row);
         m_completionEvent.trigger();
     }
 }
diff -r 942d33e2d30d -r 3f9e6edef9a5 source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp	Tue Aug 20 14:13:33 2013 +0800
+++ b/source/encoder/framefilter.cpp	Tue Aug 20 14:13:50 2013 +0800
@@ -33,10 +33,9 @@
 // * LoopFilter
 // **************************************************************************
 FrameFilter::FrameFilter(ThreadPool* pool)
-    : WaveFront(pool)
+    : JobProvider(pool)
     , m_cfg(NULL)
     , m_pic(NULL)
-    , m_lft_active(false)
     , m_sao(NULL)
 {}
 
@@ -59,6 +58,21 @@
     }
 }
 
+bool FrameFilter::findJob()
+{
+    ScopedLock self(m_lock);
+
+    // NOTE: only one thread can be here
+    if (row_done < row_ready)
+    {
+        // NOTE: not need atom operator here because we lock before
+        row_done++;
+        processRow(row_done);
+        return true;
+    }
+    return false;
+}
+
 void FrameFilter::init(TEncTop *top, int numRows)
 {
     m_cfg = top;
@@ -77,12 +91,6 @@
             m_sao[i].createEncBuffer();
         }
     }
-
-    if (!WaveFront::init(m_numRows))
-    {
-        assert(!"Unable to initialize job queue.");
-        m_pool = NULL;
-    }
 }
 
 void FrameFilter::start(TComPic *pic)
@@ -90,7 +98,8 @@
     m_pic = pic;
 
     m_loopFilter.setCfg(pic->getSlice()->getPPS()->getLoopFilterAcrossTilesEnabledFlag());
-    m_lft_active = false;
+    row_ready = -1;
+    row_done = -1;
     for (int i = 0; i < m_numRows; i++)
     {
         if (m_cfg->param.bEnableLoopFilter)
@@ -103,7 +112,7 @@
 
     if (m_cfg->param.bEnableLoopFilter && m_pool && m_cfg->param.bEnableWavefront)
     {
-        WaveFront::enqueue();
+        JobProvider::enqueue();
     }
 }
 
@@ -111,7 +120,7 @@
 {
     // Block until worker threads complete the frame
     m_completionEvent.wait();
-    WaveFront::dequeue();
+    JobProvider::dequeue();
 }
 
 void FrameFilter::end()
@@ -127,12 +136,10 @@
 
 void FrameFilter::enqueueRow(int row)
 {
-    ScopedLock self(m_lock);
-
-    if (!m_lft_active)
-    {
-        WaveFront::enqueueRow(row);
-    }
+    assert(row < m_numRows);
+    // NOTE: not need atom here since we have only one writer and reader
+    row_ready = row;
+    m_pool->pokeIdleThread();
 }
 
 void FrameFilter::processRow(int row)
@@ -144,13 +151,6 @@
     const uint32_t numCols = m_pic->getPicSym()->getFrameWidthInCU();
     const uint32_t lineStartCUAddr = row * numCols;
 
-    {
-        ScopedLock self(m_lock);
-        if (m_lft_active)
-            return;
-        m_lft_active = true;
-    }
-
     // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
     if (m_cfg->param.saoLcuBasedOptimization && m_cfg->param.saoLcuBoundary)
     {
@@ -180,23 +180,6 @@
         m_loopFilter.loopFilterCU(cu_prev, EDGE_HOR);
     }
 
-    // Active next row when possible
-    ScopedLock self(m_lock);
-    m_lft_active = false;
-    if (row + 2 < m_numRows)
-    {
-        if (m_pic->m_complete_enc[row + 2] == numCols)
-        {
-            WaveFront::enqueueRow(row + 1);
-        }
-    }
-
-    // Active last row
-    if (row == m_numRows - 2)
-    {
-        WaveFront::enqueueRow(row + 1);
-    }
-
     // this row of CTUs has been encoded
     if (row == m_numRows - 1)
     {
diff -r 942d33e2d30d -r 3f9e6edef9a5 source/encoder/framefilter.h
--- a/source/encoder/framefilter.h	Tue Aug 20 14:13:33 2013 +0800
+++ b/source/encoder/framefilter.h	Tue Aug 20 14:13:50 2013 +0800
@@ -40,7 +40,7 @@
 class ThreadPool;
 
 // Manages the wave-front processing of a single frame loopfilter
-class FrameFilter : public WaveFront
+class FrameFilter : public JobProvider
 {
 public:
 
@@ -58,6 +58,7 @@
     void wait();
 
     void enqueueRow(int row);
+    bool findJob();
 
     void processRow(int row);
 
@@ -65,7 +66,6 @@
 
     TEncCfg*            m_cfg;
     TComPic*            m_pic;
-    volatile bool       m_lft_active;
     Lock                m_lock;
 
 public:
@@ -73,6 +73,11 @@
     TComLoopFilter              m_loopFilter;
     TEncSampleAdaptiveOffset*   m_sao;
     int                         m_numRows;
+
+    // TODO: if you want thread priority logic, add col here
+    volatile int                row_ready;
+    volatile int                row_done;
+
     Event                       m_completionEvent;
 };
 



More information about the x265-devel mailing list