This avoids having to malloc a whole lot of separate arrays, all which are all bounded by MAX_THREADS_NUM.
Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 2 files). Show all
Unified · Split
| @@ -316,32 +316,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 315 unmodified lines | |||
| 316 | pSmt->pThreadPEncCtx = (SSliceThreadPrivateData*)pMa->WelsMalloc (sizeof (SSliceThreadPrivateData) * iThreadNum, | 316 | pSmt->pThreadPEncCtx = (SSliceThreadPrivateData*)pMa->WelsMalloc (sizeof (SSliceThreadPrivateData) * iThreadNum, |
| 317 | "pThreadPEncCtx"); | 317 | "pThreadPEncCtx"); |
| 318 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadPEncCtx), FreeMemorySvc (ppCtx)) | 318 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadPEncCtx), FreeMemorySvc (ppCtx)) |
| 319 | pSmt->pThreadHandles = (WELS_THREAD_HANDLE*)pMa->WelsMalloc (sizeof (WELS_THREAD_HANDLE) * iThreadNum, | ||
| 320 | "pThreadHandles"); | ||
| 321 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadHandles), FreeMemorySvc (ppCtx)) | ||
| 322 | |||
| 323 | pSmt->pSliceCodedEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pSliceCodedEvent"); | ||
| 324 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceCodedEvent), FreeMemorySvc (ppCtx)) | ||
| 325 | pSmt->pReadySliceCodingEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, | ||
| 326 | "pReadySliceCodingEvent"); | ||
| 327 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pReadySliceCodingEvent), FreeMemorySvc (ppCtx)) | ||
| 328 | |||
| 329 | pSmt->pUpdateMbListEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pUpdateMbListEvent"); | ||
| 330 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pUpdateMbListEvent), FreeMemorySvc (ppCtx)) | ||
| 331 | pSmt->pFinUpdateMbListEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pFinUpdateMbListEvent"); | ||
| 332 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pFinUpdateMbListEvent), FreeMemorySvc (ppCtx)) | ||
| 333 | |||
| 334 | #ifdef _WIN32 | ||
| 335 | pSmt->pFinSliceCodingEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pFinSliceCodingEvent"); | ||
| 336 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pFinSliceCodingEvent), FreeMemorySvc (ppCtx)) | ||
| 337 | |||
| 338 | pSmt->pExitEncodeEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pExitEncodeEvent"); | ||
| 339 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pExitEncodeEvent), FreeMemorySvc (ppCtx)) | ||
| 340 | #else | ||
| 341 | pSmt->pUpdateMbListThrdHandles = (WELS_THREAD_HANDLE*)pMa->WelsMalloc (sizeof (WELS_THREAD_HANDLE) * iThreadNum, | ||
| 342 | "pUpdateMbListThrdHandles"); | ||
| 343 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pUpdateMbListThrdHandles), FreeMemorySvc (ppCtx)) | ||
| 344 | #endif//!_WIN32 | ||
| 345 | 319 | ||
| 346 | iIdx = 0; | 320 | iIdx = 0; |
| 347 | while (iIdx < iNumSpatialLayers) { | 321 | while (iIdx < iNumSpatialLayers) { |
| @@ -515,25 +489,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 167 unmodified lines | |||
| 515 | ++ iIdx; | 489 | ++ iIdx; |
| 516 | } | 490 | } |
| 517 | 491 | ||
| 518 | if (pSmt->pSliceCodedEvent != NULL) { | ||
| 519 | pMa->WelsFree (pSmt->pSliceCodedEvent, "pSliceCodedEvent"); | ||
| 520 | pSmt->pSliceCodedEvent = NULL; | ||
| 521 | } | ||
| 522 | if (pSmt->pReadySliceCodingEvent != NULL) { | ||
| 523 | pMa->WelsFree (pSmt->pReadySliceCodingEvent, "pReadySliceCodingEvent"); | ||
| 524 | pSmt->pReadySliceCodingEvent = NULL; | ||
| 525 | } | ||
| 526 | #ifdef _WIN32 | ||
| 527 | if (pSmt->pExitEncodeEvent != NULL) { | ||
| 528 | pMa->WelsFree (pSmt->pExitEncodeEvent, "pExitEncodeEvent"); | ||
| 529 | pSmt->pExitEncodeEvent = NULL; | ||
| 530 | } | ||
| 531 | if (pSmt->pFinSliceCodingEvent != NULL) { | ||
| 532 | pMa->WelsFree (pSmt->pFinSliceCodingEvent, "pFinSliceCodingEvent"); | ||
| 533 | pSmt->pFinSliceCodingEvent = NULL; | ||
| 534 | } | ||
| 535 | #endif//_WIN32 | ||
| 536 | |||
| 537 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); | 492 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); |
| 538 | WelsMutexDestroy (&((*ppCtx)->mutexEncoderError)); | 493 | WelsMutexDestroy (&((*ppCtx)->mutexEncoderError)); |
| 539 | 494 | ||
| @@ -541,10 +496,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 1 unmodified line | |||
| 541 | pMa->WelsFree (pSmt->pThreadPEncCtx, "pThreadPEncCtx"); | 496 | pMa->WelsFree (pSmt->pThreadPEncCtx, "pThreadPEncCtx"); |
| 542 | pSmt->pThreadPEncCtx = NULL; | 497 | pSmt->pThreadPEncCtx = NULL; |
| 543 | } | 498 | } |
| 544 | if (pSmt->pThreadHandles != NULL) { | ||
| 545 | pMa->WelsFree (pSmt->pThreadHandles, "pThreadHandles"); | ||
| 546 | pSmt->pThreadHandles = NULL; | ||
| 547 | } | ||
| 548 | 499 | ||
| 549 | pSliceB = (*ppCtx)->pSliceBs; | 500 | pSliceB = (*ppCtx)->pSliceBs; |
| 550 | iIdx = 0; | 501 | iIdx = 0; |
| @@ -574,21 +525,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 23 unmodified lines | |||
| 574 | ++ iIdx; | 525 | ++ iIdx; |
| 575 | } | 526 | } |
| 576 | 527 | ||
| 577 | if (pSmt->pUpdateMbListEvent != NULL) { | ||
| 578 | pMa->WelsFree (pSmt->pUpdateMbListEvent, "pUpdateMbListEvent"); | ||
| 579 | pSmt->pUpdateMbListEvent = NULL; | ||
| 580 | } | ||
| 581 | if (pSmt->pFinUpdateMbListEvent != NULL) { | ||
| 582 | pMa->WelsFree (pSmt->pFinUpdateMbListEvent, "pFinUpdateMbListEvent"); | ||
| 583 | pSmt->pFinUpdateMbListEvent = NULL; | ||
| 584 | } | ||
| 585 | #ifndef _WIN32 | ||
| 586 | if (pSmt->pUpdateMbListThrdHandles) { | ||
| 587 | pMa->WelsFree (pSmt->pUpdateMbListThrdHandles, "pUpdateMbListThrdHandles"); | ||
| 588 | pSmt->pUpdateMbListThrdHandles = NULL; | ||
| 589 | } | ||
| 590 | #endif//!_WIN32 | ||
| 591 | |||
| 592 | #ifdef MT_DEBUG | 528 | #ifdef MT_DEBUG |
| 593 | // file handle for debug | 529 | // file handle for debug |
| 594 | if (pSmt->pFSliceDiff) { | 530 | if (pSmt->pFSliceDiff) { |