📄 omxvcm4p10_motionestimationmb.c
字号:
/* * Update neighbouring MV array and Ref frame array which will be used for * prediction of MVs and Ref frames. */ /* Set cost to a high value */ Cost = BestCost = ARM_VCM4P10_MAX_COST; for (y = 0; y < 8; y++) { for (x = 0; x < 12; x++) { i = 3 * (y >> 2) + (x >> 2); if ((y < 4 || x < 4) && (pMBInter[IndexToLoc[i]] != NULL)) { MVArr [y][x].dx = pMBInter[IndexToLoc[i]]->pMV0[y % 4][x % 4].dx; MVArr [y][x].dy = pMBInter[IndexToLoc[i]]->pMV0[y % 4][x % 4].dy; } else { MVArr [y][x].dx = 0; MVArr [y][x].dy = 0; } } } for (y = 0; y < 4; y++) { for (x = 0; x < 6; x++) { i = 3 * (y >> 1) + (x >> 1); if ((y < 2 || x < 2) && (pMBInter[IndexToLoc[i]] != NULL)) { RefFrArr [y][x] = pMBInter[IndexToLoc[i]]->pRefL0Idx [(y % 2) * 2 + (x % 2)]; } else { RefFrArr [y][x] = ARM_VCM4P10_INVALID_BLOCK; } } } for (y = 0; y < 4; y++) { for (x = 0; x < 4; x++) { MVPredArr [y][x].dx = 0; MVPredArr [y][x].dy = 0; } } /* * Motion Estimation for 8x8 MB Partition */ for (i = 0; i < 4; i++) { MotionCost8x8 [i] = 0; } pMBOptions = (OMXVCM4P10MEParams *) pMESpec; if (pMBOptions->blockSplitEnable8x8 == 1 && pMBOptions->blockSplitEnable4x4 == 1) { pSrcDstMBCurr->mbType = OMX_VC_P_8x8; PartWidth = PartSz [0][0]; PartHeight = PartSz [0][1]; /* For each 8x8 partitions */ for (Block8x8 = 0; Block8x8 < 4; Block8x8++) { PartStartX = (Block8x8 % 2) << 3; PartStartY = (Block8x8 / 2) << 3; Block2x = (Block8x8 & 1) << 1; Block2y = (Block8x8 >> 1) << 1; BestCost = ARM_VCM4P10_MAX_COST; for (mode = 0; mode < 3; mode++) { BlockWidth = BlkSz [mode][0]; BlockHeight = BlkSz [mode][1]; armVCM4P10_PartitionME ( pSrcCurrBuf, SrcCurrStep, pSrcRefBufList, SrcRefStep, pRefRect, pCurrPointPos, pMESpec, PartWidth, PartHeight, BlockWidth, BlockHeight, PartStartX, PartStartY, MVArr, RefFrArr, MVPredArr, Lambda, &Cost); if (Cost <= BestCost) { /* Update cost */ BestCost = Cost; /* Update MBCurr struct */ pSrcDstMBCurr->subMBType [Block8x8] = ModeSubMBType4x4 [mode]; pSrcDstMBCurr->pRefL0Idx [Block8x8] = RefFrArr [2 + (PartStartY >> 3)][2 + (PartStartX >> 3)]; /* Update pMV0 and pMVPred of MBCurr struct */ for (j = 0; j < 2; j++) { for (i = 0; i < 2; i++) { pSrcDstMBCurr->pMV0 [Block2y + j][Block2x + i].dx = MVArr [4 + Block2y + j][4 + Block2x + i].dx; pSrcDstMBCurr->pMV0 [Block2y + j][Block2x + i].dy = MVArr [4 + Block2y + j][4 + Block2x + i].dy; pSrcDstMBCurr->pMVPred [Block2y + j][Block2x + i].dx = MVPredArr [Block2y + j][Block2x + i].dx; pSrcDstMBCurr->pMVPred [Block2y + j][Block2x + i].dy = MVPredArr [Block2y + j][Block2x + i].dy; } } } } /* Update cost */ MotionCost8x8 [Block8x8] = BestCost; } /* Cost for mbType OMX_VC_P_8x8 */ BestCost = 0; for (i = 0; i < 4; i++) { BestCost += MotionCost8x8 [i]; } } else { /* Set sub MB type to 8x8 */ for (i = 0; i < 4; i++) { pSrcDstMBCurr->subMBType [i] = OMX_VC_SUB_P_8x8; } } /* * Motion Estimation for 8x8, 8x16, 16x8 and 16x16 MB Partition * If pMBOptions->b8x8BlockSplitEnable is 0, do only 16x16 ME (mode 3) */ for (mode = (pMBOptions->blockSplitEnable8x8 == 1 ? 0 : 3); mode < 4; mode++) { BlockWidth = PartWidth = PartSz [mode][0]; BlockHeight = PartHeight = PartSz [mode][1]; XPerMB = 16 / PartWidth; YPerMB = 16 / PartHeight; MaxPart = XPerMB * YPerMB; MBCost = 0; /* part size 4, 2, 2 and 1 corresponding to 8x8, 8x16, 16x8 and 16x16 MB */ for (part = 0; part < MaxPart; part++) { PartStartX = (part % XPerMB) * PartWidth; PartStartY = (part / XPerMB) * PartHeight; armVCM4P10_PartitionME ( pSrcCurrBuf, SrcCurrStep, pSrcRefBufList, SrcRefStep, pRefRect, pCurrPointPos, pMESpec, PartWidth, PartHeight, BlockWidth, BlockHeight, PartStartX, PartStartY, MVArr, RefFrArr, MVPredArr, Lambda, &Cost); MBCost += Cost; } if (MBCost <= BestCost) { /* Update cost */ BestCost = MBCost; /* Update mbType of MBCurr struct */ pSrcDstMBCurr->mbType = ModeMBType [mode]; /* Update pMV0 and pMVPred of MBCurr struct */ for (j = 0; j < 4; j++) { for (i = 0; i < 4; i++) { pSrcDstMBCurr->pMV0 [j][i].dx = MVArr [4+j][4+i].dx; pSrcDstMBCurr->pMV0 [j][i].dy = MVArr [4+j][4+i].dy; pSrcDstMBCurr->pMVPred [j][i].dx = MVPredArr [j][i].dx; pSrcDstMBCurr->pMVPred [j][i].dy = MVPredArr [j][i].dy; } } for (j = 0; j < 2; j++) { for (i = 0; i < 2; i++) { pSrcDstMBCurr->pRefL0Idx [j*2+i] = RefFrArr [2+j][2+i]; } } } } /* Update Best Cost */ *pDstCost = BestCost; return OMX_Sts_NoErr;}/** * Function: omxVCM4P10_MotionEstimationMB (6.3.5.3.1) * * Description: * Performs MB-level motion estimation and selects best motion estimation * strategy from the set of modes supported in baseline profile [ISO14496-10]. * * Input Arguments: * * pSrcCurrBuf - Pointer to the current position in original picture plane; * 16-byte alignment required * pSrcRefBufList - Pointer to an array with 16 entries. Each entry points * to the top-left corner of the co-located MB in a reference * picture. The array is filled from low-to-high with valid * reference frame pointers; the unused high entries should be set * to NULL. Ordering of the reference frames should follow * [ISO14496-10] subclause 8.2.4 Decoding Process for Reference * Picture Lists. The entries must be 16-byte aligned. * pSrcRecBuf - Pointer to the top-left corner of the co-located MB in the * reconstructed picture; must be 16-byte aligned. * SrcCurrStep - Width of the original picture plane in terms of full * pixels; must be a multiple of 16. * SrcRefStep - Width of the reference picture plane in terms of full * pixels; must be a multiple of 16. * SrcRecStep - Width of the reconstructed picture plane in terms of full * pixels; must be a multiple of 16. * pRefRect - Pointer to the valid reference rectangle; relative to the * image origin. * pCurrPointPos - Position of the current macroblock in the current plane. * Lambda - Lagrange factor for computing the cost function * pMESpec - Pointer to the motion estimation specification structure; must * have been allocated and initialized prior to calling this * function. * pMBInter - Array, of dimension four, containing pointers to information * associated with four adjacent type INTER MBs (Left, Top, * Top-Left, Top-Right). Any pointer in the array may be set equal * to NULL if the corresponding MB doesn t exist or is not of type * INTER. pMBInter[0] - Pointer to left MB information pMBInter[1] * - Pointer to top MB information pMBInter[2] - Pointer to * top-left MB information pMBInter[3] - Pointer to top-right MB * information * pMBIntra - Array, of dimension four, containing pointers to information * associated with four adjacent type INTRA MBs (Left, Top, * Top-Left, Top-Right). Any pointer in the array may be set equal * to NULL if the corresponding MB doesn t exist or is not of type * INTRA. pMBIntra[0] - Pointer to left MB information pMBIntra[1] * - Pointer to top MB information pMBIntra[2] - Pointer to * top-left MB information pMBIntra[3] - Pointer to top-right MB * information * pSrcDstMBCurr - Pointer to information structure for the current MB. * The following entries should be set prior to calling the * function: sliceID - the number of the slice the to which the * current MB belongs. * * Output Arguments: * * pDstCost - Pointer to the minimum motion cost for the current MB. * pDstBlockSAD - Pointer to the array of SADs for each of the sixteen luma * 4x4 blocks in each MB. The block SADs are in scan order for * each MB. For implementations that cannot compute the SAD values * individually, the maximum possible value (0xffff) is returned * for each of the 16 block SAD entries. * pSrcDstMBCurr - Pointer to updated information structure for the current * MB after MB-level motion estimation has been completed. The * following fields are updated by the ME function. The following * parameter set quantifies the MB-level ME search results: MbType * subMBType[4] pMV0[4][4] pMVPred[4][4] pRefL0Idx[4] * Intra16x16PredMode pIntra4x4PredMode[4][4] * * Return Value: * OMX_Sts_NoErr, if the function runs without error. * OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: * - One of more of the following pointers is NULL: pSrcCurrBuf, * pSrcRefBufList, pSrcRecBuf, pRefRect, pCurrPointPos, pMESpec, * pMBInter, pMBIntra,pSrcDstMBCurr, pDstCost, pSrcRefBufList[0] * - SrcRefStep, SrcRecStep are not multiples of 16 * - iBlockWidth or iBlockHeight are values other than 4, 8, or 16. * - Any alignment restrictions are violated * */ OMXResult omxVCM4P10_MotionEstimationMB( const OMX_U8 *pSrcCurrBuf, OMX_S32 SrcCurrStep, const OMX_U8 *pSrcRefBufList[ARM_VCM4P10_MAX_FRAMES], OMX_S32 SrcRefStep, const OMX_U8 *pSrcRecBuf, OMX_S32 SrcRecStep, const OMXRect *pRefRect, const OMXVCM4P2Coordinate *pCurrPointPos, OMX_U32 Lambda, void *pMESpec, const OMXVCM4P10MBInfoPtr *pMBInter, const OMXVCM4P10MBInfoPtr *pMBIntra, OMXVCM4P10MBInfo *pSrcDstMBCurr, OMX_INT *pDstCost, OMX_U16 *pDstBlockSAD){ OMX_U32 Cost, i, IntraFlag = 1; OMXVCM4P10MEParams *pMEParams; /* check for argument error */ armRetArgErrIf(pSrcCurrBuf == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pSrcRefBufList == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pSrcRecBuf == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pRefRect == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pCurrPointPos == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pMESpec == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pMBInter == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pMBIntra == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pSrcDstMBCurr == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(pDstCost == NULL, OMX_Sts_BadArgErr) armRetArgErrIf(SrcRefStep <= 0 || SrcRefStep & 15, OMX_Sts_BadArgErr) armRetArgErrIf(SrcRecStep <= 0 || SrcRecStep & 15, OMX_Sts_BadArgErr) armRetArgErrIf(SrcCurrStep <= 0 || SrcCurrStep & 15, OMX_Sts_BadArgErr) armRetArgErrIf(armNot16ByteAligned(pSrcCurrBuf), OMX_Sts_BadArgErr) armRetArgErrIf(armNot16ByteAligned(pSrcRecBuf), OMX_Sts_BadArgErr) for (i = 0; i < ARM_VCM4P10_MAX_FRAMES; i++) { armRetArgErrIf(pSrcRefBufList [i] != NULL && armNot16ByteAligned(pSrcRefBufList [i]), OMX_Sts_BadArgErr) /* Check if current MB needs INTER cost calculations */ if (pSrcRefBufList [i] != NULL && IntraFlag == 1) { IntraFlag = 0; } } *pDstCost = ARM_VCM4P10_MAX_COST; /* * Inter cost calculations */ /* check this MB can be Inter */ if (IntraFlag != 1) { armVCM4P10_InterMEMB( pSrcCurrBuf, SrcCurrStep, pSrcRefBufList, SrcRefStep, pRefRect, pCurrPointPos, Lambda, pMESpec, pMBInter, pSrcDstMBCurr, &Cost ); *pDstCost = Cost; } pMEParams = (OMXVCM4P10MEParams *)pMESpec; if (pMEParams->intraEnable4x4 == 1) { /* * Intra 4x4 cost calculations */ armVCM4P10_Intra4x4Estimation( pSrcCurrBuf, SrcCurrStep, pSrcRecBuf, SrcRecStep, pMBIntra, pSrcDstMBCurr, &Cost ); if (Cost <= *pDstCost) { *pDstCost = Cost; pSrcDstMBCurr->mbType = OMX_VC_INTRA_4x4; } } /* * Cost for Intra 16x16 mode */ armVCM4P10_Intra16x16Estimation( pSrcCurrBuf, SrcCurrStep, pSrcRecBuf, SrcRecStep, pCurrPointPos, pMBInter, pMBIntra, pSrcDstMBCurr, &Cost ); if (Cost <= *pDstCost) { *pDstCost = Cost; pSrcDstMBCurr->mbType = OMX_VC_INTRA_16x16; } /* * Update pDstBlockSAD to max value */ armVCM4P10_CalculateBlockSAD( pSrcDstMBCurr, pSrcCurrBuf, SrcCurrStep, pSrcRefBufList, SrcRefStep, pSrcRecBuf, SrcRecStep, pRefRect, pCurrPointPos, pMBInter, pMBIntra, pDstBlockSAD); return OMX_Sts_NoErr;}/***************************************************************************** * END OF FILE *****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -