static int32_t RemainOneBufferInDpbForEC (PWelsDecoderContext pCtx) { int32_t iRet = ERR_NONE; PRefPic pRefPic = &pCtx->sRefPic; if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] < pCtx->pSps->iNumRefFrames) return iRet; if (pRefPic->uiShortRefCount[0] > 0) { iRet = SlidingWindow (pCtx); } else { //all LTR, remove the smallest long_term_frame_idx int32_t iLongTermFrameIdx = 0; int32_t iMaxLongTermFrameIdx = pRefPic->iMaxLongTermFrameIdx; #ifdef LONG_TERM_REF int32_t iCurrLTRFrameIdx = GetLTRFrameIndex (pRefPic, pCtx->iFrameNumOfAuMarkedLtr); #endif while ((pRefPic->uiLongRefCount[0] >= pCtx->pSps->iNumRefFrames) && (iLongTermFrameIdx <= iMaxLongTermFrameIdx)) { #ifdef LONG_TERM_REF if (iLongTermFrameIdx == iCurrLTRFrameIdx) { iLongTermFrameIdx++; continue; } #endif WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx); iLongTermFrameIdx++; } } if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] >= pCtx->pSps->iNumRefFrames) { //fail to remain one empty buffer in DPB WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "RemainOneBufferInDpbForEC(): empty one DPB failed for EC!"); iRet = ERR_INFO_REF_COUNT_OVERFLOW; } return iRet; }
Stmt sliding_window(Stmt s, const map<string, Function> &env) { return SlidingWindow(env).mutate(s); }
int32_t WelsMarkAsRef (PWelsDecoderContext pCtx) { PRefPic pRefPic = &pCtx->sRefPic; PRefPicMarking pRefPicMarking = pCtx->pCurDqLayer->pRefPicMarking; PAccessUnit pCurAU = pCtx->pAccessUnitList; bool bIsIDRAU = false; uint32_t j; int32_t iRet = ERR_NONE; pCtx->pDec->uiQualityId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiQualityId; pCtx->pDec->uiTemporalId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiTemporalId; pCtx->pDec->iSpsId = pCtx->pSps->iSpsId; pCtx->pDec->iPpsId = pCtx->pPps->iPpsId; for (j = pCurAU->uiStartPos; j <= pCurAU->uiEndPos; j++) { if (pCurAU->pNalUnitsList[j]->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR || pCurAU->pNalUnitsList[j]->sNalHeaderExt.bIdrFlag) { bIsIDRAU = true; break; } } if (bIsIDRAU) { if (pRefPicMarking->bLongTermRefFlag) { pCtx->sRefPic.iMaxLongTermFrameIdx = 0; AddLongTermToList (pRefPic, pCtx->pDec, 0); } else { pCtx->sRefPic.iMaxLongTermFrameIdx = -1; } } else { if (pRefPicMarking->bAdaptiveRefPicMarkingModeFlag) { iRet = MMCO (pCtx, pRefPicMarking); if (iRet != ERR_NONE) { if (pCtx->eErrorConMethod != ERROR_CON_DISABLE) { iRet = RemainOneBufferInDpbForEC (pCtx); WELS_VERIFY_RETURN_IF (iRet, iRet); } else { return iRet; } } if (pCtx->bLastHasMmco5) { pCtx->pDec->iFrameNum = 0; pCtx->pDec->iFramePoc = 0; } } else { iRet = SlidingWindow (pCtx); if (iRet != ERR_NONE) { if (pCtx->eErrorConMethod != ERROR_CON_DISABLE) { iRet = RemainOneBufferInDpbForEC (pCtx); WELS_VERIFY_RETURN_IF (iRet, iRet); } else { return iRet; } } } } if (!pCtx->pDec->bIsLongRef) { if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX (1, pCtx->pSps->iNumRefFrames)) { if (pCtx->eErrorConMethod != ERROR_CON_DISABLE) { iRet = RemainOneBufferInDpbForEC (pCtx); WELS_VERIFY_RETURN_IF (iRet, iRet); } else { return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW; } } iRet = AddShortTermToList (pRefPic, pCtx->pDec); } return iRet; }
int32_t WelsMarkAsRef(PWelsDecoderContext pCtx, const bool_t kbRefBaseMarkingFlag) { PRefPic pRefPic = &pCtx->sRefPic; PRefPicMarking pRefPicMarking = pCtx->pCurDqLayer->pRefPicMarking; PRefBasePicMarking pRefPicBaseMarking =pCtx->pCurDqLayer->pRefPicBaseMarking; PAccessUnit pCurAU = pCtx->pAccessUnitList; bool_t bIsIDRAU = FALSE; uint32_t j; int32_t iRet = ERR_NONE; if(pCtx->pCurDqLayer->bStoreRefBasePicFlag && (pCtx->pSps->iNumRefFrames<2)){ return ERR_INFO_INVALID_MMCO_REF_NUM_NOT_ENOUGH; } pCtx->pDec->bUsedAsRef = TRUE; pCtx->pDec->uiQualityId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiQualityId; pCtx->pDec->uiTemporalId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiTemporalId; pCtx->pDec->bRefBaseFlag = kbRefBaseMarkingFlag; for( j = pCurAU->uiStartPos; j <= pCurAU->uiEndPos; j++ ) { if (pCurAU->pNalUnitsList[j]->sNalHeaderExt.sNalUnitHeader.eNalUnitType== NAL_UNIT_CODED_SLICE_IDR|| pCurAU->pNalUnitsList[j]->sNalHeaderExt.bIdrFlag) { bIsIDRAU = TRUE; break; } } if(bIsIDRAU){ if (pRefPicMarking->bLongTermRefFlag){ pCtx->sRefPic.iMaxLongTermFrameIdx = 0; AddLongTermToList(pRefPic,pCtx->pDec,0); }else{ pCtx->sRefPic.iMaxLongTermFrameIdx = -1; } }else{ if (pRefPicBaseMarking->bAdaptiveRefBasePicMarkingModeFlag){ iRet = MMCOBase(pCtx,pRefPicBaseMarking); } if (iRet != ERR_NONE){ return iRet; } if (pRefPicMarking->bAdaptiveRefPicMarkingModeFlag){ iRet = MMCO(pCtx,pRefPicMarking); if( pCtx->bLastHasMmco5 ) { pCtx->pDec->iFrameNum = 0; pCtx->pDec->iFramePoc = 0; } if (pRefPic->uiLongRefCount[LIST_0]+pRefPic->uiShortRefCount[LIST_0] > pCtx->pSps->iNumRefFrames){ return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW; } }else{ iRet = SlidingWindow(pCtx); } } if (!pCtx->pDec->bIsLongRef){ AddShortTermToList(pRefPic,pCtx->pDec); } return iRet; }