History

fix vlc overflow

ruil2 committed 12 years ago

Commit db11ba71 parent ce0d37114 files · +136 −47Browse files

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

Unified · Split

codec/encoder/core/src/svc_encode_slice.cpp+61−21
@@ -460,7 +460,25 @@ void OutputPMbWithoutConstructCsRsNoCopy (sWelsEncCtx* pCtx, SDqLayer* pDq, SSli · 459 unmodified lines
460460 pfIdctFour4x4 (pDecV, kiDecStrideChroma, pDecV, kiDecStrideChroma, pScaledTcoeff + 320);
461461 }
462462 }
463−
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+}
478+void UpdateQpForOverflow (SMB* pCurMb, uint8_t kuiChromaQpIndexOffset) {
479+ pCurMb->uiLumaQp += DELTA_QP;
480+ pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)];
481+}
464482 // for intra non-dynamic pSlice
465483 //encapsulate two kinds of reconstruction:
466484 //first. store base or highest Dependency Layer with only one quality (without CS RS reconstruction)
@@ -477,22 +495,31 @@ int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encodin · 10 unmodified lines
477495 const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight;
478496 int32_t iCurMbIdx = 0, iNumMbCoded = 0;
479497 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
498+ const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
480499
481500 SWelsMD sMd;
482501 int32_t iEncReturn = ENC_RETURN_SUCCESS;
483−
502+ SBitStringAux* pBs = pSlice->pSliceBsa;
503+ SDynamicSlicingStack sDss;
484504 for (; ;) {
505+ StashMBStatus (&sDss, pBs, pSlice);
485506 iCurMbIdx = iNextMbIdx;
486507 pCurMb = &pMbList[ iCurMbIdx ];
508+
487509 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);
510+ WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
488511
512+TRY_REENCODING:
489513 sMd.iLambda = g_kiQpCostTable[pCurMb->uiLumaQp];
490−
491− WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
492514 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);
493515 UpdateNonZeroCountCache (pCurMb, pMbCache);
494516
495517 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
518+ if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
519+ StashPopMBStatus (&sDss, pBs, pSlice);
520+ UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
521+ goto TRY_REENCODING;
522+ }
496523 if (ENC_RETURN_SUCCESS != iEncReturn)
497524 return iEncReturn;
498525
@@ -505,7 +532,6 @@ int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encodin · 6 unmodified lines
505532 pEncCtx->pFuncList->pfRc.pfWelsRcMbInfoUpdate (pEncCtx, pCurMb, sMd.iCostLuma, pSlice);
506533
507534 ++iNumMbCoded;
508−
509535 iNextMbIdx = WelsGetNextMbOfSlice (pSliceCtx, iCurMbIdx);
510536 if (iNextMbIdx == -1 || iNextMbIdx >= kiTotalNumMb || iNumMbCoded >= kiTotalNumMb) {
511537 break;
@@ -540,24 +566,27 @@ int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + · 28 unmodified lines
540566 for (; ;) {
541567 iCurMbIdx = iNextMbIdx;
542568 pCurMb = &pMbList[ iCurMbIdx ];
569+
570+ StashMBStatus (&sDss, pBs, pSlice);
543571 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);
544572 // if already reaches the largest number of slices, set QPs to the upper bound
545573 if (pSlice->bDynamicSlicingSliceSizeCtrlFlag) {
546574 pCurMb->uiLumaQp = pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId].iMaxQp;
547575 pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)];
548576 }
577+ WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
549578
579+TRY_REENCODING:
550580 sMd.iLambda = g_kiQpCostTable[pCurMb->uiLumaQp];
551−
552− WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
553581 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);
554582 UpdateNonZeroCountCache (pCurMb, pMbCache);
555− //stack pBs pointer
556− sDss.pBsStackBufPtr = pBs->pBufPtr;
557− sDss.uiBsStackCurBits = pBs->uiCurBits;
558− sDss.iBsStackLeftBits = pBs->iLeftBits;
559583
560584 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
585+ if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
586+ StashPopMBStatus (&sDss, pBs, pSlice);
587+ UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
588+ goto TRY_REENCODING;
589+ }
561590 if (ENC_RETURN_SUCCESS != iEncReturn)
562591 return iEncReturn;
563592
@@ -926,18 +955,22 @@ int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, · 362 unmodified lines
926955 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
927956 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
928957 int32_t iEncReturn = ENC_RETURN_SUCCESS;
929−
958+ SDynamicSlicingStack sDss;
930959 for (;;) {
960+ StashMBStatus (&sDss, pBs, pSlice, iMbSkipRun);
931961 //point to current pMb
932962 iCurMbIdx = iNextMbIdx;
933963 pCurMb = &pMbList[ iCurMbIdx ];
934964
965+
935966 //step(1): set QP for the current MB
936967 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);
937968
938969 //step (2). save some vale for future use, initial pWelsMd
939970 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
940971 WelsMdInterInit (pEncCtx, pSlice, pCurMb, kiSliceFirstMbXY);
972+
973+TRY_REENCODING:
941974 WelsInitInterMDStruc (pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd);
942975 pEncCtx->pFuncList->pfInterMd (pEncCtx, pMd, pSlice, pCurMb, pMbCache);
943976 //mb_qp
@@ -961,6 +994,11 @@ int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, · 17 unmodified lines
961994 BsWriteUE (pBs, iMbSkipRun);
962995 iMbSkipRun = 0;
963996 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
997+ if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
998+ StashPopMBStatus (&sDss, pBs, pSlice, &iMbSkipRun);
999+ UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
1000+ goto TRY_REENCODING;
1001+ }
9641002 if (ENC_RETURN_SUCCESS != iEncReturn)
9651003 return iEncReturn;
9661004 }
@@ -1018,6 +1056,10 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 51 unmodified lines
10181056 SDynamicSlicingStack sDss;
10191057 sDss.iStartPos = BsGetBitsPos (pBs);
10201058 for (;;) {
1059+ //DYNAMIC_SLICING_ONE_THREAD - MultiD
1060+ //stack pBs pointer
1061+ StashMBStatus (&sDss, pBs, pSlice, iMbSkipRun);
1062+
10211063 //point to current pMb
10221064 iCurMbIdx = iNextMbIdx;
10231065 pCurMb = &pMbList[ iCurMbIdx ];
@@ -1036,6 +1078,8 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 12 unmodified lines
10361078 //step (2). save some vale for future use, initial pWelsMd
10371079 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
10381080 WelsMdInterInit (pEncCtx, pSlice, pCurMb, kiSliceFirstMbXY);
1081+
1082+TRY_REENCODING:
10391083 WelsInitInterMDStruc (pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd);
10401084 pEncCtx->pFuncList->pfInterMd (pEncCtx, pMd, pSlice, pCurMb, pMbCache);
10411085 //mb_qp
@@ -1051,15 +1095,6 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 9 unmodified lines
10511095
10521096 //step (6): begin to write bit stream; if the pSlice size is controlled, the writing may be skipped
10531097
1054− //DYNAMIC_SLICING_ONE_THREAD - MultiD
1055− //stack pBs pointer
1056− sDss.pBsStackBufPtr = pBs->pBufPtr;
1057− sDss.uiBsStackCurBits = pBs->uiCurBits;
1058− sDss.iBsStackLeftBits = pBs->iLeftBits;
1059− //stack Pskip status
1060− sDss.iMbSkipRunStack = iMbSkipRun;
1061− //DYNAMIC_SLICING_ONE_THREAD - MultiD
1062−
10631098 if (IS_SKIP (pCurMb->uiMbType)) {
10641099 pCurMb->uiLumaQp = pSlice->uiLastMbQp;
10651100 pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)];
@@ -1069,6 +1104,11 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 3 unmodified lines
10691104 BsWriteUE (pBs, iMbSkipRun);
10701105 iMbSkipRun = 0;
10711106 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
1107+ if (iEncReturn == ENC_RETURN_VLCOVERFLOWFOUND) {
1108+ StashPopMBStatus (&sDss, pBs, pSlice, &iMbSkipRun);
1109+ UpdateQpForOverflow (pCurMb, kuiChromaQpIndexOffset);
1110+ goto TRY_REENCODING;
1111+ }
10721112 if (ENC_RETURN_SUCCESS != iEncReturn)
10731113 return iEncReturn;
10741114 }

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