Make sure the random test bitrate is high enough
Showing the changes to codec/decoder (11 of 16 files). Show all
Unified · Split
| @@ -131,11 +131,26 @@ int32_t ParseSps (PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t* pPicW · 130 unmodified lines | ||
| 131 | 131 | */ |
| 132 | 132 | int32_t ParsePps (PWelsDecoderContext pCtx, PPps pPpsList, PBitStringAux pBsAux, uint8_t* pSrcNal, const int32_t kSrcNalLen); |
| 133 | 133 | |
| 134 | +/*! | |
| 135 | + ************************************************************************************* | |
| 136 | + * \brief to parse scaling list message payload | |
| 137 | + * | |
| 138 | + * \param PPS SPS scaling list matrix message to be parsed output | |
| 139 | + * \param pBsAux bitstream reader auxiliary | |
| 140 | + * | |
| 141 | + * \return 0 - successed | |
| 142 | + * 1 - failed | |
| 143 | + * | |
| 144 | + * \note Call it in case scaling matrix present at sps or pps | |
| 145 | + ************************************************************************************* | |
| 146 | +*/ | |
| 147 | +int32_t SetScalingListValue (uint8_t *pScalingList,int iScalingListNum,bool* bUseDefaultScalingMatrixFlag,PBitStringAux pBsAux); | |
| 148 | +int32_t ParseScalingList(PSps pSps,PBitStringAux pBs,bool bPPS,bool *bScalingListPresentFlag,uint8_t(*iScalingList4x4)[16],uint8_t(*iScalingList8x8)[64]); | |
| 134 | 149 | /*! |
| 135 | 150 | ************************************************************************************* |
| 136 | 151 | * \brief to parse SEI message payload |
| 137 | 152 | * |
| 138 | − * \param pSei sei message to be parsed output | |
| 153 | + * \param pSei sei message to be parsed output | |
| 139 | 154 | * \param pBsAux bitstream reader auxiliary |
| 140 | 155 | * |
| 141 | 156 | * \return 0 - successed |
| @@ -59,7 +59,7 @@ int32_t WelsMbIntraPredictionConstruction (PWelsDecoderContext pCtx, PDqLayer pC · 58 unmodified lines | ||
| 59 | 59 | int32_t WelsMbInterSampleConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer, |
| 60 | 60 | uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV, int32_t iStrideL, int32_t iStrideC); |
| 61 | 61 | int32_t WelsMbInterConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer); |
| 62 | −void WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp); | |
| 62 | +void WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp,PWelsDecoderContext pCtx); | |
| 63 | 63 | int32_t WelsMbInterPrediction (PWelsDecoderContext pCtx, PDqLayer pCurLayer); |
| 64 | 64 | void WelsChromaDcIdct (int16_t* pBlock); |
| 65 | 65 | |
| @@ -409,6 +409,15 @@ bool bRPLRError; · 408 unmodified lines | ||
| 409 | 409 | int32_t iECMVs[16][2]; |
| 410 | 410 | PPicture pECRefPic[16]; |
| 411 | 411 | unsigned long long uiTimeStamp; |
| 412 | +// To support scaling list HP | |
| 413 | +uint16_t pDequant_coeff_buffer4x4[6][52][16]; | |
| 414 | +uint16_t pDequant_coeff_buffer8x8[6][52][64]; | |
| 415 | +uint16_t (*pDequant_coeff4x4[6])[16];// 4x4 sclaing list value pointer | |
| 416 | +uint16_t (*pDequant_coeff8x8[6])[64];//64 residual coeff ,with 6 kinds of residual type, 52 qp level | |
| 417 | +int iDequantCoeffPpsid;//When a new pps actived, reinitialised the scaling list value | |
| 418 | +bool bDequantCoeff4x4Init; | |
| 419 | +bool bSpsLatePps; | |
| 420 | +bool bUseScalingList; | |
| 412 | 421 | } SWelsDecoderContext, *PWelsDecoderContext; |
| 413 | 422 | |
| 414 | 423 | static inline void ResetActiveSPSForEachLayer (PWelsDecoderContext pCtx) { |
| @@ -185,6 +185,8 @@ ERR_INFO_INVALID_MMCO_REF_NUM_NOT_ENOUGH, · 184 unmodified lines | ||
| 185 | 185 | ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX, |
| 186 | 186 | //for CABAC |
| 187 | 187 | ERR_CABAC_NO_BS_TO_READ, |
| 188 | +//for scaling list | |
| 189 | +ERR_SCALING_LIST_DELTA_SCALE, | |
| 188 | 190 | }; |
| 189 | 191 | //----------------------------------------------------------------------------------------------------------- |
| 190 | 192 | |
| @@ -88,7 +88,11 @@ typedef struct TagSps { · 87 unmodified lines | ||
| 88 | 88 | bool bQpPrimeYZeroTransfBypassFlag; |
| 89 | 89 | bool bSeqScalingMatrixPresentFlag; |
| 90 | 90 | bool bSeqScalingListPresentFlag[12]; |
| 91 | − const SLevelLimits* pSLevelLimits; | |
| 91 | + //Add scaling list supporting | |
| 92 | + uint8_t iScalingList4x4[6][16]; | |
| 93 | + uint8_t iScalingList8x8[6][64]; | |
| 94 | + | |
| 95 | +const SLevelLimits* pSLevelLimits; | |
| 92 | 96 | } SSps, *PSps; |
| 93 | 97 | |
| 94 | 98 | |
| @@ -163,7 +167,12 @@ typedef struct TagPps { · 68 unmodified lines | ||
| 163 | 167 | bool bRedundantPicCntPresentFlag; |
| 164 | 168 | bool bWeightedPredFlag; |
| 165 | 169 | uint8_t uiWeightedBipredIdc; |
| 166 | − | |
| 170 | + bool bTransform_8x8_mode_flag; | |
| 171 | + //Add for scalinglist support | |
| 172 | + bool bPicScalingMatrixPresentFlag; | |
| 173 | + bool bPicScalingListPresentFlag[12]; | |
| 174 | + uint8_t iScalingList4x4[6][16]; | |
| 175 | + uint8_t iScalingList8x8[6][64]; | |
| 167 | 176 | } SPps, *PPps; |
| 168 | 177 | |
| 169 | 178 | } // namespace WelsDec |
| @@ -132,6 +132,12 @@ typedef int32_t SubMbType; · 131 unmodified lines | ||
| 132 | 132 | #define CHROMA_DC_V 7 |
| 133 | 133 | #define CHROMA_AC_U 8 |
| 134 | 134 | #define CHROMA_AC_V 9 |
| 135 | +#define LUMA_DC_AC_INTRA 10 | |
| 136 | +#define LUMA_DC_AC_INTER 11 | |
| 137 | +#define CHROMA_DC_U_INTER 12 | |
| 138 | +#define CHROMA_DC_V_INTER 13 | |
| 139 | +#define CHROMA_AC_U_INTER 14 | |
| 140 | +#define CHROMA_AC_V_INTER 15 | |
| 135 | 141 | |
| 136 | 142 | typedef struct TagReadBitsCache { |
| 137 | 143 | uint32_t uiCache32Bit; |
| @@ -150,6 +156,59 @@ static const uint8_t g_kuiZigzagScan[16] = { //4*4block residual zig-zag scan or · 12 unmodified lines | ||
| 150 | 156 | }; |
| 151 | 157 | |
| 152 | 158 | |
| 159 | +static inline void GetMbResProperty(int32_t * pMBproperty,int32_t* pResidualProperty,bool bCavlc) | |
| 160 | +{ | |
| 161 | + switch(*pResidualProperty) | |
| 162 | + { | |
| 163 | + case CHROMA_AC_U: | |
| 164 | + *pMBproperty = 1; | |
| 165 | + *pResidualProperty = bCavlc ? CHROMA_AC : CHROMA_AC_U; | |
| 166 | + break; | |
| 167 | + case CHROMA_AC_V: | |
| 168 | + *pMBproperty = 2; | |
| 169 | + *pResidualProperty = bCavlc ? CHROMA_AC : CHROMA_AC_V; | |
| 170 | + break; | |
| 171 | + case LUMA_DC_AC_INTRA: | |
| 172 | + *pMBproperty = 0; | |
| 173 | + *pResidualProperty = LUMA_DC_AC; | |
| 174 | + break; | |
| 175 | + case CHROMA_DC_U: | |
| 176 | + *pMBproperty = 1; | |
| 177 | + *pResidualProperty = bCavlc ? CHROMA_DC : CHROMA_DC_U; | |
| 178 | + break; | |
| 179 | + case CHROMA_DC_V: | |
| 180 | + *pMBproperty = 2; | |
| 181 | + *pResidualProperty = bCavlc ? CHROMA_DC : CHROMA_DC_V; | |
| 182 | + break; | |
| 183 | + case I16_LUMA_AC: | |
| 184 | + *pMBproperty = 0; | |
| 185 | + break; | |
| 186 | + case I16_LUMA_DC: | |
| 187 | + *pMBproperty = 0; | |
| 188 | + break; | |
| 189 | + case LUMA_DC_AC_INTER: | |
| 190 | + *pMBproperty = 3; | |
| 191 | + *pResidualProperty = LUMA_DC_AC; | |
| 192 | + break; | |
| 193 | + case CHROMA_DC_U_INTER: | |
| 194 | + *pMBproperty = 4; | |
| 195 | + *pResidualProperty = bCavlc ? CHROMA_DC : CHROMA_DC_U; | |
| 196 | + break; | |
| 197 | + case CHROMA_DC_V_INTER: | |
| 198 | + *pMBproperty = 5; | |
| 199 | + *pResidualProperty = bCavlc ? CHROMA_DC : CHROMA_DC_V; | |
| 200 | + break; | |
| 201 | + case CHROMA_AC_U_INTER: | |
| 202 | + *pMBproperty = 4; | |
| 203 | + *pResidualProperty = bCavlc ? CHROMA_AC : CHROMA_AC_U; | |
| 204 | + break; | |
| 205 | + case CHROMA_AC_V_INTER: | |
| 206 | + *pMBproperty = 5; | |
| 207 | + *pResidualProperty = bCavlc ?CHROMA_AC:CHROMA_AC_V; | |
| 208 | + break; | |
| 209 | + } | |
| 210 | + } | |
| 211 | + | |
| 153 | 212 | typedef struct TagI16PredInfo { |
| 154 | 213 | int8_t iPredMode; |
| 155 | 214 | int8_t iLeftAvail; |
| @@ -833,6 +833,8 @@ bool CheckSpsActive (PWelsDecoderContext pCtx, PSps pSps, bool bUseSubsetFlag) { · 832 unmodified lines | ||
| 833 | 833 | #define PPS_PIC_INIT_QP_QS_MAX 51 |
| 834 | 834 | #define PPS_CHROMA_QP_INDEX_OFFSET_MIN -12 |
| 835 | 835 | #define PPS_CHROMA_QP_INDEX_OFFSET_MAX 12 |
| 836 | +#define SCALING_LIST_DELTA_SCALE_MAX 127 | |
| 837 | +#define SCALING_LIST_DELTA_SCALE_MIN -128 | |
| 836 | 838 | |
| 837 | 839 | /*! |
| 838 | 840 | ************************************************************************************* |
| @@ -935,12 +937,16 @@ int32_t ParseSps (PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t* pPicW · 96 unmodified lines | ||
| 935 | 937 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //seq_scaling_matrix_present_flag |
| 936 | 938 | pSps->bSeqScalingMatrixPresentFlag = !!uiCode; |
| 937 | 939 | |
| 938 | − if (pSps->bSeqScalingMatrixPresentFlag) { // For high profile, it is not used in current application. FIXME | |
| 939 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, | |
| 940 | − "ParseSps(): seq_scaling_matrix_present_flag (%d). Feature not supported.", | |
| 941 | − pSps->bSeqScalingMatrixPresentFlag); | |
| 942 | − return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | |
| 943 | − } | |
| 940 | + if (pSps->bSeqScalingMatrixPresentFlag)// For high profile, it is not used in current application. FIXME | |
| 941 | + | |
| 942 | + WELS_READ_VERIFY (ParseScalingList (pSps, pBs, 0, pSps->bSeqScalingListPresentFlag, pSps->iScalingList4x4, | |
| 943 | + pSps->iScalingList8x8)); | |
| 944 | + //if exist, to parse scalinglist matrix value | |
| 945 | + | |
| 946 | + // WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, | |
| 947 | + // "ParseSps(): seq_scaling_matrix_present_flag (%d). Feature not supported.", | |
| 948 | + // pSps->bSeqScalingMatrixPresentFlag); | |
| 949 | + //return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | |
| 944 | 950 | } |
| 945 | 951 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //log2_max_frame_num_minus4 |
| 946 | 952 | WELS_CHECK_SE_UPPER_ERROR (uiCode, SPS_LOG2_MAX_FRAME_NUM_MINUS4_MAX, "log2_max_frame_num_minus4", |
| @@ -1307,6 +1313,22 @@ int32_t ParsePps (PWelsDecoderContext pCtx, PPps pPpsList, PBitStringAux pBsAux, · 360 unmodified lines | ||
| 1307 | 1313 | pPps->bConstainedIntraPredFlag = !!uiCode; |
| 1308 | 1314 | WELS_READ_VERIFY (BsGetOneBit (pBsAux, &uiCode)); //redundant_pic_cnt_present_flag |
| 1309 | 1315 | pPps->bRedundantPicCntPresentFlag = !!uiCode; |
| 1316 | +//going on to parse high profile syntax, need fix me | |
| 1317 | + WELS_READ_VERIFY (BsGetOneBit (pBsAux, &uiCode)); | |
| 1318 | + pPps->bTransform_8x8_mode_flag = !!uiCode; | |
| 1319 | + WELS_READ_VERIFY (BsGetOneBit (pBsAux, &uiCode)); | |
| 1320 | + pPps->bPicScalingMatrixPresentFlag = !!uiCode; | |
| 1321 | + if (pPps->bPicScalingMatrixPresentFlag) { | |
| 1322 | + if (pCtx->bSpsAvailFlags[pPps->iSpsId]) | |
| 1323 | + WELS_READ_VERIFY (ParseScalingList (&pCtx->sSpsBuffer[pPps->iSpsId], pBsAux, 1, pPps->bPicScalingListPresentFlag, | |
| 1324 | + pPps->iScalingList4x4, pPps->iScalingList8x8)); | |
| 1325 | + else { | |
| 1326 | + pCtx->bSpsLatePps = true; | |
| 1327 | + WELS_READ_VERIFY (ParseScalingList (NULL, pBsAux, 1, pPps->bPicScalingListPresentFlag, pPps->iScalingList4x4, | |
| 1328 | + pPps->iScalingList8x8)); | |
| 1329 | + } | |
| 1330 | + } | |
| 1331 | + | |
| 1310 | 1332 | if (pCtx->pAccessUnitList->uiAvailUnitsNum > 0) { |
| 1311 | 1333 | PNalUnit pLastNalUnit = pCtx->pAccessUnitList->pNalUnitsList[pCtx->pAccessUnitList->uiAvailUnitsNum - 1]; |
| 1312 | 1334 | PPps pLastPps = pLastNalUnit->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pPps; |
| @@ -1355,6 +1377,113 @@ int32_t ParseSei (void* pSei, PBitStringAux pBsAux) { // reserved Sei_Msg type · 42 unmodified lines | ||
| 1355 | 1377 | |
| 1356 | 1378 | return ERR_NONE; |
| 1357 | 1379 | } |
| 1380 | +/* | |
| 1381 | + ************************************************************************************* | |
| 1382 | + * \brief to parse scalinglist message payload | |
| 1383 | + * | |
| 1384 | + * \param pps sps scaling list matrix message to be parsed output | |
| 1385 | + * \param pBsAux bitstream reader auxiliary | |
| 1386 | + * | |
| 1387 | + * \return 0 - successed | |
| 1388 | + * 1 - failed | |
| 1389 | + * | |
| 1390 | + * \note Call it in case scaling list matrix present at sps or pps level | |
| 1391 | + ************************************************************************************* | |
| 1392 | + */ | |
| 1393 | +int32_t SetScalingListValue (uint8_t* pScalingList, int iScalingListNum, bool* bUseDefaultScalingMatrixFlag, | |
| 1394 | + PBitStringAux pBsAux) { // reserved Sei_Msg type | |
| 1395 | + int iLastScale = 8; | |
| 1396 | + int iNextScale = 8; | |
| 1397 | + int iDeltaScale; | |
| 1398 | + int32_t iCode; | |
| 1399 | + for (int j = 0; j < iScalingListNum; j++) { | |
| 1400 | + if (iNextScale != 0) { | |
| 1401 | + WELS_READ_VERIFY (BsGetSe (pBsAux, &iCode)); | |
| 1402 | + WELS_CHECK_SE_BOTH_ERROR_NOLOG (iCode, SCALING_LIST_DELTA_SCALE_MIN, SCALING_LIST_DELTA_SCALE_MAX, "DeltaScale", | |
| 1403 | + ERR_SCALING_LIST_DELTA_SCALE); | |
| 1404 | + iDeltaScale = iCode; | |
| 1405 | + iNextScale = (iLastScale + iDeltaScale + 256) % 256; | |
| 1406 | + *bUseDefaultScalingMatrixFlag = (j == 0 && iNextScale == 0); | |
| 1407 | + if (*bUseDefaultScalingMatrixFlag) | |
| 1408 | + break; | |
| 1409 | + } | |
| 1410 | + pScalingList[g_kuiZigzagScan[j]] = (iNextScale == 0) ? iLastScale : iNextScale; | |
| 1411 | + iLastScale = pScalingList[g_kuiZigzagScan[j]]; | |
| 1412 | + } | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + return ERR_NONE; | |
| 1416 | +} | |
| 1417 | + | |
| 1418 | +int32_t ParseScalingList (PSps pSps, PBitStringAux pBs, bool bPPS, bool* pScalingListPresentFlag, | |
| 1419 | + uint8_t (*iScalingList4x4)[16], uint8_t (*iScalingList8x8)[64]) { | |
| 1420 | + uint32_t uiScalingListNum; | |
| 1421 | + uint32_t uiCode; | |
| 1422 | + int32_t iRetTmp; | |
| 1423 | + bool bUseDefaultScalingMatrixFlag4x4 = false; | |
| 1424 | + bool bUseDefaultScalingMatrixFlag8x8 = false; | |
| 1425 | + bool bInit = false; | |
| 1426 | + const uint8_t* defaultScaling[4]; | |
| 1427 | + | |
| 1428 | + if (pSps != NULL) { | |
| 1429 | + uiScalingListNum = (pSps->uiChromaFormatIdc != 3) ? 8 : 12; | |
| 1430 | + bInit = bPPS && pSps->bSeqScalingMatrixPresentFlag; | |
| 1431 | + } else | |
| 1432 | + uiScalingListNum = 12; | |
| 1433 | + | |
| 1434 | +//Init default_scaling_list value for sps or pps | |
| 1435 | + defaultScaling[0] = bInit ? pSps->iScalingList4x4[0] : g_kuiDequantScaling4x4Default[0]; | |
| 1436 | + defaultScaling[1] = bInit ? pSps->iScalingList4x4[3] : g_kuiDequantScaling4x4Default[1]; | |
| 1437 | + defaultScaling[2] = bInit ? pSps->iScalingList8x8[0] : g_kuiDequantScaling8x8Default[0]; | |
| 1438 | + defaultScaling[3] = bInit ? pSps->iScalingList8x8[1] : g_kuiDequantScaling8x8Default[1]; | |
| 1439 | + | |
| 1440 | + for (int i = 0; i < uiScalingListNum; i++) { | |
| 1441 | + WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); | |
| 1442 | + pScalingListPresentFlag[i] = !!uiCode; | |
| 1443 | + if (!!uiCode) { | |
| 1444 | + if (i < 6) { | |
| 1445 | + iRetTmp = SetScalingListValue (iScalingList4x4[i], 16, &bUseDefaultScalingMatrixFlag4x4, pBs); | |
| 1446 | + if (iRetTmp == ERR_NONE) { | |
| 1447 | + if (bUseDefaultScalingMatrixFlag4x4) { | |
| 1448 | + bUseDefaultScalingMatrixFlag4x4 = false; | |
| 1449 | + memcpy (iScalingList4x4[i], g_kuiDequantScaling4x4Default[i / 3], sizeof (uint8_t) * 16); | |
| 1450 | + } | |
| 1451 | + } else | |
| 1452 | + return iRetTmp; | |
| 1453 | + | |
| 1454 | + } else { | |
| 1455 | + SetScalingListValue (iScalingList8x8[i - 6], 64, &bUseDefaultScalingMatrixFlag8x8, pBs); | |
| 1456 | + //if(iRetTmp == ERR_NONE) | |
| 1457 | + //{ | |
| 1458 | + if (bUseDefaultScalingMatrixFlag8x8) { | |
| 1459 | + bUseDefaultScalingMatrixFlag8x8 = false; | |
| 1460 | + memcpy (iScalingList8x8[i - 6], g_kuiDequantScaling8x8Default[ (i - 6) & 1], sizeof (uint8_t) * 64); | |
| 1461 | + } | |
| 1462 | + // } | |
| 1463 | + | |
| 1464 | + //else | |
| 1465 | + // return iRetTmp; | |
| 1466 | + } | |
| 1467 | + | |
| 1468 | + } else { | |
| 1469 | + if (i < 6) { | |
| 1470 | + if ((i != 0) && (i != 3)) | |
| 1471 | + memcpy (iScalingList4x4[i], iScalingList4x4[i - 1], sizeof (uint8_t) * 16); | |
| 1472 | + else | |
| 1473 | + memcpy (iScalingList4x4[i], defaultScaling[i / 3], sizeof (uint8_t) * 16); | |
| 1474 | + | |
| 1475 | + } else { | |
| 1476 | + if ((i == 6) || (i == 7)) | |
| 1477 | + memcpy (iScalingList8x8[i - 6], defaultScaling[ (i & 1) + 2], sizeof (uint8_t) * 64); | |
| 1478 | + else | |
| 1479 | + memcpy (iScalingList8x8[i - 6], iScalingList8x8[ (i - 6) / 3], sizeof (uint8_t) * 64); | |
| 1480 | + | |
| 1481 | + } | |
| 1482 | + } | |
| 1483 | + } | |
| 1484 | + return ERR_NONE; | |
| 1485 | + | |
| 1486 | +} | |
| 1358 | 1487 | |
| 1359 | 1488 | /*! |
| 1360 | 1489 | ************************************************************************************* |
| @@ -197,8 +197,8 @@ int32_t WelsMbInterConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) { · 196 unmodified lines | ||
| 197 | 197 | return 0; |
| 198 | 198 | } |
| 199 | 199 | |
| 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]; | |
| 202 | 202 | #define STRIDE 16 |
| 203 | 203 | int32_t i; |
| 204 | 204 | 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 | ||
| 246 | 246 | WelsFillRecNeededMbInfo (pCtx, bOutput, pCurLayer); |
| 247 | 247 | |
| 248 | 248 | if (IS_INTRA16x16 (pCurLayer->pMbType[iMbXy])) { |
| 249 | − WelsLumaDcDequantIdct (pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy]); | |
| 249 | + WelsLumaDcDequantIdct (pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx); | |
| 250 | 250 | RecI16x16Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer); |
| 251 | 251 | |
| 252 | 252 | return 0; |
| @@ -596,7 +596,8 @@ int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& ui · 343 unmodified lines | ||
| 596 | 596 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 597 | 597 | //Luma (DC and AC decoding together) |
| 598 | 598 | 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], | |
| 600 | 601 | pCtx)); |
| 601 | 602 | iIdx++; |
| 602 | 603 | } |
| @@ -610,25 +611,26 @@ int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& ui · 7 unmodified lines | ||
| 610 | 611 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 611 | 612 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 612 | 613 | } |
| 613 | − | |
| 614 | + int32_t iMbResProperty; | |
| 614 | 615 | //chroma |
| 615 | 616 | //step1: DC |
| 616 | 617 | if (1 == uiCbpChroma || 2 == uiCbpChroma) { |
| 617 | 618 | //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 | + } | |
| 622 | 624 | } |
| 623 | 625 | |
| 624 | 626 | //step2: AC |
| 625 | 627 | if (2 == uiCbpChroma) { |
| 626 | 628 | 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; | |
| 628 | 630 | int32_t iIdx = 16 + (i << 2); |
| 629 | 631 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 630 | 632 | 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, | |
| 632 | 634 | pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), pCurLayer->pChromaQp[iMbXy], pCtx)); |
| 633 | 635 | iIdx++; |
| 634 | 636 | } |
| @@ -673,7 +675,7 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 38 unmodified lines | ||
| 673 | 675 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; |
| 674 | 676 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; |
| 675 | 677 | int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 676 | − | |
| 678 | + int32_t iMbResProperty; | |
| 677 | 679 | int32_t i; |
| 678 | 680 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpLuma = 0, uiCbpChroma = 0; |
| 679 | 681 | |
| @@ -723,6 +725,21 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 43 unmodified lines | ||
| 723 | 725 | } |
| 724 | 726 | } |
| 725 | 727 | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 726 | 743 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 727 | 744 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 728 | 745 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| @@ -774,13 +791,15 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 45 unmodified lines | ||
| 774 | 791 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 775 | 792 | } |
| 776 | 793 | } else { //non-MB_TYPE_INTRA16x16 |
| 794 | + iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER; | |
| 777 | 795 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 778 | 796 | if (uiCbpLuma & (1 << iId8x8)) { |
| 779 | 797 | int32_t iIdx = (iId8x8 << 2); |
| 780 | 798 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 781 | 799 | //Luma (DC and AC decoding together) |
| 782 | 800 | 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], | |
| 784 | 803 | pCtx)); |
| 785 | 804 | iIdx++; |
| 786 | 805 | } |
| @@ -799,20 +818,27 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 12 unmodified lines | ||
| 799 | 818 | //step1: DC |
| 800 | 819 | if (1 == uiCbpChroma || 2 == uiCbpChroma) { |
| 801 | 820 | 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 | + | |
| 803 | 826 | 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)); | |
| 805 | 828 | } |
| 806 | 829 | } |
| 807 | 830 | //step2: AC |
| 808 | 831 | if (2 == uiCbpChroma) { |
| 809 | 832 | 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; | |
| 811 | 837 | int32_t index = 16 + (i << 2); |
| 812 | 838 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 813 | 839 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, index, |
| 814 | 840 | 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)); | |
| 816 | 842 | index++; |
| 817 | 843 | } |
| 818 | 844 | } |
| @@ -893,6 +919,46 @@ int32_t WelsDecodeMbCabacPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uin · 74 unmodified lines | ||
| 893 | 919 | WELS_READ_VERIFY (WelsDecodeMbCabacPSliceBaseMode0 (pCtx, &uiNeighAvail, uiEosFlag)); |
| 894 | 920 | return ERR_NONE; |
| 895 | 921 | } |
| 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 | +} | |
| 896 | 962 | |
| 897 | 963 | int32_t WelsDecodeSlice (PWelsDecoderContext pCtx, bool bFirstSliceInLayer, PNalUnit pNalCur) { |
| 898 | 964 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| @@ -950,6 +1016,8 @@ int32_t WelsDecodeSlice (PWelsDecoderContext pCtx, bool bFirstSliceInLayer, PNal · 51 unmodified lines | ||
| 950 | 1016 | pSlice->iLastDeltaQp = 0; |
| 951 | 1017 | WELS_READ_VERIFY (InitCabacDecEngineFromBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux)); |
| 952 | 1018 | } |
| 1019 | + //try to calculate the dequant_coeff | |
| 1020 | + WelsCalcDeqCoeffScalingList (pCtx); | |
| 953 | 1021 | |
| 954 | 1022 | iNextMbXyIndex = pSliceHeader->iFirstMbInSlice; |
| 955 | 1023 | iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; |
| @@ -1001,6 +1069,7 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 45 unmodified lines | ||
| 1001 | 1069 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 1002 | 1070 | |
| 1003 | 1071 | SWelsNeighAvail sNeighAvail; |
| 1072 | + int32_t iMbResProperty; | |
| 1004 | 1073 | |
| 1005 | 1074 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; |
| 1006 | 1075 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; |
| @@ -1038,6 +1107,7 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 31 unmodified lines | ||
| 1038 | 1107 | |
| 1039 | 1108 | uint8_t* pTmpBsBuf; |
| 1040 | 1109 | |
| 1110 | + | |
| 1041 | 1111 | int32_t i; |
| 1042 | 1112 | int32_t iCopySizeY = (sizeof (uint8_t) << 4); |
| 1043 | 1113 | int32_t iCopySizeUV = (sizeof (uint8_t) << 3); |
| @@ -1165,7 +1235,7 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 121 unmodified lines | ||
| 1165 | 1235 | //Luma (DC and AC decoding together) |
| 1166 | 1236 | if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, |
| 1167 | 1237 | 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)) { | |
| 1169 | 1239 | return -1;//abnormal |
| 1170 | 1240 | } |
| 1171 | 1241 | iIndex++; |
| @@ -1185,8 +1255,9 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 13 unmodified lines | ||
| 1185 | 1255 | //step1: DC |
| 1186 | 1256 | if (1 == uiCbpC || 2 == uiCbpC) { |
| 1187 | 1257 | for (i = 0; i < 2; i++) { //Cb Cr |
| 1258 | + iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; | |
| 1188 | 1259 | 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), | |
| 1190 | 1261 | pCurLayer->pChromaQp[iMbXy], pCtx)) { |
| 1191 | 1262 | return -1;//abnormal |
| 1192 | 1263 | } |
| @@ -1196,11 +1267,12 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 3 unmodified lines | ||
| 1196 | 1267 | //step2: AC |
| 1197 | 1268 | if (2 == uiCbpC) { |
| 1198 | 1269 | for (i = 0; i < 2; i++) { //Cb Cr |
| 1270 | + iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; | |
| 1199 | 1271 | int32_t iIndex = 16 + (i << 2); |
| 1200 | 1272 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1201 | 1273 | if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, |
| 1202 | 1274 | 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)) { | |
| 1204 | 1276 | return -1;//abnormal |
| 1205 | 1277 | } |
| 1206 | 1278 | iIndex++; |
| @@ -1277,6 +1349,8 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 70 unmodified lines | ||
| 1277 | 1349 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0; |
| 1278 | 1350 | uint32_t uiCode; |
| 1279 | 1351 | int32_t iCode; |
| 1352 | + int32_t iMbResProperty; | |
| 1353 | + | |
| 1280 | 1354 | GetNeighborAvailMbType (&sNeighAvail, pCurLayer); |
| 1281 | 1355 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); |
| 1282 | 1356 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;//2009.10.23 |
| @@ -1461,12 +1535,13 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 178 unmodified lines | ||
| 1461 | 1535 | } |
| 1462 | 1536 | } else { //non-MB_TYPE_INTRA16x16 |
| 1463 | 1537 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 1538 | + iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER; | |
| 1464 | 1539 | if (uiCbpL & (1 << iId8x8)) { |
| 1465 | 1540 | int32_t iIndex = (iId8x8 << 2); |
| 1466 | 1541 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1467 | 1542 | //Luma (DC and AC decoding together) |
| 1468 | 1543 | if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, |
| 1469 | − iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC, | |
| 1544 | + iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan + iScanIdxStart, iMbResProperty, | |
| 1470 | 1545 | pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pLumaQp[iMbXy], pCtx)) { |
| 1471 | 1546 | return -1;//abnormal |
| 1472 | 1547 | } |
| @@ -1488,8 +1563,13 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 15 unmodified lines | ||
| 1488 | 1563 | //step1: DC |
| 1489 | 1564 | if (1 == uiCbpC || 2 == uiCbpC) { |
| 1490 | 1565 | 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 | + | |
| 1491 | 1571 | 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), | |
| 1493 | 1573 | pCurLayer->pChromaQp[iMbXy], pCtx)) { |
| 1494 | 1574 | return -1;//abnormal |
| 1495 | 1575 | } |
| @@ -1499,11 +1579,16 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 3 unmodified lines | ||
| 1499 | 1579 | //step2: AC |
| 1500 | 1580 | if (2 == uiCbpC) { |
| 1501 | 1581 | 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 | + | |
| 1502 | 1587 | int32_t iIndex = 16 + (i << 2); |
| 1503 | 1588 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1504 | 1589 | if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, |
| 1505 | 1590 | 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)) { | |
| 1507 | 1592 | return -1;//abnormal |
| 1508 | 1593 | } |
| 1509 | 1594 | iIndex++; |
| @@ -309,6 +309,8 @@ void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx) { · 308 unmodified lines | ||
| 309 | 309 | pCtx->eErrorConMethod = ERROR_CON_SLICE_COPY_CROSS_IDR_FREEZE_RES_CHANGE; |
| 310 | 310 | pCtx->pPreviousDecodedPictureInDpb = NULL; |
| 311 | 311 | pCtx->sDecoderStatistics.iAvgLumaQp = -1; |
| 312 | + pCtx->bSpsLatePps = false; | |
| 313 | + pCtx->bUseScalingList = false; | |
| 312 | 314 | |
| 313 | 315 | } |
| 314 | 316 | |
| @@ -821,11 +821,15 @@ int32_t ParseResidualBlockCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroC · 820 unmodified lines | ||
| 821 | 821 | const uint8_t* pScanTable, int32_t iResProperty, short* sTCoeff, /*int mb_mode*/ uint8_t uiQp, |
| 822 | 822 | PWelsDecoderContext pCtx) { |
| 823 | 823 | int32_t iCurNzCacheIdx; |
| 824 | − const uint16_t* pDeQuantMul = g_kuiDequantCoeff[uiQp]; | |
| 825 | 824 | uint32_t uiTotalCoeffNum = 0; |
| 826 | 825 | uint32_t uiCbpBit; |
| 827 | 826 | int32_t pSignificantMap[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 828 | 827 | |
| 828 | + int32_t iMbResProperty; | |
| 829 | + GetMbResProperty (&iMbResProperty, &iResProperty, false); | |
| 830 | + const uint16_t* pDeQuantMul = (pCtx->bUseScalingList) ? pCtx->pDequant_coeff4x4[iMbResProperty][uiQp] : | |
| 831 | + g_kuiDequantCoeff[uiQp]; | |
| 832 | + | |
| 829 | 833 | WELS_READ_VERIFY (ParseCbfInfoCabac (pNeighAvail, pNonZeroCountCache, iIndex, iResProperty, pCtx, uiCbpBit)); |
| 830 | 834 | if (uiCbpBit) { //has coeff |
| 831 | 835 | WELS_READ_VERIFY (ParseSignificantMapCabac (pSignificantMap, iResProperty, pCtx, uiTotalCoeffNum)); |
| @@ -847,13 +851,15 @@ int32_t ParseResidualBlockCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroC · 15 unmodified lines | ||
| 847 | 851 | } else if (iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) { |
| 848 | 852 | do { |
| 849 | 853 | if (pSignificantMap[j] != 0) |
| 850 | − sTCoeff[pScanTable[j]] = pSignificantMap[j] * pDeQuantMul[0]; | |
| 854 | + sTCoeff[pScanTable[j]] = pCtx->bUseScalingList ? (pSignificantMap[j] * pDeQuantMul[0]) >> 4 : | |
| 855 | + (pSignificantMap[j] * pDeQuantMul[0]); | |
| 851 | 856 | ++j; |
| 852 | 857 | } while (j < 16); |
| 853 | 858 | } else { //luma ac, chroma ac |
| 854 | 859 | do { |
| 855 | 860 | if (pSignificantMap[j] != 0) |
| 856 | − sTCoeff[pScanTable[j]] = pSignificantMap[j] * pDeQuantMul[pScanTable[j] & 0x07]; | |
| 861 | + sTCoeff[pScanTable[j]] = pCtx->bUseScalingList ? (pSignificantMap[j] * pDeQuantMul[pScanTable[j]] >> 4) : | |
| 862 | + pSignificantMap[j] * pDeQuantMul[pScanTable[j] & 0x07]; | |
| 857 | 863 | ++j; |
| 858 | 864 | } while (j < 16); |
| 859 | 865 | } |
| @@ -236,8 +236,8 @@ void WelsFillCacheConstrain0Intra4x4 (PWelsNeighAvail pNeighAvail, uint8_t* pNon · 235 unmodified lines | ||
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | −void WelsFillCacheInterCabac(PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount, int16_t iMvArray[LIST_A][30][MV_A], int16_t iMvdCache[LIST_A][30][MV_A], int8_t iRefIdxArray[LIST_A][30], PDqLayer pCurLayer) | |
| 240 | −{ | |
| 239 | +void WelsFillCacheInterCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount, int16_t iMvArray[LIST_A][30][MV_A], | |
| 240 | + int16_t iMvdCache[LIST_A][30][MV_A], int8_t iRefIdxArray[LIST_A][30], PDqLayer pCurLayer) { | |
| 241 | 241 | int32_t iCurXy = pCurLayer->iMbXyIndex; |
| 242 | 242 | int32_t iTopXy = 0; |
| 243 | 243 | int32_t iLeftXy = 0; |
| @@ -267,10 +267,10 @@ void WelsFillCacheInterCabac(PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount · 23 unmodified lines | ||
| 267 | 267 | ST32 (iMvArray[0][18], LD32 (pCurLayer->pMv[0][iLeftXy][11])); |
| 268 | 268 | ST32 (iMvArray[0][24], LD32 (pCurLayer->pMv[0][iLeftXy][15])); |
| 269 | 269 | |
| 270 | − ST32(iMvdCache[0][ 6], LD32(pCurLayer->pMvd[0][iLeftXy][ 3])); | |
| 271 | − ST32(iMvdCache[0][12], LD32(pCurLayer->pMvd[0][iLeftXy][ 7])); | |
| 272 | − ST32(iMvdCache[0][18], LD32(pCurLayer->pMvd[0][iLeftXy][11])); | |
| 273 | − ST32(iMvdCache[0][24], LD32(pCurLayer->pMvd[0][iLeftXy][15])); | |
| 270 | + ST32 (iMvdCache[0][ 6], LD32 (pCurLayer->pMvd[0][iLeftXy][ 3])); | |
| 271 | + ST32 (iMvdCache[0][12], LD32 (pCurLayer->pMvd[0][iLeftXy][ 7])); | |
| 272 | + ST32 (iMvdCache[0][18], LD32 (pCurLayer->pMvd[0][iLeftXy][11])); | |
| 273 | + ST32 (iMvdCache[0][24], LD32 (pCurLayer->pMvd[0][iLeftXy][15])); | |
| 274 | 274 | |
| 275 | 275 | iRefIdxArray[0][ 6] = pCurLayer->pRefIndex[0][iLeftXy][ 3]; |
| 276 | 276 | iRefIdxArray[0][12] = pCurLayer->pRefIndex[0][iLeftXy][ 7]; |
| @@ -282,31 +282,31 @@ void WelsFillCacheInterCabac(PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount · 5 unmodified lines | ||
| 282 | 282 | ST32 (iMvArray[0][18], 0); |
| 283 | 283 | ST32 (iMvArray[0][24], 0); |
| 284 | 284 | |
| 285 | − ST32(iMvdCache[0][ 6], 0); | |
| 286 | − ST32(iMvdCache[0][12], 0); | |
| 287 | − ST32(iMvdCache[0][18], 0); | |
| 288 | − ST32(iMvdCache[0][24], 0); | |
| 285 | + ST32 (iMvdCache[0][ 6], 0); | |
| 286 | + ST32 (iMvdCache[0][12], 0); | |
| 287 | + ST32 (iMvdCache[0][18], 0); | |
| 288 | + ST32 (iMvdCache[0][24], 0); | |
| 289 | 289 | |
| 290 | 290 | |
| 291 | 291 | if (0 == pNeighAvail->iLeftAvail) { //not available |
| 292 | 292 | iRefIdxArray[0][ 6] = |
| 293 | − iRefIdxArray[0][12] = | |
| 294 | − iRefIdxArray[0][18] = | |
| 295 | − iRefIdxArray[0][24] = REF_NOT_AVAIL; | |
| 293 | + iRefIdxArray[0][12] = | |
| 294 | + iRefIdxArray[0][18] = | |
| 295 | + iRefIdxArray[0][24] = REF_NOT_AVAIL; | |
| 296 | 296 | } else { //available but is intra mb type |
| 297 | 297 | iRefIdxArray[0][ 6] = |
| 298 | − iRefIdxArray[0][12] = | |
| 299 | − iRefIdxArray[0][18] = | |
| 300 | − iRefIdxArray[0][24] = REF_NOT_IN_LIST; | |
| 298 | + iRefIdxArray[0][12] = | |
| 299 | + iRefIdxArray[0][18] = | |
| 300 | + iRefIdxArray[0][24] = REF_NOT_IN_LIST; | |
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | if (pNeighAvail->iLeftTopAvail && IS_INTER (pNeighAvail->iLeftTopType)) { |
| 304 | 304 | ST32 (iMvArray[0][0], LD32 (pCurLayer->pMv[0][iLeftTopXy][15])); |
| 305 | − ST32(iMvdCache[0][0], LD32(pCurLayer->pMvd[0][iLeftTopXy][15])); | |
| 305 | + ST32 (iMvdCache[0][0], LD32 (pCurLayer->pMvd[0][iLeftTopXy][15])); | |
| 306 | 306 | iRefIdxArray[0][0] = pCurLayer->pRefIndex[0][iLeftTopXy][15]; |
| 307 | 307 | } else { |
| 308 | 308 | ST32 (iMvArray[0][0], 0); |
| 309 | − ST32(iMvdCache[0][0], 0); | |
| 309 | + ST32 (iMvdCache[0][0], 0); | |
| 310 | 310 | if (0 == pNeighAvail->iLeftTopAvail) { //not available |
| 311 | 311 | iRefIdxArray[0][0] = REF_NOT_AVAIL; |
| 312 | 312 | } else { //available but is intra mb type |
| @@ -317,30 +317,30 @@ void WelsFillCacheInterCabac(PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount · 4 unmodified lines | ||
| 317 | 317 | if (pNeighAvail->iTopAvail && IS_INTER (pNeighAvail->iTopType)) { |
| 318 | 318 | ST64 (iMvArray[0][1], LD64 (pCurLayer->pMv[0][iTopXy][12])); |
| 319 | 319 | ST64 (iMvArray[0][3], LD64 (pCurLayer->pMv[0][iTopXy][14])); |
| 320 | − ST64(iMvdCache[0][1], LD64(pCurLayer->pMvd[0][iTopXy][12])); | |
| 321 | − ST64(iMvdCache[0][3], LD64(pCurLayer->pMvd[0][iTopXy][14])); | |
| 320 | + ST64 (iMvdCache[0][1], LD64 (pCurLayer->pMvd[0][iTopXy][12])); | |
| 321 | + ST64 (iMvdCache[0][3], LD64 (pCurLayer->pMvd[0][iTopXy][14])); | |
| 322 | 322 | ST32 (&iRefIdxArray[0][1], LD32 (&pCurLayer->pRefIndex[0][iTopXy][12])); |
| 323 | 323 | } else { |
| 324 | 324 | ST64 (iMvArray[0][1], 0); |
| 325 | 325 | ST64 (iMvArray[0][3], 0); |
| 326 | − ST64(iMvdCache[0][1], 0); | |
| 327 | − ST64(iMvdCache[0][3], 0); | |
| 326 | + ST64 (iMvdCache[0][1], 0); | |
| 327 | + ST64 (iMvdCache[0][3], 0); | |
| 328 | 328 | if (0 == pNeighAvail->iTopAvail) { //not available |
| 329 | 329 | iRefIdxArray[0][1] = |
| 330 | − iRefIdxArray[0][2] = | |
| 331 | − iRefIdxArray[0][3] = | |
| 332 | − iRefIdxArray[0][4] = REF_NOT_AVAIL; | |
| 330 | + iRefIdxArray[0][2] = | |
| 331 | + iRefIdxArray[0][3] = | |
| 332 | + iRefIdxArray[0][4] = REF_NOT_AVAIL; | |
| 333 | 333 | } else { //available but is intra mb type |
| 334 | 334 | iRefIdxArray[0][1] = |
| 335 | − iRefIdxArray[0][2] = | |
| 336 | − iRefIdxArray[0][3] = | |
| 337 | − iRefIdxArray[0][4] = REF_NOT_IN_LIST; | |
| 335 | + iRefIdxArray[0][2] = | |
| 336 | + iRefIdxArray[0][3] = | |
| 337 | + iRefIdxArray[0][4] = REF_NOT_IN_LIST; | |
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | if (pNeighAvail->iRightTopAvail && IS_INTER (pNeighAvail->iRightTopType)) { |
| 342 | 342 | ST32 (iMvArray[0][5], LD32 (pCurLayer->pMv[0][iRightTopXy][12])); |
| 343 | − ST32(iMvdCache[0][5], LD32(pCurLayer->pMvd[0][iRightTopXy][12])); | |
| 343 | + ST32 (iMvdCache[0][5], LD32 (pCurLayer->pMvd[0][iRightTopXy][12])); | |
| 344 | 344 | iRefIdxArray[0][5] = pCurLayer->pRefIndex[0][iRightTopXy][12]; |
| 345 | 345 | } else { |
| 346 | 346 | ST32 (iMvArray[0][5], 0); |
| @@ -357,21 +357,20 @@ void WelsFillCacheInterCabac(PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount · 10 unmodified lines | ||
| 357 | 357 | ST32 (iMvArray[0][11], 0); |
| 358 | 358 | ST32 (iMvArray[0][17], 0); |
| 359 | 359 | ST32 (iMvArray[0][23], 0); |
| 360 | − ST32(iMvdCache[0][ 9], 0); | |
| 361 | − ST32(iMvdCache[0][21], 0); | |
| 362 | − ST32(iMvdCache[0][11], 0); | |
| 363 | − ST32(iMvdCache[0][17], 0); | |
| 364 | − ST32(iMvdCache[0][23], 0); | |
| 360 | + ST32 (iMvdCache[0][ 9], 0); | |
| 361 | + ST32 (iMvdCache[0][21], 0); | |
| 362 | + ST32 (iMvdCache[0][11], 0); | |
| 363 | + ST32 (iMvdCache[0][17], 0); | |
| 364 | + ST32 (iMvdCache[0][23], 0); | |
| 365 | 365 | iRefIdxArray[0][ 9] = |
| 366 | − iRefIdxArray[0][21] = | |
| 367 | − iRefIdxArray[0][11] = | |
| 368 | − iRefIdxArray[0][17] = | |
| 369 | − iRefIdxArray[0][23] = REF_NOT_AVAIL; | |
| 366 | + iRefIdxArray[0][21] = | |
| 367 | + iRefIdxArray[0][11] = | |
| 368 | + iRefIdxArray[0][17] = | |
| 369 | + iRefIdxArray[0][23] = REF_NOT_AVAIL; | |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | void WelsFillCacheInter (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount, |
| 373 | − int16_t iMvArray[LIST_A][30][MV_A], int8_t iRefIdxArray[LIST_A][30], PDqLayer pCurLayer) | |
| 374 | −{ | |
| 373 | + int16_t iMvArray[LIST_A][30][MV_A], int8_t iRefIdxArray[LIST_A][30], PDqLayer pCurLayer) { | |
| 375 | 374 | int32_t iCurXy = pCurLayer->iMbXyIndex; |
| 376 | 375 | int32_t iTopXy = 0; |
| 377 | 376 | int32_t iLeftXy = 0; |
| @@ -798,7 +797,13 @@ int32_t WelsResidualBlockCavlc (SVlcTable* pVlcTable, uint8_t* pNonZeroCountCach · 420 unmodified lines | ||
| 798 | 797 | int32_t iLevel[16], iZerosLeft, iCoeffNum; |
| 799 | 798 | int32_t iRun[16]; |
| 800 | 799 | int32_t iCurNonZeroCacheIdx, i; |
| 801 | − const uint16_t* kpDequantCoeff = g_kuiDequantCoeff[uiQp]; | |
| 800 | + | |
| 801 | + | |
| 802 | + int32_t iMbResProperty = 0; | |
| 803 | + GetMbResProperty (&iMbResProperty, &iResidualProperty, 1); | |
| 804 | + const uint16_t* kpDequantCoeff = pCtx->bUseScalingList ? pCtx->pDequant_coeff4x4[iMbResProperty][uiQp] : | |
| 805 | + g_kuiDequantCoeff[uiQp]; | |
| 806 | + | |
| 802 | 807 | int8_t nA, nB, nC; |
| 803 | 808 | uint8_t uiTotalCoeff, uiTrailingOnes; |
| 804 | 809 | int32_t iUsedBits = 0; |
| @@ -867,7 +872,7 @@ int32_t WelsResidualBlockCavlc (SVlcTable* pVlcTable, uint8_t* pNonZeroCountCach · 62 unmodified lines | ||
| 867 | 872 | int32_t j; |
| 868 | 873 | iCoeffNum += iRun[i] + 1; //FIXME add 1 earlier ? |
| 869 | 874 | j = kpZigzagTable[ iCoeffNum ]; |
| 870 | − pTCoeff[j] = iLevel[i] * kpDequantCoeff[0]; | |
| 875 | + pTCoeff[j] = pCtx->bUseScalingList ? (iLevel[i] * kpDequantCoeff[0]) >> 4 : (iLevel[i] * kpDequantCoeff[0]); | |
| 871 | 876 | } |
| 872 | 877 | } else if (iResidualProperty == I16_LUMA_DC) { //DC coefficent, only call in Intra_16x16, base_mode_flag = 0 |
| 873 | 878 | for (i = uiTotalCoeff - 1; i >= 0; --i) { //FIXME merge into rundecode? |
| @@ -881,7 +886,7 @@ int32_t WelsResidualBlockCavlc (SVlcTable* pVlcTable, uint8_t* pNonZeroCountCach · 7 unmodified lines | ||
| 881 | 886 | int32_t j; |
| 882 | 887 | iCoeffNum += iRun[i] + 1; //FIXME add 1 earlier ? |
| 883 | 888 | j = kpZigzagTable[ iCoeffNum ]; |
| 884 | − pTCoeff[j] = iLevel[i] * kpDequantCoeff[j & 0x07]; | |
| 889 | + pTCoeff[j] = pCtx->bUseScalingList ? (iLevel[i] * kpDequantCoeff[j]) >> 4 : (iLevel[i] * kpDequantCoeff[j & 0x07]); | |
| 885 | 890 | } |
| 886 | 891 | } |
| 887 | 892 | |