| 361 | } |
| 362 | |
| 363 | void ReleaseMtResource (sWelsEncCtx** ppCtx) { |
| 364 | SSliceThreading* pSmt = NULL; |
| 365 | CMemoryAlign* pMa = NULL; |
| 366 | int32_t iIdx = 0; |
| 367 | int32_t iThreadNum = 0; |
| 368 | |
| 369 | if (NULL == ppCtx || NULL == *ppCtx) |
| 370 | return; |
| 371 | |
| 372 | pMa = (*ppCtx)->pMemAlign; |
| 373 | iThreadNum = (*ppCtx)->pSvcParam->iMultipleThreadIdc; |
| 374 | pSmt = (*ppCtx)->pSliceThreading; |
| 375 | |
| 376 | if (NULL == pSmt) |
| 377 | return; |
| 378 | |
| 379 | char ename[SEM_NAME_MAX] = {0}; |
| 380 | while (iIdx < iThreadNum) { |
| 381 | // length of semaphore name should be system constrained at least on mac 10.7 |
| 382 | WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace); |
| 383 | WelsEventClose (&pSmt->pSliceCodedEvent[iIdx], ename); |
| 384 | WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%s", iIdx, pSmt->eventNamespace); |
| 385 | WelsEventClose (&pSmt->pReadySliceCodingEvent[iIdx], ename); |
| 386 | WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%s", iIdx, pSmt->eventNamespace); |
| 387 | WelsEventClose (&pSmt->pUpdateMbListEvent[iIdx], ename); |
| 388 | WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace); |
| 389 | WelsEventClose (&pSmt->pFinUpdateMbListEvent[iIdx], ename); |
| 390 | |
| 391 | ++ iIdx; |
| 392 | } |
| 393 | WelsSnprintf (ename, SEM_NAME_MAX, "scm%s", pSmt->eventNamespace); |
| 394 | WelsEventClose (&pSmt->pSliceCodedMasterEvent, ename); |
| 395 | |
| 396 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); |
| 397 | WelsMutexDestroy (&pSmt->mutexThreadBsBufferUsage); |
| 398 | WelsMutexDestroy (&pSmt->mutexThreadSlcBuffReallocate); |
| 399 | WelsMutexDestroy (& ((*ppCtx)->mutexEncoderError)); |
| 400 | WelsMutexDestroy (&pSmt->mutexEvent); |
| 401 | if (pSmt->pThreadPEncCtx != NULL) { |
| 402 | pMa->WelsFree (pSmt->pThreadPEncCtx, "pThreadPEncCtx"); |
| 403 | pSmt->pThreadPEncCtx = NULL; |
| 404 | } |
| 405 | |
| 406 | for (int i = 0; i < MAX_THREADS_NUM; i++) { |
| 407 | if (pSmt->pThreadBsBuffer[i]) { |
| 408 | pMa->WelsFree (pSmt->pThreadBsBuffer[i], "pSmt->pThreadBsBuffer"); |
| 409 | pSmt->pThreadBsBuffer[i] = NULL; |
| 410 | } |
| 411 | } |
| 412 | memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool)); |
| 413 | |
| 414 | if ((*ppCtx)->pTaskManage != NULL) { |
| 415 | WELS_DELETE_OP ((*ppCtx)->pTaskManage); |
| 416 | } |
| 417 | |
| 418 | #ifdef MT_DEBUG |
| 419 | // file handle for debug |
| 420 | if (pSmt->pFSliceDiff) { |
no test coverage detected