Showing the changes to codec/decoder/core/src/decoder.cpp (1 of 12 files). Show all
Unified · Split
| @@ -57,7 +57,7 @@ namespace WelsDec { · 56 unmodified lines | ||
| 57 | 57 | |
| 58 | 58 | extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight); |
| 59 | 59 | |
| 60 | −extern void FreePicture (PPicture pPic); | |
| 60 | +extern void FreePicture (PPicture pPic, CMemoryAlign* pMa); | |
| 61 | 61 | |
| 62 | 62 | static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiSize, |
| 63 | 63 | const int32_t kiPicWidth, const int32_t kiPicHeight) { |
| @@ -67,17 +67,19 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 3 unmodified lines | ||
| 67 | 67 | return 1; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | − pPicBuf = (PPicBuff)WelsMallocz (sizeof (SPicBuff), "PPicBuff"); | |
| 70 | + CMemoryAlign* pMa = pCtx->pMemAlign; | |
| 71 | + | |
| 72 | + pPicBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff"); | |
| 71 | 73 | |
| 72 | 74 | if (NULL == pPicBuf) { |
| 73 | 75 | return 1; |
| 74 | 76 | } |
| 75 | 77 | |
| 76 | − pPicBuf->ppPic = (PPicture*)WelsMallocz (kiSize * sizeof (PPicture), "PPicture*"); | |
| 78 | + pPicBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiSize * sizeof (PPicture), "PPicture*"); | |
| 77 | 79 | |
| 78 | 80 | if (NULL == pPicBuf->ppPic) { |
| 79 | 81 | pPicBuf->iCapacity = 0; |
| 80 | − DestroyPicBuff (&pPicBuf); | |
| 82 | + DestroyPicBuff (&pPicBuf, pMa); | |
| 81 | 83 | return 1; |
| 82 | 84 | } |
| 83 | 85 | |
| @@ -86,7 +88,7 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 2 unmodified lines | ||
| 86 | 88 | if (NULL == pPic) { |
| 87 | 89 | // init capacity first for free memory |
| 88 | 90 | pPicBuf->iCapacity = iPicIdx; |
| 89 | − DestroyPicBuff (&pPicBuf); | |
| 91 | + DestroyPicBuff (&pPicBuf, pMa); | |
| 90 | 92 | return 1; |
| 91 | 93 | } |
| 92 | 94 | pPicBuf->ppPic[iPicIdx] = pPic; |
| @@ -109,17 +111,18 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 16 unmodified lines | ||
| 109 | 111 | return 1; |
| 110 | 112 | } |
| 111 | 113 | |
| 112 | − pPicNewBuf = (PPicBuff)WelsMallocz (sizeof (SPicBuff), "PPicBuff"); | |
| 114 | + CMemoryAlign* pMa = pCtx->pMemAlign; | |
| 115 | + pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff"); | |
| 113 | 116 | |
| 114 | 117 | if (NULL == pPicNewBuf) { |
| 115 | 118 | return 1; |
| 116 | 119 | } |
| 117 | 120 | |
| 118 | − pPicNewBuf->ppPic = (PPicture*)WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*"); | |
| 121 | + pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*"); | |
| 119 | 122 | |
| 120 | 123 | if (NULL == pPicNewBuf->ppPic) { |
| 121 | 124 | pPicNewBuf->iCapacity = 0; |
| 122 | − DestroyPicBuff (&pPicNewBuf); | |
| 125 | + DestroyPicBuff (&pPicNewBuf, pMa); | |
| 123 | 126 | return 1; |
| 124 | 127 | } |
| 125 | 128 | |
| @@ -129,7 +132,7 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 3 unmodified lines | ||
| 129 | 132 | if (NULL == pPic) { |
| 130 | 133 | // Set maximum capacity as the new malloc memory at the tail |
| 131 | 134 | pPicNewBuf->iCapacity = iPicIdx; |
| 132 | − DestroyPicBuff (&pPicNewBuf); | |
| 135 | + DestroyPicBuff (&pPicNewBuf, pMa); | |
| 133 | 136 | return 1; |
| 134 | 137 | } |
| 135 | 138 | pPicNewBuf->ppPic[iPicIdx] = pPic; |
| @@ -152,12 +155,12 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 16 unmodified lines | ||
| 152 | 155 | } |
| 153 | 156 | // remove old PicBuf |
| 154 | 157 | if (pPicOldBuf->ppPic != NULL) { |
| 155 | − WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue"); | |
| 158 | + pMa->WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue"); | |
| 156 | 159 | pPicOldBuf->ppPic = NULL; |
| 157 | 160 | } |
| 158 | 161 | pPicOldBuf->iCapacity = 0; |
| 159 | 162 | pPicOldBuf->iCurrentIdx = 0; |
| 160 | − WelsFree (pPicOldBuf, "pPicOldBuf"); | |
| 163 | + pMa->WelsFree (pPicOldBuf, "pPicOldBuf"); | |
| 161 | 164 | pPicOldBuf = NULL; |
| 162 | 165 | return 0; |
| 163 | 166 | } |
| @@ -171,17 +174,19 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 7 unmodified lines | ||
| 171 | 174 | return 1; |
| 172 | 175 | } |
| 173 | 176 | |
| 174 | − pPicNewBuf = (PPicBuff)WelsMallocz (sizeof (SPicBuff), "PPicBuff"); | |
| 177 | + CMemoryAlign* pMa = pCtx->pMemAlign; | |
| 178 | + | |
| 179 | + pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff"); | |
| 175 | 180 | |
| 176 | 181 | if (NULL == pPicNewBuf) { |
| 177 | 182 | return 1; |
| 178 | 183 | } |
| 179 | 184 | |
| 180 | − pPicNewBuf->ppPic = (PPicture*)WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*"); | |
| 185 | + pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*"); | |
| 181 | 186 | |
| 182 | 187 | if (NULL == pPicNewBuf->ppPic) { |
| 183 | 188 | pPicNewBuf->iCapacity = 0; |
| 184 | − DestroyPicBuff (&pPicNewBuf); | |
| 189 | + DestroyPicBuff (&pPicNewBuf, pMa); | |
| 185 | 190 | return 1; |
| 186 | 191 | } |
| 187 | 192 | |
| @@ -207,7 +212,7 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 19 unmodified lines | ||
| 207 | 212 | for (iPicIdx = iDelIdx; iPicIdx < kiOldSize; iPicIdx++) { |
| 208 | 213 | if (iPrevPicIdx != iPicIdx) { |
| 209 | 214 | if (pPicOldBuf->ppPic[iPicIdx] != NULL) { |
| 210 | − FreePicture (pPicOldBuf->ppPic[iPicIdx]); | |
| 215 | + FreePicture (pPicOldBuf->ppPic[iPicIdx], pMa); | |
| 211 | 216 | pPicOldBuf->ppPic[iPicIdx] = NULL; |
| 212 | 217 | } |
| 213 | 218 | } |
| @@ -226,18 +231,18 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 12 unmodified lines | ||
| 226 | 231 | } |
| 227 | 232 | // remove old PicBuf |
| 228 | 233 | if (pPicOldBuf->ppPic != NULL) { |
| 229 | − WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue"); | |
| 234 | + pMa->WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue"); | |
| 230 | 235 | pPicOldBuf->ppPic = NULL; |
| 231 | 236 | } |
| 232 | 237 | pPicOldBuf->iCapacity = 0; |
| 233 | 238 | pPicOldBuf->iCurrentIdx = 0; |
| 234 | − WelsFree (pPicOldBuf, "pPicOldBuf"); | |
| 239 | + pMa->WelsFree (pPicOldBuf, "pPicOldBuf"); | |
| 235 | 240 | pPicOldBuf = NULL; |
| 236 | 241 | |
| 237 | 242 | return 0; |
| 238 | 243 | } |
| 239 | 244 | |
| 240 | −void DestroyPicBuff (PPicBuff* ppPicBuf) { | |
| 245 | +void DestroyPicBuff (PPicBuff* ppPicBuf, CMemoryAlign* pMa) { | |
| 241 | 246 | PPicBuff pPicBuf = NULL; |
| 242 | 247 | |
| 243 | 248 | if (NULL == ppPicBuf || NULL == *ppPicBuf) |
| @@ -249,20 +254,20 @@ void DestroyPicBuff (PPicBuff* ppPicBuf) { · 5 unmodified lines | ||
| 249 | 254 | while (iPicIdx < pPicBuf->iCapacity) { |
| 250 | 255 | PPicture pPic = pPicBuf->ppPic[iPicIdx]; |
| 251 | 256 | if (pPic != NULL) { |
| 252 | − FreePicture (pPic); | |
| 257 | + FreePicture (pPic, pMa); | |
| 253 | 258 | } |
| 254 | 259 | pPic = NULL; |
| 255 | 260 | ++ iPicIdx; |
| 256 | 261 | } |
| 257 | 262 | |
| 258 | − WelsFree (pPicBuf->ppPic, "pPicBuf->queue"); | |
| 263 | + pMa->WelsFree (pPicBuf->ppPic, "pPicBuf->queue"); | |
| 259 | 264 | |
| 260 | 265 | pPicBuf->ppPic = NULL; |
| 261 | 266 | } |
| 262 | 267 | pPicBuf->iCapacity = 0; |
| 263 | 268 | pPicBuf->iCurrentIdx = 0; |
| 264 | 269 | |
| 265 | − WelsFree (pPicBuf, "pPicBuf"); | |
| 270 | + pMa->WelsFree (pPicBuf, "pPicBuf"); | |
| 266 | 271 | |
| 267 | 272 | pPicBuf = NULL; |
| 268 | 273 | *ppPicBuf = NULL; |
| @@ -270,10 +275,11 @@ void DestroyPicBuff (PPicBuff* ppPicBuf) { · 1 unmodified line | ||
| 270 | 275 | /* |
| 271 | 276 | * fill data fields in default for decoder context |
| 272 | 277 | */ |
| 273 | −void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx) { | |
| 278 | +void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx, CMemoryAlign* pMa) { | |
| 274 | 279 | int32_t iCpuCores = 1; |
| 275 | 280 | memset (pCtx, 0, sizeof (SWelsDecoderContext)); // fill zero first |
| 276 | 281 | pCtx->sLogCtx = *pLogCtx; |
| 282 | + pCtx->pMemAlign = pMa; | |
| 277 | 283 | |
| 278 | 284 | pCtx->pArgDec = NULL; |
| 279 | 285 | |
| @@ -360,6 +366,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 80 unmodified lines | ||
| 360 | 366 | int32_t iListIdx = 0; //, mb_blocks = 0; |
| 361 | 367 | int32_t iPicQueueSize = 0; // adaptive size of picture queue, = (pSps->iNumRefFrames x 2) |
| 362 | 368 | bool bNeedChangePicQueue = true; |
| 369 | + CMemoryAlign* pMa = pCtx->pMemAlign; | |
| 363 | 370 | |
| 364 | 371 | WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pCtx || kiPicWidth <= 0 || kiPicHeight <= 0)) |
| 365 | 372 | |
| @@ -404,7 +411,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 38 unmodified lines | ||
| 404 | 411 | for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { |
| 405 | 412 | PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx]; |
| 406 | 413 | if (NULL != ppPic && NULL != *ppPic) { |
| 407 | − DestroyPicBuff (ppPic); | |
| 414 | + DestroyPicBuff (ppPic, pMa); | |
| 408 | 415 | } |
| 409 | 416 | } |
| 410 | 417 | |
| @@ -425,7 +432,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 14 unmodified lines | ||
| 425 | 432 | pCtx->pDec = NULL; // need prefetch a new pic due to spatial size changed |
| 426 | 433 | |
| 427 | 434 | if (pCtx->pCabacDecEngine == NULL) |
| 428 | − pCtx->pCabacDecEngine = (SWelsCabacDecEngine*) WelsMallocz (sizeof (SWelsCabacDecEngine), "pCtx->pCabacDecEngine"); | |
| 435 | + pCtx->pCabacDecEngine = (SWelsCabacDecEngine*) pMa->WelsMallocz (sizeof (SWelsCabacDecEngine), "pCtx->pCabacDecEngine"); | |
| 429 | 436 | WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY, (NULL == pCtx->pCabacDecEngine)) |
| 430 | 437 | return ERR_NONE; |
| 431 | 438 | } |
| @@ -435,6 +442,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 3 unmodified lines | ||
| 435 | 442 | */ |
| 436 | 443 | void WelsFreeMem (PWelsDecoderContext pCtx) { |
| 437 | 444 | int32_t iListIdx = 0; |
| 445 | + CMemoryAlign* pMa = pCtx->pMemAlign; | |
| 438 | 446 | |
| 439 | 447 | /* TODO: free memory blocks introduced in avc */ |
| 440 | 448 | ResetFmoList (pCtx); |
| @@ -445,7 +453,7 @@ void WelsFreeMem (PWelsDecoderContext pCtx) { · 4 unmodified lines | ||
| 445 | 453 | for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { |
| 446 | 454 | PPicBuff* pPicBuff = &pCtx->pPicBuff[iListIdx]; |
| 447 | 455 | if (NULL != pPicBuff && NULL != *pPicBuff) { |
| 448 | − DestroyPicBuff (pPicBuff); | |
| 456 | + DestroyPicBuff (pPicBuff, pMa); | |
| 449 | 457 | } |
| 450 | 458 | } |
| 451 | 459 | |
| @@ -456,7 +464,7 @@ void WelsFreeMem (PWelsDecoderContext pCtx) { · 4 unmodified lines | ||
| 456 | 464 | pCtx->iLastImgHeightInPixel = 0; |
| 457 | 465 | pCtx->bFreezeOutput = true; |
| 458 | 466 | pCtx->bHaveGotMemory = false; |
| 459 | − WelsFree (pCtx->pCabacDecEngine, "pCtx->pCabacDecEngine"); | |
| 467 | + pMa->WelsFree (pCtx->pCabacDecEngine, "pCtx->pCabacDecEngine"); | |
| 460 | 468 | } |
| 461 | 469 | |
| 462 | 470 | /*! |
| @@ -517,7 +525,9 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa · 54 unmodified lines | ||
| 517 | 525 | if (NULL == pCtx || NULL == kpParam) |
| 518 | 526 | return 1; |
| 519 | 527 | |
| 520 | − pCtx->pParam = (SDecodingParam*)WelsMallocz (sizeof (SDecodingParam), "SDecodingParam"); | |
| 528 | + CMemoryAlign* pMa = pCtx->pMemAlign; | |
| 529 | + | |
| 530 | + pCtx->pParam = (SDecodingParam*)pMa->WelsMallocz (sizeof (SDecodingParam), "SDecodingParam"); | |
| 521 | 531 | |
| 522 | 532 | if (NULL == pCtx->pParam) |
| 523 | 533 | return 1; |
| @@ -565,7 +575,7 @@ int32_t WelsInitDecoder (PWelsDecoderContext pCtx, const bool bParseOnly, SLogCo · 41 unmodified lines | ||
| 565 | 575 | } |
| 566 | 576 | |
| 567 | 577 | // default |
| 568 | − WelsDecoderDefaults (pCtx, pLogCtx); | |
| 578 | + WelsDecoderDefaults (pCtx, pLogCtx, pCtx->pMemAlign); | |
| 569 | 579 | |
| 570 | 580 | pCtx->bParseOnly = bParseOnly; |
| 571 | 581 | // open decoder |
| @@ -834,7 +844,10 @@ int32_t SyncPictureResolutionExt (PWelsDecoderContext pCtx, const int32_t kiMbWi · 262 unmodified lines | ||
| 834 | 844 | "SyncPictureResolutionExt()::InitialDqLayersContext--buffer allocated failure."); |
| 835 | 845 | pCtx->iErrorCode = dsOutOfMemory; |
| 836 | 846 | } |
| 837 | − | |
| 847 | +#if defined(MEMORY_MONITOR) | |
| 848 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "SyncPictureResolutionExt(), overall memory usage: %llu bytes", | |
| 849 | + static_cast<unsigned long long> (sizeof (SWelsDecoderContext) + pCtx->pMemAlign->WelsGetMemoryUsage())); | |
| 850 | +#endif//MEMORY_MONITOR | |
| 838 | 851 | return iErr; |
| 839 | 852 | } |
| 840 | 853 | |