Re: [x265] [PATCH 2 of 2] pass TLD into class FrameFilter

2014-06-25 Thread Deepthi Nandakumar
On Tue, Jun 24, 2014 at 5:36 AM, Min Chen chenm...@163.com wrote:

 # HG changeset patch
 # User Min Chen chenm...@163.com
 # Date 1403568362 25200
 # Node ID efa48bc0245bded1418db3c42b042acb9969146c
 # Parent  12c1d8aaa8f56a8f2de74c8ff1451d99d04c817d
 pass TLD into class FrameFilter

 diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/cturow.h
 --- a/source/encoder/cturow.h   Mon Jun 23 17:03:49 2014 -0700
 +++ b/source/encoder/cturow.h   Mon Jun 23 17:06:02 2014 -0700
 @@ -47,6 +47,10 @@
  RDCost  m_rdCost;
  TComTrQuant m_trQuant;

 +// NOTE: the maximum LCU 64x64 have 256 partitions
 +boolm_edgeFilter[256];
 +uint8_t m_blockingStrength[256];
 +
  void init(Encoder);
  ~ThreadLocalData();
  };
 diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/encoder.cpp
 --- a/source/encoder/encoder.cppMon Jun 23 17:03:49 2014 -0700
 +++ b/source/encoder/encoder.cppMon Jun 23 17:06:02 2014 -0700
 @@ -42,6 +42,7 @@
  #include x265.h

  using namespace x265;
 +ThreadLocalData* Encoder::m_threadLocalData;

  Encoder::Encoder()
  {
 @@ -194,9 +195,10 @@
  if (m_frameEncoder)
  {
  int numRows = (m_param-sourceHeight + g_maxCUSize - 1) /
 g_maxCUSize;
 +int numCols = (m_param-sourceWidth  + g_maxCUSize - 1) /
 g_maxCUSize;
  for (int i = 0; i  m_param-frameNumThreads; i++)
  {
 -if (!m_frameEncoder[i].init(this, numRows))
 +if (!m_frameEncoder[i].init(this, numRows, numCols))
  {
  x265_log(m_param, X265_LOG_ERROR, Unable to initialize
 frame encoder, aborting\n);
  m_aborted = true;
 diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/encoder.h
 --- a/source/encoder/encoder.h  Mon Jun 23 17:03:49 2014 -0700
 +++ b/source/encoder/encoder.h  Mon Jun 23 17:06:02 2014 -0700
 @@ -175,7 +175,7 @@

  x265_param*m_param;
  RateControl*   m_rateControl;
 -ThreadLocalData*   m_threadLocalData;
 +static ThreadLocalData*   m_threadLocalData;

  bool   m_bEnableRDOQ;

 diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/frameencoder.cpp
 --- a/source/encoder/frameencoder.cpp   Mon Jun 23 17:03:49 2014 -0700
 +++ b/source/encoder/frameencoder.cpp   Mon Jun 23 17:06:02 2014 -0700
 @@ -80,15 +80,17 @@
  stop();
  }

 -bool FrameEncoder::init(Encoder *top, int numRows)
 +bool FrameEncoder::init(Encoder *top, int numRows, int numCols)
  {
  bool ok = true;

  m_top = top;
  m_param = top-m_param;
  m_numRows = numRows;
 +m_numCols = numCols;
  m_filterRowDelay = (m_param-saoLcuBasedOptimization 
 m_param-saoLcuBoundary) ?
  2 : (m_param-bEnableSAO || m_param-bEnableLoopFilter ? 1 : 0);
 +m_filterRowDelayCus = m_filterRowDelay * numCols;

  m_rows = new CTURow[m_numRows];
  for (int i = 0; i  m_numRows; ++i)
 @@ -505,7 +507,7 @@
  // Extend border after whole-frame SAO is finished
  for (int row = 0; row  m_numRows; row++)
  {
 -m_frameFilter.processRowPost(row);
 +m_frameFilter.processRowPost(row, 0);
  }
  }

 @@ -845,7 +847,7 @@
  }

  // setup thread-local data
 -ThreadLocalData tld = threadId = 0 ?
 m_top-m_threadLocalData[threadId] : m_tld;
 +ThreadLocalData tld = threadId = 0 ?
 Encoder::m_threadLocalData[threadId] : m_tld;
  tld.m_trQuant.m_nr = m_nr;
  tld.m_search.m_mref = m_mref;
  codeRow.setThreadLocalData(tld);
 @@ -856,7 +858,8 @@
  tld.m_cuCoder.m_log =
 tld.m_cuCoder.m_sliceTypeLog[m_frame-getSlice()-getSliceType()];

  int64_t startTime = x265_mdate();
 -const uint32_t numCols = m_frame-getPicSym()-getFrameWidthInCU();
 +assert(m_frame-getPicSym()-getFrameWidthInCU() == m_numCols);
 +const uint32_t numCols = m_numCols;
  const uint32_t lineStartCUAddr = row * numCols;
  bool bIsVbv = m_param-rc.vbvBufferSize  0 
 m_param-rc.vbvMaxBitrate  0;

 diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/frameencoder.h
 --- a/source/encoder/frameencoder.h Mon Jun 23 17:03:49 2014 -0700
 +++ b/source/encoder/frameencoder.h Mon Jun 23 17:06:02 2014 -0700
 @@ -65,15 +65,15 @@

  void setThreadPool(ThreadPool *p);

 -bool init(Encoder *top, int numRows);
 +bool init(Encoder *top, int numRows, int numCols);

  void destroy();

  void processRowEncoder(int row, const int threadId);

 -void processRowFilter(int row)
 +void processRowFilter(int row, const int threadId)
  {
 -m_frameFilter.processRow(row);
 +m_frameFilter.processRow(row, threadId);
  }

  void enqueueRowEncoder(int row)
 @@ -108,7 +108,7 @@
  }
  else
  {
 -processRowFilter(realRow);
 +processRowFilter(realRow, threadId);

  // NOTE: Active next row
  if (realRow != m_numRows - 1)
 @@ -154,6 +154,7 @@
  bool 

[x265] [PATCH 2 of 2] pass TLD into class FrameFilter

2014-06-23 Thread Min Chen
# HG changeset patch
# User Min Chen chenm...@163.com
# Date 1403568362 25200
# Node ID efa48bc0245bded1418db3c42b042acb9969146c
# Parent  12c1d8aaa8f56a8f2de74c8ff1451d99d04c817d
pass TLD into class FrameFilter

diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/cturow.h
--- a/source/encoder/cturow.h   Mon Jun 23 17:03:49 2014 -0700
+++ b/source/encoder/cturow.h   Mon Jun 23 17:06:02 2014 -0700
@@ -47,6 +47,10 @@
 RDCost  m_rdCost;
 TComTrQuant m_trQuant;
 
+// NOTE: the maximum LCU 64x64 have 256 partitions
+boolm_edgeFilter[256];
+uint8_t m_blockingStrength[256];
+
 void init(Encoder);
 ~ThreadLocalData();
 };
diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppMon Jun 23 17:03:49 2014 -0700
+++ b/source/encoder/encoder.cppMon Jun 23 17:06:02 2014 -0700
@@ -42,6 +42,7 @@
 #include x265.h
 
 using namespace x265;
+ThreadLocalData* Encoder::m_threadLocalData;
 
 Encoder::Encoder()
 {
@@ -194,9 +195,10 @@
 if (m_frameEncoder)
 {
 int numRows = (m_param-sourceHeight + g_maxCUSize - 1) / g_maxCUSize;
+int numCols = (m_param-sourceWidth  + g_maxCUSize - 1) / g_maxCUSize;
 for (int i = 0; i  m_param-frameNumThreads; i++)
 {
-if (!m_frameEncoder[i].init(this, numRows))
+if (!m_frameEncoder[i].init(this, numRows, numCols))
 {
 x265_log(m_param, X265_LOG_ERROR, Unable to initialize frame 
encoder, aborting\n);
 m_aborted = true;
diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/encoder.h
--- a/source/encoder/encoder.h  Mon Jun 23 17:03:49 2014 -0700
+++ b/source/encoder/encoder.h  Mon Jun 23 17:06:02 2014 -0700
@@ -175,7 +175,7 @@
 
 x265_param*m_param;
 RateControl*   m_rateControl;
-ThreadLocalData*   m_threadLocalData;
+static ThreadLocalData*   m_threadLocalData;
 
 bool   m_bEnableRDOQ;
 
diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp   Mon Jun 23 17:03:49 2014 -0700
+++ b/source/encoder/frameencoder.cpp   Mon Jun 23 17:06:02 2014 -0700
@@ -80,15 +80,17 @@
 stop();
 }
 
-bool FrameEncoder::init(Encoder *top, int numRows)
+bool FrameEncoder::init(Encoder *top, int numRows, int numCols)
 {
 bool ok = true;
 
 m_top = top;
 m_param = top-m_param;
 m_numRows = numRows;
+m_numCols = numCols;
 m_filterRowDelay = (m_param-saoLcuBasedOptimization  
m_param-saoLcuBoundary) ?
 2 : (m_param-bEnableSAO || m_param-bEnableLoopFilter ? 1 : 0);
+m_filterRowDelayCus = m_filterRowDelay * numCols;
 
 m_rows = new CTURow[m_numRows];
 for (int i = 0; i  m_numRows; ++i)
@@ -505,7 +507,7 @@
 // Extend border after whole-frame SAO is finished
 for (int row = 0; row  m_numRows; row++)
 {
-m_frameFilter.processRowPost(row);
+m_frameFilter.processRowPost(row, 0);
 }
 }
 
@@ -845,7 +847,7 @@
 }
 
 // setup thread-local data
-ThreadLocalData tld = threadId = 0 ? m_top-m_threadLocalData[threadId] 
: m_tld;
+ThreadLocalData tld = threadId = 0 ? 
Encoder::m_threadLocalData[threadId] : m_tld;
 tld.m_trQuant.m_nr = m_nr;
 tld.m_search.m_mref = m_mref;
 codeRow.setThreadLocalData(tld);
@@ -856,7 +858,8 @@
 tld.m_cuCoder.m_log = 
tld.m_cuCoder.m_sliceTypeLog[m_frame-getSlice()-getSliceType()];
 
 int64_t startTime = x265_mdate();
-const uint32_t numCols = m_frame-getPicSym()-getFrameWidthInCU();
+assert(m_frame-getPicSym()-getFrameWidthInCU() == m_numCols);
+const uint32_t numCols = m_numCols;
 const uint32_t lineStartCUAddr = row * numCols;
 bool bIsVbv = m_param-rc.vbvBufferSize  0  m_param-rc.vbvMaxBitrate  
0;
 
diff -r 12c1d8aaa8f5 -r efa48bc0245b source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h Mon Jun 23 17:03:49 2014 -0700
+++ b/source/encoder/frameencoder.h Mon Jun 23 17:06:02 2014 -0700
@@ -65,15 +65,15 @@
 
 void setThreadPool(ThreadPool *p);
 
-bool init(Encoder *top, int numRows);
+bool init(Encoder *top, int numRows, int numCols);
 
 void destroy();
 
 void processRowEncoder(int row, const int threadId);
 
-void processRowFilter(int row)
+void processRowFilter(int row, const int threadId)
 {
-m_frameFilter.processRow(row);
+m_frameFilter.processRow(row, threadId);
 }
 
 void enqueueRowEncoder(int row)
@@ -108,7 +108,7 @@
 }
 else
 {
-processRowFilter(realRow);
+processRowFilter(realRow, threadId);
 
 // NOTE: Active next row
 if (realRow != m_numRows - 1)
@@ -154,6 +154,7 @@
 bool m_threadActive;
 
 int  m_numRows;
+uint32_t m_numCols;
 CTURow*  m_rows;
 TComSPS  m_sps;