History

add encoder cabac support

ruil2 committed 12 years ago

Commit abc01e61 parent 2dbb75738 files · +2072 −273Browse files

Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 38 files). Show all

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t