Merge pull request #2281 from sijchen/th11

[Encoder] remove duplicated operation after thread pool
This commit is contained in:
HaiboZhu 2015-11-27 12:13:33 +08:00
commit f679da900f
7 changed files with 26 additions and 23 deletions

View File

@ -108,6 +108,7 @@ SPicture* pRefOri[MAX_REF_PIC_COUNT];
int32_t* pNumSliceCodedOfPartition; // for dynamic slicing mode
int32_t* pLastCodedMbIdxOfPartition; // for dynamic slicing mode
int32_t* pLastMbIdxOfPartition; // for dynamic slicing mode
bool bNeedAdjustingSlicing;
SFeatureSearchPreparation* pFeatureSearchPreparation;

View File

@ -55,7 +55,7 @@ class CWelsBaseTask : public WelsCommon::IWelsTask {
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_UPDATEMBMAP = 1,
WELS_ENC_TASK_PREPROCESS = 2,
WELS_ENC_TASK_ALL = 3,
};

View File

@ -132,7 +132,7 @@ class CWelsUpdateMbMapTask : public CWelsBaseTask {
virtual WelsErrorType Execute();
virtual uint32_t GetTaskType() const {
return WELS_ENC_TASK_PREENCODING;
return WELS_ENC_TASK_UPDATEMBMAP;
}
protected:
sWelsEncCtx* m_pCtx;

View File

@ -1178,6 +1178,7 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p
NULL == pDqLayer->pLastMbIdxOfPartition),
FreeMemorySvc (ppCtx))
}
pDqLayer->bNeedAdjustingSlicing = false;
pDqLayer->iMbWidth = kiMbW;
pDqLayer->iMbHeight = kiMbH;

View File

@ -242,21 +242,10 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx,
}
iRunLen[iSliceIdx] = iMbNumLeft;
MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,
"[MT] DynamicAdjustSlicing(), iSliceIdx= %d, iSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d",
iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY,
pSliceInLayer[iSliceIdx].iCountMbNumInSlice, iMbNumLeft);
"[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d",
iSliceIdx, pSliceComplexRatio[iSliceIdx] * 1.0f / INT_MULTIPLY, pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft);
if (DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen) == 0) {
const int32_t kiThreadNum = pCtx->pSvcParam->iCountThreadsNum;
int32_t iThreadIdx = 0;
do {
WelsEventSignal (&pCtx->pSliceThreading->pUpdateMbListEvent[iThreadIdx]);
WelsEventSignal (&pCtx->pSliceThreading->pThreadMasterEvent[iThreadIdx]);
++ iThreadIdx;
} while (iThreadIdx < kiThreadNum);
WelsMultipleEventsWaitAllBlocking (kiThreadNum, &pCtx->pSliceThreading->pFinUpdateMbListEvent[0]);
}
pCurDqLayer->bNeedAdjustingSlicing = !DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen);
}
int32_t SetMultiSliceBuffer (sWelsEncCtx** ppCtx, CMemoryAlign* pMa, SSliceThreading* pSmt,

View File

@ -99,7 +99,7 @@ WelsErrorType CWelsTaskManageBase::Init (sWelsEncCtx* pEncCtx) {
WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == m_pThreadPool)
m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_ENCODING] = m_cEncodingTaskList;
m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_PREENCODING] = m_cPreEncodingTaskList;
m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_UPDATEMBMAP] = m_cPreEncodingTaskList;
m_iCurrentTaskNum = pEncCtx->pSvcParam->sSpatialLayers[0].sSliceArgument.uiSliceNum;
//printf ("CWelsTaskManageBase Init m_iThreadNum %d m_iCurrentTaskNum %d pEncCtx->iMaxSliceCount %d\n", m_iThreadNum, m_iCurrentTaskNum, pEncCtx->iMaxSliceCount);
@ -202,7 +202,9 @@ WelsErrorType CWelsTaskManageBase::ExecuteTaskList (TASKLIST_TYPE* pTargetTaskL
}
void CWelsTaskManageBase::InitFrame (const int32_t kiCurDid) {
ExecuteTaskList (m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_PREENCODING]);
if (m_pEncCtx->pCurDqLayer->bNeedAdjustingSlicing) {
ExecuteTaskList (m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_UPDATEMBMAP]);
}
}
WelsErrorType CWelsTaskManageBase::ExecuteTasks (const CWelsBaseTask::ETaskType iTaskType) {
@ -229,7 +231,9 @@ void CWelsTaskManageMultiD::InitFrame (const int32_t kiCurDid) {
//printf("CWelsTaskManageMultiD: InitFrame: m_iCurDid=%d, m_iCurrentTaskNum=%d\n", m_iCurDid, m_iCurrentTaskNum);
m_iCurDid = kiCurDid;
m_iCurrentTaskNum = m_iTaskNumD[kiCurDid];
ExecuteTaskList (m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_PREENCODING]);
if (m_pEncCtx->pCurDqLayer->bNeedAdjustingSlicing) {
ExecuteTaskList (m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_UPDATEMBMAP]);
}
}
WelsErrorType CWelsTaskManageMultiD::ExecuteTasks (const CWelsBaseTask::ETaskType iTaskType) {

View File

@ -3788,6 +3788,7 @@ TEST_F (EncodeDecodeTestAPI, ThreadNumAndSliceNum) {
TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) {
//#define DEBUG_FILE_SAVE_TRIGGER
int iSpatialLayerNum = 1;
int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, (64 << 2), MAX_WIDTH);
int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, (64 << 2),
@ -3799,7 +3800,7 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) {
SEncParamExt sParam;
encoder_->GetDefaultParams (&sParam);
prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
sParam.iMultipleThreadIdc = (rand() % 8) + 1;
sParam.iMultipleThreadIdc = 4;
sParam.bSimulcastAVC = 1;
sParam.sSpatialLayers[0].iVideoWidth = iWidth;
sParam.sSpatialLayers[0].iVideoHeight = iHeight;
@ -3815,6 +3816,11 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) {
int iIdx = 0;
int aLen[MAX_SPATIAL_LAYER_NUM] = {};
#ifdef DEBUG_FILE_SAVE_TRIGGER
FILE* fEnc = fopen ("trigger00.264", "wb");
printf("Current Threads is %d\n", sParam.iMultipleThreadIdc);
#endif
//create decoder
for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
@ -3881,8 +3887,8 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) {
pData[0] = pData[1] = pData[2] = 0;
memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
#ifdef DEBUG_FILE_SAVE4
fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);
#ifdef DEBUG_FILE_SAVE_TRIGGER
fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc);
#endif
iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;
@ -3900,7 +3906,9 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) {
decoder[iIdx]->Uninitialize();
WelsDestroyDecoder (decoder[iIdx]);
}
}
#ifdef DEBUG_FILE_SAVE_TRIGGER
fclose(fEnc);
#endif
}