📄 omxvcm4p10_motionestimationmb.c
字号:
*/static OMXVoid armVCM4P10_Mode4x4Decision ( const OMX_U8* pSrcCurrBuf, OMX_S32 SrcCurrStep, OMXVCM4P10MBInfo *pSrcDstMBCurr, OMX_S32 Block8x8, OMX_S32 Block4x4, OMX_U8 *pPredIntra4x4SrcY, OMX_S32 StepPredIntra4x4SrcY, OMX_S32 pIntra4x4PredMode [][9], OMX_S32 *pBestCost){ OMX_S32 i, j, x, y, BlockX, BlockY, mode; OMX_S32 Cost, BestCost; OMX_U8 *pSrcY; OMX_S32 StepSrcY; OMX_S32 availability = 0; OMX_U8 pPredBlock [4*4]; OMXResult Ret = OMX_Sts_Err; /* Get block cordinates from 8x8 block index and 4x4 block index */ BlockX = ((Block8x8 & 1) << 1) + (Block4x4 & 1); BlockY = ((Block8x8 >> 1) << 1) + (Block4x4 >> 1); /* Add offset to point to start of current MB in the array pIntra4x4PredMode */ x = BlockX + 1; y = BlockY + 1; /* Check for availability of LEFT Block */ if (pIntra4x4PredMode [y][x - 1] != ARM_VCM4P10_INVALID_BLOCK) { availability |= OMX_VC_LEFT; } /* Check for availability of UPPER Block */ if (pIntra4x4PredMode [y - 1][x] != ARM_VCM4P10_INVALID_BLOCK) { availability |= OMX_VC_UPPER; } /* Check for availability of UPPER LEFT Block */ if (pIntra4x4PredMode [y - 1][x - 1] != ARM_VCM4P10_INVALID_BLOCK) { availability |= OMX_VC_UPPER_LEFT; } pSrcY = pPredIntra4x4SrcY + StepPredIntra4x4SrcY * (BlockY << 2) + (BlockX << 2); StepSrcY = StepPredIntra4x4SrcY; x = BlockX * 4; y = BlockY * 4; Cost = BestCost = ARM_VCM4P10_MAX_COST; /* Go through each mode for minim cost */ for (mode = 0; mode < 9; mode++) { Ret = omxVCM4P10_PredictIntra_4x4( pSrcY - 1, pSrcY - StepSrcY, pSrcY - StepSrcY - 1, pPredBlock, StepSrcY, 4, (OMXVCM4P10Intra4x4PredMode) mode, availability); if (Ret == OMX_Sts_NoErr) { armVCCOMM_SAD( pSrcCurrBuf + (y * SrcCurrStep) + x, SrcCurrStep, pPredBlock, 4, &Cost, 4, 4); if (Cost < BestCost) { BestCost = Cost; pIntra4x4PredMode [BlockY + 1][BlockX + 1] = (OMXVCM4P10Intra4x4PredMode) mode; pSrcDstMBCurr->pIntra4x4PredMode [BlockY * 4 + BlockX] = (OMXVCM4P10Intra4x4PredMode) mode; for (j = 0; j < 4; j++) { for (i = 0; i < 4; i++) { pSrcY [StepSrcY * j + i] = pPredBlock [4 * j + i]; } } } } } *pBestCost = BestCost; return;}/** * Function: armVCM4P10_SetMotionVectorPredictor * * Description: * This function will do the MV Prediction for Inter MBs * * Parameters: * [in] BlockStartX - Start X index in integer pels in current Block * [in] BlockStartY - Start Y index in integer pels in current Block * [in] BlockSizeX - Width of current block * [in] BlockSizeY - Height of current block * [in] RefFrame - Index of the reference frame for prediction * [in] pRefFrArr - Pointer to Ref array storing neighbouring MVs for MV prediction * [in] pMVArr - Pointer to MV array storing neighbouring MVs for MV prediction * [out] pMVPred - Pointer to predicted MVs * Remarks: * * Return Value: * None * */static OMXVoid armVCM4P10_SetMotionVectorPredictor( OMX_U32 BlockStartX, OMX_U32 BlockStartY, OMX_U32 BlockSizex, OMX_U32 BlockSizey, OMX_S32 RefFrame, OMX_S32 pRefFrArr[][6], OMXVCMotionVector pMVArr[][12], OMXVCMotionVector *pMVPred){ OMX_S32 RFrameL; /* Left */ OMX_S32 RFrameU; /* Up */ OMX_S32 RFrameUR; /* Up-Right */ OMX_S32 BlockX, BlockY, BlockXFr, BlockYFr, MVPredType; OMX_S32 BlockXPlusOff, BlockXPlusOffFr, BlockXMin1Fr, BlockYMin1Fr; BlockX = 4 + (BlockStartX >> 2); BlockY = 4 + (BlockStartY >> 2); BlockXPlusOff = BlockX + (BlockSizex >> 2); BlockXFr = BlockX >> 1; BlockYFr = BlockY >> 1; BlockXMin1Fr = (BlockX - 1) >> 1; BlockYMin1Fr = (BlockY - 1) >> 1; BlockXPlusOffFr = BlockXPlusOff >> 1; MVPredType = ARM_VCM4P10_MVPRED_MEDIAN; RFrameL = pRefFrArr [BlockYFr][BlockXMin1Fr]; RFrameU = pRefFrArr [BlockYMin1Fr][BlockXFr]; RFrameUR = pRefFrArr [BlockYMin1Fr][BlockXPlusOffFr]; if (RFrameUR == ARM_VCM4P10_INVALID_BLOCK) { RFrameUR = pRefFrArr [BlockYMin1Fr][BlockXMin1Fr]; } /* * Prediction if only one of the neighbors uses the reference frame * we are checking */ if (RFrameL == RefFrame && RFrameU != RefFrame && RFrameUR != RefFrame) { MVPredType = ARM_VCM4P10_MVPRED_L; } else if(RFrameL != RefFrame && RFrameU == RefFrame && RFrameUR != RefFrame) { MVPredType = ARM_VCM4P10_MVPRED_U; } else if(RFrameL != RefFrame && RFrameU != RefFrame && RFrameUR == RefFrame) { MVPredType = ARM_VCM4P10_MVPRED_UR; } /* Directional predictions */ else if(BlockSizex == 8 && BlockSizey == 16) { if(BlockStartX == 0) { if(RFrameL == RefFrame) { MVPredType = ARM_VCM4P10_MVPRED_L; } } else { if (RFrameUR == RefFrame) { MVPredType = ARM_VCM4P10_MVPRED_UR; } } } else if(BlockSizex == 16 && BlockSizey == 8) { if(BlockStartY == 0) { if(RFrameU == RefFrame) { MVPredType = ARM_VCM4P10_MVPRED_U; } } else { if(RFrameL == RefFrame) { MVPredType = ARM_VCM4P10_MVPRED_L; } } } switch (MVPredType) { case ARM_VCM4P10_MVPRED_MEDIAN: if (!(pRefFrArr [BlockYMin1Fr][BlockXMin1Fr] == ARM_VCM4P10_INVALID_BLOCK || pRefFrArr [BlockYMin1Fr][BlockXFr] == ARM_VCM4P10_INVALID_BLOCK || pRefFrArr [BlockYMin1Fr][BlockXPlusOffFr] == ARM_VCM4P10_INVALID_BLOCK)) { pMVPred->dx = pMVArr [BlockY][BlockX - 1].dx; pMVPred->dy = pMVArr [BlockY][BlockX - 1].dy; } else { pMVPred->dx = ARM_VCM4P10_MEDIAN(pMVArr [BlockY][BlockX - 1].dx, pMVArr [BlockY - 1][BlockX].dx, pMVArr [BlockY - 1][BlockXPlusOff].dx); pMVPred->dy = ARM_VCM4P10_MEDIAN(pMVArr [BlockY][BlockX - 1].dy, pMVArr [BlockY - 1][BlockX].dy, pMVArr [BlockY - 1][BlockXPlusOff].dy); } break; case ARM_VCM4P10_MVPRED_L: pMVPred->dx = pMVArr [BlockY][BlockX - 1].dx; pMVPred->dy = pMVArr [BlockY][BlockX - 1].dy; break; case ARM_VCM4P10_MVPRED_U: pMVPred->dx = pMVArr [BlockY - 1][BlockX].dx; pMVPred->dy = pMVArr [BlockY - 1][BlockX].dy; break; case ARM_VCM4P10_MVPRED_UR: if (pRefFrArr [BlockYMin1Fr][BlockXPlusOffFr] != ARM_VCM4P10_INVALID_BLOCK) { pMVPred->dx = pMVArr [BlockY - 1][BlockXPlusOff].dx; pMVPred->dy = pMVArr [BlockY - 1][BlockXPlusOff].dy; } else { pMVPred->dx = pMVArr [BlockY - 1][BlockX - 1].dx; pMVPred->dy = pMVArr [BlockY - 1][BlockX - 1].dy; } break; default: break; } return;}/** * Function: armVCM4P10_BlockMotionSearch * * Description: * Gets best MV for the current block * * Parameters: * [in] pSrcCurrBuf - Pointer to the start of luma component of current Macroblock * [in] SrcCurrStep - Step size for the pointer pSrcCurrBuf * [in] pSrcRefY - Pointer to the start of luma component of co-located reference MB * [in] nSrcRefStep - Step size for the pointer pSrcRefY * [in] pRefRect Pointer to the valid reference rectangle; relative to the image origin. * [in] pCurrPointPos Position of the current macroblock in the current plane. * [in] pMESpec - Motion estimation structure * [in] pMBInter - Array, of dimension four, containing pointers to information associated with four * adjacent type INTER MBs (Left, Top, Top-Left, Top-Right). * [in] nLamda - For calculating the cost * [out] pBestCost - Minimum cost for encoding current block * [out] pBestMV - MV corresponding to best cost * [in] BlockStartX - Block start X index in integer pels * [in] BlockStartY - Block start Y index in integer pels * [in] BlockSizeX - Width of current block * [in] BlockSizeY - Height of current block * [in] RefFrame - Index of the reference frame for prediction * [in] pRefFrArr - Pointer to reference frame array storing neighbouring MVs for prediction * [in] pMVArr - Pointer to MV array storing neighbouring MVs for MV prediction * [in] pMVPred - Pointer to MV predicted from neighbour MVs * Remarks: * * Return Value: * OMXResult * */static OMXResult armVCM4P10_BlockMotionSearch( const OMX_U8* pSrcCurrBuf, OMX_S32 SrcCurrStep, const OMX_U8* pSrcRefY, OMX_S32 nSrcRefStep, const OMXRect *pRefRect, const OMXVCM4P2Coordinate *pCurrPointPos, void* pMESpec, OMX_S32 nLamda, OMX_S32* pBestCost, OMXVCMotionVector *pBestMV, OMX_U32 BlockStartX, OMX_U32 BlockStartY, OMX_U32 BlockSizeX, OMX_U32 BlockSizeY, OMX_S32 RefFrame, OMX_S32 pRefFrArr [][6], OMXVCMotionVector pMVArr [][12], OMXVCMotionVector *pMVPred ){ OMXVCMotionVector MVCalculated, MVCandidate; OMX_S32 Cost; OMXResult RetValue; OMXVCM4P10MEParams *pMEParams; OMXVCM4P2Coordinate CurrBlockPos; /* Get Predicted Motion Vectors */ armVCM4P10_SetMotionVectorPredictor ( BlockStartX, BlockStartY, BlockSizeX, BlockSizeY, RefFrame, pRefFrArr, pMVArr, pMVPred); /* Initialize candidate MV */ MVCandidate.dx = 0; MVCandidate.dy = 0; CurrBlockPos.x = pCurrPointPos->x + BlockStartX; CurrBlockPos.y = pCurrPointPos->y + BlockStartY; /* Block Match Integer */ RetValue = omxVCM4P10_BlockMatch_Integer ( pSrcCurrBuf, SrcCurrStep, pSrcRefY, nSrcRefStep, pRefRect, &CurrBlockPos, BlockSizeX, BlockSizeY, nLamda, pMVPred, &MVCandidate, &MVCalculated, &Cost, pMESpec); /* updated BestMV*/ /**pBestCost = Cost; pBestMV->dx = MVCalculated.dx; pBestMV->dy = MVCalculated.dy;*/ pMEParams = (OMXVCM4P10MEParams *) pMESpec; /* Block Match Half pel */ if (pMEParams->halfSearchEnable) { RetValue = omxVCM4P10_BlockMatch_Half( pSrcCurrBuf, SrcCurrStep, pSrcRefY, nSrcRefStep, BlockSizeX, BlockSizeY, nLamda, pMVPred, &MVCalculated, /* input/output*/ &Cost); } /* Block Match Quarter pel */ if (pMEParams->quarterSearchEnable) { RetValue = omxVCM4P10_BlockMatch_Quarter( pSrcCurrBuf, SrcCurrStep, pSrcRefY, nSrcRefStep, BlockSizeX, BlockSizeY, nLamda, pMVPred, &MVCalculated, &Cost); } /* updated Best Cost and Best MV */ *pBestCost = Cost; pBestMV->dx = MVCalculated.dx; pBestMV->dy = MVCalculated.dy; /* * Skip MB cost calculations of 16x16 inter mode */ return RetValue;}/** * Function: armVCM4P10_PartitionME * * Description: * Gets best cost for the current partition * * Parameters: * [in] pSrcCurrBuf - Pointer to the start of luma component of current Macroblock * [in] SrcCurrStep - Step size for the pointer pSrcCurrBuf * [in] pSrcRefBufList - Pointer to List of ref buffer of co-located reference MB * [in] nSrcRefStep - Step size for the pointer pSrcRefY * [in] pRefRect Pointer to the valid reference rectangle; relative to the image origin. * [in] pCurrPointPos Position of the current macroblock in the current plane. * [in] pMESpec - Motion estimation structure * [in] PartWidth - Width of current partition * [in] PartHeight - Height of current partition * [in] BlockWidth - Width of current block * [in] BlockHeight - Height of current block * [in] PartStartX - Partition start X index in integer pels * [in] PartStartY - Partition start Y index in integer pels * [in] pMVArr - Pointer to MV array storing neighbouring MVs for MV prediction * [in] pRefFrArr - Pointer to reference frame array storing neighbouring MVs for prediction * [in] Lambda - For calculating the cost * [out] pCost - Pointer to cost for Inter MB * * Return Value: * OMXResult * */static OMXResult armVCM4P10_PartitionME ( const OMX_U8* pSrcCurrBuf, OMX_S32 SrcCurrStep, const OMX_U8 *pSrcRefBufList[ARM_VCM4P10_MAX_FRAMES], OMX_S32 SrcRefStep, const OMXRect *pRefRect, const OMXVCM4P2Coordinate *pCurrPointPos, void* pMESpec, OMX_S32 PartWidth, OMX_S32 PartHeight, OMX_S32 BlockWidth, OMX_S32 BlockHeight, OMX_S32 PartStartX, OMX_S32 PartStartY, OMXVCMotionVector pMVArr [][12], OMX_S32 pRefFrArr [][6], OMXVCMotionVector pMVPredArr [][4], OMX_S32 Lambda, OMX_S32 *pCost){ OMX_U32 x, y, i, j, ref, OffX, OffY, OffSrc, OffRef; OMX_S32 BlockCost, PartitionCost, BestCost; OMX_S32 BestRefFrame=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -