shithub: openh264

Download patch

ref: b1653b36995241e5a7b557d68db403d8ec671de9
parent: 51a68875cde2fcbc2bc22349768aa852e0b5c2ff
parent: e89f8a51b25fbe2ef5bba781b26236a53d09bc37
author: huili2 <huili2@cisco.com>
date: Tue Aug 21 10:06:54 EDT 2018

Merge pull request #3011 from xiaotiansf/master

Fix Bugzillia reported Bug-1479669, Bug-1479670 and Bug-1479831. fix null pointers for some test cases when specific error conditions.

--- a/codec/decoder/core/inc/mv_pred.h
+++ b/codec/decoder/core/inc/mv_pred.h
@@ -98,7 +98,8 @@
 * \param
 * \param   output iMvp[] and ref
 */
-SubMbType  PredMvBDirectSpatial (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A]);
+int32_t  PredMvBDirectSpatial (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A],
+                               SubMbType& subMbType);
 
 /*!
 * \brief   get Colocated MB for both Spatial and Temporal Direct Mode
@@ -110,7 +111,7 @@
 /*!
 * \brief   get the motion predictor for B-slice temporal direct mode 16x16
 */
-void PredBDirectTemporal (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A]);
+int32_t PredBDirectTemporal (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A]);
 
 /*!
 * \brief   get the motion params for B-slice spatial direct mode
--- a/codec/decoder/core/src/decode_slice.cpp
+++ b/codec/decoder/core/src/decode_slice.cpp
@@ -52,6 +52,8 @@
 
 namespace WelsDec {
 
+extern void FreePicture (PPicture pPic, CMemoryAlign* pMa);
+
 static inline int32_t iAbs (int32_t x) {
   static const int32_t INT_BITS = (sizeof (int) * CHAR_BIT) - 1;
   int32_t y = x >> INT_BITS;
@@ -208,6 +210,12 @@
   } else {
     if (pCtx->pTempDec == NULL)
       pCtx->pTempDec = AllocPicture (pCtx, pCtx->pSps->iMbWidth << 4, pCtx->pSps->iMbHeight << 4);
+    else {
+      if (pCtx->pTempDec->iLinesize[0] != pCtx->pDec->iLinesize[0]) {
+        FreePicture (pCtx->pTempDec, pCtx->pMemAlign);
+        pCtx->pTempDec = AllocPicture (pCtx, pCtx->pSps->iMbWidth << 4, pCtx->pSps->iMbHeight << 4);
+      }
+    }
     uint8_t*   pTempDstYCbCr[3];
     uint8_t*   pDstYCbCr[3];
     pTempDstYCbCr[0] = pCtx->pTempDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4);
@@ -1415,15 +1423,24 @@
     pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPicL0[0] && ppRefPicL0[0]->bIsComplete)
                             || ! (ppRefPicL1[0] && ppRefPicL1[0]->bIsComplete);
 
+
     if (pSliceHeader->iDirectSpatialMvPredFlag) {
 
       //predict direct spatial mv
-      PredMvBDirectSpatial (pCtx, pMv, ref);
+      SubMbType subMbType;
+      int32_t ret = PredMvBDirectSpatial (pCtx, pMv, ref, subMbType);
+      if (ret != ERR_NONE) {
+        return ret;
+      }
     } else {
       //temporal direct mode
       ComputeColocated (pCtx);
-      PredBDirectTemporal (pCtx, pMv, ref);
+      int32_t ret = PredBDirectTemporal (pCtx, pMv, ref);
+      if (ret != ERR_NONE) {
+        return ret;
+      }
     }
+
 
     //reset rS
     pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; //??????????????? dqaunt of previous mb
--- a/codec/decoder/core/src/decoder_core.cpp
+++ b/codec/decoder/core/src/decoder_core.cpp
@@ -526,7 +526,9 @@
 
           pCtx->iPrevPicOrderCntLsb = 0;
           pCtx->iPrevPicOrderCntMsb = 0;
-          pCtx->pSliceHeader->iPicOrderCntLsb = 0;
+          pSh->iPicOrderCntLsb = 0;
+          if (pCtx->pSliceHeader)
+            pCtx->pSliceHeader->iPicOrderCntLsb = 0;
         }
         ++ iIdx;
 
--- a/codec/decoder/core/src/mv_pred.cpp
+++ b/codec/decoder/core/src/mv_pred.cpp
@@ -313,6 +313,12 @@
 
   PPicture colocPic = pCtx->sRefPic.pRefList[LIST_1][0];
 
+  if (colocPic == NULL) {
+    SLogContext* pLogCtx = & (pCtx->sLogCtx);
+    WelsLog (pLogCtx, WELS_LOG_ERROR, "Colocated Ref Picture for B-Slice is lost, B-Slice decoding cannot be continued!");
+    return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_DATA, ERR_INFO_REFERENCE_PIC_LOST);
+  }
+
   MbType coloc_mbType = colocPic->pMbType[iMbXy];
 
   if (IS_Inter_8x8 (coloc_mbType) && !pCtx->pSps->bDirect8x8InferenceFlag) {
@@ -328,7 +334,7 @@
 
   if (IS_INTRA (coloc_mbType)) {
     SetRectBlock (pCurLayer->iColocIntra, 4, 4, 4 * sizeof (int8_t), 1, sizeof (int8_t));
-    return 1;
+    return ERR_NONE;
   }
   SetRectBlock (pCurLayer->iColocIntra, 4, 4, 4 * sizeof (int8_t), 0, sizeof (int8_t));
 
@@ -366,18 +372,22 @@
         SetRectBlock (&pCurLayer->iColocRefIndex[1][0], 4, 4, 4, (uint8_t)REF_NOT_IN_LIST, 1);
     }
   }
-  return 1;
+  return ERR_NONE;
 }
 
-SubMbType PredMvBDirectSpatial (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A]) {
+int32_t PredMvBDirectSpatial (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A],
+                              SubMbType& subMbType) {
 
+  int32_t ret = ERR_NONE;
   PDqLayer pCurLayer = pCtx->pCurDqLayer;
   int32_t iMbXy = pCurLayer->iMbXyIndex;
   bool bSkipOrDirect = (IS_SKIP (pCurLayer->pMbType[iMbXy]) | IS_DIRECT (pCurLayer->pMbType[iMbXy])) > 0;
 
   MbType mbType;
-  SubMbType subMbType;
-  GetColocatedMb (pCtx, mbType, subMbType);
+  ret = GetColocatedMb (pCtx, mbType, subMbType);
+  if (ret != ERR_NONE) {
+    return ret;
+  }
 
   bool bTopAvail, bLeftTopAvail, bRightTopAvail, bLeftAvail;
   int32_t iLeftTopType, iRightTopType, iTopType, iLeftType;
@@ -494,7 +504,7 @@
     iDiagonalRef[listIdx] = iRightTopRef[listIdx];
     if (REF_NOT_AVAIL == iDiagonalRef[listIdx]) {
       iDiagonalRef[listIdx] = iLeftTopRef[listIdx];
-      * (int32_t*)iMvC[listIdx] = * (int32_t*)iMvD[listIdx];
+      ST32 (iMvC[listIdx], LD32 (iMvD[listIdx]));
     }
 
     int8_t ref_temp = WELS_MIN_POSITIVE (iTopRef[listIdx], iDiagonalRef[listIdx]);
@@ -643,16 +653,20 @@
       }
     }
   }
-  return subMbType;
+  return ret;
 }
 
-void PredBDirectTemporal (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A]) {
+int32_t PredBDirectTemporal (PWelsDecoderContext pCtx, int16_t iMvp[LIST_A][2], int8_t ref[LIST_A]) {
+  int32_t ret = ERR_NONE;
   PDqLayer pCurLayer = pCtx->pCurDqLayer;
   int32_t iMbXy = pCurLayer->iMbXyIndex;
   bool bSkipOrDirect = (IS_SKIP (pCurLayer->pMbType[iMbXy]) | IS_DIRECT (pCurLayer->pMbType[iMbXy])) > 0;
   MbType mbType;
   SubMbType subMbType;
-  GetColocatedMb (pCtx, mbType, subMbType);
+  ret = GetColocatedMb (pCtx, mbType, subMbType);
+  if (ret != ERR_NONE) {
+    return ret;
+  }
   PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer;
   if (IS_INTER_16x16 (mbType)) {
     ref[LIST_0] = 0;
@@ -664,7 +678,8 @@
       UpdateP16x16MotionOnly (pCurLayer, LIST_1, iMvp[LIST_1]);
       UpdateP16x16RefIdx (pCurLayer, LIST_0, ref[LIST_0]);
     } else {
-      ref[LIST_0] = pCurLayer->iColocRefIndex[LIST_0][0];
+      ref[LIST_0] = pCurLayer->iColocRefIndex[LIST_0][0] >= 0 ? pCurLayer->iColocRefIndex[LIST_0][0] :
+                    pCurLayer->iColocRefIndex[LIST_1][0];
       const int16_t (*mvColoc)[2] = 0 == ref[LIST_0] ? pCurLayer->iColocMv[LIST_0] : pCurLayer->iColocMv[LIST_1];
       const int16_t* mv = mvColoc[0];
       UpdateP16x16RefIdx (pCurLayer, LIST_0, ref[LIST_0]);
@@ -748,6 +763,7 @@
       }
     }
   }
+  return ret;
 }
 
 //basic iMVs prediction unit for iMVs partition width (4, 2, 1)
--- a/codec/decoder/core/src/parse_mb_syn_cabac.cpp
+++ b/codec/decoder/core/src/parse_mb_syn_cabac.cpp
@@ -80,7 +80,7 @@
     return 0; /* I4x4 */
   }
 
-  DecodeTerminateCabac (pCabacDecEngine, uiCode);
+  WELS_READ_VERIFY (DecodeTerminateCabac (pCabacDecEngine, uiCode));
   if (uiCode) {
     return 25; /* PCM */
   }
@@ -741,11 +741,18 @@
     int16_t pMvDirect[LIST_A][2] = { { 0, 0 }, { 0, 0 } };
     if (pSliceHeader->iDirectSpatialMvPredFlag) {
       //predict direct spatial mv
-      PredMvBDirectSpatial (pCtx, pMvDirect, iRef);
+      SubMbType subMbType;
+      int32_t ret = PredMvBDirectSpatial (pCtx, pMvDirect, iRef, subMbType);
+      if (ret != ERR_NONE) {
+        return ret;
+      }
     } else {
       //temporal direct 16x16 mode
       ComputeColocated (pCtx);
-      PredBDirectTemporal (pCtx, pMvDirect, iRef);
+      int32_t ret = PredBDirectTemporal (pCtx, pMvDirect, iRef);
+      if (ret != ERR_NONE) {
+        return ret;
+      }
     }
   } else if (IS_INTER_16x16 (mbType)) {
     iPartIdx = 0;
@@ -894,11 +901,18 @@
       if (IS_DIRECT (g_ksInterBSubMbTypeInfo[uiSubMbType].iType)) {
         if (!has_direct_called) {
           if (pSliceHeader->iDirectSpatialMvPredFlag) {
-            directSubMbType = PredMvBDirectSpatial (pCtx, pMvDirect, iRef);
+            int32_t ret = PredMvBDirectSpatial (pCtx, pMvDirect, iRef, directSubMbType);
+            if (ret != ERR_NONE) {
+              return ret;
+            }
+
           } else {
             //temporal direct mode
             ComputeColocated (pCtx);
-            PredBDirectTemporal (pCtx, pMvDirect, iRef);
+            int32_t ret = PredBDirectTemporal (pCtx, pMvDirect, iRef);
+            if (ret != ERR_NONE) {
+              return ret;
+            }
           }
           has_direct_called = true;
         }