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 | 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 | 57 | extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight); |
| 64 | 58 | |
| 65 | 59 | int32_t WelsTargetSliceConstruction (PWelsDecoderContext pCtx) { |
| @@ -1423,19 +1417,17 @@ int32_t WelsDecodeMbCabacBSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uin · 1357 unmodified lines | ||
| 1423 | 1417 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPicL0[0] && ppRefPicL0[0]->bIsComplete) |
| 1424 | 1418 | || ! (ppRefPicL1[0] && ppRefPicL1[0]->bIsComplete); |
| 1425 | 1419 | |
| 1426 | − | |
| 1420 | + SubMbType subMbType; | |
| 1427 | 1421 | if (pSliceHeader->iDirectSpatialMvPredFlag) { |
| 1428 | 1422 | |
| 1429 | 1423 | //predict direct spatial mv |
| 1430 | − SubMbType subMbType; | |
| 1431 | 1424 | int32_t ret = PredMvBDirectSpatial (pCtx, pMv, ref, subMbType); |
| 1432 | 1425 | if (ret != ERR_NONE) { |
| 1433 | 1426 | return ret; |
| 1434 | 1427 | } |
| 1435 | 1428 | } else { |
| 1436 | 1429 | //temporal direct mode |
| 1437 | − ComputeColocated (pCtx); | |
| 1438 | − int32_t ret = PredBDirectTemporal (pCtx, pMv, ref); | |
| 1430 | + int32_t ret = PredBDirectTemporal (pCtx, pMv, ref, subMbType); | |
| 1439 | 1431 | if (ret != ERR_NONE) { |
| 1440 | 1432 | return ret; |
| 1441 | 1433 | } |
| @@ -2386,18 +2378,17 @@ int32_t WelsDecodeMbCavlcBSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uin · 944 unmodified lines | ||
| 2386 | 2378 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPicL0[0] && ppRefPicL0[0]->bIsComplete) |
| 2387 | 2379 | || ! (ppRefPicL1[0] && ppRefPicL1[0]->bIsComplete); |
| 2388 | 2380 | //predict iMv |
| 2381 | + SubMbType subMbType; | |
| 2389 | 2382 | if (pSliceHeader->iDirectSpatialMvPredFlag) { |
| 2390 | 2383 | |
| 2391 | 2384 | //predict direct spatial mv |
| 2392 | − SubMbType subMbType; | |
| 2393 | 2385 | int32_t ret = PredMvBDirectSpatial (pCtx, iMv, ref, subMbType); |
| 2394 | 2386 | if (ret != ERR_NONE) { |
| 2395 | 2387 | return ret; |
| 2396 | 2388 | } |
| 2397 | 2389 | } else { |
| 2398 | 2390 | //temporal direct mode |
| 2399 | − ComputeColocated (pCtx); | |
| 2400 | − int32_t ret = PredBDirectTemporal (pCtx, iMv, ref); | |
| 2391 | + int32_t ret = PredBDirectTemporal (pCtx, iMv, ref, subMbType); | |
| 2401 | 2392 | if (ret != ERR_NONE) { |
| 2402 | 2393 | return ret; |
| 2403 | 2394 | } |
| @@ -2838,17 +2829,21 @@ bool ComputeColocated (PWelsDecoderContext pCtx) { · 434 unmodified lines | ||
| 2838 | 2829 | PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 2839 | 2830 | PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader; |
| 2840 | 2831 | if (!pSliceHeader->iDirectSpatialMvPredFlag) { |
| 2841 | − uint32_t uiShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0]; | |
| 2842 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 2843 | − for (uint32_t i = 0; i < uiShortRefCount; ++i) { | |
| 2844 | − int32_t iTRb = WELS_CLIP3 (-128, 127, pSliceHeader->iPicOrderCntLsb - pCtx->sRefPic.pRefList[listIdx][i]->iFramePoc); | |
| 2845 | − int32_t iTRp = WELS_CLIP3 (-128, 127, | |
| 2846 | − pCtx->sRefPic.pRefList[LIST_1][i]->iFramePoc - pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc); | |
| 2847 | − if (iTRp != 0) { | |
| 2848 | − int32_t prescale = (16384 + iAbs (iTRp / 2)) / iTRp; | |
| 2849 | − pCurSlice->iMvScale[listIdx][i] = WELS_CLIP3 (-1024, 1023, (iTRb * prescale + 32) >> 6); | |
| 2850 | − } else { | |
| 2851 | − pCurSlice->iMvScale[listIdx][i] = 0x03FFF; | |
| 2832 | + uint32_t uiRefCount = pSliceHeader->uiRefCount[LIST_0]; | |
| 2833 | + if (pCtx->sRefPic.pRefList[LIST_1][0] != NULL) { | |
| 2834 | + for (uint32_t i = 0; i < uiRefCount; ++i) { | |
| 2835 | + if (pCtx->sRefPic.pRefList[LIST_0][i] != NULL) { | |
| 2836 | + const int32_t poc0 = pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc; | |
| 2837 | + const int32_t poc1 = pCtx->sRefPic.pRefList[LIST_1][0]->iFramePoc; | |
| 2838 | + const int32_t poc = pSliceHeader->iPicOrderCntLsb; | |
| 2839 | + const int32_t td = WELS_CLIP3 (poc1 - poc0, -128, 127); | |
| 2840 | + if (td == 0) { | |
| 2841 | + pCurSlice->iMvScale[LIST_0][i] = 1 << 8; | |
| 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 | } |