Showing the changes to codec/decoder/core/src/decoder.cpp (1 of 55 files). Show all
Unified · Split
| @@ -302,12 +302,13 @@ void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx) { · 301 unmodified lines | ||
| 302 | 302 | |
| 303 | 303 | pCtx->pDec = NULL; |
| 304 | 304 | |
| 305 | + pCtx->pTempDec = NULL; | |
| 306 | + | |
| 305 | 307 | WelsResetRefPic (pCtx); |
| 306 | 308 | |
| 307 | 309 | pCtx->iActiveFmoNum = 0; |
| 308 | 310 | |
| 309 | − pCtx->pPicBuff[LIST_0] = NULL; | |
| 310 | − pCtx->pPicBuff[LIST_1] = NULL; | |
| 311 | + pCtx->pPicBuff = NULL; | |
| 311 | 312 | |
| 312 | 313 | pCtx->bAvcBasedFlag = true; |
| 313 | 314 | pCtx->pPreviousDecodedPictureInDpb = NULL; |
| @@ -324,6 +325,8 @@ void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx) { · 10 unmodified lines | ||
| 324 | 325 | pCtx->iSubSPSInvalidNum = 0; |
| 325 | 326 | pCtx->iSubSPSLastInvalidId = -1; |
| 326 | 327 | pCtx->iFeedbackNalRefIdc = -1; //initialize |
| 328 | + pCtx->iPrevPicOrderCntMsb = 0; | |
| 329 | + pCtx->iPrevPicOrderCntLsb = 0; | |
| 327 | 330 | |
| 328 | 331 | } |
| 329 | 332 | |
| @@ -363,7 +366,6 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 33 unmodified lines | ||
| 363 | 366 | const int32_t kiPicHeight = kiMbHeight << 4; |
| 364 | 367 | int32_t iErr = ERR_NONE; |
| 365 | 368 | |
| 366 | − int32_t iListIdx = 0; //, mb_blocks = 0; | |
| 367 | 369 | int32_t iPicQueueSize = 0; // adaptive size of picture queue, = (pSps->iNumRefFrames x 2) |
| 368 | 370 | bReallocFlag = false; |
| 369 | 371 | bool bNeedChangePicQueue = true; |
| @@ -375,8 +377,8 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 5 unmodified lines | ||
| 375 | 377 | // get picture queue size currently |
| 376 | 378 | iPicQueueSize = GetTargetRefListSize (pCtx); // adaptive size of picture queue, = (pSps->iNumRefFrames x 2) |
| 377 | 379 | pCtx->iPicQueueNumber = iPicQueueSize; |
| 378 | − if (pCtx->pPicBuff[LIST_0] != NULL | |
| 379 | − && pCtx->pPicBuff[LIST_0]->iCapacity == | |
| 380 | + if (pCtx->pPicBuff != NULL | |
| 381 | + && pCtx->pPicBuff->iCapacity == | |
| 380 | 382 | iPicQueueSize) // comparing current picture queue size requested and previous allocation picture queue |
| 381 | 383 | bNeedChangePicQueue = false; |
| 382 | 384 | // HD based pic buffer need consider memory size consumed when switch from 720p to other lower size |
| @@ -387,39 +389,39 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 4 unmodified lines | ||
| 387 | 389 | WelsResetRefPic (pCtx); // added to sync update ref list due to pictures are free |
| 388 | 390 | |
| 389 | 391 | if (pCtx->bHaveGotMemory && (kiPicWidth == pCtx->iImgWidthInPixel && kiPicHeight == pCtx->iImgHeightInPixel) |
| 390 | − && pCtx->pPicBuff[LIST_0] != NULL && pCtx->pPicBuff[LIST_0]->iCapacity != iPicQueueSize) { | |
| 392 | + && pCtx->pPicBuff != NULL && pCtx->pPicBuff->iCapacity != iPicQueueSize) { | |
| 391 | 393 | // currently only active for LIST_0 due to have no B frames |
| 394 | + // Actually just need one memory allocation for the PicBuff. While it needs two pointer list (LIST_0 and LIST_1). | |
| 392 | 395 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, |
| 393 | 396 | "WelsRequestMem(): memory re-alloc for no resolution change (size = %d * %d), ref list size change from %d to %d", |
| 394 | − kiPicWidth, kiPicHeight, pCtx->pPicBuff[LIST_0]->iCapacity, iPicQueueSize); | |
| 395 | − if (pCtx->pPicBuff[LIST_0]->iCapacity < iPicQueueSize) { | |
| 396 | − iErr = IncreasePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], pCtx->pPicBuff[LIST_0]->iCapacity, kiPicWidth, kiPicHeight, | |
| 397 | + kiPicWidth, kiPicHeight, pCtx->pPicBuff->iCapacity, iPicQueueSize); | |
| 398 | + if (pCtx->pPicBuff->iCapacity < iPicQueueSize) { | |
| 399 | + iErr = IncreasePicBuff (pCtx, &pCtx->pPicBuff, pCtx->pPicBuff->iCapacity, kiPicWidth, kiPicHeight, | |
| 397 | 400 | iPicQueueSize); |
| 398 | 401 | } else { |
| 399 | − iErr = DecreasePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], pCtx->pPicBuff[LIST_0]->iCapacity, kiPicWidth, kiPicHeight, | |
| 402 | + iErr = DecreasePicBuff (pCtx, &pCtx->pPicBuff, pCtx->pPicBuff->iCapacity, kiPicWidth, kiPicHeight, | |
| 400 | 403 | iPicQueueSize); |
| 401 | 404 | } |
| 402 | 405 | } else { |
| 403 | 406 | if (pCtx->bHaveGotMemory) |
| 404 | 407 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, |
| 405 | 408 | "WelsRequestMem(): memory re-alloc for resolution change, size change from %d * %d to %d * %d, ref list size change from %d to %d", |
| 406 | − pCtx->iImgWidthInPixel, pCtx->iImgHeightInPixel, kiPicWidth, kiPicHeight, pCtx->pPicBuff[LIST_0]->iCapacity, | |
| 409 | + pCtx->iImgWidthInPixel, pCtx->iImgHeightInPixel, kiPicWidth, kiPicHeight, pCtx->pPicBuff->iCapacity, | |
| 407 | 410 | iPicQueueSize); |
| 408 | 411 | else |
| 409 | 412 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "WelsRequestMem(): memory alloc size = %d * %d, ref list size = %d", |
| 410 | 413 | kiPicWidth, kiPicHeight, iPicQueueSize); |
| 411 | 414 | // for Recycled_Pic_Queue |
| 412 | − for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { | |
| 413 | − PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx]; | |
| 414 | − if (NULL != ppPic && NULL != *ppPic) { | |
| 415 | − DestroyPicBuff (ppPic, pMa); | |
| 416 | − } | |
| 415 | + PPicBuff* ppPic = &pCtx->pPicBuff; | |
| 416 | + if (NULL != ppPic && NULL != *ppPic) { | |
| 417 | + DestroyPicBuff (ppPic, pMa); | |
| 417 | 418 | } |
| 418 | 419 | |
| 420 | + | |
| 419 | 421 | pCtx->pPreviousDecodedPictureInDpb = NULL; |
| 420 | 422 | |
| 421 | 423 | // currently only active for LIST_0 due to have no B frames |
| 422 | − iErr = CreatePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], iPicQueueSize, kiPicWidth, kiPicHeight); | |
| 424 | + iErr = CreatePicBuff (pCtx, &pCtx->pPicBuff, iPicQueueSize, kiPicWidth, kiPicHeight); | |
| 423 | 425 | } |
| 424 | 426 | |
| 425 | 427 | if (iErr != ERR_NONE) |
| @@ -444,7 +446,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 18 unmodified lines | ||
| 444 | 446 | * free memory dynamically allocated during decoder |
| 445 | 447 | */ |
| 446 | 448 | void WelsFreeDynamicMemory (PWelsDecoderContext pCtx) { |
| 447 | − int32_t iListIdx = 0; | |
| 449 | + | |
| 448 | 450 | CMemoryAlign* pMa = pCtx->pMemAlign; |
| 449 | 451 | |
| 450 | 452 | //free dq layer memory |
| @@ -455,11 +457,15 @@ void WelsFreeDynamicMemory (PWelsDecoderContext pCtx) { · 4 unmodified lines | ||
| 455 | 457 | |
| 456 | 458 | //free ref-pic list & picture memory |
| 457 | 459 | WelsResetRefPic (pCtx); |
| 458 | − for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { | |
| 459 | − PPicBuff* pPicBuff = &pCtx->pPicBuff[iListIdx]; | |
| 460 | − if (NULL != pPicBuff && NULL != *pPicBuff) { | |
| 461 | − DestroyPicBuff (pPicBuff, pMa); | |
| 462 | − } | |
| 460 | + | |
| 461 | + PPicBuff* pPicBuff = &pCtx->pPicBuff; | |
| 462 | + if (NULL != pPicBuff && NULL != *pPicBuff) { | |
| 463 | + DestroyPicBuff (pPicBuff, pMa); | |
| 464 | + } | |
| 465 | + | |
| 466 | + if (pCtx->pTempDec) { | |
| 467 | + FreePicture (pCtx->pTempDec, pCtx->pMemAlign); | |
| 468 | + pCtx->pTempDec = NULL; | |
| 463 | 469 | } |
| 464 | 470 | |
| 465 | 471 | // added for safe memory |