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
460 pfIdctFour4x4 (pDecV, kiDecStrideChroma, pDecV, kiDecStrideChroma, pScaledTcoeff + 320);460 pfIdctFour4x4 (pDecV, kiDecStrideChroma, pDecV, kiDecStrideChroma, pScaledTcoeff + 320);
461 }461 }
462}462}
463 463inline 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}
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) {
479 pCurMb->uiLumaQp += DELTA_QP;
480 pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)];
481}
464// for intra non-dynamic pSlice482// for intra non-dynamic pSlice
465//encapsulate two kinds of reconstruction:483//encapsulate two kinds of reconstruction:
466//first. store base or highest Dependency Layer with only one quality (without CS RS reconstruction)484//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
477 const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight;495 const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight;
478 int32_t iCurMbIdx = 0, iNumMbCoded = 0;496 int32_t iCurMbIdx = 0, iNumMbCoded = 0;
479 const int32_t kiSliceIdx = pSlice->uiSliceIdx;497 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
498 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
480 499
481 SWelsMD sMd;500 SWelsMD sMd;
482 int32_t iEncReturn = ENC_RETURN_SUCCESS;501 int32_t iEncReturn = ENC_RETURN_SUCCESS;
483 502 SBitStringAux* pBs = pSlice->pSliceBsa;
503 SDynamicSlicingStack sDss;
484 for (; ;) {504 for (; ;) {
505 StashMBStatus (&sDss, pBs, pSlice);
485 iCurMbIdx = iNextMbIdx;506 iCurMbIdx = iNextMbIdx;
486 pCurMb = &pMbList[ iCurMbIdx ];507 pCurMb = &pMbList[ iCurMbIdx ];
508
487 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);509 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);
510 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
488 511
512TRY_REENCODING:
489 sMd.iLambda = g_kiQpCostTable[pCurMb->uiLumaQp];513 sMd.iLambda = g_kiQpCostTable[pCurMb->uiLumaQp];
490
491 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
492 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);514 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);
493 UpdateNonZeroCountCache (pCurMb, pMbCache);515 UpdateNonZeroCountCache (pCurMb, pMbCache);
494 516
495 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);517 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 }
496 if (ENC_RETURN_SUCCESS != iEncReturn)523 if (ENC_RETURN_SUCCESS != iEncReturn)
497 return iEncReturn;524 return iEncReturn;
498 525
@@ -505,7 +532,6 @@ int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encodin · 6 unmodified lines
505 pEncCtx->pFuncList->pfRc.pfWelsRcMbInfoUpdate (pEncCtx, pCurMb, sMd.iCostLuma, pSlice);532 pEncCtx->pFuncList->pfRc.pfWelsRcMbInfoUpdate (pEncCtx, pCurMb, sMd.iCostLuma, pSlice);
506 533
507 ++iNumMbCoded;534 ++iNumMbCoded;
508
509 iNextMbIdx = WelsGetNextMbOfSlice (pSliceCtx, iCurMbIdx);535 iNextMbIdx = WelsGetNextMbOfSlice (pSliceCtx, iCurMbIdx);
510 if (iNextMbIdx == -1 || iNextMbIdx >= kiTotalNumMb || iNumMbCoded >= kiTotalNumMb) {536 if (iNextMbIdx == -1 || iNextMbIdx >= kiTotalNumMb || iNumMbCoded >= kiTotalNumMb) {
511 break;537 break;
@@ -540,24 +566,27 @@ int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + · 28 unmodified lines
540 for (; ;) {566 for (; ;) {
541 iCurMbIdx = iNextMbIdx;567 iCurMbIdx = iNextMbIdx;
542 pCurMb = &pMbList[ iCurMbIdx ];568 pCurMb = &pMbList[ iCurMbIdx ];
569
570 StashMBStatus (&sDss, pBs, pSlice);
543 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);571 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);
544 // 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
545 if (pSlice->bDynamicSlicingSliceSizeCtrlFlag) {573 if (pSlice->bDynamicSlicingSliceSizeCtrlFlag) {
546 pCurMb->uiLumaQp = pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId].iMaxQp;574 pCurMb->uiLumaQp = pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId].iMaxQp;
547 pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)];575 pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)];
548 }576 }
577 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
549 578
579TRY_REENCODING:
550 sMd.iLambda = g_kiQpCostTable[pCurMb->uiLumaQp];580 sMd.iLambda = g_kiQpCostTable[pCurMb->uiLumaQp];
551
552 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
553 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);581 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);
554 UpdateNonZeroCountCache (pCurMb, pMbCache);582 UpdateNonZeroCountCache (pCurMb, pMbCache);
555 //stack pBs pointer
556 sDss.pBsStackBufPtr = pBs->pBufPtr;
557 sDss.uiBsStackCurBits = pBs->uiCurBits;
558 sDss.iBsStackLeftBits = pBs->iLeftBits;
559 583
560 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);584 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 }
561 if (ENC_RETURN_SUCCESS != iEncReturn)590 if (ENC_RETURN_SUCCESS != iEncReturn)
562 return iEncReturn;591 return iEncReturn;
563 592
@@ -926,18 +955,22 @@ int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, · 362 unmodified lines
926 const int32_t kiSliceIdx = pSlice->uiSliceIdx;955 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
927 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;956 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
928 int32_t iEncReturn = ENC_RETURN_SUCCESS;957 int32_t iEncReturn = ENC_RETURN_SUCCESS;
929 958 SDynamicSlicingStack sDss;
930 for (;;) {959 for (;;) {
960 StashMBStatus (&sDss, pBs, pSlice, iMbSkipRun);
931 //point to current pMb961 //point to current pMb
932 iCurMbIdx = iNextMbIdx;962 iCurMbIdx = iNextMbIdx;
933 pCurMb = &pMbList[ iCurMbIdx ];963 pCurMb = &pMbList[ iCurMbIdx ];
934 964
965
935 //step(1): set QP for the current MB966 //step(1): set QP for the current MB
936 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);967 pEncCtx->pFuncList->pfRc.pfWelsRcMbInit (pEncCtx, pCurMb, pSlice);
937 968
938 //step (2). save some vale for future use, initial pWelsMd969 //step (2). save some vale for future use, initial pWelsMd
939 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);970 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
940 WelsMdInterInit (pEncCtx, pSlice, pCurMb, kiSliceFirstMbXY);971 WelsMdInterInit (pEncCtx, pSlice, pCurMb, kiSliceFirstMbXY);
972
973TRY_REENCODING:
941 WelsInitInterMDStruc (pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd);974 WelsInitInterMDStruc (pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd);
942 pEncCtx->pFuncList->pfInterMd (pEncCtx, pMd, pSlice, pCurMb, pMbCache);975 pEncCtx->pFuncList->pfInterMd (pEncCtx, pMd, pSlice, pCurMb, pMbCache);
943 //mb_qp976 //mb_qp
@@ -961,6 +994,11 @@ int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, · 17 unmodified lines
961 BsWriteUE (pBs, iMbSkipRun);994 BsWriteUE (pBs, iMbSkipRun);
962 iMbSkipRun = 0;995 iMbSkipRun = 0;
963 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);996 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 }
964 if (ENC_RETURN_SUCCESS != iEncReturn)1002 if (ENC_RETURN_SUCCESS != iEncReturn)
965 return iEncReturn;1003 return iEncReturn;
966 }1004 }
@@ -1018,6 +1056,10 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 51 unmodified lines
1018 SDynamicSlicingStack sDss;1056 SDynamicSlicingStack sDss;
1019 sDss.iStartPos = BsGetBitsPos (pBs);1057 sDss.iStartPos = BsGetBitsPos (pBs);
1020 for (;;) {1058 for (;;) {
1059 //DYNAMIC_SLICING_ONE_THREAD - MultiD
1060 //stack pBs pointer
1061 StashMBStatus (&sDss, pBs, pSlice, iMbSkipRun);
1062
1021 //point to current pMb1063 //point to current pMb
1022 iCurMbIdx = iNextMbIdx;1064 iCurMbIdx = iNextMbIdx;
1023 pCurMb = &pMbList[ iCurMbIdx ];1065 pCurMb = &pMbList[ iCurMbIdx ];
@@ -1036,6 +1078,8 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 12 unmodified lines
1036 //step (2). save some vale for future use, initial pWelsMd1078 //step (2). save some vale for future use, initial pWelsMd
1037 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);1079 WelsMdIntraInit (pEncCtx, pCurMb, pMbCache, kiSliceFirstMbXY);
1038 WelsMdInterInit (pEncCtx, pSlice, pCurMb, kiSliceFirstMbXY);1080 WelsMdInterInit (pEncCtx, pSlice, pCurMb, kiSliceFirstMbXY);
1081
1082TRY_REENCODING:
1039 WelsInitInterMDStruc (pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd);1083 WelsInitInterMDStruc (pCurMb, pMvdCostTableInter, kiMvdInterTableStride, pMd);
1040 pEncCtx->pFuncList->pfInterMd (pEncCtx, pMd, pSlice, pCurMb, pMbCache);1084 pEncCtx->pFuncList->pfInterMd (pEncCtx, pMd, pSlice, pCurMb, pMbCache);
1041 //mb_qp1085 //mb_qp
@@ -1051,15 +1095,6 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 9 unmodified lines
1051 1095
1052 //step (6): begin to write bit stream; if the pSlice size is controlled, the writing may be skipped1096 //step (6): begin to write bit stream; if the pSlice size is controlled, the writing may be skipped
1053 1097
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
1063 if (IS_SKIP (pCurMb->uiMbType)) {1098 if (IS_SKIP (pCurMb->uiMbType)) {
1064 pCurMb->uiLumaQp = pSlice->uiLastMbQp;1099 pCurMb->uiLumaQp = pSlice->uiLastMbQp;
1065 pCurMb->uiChromaQp = g_kuiChromaQpTable[CLIP3_QP_0_51 (pCurMb->uiLumaQp + kuiChromaQpIndexOffset)];1100 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
1069 BsWriteUE (pBs, iMbSkipRun);1104 BsWriteUE (pBs, iMbSkipRun);
1070 iMbSkipRun = 0;1105 iMbSkipRun = 0;
1071 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);1106 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 }
1072 if (ENC_RETURN_SUCCESS != iEncReturn)1112 if (ENC_RETURN_SUCCESS != iEncReturn)
1073 return iEncReturn;1113 return iEncReturn;
1074 }1114 }

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