shithub: openh264

Download patch

ref: 71566cdba463610e74e35b2ae9d5fbdc62ced611
parent: b26bcda090f40f834fdeeb68bafdd5772dcbd726
author: huili2 <huili2@cisco.com>
date: Wed Jul 26 10:47:09 EDT 2017

fix PCM parseonly crash issue

--- a/codec/decoder/core/src/decode_slice.cpp
+++ b/codec/decoder/core/src/decode_slice.cpp
@@ -614,6 +614,7 @@
              && uiMbType <= 24))) {
     return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
   } else if (25 == uiMbType) {   //I_PCM
+    WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in I slice!");
     WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx));
     pSlice->iLastDeltaQp = 0;
     WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag));
@@ -833,6 +834,7 @@
       return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
 
     if (25 == uiMbType) {   //I_PCM
+      WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in P slice!");
       WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx));
       pSlice->iLastDeltaQp = 0;
       WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag));
@@ -1265,6 +1267,7 @@
     return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
 
   if (25 == uiMbType) {
+    WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in I slice!");
     int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
     int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1];
 
@@ -1291,21 +1294,23 @@
 
     //step 2: copy pixel from bit-stream into fdec [reconstruction]
     pTmpBsBuf = pBs->pCurBuf;
-    for (i = 0; i < 16; i++) { //luma
-      memcpy (pDecY , pTmpBsBuf, iCopySizeY);
-      pDecY += iDecStrideL;
-      pTmpBsBuf += 16;
+    if (!pCtx->pParam->bParseOnly) {
+      for (i = 0; i < 16; i++) { //luma
+        memcpy (pDecY , pTmpBsBuf, iCopySizeY);
+        pDecY += iDecStrideL;
+        pTmpBsBuf += 16;
+      }
+      for (i = 0; i < 8; i++) { //cb
+        memcpy (pDecU, pTmpBsBuf, iCopySizeUV);
+        pDecU += iDecStrideC;
+        pTmpBsBuf += 8;
+      }
+      for (i = 0; i < 8; i++) { //cr
+        memcpy (pDecV, pTmpBsBuf, iCopySizeUV);
+        pDecV += iDecStrideC;
+        pTmpBsBuf += 8;
+      }
     }
-    for (i = 0; i < 8; i++) { //cb
-      memcpy (pDecU, pTmpBsBuf, iCopySizeUV);
-      pDecU += iDecStrideC;
-      pTmpBsBuf += 8;
-    }
-    for (i = 0; i < 8; i++) { //cr
-      memcpy (pDecV, pTmpBsBuf, iCopySizeUV);
-      pDecV += iDecStrideC;
-      pTmpBsBuf += 8;
-    }
 
     pBs->pCurBuf += 384;
 
@@ -1603,6 +1608,7 @@
       return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE);
 
     if (25 == uiMbType) {
+      WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in P slice!");
       int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
       int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1];
 
@@ -1628,21 +1634,23 @@
 
       //step 2: copy pixel from bit-stream into fdec [reconstruction]
       pTmpBsBuf = pBs->pCurBuf;
-      for (i = 0; i < 16; i++) { //luma
-        memcpy (pDecY , pTmpBsBuf, iCopySizeY);
-        pDecY += iDecStrideL;
-        pTmpBsBuf += 16;
-      }
+      if (!pCtx->pParam->bParseOnly) {
+        for (i = 0; i < 16; i++) { //luma
+          memcpy (pDecY, pTmpBsBuf, iCopySizeY);
+          pDecY += iDecStrideL;
+          pTmpBsBuf += 16;
+        }
 
-      for (i = 0; i < 8; i++) { //cb
-        memcpy (pDecU, pTmpBsBuf, iCopySizeUV);
-        pDecU += iDecStrideC;
-        pTmpBsBuf += 8;
-      }
-      for (i = 0; i < 8; i++) { //cr
-        memcpy (pDecV, pTmpBsBuf, iCopySizeUV);
-        pDecV += iDecStrideC;
-        pTmpBsBuf += 8;
+        for (i = 0; i < 8; i++) { //cb
+          memcpy (pDecU, pTmpBsBuf, iCopySizeUV);
+          pDecU += iDecStrideC;
+          pTmpBsBuf += 8;
+        }
+        for (i = 0; i < 8; i++) { //cr
+          memcpy (pDecV, pTmpBsBuf, iCopySizeUV);
+          pDecV += iDecStrideC;
+          pTmpBsBuf += 8;
+        }
       }
 
       pBs->pCurBuf += 384;
--- a/codec/decoder/core/src/parse_mb_syn_cabac.cpp
+++ b/codec/decoder/core/src/parse_mb_syn_cabac.cpp
@@ -991,20 +991,22 @@
     return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_CABAC_NO_BS_TO_READ);
   }
   pPtrSrc = pBsAux->pCurBuf;
-  for (i = 0; i < 16; i++) {   //luma
-    memcpy (pMbDstY , pPtrSrc, 16);
-    pMbDstY += iDstStrideLuma;
-    pPtrSrc += 16;
-  }
-  for (i = 0; i < 8; i++) {   //cb
-    memcpy (pMbDstU, pPtrSrc, 8);
-    pMbDstU += iDstStrideChroma;
-    pPtrSrc += 8;
-  }
-  for (i = 0; i < 8; i++) {   //cr
-    memcpy (pMbDstV, pPtrSrc, 8);
-    pMbDstV += iDstStrideChroma;
-    pPtrSrc += 8;
+  if (!pCtx->pParam->bParseOnly) {
+    for (i = 0; i < 16; i++) {   //luma
+      memcpy (pMbDstY , pPtrSrc, 16);
+      pMbDstY += iDstStrideLuma;
+      pPtrSrc += 16;
+    }
+    for (i = 0; i < 8; i++) {   //cb
+      memcpy (pMbDstU, pPtrSrc, 8);
+      pMbDstU += iDstStrideChroma;
+      pPtrSrc += 8;
+    }
+    for (i = 0; i < 8; i++) {   //cr
+      memcpy (pMbDstV, pPtrSrc, 8);
+      pMbDstV += iDstStrideChroma;
+      pPtrSrc += 8;
+    }
   }
 
   pBsAux->pCurBuf += 384;