shithub: openh264

Download patch

ref: 2ff38e9175704518cc5ea3cd7d37063760041089
parent: 32d1510d296d0dd5189b5432bbc0edd83cfb49b9
author: Sijia Chen <sijchen@cisco.com>
date: Wed Jun 10 07:28:23 EDT 2015

make two un-error ending of encoding go to a same exit and save the duplicated calling of UpdateSpatialPictures and ForceCodingIDR

--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -3859,15 +3859,12 @@
 
     pCtx->pFuncList->pMarkPic (pCtx);
     if (!pCtx->pFuncList->pBuildRefList (pCtx, pCtx->iPOC, 0)) {
-      pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, iDidIdx);
-      // Force coding IDR as followed
-      ForceCodingIDR (pCtx);
       WelsLog (pLogCtx, WELS_LOG_WARNING,
                "WelsEncoderEncodeExt(), WelsBuildRefList failed for P frames, pCtx->iNumRef0= %d. ForceCodingIDR!",
                pCtx->iNumRef0);
-      pFbi->eFrameType = videoFrameTypeIDR;
+      eFrameType = videoFrameTypeIDR;
       pCtx->iEncoderError = ENC_RETURN_CORRECTED;
-      return ENC_RETURN_CORRECTED;
+      break;
     }
     if (pCtx->eSliceType != I_SLICE) {
       pCtx->pFuncList->pAfterBuildRefList (pCtx);
@@ -4134,13 +4131,10 @@
     // reference picture list update
     if (eNalRefIdc != NRI_PRI_LOWEST) {
       if (!pCtx->pFuncList->pUpdateRefList (pCtx)) {
-        pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, iDidIdx);
-        // Force coding IDR as followed
-        ForceCodingIDR (pCtx);
         WelsLog (pLogCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsUpdateRefList failed. ForceCodingIDR!");
         //the above is to set the next frame to be IDR
-        pFbi->eFrameType = eFrameType;
-        return ENC_RETURN_CORRECTED;
+        pCtx->iEncoderError = ENC_RETURN_CORRECTED;
+        break;
       }
     }
 
@@ -4293,7 +4287,8 @@
 
     if (pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, iDidIdx) != 0) {
       ForceCodingIDR (pCtx);
-      WelsLog (pLogCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), Logic Error Found in temporal level. ForceCodingIDR!");
+      WelsLog (pLogCtx, WELS_LOG_WARNING,
+               "WelsEncoderEncodeExt(), Logic Error Found in Preprocess updating. ForceCodingIDR!");
       //the above is to set the next frame IDR
       pFbi->eFrameType = eFrameType;
       return ENC_RETURN_CORRECTED;
@@ -4303,6 +4298,15 @@
         && (pCtx->pLtr[pCtx->uiDependencyId].iLTRMarkMode == LTR_DIRECT_MARK)) || eFrameType == videoFrameTypeIDR)) {
       pCtx->bRefOfCurTidIsLtr[iDidIdx][iCurTid] = true;
     }
+  }
+
+  if (ENC_RETURN_CORRECTED == pCtx->iEncoderError) {
+    pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, (pSpatialIndexMap + iSpatialIdx)->iDid);
+    ForceCodingIDR (pCtx);
+    WelsLog (pLogCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), Logic Error Found in temporal level. ForceCodingIDR!");
+    //the above is to set the next frame IDR
+    pFbi->eFrameType = eFrameType;
+    return ENC_RETURN_CORRECTED;
   }
 
 #if defined(MT_DEBUG)