Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 120 files). Show all
Unified · Split
| @@ -132,8 +132,9 @@ void CalcSliceComplexRatio (void* pRatio, SSliceCtx* pSliceCtx, uint32_t* pSlice · 131 unmodified lines | |||
| 132 | 132 | ||
| 133 | while (iSliceIdx < kiSliceCount) { | 133 | while (iSliceIdx < kiSliceCount) { |
| 134 | fAvI[iSliceIdx] = 1.0f * pCountMbInSlice[iSliceIdx] / pSliceTime[iSliceIdx]; | 134 | fAvI[iSliceIdx] = 1.0f * pCountMbInSlice[iSliceIdx] / pSliceTime[iSliceIdx]; |
| 135 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n", iSliceIdx, | 135 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n", |
| 136 | pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]); | 136 | iSliceIdx, |
| 137 | pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]); | ||
| 137 | fSumAv += fAvI[iSliceIdx]; | 138 | fSumAv += fAvI[iSliceIdx]; |
| 138 | 139 | ||
| 139 | ++ iSliceIdx; | 140 | ++ iSliceIdx; |
| @@ -156,8 +157,9 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 16 unmodified lines | |||
| 156 | iSliceIdx += 2; | 157 | iSliceIdx += 2; |
| 157 | } | 158 | } |
| 158 | if (uiTotalConsume == 0) { | 159 | if (uiTotalConsume == 0) { |
| 159 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n", | 160 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, |
| 160 | iSliceNum); | 161 | "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n", |
| 162 | iSliceNum); | ||
| 161 | return false; | 163 | return false; |
| 162 | } | 164 | } |
| 163 | 165 | ||
| @@ -183,8 +185,8 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 19 unmodified lines | |||
| 183 | if (fRmse > fThr) | 185 | if (fRmse > fThr) |
| 184 | iNeedAdj = true; | 186 | iNeedAdj = true; |
| 185 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, | 187 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, |
| 186 | "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n", | 188 | "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n", |
| 187 | iNeedAdj, fRmse, fThr, iSliceNum); | 189 | iNeedAdj, fRmse, fThr, iSliceNum); |
| 188 | 190 | ||
| 189 | return iNeedAdj; | 191 | return iNeedAdj; |
| 190 | } | 192 | } |
| @@ -256,8 +258,8 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 65 unmodified lines | |||
| 256 | } | 258 | } |
| 257 | iRunLen[iSliceIdx] = iNumMbAssigning; | 259 | iRunLen[iSliceIdx] = iNumMbAssigning; |
| 258 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, | 260 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, |
| 259 | "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n", | 261 | "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n", |
| 260 | iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iNumMbAssigning); | 262 | iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iNumMbAssigning); |
| 261 | ++ iSliceIdx; | 263 | ++ iSliceIdx; |
| 262 | iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts | 264 | iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts |
| 263 | } | 265 | } |
| @@ -313,16 +315,17 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 49 unmodified lines | |||
| 313 | 315 | ||
| 314 | #ifdef _WIN32 | 316 | #ifdef _WIN32 |
| 315 | // Dummy event namespace, the windows events don't actually use this | 317 | // Dummy event namespace, the windows events don't actually use this |
| 316 | WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p", (void*) *ppCtx); | 318 | WelsSnprintf (pSmt->eventNamespace, sizeof (pSmt->eventNamespace), "%p", (void*) *ppCtx); |
| 317 | #else | 319 | #else |
| 318 | WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p%x", (void*) *ppCtx, getpid()); | 320 | WelsSnprintf (pSmt->eventNamespace, sizeof (pSmt->eventNamespace), "%p%x", (void*) *ppCtx, getpid()); |
| 319 | #endif//!_WIN32 | 321 | #endif//!_WIN32 |
| 320 | 322 | ||
| 321 | iIdx = 0; | 323 | iIdx = 0; |
| 322 | while (iIdx < iNumSpatialLayers) { | 324 | while (iIdx < iNumSpatialLayers) { |
| 323 | SSliceConfig* pMso = &pPara->sDependencyLayers[iIdx].sSliceCfg; | 325 | SSliceConfig* pMso = &pPara->sDependencyLayers[iIdx].sSliceCfg; |
| 324 | const int32_t kiSliceNum = pMso->sSliceArgument.uiSliceNum; | 326 | const int32_t kiSliceNum = pMso->sSliceArgument.uiSliceNum; |
| 325 | if (((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pMso->uiSliceMode == SM_AUTO_SLICE)) && pPara->iMultipleThreadIdc > 1 | 327 | if (((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE) || (pMso->uiSliceMode == SM_AUTO_SLICE)) |
| 328 | && pPara->iMultipleThreadIdc > 1 | ||
| 326 | && pPara->iMultipleThreadIdc >= kiSliceNum) { | 329 | && pPara->iMultipleThreadIdc >= kiSliceNum) { |
| 327 | pSmt->pSliceConsumeTime[iIdx] = (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]"); | 330 | pSmt->pSliceConsumeTime[iIdx] = (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]"); |
| 328 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx)) | 331 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx)) |
| @@ -371,7 +374,8 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 42 unmodified lines | |||
| 371 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | 374 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); |
| 372 | WelsSnprintf (name, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace); | 375 | WelsSnprintf (name, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace); |
| 373 | err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name); | 376 | err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name); |
| 374 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | 377 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, |
| 378 | errno); | ||
| 375 | WelsSnprintf (name, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace); | 379 | WelsSnprintf (name, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace); |
| 376 | err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name); | 380 | err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name); |
| 377 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | 381 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); |
| @@ -415,10 +419,11 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 37 unmodified lines | |||
| 415 | iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate); | 419 | iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate); |
| 416 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) | 420 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) |
| 417 | 421 | ||
| 418 | iReturn = WelsMutexInit (&(*ppCtx)->mutexEncoderError); | 422 | iReturn = WelsMutexInit (& (*ppCtx)->mutexEncoderError); |
| 419 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) | 423 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) |
| 420 | 424 | ||
| 421 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n", pPara->iCountThreadsNum, | 425 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n", |
| 426 | pPara->iCountThreadsNum, | ||
| 422 | iMaxSliceNum); | 427 | iMaxSliceNum); |
| 423 | 428 | ||
| 424 | return 0; | 429 | return 0; |
| @@ -467,7 +472,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 42 unmodified lines | |||
| 467 | WelsEventClose (&pSmt->pSliceCodedMasterEvent, ename); | 472 | WelsEventClose (&pSmt->pSliceCodedMasterEvent, ename); |
| 468 | 473 | ||
| 469 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); | 474 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); |
| 470 | WelsMutexDestroy (&((*ppCtx)->mutexEncoderError)); | 475 | WelsMutexDestroy (& ((*ppCtx)->mutexEncoderError)); |
| 471 | 476 | ||
| 472 | if (pSmt->pThreadPEncCtx != NULL) { | 477 | if (pSmt->pThreadPEncCtx != NULL) { |
| 473 | pMa->WelsFree (pSmt->pThreadPEncCtx, "pThreadPEncCtx"); | 478 | pMa->WelsFree (pSmt->pThreadPEncCtx, "pThreadPEncCtx"); |
| @@ -595,7 +600,8 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 121 unmodified lines | |||
| 595 | return iLayerSize; | 600 | return iLayerSize; |
| 596 | } | 601 | } |
| 597 | 602 | ||
| 598 | int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx, int32_t& iSliceSize) { | 603 | int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx, |
| 604 | int32_t& iSliceSize) { | ||
| 599 | SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; | 605 | SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; |
| 600 | SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt; | 606 | SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt; |
| 601 | uint8_t* pDst = pFrameBsBuffer; | 607 | uint8_t* pDst = pFrameBsBuffer; |
| @@ -610,8 +616,9 @@ int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFr · 8 unmodified lines | |||
| 610 | 616 | ||
| 611 | while (iNalIdx < kiNalCnt) { | 617 | while (iNalIdx < kiNalCnt) { |
| 612 | iNalSize = 0; | 618 | iNalSize = 0; |
| 613 | iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pCtx->iFrameBsSize-kiWrittenLength-iSliceSize, pDst, &iNalSize); | 619 | iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pCtx->iFrameBsSize - kiWrittenLength - iSliceSize, |
| 614 | WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | 620 | pDst, &iNalSize); |
| 621 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) | ||
| 615 | iSliceSize += iNalSize; | 622 | iSliceSize += iNalSize; |
| 616 | pDst += iNalSize; | 623 | pDst += iNalSize; |
| 617 | pLbi->iNalLengthInByte[iNalBase + iNalIdx] = iNalSize; | 624 | pLbi->iNalLengthInByte[iNalBase + iNalIdx] = iNalSize; |
| @@ -653,8 +660,9 @@ int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSl · 35 unmodified lines | |||
| 653 | 660 | ||
| 654 | while (iNalIdx < kiNalCnt) { | 661 | while (iNalIdx < kiNalCnt) { |
| 655 | iNalSize = 0; | 662 | iNalSize = 0; |
| 656 | iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pSliceBs->uiSize-kiWrittenLength-iSliceSize, pDst, &iNalSize); | 663 | iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pSliceBs->uiSize - kiWrittenLength - iSliceSize, |
| 657 | WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | 664 | pDst, &iNalSize); |
| 665 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) | ||
| 658 | pNalLen[iNalIdx] = iNalSize; | 666 | pNalLen[iNalIdx] = iNalSize; |
| 659 | iSliceSize += iNalSize; | 667 | iSliceSize += iNalSize; |
| 660 | pDst += iNalSize; | 668 | pDst += iNalSize; |
| @@ -702,7 +710,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 41 unmodified lines | |||
| 702 | "[MT] CodingSliceThreadProc(), try to call WelsMultipleEventsWaitSingleBlocking(pEventsList= %p %p %p), pEncPEncCtx= %p!\n", | 710 | "[MT] CodingSliceThreadProc(), try to call WelsMultipleEventsWaitSingleBlocking(pEventsList= %p %p %p), pEncPEncCtx= %p!\n", |
| 703 | pEventsList[0], pEventsList[1], pEventsList[1], (void*)pEncPEncCtx); | 711 | pEventsList[0], pEventsList[1], pEventsList[1], (void*)pEncPEncCtx); |
| 704 | iWaitRet = WelsMultipleEventsWaitSingleBlocking (iEventCount, | 712 | iWaitRet = WelsMultipleEventsWaitSingleBlocking (iEventCount, |
| 705 | &pEventsList[0], &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled | 713 | &pEventsList[0], |
| 714 | &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled | ||
| 706 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited | 715 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited |
| 707 | SLayerBSInfo* pLbi = pPrivateData->pLayerBs; | 716 | SLayerBSInfo* pLbi = pPrivateData->pLayerBs; |
| 708 | const int32_t kiCurDid = pEncPEncCtx->uiDependencyId; | 717 | const int32_t kiCurDid = pEncPEncCtx->uiDependencyId; |
| @@ -722,7 +731,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 13 unmodified lines | |||
| 722 | pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | 731 | pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; |
| 723 | pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; | 732 | pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; |
| 724 | 733 | ||
| 725 | bDsaFlag = (((pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pParamD->sSliceCfg.uiSliceMode == SM_AUTO_SLICE)) && | 734 | bDsaFlag = (((pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE) |
| 735 | || (pParamD->sSliceCfg.uiSliceMode == SM_AUTO_SLICE)) && | ||
| 726 | pCodingParam->iMultipleThreadIdc > 1 && | 736 | pCodingParam->iMultipleThreadIdc > 1 && |
| 727 | pCodingParam->iMultipleThreadIdc >= pParamD->sSliceCfg.sSliceArgument.uiSliceNum); | 737 | pCodingParam->iMultipleThreadIdc >= pParamD->sSliceCfg.sSliceArgument.uiSliceNum); |
| 728 | if (bDsaFlag) | 738 | if (bDsaFlag) |
| @@ -752,7 +762,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 23 unmodified lines | |||
| 752 | WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc); | 762 | WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc); |
| 753 | 763 | ||
| 754 | iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType); | 764 | iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType); |
| 755 | if (ENC_RETURN_SUCCESS!=iReturn) { | 765 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 756 | uiThrdRet = iReturn; | 766 | uiThrdRet = iReturn; |
| 757 | break; | 767 | break; |
| 758 | } | 768 | } |
| @@ -762,15 +772,14 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 3 unmodified lines | |||
| 762 | if (0 == iSliceIdx) { | 772 | if (0 == iSliceIdx) { |
| 763 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | 773 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; |
| 764 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, iSliceSize); | 774 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, iSliceSize); |
| 765 | if (ENC_RETURN_SUCCESS!=iReturn) { | 775 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 766 | uiThrdRet = iReturn; | 776 | uiThrdRet = iReturn; |
| 767 | break; | 777 | break; |
| 768 | } | 778 | } |
| 769 | pEncPEncCtx->iPosBsBuffer += iSliceSize; | 779 | pEncPEncCtx->iPosBsBuffer += iSliceSize; |
| 770 | } else | 780 | } else { |
| 771 | { | ||
| 772 | iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize); | 781 | iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize); |
| 773 | if (ENC_RETURN_SUCCESS!=iReturn) { | 782 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 774 | uiThrdRet = iReturn; | 783 | uiThrdRet = iReturn; |
| 775 | break; | 784 | break; |
| 776 | } | 785 | } |
| @@ -859,7 +868,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 82 unmodified lines | |||
| 859 | WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc); | 868 | WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc); |
| 860 | 869 | ||
| 861 | iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType); | 870 | iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType); |
| 862 | if (ENC_RETURN_SUCCESS!=iReturn) { | 871 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 863 | uiThrdRet = iReturn; | 872 | uiThrdRet = iReturn; |
| 864 | break; | 873 | break; |
| 865 | } | 874 | } |
| @@ -869,16 +878,16 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 3 unmodified lines | |||
| 869 | if (0 == kiPartitionId) { | 878 | if (0 == kiPartitionId) { |
| 870 | if (0 == iSliceIdx) | 879 | if (0 == iSliceIdx) |
| 871 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | 880 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; |
| 872 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx, iSliceSize); | 881 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx, |
| 873 | if (ENC_RETURN_SUCCESS!=iReturn) { | 882 | iSliceSize); |
| 883 | if (ENC_RETURN_SUCCESS != iReturn) { | ||
| 874 | uiThrdRet = iReturn; | 884 | uiThrdRet = iReturn; |
| 875 | break; | 885 | break; |
| 876 | } | 886 | } |
| 877 | pEncPEncCtx->iPosBsBuffer += iSliceSize; | 887 | pEncPEncCtx->iPosBsBuffer += iSliceSize; |
| 878 | } else | 888 | } else { |
| 879 | { | ||
| 880 | iSliceSize = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize); | 889 | iSliceSize = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize); |
| 881 | if (ENC_RETURN_SUCCESS!=iReturn) { | 890 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 882 | uiThrdRet = iReturn; | 891 | uiThrdRet = iReturn; |
| 883 | break; | 892 | break; |
| 884 | } | 893 | } |
| @@ -918,20 +927,17 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 33 unmodified lines | |||
| 918 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice | 927 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice |
| 919 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent); | 928 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent); |
| 920 | } | 929 | } |
| 921 | } | 930 | } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 1 == iWaitRet) { // exit thread signal |
| 922 | else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 1 == iWaitRet) { // exit thread signal | ||
| 923 | uiThrdRet = 0; | 931 | uiThrdRet = 0; |
| 924 | break; | 932 | break; |
| 925 | } | 933 | } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) { // update pMb list singal |
| 926 | else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) { // update pMb list singal | ||
| 927 | iSliceIdx = | 934 | iSliceIdx = |
| 928 | iEventIdx; // pPrivateData->iSliceIndex; old threads can not be terminated, pPrivateData is not correct for applicable | 935 | iEventIdx; // pPrivateData->iSliceIndex; old threads can not be terminated, pPrivateData is not correct for applicable |
| 929 | pCurDq = pEncPEncCtx->pCurDqLayer; | 936 | pCurDq = pEncPEncCtx->pCurDqLayer; |
| 930 | UpdateMbListNeighborParallel (pCurDq->pSliceEncCtx, pCurDq->sMbDataP, iSliceIdx); | 937 | UpdateMbListNeighborParallel (pCurDq->pSliceEncCtx, pCurDq->sMbDataP, iSliceIdx); |
| 931 | WelsEventSignal ( | 938 | WelsEventSignal ( |
| 932 | &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice | 939 | &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice |
| 933 | } | 940 | } else { // WELS_THREAD_ERROR_WAIT_TIMEOUT, or WELS_THREAD_ERROR_WAIT_FAILED |
| 934 | else { // WELS_THREAD_ERROR_WAIT_TIMEOUT, or WELS_THREAD_ERROR_WAIT_FAILED | ||
| 935 | WelsLog (pEncPEncCtx, WELS_LOG_WARNING, | 941 | WelsLog (pEncPEncCtx, WELS_LOG_WARNING, |
| 936 | "[MT] CodingSliceThreadProc(), waiting pReadySliceCodingEvent[%d] failed(%d) and thread%d terminated!\n", iEventIdx, | 942 | "[MT] CodingSliceThreadProc(), waiting pReadySliceCodingEvent[%d] failed(%d) and thread%d terminated!\n", iEventIdx, |
| 937 | iWaitRet, iThreadIdx); | 943 | iWaitRet, iThreadIdx); |
| @@ -962,9 +968,9 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 24 unmodified lines | |||
| 962 | return 0; | 968 | return 0; |
| 963 | } | 969 | } |
| 964 | 970 | ||
| 965 | int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLbi, | 971 | int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList, |
| 966 | const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) | 972 | SLayerBSInfo* pLbi, |
| 967 | { | 973 | const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) { |
| 968 | int32_t iEndMbIdx = 0; | 974 | int32_t iEndMbIdx = 0; |
| 969 | int32_t iIdx = 0; | 975 | int32_t iIdx = 0; |
| 970 | const int32_t kiEventCnt = uiNumThreads; | 976 | const int32_t kiEventCnt = uiNumThreads; |
| @@ -1044,9 +1050,9 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 73 unmodified lines | |||
| 1044 | // if using spatial base layer for complexity estimation | 1050 | // if using spatial base layer for complexity estimation |
| 1045 | 1051 | ||
| 1046 | const bool kbModelingFromSpatial = (pCtx->pCurDqLayer->pRefLayer != NULL && iCurDid > 0) | 1052 | const bool kbModelingFromSpatial = (pCtx->pCurDqLayer->pRefLayer != NULL && iCurDid > 0) |
| 1047 | && (pCtx->pSvcParam->sDependencyLayers[iCurDid - 1].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE | 1053 | && (pCtx->pSvcParam->sDependencyLayers[iCurDid - 1].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE |
| 1048 | && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sDependencyLayers[iCurDid - | 1054 | && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sDependencyLayers[iCurDid - |
| 1049 | 1].sSliceCfg.sSliceArgument.uiSliceNum); | 1055 | 1].sSliceCfg.sSliceArgument.uiSliceNum); |
| 1050 | 1056 | ||
| 1051 | if (kbModelingFromSpatial) { // using spatial base layer for complexity estimation | 1057 | if (kbModelingFromSpatial) { // using spatial base layer for complexity estimation |
| 1052 | // do not need adjust due to not different at both slices of consumed time | 1058 | // do not need adjust due to not different at both slices of consumed time |
| @@ -1116,7 +1122,7 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 63 unmodified lines | |||
| 1116 | const uint32_t kuiCountSliceNum = pSliceCtx->iSliceNumInFrame; | 1122 | const uint32_t kuiCountSliceNum = pSliceCtx->iSliceNumInFrame; |
| 1117 | if (pCtx->pSliceThreading) { | 1123 | if (pCtx->pSliceThreading) { |
| 1118 | if (pCtx->pSliceThreading->pFSliceDiff | 1124 | if (pCtx->pSliceThreading->pFSliceDiff |
| 1119 | && ((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE)||(pMso->uiSliceMode == SM_AUTO_SLICE)) | 1125 | && ((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE) || (pMso->uiSliceMode == SM_AUTO_SLICE)) |
| 1120 | && pPara->iMultipleThreadIdc > 1 | 1126 | && pPara->iMultipleThreadIdc > 1 |
| 1121 | && pPara->iMultipleThreadIdc >= kuiCountSliceNum) { | 1127 | && pPara->iMultipleThreadIdc >= kuiCountSliceNum) { |
| 1122 | uint32_t i = 0; | 1128 | uint32_t i = 0; |