Showing the changes to codec/decoder/core/src/decode_slice.cpp (1 of 10 files). Show all
Unified · Split
| @@ -54,12 +54,6 @@ namespace WelsDec { · 53 unmodified lines | |||
| 54 | 54 | ||
| 55 | extern void FreePicture (PPicture pPic, CMemoryAlign* pMa); | 55 | extern void FreePicture (PPicture pPic, CMemoryAlign* pMa); |
| 56 | 56 | ||
| 57 | static inline int32_t iAbs (int32_t x) { | ||
| 58 | static const int32_t INT_BITS = (sizeof (int) * CHAR_BIT) - 1; | ||
| 59 | int32_t y = x >> INT_BITS; | ||
| 60 | return (x ^ y) - y; | ||
| 61 | } | ||
| 62 | |||
| 63 | extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight); | 57 | extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight); |
| 64 | 58 | ||
| 65 | int32_t WelsTargetSliceConstruction (PWelsDecoderContext pCtx) { | 59 | int32_t WelsTargetSliceConstruction (PWelsDecoderContext pCtx) { |
| @@ -1423,19 +1417,17 @@ int32_t WelsDecodeMbCabacBSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uin · 1357 unmodified lines | |||
| 1423 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPicL0[0] && ppRefPicL0[0]->bIsComplete) | 1417 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPicL0[0] && ppRefPicL0[0]->bIsComplete) |
| 1424 | || ! (ppRefPicL1[0] && ppRefPicL1[0]->bIsComplete); | 1418 | || ! (ppRefPicL1[0] && ppRefPicL1[0]->bIsComplete); |
| 1425 | 1419 | ||
| 1426 | 1420 | SubMbType subMbType; | |
| 1427 | if (pSliceHeader->iDirectSpatialMvPredFlag) { | 1421 | if (pSliceHeader->iDirectSpatialMvPredFlag) { |
| 1428 | 1422 | ||
| 1429 | //predict direct spatial mv | 1423 | //predict direct spatial mv |
| 1430 | SubMbType subMbType; | ||
| 1431 | int32_t ret = PredMvBDirectSpatial (pCtx, pMv, ref, subMbType); | 1424 | int32_t ret = PredMvBDirectSpatial (pCtx, pMv, ref, subMbType); |
| 1432 | if (ret != ERR_NONE) { | 1425 | if (ret != ERR_NONE) { |
| 1433 | return ret; | 1426 | return ret; |
| 1434 | } | 1427 | } |
| 1435 | } else { | 1428 | } else { |
| 1436 | //temporal direct mode | 1429 | //temporal direct mode |
| 1437 | ComputeColocated (pCtx); | 1430 | int32_t ret = PredBDirectTemporal (pCtx, pMv, ref, subMbType); |
| 1438 | int32_t ret = PredBDirectTemporal (pCtx, pMv, ref); | ||
| 1439 | if (ret != ERR_NONE) { | 1431 | if (ret != ERR_NONE) { |
| 1440 | return ret; | 1432 | return ret; |
| 1441 | } | 1433 | } |
| @@ -2386,18 +2378,17 @@ int32_t WelsDecodeMbCavlcBSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uin · 944 unmodified lines | |||
| 2386 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPicL0[0] && ppRefPicL0[0]->bIsComplete) | 2378 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPicL0[0] && ppRefPicL0[0]->bIsComplete) |
| 2387 | || ! (ppRefPicL1[0] && ppRefPicL1[0]->bIsComplete); | 2379 | || ! (ppRefPicL1[0] && ppRefPicL1[0]->bIsComplete); |
| 2388 | //predict iMv | 2380 | //predict iMv |
| 2381 | SubMbType subMbType; | ||
| 2389 | if (pSliceHeader->iDirectSpatialMvPredFlag) { | 2382 | if (pSliceHeader->iDirectSpatialMvPredFlag) { |
| 2390 | 2383 | ||
| 2391 | //predict direct spatial mv | 2384 | //predict direct spatial mv |
| 2392 | SubMbType subMbType; | ||
| 2393 | int32_t ret = PredMvBDirectSpatial (pCtx, iMv, ref, subMbType); | 2385 | int32_t ret = PredMvBDirectSpatial (pCtx, iMv, ref, subMbType); |
| 2394 | if (ret != ERR_NONE) { | 2386 | if (ret != ERR_NONE) { |
| 2395 | return ret; | 2387 | return ret; |
| 2396 | } | 2388 | } |
| 2397 | } else { | 2389 | } else { |
| 2398 | //temporal direct mode | 2390 | //temporal direct mode |
| 2399 | ComputeColocated (pCtx); | 2391 | int32_t ret = PredBDirectTemporal (pCtx, iMv, ref, subMbType); |
| 2400 | int32_t ret = PredBDirectTemporal (pCtx, iMv, ref); | ||
| 2401 | if (ret != ERR_NONE) { | 2392 | if (ret != ERR_NONE) { |
| 2402 | return ret; | 2393 | return ret; |
| 2403 | } | 2394 | } |
| @@ -2838,17 +2829,21 @@ bool ComputeColocated (PWelsDecoderContext pCtx) { · 434 unmodified lines | |||
| 2838 | PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 2829 | PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 2839 | PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader; | 2830 | PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader; |
| 2840 | if (!pSliceHeader->iDirectSpatialMvPredFlag) { | 2831 | if (!pSliceHeader->iDirectSpatialMvPredFlag) { |
| 2841 | uint32_t uiShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0]; | 2832 | uint32_t uiRefCount = pSliceHeader->uiRefCount[LIST_0]; |
| 2842 | for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | 2833 | if (pCtx->sRefPic.pRefList[LIST_1][0] != NULL) { |
| 2843 | for (uint32_t i = 0; i < uiShortRefCount; ++i) { | 2834 | for (uint32_t i = 0; i < uiRefCount; ++i) { |
| 2844 | int32_t iTRb = WELS_CLIP3 (-128, 127, pSliceHeader->iPicOrderCntLsb - pCtx->sRefPic.pRefList[listIdx][i]->iFramePoc); | 2835 | if (pCtx->sRefPic.pRefList[LIST_0][i] != NULL) { |
| 2845 | int32_t iTRp = WELS_CLIP3 (-128, 127, | 2836 | const int32_t poc0 = pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc; |
| 2846 | pCtx->sRefPic.pRefList[LIST_1][i]->iFramePoc - pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc); | 2837 | const int32_t poc1 = pCtx->sRefPic.pRefList[LIST_1][0]->iFramePoc; |
| 2847 | if (iTRp != 0) { | 2838 | const int32_t poc = pSliceHeader->iPicOrderCntLsb; |
| 2848 | int32_t prescale = (16384 + iAbs (iTRp / 2)) / iTRp; | 2839 | const int32_t td = WELS_CLIP3 (poc1 - poc0, -128, 127); |
| 2849 | pCurSlice->iMvScale[listIdx][i] = WELS_CLIP3 (-1024, 1023, (iTRb * prescale + 32) >> 6); | 2840 | if (td == 0) { |
| 2850 | } else { | 2841 | pCurSlice->iMvScale[LIST_0][i] = 1 << 8; |
| 2851 | pCurSlice->iMvScale[listIdx][i] = 0x03FFF; | 2842 | } else { |
| 2843 | int32_t tb = WELS_CLIP3 (poc - poc0, -128, 127); | ||
| 2844 | int32_t tx = (16384 + (abs (td) >> 1)) / td; | ||
| 2845 | pCurSlice->iMvScale[LIST_0][i] = WELS_CLIP3 ((tb * tx + 32) >> 6, -1024, 1023); | ||
| 2846 | } | ||
| 2852 | } | 2847 | } |
| 2853 | } | 2848 | } |
| 2854 | } | 2849 | } |