Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 16 files). Show all
Unified · Split
| @@ -87,7 +87,7 @@ void UpdateMbListNeighborParallel (SDqLayer* pCurDq, · 86 unmodified lines | ||
| 87 | 87 | const int32_t kiEndMbInSlice = iIdx + pUpdateSlice->iCountMbNumInSlice - 1; |
| 88 | 88 | |
| 89 | 89 | do { |
| 90 | − UpdateMbNeighbor(pCurDq, &pMbList[iIdx], kiMbWidth, uiSliceIdc); | |
| 90 | + UpdateMbNeighbor (pCurDq, &pMbList[iIdx], kiMbWidth, uiSliceIdc); | |
| 91 | 91 | ++ iIdx; |
| 92 | 92 | } while (iIdx <= kiEndMbInSlice); |
| 93 | 93 | } |
| @@ -118,7 +118,7 @@ void CalcSliceComplexRatio (SDqLayer* pCurDq) { · 24 unmodified lines | ||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | int32_t NeedDynamicAdjust (SSlice* pSliceInLayer, const int32_t iSliceNum) { |
| 121 | − if ( NULL == pSliceInLayer ) | |
| 121 | + if (NULL == pSliceInLayer) | |
| 122 | 122 | return false; |
| 123 | 123 | |
| 124 | 124 | uint32_t uiTotalConsume = 0; |
| @@ -207,7 +207,8 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 82 unmodified lines | ||
| 207 | 207 | |
| 208 | 208 | WelsEmms(); |
| 209 | 209 | |
| 210 | − MT_TRACE_LOG (&(pCtx->sLogCtx), WELS_LOG_DEBUG, "[MT] DynamicAdjustSlicing(), iDid= %d, iCountNumMb= %d", iCurDid, kiCountNumMb); | |
| 210 | + MT_TRACE_LOG (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "[MT] DynamicAdjustSlicing(), iDid= %d, iCountNumMb= %d", iCurDid, | |
| 211 | + kiCountNumMb); | |
| 211 | 212 | |
| 212 | 213 | iSliceIdx = 0; |
| 213 | 214 | while (iSliceIdx + 1 < kiCountSliceNum) { |
| @@ -232,7 +233,7 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 18 unmodified lines | ||
| 232 | 233 | return; |
| 233 | 234 | } |
| 234 | 235 | iRunLen[iSliceIdx] = iNumMbAssigning; |
| 235 | − MT_TRACE_LOG (&(pCtx->sLogCtx), WELS_LOG_DEBUG, | |
| 236 | + MT_TRACE_LOG (& (pCtx->sLogCtx), WELS_LOG_DEBUG, | |
| 236 | 237 | "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, iSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d", |
| 237 | 238 | iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY, |
| 238 | 239 | pSliceInLayer[iSliceIdx].iCountMbNumInSlice, |
| @@ -241,9 +242,10 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 2 unmodified lines | ||
| 241 | 242 | iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts |
| 242 | 243 | } |
| 243 | 244 | iRunLen[iSliceIdx] = iMbNumLeft; |
| 244 | − MT_TRACE_LOG (&(pCtx->sLogCtx), WELS_LOG_DEBUG, | |
| 245 | + MT_TRACE_LOG (& (pCtx->sLogCtx), WELS_LOG_DEBUG, | |
| 245 | 246 | "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d", |
| 246 | − iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY, pSliceInLayer[iSliceIdx].iCountMbNumInSlice, iMbNumLeft); | |
| 247 | + iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY, | |
| 248 | + pSliceInLayer[iSliceIdx].iCountMbNumInSlice, iMbNumLeft); | |
| 247 | 249 | |
| 248 | 250 | pCurDqLayer->bNeedAdjustingSlicing = !DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen); |
| 249 | 251 | } |
| @@ -274,11 +276,12 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 24 unmodified lines | ||
| 274 | 276 | iMaxSliceNumInThread = WELS_MIN ((*ppCtx)->iMaxSliceCount, (int) iMaxSliceNumInThread); |
| 275 | 277 | |
| 276 | 278 | pSmt = (SSliceThreading*)pMa->WelsMalloc (sizeof (SSliceThreading), "SSliceThreading"); |
| 277 | − WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt), FreeMemorySvc (ppCtx)) | |
| 279 | + WELS_VERIFY_RETURN_IF (1, (NULL == pSmt)) | |
| 280 | + memset (pSmt, 0, sizeof (SSliceThreading)); | |
| 278 | 281 | (*ppCtx)->pSliceThreading = pSmt; |
| 279 | 282 | pSmt->pThreadPEncCtx = (SSliceThreadPrivateData*)pMa->WelsMalloc (sizeof (SSliceThreadPrivateData) * iThreadNum, |
| 280 | 283 | "pThreadPEncCtx"); |
| 281 | − WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadPEncCtx), FreeMemorySvc (ppCtx)) | |
| 284 | + WELS_VERIFY_RETURN_IF (1, (NULL == pSmt->pThreadPEncCtx)) | |
| 282 | 285 | |
| 283 | 286 | #ifdef _WIN32 |
| 284 | 287 | // Dummy event namespace, the windows events don't actually use this |
| @@ -333,38 +336,29 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 48 unmodified lines | ||
| 333 | 336 | (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno); |
| 334 | 337 | ++ iIdx; |
| 335 | 338 | } |
| 336 | − for (; iIdx < MAX_THREADS_NUM; iIdx++) { | |
| 337 | − pSmt->pThreadBsBuffer[iIdx] = NULL; | |
| 338 | − } | |
| 339 | 339 | |
| 340 | 340 | WelsSnprintf (name, SEM_NAME_MAX, "scm%s", pSmt->eventNamespace); |
| 341 | 341 | err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name); |
| 342 | 342 | MT_TRACE_LOG (pLogCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno); |
| 343 | 343 | |
| 344 | 344 | iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate); |
| 345 | − WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) | |
| 345 | + WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn)) | |
| 346 | 346 | |
| 347 | 347 | (*ppCtx)->pTaskManage = IWelsTaskManage::CreateTaskManage (*ppCtx, iNumSpatialLayers, bDynamicSlice); |
| 348 | − WELS_VERIFY_RETURN_PROC_IF (iReturn, (NULL == (*ppCtx)->pTaskManage), FreeMemorySvc (ppCtx)) | |
| 348 | + WELS_VERIFY_RETURN_IF (1, (NULL == (*ppCtx)->pTaskManage)) | |
| 349 | + | |
| 350 | + int32_t iThreadBufferNum = WELS_MIN ((*ppCtx)->pTaskManage->GetThreadPoolThreadNum(), MAX_THREADS_NUM); | |
| 349 | 351 | |
| 350 | − int32_t iThreadBufferNum = WELS_MIN((*ppCtx)->pTaskManage->GetThreadPoolThreadNum(), MAX_THREADS_NUM); | |
| 351 | − for (iIdx = 0;iIdx < iThreadBufferNum; iIdx++) { | |
| 352 | + for (iIdx = 0; iIdx < iThreadBufferNum; iIdx++) { | |
| 352 | 353 | pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pSmt->pThreadBsBuffer"); |
| 353 | − WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx]), FreeMemorySvc (ppCtx)) | |
| 354 | − } | |
| 355 | − if (iThreadBufferNum < MAX_THREADS_NUM) { | |
| 356 | − for (iIdx = iThreadBufferNum; iIdx < MAX_THREADS_NUM; iIdx++) { | |
| 357 | − pSmt->pThreadBsBuffer[iIdx] = NULL; | |
| 358 | − } | |
| 354 | + WELS_VERIFY_RETURN_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx])) | |
| 359 | 355 | } |
| 360 | − | |
| 361 | − memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool)); | |
| 362 | 356 | iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage); |
| 363 | − WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) | |
| 357 | + WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn)) | |
| 364 | 358 | iReturn = WelsMutexInit (&pSmt->mutexEvent); |
| 365 | − WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)); | |
| 359 | + WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn)) | |
| 366 | 360 | iReturn = WelsMutexInit (& (*ppCtx)->mutexEncoderError); |
| 367 | − WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) | |
| 361 | + WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn)) | |
| 368 | 362 | |
| 369 | 363 | MT_TRACE_LOG (pLogCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iMultipleThreadIdc= %d", |
| 370 | 364 | pPara->iMultipleThreadIdc, |
| @@ -427,7 +421,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 56 unmodified lines | ||
| 427 | 421 | memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool)); |
| 428 | 422 | |
| 429 | 423 | if ((*ppCtx)->pTaskManage != NULL) { |
| 430 | − WELS_DELETE_OP((*ppCtx)->pTaskManage); | |
| 424 | + WELS_DELETE_OP ((*ppCtx)->pTaskManage); | |
| 431 | 425 | } |
| 432 | 426 | |
| 433 | 427 | #ifdef MT_DEBUG |
| @@ -516,7 +510,7 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 82 unmodified lines | ||
| 516 | 510 | return iLayerSize; |
| 517 | 511 | } |
| 518 | 512 | |
| 519 | −int32_t WriteSliceBs (sWelsEncCtx* pCtx,SWelsSliceBs* pSliceBs,const int32_t iSliceIdx,int32_t& iSliceSize) { | |
| 513 | +int32_t WriteSliceBs (sWelsEncCtx* pCtx, SWelsSliceBs* pSliceBs, const int32_t iSliceIdx, int32_t& iSliceSize) { | |
| 520 | 514 | const int32_t kiNalCnt = pSliceBs->iNalIndex; |
| 521 | 515 | int32_t iNalIdx = 0; |
| 522 | 516 | int32_t iNalSize = 0; |
| @@ -581,12 +575,13 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 58 unmodified lines | ||
| 581 | 575 | WelsThreadSetName ("OpenH264Enc_CodingSliceThreadProc"); |
| 582 | 576 | |
| 583 | 577 | do { |
| 584 | − MT_TRACE_LOG (&(pEncPEncCtx->sLogCtx), WELS_LOG_INFO, | |
| 578 | + MT_TRACE_LOG (& (pEncPEncCtx->sLogCtx), WELS_LOG_INFO, | |
| 585 | 579 | "[MT] CodingSliceThreadProc(), try to call WelsMultipleEventsWaitSingleBlocking(pEventsList= %p %p %p), pEncPEncCtx= %p!", |
| 586 | 580 | pEventsList[0], pEventsList[1], pEventsList[1], (void*)pEncPEncCtx); |
| 587 | 581 | iWaitRet = WelsMultipleEventsWaitSingleBlocking (iEventCount, |
| 588 | 582 | &pEventsList[0], |
| 589 | − &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx],&pEncPEncCtx->pSliceThreading->mutexEvent); // blocking until at least one event is signalled | |
| 583 | + &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx], | |
| 584 | + &pEncPEncCtx->pSliceThreading->mutexEvent); // blocking until at least one event is signalled | |
| 590 | 585 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited |
| 591 | 586 | //int iLayerIndex = pEncPEncCtx->pOut->iLayerBsIndex; |
| 592 | 587 | //SFrameBSInfo* pFrameBsInfo = pPrivateData->pFrameBsInfo; |
| @@ -658,7 +653,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 65 unmodified lines | ||
| 658 | 653 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); |
| 659 | 654 | |
| 660 | 655 | if (bDsaFlag) { |
| 661 | − pEncPEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].uiSliceConsumeTime = (uint32_t) ( | |
| 656 | + pEncPEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].uiSliceConsumeTime = (uint32_t) ( | |
| 662 | 657 | WelsTime() - iSliceStart); |
| 663 | 658 | MT_TRACE_LOG (& (pEncPEncCtx->sLogCtx), WELS_LOG_INFO, |
| 664 | 659 | "[MT] CodingSliceThreadProc(), coding_idx %d, uiSliceIdx %d, uiSliceConsumeTime %d, iSliceSize %d, iFirstMbInSlice %d, count_num_mb_in_slice %d", |
| @@ -693,7 +688,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 28 unmodified lines | ||
| 693 | 688 | const int32_t kiFirstMbInPartition = pPrivateData->iStartMbIndex; // inclusive |
| 694 | 689 | const int32_t kiEndMbInPartition = pPrivateData->iEndMbIndex; // exclusive |
| 695 | 690 | int32_t iAnyMbLeftInPartition = kiEndMbInPartition - kiFirstMbInPartition; |
| 696 | − SSpatialLayerInternal *pParamInternal = &pCodingParam->sDependencyLayers[kiCurDid]; | |
| 691 | + SSpatialLayerInternal* pParamInternal = &pCodingParam->sDependencyLayers[kiCurDid]; | |
| 697 | 692 | iSliceIdx = pPrivateData->iSliceIndex; |
| 698 | 693 | SSliceHeaderExt* pStartSliceHeaderExt = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].sSliceHeaderExt; |
| 699 | 694 | pStartSliceHeaderExt->sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition; |
| @@ -774,7 +769,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 74 unmodified lines | ||
| 774 | 769 | ); |
| 775 | 770 | #endif//SLICE_INFO_OUTPUT |
| 776 | 771 | |
| 777 | − MT_TRACE_LOG (&(pEncPEncCtx->sLogCtx), WELS_LOG_INFO, | |
| 772 | + MT_TRACE_LOG (& (pEncPEncCtx->sLogCtx), WELS_LOG_INFO, | |
| 778 | 773 | "[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, uiSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->pLastCodedMbIdxOfPartition[%d] %d\n", |
| 779 | 774 | pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize, |
| 780 | 775 | pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].iCountMbNumInSlice, |
| @@ -833,7 +828,7 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 52 unmodified lines | ||
| 833 | 828 | |
| 834 | 829 | ++ iIdx; |
| 835 | 830 | } |
| 836 | − MT_TRACE_LOG (&(pCtx->sLogCtx), WELS_LOG_INFO, "CreateSliceThreads() exit.."); | |
| 831 | + MT_TRACE_LOG (& (pCtx->sLogCtx), WELS_LOG_INFO, "CreateSliceThreads() exit.."); | |
| 837 | 832 | return 0; |
| 838 | 833 | } |
| 839 | 834 | |
| @@ -1007,7 +1002,7 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 167 unmodified lines | ||
| 1007 | 1002 | int32_t iMaxI = 0; |
| 1008 | 1003 | while (i < kuiCountSliceNum) { |
| 1009 | 1004 | fprintf (pCtx->pSliceThreading->pFSliceDiff, "%6d us consume_time coding_idx %d iDid %d pSlice %d\n", |
| 1010 | − pSliceInLayer[i].uiSliceConsumeTime, pCtx->iCodingIndex, kiDid, i /*/ 1000*/); | |
| 1005 | + pSliceInLayer[i].uiSliceConsumeTime, pCtx->iCodingIndex, kiDid, i /*/ 1000*/); | |
| 1011 | 1006 | if (pSliceInLayer[i].uiSliceConsumeTime > uiMaxT) { |
| 1012 | 1007 | uiMaxT = pSliceInLayer[i].uiSliceConsumeTime; |
| 1013 | 1008 | iMaxI = i; |