MCPcopy Create free account
hub / github.com/cisco/openh264 / WelsRequestMem

Function WelsRequestMem

codec/decoder/core/src/decoder.cpp:463–545  ·  view source on GitHub ↗

* request memory blocks for decoder avc part */

Source from the content-addressed store, hash-verified

461 * request memory blocks for decoder avc part
462 */
463int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const int32_t kiMbHeight,
464 bool& bReallocFlag) {
465 const int32_t kiPicWidth = kiMbWidth << 4;
466 const int32_t kiPicHeight = kiMbHeight << 4;
467 int32_t iErr = ERR_NONE;
468
469 int32_t iPicQueueSize = 0; // adaptive size of picture queue, = (pSps->iNumRefFrames x 2)
470 bReallocFlag = false;
471 bool bNeedChangePicQueue = true;
472 CMemoryAlign* pMa = pCtx->pMemAlign;
473
474 WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pCtx || kiPicWidth <= 0 || kiPicHeight <= 0))
475
476 // Fixed the issue about different gop size over last, 5/17/2010
477 // get picture queue size currently
478 iPicQueueSize = GetTargetRefListSize (pCtx); // adaptive size of picture queue, = (pSps->iNumRefFrames x 2)
479 pCtx->iPicQueueNumber = iPicQueueSize;
480 if (pCtx->pPicBuff != NULL
481 && pCtx->pPicBuff->iCapacity ==
482 iPicQueueSize) // comparing current picture queue size requested and previous allocation picture queue
483 bNeedChangePicQueue = false;
484 // HD based pic buffer need consider memory size consumed when switch from 720p to other lower size
485 WELS_VERIFY_RETURN_IF (ERR_NONE, pCtx->bHaveGotMemory && (kiPicWidth == pCtx->iImgWidthInPixel
486 && kiPicHeight == pCtx->iImgHeightInPixel) && (!bNeedChangePicQueue)) // have same scaled buffer
487
488 // sync update pRefList
489 if (GetThreadCount (pCtx) <= 1) {
490 WelsResetRefPic (pCtx); // added to sync update ref list due to pictures are free
491 }
492
493 if (pCtx->bHaveGotMemory && (kiPicWidth == pCtx->iImgWidthInPixel && kiPicHeight == pCtx->iImgHeightInPixel)
494 && pCtx->pPicBuff != NULL && pCtx->pPicBuff->iCapacity != iPicQueueSize) {
495 // currently only active for LIST_0 due to have no B frames
496 // Actually just need one memory allocation for the PicBuff. While it needs two pointer list (LIST_0 and LIST_1).
497 WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO,
498 "WelsRequestMem(): memory re-alloc for no resolution change (size = %d * %d), ref list size change from %d to %d",
499 kiPicWidth, kiPicHeight, pCtx->pPicBuff->iCapacity, iPicQueueSize);
500 if (pCtx->pPicBuff->iCapacity < iPicQueueSize) {
501 iErr = IncreasePicBuff (pCtx, &pCtx->pPicBuff, pCtx->pPicBuff->iCapacity, kiPicWidth, kiPicHeight,
502 iPicQueueSize);
503 } else {
504 iErr = DecreasePicBuff (pCtx, &pCtx->pPicBuff, pCtx->pPicBuff->iCapacity, kiPicWidth, kiPicHeight,
505 iPicQueueSize);
506 }
507 } else {
508 if (pCtx->bHaveGotMemory)
509 WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO,
510 "WelsRequestMem(): memory re-alloc for resolution change, size change from %d * %d to %d * %d, ref list size change from %d to %d",
511 pCtx->iImgWidthInPixel, pCtx->iImgHeightInPixel, kiPicWidth, kiPicHeight, pCtx->pPicBuff->iCapacity,
512 iPicQueueSize);
513 else
514 WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "WelsRequestMem(): memory alloc size = %d * %d, ref list size = %d",
515 kiPicWidth, kiPicHeight, iPicQueueSize);
516 // for Recycled_Pic_Queue
517 PPicBuff* ppPic = &pCtx->pPicBuff;
518 if (NULL != ppPic && NULL != *ppPic) {
519 DestroyPicBuff (pCtx, ppPic, pMa);
520 }

Callers 1

SyncPictureResolutionExtFunction · 0.85

Calls 9

GetTargetRefListSizeFunction · 0.85
GetThreadCountFunction · 0.85
WelsResetRefPicFunction · 0.85
WelsLogFunction · 0.85
IncreasePicBuffFunction · 0.85
DecreasePicBuffFunction · 0.85
DestroyPicBuffFunction · 0.85
CreatePicBuffFunction · 0.85
WelsMalloczMethod · 0.80

Tested by

no test coverage detected