📄 omxvcm4p10_motionestimationmb.c
字号:
OMXVCMotionVector BestMV [4][4]; OMXVCMotionVector BestMVPred [4][4]; OMXVCMotionVector MVPred; OMXVCMotionVector DstMV; BestCost = ARM_VCM4P10_MAX_COST; for (ref = 0; ref < ARM_VCM4P10_MAX_FRAMES; ref++) { if (pSrcRefBufList [ref] == NULL) { /* No reference frame, continue */ continue; } PartitionCost = 0; for (y = 0; y < PartHeight; y += BlockHeight) { for (x = 0; x < PartWidth; x += BlockWidth) { OffSrc = SrcCurrStep * (PartStartY + y) + PartStartX + x; OffRef = SrcRefStep * (PartStartY + y) + PartStartX + x; armVCM4P10_BlockMotionSearch ( pSrcCurrBuf + OffSrc, SrcCurrStep, pSrcRefBufList [ref] + OffRef, SrcRefStep, pRefRect, pCurrPointPos, pMESpec, Lambda, &BlockCost, &DstMV, x + PartStartX, y + PartStartY, BlockWidth, BlockHeight, ref, pRefFrArr, pMVArr, &MVPred); PartitionCost += BlockCost; OffX = (PartStartX + x) >> 2; OffY = (PartStartY + y) >> 2; for (j = 0; j < (BlockHeight >> 2); j++) { for (i = 0; i < (BlockWidth >> 2); i++) { pMVArr [4 + OffY + j][4 + OffX + i].dx = DstMV.dx; pMVArr [4 + OffY + j][4 + OffX + i].dy = DstMV.dy; pMVPredArr [OffY + j][OffX + i].dx = MVPred.dx; pMVPredArr [OffY + j][OffX + i].dy = MVPred.dy; } } pRefFrArr [2 + (OffY >> 1)][2 + (OffX >> 1)] = ref; for (j = 0; j < (BlockHeight >> 3); j++) { for (i = 0; i < (BlockWidth >> 3); i++) { pRefFrArr [2 + (OffY >> 1) + j][2 + (OffX >> 1) + i] = ref; } } } } /* * If PartitionCost is less for this reference frame, motion vectors needs to be backedup */ if (PartitionCost <= BestCost) { BestCost = PartitionCost; BestRefFrame = ref; for (y = 0; y < (PartHeight/BlockHeight); y++) { for (x = 0; x < (PartWidth/BlockWidth); x++) { OffX = (PartStartX + x * BlockWidth) >> 2; OffY = (PartStartY + y * BlockHeight) >> 2; BestMV[y][x].dx = pMVArr [4 + OffY][4 + OffX].dx; BestMV[y][x].dy = pMVArr [4 + OffY][4 + OffX].dy; BestMVPred[y][x].dx = pMVPredArr [OffY][OffX].dx; BestMVPred[y][x].dy = pMVPredArr [OffY][OffX].dy; } } } } /* * Copy back best reference frame, motion vectors and cost. */ for (y = 0; y < (PartHeight/BlockHeight); y++) { for (x = 0; x < (PartWidth/BlockWidth); x++) { OffX = (PartStartX + x * BlockWidth) >> 2; OffY = (PartStartY + y * BlockHeight) >> 2; for (j = 0; j < (BlockHeight >> 2); j++) { for (i = 0; i < (BlockWidth >> 2); i++) { pMVArr [4 + OffY + j][4 + OffX + i].dx = BestMV[y][x].dx; pMVArr [4 + OffY + j][4 + OffX + i].dy = BestMV[y][x].dy; pMVPredArr [OffY + j][OffX + i].dx = BestMVPred[y][x].dx; pMVPredArr [OffY + j][OffX + i].dy = BestMVPred[y][x].dy; } } for (j = 0; j < (BlockHeight >> 3); j++) { for (i = 0; i < (BlockWidth >> 3); i++) { pRefFrArr [2 + (OffY >> 1) + j][2 + (OffX >> 1) + i] = BestRefFrame; } } } } *pCost = BestCost; return OMX_Sts_NoErr;}/** * Function: armVCM4P10_Intra16x16Estimation * * Description: * Performs MB-level motion estimation for INTER MB type and selects best motion estimation strategy from * the set of modes supported in baseline profile ISO/IEC 14496-10. * * Remarks: * * Parameters: * [in] pSrcCurrBuf - Pointer to the start of luma component of current Macroblock * [in] SrcCurrStep - Step size for the pointer pSrcCurrBuf * [in] pSrcRecBuf - Pointer to the start of luma component of co-located reconstructed MB * [in] SrcRecStep - Step size for the pointer pSrcRecBuf * [in] nMBPosX - Position of MB in the frame w.r.t X axis * [in] nMBPosY - Position of MB in the frame w.r.t Y axis * [in] pMBInter - Array, of dimension four, containing pointers to information associated with four * adjacent type INTER MBs (Left, Top, Top-Left, Top-Right). * [in] pMBIntra - Array, of dimension four, containing pointers to information associated with four * adjacent type INTRA MBs (Left, Top, Top-Left, Top-Right). * [in/out] pSrcDstMBCurr - Pointer to information structure for the current MB. Following member should be set * before calling this function * [in] Lambda - For calculating the cost * [out] pCost - Pointer to cost for Intra16x16 * Return Value: * OMX_Sts_NoErr - No Error * OMX_Sts_BadArgErr - Bad arguments: * */static OMXResult armVCM4P10_Intra16x16Estimation( const OMX_U8* pSrcCurrBuf, OMX_S32 SrcCurrStep, const OMX_U8* pSrcRecBuf, OMX_S32 SrcRecStep, const OMXVCM4P2Coordinate *pCurrPointPos, const OMXVCM4P10MBInfoPtr *pMBInter, const OMXVCM4P10MBInfoPtr *pMBIntra, OMXVCM4P10MBInfo *pSrcDstMBCurr, OMX_U32 *pCost){ OMX_U8 PredBuf [16*16 + 16]; OMX_U8 *pPred; OMX_S32 mode; OMX_S32 Cost; OMX_S32 availability = 0; OMXResult Ret; OMXVCM4P10Intra16x16PredMode IntraMode16x16 [4] = {OMX_VC_16X16_VERT, OMX_VC_16X16_HOR, OMX_VC_16X16_DC, OMX_VC_16X16_PLANE}; OMX_U32 MBPosX = pCurrPointPos->x >> 4; OMX_U32 MBPosY = pCurrPointPos->y >> 4; pPred = armAlignTo16Bytes(PredBuf); /* Check for availability of LEFT MB */ if ((MBPosX != 0) && (pMBIntra [0] != 0 || pMBInter [0] != 0)) { availability |= OMX_VC_LEFT; } /* Check for availability of UP MB */ if ((MBPosY != 0) && (pMBIntra [1] != 0 || pMBInter [1] != 0)) { availability |= OMX_VC_UPPER; } /* Check for availability of UP-LEFT MB */ if ((MBPosX > 0) && (MBPosY > 0) && (pMBIntra [2] != 0 || pMBInter [2] != 0)) { availability |= OMX_VC_UPPER_LEFT; } *pCost = ARM_VCM4P10_MAX_COST; for (mode = 0; mode < 4; mode++) { Ret = omxVCM4P10_PredictIntra_16x16( pSrcRecBuf - 1, pSrcRecBuf - SrcRecStep, pSrcRecBuf - SrcRecStep - 1, pPred, SrcRecStep, 16, IntraMode16x16 [mode], availability); if (Ret == OMX_Sts_NoErr) { armVCCOMM_SAD( pSrcCurrBuf, SrcCurrStep, pPred, 16, &Cost, 16, 16); if (Cost < *pCost) { *pCost = Cost; pSrcDstMBCurr->Intra16x16PredMode = IntraMode16x16 [mode]; } } } return OMX_Sts_NoErr;}/** * Function: armVCM4P10_Intra4x4Estimation * * Description: * Performs MB-level motion estimation for Intra 4x4 MB type and selects * the best set of modes supported in baseline profile. * * Parameters: * [in] pSrcCurrBuf - Pointer to the start of luma component of current Macroblock * [in] SrcCurrStep - Step size for the pointer pSrcCurrBuf * [in] pSrcRecBuf - Pointer to the start of luma component of co-located reconstructed MB * [in] SrcRecStep - Step size for the pointer pSrcRecBuf * [in] nMBPosX - Position of MB in the frame w.r.t X axis * [in] nMBPosY - Position of MB in the frame w.r.t Y axis * [in] pMBIntra - Array, of dimension four, containing pointers to information associated with four * adjacent type INTRA MBs (Left, Top, Top-Left, Top-Right). * [in/out] pSrcDstMBCurr - Pointer to information structure for the current MB. Following member should be set * before calling this function * [in] Lambda - For calculating the cost * [out] pCost - Pointer to cost for Intra4x4 * Return Value: * OMX_Sts_NoErr - No Error * OMX_Sts_BadArgErr - Bad arguments: * */static OMXResult armVCM4P10_Intra4x4Estimation( const OMX_U8* pSrcCurrBuf, OMX_S32 SrcCurrStep, const OMX_U8* pSrcRecBuf, OMX_S32 SrcRecStep, const OMXVCM4P10MBInfoPtr *pMBIntra, OMXVCM4P10MBInfo *pSrcDstMBCurr, OMX_U32 *pCost){ OMX_S32 x, y, Block4x4, Block8x8; OMX_S32 Cost; /* * PredIntra4x4Mode will store prediction modes of 4x4 blocks. * Modes for current MB starts at index [1][1]. * Modes of nighbouring MB's will be as shown below * A value of ARM_VCM4P10_INVALID_BLOCK for any block in this array means * that block is not available for prediction. * * c3 b0 b1 b2 b3 d0 d1 d2 d3 * a0 xx xx xx xx - - - - * a1 xx xx xx xx - - - - * a2 xx xx xx xx - - - - * a3 xx xx xx xx - - - - * */ OMX_S32 PredIntra4x4Mode [5][9]; /* * pSrcY stores re-construsted source array of size 3MB X 2MB as below * * MB11 MB12 MB13 * MB21 MB22 MB23 * * This array will be used for local reconstruction of 4x4 blocks * with best prediction mode within an MB */ OMX_U8 pSrcY [(16*3)*(16*2)]; OMX_S32 StepSrcY; /* init */ *pCost = 0; for (y = 0; y < 5; y++) { for (x = 0; x < 9; x++) { /* * Initialize with value of ARM_VCM4P10_INVALID_BLOCK, to mean this * 4x4 block is not available */ PredIntra4x4Mode [y][x] = ARM_VCM4P10_INVALID_BLOCK; } } /* Replace ARM_VCM4P10_INVALID_BLOCK value with available MBs values*/ for (x = 0; x < 4; x++) { /* Store values of b0, b1, b2, b3 */ if (pMBIntra[1] != NULL) { PredIntra4x4Mode [0][x + 1] = pMBIntra[1]->pIntra4x4PredMode[3*4 + x]; } /* Store values of d0, d1, d2, d3 */ if (pMBIntra[3] != NULL) { PredIntra4x4Mode [0][x + 5] = pMBIntra[3]->pIntra4x4PredMode[3*4 + x]; } } /* Store values of c3 */ if (pMBIntra[2] != NULL) { PredIntra4x4Mode [0][0] = pMBIntra[2]->pIntra4x4PredMode[15]; } for (y = 0; y < 4; y++) { /* Store values of a0, a1, a2, a3 */ if (pMBIntra[0] != NULL) { PredIntra4x4Mode [y + 1][0] = pMBIntra[0]->pIntra4x4PredMode[y*4 + 3]; } } /* * Update neighbouring Pred mode array which will be used for * prediction of Intra4x4 modes. */ StepSrcY = 16 * 3; for (y = 0; y < (16 * 2); y++) { for (x = 0; x < (16 * 3); x++) { pSrcY [StepSrcY * y + x] = pSrcRecBuf [SrcRecStep * (y - 16) + x - 16]; } } /* for each 8x8 block */ for (Block8x8 = 0; Block8x8 < 4; Block8x8++) { /* for each 4x4 block inside 8x8 block */ for (Block4x4 = 0; Block4x4 < 4; Block4x4++) { armVCM4P10_Mode4x4Decision ( pSrcCurrBuf, SrcCurrStep, pSrcDstMBCurr, Block8x8, Block4x4, pSrcY + 16 * StepSrcY + 16, StepSrcY, PredIntra4x4Mode, &Cost); *pCost += Cost; } } return OMX_Sts_NoErr;}/** * Function: armVCM4P10_InterMEMB * * Description: * Performs MB-level motion estimation for INTER MB type and selects best motion estimation strategy from * the set of modes supported in baseline profile ISO/IEC 14496-10. * * Remarks: * * 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 the start of luma component of co-located reference MB * [in] SrcRefStep - 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/out] pSrcDstMBCurr - Pointer to information structure for the current MB. Following member should be set * before calling this function * [in] Lambda - For calculating the cost * [out] pDstCost - Pointer to cost for Inter MB * Return Value: * OMX_Sts_NoErr - No Error * OMX_Sts_BadArgErr - Bad arguments: * */static OMXResult armVCM4P10_InterMEMB( const OMX_U8 *pSrcCurrBuf, OMX_S32 SrcCurrStep, const OMX_U8 *pSrcRefBufList[ARM_VCM4P10_MAX_FRAMES], OMX_S32 SrcRefStep, const OMXRect *pRefRect, const OMXVCM4P2Coordinate *pCurrPointPos, OMX_U32 Lambda, void *pMESpec, const OMXVCM4P10MBInfoPtr *pMBInter, OMXVCM4P10MBInfoPtr pSrcDstMBCurr, OMX_U32 *pDstCost){ OMX_S32 i, j, x, y, mode; OMX_U32 Block8x8, XPerMB, YPerMB, Block2x, Block2y; OMX_S32 PartStartX = 0, PartStartY = 0; OMX_S32 PartWidth = 8, PartHeight = 8, BlockWidth = 4, BlockHeight = 4; const OMX_U32 BlkSz [4][2] = {{4,4}, {4,8}, {8,4}}; const OMX_U32 PartSz [4][2] = {{8,8}, {8,16}, {16,8}, {16,16}}; const OMXVCM4P10SubMacroblockType ModeSubMBType4x4 [] = {OMX_VC_SUB_P_4x4, OMX_VC_SUB_P_4x8, OMX_VC_SUB_P_8x4, OMX_VC_SUB_P_8x8}; const OMXVCM4P10MacroblockType ModeMBType [] = {OMX_VC_P_8x8, OMX_VC_P_8x16, OMX_VC_P_16x8, OMX_VC_P_16x16}; OMXVCM4P10MEParams *pMBOptions; /* * RefFrArr and MVArr will be used for temporary storage of Reference frame index and MVs * It will store RefIndex and MVs of 6 MBs as shown below * * |------|------|------| * |Tp-Lt |Top |Tp-R | * | MB | MB | MB | * |------|------|------| * |Left | Curr | | * | MB | MB | | * |------|------|------| */ OMX_S32 RefFrArr [4][6]; OMXVCMotionVector MVArr [8][12]; OMXVCMotionVector MVPredArr [4][4]; /* * IndexToLoc will translate pMBInter index into spacial arrangement of MBs */ OMX_S32 IndexToLoc [] = {2,1,3,0}; OMX_U32 part, MaxPart; OMX_S32 Cost, MotionCost8x8 [4], MBCost, BestCost;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -