History

Merge pull request #2281 from sijchen/th11

[Encoder] remove duplicated operation after thread pool

HaiboZhu committed 10 years ago

Commit f679da92 parents b749fe7 05c89b77 files · +26 −23Browse files

Unified · Split

7 files
  1. codec/encoder/core/inc/svc_enc_frame.h +1 −0
  2. codec/encoder/core/inc/wels_task_base.h +1 −1
  3. codec/encoder/core/inc/wels_task_encoder.h +1 −1
  4. codec/encoder/core/src/encoder_ext.cpp +1 −0
  5. codec/encoder/core/src/slice_multi_threading.cpp +3 −14
  6. codec/encoder/core/src/wels_task_management.cpp +7 −3
  7. test/api/encode_decode_api_test.cpp +12 −4
codec/encoder/core/inc/svc_enc_frame.h+1−0
@@ -108,6 +108,7 @@ SPicture* pRefOri[MAX_REF_PIC_COUNT]; · 107 unmodified lines
108int32_t* pNumSliceCodedOfPartition; // for dynamic slicing mode108int32_t* pNumSliceCodedOfPartition; // for dynamic slicing mode
109int32_t* pLastCodedMbIdxOfPartition; // for dynamic slicing mode109int32_t* pLastCodedMbIdxOfPartition; // for dynamic slicing mode
110int32_t* pLastMbIdxOfPartition; // for dynamic slicing mode110int32_t* pLastMbIdxOfPartition; // for dynamic slicing mode
111bool bNeedAdjustingSlicing;
111 112
112SFeatureSearchPreparation* pFeatureSearchPreparation;113SFeatureSearchPreparation* pFeatureSearchPreparation;
113 114
codec/encoder/core/inc/wels_task_base.h+1−1
@@ -55,7 +55,7 @@ class CWelsBaseTask : public WelsCommon::IWelsTask { · 54 unmodified lines
55 WELS_ENC_TASK_ENCODE_FIXED_SLICE = WELS_ENC_TASK_ENCODING,55 WELS_ENC_TASK_ENCODE_FIXED_SLICE = WELS_ENC_TASK_ENCODING,
56 WELS_ENC_TASK_ENCODE_SLICE_LOADBALANCING = WELS_ENC_TASK_ENCODING,56 WELS_ENC_TASK_ENCODE_SLICE_LOADBALANCING = WELS_ENC_TASK_ENCODING,
57 WELS_ENC_TASK_ENCODE_SLICE_SIZECONSTRAINED = WELS_ENC_TASK_ENCODING,57 WELS_ENC_TASK_ENCODE_SLICE_SIZECONSTRAINED = WELS_ENC_TASK_ENCODING,
58 WELS_ENC_TASK_PREENCODING = 1,58 WELS_ENC_TASK_UPDATEMBMAP = 1,
59 WELS_ENC_TASK_PREPROCESS = 2,59 WELS_ENC_TASK_PREPROCESS = 2,
60 WELS_ENC_TASK_ALL = 3,60 WELS_ENC_TASK_ALL = 3,
61 };61 };
codec/encoder/core/inc/wels_task_encoder.h+1−1
@@ -132,7 +132,7 @@ class CWelsUpdateMbMapTask : public CWelsBaseTask { · 131 unmodified lines
132 virtual WelsErrorType Execute();132 virtual WelsErrorType Execute();
133 133
134 virtual uint32_t GetTaskType() const {134 virtual uint32_t GetTaskType() const {
135 return WELS_ENC_TASK_PREENCODING;135 return WELS_ENC_TASK_UPDATEMBMAP;
136 }136 }
137 protected:137 protected:
138 sWelsEncCtx* m_pCtx;138 sWelsEncCtx* m_pCtx;
codec/encoder/core/src/encoder_ext.cpp+1−0
@@ -1178,6 +1178,7 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 1177 unmodified lines
1178 NULL == pDqLayer->pLastMbIdxOfPartition),1178 NULL == pDqLayer->pLastMbIdxOfPartition),
1179 FreeMemorySvc (ppCtx))1179 FreeMemorySvc (ppCtx))
1180 }1180 }
1181 pDqLayer->bNeedAdjustingSlicing = false;
1181 1182
1182 pDqLayer->iMbWidth = kiMbW;1183 pDqLayer->iMbWidth = kiMbW;
1183 pDqLayer->iMbHeight = kiMbH;1184 pDqLayer->iMbHeight = kiMbH;
codec/encoder/core/src/slice_multi_threading.cpp+3−14
@@ -242,21 +242,10 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 241 unmodified lines
242 }242 }
243 iRunLen[iSliceIdx] = iMbNumLeft;243 iRunLen[iSliceIdx] = iMbNumLeft;
244 MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,244 MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,
245 "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, iSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d",245 "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d",
246 iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY,246 iSliceIdx, pSliceComplexRatio[iSliceIdx] * 1.0f / INT_MULTIPLY, pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft);
247 pSliceInLayer[iSliceIdx].iCountMbNumInSlice, iMbNumLeft);
248 247
249 if (DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen) == 0) {248 pCurDqLayer->bNeedAdjustingSlicing = !DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen);
250 const int32_t kiThreadNum = pCtx->pSvcParam->iCountThreadsNum;
251 int32_t iThreadIdx = 0;
252 do {
253 WelsEventSignal (&pCtx->pSliceThreading->pUpdateMbListEvent[iThreadIdx]);
254 WelsEventSignal (&pCtx->pSliceThreading->pThreadMasterEvent[iThreadIdx]);
255 ++ iThreadIdx;
256 } while (iThreadIdx < kiThreadNum);
257
258 WelsMultipleEventsWaitAllBlocking (kiThreadNum, &pCtx->pSliceThreading->pFinUpdateMbListEvent[0]);
259 }
260}249}
261 250
262int32_t SetMultiSliceBuffer (sWelsEncCtx** ppCtx, CMemoryAlign* pMa, SSliceThreading* pSmt,251int32_t SetMultiSliceBuffer (sWelsEncCtx** ppCtx, CMemoryAlign* pMa, SSliceThreading* pSmt,
codec/encoder/core/src/wels_task_management.cpp+7−3
@@ -99,7 +99,7 @@ WelsErrorType CWelsTaskManageBase::Init (sWelsEncCtx* pEncCtx) { · 98 unmodified lines
99 WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == m_pThreadPool)99 WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == m_pThreadPool)
100 100
101 m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_ENCODING] = m_cEncodingTaskList;101 m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_ENCODING] = m_cEncodingTaskList;
102 m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_PREENCODING] = m_cPreEncodingTaskList;102 m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_UPDATEMBMAP] = m_cPreEncodingTaskList;
103 103
104 m_iCurrentTaskNum = pEncCtx->pSvcParam->sSpatialLayers[0].sSliceArgument.uiSliceNum;104 m_iCurrentTaskNum = pEncCtx->pSvcParam->sSpatialLayers[0].sSliceArgument.uiSliceNum;
105 //printf ("CWelsTaskManageBase Init m_iThreadNum %d m_iCurrentTaskNum %d pEncCtx->iMaxSliceCount %d\n", m_iThreadNum, m_iCurrentTaskNum, pEncCtx->iMaxSliceCount);105 //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 · 96 unmodified lines
202}202}
203 203
204void CWelsTaskManageBase::InitFrame (const int32_t kiCurDid) {204void CWelsTaskManageBase::InitFrame (const int32_t kiCurDid) {
205 ExecuteTaskList (m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_PREENCODING]);205 if (m_pEncCtx->pCurDqLayer->bNeedAdjustingSlicing) {
206 ExecuteTaskList (m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_UPDATEMBMAP]);
207 }
206}208}
207 209
208WelsErrorType CWelsTaskManageBase::ExecuteTasks (const CWelsBaseTask::ETaskType iTaskType) {210WelsErrorType CWelsTaskManageBase::ExecuteTasks (const CWelsBaseTask::ETaskType iTaskType) {
@@ -229,7 +231,9 @@ void CWelsTaskManageMultiD::InitFrame (const int32_t kiCurDid) { · 20 unmodified lines
229 //printf("CWelsTaskManageMultiD: InitFrame: m_iCurDid=%d, m_iCurrentTaskNum=%d\n", m_iCurDid, m_iCurrentTaskNum);231 //printf("CWelsTaskManageMultiD: InitFrame: m_iCurDid=%d, m_iCurrentTaskNum=%d\n", m_iCurDid, m_iCurrentTaskNum);
230 m_iCurDid = kiCurDid;232 m_iCurDid = kiCurDid;
231 m_iCurrentTaskNum = m_iTaskNumD[kiCurDid];233 m_iCurrentTaskNum = m_iTaskNumD[kiCurDid];
232 ExecuteTaskList (m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_PREENCODING]);234 if (m_pEncCtx->pCurDqLayer->bNeedAdjustingSlicing) {
235 ExecuteTaskList (m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_UPDATEMBMAP]);
236 }
233}237}
234 238
235WelsErrorType CWelsTaskManageMultiD::ExecuteTasks (const CWelsBaseTask::ETaskType iTaskType) {239WelsErrorType CWelsTaskManageMultiD::ExecuteTasks (const CWelsBaseTask::ETaskType iTaskType) {
test/api/encode_decode_api_test.cpp+12−4
@@ -3788,6 +3788,7 @@ TEST_F (EncodeDecodeTestAPI, ThreadNumAndSliceNum) { · 3787 unmodified lines
3788 3788
3789 3789
3790TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) {3790TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) {
3791//#define DEBUG_FILE_SAVE_TRIGGER
3791 int iSpatialLayerNum = 1;3792 int iSpatialLayerNum = 1;
3792 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, (64 << 2), MAX_WIDTH);3793 int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, (64 << 2), MAX_WIDTH);
3793 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, (64 << 2),3794 int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, (64 << 2),
@@ -3799,7 +3800,7 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) { · 5 unmodified lines
3799 SEncParamExt sParam;3800 SEncParamExt sParam;
3800 encoder_->GetDefaultParams (&sParam);3801 encoder_->GetDefaultParams (&sParam);
3801 prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);3802 prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
3802 sParam.iMultipleThreadIdc = (rand() % 8) + 1;3803 sParam.iMultipleThreadIdc = 4;
3803 sParam.bSimulcastAVC = 1;3804 sParam.bSimulcastAVC = 1;
3804 sParam.sSpatialLayers[0].iVideoWidth = iWidth;3805 sParam.sSpatialLayers[0].iVideoWidth = iWidth;
3805 sParam.sSpatialLayers[0].iVideoHeight = iHeight;3806 sParam.sSpatialLayers[0].iVideoHeight = iHeight;
@@ -3815,6 +3816,11 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) { · 9 unmodified lines
3815 int iIdx = 0;3816 int iIdx = 0;
3816 int aLen[MAX_SPATIAL_LAYER_NUM] = {};3817 int aLen[MAX_SPATIAL_LAYER_NUM] = {};
3817 3818
3819#ifdef DEBUG_FILE_SAVE_TRIGGER
3820 FILE* fEnc = fopen ("trigger00.264", "wb");
3821 printf("Current Threads is %d\n", sParam.iMultipleThreadIdc);
3822#endif
3823
3818 //create decoder3824 //create decoder
3819 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {3825 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
3820 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));3826 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
@@ -3881,8 +3887,8 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) { · 60 unmodified lines
3881 pData[0] = pData[1] = pData[2] = 0;3887 pData[0] = pData[1] = pData[2] = 0;
3882 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));3888 memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
3883 3889
3884#ifdef DEBUG_FILE_SAVE43890#ifdef DEBUG_FILE_SAVE_TRIGGER
3885 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);3891 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc);
3886#endif3892#endif
3887 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);3893 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
3888 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;3894 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << ", LayerIdx=" << iIdx;
@@ -3900,7 +3906,9 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) { · 11 unmodified lines
3900 decoder[iIdx]->Uninitialize();3906 decoder[iIdx]->Uninitialize();
3901 WelsDestroyDecoder (decoder[iIdx]);3907 WelsDestroyDecoder (decoder[iIdx]);
3902 }3908 }
3903
3904 }3909 }
3910#ifdef DEBUG_FILE_SAVE_TRIGGER
3911 fclose(fEnc);
3912#endif
3905}3913}
3906 3914

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t