shithub: openh264

Download patch

ref: 9cb4f4e8e21afc99d0b29686529d0c6bf5b8e7fe
parent: 13586a3dfcfad347f78a9d0d2d07757b2ab5aac3
author: unknown <[email protected]>
date: Fri Feb 19 09:28:31 EST 2016

modify return value check inside decoder

--- a/codec/decoder/core/inc/error_code.h
+++ b/codec/decoder/core/inc/error_code.h
@@ -129,6 +129,7 @@
 ERR_INFO_INVALID_NUM_REF_FRAME_IN_PIC_ORDER_CNT_CYCLE,
 ERR_INFO_INVALID_DBLOCKING_IDC,
 ERR_INFO_INVALID_MB_TYPE,
+ERR_INFO_INVALID_MB_SKIP_RUN,
 ERR_INFO_INVALID_SPS_ID,
 ERR_INFO_INVALID_PPS_ID,
 ERR_INFO_INVALID_SUB_MB_TYPE,
@@ -199,6 +200,16 @@
 ERR_CABAC_UNEXPECTED_VALUE,
 //for scaling list
 ERR_SCALING_LIST_DELTA_SCALE,
+//logic error related to multi-layer
+ERR_INFO_WIDTH_MISMATCH,
+//reconstruction error
+ERR_INFO_MB_RECON_FAIL,
+ERR_INFO_MB_NUM_EXCEED_FAIL,
+ERR_INFO_BS_INCOMPLETE,
+ERR_INFO_MB_NUM_INADEQUATE,
+//parse only error
+ERR_INFO_PARSEONLY_PENDING,
+ERR_INFO_PARSEONLY_ERROR,
 };
 //-----------------------------------------------------------------------------------------------------------
 
--- a/codec/decoder/core/src/au_parser.cpp
+++ b/codec/decoder/core/src/au_parser.cpp
@@ -782,7 +782,7 @@
 
 
 
-  return 0;
+  return ERR_NONE;
 }
 
 const SLevelLimits* GetLevelLimits (int32_t iLevelIdx, bool bConstraint3) {
@@ -915,6 +915,7 @@
   int32_t iSpsId;
   uint32_t uiCode;
   int32_t iCode;
+  int32_t iRet = ERR_NONE;
   bool bConstraintSetFlags[6] = { false };
   const bool kbUseSubsetFlag   = IS_SUBSET_SPS_NAL (pNalHead->eNalUnitType);
 
@@ -1207,8 +1208,8 @@
   }
   // Check if SPS SVC extension applicated
   if (kbUseSubsetFlag && (PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc)) {
-    if (DecodeSpsSvcExt (pCtx, pSubsetSps, pBs) != ERR_NONE) {
-      return -1;
+    if ((iRet = DecodeSpsSvcExt (pCtx, pSubsetSps, pBs)) != ERR_NONE) {
+      return iRet;
     }
 
     WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //svc_vui_parameters_present_flag
@@ -1271,7 +1272,7 @@
     pCtx->bSpsAvailFlags[iSpsId] = true;
     pCtx->bSpsExistAheadFlag = true;
   }
-  return 0;
+  return ERR_NONE;
 }
 
 /*!
@@ -1301,7 +1302,7 @@
   WELS_READ_VERIFY (BsGetUe (pBsAux, &uiCode)); //pic_parameter_set_id
   uiPpsId = uiCode;
   if (uiPpsId >= MAX_PPS_COUNT) {
-    return ERR_INFO_PPS_ID_OVERFLOW;
+    return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_PPS_ID_OVERFLOW);
   }
   pPps = &sTempPps;
   memset (pPps, 0, sizeof (SPps));
@@ -1311,7 +1312,7 @@
   pPps->iSpsId = uiCode;
 
   if (pPps->iSpsId >= MAX_SPS_COUNT) {
-    return ERR_INFO_SPS_ID_OVERFLOW;
+    return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_SPS_ID_OVERFLOW);
   }
 
   WELS_READ_VERIFY (BsGetOneBit (pBsAux, &uiCode)); //entropy_coding_mode_flag
@@ -1323,7 +1324,7 @@
   pPps->uiNumSliceGroups = NUM_SLICE_GROUPS_OFFSET + uiCode;
 
   if (pPps->uiNumSliceGroups > MAX_SLICEGROUP_IDS) {
-    return ERR_INFO_INVALID_SLICEGROUP;
+    return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_SLICEGROUP);
   }
 
   if (pPps->uiNumSliceGroups > 1) {
@@ -1354,7 +1355,7 @@
 
   if (pPps->uiNumRefIdxL0Active > MAX_REF_PIC_COUNT ||
       pPps->uiNumRefIdxL1Active > MAX_REF_PIC_COUNT) {
-    return ERR_INFO_REF_COUNT_OVERFLOW;
+    return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_REF_COUNT_OVERFLOW);
   }
 
   WELS_READ_VERIFY (BsGetOneBit (pBsAux, &uiCode)); //weighted_pred_flag
--- a/codec/decoder/core/src/cabac_decoder.cpp
+++ b/codec/decoder/core/src/cabac_decoder.cpp
@@ -107,7 +107,7 @@
   iNumBitsRead = 0;
   uiValue = 0;
   if (iLeftBytes <= 0) {
-    return ERR_CABAC_NO_BS_TO_READ;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_CABAC_NO_BS_TO_READ);
   }
   switch (iLeftBytes) {
   case 3:
@@ -275,7 +275,7 @@
     }
   } while (uiCode != 0 && iCount != 16);
   if (iCount == 16) {
-    return ERR_CABAC_UNEXPECTED_VALUE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_CABAC_UNEXPECTED_VALUE);
   }
 
   while (iCount--) {
--- a/codec/decoder/core/src/decode_slice.cpp
+++ b/codec/decoder/core/src/decode_slice.cpp
@@ -70,7 +70,7 @@
   PDeblockingFilterMbFunc pDeblockMb;
 
   if (!pCtx->bAvcBasedFlag && iCurLayerWidth != pCtx->iCurSeqIntervalMaxPicWidth) {
-    return -1;
+    return ERR_INFO_WIDTH_MISMATCH;
   }
 
   iNextMbXyIndex   = pSliceHeader->iFirstMbInSlice;
@@ -96,7 +96,7 @@
                  "WelsTargetSliceConstruction():::MB(%d, %d) construction error. pCurSlice_type:%d",
                  pCurLayer->iMbX, pCurLayer->iMbY, pCurSlice->eSliceType);
 
-        return -1;
+        return ERR_INFO_MB_RECON_FAIL;
       }
     }
 
@@ -112,7 +112,7 @@
                "WelsTargetSliceConstruction():::pCtx->iTotalNumMbRec:%d, iTotalMbTargetLayer:%d",
                pCtx->iTotalNumMbRec, iTotalMbTargetLayer);
 
-      return -1;
+      return ERR_INFO_MB_NUM_EXCEED_FAIL;
     }
 
     if (pSliceHeader->pPps->uiNumSliceGroups > 1) {
@@ -132,22 +132,22 @@
   pCtx->pDec->iHeightInPixel = iCurLayerHeight;
 
   if ((pCurSlice->eSliceType != I_SLICE) && (pCurSlice->eSliceType != P_SLICE))
-    return 0;
+    return ERR_NONE; //no error but just ignore the type unsupported
 
   if (pCtx->pParam->bParseOnly) //for parse only, deblocking should not go on
-    return 0;
+    return ERR_NONE;
 
   pDeblockMb = WelsDeblockingMb;
 
   if (1 == pSliceHeader->uiDisableDeblockingFilterIdc
       || pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.iTotalMbInCurSlice <= 0) {
-    return 0;//NO_SUPPORTED_FILTER_IDX
+    return ERR_NONE;//NO_SUPPORTED_FILTER_IDX
   } else {
     WelsDeblockingFilterSlice (pCtx, pDeblockMb);
   }
   // any other filter_idc not supported here, 7/22/2010
 
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t WelsMbInterSampleConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer,
@@ -191,7 +191,7 @@
     }
   }
 
-  return 0;
+  return ERR_NONE;
 }
 int32_t WelsMbInterConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) {
   int32_t iMbX = pCurLayer->iMbX;
@@ -210,7 +210,7 @@
 
   pCtx->sBlockFunc.pWelsSetNonZeroCountFunc (
     pCurLayer->pNzc[pCurLayer->iMbXyIndex]); // set all none-zero nzc to 1; dbk can be opti!
-  return 0;
+  return ERR_NONE;
 }
 
 void WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp, PWelsDecoderContext pCtx) {
@@ -265,7 +265,7 @@
     WelsLumaDcDequantIdct (pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx);
     RecI16x16Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer);
 
-    return 0;
+    return ERR_NONE;
   }
 
   if (IS_INTRA8x8 (pCurLayer->pMbType[iMbXy])) {
@@ -275,7 +275,7 @@
   if (IS_INTRA4x4 (pCurLayer->pMbType[iMbXy]))
     RecI4x4Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer);
 
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t WelsMbInterPrediction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) {
@@ -292,7 +292,7 @@
 
   GetInterPred (pDstY, pDstCb, pDstCr, pCtx);
 
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t WelsTargetMbConstruction (PWelsDecoderContext pCtx) {
@@ -299,7 +299,7 @@
   PDqLayer pCurLayer = pCtx->pCurDqLayer;
   if (MB_TYPE_INTRA_PCM == pCurLayer->pMbType[pCurLayer->iMbXyIndex]) {
     //already decoded and reconstructed when parsing
-    return 0;
+    return ERR_NONE;
   } else if (IS_INTRA (pCurLayer->pMbType[pCurLayer->iMbXyIndex])) {
     WelsMbIntraPredictionConstruction (pCtx, pCurLayer, 1);
   } else if (IS_INTER (pCurLayer->pMbType[pCurLayer->iMbXyIndex])) { //InterMB
@@ -311,10 +311,10 @@
   } else {
     WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsTargetMbConstruction():::::Unknown MB type: %d",
              pCurLayer->pMbType[pCurLayer->iMbXyIndex]);
-    return -1;
+    return ERR_INFO_MB_RECON_FAIL;
   }
 
-  return 0;
+  return ERR_NONE;
 }
 
 void WelsChromaDcIdct (int16_t* pBlock) {
@@ -445,7 +445,7 @@
 
     iFinalMode = CheckIntraNxNPredMode (&iSampleAvail[0], &iBestMode, i, false);
     if (iFinalMode  == ERR_INVALID_INTRA4X4_MODE) {
-      return ERR_INFO_INVALID_I4x4_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I4x4_PRED_MODE);
     }
 
     pCurDqLayer->pIntra4x4FinalMode[iMbXy][g_kuiScan4[i]] = iFinalMode;
@@ -465,13 +465,13 @@
   if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) {
     WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode));
     if (iCode > MAX_PRED_MODE_ID_CHROMA) {
-      return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
     }
     pCurDqLayer->pChromaPredMode[iMbXy] = iCode;
   } else {
     WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //intra_chroma_pred_mode
     if (uiCode > MAX_PRED_MODE_ID_CHROMA) {
-      return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
     }
     pCurDqLayer->pChromaPredMode[iMbXy] = uiCode;
   }
@@ -478,7 +478,7 @@
 
   if (-1 == pCurDqLayer->pChromaPredMode[iMbXy]
       || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) {
-    return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
   }
   return ERR_NONE;
 }
@@ -529,7 +529,7 @@
     iFinalMode = CheckIntraNxNPredMode (&iSampleAvail[0], &iBestMode, i << 2, true);
 
     if (iFinalMode  == ERR_INVALID_INTRA4X4_MODE) {
-      return ERR_INFO_INVALID_I4x4_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I4x4_PRED_MODE);
     }
 
     for (int j = 0; j < 4; j++) {
@@ -545,13 +545,13 @@
   if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) {
     WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode));
     if (iCode > MAX_PRED_MODE_ID_CHROMA) {
-      return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
     }
     pCurDqLayer->pChromaPredMode[iMbXy] = iCode;
   } else {
     WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //intra_chroma_pred_mode
     if (uiCode > MAX_PRED_MODE_ID_CHROMA) {
-      return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
     }
     pCurDqLayer->pChromaPredMode[iMbXy] = uiCode;
   }
@@ -558,7 +558,7 @@
 
   if (-1 == pCurDqLayer->pChromaPredMode[iMbXy]
       || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) {
-    return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
   }
 
   return ERR_NONE;
@@ -574,7 +574,7 @@
 
   if (CheckIntra16x16PredMode (uiNeighAvail,
                                &pCurDqLayer->pIntraPredMode[iMbXy][7])) { //invalid iPredMode, must stop decoding
-    return ERR_INFO_INVALID_I16x16_PRED_MODE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I16x16_PRED_MODE);
   }
   if (pCtx->pSps->uiChromaFormatIdc == 0)
     return ERR_NONE;
@@ -582,19 +582,19 @@
   if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) {
     WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode));
     if (iCode > MAX_PRED_MODE_ID_CHROMA) {
-      return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
     }
     pCurDqLayer->pChromaPredMode[iMbXy] = iCode;
   } else {
     WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //intra_chroma_pred_mode
     if (uiCode > MAX_PRED_MODE_ID_CHROMA) {
-      return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
     }
     pCurDqLayer->pChromaPredMode[iMbXy] = uiCode;
   }
   if (-1 == pCurDqLayer->pChromaPredMode[iMbXy]
       || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) {
-    return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
   }
 
   return ERR_NONE;
@@ -622,10 +622,10 @@
   GetNeighborAvailMbType (&sNeighAvail, pCurLayer);
   WELS_READ_VERIFY (ParseMBTypeISliceCabac (pCtx, &sNeighAvail, uiMbType));
   if (uiMbType > 25) {
-    return ERR_INFO_INVALID_MB_TYPE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
   } else if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17
              && uiMbType <= 24))) {
-    return ERR_INFO_INVALID_MB_TYPE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
   } else if (25 == uiMbType) {   //I_PCM
     WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx));
     pSlice->iLastDeltaQp = 0;
@@ -688,7 +688,7 @@
     int32_t iQpDelta, iId8x8, iId4x4;
     WELS_READ_VERIFY (ParseDeltaQpCabac (pCtx, iQpDelta));
     if (iQpDelta > 25 || iQpDelta < -26) {//out of iQpDelta range
-      return ERR_INFO_INVALID_QP;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP);
     }
     pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp
     pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy];
@@ -841,9 +841,9 @@
   } else { //Intra mode
     uiMbType -= 5;
     if (uiMbType > 25)
-      return ERR_INFO_INVALID_MB_TYPE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
     if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24)))
-      return ERR_INFO_INVALID_MB_TYPE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
 
     if (25 == uiMbType) {   //I_PCM
       WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx));
@@ -922,7 +922,7 @@
 
     WELS_READ_VERIFY (ParseDeltaQpCabac (pCtx, iQpDelta));
     if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range
-      return ERR_INFO_INVALID_QP;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP);
     }
     pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp
     pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy];
@@ -1276,6 +1276,7 @@
   const int32_t iMbXy = pCurLayer->iMbXyIndex;
   int8_t* pNzc = pCurLayer->pNzc[iMbXy];
   int32_t i;
+  int32_t iRet = ERR_NONE;
   uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;
   uint32_t uiCode;
   int32_t iCode;
@@ -1291,9 +1292,9 @@
   WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //uiMbType
   uiMbType = uiCode;
   if (uiMbType > 25)
-    return ERR_INFO_INVALID_MB_TYPE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
   if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24)))
-    return ERR_INFO_INVALID_MB_TYPE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
 
   if (25 == uiMbType) {
     int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
@@ -1345,7 +1346,7 @@
     memset (pCurLayer->pChromaQp[iMbXy], 0, sizeof (pCurLayer->pChromaQp[iMbXy]));
     memset (pNzc, 16, sizeof (pCurLayer->pNzc[iMbXy]));   //Rec. 9.2.1 for PCM, nzc=16
     WELS_READ_VERIFY (InitReadBits (pBs, 0));
-    return 0;
+    return ERR_NONE;
   } else if (0 == uiMbType) { //reference to JM
     ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16);
     pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4;
@@ -1369,9 +1370,9 @@
     uiCbp = uiCode;
     //G.9.1 Alternative parsing process for coded pBlock pattern
     if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47))
-      return ERR_INFO_INVALID_CBP;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP);
     if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15))
-      return ERR_INFO_INVALID_CBP;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP);
 
     if (pCtx->pSps->uiChromaFormatIdc)
       uiCbp = g_kuiIntra4x4CbpTable[uiCbp];
@@ -1416,7 +1417,7 @@
     iQpDelta = iCode;
 
     if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range
-      return ERR_INFO_INVALID_QP;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP);
     }
 
     pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp
@@ -1432,17 +1433,17 @@
 
     if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {
       //step1: Luma DC
-      if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16,
-                                  g_kuiLumaDcZigzagScan, I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)) {
-        return -1;//abnormal
+      if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan, I16_LUMA_DC,
+                                          pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) {
+        return iRet;//abnormal
       }
       //step2: Luma AC
       if (uiCbpL) {
         for (i = 0; i < 16; i++) {
-          if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i,
-                                      iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
-                                      I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), pCurLayer->pLumaQp[iMbXy], pCtx)) {
-            return -1;//abnormal
+          if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1,
+                                              g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4),
+                                              pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) {
+            return iRet;//abnormal
           }
         }
         ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1]));
@@ -1457,10 +1458,10 @@
           if (uiCbpL & (1 << iId8x8)) {
             int32_t iIndex = (iId8x8 << 2);
             for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
-              if (WelsResidualBlockCavlc8x8 (pVlcTable, pNonZeroCount, pBs, iIndex,
-                                             iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan8x8 + iScanIdxStart, iMbResProperty,
-                                             pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), iId4x4, pCurLayer->pLumaQp[iMbXy], pCtx)) {
-                return -1;
+              if ((iRet = WelsResidualBlockCavlc8x8 (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1,
+                                                     g_kuiZigzagScan8x8 + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), iId4x4,
+                                                     pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) {
+                return iRet;
               }
               iIndex++;
             }
@@ -1479,10 +1480,10 @@
             int32_t iIndex = (iId8x8 << 2);
             for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
               //Luma (DC and AC decoding together)
-              if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
-                                          iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan + iScanIdxStart,
-                                          LUMA_DC_AC_INTRA, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pLumaQp[iMbXy], pCtx)) {
-                return -1;//abnormal
+              if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1,
+                                                  g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC_INTRA, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4),
+                                                  pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) {
+                return iRet;//abnormal
               }
               iIndex++;
             }
@@ -1503,10 +1504,9 @@
     if (1 == uiCbpC || 2 == uiCbpC) {
       for (i = 0; i < 2; i++) { //Cb Cr
         iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U;
-        if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs,
-                                    16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6),
-                                    pCurLayer->pChromaQp[iMbXy][i], pCtx)) {
-          return -1;//abnormal
+        if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty,
+                                            pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) {
+          return iRet;//abnormal
         }
       }
     }
@@ -1517,10 +1517,10 @@
         iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U;
         int32_t iIndex = 16 + (i << 2);
         for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
-          if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
-                                      iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
-                                      iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pChromaQp[iMbXy][i], pCtx)) {
-            return -1;//abnormal
+          if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - WELS_MAX (iScanIdxStart,
+                                              1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4),
+                                              pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) {
+            return iRet;//abnormal
           }
           iIndex++;
         }
@@ -1533,7 +1533,7 @@
     BsEndCavlc (pBs);
   }
 
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t WelsDecodeMbCavlcISlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) {
@@ -1572,9 +1572,9 @@
     WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING,
              "WelsDecodeMbCavlcISlice()::::pBs incomplete, iUsedBits:%" PRId64 " > pBs->iBits:%d, MUST stop decoding.",
              (int64_t) iUsedBits, pBs->iBits);
-    return -1;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_BS_INCOMPLETE);
   }
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) {
@@ -1593,6 +1593,7 @@
   const int32_t iMbXy = pCurLayer->iMbXyIndex;
   int8_t* pNzc = pCurLayer->pNzc[iMbXy];
   int32_t i;
+  int32_t iRet = ERR_NONE;
   uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;
   uint32_t uiCode;
   int32_t iCode;
@@ -1609,8 +1610,8 @@
     pCurLayer->pMbType[iMbXy] = g_ksInterMbTypeInfo[uiMbType].iType;
     WelsFillCacheInter (&sNeighAvail, pNonZeroCount, iMotionVector, iRefIndex, pCurLayer);
 
-    if (ParseInterInfo (pCtx, iMotionVector, iRefIndex, pBs)) {
-      return -1;//abnormal
+    if ((iRet = ParseInterInfo (pCtx, iMotionVector, iRefIndex, pBs)) != ERR_NONE) {
+      return iRet;//abnormal
     }
 
     if (pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag == 1) {
@@ -1624,14 +1625,14 @@
       pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;
     } else {
       WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "residual_pred_flag = 1 not supported.");
-      return -1;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_UNSUPPORTED_ILP);
     }
   } else { //intra MB type
     uiMbType -= 5;
     if (uiMbType > 25)
-      return ERR_INFO_INVALID_MB_TYPE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
     if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24)))
-      return ERR_INFO_INVALID_MB_TYPE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
 
     if (25 == uiMbType) {
       int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
@@ -1689,7 +1690,7 @@
       ST32A4 (&pNzc[16], 0x10101010);
       ST32A4 (&pNzc[20], 0x10101010);
       WELS_READ_VERIFY (InitReadBits (pBs, 0));
-      return 0;
+      return ERR_NONE;
     } else {
       if (0 == uiMbType) {
         ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16);
@@ -1717,8 +1718,8 @@
         uiCbpC = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0;
         uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
         WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer);
-        if (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer)) {
-          return -1;
+        if ((iRet = ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer)) != ERR_NONE) {
+          return iRet;
         }
       }
     }
@@ -1729,9 +1730,9 @@
     uiCbp = uiCode;
     {
       if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47))
-        return ERR_INFO_INVALID_CBP;
+        return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP);
       if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15))
-        return ERR_INFO_INVALID_CBP;
+        return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP);
       if (MB_TYPE_INTRA4x4 == pCurLayer->pMbType[iMbXy] || MB_TYPE_INTRA8x8 == pCurLayer->pMbType[iMbXy]) {
 
         uiCbp = pCtx->pSps->uiChromaFormatIdc ? g_kuiIntra4x4CbpTable[uiCbp] : g_kuiIntra4x4CbpTable400[uiCbp];
@@ -1779,7 +1780,7 @@
     iQpDelta = iCode;
 
     if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range
-      return ERR_INFO_INVALID_QP;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP);
     }
 
     pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp
@@ -1794,17 +1795,17 @@
 
     if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {
       //step1: Luma DC
-      if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan,
-                                  I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)) {
-        return -1;//abnormal
+      if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan, I16_LUMA_DC,
+                                          pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) {
+        return iRet;//abnormal
       }
       //step2: Luma AC
       if (uiCbpL) {
         for (i = 0; i < 16; i++) {
-          if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i,
-                                      iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
-                                      I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), pCurLayer->pLumaQp[iMbXy], pCtx)) {
-            return -1;//abnormal
+          if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1,
+                                              g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4),
+                                              pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) {
+            return iRet;//abnormal
           }
         }
         ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1]));
@@ -1819,10 +1820,10 @@
           if (uiCbpL & (1 << iId8x8)) {
             int32_t iIndex = (iId8x8 << 2);
             for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
-              if (WelsResidualBlockCavlc8x8 (pVlcTable, pNonZeroCount, pBs, iIndex,
-                                             iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan8x8 + iScanIdxStart, iMbResProperty,
-                                             pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), iId4x4, pCurLayer->pLumaQp[iMbXy], pCtx)) {
-                return -1;
+              if ((iRet = WelsResidualBlockCavlc8x8 (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1,
+                                                     g_kuiZigzagScan8x8 + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), iId4x4,
+                                                     pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) {
+                return iRet;
               }
               iIndex++;
             }
@@ -1842,10 +1843,10 @@
             int32_t iIndex = (iId8x8 << 2);
             for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
               //Luma (DC and AC decoding together)
-              if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
-                                          iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan + iScanIdxStart, iMbResProperty,
-                                          pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pLumaQp[iMbXy], pCtx)) {
-                return -1;//abnormal
+              if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1,
+                                                  g_kuiZigzagScan + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4),
+                                                  pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) {
+                return iRet;//abnormal
               }
               iIndex++;
             }
@@ -1871,10 +1872,9 @@
         else
           iMbResProperty = i ? CHROMA_DC_V_INTER : CHROMA_DC_U_INTER;
 
-        if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs,
-                                    16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6),
-                                    pCurLayer->pChromaQp[iMbXy][i], pCtx)) {
-          return -1;//abnormal
+        if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty,
+                                            pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) {
+          return iRet;//abnormal
         }
       }
     } else {
@@ -1889,10 +1889,10 @@
 
         int32_t iIndex = 16 + (i << 2);
         for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
-          if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
-                                      iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
-                                      iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), pCurLayer->pChromaQp[iMbXy][i], pCtx)) {
-            return -1;//abnormal
+          if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - WELS_MAX (iScanIdxStart,
+                                              1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4),
+                                              pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) {
+            return iRet;//abnormal
           }
           iIndex++;
         }
@@ -1905,7 +1905,7 @@
     BsEndCavlc (pBs);
   }
 
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t WelsDecodeMbCavlcPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) {
@@ -1928,7 +1928,7 @@
     WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //mb_skip_run
     pSlice->iMbSkipRun = uiCode;
     if (-1 == pSlice->iMbSkipRun) {
-      return -1;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_SKIP_RUN);
     }
   }
   if (pSlice->iMbSkipRun--) {
@@ -1995,9 +1995,9 @@
     WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING,
              "WelsDecodeMbCavlcISlice()::::pBs incomplete, iUsedBits:%" PRId64 " > pBs->iBits:%d, MUST stop decoding.",
              (int64_t) iUsedBits, pBs->iBits);
-    return -1;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_BS_INCOMPLETE);
   }
-  return 0;
+  return ERR_NONE;
 }
 
 void WelsBlockFuncInit (SBlockFunc*   pFunc,  int32_t iCpu) {
--- a/codec/decoder/core/src/decoder.cpp
+++ b/codec/decoder/core/src/decoder.cpp
@@ -64,7 +64,7 @@
   PPicBuff pPicBuf = NULL;
   int32_t iPicIdx = 0;
   if (kiSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) {
-    return 1;
+    return ERR_INFO_INVALID_PARAM;
   }
 
   CMemoryAlign* pMa = pCtx->pMemAlign;
@@ -72,7 +72,7 @@
   pPicBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff");
 
   if (NULL == pPicBuf) {
-    return 1;
+    return ERR_INFO_OUT_OF_MEMORY;
   }
 
   pPicBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiSize * sizeof (PPicture), "PPicture*");
@@ -80,7 +80,7 @@
   if (NULL == pPicBuf->ppPic) {
     pPicBuf->iCapacity = 0;
     DestroyPicBuff (&pPicBuf, pMa);
-    return 1;
+    return ERR_INFO_OUT_OF_MEMORY;
   }
 
   for (iPicIdx = 0; iPicIdx < kiSize; ++ iPicIdx) {
@@ -89,7 +89,7 @@
       // init capacity first for free memory
       pPicBuf->iCapacity = iPicIdx;
       DestroyPicBuff (&pPicBuf, pMa);
-      return 1;
+      return ERR_INFO_OUT_OF_MEMORY;
     }
     pPicBuf->ppPic[iPicIdx] = pPic;
   }
@@ -99,7 +99,7 @@
   pPicBuf->iCurrentIdx = 0;
   * ppPicBuf           = pPicBuf;
 
-  return 0;
+  return ERR_NONE;
 }
 
 static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiOldSize,
@@ -108,7 +108,7 @@
   PPicBuff pPicNewBuf = NULL;
   int32_t iPicIdx = 0;
   if (kiOldSize <= 0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) {
-    return 1;
+    return ERR_INFO_INVALID_PARAM;
   }
 
   CMemoryAlign* pMa = pCtx->pMemAlign;
@@ -115,7 +115,7 @@
   pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff");
 
   if (NULL == pPicNewBuf) {
-    return 1;
+    return ERR_INFO_OUT_OF_MEMORY;
   }
 
   pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");
@@ -123,7 +123,7 @@
   if (NULL == pPicNewBuf->ppPic) {
     pPicNewBuf->iCapacity = 0;
     DestroyPicBuff (&pPicNewBuf, pMa);
-    return 1;
+    return ERR_INFO_OUT_OF_MEMORY;
   }
 
   // increase new PicBuf
@@ -133,7 +133,7 @@
       // Set maximum capacity as the new malloc memory at the tail
       pPicNewBuf->iCapacity = iPicIdx;
       DestroyPicBuff (&pPicNewBuf, pMa);
-      return 1;
+      return ERR_INFO_OUT_OF_MEMORY;
     }
     pPicNewBuf->ppPic[iPicIdx] = pPic;
   }
@@ -162,7 +162,7 @@
   pPicOldBuf->iCurrentIdx = 0;
   pMa->WelsFree (pPicOldBuf, "pPicOldBuf");
   pPicOldBuf = NULL;
-  return 0;
+  return ERR_NONE;
 }
 
 static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiOldSize,
@@ -171,7 +171,7 @@
   PPicBuff pPicNewBuf = NULL;
   int32_t iPicIdx = 0;
   if (kiOldSize <= 0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) {
-    return 1;
+    return ERR_INFO_INVALID_PARAM;
   }
 
   CMemoryAlign* pMa = pCtx->pMemAlign;
@@ -179,7 +179,7 @@
   pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff");
 
   if (NULL == pPicNewBuf) {
-    return 1;
+    return ERR_INFO_OUT_OF_MEMORY;
   }
 
   pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");
@@ -187,7 +187,7 @@
   if (NULL == pPicNewBuf->ppPic) {
     pPicNewBuf->iCapacity = 0;
     DestroyPicBuff (&pPicNewBuf, pMa);
-    return 1;
+    return ERR_INFO_OUT_OF_MEMORY;
   }
 
   int32_t iPrevPicIdx = -1;
@@ -239,7 +239,7 @@
   pMa->WelsFree (pPicOldBuf, "pPicOldBuf");
   pPicOldBuf = NULL;
 
-  return 0;
+  return ERR_NONE;
 }
 
 void DestroyPicBuff (PPicBuff* ppPicBuf, CMemoryAlign* pMa) {
@@ -523,7 +523,7 @@
  */
 int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpParam) {
   if (NULL == pCtx || NULL == kpParam)
-    return 1;
+    return ERR_INFO_INVALID_PARAM;
 
   memcpy (pCtx->pParam, kpParam, sizeof (SDecodingParam));
   if ((pCtx->pParam->eEcActiveIdc > ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE)
@@ -549,7 +549,7 @@
 
   WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "eVideoType: %d", pCtx->eVideoType);
 
-  return 0;
+  return ERR_NONE;
 }
 
 /*!
--- a/codec/decoder/core/src/decoder_core.cpp
+++ b/codec/decoder/core/src/decoder_core.cpp
@@ -133,7 +133,7 @@
         pCtx->pDec->bIsComplete = false;
         pCtx->bFrameFinish = false; //current frame not finished
         pCtx->iErrorCode |= dsFramePending;
-        return -1;
+        return ERR_INFO_PARSEONLY_PENDING;
         //pCtx->pParserBsInfo->iNalNum = 0;
       }
     } else { //error
@@ -141,9 +141,9 @@
       pCtx->pParserBsInfo->iNalNum = 0;
       pCtx->pParserBsInfo->iSpsWidthInPixel = 0;
       pCtx->pParserBsInfo->iSpsHeightInPixel = 0;
-      return -1;
+      return ERR_INFO_PARSEONLY_ERROR;
     }
-    return 0;
+    return ERR_NONE;
   }
 
   if (pCtx->iTotalNumMbRec != kiTotalNumMbInCurLayer) {
@@ -152,7 +152,7 @@
              pCtx->iTotalNumMbRec, kiTotalNumMbInCurLayer, pCurDq->iMbWidth, pCurDq->iMbHeight);
     bFrameCompleteFlag = false; //return later after output buffer is done
     if (pCtx->bInstantDecFlag) //no-delay decoding, wait for new slice
-      return -1;
+      return ERR_INFO_MB_NUM_INADEQUATE;
   } else if (pCurDq->sLayerInfo.sNalHeaderExt.bIdrFlag
              && (pCtx->iErrorCode == dsErrorFree)) { //complete non-ECed IDR frame done
     pCtx->pDec->bIsComplete = true;
@@ -193,7 +193,7 @@
   if (pDstInfo->iBufferStatus == 0) {
     if (!bFrameCompleteFlag)
       pCtx->iErrorCode |= dsBitstreamError;
-    return -1;
+    return ERR_INFO_MB_NUM_INADEQUATE;
   }
   if (pCtx->bFreezeOutput) {
     pDstInfo->iBufferStatus = 0;
@@ -206,7 +206,7 @@
   pCtx->iMbEcedPropNum = pPic->iMbEcedPropNum;
   UpdateDecStat (pCtx, pDstInfo->iBufferStatus != 0);
 
-  return 0;
+  return ERR_NONE;
 }
 
 inline bool    CheckSliceNeedReconstruct (uint8_t uiLayerDqId, uint8_t uiTargetDqId) {
@@ -971,7 +971,7 @@
     if (pSliceHead->uiDisableDeblockingFilterIdc > 6) {
       WelsLog (pLogCtx, WELS_LOG_WARNING, "disable_deblock_filter_idc (%d) out of range [0, 6]",
                pSliceHead->uiDisableDeblockingFilterIdc);
-      return ERR_INFO_INVALID_DBLOCKING_IDC;
+      return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_DBLOCKING_IDC);
     }
     if (pSliceHead->uiDisableDeblockingFilterIdc != 1) {
       WELS_READ_VERIFY (BsGetSe (pBs, &iCode)); //slice_alpha_c0_offset_div2
@@ -1018,7 +1018,7 @@
         if (pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc > 6) {
           WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "disable_inter_layer_deblock_filter_idc (%d) out of range [0, 6]",
                    pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc);
-          return ERR_INFO_INVALID_DBLOCKING_IDC;
+          return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_DBLOCKING_IDC);
         }
         if (pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc != 1) {
           WELS_READ_VERIFY (BsGetSe (pBs, &iCode)); //inter_layer_slice_alpha_c0_offset_div2
@@ -1298,7 +1298,6 @@
                              "pCtx->sMb.pSliceIdc[]"); // using int32_t for slice_idc, 4/21/2010
     pCtx->sMb.pResidualPredFlag[i] = (int8_t*) pMa->WelsMallocz (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t),
                                      "pCtx->sMb.pResidualPredFlag[]");
-    //pCtx->sMb.pMotionPredFlag[i] = (uint8_t *) pMa->WelsMallocz(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(uint8_t), "pCtx->sMb.pMotionPredFlag[]");
     pCtx->sMb.pInterPredictionDoneFlag[i] = (int8_t*) pMa->WelsMallocz (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (
         int8_t), "pCtx->sMb.pInterPredictionDoneFlag[]");
 
@@ -1314,6 +1313,8 @@
                             (NULL == pCtx->sMb.pMv[i][0]) ||
                             (NULL == pCtx->sMb.pRefIndex[i][0]) ||
                             (NULL == pCtx->sMb.pLumaQp[i]) ||
+                            (NULL == pCtx->sMb.pNoSubMbPartSizeLessThan8x8Flag[i]) ||
+                            (NULL == pCtx->sMb.pTransformSize8x8Flag[i]) ||
                             (NULL == pCtx->sMb.pChromaQp[i]) ||
                             (NULL == pCtx->sMb.pMvd[i][0]) ||
                             (NULL == pCtx->sMb.pCbfDc[i]) ||
@@ -1322,6 +1323,7 @@
                             (NULL == pCtx->sMb.pScaledTCoeff[i]) ||
                             (NULL == pCtx->sMb.pIntraPredMode[i]) ||
                             (NULL == pCtx->sMb.pIntra4x4FinalMode[i]) ||
+                            (NULL == pCtx->sMb.pIntraNxNAvailFlag[i]) ||
                             (NULL == pCtx->sMb.pChromaPredMode[i]) ||
                             (NULL == pCtx->sMb.pCbp[i]) ||
                             (NULL == pCtx->sMb.pSubMbType[i]) ||
@@ -2007,7 +2009,7 @@
     return iErr;
   }
 
-  return 0;
+  return ERR_NONE;
 }
 
 static inline void InitDqLayerInfo (PDqLayer pDqLayer, PLayerInfo pLayerInfo, PNalUnit pNalUnit, PPicture pPicDec) {
@@ -2251,7 +2253,7 @@
 #else
               pCtx->bReferenceLostAtT0Flag = true;
 #endif
-              return ERR_INFO_REFERENCE_PIC_LOST;
+              return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_REFERENCE_PIC_LOST);
             }
           }
         }
@@ -2290,9 +2292,9 @@
         }
 
         if (bReconstructSlice) {
-          if (WelsDecodeConstructSlice (pCtx, pNalCur)) {
+          if ((iRet = WelsDecodeConstructSlice (pCtx, pNalCur)) != ERR_NONE) {
             pCtx->pDec->bIsComplete = false; // reconstruction error, directly set the flag false
-            return -1;
+            return iRet;
           }
         }
         if (bAllRefComplete && pCtx->eSliceType != I_SLICE) {
@@ -2479,6 +2481,8 @@
     }
     iRealMbIdx = (pCtx->pPps->uiNumSliceGroups > 1) ? FmoNextMb (pCtx->pFmo, iRealMbIdx) :
                  (pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iFirstMbInSlice + iMbIdx);
+    if (iRealMbIdx == -1) //caused by abnormal return of FmoNextMb()
+      return false;
   }
   return bAllRefComplete;
 }
--- a/codec/decoder/core/src/error_concealment.cpp
+++ b/codec/decoder/core/src/error_concealment.cpp
@@ -246,7 +246,7 @@
     iMVs[1] = iFullMVy - (iMbYInPix << 2);
     BaseMC (pMCRefMem, iMbXInPix, iMbYInPix, &pCtx->sMcFunc, 16, 16, iMVs);
   }
-  return ;
+  return;
 }
 
 void GetAvilInfoFromCorrectMb (PWelsDecoderContext pCtx) {
--- a/codec/decoder/core/src/fmo.cpp
+++ b/codec/decoder/core/src/fmo.cpp
@@ -40,6 +40,7 @@
 
 #include "fmo.h"
 #include "memory_align.h"
+#include "error_code.h"
 
 namespace WelsDec {
 
@@ -56,10 +57,11 @@
   int32_t iMbNum = 0;
   int32_t i = 0;
 
-  WELS_VERIFY_RETURN_IF (1, (NULL == pFmo || NULL == pPps))
+  WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pFmo || NULL == pPps))
   uiNumSliceGroups = pPps->uiNumSliceGroups;
   iMbNum = pFmo->iCountMbNum;
-  WELS_VERIFY_RETURN_IF (1, (NULL == pFmo->pMbAllocMap || iMbNum <= 0 || uiNumSliceGroups > MAX_SLICEGROUP_IDS))
+  WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pFmo->pMbAllocMap || iMbNum <= 0
+                         || uiNumSliceGroups > MAX_SLICEGROUP_IDS))
 
   do {
     uint8_t uiGroup = 0;
@@ -75,7 +77,7 @@
     } while (uiGroup < uiNumSliceGroups && i < iMbNum);
   } while (i < iMbNum);
 
-  return 0; // well here
+  return ERR_NONE; // well here
 }
 
 /*!
@@ -91,11 +93,11 @@
   uint32_t uiNumSliceGroups = 0;
   int32_t iMbNum = 0;
   int32_t i = 0;
-  WELS_VERIFY_RETURN_IF (1, (NULL == pFmo || NULL == pPps))
+  WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pFmo || NULL == pPps))
   uiNumSliceGroups = pPps->uiNumSliceGroups;
   iMbNum = pFmo->iCountMbNum;
-  WELS_VERIFY_RETURN_IF (1, (NULL == pFmo->pMbAllocMap || iMbNum <= 0 || kiMbWidth == 0
-                             || uiNumSliceGroups > MAX_SLICEGROUP_IDS))
+  WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pFmo->pMbAllocMap || iMbNum <= 0 || kiMbWidth == 0
+                         || uiNumSliceGroups > MAX_SLICEGROUP_IDS))
 
   do {
     pFmo->pMbAllocMap[i] = (uint8_t) (((i % kiMbWidth) + (((i / kiMbWidth) * uiNumSliceGroups) >> 1)) % uiNumSliceGroups);
@@ -102,7 +104,7 @@
     ++ i;
   } while (i < iMbNum);
 
-  return 0; // well here
+  return ERR_NONE; // well here
 }
 
 /*!
@@ -122,7 +124,7 @@
   bool bResolutionChanged = false;
 
   // the cases we would not like
-  WELS_VERIFY_RETURN_IF (1, (NULL == pFmo || NULL == kpPps))
+  WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pFmo || NULL == kpPps))
 
   iNumMb        = pFmo->iCountMbNum;
 
@@ -129,11 +131,11 @@
   iNumMb = kiMbWidth * kiMbHeight;
 
   if (0 == iNumMb)
-    return 1;
+    return ERR_INFO_INVALID_PARAM;
 
   pMa->WelsFree (pFmo->pMbAllocMap, "_fmo->pMbAllocMap");
   pFmo->pMbAllocMap = (uint8_t*)pMa->WelsMallocz (iNumMb * sizeof (uint8_t), "_fmo->pMbAllocMap");
-  WELS_VERIFY_RETURN_IF (1, (NULL == pFmo->pMbAllocMap)) // out of memory
+  WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY, (NULL == pFmo->pMbAllocMap)) // out of memory
 
   pFmo->iCountMbNum = iNumMb;
 
@@ -142,7 +144,7 @@
 
     pFmo->iSliceGroupCount = 1;
 
-    return 0;
+    return ERR_NONE;
   }
 
   if (bResolutionChanged || ((int32_t)kpPps->uiSliceGroupMapType != pFmo->iSliceGroupType)
@@ -163,7 +165,7 @@
       iErr = 1;
       break;
     default:
-      return 1;
+      return ERR_INFO_UNSUPPORTED_FMOTYPE;
     }
   }
 
--- a/codec/decoder/core/src/memmgr_nal_unit.cpp
+++ b/codec/decoder/core/src/memmgr_nal_unit.cpp
@@ -40,6 +40,7 @@
  *****************************************************************************/
 #include "memmgr_nal_unit.h"
 #include "memory_align.h"
+#include "error_code.h"
 
 namespace WelsDec {
 
@@ -52,7 +53,7 @@
   const uint32_t kuiCountSize = (kuiSizeAu + kuiSizeNalUnitPtr + kuiSize * kuiSizeNalUnit) * sizeof (uint8_t);
 
   if (kuiSize == 0)
-    return 1;
+    return ERR_INFO_INVALID_PARAM;
 
   if (*ppAu != NULL) {
     MemFreeNalList (ppAu, pMa);
@@ -60,7 +61,7 @@
 
   pBase = (uint8_t*)pMa->WelsMallocz (kuiCountSize, "Access Unit");
   if (pBase == NULL)
-    return 1;
+    return ERR_INFO_OUT_OF_MEMORY;
   pPtr = pBase;
   *ppAu = (PAccessUnit)pPtr;
   pPtr += kuiSizeAu;
@@ -79,7 +80,7 @@
   (*ppAu)->uiEndPos             = 0;
   (*ppAu)->bCompletedAuFlag     = false;
 
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t MemFreeNalList (PAccessUnit* ppAu, CMemoryAlign* pMa) {
@@ -90,20 +91,20 @@
       *ppAu = NULL;
     }
   }
-  return 0;
+  return ERR_NONE;
 }
 
 
 int32_t ExpandNalUnitList (PAccessUnit* ppAu, const int32_t kiOrgSize, const int32_t kiExpSize, CMemoryAlign* pMa) {
   if (kiExpSize <= kiOrgSize)
-    return 1;
+    return ERR_INFO_INVALID_PARAM;
   else {
     PAccessUnit pTmp = NULL;
     int32_t iIdx = 0;
+    int32_t iRet = ERR_NONE;
+    if ((iRet = MemInitNalList (&pTmp, kiExpSize, pMa)) != ERR_NONE) // request new list with expanding
+      return iRet;
 
-    if (MemInitNalList (&pTmp, kiExpSize, pMa)) // request new list with expanding
-      return 1;
-
     do {
       memcpy (pTmp->pNalUnitsList[iIdx], (*ppAu)->pNalUnitsList[iIdx], sizeof (SNalUnit)); //confirmed_safe_unsafe_usage
       ++ iIdx;
@@ -117,7 +118,7 @@
 
     MemFreeNalList (ppAu, pMa); // free old list
     *ppAu = pTmp;
-    return 0;
+    return ERR_NONE;
   }
 }
 
--- a/codec/decoder/core/src/parse_mb_syn_cabac.cpp
+++ b/codec/decoder/core/src/parse_mb_syn_cabac.cpp
@@ -401,7 +401,7 @@
         iRef[0] = 0;
         pCtx->iErrorCode |= dsBitstreamError;
       } else {
-        return ERR_INFO_INVALID_REF_INDEX;
+        return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
       }
     }
     pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[0]]
@@ -427,7 +427,7 @@
           iRef[i] = 0;
           pCtx->iErrorCode |= dsBitstreamError;
         } else {
-          return ERR_INFO_INVALID_REF_INDEX;
+          return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
         }
       }
       pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]]
@@ -457,7 +457,7 @@
           iRef[i] = 0;
           pCtx->iErrorCode |= dsBitstreamError;
         } else {
-          return ERR_INFO_INVALID_REF_INDEX;
+          return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
         }
       }
       pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]]
@@ -485,7 +485,7 @@
     for (i = 0; i < 4; i++) {
       WELS_READ_VERIFY (ParseSubMBTypeCabac (pCtx, pNeighAvail, uiSubMbType));
       if (uiSubMbType >= 4) { //invalid sub_mb_type
-        return ERR_INFO_INVALID_SUB_MB_TYPE;
+        return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE);
       }
       pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterSubMbTypeInfo[uiSubMbType].iType;
       pSubPartCount[i] = g_ksInterSubMbTypeInfo[uiSubMbType].iPartCount;
@@ -505,7 +505,7 @@
           pRefIdx[i] = 0;
           pCtx->iErrorCode |= dsBitstreamError;
         } else {
-          return ERR_INFO_INVALID_REF_INDEX;
+          return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
         }
       }
       pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[pRefIdx[i]]
@@ -973,7 +973,7 @@
   RestoreCabacDecEngineToBS (pCabacDecEngine, pBsAux);
   intX_t iBytesLeft = pBsAux->pEndBuf - pBsAux->pCurBuf;
   if (iBytesLeft < 384) {
-    return ERR_CABAC_NO_BS_TO_READ;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_CABAC_NO_BS_TO_READ);
   }
   pPtrSrc = pBsAux->pCurBuf;
   for (i = 0; i < 16; i++) {   //luma
--- a/codec/decoder/core/src/parse_mb_syn_cavlc.cpp
+++ b/codec/decoder/core/src/parse_mb_syn_cavlc.cpp
@@ -518,12 +518,12 @@
   int32_t iTopAvail      = uiSampleAvail & 0x01;
 
   if ((*pMode < 0) || (*pMode > MAX_PRED_MODE_ID_I16x16)) {
-    return ERR_INFO_INVALID_I16x16_PRED_MODE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I16x16_PRED_MODE);
   }
 
   if (I16_PRED_DC == *pMode) {
     if (iLeftAvail && iTopAvail) {
-      return 0;
+      return ERR_NONE;
     } else if (iLeftAvail) {
       *pMode = I16_PRED_DC_L;
     } else if (iTopAvail) {
@@ -534,10 +534,10 @@
   } else {
     bool bModeAvail = CHECK_I16_MODE (*pMode, iLeftAvail, iTopAvail, bLeftTopAvail);
     if (0 == bModeAvail) {
-      return ERR_INFO_INVALID_I16x16_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I16x16_PRED_MODE);
     }
   }
-  return 0;
+  return ERR_NONE;
 }
 
 
@@ -548,7 +548,7 @@
 
   if (C_PRED_DC == *pMode) {
     if (iLeftAvail && iTopAvail) {
-      return 0;
+      return ERR_NONE;
     } else if (iLeftAvail) {
       *pMode = C_PRED_DC_L;
     } else if (iTopAvail) {
@@ -559,10 +559,10 @@
   } else {
     bool bModeAvail = CHECK_CHROMA_MODE (*pMode, iLeftAvail, iTopAvail, bLeftTopAvail);
     if (0 == bModeAvail) {
-      return ERR_INFO_INVALID_I_CHROMA_PRED_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE);
     }
   }
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t CheckIntraNxNPredMode (int32_t* pSampleAvail, int8_t* pMode, int32_t iIndex, bool b8x8) {
@@ -576,7 +576,7 @@
   int8_t iFinalMode;
 
   if ((*pMode < 0) || (*pMode > MAX_PRED_MODE_ID_I4x4)) {
-    return ERR_INVALID_INTRA4X4_MODE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INVALID_INTRA4X4_MODE);
   }
 
   if (I4_PRED_DC == *pMode) {
@@ -592,7 +592,7 @@
   } else {
     bool bModeAvail = CHECK_I4_MODE (*pMode, iLeftAvail, iTopAvail, bLeftTopAvail);
     if (0 == bModeAvail) {
-      return ERR_INVALID_INTRA4X4_MODE;
+      return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INVALID_INTRA4X4_MODE);
     }
 
     iFinalMode = *pMode;
@@ -848,13 +848,13 @@
   }
   if (0 == uiTotalCoeff) {
     pBs->iIndex += iUsedBits;
-    return 0;
+    return ERR_NONE;
   }
   if ((uiTrailingOnes > 3) || (uiTotalCoeff > 16)) { /////////////////check uiTrailingOnes and uiTotalCoeff
-    return ERR_INFO_CAVLC_INVALID_TOTAL_COEFF_OR_TRAILING_ONES;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_CAVLC_INVALID_TOTAL_COEFF_OR_TRAILING_ONES);
   }
   if ((i = CavlcGetLevelVal (iLevel, &sReadBitsCache, uiTotalCoeff, uiTrailingOnes)) == -1) {
-    return ERR_INFO_CAVLC_INVALID_LEVEL;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_CAVLC_INVALID_LEVEL);
   }
   iUsedBits += i;
   if (uiTotalCoeff < iMaxNumCoeff) {
@@ -864,10 +864,10 @@
   }
 
   if ((iZerosLeft < 0) || ((iZerosLeft + uiTotalCoeff) > iMaxNumCoeff)) {
-    return ERR_INFO_CAVLC_INVALID_ZERO_LEFT;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_CAVLC_INVALID_ZERO_LEFT);
   }
   if ((i = CavlcGetRunBefore (iRun, &sReadBitsCache, uiTotalCoeff, pVlcTable, iZerosLeft)) == -1) {
-    return ERR_INFO_CAVLC_INVALID_RUN_BEFORE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_CAVLC_INVALID_RUN_BEFORE);
   }
   iUsedBits += i;
   pBs->iIndex += iUsedBits;
@@ -898,7 +898,7 @@
     }
   }
 
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t WelsResidualBlockCavlc8x8 (SVlcTable* pVlcTable, uint8_t* pNonZeroCountCache, PBitStringAux pBs, int32_t iIndex,
@@ -951,13 +951,13 @@
   }
   if (0 == uiTotalCoeff) {
     pBs->iIndex += iUsedBits;
-    return 0;
+    return ERR_NONE;
   }
   if ((uiTrailingOnes > 3) || (uiTotalCoeff > 16)) { /////////////////check uiTrailingOnes and uiTotalCoeff
-    return ERR_INFO_CAVLC_INVALID_TOTAL_COEFF_OR_TRAILING_ONES;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_CAVLC_INVALID_TOTAL_COEFF_OR_TRAILING_ONES);
   }
   if ((i = CavlcGetLevelVal (iLevel, &sReadBitsCache, uiTotalCoeff, uiTrailingOnes)) == -1) {
-    return ERR_INFO_CAVLC_INVALID_LEVEL;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_CAVLC_INVALID_LEVEL);
   }
   iUsedBits += i;
   if (uiTotalCoeff < iMaxNumCoeff) {
@@ -967,10 +967,10 @@
   }
 
   if ((iZerosLeft < 0) || ((iZerosLeft + uiTotalCoeff) > iMaxNumCoeff)) {
-    return ERR_INFO_CAVLC_INVALID_ZERO_LEFT;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_CAVLC_INVALID_ZERO_LEFT);
   }
   if ((i = CavlcGetRunBefore (iRun, &sReadBitsCache, uiTotalCoeff, pVlcTable, iZerosLeft)) == -1) {
-    return ERR_INFO_CAVLC_INVALID_RUN_BEFORE;
+    return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_CAVLC_INVALID_RUN_BEFORE);
   }
   iUsedBits += i;
   pBs->iIndex += iUsedBits;
@@ -985,7 +985,7 @@
                  : ((iLevel[i] * kpDequantCoeff[j] + (1 << (5 - uiQp / 6))) >> (6 - uiQp / 6));
   }
 
-  return 0;
+  return ERR_NONE;
 }
 
 int32_t ParseInterInfo (PWelsDecoderContext pCtx, int16_t iMvArray[LIST_A][30][MV_A], int8_t iRefIdxArray[LIST_A][30],
@@ -1026,7 +1026,7 @@
           iRefIdx = 0;
           pCtx->iErrorCode |= dsBitstreamError;
         } else {
-          return ERR_INFO_INVALID_REF_INDEX;
+          return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
         }
       }
       pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRefIdx]
@@ -1067,7 +1067,7 @@
           iRefIdx[i] = 0;
           pCtx->iErrorCode |= dsBitstreamError;
         } else {
-          return ERR_INFO_INVALID_REF_INDEX;
+          return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
         }
       }
       pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRefIdx[i]]
@@ -1104,7 +1104,7 @@
             iRefIdx[i] = 0;
             pCtx->iErrorCode |= dsBitstreamError;
           } else {
-            return ERR_INFO_INVALID_REF_INDEX;
+            return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
           }
         }
         pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRefIdx[i]]
@@ -1142,7 +1142,7 @@
       WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //sub_mb_type[ mbPartIdx ]
       uiSubMbType = uiCode;
       if (uiSubMbType >= 4) { //invalid uiSubMbType
-        return ERR_INFO_INVALID_SUB_MB_TYPE;
+        return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE);
       }
       pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterSubMbTypeInfo[uiSubMbType].iType;
       iSubPartCount[i] = g_ksInterSubMbTypeInfo[uiSubMbType].iPartCount;
@@ -1176,7 +1176,7 @@
               iRefIdx[i] = 0;
               pCtx->iErrorCode |= dsBitstreamError;
             } else {
-              return ERR_INFO_INVALID_REF_INDEX;
+              return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
             }
           }
           pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRefIdx[i]]
@@ -1245,7 +1245,7 @@
     break;
   }
 
-  return 0;
+  return ERR_NONE;
 }
 
 } // namespace WelsDec