Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 15 files). Show all
Unified · Split
| @@ -333,6 +333,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 332 unmodified lines | |||
| 333 | int32_t iIdx = 0; | 333 | int32_t iIdx = 0; |
| 334 | int16_t iMaxSliceNum = 1; | 334 | int16_t iMaxSliceNum = 1; |
| 335 | int32_t iReturn = ENC_RETURN_SUCCESS; | 335 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 336 | bool bWillUseTaskManage = false; | ||
| 336 | 337 | ||
| 337 | if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0) | 338 | if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0) |
| 338 | return 1; | 339 | return 1; |
| @@ -372,6 +373,10 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 33 unmodified lines | |||
| 372 | pSmt->pSliceConsumeTime[iIdx] = NULL; | 373 | pSmt->pSliceConsumeTime[iIdx] = NULL; |
| 373 | pSmt->pSliceComplexRatio[iIdx] = NULL; | 374 | pSmt->pSliceComplexRatio[iIdx] = NULL; |
| 374 | } | 375 | } |
| 376 | |||
| 377 | if ( pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pMso->uiSliceMode == SM_RASTER_SLICE || pMso->uiSliceMode == SM_ROWMB_SLICE) { | ||
| 378 | bWillUseTaskManage = true; | ||
| 379 | } | ||
| 375 | ++ iIdx; | 380 | ++ iIdx; |
| 376 | } | 381 | } |
| 377 | // NULL for pSliceConsumeTime[iIdx]: iIdx from iNumSpatialLayers to MAX_DEPENDENCY_LAYERS | 382 | // NULL for pSliceConsumeTime[iIdx]: iIdx from iNumSpatialLayers to MAX_DEPENDENCY_LAYERS |
| @@ -430,9 +435,11 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 52 unmodified lines | |||
| 430 | pSmt->pThreadBsBuffer[iIdx] = NULL; | 435 | pSmt->pThreadBsBuffer[iIdx] = NULL; |
| 431 | } | 436 | } |
| 432 | 437 | ||
| 438 | //previous conflict | ||
| 433 | WelsSnprintf (name, SEM_NAME_MAX, "scm%s", pSmt->eventNamespace); | 439 | WelsSnprintf (name, SEM_NAME_MAX, "scm%s", pSmt->eventNamespace); |
| 434 | err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name); | 440 | err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name); |
| 435 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno); | 441 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno); |
| 442 | //previous conflict ends | ||
| 436 | 443 | ||
| 437 | 444 | ||
| 438 | iReturn = SetMultiSliceBuffer (ppCtx, pMa, pSmt, iMaxSliceNum, | 445 | iReturn = SetMultiSliceBuffer (ppCtx, pMa, pSmt, iMaxSliceNum, |
| @@ -444,6 +451,11 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 5 unmodified lines | |||
| 444 | iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate); | 451 | iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate); |
| 445 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) | 452 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) |
| 446 | 453 | ||
| 454 | if (bWillUseTaskManage) { | ||
| 455 | (*ppCtx)->pTaskManage = IWelsTaskManage::CreateTaskManage(*ppCtx, bDynamicSlice); | ||
| 456 | WELS_VERIFY_RETURN_PROC_IF (iReturn, (NULL == (*ppCtx)->pTaskManage), FreeMemorySvc (ppCtx)) | ||
| 457 | } | ||
| 458 | |||
| 447 | memset(&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof(bool)); | 459 | memset(&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof(bool)); |
| 448 | iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage); | 460 | iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage); |
| 449 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) | 461 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) |
| @@ -530,6 +542,12 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 80 unmodified lines | |||
| 530 | pMa->WelsFree ((*ppCtx)->pSliceBs, "pSliceBs"); | 542 | pMa->WelsFree ((*ppCtx)->pSliceBs, "pSliceBs"); |
| 531 | (*ppCtx)->pSliceBs = NULL; | 543 | (*ppCtx)->pSliceBs = NULL; |
| 532 | } | 544 | } |
| 545 | |||
| 546 | if ((*ppCtx)->pTaskManage != NULL) { | ||
| 547 | delete (*ppCtx)->pTaskManage; | ||
| 548 | (*ppCtx)->pTaskManage = NULL; | ||
| 549 | } | ||
| 550 | |||
| 533 | iIdx = 0; | 551 | iIdx = 0; |
| 534 | while (iIdx < pCodingParam->iSpatialLayerNum) { | 552 | while (iIdx < pCodingParam->iSpatialLayerNum) { |
| 535 | if (pSmt->pSliceConsumeTime[iIdx]) { | 553 | if (pSmt->pSliceConsumeTime[iIdx]) { |
| @@ -1171,6 +1189,7 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 635 unmodified lines | |||
| 1171 | void SetOneSliceBsBufferUnderMultithread (sWelsEncCtx* pCtx, const int32_t kiThreadIdx, const int32_t iSliceIdx) { | 1189 | void SetOneSliceBsBufferUnderMultithread (sWelsEncCtx* pCtx, const int32_t kiThreadIdx, const int32_t iSliceIdx) { |
| 1172 | pCtx->pSliceBs[iSliceIdx].pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx]; | 1190 | pCtx->pSliceBs[iSliceIdx].pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx]; |
| 1173 | pCtx->pSliceBs[iSliceIdx].uiBsPos = 0; | 1191 | pCtx->pSliceBs[iSliceIdx].uiBsPos = 0; |
| 1192 | //printf("SetOneSliceBsBufferUnderMultithread, thread %d, slice %d, buffer=%x\n", kiThreadIdx, iSliceIdx, pCtx->pSliceBs[iSliceIdx].pBsBuffer); | ||
| 1174 | } | 1193 | } |
| 1175 | } | 1194 | } |
| 1176 | 1195 | ||