[x265] [PATCH] encoder: fix --no-wpp behavior, keep TLD selection logic in one place
Steve Borho
steve at borho.org
Wed Jul 2 20:05:09 CEST 2014
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1404281950 18000
# Wed Jul 02 01:19:10 2014 -0500
# Node ID 0743791a8245aacf4868f5a94ab04ab5aaba2d7a
# Parent 99b8e4d69e0fa63cc7403dba371c6a0f24fb127d
encoder: fix --no-wpp behavior, keep TLD selection logic in one place
do not use static m_threadLocalData, this would break if multiple encoders were
allocated in a single process
pass the selected TLD to row processes, so they do not need to be aware of the
WPP/NO-WPP details.
Cleanup frameencoder.h, move non-trivial processRow() to the cpp file
diff -r 99b8e4d69e0f -r 0743791a8245 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Tue Jul 01 17:47:28 2014 -0500
+++ b/source/encoder/encoder.cpp Wed Jul 02 01:19:10 2014 -0500
@@ -42,7 +42,6 @@
#include "x265.h"
using namespace x265;
-ThreadLocalData* Encoder::m_threadLocalData;
Encoder::Encoder()
{
diff -r 99b8e4d69e0f -r 0743791a8245 source/encoder/encoder.h
--- a/source/encoder/encoder.h Tue Jul 01 17:47:28 2014 -0500
+++ b/source/encoder/encoder.h Wed Jul 02 01:19:10 2014 -0500
@@ -166,7 +166,7 @@
x265_param* m_param;
RateControl* m_rateControl;
- static ThreadLocalData* m_threadLocalData;
+ ThreadLocalData* m_threadLocalData;
bool m_bEnableRDOQ;
diff -r 99b8e4d69e0f -r 0743791a8245 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp Tue Jul 01 17:47:28 2014 -0500
+++ b/source/encoder/frameencoder.cpp Wed Jul 02 01:19:10 2014 -0500
@@ -507,9 +507,7 @@
// Extend border after whole-frame SAO is finished
for (int row = 0; row < m_numRows; row++)
- {
- m_frameFilter.processRowPost(row, 0);
- }
+ m_frameFilter.processRowPost(row);
}
slice->setSaoEnabledFlag((saoParam->bSaoFlag[0] == 1) ? true : false);
@@ -831,8 +829,29 @@
m_totalTime = 0;
}
+void FrameEncoder::processRow(int row, const int threadId)
+{
+ const int realRow = row >> 1;
+ const int typeNum = row & 1;
+
+ ThreadLocalData& tld = threadId >= 0 ? m_top->m_threadLocalData[threadId] : m_tld;
+
+ if (!typeNum)
+ processRowEncoder(realRow, tld);
+ else
+ {
+ processRowFilter(realRow, tld);
+
+ // NOTE: Active next row
+ if (realRow != m_numRows - 1)
+ enqueueRowFilter(realRow + 1);
+ else
+ m_completionEvent.trigger();
+ }
+}
+
// Called by worker threads
-void FrameEncoder::processRowEncoder(int row, const int threadId)
+void FrameEncoder::processRowEncoder(int row, ThreadLocalData& tld)
{
PPAScopeEvent(Thread_ProcessRow);
@@ -860,7 +879,6 @@
}
// setup thread-local data
- 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);
diff -r 99b8e4d69e0f -r 0743791a8245 source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h Tue Jul 01 17:47:28 2014 -0500
+++ b/source/encoder/frameencoder.h Wed Jul 02 01:19:10 2014 -0500
@@ -69,61 +69,21 @@
void destroy();
- void processRowEncoder(int row, const int threadId);
+ /* Called by WaveFront::findJob() */
+ void processRow(int row, const int threadId);
- void processRowFilter(int row, const int threadId)
- {
- m_frameFilter.processRow(row, threadId);
- }
+ void processRowEncoder(int row, ThreadLocalData& tld);
- void enqueueRowEncoder(int row)
- {
- WaveFront::enqueueRow(row * 2 + 0);
- }
+ void processRowFilter(int row, ThreadLocalData& tld) { m_frameFilter.processRow(row, tld); }
- void enqueueRowFilter(int row)
- {
- WaveFront::enqueueRow(row * 2 + 1);
- }
-
- void enableRowEncoder(int row)
- {
- WaveFront::enableRow(row * 2 + 0);
- }
-
- void enableRowFilter(int row)
- {
- WaveFront::enableRow(row * 2 + 1);
- }
-
- void processRow(int row, int threadId)
- {
- const int realRow = row >> 1;
- const int typeNum = row & 1;
-
- // TODO: use switch when more type
- if (typeNum == 0)
- {
- processRowEncoder(realRow, threadId);
- }
- else
- {
- processRowFilter(realRow, threadId);
-
- // NOTE: Active next row
- if (realRow != m_numRows - 1)
- enqueueRowFilter(realRow + 1);
- else
- m_completionEvent.trigger();
- }
- }
+ void enqueueRowEncoder(int row) { WaveFront::enqueueRow(row * 2 + 0); }
+ void enqueueRowFilter(int row) { WaveFront::enqueueRow(row * 2 + 1); }
+ void enableRowEncoder(int row) { WaveFront::enableRow(row * 2 + 0); }
+ void enableRowFilter(int row) { WaveFront::enableRow(row * 2 + 1); }
TEncEntropy* getEntropyCoder(int row) { return &this->m_rows[row].m_entropyCoder; }
-
TEncSbac* getSbacCoder(int row) { return &this->m_rows[row].m_sbacCoder; }
-
TEncSbac* getRDGoOnSbacCoder(int row) { return &this->m_rows[row].m_rdGoOnSbacCoder; }
-
TEncSbac* getBufferSBac(int row) { return &this->m_rows[row].m_bufferSbacCoder; }
/* Frame singletons, last the life of the encoder */
@@ -139,9 +99,10 @@
/* called by compressFrame to perform wave-front compression analysis */
void compressCTURows();
+ /* called by compressFrame to generate final per-row bitstreams */
void encodeSlice(Bitstream* substreams);
- /* blocks until worker thread is done, returns encoded picture and bitstream */
+ /* blocks until worker thread is done, returns access unit */
Frame *getEncodedPicture(NALList& list);
void setLambda(int qp, ThreadLocalData& tld);
diff -r 99b8e4d69e0f -r 0743791a8245 source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp Tue Jul 01 17:47:28 2014 -0500
+++ b/source/encoder/framefilter.cpp Wed Jul 02 01:19:10 2014 -0500
@@ -121,15 +121,13 @@
}
}
-void FrameFilter::processRow(int row, const int threadId)
+void FrameFilter::processRow(int row, ThreadLocalData& tld)
{
PPAScopeEvent(Thread_filterCU);
- assert(threadId >= 0);
- ThreadLocalData& tld = Encoder::m_threadLocalData[threadId];
if (!m_param->bEnableLoopFilter && !m_param->bEnableSAO)
{
- processRowPost(row, threadId);
+ processRowPost(row);
return;
}
@@ -177,7 +175,7 @@
// NOTE: Delay a row because SAO decide need top row pixels at next row, is it HM's bug?
if (row >= m_saoRowDelay)
{
- processSao(row - m_saoRowDelay, threadId);
+ processSao(row - m_saoRowDelay);
}
}
@@ -189,7 +187,7 @@
if (row > 0)
{
- processRowPost(row - 1, threadId);
+ processRowPost(row - 1);
}
if (row == m_numRows - 1)
@@ -200,15 +198,15 @@
for (int i = m_numRows - m_saoRowDelay; i < m_numRows; i++)
{
- processSao(i, threadId);
+ processSao(i);
}
}
- processRowPost(row, threadId);
+ processRowPost(row);
}
}
-void FrameFilter::processRowPost(int row, const int /*threadId*/)
+void FrameFilter::processRowPost(int row)
{
const uint32_t numCols = m_pic->getPicSym()->getFrameWidthInCU();
const uint32_t lineStartCUAddr = row * numCols;
@@ -501,7 +499,7 @@
return ssim;
}
-void FrameFilter::processSao(int row, const int /*threadId*/)
+void FrameFilter::processSao(int row)
{
const uint32_t numCols = m_pic->getPicSym()->getFrameWidthInCU();
const uint32_t lineStartCUAddr = row * numCols;
diff -r 99b8e4d69e0f -r 0743791a8245 source/encoder/framefilter.h
--- a/source/encoder/framefilter.h Tue Jul 01 17:47:28 2014 -0500
+++ b/source/encoder/framefilter.h Wed Jul 02 01:19:10 2014 -0500
@@ -50,9 +50,9 @@
void start(Frame *pic);
- void processRow(int row, const int threadId);
- void processRowPost(int row, const int threadId);
- void processSao(int row, const int threadId);
+ void processRow(int row, ThreadLocalData& tld);
+ void processRowPost(int row);
+ void processSao(int row);
protected:
More information about the x265-devel
mailing list