ref: beacba76e33841be0b26013a735081a8b8f54407
parent: 1a2606f45d36c7ae030826c4e0859052c5d9486b
parent: ee27d132629fc449a068bd5f11767f5109efb250
author: HaiboZhu <haibozhu@cisco.com>
date: Thu Nov 12 08:54:49 EST 2015
Merge pull request #2220 from sijchen/thp61 [Encoder] add preencodingtasklist in task management
--- a/codec/encoder/core/inc/wels_task_base.h
+++ b/codec/encoder/core/inc/wels_task_base.h
@@ -50,10 +50,14 @@
class CWelsBaseTask : public WelsCommon::IWelsTask {
public:
- enum {
- WELS_ENC_TASK_ENCODE_FIXED_SLICE = 0,
- WELS_ENC_TASK_ENCODE_SLICE_LOADBALANCING = 1,
- WELS_ENC_TASK_ENCODE_SLICE_SIZECONSTRAINED = 2,
+ enum ETaskType {
+ WELS_ENC_TASK_ENCODING = 0,
+ WELS_ENC_TASK_ENCODE_FIXED_SLICE = WELS_ENC_TASK_ENCODING,
+ WELS_ENC_TASK_ENCODE_SLICE_LOADBALANCING = WELS_ENC_TASK_ENCODING,
+ WELS_ENC_TASK_ENCODE_SLICE_SIZECONSTRAINED = WELS_ENC_TASK_ENCODING,
+ WELS_ENC_TASK_PREENCODING = 1,
+ WELS_ENC_TASK_PREPROCESS = 2,
+ WELS_ENC_TASK_ALL = 3,
};
CWelsBaseTask();
--- a/codec/encoder/core/inc/wels_task_encoder.h
+++ b/codec/encoder/core/inc/wels_task_encoder.h
@@ -122,6 +122,20 @@
};
*/
+class CWelsUpdateMbMapTask : public CWelsBaseTask {
+ public:
+ CWelsUpdateMbMapTask (sWelsEncCtx* pCtx, const int32_t iSliceIdx);
+ virtual ~CWelsUpdateMbMapTask();
+
+ virtual WelsErrorType Execute();
+
+ virtual uint32_t GetTaskType() const {
+ return WELS_ENC_TASK_PREENCODING;
+ }
+ protected:
+ sWelsEncCtx* m_pCtx;
+ int32_t m_iSliceIdx;
+};
} //namespace
#endif //header guard
--- a/codec/encoder/core/inc/wels_task_management.h
+++ b/codec/encoder/core/inc/wels_task_management.h
@@ -44,11 +44,10 @@
#include "wels_common_basis.h"
#include "WelsLock.h"
#include "WelsThreadPool.h"
+#include "wels_task_base.h"
namespace WelsEnc {
-class CWelsBaseTask;
-
class IWelsTaskManage {
public:
virtual ~IWelsTaskManage() { }
@@ -57,7 +56,7 @@
virtual void Uninit() = 0;
virtual void InitFrame (const int32_t kiCurDid) {}
- virtual WelsErrorType ExecuteTasks() = 0;
+ virtual WelsErrorType ExecuteTasks(const CWelsBaseTask::ETaskType iTaskType = CWelsBaseTask::WELS_ENC_TASK_ENCODING) = 0;
static IWelsTaskManage* CreateTaskManage (sWelsEncCtx* pCtx, bool bNeedLock);
};
@@ -76,7 +75,7 @@
void Uninit();
virtual void InitFrame (const int32_t kiCurDid);
- virtual WelsErrorType ExecuteTasks();
+ virtual WelsErrorType ExecuteTasks(const CWelsBaseTask::ETaskType iTaskType = CWelsBaseTask::WELS_ENC_TASK_ENCODING);
//IWelsThreadPoolSink
virtual WelsErrorType OnTaskExecuted (WelsCommon::IWelsTask* pTask);
@@ -85,12 +84,15 @@
protected:
virtual WelsErrorType CreateTasks (sWelsEncCtx* pEncCtx, const int32_t kiTaskCount);
void DestroyTasks();
+ WelsErrorType ExecuteTaskList(TASKLIST_TYPE* pTargetTaskList);
protected:
sWelsEncCtx* m_pEncCtx;
WelsCommon::CWelsThreadPool* m_pThreadPool;
- TASKLIST_TYPE* m_cTaskList;
+ TASKLIST_TYPE* m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_ALL];
+ TASKLIST_TYPE* m_cEncodingTaskList;
+ TASKLIST_TYPE* m_cPreEncodingTaskList;
int32_t m_iTaskNum;
//SLICE_PAIR_LIST *m_cSliceList;
@@ -113,12 +115,12 @@
virtual ~CWelsTaskManageOne();
WelsErrorType Init (sWelsEncCtx* pEncCtx);
- virtual WelsErrorType ExecuteTasks();
+ virtual WelsErrorType ExecuteTasks(const CWelsBaseTask::ETaskType iTaskType = CWelsBaseTask::WELS_ENC_TASK_ENCODING);
};
class CWelsTaskManageParallel : public CWelsTaskManageBase {
public:
- virtual WelsErrorType ExecuteTasks();
+ virtual WelsErrorType ExecuteTasks(const CWelsBaseTask::ETaskType iTaskType = CWelsBaseTask::WELS_ENC_TASK_ENCODING);
protected:
virtual WelsErrorType CreateTasks (sWelsEncCtx* pEncCtx, const int32_t kiTaskCount);
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -228,6 +228,20 @@
m_pCtx->pCurDqLayer->pSliceEncCtx->pCountMbNumInSlice[m_iSliceIdx]);
}
+
+CWelsUpdateMbMapTask::CWelsUpdateMbMapTask (sWelsEncCtx* pCtx, const int32_t iSliceIdx) {
+ m_pCtx = pCtx;
+ m_iSliceIdx = iSliceIdx;
+}
+
+CWelsUpdateMbMapTask::~CWelsUpdateMbMapTask() {
+}
+
+WelsErrorType CWelsUpdateMbMapTask::Execute() {
+ UpdateMbListNeighborParallel (m_pCtx->pCurDqLayer->pSliceEncCtx, m_pCtx->pCurDqLayer->sMbDataP, m_iSliceIdx);
+ return ENC_RETURN_SUCCESS;
+}
+
}
--- a/codec/encoder/core/src/wels_task_management.cpp
+++ b/codec/encoder/core/src/wels_task_management.cpp
@@ -79,7 +79,8 @@
m_pThreadPool (NULL),
m_iTaskNum (0),
m_iWaitTaskNum (0) {
- m_cTaskList = new TASKLIST_TYPE();
+ m_cEncodingTaskList = new TASKLIST_TYPE();
+ m_cPreEncodingTaskList = new TASKLIST_TYPE();
WelsEventOpen (&m_hTaskEvent);
}
@@ -96,6 +97,10 @@
WelsCommon::CWelsThreadPool);
WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == m_pThreadPool)
//printf("CWelsTaskManageBase Init m_iThreadNum %d pEncCtx->iMaxSliceCount=%d\n", m_iThreadNum, pEncCtx->iMaxSliceCount);
+
+ m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_ENCODING] = m_cEncodingTaskList;
+ m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_PREENCODING] = m_cPreEncodingTaskList;
+
return CreateTasks (pEncCtx, pEncCtx->iMaxSliceCount);
}
@@ -103,7 +108,8 @@
DestroyTasks();
WELS_DELETE_OP (m_pThreadPool);
- delete m_cTaskList;
+ delete m_cEncodingTaskList;
+ delete m_cPreEncodingTaskList;
WelsEventClose (&m_hTaskEvent);
}
@@ -111,9 +117,15 @@
CWelsBaseTask* pTask = NULL;
for (int idx = 0; idx < kiTaskCount; idx++) {
+ pTask = WELS_NEW_OP (CWelsUpdateMbMapTask (pEncCtx, idx), CWelsUpdateMbMapTask);
+ WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == pTask)
+ m_cPreEncodingTaskList->push_back (pTask);
+ }
+
+ for (int idx = 0; idx < kiTaskCount; idx++) {
pTask = WELS_NEW_OP (CWelsSliceEncodingTask (pEncCtx, idx), CWelsSliceEncodingTask);
WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == pTask)
- m_cTaskList->push_back (pTask);
+ m_cEncodingTaskList->push_back (pTask);
}
m_iTaskNum = kiTaskCount;
@@ -126,15 +138,15 @@
return;
}
- if (m_cTaskList->size() != m_iTaskNum) {
- //printf("m_cTaskList %d %d\n", static_cast<int32_t>(m_cTaskList->size()), m_iTaskNum);
+ if (m_cEncodingTaskList->size() != m_iTaskNum) {
+ //printf("m_cEncodingTaskList %d %d\n", static_cast<int32_t>(m_cEncodingTaskList->size()), m_iTaskNum);
//WELS_ERROR_TRACE ("CWelsTaskManage::DestroyTasks: Incorrect task numbers");
}
- while (NULL != m_cTaskList->begin()) {
- CWelsBaseTask* pTask = m_cTaskList->begin();
+ while (NULL != m_cEncodingTaskList->begin()) {
+ CWelsBaseTask* pTask = m_cEncodingTaskList->begin();
WELS_DELETE_OP (pTask);
- m_cTaskList->pop_front();
+ m_cEncodingTaskList->pop_front();
}
//WelsLog (&m_pEncCtx->sLogCtx, WELS_LOG_INFO,
// "[MT] CWelsTaskManageParallel()DestroyTasks, cleaned %d tasks", m_iTaskNum);
@@ -167,12 +179,12 @@
//TODO: update mbmap;
}
-WelsErrorType CWelsTaskManageBase::ExecuteTasks() {
+WelsErrorType CWelsTaskManageBase::ExecuteTaskList(TASKLIST_TYPE* pTargetTaskList) {
//printf("ExecuteTasks m_iWaitTaskNum=%d\n", m_iWaitTaskNum);
int32_t iCurrentTaskCount = m_iWaitTaskNum; //if directly use m_iWaitTaskNum in the loop make cause sync problem
int32_t iIdx = 0;
- while (iIdx < iCurrentTaskCount) {
- m_pThreadPool->QueueTask (m_cTaskList->GetIndexNode(iIdx));
+ while (iIdx < iCurrentTaskCount) {
+ m_pThreadPool->QueueTask (pTargetTaskList->GetIndexNode(iIdx));
iIdx ++;
}
WelsEventWait (&m_hTaskEvent);
@@ -180,6 +192,10 @@
return ENC_RETURN_SUCCESS;
}
+WelsErrorType CWelsTaskManageBase::ExecuteTasks(const CWelsBaseTask::ETaskType iTaskType) {
+ return ExecuteTaskList(m_pcAllTaskList[iTaskType]);
+}
+
WelsErrorType CWelsTaskManageOne::Init (sWelsEncCtx* pEncCtx) {
Uninit();
m_pEncCtx = pEncCtx;
@@ -187,24 +203,24 @@
return CreateTasks (pEncCtx, pEncCtx->iMaxSliceCount);
}
-WelsErrorType CWelsTaskManageOne::ExecuteTasks() {
- while (NULL != m_cTaskList->begin()) {
- (m_cTaskList->begin())->Execute();
- m_cTaskList->pop_front();
+WelsErrorType CWelsTaskManageOne::ExecuteTasks(const CWelsBaseTask::ETaskType iTaskType) {
+ while (NULL != m_cEncodingTaskList->begin()) {
+ (m_cEncodingTaskList->begin())->Execute();
+ m_cEncodingTaskList->pop_front();
}
return ENC_RETURN_SUCCESS;
}
//TODO: at present there is no diff betweenCWelsTaskManageParallel and CWelsTaskManageBase, to finish later
-WelsErrorType CWelsTaskManageParallel::ExecuteTasks() {
+WelsErrorType CWelsTaskManageParallel::ExecuteTasks(const CWelsBaseTask::ETaskType iTaskType) {
WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == m_pThreadPool)
// need lock here?
- m_iWaitTaskNum = static_cast<int32_t> (m_cTaskList->size());
+ m_iWaitTaskNum = static_cast<int32_t> (m_cEncodingTaskList->size());
- while (NULL != m_cTaskList->begin()) {
- m_pThreadPool->QueueTask (m_cTaskList->begin());
- m_cTaskList->pop_front();
+ while (NULL != m_cEncodingTaskList->begin()) {
+ m_pThreadPool->QueueTask (m_cEncodingTaskList->begin());
+ m_cEncodingTaskList->pop_front();
}
WelsEventWait (&m_hTaskEvent);