Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 38 files). Show all
Unified · Split
| @@ -43,7 +43,7 @@ · 42 unmodified lines | ||
| 43 | 43 | #include "svc_enc_golomb.h" |
| 44 | 44 | #include "svc_base_layer_md.h" |
| 45 | 45 | #include "svc_encode_mb.h" |
| 46 | −#include "svc_set_mb_syn_cavlc.h" | |
| 46 | +#include "svc_set_mb_syn.h" | |
| 47 | 47 | #include "decode_mb_aux.h" |
| 48 | 48 | #include "svc_mode_decision.h" |
| 49 | 49 | |
| @@ -270,6 +270,9 @@ void WelsSliceHeaderWrite (SBitStringAux* pBs, SDqLayer* pCurLayer, SSlice* pSli · 220 unmodified lines | ||
| 270 | 270 | WriteRefPicMarking (pBs, pSliceHeader, pNalHead); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | + if (pPps->bEntropyCodingModeFlag && pSliceHeader->eSliceType != I_SLICE) { | |
| 274 | + BsWriteUE (pBs, pSlice->iCabacInitIdc); | |
| 275 | + } | |
| 273 | 276 | BsWriteSE (pBs, pSliceHeader->iSliceQpDelta); /* pSlice qp delta */ |
| 274 | 277 | |
| 275 | 278 | if (pPps->bDeblockingFilterControlPresentFlag) { |
| @@ -338,6 +341,11 @@ void WelsSliceHeaderExtWrite (SBitStringAux* pBs, SDqLayer* pCurLayer, SSlice* p · 62 unmodified lines | ||
| 338 | 341 | } |
| 339 | 342 | // } |
| 340 | 343 | |
| 344 | + | |
| 345 | + if (pPps->bEntropyCodingModeFlag && pSliceHeader->eSliceType != I_SLICE) { | |
| 346 | + BsWriteUE (pBs, pSlice->iCabacInitIdc); | |
| 347 | + } | |
| 348 | + | |
| 341 | 349 | BsWriteSE (pBs, pSliceHeader->iSliceQpDelta); /* pSlice qp delta */ |
| 342 | 350 | |
| 343 | 351 | if (pPps->bDeblockingFilterControlPresentFlag) { |
| @@ -460,21 +468,7 @@ void OutputPMbWithoutConstructCsRsNoCopy (sWelsEncCtx* pCtx, SDqLayer* pDq, SSli · 116 unmodified lines | ||
| 460 | 468 | pfIdctFour4x4 (pDecV, kiDecStrideChroma, pDecV, kiDecStrideChroma, pScaledTcoeff + 320); |
| 461 | 469 | } |
| 462 | 470 | } |
| 463 | −inline void StashMBStatus (SDynamicSlicingStack* pDss, SBitStringAux* pBs, SSlice* pSlice, int32_t iMbSkipRun = 0) { | |
| 464 | − pDss->pBsStackBufPtr = pBs->pBufPtr; | |
| 465 | − pDss->uiBsStackCurBits = pBs->uiCurBits; | |
| 466 | − pDss->iBsStackLeftBits = pBs->iLeftBits; | |
| 467 | − pDss->uiLastMbQp = pSlice->uiLastMbQp; | |
| 468 | − pDss->iMbSkipRunStack = iMbSkipRun; | |
| 469 | −} | |
| 470 | −void StashPopMBStatus (SDynamicSlicingStack* pDss, SBitStringAux* pBs, SSlice* pSlice, int32_t* pMbSkipRun = 0) { | |
| 471 | − pBs->pBufPtr = pDss->pBsStackBufPtr; | |
| 472 | − pBs->uiCurBits = pDss->uiBsStackCurBits; | |
| 473 | − pBs->iLeftBits = pDss->iBsStackLeftBits; | |
| 474 | − pSlice->uiLastMbQp = pDss->uiLastMbQp; | |
| 475 | − if (pMbSkipRun) | |
| 476 | − *pMbSkipRun = pDss->iMbSkipRunStack; | |
| 477 | −} | |
| 471 | + | |
| 478 | 472 | void UpdateQpForOverflow (SMB* pCurMb, uint8_t kuiChromaQpIndexOffset) { |
| 479 | 473 | pCurMb->uiLumaQp += DELTA_QP; |
| 480 | 474 | pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)]; |
| @@ -501,8 +495,11 @@ int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encodin · 20 unmodified lines | ||
| 501 | 495 | int32_t iEncReturn = ENC_RETURN_SUCCESS; |
| 502 | 496 | SBitStringAux* pBs = pSlice->pSliceBsa; |
| 503 | 497 | SDynamicSlicingStack sDss; |
| 498 | + if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) { | |
| 499 | + WelsInitSliceCabac (pEncCtx, pSlice); | |
| 500 | + } | |
| 504 | 501 | for (; ;) { |
| 505 | − StashMBStatus (&sDss, pBs, pSlice); | |
| 502 | + pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, 0); | |
| 506 | 503 | iCurMbIdx = iNextMbIdx; |
| 507 | 504 | pCurMb = &pMbList[ iCurMbIdx ]; |
| 508 | 505 | |
| @@ -514,9 +511,10 @@ TRY_REENCODING: · 5 unmodified lines | ||
| 514 | 511 | WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache); |
| 515 | 512 | UpdateNonZeroCountCache (pCurMb, pMbCache); |
| 516 | 513 | |
| 517 | − iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb); | |
| 514 | + | |
| 515 | + iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb); | |
| 518 | 516 | if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) { |
| 519 | − StashPopMBStatus (&sDss, pBs, pSlice); | |
| 517 | + pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice); | |
| 520 | 518 | UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset); |
| 521 | 519 | goto TRY_REENCODING; |
| 522 | 520 | } |
| @@ -562,12 +560,14 @@ int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + · 39 unmodified lines | ||
| 562 | 560 | SWelsMD sMd; |
| 563 | 561 | SDynamicSlicingStack sDss; |
| 564 | 562 | sDss.iStartPos = BsGetBitsPos (pBs); |
| 565 | − | |
| 563 | + if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) { | |
| 564 | + WelsInitSliceCabac (pEncCtx, pSlice); | |
| 565 | + } | |
| 566 | 566 | for (; ;) { |
| 567 | 567 | iCurMbIdx = iNextMbIdx; |
| 568 | 568 | pCurMb = &pMbList[ iCurMbIdx ]; |
| 569 | 569 | |
| 570 | − StashMBStatus (&sDss, pBs, pSlice); | |
| 570 | + pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, 0); | |
| 571 | 571 | pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice); |
| 572 | 572 | // if already reaches the largest number of slices, set QPs to the upper bound |
| 573 | 573 | if (pSlice->bDynamicSlicingSliceSizeCtrlFlag) { |
| @@ -581,9 +581,9 @@ TRY_REENCODING: · 7 unmodified lines | ||
| 581 | 581 | WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache); |
| 582 | 582 | UpdateNonZeroCountCache (pCurMb, pMbCache); |
| 583 | 583 | |
| 584 | − iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb); | |
| 584 | + iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb); | |
| 585 | 585 | if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) { |
| 586 | − StashPopMBStatus (&sDss, pBs, pSlice); | |
| 586 | + pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice); | |
| 587 | 587 | UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset); |
| 588 | 588 | goto TRY_REENCODING; |
| 589 | 589 | } |
| @@ -593,7 +593,7 @@ TRY_REENCODING: · 3 unmodified lines | ||
| 593 | 593 | sDss.iCurrentPos = BsGetBitsPos (pBs); |
| 594 | 594 | |
| 595 | 595 | if (DynSlcJudgeSliceBoundaryStepBack (pEncCtx, pSlice, pSliceCtx, pCurMb, &sDss)) { //islice |
| 596 | − StashPopMBStatus (&sDss, pBs, pSlice); | |
| 596 | + pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice); | |
| 597 | 597 | pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx - |
| 598 | 598 | 1; // update pLastCodedMbIdxOfPartition, need to -1 due to stepping back |
| 599 | 599 | ++ pCurLayer->pNumSliceCodedOfPartition[kiPartitionId]; |
| @@ -749,7 +749,7 @@ int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx, const · 149 unmodified lines | ||
| 749 | 749 | if (ENC_RETURN_SUCCESS != iEncReturn) |
| 750 | 750 | return iEncReturn; |
| 751 | 751 | |
| 752 | − BsRbspTrailingBits (pBs); | |
| 752 | + WelsWriteSliceEndSyn (pCurSlice, pEncCtx->pSvcParam->iEntropyCodingModeFlag); | |
| 753 | 753 | |
| 754 | 754 | return ENC_RETURN_SUCCESS; |
| 755 | 755 | } |
| @@ -942,7 +942,6 @@ int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, · 186 unmodified lines | ||
| 942 | 942 | int32_t iNumMbCoded = 0; |
| 943 | 943 | int32_t iNextMbIdx = kiSliceFirstMbXY; |
| 944 | 944 | int32_t iCurMbIdx = -1; |
| 945 | − int32_t iMbSkipRun = 0; | |
| 946 | 945 | const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight; |
| 947 | 946 | const int32_t kiMvdInterTableStride = pEncCtx->iMvdCostTableStride; |
| 948 | 947 | uint16_t* pMvdCostTable = &pEncCtx->pMvdCostTable[pEncCtx->iMvdCostTableSize]; |
| @@ -950,8 +949,12 @@ int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, · 1 unmodified line | ||
| 950 | 949 | const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset; |
| 951 | 950 | int32_t iEncReturn = ENC_RETURN_SUCCESS; |
| 952 | 951 | SDynamicSlicingStack sDss; |
| 952 | + if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) { | |
| 953 | + WelsInitSliceCabac (pEncCtx, pSlice); | |
| 954 | + } | |
| 955 | + pSlice->iMbSkipRun = 0; | |
| 953 | 956 | for (;;) { |
| 954 | − StashMBStatus (&sDss, pBs, pSlice, iMbSkipRun); | |
| 957 | + pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, pSlice->iMbSkipRun); | |
| 955 | 958 | //point to current pMb |
| 956 | 959 | iCurMbIdx = iNextMbIdx; |
| 957 | 960 | pCurMb = &pMbList[ iCurMbIdx ]; |
| @@ -979,23 +982,16 @@ TRY_REENCODING: · 21 unmodified lines | ||
| 979 | 982 | UpdateNonZeroCountCache (pCurMb, pMbCache); |
| 980 | 983 | |
| 981 | 984 | //step (6): begin to write bit stream; if the pSlice size is controlled, the writing may be skipped |
| 982 | − if (IS_SKIP (pCurMb->uiMbType)) { | |
| 983 | − pCurMb->uiLumaQp = pSlice->uiLastMbQp; | |
| 984 | − pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)]; | |
| 985 | 985 | |
| 986 | − iMbSkipRun++; | |
| 987 | − } else { | |
| 988 | − BsWriteUE (pBs, iMbSkipRun); | |
| 989 | − iMbSkipRun = 0; | |
| 990 | − iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb); | |
| 991 | − if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) { | |
| 992 | − StashPopMBStatus (&sDss, pBs, pSlice, &iMbSkipRun); | |
| 993 | − UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset); | |
| 994 | − goto TRY_REENCODING; | |
| 995 | − } | |
| 996 | − if (ENC_RETURN_SUCCESS != iEncReturn) | |
| 997 | − return iEncReturn; | |
| 986 | + iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb); | |
| 987 | + if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) { | |
| 988 | + pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice); | |
| 989 | + UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset); | |
| 990 | + goto TRY_REENCODING; | |
| 998 | 991 | } |
| 992 | + if (ENC_RETURN_SUCCESS != iEncReturn) | |
| 993 | + return iEncReturn; | |
| 994 | + | |
| 999 | 995 | |
| 1000 | 996 | //step (7): reconstruct current MB |
| 1001 | 997 | pCurMb->uiSliceIdc = kiSliceIdx; |
| @@ -1017,8 +1013,8 @@ TRY_REENCODING: · 15 unmodified lines | ||
| 1017 | 1013 | } |
| 1018 | 1014 | } |
| 1019 | 1015 | |
| 1020 | − if (iMbSkipRun) { | |
| 1021 | − BsWriteUE (pBs, iMbSkipRun); | |
| 1016 | + if (pSlice->iMbSkipRun) { | |
| 1017 | + BsWriteUE (pBs, pSlice->iMbSkipRun); | |
| 1022 | 1018 | } |
| 1023 | 1019 | |
| 1024 | 1020 | return iEncReturn; |
| @@ -1038,7 +1034,6 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 13 unmodified lines | ||
| 1038 | 1034 | const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight; |
| 1039 | 1035 | int32_t iNextMbIdx = kiSliceFirstMbXY; |
| 1040 | 1036 | int32_t iCurMbIdx = -1; |
| 1041 | − int32_t iMbSkipRun = 0; | |
| 1042 | 1037 | const int32_t kiMvdInterTableStride = pEncCtx->iMvdCostTableStride; |
| 1043 | 1038 | uint16_t* pMvdCostTable = &pEncCtx->pMvdCostTable[pEncCtx->iMvdCostTableSize]; |
| 1044 | 1039 | const int32_t kiSliceIdx = pSlice->uiSliceIdx; |
| @@ -1048,10 +1043,14 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 3 unmodified lines | ||
| 1048 | 1043 | |
| 1049 | 1044 | SDynamicSlicingStack sDss; |
| 1050 | 1045 | sDss.iStartPos = BsGetBitsPos (pBs); |
| 1046 | + if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) { | |
| 1047 | + WelsInitSliceCabac (pEncCtx, pSlice); | |
| 1048 | + } | |
| 1049 | + pSlice->iMbSkipRun = 0; | |
| 1051 | 1050 | for (;;) { |
| 1052 | 1051 | //DYNAMIC_SLICING_ONE_THREAD - MultiD |
| 1053 | 1052 | //stack pBs pointer |
| 1054 | − StashMBStatus (&sDss, pBs, pSlice, iMbSkipRun); | |
| 1053 | + pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, pSlice->iMbSkipRun); | |
| 1055 | 1054 | |
| 1056 | 1055 | //point to current pMb |
| 1057 | 1056 | iCurMbIdx = iNextMbIdx; |
| @@ -1088,28 +1087,22 @@ TRY_REENCODING: · 30 unmodified lines | ||
| 1088 | 1087 | |
| 1089 | 1088 | //step (6): begin to write bit stream; if the pSlice size is controlled, the writing may be skipped |
| 1090 | 1089 | |
| 1091 | − if (IS_SKIP (pCurMb->uiMbType)) { | |
| 1092 | − pCurMb->uiLumaQp = pSlice->uiLastMbQp; | |
| 1093 | − pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)]; | |
| 1094 | 1090 | |
| 1095 | − iMbSkipRun++; | |
| 1096 | − } else { | |
| 1097 | − BsWriteUE (pBs, iMbSkipRun); | |
| 1098 | − iMbSkipRun = 0; | |
| 1099 | − iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb); | |
| 1100 | − if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) { | |
| 1101 | − StashPopMBStatus (&sDss, pBs, pSlice, &iMbSkipRun); | |
| 1102 | − UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset); | |
| 1103 | − goto TRY_REENCODING; | |
| 1104 | − } | |
| 1105 | − if (ENC_RETURN_SUCCESS != iEncReturn) | |
| 1106 | − return iEncReturn; | |
| 1091 | + | |
| 1092 | + iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb); | |
| 1093 | + if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) { | |
| 1094 | + pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice); | |
| 1095 | + UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset); | |
| 1096 | + goto TRY_REENCODING; | |
| 1107 | 1097 | } |
| 1098 | + if (ENC_RETURN_SUCCESS != iEncReturn) | |
| 1099 | + return iEncReturn; | |
| 1100 | + | |
| 1108 | 1101 | |
| 1109 | 1102 | //DYNAMIC_SLICING_ONE_THREAD - MultiD |
| 1110 | 1103 | sDss.iCurrentPos = BsGetBitsPos (pBs); |
| 1111 | 1104 | if (DynSlcJudgeSliceBoundaryStepBack (pEncCtx, pSlice, pSliceCtx, pCurMb, &sDss)) { |
| 1112 | − StashPopMBStatus (&sDss, pBs, pSlice, &iMbSkipRun); | |
| 1105 | + pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice); | |
| 1113 | 1106 | pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx - |
| 1114 | 1107 | 1; // update pLastCodedMbIdxOfPartition, need to -1 due to stepping back |
| 1115 | 1108 | ++ pCurLayer->pNumSliceCodedOfPartition[kiPartitionId]; |
| @@ -1139,8 +1132,8 @@ TRY_REENCODING: · 23 unmodified lines | ||
| 1139 | 1132 | } |
| 1140 | 1133 | } |
| 1141 | 1134 | |
| 1142 | − if (iMbSkipRun) { | |
| 1143 | − BsWriteUE (pBs, iMbSkipRun); | |
| 1135 | + if (pSlice->iMbSkipRun) { | |
| 1136 | + BsWriteUE (pBs, pSlice->iMbSkipRun); | |
| 1144 | 1137 | } |
| 1145 | 1138 | |
| 1146 | 1139 | return iEncReturn; |