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
4343 #include "svc_enc_golomb.h"
4444 #include "svc_base_layer_md.h"
4545 #include "svc_encode_mb.h"
46−#include "svc_set_mb_syn_cavlc.h"
46+#include "svc_set_mb_syn.h"
4747 #include "decode_mb_aux.h"
4848 #include "svc_mode_decision.h"
4949
@@ -270,6 +270,9 @@ void WelsSliceHeaderWrite (SBitStringAux* pBs, SDqLayer* pCurLayer, SSlice* pSli · 220 unmodified lines
270270 WriteRefPicMarking (pBs, pSliceHeader, pNalHead);
271271 }
272272
273+ if (pPps->bEntropyCodingModeFlag && pSliceHeader->eSliceType != I_SLICE) {
274+ BsWriteUE (pBs, pSlice->iCabacInitIdc);
275+ }
273276 BsWriteSE (pBs, pSliceHeader->iSliceQpDelta); /* pSlice qp delta */
274277
275278 if (pPps->bDeblockingFilterControlPresentFlag) {
@@ -338,6 +341,11 @@ void WelsSliceHeaderExtWrite (SBitStringAux* pBs, SDqLayer* pCurLayer, SSlice* p · 62 unmodified lines
338341 }
339342 // }
340343
344+
345+ if (pPps->bEntropyCodingModeFlag && pSliceHeader->eSliceType != I_SLICE) {
346+ BsWriteUE (pBs, pSlice->iCabacInitIdc);
347+ }
348+
341349 BsWriteSE (pBs, pSliceHeader->iSliceQpDelta); /* pSlice qp delta */
342350
343351 if (pPps->bDeblockingFilterControlPresentFlag) {
@@ -460,21 +468,7 @@ void OutputPMbWithoutConstructCsRsNoCopy (sWelsEncCtx* pCtx, SDqLayer* pDq, SSli · 116 unmodified lines
460468 pfIdctFour4x4 (pDecV, kiDecStrideChroma, pDecV, kiDecStrideChroma, pScaledTcoeff + 320);
461469 }
462470 }
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+
478472 void UpdateQpForOverflow (SMB* pCurMb, uint8_t kuiChromaQpIndexOffset) {
479473 pCurMb->uiLumaQp += DELTA_QP;
480474 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
501495 int32_t iEncReturn = ENC_RETURN_SUCCESS;
502496 SBitStringAux* pBs = pSlice->pSliceBsa;
503497 SDynamicSlicingStack sDss;
498+ if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) {
499+ WelsInitSliceCabac (pEncCtx, pSlice);
500+ }
504501 for (; ;) {
505− StashMBStatus (&sDss, pBs, pSlice);
502+ pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, 0);
506503 iCurMbIdx = iNextMbIdx;
507504 pCurMb = &pMbList[ iCurMbIdx ];
508505
@@ -514,9 +511,10 @@ TRY_REENCODING: · 5 unmodified lines
514511 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);
515512 UpdateNonZeroCountCache (pCurMb, pMbCache);
516513
517− iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
514+
515+ iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
518516 if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
519− StashPopMBStatus (&sDss, pBs, pSlice);
517+ pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
520518 UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
521519 goto TRY_REENCODING;
522520 }
@@ -562,12 +560,14 @@ int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + · 39 unmodified lines
562560 SWelsMD sMd;
563561 SDynamicSlicingStack sDss;
564562 sDss.iStartPos = BsGetBitsPos (pBs);
565−
563+ if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) {
564+ WelsInitSliceCabac (pEncCtx, pSlice);
565+ }
566566 for (; ;) {
567567 iCurMbIdx = iNextMbIdx;
568568 pCurMb = &pMbList[ iCurMbIdx ];
569569
570− StashMBStatus (&sDss, pBs, pSlice);
570+ pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, 0);
571571 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);
572572 // if already reaches the largest number of slices, set QPs to the upper bound
573573 if (pSlice->bDynamicSlicingSliceSizeCtrlFlag) {
@@ -581,9 +581,9 @@ TRY_REENCODING: · 7 unmodified lines
581581 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);
582582 UpdateNonZeroCountCache (pCurMb, pMbCache);
583583
584− iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
584+ iEncReturn = pEncCtx->pFuncList->pfWelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
585585 if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
586− StashPopMBStatus (&sDss, pBs, pSlice);
586+ pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
587587 UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
588588 goto TRY_REENCODING;
589589 }
@@ -593,7 +593,7 @@ TRY_REENCODING: · 3 unmodified lines
593593 sDss.iCurrentPos = BsGetBitsPos (pBs);
594594
595595 if (DynSlcJudgeSliceBoundaryStepBack (pEncCtx, pSlice, pSliceCtx, pCurMb, &sDss)) { //islice
596− StashPopMBStatus (&sDss, pBs, pSlice);
596+ pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
597597 pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx -
598598 1; // update pLastCodedMbIdxOfPartition, need to -1 due to stepping back
599599 ++ pCurLayer->pNumSliceCodedOfPartition[kiPartitionId];
@@ -749,7 +749,7 @@ int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx, const · 149 unmodified lines
749749 if (ENC_RETURN_SUCCESS != iEncReturn)
750750 return iEncReturn;
751751
752− BsRbspTrailingBits (pBs);
752+ WelsWriteSliceEndSyn (pCurSlice, pEncCtx->pSvcParam->iEntropyCodingModeFlag);
753753
754754 return ENC_RETURN_SUCCESS;
755755 }
@@ -942,7 +942,6 @@ int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, · 186 unmodified lines
942942 int32_t iNumMbCoded = 0;
943943 int32_t iNextMbIdx = kiSliceFirstMbXY;
944944 int32_t iCurMbIdx = -1;
945− int32_t iMbSkipRun = 0;
946945 const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight;
947946 const int32_t kiMvdInterTableStride = pEncCtx->iMvdCostTableStride;
948947 uint16_t* pMvdCostTable = &pEncCtx->pMvdCostTable[pEncCtx->iMvdCostTableSize];
@@ -950,8 +949,12 @@ int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, · 1 unmodified line
950949 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
951950 int32_t iEncReturn = ENC_RETURN_SUCCESS;
952951 SDynamicSlicingStack sDss;
952+ if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) {
953+ WelsInitSliceCabac (pEncCtx, pSlice);
954+ }
955+ pSlice->iMbSkipRun = 0;
953956 for (;;) {
954− StashMBStatus (&sDss, pBs, pSlice, iMbSkipRun);
957+ pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, pSlice->iMbSkipRun);
955958 //point to current pMb
956959 iCurMbIdx = iNextMbIdx;
957960 pCurMb = &pMbList[ iCurMbIdx ];
@@ -979,23 +982,16 @@ TRY_REENCODING: · 21 unmodified lines
979982 UpdateNonZeroCountCache (pCurMb, pMbCache);
980983
981984 //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)];
985985
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;
998991 }
992+ if (ENC_RETURN_SUCCESS != iEncReturn)
993+ return iEncReturn;
994+
999995
1000996 //step (7): reconstruct current MB
1001997 pCurMb->uiSliceIdc = kiSliceIdx;
@@ -1017,8 +1013,8 @@ TRY_REENCODING: · 15 unmodified lines
10171013 }
10181014 }
10191015
1020− if (iMbSkipRun) {
1021− BsWriteUE (pBs, iMbSkipRun);
1016+ if (pSlice->iMbSkipRun) {
1017+ BsWriteUE (pBs, pSlice->iMbSkipRun);
10221018 }
10231019
10241020 return iEncReturn;
@@ -1038,7 +1034,6 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 13 unmodified lines
10381034 const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight;
10391035 int32_t iNextMbIdx = kiSliceFirstMbXY;
10401036 int32_t iCurMbIdx = -1;
1041− int32_t iMbSkipRun = 0;
10421037 const int32_t kiMvdInterTableStride = pEncCtx->iMvdCostTableStride;
10431038 uint16_t* pMvdCostTable = &pEncCtx->pMvdCostTable[pEncCtx->iMvdCostTableSize];
10441039 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
@@ -1048,10 +1043,14 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 3 unmodified lines
10481043
10491044 SDynamicSlicingStack sDss;
10501045 sDss.iStartPos = BsGetBitsPos (pBs);
1046+ if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) {
1047+ WelsInitSliceCabac (pEncCtx, pSlice);
1048+ }
1049+ pSlice->iMbSkipRun = 0;
10511050 for (;;) {
10521051 //DYNAMIC_SLICING_ONE_THREAD - MultiD
10531052 //stack pBs pointer
1054− StashMBStatus (&sDss, pBs, pSlice, iMbSkipRun);
1053+ pEncCtx->pFuncList->pfStashMBStatus (&sDss, pBs, pSlice, pSlice->iMbSkipRun);
10551054
10561055 //point to current pMb
10571056 iCurMbIdx = iNextMbIdx;
@@ -1088,28 +1087,22 @@ TRY_REENCODING: · 30 unmodified lines
10881087
10891088 //step (6): begin to write bit stream; if the pSlice size is controlled, the writing may be skipped
10901089
1091− if (IS_SKIP (pCurMb->uiMbType)) {
1092− pCurMb->uiLumaQp = pSlice->uiLastMbQp;
1093− pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)];
10941090
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;
11071097 }
1098+ if (ENC_RETURN_SUCCESS != iEncReturn)
1099+ return iEncReturn;
1100+
11081101
11091102 //DYNAMIC_SLICING_ONE_THREAD - MultiD
11101103 sDss.iCurrentPos = BsGetBitsPos (pBs);
11111104 if (DynSlcJudgeSliceBoundaryStepBack (pEncCtx, pSlice, pSliceCtx, pCurMb, &sDss)) {
1112− StashPopMBStatus (&sDss, pBs, pSlice, &iMbSkipRun);
1105+ pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pBs, pSlice);
11131106 pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx -
11141107 1; // update pLastCodedMbIdxOfPartition, need to -1 due to stepping back
11151108 ++ pCurLayer->pNumSliceCodedOfPartition[kiPartitionId];
@@ -1139,8 +1132,8 @@ TRY_REENCODING: · 23 unmodified lines
11391132 }
11401133 }
11411134
1142− if (iMbSkipRun) {
1143− BsWriteUE (pBs, iMbSkipRun);
1135+ if (pSlice->iMbSkipRun) {
1136+ BsWriteUE (pBs, pSlice->iMbSkipRun);
11441137 }
11451138
11461139 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