shithub: openh264

Download patch

ref: b719c3b0d5872fbfbcd962c299fd51f9164671a3
parent: d2d4ab8c67cacfd0ce2c9a6dada5024c1d207388
author: huili2 <huili2@cisco.com>
date: Sun Jan 4 12:01:19 EST 2015

output error when frame incomplete for parse only usage

--- a/codec/decoder/core/src/decode_slice.cpp
+++ b/codec/decoder/core/src/decode_slice.cpp
@@ -90,12 +90,14 @@
       break;
     }
 
-    if (WelsTargetMbConstruction (pCtx)) {
-      WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING,
-               "WelsTargetSliceConstruction():::MB(%d, %d) construction error. pCurSlice_type:%d",
-               pCurLayer->iMbX, pCurLayer->iMbY, pCurSlice->eSliceType);
+    if (!pCtx->bParseOnly) { //for parse only, actual recon MB unnecessary
+      if (WelsTargetMbConstruction (pCtx)) {
+        WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING,
+                 "WelsTargetSliceConstruction():::MB(%d, %d) construction error. pCurSlice_type:%d",
+                 pCurLayer->iMbX, pCurLayer->iMbY, pCurSlice->eSliceType);
 
-      return -1;
+        return -1;
+      }
     }
 
     ++iCountNumMb;
@@ -130,6 +132,9 @@
   pCtx->pDec->iHeightInPixel = iCurLayerHeight;
 
   if ((pCurSlice->eSliceType != I_SLICE) && (pCurSlice->eSliceType != P_SLICE))
+    return 0;
+
+  if (pCtx->bParseOnly) //for parse only, deblocking should not go on
     return 0;
 
   pDeblockMb = WelsDeblockingMb;
--- a/codec/decoder/core/src/decoder_core.cpp
+++ b/codec/decoder/core/src/decoder_core.cpp
@@ -45,6 +45,8 @@
 
 namespace WelsDec {
 static inline int32_t DecodeFrameConstruction (PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferInfo* pDstInfo) {
+  if (pDstInfo == NULL) //parse only usage
+    return -1;
   PDqLayer pCurDq = pCtx->pCurDqLayer;
   PPicture pPic = pCtx->pDec;
 
@@ -1760,7 +1762,7 @@
   iErr = DecodeCurrentAccessUnit (pCtx, ppDst, pDstInfo);
 
   if (pCtx->bParseOnly) {
-    if (dsErrorFree == pCtx->iErrorCode) {
+    if ((dsErrorFree == pCtx->iErrorCode) && (pCtx->iTotalNumMbRec == pCtx->pSps->iMbHeight * pCtx->pSps->iMbWidth)) {
       SParserBsInfo* pParser = pCtx->pParserBsInfo;
       uint8_t* pDstBuf = pParser->pDstBuff;
       SNalUnit* pCurNal = NULL;
@@ -1804,6 +1806,10 @@
       pCtx->pParserBsInfo->iNalNum = 0;
       pCtx->pParserBsInfo->iSpsWidthInPixel = 0;
       pCtx->pParserBsInfo->iSpsHeightInPixel = 0;
+      if (dsErrorFree == pCtx->iErrorCode) { //frame not complete
+        pCtx->iTotalNumMbRec = 0;
+        pCtx->iErrorCode |= dsFramePending;
+      }
     }
   }
 
@@ -2082,12 +2088,10 @@
           }
         }
 
-        if (!pCtx->bParseOnly) {
-          if (bReconstructSlice) {
-            if (WelsDecodeConstructSlice (pCtx, pNalCur)) {
-              pCtx->pDec->bIsComplete = false; // reconstruction error, directly set the flag false
-              return -1;
-            }
+        if (bReconstructSlice) {
+          if (WelsDecodeConstructSlice (pCtx, pNalCur)) {
+            pCtx->pDec->bIsComplete = false; // reconstruction error, directly set the flag false
+            return -1;
           }
         }
         if (bAllRefComplete && pCtx->eSliceType != I_SLICE) {
@@ -2158,7 +2162,8 @@
             return iRet;
           }
         }
-        ExpandReferencingPicture (pCtx->pDec->pData, pCtx->pDec->iWidthInPixel, pCtx->pDec->iHeightInPixel,
+        if (!pCtx->bParseOnly)
+          ExpandReferencingPicture (pCtx->pDec->pData, pCtx->pDec->iWidthInPixel, pCtx->pDec->iHeightInPixel,
                                   pCtx->pDec->iLinesize,
                                   pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture);
       }