History

to support monochroma

add mbtype judge logic

zhuiling committed 11 years ago

Commit 0a8a4f21 parent a00dd565 files · +65 −39Browse files

Showing the changes to codec/decoder/core/src (4 of 5 files). Show all

Unified · Split

4 files
  1. codec/decoder/core/src/au_parser.cpp +9 −3
  2. codec/decoder/core/src/decode_slice.cpp +39 −36
  3. codec/decoder/core/src/decoder_data_tables.cpp +9 −0
  4. codec/decoder/core/src/parse_mb_syn_cabac.cpp +6 −0
codec/decoder/core/src/au_parser.cpp+9−3
@@ -936,11 +936,17 @@ int32_t ParseSps (PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t* pPicW · 935 unmodified lines
936936
937937 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //chroma_format_idc
938938 pSps->uiChromaFormatIdc = uiCode;
939− if (pSps->uiChromaFormatIdc != 1) {
940− WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "ParseSps(): chroma_format_idc (%d) = 1 supported.",
939+// if (pSps->uiChromaFormatIdc != 1) {
940+// WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "ParseSps(): chroma_format_idc (%d) = 1 supported.",
941+// pSps->uiChromaFormatIdc);
942+// return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE);
943+// }
944+ if (pSps->uiChromaFormatIdc > 1) {
945+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "ParseSps(): chroma_format_idc (%d) <=1 supported.",
941946 pSps->uiChromaFormatIdc);
942947 return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE);
943− }
948+
949+ }// To support 4:0:0; 4:2:0
944950 pSps->uiChromaArrayType = pSps->uiChromaFormatIdc;
945951 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //bit_depth_luma_minus8
946952 if (uiCode != 0) {
codec/decoder/core/src/decode_slice.cpp+39−36
@@ -444,6 +444,10 @@ int32_t ParseIntra4x4Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail · 443 unmodified lines
444444 pCurDqLayer->pIntraPredMode[iMbXy][4] = pIntraPredMode[4 + 8 * 1];
445445 pCurDqLayer->pIntraPredMode[iMbXy][5] = pIntraPredMode[4 + 8 * 2];
446446 pCurDqLayer->pIntraPredMode[iMbXy][6] = pIntraPredMode[4 + 8 * 3];
447+
448+ if (pCtx->pSps->uiChromaFormatIdc == 0)//no need parse chroma
449+ return ERR_NONE;
450+
447451 if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) {
448452 WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode));
449453 if (iCode > MAX_PRED_MODE_ID_CHROMA) {
@@ -462,7 +466,6 @@ int32_t ParseIntra4x4Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail · 12 unmodified lines
462466 || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) {
463467 return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
464468 }
465−
466469 return ERR_NONE;
467470 }
468471
@@ -478,6 +481,9 @@ int32_t ParseIntra16x16Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAva · 9 unmodified lines
478481 &pCurDqLayer->pIntraPredMode[iMbXy][7])) { //invalid iPredMode, must stop decoding
479482 return ERR_INFO_INVALID_I16x16_PRED_MODE;
480483 }
484+ if (pCtx->pSps->uiChromaFormatIdc == 0)
485+ return ERR_NONE;
486+
481487 if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) {
482488 WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode));
483489 if (iCode > MAX_PRED_MODE_ID_CHROMA) {
@@ -519,6 +525,9 @@ int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& ui · 35 unmodified lines
519525 WELS_READ_VERIFY (ParseMBTypeISliceCabac (pCtx, &sNeighAvail, uiMbType));
520526 if (uiMbType > 25) {
521527 return ERR_INFO_INVALID_MB_TYPE;
528+ } else if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17
529+ && uiMbType <= 24))) {
530+ return ERR_INFO_INVALID_MB_TYPE;
522531 } else if (25 == uiMbType) { //I_PCM
523532 WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx));
524533 pSlice->iLastDeltaQp = 0;
@@ -536,19 +545,18 @@ int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& ui · 11 unmodified lines
536545 WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, &sNeighAvail, uiCbp));
537546 pCurLayer->pCbp[iMbXy] = uiCbp;
538547 pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp;
539− uiCbpChroma = uiCbp >> 4;
548+ uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? uiCbp >> 4 : 0;
540549 uiCbpLuma = uiCbp & 15;
541550 } else { //I16x16;
542551 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16;
543552 pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3;
544553 pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2];
545− uiCbpChroma = pCurLayer->pCbp[iMbXy] >> 4;
554+ uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0 ;
546555 uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15;
547556 WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer);
548557 WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBsAux, pCurLayer));
549558 }
550559
551−
552560 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
553561 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
554562 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
@@ -705,9 +713,10 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 150 unmodified lines
705713 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;
706714 } else { //Intra mode
707715 uiMbType -= 5;
708− if (uiMbType > 25) {
716+ if (uiMbType > 25)
717+ return ERR_INFO_INVALID_MB_TYPE;
718+ if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24)))
709719 return ERR_INFO_INVALID_MB_TYPE;
710− }
711720
712721 if (25 == uiMbType) { //I_PCM
713722 WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx));
@@ -727,7 +736,7 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 13 unmodified lines
727736 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16;
728737 pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3;
729738 pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2];
730− uiCbpChroma = pCurLayer->pCbp[iMbXy] >> 4;
739+ uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0;
731740 uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15;
732741 WelsFillCacheNonZeroCount (pNeighAvail, pNonZeroCount, pCurLayer);
733742 WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, pNeighAvail, pBsAux, pCurLayer));
@@ -735,21 +744,6 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 1 unmodified line
735744 }
736745 }
737746
738−
739−
740−
741−
742−
743−
744−
745−
746−
747−
748−
749−
750−
751−
752−
753747 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
754748 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
755749 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
@@ -759,9 +753,10 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 3 unmodified lines
759753
760754 if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) {
761755 WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, pNeighAvail, uiCbp));
756+
762757 pCurLayer->pCbp[iMbXy] = uiCbp;
763758 pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp;
764− uiCbpChroma = pCurLayer->pCbp[iMbXy] >> 4;
759+ uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0 ;
765760 uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15;
766761 }
767762
@@ -1104,9 +1099,10 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 336 unmodified lines
11041099
11051100 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //uiMbType
11061101 uiMbType = uiCode;
1107− if (uiMbType > 25) {
1102+ if (uiMbType > 25)
1103+ return ERR_INFO_INVALID_MB_TYPE;
1104+ if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24)))
11081105 return ERR_INFO_INVALID_MB_TYPE;
1109− }
11101106
11111107 if (25 == uiMbType) {
11121108 int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
@@ -1169,11 +1165,15 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 56 unmodified lines
11691165 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern
11701166 uiCbp = uiCode;
11711167 //G.9.1 Alternative parsing process for coded pBlock pattern
1172− if (uiCbp > 47)
1168+ if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47))
1169+ return ERR_INFO_INVALID_CBP;
1170+ if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15))
11731171 return ERR_INFO_INVALID_CBP;
11741172
1175− uiCbp = g_kuiIntra4x4CbpTable[uiCbp];
1176−
1173+ if (pCtx->pSps->uiChromaFormatIdc)
1174+ uiCbp = g_kuiIntra4x4CbpTable[uiCbp];
1175+ else
1176+ uiCbp = g_kuiIntra4x4CbpTable400[uiCbp];
11771177 pCurLayer->pCbp[iMbXy] = uiCbp;
11781178 uiCbpC = uiCbp >> 4;
11791179 uiCbpL = uiCbp & 15;
@@ -1181,7 +1181,7 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 1 unmodified line
11811181 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16;
11821182 pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3;
11831183 pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2];
1184− uiCbpC = pCurLayer->pCbp[iMbXy] >> 4;
1184+ uiCbpC = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0;
11851185 uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
11861186 WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer);
11871187 WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer));
@@ -1398,9 +1398,10 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 210 unmodified lines
13981398 }
13991399 } else { //intra MB type
14001400 uiMbType -= 5;
1401− if (uiMbType > 25) {
1401+ if (uiMbType > 25)
1402+ return ERR_INFO_INVALID_MB_TYPE;
1403+ if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24)))
14021404 return ERR_INFO_INVALID_MB_TYPE;
1403− }
14041405
14051406 if (25 == uiMbType) {
14061407 int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
@@ -1471,7 +1472,7 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 64 unmodified lines
14711472 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16;
14721473 pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3;
14731474 pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2];
1474− uiCbpC = pCurLayer->pCbp[iMbXy] >> 4;
1475+ uiCbpC = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0;
14751476 uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
14761477 WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer);
14771478 if (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer)) {
@@ -1485,13 +1486,15 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 7 unmodified lines
14851486 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern
14861487 uiCbp = uiCode;
14871488 {
1488− if (uiCbp > 47)
1489+ if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47))
1490+ return ERR_INFO_INVALID_CBP;
1491+ if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15))
14891492 return ERR_INFO_INVALID_CBP;
1490−
14911493 if (MB_TYPE_INTRA4x4 == pCurLayer->pMbType[iMbXy]) {
1492− uiCbp = g_kuiIntra4x4CbpTable[uiCbp];
1494+
1495+ uiCbp = pCtx->pSps->uiChromaFormatIdc ? g_kuiIntra4x4CbpTable[uiCbp] : g_kuiIntra4x4CbpTable400[uiCbp];
14931496 } else //inter
1494− uiCbp = g_kuiInterCbpTable[uiCbp];
1497+ uiCbp = pCtx->pSps->uiChromaFormatIdc ? g_kuiInterCbpTable[uiCbp] : g_kuiInterCbpTable400[uiCbp];
14951498 }
14961499
14971500 pCurLayer->pCbp[iMbXy] = uiCbp;
codec/decoder/core/src/decoder_data_tables.cpp+9−0
@@ -134,12 +134,21 @@ const uint8_t g_kuiIntra4x4CbpTable[48] = { · 133 unmodified lines
134134 8, 17, 18, 20, 24, 6, 9, 22, 25, 32, 33, 34, 36, 40, 38, 41 //47
135135 };
136136
137+const uint8_t g_kuiIntra4x4CbpTable400[16] = {
138+ 15, 0, 7, 11, 13, 14, 3, 5, 10, 12, 1, 2, 4, 8, 6, 9
139+
140+};
141+
137142 const uint8_t g_kuiInterCbpTable[48] = {
138143 0, 16, 1, 2, 4, 8, 32, 3, 5, 10, 12, 15, 47, 7, 11, 13, //15
139144 14, 6, 9, 31, 35, 37, 42, 44, 33, 34, 36, 40, 39, 43, 45, 46, //31
140145 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41 //47
141146 };
142147
148+const uint8_t g_kuiInterCbpTable400[16] = {
149+ 0, 1, 2, 4, 8, 3, 5, 10, 12, 15, 7, 11, 13, 14, 6, 9
150+};
151+
143152 const uint8_t g_kuiLeadingZeroTable[256] = {
144153 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
145154 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
codec/decoder/core/src/parse_mb_syn_cabac.cpp+6−0
@@ -669,6 +669,10 @@ int32_t ParseCbpInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail · 668 unmodified lines
669669 if (pCbpBit[3])
670670 uiCbp += 0x08;
671671
672+ if (pCtx->pSps->uiChromaFormatIdc == 0)//monochroma
673+ return ERR_NONE;
674+
675+
672676 //Chroma: bit by bit
673677 iIdxB = pNeighAvail->iTopAvail && (pNeighAvail->iTopType == MB_TYPE_INTRA_PCM || (pNeighAvail->iTopCbp >> 4));
674678 iIdxA = pNeighAvail->iLeftAvail && (pNeighAvail->iLeftType == MB_TYPE_INTRA_PCM || (pNeighAvail->iLeftCbp >> 4));
@@ -687,7 +691,9 @@ int32_t ParseCbpInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail · 12 unmodified lines
687691 pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + 2 * CTX_NUM_CBP + iCtxInc,
688692 pCbpBit[5]));
689693 uiCbp += 1 << (4 + pCbpBit[5]);
694+
690695 }
696+
691697 return ERR_NONE;
692698 }
693699

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