ref: 05c89b75f023977af8b4da908f71d1638eea7ad0
parent: 67dab5d70e033cbf2a6a0a0c6dfc1dd6b0e6e264
author: sijchen <[email protected]>
date: Wed Nov 25 08:46:21 EST 2015
remove duplicated operation after thread pool and rename a task for clearer meaning
--- a/codec/encoder/core/inc/svc_enc_frame.h
+++ b/codec/encoder/core/inc/svc_enc_frame.h
@@ -108,6 +108,7 @@
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;
--- a/codec/encoder/core/inc/wels_task_base.h
+++ b/codec/encoder/core/inc/wels_task_base.h
@@ -55,7 +55,7 @@
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,
};
--- a/codec/encoder/core/inc/wels_task_encoder.h
+++ b/codec/encoder/core/inc/wels_task_encoder.h
@@ -132,7 +132,7 @@
virtual WelsErrorType Execute();
virtual uint32_t GetTaskType() const {
- return WELS_ENC_TASK_PREENCODING;
+ return WELS_ENC_TASK_UPDATEMBMAP;
}
protected:
sWelsEncCtx* m_pCtx;
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -1178,6 +1178,7 @@
NULL == pDqLayer->pLastMbIdxOfPartition),
FreeMemorySvc (ppCtx))
}
+ pDqLayer->bNeedAdjustingSlicing = false;
pDqLayer->iMbWidth = kiMbW;
pDqLayer->iMbHeight = kiMbH;
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -278,21 +278,10 @@
}
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,
--- a/codec/encoder/core/src/wels_task_management.cpp
+++ b/codec/encoder/core/src/wels_task_management.cpp
@@ -99,7 +99,7 @@
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);
@@ -199,7 +199,9 @@
}
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) {
@@ -226,7 +228,9 @@
//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) {
--- a/test/api/encode_decode_api_test.cpp
+++ b/test/api/encode_decode_api_test.cpp
@@ -3788,6 +3788,7 @@
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 @@
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 @@
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 @@
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 @@
decoder[iIdx]->Uninitialize();
WelsDestroyDecoder (decoder[iIdx]);
}
-
}
+#ifdef DEBUG_FILE_SAVE_TRIGGER
+ fclose(fEnc);
+#endif
}