* free memory dynamically allocated during decoder */
| 548 | * free memory dynamically allocated during decoder |
| 549 | */ |
| 550 | void WelsFreeDynamicMemory (PWelsDecoderContext pCtx) { |
| 551 | |
| 552 | CMemoryAlign* pMa = pCtx->pMemAlign; |
| 553 | |
| 554 | //free dq layer memory |
| 555 | UninitialDqLayersContext (pCtx); |
| 556 | |
| 557 | //free FMO memory |
| 558 | ResetFmoList (pCtx); |
| 559 | |
| 560 | //free ref-pic list & picture memory |
| 561 | WelsResetRefPic (pCtx); |
| 562 | |
| 563 | PPicBuff* pPicBuff = &pCtx->pPicBuff; |
| 564 | if (NULL != pPicBuff && NULL != *pPicBuff) { |
| 565 | DestroyPicBuff (pCtx, pPicBuff, pMa); |
| 566 | } |
| 567 | if (GetThreadCount (pCtx) > 1) { |
| 568 | //prevent from double destruction of PPicBuff |
| 569 | PWelsDecoderThreadCTX pThreadCtx = (PWelsDecoderThreadCTX) (pCtx->pThreadCtx); |
| 570 | int32_t threadCount = pThreadCtx->sThreadInfo.uiThrMaxNum; |
| 571 | int32_t id = pThreadCtx->sThreadInfo.uiThrNum; |
| 572 | for (int32_t i = 0; i < threadCount; ++i) { |
| 573 | if (pThreadCtx[i - id].pCtx != NULL) { |
| 574 | pThreadCtx[i - id].pCtx->pPicBuff = NULL; |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | if (pCtx->pTempDec) { |
| 580 | FreePicture (pCtx->pTempDec, pCtx->pMemAlign); |
| 581 | pCtx->pTempDec = NULL; |
| 582 | } |
| 583 | |
| 584 | // added for safe memory |
| 585 | pCtx->iImgWidthInPixel = 0; |
| 586 | pCtx->iImgHeightInPixel = 0; |
| 587 | pCtx->iLastImgWidthInPixel = 0; |
| 588 | pCtx->iLastImgHeightInPixel = 0; |
| 589 | pCtx->bFreezeOutput = true; |
| 590 | pCtx->bHaveGotMemory = false; |
| 591 | |
| 592 | //free CABAC memory |
| 593 | pMa->WelsFree (pCtx->pCabacDecEngine, "pCtx->pCabacDecEngine"); |
| 594 | } |
| 595 | |
| 596 | /*! |
| 597 | * \brief Open decoder |
no test coverage detected