shithub: openh264

Download patch

ref: fdcecde1c7786b74426f32c4de4c9ab8b7667e5f
parent: 297e043f7bc26dfbcc9e8ff72df3138ec7723477
author: Karina <ruil2@cisco.com>
date: Tue Oct 10 09:55:08 EDT 2017

fix frequent IDR issue when smaller level is set

--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -4238,20 +4238,7 @@
 
         break;
       }
-      if (pOldParam->sSpatialLayers[iIndexD].uiProfileIdc !=
-          pNewParam->sSpatialLayers[iIndexD].uiProfileIdc
-          ||
-          pOldParam->sSpatialLayers[iIndexD].uiLevelIdc !=
-          pNewParam->sSpatialLayers[iIndexD].uiLevelIdc) {
-        bNeedReset = true;
-        WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
-                 "WelsEncoderParamAdjust(),iIndexD = %d,uiProfileIdc(%d,%d),uiLevelIdc(%d,%d)", iIndexD,
-                 pOldParam->sSpatialLayers[iIndexD].uiProfileIdc, pNewParam->sSpatialLayers[iIndexD].uiProfileIdc,
-                 pOldParam->sSpatialLayers[iIndexD].uiLevelIdc, pNewParam->sSpatialLayers[iIndexD].uiLevelIdc);
 
-        break;
-      }
-
       // check frame rate
       // we can not check whether corresponding fFrameRate is equal or not,
       // only need to check d_max/d_min and max_fr/d_max whether it is equal or not
@@ -4265,6 +4252,22 @@
                  "WelsEncoderParamAdjust() iIndexD = %d,fInputFrameRate(%f,%f),fOutputFrameRate(%f,%f),fMaxFrameRate(%f,%f)", iIndexD,
                  kpOldDlp->fInputFrameRate, kpNewDlp->fInputFrameRate, kpOldDlp->fOutputFrameRate, kpNewDlp->fOutputFrameRate,
                  pOldParam->fMaxFrameRate, pNewParam->fMaxFrameRate);
+        break;
+      }
+      if (pOldParam->sSpatialLayers[iIndexD].uiProfileIdc != pNewParam->sSpatialLayers[iIndexD].uiProfileIdc) {
+        bNeedReset = true;
+        WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
+                 "WelsEncoderParamAdjust(),iIndexD = %d,uiProfileIdc(%d,%d)", iIndexD,
+                 pOldParam->sSpatialLayers[iIndexD].uiProfileIdc, pNewParam->sSpatialLayers[iIndexD].uiProfileIdc);
+        break;
+      }
+      //check level change,if new level is smaller than old level,don't reset encoder. still use old level.
+
+      if (pNewParam->sSpatialLayers[iIndexD].uiLevelIdc > pOldParam->sSpatialLayers[iIndexD].uiLevelIdc) {
+        bNeedReset = true;
+        WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
+                 "WelsEncoderParamAdjust(),iIndexD = %d,uiLevelIdc(%d,%d)", iIndexD,
+                 pOldParam->sSpatialLayers[iIndexD].uiLevelIdc, pNewParam->sSpatialLayers[iIndexD].uiLevelIdc);
         break;
       }
       ++ iIndexD;