History

Merge pull request #1657 from mstorsjo/clip-bitrate

Make sure the random test bitrate is high enough

sijchen committed 11 years ago

Commit 9a602ca2 parents 397c7ca 887b4f416 files · +705 −79Browse files

Showing the changes to codec/decoder/core/src/decode_slice.cpp (1 of 16 files). Show all

Unified · Split

codec/decoder/core/src/decode_slice.cpp+108−23
@@ -197,8 +197,8 @@ int32_t WelsMbInterConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) { · 196 unmodified lines
197197 return 0;
198198 }
199199
200−void WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp) {
201− const int32_t kiQMul = g_kuiDequantCoeff[iQp][0];
200+void WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp, PWelsDecoderContext pCtx) {
201+ const int32_t kiQMul = pCtx->bUseScalingList ? pCtx->pDequant_coeff4x4[0][iQp][0] >> 4 : g_kuiDequantCoeff[iQp][0];
202202 #define STRIDE 16
203203 int32_t i;
204204 int32_t iTemp[16]; //FIXME check if this is a good idea
@@ -246,7 +246,7 @@ int32_t WelsMbIntraPredictionConstruction (PWelsDecoderContext pCtx, PDqLayer pC · 41 unmodified lines
246246 WelsFillRecNeededMbInfo (pCtx, bOutput, pCurLayer);
247247
248248 if (IS_INTRA16x16 (pCurLayer->pMbType[iMbXy])) {
249− WelsLumaDcDequantIdct (pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy]);
249+ WelsLumaDcDequantIdct (pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx);
250250 RecI16x16Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer);
251251
252252 return 0;
@@ -596,7 +596,8 @@ int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& ui · 343 unmodified lines
596596 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
597597 //Luma (DC and AC decoding together)
598598 WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, iIdx, iScanIdxEnd - iScanIdxStart + 1,
599− g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), pCurLayer->pLumaQp[iMbXy],
599+ g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC_INTRA, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4),
600+ pCurLayer->pLumaQp[iMbXy],
600601 pCtx));
601602 iIdx++;
602603 }
@@ -610,25 +611,26 @@ int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& ui · 7 unmodified lines
610611 ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3]));
611612 ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4]));
612613 }
613−
614+ int32_t iMbResProperty;
614615 //chroma
615616 //step1: DC
616617 if (1 == uiCbpChroma || 2 == uiCbpChroma) {
617618 //Cb Cr
618− WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, 16 + (0 << 2), 4, g_kuiChromaDcScan,
619− CHROMA_DC_V, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (0 << 6), pCurLayer->pChromaQp[iMbXy], pCtx));
620− WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, 16 + (1 << 2), 4, g_kuiChromaDcScan,
621− CHROMA_DC_U, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (1 << 6), pCurLayer->pChromaQp[iMbXy], pCtx));
619+ for (i = 0; i < 2; i++) {
620+ iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U;
621+ WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, 16 + (i << 2), 4, g_kuiChromaDcScan,
622+ iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy], pCtx));
623+ }
622624 }
623625
624626 //step2: AC
625627 if (2 == uiCbpChroma) {
626628 for (i = 0; i < 2; i++) { //Cb Cr
627− int32_t iResProperty = i ? CHROMA_AC_V : CHROMA_AC_U;
629+ iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U;
628630 int32_t iIdx = 16 + (i << 2);
629631 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
630632 WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, iIdx,
631− iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iResProperty,
633+ iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iMbResProperty,
632634 pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), pCurLayer->pChromaQp[iMbXy], pCtx));
633635 iIdx++;
634636 }
@@ -673,7 +675,7 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 38 unmodified lines
673675 int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart;
674676 int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd;
675677 int32_t iMbXy = pCurLayer->iMbXyIndex;
676−
678+ int32_t iMbResProperty;
677679 int32_t i;
678680 uint32_t uiMbType = 0, uiCbp = 0, uiCbpLuma = 0, uiCbpChroma = 0;
679681
@@ -723,6 +725,21 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 43 unmodified lines
723725 }
724726 }
725727
728+
729+
730+
731+
732+
733+
734+
735+
736+
737+
738+
739+
740+
741+
742+
726743 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
727744 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
728745 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
@@ -774,13 +791,15 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 45 unmodified lines
774791 ST32 (&pCurLayer->pNzc[iMbXy][12], 0);
775792 }
776793 } else { //non-MB_TYPE_INTRA16x16
794+ iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER;
777795 for (iId8x8 = 0; iId8x8 < 4; iId8x8++) {
778796 if (uiCbpLuma & (1 << iId8x8)) {
779797 int32_t iIdx = (iId8x8 << 2);
780798 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
781799 //Luma (DC and AC decoding together)
782800 WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, iIdx, iScanIdxEnd - iScanIdxStart + 1,
783− g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), pCurLayer->pLumaQp[iMbXy],
801+ g_kuiZigzagScan + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4),
802+ pCurLayer->pLumaQp[iMbXy],
784803 pCtx));
785804 iIdx++;
786805 }
@@ -799,20 +818,27 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 12 unmodified lines
799818 //step1: DC
800819 if (1 == uiCbpChroma || 2 == uiCbpChroma) {
801820 for (i = 0; i < 2; i++) {
802− int32_t iResProperty = i ? CHROMA_DC_V : CHROMA_DC_U;
821+ if (IS_INTRA (pCurLayer->pMbType[iMbXy]))
822+ iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U;
823+ else
824+ iMbResProperty = i ? CHROMA_DC_V_INTER : CHROMA_DC_U_INTER;
825+
803826 WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, 16 + (i << 2), 4, g_kuiChromaDcScan,
804− iResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy], pCtx));
827+ iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy], pCtx));
805828 }
806829 }
807830 //step2: AC
808831 if (2 == uiCbpChroma) {
809832 for (i = 0; i < 2; i++) {
810− int32_t iResProperty = i ? CHROMA_AC_V : CHROMA_AC_U;
833+ if (IS_INTRA (pCurLayer->pMbType[iMbXy]))
834+ iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U;
835+ else
836+ iMbResProperty = i ? CHROMA_AC_V_INTER : CHROMA_AC_U_INTER;
811837 int32_t index = 16 + (i << 2);
812838 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
813839 WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, index,
814840 iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
815− iResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (index << 4), pCurLayer->pChromaQp[iMbXy], pCtx));
841+ iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (index << 4), pCurLayer->pChromaQp[iMbXy], pCtx));
816842 index++;
817843 }
818844 }
@@ -893,6 +919,46 @@ int32_t WelsDecodeMbCabacPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uin · 74 unmodified lines
893919 WELS_READ_VERIFY (WelsDecodeMbCabacPSliceBaseMode0 (pCtx, &uiNeighAvail, uiEosFlag));
894920 return ERR_NONE;
895921 }
922+// Calculate deqaunt coeff scaling list value
923+int32_t WelsCalcDeqCoeffScalingList (PWelsDecoderContext pCtx) {
924+ int32_t iScalingListNum = 0;
925+ if (pCtx->pSps->bSeqScalingMatrixPresentFlag || pCtx->pPps->bPicScalingMatrixPresentFlag) {
926+ pCtx->bUseScalingList = true;
927+ iScalingListNum = (pCtx->pSps->uiChromaFormatIdc != 3) ? 8 : 12;
928+
929+ if (!pCtx->bDequantCoeff4x4Init || (pCtx->iDequantCoeffPpsid != pCtx->pPps->iPpsId)) {
930+ int i, q, x;
931+ // Rewrite pps scaling list for scalingList present flag=0
932+ if (pCtx->bSpsLatePps) {
933+ for (i = 0; i < 6; i++) {
934+ if (!pCtx->pSps->bSeqScalingListPresentFlag[i]) {
935+ if (i == 0 || i == 3)
936+ memcpy (pCtx->pPps->iScalingList4x4[i], pCtx->pSps->iScalingList4x4[i], 16 * sizeof (uint8_t));
937+ else
938+ memcpy (pCtx->pPps->iScalingList4x4[i], pCtx->pPps->iScalingList4x4[i - 1], 16 * sizeof (uint8_t));
939+
940+ }
941+ }
942+ //TO DO, SUPPORT 8x8 SCALINGlist
943+
944+ }
945+ //Init dequant coeff value for different QP
946+ for (i = 0; i < 6; i++) {
947+ pCtx->pDequant_coeff4x4[i] = pCtx->pDequant_coeff_buffer4x4[i];
948+ for (q = 0; q < 51; q++) {
949+ for (x = 0; x < 16; x++) {
950+ pCtx->pDequant_coeff4x4[i][q][x] = pCtx->pPps->bPicScalingMatrixPresentFlag ? pCtx->pPps->iScalingList4x4[i][x] *
951+ g_kuiDequantCoeff[q][x & 0x07] : pCtx->pSps->iScalingList4x4[i][x] * g_kuiDequantCoeff[q][x & 0x07];
952+ }
953+ }
954+ }
955+
956+ pCtx->bDequantCoeff4x4Init = true;
957+ }
958+ } else
959+ pCtx->bUseScalingList = false;
960+ return ERR_NONE;
961+}
896962
897963 int32_t WelsDecodeSlice (PWelsDecoderContext pCtx, bool bFirstSliceInLayer, PNalUnit pNalCur) {
898964 PDqLayer pCurLayer = pCtx->pCurDqLayer;
@@ -950,6 +1016,8 @@ int32_t WelsDecodeSlice (PWelsDecoderContext pCtx, bool bFirstSliceInLayer, PNal · 51 unmodified lines
9501016 pSlice->iLastDeltaQp = 0;
9511017 WELS_READ_VERIFY (InitCabacDecEngineFromBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux));
9521018 }
1019+ //try to calculate the dequant_coeff
1020+ WelsCalcDeqCoeffScalingList (pCtx);
9531021
9541022 iNextMbXyIndex = pSliceHeader->iFirstMbInSlice;
9551023 iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;
@@ -1001,6 +1069,7 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 45 unmodified lines
10011069 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;
10021070
10031071 SWelsNeighAvail sNeighAvail;
1072+ int32_t iMbResProperty;
10041073
10051074 int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart;
10061075 int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd;
@@ -1038,6 +1107,7 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 31 unmodified lines
10381107
10391108 uint8_t* pTmpBsBuf;
10401109
1110+
10411111 int32_t i;
10421112 int32_t iCopySizeY = (sizeof (uint8_t) << 4);
10431113 int32_t iCopySizeUV = (sizeof (uint8_t) << 3);
@@ -1165,7 +1235,7 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 121 unmodified lines
11651235 //Luma (DC and AC decoding together)
11661236 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
11671237 iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan + iScanIdxStart,
1168− LUMA_DC_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pLumaQp[iMbXy], pCtx)) {
1238+ LUMA_DC_AC_INTRA, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pLumaQp[iMbXy], pCtx)) {
11691239 return -1;//abnormal
11701240 }
11711241 iIndex++;
@@ -1185,8 +1255,9 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 13 unmodified lines
11851255 //step1: DC
11861256 if (1 == uiCbpC || 2 == uiCbpC) {
11871257 for (i = 0; i < 2; i++) { //Cb Cr
1258+ iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U;
11881259 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs,
1189− 16 + (i << 2), 4, g_kuiChromaDcScan, CHROMA_DC, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6),
1260+ 16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6),
11901261 pCurLayer->pChromaQp[iMbXy], pCtx)) {
11911262 return -1;//abnormal
11921263 }
@@ -1196,11 +1267,12 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 3 unmodified lines
11961267 //step2: AC
11971268 if (2 == uiCbpC) {
11981269 for (i = 0; i < 2; i++) { //Cb Cr
1270+ iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U;
11991271 int32_t iIndex = 16 + (i << 2);
12001272 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
12011273 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
12021274 iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
1203− CHROMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pChromaQp[iMbXy], pCtx)) {
1275+ iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pChromaQp[iMbXy], pCtx)) {
12041276 return -1;//abnormal
12051277 }
12061278 iIndex++;
@@ -1277,6 +1349,8 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 70 unmodified lines
12771349 uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;
12781350 uint32_t uiCode;
12791351 int32_t iCode;
1352+ int32_t iMbResProperty;
1353+
12801354 GetNeighborAvailMbType (&sNeighAvail, pCurLayer);
12811355 ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16);
12821356 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;//2009.10.23
@@ -1461,12 +1535,13 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 178 unmodified lines
14611535 }
14621536 } else { //non-MB_TYPE_INTRA16x16
14631537 for (iId8x8 = 0; iId8x8 < 4; iId8x8++) {
1538+ iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER;
14641539 if (uiCbpL & (1 << iId8x8)) {
14651540 int32_t iIndex = (iId8x8 << 2);
14661541 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
14671542 //Luma (DC and AC decoding together)
14681543 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
1469− iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC,
1544+ iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan + iScanIdxStart, iMbResProperty,
14701545 pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pLumaQp[iMbXy], pCtx)) {
14711546 return -1;//abnormal
14721547 }
@@ -1488,8 +1563,13 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 15 unmodified lines
14881563 //step1: DC
14891564 if (1 == uiCbpC || 2 == uiCbpC) {
14901565 for (i = 0; i < 2; i++) { //Cb Cr
1566+ if (IS_INTRA (pCurLayer->pMbType[iMbXy]))
1567+ iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U;
1568+ else
1569+ iMbResProperty = i ? CHROMA_DC_V_INTER : CHROMA_DC_U_INTER;
1570+
14911571 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs,
1492− 16 + (i << 2), 4, g_kuiChromaDcScan, CHROMA_DC, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6),
1572+ 16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6),
14931573 pCurLayer->pChromaQp[iMbXy], pCtx)) {
14941574 return -1;//abnormal
14951575 }
@@ -1499,11 +1579,16 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 3 unmodified lines
14991579 //step2: AC
15001580 if (2 == uiCbpC) {
15011581 for (i = 0; i < 2; i++) { //Cb Cr
1582+ if (IS_INTRA (pCurLayer->pMbType[iMbXy]))
1583+ iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U;
1584+ else
1585+ iMbResProperty = i ? CHROMA_AC_V_INTER : CHROMA_AC_U_INTER;
1586+
15021587 int32_t iIndex = 16 + (i << 2);
15031588 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
15041589 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
15051590 iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
1506− CHROMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pChromaQp[iMbXy], pCtx)) {
1591+ iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pChromaQp[iMbXy], pCtx)) {
15071592 return -1;//abnormal
15081593 }
15091594 iIndex++;

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