Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 5 files). Show all
Unified · Split
| @@ -63,9 +63,7 @@ · 62 unmodified lines | |||
| 63 | #include "cpu.h" | 63 | #include "cpu.h" |
| 64 | #endif//X86_ASM | 64 | #endif//X86_ASM |
| 65 | 65 | ||
| 66 | #if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG) | ||
| 67 | #include "measure_time.h" | 66 | #include "measure_time.h" |
| 68 | #endif//DYNAMIC_SLICE_ASSIGN | ||
| 69 | namespace WelsSVCEnc { | 67 | namespace WelsSVCEnc { |
| 70 | void UpdateMbListNeighborParallel (SSliceCtx* pSliceCtx, | 68 | void UpdateMbListNeighborParallel (SSliceCtx* pSliceCtx, |
| 71 | SMB* pMbList, | 69 | SMB* pMbList, |
| @@ -144,12 +142,8 @@ void CalcSliceComplexRatio (void* pRatio, SSliceCtx* pSliceCtx, uint32_t* pSlice · 72 unmodified lines | |||
| 144 | } | 142 | } |
| 145 | } | 143 | } |
| 146 | 144 | ||
| 147 | #if defined(MT_ENABLED) && defined(DYNAMIC_SLICE_ASSIGN) && defined(NOT_ABSOLUTE_BALANCING) | 145 | #if defined(MT_ENABLED) |
| 148 | int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { | 146 | int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { |
| 149 | #if !defined(USE_RMSE_SLICE_COMPLEXITY_RATIO_FOR_BALANCING) | ||
| 150 | const float fRatioLower = TOLERANT_BALANCING_RATIO_LOWER (uiSliceNum); | ||
| 151 | const float fRatioUpper = TOLERANT_BALANCING_RATIO_UPPER (uiSliceNum); | ||
| 152 | #endif//USE_RMSE_SLICE_COMPLEXITY_RATIO_FOR_BALANCING | ||
| 153 | uint32_t* pSliceConsume = (uint32_t*)pConsumeTime; | 147 | uint32_t* pSliceConsume = (uint32_t*)pConsumeTime; |
| 154 | uint32_t uiTotalConsume = 0; | 148 | uint32_t uiTotalConsume = 0; |
| 155 | int32_t iSliceIdx = 0; | 149 | int32_t iSliceIdx = 0; |
| @@ -172,7 +166,6 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 16 unmodified lines | |||
| 172 | } | 166 | } |
| 173 | 167 | ||
| 174 | iSliceIdx = 0; | 168 | iSliceIdx = 0; |
| 175 | #if defined(USE_RMSE_SLICE_COMPLEXITY_RATIO_FOR_BALANCING) | ||
| 176 | float fThr = EPSN; // threshold for various cores cases | 169 | float fThr = EPSN; // threshold for various cores cases |
| 177 | float fRmse = .0f; // root mean square error of pSlice consume ratios | 170 | float fRmse = .0f; // root mean square error of pSlice consume ratios |
| 178 | const float kfMeanRatio = 1.0f / iSliceNum; | 171 | const float kfMeanRatio = 1.0f / iSliceNum; |
| @@ -198,27 +191,11 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 19 unmodified lines | |||
| 198 | "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n", | 191 | "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n", |
| 199 | iNeedAdj, fRmse, fThr, iSliceNum); | 192 | iNeedAdj, fRmse, fThr, iSliceNum); |
| 200 | #endif//ENABLE_TRACE_MT | 193 | #endif//ENABLE_TRACE_MT |
| 201 | #else | ||
| 202 | do { | ||
| 203 | const float kfRatio = 1.0f * pSliceConsume[uiSliceIdx] / uiTotalConsume; | ||
| 204 | if (kfRatio + EPSN < fRatioLower || kfRatio > ratio_upper + EPSN) { | ||
| 205 | #if defined(ENABLE_TRACE_MT) | ||
| 206 | WelsLog (NULL, WELS_LOG_DEBUG, | ||
| 207 | "[MT] NeedDynamicAdjust(), herein adjustment decision is made by pSlice consume time not balanced at all, uiSliceIdx= %d, comp_ratio= %.6f, pSliceConsumeTime= %d, total_consume_time= %d, iCountSliceNum= %d\n", | ||
| 208 | uiSliceIdx, kfRatio, pSliceConsume[uiSliceIdx], uiTotalConsume, uiSliceNum); | ||
| 209 | #endif//ENABLE_TRACE_MT | ||
| 210 | iNeedAdj = true; | ||
| 211 | break; | ||
| 212 | } | ||
| 213 | ++ uiSliceIdx; | ||
| 214 | } while (uiSliceIdx + 1 < uiSliceNum); | ||
| 215 | #endif//USE_RMSE_SLICE_COMPLEXITY_RATIO_FOR_BALANCING | ||
| 216 | 194 | ||
| 217 | return iNeedAdj; | 195 | return iNeedAdj; |
| 218 | } | 196 | } |
| 219 | #endif//.. | 197 | #endif |
| 220 | 198 | ||
| 221 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 222 | void DynamicAdjustSlicing (sWelsEncCtx* pCtx, | 199 | void DynamicAdjustSlicing (sWelsEncCtx* pCtx, |
| 223 | SDqLayer* pCurDqLayer, | 200 | SDqLayer* pCurDqLayer, |
| 224 | void* pComplexRatio, | 201 | void* pComplexRatio, |
| @@ -320,20 +297,7 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 95 unmodified lines | |||
| 320 | WelsMultipleEventsWaitAllBlocking (kiThreadNum, &pCtx->pSliceThreading->pFinUpdateMbListEvent[0]); | 297 | WelsMultipleEventsWaitAllBlocking (kiThreadNum, &pCtx->pSliceThreading->pFinUpdateMbListEvent[0]); |
| 321 | } | 298 | } |
| 322 | } | 299 | } |
| 323 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 324 | 300 | ||
| 325 | #ifdef PACKING_ONE_SLICE_PER_LAYER | ||
| 326 | void ResetEnvMt (sWelsEncCtx* pCtx) { | ||
| 327 | const int16_t kiSliceCount = pCtx->iMaxSliceCount; | ||
| 328 | int32_t iIdx = 0; | ||
| 329 | |||
| 330 | while (iIdx < kiSliceCount) { | ||
| 331 | SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iIdx]; | ||
| 332 | pSliceBs->uiBsPos = 0; | ||
| 333 | ++ iIdx; | ||
| 334 | } | ||
| 335 | } | ||
| 336 | #endif//PACKING_ONE_SLICE_PER_LAYER | ||
| 337 | 301 | ||
| 338 | int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen, | 302 | int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen, |
| 339 | const int32_t iTargetSpatialBsSize) { | 303 | const int32_t iTargetSpatialBsSize) { |
| @@ -378,7 +342,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 38 unmodified lines | |||
| 378 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pFinSliceCodingEvent), FreeMemorySvc (ppCtx)) | 342 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pFinSliceCodingEvent), FreeMemorySvc (ppCtx)) |
| 379 | #endif//_WIN32 | 343 | #endif//_WIN32 |
| 380 | 344 | ||
| 381 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 382 | #if defined(__GNUC__) | 345 | #if defined(__GNUC__) |
| 383 | pSmt->pUpdateMbListThrdHandles = (WELS_THREAD_HANDLE*)pMa->WelsMalloc (sizeof (WELS_THREAD_HANDLE) * iThreadNum, | 346 | pSmt->pUpdateMbListThrdHandles = (WELS_THREAD_HANDLE*)pMa->WelsMalloc (sizeof (WELS_THREAD_HANDLE) * iThreadNum, |
| 384 | "pUpdateMbListThrdHandles"); | 347 | "pUpdateMbListThrdHandles"); |
| @@ -390,14 +353,12 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 5 unmodified lines | |||
| 390 | pSmt->pFinUpdateMbListEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pFinUpdateMbListEvent"); | 353 | pSmt->pFinUpdateMbListEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pFinUpdateMbListEvent"); |
| 391 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pFinUpdateMbListEvent), FreeMemorySvc (ppCtx)) | 354 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pFinUpdateMbListEvent), FreeMemorySvc (ppCtx)) |
| 392 | #endif//_WIN32 | 355 | #endif//_WIN32 |
| 393 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 394 | 356 | ||
| 395 | #ifdef _WIN32 | 357 | #ifdef _WIN32 |
| 396 | pSmt->pExitEncodeEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pExitEncodeEvent"); | 358 | pSmt->pExitEncodeEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pExitEncodeEvent"); |
| 397 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pExitEncodeEvent), FreeMemorySvc (ppCtx)) | 359 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pExitEncodeEvent), FreeMemorySvc (ppCtx)) |
| 398 | #endif//_WIN32 | 360 | #endif//_WIN32 |
| 399 | 361 | ||
| 400 | #if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG) | ||
| 401 | iIdx = 0; | 362 | iIdx = 0; |
| 402 | while (iIdx < iNumSpatialLayers) { | 363 | while (iIdx < iNumSpatialLayers) { |
| 403 | SSliceConfig* pMso = &pPara->sDependencyLayers[iIdx].sSliceCfg; | 364 | SSliceConfig* pMso = &pPara->sDependencyLayers[iIdx].sSliceCfg; |
| @@ -406,20 +367,15 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 2 unmodified lines | |||
| 406 | && pPara->iMultipleThreadIdc >= kiSliceNum) { | 367 | && pPara->iMultipleThreadIdc >= kiSliceNum) { |
| 407 | pSmt->pSliceConsumeTime[iIdx] = (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]"); | 368 | pSmt->pSliceConsumeTime[iIdx] = (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]"); |
| 408 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx)) | 369 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx)) |
| 409 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 410 | pSmt->pSliceComplexRatio[iIdx] = (float*)pMa->WelsMalloc (kiSliceNum * sizeof (float), "pSliceComplexRatio[]"); | 370 | pSmt->pSliceComplexRatio[iIdx] = (float*)pMa->WelsMalloc (kiSliceNum * sizeof (float), "pSliceComplexRatio[]"); |
| 411 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceComplexRatio[iIdx]), FreeMemorySvc (ppCtx)) | 371 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceComplexRatio[iIdx]), FreeMemorySvc (ppCtx)) |
| 412 | #endif//TRY_SLICING_BALANCE | ||
| 413 | } else { | 372 | } else { |
| 414 | pSmt->pSliceConsumeTime[iIdx] = NULL; | 373 | pSmt->pSliceConsumeTime[iIdx] = NULL; |
| 415 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 416 | pSmt->pSliceComplexRatio[iIdx] = NULL; | 374 | pSmt->pSliceComplexRatio[iIdx] = NULL; |
| 417 | #endif//TRY_SLICING_BALANCE | ||
| 418 | } | 375 | } |
| 419 | ++ iIdx; | 376 | ++ iIdx; |
| 420 | } | 377 | } |
| 421 | // NULL for pSliceConsumeTime[iIdx]: iIdx from iNumSpatialLayers to MAX_DEPENDENCY_LAYERS | 378 | // NULL for pSliceConsumeTime[iIdx]: iIdx from iNumSpatialLayers to MAX_DEPENDENCY_LAYERS |
| 422 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG) | ||
| 423 | 379 | ||
| 424 | #ifdef MT_DEBUG | 380 | #ifdef MT_DEBUG |
| 425 | // file handle for MT debug | 381 | // file handle for MT debug |
| @@ -447,7 +403,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 21 unmodified lines | |||
| 447 | pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx; | 403 | pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx; |
| 448 | pSmt->pThreadHandles[iIdx] = 0; | 404 | pSmt->pThreadHandles[iIdx] = 0; |
| 449 | 405 | ||
| 450 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 451 | #ifdef _WIN32 | 406 | #ifdef _WIN32 |
| 452 | WelsEventInit (&pSmt->pUpdateMbListEvent[iIdx]); | 407 | WelsEventInit (&pSmt->pUpdateMbListEvent[iIdx]); |
| 453 | WelsEventInit (&pSmt->pFinUpdateMbListEvent[iIdx]); | 408 | WelsEventInit (&pSmt->pFinUpdateMbListEvent[iIdx]); |
| @@ -464,7 +419,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 10 unmodified lines | |||
| 464 | WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); | 419 | WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); |
| 465 | #endif | 420 | #endif |
| 466 | #endif//_WIN32 | 421 | #endif//_WIN32 |
| 467 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 468 | 422 | ||
| 469 | #ifdef _WIN32 | 423 | #ifdef _WIN32 |
| 470 | WelsEventInit (&pSmt->pSliceCodedEvent[iIdx]); | 424 | WelsEventInit (&pSmt->pSliceCodedEvent[iIdx]); |
| @@ -488,11 +442,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 17 unmodified lines | |||
| 488 | ++ iIdx; | 442 | ++ iIdx; |
| 489 | } | 443 | } |
| 490 | 444 | ||
| 491 | #ifdef PACKING_ONE_SLICE_PER_LAYER | ||
| 492 | pSmt->pCountBsSizeInPartition = (uint32_t*)pMa->WelsMalloc (sizeof (uint32_t) * iThreadNum, "pCountBsSizeInPartition"); | ||
| 493 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pCountBsSizeInPartition), FreeMemorySvc (ppCtx)) | ||
| 494 | #endif//PACKING_ONE_SLICE_PER_LAYER | ||
| 495 | |||
| 496 | (*ppCtx)->pSliceBs = (SWelsSliceBs*)pMa->WelsMalloc (sizeof (SWelsSliceBs) * iMaxSliceNum, "pSliceBs"); | 445 | (*ppCtx)->pSliceBs = (SWelsSliceBs*)pMa->WelsMalloc (sizeof (SWelsSliceBs) * iMaxSliceNum, "pSliceBs"); |
| 497 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSliceBs), FreeMemorySvc (ppCtx)) | 446 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSliceBs), FreeMemorySvc (ppCtx)) |
| 498 | 447 | ||
| @@ -566,12 +515,10 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 67 unmodified lines | |||
| 566 | WelsEventDestroy (&pSmt->pFinSliceCodingEvent[iIdx]); | 515 | WelsEventDestroy (&pSmt->pFinSliceCodingEvent[iIdx]); |
| 567 | if (pSmt->pExitEncodeEvent != NULL) | 516 | if (pSmt->pExitEncodeEvent != NULL) |
| 568 | WelsEventDestroy (&pSmt->pExitEncodeEvent[iIdx]); | 517 | WelsEventDestroy (&pSmt->pExitEncodeEvent[iIdx]); |
| 569 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 570 | if (pSmt->pUpdateMbListEvent != NULL) | 518 | if (pSmt->pUpdateMbListEvent != NULL) |
| 571 | WelsEventDestroy (&pSmt->pUpdateMbListEvent[iIdx]); | 519 | WelsEventDestroy (&pSmt->pUpdateMbListEvent[iIdx]); |
| 572 | if (pSmt->pFinUpdateMbListEvent != NULL) | 520 | if (pSmt->pFinUpdateMbListEvent != NULL) |
| 573 | WelsEventDestroy (&pSmt->pFinUpdateMbListEvent[iIdx]); | 521 | WelsEventDestroy (&pSmt->pFinUpdateMbListEvent[iIdx]); |
| 574 | #endif//DYNAMIC_SLICE_ASSIGN && TRY_SLICING_BALANCE | ||
| 575 | #else | 522 | #else |
| 576 | char ename[SEM_NAME_MAX] = {0}; | 523 | char ename[SEM_NAME_MAX] = {0}; |
| 577 | // length of semaphore name should be system constrained at least on mac 10.7 | 524 | // length of semaphore name should be system constrained at least on mac 10.7 |
| @@ -579,12 +526,10 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 1 unmodified line | |||
| 579 | WelsEventClose (pSmt->pSliceCodedEvent[iIdx], ename); | 526 | WelsEventClose (pSmt->pSliceCodedEvent[iIdx], ename); |
| 580 | WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx)); | 527 | WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx)); |
| 581 | WelsEventClose (pSmt->pReadySliceCodingEvent[iIdx], ename); | 528 | WelsEventClose (pSmt->pReadySliceCodingEvent[iIdx], ename); |
| 582 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 583 | WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx)); | 529 | WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx)); |
| 584 | WelsEventClose (pSmt->pUpdateMbListEvent[iIdx], ename); | 530 | WelsEventClose (pSmt->pUpdateMbListEvent[iIdx], ename); |
| 585 | WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx)); | 531 | WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx)); |
| 586 | WelsEventClose (pSmt->pFinUpdateMbListEvent[iIdx], ename); | 532 | WelsEventClose (pSmt->pFinUpdateMbListEvent[iIdx], ename); |
| 587 | #endif//DYNAMIC_SLICE_ASSIGN && TRY_SLICING_BALANCE | ||
| 588 | #endif//_WIN32 | 533 | #endif//_WIN32 |
| 589 | 534 | ||
| 590 | ++ iIdx; | 535 | ++ iIdx; |
| @@ -609,13 +554,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 18 unmodified lines | |||
| 609 | } | 554 | } |
| 610 | #endif//_WIN32 | 555 | #endif//_WIN32 |
| 611 | 556 | ||
| 612 | #ifdef PACKING_ONE_SLICE_PER_LAYER | ||
| 613 | if (NULL != pSmt->pCountBsSizeInPartition) { | ||
| 614 | pMa->WelsFree (pSmt->pCountBsSizeInPartition, "pCountBsSizeInPartition"); | ||
| 615 | pSmt->pCountBsSizeInPartition = NULL; | ||
| 616 | } | ||
| 617 | #endif//PACKING_ONE_SLICE_PER_LAYER | ||
| 618 | |||
| 619 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); | 557 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); |
| 620 | WelsMutexDestroy (&((*ppCtx)->mutexEncoderError)); | 558 | WelsMutexDestroy (&((*ppCtx)->mutexEncoderError)); |
| 621 | 559 | ||
| @@ -643,24 +581,18 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 21 unmodified lines | |||
| 643 | pMa->WelsFree ((*ppCtx)->pSliceBs, "pSliceBs"); | 581 | pMa->WelsFree ((*ppCtx)->pSliceBs, "pSliceBs"); |
| 644 | (*ppCtx)->pSliceBs = NULL; | 582 | (*ppCtx)->pSliceBs = NULL; |
| 645 | } | 583 | } |
| 646 | #if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG) | ||
| 647 | iIdx = 0; | 584 | iIdx = 0; |
| 648 | while (iIdx < pCodingParam->iSpatialLayerNum) { | 585 | while (iIdx < pCodingParam->iSpatialLayerNum) { |
| 649 | if (pSmt->pSliceConsumeTime[iIdx]) { | 586 | if (pSmt->pSliceConsumeTime[iIdx]) { |
| 650 | pMa->WelsFree (pSmt->pSliceConsumeTime[iIdx], "pSliceConsumeTime[]"); | 587 | pMa->WelsFree (pSmt->pSliceConsumeTime[iIdx], "pSliceConsumeTime[]"); |
| 651 | pSmt->pSliceConsumeTime[iIdx] = NULL; | 588 | pSmt->pSliceConsumeTime[iIdx] = NULL; |
| 652 | } | 589 | } |
| 653 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 654 | if (pSmt->pSliceComplexRatio[iIdx] != NULL) { | 590 | if (pSmt->pSliceComplexRatio[iIdx] != NULL) { |
| 655 | pMa->WelsFree (pSmt->pSliceComplexRatio[iIdx], "pSliceComplexRatio[]"); | 591 | pMa->WelsFree (pSmt->pSliceComplexRatio[iIdx], "pSliceComplexRatio[]"); |
| 656 | pSmt->pSliceComplexRatio[iIdx] = NULL; | 592 | pSmt->pSliceComplexRatio[iIdx] = NULL; |
| 657 | } | 593 | } |
| 658 | #endif//TRY_SLICING_BALANCE | ||
| 659 | ++ iIdx; | 594 | ++ iIdx; |
| 660 | } | 595 | } |
| 661 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG) | ||
| 662 | |||
| 663 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 664 | 596 | ||
| 665 | #ifdef _WIN32 | 597 | #ifdef _WIN32 |
| 666 | if (pSmt->pUpdateMbListEvent != NULL) { | 598 | if (pSmt->pUpdateMbListEvent != NULL) { |
| @@ -678,8 +610,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 11 unmodified lines | |||
| 678 | } | 610 | } |
| 679 | #endif//_WIN32 | 611 | #endif//_WIN32 |
| 680 | 612 | ||
| 681 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 682 | |||
| 683 | #ifdef MT_DEBUG | 613 | #ifdef MT_DEBUG |
| 684 | // file handle for debug | 614 | // file handle for debug |
| 685 | if (pSmt->pFSliceDiff) { | 615 | if (pSmt->pFSliceDiff) { |
| @@ -781,12 +711,8 @@ int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFr · 95 unmodified lines | |||
| 781 | const int32_t kiNalCnt = pSliceBs->iNalIndex; | 711 | const int32_t kiNalCnt = pSliceBs->iNalIndex; |
| 782 | int32_t iNalIdx = 0; | 712 | int32_t iNalIdx = 0; |
| 783 | int32_t iNalSize = 0; | 713 | int32_t iNalSize = 0; |
| 784 | #if !defined(PACKING_ONE_SLICE_PER_LAYER) | ||
| 785 | const int32_t iFirstSlice = (iSliceIdx == 0); | 714 | const int32_t iFirstSlice = (iSliceIdx == 0); |
| 786 | int32_t iNalBase = iFirstSlice ? 0 : pLbi->iNalCount; | 715 | int32_t iNalBase = iFirstSlice ? 0 : pLbi->iNalCount; |
| 787 | #else | ||
| 788 | int32_t iNalBase = 0; | ||
| 789 | #endif//!PACKING_ONE_SLICE_PER_LAYER | ||
| 790 | int32_t iReturn = ENC_RETURN_SUCCESS; | 716 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 791 | const int32_t kiWrittenLength = pCtx->iPosBsBuffer; | 717 | const int32_t kiWrittenLength = pCtx->iPosBsBuffer; |
| 792 | iSliceSize = 0; | 718 | iSliceSize = 0; |
| @@ -803,7 +729,6 @@ int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFr · 10 unmodified lines | |||
| 803 | ++ iNalIdx; | 729 | ++ iNalIdx; |
| 804 | } | 730 | } |
| 805 | 731 | ||
| 806 | #if !defined(PACKING_ONE_SLICE_PER_LAYER) | ||
| 807 | pSliceBs->uiBsPos = iSliceSize; | 732 | pSliceBs->uiBsPos = iSliceSize; |
| 808 | if (iFirstSlice) { | 733 | if (iFirstSlice) { |
| 809 | // pBsBuffer has been updated at coding_slice_0_in_encoder_mother_thread() | 734 | // pBsBuffer has been updated at coding_slice_0_in_encoder_mother_thread() |
| @@ -816,14 +741,6 @@ int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFr · 6 unmodified lines | |||
| 816 | } else { | 741 | } else { |
| 817 | pLbi->iNalCount += kiNalCnt; | 742 | pLbi->iNalCount += kiNalCnt; |
| 818 | } | 743 | } |
| 819 | #else | ||
| 820 | pLbi->uiLayerType = VIDEO_CODING_LAYER; | ||
| 821 | pLbi->uiSpatialId = pNalHdrExt->uiDependencyId; | ||
| 822 | pLbi->uiTemporalId = pNalHdrExt->uiTemporalId; | ||
| 823 | pLbi->uiQualityId = 0; | ||
| 824 | pLbi->uiPriorityId = 0; | ||
| 825 | pLbi->iNalCount = kiNalCnt; | ||
| 826 | #endif//PACKING_ONE_SLICE_PER_LAYER | ||
| 827 | 744 | ||
| 828 | return ENC_RETURN_SUCCESS; | 745 | return ENC_RETURN_SUCCESS; |
| 829 | } | 746 | } |
| @@ -858,7 +775,6 @@ int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSl · 28 unmodified lines | |||
| 858 | return iReturn; | 775 | return iReturn; |
| 859 | } | 776 | } |
| 860 | 777 | ||
| 861 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 862 | #if defined(__GNUC__) && !defined(_WIN32) | 778 | #if defined(__GNUC__) && !defined(_WIN32) |
| 863 | WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg) { | 779 | WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg) { |
| 864 | SSliceThreadPrivateData* pPrivateData = (SSliceThreadPrivateData*)arg; | 780 | SSliceThreadPrivateData* pPrivateData = (SSliceThreadPrivateData*)arg; |
| @@ -899,7 +815,6 @@ WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg) { · 34 unmodified lines | |||
| 899 | WELS_THREAD_ROUTINE_RETURN (uiThrdRet); | 815 | WELS_THREAD_ROUTINE_RETURN (uiThrdRet); |
| 900 | } | 816 | } |
| 901 | #endif//__GNUC__ | 817 | #endif//__GNUC__ |
| 902 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 903 | 818 | ||
| 904 | // thread process for coding one pSlice | 819 | // thread process for coding one pSlice |
| 905 | WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { | 820 | WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { |
| @@ -936,9 +851,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 30 unmodified lines | |||
| 936 | #ifdef _WIN32 | 851 | #ifdef _WIN32 |
| 937 | pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]; | 852 | pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]; |
| 938 | pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pExitEncodeEvent[iEventIdx]; | 853 | pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pExitEncodeEvent[iEventIdx]; |
| 939 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 940 | pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx]; | 854 | pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx]; |
| 941 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 942 | #endif//_WIN32 | 855 | #endif//_WIN32 |
| 943 | 856 | ||
| 944 | do { | 857 | do { |
| @@ -973,17 +886,13 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 28 unmodified lines | |||
| 973 | pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | 886 | pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; |
| 974 | pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; | 887 | pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; |
| 975 | 888 | ||
| 976 | #if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG) | ||
| 977 | bDsaFlag = (pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE && | 889 | bDsaFlag = (pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE && |
| 978 | pCodingParam->iMultipleThreadIdc > 1 && | 890 | pCodingParam->iMultipleThreadIdc > 1 && |
| 979 | pCodingParam->iMultipleThreadIdc >= pParamD->sSliceCfg.sSliceArgument.uiSliceNum); | 891 | pCodingParam->iMultipleThreadIdc >= pParamD->sSliceCfg.sSliceArgument.uiSliceNum); |
| 980 | if (bDsaFlag) | 892 | if (bDsaFlag) |
| 981 | iSliceStart = WelsTime(); | 893 | iSliceStart = WelsTime(); |
| 982 | #endif//DYNAMIC_SLICE_ASSIGN || MT_DEBUG | ||
| 983 | 894 | ||
| 984 | #if !defined(PACKING_ONE_SLICE_PER_LAYER) | ||
| 985 | pSliceBs->uiBsPos = 0; | 895 | pSliceBs->uiBsPos = 0; |
| 986 | #endif//!PACKING_ONE_SLICE_PER_LAYER | ||
| 987 | pSliceBs->iNalIndex = 0; | 896 | pSliceBs->iNalIndex = 0; |
| 988 | assert ((void*) (&pSliceBs->sBsWrite) == (void*)pSlice->pSliceBsa); | 897 | assert ((void*) (&pSliceBs->sBsWrite) == (void*)pSlice->pSliceBsa); |
| 989 | InitBits (&pSliceBs->sBsWrite, pSliceBs->pBsBuffer, pSliceBs->uiSize); | 898 | InitBits (&pSliceBs->sBsWrite, pSliceBs->pBsBuffer, pSliceBs->uiSize); |
| @@ -1014,7 +923,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 24 unmodified lines | |||
| 1014 | 923 | ||
| 1015 | WelsUnloadNalForSlice (pSliceBs); | 924 | WelsUnloadNalForSlice (pSliceBs); |
| 1016 | 925 | ||
| 1017 | #if !defined(PACKING_ONE_SLICE_PER_LAYER) | ||
| 1018 | if (0 == iSliceIdx) { | 926 | if (0 == iSliceIdx) { |
| 1019 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | 927 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; |
| 1020 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, iSliceSize); | 928 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, iSliceSize); |
| @@ -1031,25 +939,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 10 unmodified lines | |||
| 1031 | break; | 939 | break; |
| 1032 | } | 940 | } |
| 1033 | } | 941 | } |
| 1034 | #else// PACKING_ONE_SLICE_PER_LAYER | ||
| 1035 | if (0 == iSliceIdx) { | ||
| 1036 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | ||
| 1037 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, &iSliceSize); | ||
| 1038 | if (ENC_RETURN_SUCCESS!=iReturn) { | ||
| 1039 | uiThrdRet = iReturn; | ||
| 1040 | break; | ||
| 1041 | } | ||
| 1042 | pEncPEncCtx->iPosBsBuffer += iSliceSize; | ||
| 1043 | } else { | ||
| 1044 | pLbi->pBsBuf = pSliceBs->bs + pSliceBs->uiBsPos; | ||
| 1045 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, &iSliceSize); | ||
| 1046 | if (ENC_RETURN_SUCCESS!=iReturn) { | ||
| 1047 | uiThrdRet = iReturn; | ||
| 1048 | break; | ||
| 1049 | } | ||
| 1050 | pSliceBs->uiBsPos += iSliceSize; | ||
| 1051 | } | ||
| 1052 | #endif//!PACKING_ONE_SLICE_PER_LAYER | ||
| 1053 | 942 | ||
| 1054 | if (pCurDq->bDeblockingParallelFlag && pSlice->sSliceHeaderExt.sSliceHeader.uiDisableDeblockingFilterIdc != 1 | 943 | if (pCurDq->bDeblockingParallelFlag && pSlice->sSliceHeaderExt.sSliceHeader.uiDisableDeblockingFilterIdc != 1 |
| 1055 | #if !defined(ENABLE_FRAME_DUMP) | 944 | #if !defined(ENABLE_FRAME_DUMP) |
| @@ -1060,7 +949,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 4 unmodified lines | |||
| 1060 | DeblockingFilterSliceAvcbase (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); | 949 | DeblockingFilterSliceAvcbase (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); |
| 1061 | } | 950 | } |
| 1062 | 951 | ||
| 1063 | #if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG) | ||
| 1064 | if (bDsaFlag) { | 952 | if (bDsaFlag) { |
| 1065 | pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx] = (uint32_t) ( | 953 | pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx] = (uint32_t) ( |
| 1066 | WelsTime() - iSliceStart); | 954 | WelsTime() - iSliceStart); |
| @@ -1072,7 +960,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 5 unmodified lines | |||
| 1072 | pCurDq->pSliceEncCtx->pFirstMbInSlice[iSliceIdx], pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx]); | 960 | pCurDq->pSliceEncCtx->pFirstMbInSlice[iSliceIdx], pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx]); |
| 1073 | #endif//ENABLE_TRACE_MT | 961 | #endif//ENABLE_TRACE_MT |
| 1074 | } | 962 | } |
| 1075 | #endif//DYNAMIC_SLICE_ASSIGN || MT_DEBUG | ||
| 1076 | 963 | ||
| 1077 | #if defined(SLICE_INFO_OUTPUT) | 964 | #if defined(SLICE_INFO_OUTPUT) |
| 1078 | fprintf (stderr, | 965 | fprintf (stderr, |
| @@ -1095,9 +982,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 16 unmodified lines | |||
| 1095 | WelsEventSignal (pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice | 982 | WelsEventSignal (pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice |
| 1096 | #endif//WIN32 | 983 | #endif//WIN32 |
| 1097 | } else { // for SM_DYN_SLICE parallelization | 984 | } else { // for SM_DYN_SLICE parallelization |
| 1098 | #ifdef PACKING_ONE_SLICE_PER_LAYER | ||
| 1099 | SLayerBSInfo* pLbiPacking = NULL; | ||
| 1100 | #endif//PACKING_ONE_SLICE_PER_LAYER | ||
| 1101 | SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx; | 985 | SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx; |
| 1102 | const int32_t kiPartitionId = iThreadIdx; | 986 | const int32_t kiPartitionId = iThreadIdx; |
| 1103 | const int32_t kiSliceIdxStep = pEncPEncCtx->iActiveThreadsNum; | 987 | const int32_t kiSliceIdxStep = pEncPEncCtx->iActiveThreadsNum; |
| @@ -1124,9 +1008,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 20 unmodified lines | |||
| 1124 | pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | 1008 | pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; |
| 1125 | pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; | 1009 | pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; |
| 1126 | 1010 | ||
| 1127 | #if !defined(PACKING_ONE_SLICE_PER_LAYER) | ||
| 1128 | pSliceBs->uiBsPos = 0; | 1011 | pSliceBs->uiBsPos = 0; |
| 1129 | #endif//!PACKING_ONE_SLICE_PER_LAYER | ||
| 1130 | pSliceBs->iNalIndex = 0; | 1012 | pSliceBs->iNalIndex = 0; |
| 1131 | InitBits (&pSliceBs->sBsWrite, pSliceBs->pBsBuffer, pSliceBs->uiSize); | 1013 | InitBits (&pSliceBs->sBsWrite, pSliceBs->pBsBuffer, pSliceBs->uiSize); |
| 1132 | 1014 | ||
| @@ -1152,7 +1034,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 19 unmodified lines | |||
| 1152 | 1034 | ||
| 1153 | WelsUnloadNalForSlice (pSliceBs); | 1035 | WelsUnloadNalForSlice (pSliceBs); |
| 1154 | 1036 | ||
| 1155 | #if !defined(PACKING_ONE_SLICE_PER_LAYER) | ||
| 1156 | if (0 == kiPartitionId) { | 1037 | if (0 == kiPartitionId) { |
| 1157 | if (0 == iSliceIdx) | 1038 | if (0 == iSliceIdx) |
| 1158 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | 1039 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; |
| @@ -1170,28 +1051,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 11 unmodified lines | |||
| 1170 | break; | 1051 | break; |
| 1171 | } | 1052 | } |
| 1172 | } | 1053 | } |
| 1173 | #else// PACKING_ONE_SLICE_PER_LAYER | ||
| 1174 | pLbiPacking = pLbi + (iSliceIdx - kiPartitionId); | ||
| 1175 | |||
| 1176 | if (0 == kiPartitionId) { | ||
| 1177 | pLbiPacking->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | ||
| 1178 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbiPacking, pLbiPacking->pBsBuf, iSliceIdx, iSliceSize); | ||
| 1179 | if (ENC_RETURN_SUCCESS!=iReturn) { | ||
| 1180 | uiThrdRet = iReturn; | ||
| 1181 | break; | ||
| 1182 | } | ||
| 1183 | pEncPEncCtx->iPosBsBuffer += iSliceSize; | ||
| 1184 | } else { | ||
| 1185 | pLbiPacking->pBsBuf = pSliceBs->bs + pSliceBs->uiBsPos; | ||
| 1186 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbiPacking, pLbiPacking->pBsBuf, iSliceIdx, iSliceSize); | ||
| 1187 | if (ENC_RETURN_SUCCESS!=iReturn) { | ||
| 1188 | uiThrdRet = iReturn; | ||
| 1189 | break; | ||
| 1190 | } | ||
| 1191 | pSliceBs->uiBsPos += iSliceSize; | ||
| 1192 | } | ||
| 1193 | pEncPEncCtx->pSliceThreading->pCountBsSizeInPartition[kiPartitionId] += iSliceSize; | ||
| 1194 | #endif//!PACKING_ONE_SLICE_PER_LAYER | ||
| 1195 | 1054 | ||
| 1196 | if (pCurDq->bDeblockingParallelFlag && pSlice->sSliceHeaderExt.sSliceHeader.uiDisableDeblockingFilterIdc != 1 | 1055 | if (pCurDq->bDeblockingParallelFlag && pSlice->sSliceHeaderExt.sSliceHeader.uiDisableDeblockingFilterIdc != 1 |
| 1197 | #if !defined(ENABLE_FRAME_DUMP) | 1056 | #if !defined(ENABLE_FRAME_DUMP) |
| @@ -1238,7 +1097,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 40 unmodified lines | |||
| 1238 | uiThrdRet = 0; | 1097 | uiThrdRet = 0; |
| 1239 | break; | 1098 | break; |
| 1240 | } | 1099 | } |
| 1241 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 1242 | else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) { // update pMb list singal | 1100 | else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) { // update pMb list singal |
| 1243 | iSliceIdx = | 1101 | iSliceIdx = |
| 1244 | iEventIdx; // pPrivateData->iSliceIndex; old threads can not be terminated, pPrivateData is not correct for applicable | 1102 | iEventIdx; // pPrivateData->iSliceIndex; old threads can not be terminated, pPrivateData is not correct for applicable |
| @@ -1247,7 +1105,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 2 unmodified lines | |||
| 1247 | WelsEventSignal ( | 1105 | WelsEventSignal ( |
| 1248 | &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice | 1106 | &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice |
| 1249 | } | 1107 | } |
| 1250 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 1251 | #endif//WIN32 | 1108 | #endif//WIN32 |
| 1252 | else { // WELS_THREAD_ERROR_WAIT_TIMEOUT, or WELS_THREAD_ERROR_WAIT_FAILED | 1109 | else { // WELS_THREAD_ERROR_WAIT_TIMEOUT, or WELS_THREAD_ERROR_WAIT_FAILED |
| 1253 | WelsLog (pEncPEncCtx, WELS_LOG_WARNING, | 1110 | WelsLog (pEncPEncCtx, WELS_LOG_WARNING, |
| @@ -1299,12 +1156,10 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 45 unmodified lines | |||
| 1299 | // We need extra threads for update_mb_list_proc on __GNUC__ like OS (mac/linux) | 1156 | // We need extra threads for update_mb_list_proc on __GNUC__ like OS (mac/linux) |
| 1300 | // due to WelsMultipleEventsWaitSingleBlocking implememtation can not work well | 1157 | // due to WelsMultipleEventsWaitSingleBlocking implememtation can not work well |
| 1301 | // in case waiting pUpdateMbListEvent and pReadySliceCodingEvent events at the same time | 1158 | // in case waiting pUpdateMbListEvent and pReadySliceCodingEvent events at the same time |
| 1302 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 1303 | #if defined(__GNUC__) && !defined(_WIN32) | 1159 | #if defined(__GNUC__) && !defined(_WIN32) |
| 1304 | WelsThreadCreate (&pCtx->pSliceThreading->pUpdateMbListThrdHandles[iIdx], UpdateMbListThreadProc, | 1160 | WelsThreadCreate (&pCtx->pSliceThreading->pUpdateMbListThrdHandles[iIdx], UpdateMbListThreadProc, |
| 1305 | &pCtx->pSliceThreading->pThreadPEncCtx[iIdx], 0); | 1161 | &pCtx->pSliceThreading->pThreadPEncCtx[iIdx], 0); |
| 1306 | #endif//__GNUC__ | 1162 | #endif//__GNUC__ |
| 1307 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | ||
| 1308 | 1163 | ||
| 1309 | ++ iIdx; | 1164 | ++ iIdx; |
| 1310 | } | 1165 | } |
| @@ -1314,14 +1169,6 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 3 unmodified lines | |||
| 1314 | return 0; | 1169 | return 0; |
| 1315 | } | 1170 | } |
| 1316 | 1171 | ||
| 1317 | #ifdef PACKING_ONE_SLICE_PER_LAYER | ||
| 1318 | void ResetCountBsSizeInPartitions (uint32_t* pCountBsSizeList, const int32_t iPartitionCnt) { | ||
| 1319 | if (pCountBsSizeList != NULL && iPartitionCnt > 0) { | ||
| 1320 | memset (pCountBsSizeList, 0, sizeof (pCountBsSizeList[0]) * iPartitionCnt); | ||
| 1321 | } | ||
| 1322 | } | ||
| 1323 | #endif//PACKING_ONE_SLICE_PER_LAYER | ||
| 1324 | |||
| 1325 | #ifdef _WIN32 | 1172 | #ifdef _WIN32 |
| 1326 | int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, SLayerBSInfo* pLbi, | 1173 | int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, SLayerBSInfo* pLbi, |
| 1327 | const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) | 1174 | const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) |
| @@ -1341,33 +1188,6 @@ int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT** pEven · 13 unmodified lines | |||
| 1341 | return 1; | 1188 | return 1; |
| 1342 | } | 1189 | } |
| 1343 | 1190 | ||
| 1344 | #if defined(PACKING_ONE_SLICE_PER_LAYER) | ||
| 1345 | //////////////////////////////////////// | ||
| 1346 | if (bIsDynamicSlicingMode) { | ||
| 1347 | iEndMbIdx = pSliceCtx->iMbNumInFrame; | ||
| 1348 | for (iIdx = kiEventCnt - 1; iIdx >= 0; --iIdx) { | ||
| 1349 | const int32_t kiFirstMbIdx = pSliceCtx->pFirstMbInSlice[iIdx]; | ||
| 1350 | pPriData[iIdx].iStartMbIndex = kiFirstMbIdx; | ||
| 1351 | pPriData[iIdx].iEndMbIndex = iEndMbIdx; | ||
| 1352 | iEndMbIdx = kiFirstMbIdx; | ||
| 1353 | } | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | iIdx = 0; | ||
| 1357 | while (iIdx < kiEventCnt) { | ||
| 1358 | pPriData[iIdx].pLayerBs = pLbi; | ||
| 1359 | pPriData[iIdx].iSliceIndex = iIdx; | ||
| 1360 | #ifdef _WIN32 | ||
| 1361 | if (pEventsList[iIdx]) | ||
| 1362 | WelsEventSignal (&pEventsList[iIdx]); | ||
| 1363 | #else | ||
| 1364 | WelsEventSignal (pEventsList[iIdx]); | ||
| 1365 | #endif//WIN32 | ||
| 1366 | ++ pLbi; | ||
| 1367 | ++ iIdx; | ||
| 1368 | } | ||
| 1369 | //////////////////////////////////////// | ||
| 1370 | #else | ||
| 1371 | //////////////////////////////////////// | 1191 | //////////////////////////////////////// |
| 1372 | if (bIsDynamicSlicingMode) { | 1192 | if (bIsDynamicSlicingMode) { |
| 1373 | iEndMbIdx = pSliceCtx->iMbNumInFrame; | 1193 | iEndMbIdx = pSliceCtx->iMbNumInFrame; |
| @@ -1391,8 +1211,6 @@ int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT** pEven · 17 unmodified lines | |||
| 1391 | #endif//WIN32 | 1211 | #endif//WIN32 |
| 1392 | ++ iIdx; | 1212 | ++ iIdx; |
| 1393 | } | 1213 | } |
| 1394 | //////////////////////////////////////// | ||
| 1395 | #endif//PACKING_ONE_SLICE_PER_LAYER | ||
| 1396 | 1214 | ||
| 1397 | return 0; | 1215 | return 0; |
| 1398 | } | 1216 | } |
| @@ -1403,28 +1221,23 @@ int32_t DynamicDetectCpuCores() { · 4 unmodified lines | |||
| 1403 | return info.ProcessorCount; | 1221 | return info.ProcessorCount; |
| 1404 | } | 1222 | } |
| 1405 | 1223 | ||
| 1406 | #if defined(MT_ENABLED) && defined(DYNAMIC_SLICE_ASSIGN) | 1224 | #if defined(MT_ENABLED) |
| 1407 | |||
| 1408 | int32_t AdjustBaseLayer (sWelsEncCtx* pCtx) { | 1225 | int32_t AdjustBaseLayer (sWelsEncCtx* pCtx) { |
| 1409 | SDqLayer* pCurDq = pCtx->ppDqLayerList[0]; | 1226 | SDqLayer* pCurDq = pCtx->ppDqLayerList[0]; |
| 1410 | int32_t iNeedAdj = 1; | 1227 | int32_t iNeedAdj = 1; |
| 1411 | #ifdef MT_DEBUG | 1228 | #ifdef MT_DEBUG |
| 1412 | int64_t iT0 = WelsTime(); | 1229 | int64_t iT0 = WelsTime(); |
| 1413 | #endif//MT_DEBUG | 1230 | #endif//MT_DEBUG |
| 1414 | #ifdef TRY_SLICING_BALANCE | ||
| 1415 | 1231 | ||
| 1416 | pCtx->pCurDqLayer = pCurDq; | 1232 | pCtx->pCurDqLayer = pCurDq; |
| 1417 | 1233 | ||
| 1418 | #ifdef NOT_ABSOLUTE_BALANCING | ||
| 1419 | // do not need adjust due to not different at both slices of consumed time | 1234 | // do not need adjust due to not different at both slices of consumed time |
| 1420 | iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[0], pCurDq->pSliceEncCtx->iSliceNumInFrame); | 1235 | iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[0], pCurDq->pSliceEncCtx->iSliceNumInFrame); |
| 1421 | if (iNeedAdj) | 1236 | if (iNeedAdj) |
| 1422 | #endif//NOT_ABSOLUTE_BALANCING | ||
| 1423 | DynamicAdjustSlicing (pCtx, | 1237 | DynamicAdjustSlicing (pCtx, |
| 1424 | pCurDq, | 1238 | pCurDq, |
| 1425 | pCtx->pSliceThreading->pSliceComplexRatio[0], | 1239 | pCtx->pSliceThreading->pSliceComplexRatio[0], |
| 1426 | 0); | 1240 | 0); |
| 1427 | #endif//TRY_SLICING_BALANCE | ||
| 1428 | #ifdef MT_DEBUG | 1241 | #ifdef MT_DEBUG |
| 1429 | iT0 = WelsTime() - iT0; | 1242 | iT0 = WelsTime() - iT0; |
| 1430 | if (pCtx->pSliceThreading->pFSliceDiff) { | 1243 | if (pCtx->pSliceThreading->pFSliceDiff) { |
| @@ -1455,33 +1268,25 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 24 unmodified lines | |||
| 1455 | 1].sSliceCfg.sSliceArgument.uiSliceNum); | 1268 | 1].sSliceCfg.sSliceArgument.uiSliceNum); |
| 1456 | 1269 | ||
| 1457 | if (kbModelingFromSpatial) { // using spatial base layer for complexity estimation | 1270 | if (kbModelingFromSpatial) { // using spatial base layer for complexity estimation |
| 1458 | #ifdef TRY_SLICING_BALANCE | ||
| 1459 | #ifdef NOT_ABSOLUTE_BALANCING | ||
| 1460 | // do not need adjust due to not different at both slices of consumed time | 1271 | // do not need adjust due to not different at both slices of consumed time |
| 1461 | iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[iCurDid - 1], | 1272 | iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[iCurDid - 1], |
| 1462 | pCtx->pCurDqLayer->pSliceEncCtx->iSliceNumInFrame); | 1273 | pCtx->pCurDqLayer->pSliceEncCtx->iSliceNumInFrame); |
| 1463 | if (iNeedAdj) | 1274 | if (iNeedAdj) |
| 1464 | #endif//NOT_ABSOLUTE_BALANCING | ||
| 1465 | DynamicAdjustSlicing (pCtx, | 1275 | DynamicAdjustSlicing (pCtx, |
| 1466 | pCtx->pCurDqLayer, | 1276 | pCtx->pCurDqLayer, |
| 1467 | pCtx->pSliceThreading->pSliceComplexRatio[iCurDid - 1], | 1277 | pCtx->pSliceThreading->pSliceComplexRatio[iCurDid - 1], |
| 1468 | iCurDid | 1278 | iCurDid |
| 1469 | ); | 1279 | ); |
| 1470 | #endif//TRY_SLICING_BALANCE | ||
| 1471 | } else { // use temporal layer for complexity estimation | 1280 | } else { // use temporal layer for complexity estimation |
| 1472 | #ifdef TRY_SLICING_BALANCE | ||
| 1473 | #ifdef NOT_ABSOLUTE_BALANCING | ||
| 1474 | // do not need adjust due to not different at both slices of consumed time | 1281 | // do not need adjust due to not different at both slices of consumed time |
| 1475 | iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[iCurDid], | 1282 | iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[iCurDid], |
| 1476 | pCtx->pCurDqLayer->pSliceEncCtx->iSliceNumInFrame); | 1283 | pCtx->pCurDqLayer->pSliceEncCtx->iSliceNumInFrame); |
| 1477 | if (iNeedAdj) | 1284 | if (iNeedAdj) |
| 1478 | #endif//NOT_ABSOLUTE_BALANCING | ||
| 1479 | DynamicAdjustSlicing (pCtx, | 1285 | DynamicAdjustSlicing (pCtx, |
| 1480 | pCtx->pCurDqLayer, | 1286 | pCtx->pCurDqLayer, |
| 1481 | pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], | 1287 | pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], |
| 1482 | iCurDid | 1288 | iCurDid |
| 1483 | ); | 1289 | ); |
| 1484 | #endif//TRY_SLICING_BALANCE | ||
| 1485 | } | 1290 | } |
| 1486 | 1291 | ||
| 1487 | #ifdef MT_DEBUG | 1292 | #ifdef MT_DEBUG |
| @@ -1500,11 +1305,11 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 12 unmodified lines | |||
| 1500 | return iNeedAdj; | 1305 | return iNeedAdj; |
| 1501 | } | 1306 | } |
| 1502 | 1307 | ||
| 1503 | #endif//#if defined(MT_ENABLED) && defined(DYNAMIC_SLICE_ASSIGN) | 1308 | #endif//#if defined(MT_ENABLED) |
| 1504 | 1309 | ||
| 1505 | #if defined(MT_ENABLED) | 1310 | #if defined(MT_ENABLED) |
| 1506 | 1311 | ||
| 1507 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) && defined(MT_DEBUG) | 1312 | #if defined(MT_DEBUG) |
| 1508 | void TrackSliceComplexities (sWelsEncCtx* pCtx, const int32_t iCurDid) { | 1313 | void TrackSliceComplexities (sWelsEncCtx* pCtx, const int32_t iCurDid) { |
| 1509 | const int32_t kiCountSliceNum = pCtx->pCurDqLayer->pSliceEncCtx->iSliceNumInFrame; | 1314 | const int32_t kiCountSliceNum = pCtx->pCurDqLayer->pSliceEncCtx->iSliceNumInFrame; |
| 1510 | if (kiCountSliceNum > 0) { | 1315 | if (kiCountSliceNum > 0) { |
| @@ -1516,9 +1321,9 @@ void TrackSliceComplexities (sWelsEncCtx* pCtx, const int32_t iCurDid) { · 5 unmodified lines | |||
| 1516 | } while (iSliceIdx < kiCountSliceNum); | 1321 | } while (iSliceIdx < kiCountSliceNum); |
| 1517 | } | 1322 | } |
| 1518 | } | 1323 | } |
| 1519 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE) | 1324 | #endif |
| 1520 | 1325 | ||
| 1521 | #if defined(DYNAMIC_SLICE_ASSIGN) && defined(MT_DEBUG) | 1326 | #if defined(MT_DEBUG) |
| 1522 | void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t iSpatialNum) { | 1327 | void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t iSpatialNum) { |
| 1523 | SWelsSvcCodingParam* pPara = NULL; | 1328 | SWelsSvcCodingParam* pPara = NULL; |
| 1524 | int32_t iSpatialIdx = 0; | 1329 | int32_t iSpatialIdx = 0; |
| @@ -1557,7 +1362,7 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 32 unmodified lines | |||
| 1557 | ++ iSpatialIdx; | 1362 | ++ iSpatialIdx; |
| 1558 | } | 1363 | } |
| 1559 | } | 1364 | } |
| 1560 | #endif//#if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG) | 1365 | #endif//#if defined(MT_DEBUG) |
| 1561 | 1366 | ||
| 1562 | #endif//MT_ENABLED | 1367 | #endif//MT_ENABLED |
| 1563 | } | 1368 | } |