Showing the changes to test/decoder/DecUT_PredMv.cpp (1 of 23 files). Show all
Unified · Split
| @@ -0,0 +1,670 @@ | |||
| 1 | #include<gtest/gtest.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <time.h> | ||
| 4 | |||
| 5 | #include "../codec/decoder/core/inc/wels_common_basis.h" | ||
| 6 | #include "../codec/decoder/core/inc/mem_align.h" | ||
| 7 | #include "../codec/decoder/core/inc/mv_pred.h" | ||
| 8 | #include "ls_defines.h" | ||
| 9 | |||
| 10 | using namespace WelsDec; | ||
| 11 | |||
| 12 | //Anchor functions | ||
| 13 | #define REF_NOT_AVAIL -2 | ||
| 14 | #define REF_NOT_IN_LIST -1 //intra | ||
| 15 | |||
| 16 | //cache element equal to 30 | ||
| 17 | const uint8_t g_kuiAnchorCache30ScanIdx[16] = { //mv or ref_index cache scan index, 4*4 block as basic unit | ||
| 18 | 7, 8, 13, 14, | ||
| 19 | 9, 10, 15, 16, | ||
| 20 | 19, 20, 25, 26, | ||
| 21 | 21, 22, 27, 28 | ||
| 22 | }; | ||
| 23 | |||
| 24 | typedef struct TagAnchorMvPred { | ||
| 25 | int16_t iMvArray[2][30][2]; | ||
| 26 | int8_t iRefIdxArray[2][30]; | ||
| 27 | int32_t iPartIdx; | ||
| 28 | int32_t iPartWidth; | ||
| 29 | int32_t iRef; | ||
| 30 | int16_t iMvp[2]; | ||
| 31 | } SAnchorMvPred; | ||
| 32 | |||
| 33 | void AnchorPredMv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30], | ||
| 34 | int32_t iPartIdx, int32_t iPartWidth, int8_t iRef, int16_t iMVP[2]) { | ||
| 35 | const uint8_t kuiLeftIdx = g_kuiAnchorCache30ScanIdx[iPartIdx] - 1; | ||
| 36 | const uint8_t kuiTopIdx = g_kuiAnchorCache30ScanIdx[iPartIdx] - 6; | ||
| 37 | const uint8_t kuiRightTopIdx = kuiTopIdx + iPartWidth; | ||
| 38 | const uint8_t kuiLeftTopIdx = kuiTopIdx - 1; | ||
| 39 | const int8_t kiLeftRef = iRefIndex[0][kuiLeftIdx]; | ||
| 40 | const int8_t kiTopRef = iRefIndex[0][kuiTopIdx]; | ||
| 41 | const int8_t kiRightTopRef = iRefIndex[0][kuiRightTopIdx]; | ||
| 42 | const int8_t kiLeftTopRef = iRefIndex[0][kuiLeftTopIdx]; | ||
| 43 | int8_t iDiagonalRef = kiRightTopRef; | ||
| 44 | int8_t iMatchRef = 0; | ||
| 45 | |||
| 46 | int16_t iAMV[2], iBMV[2], iCMV[2]; | ||
| 47 | |||
| 48 | * (int32_t*)iAMV = INTD32 (iMotionVector[0][kuiLeftIdx]); | ||
| 49 | * (int32_t*)iBMV = INTD32 (iMotionVector[0][kuiTopIdx]); | ||
| 50 | * (int32_t*)iCMV = INTD32 (iMotionVector[0][kuiRightTopIdx]); | ||
| 51 | |||
| 52 | if (REF_NOT_AVAIL == iDiagonalRef) { | ||
| 53 | iDiagonalRef = kiLeftTopRef; | ||
| 54 | * (int32_t*)iCMV = INTD32 (iMotionVector[0][kuiLeftTopIdx]); | ||
| 55 | } | ||
| 56 | |||
| 57 | iMatchRef = (iRef == kiLeftRef) + (iRef == kiTopRef) + (iRef == iDiagonalRef); | ||
| 58 | |||
| 59 | if ((REF_NOT_AVAIL == kiTopRef) && (REF_NOT_AVAIL == iDiagonalRef) && (kiLeftRef >= REF_NOT_IN_LIST)) { | ||
| 60 | ST32 (iMVP, LD32 (iAMV)); | ||
| 61 | return; | ||
| 62 | } | ||
| 63 | |||
| 64 | if (1 == iMatchRef) { | ||
| 65 | if (iRef == kiLeftRef) { | ||
| 66 | ST32 (iMVP, LD32 (iAMV)); | ||
| 67 | } else if (iRef == kiTopRef) { | ||
| 68 | ST32 (iMVP, LD32 (iBMV)); | ||
| 69 | } else { | ||
| 70 | ST32 (iMVP, LD32 (iCMV)); | ||
| 71 | } | ||
| 72 | } else { | ||
| 73 | iMVP[0] = WelsMedian (iAMV[0], iBMV[0], iCMV[0]); | ||
| 74 | iMVP[1] = WelsMedian (iAMV[1], iBMV[1], iCMV[1]); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | void AnchorPredInter8x16Mv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30], | ||
| 79 | int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]) { | ||
| 80 | if (0 == iPartIdx) { | ||
| 81 | const int8_t kiLeftRef = iRefIndex[0][6]; | ||
| 82 | if (iRef == kiLeftRef) { | ||
| 83 | ST32 (iMVP, LD32 (&iMotionVector[0][6][0])); | ||
| 84 | return; | ||
| 85 | } | ||
| 86 | } else { // 4 == iPartIdx | ||
| 87 | int8_t iDiagonalRef = iRefIndex[0][5]; //top-right | ||
| 88 | int8_t index = 5; | ||
| 89 | if (REF_NOT_AVAIL == iDiagonalRef) { | ||
| 90 | iDiagonalRef = iRefIndex[0][2]; //top-left for 8*8 block(index 1) | ||
| 91 | index = 2; | ||
| 92 | } | ||
| 93 | if (iRef == iDiagonalRef) { | ||
| 94 | ST32 (iMVP, LD32 (&iMotionVector[0][index][0])); | ||
| 95 | return; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | AnchorPredMv (iMotionVector, iRefIndex, iPartIdx, 2, iRef, iMVP); | ||
| 100 | } | ||
| 101 | |||
| 102 | void AnchorPredInter16x8Mv (int16_t iMotionVector[LIST_A][30][MV_A], int8_t iRefIndex[LIST_A][30], | ||
| 103 | int32_t iPartIdx, int8_t iRef, int16_t iMVP[2]) { | ||
| 104 | if (0 == iPartIdx) { | ||
| 105 | const int8_t kiTopRef = iRefIndex[0][1]; | ||
| 106 | if (iRef == kiTopRef) { | ||
| 107 | ST32 (iMVP, LD32 (&iMotionVector[0][1][0])); | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | } else { // 8 == iPartIdx | ||
| 111 | const int8_t kiLeftRef = iRefIndex[0][18]; | ||
| 112 | if (iRef == kiLeftRef) { | ||
| 113 | ST32 (iMVP, LD32 (&iMotionVector[0][18][0])); | ||
| 114 | return; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | AnchorPredMv (iMotionVector, iRefIndex, iPartIdx, 4, iRef, iMVP); | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
| 122 | //Ref functions in WelsDec | ||
| 123 | //Input structure for test | ||
| 124 | typedef struct TagWelsMvPred { | ||
| 125 | int16_t iMvArray[2][30][2]; | ||
| 126 | int8_t iRefIdxArray[2][30]; | ||
| 127 | int32_t iPartIdx; | ||
| 128 | int32_t iPartWidth; | ||
| 129 | int32_t iRef; | ||
| 130 | int16_t iMvp[2]; | ||
| 131 | } SWelsMvPred; | ||
| 132 | |||
| 133 | //mok input data | ||
| 134 | void AssignMvInputData (SAnchorMvPred* pAncMvPred) { | ||
| 135 | int32_t i, j, k; | ||
| 136 | srand ((uint32_t)time (NULL)); | ||
| 137 | //fill MV data and refIdx | ||
| 138 | for (i = 0; i < 2; ++i) { | ||
| 139 | for (j = 0; j < 30; ++j) { | ||
| 140 | for (k = 0; k < 2; ++k) { | ||
| 141 | pAncMvPred->iMvArray[i][j][k] = (rand() - RAND_MAX / 2); | ||
| 142 | } | ||
| 143 | pAncMvPred->iRefIdxArray[i][j] = (rand() % 18) - 2; //-2 ~ 15. 8x8 may have different values, but it matters nothing | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | void CopyMvInputData (SAnchorMvPred* pDstMvPred, SWelsMvPred* pSrcMvPred) { | ||
| 149 | int32_t i, j, k; | ||
| 150 | //fill MV data and refIdx | ||
| 151 | for (i = 0; i < 2; ++i) { | ||
| 152 | for (j = 0; j < 30; ++j) { | ||
| 153 | for (k = 0; k < 2; ++k) { | ||
| 154 | pDstMvPred->iMvArray[i][j][k] = pSrcMvPred->iMvArray[i][j][k]; | ||
| 155 | } | ||
| 156 | pDstMvPred->iRefIdxArray[i][j] = pSrcMvPred->iRefIdxArray[i][j]; | ||
| 157 | } | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | #define INIT_MV_DATA \ | ||
| 162 | AssignMvInputData (&sAncMvPred); \ | ||
| 163 | CopyMvInputData (&sAncMvPred, &sWelsMvPred); | ||
| 164 | |||
| 165 | #define TEST_MV_PRED \ | ||
| 166 | AnchorPredMv (sAncMvPred.iMvArray, sAncMvPred.iRefIdxArray, iIndex, iBlockWidth, iRef, sAncMvPred.iMvp); \ | ||
| 167 | PredMv (sWelsMvPred.iMvArray, sWelsMvPred.iRefIdxArray, iIndex, iBlockWidth, iRef, sWelsMvPred.iMvp); \ | ||
| 168 | bOK = ((sAncMvPred.iMvp[0] == sWelsMvPred.iMvp[0]) && (sAncMvPred.iMvp[1] == sWelsMvPred.iMvp[1])); \ | ||
| 169 | EXPECT_EQ (bOK, true); | ||
| 170 | |||
| 171 | |||
| 172 | //TEST cases followed | ||
| 173 | |||
| 174 | TEST (PredMvTest, PredMv) { | ||
| 175 | SWelsMvPred sWelsMvPred; | ||
| 176 | SAnchorMvPred sAncMvPred; | ||
| 177 | int32_t i, iRef, iBlockWidth, iIndex; | ||
| 178 | const int32_t kiRandTime = 100; | ||
| 179 | bool bOK = true; | ||
| 180 | |||
| 181 | //test specific input: 16x16 | ||
| 182 | iIndex = 0; | ||
| 183 | iBlockWidth = 4; | ||
| 184 | i = 0; | ||
| 185 | srand ((uint32_t)time (NULL)); | ||
| 186 | while (i++ < kiRandTime) { | ||
| 187 | iRef = (rand() % 18) - 2; //-2~15 | ||
| 188 | INIT_MV_DATA; | ||
| 189 | TEST_MV_PRED; | ||
| 190 | } | ||
| 191 | //test specific input: 16x8 | ||
| 192 | iBlockWidth = 4; | ||
| 193 | i = 0; | ||
| 194 | while (i++ < kiRandTime) { | ||
| 195 | iIndex = (rand() & 1) << 3; //0,8 | ||
| 196 | iRef = (rand() % 18) - 2; //-2~15 | ||
| 197 | INIT_MV_DATA; | ||
| 198 | TEST_MV_PRED; | ||
| 199 | } | ||
| 200 | //test specific input: 8x16 | ||
| 201 | iBlockWidth = 2; | ||
| 202 | i = 0; | ||
| 203 | while (i++ < kiRandTime) { | ||
| 204 | iIndex = (rand() & 1) << 2; //0,4 | ||
| 205 | iRef = (rand() % 18) - 2; //-2~15 | ||
| 206 | INIT_MV_DATA; | ||
| 207 | TEST_MV_PRED; | ||
| 208 | } | ||
| 209 | //test specific input: 8x8 | ||
| 210 | iBlockWidth = 2; | ||
| 211 | i = 0; | ||
| 212 | while (i++ < kiRandTime) { | ||
| 213 | iIndex = (rand() & 3) << 2; //0,4,8,12 | ||
| 214 | iRef = (rand() % 18) - 2; //-2~15 | ||
| 215 | INIT_MV_DATA; | ||
| 216 | TEST_MV_PRED; | ||
| 217 | } | ||
| 218 | //test specific input: 4x4 | ||
| 219 | iBlockWidth = 1; | ||
| 220 | i = 0; | ||
| 221 | while (i++ < kiRandTime) { | ||
| 222 | iIndex = rand() & 0x0f; //0~15 | ||
| 223 | iRef = (rand() % 18) - 2; //-2~15 | ||
| 224 | INIT_MV_DATA; | ||
| 225 | TEST_MV_PRED; | ||
| 226 | } | ||
| 227 | } //TEST PredMv | ||
| 228 | |||
| 229 | |||
| 230 | TEST (PredMvTest, PredInter16x8Mv) { | ||
| 231 | SWelsMvPred sWelsMvPred; | ||
| 232 | SAnchorMvPred sAncMvPred; | ||
| 233 | int32_t i, iRef, iIndex; | ||
| 234 | const int32_t kiRandTime = 100; | ||
| 235 | bool bOK = true; | ||
| 236 | |||
| 237 | i = 0; | ||
| 238 | srand ((uint32_t)time (NULL)); | ||
| 239 | while (i++ < kiRandTime) { | ||
| 240 | iIndex = (rand() & 1) << 3; //0, 8 | ||
| 241 | iRef = (rand() % 18) - 2; //-2~15 | ||
| 242 | INIT_MV_DATA; | ||
| 243 | AnchorPredInter16x8Mv (sAncMvPred.iMvArray, sAncMvPred.iRefIdxArray, iIndex, iRef, sAncMvPred.iMvp); | ||
| 244 | PredInter16x8Mv (sWelsMvPred.iMvArray, sWelsMvPred.iRefIdxArray, iIndex, iRef, sWelsMvPred.iMvp); | ||
| 245 | bOK = ((sAncMvPred.iMvp[0] == sWelsMvPred.iMvp[0]) && (sAncMvPred.iMvp[1] == sWelsMvPred.iMvp[1])); | ||
| 246 | EXPECT_EQ (bOK, true); | ||
| 247 | } | ||
| 248 | } //TEST PredInter16x8Mv | ||
| 249 | |||
| 250 | TEST (PredMvTest, PredInter8x16Mv) { | ||
| 251 | SWelsMvPred sWelsMvPred; | ||
| 252 | SAnchorMvPred sAncMvPred; | ||
| 253 | int32_t i, iRef, iIndex; | ||
| 254 | const int32_t kiRandTime = 100; | ||
| 255 | bool bOK = true; | ||
| 256 | |||
| 257 | i = 0; | ||
| 258 | srand ((uint32_t)time (NULL)); | ||
| 259 | while (i++ < kiRandTime) { | ||
| 260 | iIndex = (rand() & 1) << 2; //0, 4 | ||
| 261 | iRef = (rand() % 18) - 2; //-2~15 | ||
| 262 | INIT_MV_DATA; | ||
| 263 | AnchorPredInter8x16Mv (sAncMvPred.iMvArray, sAncMvPred.iRefIdxArray, iIndex, iRef, sAncMvPred.iMvp); | ||
| 264 | PredInter8x16Mv (sWelsMvPred.iMvArray, sWelsMvPred.iRefIdxArray, iIndex, iRef, sWelsMvPred.iMvp); | ||
| 265 | bOK = ((sAncMvPred.iMvp[0] == sWelsMvPred.iMvp[0]) && (sAncMvPred.iMvp[1] == sWelsMvPred.iMvp[1])); | ||
| 266 | EXPECT_EQ (bOK, true); | ||
| 267 | } | ||
| 268 | } //TEST PredInter16x8Mv | ||
| 269 | |||
| 270 | void AnchorPredPSkipMvFromNeighbor (PDqLayer pCurLayer, int16_t iMvp[2]) { | ||
| 271 | bool bTopAvail, bLeftTopAvail, bRightTopAvail, bLeftAvail; | ||
| 272 | |||
| 273 | int32_t iCurSliceIdc, iTopSliceIdc, iLeftTopSliceIdc, iRightTopSliceIdc, iLeftSliceIdc; | ||
| 274 | int32_t iLeftTopType, iRightTopType, iTopType, iLeftType; | ||
| 275 | int32_t iCurX, iCurY, iCurXy, iLeftXy, iTopXy, iLeftTopXy, iRightTopXy; | ||
| 276 | |||
| 277 | int8_t iLeftRef; | ||
| 278 | int8_t iTopRef; | ||
| 279 | int8_t iRightTopRef; | ||
| 280 | int8_t iLeftTopRef; | ||
| 281 | int8_t iDiagonalRef; | ||
| 282 | int8_t iMatchRef; | ||
| 283 | int16_t iMvA[2], iMvB[2], iMvC[2], iMvD[2]; | ||
| 284 | |||
| 285 | iCurXy = pCurLayer->iMbXyIndex; | ||
| 286 | iCurX = pCurLayer->iMbX; | ||
| 287 | iCurY = pCurLayer->iMbY; | ||
| 288 | iCurSliceIdc = pCurLayer->pSliceIdc[iCurXy]; | ||
| 289 | |||
| 290 | if (iCurX != 0) { | ||
| 291 | iLeftXy = iCurXy - 1; | ||
| 292 | iLeftSliceIdc = pCurLayer->pSliceIdc[iLeftXy]; | ||
| 293 | bLeftAvail = (iLeftSliceIdc == iCurSliceIdc); | ||
| 294 | } else { | ||
| 295 | bLeftAvail = 0; | ||
| 296 | bLeftTopAvail = 0; | ||
| 297 | } | ||
| 298 | |||
| 299 | if (iCurY != 0) { | ||
| 300 | iTopXy = iCurXy - pCurLayer->iMbWidth; | ||
| 301 | iTopSliceIdc = pCurLayer->pSliceIdc[iTopXy]; | ||
| 302 | bTopAvail = (iTopSliceIdc == iCurSliceIdc); | ||
| 303 | if (iCurX != 0) { | ||
| 304 | iLeftTopXy = iTopXy - 1; | ||
| 305 | iLeftTopSliceIdc = pCurLayer->pSliceIdc[iLeftTopXy]; | ||
| 306 | bLeftTopAvail = (iLeftTopSliceIdc == iCurSliceIdc); | ||
| 307 | } else { | ||
| 308 | bLeftTopAvail = 0; | ||
| 309 | } | ||
| 310 | if (iCurX != (pCurLayer->iMbWidth - 1)) { | ||
| 311 | iRightTopXy = iTopXy + 1; | ||
| 312 | iRightTopSliceIdc = pCurLayer->pSliceIdc[iRightTopXy]; | ||
| 313 | bRightTopAvail = (iRightTopSliceIdc == iCurSliceIdc); | ||
| 314 | } else { | ||
| 315 | bRightTopAvail = 0; | ||
| 316 | } | ||
| 317 | } else { | ||
| 318 | bTopAvail = 0; | ||
| 319 | bLeftTopAvail = 0; | ||
| 320 | bRightTopAvail = 0; | ||
| 321 | } | ||
| 322 | |||
| 323 | iLeftType = ((iCurX != 0 && bLeftAvail) ? pCurLayer->pMbType[iLeftXy] : 0); | ||
| 324 | iTopType = ((iCurY != 0 && bTopAvail) ? pCurLayer->pMbType[iTopXy] : 0); | ||
| 325 | iLeftTopType = ((iCurX != 0 && iCurY != 0 && bLeftTopAvail) | ||
| 326 | ? pCurLayer->pMbType[iLeftTopXy] : 0); | ||
| 327 | iRightTopType = ((iCurX != pCurLayer->iMbWidth - 1 && iCurY != 0 && bRightTopAvail) | ||
| 328 | ? pCurLayer->pMbType[iRightTopXy] : 0); | ||
| 329 | |||
| 330 | /*get neb mv&iRefIdxArray*/ | ||
| 331 | /*left*/ | ||
| 332 | if (bLeftAvail && IS_INTER (iLeftType)) { | ||
| 333 | ST32 (iMvA, LD32 (pCurLayer->pMv[0][iLeftXy][3])); | ||
| 334 | iLeftRef = pCurLayer->pRefIndex[0][iLeftXy][3]; | ||
| 335 | } else { | ||
| 336 | ST32 (iMvA, 0); | ||
| 337 | if (0 == bLeftAvail) { //not available | ||
| 338 | iLeftRef = REF_NOT_AVAIL; | ||
| 339 | } else { //available but is intra mb type | ||
| 340 | iLeftRef = REF_NOT_IN_LIST; | ||
| 341 | } | ||
| 342 | } | ||
| 343 | if (REF_NOT_AVAIL == iLeftRef || | ||
| 344 | (0 == iLeftRef && 0 == * (int32_t*)iMvA)) { | ||
| 345 | ST32 (iMvp, 0); | ||
| 346 | return; | ||
| 347 | } | ||
| 348 | |||
| 349 | /*top*/ | ||
| 350 | if (bTopAvail && IS_INTER (iTopType)) { | ||
| 351 | ST32 (iMvB, LD32 (pCurLayer->pMv[0][iTopXy][12])); | ||
| 352 | iTopRef = pCurLayer->pRefIndex[0][iTopXy][12]; | ||
| 353 | } else { | ||
| 354 | ST32 (iMvB, 0); | ||
| 355 | if (0 == bTopAvail) { //not available | ||
| 356 | iTopRef = REF_NOT_AVAIL; | ||
| 357 | } else { //available but is intra mb type | ||
| 358 | iTopRef = REF_NOT_IN_LIST; | ||
| 359 | } | ||
| 360 | } | ||
| 361 | if (REF_NOT_AVAIL == iTopRef || | ||
| 362 | (0 == iTopRef && 0 == * (int32_t*)iMvB)) { | ||
| 363 | ST32 (iMvp, 0); | ||
| 364 | return; | ||
| 365 | } | ||
| 366 | |||
| 367 | /*right_top*/ | ||
| 368 | if (bRightTopAvail && IS_INTER (iRightTopType)) { | ||
| 369 | ST32 (iMvC, LD32 (pCurLayer->pMv[0][iRightTopXy][12])); | ||
| 370 | iRightTopRef = pCurLayer->pRefIndex[0][iRightTopXy][12]; | ||
| 371 | } else { | ||
| 372 | ST32 (iMvC, 0); | ||
| 373 | if (0 == bRightTopAvail) { //not available | ||
| 374 | iRightTopRef = REF_NOT_AVAIL; | ||
| 375 | } else { //available but is intra mb type | ||
| 376 | iRightTopRef = REF_NOT_IN_LIST; | ||
| 377 | } | ||
| 378 | } | ||
| 379 | |||
| 380 | /*left_top*/ | ||
| 381 | if (bLeftTopAvail && IS_INTER (iLeftTopType)) { | ||
| 382 | ST32 (iMvD, LD32 (pCurLayer->pMv[0][iLeftTopXy][15])); | ||
| 383 | iLeftTopRef = pCurLayer->pRefIndex[0][iLeftTopXy][15]; | ||
| 384 | } else { | ||
| 385 | ST32 (iMvD, 0); | ||
| 386 | if (0 == bLeftTopAvail) { //not available | ||
| 387 | iLeftTopRef = REF_NOT_AVAIL; | ||
| 388 | } else { //available but is intra mb type | ||
| 389 | iLeftTopRef = REF_NOT_IN_LIST; | ||
| 390 | } | ||
| 391 | } | ||
| 392 | |||
| 393 | iDiagonalRef = iRightTopRef; | ||
| 394 | if (REF_NOT_AVAIL == iDiagonalRef) { | ||
| 395 | iDiagonalRef = iLeftTopRef; | ||
| 396 | * (int32_t*)iMvC = * (int32_t*)iMvD; | ||
| 397 | } | ||
| 398 | |||
| 399 | if (REF_NOT_AVAIL == iTopRef && REF_NOT_AVAIL == iDiagonalRef && iLeftRef >= REF_NOT_IN_LIST) { | ||
| 400 | ST32 (iMvp, LD32 (iMvA)); | ||
| 401 | return; | ||
| 402 | } | ||
| 403 | |||
| 404 | iMatchRef = (0 == iLeftRef) + (0 == iTopRef) + (0 == iDiagonalRef); | ||
| 405 | if (1 == iMatchRef) { | ||
| 406 | if (0 == iLeftRef) { | ||
| 407 | ST32 (iMvp, LD32 (iMvA)); | ||
| 408 | } else if (0 == iTopRef) { | ||
| 409 | ST32 (iMvp, LD32 (iMvB)); | ||
| 410 | } else { | ||
| 411 | ST32 (iMvp, LD32 (iMvC)); | ||
| 412 | } | ||
| 413 | } else { | ||
| 414 | iMvp[0] = WelsMedian (iMvA[0], iMvB[0], iMvC[0]); | ||
| 415 | iMvp[1] = WelsMedian (iMvA[1], iMvB[1], iMvC[1]); | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 | |||
| 420 | |||
| 421 | int32_t AllocLayerData (PDqLayer pDqLayer) { | ||
| 422 | |||
| 423 | pDqLayer->pSliceIdc = (int32_t*) WelsMalloc (pDqLayer->iMbWidth * pDqLayer->iMbHeight * sizeof (int32_t), | ||
| 424 | "pDqLayer->pSliceIdc"); | ||
| 425 | if (pDqLayer->pSliceIdc == NULL) | ||
| 426 | return 1; | ||
| 427 | |||
| 428 | pDqLayer->pMbType = (int8_t*) WelsMalloc (pDqLayer->iMbWidth * pDqLayer->iMbHeight * sizeof (int8_t), | ||
| 429 | "pDqLayer->pMbType"); | ||
| 430 | if (pDqLayer->pMbType == NULL) | ||
| 431 | return 1; | ||
| 432 | |||
| 433 | pDqLayer->pMv[0] = (int16_t (*)[MB_BLOCK4x4_NUM][MV_A]) WelsMalloc (pDqLayer->iMbWidth * pDqLayer->iMbHeight * sizeof ( | ||
| 434 | int16_t) * MV_A * MB_BLOCK4x4_NUM, "pDqLayer->pMv"); | ||
| 435 | if (pDqLayer->pMv[0] == NULL) | ||
| 436 | return 1; | ||
| 437 | |||
| 438 | pDqLayer->pRefIndex[0] = (int8_t (*)[MB_BLOCK4x4_NUM]) WelsMalloc (pDqLayer->iMbWidth * pDqLayer->iMbHeight * sizeof ( | ||
| 439 | int8_t) * MB_BLOCK4x4_NUM, "pDqLayer->pRefIndex"); | ||
| 440 | if (pDqLayer->pRefIndex[0] == NULL) | ||
| 441 | return 1; | ||
| 442 | |||
| 443 | return 0; | ||
| 444 | } | ||
| 445 | |||
| 446 | int32_t FreeLayerData (PDqLayer pDqLayer) { | ||
| 447 | |||
| 448 | if (pDqLayer->pSliceIdc != NULL) { | ||
| 449 | WelsFree (pDqLayer->pSliceIdc, "pDqLayer->pSliceIdc"); | ||
| 450 | pDqLayer->pSliceIdc = NULL; | ||
| 451 | } | ||
| 452 | |||
| 453 | if (pDqLayer->pMbType != NULL) { | ||
| 454 | WelsFree (pDqLayer->pMbType, "pDqLayer->pMbType"); | ||
| 455 | pDqLayer->pMbType = NULL; | ||
| 456 | } | ||
| 457 | |||
| 458 | if (pDqLayer->pMv[0] != NULL) { | ||
| 459 | WelsFree (pDqLayer->pMv[0], "pDqlayer->pMv[0]"); | ||
| 460 | pDqLayer->pMv[0] = NULL; | ||
| 461 | } | ||
| 462 | |||
| 463 | if (pDqLayer->pRefIndex[0] != NULL) { | ||
| 464 | WelsFree (pDqLayer->pRefIndex[0], "pDqlayer->pRefIndex[0]"); | ||
| 465 | pDqLayer->pRefIndex[0] = NULL; | ||
| 466 | } | ||
| 467 | |||
| 468 | return 0; | ||
| 469 | } | ||
| 470 | |||
| 471 | void InitRandomLayerSliceIdc (PDqLayer pDqLayer) { | ||
| 472 | srand ((uint32_t)time (NULL)); | ||
| 473 | int32_t i = 0; | ||
| 474 | int32_t iTotalMbNum = pDqLayer->iMbWidth * pDqLayer->iMbHeight; | ||
| 475 | int32_t iMbFirstSliceEnd = rand() % (iTotalMbNum - 1); //assure 2 slices | ||
| 476 | for (i = 0; i <= iMbFirstSliceEnd; ++i) { | ||
| 477 | pDqLayer->pSliceIdc[i] = 0; //to keep simple value here | ||
| 478 | } | ||
| 479 | for (; i < iTotalMbNum; ++i) { | ||
| 480 | pDqLayer->pSliceIdc[i] = 1; //to keep simple value here | ||
| 481 | } | ||
| 482 | } | ||
| 483 | |||
| 484 | void InitRandomLayerMbType (PDqLayer pDqLayer) { | ||
| 485 | srand ((uint32_t)time (NULL)); | ||
| 486 | for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) { | ||
| 487 | pDqLayer->pMbType[i] = (rand() & 0x0f) + 1; //1 ~ 16 | ||
| 488 | } | ||
| 489 | } | ||
| 490 | |||
| 491 | void InitRandomLayerMvData (PDqLayer pDqLayer) { | ||
| 492 | srand ((uint32_t)time (NULL)); | ||
| 493 | for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) { | ||
| 494 | for (int32_t j = 0; j < MB_BLOCK4x4_NUM; ++j) { | ||
| 495 | for (int32_t k = 0; k < MV_A; ++k) { | ||
| 496 | pDqLayer->pMv[0][i][j][k] = (rand() - RAND_MAX / 2); | ||
| 497 | } | ||
| 498 | } | ||
| 499 | } | ||
| 500 | } | ||
| 501 | |||
| 502 | void InitRandomLayerRefIdxData (PDqLayer pDqLayer) { | ||
| 503 | srand ((uint32_t)time (NULL)); | ||
| 504 | for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) { | ||
| 505 | for (int32_t j = 0; j < MB_BLOCK4x4_NUM; ++j) { | ||
| 506 | pDqLayer->pRefIndex[0][i][j] = (rand() % 18 - 2); //-2 ~ 15 | ||
| 507 | } | ||
| 508 | } | ||
| 509 | } | ||
| 510 | |||
| 511 | void InitRandomLayerData (PDqLayer pDqLayer) { | ||
| 512 | InitRandomLayerSliceIdc (pDqLayer); | ||
| 513 | InitRandomLayerMbType (pDqLayer); | ||
| 514 | InitRandomLayerMvData (pDqLayer); | ||
| 515 | InitRandomLayerRefIdxData (pDqLayer); | ||
| 516 | } | ||
| 517 | |||
| 518 | #define TEST_SKIP_MV_PRED \ | ||
| 519 | PredPSkipMvFromNeighbor (&sDqLayer, iWelsMvp); \ | ||
| 520 | bOK = ((iWelsMvp[0] == iAncMvp[0]) && (iWelsMvp[1] == iAncMvp[1])); \ | ||
| 521 | EXPECT_EQ (bOK, true); | ||
| 522 | |||
| 523 | TEST (PredMvTest, PredSkipMvFromNeighbor) { | ||
| 524 | const int32_t kiRandTime = 100; | ||
| 525 | bool bOK = true; | ||
| 526 | SDqLayer sDqLayer; | ||
| 527 | int16_t iAncMvp[2], iWelsMvp[2]; | ||
| 528 | |||
| 529 | memset (&sDqLayer, 0, sizeof (SDqLayer)); | ||
| 530 | //Assume the input data as 352x288 size | ||
| 531 | //allocate the data | ||
| 532 | sDqLayer.iMbWidth = 11; | ||
| 533 | sDqLayer.iMbHeight = 9; | ||
| 534 | if (AllocLayerData (&sDqLayer)) { //memory allocate failed | ||
| 535 | FreeLayerData (&sDqLayer); | ||
| 536 | return; | ||
| 537 | } | ||
| 538 | InitRandomLayerData (&sDqLayer); //init MV data, as it would not affect the following logic test | ||
| 539 | |||
| 540 | #define CURR_MB_IDX (sDqLayer.iMbXyIndex) | ||
| 541 | #define LEFT_MB_IDX (sDqLayer.iMbXyIndex - 1) | ||
| 542 | #define LEFT_MB_BLK 3 | ||
| 543 | #define TOP_MB_IDX (sDqLayer.iMbXyIndex - sDqLayer.iMbWidth) | ||
| 544 | #define TOP_MB_BLK 12 | ||
| 545 | #define LEFT_TOP_MB_IDX (sDqLayer.iMbXyIndex - sDqLayer.iMbWidth - 1) | ||
| 546 | #define LEFT_TOP_MB_BLK 15 | ||
| 547 | #define RIGHT_TOP_MB_IDX (sDqLayer.iMbXyIndex - sDqLayer.iMbWidth + 1) | ||
| 548 | #define RIGHT_TOP_MB_BLK 12 | ||
| 549 | |||
| 550 | //CASE 1: test MB [0,0], expect mvp = (0,0) | ||
| 551 | sDqLayer.iMbX = 0; | ||
| 552 | sDqLayer.iMbY = 0; | ||
| 553 | sDqLayer.iMbXyIndex = sDqLayer.iMbY * sDqLayer.iMbWidth + sDqLayer.iMbX; | ||
| 554 | iAncMvp[0] = iAncMvp[1] = 0; //expect anchor result to 0 | ||
| 555 | TEST_SKIP_MV_PRED; | ||
| 556 | //CASE 2: test MB [ANY, 0], expect mvp = (0,0) | ||
| 557 | sDqLayer.iMbX = rand() % sDqLayer.iMbWidth; | ||
| 558 | sDqLayer.iMbY = 0; | ||
| 559 | sDqLayer.iMbXyIndex = sDqLayer.iMbY * sDqLayer.iMbWidth + sDqLayer.iMbX; | ||
| 560 | iAncMvp[0] = iAncMvp[1] = 0; //expect anchor result to 0 | ||
| 561 | TEST_SKIP_MV_PRED; | ||
| 562 | //CASE 3: test MB [0, ANY], expect mvp = (0,0) | ||
| 563 | sDqLayer.iMbX = 0; | ||
| 564 | sDqLayer.iMbY = rand() % sDqLayer.iMbHeight; | ||
| 565 | sDqLayer.iMbXyIndex = sDqLayer.iMbY * sDqLayer.iMbWidth + sDqLayer.iMbX; | ||
| 566 | iAncMvp[0] = iAncMvp[1] = 0; //expect anchor result to 0 | ||
| 567 | TEST_SKIP_MV_PRED; | ||
| 568 | //CASE 4.1: test MB [RIGHT_SIDE, ANY] | ||
| 569 | sDqLayer.iMbX = sDqLayer.iMbWidth - 1; | ||
| 570 | sDqLayer.iMbY = rand() % (sDqLayer.iMbHeight - 1) + 1; //not equal to 0 | ||
| 571 | sDqLayer.iMbXyIndex = sDqLayer.iMbY * sDqLayer.iMbWidth + sDqLayer.iMbX; | ||
| 572 | //CASE 4.1.1: same slice_idc, assume = 0 | ||
| 573 | memset (sDqLayer.pSliceIdc, 0, sDqLayer.iMbWidth * sDqLayer.iMbHeight * sizeof (int32_t)); | ||
| 574 | //CASE 4.1.1.1: ALL P modes | ||
| 575 | memset (sDqLayer.pMbType, MB_TYPE_16x16, sDqLayer.iMbWidth * sDqLayer.iMbHeight * sizeof (int8_t)); | ||
| 576 | //CASE 4.1.1.1.1: ref_idx = 0, left MV = 0, top MV != 0, expect mvp = (0,0) | ||
| 577 | memset (sDqLayer.pRefIndex[0], 0, sDqLayer.iMbWidth * sDqLayer.iMbHeight * MB_BLOCK4x4_NUM * sizeof (int8_t)); | ||
| 578 | InitRandomLayerMvData (&sDqLayer); //reset Mv data | ||
| 579 | sDqLayer.pMv[0][LEFT_MB_IDX][LEFT_MB_BLK][0] = sDqLayer.pMv[0][LEFT_MB_IDX][LEFT_MB_BLK][1] = 0; //left_mv = 0 | ||
| 580 | sDqLayer.pMv[0][ TOP_MB_IDX][ TOP_MB_BLK][0] = sDqLayer.pMv[0][ TOP_MB_IDX][ TOP_MB_BLK][1] = 1; //top_mv != 0 | ||
| 581 | iAncMvp[0] = iAncMvp[1] = 0; //expect anchor result to 0 | ||
| 582 | TEST_SKIP_MV_PRED; | ||
| 583 | //CASE 4.1.1.1.2: ref_idx = 0, left MV != 0, top MV = 0, expect mvp = (0,0) | ||
| 584 | memset (sDqLayer.pRefIndex[0], 0, sDqLayer.iMbWidth * sDqLayer.iMbHeight * MB_BLOCK4x4_NUM * sizeof (int8_t)); | ||
| 585 | InitRandomLayerMvData (&sDqLayer); //reset Mv data | ||
| 586 | sDqLayer.pMv[0][LEFT_MB_IDX][LEFT_MB_BLK][0] = sDqLayer.pMv[0][LEFT_MB_IDX][LEFT_MB_BLK][1] = 1; //left_mv != 0 | ||
| 587 | sDqLayer.pMv[0][ TOP_MB_IDX][ TOP_MB_BLK][0] = sDqLayer.pMv[0][ TOP_MB_IDX][ TOP_MB_BLK][1] = 0; //top_mv = 0 | ||
| 588 | iAncMvp[0] = iAncMvp[1] = 0; //expect anchor result to 0 | ||
| 589 | TEST_SKIP_MV_PRED; | ||
| 590 | //CASE 4.1.1.1.3: ref_idx top = 0, others = 1, expect mvp = top mv | ||
| 591 | InitRandomLayerMvData (&sDqLayer); //reset Mv data | ||
| 592 | sDqLayer.pRefIndex[0][ TOP_MB_IDX][ TOP_MB_BLK] = 0; //top ref_idx = 0 | ||
| 593 | sDqLayer.pRefIndex[0][LEFT_MB_IDX][LEFT_MB_BLK] = 1; //left ref_idx = 1 | ||
| 594 | sDqLayer.pRefIndex[0][LEFT_TOP_MB_IDX][LEFT_TOP_MB_BLK] = 1; //left_top ref_idx = 1 | ||
| 595 | iAncMvp[0] = sDqLayer.pMv[0][TOP_MB_IDX][TOP_MB_BLK][0]; | ||
| 596 | iAncMvp[1] = sDqLayer.pMv[0][TOP_MB_IDX][TOP_MB_BLK][1]; | ||
| 597 | TEST_SKIP_MV_PRED; | ||
| 598 | //CASE 4.1.1.1.4: ref_idx left = 0, others = 1, expect mvp = left mv | ||
| 599 | sDqLayer.pRefIndex[0][ TOP_MB_IDX][ TOP_MB_BLK] = 1; //top ref_idx = 1 | ||
| 600 | sDqLayer.pRefIndex[0][LEFT_MB_IDX][LEFT_MB_BLK] = 0; //left ref_idx = 0 | ||
| 601 | sDqLayer.pRefIndex[0][LEFT_TOP_MB_IDX][LEFT_TOP_MB_BLK] = 1; //left_top ref_idx = 1 | ||
| 602 | iAncMvp[0] = sDqLayer.pMv[0][LEFT_MB_IDX][LEFT_MB_BLK][0]; | ||
| 603 | iAncMvp[1] = sDqLayer.pMv[0][LEFT_MB_IDX][LEFT_MB_BLK][1]; | ||
| 604 | TEST_SKIP_MV_PRED; | ||
| 605 | //CASE 4.1.1.2: All I | ||
| 606 | memset (sDqLayer.pMbType, MB_TYPE_INTRA16x16, sDqLayer.iMbWidth * sDqLayer.iMbHeight * sizeof (int8_t)); | ||
| 607 | //CASE 4.1.1.2.1: left P, expect mvp = left mv | ||
| 608 | sDqLayer.pMbType[LEFT_MB_IDX] = MB_TYPE_16x16; //left P | ||
| 609 | iAncMvp[0] = sDqLayer.pMv[0][LEFT_MB_IDX][LEFT_MB_BLK][0]; | ||
| 610 | iAncMvp[1] = sDqLayer.pMv[0][LEFT_MB_IDX][LEFT_MB_BLK][1]; | ||
| 611 | TEST_SKIP_MV_PRED; | ||
| 612 | //CASE 4.1.1.3: only top P, top ref_idx = 0, expect mvp = top mv | ||
| 613 | memset (sDqLayer.pMbType, MB_TYPE_INTRA16x16, sDqLayer.iMbWidth * sDqLayer.iMbHeight * sizeof (int8_t)); // All I MB | ||
| 614 | memset (sDqLayer.pRefIndex[0], 1, sDqLayer.iMbWidth * sDqLayer.iMbHeight * MB_BLOCK4x4_NUM * sizeof ( | ||
| 615 | int8_t)); // All ref_idx = 1 | ||
| 616 | sDqLayer.pMbType[TOP_MB_IDX] = MB_TYPE_16x16; //top P | ||
| 617 | sDqLayer.pRefIndex[0][TOP_MB_IDX][TOP_MB_BLK] = 0; //top ref_idx = 0 | ||
| 618 | iAncMvp[0] = sDqLayer.pMv[0][TOP_MB_IDX][TOP_MB_BLK][0]; | ||
| 619 | iAncMvp[1] = sDqLayer.pMv[0][TOP_MB_IDX][TOP_MB_BLK][1]; | ||
| 620 | TEST_SKIP_MV_PRED; | ||
| 621 | //CASE 4.1.1.4: only left_top P, left_top ref_idx = 0, expect mvp = 0 | ||
| 622 | sDqLayer.iMbX = (rand() % (sDqLayer.iMbWidth - 2)) + 1; //1 ~ (mb_width - 2) | ||
| 623 | sDqLayer.iMbY = (rand() % (sDqLayer.iMbHeight - 2)) + 1; //1 ~ (mb_height - 2) | ||
| 624 | sDqLayer.iMbXyIndex = sDqLayer.iMbY * sDqLayer.iMbWidth + sDqLayer.iMbX; | ||
| 625 | memset (sDqLayer.pMbType, MB_TYPE_INTRA16x16, sDqLayer.iMbWidth * sDqLayer.iMbHeight * sizeof (int8_t)); // All I MB | ||
| 626 | memset (sDqLayer.pRefIndex[0], 1, sDqLayer.iMbWidth * sDqLayer.iMbHeight * MB_BLOCK4x4_NUM * sizeof ( | ||
| 627 | int8_t)); // All ref_idx = 1 | ||
| 628 | sDqLayer.pMbType[LEFT_TOP_MB_IDX] = MB_TYPE_16x16; //top P | ||
| 629 | sDqLayer.pRefIndex[0][LEFT_TOP_MB_IDX][LEFT_TOP_MB_BLK] = 0; //top ref_idx = 0 | ||
| 630 | iAncMvp[0] = iAncMvp[1] = 0; //expect anchor result to 0 | ||
| 631 | TEST_SKIP_MV_PRED; | ||
| 632 | //CASE 4.1.1.5: only right_top P, right_top ref_idx = 0, expect mvp = right_top mv | ||
| 633 | sDqLayer.iMbX = (rand() % (sDqLayer.iMbWidth - 2)) + 1; //1 ~ (mb_width - 2) | ||
| 634 | sDqLayer.iMbY = (rand() % (sDqLayer.iMbHeight - 2)) + 1; //1 ~ (mb_height - 2) | ||
| 635 | sDqLayer.iMbXyIndex = sDqLayer.iMbY * sDqLayer.iMbWidth + sDqLayer.iMbX; | ||
| 636 | memset (sDqLayer.pMbType, MB_TYPE_INTRA16x16, sDqLayer.iMbWidth * sDqLayer.iMbHeight * sizeof (int8_t)); // All I MB | ||
| 637 | memset (sDqLayer.pRefIndex[0], 1, sDqLayer.iMbWidth * sDqLayer.iMbHeight * MB_BLOCK4x4_NUM * sizeof ( | ||
| 638 | int8_t)); // All ref_idx = 1 | ||
| 639 | sDqLayer.pMbType[RIGHT_TOP_MB_IDX] = MB_TYPE_16x16; //top P | ||
| 640 | sDqLayer.pRefIndex[0][RIGHT_TOP_MB_IDX][RIGHT_TOP_MB_BLK] = 0; //top ref_idx = 0 | ||
| 641 | iAncMvp[0] = sDqLayer.pMv[0][RIGHT_TOP_MB_IDX][RIGHT_TOP_MB_BLK][0]; | ||
| 642 | iAncMvp[1] = sDqLayer.pMv[0][RIGHT_TOP_MB_IDX][RIGHT_TOP_MB_BLK][1]; | ||
| 643 | TEST_SKIP_MV_PRED; | ||
| 644 | //CASE 4.1.2: different neighbor slice idc for all P and ref_idx = 0, expect mvp = 0 | ||
| 645 | memset (sDqLayer.pMbType, MB_TYPE_16x16, sDqLayer.iMbWidth * sDqLayer.iMbHeight * sizeof (int8_t)); // All I MB | ||
| 646 | memset (sDqLayer.pRefIndex[0], 0, sDqLayer.iMbWidth * sDqLayer.iMbHeight * MB_BLOCK4x4_NUM * sizeof ( | ||
| 647 | int8_t)); // All ref_idx = 1 | ||
| 648 | sDqLayer.iMbX = (rand() % (sDqLayer.iMbWidth - 2)) + 1; //1 ~ (mb_width - 2) | ||
| 649 | sDqLayer.iMbY = (rand() % (sDqLayer.iMbHeight - 2)) + 1; //1 ~ (mb_height - 2) | ||
| 650 | sDqLayer.iMbXyIndex = sDqLayer.iMbY * sDqLayer.iMbWidth + sDqLayer.iMbX; | ||
| 651 | sDqLayer.pSliceIdc[CURR_MB_IDX] = 5; | ||
| 652 | sDqLayer.pSliceIdc[LEFT_MB_IDX] = 0; | ||
| 653 | sDqLayer.pSliceIdc[TOP_MB_IDX] = 1; | ||
| 654 | sDqLayer.pSliceIdc[LEFT_TOP_MB_IDX] = 2; | ||
| 655 | sDqLayer.pSliceIdc[RIGHT_TOP_MB_IDX] = 3; | ||
| 656 | iAncMvp[0] = iAncMvp[1] = 0; | ||
| 657 | TEST_SKIP_MV_PRED; | ||
| 658 | |||
| 659 | //add new specific tests here | ||
| 660 | |||
| 661 | //normal tests | ||
| 662 | int32_t i = 0; | ||
| 663 | while (i++ < kiRandTime) { | ||
| 664 | InitRandomLayerData (&sDqLayer); //init MV data, as it would not affect the following logic test | ||
| 665 | AnchorPredPSkipMvFromNeighbor (&sDqLayer, iAncMvp); | ||
| 666 | TEST_SKIP_MV_PRED; | ||
| 667 | } | ||
| 668 | |||
| 669 | FreeLayerData (&sDqLayer); | ||
| 670 | } | ||